power: supply: cros: add support for dedicated port and expose connected ports
Subsystems (3)
v2 cover power: supply: cros: add support for dedicated port and expose connected ports
Dear all,
This patch series adds support for an optional dedicated port to the ChromeOS power supply driver and adds a new property that expose when a power supply is connected. The series was tested on ChromeOS "Fizz" hardware.
This patch series depends on the following patch serie which adds the ChromeOS power supply driver:
* https://lkml.org/lkml/2018/5/2/585 [PATCH v4 0/3] mfd/power: cros_ec: add support for USBPD charger driver
The ChromeOS power supply driver also depends on the following patches to be applied:
* https://lkml.org/lkml/2018/4/23/602 ([PATCH v8 0/6] typec: tcpm: Add sink side support for PPS)
* https://lkml.org/lkml/2018/4/18/229 ([RESEND PATCH v5 4/7] mfd:
cros_ec_dev: Register cros-ec-rtc driver as a subdevice.)
Best Regards,
Fabien
V2:
* Rebased to fixed apply issue with patch #2
Fabien Parent (3):
mfd: cros: add charger port count command definition
power: supply: cros: add support for dedicated port
power: supply: cros: add property to detect connected ports
drivers/power/supply/cros_usbpd-charger.c | 126 +++++++++++++++++++--- include/linux/mfd/cros_ec_commands.h | 10 ++ 2 files changed, 122 insertions(+), 14 deletions(-)
Signature · 1 line
2.18.0
PATCH v2 1/3 mfd: cros: add charger port count command definition
A new more command has been added to the ChromeOS embedded controller that allows to get the number of charger port count. Unlike EC_CMD_USB_PD_PORTS, this new command also includes the dedicated port if present.
This command will be used to expose the dedicated charger port in the ChromeOS charger driver.
---
V1 -> V2:
* No change
--- include/linux/mfd/cros_ec_commands.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/mfd/cros_ec_commands.h +10 -0
@@ -3005,6 +3005,16 @@ struct ec_params_usb_pd_info_request {uint8_t port; } __packed; +/* +* This command will return the number of USB PD charge port + the number +* of dedicated port present. +* EC_CMD_USB_PD_PORTS does NOT include the dedicated ports +*/ +#define EC_CMD_CHARGE_PORT_COUNT 0x0105 +struct ec_response_charge_port_count { +uint8_t port_count; +} __packed; +/* Read USB-PD Device discovery info */ #define EC_CMD_USB_PD_DISCOVERY 0x0113struct ec_params_usb_pd_discovery_entry {
Signature · 1 line
2.18.0
PATCH v2 2/3 power: supply: cros: add support for dedicated port
In reply to Fabien ParentChromeOS devices can have one optional dedicated port. The Dedicated port is unique and similar to the USB PD ports except that it doesn't support as many properties.
The presence of a dedicated port is determined from whether the EC's charger port count is equal to 'number of USB PD port' + 1. The dedicated port ID is always the last valid port ID.
This commit keeps compatibility with Embedded Controllers that do not support the new EC_CMD_CHARGE_PORT_COUNT command by setting the number of charger port to be equal to the number of USB PD port when this command fails.
---
V1 -> V2:
* Rebased
--- drivers/power/supply/cros_usbpd-charger.c | 115 +++++++++++++++++++--- 1 file changed, 101 insertions(+), 14 deletions(-)
drivers/power/supply/cros_usbpd-charger.c +101 -14
@@ -12,8 +12,12 @@#include <linux/power_supply.h> #include <linux/slab.h> -#define CHARGER_DIR_NAME "CROS_USBPD_CHARGER%d" -#define CHARGER_DIR_NAME_LENGTH sizeof(CHARGER_DIR_NAME) +#define CHARGER_USBPD_DIR_NAME "CROS_USBPD_CHARGER%d" +#define CHARGER_DEDICATED_DIR_NAME "CROS_DEDICATED_CHARGER" +#define CHARGER_DIR_NAME_LENGTH (sizeof(CHARGER_USBPD_DIR_NAME) >= \ + sizeof(CHARGER_DEDICATED_DIR_NAME) ? \ + sizeof(CHARGER_USBPD_DIR_NAME) : \ + sizeof(CHARGER_DEDICATED_DIR_NAME))#define CHARGER_CACHE_UPDATE_DELAY msecs_to_jiffies(500)#define CHARGER_MANUFACTURER_MODEL_LENGTH 32
@@ -42,6 +46,7 @@ struct charger_data {struct cros_ec_dev *ec_dev;struct cros_ec_device *ec_device;int num_charger_ports; +int num_usbpd_ports;int num_registered_psy;struct port_data *ports[EC_USB_PD_MAX_PORTS ];struct notifier_block notifier;
@@ -58,6 +63,12 @@ static enum power_supply_property cros_usbpd_charger_props[] = {POWER_SUPPLY_PROP_USB_TYPE }; +static enum power_supply_property cros_usbpd_dedicated_charger_props[] = { +POWER_SUPPLY_PROP_ONLINE , +POWER_SUPPLY_PROP_STATUS , +POWER_SUPPLY_PROP_VOLTAGE_NOW , +}; +static enum power_supply_usb_type cros_usbpd_charger_usb_types[] = {POWER_SUPPLY_USB_TYPE_UNKNOWN ,POWER_SUPPLY_USB_TYPE_SDP ,
@@ -69,6 +80,11 @@ static enum power_supply_usb_type cros_usbpd_charger_usb_types[] = {POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID }; +static bool cros_usbpd_charger_port_is_dedicated (struct port_data *port) +{ +return port->port_number >= port->charger->num_usbpd_ports; +} + static int cros_usbpd_charger_ec_command(struct charger_data *charger, unsigned int version, unsigned int command,
@@ -102,6 +118,23 @@ static int cros_usbpd_charger_ec_command(struct charger_data *charger, }static int cros_usbpd_charger_get_num_ports (struct charger_data *charger) +{ +struct ec_response_charge_port_count resp; +int ret; + + ret =cros_usbpd_charger_ec_command (charger,0 , +EC_CMD_CHARGE_PORT_COUNT , +NULL ,0 , &resp,sizeof (resp)); +if (ret <0 ) { +dev_err (charger->dev, +"Unable to get the number of ports (err:0x%x)\n" , ret); +return ret; + } + +return resp.port_count; +} + +static int cros_usbpd_charger_get_usbpd_num_ports (struct charger_data *charger) {struct ec_response_usb_pd_ports resp;int ret;
@@ -246,7 +279,10 @@ static int cros_usbpd_charger_get_power_info(struct port_data *port) port->psy_usb_type =POWER_SUPPLY_USB_TYPE_SDP ; } - port->psy_desc.type =POWER_SUPPLY_TYPE_USB ; +if (cros_usbpd_charger_port_is_dedicated (port)) + port->psy_desc.type =POWER_SUPPLY_TYPE_MAINS ; +else + port->psy_desc.type =POWER_SUPPLY_TYPE_USB ; dev_dbg(dev, "Port %d: type=%d vmax=%d vnow=%d cmax=%d clim=%d pmax=%d\n",
@@ -281,7 +317,8 @@ static int cros_usbpd_charger_get_port_status(struct port_data *port,if (ret <0 )return ret; - ret =cros_usbpd_charger_get_discovery_info (port); +if (!cros_usbpd_charger_port_is_dedicated (port)) + ret =cros_usbpd_charger_get_discovery_info (port); port->last_update = jiffies;return ret;
@@ -426,17 +463,56 @@ static int cros_usbpd_charger_probe(struct platform_device *pd)platform_set_drvdata (pd, charger); +/* +* We need to know the number of USB PD ports in order to know whether +* there is a dedicated port. The dedicated port will always be +* after the USB PD ports, and there should be only one. +*/ + charger->num_usbpd_ports = +cros_usbpd_charger_get_usbpd_num_ports (charger); +if (charger->num_usbpd_ports <=0 ) { +/* +* This can happen on a system that doesn't support USB PD. +* Log a message, but no need to warn. +*/ +dev_info (dev,"No USB PD charging ports found\n" ); + } + charger->num_charger_ports =cros_usbpd_charger_get_num_ports (charger); -if (charger->num_charger_ports <=0 ) { +if (charger->num_charger_ports <0 ) {/* * This can happen on a system that doesn't support USB PD. * Log a message, but no need to warn. +* Older ECs do not support the above command, in that case +* let's set up the number of charger ports equal to the number +* of USB PD ports +*/ +dev_info (dev,"Could not get charger port count\n" ); + charger->num_charger_ports = charger->num_usbpd_ports; + } + +if (charger->num_charger_ports <=0 ) { +/* +* This can happen on a system that doesn't support USB PD and +* doesn't have a dedicated port. +* Log a message, but no need to warn. */ dev_info (dev,"No charging ports found\n" ); ret = -ENODEV ; goto fail_nowarn; } +/* +* Sanity checks on the number of ports: +* there should be at most 1 dedicated port +*/ +if (charger->num_charger_ports < charger->num_usbpd_ports || + charger->num_charger_ports > (charger->num_usbpd_ports +1 )) { +dev_err (dev,"Unexpected number of charge port count\n" ); + ret = -EPROTO ; + goto fail_nowarn; + } +for (i =0 ; i < charger->num_charger_ports; i++) {struct power_supply_config psy_cfg = {};
@@ -448,22 +524,33 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) port->charger = charger; port->port_number = i; -sprintf (port->name,CHARGER_DIR_NAME , i); psy_desc = &port->psy_desc; - psy_desc->name = port->name; - psy_desc->type =POWER_SUPPLY_TYPE_USB ; psy_desc->get_property = cros_usbpd_charger_get_prop; psy_desc->external_power_changed = cros_usbpd_charger_power_changed; - psy_desc->properties = cros_usbpd_charger_props; - psy_desc->num_properties = -ARRAY_SIZE (cros_usbpd_charger_props); - psy_desc->usb_types = cros_usbpd_charger_usb_types; - psy_desc->num_usb_types = -ARRAY_SIZE (cros_usbpd_charger_usb_types); psy_cfg.drv_data = port; +if (cros_usbpd_charger_port_is_dedicated (port)) { +sprintf (port->name,CHARGER_DEDICATED_DIR_NAME ); + psy_desc->type =POWER_SUPPLY_TYPE_MAINS ; + psy_desc->properties = + cros_usbpd_dedicated_charger_props; + psy_desc->num_properties = +ARRAY_SIZE (cros_usbpd_dedicated_charger_props); + }else { +sprintf (port->name,CHARGER_USBPD_DIR_NAME , i); + psy_desc->type =POWER_SUPPLY_TYPE_USB ; + psy_desc->properties = cros_usbpd_charger_props; + psy_desc->num_properties = +ARRAY_SIZE (cros_usbpd_charger_props); + psy_desc->usb_types = cros_usbpd_charger_usb_types; + psy_desc->num_usb_types = +ARRAY_SIZE (cros_usbpd_charger_usb_types); + } + + psy_desc->name = port->name; + psy =devm_power_supply_register_no_ws (dev, psy_desc, &psy_cfg);if (IS_ERR (psy)) {
Signature · 1 line
2.18.0
PATCH v2 3/3 power: supply: cros: add property to detect connected ports
In reply to Fabien ParentWhen a port is connected but acting as a source, its 'online' and 'status' properties are identical to a port that is not connected. This makes it tedious for userspace to know for sure whether a port is connected or not.
This commit adds a new property 'present' to reflect whether a port is connected or not.
---
V1 -> V2:
* No change
--- drivers/power/supply/cros_usbpd-charger.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/power/supply/cros_usbpd-charger.c +11 -0
@@ -32,6 +32,7 @@ struct port_data {struct power_supply_desc psy_desc;int psy_usb_type;int psy_online; +int psy_present;int psy_status;int psy_current_max;int psy_voltage_max_design;
@@ -54,6 +55,7 @@ struct charger_data {static enum power_supply_property cros_usbpd_charger_props[] = {POWER_SUPPLY_PROP_ONLINE , +POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_STATUS ,POWER_SUPPLY_PROP_CURRENT_MAX ,POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN ,
@@ -65,6 +67,7 @@ static enum power_supply_property cros_usbpd_charger_props[] = {static enum power_supply_property cros_usbpd_dedicated_charger_props[] = {POWER_SUPPLY_PROP_ONLINE , +POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_STATUS ,POWER_SUPPLY_PROP_VOLTAGE_NOW , };
@@ -205,18 +208,22 @@ static int cros_usbpd_charger_get_power_info(struct port_data *port)case USB_PD_PORT_POWER_DISCONNECTED : port->psy_status =POWER_SUPPLY_STATUS_NOT_CHARGING ; port->psy_online =0 ; + port->psy_present =0 ;break ;case USB_PD_PORT_POWER_SOURCE : port->psy_status =POWER_SUPPLY_STATUS_NOT_CHARGING ; port->psy_online =0 ; + port->psy_present =1 ;break ;case USB_PD_PORT_POWER_SINK : port->psy_status =POWER_SUPPLY_STATUS_CHARGING ; port->psy_online =1 ; + port->psy_present =1 ;break ;case USB_PD_PORT_POWER_SINK_NOT_CHARGING : port->psy_status =POWER_SUPPLY_STATUS_NOT_CHARGING ; port->psy_online =1 ; + port->psy_present =1 ;break ;default :dev_err (dev,"Unknown role %d\n" , resp.role);
@@ -363,6 +370,7 @@ static int cros_usbpd_charger_get_prop(struct power_supply *psy,if (ec_device->mkbp_event_supported || port->psy_online)break ;/* fall through */ +case POWER_SUPPLY_PROP_PRESENT :case POWER_SUPPLY_PROP_CURRENT_MAX :case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN :case POWER_SUPPLY_PROP_VOLTAGE_NOW :
@@ -381,6 +389,9 @@ static int cros_usbpd_charger_get_prop(struct power_supply *psy,case POWER_SUPPLY_PROP_ONLINE : val->intval = port->psy_online;break ; +case POWER_SUPPLY_PROP_PRESENT : + val->intval = port->psy_present; +break ;case POWER_SUPPLY_PROP_STATUS : val->intval = port->psy_status;break ;
Signature · 1 line
2.18.0
Re: [PATCH v2 1/3] mfd: cros: add charger port count command definition
In reply to Fabien ParentHi,
Missatge de Fabien Parent <[email protected]> del dia dv., 10 d’ag. 2018 a les 15:17:
Quoted 10 lines
A new more command has been added to the ChromeOS embedded controller that allows to get the number of charger port count. Unlike
EC_CMD_USB_PD_PORTS, this new command also includes the dedicated port if present.This command will be used to expose the dedicated charger port in the ChromeOS charger driver.
Signed-off-by Fabien Parent <[email protected]>
Seems you missed my Reviewed-by tag, not a problem :), in any case, for if it helps to land adding again
Quoted 32 lines
Acked-for-MFD-by Lee Jones <[email protected]>---
V1 -> V2:
* No change--- include/linux/mfd/cros_ec_commands.h | 10 ++++++++++ 1 file changed, 10 insertions(+)include/linux/mfd/cros_ec_commands.h +10
-1@@ -3005,6 +3005,16 @@ struct ec_params_usb_pd_info_request {uint8_t port; } __packed; +/* +* This command will return the number of USB PD charge port + the number +* of dedicated port present. +* EC_CMD_USB_PD_PORTS does NOT include the dedicated ports +*/ +#define EC_CMD_CHARGE_PORT_COUNT 0x0105 +struct ec_response_charge_port_count { +uint8_t port_count; +} __packed; +/* Read USB-PD Device discovery info */ #define EC_CMD_USB_PD_DISCOVERY 0x0113struct ec_params_usb_pd_discovery_entry { --2.18.0
Re: [PATCH v2 3/3] power: supply: cros: add property to detect connected ports
In reply to Fabien ParentHi,
Quoted 10 lines · Fabien Parent
When a port is connected but acting as a source, its 'online' and 'status' properties are identical to a port that is not connected. This makes it tedious for userspace to know for sure whether a port is connected or not.
This commit adds a new property 'present' to reflect whether a port is connected or not.
Signed-off-by Fabien Parent <[email protected]>---
I think it's better to just set use POWER_SUPPLY_STATUS_DISCHARGING for USB_PD_PORT_POWER_SOURCE.
-- Sebastian
Quoted 80 lines
V1 -> V2:
* No change--- drivers/power/supply/cros_usbpd-charger.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/power/supply/cros_usbpd-charger.c +11
-0@@ -32,6 +32,7 @@ struct port_data {struct power_supply_desc psy_desc;int psy_usb_type;int psy_online; +int psy_present;int psy_status;int psy_current_max;int psy_voltage_max_design;@@ -54,6 +55,7 @@ struct charger_data {static enum power_supply_property cros_usbpd_charger_props[] = {POWER_SUPPLY_PROP_ONLINE , +POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_STATUS ,POWER_SUPPLY_PROP_CURRENT_MAX ,POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN ,@@ -65,6 +67,7 @@ static enum power_supply_property cros_usbpd_charger_props[] = {static enum power_supply_property cros_usbpd_dedicated_charger_props[] = {POWER_SUPPLY_PROP_ONLINE , +POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_STATUS ,POWER_SUPPLY_PROP_VOLTAGE_NOW , };@@ -205,18 +208,22 @@ static int cros_usbpd_charger_get_power_info(struct port_data *port)case USB_PD_PORT_POWER_DISCONNECTED : port->psy_status =POWER_SUPPLY_STATUS_NOT_CHARGING ; port->psy_online =0 ; + port->psy_present =0 ;break ;case USB_PD_PORT_POWER_SOURCE : port->psy_status =POWER_SUPPLY_STATUS_NOT_CHARGING ; port->psy_online =0 ; + port->psy_present =1 ;break ;case USB_PD_PORT_POWER_SINK : port->psy_status =POWER_SUPPLY_STATUS_CHARGING ; port->psy_online =1 ; + port->psy_present =1 ;break ;case USB_PD_PORT_POWER_SINK_NOT_CHARGING : port->psy_status =POWER_SUPPLY_STATUS_NOT_CHARGING ; port->psy_online =1 ; + port->psy_present =1 ;break ;default :dev_err (dev,"Unknown role %d\n" , resp.role);@@ -363,6 +370,7 @@ static int cros_usbpd_charger_get_prop(struct power_supply *psy,if (ec_device->mkbp_event_supported || port->psy_online)break ;/* fall through */ +case POWER_SUPPLY_PROP_PRESENT :case POWER_SUPPLY_PROP_CURRENT_MAX :case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN :case POWER_SUPPLY_PROP_VOLTAGE_NOW :@@ -381,6 +389,9 @@ static int cros_usbpd_charger_get_prop(struct power_supply *psy,case POWER_SUPPLY_PROP_ONLINE : val->intval = port->psy_online;break ; +case POWER_SUPPLY_PROP_PRESENT : + val->intval = port->psy_present; +break ;case POWER_SUPPLY_PROP_STATUS : val->intval = port->psy_status;break ;Signature · 1 line
2.18.0
Hi,
Quoted 22 lines · Fabien Parent
Dear all,
This patch series adds support for an optional dedicated port to the ChromeOS power supply driver and adds a new property that expose when a power supply is connected. The series was tested on ChromeOS "Fizz" hardware.
This patch series depends on the following patch serie which adds the ChromeOS power supply driver:
* https://lkml.org/lkml/2018/5/2/585 [PATCH v4 0/3] mfd/power:cros_ec: add support for USBPD charger driverThe ChromeOS power supply driver also depends on the following patches to be applied:
* https://lkml.org/lkml/2018/4/23/602 ([PATCH v8 0/6] typec: tcpm: Add sink side support for PPS)
* https://lkml.org/lkml/2018/4/18/229 ([RESEND PATCH v5 4/7] mfd:
cros_ec_dev: Register cros-ec-rtc driver as a subdevice.)Best Regards,
Fabien
Quoted 7 lines
V2:
* Rebased to fixed apply issue with patch #2Fabien Parent (3):
mfd: cros: add charger port count command definition
power: supply: cros: add support for dedicated port
power: supply: cros: add property to detect connected ports
I prepared an immutable branch for patch 1+2 and merged it into power-supply-next. I will push out the branch and send a pull request for the immutable branch to Lee later (once I have Internet connection).
-- Sebastian
Quoted 7 lines
drivers/power/supply/cros_usbpd-charger.c | 126 +++++++++++++++++++--- include/linux/mfd/cros_ec_commands.h | 10 ++ 2 files changed, 122 insertions(+), 14 deletions(-)Signature · 1 line
2.18.0
Hi Lee,
Quoted 33 lines · Sebastian Reichel
Hi,
Quoted 22 lines · Fabien Parent
Dear all,
This patch series adds support for an optional dedicated port to the ChromeOS power supply driver and adds a new property that expose when a power supply is connected. The series was tested on ChromeOS "Fizz" hardware.
This patch series depends on the following patch serie which adds the ChromeOS power supply driver:
* https://lkml.org/lkml/2018/5/2/585 [PATCH v4 0/3] mfd/power:cros_ec: add support for USBPD charger driverThe ChromeOS power supply driver also depends on the following patches to be applied:
* https://lkml.org/lkml/2018/4/23/602 ([PATCH v8 0/6] typec: tcpm: Add sink side support for PPS)
* https://lkml.org/lkml/2018/4/18/229 ([RESEND PATCH v5 4/7] mfd:
cros_ec_dev: Register cros-ec-rtc driver as a subdevice.)Best Regards,
FabienQuoted 7 lines
V2:
* Rebased to fixed apply issue with patch #2Fabien Parent (3):
mfd: cros: add charger port count command definition
power: supply: cros: add support for dedicated port
power: supply: cros: add property to detect connected ports
Quoted 4 lines
I prepared an immutable branch for patch 1+2 and merged it into power-supply-next. I will push out the branch and send a pull request for the immutable branch to Lee later (once I have Internet connection).
The following changes since commit 5b394b2ddf0347bef56e50c69a58773c94343ff3:
Linux 4.19-rc1 (2018-08-26 14:11:59 -0700)
are available in the Git repository at:
ssh://[email protected]/pub/scm/linux/kernel/git/sre/linux-power-supply.git/ tags/psy-mfd-cros-immutable-for-v4.20-signed
for you to fetch changes up to 3af15cfacd1eef7f223802d49a88cae23c509183:
power: supply: cros: add support for dedicated port (2018-09-16 12:55:25 +0200)
----------------------------------------------------------------
Immutable branch for mfd and power-supply for v4.20
Immutable branch between mfd and power-supply for driver changes in CROS USBPD charger driver.
----------------------------------------------------------------
Fabien Parent (2):
mfd: cros: add charger port count command definition
power: supply: cros: add support for dedicated port
drivers/power/supply/cros_usbpd-charger.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- include/linux/mfd/cros_ec_commands.h | 10 ++++++++++ 2 files changed, 111 insertions(+), 14 deletions(-)
-- Sebastian