platform/chrome: Only register PCHG if present
Subsystems (4)
cover platform/chrome: Only register PCHG if present
I see a printk when booting on chromebooks that don't have the PCHG device. This series extracts the count function from the PCHG driver and uses it in the mfd driver to skip registration of the PCHG device if there aren't any charger ports. This gets rid of the message at boot and removes one struct device from my system.
Stephen Boyd (3):
platform/chrome: cros_ec_proto: Add peripheral charger count API
mfd: cros_ec_dev: Only register PCHG device if present
power: supply: PCHG: Use cros_ec_pchg_port_count()
drivers/mfd/cros_ec_dev.c | 16 ++++++++++ drivers/platform/chrome/cros_ec_proto.c | 31 +++++++++++++++++++ .../power/supply/cros_peripheral_charger.c | 29 +---------------- include/linux/platform_data/cros_ec_proto.h | 1 + 4 files changed, 49 insertions(+), 28 deletions(-)
base-commit: 3123109284176b1532874591f7c81f3837bbdc17
Signature · 1 line
https://chromeos.dev
PATCH 1/3 platform/chrome: cros_ec_proto: Add peripheral charger count API
Add a peripheral charger count API similar to the one implemented in the ChromeOS PCHG driver so we can use it to decide whether or not to register the PCHG device in the cros_ec MFD driver.
--- drivers/platform/chrome/cros_ec_proto.c | 31 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 1 + 2 files changed, 32 insertions(+)
drivers/platform/chrome/cros_ec_proto.c +31 -0
@@ -832,6 +832,37 @@ bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) }EXPORT_SYMBOL_GPL (cros_ec_check_features); +/** +* cros_ec_pchg_port_count() - Return the number of peripheral charger ports. +* @ec: EC device. +* +* Return: Number of peripheral charger ports, or 0 in case of error. +*/ +unsigned int cros_ec_pchg_port_count (struct cros_ec_dev *ec) +{ +struct cros_ec_command *msg; +const struct ec_response_pchg_count *rsp; +struct cros_ec_device *ec_dev = ec->ec_dev; +int ret, count =0 ; + + msg =kzalloc (sizeof (*msg) +sizeof (*rsp),GFP_KERNEL ); +if (!msg) +return 0 ; + + msg->command =EC_CMD_PCHG_COUNT + ec->cmd_offset; + msg->insize =sizeof (*rsp); + + ret =cros_ec_cmd_xfer_status (ec_dev, msg); +if (ret >=0 ) { + rsp = (const struct ec_response_pchg_count *)msg->data; + count = rsp->port_count; + } +kfree (msg); + +return count; +} +EXPORT_SYMBOL_GPL (cros_ec_pchg_port_count); +/** * cros_ec_get_sensor_count() - Return the number of MEMS sensors supported. *
include/linux/platform_data/cros_ec_proto.h +1 -0
@@ -230,6 +230,7 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);bool cros_ec_check_features (struct cros_ec_dev *ec,int feature);int cros_ec_get_sensor_count (struct cros_ec_dev *ec); +unsigned int cros_ec_pchg_port_count (struct cros_ec_dev *ec);int cros_ec_command (struct cros_ec_device *ec_dev,unsigned int version,int command,void *outdata,int outsize,void *indata,int insize);
Signature · 1 line
https://chromeos.dev
Re: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API
Quoted 10 lines · Stephen Boyd
Add a peripheral charger count API similar to the one implemented in the ChromeOS PCHG driver so we can use it to decide whether or not to register the PCHG device in the
cros_ecMFD driver.Cc Lee Jones <[email protected]>Cc Daisuke Nojiri <[email protected]>Cc Benson Leung <[email protected]>Cc Guenter Roeck <[email protected]>Cc <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
With a minor comment about the naming,
include/linux/platform_data/cros_ec_proto.h u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); · line 233
Quoted 9 lines
include/linux/platform_data/cros_ec_proto.h +1
-0@@ -230,6 +230,7 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);bool cros_ec_check_features (struct cros_ec_dev *ec,int feature);int cros_ec_get_sensor_count (struct cros_ec_dev *ec); +unsigned int cros_ec_pchg_port_count (struct cros_ec_dev *ec);
I wonder if "cros_ec_get_pchg_port_count" would be a better name for the API.
Re: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API
Quoting Tzung-Bi Shih (2022-04-17 20:23:27)
Quoted 12 lines · Stephen Boyd
Quoted 10 lines
Add a peripheral charger count API similar to the one implemented in the ChromeOS PCHG driver so we can use it to decide whether or not to register the PCHG device in the
cros_ecMFD driver.Cc Lee Jones <[email protected]>Cc Daisuke Nojiri <[email protected]>Cc Benson Leung <[email protected]>Cc Guenter Roeck <[email protected]>Cc <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Quoted 2 lines
With a minor comment about the naming,
Reviewed-by Tzung-Bi Shih <[email protected]>
Cool thanks.
Quoted 8 lines
Quoted 8 lines
include/linux/platform_data/cros_ec_proto.h +0
-0@@ -230,6 +230,7 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);bool cros_ec_check_features (struct cros_ec_dev *ec,int feature);
Quoted 4 lines
include/linux/platform_data/cros_ec_proto.h u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); · line 233
Quoted 2 lines
include/linux/platform_data/cros_ec_proto.h +1
-0int cros_ec_get_sensor_count (struct cros_ec_dev *ec); +unsigned int cros_ec_pchg_port_count (struct cros_ec_dev *ec);I wonder if "
cros_ec_get_pchg_port_count" would be a better name for the API.
Sure. I left out 'get' even though it's similar to cros_ec_get_sensor_count() because it seemed redundant. We can't "set" the port count. Anyway, I don't really care so I'll leave it up to cros maintainers.
Re: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API
In reply to Stephen BoydHey Stephen,
Quoted 39 lines · Stephen Boyd
Add a peripheral charger count API similar to the one implemented in the ChromeOS PCHG driver so we can use it to decide whether or not to register the PCHG device in the
cros_ecMFD driver.Cc Lee Jones <[email protected]>Cc Daisuke Nojiri <[email protected]>Cc Benson Leung <[email protected]>Cc Guenter Roeck <[email protected]>Cc <[email protected]>Signed-off-by Stephen Boyd <[email protected]>--- drivers/platform/chrome/cros_ec_proto.c | 31 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 1 + 2 files changed, 32 insertions(+)drivers/platform/chrome/cros_ec_proto.c +16
-0@@ -832,6 +832,37 @@ bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) }EXPORT_SYMBOL_GPL (cros_ec_check_features); +/** +* cros_ec_pchg_port_count() - Return the number of peripheral charger ports. +* @ec: EC device. +* +* Return: Number of peripheral charger ports, or 0 in case of error. +*/ +unsigned int cros_ec_pchg_port_count (struct cros_ec_dev *ec) +{ +struct cros_ec_command *msg; +const struct ec_response_pchg_count *rsp; +struct cros_ec_device *ec_dev = ec->ec_dev; +int ret, count =0 ; + + msg =kzalloc (sizeof (*msg) +sizeof (*rsp),GFP_KERNEL ); +if (!msg) +return 0 ;
drivers/platform/chrome/cros_ec_proto.c bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) · line 860
Quoted 10 lines
drivers/platform/chrome/cros_ec_proto.c +10
-0+ + msg->command =EC_CMD_PCHG_COUNT + ec->cmd_offset; + msg->insize =sizeof (*rsp); + + ret =cros_ec_cmd_xfer_status (ec_dev, msg); +if (ret >=0 ) { + rsp = (const struct ec_response_pchg_count *)msg->data; + count = rsp->port_count; + } +kfree (msg);
Can we use the wrapper function cros_ec_command() [1] here, which does the kzalloc and msg construction?
Best regards,
-Prashant
[1] https://elixir.bootlin.com/linux/latest/source/drivers/platform/chrome/cros_ec_proto.c#L914
Re: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API
Quoting Prashant Malani (2022-04-18 16:08:39)
Quoted 30 lines · Stephen Boyd
Quoted 29 lines
drivers/platform/chrome/cros_ec_proto.c +21
-0@@ -832,6 +832,37 @@ bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) }EXPORT_SYMBOL_GPL (cros_ec_check_features); +/** +* cros_ec_pchg_port_count() - Return the number of peripheral charger ports. +* @ec: EC device. +* +* Return: Number of peripheral charger ports, or 0 in case of error. +*/ +unsigned int cros_ec_pchg_port_count (struct cros_ec_dev *ec) +{ +struct cros_ec_command *msg; +const struct ec_response_pchg_count *rsp; +struct cros_ec_device *ec_dev = ec->ec_dev; +int ret, count =0 ; + + msg =kzalloc (sizeof (*msg) +sizeof (*rsp),GFP_KERNEL ); +if (!msg) +return 0 ; + + msg->command =EC_CMD_PCHG_COUNT + ec->cmd_offset; + msg->insize =sizeof (*rsp); + + ret =cros_ec_cmd_xfer_status (ec_dev, msg);
Quoted 9 lines
drivers/platform/chrome/cros_ec_proto.c bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) · line 860
Quoted 5 lines
drivers/platform/chrome/cros_ec_proto.c +5
-0+if (ret >=0 ) { + rsp = (const struct ec_response_pchg_count *)msg->data; + count = rsp->port_count; + } +kfree (msg);Can we use the wrapper function
cros_ec_command()[1] here, which does the kzalloc and msg construction?
Sure. I take it that I can drop this function entirely then? BTW, why is that function name the same as a struct name? It confuses my ctags.
Re: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API
Quoted 41 lines · Stephen Boyd
Quoting Prashant Malani (2022-04-18 16:08:39)
Quoted 30 lines · Stephen Boyd
Quoted 29 lines
drivers/platform/chrome/cros_ec_proto.c +21
-0@@ -832,6 +832,37 @@ bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) }EXPORT_SYMBOL_GPL (cros_ec_check_features); +/** +* cros_ec_pchg_port_count() - Return the number of peripheral charger ports. +* @ec: EC device. +* +* Return: Number of peripheral charger ports, or 0 in case of error. +*/ +unsigned int cros_ec_pchg_port_count (struct cros_ec_dev *ec) +{ +struct cros_ec_command *msg; +const struct ec_response_pchg_count *rsp; +struct cros_ec_device *ec_dev = ec->ec_dev; +int ret, count =0 ; + + msg =kzalloc (sizeof (*msg) +sizeof (*rsp),GFP_KERNEL ); +if (!msg) +return 0 ; + + msg->command =EC_CMD_PCHG_COUNT + ec->cmd_offset; + msg->insize =sizeof (*rsp); + + ret =cros_ec_cmd_xfer_status (ec_dev, msg);Quoted 9 lines
drivers/platform/chrome/cros_ec_proto.c bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) · line 860
Quoted 5 lines
drivers/platform/chrome/cros_ec_proto.c +5
-0+if (ret >=0 ) { + rsp = (const struct ec_response_pchg_count *)msg->data; + count = rsp->port_count; + } +kfree (msg);Can we use the wrapper function
cros_ec_command()[1] here, which does the kzalloc and msg construction?
Quoted 1 line
Sure. I take it that I can drop this function entirely then?
Yeah, if it's a simple response, should be fine.
Quoted 2 lines
BTW, why is
that function name the same as a struct name? It confuses my ctags.
Yeahhh, didn't think about ctags... :/
Topic for another series: probably can be renamed to cros_ec_cmd() (just to keep ctags happy) ?
Best regards,
-Prashant
Re: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API
Quoting Prashant Malani (2022-04-18 16:21:52)
Quoted 12 lines · Stephen Boyd
Quoted 2 lines
Sure. I take it that I can drop this function entirely then?
Yeah, if it's a simple response, should be fine.
Quoted 2 lines
BTW, why is
that function name the same as a struct name? It confuses my ctags.Yeahhh, didn't think about ctags... :/
Topic for another series: probably can be renamed tocros_ec_cmd()(just to keep ctags happy) ?
But then there'll be two cros_ec_cmd() because there's a cros-ec-regulator. Fun! :)
Re: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API
Quoted 10 lines · Stephen Boyd
Quoting Prashant Malani (2022-04-18 16:21:52)
Quoted 9 lines · Stephen Boyd
Quoted 2 lines
Sure. I take it that I can drop this function entirely then?
Yeah, if it's a simple response, should be fine.
Quoted 2 lines
BTW, why is
that function name the same as a struct name? It confuses my ctags.
Quoted 6 lines
Quoted 3 lines
Yeahhh, didn't think about ctags... :/
Topic for another series: probably can be renamed tocros_ec_cmd()(just to keep ctags happy) ?But then there'll be two
cros_ec_cmd()because there's a cros-ec-regulator. Fun! :)
Ugh :S
I think we can get rid of that one; it looks to be the same as this one :)
I'll write up a cleanup series if it all looks OK.
Re: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API
Quoting Prashant Malani (2022-04-18 16:31:57)
Quoted 18 lines · Stephen Boyd
Quoted 10 lines
Quoting Prashant Malani (2022-04-18 16:21:52)
Quoted 9 lines · Stephen Boyd
Quoted 2 lines
Sure. I take it that I can drop this function entirely then?
Yeah, if it's a simple response, should be fine.
Quoted 2 lines
BTW, why is
that function name the same as a struct name? It confuses my ctags.Quoted 6 lines
Quoted 3 lines
Yeahhh, didn't think about ctags... :/
Topic for another series: probably can be renamed tocros_ec_cmd()(just to keep ctags happy) ?But then there'll be two
cros_ec_cmd()because there's a cros-ec-regulator. Fun! :)
Quoted 8 lines
Ugh :S
I think we can get rid of that one; it looks to be the same as this one :)
I'll write up a cleanup series if it all looks OK.
Cool thanks! Would be useful to change those insize and outsize sizes to size_t as well. Please Cc me on the series. I'll resend this series with cros_ec_command() shortly.
PATCH 2/3 mfd: cros_ec_dev: Only register PCHG device if present
In reply to Stephen BoydDon't create a device for the peripheral charger (PCHG) if there aren't any peripheral charger ports. This removes a device on most ChromeOS systems, because the peripheral charger functionality isn't always present.
--- drivers/mfd/cros_ec_dev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/mfd/cros_ec_dev.c +16 -0
@@ -114,6 +114,9 @@ static const struct mfd_cell cros_ec_platform_cells[] = { { .name = "cros-ec-chardev", }, { .name = "cros-ec-debugfs", }, { .name = "cros-ec-sysfs", }, +}; + +static const struct mfd_cell cros_ec_pchg_cells[] = { { .name = "cros-ec-pchg", }, };
@@ -242,6 +245,19 @@ static int ec_device_probe(struct platform_device *pdev) } } +/* +* The PCHG device cannot be detected by sending EC_FEATURE_GET_CMD, but +* it can be detected by querying the number of peripheral chargers. +*/ +if (cros_ec_pchg_port_count (ec)) { + retval =mfd_add_hotplug_devices (ec->dev, + cros_ec_pchg_cells, +ARRAY_SIZE (cros_ec_pchg_cells)); +if (retval) +dev_warn (ec->dev,"failed to add pchg: %d\n" , + retval); + } +/* * The following subdevices cannot be detected by sending the * EC_FEATURE_GET_CMD to the Embedded Controller device.
Signature · 1 line
https://chromeos.dev
Re: [PATCH 2/3] mfd: cros_ec_dev: Only register PCHG device if present
Quoted 11 lines · Stephen Boyd
Don't create a device for the peripheral charger (PCHG) if there aren't any peripheral charger ports. This removes a device on most ChromeOS systems, because the peripheral charger functionality isn't always present.
Cc Lee Jones <[email protected]>Cc Daisuke Nojiri <[email protected]>Cc Benson Leung <[email protected]>Cc Guenter Roeck <[email protected]>Cc <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Share the same comment with the 1st patch in the series,
PATCH 3/3 power: supply: PCHG: Use cros_ec_pchg_port_count()
In reply to Stephen BoydUse the common function cros_ec_pchg_port_count() now that we only register this device when there are a non-zero number of peripheral charger ports.
--- .../power/supply/cros_peripheral_charger.c | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-)
drivers/power/supply/cros_peripheral_charger.c +1 -28
@@ -104,22 +104,6 @@ static bool cros_pchg_cmd_ver_check(const struct charger_data *charger)return !!(rsp.version_mask &BIT (pchg_cmd_version)); } -static int cros_pchg_port_count (const struct charger_data *charger) -{ -struct ec_response_pchg_count rsp; -int ret; - - ret =cros_pchg_ec_command (charger,0 ,EC_CMD_PCHG_COUNT , -NULL ,0 , &rsp,sizeof (rsp)); -if (ret <0 ) { -dev_warn (charger->dev, -"Unable to get number or ports (err:%d)\n" , ret); -return ret; - } - -return rsp.port_count; -} -static int cros_pchg_get_status (struct port_data *port) {struct charger_data *charger = port->charger;
@@ -281,24 +265,13 @@ static int cros_pchg_probe(struct platform_device *pdev) charger->ec_dev = ec_dev; charger->ec_device = ec_device; - ret =cros_pchg_port_count (charger); -if (ret <=0 ) { -/* -* This feature is enabled by the EC and the kernel driver is -* included by default for CrOS devices. Don't need to be loud -* since this error can be normal. -*/ -dev_info (dev,"No peripheral charge ports (err:%d)\n" , ret); -return -ENODEV ; - } -if (!cros_pchg_cmd_ver_check (charger)) {dev_err (dev,"EC_CMD_PCHG version %d isn't available.\n" , pchg_cmd_version);return -EOPNOTSUPP ; } - num_ports = ret; + num_ports =cros_ec_pchg_port_count (ec_dev);if (num_ports >EC_PCHG_MAX_PORTS ) {dev_err (dev,"Too many peripheral charge ports (%d)\n" , num_ports);
Signature · 1 line
https://chromeos.dev
Re: [PATCH 3/3] power: supply: PCHG: Use cros_ec_pchg_port_count()
Quoted 10 lines · Stephen Boyd
Use the common function
cros_ec_pchg_port_count()now that we only register this device when there are a non-zero number of peripheral charger ports.Cc Lee Jones <[email protected]>Cc Daisuke Nojiri <[email protected]>Cc Benson Leung <[email protected]>Cc Guenter Roeck <[email protected]>Cc <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Share the same comment with the 1st patch in the series,