From 895ad29b0d2f1a1863df316aa94f6d77c2fe23ee Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sat, 19 Sep 2015 13:58:49 -0600 Subject: [PATCH] Fix IOCTL definition to avoid duplication and mess --- drivers/power/battery_charger.c | 1 + drivers/power/battery_gauge.c | 1 + drivers/power/max1704x.c | 35 ++++++++-------- include/nuttx/power/battery_charger.h | 6 --- include/nuttx/power/battery_gauge.h | 5 --- include/nuttx/power/battery_ioctl.h | 58 +++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 include/nuttx/power/battery_ioctl.h diff --git a/drivers/power/battery_charger.c b/drivers/power/battery_charger.c index 1e12f7dd2ce..20f84bb03dd 100644 --- a/drivers/power/battery_charger.c +++ b/drivers/power/battery_charger.c @@ -47,6 +47,7 @@ #include #include +#include /* This driver requires: * diff --git a/drivers/power/battery_gauge.c b/drivers/power/battery_gauge.c index 696b29e6327..032b6b1158a 100644 --- a/drivers/power/battery_gauge.c +++ b/drivers/power/battery_gauge.c @@ -47,6 +47,7 @@ #include #include +#include /* This driver requires: * diff --git a/drivers/power/max1704x.c b/drivers/power/max1704x.c index 2df676fa617..571fe63c3ef 100644 --- a/drivers/power/max1704x.c +++ b/drivers/power/max1704x.c @@ -1,6 +1,6 @@ /**************************************************************************** * drivers/power/max1704x.c - * Lower half driver for MAX1704x battery charger + * Lower half driver for MAX1704x battery fuel gauge * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -55,11 +55,11 @@ #include #include -#include +#include /* This driver requires: * - * CONFIG_BATTERY - Upper half battery driver support + * CONFIG_BATTERY - Upper half battery gauge driver support * CONFIG_I2C - I2C support * CONFIG_I2C_MAX1704X - And the driver must be explictly selected. */ @@ -177,8 +177,8 @@ struct max1704x_dev_s { /* The common part of the battery driver visible to the upper-half driver */ - FAR const struct battery_operations_s *ops; /* Battery operations */ - sem_t batsem; /* Enforce mutually exclusive access */ + FAR const struct battery_gauge_operations_s *ops; /* Battery operations */ + sem_t batsem; /* Enforce mutually exclusive access */ /* Data fields specific to the lower half MAX1704x driver follow */ @@ -208,16 +208,16 @@ static inline int max1704x_reset(FAR struct max1704x_dev_s *priv); /* Battery driver lower half methods */ -static int max1704x_state(struct battery_dev_s *dev, int *status); -static int max1704x_online(struct battery_dev_s *dev, bool *status); -static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value); -static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value); +static int max1704x_state(struct battery_gauge_dev_s *dev, int *status); +static int max1704x_online(struct battery_gauge_dev_s *dev, bool *status); +static int max1704x_voltage(struct battery_gauge_dev_s *dev, b16_t *value); +static int max1704x_capacity(struct battery_gauge_dev_s *dev, b16_t *value); /**************************************************************************** * Private Data ****************************************************************************/ -static const struct battery_operations_s g_max1704xops = +static const struct battery_gauge_operations_s g_max1704xops = { max1704x_state, max1704x_online, @@ -410,7 +410,7 @@ static inline int max1704x_reset(FAR struct max1704x_dev_s *priv) * ****************************************************************************/ -static int max1704x_state(struct battery_dev_s *dev, int *status) +static int max1704x_state(struct battery_gauge_dev_s *dev, int *status) { FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev; b16_t soc = 0; @@ -454,7 +454,7 @@ static int max1704x_state(struct battery_dev_s *dev, int *status) * ****************************************************************************/ -static int max1704x_online(struct battery_dev_s *dev, bool *status) +static int max1704x_online(struct battery_gauge_dev_s *dev, bool *status) { /* There is no concept of online/offline in this driver */ @@ -470,7 +470,7 @@ static int max1704x_online(struct battery_dev_s *dev, bool *status) * ****************************************************************************/ -static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value) +static int max1704x_voltage(struct battery_gauge_dev_s *dev, b16_t *value) { FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev; return max1704x_getvcell(priv, value); @@ -484,7 +484,7 @@ static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value) * ****************************************************************************/ -static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value) +static int max1704x_capacity(struct battery_gauge_dev_s *dev, b16_t *value) { FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev; return max1704x_getsoc(priv, value); @@ -520,8 +520,9 @@ static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value) * ****************************************************************************/ -FAR struct battery_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c, - uint8_t addr, uint32_t frequency) +FAR struct battery_gauge_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c, + uint8_t addr, + uint32_t frequency) { FAR struct max1704x_dev_s *priv; #if 0 @@ -557,7 +558,7 @@ FAR struct battery_dev_s *max1704x_initialize(FAR struct i2c_dev_s *i2c, } #endif } - return (FAR struct battery_dev_s *)priv; + return (FAR struct battery_gauge_dev_s *)priv; } #endif /* CONFIG_BATTERY && CONFIG_I2C && CONFIG_I2C_MAX1704X */ diff --git a/include/nuttx/power/battery_charger.h b/include/nuttx/power/battery_charger.h index fadb331b211..99be21f88a5 100644 --- a/include/nuttx/power/battery_charger.h +++ b/include/nuttx/power/battery_charger.h @@ -83,12 +83,6 @@ * Input value: An int defining the voltage value. */ -#define BATIOC_STATE _BATIOC(0x0001) -#define BATIOC_HEALTH _BATIOC(0x0002) -#define BATIOC_ONLINE _BATIOC(0x0003) -#define BATIOC_VOLTAGE _BATIOC(0x0004) -#define BATIOC_CURRENT _BATIOC(0x0005) - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/include/nuttx/power/battery_gauge.h b/include/nuttx/power/battery_gauge.h index 83430582c40..d087f2213c2 100644 --- a/include/nuttx/power/battery_gauge.h +++ b/include/nuttx/power/battery_gauge.h @@ -86,11 +86,6 @@ * Input value: A pointer to type b16_t. */ -#define BATIOC_STATE _BATIOC(0x0001) -#define BATIOC_ONLINE _BATIOC(0x0002) -#define BATIOC_VOLTAGE _BATIOC(0x0003) -#define BATIOC_CAPACITY _BATIOC(0x0004) - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/include/nuttx/power/battery_ioctl.h b/include/nuttx/power/battery_ioctl.h new file mode 100644 index 00000000000..4bbd46e21bc --- /dev/null +++ b/include/nuttx/power/battery_ioctl.h @@ -0,0 +1,58 @@ +/**************************************************************************** + * include/nuttx/power/battery_ioctl.h + * NuttX Battery IOCTLs definition + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_POWER_BATTERY_IOCTL_H +#define __INCLUDE_NUTTX_POWER_BATTERY_IOCTL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BATIOC_STATE _BATIOC(0x0001) +#define BATIOC_HEALTH _BATIOC(0x0002) +#define BATIOC_ONLINE _BATIOC(0x0003) +#define BATIOC_VOLTAGE _BATIOC(0x0004) +#define BATIOC_CURRENT _BATIOC(0x0005) +#define BATIOC_CAPACITY _BATIOC(0x0006) + +#endif /* __INCLUDE_NUTTX_POWER_BATTERY_IOCTL_H */