Skip to content

Commit 40b17a3

Browse files
jthiesatgooglegregkh
authored andcommitted
usb: typec: cros_ec_ucsi: Load driver from OF and ACPI definitions
Add support for cros_ec_ucsi to load based on "google,cros-ec-ucsi" compatible devices and "GOOG0021" ACPI nodes. Signed-off-by: Jameson Thies <jthies@google.com> Reviewed-by: Benson Leung <bleung@chromium.org> Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org> Link: https://patch.msgid.link/20260403223357.1896403-3-jthies@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 250892b commit 40b17a3

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

drivers/usb/typec/ucsi/cros_ec_ucsi.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
* Copyright 2024 Google LLC.
66
*/
77

8+
#include <linux/acpi.h>
89
#include <linux/container_of.h>
910
#include <linux/dev_printk.h>
1011
#include <linux/jiffies.h>
1112
#include <linux/mod_devicetable.h>
1213
#include <linux/module.h>
14+
#include <linux/of.h>
1315
#include <linux/platform_data/cros_ec_commands.h>
1416
#include <linux/platform_data/cros_usbpd_notify.h>
1517
#include <linux/platform_data/cros_ec_proto.h>
@@ -257,17 +259,23 @@ static void cros_ucsi_destroy(struct cros_ucsi_data *udata)
257259
static int cros_ucsi_probe(struct platform_device *pdev)
258260
{
259261
struct device *dev = &pdev->dev;
260-
struct cros_ec_dev *ec_data = dev_get_drvdata(dev->parent);
261262
struct cros_ucsi_data *udata;
262263
int ret;
263264

264265
udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL);
265266
if (!udata)
266267
return -ENOMEM;
267268

269+
/* ACPI and OF FW nodes for cros_ec_ucsi are children of the ChromeOS EC. If the
270+
* cros_ec_ucsi device has an ACPI or OF FW node, its parent is the ChromeOS EC device.
271+
* Platforms without a FW node for cros_ec_ucsi may add it as a subdevice of cros_ec_dev.
272+
*/
268273
udata->dev = dev;
274+
if (is_acpi_device_node(dev->fwnode) || is_of_node(dev->fwnode))
275+
udata->ec = dev_get_drvdata(dev->parent);
276+
else
277+
udata->ec = ((struct cros_ec_dev *)dev_get_drvdata(dev->parent))->ec_dev;
269278

270-
udata->ec = ec_data->ec_dev;
271279
if (!udata->ec)
272280
return dev_err_probe(dev, -ENODEV, "couldn't find parent EC device\n");
273281

@@ -348,10 +356,24 @@ static const struct platform_device_id cros_ucsi_id[] = {
348356
};
349357
MODULE_DEVICE_TABLE(platform, cros_ucsi_id);
350358

359+
static const struct acpi_device_id cros_ec_ucsi_acpi_device_ids[] = {
360+
{ "GOOG0021", 0 },
361+
{ }
362+
};
363+
MODULE_DEVICE_TABLE(acpi, cros_ec_ucsi_acpi_device_ids);
364+
365+
static const struct of_device_id cros_ucsi_of_match[] = {
366+
{ .compatible = "google,cros-ec-ucsi", },
367+
{}
368+
};
369+
MODULE_DEVICE_TABLE(of, cros_ucsi_of_match);
370+
351371
static struct platform_driver cros_ucsi_driver = {
352372
.driver = {
353373
.name = KBUILD_MODNAME,
354374
.pm = &cros_ucsi_pm_ops,
375+
.acpi_match_table = cros_ec_ucsi_acpi_device_ids,
376+
.of_match_table = cros_ucsi_of_match,
355377
},
356378
.id_table = cros_ucsi_id,
357379
.probe = cros_ucsi_probe,

0 commit comments

Comments
 (0)