Skip to contentSkip to conversation

BQ24190 devicetree config

PATCH Superseded Liam Breck 6 participants 17 messages Aug 7, 2017 – Aug 25, 2017 4 messages not in the archive

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author
#3 lore raw

PATCH v2 2/5 devicetree: power: Add docs for TI BQ24190 battery charger

In reply to Liam Breck

From: Liam Breck <[email protected]>

Document monitored-battery and ti,system-minimum-microvolt properties.

---
 .../devicetree/bindings/power/supply/bq24190.txt   | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq24190.txt
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +49 -0
new file mode 100644
index 00000000..82a1c842
@@ -0,0 +1,49 @@
+TI BQ24190 Li-Ion Battery Charger
+
+Required properties:
+- compatible: contains one of the following:
+    * "ti,bq24190"
+    * "ti,bq24192i"
+- reg: integer, I2C address of the charger.
+- interrupts[-extended]: configuration for charger INT pin.
+
+Optional properties:
+- monitored-battery: phandle of battery characteristics devicetree node
+    The charger uses the following battery properties:
+    + precharge-current-microamp: maximum charge current during precharge
+      phase (typically 20% of battery capacity).
+    + charge-term-current-microamp: a charge cycle terminates when the
+      battery voltage is above recharge threshold, and the current is below
+      this setting (typically 10% of battery capacity).
+    See Documentation/devicetree/bindings/power/supply/battery.txt
+- ti,system-minimum-microvolt: when power is connected and the battery is below
+    minimum system voltage, the system will be regulated above this setting.
+
+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.
+
+Example:
+
+	bat: battery {
+		compatible = "simple-battery";
+		precharge-current-microamp = <256000>;
+		charge-term-current-microamp = <128000>;
+		// etc.
+	};
+
+	bq24190: charger@6a {
+		compatible = "ti,bq24190";
+		reg = <0x6a>;
+		interrupts-extended = <&gpiochip 10 IRQ_TYPE_EDGE_FALLING>;
+		monitored-battery = <&bat>;
+		ti,system-minimum-microvolt = <3200000>;
+	};
+
+	&twl_gpio {
+		otg {
+			gpio-hog;
+			gpios = <6 0>;
+			output-high;
+			line-name = "otg-gpio";
+		};
+	};
Signature · 1 line
2.13.2

Liam Breck

author
#0 lore raw

v2 cover BQ24190 devicetree config

Hi Sebastian, here is this series that was waiting on the power_supply_battery_info patchset. Thanks!

Overview:
BQ24190 uses power_supply_battery_info fields for precharge & charge-termination current and a DT property for system min voltage. A new DT binding documents these.

Changes in v2:
* new patch adds bq24192i to DT table
* dropped patches for power_supply precharge-current; they moved to bq27xxx series
* dropped patches for recently-applied fixes
* rebased to -next

Issues in v1:
* power_supply_prop_precharge & endcharge are added at end of enum to avoid sysfs breakage
* "Set bq24190-battery device .type=unknown" is a temporary workaround to be fixed in v2

Liam Breck (5):
power: bq24190_charger: Add ti,bq24192i to devicetree table
devicetree: power: Add docs for TI BQ24190 battery charger
power: bq24190_charger: Enable devicetree config
power: bq24190_charger: Add property system-minimum-microvolt
power: bq24190_charger: Add power_supply_battery_info support

 .../devicetree/bindings/power/supply/bq24190.txt   |  49 ++++++
 drivers/power/supply/bq24190_charger.c             | 177 ++++++++++++++++++---
 2 files changed, 203 insertions(+), 23 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq24190.txt
Signature · 1 line
2.13.2
author
#1 lore raw

PATCH v2 1/5 power: bq24190_charger: Add ti,bq24192i to devicetree table

From: Liam Breck <[email protected]>

bq24192i was previously only in ID table, so add it to DT table.

Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/power/supply/bq24190_charger.c +2 -3
index 14199561..3340ffa2 100644
@@ -1732,13 +1732,12 @@ MODULE_DEVICE_TABLE(i2c, bq24190_i2c_ids);
 #ifdef CONFIG_OF
 static const struct of_device_id bq24190_of_match[] = {
 	{ .compatible = "ti,bq24190", },
+	{ .compatible = "ti,bq24192i", },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, bq24190_of_match);
 #else
-static const struct of_device_id bq24190_of_match[] = {
-	{ },
-};
+static const struct of_device_id bq24190_of_match[] = { {} };
 #endif
 
 static struct i2c_driver bq24190_driver = {
Signature · 1 line
2.13.2
author
#18 lore raw

PATCH v2 3/5 power: bq24190_charger: Enable devicetree config

In reply to Liam Breck

From: Liam Breck <[email protected]>

Add get_config(). Rename set_mode_host() to set_config(). Call get_config() and hw_init() after power_supply_register(). No functional changes.

Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 63 +++++++++++++++++++++++-----------
 1 file changed, 43 insertions(+), 20 deletions(-)
drivers/power/supply/bq24190_charger.c +43 -20
index 3340ffa2..2ab580bf 100644
@@ -504,15 +504,7 @@ static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi)
 static inline void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi) {}
 #endif
 
-/*
- * According to the "Host Mode and default Mode" section of the
- * manual, a write to any register causes the bq24190 to switch
- * from default mode to host mode.  It will switch back to default
- * mode after a WDT timeout unless the WDT is turned off as well.
- * So, by simply turning off the WDT, we accomplish both with the
- * same write.
- */
-static int bq24190_set_mode_host(struct bq24190_dev_info *bdi)
+static int bq24190_set_config(struct bq24190_dev_info *bdi)
 {
 	int ret;
 	u8 v;
@@ -523,9 +515,22 @@ static int bq24190_set_mode_host(struct bq24190_dev_info *bdi)
 
 	bdi->watchdog = ((v & BQ24190_REG_CTTC_WATCHDOG_MASK) >>
 					BQ24190_REG_CTTC_WATCHDOG_SHIFT);
+
+	/*
+	 * According to the "Host Mode and default Mode" section of the
+	 * manual, a write to any register causes the bq24190 to switch
+	 * from default mode to host mode.  It will switch back to default
+	 * mode after a WDT timeout unless the WDT is turned off as well.
+	 * So, by simply turning off the WDT, we accomplish both with the
+	 * same write.
+	 */
 	v &= ~BQ24190_REG_CTTC_WATCHDOG_MASK;
 
-	return bq24190_write(bdi, BQ24190_REG_CTTC, v);
+	ret = bq24190_write(bdi, BQ24190_REG_CTTC, v);
+	if (ret < 0)
+		return ret;
+
+	return 0;
 }
 
 static int bq24190_register_reset(struct bq24190_dev_info *bdi)
@@ -1456,13 +1461,25 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)
 	if (ret < 0)
 		return ret;
 
-	ret = bq24190_set_mode_host(bdi);
+	ret = bq24190_set_config(bdi);
 	if (ret < 0)
 		return ret;
 
 	return bq24190_read(bdi, BQ24190_REG_SS, &bdi->ss_reg);
 }
 
+static int bq24190_get_config(struct bq24190_dev_info *bdi)
+{
+#ifdef CONFIG_OF
+	int v;
+
+	if (!bdi->dev->of_node)
+		return -EINVAL;
+
+#endif
+	return 0;
+}
+
 static int bq24190_probe(struct i2c_client *client,
 		const struct i2c_device_id *id)
 {
@@ -1493,7 +1510,7 @@ static int bq24190_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, bdi);
 
-	if (!client->irq) {
+	if (client->irq <= 0) {
 		dev_err(dev, "Can't get irq info\n");
 		return -EINVAL;
 	}
@@ -1526,12 +1543,6 @@ static int bq24190_probe(struct i2c_client *client,
 		goto out_pmrt;
 	}
 
-	ret = bq24190_hw_init(bdi);
-	if (ret < 0) {
-		dev_err(dev, "Hardware init failed\n");
-		goto out_pmrt;
-	}
-
 	charger_cfg.drv_data = bdi;
 	charger_cfg.supplied_to = bq24190_charger_supplied_to;
 	charger_cfg.num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to),
@@ -1556,8 +1567,20 @@ static int bq24190_probe(struct i2c_client *client,
 		}
 	}
 
+	ret = bq24190_get_config(bdi);
+	if (ret < 0) {
+		dev_err(dev, "Can't get devicetree config\n");
+		goto out_charger;
+	}
+
+	ret = bq24190_hw_init(bdi);
+	if (ret < 0) {
+		dev_err(dev, "Hardware init failed\n");
+		goto out_charger;
+	}
+
 	ret = bq24190_sysfs_create_group(bdi);
-	if (ret) {
+	if (ret < 0) {
 		dev_err(dev, "Can't create sysfs entries\n");
 		goto out_charger;
 	}
@@ -1700,7 +1723,7 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)
 	}
 
 	bq24190_register_reset(bdi);
-	bq24190_set_mode_host(bdi);
+	bq24190_set_config(bdi);
 	bq24190_read(bdi, BQ24190_REG_SS, &bdi->ss_reg);
 
 	if (error >= 0) {
Signature · 1 line
2.13.2
author
#19 lore raw

PATCH v2 4/5 power: bq24190_charger: Add property system-minimum-microvolt

In reply to Liam Breck

From: Liam Breck <[email protected]>

Set minimum system voltage limit obtained from device property.

Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/power/supply/bq24190_charger.c +23 -0
index 2ab580bf..f20d2c68 100644
@@ -43,6 +43,8 @@
 #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_SYS_MIN_MIN			3000
+#define BQ24190_REG_POC_SYS_MIN_MAX			3700
 #define BQ24190_REG_POC_BOOST_LIM_MASK		BIT(0)
 #define BQ24190_REG_POC_BOOST_LIM_SHIFT		0
 
@@ -159,6 +161,7 @@ struct bq24190_dev_info {
 	char				model_name[I2C_NAME_SIZE];
 	bool				initialized;
 	bool				irq_event;
+	u16				sys_min;
 	struct mutex			f_reg_lock;
 	u8				f_reg;
 	u8				ss_reg;
@@ -530,6 +533,16 @@ static int bq24190_set_config(struct bq24190_dev_info *bdi)
 	if (ret < 0)
 		return ret;
 
+	if (bdi->sys_min) {
+		v = bdi->sys_min / 100 - 30; // manual section 9.5.1.2, table 9
+		ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
+					 BQ24190_REG_POC_SYS_MIN_MASK,
+					 BQ24190_REG_POC_SYS_MIN_SHIFT,
+					 v);
+		if (ret < 0)
+			return ret;
+	}
+
 	return 0;
 }
 
@@ -1471,11 +1484,21 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)
 static int bq24190_get_config(struct bq24190_dev_info *bdi)
 {
 #ifdef CONFIG_OF
+	const char * const s = "ti,system-minimum-microvolt";
 	int v;
 
 	if (!bdi->dev->of_node)
 		return -EINVAL;
 
+	if (device_property_read_u32(bdi->dev, s, &v) == 0) {
+		v /= 1000;
+		if (v >= BQ24190_REG_POC_SYS_MIN_MIN
+		 && v <= BQ24190_REG_POC_SYS_MIN_MAX)
+			bdi->sys_min = v;
+		else
+			dev_warn(bdi->dev, "invalid value for %s: %u\n", s, v);
+	}
+
 #endif
 	return 0;
 }
Signature · 1 line
2.13.2
author
#20 lore raw

PATCH v2 5/5 power: bq24190_charger: Add power_supply_battery_info support

In reply to Liam Breck

From: Liam Breck <[email protected]>

Set pre-charge and charge-term current, obtained from power_supply_battery_info. Add sysfs attributes precharge_current & charge_term_current.

Cc Tony Lindgren <[email protected]>
Cc Hans de Goede <[email protected]>
---
 drivers/power/supply/bq24190_charger.c | 86 ++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
drivers/power/supply/bq24190_charger.c +86 -0
index f20d2c68..8a2120cc 100644
@@ -59,9 +59,13 @@
 #define BQ24190_REG_PCTCC_IPRECHG_MASK		(BIT(7) | BIT(6) | BIT(5) | \
 						 BIT(4))
 #define BQ24190_REG_PCTCC_IPRECHG_SHIFT		4
+#define BQ24190_REG_PCTCC_IPRECHG_MIN			128
+#define BQ24190_REG_PCTCC_IPRECHG_MAX			2048
 #define BQ24190_REG_PCTCC_ITERM_MASK		(BIT(3) | BIT(2) | BIT(1) | \
 						 BIT(0))
 #define BQ24190_REG_PCTCC_ITERM_SHIFT		0
+#define BQ24190_REG_PCTCC_ITERM_MIN			128
+#define BQ24190_REG_PCTCC_ITERM_MAX			2048
 
 #define BQ24190_REG_CVC		0x04 /* Charge Voltage Control */
 #define BQ24190_REG_CVC_VREG_MASK		(BIT(7) | BIT(6) | BIT(5) | \
@@ -162,6 +166,8 @@ struct bq24190_dev_info {
 	bool				initialized;
 	bool				irq_event;
 	u16				sys_min;
+	u16				iprechg;
+	u16				iterm;
 	struct mutex			f_reg_lock;
 	u8				f_reg;
 	u8				ss_reg;
@@ -543,6 +549,26 @@ static int bq24190_set_config(struct bq24190_dev_info *bdi)
 			return ret;
 	}
 
+	if (bdi->iprechg) {
+		v = bdi->iprechg / 128 - 1; // manual section 9.5.1.4, table 11
+		ret = bq24190_write_mask(bdi, BQ24190_REG_PCTCC,
+					 BQ24190_REG_PCTCC_IPRECHG_MASK,
+					 BQ24190_REG_PCTCC_IPRECHG_SHIFT,
+					 v);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (bdi->iterm) {
+		v = bdi->iterm / 128 - 1; // manual section 9.5.1.4, table 11
+		ret = bq24190_write_mask(bdi, BQ24190_REG_PCTCC,
+					 BQ24190_REG_PCTCC_ITERM_MASK,
+					 BQ24190_REG_PCTCC_ITERM_SHIFT,
+					 v);
+		if (ret < 0)
+			return ret;
+	}
+
 	return 0;
 }
 
@@ -787,6 +813,38 @@ static int bq24190_charger_set_temp_alert_max(struct bq24190_dev_info *bdi,
 	return bq24190_battery_set_temp_alert_max(bdi, val);
 }
 
+static int bq24190_charger_get_precharge(struct bq24190_dev_info *bdi,
+		union power_supply_propval *val)
+{
+	u8 v;
+	int ret;
+
+	ret = bq24190_read_mask(bdi, BQ24190_REG_PCTCC,
+			BQ24190_REG_PCTCC_IPRECHG_MASK,
+			BQ24190_REG_PCTCC_IPRECHG_SHIFT, &v);
+	if (ret < 0)
+		return ret;
+
+	val->intval = ++v * 128 * 1000;
+	return 0;
+}
+
+static int bq24190_charger_get_charge_term(struct bq24190_dev_info *bdi,
+		union power_supply_propval *val)
+{
+	u8 v;
+	int ret;
+
+	ret = bq24190_read_mask(bdi, BQ24190_REG_PCTCC,
+			BQ24190_REG_PCTCC_ITERM_MASK,
+			BQ24190_REG_PCTCC_ITERM_SHIFT, &v);
+	if (ret < 0)
+		return ret;
+
+	val->intval = ++v * 128 * 1000;
+	return 0;
+}
+
 static int bq24190_charger_get_current(struct bq24190_dev_info *bdi,
 		union power_supply_propval *val)
 {
@@ -907,6 +965,12 @@ static int bq24190_charger_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
 		ret =  bq24190_charger_get_temp_alert_max(bdi, val);
 		break;
+	case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
+		ret = bq24190_charger_get_precharge(bdi, val);
+		break;
+	case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
+		ret = bq24190_charger_get_charge_term(bdi, val);
+		break;
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
 		ret = bq24190_charger_get_current(bdi, val);
 		break;
@@ -1006,6 +1070,8 @@ static enum power_supply_property bq24190_charger_properties[] = {
 	POWER_SUPPLY_PROP_ONLINE,
 	POWER_SUPPLY_PROP_STATUS,
 	POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
+	POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
+	POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
@@ -1485,6 +1551,7 @@ static int bq24190_get_config(struct bq24190_dev_info *bdi)
 {
 #ifdef CONFIG_OF
 	const char * const s = "ti,system-minimum-microvolt";
+	struct power_supply_battery_info info = {};
 	int v;
 
 	if (!bdi->dev->of_node)
@@ -1499,6 +1566,24 @@ static int bq24190_get_config(struct bq24190_dev_info *bdi)
 			dev_warn(bdi->dev, "invalid value for %s: %u\n", s, v);
 	}
 
+	if (!power_supply_get_battery_info(bdi->charger, &info)) {
+		v = info.precharge_current_ua / 1000;
+		if (v >= BQ24190_REG_PCTCC_IPRECHG_MIN
+		 && v <= BQ24190_REG_PCTCC_IPRECHG_MAX)
+			bdi->iprechg = v;
+		else
+			dev_warn(bdi->dev, "invalid value for battery:precharge-current-microamp: %d\n",
+				 v);
+
+		v = info.charge_term_current_ua / 1000;
+		if (v >= BQ24190_REG_PCTCC_ITERM_MIN
+		 && v <= BQ24190_REG_PCTCC_ITERM_MAX)
+			bdi->iterm = v;
+		else
+			dev_warn(bdi->dev, "invalid value for battery:charge-term-current-microamp: %d\n",
+				 v);
+	}
+
 #endif
 	return 0;
 }
@@ -1567,6 +1652,7 @@ static int bq24190_probe(struct i2c_client *client,
 	}
 
 	charger_cfg.drv_data = bdi;
+	charger_cfg.of_node = dev->of_node;
 	charger_cfg.supplied_to = bq24190_charger_supplied_to;
 	charger_cfg.num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to),
 	bdi->charger = power_supply_register(dev, &bq24190_charger_desc,
Signature · 1 line
2.13.2
#5 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

In reply to a message not in the archive
Quoted 31 lines · Liam Breck

From: Liam Breck <[email protected]>

Document monitored-battery and ti,system-minimum-microvolt properties.

---
 .../devicetree/bindings/power/supply/bq24190.txt   | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq24190.txt
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +13 -0
new file mode 100644
index 00000000..82a1c842
@@ -0,0 +1,49 @@
+TI BQ24190 Li-Ion Battery Charger
+
+Required properties:
+- compatible: contains one of the following:
+    * "ti,bq24190"
+    * "ti,bq24192i"
+- reg: integer, I2C address of the charger.
+- interrupts[-extended]: configuration for charger INT pin.
+
+Optional properties:
+- monitored-battery: phandle of battery characteristics devicetree node
+    The charger uses the following battery properties:
+    + precharge-current-microamp: maximum charge current during precharge

Documentation/devicetree/bindings/power/supply/bq24190.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +10 -0
+      phase (typically 20% of battery capacity).
+    + charge-term-current-microamp: a charge cycle terminates when the
+      battery voltage is above recharge threshold, and the current is below
+      this setting (typically 10% of battery capacity).
+    See Documentation/devicetree/bindings/power/supply/battery.txt
+- ti,system-minimum-microvolt: when power is connected and the battery is below
+    minimum system voltage, the system will be regulated above this setting.
+
+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.

Why doesn't the charger driver control this?

Quoted 29 lines
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +26 -0
+
+Example:
+
+	bat: battery {
+		compatible = "simple-battery";
+		precharge-current-microamp = <256000>;
+		charge-term-current-microamp = <128000>;
+		// etc.
+	};
+
+	bq24190: charger@6a {
+		compatible = "ti,bq24190";
+		reg = <0x6a>;
+		interrupts-extended = <&gpiochip 10 IRQ_TYPE_EDGE_FALLING>;
+		monitored-battery = <&bat>;
+		ti,system-minimum-microvolt = <3200000>;
+	};
+
+	&twl_gpio {
+		otg {
+			gpio-hog;
+			gpios = <6 0>;
+			output-high;
+			line-name = "otg-gpio";
+		};
+	};
Signature · 1 line
2.13.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#6 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

Hi Rob,

Quoted 36 lines · Rob Herring
Quoted 35 lines · Liam Breck

From: Liam Breck <[email protected]>

Document monitored-battery and ti,system-minimum-microvolt properties.

---
 .../devicetree/bindings/power/supply/bq24190.txt   | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq24190.txt
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +17 -0
new file mode 100644
index 00000000..82a1c842
@@ -0,0 +1,49 @@
+TI BQ24190 Li-Ion Battery Charger
+
+Required properties:
+- compatible: contains one of the following:
+    * "ti,bq24190"
+    * "ti,bq24192i"
+- reg: integer, I2C address of the charger.
+- interrupts[-extended]: configuration for charger INT pin.
+
+Optional properties:
+- monitored-battery: phandle of battery characteristics devicetree node
+    The charger uses the following battery properties:
+    + precharge-current-microamp: maximum charge current during precharge
+      phase (typically 20% of battery capacity).
+    + charge-term-current-microamp: a charge cycle terminates when the
+      battery voltage is above recharge threshold, and the current is below
+      this setting (typically 10% of battery capacity).
Quoted 8 lines

Documentation/devicetree/bindings/power/supply/bq24190.txt line 23

Quoted 6 lines
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +6 -0
+    See Documentation/devicetree/bindings/power/supply/battery.txt
+- ti,system-minimum-microvolt: when power is connected and the battery is below
+    minimum system voltage, the system will be regulated above this setting.
+
+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.

Why doesn't the charger driver control this?

This pin/gpio has to be high when USB is plugged in to make the charger chip negotiate 500mA from a SDP port. It should generally be configured that way even if the driver is not loaded, as the chip does not require a driver to function. Some boards may do that with a pull-up. Also the user may want to change this via sysfs and not have the driver "fix" it.

Quoted 29 lines
Quoted 29 lines
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +26 -1
+
+Example:
+
+     bat: battery {
+             compatible = "simple-battery";
+             precharge-current-microamp = <256000>;
+             charge-term-current-microamp = <128000>;
+             // etc.
+     };
+
+     bq24190: charger@6a {
+             compatible = "ti,bq24190";
+             reg = <0x6a>;
+             interrupts-extended = <&gpiochip 10 IRQ_TYPE_EDGE_FALLING>;
+             monitored-battery = <&bat>;
+             ti,system-minimum-microvolt = <3200000>;
+     };
+
+     &twl_gpio {
+             otg {
+                     gpio-hog;
+                     gpios = <6 0>;
+                     output-high;
+                     line-name = "otg-gpio";
+             };
+     };
--

2.13.2

#7 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

Hi,

Quoted 46 lines · Liam Breck
Quoted 36 lines · Rob Herring
Quoted 35 lines · Liam Breck

From: Liam Breck <[email protected]>

Document monitored-battery and ti,system-minimum-microvolt properties.

---
 .../devicetree/bindings/power/supply/bq24190.txt   | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq24190.txt
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +17 -0
new file mode 100644
index 00000000..82a1c842
@@ -0,0 +1,49 @@
+TI BQ24190 Li-Ion Battery Charger
+
+Required properties:
+- compatible: contains one of the following:
+    * "ti,bq24190"
+    * "ti,bq24192i"
+- reg: integer, I2C address of the charger.
+- interrupts[-extended]: configuration for charger INT pin.
+
+Optional properties:
+- monitored-battery: phandle of battery characteristics devicetree node
+    The charger uses the following battery properties:
+    + precharge-current-microamp: maximum charge current during precharge
+      phase (typically 20% of battery capacity).
+    + charge-term-current-microamp: a charge cycle terminates when the
+      battery voltage is above recharge threshold, and the current is below
+      this setting (typically 10% of battery capacity).
Quoted 8 lines

Documentation/devicetree/bindings/power/supply/bq24190.txt line 23

Quoted 6 lines
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +6 -0
+    See Documentation/devicetree/bindings/power/supply/battery.txt
+- ti,system-minimum-microvolt: when power is connected and the battery is below
+    minimum system voltage, the system will be regulated above this setting.
+
+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.

Why doesn't the charger driver control this?

Quoted 6 lines

This pin/gpio has to be high when USB is plugged in to make the charger chip negotiate 500mA from a SDP port. It should generally be configured that way even if the driver is not loaded, as the chip does not require a driver to function. Some boards may do that with a pull-up. Also the user may want to change this via sysfs and not have the driver "fix" it.

drivers/power/supply/qcom_smbb.c exposes the otg feature as regulator. I think in this case it could be exposed as gpio-regulator.

-- Sebastian

#8 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

Hi Sebastian,

Quoted 56 lines · Sebastian Reichel

Hi,

Quoted 46 lines · Liam Breck
Quoted 36 lines · Rob Herring
Quoted 35 lines · Liam Breck

From: Liam Breck <[email protected]>

Document monitored-battery and ti,system-minimum-microvolt properties.

---
 .../devicetree/bindings/power/supply/bq24190.txt   | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq24190.txt
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +17 -0
new file mode 100644
index 00000000..82a1c842
@@ -0,0 +1,49 @@
+TI BQ24190 Li-Ion Battery Charger
+
+Required properties:
+- compatible: contains one of the following:
+    * "ti,bq24190"
+    * "ti,bq24192i"
+- reg: integer, I2C address of the charger.
+- interrupts[-extended]: configuration for charger INT pin.
+
+Optional properties:
+- monitored-battery: phandle of battery characteristics devicetree node
+    The charger uses the following battery properties:
+    + precharge-current-microamp: maximum charge current during precharge
+      phase (typically 20% of battery capacity).
+    + charge-term-current-microamp: a charge cycle terminates when the
+      battery voltage is above recharge threshold, and the current is below
+      this setting (typically 10% of battery capacity).
Quoted 8 lines

Documentation/devicetree/bindings/power/supply/bq24190.txt line 23

Quoted 6 lines
Documentation/devicetree/bindings/power/supply/bq24190.txt new file +6 -0
+    See Documentation/devicetree/bindings/power/supply/battery.txt
+- ti,system-minimum-microvolt: when power is connected and the battery is below
+    minimum system voltage, the system will be regulated above this setting.
+
+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.

Why doesn't the charger driver control this?

Quoted 6 lines

This pin/gpio has to be high when USB is plugged in to make the charger chip negotiate 500mA from a SDP port. It should generally be configured that way even if the driver is not loaded, as the chip does not require a driver to function. Some boards may do that with a pull-up. Also the user may want to change this via sysfs and not have the driver "fix" it.

Quoted 3 lines

drivers/power/supply/qcom_smbb.c exposes the otg feature as regulator. I think in this case it could be exposed as gpio-regulator.

Hans is doing that here:
https://patchwork.kernel.org/patch/9883717/

The datasheet labels one pin "OTG" but that's misleading; it really enables negotiation of 500mA input current, but does not turn on OTG mode. If this pin is low, it only prevents the driver from starting OTG mode via I2C msg.

Tony & Matt & I discussed this at some length off-list.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

In reply to a message not in the archive
Quoted 18 lines · Liam Breck
Quoted 13 lines · Sebastian Reichel
Quoted 11 lines · Liam Breck
Quoted 4 lines
Quoted 2 lines

+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.

Why doesn't the charger driver control this?

This pin/gpio has to be high when USB is plugged in to make the charger chip negotiate 500mA from a SDP port. It should generally be configured that way even if the driver is not loaded, as the chip does not require a driver to function. Some boards may do that with a pull-up. Also the user may want to change this via sysfs and not have the driver "fix" it.

Quoted 3 lines

drivers/power/supply/qcom_smbb.c exposes the otg feature as regulator. I think in this case it could be exposed as gpio-regulator.

Quoted 7 lines

Hans is doing that here:
https://patchwork.kernel.org/patch/9883717/

The datasheet labels one pin "OTG" but that's misleading; it really enables negotiation of 500mA input current, but does not turn on OTG mode. If this pin is low, it only prevents the driver from starting OTG mode via I2C msg.

Yeah so before the device has enumerated this pin keeps the max current at 100mA as required by the USB spec. This pin should be only toggled after enumerating in bootloader or by the kernel driver. I tink the USB PHY driver can also be wired to control this line.

Probably best to set it up as just a GPIO that the bq24190 driver controls optionally.

Then later on we should have some Linux generic way for USB gadget subsystem to tell the charger that we have enumerated, and then bq24190 driver can toggle this GPIO to enable higher charge rates.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#11 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

Quoted 33 lines · Tony Lindgren
Quoted 18 lines · Liam Breck
Quoted 13 lines · Sebastian Reichel
Quoted 11 lines · Liam Breck
Quoted 4 lines
Quoted 2 lines

+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.

Why doesn't the charger driver control this?

This pin/gpio has to be high when USB is plugged in to make the charger chip negotiate 500mA from a SDP port. It should generally be configured that way even if the driver is not loaded, as the chip does not require a driver to function. Some boards may do that with a pull-up. Also the user may want to change this via sysfs and not have the driver "fix" it.

Quoted 3 lines

drivers/power/supply/qcom_smbb.c exposes the otg feature as regulator. I think in this case it could be exposed as gpio-regulator.

Quoted 7 lines

Hans is doing that here:
https://patchwork.kernel.org/patch/9883717/

The datasheet labels one pin "OTG" but that's misleading; it really enables negotiation of 500mA input current, but does not turn on OTG mode. If this pin is low, it only prevents the driver from starting OTG mode via I2C msg.

Yeah so before the device has enumerated this pin keeps the max current at 100mA as required by the USB spec. This pin should be only toggled after enumerating in bootloader or by the kernel driver. I tink the USB PHY driver can also be wired to control this line.

Quoted 7 lines

Probably best to set it up as just a GPIO that the bq24190 driver controls optionally.

Then later on we should have some Linux generic way for USB gadget subsystem to tell the charger that we have enumerated, and then bq24190 driver can toggle this GPIO to enable higher charge rates.

I discovered a few months ago that setting this pin high after USB connect has NO effect on iinlim. It has to be high at connect to auto-negotiate 500mA. There is no point in making the driver control this pin; we already tried that.

Here we are just documenting how the DT can enable this pin via gpio-hog.

I believe the only way to defer 500mA negotiation is to leave this pin off and set iinlim via I2C msg to chip. We can do that in a gadget script via sysfs input_current_limit. Hans does not have to enable this pin to start OTG-host on his x86 device, perhaps because it is wired high there. Our script can set the linked gpio high if nec for OTG-host.

#13 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

In reply to a message not in the archive
Quoted 42 lines · Liam Breck
Quoted 33 lines · Tony Lindgren
Quoted 18 lines · Liam Breck
Quoted 13 lines · Sebastian Reichel
Quoted 11 lines · Liam Breck
Quoted 4 lines
Quoted 2 lines

+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.

Why doesn't the charger driver control this?

This pin/gpio has to be high when USB is plugged in to make the charger chip negotiate 500mA from a SDP port. It should generally be configured that way even if the driver is not loaded, as the chip does not require a driver to function. Some boards may do that with a pull-up. Also the user may want to change this via sysfs and not have the driver "fix" it.

Quoted 3 lines

drivers/power/supply/qcom_smbb.c exposes the otg feature as regulator. I think in this case it could be exposed as gpio-regulator.

Quoted 7 lines

Hans is doing that here:
https://patchwork.kernel.org/patch/9883717/

The datasheet labels one pin "OTG" but that's misleading; it really enables negotiation of 500mA input current, but does not turn on OTG mode. If this pin is low, it only prevents the driver from starting OTG mode via I2C msg.

Yeah so before the device has enumerated this pin keeps the max current at 100mA as required by the USB spec. This pin should be only toggled after enumerating in bootloader or by the kernel driver. I tink the USB PHY driver can also be wired to control this line.

Quoted 7 lines

Probably best to set it up as just a GPIO that the bq24190 driver controls optionally.

Then later on we should have some Linux generic way for USB gadget subsystem to tell the charger that we have enumerated, and then bq24190 driver can toggle this GPIO to enable higher charge rates.

Quoted 6 lines

I discovered a few months ago that setting this pin high after USB connect has NO effect on iinlim. It has to be high at connect to auto-negotiate 500mA. There is no point in making the driver control this pin; we already tried that.

Here we are just documenting how the DT can enable this pin via gpio-hog.

Or in bootloader. Yeah this is mostly for completely empty battery to start charging at 100mA until bootloader can start and enable higher rates.

Quoted 6 lines

I believe the only way to defer 500mA negotiation is to leave this pin off and set iinlim via I2C msg to chip. We can do that in a gadget script via sysfs input_current_limit. Hans does not have to enable this pin to start OTG-host on his x86 device, perhaps because it is wired high there. Our script can set the linked gpio high if nec for OTG-host.

Yeah once something is running?

If the kernel does not need to do anything about it, how about just leave it out of the binding docs then?

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#14 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

Quoted 54 lines · Tony Lindgren
Quoted 42 lines · Liam Breck
Quoted 33 lines · Tony Lindgren
Quoted 18 lines · Liam Breck
Quoted 13 lines · Sebastian Reichel
Quoted 11 lines · Liam Breck
Quoted 4 lines
Quoted 2 lines

+Other features:
+- Use gpio-hog to set the OTG pin high to enable 500mA charge current on USB SDP port.

Why doesn't the charger driver control this?

This pin/gpio has to be high when USB is plugged in to make the charger chip negotiate 500mA from a SDP port. It should generally be configured that way even if the driver is not loaded, as the chip does not require a driver to function. Some boards may do that with a pull-up. Also the user may want to change this via sysfs and not have the driver "fix" it.

Quoted 3 lines

drivers/power/supply/qcom_smbb.c exposes the otg feature as regulator. I think in this case it could be exposed as gpio-regulator.

Quoted 7 lines

Hans is doing that here:
https://patchwork.kernel.org/patch/9883717/

The datasheet labels one pin "OTG" but that's misleading; it really enables negotiation of 500mA input current, but does not turn on OTG mode. If this pin is low, it only prevents the driver from starting OTG mode via I2C msg.

Yeah so before the device has enumerated this pin keeps the max current at 100mA as required by the USB spec. This pin should be only toggled after enumerating in bootloader or by the kernel driver. I tink the USB PHY driver can also be wired to control this line.

Quoted 7 lines

Probably best to set it up as just a GPIO that the bq24190 driver controls optionally.

Then later on we should have some Linux generic way for USB gadget subsystem to tell the charger that we have enumerated, and then bq24190 driver can toggle this GPIO to enable higher charge rates.

Quoted 6 lines

I discovered a few months ago that setting this pin high after USB connect has NO effect on iinlim. It has to be high at connect to auto-negotiate 500mA. There is no point in making the driver control this pin; we already tried that.

Here we are just documenting how the DT can enable this pin via gpio-hog.

Or in bootloader. Yeah this is mostly for completely empty battery to start charging at 100mA until bootloader can start and enable higher rates.

Quoted 8 lines
Quoted 6 lines

I believe the only way to defer 500mA negotiation is to leave this pin off and set iinlim via I2C msg to chip. We can do that in a gadget script via sysfs input_current_limit. Hans does not have to enable this pin to start OTG-host on his x86 device, perhaps because it is wired high there. Our script can set the linked gpio high if nec for OTG-host.

Yeah once something is running?

I haven't tried OTG-host on the anvl yet since it requires a special cable.

Quoted 2 lines

If the kernel does not need to do anything about it, how about just leave it out of the binding docs then?

It seemed useful to document the OTG pin DT config for boards that have it wired to a gpio... Is that not wise?

#16 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

In reply to a message not in the archive
Quoted 7 lines · Liam Breck
Quoted 2 lines · Tony Lindgren

If the kernel does not need to do anything about it, how about just leave it out of the binding docs then?

It seemed useful to document the OTG pin DT config for boards that have it wired to a gpio... Is that not wise?

Well maybe just add a comment to the driver about it until we know how we want to handle it?

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Re: [PATCH v2 1/5] power: bq24190_charger: Add ti,bq24192i to devicetree table

In reply to Liam Breck

drivers/power/supply/bq24190_charger.c MODULE_DEVICE_TABLE(i2c, bq24190_i2c_ids); · line 1741

Quoted 9 lines · Liam Breck

From: Liam Breck <[email protected]>

drivers/power/supply/bq24190_charger.c +1 -3
 #else
-static const struct of_device_id bq24190_of_match[] = {
-	{ },
-};
+static const struct of_device_id bq24190_of_match[] = { {} };
 #endif

Maybe check what checkpatch says about this one? It might actually prefer what we have now. You should also mention it in the commit message or just drop that change as people could complain it's an unrelated change.

Regards,

Tony

#17 lore raw

Re: [PATCH v2 2/5] devicetree: power: Add docs for TI BQ24190 battery charger

In reply to a message not in the archive
Quoted 6 lines · Liam Breck
Quoted 2 lines · Tony Lindgren

If the kernel does not need to do anything about it, how about just leave it out of the binding docs then?

It seemed useful to document the OTG pin DT config for boards that have it wired to a gpio... Is that not wise?

Well maybe add it as a note to the description rather than a binding. It might be actually best to document it in both places.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html