Driver for UCS1002
Subsystems (2)
v3 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 [v2]:
- Fixed a bug pointed out by Lucas
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
[v2] https://lore.kernel.org/lkml/[email protected]
[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 v3 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 v3 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
Re: [PATCH v3 2/3] power: supply: Add driver for Microchip UCS1002
Quoted 54 lines · Andrey Smirnov
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.
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]>--- 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.cdrivers/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_SUPPLYdrivers/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.odrivers/power/supply/ucs1002_power.c new file +0
-0@@ -0,0 +1,646 @@
...
Quoted 6 lines
drivers/power/supply/ucs1002_power.c new file +6
-0+ +static enum power_supply_usb_type ucs1002_usb_types[] = { +POWER_SUPPLY_USB_TYPE_PD , +POWER_SUPPLY_USB_TYPE_SDP , +POWER_SUPPLY_USB_TYPE_DCP , +POWER_SUPPLY_USB_TYPE_CDP ,
drivers/power/supply/ucs1002_power.c line 290
Quoted 10 lines
drivers/power/supply/ucs1002_power.c new file +10
-0+ POWER_SUPPLY_USB_TYPE_UNKNOWN, +}; + +static int ucs1002_set_usb_type (struct ucs1002_info *info,int val) +{ +unsigned int mode; + +if (val >=ARRAY_SIZE (ucs1002_usb_types)) +return -EINVAL ; +
I hate to bring it up that late, but I don't see a check against val being negative anywhere in the calling code.
Guenter
Re: [PATCH v3 2/3] power: supply: Add driver for Microchip UCS1002
Quoted 67 lines · Guenter Roeck
Quoted 54 lines · Andrey Smirnov
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.
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]>--- 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.cdrivers/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_SUPPLYdrivers/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.odrivers/power/supply/ucs1002_power.c new file +0
-0@@ -0,0 +1,646 @@...
Quoted 10 lines
drivers/power/supply/ucs1002_power.c new file +10
-0+ +static enum power_supply_usb_type ucs1002_usb_types[] = { +POWER_SUPPLY_USB_TYPE_PD , +POWER_SUPPLY_USB_TYPE_SDP , +POWER_SUPPLY_USB_TYPE_DCP , +POWER_SUPPLY_USB_TYPE_CDP , +POWER_SUPPLY_USB_TYPE_UNKNOWN , +}; + +static int ucs1002_set_usb_type (struct ucs1002_info *info,int val)
Quoted 9 lines
drivers/power/supply/ucs1002_power.c line 290
Quoted 6 lines
drivers/power/supply/ucs1002_power.c new file +6
-0+{ +unsigned int mode; + +if (val >=ARRAY_SIZE (ucs1002_usb_types)) +return -EINVAL ; +I hate to bring it up that late, but I don't see a check against val being negative anywhere in the calling code.
Sure, I'll add it in v4
Thanks,
Andrey Smirnov
PATCH v3 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