Skip to contentSkip to conversation

power: supply: Add driver for TI BQ2416X battery charger

PATCH In review Karsten Mueller 2 participants 4 messages Sep 17, 2018 – Sep 24, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 power: supply: Add driver for TI BQ2416X battery charger

This patch set is to add power driver for TI BQ2416X.

Driver is tested with BQ24160 and is based on:
https://lore.kernel.org/patchwork/patch/758105/

---
 drivers/power/supply/Kconfig           |    6 +
 drivers/power/supply/Makefile          |    1 +
 drivers/power/supply/bq2416x_charger.c | 1669 ++++++++++++++++++++++++
 3 files changed, 1676 insertions(+)
 create mode 100644 drivers/power/supply/bq2416x_charger.c
drivers/power/supply/Kconfig +6 -0
index ff6dab0bf..6e3604458 100644
@@ -543,6 +543,12 @@ config CHARGER_BQ2415X
 	  You'll need this driver to charge batteries on e.g. Nokia
 	  RX-51/N900.
 
+config CHARGER_BQ2416X
+	tristate "TI BQ2416x Dual-Input, Single Cell Switch-Mode Li-Ion charger"
+	depends on I2C
+	help
+	  Say Y here to enable support for the TI BQ2416x battery charger.
+
 config CHARGER_BQ24190
 	tristate "TI BQ24190 battery charger driver"
 	depends on I2C
drivers/power/supply/Makefile +1 -0
index a26b402c4..f44b24e41 100644
@@ -75,6 +75,7 @@ obj-$(CONFIG_CHARGER_MAX8997)	+= max8997_charger.o
 obj-$(CONFIG_CHARGER_MAX8998)	+= max8998_charger.o
 obj-$(CONFIG_CHARGER_QCOM_SMBB)	+= qcom_smbb.o
 obj-$(CONFIG_CHARGER_BQ2415X)	+= bq2415x_charger.o
+obj-$(CONFIG_CHARGER_BQ2416X)	+= bq2416x_charger.o
 obj-$(CONFIG_CHARGER_BQ24190)	+= bq24190_charger.o
 obj-$(CONFIG_CHARGER_BQ24257)	+= bq24257_charger.o
 obj-$(CONFIG_CHARGER_BQ24735)	+= bq24735-charger.o
drivers/power/supply/bq2416x_charger.c new file +1669 -0

1,669 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/3 dt-bindings: power: supply: bq2416x driver

---
 .../bindings/power/supply/bq2416x.txt         | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq2416x.txt
Documentation/devicetree/bindings/power/supply/bq2416x.txt new file +75 -0
new file mode 100644
index 000000000..742d41642
@@ -0,0 +1,75 @@
+Binding for TI bq2416x Li-Ion Charger
+
+Required properties:
+====================
+- compatible: one of the following:
+ * "ti,bq24160"
+ * "ti,bq24160a"
+ * "ti,bq24161"
+ * "ti,bq24161b"
+ * "ti,bq24163"
+ * "ti,bq24168"
+
+- reg:			I2C address of the device.
+- interrupt-parent:	The IRQ controller (phandle) connected to the INT pin of
+			the bq2416x
+- interrupts:		The IRQ number assigned for INT pin.
+
+Optional properties:
+====================
+
+- ti,in-current-limit-microamp:	IN source current limit.
+	Possible values: 1500000 (default), 2500000
+
+- ti,usb-current-limit-microamp: USB source current limit.
+	If not specified, auto detection of USB (D+/D- based) is used (for
+	BQ24160/0A/3 only) or settings of default mode are kept (BQ24161/1B/8).
+	Both pre-select only 100 mA or 1500 mA (refer to datasheet).
+	Possible values: 100000, 150000, 500000, 800000, 90000, 1500000
+
+- ti,usb-dpm-voltage-microvolt:	USB threshold for dynamic power path management.
+	Configures the threshold input voltage (usb input) for the dynamic power
+	path management. If not specified a default of 4,200,000 (= 4.2V) is
+	used.
+
+- ti,in-dpm-voltage-microvolt: IN threshold for dynamic power path management.
+	Configures the threshold input voltage (in input) for the dynamic power
+	path management. If not specified a default of 4,200,000 (= 4.2V) is
+	used.
+
+- monitored-battery: phandle of battery information devicetree node
+	If not specified, no battery is assumed (charge disable, nobat operation
+	mode, no NTC check of battery), Vsys output voltage is set to 4.2V. The
+	charger uses the following battery properties:
+	+ constant_charge_current_max_microamp: maximum current in fast charge
+	  mode
+	+ constant_charge_voltage_max_microvolt: maximum constant charging
+	  voltage / output voltage (refer to datasheet)
+	+ 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). If not specified,
+	  termination of current detection is disabled (refer to datasheet).
+
+Example:
+========
+
+bat: battery {
+		compatible = "simple-battery";
+		charge-term-current-microamp = <128000>;
+		constant-charge-current-max-microamp = <900000>;
+		constant-charge-voltage-max-microvolt = <4200000>;
+	};
+
+bq24160@6b {
+	compatible = "ti,bq24160";
+	reg = <0x6b>;
+
+	interrupt-parent = <&gpio5>;
+	interrupts = <31 IRQ_TYPE_EDGE_RISING>;
+
+	monitored-battery = <&bat>;
+	ti,in-current-limit-microamp = <1500000>;
+	ti,usb-current-limit-microamp = <500000>;
+	ti,usb-dpm-voltage-microvolt = <4300000>;
+	ti,in-dpm-voltage-microvolt = <4300000>;
+};
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 2/3] dt-bindings: power: supply: bq2416x driver

Quoted 1 line · Karsten Mueller

Commit msg needed.

Quoted 16 lines
---
 .../bindings/power/supply/bq2416x.txt         | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq2416x.txt
Documentation/devicetree/bindings/power/supply/bq2416x.txt new file +5 -0
new file mode 100644
index 000000000..742d41642
@@ -0,0 +1,75 @@
+Binding for TI bq2416x Li-Ion Charger
+
+Required properties:
+====================
+- compatible: one of the following:

Documentation/devicetree/bindings/power/supply/bq2416x.txt line 15

Quoted 10 lines
Documentation/devicetree/bindings/power/supply/bq2416x.txt new file +10 -0
+ * "ti,bq24160"
+ * "ti,bq24160a"
+ * "ti,bq24161"
+ * "ti,bq24161b"
+ * "ti,bq24163"
+ * "ti,bq24168"
+
+- reg:			I2C address of the device.
+- interrupt-parent:	The IRQ controller (phandle) connected to the INT pin of
+			the bq2416x

Drop this as it is implied (and could be in the parent).

Documentation/devicetree/bindings/power/supply/bq2416x.txt line 28

Quoted 13 lines
Documentation/devicetree/bindings/power/supply/bq2416x.txt new file +13 -0
+- interrupts:		The IRQ number assigned for INT pin.
+
+Optional properties:
+====================
+
+- ti,in-current-limit-microamp:	IN source current limit.
+	Possible values: 1500000 (default), 2500000
+
+- ti,usb-current-limit-microamp: USB source current limit.
+	If not specified, auto detection of USB (D+/D- based) is used (for
+	BQ24160/0A/3 only) or settings of default mode are kept (BQ24161/1B/8).
+	Both pre-select only 100 mA or 1500 mA (refer to datasheet).
+	Possible values: 100000, 150000, 500000, 800000, 90000, 1500000

Can't these be common?

Quoted 25 lines
Documentation/devicetree/bindings/power/supply/bq2416x.txt new file +25 -0
+
+- ti,usb-dpm-voltage-microvolt:	USB threshold for dynamic power path management.
+	Configures the threshold input voltage (usb input) for the dynamic power
+	path management. If not specified a default of 4,200,000 (= 4.2V) is
+	used.
+
+- ti,in-dpm-voltage-microvolt: IN threshold for dynamic power path management.
+	Configures the threshold input voltage (in input) for the dynamic power
+	path management. If not specified a default of 4,200,000 (= 4.2V) is
+	used.
+
+- monitored-battery: phandle of battery information devicetree node
+	If not specified, no battery is assumed (charge disable, nobat operation
+	mode, no NTC check of battery), Vsys output voltage is set to 4.2V. The
+	charger uses the following battery properties:
+	+ constant_charge_current_max_microamp: maximum current in fast charge
+	  mode
+	+ constant_charge_voltage_max_microvolt: maximum constant charging
+	  voltage / output voltage (refer to datasheet)
+	+ 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). If not specified,
+	  termination of current detection is disabled (refer to datasheet).
+
+Example:

Documentation/devicetree/bindings/power/supply/bq2416x.txt line 63

Quoted 10 lines
Documentation/devicetree/bindings/power/supply/bq2416x.txt new file +10 -0
+========
+
+bat: battery {
+		compatible = "simple-battery";
+		charge-term-current-microamp = <128000>;
+		constant-charge-current-max-microamp = <900000>;
+		constant-charge-voltage-max-microvolt = <4200000>;
+	};
+
+bq24160@6b {

charger@6b

Quoted 15 lines
Documentation/devicetree/bindings/power/supply/bq2416x.txt new file +12 -0
+	compatible = "ti,bq24160";
+	reg = <0x6b>;
+
+	interrupt-parent = <&gpio5>;
+	interrupts = <31 IRQ_TYPE_EDGE_RISING>;
+
+	monitored-battery = <&bat>;
+	ti,in-current-limit-microamp = <1500000>;
+	ti,usb-current-limit-microamp = <500000>;
+	ti,usb-dpm-voltage-microvolt = <4300000>;
+	ti,in-dpm-voltage-microvolt = <4300000>;
+};
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/3 Add sysfs ABI for bq2416x

In reply to Karsten Mueller
---
 Documentation/ABI/testing/sysfs-class-power | 118 ++++++++++++++++++++
 1 file changed, 118 insertions(+)
Documentation/ABI/testing/sysfs-class-power +118 -0
index 5e23e22dc..3881485ca 100644
@@ -587,3 +587,121 @@ Description:
 		Valid values:
 		- 1: enabled
 		- 0: disabled
+
+What:		/sys/class/power_supply/bq2416x-charger/usb_curr_limit
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		Reports and sets the maximum current the "usb" supply can
+		support.
+
+		Access: Read, Write
+		Valid values:
+		- 100000, 150000, 500000, 800000, 900000, 1500000 (uA)
+
+What:		/sys/class/power_supply/bq2416x-charger/in_curr_limit
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		Reports and sets the maximum current the "in" (wall) supply can
+		support.
+
+		Access: Read, Write
+		Valid values:
+		- 1500000, 2500000 (uA)
+
+What:		/sys/class/power_supply/bq2416x-charger/in_dpm_voltage
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		This entry configures the "in" (wall) input dynamic power path
+		management voltage of bq2416x-type charger devices. Once the
+		supply drops to the configured voltage, the input current limit
+		is reduced down to prevent the further drop of the supply. When
+		the IC enters this mode, the charge current is lower than the
+		set value.
+
+		Access: Read, Write
+		Valid values:
+		- 4200000, 4280000, 4360000, 4440000, 4520000, 4600000, 4680000,
+		  4760000 (all uV)
+
+What:		/sys/class/power_supply/bq2416x-charger/usb_dpm_voltage
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		This entry configures the "usb" input dynamic power path
+		management voltage of bq2416x-type charger devices. Once the
+		supply drops to the configured voltage, the input current limit
+		is reduced down to prevent the further drop of the supply. When
+		the IC enters this mode, the charge current is lower than the
+		set value.
+
+		Access: Read, Write
+		Valid values:
+		- 4200000, 4280000, 4360000, 4440000, 4520000, 4600000, 4680000,
+		  4760000 (all uV)
+
+What:		/sys/class/power_supply/bq2416x-charger/high_impedance_enable
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		This entry allows enabling the high-impedance mode of
+		bq2416x-type charger devices. If enabled, it places the charger
+		IC into low power standby mode with the switch mode controller
+		disabled. When disabled, the charger operates normally.
+
+		Access: Read, Write
+		Valid values:
+		- 1: enabled
+		- 0: disabled
+
+What:		/sys/class/power_supply/bq2416x-charger/dpm_status
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		Reports whether dynamic power management is active, i.e. input
+		current of used source is limited to prevent further drop of
+		voltage.
+
+		Valid values:
+		- 0: not active
+		- 1: active
+
+What:		/sys/class/power_supply/bq2416x-charger/supply_sel
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		This entry configures which input ("in", "usb") should be
+		preferred as input source.
+
+		Valid values:
+		- "in", "usb"
+
+What:		/sys/class/power_supply/bq2416x-charger/ts_fault
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		Reports state of NTC temperature monitor.
+
+		Valid values:
+		- "normal", "cold/hot(charge suspended)",
+		  "cool(half current charge)", "warm(voltage reduced)"
+
+What:		/sys/class/power_supply/bq2416x-charger/in_status
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		Reports state of "in" input source.
+
+		Valid values:
+		- "Normal", "OVP", "Weak source", "Faulty Adapter"
+
+What:		/sys/class/power_supply/bq2416x-charger/usb_status
+Date:		September 2018
+Contact:	Karsten Mueller <[email protected]>
+Description:
+		Reports state of "usb" input source.
+
+		Valid values:
+		- "Normal", "OVP", "Weak source", "Faulty Adapter"
Signature · 1 line
2.17.1