Driver for UCS1002
Subsystems (2)
v2 cover Driver for UCS1002
Everyone:
This small series adds a driver for UCS1002 Programmable USB Port Power Controller with Charger Emulation. See [page] for product page and [datasheet] for device dataseet. Hopefully each individual patch is self explanatory.
Note that this series is a revival of the upstreaming effort by Enric Balletbo Serra last version of which can be found at [original-effort]
Feedback is welcome!
Thanks,
Andrey Smirnov
Changes since [v1]:
- Moved IRQ trigger specification to DT
- Fixed silent error paths in probe()
- Dropped error message in ucs1002_set_max_current()
- Fixed license mismatch
- Changed the driver to configure the chip to BC1.2 CDP by default
- Made other small fixes as per feedback for v1
[v1] https://lore.kernel.org/lkml/[email protected]/
[page] https://www.microchip.com/wwwproducts/en/UCS1002-2
[datasheet] https://ww1.microchip.com/downloads/en/DeviceDoc/UCS1002-2%20Data%20Sheet.pdf
[original-effort] https://lore.kernel.org/lkml/[email protected]/
Andrey Smirnov (3):
power: supply: core: Add POWER_SUPPLY_HEALTH_OVERCURRENT constant
power: supply: Add driver for Microchip UCS1002
dt-bindings: power: supply: Add bindings for Microchip UCS1002
.../power/supply/microchip,ucs1002.txt | 27 + drivers/power/supply/Kconfig | 9 + drivers/power/supply/Makefile | 1 + drivers/power/supply/power_supply_sysfs.c | 2 +- drivers/power/supply/ucs1002_power.c | 646 ++++++++++++++++++ include/linux/power_supply.h | 1 + 6 files changed, 685 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt create mode 100644 drivers/power/supply/ucs1002_power.c
Signature · 1 line
2.20.1
PATCH v2 1/3 power: supply: core: Add POWER_SUPPLY_HEALTH_OVERCURRENT constant
Add POWER_SUPPLY_HEALTH_OVERCURRENT constant in order to allow singalling overcurrent condition via power supply health information.
--- drivers/power/supply/power_supply_sysfs.c | 2 +- include/linux/power_supply.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/power/supply/power_supply_sysfs.c +1 -1
@@ -62,7 +62,7 @@ static const char * const power_supply_charge_type_text[] = {static const char *const power_supply_health_text[] = {"Unknown" ,"Good" ,"Overheat" ,"Dead" ,"Over voltage" ,"Unspecified failure" ,"Cold" ,"Watchdog timer expire" , -"Safety timer expire" +"Safety timer expire" ,"Over current" };static const char *const power_supply_technology_text[] = {
include/linux/power_supply.h +1 -0
@@ -57,6 +57,7 @@ enum {POWER_SUPPLY_HEALTH_COLD ,POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE ,POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE , + POWER_SUPPLY_HEALTH_OVERCURRENT, }; enum {
Signature · 1 line
2.20.1
PATCH v2 2/3 power: supply: Add driver for Microchip UCS1002
In reply to Andrey SmirnovAdd driver for Microchip UCS1002 Programmable USB Port Power Controller with Charger Emulation. The driver exposed a power supply device to control/monitor various parameter of the device as well as a regulator to allow controlling VBUS line.
--- drivers/power/supply/Kconfig | 9 + drivers/power/supply/Makefile | 1 + drivers/power/supply/ucs1002_power.c | 646 +++++++++++++++++++++++++++ 3 files changed, 656 insertions(+) create mode 100644 drivers/power/supply/ucs1002_power.c
drivers/power/supply/Kconfig +9 -0
@@ -660,4 +660,13 @@ config FUEL_GAUGE_SC27XX Say Y here to enable support for fuel gauge with SC27XX PMIC chips. +config CHARGER_UCS1002 + tristate "Microchip UCS1002 USB Port Power Controller" + depends on I2C + depends on OF + select REGMAP_I2C + help + Say Y to enable support for Microchip UCS1002 Programmable + USB Port Power Controller with Charger Emulation. + endif # POWER_SUPPLY
drivers/power/supply/Makefile +1 -0
@@ -87,3 +87,4 @@ obj-$(CONFIG_AXP288_CHARGER) += axp288_charger.o obj-$(CONFIG_CHARGER_CROS_USBPD) += cros_usbpd-charger.o obj-$(CONFIG_CHARGER_SC2731) += sc2731_charger.o obj-$(CONFIG_FUEL_GAUGE_SC27XX) += sc27xx_fuel_gauge.o +obj-$(CONFIG_CHARGER_UCS1002) += ucs1002_power.o
drivers/power/supply/ucs1002_power.c new file +646 -0
646 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v2 3/3 dt-bindings: power: supply: Add bindings for Microchip UCS1002
In reply to Andrey SmirnovAdd bindings for Microchip UCS1002 Programmable USB Port Power Controller with Charger Emulation.
--- .../power/supply/microchip,ucs1002.txt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt
Documentation/devicetree/bindings/power/supply/microchip,ucs1002.txt new file +27 -0
@@ -0,0 +1,27 @@ +Microchip UCS1002 USB Port Power Controller + +Required properties: +- compatible : Should be "microchip,ucs1002"; +- reg : I2C slave address + +Optional properties: +- interrupts-extended : A list of interrupts lines present (could be either + corresponding to A_DET# pin, ALERT# pin, or both) +- interrupt-names : A list of interrupt names. Should contain (if + present): + - "a_det" for line connected to A_DET# pin + - "alert" for line connected to ALERT# pin + Both are expected to be IRQ_TYPE_EDGE_BOTH +Example: + +&i2c3 { + charger@32 { + compatible = "microchip,ucs1002"; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_ucs1002_pins>; + reg = <0x32>; + interrupts-extended = <&gpio5 2 IRQ_TYPE_EDGE_BOTH>, + <&gpio3 21 IRQ_TYPE_EDGE_BOTH>; + interrupt-names = "a_det", "alert"; + }; +};
Signature · 1 line
2.20.1
Re: [PATCH v2 2/3] power: supply: Add driver for Microchip UCS1002
In reply to Andrey SmirnovHi Andrey,
Am Sonntag, den 28.04.2019, 22:47 -0700 schrieb Andrey Smirnov:
Quoted 15 lines
Add driver for Microchip UCS1002 Programmable USB Port Power Controller with Charger Emulation. The driver exposed a power supply device to control/monitor various parameter of the device as well as a regulator to allow controlling VBUS line.
Quoted 7 lines
Signed-off-by Enric Balletbo Serra <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>Cc Chris Healy <[email protected]>Cc Lucas Stach <[email protected]>Cc Fabio Estevam <[email protected]>Cc Guenter Roeck <[email protected]>Cc Sebastian Reichel <[email protected]>---
[...]
Quoted 14 lines
(quoted diff) +1
-0+ /* Enable charge rationing by default */Review
Quoted 6 lines
(quoted diff) +6
-0+ ret = regmap_update_bits(info->regmap, UCS1002_REG_GENERAL_CFG, + F_RATION_EN, F_RATION_EN); + if (ret) { + dev_err(dev, "Failed to read general config: %d\n", ret); + return ret; + }+
Quoted 6 lines
(quoted diff) +6
-0+ /* + * Ignore the M1, M2, PWR_EN, and EM_EN pin states. Set active + * mode selection to BC1.2 CDP. + */ + ret = regmap_update_bits(info->regmap, UCS1002_REG_SWITCH_CFG, + V_SET_ACTIVE_MODE_MASK,
Review
Quoted 1 line
(quoted diff) +1
-0+ V_SET_ACTIVE_MODE_BC12_CDP);
This doesn't work as the F_PIN_IGNORE bit isn't set, so the the external strap settings are applied. I had to apply the following diff to make the driver behave as expected again:
drivers/power/supply/ucs1002_power.c +0 -0
@@ -548,8 +548,8 @@ static int ucs1002_probe(struct i2c_client *client,
* mode selection to BC1.2 CDP.
*/
ret = regmap_update_bits(info->regmap, UCS1002_REG_SWITCH_CFG, - V_SET_ACTIVE_MODE_MASK,
- V_SET_ACTIVE_MODE_BC12_CDP);
+ V_SET_ACTIVE_MODE_MASK | F_PIN_IGNORE, + V_SET_ACTIVE_MODE_BC12_CDP | F_PIN_IGNORE);
Regards,
Lucas
Re: [PATCH v2 2/3] power: supply: Add driver for Microchip UCS1002
Quoted 34 lines · Lucas Stach
Hi Andrey,
Am Sonntag, den 28.04.2019, 22:47 -0700 schrieb Andrey Smirnov:
Quoted 15 lines
Add driver for Microchip UCS1002 Programmable USB Port Power Controller with Charger Emulation. The driver exposed a power supply device to control/monitor various parameter of the device as well as a regulator to allow controlling VBUS line.
Quoted 7 lines
Signed-off-by Enric Balletbo Serra <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>Cc Chris Healy <[email protected]>Cc Lucas Stach <[email protected]>Cc Fabio Estevam <[email protected]>Cc Guenter Roeck <[email protected]>Cc Sebastian Reichel <[email protected]>---
[...]
Quoted 14 lines
+ /* Enable charge rationing by default */
Review
Quoted 6 lines
(quoted diff) +6
-0+ ret = regmap_update_bits(info->regmap, UCS1002_REG_GENERAL_CFG, + F_RATION_EN, F_RATION_EN); + if (ret) { + dev_err(dev, "Failed to read general config: %d\n", ret); + return ret; + }+
Quoted 6 lines
(quoted diff) +6
-0+ /* + * Ignore the M1, M2, PWR_EN, and EM_EN pin states. Set active + * mode selection to BC1.2 CDP. + */ + ret = regmap_update_bits(info->regmap, UCS1002_REG_SWITCH_CFG, + V_SET_ACTIVE_MODE_MASK,
Quoted 6 lines
Quoted 1 line
+
V_SET_ACTIVE_MODE_BC12_CDP);This doesn't work as the
F_PIN_IGNOREbit isn't set, so the the external strap settings are applied. I had to apply the following diff to make the driver behave as expected again:
Ugh, I missed this since pins on my board are set properly. Thanks for catching that and sorry about the bug. Will fix in v3.
Thanks,
Andrey Smirnov