Skip to contentSkip to conversation

BQ24190 charger fixes

PATCH Superseded Liam Breck 2 participants 21 messages Apr 6, 2017 – Apr 10, 2017 Power supply

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Liam Breck

author
#0 lore raw

v4 cover BQ24190 charger fixes

Hi Sebastian,

Here in one patchset are two patches I posted recently, and two more:

Patch 1 is a replacement (as agreed) for
"power: supply: bq24190_charger: Don't spam the logs on charger plug / unplug"
Patch 2 fixes up Hans' extcon patch. If you would like me to squash it with his
original patch, let me know.
Patch 3 (repost) fixes some issues with PM runtime error handling. Patch 4 fixes a nit in register_reset().

Changes in v4:
* fix definition of bq24190_reg_poc_chg_config_*
* revert to if (device_property_read... == 0)

Liam Breck (4):
power: bq24190_charger: Limit over/under voltage fault logging
power: bq24190_charger: Clean up extcon code
power: bq24190_charger: Uniform pm_runtime_get() failure handling
power: bq24190_charger: Delay before polling reset flag

 drivers/power/supply/bq24190_charger.c | 125 ++++++++++++++++-----------------
 1 file changed, 62 insertions(+), 63 deletions(-)
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH v4 1/4 power: bq24190_charger: Limit over/under voltage fault logging

From: Liam Breck <[email protected]>

If the charger is unplugged before the battery is full we may see an over/under voltage fault. Ignore this rather then emitting a message or uevent.

This prevents messages like these on charger unplug/replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0

Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/power/supply/bq24190_charger.c +6 -1
index a699ad3..64a48b9 100644
@@ -1222,8 +1222,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)
 		}
 	} while (f_reg && ++i < 2);
 
+	/* ignore over/under voltage fault after disconnect */
+	if (f_reg == (1 << BQ24190_REG_F_CHRG_FAULT_SHIFT) &&
+	    !(ss_reg & BQ24190_REG_SS_PG_STAT_MASK))
+		f_reg = 0;
+
 	if (f_reg != bdi->f_reg) {
-		dev_info(bdi->dev,
+		dev_warn(bdi->dev,
 			"Fault: boost %d, charge %d, battery %d, ntc %d\n",
 			!!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK),
 			!!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),
Signature · 1 line
2.9.3
author
#3 lore raw

PATCH v4 2/4 power: bq24190_charger: Clean up extcon code

In reply to Liam Breck

From: Liam Breck <[email protected]>

Polishing and fixes for initial extcon patch.

Fixes 4db249b6f3b4 ("power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost")
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 73 ++++++++++++++++------------------
 1 file changed, 35 insertions(+), 38 deletions(-)
drivers/power/supply/bq24190_charger.c +35 -38
index 64a48b9..10e5324 100644
@@ -38,8 +38,9 @@
 #define BQ24190_REG_POC_WDT_RESET_SHIFT		6
 #define BQ24190_REG_POC_CHG_CONFIG_MASK		(BIT(5) | BIT(4))
 #define BQ24190_REG_POC_CHG_CONFIG_SHIFT	4
-#define BQ24190_REG_POC_CHG_CONFIG_CHARGE	1
-#define BQ24190_REG_POC_CHG_CONFIG_OTG		2
+#define BQ24190_REG_POC_CHG_CONFIG_DISABLE		0x0
+#define BQ24190_REG_POC_CHG_CONFIG_CHARGE		0x1
+#define BQ24190_REG_POC_CHG_CONFIG_OTG			0x2
 #define BQ24190_REG_POC_SYS_MIN_MASK		(BIT(3) | BIT(2) | BIT(1))
 #define BQ24190_REG_POC_SYS_MIN_SHIFT		1
 #define BQ24190_REG_POC_BOOST_LIM_MASK		BIT(0)
@@ -173,8 +174,9 @@ struct bq24190_dev_info {
  */
 
 /* REG00[2:0] (IINLIM) in uAh */
-static const int bq24190_iinlim_values[] = {
-	100000, 150000, 500000, 900000, 1200000, 1500000, 2000000, 3000000 };
+static const int bq24190_isc_iinlim_values[] = {
+	 100000,  150000,  500000,  900000, 1200000, 1500000, 2000000, 3000000
+};
 
 /* REG02[7:2] (ICHG) in uAh */
 static const int bq24190_ccc_ichg_values[] = {
@@ -1298,16 +1300,17 @@ static void bq24190_extcon_work(struct work_struct *work)
 {
 	struct bq24190_dev_info *bdi =
 		container_of(work, struct bq24190_dev_info, extcon_work.work);
-	int ret, iinlim = 0;
+	int error, iinlim = 0;
 
-	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0) {
-		dev_err(bdi->dev, "Error getting runtime-pm ref: %d\n", ret);
+	error = pm_runtime_get_sync(bdi->dev);
+	if (error < 0) {
+		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
+		pm_runtime_put_noidle(bdi->dev);
 		return;
 	}
 
-	if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1)
-		iinlim = 500000;
+	if      (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1)
+		iinlim =  500000;
 	else if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_CDP) == 1 ||
 		 extcon_get_state(bdi->extcon, EXTCON_CHG_USB_ACA) == 1)
 		iinlim = 1500000;
@@ -1315,33 +1318,25 @@ static void bq24190_extcon_work(struct work_struct *work)
 		iinlim = 2000000;
 
 	if (iinlim) {
-		ret = bq24190_set_field_val(bdi, BQ24190_REG_ISC,
-				BQ24190_REG_ISC_IINLIM_MASK,
-				BQ24190_REG_ISC_IINLIM_SHIFT,
-				bq24190_iinlim_values,
-				ARRAY_SIZE(bq24190_iinlim_values),
-				iinlim);
-		if (ret)
-			dev_err(bdi->dev, "Can't set IINLIM: %d\n", ret);
+		error = bq24190_set_field_val(bdi, BQ24190_REG_ISC,
+					      BQ24190_REG_ISC_IINLIM_MASK,
+					      BQ24190_REG_ISC_IINLIM_SHIFT,
+					      bq24190_isc_iinlim_values,
+					      ARRAY_SIZE(bq24190_isc_iinlim_values),
+					      iinlim);
+		if (error < 0)
+			dev_err(bdi->dev, "Can't set IINLIM: %d\n", error);
 	}
 
-	/*
-	 * If no charger has been detected and host mode is requested, activate
-	 * the 5V boost converter, otherwise deactivate it.
-	 */
-	if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1) {
-		ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-					 BQ24190_REG_POC_CHG_CONFIG_MASK,
-					 BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-					 BQ24190_REG_POC_CHG_CONFIG_OTG);
-	} else {
-		ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-					 BQ24190_REG_POC_CHG_CONFIG_MASK,
-					 BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-					 BQ24190_REG_POC_CHG_CONFIG_CHARGE);
-	}
-	if (ret)
-		dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
+	/* Set OTG 5V boost: on if no charger detected and in USB host mode, else off */
+	error = bq24190_write_mask(bdi, BQ24190_REG_POC,
+				   BQ24190_REG_POC_CHG_CONFIG_MASK,
+				   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+			!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1
+				 ? BQ24190_REG_POC_CHG_CONFIG_OTG
+				 : BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+	if (error < 0)
+		dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
 
 	pm_runtime_mark_last_busy(bdi->dev);
 	pm_runtime_put_autosuspend(bdi->dev);
@@ -1432,8 +1427,8 @@ static int bq24190_probe(struct i2c_client *client,
 	}
 
 	/*
-	 * The extcon-name property is purely an in kernel interface for
-	 * x86/ACPI use, DT platforms should get extcon via phandle.
+	 * ACPI platforms should use device_property "extcon-name".
+	 * Devicetree platforms should get extcon via phandle (not yet supported).
 	 */
 	if (device_property_read_string(dev, "extcon-name", &name) == 0) {
 		bdi->extcon = extcon_get_extcon_dev(name);
@@ -1498,8 +1493,10 @@ static int bq24190_probe(struct i2c_client *client,
 		bdi->extcon_nb.notifier_call = bq24190_extcon_event;
 		ret = devm_extcon_register_notifier(dev, bdi->extcon, -1,
 						    &bdi->extcon_nb);
-		if (ret)
+		if (ret) {
+			dev_err(dev, "Can't register extcon\n");
 			goto out5;
+		}
 
 		/* Sync initial cable state */
 		queue_delayed_work(system_wq, &bdi->extcon_work, 0);
Signature · 1 line
2.9.3
author
#11 lore raw

PATCH v4 3/4 power: bq24190_charger: Uniform pm_runtime_get() failure handling

In reply to Liam Breck

From: Liam Breck <[email protected]>

On pm_runtime_get() failure, always emit an error message. Prevent unbalanced pm_runtime_get by calling:
pm_runtime_put_noidle() in irq handler pm_runtime_put_sync() on any probe() failure
Rename probe() out labels instead of renumbering them.

Fixes 13d6fa8447fa ("power: bq24190_charger: Use PM runtime autosuspend")
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 37 +++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/power/supply/bq24190_charger.c +19 -18
index 10e5324..fa29cb3 100644
@@ -1280,12 +1280,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)
 static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
 {
 	struct bq24190_dev_info *bdi = data;
-	int ret;
+	int error;
 
 	bdi->irq_event = true;
-	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0) {
-		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
+	error = pm_runtime_get_sync(bdi->dev);
+	if (error < 0) {
+		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
+		pm_runtime_put_noidle(bdi->dev);
 		return IRQ_NONE;
 	}
 	bq24190_check_status(bdi);
@@ -1442,13 +1443,15 @@ static int bq24190_probe(struct i2c_client *client,
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 600);
 	ret = pm_runtime_get_sync(dev);
-	if (ret < 0)
-		goto out1;
+	if (ret < 0) {
+		dev_err(dev, "pm_runtime_get failed: %i\n", ret);
+		goto out_pmrt;
+	}
 
 	ret = bq24190_hw_init(bdi);
 	if (ret < 0) {
 		dev_err(dev, "Hardware init failed\n");
-		goto out2;
+		goto out_pmrt;
 	}
 
 	charger_cfg.drv_data = bdi;
@@ -1459,7 +1462,7 @@ static int bq24190_probe(struct i2c_client *client,
 	if (IS_ERR(bdi->charger)) {
 		dev_err(dev, "Can't register charger\n");
 		ret = PTR_ERR(bdi->charger);
-		goto out2;
+		goto out_pmrt;
 	}
 
 	battery_cfg.drv_data = bdi;
@@ -1468,13 +1471,13 @@ static int bq24190_probe(struct i2c_client *client,
 	if (IS_ERR(bdi->battery)) {
 		dev_err(dev, "Can't register battery\n");
 		ret = PTR_ERR(bdi->battery);
-		goto out3;
+		goto out_charger;
 	}
 
 	ret = bq24190_sysfs_create_group(bdi);
 	if (ret) {
 		dev_err(dev, "Can't create sysfs entries\n");
-		goto out4;
+		goto out_battery;
 	}
 
 	bdi->initialized = true;
@@ -1485,7 +1488,7 @@ static int bq24190_probe(struct i2c_client *client,
 			"bq24190-charger", bdi);
 	if (ret < 0) {
 		dev_err(dev, "Can't set up irq handler\n");
-		goto out5;
+		goto out_sysfs;
 	}
 
 	if (bdi->extcon) {
@@ -1495,7 +1498,7 @@ static int bq24190_probe(struct i2c_client *client,
 						    &bdi->extcon_nb);
 		if (ret) {
 			dev_err(dev, "Can't register extcon\n");
-			goto out5;
+			goto out_sysfs;
 		}
 
 		/* Sync initial cable state */
@@ -1509,19 +1512,17 @@ static int bq24190_probe(struct i2c_client *client,
 
 	return 0;
 
-out5:
+out_sysfs:
 	bq24190_sysfs_remove_group(bdi);
 
-out4:
+out_battery:
 	power_supply_unregister(bdi->battery);
 
-out3:
+out_charger:
 	power_supply_unregister(bdi->charger);
 
-out2:
+out_pmrt:
 	pm_runtime_put_sync(dev);
-
-out1:
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 	return ret;
Signature · 1 line
2.9.3
author
#13 lore raw

PATCH v4 4/4 power: bq24190_charger: Delay before polling reset flag

In reply to Liam Breck

From: Liam Breck <[email protected]>

On chip reset, polling loop was reading reset register immediately. Instead, call udelay() before reading chip register.

Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -6
index fa29cb3..71a796e 100644
@@ -543,18 +543,14 @@ static int bq24190_register_reset(struct bq24190_dev_info *bdi)
 
 	/* Reset bit will be cleared by hardware so poll until it is */
 	do {
+		udelay(10);
 		ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
 				BQ24190_REG_POC_RESET_MASK,
 				BQ24190_REG_POC_RESET_SHIFT,
 				&v);
 		if (ret < 0)
 			return ret;
-
-		if (!v)
-			break;
-
-		udelay(10);
-	} while (--limit);
+	} while (v && --limit);
 
 	if (!limit)
 		return -EIO;
Signature · 1 line
2.9.3
Reviewed-by on v4 1/4
#2 lore raw

Re: [PATCH v4 1/4] power: bq24190_charger: Limit over/under voltage fault logging

In reply to Liam Breck

Hi,

Quoted 6 lines · Liam Breck

From: Liam Breck <[email protected]>

If the charger is unplugged before the battery is full we may see an over/under voltage fault. Ignore this rather then emitting a message or uevent.

Quoted 7 lines

This prevents messages like these on charger unplug/replug:
bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0

Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>

Patch looks good to me:

Regards,

Hans

Quoted 24 lines
---
 drivers/power/supply/bq24190_charger.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/power/supply/bq24190_charger.c +6 -1
index a699ad3..64a48b9 100644
@@ -1222,8 +1222,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)
 		}
 	} while (f_reg && ++i < 2);
 
+	/* ignore over/under voltage fault after disconnect */
+	if (f_reg == (1 << BQ24190_REG_F_CHRG_FAULT_SHIFT) &&
+	    !(ss_reg & BQ24190_REG_SS_PG_STAT_MASK))
+		f_reg = 0;
+
 	if (f_reg != bdi->f_reg) {
-		dev_info(bdi->dev,
+		dev_warn(bdi->dev,
 			"Fault: boost %d, charge %d, battery %d, ntc %d\n",
 			!!(f_reg & BQ24190_REG_F_BOOST_FAULT_MASK),
 			!!(f_reg & BQ24190_REG_F_CHRG_FAULT_MASK),
#4 lore raw

Re: [PATCH v4 2/4] power: bq24190_charger: Clean up extcon code

In reply to Liam Breck

Hi,

Quoted 75 lines · Liam Breck

From: Liam Breck <[email protected]>

Polishing and fixes for initial extcon patch.

Fixes 4db249b6f3b4 ("power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost")
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 73 ++++++++++++++++------------------
 1 file changed, 35 insertions(+), 38 deletions(-)
drivers/power/supply/bq24190_charger.c +13 -17
index 64a48b9..10e5324 100644
@@ -38,8 +38,9 @@
 #define BQ24190_REG_POC_WDT_RESET_SHIFT		6
 #define BQ24190_REG_POC_CHG_CONFIG_MASK		(BIT(5) | BIT(4))
 #define BQ24190_REG_POC_CHG_CONFIG_SHIFT	4
-#define BQ24190_REG_POC_CHG_CONFIG_CHARGE	1
-#define BQ24190_REG_POC_CHG_CONFIG_OTG		2
+#define BQ24190_REG_POC_CHG_CONFIG_DISABLE		0x0
+#define BQ24190_REG_POC_CHG_CONFIG_CHARGE		0x1
+#define BQ24190_REG_POC_CHG_CONFIG_OTG			0x2
 #define BQ24190_REG_POC_SYS_MIN_MASK		(BIT(3) | BIT(2) | BIT(1))
 #define BQ24190_REG_POC_SYS_MIN_SHIFT		1
 #define BQ24190_REG_POC_BOOST_LIM_MASK		BIT(0)
@@ -173,8 +174,9 @@ struct bq24190_dev_info {
  */
 
 /* REG00[2:0] (IINLIM) in uAh */
-static const int bq24190_iinlim_values[] = {
-	100000, 150000, 500000, 900000, 1200000, 1500000, 2000000, 3000000 };
+static const int bq24190_isc_iinlim_values[] = {
+	 100000,  150000,  500000,  900000, 1200000, 1500000, 2000000, 3000000
+};
 
 /* REG02[7:2] (ICHG) in uAh */
 static const int bq24190_ccc_ichg_values[] = {
@@ -1298,16 +1300,17 @@ static void bq24190_extcon_work(struct work_struct *work)
 {
 	struct bq24190_dev_info *bdi =
 		container_of(work, struct bq24190_dev_info, extcon_work.work);
-	int ret, iinlim = 0;
+	int error, iinlim = 0;
 
-	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0) {
-		dev_err(bdi->dev, "Error getting runtime-pm ref: %d\n", ret);
+	error = pm_runtime_get_sync(bdi->dev);
+	if (error < 0) {
+		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
+		pm_runtime_put_noidle(bdi->dev);
 		return;
 	}
 
-	if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1)
-		iinlim = 500000;
+	if      (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1)
+		iinlim =  500000;
 	else if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_CDP) == 1 ||
 		 extcon_get_state(bdi->extcon, EXTCON_CHG_USB_ACA) == 1)
 		iinlim = 1500000;
@@ -1315,33 +1318,25 @@ static void bq24190_extcon_work(struct work_struct *work)
 		iinlim = 2000000;
 
 	if (iinlim) {
-		ret = bq24190_set_field_val(bdi, BQ24190_REG_ISC,
-				BQ24190_REG_ISC_IINLIM_MASK,
-				BQ24190_REG_ISC_IINLIM_SHIFT,
-				bq24190_iinlim_values,
-				ARRAY_SIZE(bq24190_iinlim_values),
-				iinlim);
-		if (ret)

drivers/power/supply/bq24190_charger.c static void bq24190_extcon_work(struct work_struct *work) · line 1329

Quoted 10 lines
drivers/power/supply/bq24190_charger.c +8 -1
-			dev_err(bdi->dev, "Can't set IINLIM: %d\n", ret);
+		error = bq24190_set_field_val(bdi, BQ24190_REG_ISC,
+					      BQ24190_REG_ISC_IINLIM_MASK,
+					      BQ24190_REG_ISC_IINLIM_SHIFT,
+					      bq24190_isc_iinlim_values,
+					      ARRAY_SIZE(bq24190_isc_iinlim_values),
+					      iinlim);
+		if (error < 0)
+			dev_err(bdi->dev, "Can't set IINLIM: %d\n", error);
 	}

The above changes are fine with me,

Quoted 19 lines
drivers/power/supply/bq24190_charger.c +2 -17
-	/*
-	 * If no charger has been detected and host mode is requested, activate
-	 * the 5V boost converter, otherwise deactivate it.
-	 */
-	if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1) {
-		ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-					 BQ24190_REG_POC_CHG_CONFIG_MASK,
-					 BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-					 BQ24190_REG_POC_CHG_CONFIG_OTG);
-	} else {
-		ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-					 BQ24190_REG_POC_CHG_CONFIG_MASK,
-					 BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-					 BQ24190_REG_POC_CHG_CONFIG_CHARGE);
-	}
-	if (ret)
-		dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
+	/* Set OTG 5V boost: on if no charger detected and in USB host mode, else off */
+	error = bq24190_write_mask(bdi, BQ24190_REG_POC,

drivers/power/supply/bq24190_charger.c static void bq24190_extcon_work(struct work_struct *work) · line 1342

Quoted 10 lines
drivers/power/supply/bq24190_charger.c +7 -0
+				   BQ24190_REG_POC_CHG_CONFIG_MASK,
+				   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+			!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1
+				 ? BQ24190_REG_POC_CHG_CONFIG_OTG
+				 : BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+	if (error < 0)
+		dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
 
 	pm_runtime_mark_last_busy(bdi->dev);
 	pm_runtime_put_autosuspend(bdi->dev);

I still find the refactored code you're proposing here a lot less readable then the original code, and the same goes for the comment. If you insist in changing this, then I suggest changing it into this:

	/*
	 * If no charger has been detected and host mode is requested, activate
	 * the 5V boost converter, otherwise deactivate it.
	 */
	if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1)
		chg_config = BQ24190_REG_POC_CHG_CONFIG_OTG;
	else
		chg_config = BQ24190_REG_POC_CHG_CONFIG_CHARGE;

	error = bq24190_write_mask(bdi, BQ24190_REG_POC,
				   BQ24190_REG_POC_CHG_CONFIG_MASK,
				   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
				   chg_config);
	if (error)
		dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);

drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1434

Quoted 11 lines
drivers/power/supply/bq24190_charger.c +2 -2
@@ -1432,8 +1427,8 @@ static int bq24190_probe(struct i2c_client *client,
 	}
 
 	/*
-	 * The extcon-name property is purely an in kernel interface for
-	 * x86/ACPI use, DT platforms should get extcon via phandle.
+	 * ACPI platforms should use device_property "extcon-name".
+	 * Devicetree platforms should get extcon via phandle (not yet supported).
 	 */
 	if (device_property_read_string(dev, "extcon-name", &name) == 0) {
 		bdi->extcon = extcon_get_extcon_dev(name);

The new comment suggest that extcon-name is something which should actually be used inside ACPI DSDT tables, which it is not, please leave the comment as is.

drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1502

Quoted 13 lines
drivers/power/supply/bq24190_charger.c +3 -1
@@ -1498,8 +1493,10 @@ static int bq24190_probe(struct i2c_client *client,
 		bdi->extcon_nb.notifier_call = bq24190_extcon_event;
 		ret = devm_extcon_register_notifier(dev, bdi->extcon, -1,
 						    &bdi->extcon_nb);
-		if (ret)
+		if (ret) {
+			dev_err(dev, "Can't register extcon\n");
 			goto out5;
+		}
 
 		/* Sync initial cable state */
 		queue_delayed_work(system_wq, &bdi->extcon_work, 0);

Regards,

Hans

Reviewed-by on v4 3/4
#12 lore raw

Re: [PATCH v4 3/4] power: bq24190_charger: Uniform pm_runtime_get() failure handling

In reply to Liam Breck

Hi,

Quoted 8 lines · Liam Breck

From: Liam Breck <[email protected]>

On pm_runtime_get() failure, always emit an error message. Prevent unbalanced pm_runtime_get by calling:
pm_runtime_put_noidle() in irq handler pm_runtime_put_sync() on any probe() failure
Rename probe() out labels instead of renumbering them.

Quoted 4 lines
Fixes 13d6fa8447fa ("power: bq24190_charger: Use PM runtime autosuspend")
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>

Patch looks good to me:

Regards,

Hans

Quoted 113 lines
---
 drivers/power/supply/bq24190_charger.c | 37 +++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/power/supply/bq24190_charger.c +19 -18
index 10e5324..fa29cb3 100644
@@ -1280,12 +1280,13 @@ static void bq24190_check_status(struct bq24190_dev_info *bdi)
 static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
 {
 	struct bq24190_dev_info *bdi = data;
-	int ret;
+	int error;
 
 	bdi->irq_event = true;
-	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0) {
-		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
+	error = pm_runtime_get_sync(bdi->dev);
+	if (error < 0) {
+		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
+		pm_runtime_put_noidle(bdi->dev);
 		return IRQ_NONE;
 	}
 	bq24190_check_status(bdi);
@@ -1442,13 +1443,15 @@ static int bq24190_probe(struct i2c_client *client,
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 600);
 	ret = pm_runtime_get_sync(dev);
-	if (ret < 0)
-		goto out1;
+	if (ret < 0) {
+		dev_err(dev, "pm_runtime_get failed: %i\n", ret);
+		goto out_pmrt;
+	}
 
 	ret = bq24190_hw_init(bdi);
 	if (ret < 0) {
 		dev_err(dev, "Hardware init failed\n");
-		goto out2;
+		goto out_pmrt;
 	}
 
 	charger_cfg.drv_data = bdi;
@@ -1459,7 +1462,7 @@ static int bq24190_probe(struct i2c_client *client,
 	if (IS_ERR(bdi->charger)) {
 		dev_err(dev, "Can't register charger\n");
 		ret = PTR_ERR(bdi->charger);
-		goto out2;
+		goto out_pmrt;
 	}
 
 	battery_cfg.drv_data = bdi;
@@ -1468,13 +1471,13 @@ static int bq24190_probe(struct i2c_client *client,
 	if (IS_ERR(bdi->battery)) {
 		dev_err(dev, "Can't register battery\n");
 		ret = PTR_ERR(bdi->battery);
-		goto out3;
+		goto out_charger;
 	}
 
 	ret = bq24190_sysfs_create_group(bdi);
 	if (ret) {
 		dev_err(dev, "Can't create sysfs entries\n");
-		goto out4;
+		goto out_battery;
 	}
 
 	bdi->initialized = true;
@@ -1485,7 +1488,7 @@ static int bq24190_probe(struct i2c_client *client,
 			"bq24190-charger", bdi);
 	if (ret < 0) {
 		dev_err(dev, "Can't set up irq handler\n");
-		goto out5;
+		goto out_sysfs;
 	}
 
 	if (bdi->extcon) {
@@ -1495,7 +1498,7 @@ static int bq24190_probe(struct i2c_client *client,
 						    &bdi->extcon_nb);
 		if (ret) {
 			dev_err(dev, "Can't register extcon\n");
-			goto out5;
+			goto out_sysfs;
 		}
 
 		/* Sync initial cable state */
@@ -1509,19 +1512,17 @@ static int bq24190_probe(struct i2c_client *client,
 
 	return 0;
 
-out5:
+out_sysfs:
 	bq24190_sysfs_remove_group(bdi);
 
-out4:
+out_battery:
 	power_supply_unregister(bdi->battery);
 
-out3:
+out_charger:
 	power_supply_unregister(bdi->charger);
 
-out2:
+out_pmrt:
 	pm_runtime_put_sync(dev);
-
-out1:
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 	return ret;
#14 lore raw

Re: [PATCH v4 4/4] power: bq24190_charger: Delay before polling reset flag

In reply to Liam Breck

Hi,

Quoted 4 lines · Liam Breck

From: Liam Breck <[email protected]>

On chip reset, polling loop was reading reset register immediately. Instead, call udelay() before reading chip register.

Can you extend the commit message to explain why udelay is being called ? IOW what is the problem with reading the register immediately which this patch addresses ?

Regards,

Hans

Quoted 34 lines
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -6
index fa29cb3..71a796e 100644
@@ -543,18 +543,14 @@ static int bq24190_register_reset(struct bq24190_dev_info *bdi)
 
 	/* Reset bit will be cleared by hardware so poll until it is */
 	do {
+		udelay(10);
 		ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
 				BQ24190_REG_POC_RESET_MASK,
 				BQ24190_REG_POC_RESET_SHIFT,
 				&v);
 		if (ret < 0)
 			return ret;
-
-		if (!v)
-			break;
-
-		udelay(10);
-	} while (--limit);
+	} while (v && --limit);
 
 	if (!limit)
 		return -EIO;
author
#15 lore raw

Re: [PATCH v4 4/4] power: bq24190_charger: Delay before polling reset flag

Hi Hans,

Quoted 6 lines · Hans de Goede

Hi,

Quoted 3 lines · Liam Breck

From: Liam Breck <[email protected]>

Quoted 7 lines
Quoted 2 lines

On chip reset, polling loop was reading reset register immediately. Instead, call udelay() before reading chip register.

Can you extend the commit message to explain why udelay is being called ? IOW what is the problem with reading the register immediately which this patch addresses ?

I thought I'd read that reset isn't instantaneous, but in testing it seems to be. So I will revert to the original post-reset delay, and change udelay() to usleep_range(10, 20). Any thoughts on those numbers?

Quoted 41 lines
Quoted 40 lines
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -6
index fa29cb3..71a796e 100644
@@ -543,18 +543,14 @@ static int bq24190_register_reset(struct
 bq24190_dev_info *bdi)
 
        /* Reset bit will be cleared by hardware so poll until it is */
        do {
+               udelay(10);
                ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
                                BQ24190_REG_POC_RESET_MASK,
                                BQ24190_REG_POC_RESET_SHIFT,
                                &v);
                if (ret < 0)
                        return ret;
-
-               if (!v)
-                       break;
-
-               udelay(10);
-       } while (--limit);
+       } while (v && --limit);
 
        if (!limit)
                return -EIO;
author
#5 lore raw

Re: [PATCH v4 2/4] power: bq24190_charger: Clean up extcon code

In reply to Hans de Goede

Hallo Hans,

Quoted 97 lines · Hans de Goede

Hi,

Quoted 93 lines · Liam Breck

From: Liam Breck <[email protected]>

Polishing and fixes for initial extcon patch.

Fixes 4db249b6f3b4 ("power: supply: bq24190_charger: Use extcon to

determine ilimit, 5v boost")

Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 73
++++++++++++++++------------------
 1 file changed, 35 insertions(+), 38 deletions(-)
drivers/power/supply/bq24190_charger.c +5 -4
index 64a48b9..10e5324 100644
@@ -38,8 +38,9 @@
 #define BQ24190_REG_POC_WDT_RESET_SHIFT                6
 #define BQ24190_REG_POC_CHG_CONFIG_MASK                (BIT(5) | BIT(4))
 #define BQ24190_REG_POC_CHG_CONFIG_SHIFT       4
-#define BQ24190_REG_POC_CHG_CONFIG_CHARGE      1
-#define BQ24190_REG_POC_CHG_CONFIG_OTG         2
+#define BQ24190_REG_POC_CHG_CONFIG_DISABLE             0x0
+#define BQ24190_REG_POC_CHG_CONFIG_CHARGE              0x1
+#define BQ24190_REG_POC_CHG_CONFIG_OTG                 0x2
 #define BQ24190_REG_POC_SYS_MIN_MASK           (BIT(3) | BIT(2) | BIT(1))
 #define BQ24190_REG_POC_SYS_MIN_SHIFT          1
 #define BQ24190_REG_POC_BOOST_LIM_MASK         BIT(0)
@@ -173,8 +174,9 @@ struct bq24190_dev_info {
  */
 
 /* REG00[2:0] (IINLIM) in uAh */
-static const int bq24190_iinlim_values[] = {
-       100000, 150000, 500000, 900000, 1200000, 1500000, 2000000, 3000000
 };
+static const int bq24190_isc_iinlim_values[] = {
+        100000,  150000,  500000,  900000, 1200000, 1500000, 2000000,

3000000

drivers/power/supply/bq24190_charger.c +8 -6
+};
 
 /* REG02[7:2] (ICHG) in uAh */
 static const int bq24190_ccc_ichg_values[] = {
@@ -1298,16 +1300,17 @@ static void bq24190_extcon_work(struct work_struct
 *work)
 {
        struct bq24190_dev_info *bdi =
                container_of(work, struct bq24190_dev_info,
 extcon_work.work);
-       int ret, iinlim = 0;
+       int error, iinlim = 0;
 
-       ret = pm_runtime_get_sync(bdi->dev);
-       if (ret < 0) {
-               dev_err(bdi->dev, "Error getting runtime-pm ref: %d\n",
 ret);
+       error = pm_runtime_get_sync(bdi->dev);
+       if (error < 0) {
+               dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
+               pm_runtime_put_noidle(bdi->dev);
                return;
        }
 
-       if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1)
-               iinlim = 500000;
+       if      (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1)
+               iinlim =  500000;
        else if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_CDP) == 1 ||
                 extcon_get_state(bdi->extcon, EXTCON_CHG_USB_ACA) == 1)
                iinlim = 1500000;
drivers/power/supply/bq24190_charger.c +5 -8
@@ -1315,33 +1318,25 @@ static void bq24190_extcon_work(struct work_struct
 *work)
                iinlim = 2000000;
 
        if (iinlim) {
-               ret = bq24190_set_field_val(bdi, BQ24190_REG_ISC,
-                               BQ24190_REG_ISC_IINLIM_MASK,
-                               BQ24190_REG_ISC_IINLIM_SHIFT,
-                               bq24190_iinlim_values,
-                               ARRAY_SIZE(bq24190_iinlim_values),
-                               iinlim);
-               if (ret)
-                       dev_err(bdi->dev, "Can't set IINLIM: %d\n", ret);
+               error = bq24190_set_field_val(bdi, BQ24190_REG_ISC,
+                                             BQ24190_REG_ISC_IINLIM_MASK,
+
 BQ24190_REG_ISC_IINLIM_SHIFT,
+                                             bq24190_isc_iinlim_values,
+
 ARRAY_SIZE(bq24190_isc_iinlim_values),
Quoted 8 lines

drivers/power/supply/bq24190_charger.c static void bq24190_extcon_work(struct work_struct *work) · line 1329

Quoted 5 lines
drivers/power/supply/bq24190_charger.c +3 -0
+                                             iinlim);
+               if (error < 0)
+                       dev_err(bdi->dev, "Can't set IINLIM: %d\n",
 error);
        }

The above changes are fine with me,

High-five :-)

Quoted 32 lines
Quoted 32 lines
drivers/power/supply/bq24190_charger.c +0 -2
-       /*
-        * If no charger has been detected and host mode is requested,

activate

drivers/power/supply/bq24190_charger.c +0 -3
-        * the 5V boost converter, otherwise deactivate it.
-        */
-       if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) ==

1) {

drivers/power/supply/bq24190_charger.c +0 -9
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-                                        BQ24190_REG_POC_CHG_CONFIG_MASK,
-                                        BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-                                        BQ24190_REG_POC_CHG_CONFIG_OTG);
-       } else {
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-                                        BQ24190_REG_POC_CHG_CONFIG_MASK,
-                                        BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-

BQ24190_REG_POC_CHG_CONFIG_CHARGE);

drivers/power/supply/bq24190_charger.c +1 -3
-       }
-       if (ret)
-               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
+       /* Set OTG 5V boost: on if no charger detected and in USB host

mode, else off */

drivers/power/supply/bq24190_charger.c +4 -0
+       error = bq24190_write_mask(bdi, BQ24190_REG_POC,
+                                  BQ24190_REG_POC_CHG_CONFIG_MASK,
+                                  BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+                       !iinlim && extcon_get_state(bdi->extcon,

EXTCON_USB_HOST) == 1

drivers/power/supply/bq24190_charger.c +4 -0
+                                ? BQ24190_REG_POC_CHG_CONFIG_OTG
+                                : BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+       if (error < 0)
+               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 7 lines
Quoted 2 lines
        pm_runtime_mark_last_busy(bdi->dev);
        pm_runtime_put_autosuspend(bdi->dev);

I still find the refactored code you're proposing here a lot less readable then the original code, and the same goes for the comment. If you insist in changing this, then I suggest changing it into this:

OK. I'll collapse the comment to one line tho.

Quoted 20 lines

/*
* If no charger has been detected and host mode is requested,
activate

         * the 5V boost converter, otherwise deactivate it.
         */
        if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1)
                chg_config = BQ24190_REG_POC_CHG_CONFIG_OTG;
        else
                chg_config = BQ24190_REG_POC_CHG_CONFIG_CHARGE;

        error = bq24190_write_mask(bdi, BQ24190_REG_POC,
                                   BQ24190_REG_POC_CHG_CONFIG_MASK,
                                   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
                                   chg_config);
        if (error)
                dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 3 lines
drivers/power/supply/bq24190_charger.c +0 -0
@@ -1432,8 +1427,8 @@ static int bq24190_probe(struct i2c_client *client,
        }
 
Quoted 14 lines
Quoted 9 lines
drivers/power/supply/bq24190_charger.c +2 -2
        /*
-        * The extcon-name property is purely an in kernel interface for
-        * x86/ACPI use, DT platforms should get extcon via phandle.
+        * ACPI platforms should use device_property "extcon-name".
+        * Devicetree platforms should get extcon via phandle (not yet

supported).

         */
        if (device_property_read_string(dev, "extcon-name", &name) == 0) {
                bdi->extcon = extcon_get_extcon_dev(name);

The new comment suggest that extcon-name is something which should actually be used inside ACPI DSDT tables, which it is not, please leave the comment as is.

OK, right. But "in kernel interface" sounds official, and this is really a custom msg passing method. A platform-data struct is documented in a header, and a module parameter has its own docs scheme; and use of those methods is well documented. I can't tell how I would invoke this one. How about this...

A Devicetree should provide extcon-name via phandle (not yet supported). ACPI extcon drivers/clients[?] should insert[?] device_property extcon-name into our device with relevant_api_call(args).

Quoted 18 lines

drivers/power/supply/bq24190_charger.c static int bq24190_probe(struct i2c_client *client, · line 1502

Quoted 13 lines
drivers/power/supply/bq24190_charger.c +3 -1
@@ -1498,8 +1493,10 @@ static int bq24190_probe(struct i2c_client *client,
                bdi->extcon_nb.notifier_call = bq24190_extcon_event;
                ret = devm_extcon_register_notifier(dev, bdi->extcon, -1,
                                                    &bdi->extcon_nb);
-               if (ret)
+               if (ret) {
+                       dev_err(dev, "Can't register extcon\n");
                        goto out5;
+               }
 
                /* Sync initial cable state */
                queue_delayed_work(system_wq, &bdi->extcon_work, 0);

Regards,

Hans

#16 lore raw

Re: [PATCH v4 4/4] power: bq24190_charger: Delay before polling reset flag

In reply to Liam Breck

Hi,

Quoted 13 lines · Liam Breck

Hi Hans,

Quoted 10 lines · Hans de Goede

Hi,

Quoted 5 lines · Liam Breck

From: Liam Breck <[email protected]>

On chip reset, polling loop was reading reset register immediately. Instead, call udelay() before reading chip register.

Quoted 8 lines
Quoted 3 lines

Can you extend the commit message to explain why udelay is being called ? IOW what is the problem with reading the register immediately which this patch addresses ?

I thought I'd read that reset isn't instantaneous, but in testing it seems to be. So I will revert to the original post-reset delay, and change udelay() to usleep_range(10, 20). Any thoughts on those numbers?

Using usleep makes no sense for such short delays, so I would stick with udelay.

More importantly you still have not explained why we need to delay *at all* esp. such a short delay, 10us is a single bit at 100kHz i2c so the set bq24190 register-pointer part of the i2c transfer which happens before reading back the reset-bit alone takes 20 times as long as the delay.

I still don't understand why a delay is needed at all, what are you trying to achieve with this delay ? Are you seeing a specific problem you are trying to fix ?

Regards,

Hans

Quoted 44 lines
Quoted 44 lines
Quoted 43 lines
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -6
index fa29cb3..71a796e 100644
@@ -543,18 +543,14 @@ static int bq24190_register_reset(struct
 bq24190_dev_info *bdi)
 
        /* Reset bit will be cleared by hardware so poll until it is */
        do {
+               udelay(10);
                ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
                                BQ24190_REG_POC_RESET_MASK,
                                BQ24190_REG_POC_RESET_SHIFT,
                                &v);
                if (ret < 0)
                        return ret;
-
-               if (!v)
-                       break;
-
-               udelay(10);
-       } while (--limit);
+       } while (v && --limit);
 
        if (!limit)
                return -EIO;
#6 lore raw

Re: [PATCH v4 2/4] power: bq24190_charger: Clean up extcon code

In reply to Liam Breck

Hi,

Quoted 3 lines · Liam Breck

Hallo Hans,

On Thu, Apr 6, 2017 at 12:17 AM, Hans de Goede <[email protected]> wrote:

<snip>

Quoted 36 lines
Quoted 36 lines
Quoted 34 lines
(quoted diff) +0 -2
-       /*
-        * If no charger has been detected and host mode is requested,

activate

drivers/power/supply/bq24190_charger.c +0 -3
-        * the 5V boost converter, otherwise deactivate it.
-        */
-       if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) ==

1) {

drivers/power/supply/bq24190_charger.c +0 -9
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-                                        BQ24190_REG_POC_CHG_CONFIG_MASK,
-                                        BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-                                        BQ24190_REG_POC_CHG_CONFIG_OTG);
-       } else {
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-                                        BQ24190_REG_POC_CHG_CONFIG_MASK,
-                                        BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-

BQ24190_REG_POC_CHG_CONFIG_CHARGE);

drivers/power/supply/bq24190_charger.c +1 -3
-       }
-       if (ret)
-               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
+       /* Set OTG 5V boost: on if no charger detected and in USB host

mode, else off */

drivers/power/supply/bq24190_charger.c +4 -0
+       error = bq24190_write_mask(bdi, BQ24190_REG_POC,
+                                  BQ24190_REG_POC_CHG_CONFIG_MASK,
+                                  BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+                       !iinlim && extcon_get_state(bdi->extcon,

EXTCON_USB_HOST) == 1

drivers/power/supply/bq24190_charger.c +4 -0
+                                ? BQ24190_REG_POC_CHG_CONFIG_OTG
+                                : BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+       if (error < 0)
+               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
 
        pm_runtime_mark_last_busy(bdi->dev);
        pm_runtime_put_autosuspend(bdi->dev);
Quoted 5 lines
Quoted 3 lines

I still find the refactored code you're proposing here a lot less readable then the original code, and the same goes for the comment. If you insist in changing this, then I suggest changing it into this:

OK. I'll collapse the comment to one line tho.

Please don't having this as 2 lines really is not a problem in any way and I find the longer comment a lot easier to parse.

Quoted 36 lines
Quoted 21 lines

/*
* If no charger has been detected and host mode is requested,
activate

         * the 5V boost converter, otherwise deactivate it.
         */
        if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1)
                chg_config = BQ24190_REG_POC_CHG_CONFIG_OTG;
        else
                chg_config = BQ24190_REG_POC_CHG_CONFIG_CHARGE;

        error = bq24190_write_mask(bdi, BQ24190_REG_POC,
                                   BQ24190_REG_POC_CHG_CONFIG_MASK,
                                   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
                                   chg_config);
        if (error)
                dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 3 lines
(quoted diff) +0 -0
@@ -1432,8 +1427,8 @@ static int bq24190_probe(struct i2c_client *client,
        }
 
Quoted 14 lines
Quoted 9 lines
drivers/power/supply/bq24190_charger.c +2 -2
        /*
-        * The extcon-name property is purely an in kernel interface for
-        * x86/ACPI use, DT platforms should get extcon via phandle.
+        * ACPI platforms should use device_property "extcon-name".
+        * Devicetree platforms should get extcon via phandle (not yet

supported).

         */
        if (device_property_read_string(dev, "extcon-name", &name) == 0) {
                bdi->extcon = extcon_get_extcon_dev(name);

The new comment suggest that extcon-name is something which should actually be used inside ACPI DSDT tables, which it is not, please leave the comment as is.

Quoted 7 lines

OK, right. But "in kernel interface" sounds official, and this is really a custom msg passing method. A platform-data struct is documented in a header, and a module parameter has its own docs scheme; and use of those methods is well documented. I can't tell how I would invoke this one. How about this...

A Devicetree should provide extcon-name via phandle (not yet supported).

No a devicetree should not provide a name it would provide a phandle pointing to the extcon, no name (and name based lookup) should be involved.

Quoted 2 lines

ACPI extcon drivers/clients[?] should insert[?] device_property extcon-name into our device with relevant_api_call(args).

For an example of how this is used see:

https://github.com/jwrdegoede/linux-sunxi/commit/7fa4460e2a18a3f6ffb39ae4940fee1dd2a880a4

Around line 214 of i2c-cht-wc.c and later.

Regards,

Hans

author
#7 lore raw

Re: [PATCH v4 2/4] power: bq24190_charger: Clean up extcon code

Quoted 117 lines · Hans de Goede

Hi,

Quoted 5 lines · Liam Breck

Hallo Hans,

On Thu, Apr 6, 2017 at 12:17 AM, Hans de Goede <[email protected]> wrote:

<snip>

Quoted 48 lines
Quoted 37 lines
Quoted 37 lines
(quoted diff) +0 -2
-       /*
-        * If no charger has been detected and host mode is requested,

activate

drivers/power/supply/bq24190_charger.c +0 -3
-        * the 5V boost converter, otherwise deactivate it.
-        */
-       if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) ==

1) {

(quoted diff) +0 -2
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-

BQ24190_REG_POC_CHG_CONFIG_MASK,
-
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-
BQ24190_REG_POC_CHG_CONFIG_OTG);

drivers/power/supply/bq24190_charger.c +0 -3
-       } else {
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-

BQ24190_REG_POC_CHG_CONFIG_MASK,
-
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-
BQ24190_REG_POC_CHG_CONFIG_CHARGE);

drivers/power/supply/bq24190_charger.c +1 -3
-       }
-       if (ret)
-               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
+       /* Set OTG 5V boost: on if no charger detected and in USB host

mode, else off */

drivers/power/supply/bq24190_charger.c +4 -0
+       error = bq24190_write_mask(bdi, BQ24190_REG_POC,
+                                  BQ24190_REG_POC_CHG_CONFIG_MASK,
+                                  BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+                       !iinlim && extcon_get_state(bdi->extcon,

EXTCON_USB_HOST) == 1

drivers/power/supply/bq24190_charger.c +4 -0
+                                ? BQ24190_REG_POC_CHG_CONFIG_OTG
+                                : BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+       if (error < 0)
+               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 9 lines
Quoted 2 lines
        pm_runtime_mark_last_busy(bdi->dev);
        pm_runtime_put_autosuspend(bdi->dev);

I still find the refactored code you're proposing here a lot less readable
then the original code, and the same goes for the comment. If you insist in changing this, then I suggest changing it into this:

Quoted 1 line

OK. I'll collapse the comment to one line tho.

Please don't having this as 2 lines really is not a problem in any way and I find the longer comment a lot easier to parse.

Quoted 49 lines
Quoted 36 lines

/*
* If no charger has been detected and host mode is requested,
activate

         * the 5V boost converter, otherwise deactivate it.
         */
        if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) ==
1)
                chg_config = BQ24190_REG_POC_CHG_CONFIG_OTG;
        else
                chg_config = BQ24190_REG_POC_CHG_CONFIG_CHARGE;

        error = bq24190_write_mask(bdi, BQ24190_REG_POC,
                                   BQ24190_REG_POC_CHG_CONFIG_MASK,
                                   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
                                   chg_config);
        if (error)
                dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +2 -2
@@ -1432,8 +1427,8 @@ static int bq24190_probe(struct i2c_client
 *client,
        }
 
        /*
-        * The extcon-name property is purely an in kernel interface for
-        * x86/ACPI use, DT platforms should get extcon via phandle.
+        * ACPI platforms should use device_property "extcon-name".
+        * Devicetree platforms should get extcon via phandle (not yet

supported).

Quoted 4 lines
         */
        if (device_property_read_string(dev, "extcon-name", &name) == 0)
{
                bdi->extcon = extcon_get_extcon_dev(name);
Quoted 5 lines

The new comment suggest that extcon-name is something which should actually
be used inside ACPI DSDT tables, which it is not, please leave the comment
as is.

OK, right. But "in kernel interface" sounds official, and this is really a custom msg passing method. A platform-data struct is documented in a header, and a module parameter has its own docs scheme; and use of those methods is well documented. I can't tell how I would invoke this one. How about this...

Quoted 6 lines
Quoted 1 line

A Devicetree should provide extcon-name via phandle (not yet supported).

No a devicetree should not provide a name it would provide a phandle pointing to the extcon, no name (and name based lookup) should be involved.

OK.

Quoted 9 lines
Quoted 2 lines

ACPI extcon drivers/clients[?] should insert[?] device_property extcon-name into our device with relevant_api_call(args).

For an example of how this is used see:

https://github.com/jwrdegoede/linux-sunxi/commit/7fa4460e2a18a3f6ffb39ae4940fee1dd2a880a4

Around line 214 of i2c-cht-wc.c and later.

So a comment like...

On ACPI platforms, extcon clients should invoke this driver with:
struct i2c_adapter a = { ... };
i2c_add_adapter(&a);
struct property_entry pe[] = { PROPERTY_ENTRY_STRING("extcon-name", <name>), ... };
struct i2c_board_info bi = { .type = "bq24190", .addr = 0x6b, .properties = pe, .irq = <irq> };
i2c_new_device(&a, &bi);

author
#17 lore raw

Re: [PATCH v4 4/4] power: bq24190_charger: Delay before polling reset flag

In reply to Hans de Goede
Quoted 41 lines · Hans de Goede

Hi,

Quoted 23 lines · Liam Breck

Hi Hans,

Quoted 8 lines · Hans de Goede

Hi,

Quoted 4 lines · Liam Breck

From: Liam Breck <[email protected]>

Quoted 8 lines
Quoted 2 lines

On chip reset, polling loop was reading reset register immediately. Instead, call udelay() before reading chip register.

Can you extend the commit message to explain why udelay is being called ? IOW what is the problem with reading the register immediately which this patch addresses ?

Quoted 4 lines

I thought I'd read that reset isn't instantaneous, but in testing it seems to be. So I will revert to the original post-reset delay, and change udelay() to usleep_range(10, 20). Any thoughts on those numbers?

Using usleep makes no sense for such short delays, so I would stick with udelay.

More importantly you still have not explained why we need to delay *at all* esp. such a short delay, 10us is a single bit at 100kHz i2c so the set bq24190 register-pointer part of the i2c transfer which happens before reading back the reset-bit alone takes 20 times as long as the delay.

Quoted 3 lines

I still don't understand why a delay is needed at all, what are you trying to achieve with this delay ? Are you seeing a specific problem you are trying to fix ?

A loop with udelay(10) was in the code already, because at manual 9.5.1.2 the note for bit 7 says "Back to 0 after register reset".

But I think you're right, we don't need to loop checking this; I'll just return -EIO (?) if bit 7 isn't 0 -- which presumably means charger is kaput.

Quoted 49 lines
Quoted 48 lines
Quoted 48 lines
Quoted 47 lines
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -6
index fa29cb3..71a796e 100644
@@ -543,18 +543,14 @@ static int bq24190_register_reset(struct
 bq24190_dev_info *bdi)
 
        /* Reset bit will be cleared by hardware so poll until it is */
        do {
+               udelay(10);
                ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
                                BQ24190_REG_POC_RESET_MASK,
                                BQ24190_REG_POC_RESET_SHIFT,
                                &v);
                if (ret < 0)
                        return ret;
-
-               if (!v)
-                       break;
-
-               udelay(10);
-       } while (--limit);
+       } while (v && --limit);
 
        if (!limit)
                return -EIO;
#8 lore raw

Re: [PATCH v4 2/4] power: bq24190_charger: Clean up extcon code

In reply to Liam Breck

Hi,

Quoted 139 lines · Liam Breck
Quoted 117 lines · Hans de Goede

Hi,

Quoted 5 lines · Liam Breck

Hallo Hans,

On Thu, Apr 6, 2017 at 12:17 AM, Hans de Goede <[email protected]> wrote:

<snip>

Quoted 48 lines
Quoted 37 lines
Quoted 37 lines
(quoted diff) +0 -2
-       /*
-        * If no charger has been detected and host mode is requested,

activate

drivers/power/supply/bq24190_charger.c +0 -3
-        * the 5V boost converter, otherwise deactivate it.
-        */
-       if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) ==

1) {

(quoted diff) +0 -2
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-

BQ24190_REG_POC_CHG_CONFIG_MASK,
-
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-
BQ24190_REG_POC_CHG_CONFIG_OTG);

drivers/power/supply/bq24190_charger.c +0 -3
-       } else {
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-

BQ24190_REG_POC_CHG_CONFIG_MASK,
-
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-
BQ24190_REG_POC_CHG_CONFIG_CHARGE);

drivers/power/supply/bq24190_charger.c +1 -3
-       }
-       if (ret)
-               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
+       /* Set OTG 5V boost: on if no charger detected and in USB host

mode, else off */

drivers/power/supply/bq24190_charger.c +4 -0
+       error = bq24190_write_mask(bdi, BQ24190_REG_POC,
+                                  BQ24190_REG_POC_CHG_CONFIG_MASK,
+                                  BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+                       !iinlim && extcon_get_state(bdi->extcon,

EXTCON_USB_HOST) == 1

drivers/power/supply/bq24190_charger.c +4 -0
+                                ? BQ24190_REG_POC_CHG_CONFIG_OTG
+                                : BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+       if (error < 0)
+               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 9 lines
Quoted 2 lines
        pm_runtime_mark_last_busy(bdi->dev);
        pm_runtime_put_autosuspend(bdi->dev);

I still find the refactored code you're proposing here a lot less readable
then the original code, and the same goes for the comment. If you insist in changing this, then I suggest changing it into this:

Quoted 1 line

OK. I'll collapse the comment to one line tho.

Please don't having this as 2 lines really is not a problem in any way and I find the longer comment a lot easier to parse.

Quoted 49 lines
Quoted 36 lines

/*
* If no charger has been detected and host mode is requested,
activate

         * the 5V boost converter, otherwise deactivate it.
         */
        if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) ==
1)
                chg_config = BQ24190_REG_POC_CHG_CONFIG_OTG;
        else
                chg_config = BQ24190_REG_POC_CHG_CONFIG_CHARGE;

        error = bq24190_write_mask(bdi, BQ24190_REG_POC,
                                   BQ24190_REG_POC_CHG_CONFIG_MASK,
                                   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
                                   chg_config);
        if (error)
                dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 10 lines
drivers/power/supply/bq24190_charger.c +2 -2
@@ -1432,8 +1427,8 @@ static int bq24190_probe(struct i2c_client
 *client,
        }
 
        /*
-        * The extcon-name property is purely an in kernel interface for
-        * x86/ACPI use, DT platforms should get extcon via phandle.
+        * ACPI platforms should use device_property "extcon-name".
+        * Devicetree platforms should get extcon via phandle (not yet

supported).

Quoted 4 lines
         */
        if (device_property_read_string(dev, "extcon-name", &name) == 0)
{
                bdi->extcon = extcon_get_extcon_dev(name);
Quoted 5 lines

The new comment suggest that extcon-name is something which should actually
be used inside ACPI DSDT tables, which it is not, please leave the comment
as is.

OK, right. But "in kernel interface" sounds official, and this is really a custom msg passing method. A platform-data struct is documented in a header, and a module parameter has its own docs scheme; and use of those methods is well documented. I can't tell how I would invoke this one. How about this...

Quoted 6 lines
Quoted 1 line

A Devicetree should provide extcon-name via phandle (not yet supported).

No a devicetree should not provide a name it would provide a phandle pointing to the extcon, no name (and name based lookup) should be involved.

OK.

Quoted 9 lines
Quoted 2 lines

ACPI extcon drivers/clients[?] should insert[?] device_property extcon-name into our device with relevant_api_call(args).

For an example of how this is used see:

https://github.com/jwrdegoede/linux-sunxi/commit/7fa4460e2a18a3f6ffb39ae4940fee1dd2a880a4

Around line 214 of i2c-cht-wc.c and later.

So a comment like...

Quoted 8 lines

On ACPI platforms, extcon clients should invoke this driver with:
struct i2c_adapter a = { ... };
i2c_add_adapter(&a);
struct property_entry pe[] = { PROPERTY_ENTRY_STRING("extcon-name", <name>), ... };
struct i2c_board_info bi = { .type = "bq24190", .addr = 0x6b, .properties = pe, .irq = <irq> };
i2c_new_device(&a, &bi);

Sure that works for me.

Regards,

Hans

#18 lore raw

Re: [PATCH v4 4/4] power: bq24190_charger: Delay before polling reset flag

In reply to Liam Breck

Hi,

Quoted 46 lines · Liam Breck
Quoted 41 lines · Hans de Goede

Hi,

Quoted 23 lines · Liam Breck

Hi Hans,

Quoted 8 lines · Hans de Goede

Hi,

Quoted 4 lines · Liam Breck

From: Liam Breck <[email protected]>

Quoted 8 lines
Quoted 2 lines

On chip reset, polling loop was reading reset register immediately. Instead, call udelay() before reading chip register.

Can you extend the commit message to explain why udelay is being called ? IOW what is the problem with reading the register immediately which this patch addresses ?

Quoted 4 lines

I thought I'd read that reset isn't instantaneous, but in testing it seems to be. So I will revert to the original post-reset delay, and change udelay() to usleep_range(10, 20). Any thoughts on those numbers?

Using usleep makes no sense for such short delays, so I would stick with udelay.

More importantly you still have not explained why we need to delay *at all* esp. such a short delay, 10us is a single bit at 100kHz i2c so the set bq24190 register-pointer part of the i2c transfer which happens before reading back the reset-bit alone takes 20 times as long as the delay.

Quoted 3 lines

I still don't understand why a delay is needed at all, what are you trying to achieve with this delay ? Are you seeing a specific problem you are trying to fix ?

Quoted 6 lines

A loop with udelay(10) was in the code already, because at manual 9.5.1.2 the note for bit 7 says "Back to 0 after register reset".

But I think you're right, we don't need to loop checking this; I'll just return -EIO (?) if bit 7 isn't 0 -- which presumably means charger is kaput.

Having a loop to check for this is not unusual, I think it would be fine to just keep the code as is unless you've a specific reason to change it.

Regards,

Hans

Quoted 52 lines
Quoted 52 lines
Quoted 51 lines
Quoted 51 lines
Quoted 50 lines
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -6
index fa29cb3..71a796e 100644
@@ -543,18 +543,14 @@ static int bq24190_register_reset(struct
 bq24190_dev_info *bdi)
 
        /* Reset bit will be cleared by hardware so poll until it is */
        do {
+               udelay(10);
                ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
                                BQ24190_REG_POC_RESET_MASK,
                                BQ24190_REG_POC_RESET_SHIFT,
                                &v);
                if (ret < 0)
                        return ret;
-
-               if (!v)
-                       break;
-
-               udelay(10);
-       } while (--limit);
+       } while (v && --limit);
 
        if (!limit)
                return -EIO;
author
#19 lore raw

Re: [PATCH v4 4/4] power: bq24190_charger: Delay before polling reset flag

Quoted 62 lines · Hans de Goede

Hi,

Quoted 58 lines · Liam Breck
Quoted 48 lines · Hans de Goede

Hi,

Quoted 28 lines · Liam Breck

Hi Hans,

Quoted 16 lines · Hans de Goede

Hi,

Quoted 7 lines · Liam Breck

From: Liam Breck <[email protected]>

On chip reset, polling loop was reading reset register immediately. Instead, call udelay() before reading chip register.

Quoted 3 lines

Can you extend the commit message to explain why udelay is being called ? IOW what is the problem with reading the register immediately which this patch addresses ?

Quoted 4 lines

I thought I'd read that reset isn't instantaneous, but in testing it seems to be. So I will revert to the original post-reset delay, and change udelay() to usleep_range(10, 20). Any thoughts on those numbers?

Using usleep makes no sense for such short delays, so I would stick with udelay.

More importantly you still have not explained why we need to delay *at all* esp. such a short delay, 10us is a single bit at 100kHz i2c so the set bq24190 register-pointer part of the i2c transfer which happens before reading back the reset-bit alone takes 20 times as long as the delay.

Quoted 3 lines

I still don't understand why a delay is needed at all, what are you trying to achieve with this delay ? Are you seeing a specific problem you are trying to fix ?

A loop with udelay(10) was in the code already, because at manual 9.5.1.2 the note for bit 7 says "Back to 0 after register reset".

Quoted 8 lines
Quoted 3 lines

But I think you're right, we don't need to loop checking this; I'll just return -EIO (?) if bit 7 isn't 0 -- which presumably means charger is kaput.

Having a loop to check for this is not unusual, I think it would be fine to just keep the code as is unless you've a specific reason to change it.

Well you did point out that the delay is too short to be useful. Our bus runs at 400kHz, and we retry 100x, so we can wait 400 clicks (1ms). We should probably wait longer or not at all.

Quoted 59 lines
Quoted 58 lines
Quoted 58 lines
Quoted 57 lines
Quoted 57 lines
Quoted 56 lines
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -6
index fa29cb3..71a796e 100644
@@ -543,18 +543,14 @@ static int bq24190_register_reset(struct
 bq24190_dev_info *bdi)
 
        /* Reset bit will be cleared by hardware so poll until it is
 */
        do {
+               udelay(10);
                ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
                                BQ24190_REG_POC_RESET_MASK,
                                BQ24190_REG_POC_RESET_SHIFT,
                                &v);
                if (ret < 0)
                        return ret;
-
-               if (!v)
-                       break;
-
-               udelay(10);
-       } while (--limit);
+       } while (v && --limit);
 
        if (!limit)
                return -EIO;
#20 lore raw

Re: [PATCH v4 4/4] power: bq24190_charger: Delay before polling reset flag

Hi,

Quoted 68 lines · Liam Breck
Quoted 67 lines · Hans de Goede

Hi,

Quoted 61 lines · Liam Breck
Quoted 48 lines · Hans de Goede

Hi,

Quoted 28 lines · Liam Breck

Hi Hans,

Quoted 16 lines · Hans de Goede

Hi,

Quoted 7 lines · Liam Breck

From: Liam Breck <[email protected]>

On chip reset, polling loop was reading reset register immediately. Instead, call udelay() before reading chip register.

Quoted 3 lines

Can you extend the commit message to explain why udelay is being called ? IOW what is the problem with reading the register immediately which this patch addresses ?

Quoted 4 lines

I thought I'd read that reset isn't instantaneous, but in testing it seems to be. So I will revert to the original post-reset delay, and change udelay() to usleep_range(10, 20). Any thoughts on those numbers?

Using usleep makes no sense for such short delays, so I would stick with udelay.

More importantly you still have not explained why we need to delay *at all* esp. such a short delay, 10us is a single bit at 100kHz i2c so the set bq24190 register-pointer part of the i2c transfer which happens before reading back the reset-bit alone takes 20 times as long as the delay.

Quoted 3 lines

I still don't understand why a delay is needed at all, what are you trying to achieve with this delay ? Are you seeing a specific problem you are trying to fix ?

A loop with udelay(10) was in the code already, because at manual 9.5.1.2 the note for bit 7 says "Back to 0 after register reset".

But I think you're right, we don't need to loop checking this; I'll just return -EIO (?) if bit 7 isn't 0 -- which presumably means charger is kaput.

Quoted 7 lines
Quoted 3 lines

Having a loop to check for this is not unusual, I think it would be fine to just keep the code as is unless you've a specific reason to change it.

Well you did point out that the delay is too short to be useful. Our bus runs at 400kHz, and we retry 100x, so we can wait 400 clicks (1ms). We should probably wait longer or not at all.

Ok, either way is fine by me.

Regards,

Hans

Quoted 60 lines
Quoted 60 lines
Quoted 59 lines
Quoted 59 lines
Quoted 58 lines
Quoted 58 lines
Quoted 57 lines
Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -6
index fa29cb3..71a796e 100644
@@ -543,18 +543,14 @@ static int bq24190_register_reset(struct
 bq24190_dev_info *bdi)
 
        /* Reset bit will be cleared by hardware so poll until it is
 */
        do {
+               udelay(10);
                ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
                                BQ24190_REG_POC_RESET_MASK,
                                BQ24190_REG_POC_RESET_SHIFT,
                                &v);
                if (ret < 0)
                        return ret;
-
-               if (!v)
-                       break;
-
-               udelay(10);
-       } while (--limit);
+       } while (v && --limit);
 
        if (!limit)
                return -EIO;
author
#9 lore raw

Re: [PATCH v4 2/4] power: bq24190_charger: Clean up extcon code

In reply to Hans de Goede
Quoted 174 lines · Hans de Goede

Hi,

Quoted 160 lines · Liam Breck
Quoted 132 lines · Hans de Goede

Hi,

Quoted 6 lines · Liam Breck

Hallo Hans,

On Thu, Apr 6, 2017 at 12:17 AM, Hans de Goede <[email protected]> wrote:

<snip>

Quoted 53 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +0 -2
-       /*
-        * If no charger has been detected and host mode is requested,

activate

drivers/power/supply/bq24190_charger.c +0 -3
-        * the 5V boost converter, otherwise deactivate it.
-        */
-       if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST)

==
1) {

(quoted diff) +0 -2
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-

BQ24190_REG_POC_CHG_CONFIG_MASK,
-
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-
BQ24190_REG_POC_CHG_CONFIG_OTG);

drivers/power/supply/bq24190_charger.c +0 -3
-       } else {
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-

BQ24190_REG_POC_CHG_CONFIG_MASK,
-
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-
BQ24190_REG_POC_CHG_CONFIG_CHARGE);

drivers/power/supply/bq24190_charger.c +1 -3
-       }
-       if (ret)
-               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
+       /* Set OTG 5V boost: on if no charger detected and in USB host

mode, else off */

drivers/power/supply/bq24190_charger.c +4 -0
+       error = bq24190_write_mask(bdi, BQ24190_REG_POC,
+                                  BQ24190_REG_POC_CHG_CONFIG_MASK,
+                                  BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+                       !iinlim && extcon_get_state(bdi->extcon,

EXTCON_USB_HOST) == 1

drivers/power/supply/bq24190_charger.c +4 -0
+                                ? BQ24190_REG_POC_CHG_CONFIG_OTG
+                                : BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+       if (error < 0)
+               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n",

error);

Quoted 11 lines
Quoted 2 lines
        pm_runtime_mark_last_busy(bdi->dev);
        pm_runtime_put_autosuspend(bdi->dev);

I still find the refactored code you're proposing here a lot less readable
then the original code, and the same goes for the comment. If you insist
in changing this, then I suggest changing it into this:

Quoted 1 line

OK. I'll collapse the comment to one line tho.

Please don't having this as 2 lines really is not a problem in any way and
I find the longer comment a lot easier to parse.

Quoted 54 lines
Quoted 40 lines

/*
* If no charger has been detected and host mode is requested,
activate

         * the 5V boost converter, otherwise deactivate it.
         */
        if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST)
==
1)
                chg_config = BQ24190_REG_POC_CHG_CONFIG_OTG;
        else
                chg_config = BQ24190_REG_POC_CHG_CONFIG_CHARGE;

        error = bq24190_write_mask(bdi, BQ24190_REG_POC,
                                   BQ24190_REG_POC_CHG_CONFIG_MASK,
                                   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
                                   chg_config);
        if (error)
                dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 11 lines
(quoted diff) +0 -1
@@ -1432,8 +1427,8 @@ static int bq24190_probe(struct i2c_client
 *client,
        }
 
        /*
-        * The extcon-name property is purely an in kernel interface

for

drivers/power/supply/bq24190_charger.c +2 -1
-        * x86/ACPI use, DT platforms should get extcon via phandle.
+        * ACPI platforms should use device_property "extcon-name".
+        * Devicetree platforms should get extcon via phandle (not yet

supported).

Quoted 5 lines
         */
        if (device_property_read_string(dev, "extcon-name", &name) ==
0)
{
                bdi->extcon = extcon_get_extcon_dev(name);
Quoted 5 lines

The new comment suggest that extcon-name is something which should actually
be used inside ACPI DSDT tables, which it is not, please leave the comment
as is.

OK, right. But "in kernel interface" sounds official, and this is really a custom msg passing method. A platform-data struct is documented in a header, and a module parameter has its own docs scheme; and use of those methods is well documented. I can't tell how I would invoke this one. How about this...

Quoted 7 lines
Quoted 1 line

A Devicetree should provide extcon-name via phandle (not yet supported).

No a devicetree should not provide a name it would provide a phandle pointing to the extcon, no name (and name based lookup) should be involved.

OK.

Quoted 11 lines
Quoted 2 lines

ACPI extcon drivers/clients[?] should insert[?] device_property extcon-name into our device with relevant_api_call(args).

For an example of how this is used see:

https://github.com/jwrdegoede/linux-sunxi/commit/7fa4460e2a18a3f6ffb39ae4940fee1dd2a880a4

Around line 214 of i2c-cht-wc.c and later.

So a comment like...

Quoted 8 lines

On ACPI platforms, extcon clients should invoke this driver with:
struct i2c_adapter a = { ... };
i2c_add_adapter(&a);
struct property_entry pe[] = { PROPERTY_ENTRY_STRING("extcon-name", <name>), ... };
struct i2c_board_info bi = { .type = "bq24190", .addr = 0x6b, .properties = pe, .irq = <irq> };
i2c_new_device(&a, &bi);

Quoted 1 line

Sure that works for me.

Should we export a function from the charger driver to do the above, rather than requiring every client driver to replicate it?

#10 lore raw

Re: [PATCH v4 2/4] power: bq24190_charger: Clean up extcon code

Hi,

Quoted 175 lines · Liam Breck
Quoted 174 lines · Hans de Goede

Hi,

Quoted 168 lines · Liam Breck
Quoted 132 lines · Hans de Goede

Hi,

Quoted 6 lines · Liam Breck

Hallo Hans,

On Thu, Apr 6, 2017 at 12:17 AM, Hans de Goede <[email protected]> wrote:

<snip>

Quoted 53 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +0 -2
-       /*
-        * If no charger has been detected and host mode is requested,

activate

(quoted diff) +0 -3
-        * the 5V boost converter, otherwise deactivate it.
-        */
-       if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST)

==
1) {

(quoted diff) +0 -2
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-

BQ24190_REG_POC_CHG_CONFIG_MASK,
-
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-
BQ24190_REG_POC_CHG_CONFIG_OTG);

(quoted diff) +0 -3
-       } else {
-               ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
-

BQ24190_REG_POC_CHG_CONFIG_MASK,
-
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
-
BQ24190_REG_POC_CHG_CONFIG_CHARGE);

(quoted diff) +1 -3
-       }
-       if (ret)
-               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
+       /* Set OTG 5V boost: on if no charger detected and in USB host

mode, else off */

(quoted diff) +4 -0
+       error = bq24190_write_mask(bdi, BQ24190_REG_POC,
+                                  BQ24190_REG_POC_CHG_CONFIG_MASK,
+                                  BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+                       !iinlim && extcon_get_state(bdi->extcon,

EXTCON_USB_HOST) == 1

(quoted diff) +4 -0
+                                ? BQ24190_REG_POC_CHG_CONFIG_OTG
+                                : BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+       if (error < 0)
+               dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n",

error);

Quoted 11 lines
Quoted 2 lines
        pm_runtime_mark_last_busy(bdi->dev);
        pm_runtime_put_autosuspend(bdi->dev);

I still find the refactored code you're proposing here a lot less readable
then the original code, and the same goes for the comment. If you insist
in changing this, then I suggest changing it into this:

Quoted 1 line

OK. I'll collapse the comment to one line tho.

Please don't having this as 2 lines really is not a problem in any way and
I find the longer comment a lot easier to parse.

Quoted 54 lines
Quoted 40 lines

/*
* If no charger has been detected and host mode is requested,
activate

         * the 5V boost converter, otherwise deactivate it.
         */
        if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST)
==
1)
                chg_config = BQ24190_REG_POC_CHG_CONFIG_OTG;
        else
                chg_config = BQ24190_REG_POC_CHG_CONFIG_CHARGE;

        error = bq24190_write_mask(bdi, BQ24190_REG_POC,
                                   BQ24190_REG_POC_CHG_CONFIG_MASK,
                                   BQ24190_REG_POC_CHG_CONFIG_SHIFT,
                                   chg_config);
        if (error)
                dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
Quoted 11 lines
(quoted diff) +0 -1
@@ -1432,8 +1427,8 @@ static int bq24190_probe(struct i2c_client
 *client,
        }
 
        /*
-        * The extcon-name property is purely an in kernel interface

for

(quoted diff) +2 -1
-        * x86/ACPI use, DT platforms should get extcon via phandle.
+        * ACPI platforms should use device_property "extcon-name".
+        * Devicetree platforms should get extcon via phandle (not yet

supported).

Quoted 5 lines
         */
        if (device_property_read_string(dev, "extcon-name", &name) ==
0)
{
                bdi->extcon = extcon_get_extcon_dev(name);
Quoted 5 lines

The new comment suggest that extcon-name is something which should actually
be used inside ACPI DSDT tables, which it is not, please leave the comment
as is.

OK, right. But "in kernel interface" sounds official, and this is really a custom msg passing method. A platform-data struct is documented in a header, and a module parameter has its own docs scheme; and use of those methods is well documented. I can't tell how I would invoke this one. How about this...

Quoted 7 lines
Quoted 1 line

A Devicetree should provide extcon-name via phandle (not yet supported).

No a devicetree should not provide a name it would provide a phandle pointing to the extcon, no name (and name based lookup) should be involved.

OK.

Quoted 11 lines
Quoted 2 lines

ACPI extcon drivers/clients[?] should insert[?] device_property extcon-name into our device with relevant_api_call(args).

For an example of how this is used see:

https://github.com/jwrdegoede/linux-sunxi/commit/7fa4460e2a18a3f6ffb39ae4940fee1dd2a880a4

Around line 214 of i2c-cht-wc.c and later.

So a comment like...

On ACPI platforms, extcon clients should invoke this driver with:
struct i2c_adapter a = { ... };
i2c_add_adapter(&a);
struct property_entry pe[] = { PROPERTY_ENTRY_STRING("extcon-name", <name>), ... };
struct i2c_board_info bi = { .type = "bq24190", .addr = 0x6b, .properties = pe, .irq = <irq> };
i2c_new_device(&a, &bi);

Quoted 4 lines
Quoted 1 line

Sure that works for me.

Should we export a function from the charger driver to do the above, rather than requiring every client driver to replicate it?

If we end up needing to do this in more places, then we could consider making iinlim a property and adding something generic for this to the power_supply core. But that is something to do when we've at least 2 users, I've a feeling this will look different per use-case (what about e.g. the 5v boost converter?) so we really need a better idea of what a generic solution should look like before writing one.

Regards,

Hans