Load cros_ec_ucsi from OF and ACPI definitions
Subsystems (6)
Jameson Thies
maintainercover Load cros_ec_ucsi from OF and ACPI definitions
The ChromeOS UCSI driver (cros_ec_ucsi) currently gets added as subdevice of cros_ec_dev. But without it being defined by an ACPI node or in the OF device tree, the typec connectors are not correctly associated with other part of the device tree. This series updates the cros_ec_ucsi driver to load based on device definitions in ACPI and OF. It also changes the cros_ec_dev driver to block adding cros_ec_ucsi as a subdevice if it is defined in the device tree.
For context, I initially sent out this series for review in March 2025
(https://lkml.kernel.org/[email protected]/).
Patch 1/3 has been updated to address comments from the initial review. There were some open questions on patch 3/3 regarding adding MFD children when there is no cros_ec_ucsi node and parents conditionally checking if a child exists to create one.
The expected behavior of this series is to only add the cros_ec_ucsi subdevice when there isn't a corresponding FW node because always adding it would result in multiple cros_ec_ucsi devices and too many ports being registered with the USB Type-C connector class on devices with correctly defined FW nodes. It also does not look for a child node to create a child. It is looking for a child of the parent EC device to only add cros_ec_ucsi if it does not already exist as a sibling.
Jameson Thies (3):
dt-bindings: chrome: Add Cros EC UCSI driver
usb: typec: cros_ec_ucsi: Load driver from OF and ACPI definitions
mfd: cros_ec: Don't add cros_ec_ucsi if it is defined in OF or ACPI
.../bindings/chrome/google,cros-ec-ucsi.yaml | 71 +++++++++++++++++++ drivers/mfd/cros_ec_dev.c | 38 ++++++++-- drivers/usb/typec/ucsi/cros_ec_ucsi.c | 25 ++++++- 3 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 Documentation/devicetree/bindings/chrome/google,cros-ec-ucsi.yaml
base-commit: 48633acccf38d706d7b368400647bb9db9caf1ae
Signature · 1 line
2.51.0.570.gb178f27e6d-goog
Jameson Thies
maintainerPATCH 1/3 dt-bindings: chrome: Add Cros EC UCSI driver
Chrome OS devices with PDCs allow the host to read port status and control port behavior with UCSI commands sent to the embedded controller (EC). Add documentation for cros-ec-ucsi node which loads the Chrome OS UCSI driver.
--- .../bindings/chrome/google,cros-ec-ucsi.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/chrome/google,cros-ec-ucsi.yaml
Documentation/devicetree/bindings/chrome/google,cros-ec-ucsi.yaml new file +71 -0
@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/chrome/google,cros-ec-ucsi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google Chrome OS EC(Embedded Controller) UCSI driver. + +maintainers: + - Abhishek Pandit-Subedi <[email protected]> + - Andrei Kuchynski <[email protected]> + - Benson Leung <[email protected]> + - Jameson Thies <[email protected]> + - Łukasz Bartosik <[email protected]> + +description: + Chrome OS devices with PDC-based USB-C ports expose a UCSI interface + from the Embedded Controller (EC) which allows the host to request + port state and control limited port behavior (DR/PR swap). This node + allows the host UCSI driver to send and receive UCSI commands to a + Chrome OS EC. The node for this device should be under a cros-ec node + like google,cros-ec-spi. + +properties: + compatible: + const: google,cros-ec-ucsi + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + '^connector@[0-9a-f]+$': + $ref: /schemas/connector/usb-connector.yaml# + required: + - reg + +required: + - compatible + +additionalProperties: false + +examples: + - |+ + spi { + #address-cells = <1>; + #size-cells = <0>; + + cros_ec: ec@0 { + compatible = "google,cros-ec-spi"; + reg = <0>; + interrupts = <35 0>; + + typec { + compatible = "google,cros-ec-ucsi"; + + #address-cells = <1>; + #size-cells = <0>; + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + power-role = "dual"; + data-role = "dual"; + try-power-role = "source"; + }; + }; + }; + };
Signature · 1 line
2.51.0.570.gb178f27e6d-goog
Jameson Thies
maintainerPATCH 2/3 usb: typec: cros_ec_ucsi: Load driver from OF and ACPI definitions
In reply to Jameson ThiesAdd support for cros_ec_ucsi to load based on "google,cros-ec-ucsi" compatible devices and "GOOG0021" ACPI nodes.
--- drivers/usb/typec/ucsi/cros_ec_ucsi.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +23 -2
@@ -5,11 +5,13 @@* Copyright 2024 Google LLC. */ +#include <linux/acpi.h> #include <linux/container_of.h> #include <linux/dev_printk.h> #include <linux/jiffies.h> #include <linux/mod_devicetable.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/platform_data/cros_ec_commands.h> #include <linux/platform_data/cros_usbpd_notify.h> #include <linux/platform_data/cros_ec_proto.h>
@@ -235,7 +237,7 @@ static void cros_ucsi_destroy(struct cros_ucsi_data *udata)static int cros_ucsi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct cros_ec_dev *ec_data =dev_get_drvdata (dev->parent); +struct cros_ec_dev *ec_data;struct cros_ucsi_data *udata;int ret;
@@ -244,8 +246,13 @@ static int cros_ucsi_probe(struct platform_device *pdev)return -ENOMEM ; udata->dev = dev; +if (is_acpi_device_node (dev->fwnode) ||is_of_node (dev->fwnode)) { + udata->ec =dev_get_drvdata (pdev->dev.parent); + }else { + ec_data =dev_get_drvdata (dev->parent); + udata->ec = ec_data->ec_dev; + } - udata->ec = ec_data->ec_dev;if (!udata->ec)return dev_err_probe (dev, -ENODEV ,"couldn't find parent EC device\n" );
@@ -326,10 +333,24 @@ static const struct platform_device_id cros_ucsi_id[] = { };MODULE_DEVICE_TABLE (platform, cros_ucsi_id); +static const struct acpi_device_id cros_ec_ucsi_acpi_device_ids[] = { + {"GOOG0021" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, cros_ec_ucsi_acpi_device_ids); + +static const struct of_device_id cros_ucsi_of_match[] = { + { .compatible ="google,cros-ec-ucsi" , }, + {} +}; +MODULE_DEVICE_TABLE (of, cros_ucsi_of_match); +static struct platform_driver cros_ucsi_driver = { .driver = { .name =KBUILD_MODNAME , .pm = &cros_ucsi_pm_ops, + .acpi_match_table = cros_ec_ucsi_acpi_device_ids, + .of_match_table = cros_ucsi_of_match, }, .id_table = cros_ucsi_id, .probe = cros_ucsi_probe,
Signature · 1 line
2.51.0.570.gb178f27e6d-goog
Jameson Thies
maintainerPATCH 3/3 mfd: cros_ec: Don't add cros_ec_ucsi if it is defined in OF or ACPI
In reply to Jameson ThiesOn devices with a UCSI PPM in the EC, check for cros_ec_ucsi to be defined in the OF device tree or an ACPI node. If it is defined by either OF or ACPI, it does not need to be added as a subdevice of cros_ec_dev.
--- drivers/mfd/cros_ec_dev.c | 40 ++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-)
drivers/mfd/cros_ec_dev.c +35 -5
@@ -5,6 +5,7 @@* Copyright (C) 2014 Google, Inc. */ +#include <linux/acpi.h> #include <linux/dmi.h> #include <linux/kconfig.h> #include <linux/mfd/core.h>
@@ -131,11 +132,6 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_ec_rtc_cells, .num_cells = ARRAY_SIZE(cros_ec_rtc_cells), }, - { - .id = EC_FEATURE_UCSI_PPM, - .mfd_cells = cros_ec_ucsi_cells, - .num_cells = ARRAY_SIZE(cros_ec_ucsi_cells), - }, { .id = EC_FEATURE_HANG_DETECT, .mfd_cells = cros_ec_wdt_cells,
@@ -177,6 +173,16 @@ static const struct mfd_cell cros_ec_vbc_cells[] = { { .name = "cros-ec-vbc", } }; +static int ucsi_acpi_match (struct device *dev,const void *data) +{ +struct acpi_device_id ucsi_acpi_device_ids[] = { + {"GOOG0021" ,0 }, + {"" ,0 }, + }; +return !!acpi_match_device (ucsi_acpi_device_ids, dev); +} + +static void cros_ec_class_release (struct device *dev) {kfree (to_cros_ec_dev (dev));
@@ -264,6 +270,30 @@ static int ec_device_probe(struct platform_device *pdev) } } +/* +* FW nodes can load cros_ec_ucsi, but early PDC devices did not define +* the required nodes. On PDC systems without FW nodes for cros_ec_ucsi, +* the driver should be added as an mfd subdevice. +*/ +if (cros_ec_check_features (ec,EC_FEATURE_USB_PD ) && +cros_ec_check_features (ec,EC_FEATURE_UCSI_PPM )) { +struct device *acpi_dev =device_find_child (ec->ec_dev->dev, +NULL , + ucsi_acpi_match); + +if (!!acpi_dev) { +put_device (acpi_dev); + }else if (!of_find_compatible_node (NULL ,NULL , +"google,cros-ec-ucsi" )) { + retval =mfd_add_hotplug_devices ( + ec->dev, cros_ec_ucsi_cells, +ARRAY_SIZE (cros_ec_ucsi_cells)); +if (retval) +dev_warn (ec->dev, +"failed to add cros_ec_ucsi: %d\n" , retval); + } + } +/* * UCSI provides power supply information so we don't need to separately * load the cros_usbpd_charger driver.
Signature · 1 line
2.51.0.570.gb178f27e6d-goog
Rob Herring (Arm)
maintainerRe: [PATCH v1 1/3] dt-bindings: chrome: Add Cros EC UCSI driver
In reply to Jameson ThiesQuoted 11 lines · Jameson Thies
Chrome OS devices with PDCs allow the host to read port status and control port behavior with UCSI commands sent to the embedded controller (EC). Add documentation for cros-ec-ucsi node which loads the Chrome OS UCSI driver.
Signed-off-by Jameson Thies <[email protected]>--- .../bindings/chrome/google,cros-ec-ucsi.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/chrome/google,cros-ec-ucsi.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/chrome/google,cros-ec-ucsi.example.dtb: ec@0 (google,cros-ec-spi): typec:compatible:0: 'google,cros-ec-typec' was expected
from schema $id: http://devicetree.org/schemas/mfd/google,cros-ec.yaml#
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Jameson Thies
maintainerRe: [PATCH v1 1/3] dt-bindings: chrome: Add Cros EC UCSI driver
Quoted 1 line
My bot found errors running 'make
dt_binding_check' on your patch:
Thanks for catching this. I did run "make dt_binding_check DT_SCHEMA_FILES=google,cros-ec-ucsi.yaml" to check the newly added yaml file. But I didn't check google,cros-ec.yaml or any of the DTS files with "make dtbs_check" so I missed this regression. I'll follow up with a v2 series and test all bindings with "make dt_binding_check" and "make dtbs_check".