linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] cpcap battery simplification and calibrate support
@ 2019-10-09 21:06 Tony Lindgren
  2019-10-09 21:06 ` [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata Tony Lindgren
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Tony Lindgren @ 2019-10-09 21:06 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

Hi,

This set of changes simplifies the coulomb counter code for cpcap-battery.
And the last patch in the series add support for coulomb counter calibration
on probe.

Regards,

Tony

Tony Lindgren (5):
  power: supply: cpcap-battery: Move coulomb counter units per lsb to
    ddata
  power: supply: cpcap-battery: Simplify coulomb counter calculation
    with div_s64
  power: supply: cpcap-battery: Simplify short term power average
    calculation
  power: supply: cpcap-battery: Read and save integrator register CCI
  power: supply: cpcap-battery: Add basic coulomb counter calibrate
    support

 drivers/power/supply/cpcap-battery.c | 178 +++++++++++++++++++--------
 1 file changed, 125 insertions(+), 53 deletions(-)

-- 
2.23.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata
  2019-10-09 21:06 [PATCH 0/5] cpcap battery simplification and calibrate support Tony Lindgren
@ 2019-10-09 21:06 ` Tony Lindgren
  2019-10-13 10:55   ` Pavel Machek
  2019-10-13 11:35   ` Pavel Machek
  2019-10-09 21:06 ` [PATCH 2/5] power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64 Tony Lindgren
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 16+ messages in thread
From: Tony Lindgren @ 2019-10-09 21:06 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

We can simplify cpcap_battery_cc_raw_div() a bit by moving the units per
lsb to ddata.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-battery.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -111,6 +111,7 @@ struct cpcap_battery_ddata {
 	struct power_supply *psy;
 	struct cpcap_battery_config config;
 	struct cpcap_battery_state_data state[CPCAP_BATTERY_STATE_NR];
+	u32 cc_lsb;		/* μAms per LSB */
 	atomic_t active;
 	int status;
 	u16 vendor;
@@ -220,32 +221,19 @@ static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata,
 	s64 acc;
 	u64 tmp;
 	int avg_current;
-	u32 cc_lsb;
 
 	if (!divider)
 		return 0;
 
-	switch (ddata->vendor) {
-	case CPCAP_VENDOR_ST:
-		cc_lsb = 95374;		/* μAms per LSB */
-		break;
-	case CPCAP_VENDOR_TI:
-		cc_lsb = 91501;		/* μAms per LSB */
-		break;
-	default:
-		return -EINVAL;
-	}
-
 	acc = accumulator;
 	acc = acc - ((s64)sample * offset);
-	cc_lsb = (cc_lsb * ddata->config.cd_factor) / 1000;
 
 	if (acc >=  0)
 		tmp = acc;
 	else
 		tmp = acc * -1;
 
-	tmp = tmp * cc_lsb;
+	tmp = tmp * ddata->cc_lsb;
 	do_div(tmp, divider);
 	avg_current = tmp;
 
@@ -814,6 +802,18 @@ static int cpcap_battery_probe(struct platform_device *pdev)
 	if (error)
 		return error;
 
+	switch (ddata->vendor) {
+	case CPCAP_VENDOR_ST:
+		ddata->cc_lsb = 95374;	/* μAms per LSB */
+		break;
+	case CPCAP_VENDOR_TI:
+		ddata->cc_lsb = 91501;	/* μAms per LSB */
+		break;
+	default:
+		return -EINVAL;
+	}
+	ddata->cc_lsb = (ddata->cc_lsb * ddata->config.cd_factor) / 1000;
+
 	platform_set_drvdata(pdev, ddata);
 
 	error = regmap_update_bits(ddata->reg, CPCAP_REG_CCM,
-- 
2.23.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/5] power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64
  2019-10-09 21:06 [PATCH 0/5] cpcap battery simplification and calibrate support Tony Lindgren
  2019-10-09 21:06 ` [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata Tony Lindgren
@ 2019-10-09 21:06 ` Tony Lindgren
  2019-10-13 11:01   ` Pavel Machek
  2019-10-13 11:36   ` Pavel Machek
  2019-10-09 21:06 ` [PATCH 3/5] power: supply: cpcap-battery: Simplify short term power average calculation Tony Lindgren
                   ` (4 subsequent siblings)
  6 siblings, 2 replies; 16+ messages in thread
From: Tony Lindgren @ 2019-10-09 21:06 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

We can simplify cpcap_battery_cc_raw_div() with div_s64.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-battery.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -33,8 +33,6 @@
 #include <linux/iio/types.h>
 #include <linux/mfd/motorola-cpcap.h>
 
-#include <asm/div64.h>
-
 /*
  * Register bit defines for CPCAP_REG_BPEOL. Some of these seem to
  * map to MC13783UG.pdf "Table 5-19. Register 13, Power Control 0"
@@ -219,28 +217,17 @@ static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata,
 				    s16 offset, u32 divider)
 {
 	s64 acc;
-	u64 tmp;
-	int avg_current;
 
 	if (!divider)
 		return 0;
 
 	acc = accumulator;
-	acc = acc - ((s64)sample * offset);
-
-	if (acc >=  0)
-		tmp = acc;
-	else
-		tmp = acc * -1;
+	acc -= (s64)sample * offset;
+	acc *= ddata->cc_lsb;
+	acc *= -1;
+	acc = div_s64(acc, divider);
 
-	tmp = tmp * ddata->cc_lsb;
-	do_div(tmp, divider);
-	avg_current = tmp;
-
-	if (acc >= 0)
-		return -avg_current;
-	else
-		return avg_current;
+	return acc;
 }
 
 /* 3600000μAms = 1μAh */
-- 
2.23.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 3/5] power: supply: cpcap-battery: Simplify short term power average calculation
  2019-10-09 21:06 [PATCH 0/5] cpcap battery simplification and calibrate support Tony Lindgren
  2019-10-09 21:06 ` [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata Tony Lindgren
  2019-10-09 21:06 ` [PATCH 2/5] power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64 Tony Lindgren
@ 2019-10-09 21:06 ` Tony Lindgren
  2019-10-13 11:42   ` Pavel Machek
  2019-10-13 11:42   ` Pavel Machek
  2019-10-09 21:06 ` [PATCH 4/5] power: supply: cpcap-battery: Read and save integrator register CCI Tony Lindgren
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 16+ messages in thread
From: Tony Lindgren @ 2019-10-09 21:06 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

We can use sign_extend32() here to simplify things. And let's fix the
comment for CCM register, that contains the calibration offset.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-battery.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -312,31 +312,28 @@ cpcap_battery_read_accumulated(struct cpcap_battery_ddata *ddata,
 static int cpcap_battery_cc_get_avg_current(struct cpcap_battery_ddata *ddata)
 {
 	int value, acc, error;
-	s32 sample = 1;
+	s32 sample;
 	s16 offset;
 
-	if (ddata->vendor == CPCAP_VENDOR_ST)
-		sample = 4;
-
 	/* Coulomb counter integrator */
 	error = regmap_read(ddata->reg, CPCAP_REG_CCI, &value);
 	if (error)
 		return error;
 
-	if ((ddata->vendor == CPCAP_VENDOR_TI) && (value > 0x2000))
-		value = value | 0xc000;
-
-	acc = (s16)value;
+	if (ddata->vendor == CPCAP_VENDOR_TI) {
+		acc = sign_extend32(value, 13);
+		sample = 1;
+	} else {
+		acc = (s16)value;
+		sample = 4;
+	}
 
-	/* Coulomb counter sample time */
+	/* Coulomb counter calibration offset  */
 	error = regmap_read(ddata->reg, CPCAP_REG_CCM, &value);
 	if (error)
 		return error;
 
-	if (value < 0x200)
-		offset = value;
-	else
-		offset = value | 0xfc00;
+	offset = sign_extend32(value, 9);
 
 	return cpcap_battery_cc_to_ua(ddata, sample, acc, offset);
 }
-- 
2.23.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 4/5] power: supply: cpcap-battery: Read and save integrator register CCI
  2019-10-09 21:06 [PATCH 0/5] cpcap battery simplification and calibrate support Tony Lindgren
                   ` (2 preceding siblings ...)
  2019-10-09 21:06 ` [PATCH 3/5] power: supply: cpcap-battery: Simplify short term power average calculation Tony Lindgren
@ 2019-10-09 21:06 ` Tony Lindgren
  2019-10-09 21:06 ` [PATCH 5/5] power: supply: cpcap-battery: Add basic coulomb counter calibrate support Tony Lindgren
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Tony Lindgren @ 2019-10-09 21:06 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

We can simplify code in the later patches by reading and saving the
integrator register CCI. Let's also fix a comment typo for register range
naming while at it.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-battery.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -84,6 +84,7 @@ struct cpcap_coulomb_counter_data {
 	s32 sample;		/* 24 or 32 bits */
 	s32 accumulator;
 	s16 offset;		/* 9 bits */
+	s16 integrator;		/* 13 or 16 bits */
 };
 
 enum cpcap_battery_state {
@@ -269,12 +270,13 @@ static int
 cpcap_battery_read_accumulated(struct cpcap_battery_ddata *ddata,
 			       struct cpcap_coulomb_counter_data *ccd)
 {
-	u16 buf[7];	/* CPCAP_REG_CC1 to CCI */
+	u16 buf[7];	/* CPCAP_REG_CCS1 to CCI */
 	int error;
 
 	ccd->sample = 0;
 	ccd->accumulator = 0;
 	ccd->offset = 0;
+	ccd->integrator = 0;
 
 	/* Read coulomb counter register range */
 	error = regmap_bulk_read(ddata->reg, CPCAP_REG_CCS1,
@@ -299,6 +301,12 @@ cpcap_battery_read_accumulated(struct cpcap_battery_ddata *ddata,
 	ccd->offset = buf[4];
 	ccd->offset = sign_extend32(ccd->offset, 9);
 
+	/* Integrator register CPCAP_REG_CCI */
+	if (ddata->vendor == CPCAP_VENDOR_TI)
+		ccd->integrator = sign_extend32(buf[6], 13);
+	else
+		ccd->integrator = (s16)buf[6];
+
 	return cpcap_battery_cc_to_uah(ddata,
 				       ccd->sample,
 				       ccd->accumulator,
-- 
2.23.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 5/5] power: supply: cpcap-battery: Add basic coulomb counter calibrate support
  2019-10-09 21:06 [PATCH 0/5] cpcap battery simplification and calibrate support Tony Lindgren
                   ` (3 preceding siblings ...)
  2019-10-09 21:06 ` [PATCH 4/5] power: supply: cpcap-battery: Read and save integrator register CCI Tony Lindgren
@ 2019-10-09 21:06 ` Tony Lindgren
  2019-10-13 11:26   ` Pavel Machek
  2019-10-16 22:45 ` [PATCH 0/5] cpcap battery simplification and " Tony Lindgren
  2019-10-20 20:36 ` Sebastian Reichel
  6 siblings, 1 reply; 16+ messages in thread
From: Tony Lindgren @ 2019-10-09 21:06 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

This patch adds support for the coulomb counter calibration on init. We do
this by polling for now, and only add partial calibration done interrupt
support.

Then later on when we know for sure we have the calibration done interrupt
available in the device tree, we can switch to using the calibration done
interrupt.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-battery.c | 96 +++++++++++++++++++++++++---
 1 file changed, 88 insertions(+), 8 deletions(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -50,6 +50,26 @@
 #define CPCAP_REG_BPEOL_BIT_BATTDETEN	BIT(1)	/* Enable battery detect */
 #define CPCAP_REG_BPEOL_BIT_EOLSEL	BIT(0)	/* BPDET = 0, EOL = 1 */
 
+/*
+ * Register bit defines for CPCAP_REG_CCC1. These seem similar to the twl6030
+ * coulomb counter registers rather than the mc13892 registers. Both twl6030
+ * and mc13892 set bits 2 and 1 to reset and clear registers. But mc13892
+ * sets bit 0 to start the coulomb counter while twl6030 sets bit 0 to stop
+ * the coulomb counter like cpcap does. So for now, we use the twl6030 style
+ * naming for the registers.
+ */
+#define CPCAP_REG_CCC1_ACTIVE_MODE1	BIT(4)	/* Update rate */
+#define CPCAP_REG_CCC1_ACTIVE_MODE0	BIT(3)	/* Update rate */
+#define CPCAP_REG_CCC1_AUTOCLEAR	BIT(2)	/* Resets sample registers */
+#define CPCAP_REG_CCC1_CAL_EN		BIT(1)	/* Clears after write in 1s */
+#define CPCAP_REG_CCC1_PAUSE		BIT(0)	/* Stop counters, allow write */
+#define CPCAP_REG_CCC1_RESET_MASK	(CPCAP_REG_CCC1_AUTOCLEAR | \
+					 CPCAP_REG_CCC1_CAL_EN)
+
+#define CPCAP_REG_CCCC2_RATE1		BIT(5)
+#define CPCAP_REG_CCCC2_RATE0		BIT(4)
+#define CPCAP_REG_CCCC2_ENABLE		BIT(3)
+
 #define CPCAP_BATTERY_CC_SAMPLE_PERIOD_MS	250
 
 enum {
@@ -62,6 +82,7 @@ enum {
 
 enum cpcap_battery_irq_action {
 	CPCAP_BATTERY_IRQ_ACTION_NONE,
+	CPCAP_BATTERY_IRQ_ACTION_CC_CAL_DONE,
 	CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW,
 	CPCAP_BATTERY_IRQ_ACTION_POWEROFF,
 };
@@ -74,7 +95,6 @@ struct cpcap_interrupt_desc {
 };
 
 struct cpcap_battery_config {
-	int ccm;
 	int cd_factor;
 	struct power_supply_info info;
 	struct power_supply_battery_info bat;
@@ -609,6 +629,9 @@ static irqreturn_t cpcap_battery_irq_thread(int irq, void *data)
 	latest = cpcap_battery_latest(ddata);
 
 	switch (d->action) {
+	case CPCAP_BATTERY_IRQ_ACTION_CC_CAL_DONE:
+		dev_info(ddata->dev, "Coulomb counter calibration done\n");
+		break;
 	case CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW:
 		if (latest->current_ua >= 0)
 			dev_warn(ddata->dev, "Battery low at %imV!\n",
@@ -661,7 +684,9 @@ static int cpcap_battery_init_irq(struct platform_device *pdev,
 	d->name = name;
 	d->irq = irq;
 
-	if (!strncmp(name, "lowbph", 6))
+	if (!strncmp(name, "cccal", 5))
+		d->action = CPCAP_BATTERY_IRQ_ACTION_CC_CAL_DONE;
+	else if (!strncmp(name, "lowbph", 6))
 		d->action = CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW;
 	else if (!strncmp(name, "lowbpl", 6))
 		d->action = CPCAP_BATTERY_IRQ_ACTION_POWEROFF;
@@ -687,6 +712,9 @@ static int cpcap_battery_init_interrupts(struct platform_device *pdev,
 			return error;
 	}
 
+	/* Enable calibration interrupt if already available in dts */
+	cpcap_battery_init_irq(pdev, ddata, "cccal");
+
 	/* Enable low battery interrupts for 3.3V high and 3.1V low */
 	error = regmap_update_bits(ddata->reg, CPCAP_REG_BPEOL,
 				   0xffff,
@@ -728,6 +756,60 @@ static int cpcap_battery_init_iio(struct cpcap_battery_ddata *ddata)
 	return error;
 }
 
+/* Calibrate coulomb counter */
+static int cpcap_battery_calibrate(struct cpcap_battery_ddata *ddata)
+{
+	int error, ccc1, value;
+	unsigned long timeout;
+
+	error = regmap_read(ddata->reg, CPCAP_REG_CCC1, &ccc1);
+	if (error)
+		return error;
+
+	timeout = jiffies + msecs_to_jiffies(6000);
+
+	/* Start calibration */
+	error = regmap_update_bits(ddata->reg, CPCAP_REG_CCC1,
+				   0xffff,
+				   CPCAP_REG_CCC1_CAL_EN);
+	if (error)
+		goto restore;
+
+	while (time_before(jiffies, timeout)) {
+		error = regmap_read(ddata->reg, CPCAP_REG_CCC1, &value);
+		if (error)
+			goto restore;
+
+		if (!(value & CPCAP_REG_CCC1_CAL_EN))
+			break;
+
+		error = regmap_read(ddata->reg, CPCAP_REG_CCM, &value);
+		if (error)
+			goto restore;
+
+		msleep(300);
+	}
+
+	/* Read calibration offset from CCM */
+	error = regmap_read(ddata->reg, CPCAP_REG_CCM, &value);
+	if (error)
+		goto restore;
+
+	dev_info(ddata->dev, "calibration done: 0x%04x\n", value);
+
+restore:
+	if (error)
+		dev_err(ddata->dev, "%s: error %i\n", __func__, error);
+
+	error = regmap_update_bits(ddata->reg, CPCAP_REG_CCC1,
+				   0xffff, ccc1);
+	if (error)
+		dev_err(ddata->dev, "%s: restore error %i\n",
+			__func__, error);
+
+	return error;
+}
+
 /*
  * Based on the values from Motorola mapphone Linux kernel. In the
  * the Motorola mapphone Linux kernel tree the value for pm_cd_factor
@@ -739,7 +821,6 @@ static int cpcap_battery_init_iio(struct cpcap_battery_ddata *ddata)
  * at 3078000. The device will die around 2743000.
  */
 static const struct cpcap_battery_config cpcap_battery_default_data = {
-	.ccm = 0x3ff,
 	.cd_factor = 0x3cc,
 	.info.technology = POWER_SUPPLY_TECHNOLOGY_LION,
 	.info.voltage_max_design = 4351000,
@@ -808,11 +889,6 @@ static int cpcap_battery_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, ddata);
 
-	error = regmap_update_bits(ddata->reg, CPCAP_REG_CCM,
-				   0xffff, ddata->config.ccm);
-	if (error)
-		return error;
-
 	error = cpcap_battery_init_interrupts(pdev, ddata);
 	if (error)
 		return error;
@@ -846,6 +922,10 @@ static int cpcap_battery_probe(struct platform_device *pdev)
 
 	atomic_set(&ddata->active, 1);
 
+	error = cpcap_battery_calibrate(ddata);
+	if (error)
+		return error;
+
 	return 0;
 }
 
-- 
2.23.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata
  2019-10-09 21:06 ` [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata Tony Lindgren
@ 2019-10-13 10:55   ` Pavel Machek
  2019-10-16 22:01     ` Tony Lindgren
  2019-10-13 11:35   ` Pavel Machek
  1 sibling, 1 reply; 16+ messages in thread
From: Pavel Machek @ 2019-10-13 10:55 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

On Wed 2019-10-09 14:06:17, Tony Lindgren wrote:
> We can simplify cpcap_battery_cc_raw_div() a bit by moving the units per
> lsb to ddata.
> 
> Cc: Merlijn Wajer <merlijn@wizzup.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Signed-off-by: Tony Lindgren <tony@atomide.com>
> ---
>  drivers/power/supply/cpcap-battery.c | 28 ++++++++++++++--------------
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
> --- a/drivers/power/supply/cpcap-battery.c
> +++ b/drivers/power/supply/cpcap-battery.c
> @@ -111,6 +111,7 @@ struct cpcap_battery_ddata {
>  	struct power_supply *psy;
>  	struct cpcap_battery_config config;
>  	struct cpcap_battery_state_data state[CPCAP_BATTERY_STATE_NR];
> +	u32 cc_lsb;		/* μAms per LSB */

micro-Ampere-seconds? Should be uAs?

									Pavel


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/5] power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64
  2019-10-09 21:06 ` [PATCH 2/5] power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64 Tony Lindgren
@ 2019-10-13 11:01   ` Pavel Machek
  2019-10-13 11:36   ` Pavel Machek
  1 sibling, 0 replies; 16+ messages in thread
From: Pavel Machek @ 2019-10-13 11:01 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

On Wed 2019-10-09 14:06:18, Tony Lindgren wrote:
> We can simplify cpcap_battery_cc_raw_div() with div_s64.
> 
> Cc: Merlijn Wajer <merlijn@wizzup.org>
> Cc: Pavel Machek <pavel@ucw.cz>

Acked-by: Pavel Machek <pavel@ucw.cz>

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/5] power: supply: cpcap-battery: Add basic coulomb counter calibrate support
  2019-10-09 21:06 ` [PATCH 5/5] power: supply: cpcap-battery: Add basic coulomb counter calibrate support Tony Lindgren
@ 2019-10-13 11:26   ` Pavel Machek
  0 siblings, 0 replies; 16+ messages in thread
From: Pavel Machek @ 2019-10-13 11:26 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

[-- Attachment #1: Type: text/plain, Size: 708 bytes --]

On Wed 2019-10-09 14:06:21, Tony Lindgren wrote:
> This patch adds support for the coulomb counter calibration on init. We do
> this by polling for now, and only add partial calibration done interrupt
> support.
> 
> Then later on when we know for sure we have the calibration done interrupt
> available in the device tree, we can switch to using the calibration done
> interrupt.
> 
> Cc: Merlijn Wajer <merlijn@wizzup.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Signed-off-by: Tony Lindgren <tony@atomide.com>

4,5: Acked-by: Pavel Machek <pavel@ucw.cz>

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata
  2019-10-09 21:06 ` [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata Tony Lindgren
  2019-10-13 10:55   ` Pavel Machek
@ 2019-10-13 11:35   ` Pavel Machek
  1 sibling, 0 replies; 16+ messages in thread
From: Pavel Machek @ 2019-10-13 11:35 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

[-- Attachment #1: Type: text/plain, Size: 371 bytes --]

On Wed 2019-10-09 14:06:17, Tony Lindgren wrote:
> We can simplify cpcap_battery_cc_raw_div() a bit by moving the units per
> lsb to ddata.
> 
> Cc: Merlijn Wajer <merlijn@wizzup.org>

Acked-by: Pavel Machek <pavel@ucw.cz>

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/5] power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64
  2019-10-09 21:06 ` [PATCH 2/5] power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64 Tony Lindgren
  2019-10-13 11:01   ` Pavel Machek
@ 2019-10-13 11:36   ` Pavel Machek
  1 sibling, 0 replies; 16+ messages in thread
From: Pavel Machek @ 2019-10-13 11:36 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

On Wed 2019-10-09 14:06:18, Tony Lindgren wrote:
> We can simplify cpcap_battery_cc_raw_div() with div_s64.
> 
> Cc: Merlijn Wajer <merlijn@wizzup.org>
> Cc: Pavel Machek <pavel@ucw.cz>

Acked-by: Pavel Machek <pavel@ucw.cz>

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/5] power: supply: cpcap-battery: Simplify short term power average calculation
  2019-10-09 21:06 ` [PATCH 3/5] power: supply: cpcap-battery: Simplify short term power average calculation Tony Lindgren
@ 2019-10-13 11:42   ` Pavel Machek
  2019-10-13 11:42   ` Pavel Machek
  1 sibling, 0 replies; 16+ messages in thread
From: Pavel Machek @ 2019-10-13 11:42 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

On Wed 2019-10-09 14:06:19, Tony Lindgren wrote:
> We can use sign_extend32() here to simplify things. And let's fix the
> comment for CCM register, that contains the calibration offset.
> 
> Cc: Merlijn Wajer <merlijn@wizzup.org>
> Cc: Pavel Machek <pavel@ucw.cz>

Acked-by: Pavel Machek <pavel@ucw.cz>

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/5] power: supply: cpcap-battery: Simplify short term power average calculation
  2019-10-09 21:06 ` [PATCH 3/5] power: supply: cpcap-battery: Simplify short term power average calculation Tony Lindgren
  2019-10-13 11:42   ` Pavel Machek
@ 2019-10-13 11:42   ` Pavel Machek
  1 sibling, 0 replies; 16+ messages in thread
From: Pavel Machek @ 2019-10-13 11:42 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

On Wed 2019-10-09 14:06:19, Tony Lindgren wrote:
> We can use sign_extend32() here to simplify things. And let's fix the
> comment for CCM register, that contains the calibration offset.
> 
> Cc: Merlijn Wajer <merlijn@wizzup.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Signed-off-by: Tony Lindgren <tony@atomide.com>

Acked-by: Pavel Machek <pavel@ucw.cz>


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata
  2019-10-13 10:55   ` Pavel Machek
@ 2019-10-16 22:01     ` Tony Lindgren
  0 siblings, 0 replies; 16+ messages in thread
From: Tony Lindgren @ 2019-10-16 22:01 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

* Pavel Machek <pavel@ucw.cz> [191013 10:56]:
> On Wed 2019-10-09 14:06:17, Tony Lindgren wrote:
> > We can simplify cpcap_battery_cc_raw_div() a bit by moving the units per
> > lsb to ddata.
> > 
> > Cc: Merlijn Wajer <merlijn@wizzup.org>
> > Cc: Pavel Machek <pavel@ucw.cz>
> > Signed-off-by: Tony Lindgren <tony@atomide.com>
> > ---
> >  drivers/power/supply/cpcap-battery.c | 28 ++++++++++++++--------------
> >  1 file changed, 14 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
> > --- a/drivers/power/supply/cpcap-battery.c
> > +++ b/drivers/power/supply/cpcap-battery.c
> > @@ -111,6 +111,7 @@ struct cpcap_battery_ddata {
> >  	struct power_supply *psy;
> >  	struct cpcap_battery_config config;
> >  	struct cpcap_battery_state_data state[CPCAP_BATTERY_STATE_NR];
> > +	u32 cc_lsb;		/* μAms per LSB */
> 
> micro-Ampere-seconds? Should be uAs?

That's micro-Ampere-milliseconds per LSB here.

Regards,

Tony

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] cpcap battery simplification and calibrate support
  2019-10-09 21:06 [PATCH 0/5] cpcap battery simplification and calibrate support Tony Lindgren
                   ` (4 preceding siblings ...)
  2019-10-09 21:06 ` [PATCH 5/5] power: supply: cpcap-battery: Add basic coulomb counter calibrate support Tony Lindgren
@ 2019-10-16 22:45 ` Tony Lindgren
  2019-10-20 20:36 ` Sebastian Reichel
  6 siblings, 0 replies; 16+ messages in thread
From: Tony Lindgren @ 2019-10-16 22:45 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

* Tony Lindgren <tony@atomide.com> [191009 21:07]:
> This set of changes simplifies the coulomb counter code for cpcap-battery.
> And the last patch in the series add support for coulomb counter calibration
> on probe.

Sebastian, if no other comments, let me know if you need a
resend of this set too with Pavel's acks collected.

Regards,

Tony

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] cpcap battery simplification and calibrate support
  2019-10-09 21:06 [PATCH 0/5] cpcap battery simplification and calibrate support Tony Lindgren
                   ` (5 preceding siblings ...)
  2019-10-16 22:45 ` [PATCH 0/5] cpcap battery simplification and " Tony Lindgren
@ 2019-10-20 20:36 ` Sebastian Reichel
  6 siblings, 0 replies; 16+ messages in thread
From: Sebastian Reichel @ 2019-10-20 20:36 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

[-- Attachment #1: Type: text/plain, Size: 901 bytes --]

Hi,

On Wed, Oct 09, 2019 at 02:06:16PM -0700, Tony Lindgren wrote:
> Hi,
> 
> This set of changes simplifies the coulomb counter code for cpcap-battery.
> And the last patch in the series add support for coulomb counter calibration
> on probe.
> 
> Regards,
> 
> Tony
> 
> Tony Lindgren (5):
>   power: supply: cpcap-battery: Move coulomb counter units per lsb to
>     ddata
>   power: supply: cpcap-battery: Simplify coulomb counter calculation
>     with div_s64
>   power: supply: cpcap-battery: Simplify short term power average
>     calculation
>   power: supply: cpcap-battery: Read and save integrator register CCI
>   power: supply: cpcap-battery: Add basic coulomb counter calibrate
>     support
> 
>  drivers/power/supply/cpcap-battery.c | 178 +++++++++++++++++++--------
>  1 file changed, 125 insertions(+), 53 deletions(-)

Thanks, queued.

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-10-20 20:36 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09 21:06 [PATCH 0/5] cpcap battery simplification and calibrate support Tony Lindgren
2019-10-09 21:06 ` [PATCH 1/5] power: supply: cpcap-battery: Move coulomb counter units per lsb to ddata Tony Lindgren
2019-10-13 10:55   ` Pavel Machek
2019-10-16 22:01     ` Tony Lindgren
2019-10-13 11:35   ` Pavel Machek
2019-10-09 21:06 ` [PATCH 2/5] power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64 Tony Lindgren
2019-10-13 11:01   ` Pavel Machek
2019-10-13 11:36   ` Pavel Machek
2019-10-09 21:06 ` [PATCH 3/5] power: supply: cpcap-battery: Simplify short term power average calculation Tony Lindgren
2019-10-13 11:42   ` Pavel Machek
2019-10-13 11:42   ` Pavel Machek
2019-10-09 21:06 ` [PATCH 4/5] power: supply: cpcap-battery: Read and save integrator register CCI Tony Lindgren
2019-10-09 21:06 ` [PATCH 5/5] power: supply: cpcap-battery: Add basic coulomb counter calibrate support Tony Lindgren
2019-10-13 11:26   ` Pavel Machek
2019-10-16 22:45 ` [PATCH 0/5] cpcap battery simplification and " Tony Lindgren
2019-10-20 20:36 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).