[PATCH 2/2] iio: ad7793: Fix the serial interface reset

2017-09-05 Thread Dragos Bogdan
The serial interface can be reset by writing 32 consecutive 1s to the device.
'ret' was initialized correctly but its value was overwritten when
ad7793_check_platform_data() was called. Since a dedicated reset function
is present now, it should be used instead.

Fixes: 2edb769d246e ("iio:ad7793: Add support for the ad7798 and ad7799")
Signed-off-by: Dragos Bogdan <dragos.bog...@analog.com>
---
 drivers/iio/adc/ad7793.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index e6706a09e100..47c3d7f32900 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
unsigned int vref_mv)
 {
struct ad7793_state *st = iio_priv(indio_dev);
-   int i, ret = -1;
+   int i, ret;
unsigned long long scale_uv;
u32 id;
 
@@ -266,7 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
return ret;
 
/* reset the serial interface */
-   ret = spi_write(st->sd.spi, (u8 *), sizeof(ret));
+   ret = ad_sd_reset(>sd, 32);
if (ret < 0)
goto out;
usleep_range(500, 2000); /* Wait for at least 500us */
-- 
2.11.0



[PATCH 2/2] iio: ad7793: Fix the serial interface reset

2017-09-05 Thread Dragos Bogdan
The serial interface can be reset by writing 32 consecutive 1s to the device.
'ret' was initialized correctly but its value was overwritten when
ad7793_check_platform_data() was called. Since a dedicated reset function
is present now, it should be used instead.

Fixes: 2edb769d246e ("iio:ad7793: Add support for the ad7798 and ad7799")
Signed-off-by: Dragos Bogdan 
---
 drivers/iio/adc/ad7793.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index e6706a09e100..47c3d7f32900 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
unsigned int vref_mv)
 {
struct ad7793_state *st = iio_priv(indio_dev);
-   int i, ret = -1;
+   int i, ret;
unsigned long long scale_uv;
u32 id;
 
@@ -266,7 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
return ret;
 
/* reset the serial interface */
-   ret = spi_write(st->sd.spi, (u8 *), sizeof(ret));
+   ret = ad_sd_reset(>sd, 32);
if (ret < 0)
goto out;
usleep_range(500, 2000); /* Wait for at least 500us */
-- 
2.11.0



[PATCH 1/2] iio: ad_sigma_delta: Implement a dedicated reset function

2017-09-05 Thread Dragos Bogdan
Since most of the SD ADCs have the option of reseting the serial
interface by sending a number of SCLKs with CS = 0 and DIN = 1,
a dedicated function that can do this is usefull.

Signed-off-by: Dragos Bogdan <dragos.bog...@analog.com>
---
 drivers/iio/adc/ad_sigma_delta.c   | 28 
 include/linux/iio/adc/ad_sigma_delta.h |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index d10bd0c97233..22c4c17cd996 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -177,6 +177,34 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
 }
 EXPORT_SYMBOL_GPL(ad_sd_read_reg);
 
+/**
+ * ad_sd_reset() - Reset the serial interface
+ *
+ * @sigma_delta: The sigma delta device
+ * @reset_length: Number of SCLKs with DIN = 1
+ *
+ * Returns 0 on success, an error code otherwise.
+ **/
+int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
+   unsigned int reset_length)
+{
+   uint8_t *buf;
+   unsigned int size;
+   int ret;
+
+   size = DIV_ROUND_UP(reset_length, 8);
+   buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   memset(buf, 0xff, size);
+   ret = spi_write(sigma_delta->spi, buf, size);
+   kfree(buf);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(ad_sd_reset);
+
 static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
unsigned int mode, unsigned int channel)
 {
diff --git a/include/linux/iio/adc/ad_sigma_delta.h 
b/include/linux/iio/adc/ad_sigma_delta.h
index 5ba430cc9a87..1fc7abd28b0b 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, 
unsigned int reg,
 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
unsigned int size, unsigned int *val);
 
+int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
+   unsigned int reset_length);
+
 int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *val);
 int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,
-- 
2.11.0



[PATCH 1/2] iio: ad_sigma_delta: Implement a dedicated reset function

2017-09-05 Thread Dragos Bogdan
Since most of the SD ADCs have the option of reseting the serial
interface by sending a number of SCLKs with CS = 0 and DIN = 1,
a dedicated function that can do this is usefull.

Signed-off-by: Dragos Bogdan 
---
 drivers/iio/adc/ad_sigma_delta.c   | 28 
 include/linux/iio/adc/ad_sigma_delta.h |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index d10bd0c97233..22c4c17cd996 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -177,6 +177,34 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
 }
 EXPORT_SYMBOL_GPL(ad_sd_read_reg);
 
+/**
+ * ad_sd_reset() - Reset the serial interface
+ *
+ * @sigma_delta: The sigma delta device
+ * @reset_length: Number of SCLKs with DIN = 1
+ *
+ * Returns 0 on success, an error code otherwise.
+ **/
+int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
+   unsigned int reset_length)
+{
+   uint8_t *buf;
+   unsigned int size;
+   int ret;
+
+   size = DIV_ROUND_UP(reset_length, 8);
+   buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   memset(buf, 0xff, size);
+   ret = spi_write(sigma_delta->spi, buf, size);
+   kfree(buf);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(ad_sd_reset);
+
 static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
unsigned int mode, unsigned int channel)
 {
diff --git a/include/linux/iio/adc/ad_sigma_delta.h 
b/include/linux/iio/adc/ad_sigma_delta.h
index 5ba430cc9a87..1fc7abd28b0b 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, 
unsigned int reg,
 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
unsigned int size, unsigned int *val);
 
+int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
+   unsigned int reset_length);
+
 int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *val);
 int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,
-- 
2.11.0



[PATCH] iio:ad7793: Fix the serial interface reset

2017-09-04 Thread Dragos Bogdan
The serial interface can be reset by writing 32 consecutive 1s to the device.
The value of 'ret' is overwritten when ad7793_check_platform_data() is called,
so it should be initialized to -1 only before doing the spi_write().

Fixes: commit 2edb769d246e ("iio:ad7793: Add support for the ad7798 and ad7799")

Signed-off-by: Dragos Bogdan <dragos.bog...@analog.com>
---
 drivers/iio/adc/ad7793.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index e6706a09e100..8680abf72dd2 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
unsigned int vref_mv)
 {
struct ad7793_state *st = iio_priv(indio_dev);
-   int i, ret = -1;
+   int i, ret;
unsigned long long scale_uv;
u32 id;
 
@@ -266,6 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
return ret;
 
/* reset the serial interface */
+   ret = -1;
ret = spi_write(st->sd.spi, (u8 *), sizeof(ret));
if (ret < 0)
goto out;
-- 
2.11.0



[PATCH] iio:ad7793: Fix the serial interface reset

2017-09-04 Thread Dragos Bogdan
The serial interface can be reset by writing 32 consecutive 1s to the device.
The value of 'ret' is overwritten when ad7793_check_platform_data() is called,
so it should be initialized to -1 only before doing the spi_write().

Fixes: commit 2edb769d246e ("iio:ad7793: Add support for the ad7798 and ad7799")

Signed-off-by: Dragos Bogdan 
---
 drivers/iio/adc/ad7793.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index e6706a09e100..8680abf72dd2 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
unsigned int vref_mv)
 {
struct ad7793_state *st = iio_priv(indio_dev);
-   int i, ret = -1;
+   int i, ret;
unsigned long long scale_uv;
u32 id;
 
@@ -266,6 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
return ret;
 
/* reset the serial interface */
+   ret = -1;
ret = spi_write(st->sd.spi, (u8 *), sizeof(ret));
if (ret < 0)
goto out;
-- 
2.11.0



[PATCH] iio: imu: adis16480: Fix acceleration scale factor for adis16480

2017-08-03 Thread Dragos Bogdan
According to the datasheet, the range of the acceleration is [-10 g, + 10 g],
so the scale factor should be 10 instead of 5.

Signed-off-by: Dragos Bogdan <dragos.bog...@analog.com>
---
 drivers/iio/imu/adis16480.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 8cf84d3488b2..12898424d838 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -696,7 +696,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_val = IIO_RAD_TO_DEGREE(22500),
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(12500),
-   .accel_max_scale = 5,
+   .accel_max_scale = 10,
},
[ADIS16485] = {
.channels = adis16485_channels,
-- 
2.11.0



[PATCH] iio: imu: adis16480: Fix acceleration scale factor for adis16480

2017-08-03 Thread Dragos Bogdan
According to the datasheet, the range of the acceleration is [-10 g, + 10 g],
so the scale factor should be 10 instead of 5.

Signed-off-by: Dragos Bogdan 
---
 drivers/iio/imu/adis16480.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 8cf84d3488b2..12898424d838 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -696,7 +696,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_val = IIO_RAD_TO_DEGREE(22500),
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(12500),
-   .accel_max_scale = 5,
+   .accel_max_scale = 10,
},
[ADIS16485] = {
.channels = adis16485_channels,
-- 
2.11.0



[PATCH v2] power: supply: ltc2941-battery-gauge: Add LTC2944 support

2017-07-11 Thread Dragos Bogdan
The only difference between the already supported LTC2943 and LTC2944 is the 
operating range (3.6V - 20V compared to 3.6V - 60V).

Signed-off-by: Dragos Bogdan <dragos.bog...@analog.com>
---
Changes in v2:
- Fix the voltage and current conversion.

 .../devicetree/bindings/power/supply/ltc2941.txt   | 10 ++---
 drivers/power/supply/ltc2941-battery-gauge.c   | 46 +-
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/Documentation/devicetree/bindings/power/supply/ltc2941.txt 
b/Documentation/devicetree/bindings/power/supply/ltc2941.txt
index a9d7aa60558b..ed0f02846d10 100644
--- a/Documentation/devicetree/bindings/power/supply/ltc2941.txt
+++ b/Documentation/devicetree/bindings/power/supply/ltc2941.txt
@@ -1,9 +1,9 @@
-binding for LTC2941 and LTC2943 battery gauges
+binding for LTC2941, LTC2943 and LTC2944 battery gauges
 
-Both the LTC2941 and LTC2943 measure battery capacity.
-The LTC2943 is compatible with the LTC2941, it adds voltage and
-temperature monitoring, and uses a slightly different conversion
-formula for the charge counter.
+All the LTC2941, LTC2943 and LTC2944 measure battery capacity.
+The LTC2943 and LTC2944 are compatible with the LTC2941, they add voltage and
+temperature monitoring, and use a slightly different conversion formula for the
+charge counter.
 
 Required properties:
 - compatible: Should contain "lltc,ltc2941" or "lltc,ltc2943" which also
diff --git a/drivers/power/supply/ltc2941-battery-gauge.c 
b/drivers/power/supply/ltc2941-battery-gauge.c
index 7efb908f4451..4c979b1a022b 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -1,5 +1,5 @@
 /*
- * I2C client/driver for the Linear Technology LTC2941 and LTC2943
+ * I2C client/driver for the Linear Technology LTC2941, LTC2943 and LTC2944
  * Battery Gas Gauge IC
  *
  * Copyright (C) 2014 Topic Embedded Systems
@@ -57,6 +57,12 @@ enum ltc294x_reg {
 #define LTC2941_NUM_REGS   0x08
 #define LTC2943_NUM_REGS   0x18
 
+enum ltc294x_id {
+   LTC2941_ID,
+   LTC2943_ID,
+   LTC2944_ID,
+};
+
 struct ltc294x_info {
struct i2c_client *client;  /* I2C Client pointer */
struct power_supply *supply;/* Supply pointer */
@@ -66,6 +72,7 @@ struct ltc294x_info {
int charge; /* Last charge register content */
int r_sense;/* mOhm */
int Qlsb;   /* nAh */
+   enum ltc294x_id id;
 };
 
 static inline int convert_bin_to_uAh(
@@ -145,7 +152,7 @@ static int ltc294x_reset(const struct ltc294x_info *info, 
int prescaler_exp)
 
control = LTC294X_REG_CONTROL_PRESCALER_SET(prescaler_exp) |
LTC294X_REG_CONTROL_ALCC_CONFIG_DISABLED;
-   /* Put the 2943 into "monitor" mode, so it measures every 10 sec */
+   /* Put the 2943/4 into "monitor" mode, so it measures every 10 sec */
if (info->num_regs == LTC2943_NUM_REGS)
control |= LTC2943_REG_CONTROL_MODE_SCAN;
 
@@ -248,11 +255,16 @@ static int ltc294x_get_voltage(const struct ltc294x_info 
*info, int *val)
int ret;
u8 datar[2];
u32 value;
+   u32 full_scale;
 
ret = ltc294x_read_regs(info->client,
LTC294X_REG_VOLTAGE_MSB, [0], 2);
value = (datar[0] << 8) | datar[1];
-   *val = ((value * 23600) / 0x) * 1000; /* in uV */
+   if (info->id == LTC2944_ID)
+   full_scale = 70800;
+   else
+   full_scale = 23600;
+   *val = ((value * full_scale) / 0x) * 1000; /* in uV */
return ret;
 }
 
@@ -261,15 +273,20 @@ static int ltc294x_get_current(const struct ltc294x_info 
*info, int *val)
int ret;
u8 datar[2];
s32 value;
+   u32 full_scale;
 
ret = ltc294x_read_regs(info->client,
LTC294X_REG_CURRENT_MSB, [0], 2);
value = (datar[0] << 8) | datar[1];
value -= 0x7FFF;
+   if (info->id == LTC2944_ID)
+   full_scale = 64000;
+   else
+   full_scale = 6;
/* Value is in range -32k..+32k, r_sense is usually 10..50 mOhm,
 * the formula below keeps everything in s32 range while preserving
 * enough digits */
-   *val = 1000 * ((6 * value) / (info->r_sense * 0x7FFF)); /* in uA */
+   *val = 1000 * ((full_scale * value) / (info->r_sense * 0x7FFF)); /* in 
uA */
return ret;
 }
 
@@ -388,7 +405,11 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
 
np = of_node_get(client->dev.of_node);
 
-   info->num_regs = (unsigned long)of_device_get_match_data(>dev);
+   info->id = (enum ltc294x_id)of_device_get_match_data(>dev);
+   if (info->id == LTC2941_ID)
+   info->num_regs = LTC2941_NUM_REGS;
+   else
+   info->num_regs = LTC2943_NUM_REGS;
info->supply_des

[PATCH v2] power: supply: ltc2941-battery-gauge: Add LTC2944 support

2017-07-11 Thread Dragos Bogdan
The only difference between the already supported LTC2943 and LTC2944 is the 
operating range (3.6V - 20V compared to 3.6V - 60V).

Signed-off-by: Dragos Bogdan 
---
Changes in v2:
- Fix the voltage and current conversion.

 .../devicetree/bindings/power/supply/ltc2941.txt   | 10 ++---
 drivers/power/supply/ltc2941-battery-gauge.c   | 46 +-
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/Documentation/devicetree/bindings/power/supply/ltc2941.txt 
b/Documentation/devicetree/bindings/power/supply/ltc2941.txt
index a9d7aa60558b..ed0f02846d10 100644
--- a/Documentation/devicetree/bindings/power/supply/ltc2941.txt
+++ b/Documentation/devicetree/bindings/power/supply/ltc2941.txt
@@ -1,9 +1,9 @@
-binding for LTC2941 and LTC2943 battery gauges
+binding for LTC2941, LTC2943 and LTC2944 battery gauges
 
-Both the LTC2941 and LTC2943 measure battery capacity.
-The LTC2943 is compatible with the LTC2941, it adds voltage and
-temperature monitoring, and uses a slightly different conversion
-formula for the charge counter.
+All the LTC2941, LTC2943 and LTC2944 measure battery capacity.
+The LTC2943 and LTC2944 are compatible with the LTC2941, they add voltage and
+temperature monitoring, and use a slightly different conversion formula for the
+charge counter.
 
 Required properties:
 - compatible: Should contain "lltc,ltc2941" or "lltc,ltc2943" which also
diff --git a/drivers/power/supply/ltc2941-battery-gauge.c 
b/drivers/power/supply/ltc2941-battery-gauge.c
index 7efb908f4451..4c979b1a022b 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -1,5 +1,5 @@
 /*
- * I2C client/driver for the Linear Technology LTC2941 and LTC2943
+ * I2C client/driver for the Linear Technology LTC2941, LTC2943 and LTC2944
  * Battery Gas Gauge IC
  *
  * Copyright (C) 2014 Topic Embedded Systems
@@ -57,6 +57,12 @@ enum ltc294x_reg {
 #define LTC2941_NUM_REGS   0x08
 #define LTC2943_NUM_REGS   0x18
 
+enum ltc294x_id {
+   LTC2941_ID,
+   LTC2943_ID,
+   LTC2944_ID,
+};
+
 struct ltc294x_info {
struct i2c_client *client;  /* I2C Client pointer */
struct power_supply *supply;/* Supply pointer */
@@ -66,6 +72,7 @@ struct ltc294x_info {
int charge; /* Last charge register content */
int r_sense;/* mOhm */
int Qlsb;   /* nAh */
+   enum ltc294x_id id;
 };
 
 static inline int convert_bin_to_uAh(
@@ -145,7 +152,7 @@ static int ltc294x_reset(const struct ltc294x_info *info, 
int prescaler_exp)
 
control = LTC294X_REG_CONTROL_PRESCALER_SET(prescaler_exp) |
LTC294X_REG_CONTROL_ALCC_CONFIG_DISABLED;
-   /* Put the 2943 into "monitor" mode, so it measures every 10 sec */
+   /* Put the 2943/4 into "monitor" mode, so it measures every 10 sec */
if (info->num_regs == LTC2943_NUM_REGS)
control |= LTC2943_REG_CONTROL_MODE_SCAN;
 
@@ -248,11 +255,16 @@ static int ltc294x_get_voltage(const struct ltc294x_info 
*info, int *val)
int ret;
u8 datar[2];
u32 value;
+   u32 full_scale;
 
ret = ltc294x_read_regs(info->client,
LTC294X_REG_VOLTAGE_MSB, [0], 2);
value = (datar[0] << 8) | datar[1];
-   *val = ((value * 23600) / 0x) * 1000; /* in uV */
+   if (info->id == LTC2944_ID)
+   full_scale = 70800;
+   else
+   full_scale = 23600;
+   *val = ((value * full_scale) / 0x) * 1000; /* in uV */
return ret;
 }
 
@@ -261,15 +273,20 @@ static int ltc294x_get_current(const struct ltc294x_info 
*info, int *val)
int ret;
u8 datar[2];
s32 value;
+   u32 full_scale;
 
ret = ltc294x_read_regs(info->client,
LTC294X_REG_CURRENT_MSB, [0], 2);
value = (datar[0] << 8) | datar[1];
value -= 0x7FFF;
+   if (info->id == LTC2944_ID)
+   full_scale = 64000;
+   else
+   full_scale = 6;
/* Value is in range -32k..+32k, r_sense is usually 10..50 mOhm,
 * the formula below keeps everything in s32 range while preserving
 * enough digits */
-   *val = 1000 * ((6 * value) / (info->r_sense * 0x7FFF)); /* in uA */
+   *val = 1000 * ((full_scale * value) / (info->r_sense * 0x7FFF)); /* in 
uA */
return ret;
 }
 
@@ -388,7 +405,11 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
 
np = of_node_get(client->dev.of_node);
 
-   info->num_regs = (unsigned long)of_device_get_match_data(>dev);
+   info->id = (enum ltc294x_id)of_device_get_match_data(>dev);
+   if (info->id == LTC2941_ID)
+   info->num_regs = LTC2941_NUM_REGS;
+   else
+   info->num_regs = LTC2943_NUM_REGS;
info->supply_desc.name = np->name;
 

[PATCH] power: supply: ltc2941-battery-gauge: Add LTC2944 support

2017-07-11 Thread Dragos Bogdan
The only difference between the already supported LTC2943 and LTC2944 is the
operating range (3.6V - 20V compared to 3.6V - 60V).

Signed-off-by: Dragos Bogdan <dragos.bog...@analog.com>
---
 Documentation/devicetree/bindings/power/supply/ltc2941.txt | 10 +-
 drivers/power/supply/ltc2941-battery-gauge.c   | 11 ---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/Documentation/devicetree/bindings/power/supply/ltc2941.txt 
b/Documentation/devicetree/bindings/power/supply/ltc2941.txt
index a9d7aa60558b..ed0f02846d10 100644
--- a/Documentation/devicetree/bindings/power/supply/ltc2941.txt
+++ b/Documentation/devicetree/bindings/power/supply/ltc2941.txt
@@ -1,9 +1,9 @@
-binding for LTC2941 and LTC2943 battery gauges
+binding for LTC2941, LTC2943 and LTC2944 battery gauges
 
-Both the LTC2941 and LTC2943 measure battery capacity.
-The LTC2943 is compatible with the LTC2941, it adds voltage and
-temperature monitoring, and uses a slightly different conversion
-formula for the charge counter.
+All the LTC2941, LTC2943 and LTC2944 measure battery capacity.
+The LTC2943 and LTC2944 are compatible with the LTC2941, they add voltage and
+temperature monitoring, and use a slightly different conversion formula for the
+charge counter.
 
 Required properties:
 - compatible: Should contain "lltc,ltc2941" or "lltc,ltc2943" which also
diff --git a/drivers/power/supply/ltc2941-battery-gauge.c 
b/drivers/power/supply/ltc2941-battery-gauge.c
index 7efb908f4451..48af7b6fb704 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -1,5 +1,5 @@
 /*
- * I2C client/driver for the Linear Technology LTC2941 and LTC2943
+ * I2C client/driver for the Linear Technology LTC2941, LTC2943 and LTC2944
  * Battery Gas Gauge IC
  *
  * Copyright (C) 2014 Topic Embedded Systems
@@ -145,7 +145,7 @@ static int ltc294x_reset(const struct ltc294x_info *info, 
int prescaler_exp)
 
control = LTC294X_REG_CONTROL_PRESCALER_SET(prescaler_exp) |
LTC294X_REG_CONTROL_ALCC_CONFIG_DISABLED;
-   /* Put the 2943 into "monitor" mode, so it measures every 10 sec */
+   /* Put the 2943/4 into "monitor" mode, so it measures every 10 sec */
if (info->num_regs == LTC2943_NUM_REGS)
control |= LTC2943_REG_CONTROL_MODE_SCAN;
 
@@ -494,6 +494,7 @@ static SIMPLE_DEV_PM_OPS(ltc294x_pm_ops, ltc294x_suspend, 
ltc294x_resume);
 static const struct i2c_device_id ltc294x_i2c_id[] = {
{"ltc2941", LTC2941_NUM_REGS},
{"ltc2943", LTC2943_NUM_REGS},
+   {"ltc2944", LTC2943_NUM_REGS},
{ },
 };
 MODULE_DEVICE_TABLE(i2c, ltc294x_i2c_id);
@@ -507,6 +508,10 @@ static const struct of_device_id ltc294x_i2c_of_match[] = {
.compatible = "lltc,ltc2943",
.data = (void *)LTC2943_NUM_REGS
},
+   {
+   .compatible = "lltc,ltc2944",
+   .data = (void *)LTC2943_NUM_REGS
+   },
{ },
 };
 MODULE_DEVICE_TABLE(of, ltc294x_i2c_of_match);
@@ -525,5 +530,5 @@ module_i2c_driver(ltc294x_driver);
 
 MODULE_AUTHOR("Auryn Verwegen, Topic Embedded Systems");
 MODULE_AUTHOR("Mike Looijmans, Topic Embedded Products");
-MODULE_DESCRIPTION("LTC2941/LTC2943 Battery Gas Gauge IC driver");
+MODULE_DESCRIPTION("LTC2941/LTC2943/LTC2944 Battery Gas Gauge IC driver");
 MODULE_LICENSE("GPL");
-- 
2.11.0



[PATCH] power: supply: ltc2941-battery-gauge: Add LTC2944 support

2017-07-11 Thread Dragos Bogdan
The only difference between the already supported LTC2943 and LTC2944 is the
operating range (3.6V - 20V compared to 3.6V - 60V).

Signed-off-by: Dragos Bogdan 
---
 Documentation/devicetree/bindings/power/supply/ltc2941.txt | 10 +-
 drivers/power/supply/ltc2941-battery-gauge.c   | 11 ---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/Documentation/devicetree/bindings/power/supply/ltc2941.txt 
b/Documentation/devicetree/bindings/power/supply/ltc2941.txt
index a9d7aa60558b..ed0f02846d10 100644
--- a/Documentation/devicetree/bindings/power/supply/ltc2941.txt
+++ b/Documentation/devicetree/bindings/power/supply/ltc2941.txt
@@ -1,9 +1,9 @@
-binding for LTC2941 and LTC2943 battery gauges
+binding for LTC2941, LTC2943 and LTC2944 battery gauges
 
-Both the LTC2941 and LTC2943 measure battery capacity.
-The LTC2943 is compatible with the LTC2941, it adds voltage and
-temperature monitoring, and uses a slightly different conversion
-formula for the charge counter.
+All the LTC2941, LTC2943 and LTC2944 measure battery capacity.
+The LTC2943 and LTC2944 are compatible with the LTC2941, they add voltage and
+temperature monitoring, and use a slightly different conversion formula for the
+charge counter.
 
 Required properties:
 - compatible: Should contain "lltc,ltc2941" or "lltc,ltc2943" which also
diff --git a/drivers/power/supply/ltc2941-battery-gauge.c 
b/drivers/power/supply/ltc2941-battery-gauge.c
index 7efb908f4451..48af7b6fb704 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -1,5 +1,5 @@
 /*
- * I2C client/driver for the Linear Technology LTC2941 and LTC2943
+ * I2C client/driver for the Linear Technology LTC2941, LTC2943 and LTC2944
  * Battery Gas Gauge IC
  *
  * Copyright (C) 2014 Topic Embedded Systems
@@ -145,7 +145,7 @@ static int ltc294x_reset(const struct ltc294x_info *info, 
int prescaler_exp)
 
control = LTC294X_REG_CONTROL_PRESCALER_SET(prescaler_exp) |
LTC294X_REG_CONTROL_ALCC_CONFIG_DISABLED;
-   /* Put the 2943 into "monitor" mode, so it measures every 10 sec */
+   /* Put the 2943/4 into "monitor" mode, so it measures every 10 sec */
if (info->num_regs == LTC2943_NUM_REGS)
control |= LTC2943_REG_CONTROL_MODE_SCAN;
 
@@ -494,6 +494,7 @@ static SIMPLE_DEV_PM_OPS(ltc294x_pm_ops, ltc294x_suspend, 
ltc294x_resume);
 static const struct i2c_device_id ltc294x_i2c_id[] = {
{"ltc2941", LTC2941_NUM_REGS},
{"ltc2943", LTC2943_NUM_REGS},
+   {"ltc2944", LTC2943_NUM_REGS},
{ },
 };
 MODULE_DEVICE_TABLE(i2c, ltc294x_i2c_id);
@@ -507,6 +508,10 @@ static const struct of_device_id ltc294x_i2c_of_match[] = {
.compatible = "lltc,ltc2943",
.data = (void *)LTC2943_NUM_REGS
},
+   {
+   .compatible = "lltc,ltc2944",
+   .data = (void *)LTC2943_NUM_REGS
+   },
{ },
 };
 MODULE_DEVICE_TABLE(of, ltc294x_i2c_of_match);
@@ -525,5 +530,5 @@ module_i2c_driver(ltc294x_driver);
 
 MODULE_AUTHOR("Auryn Verwegen, Topic Embedded Systems");
 MODULE_AUTHOR("Mike Looijmans, Topic Embedded Products");
-MODULE_DESCRIPTION("LTC2941/LTC2943 Battery Gas Gauge IC driver");
+MODULE_DESCRIPTION("LTC2941/LTC2943/LTC2944 Battery Gas Gauge IC driver");
 MODULE_LICENSE("GPL");
-- 
2.11.0