|
5 | 5 | * Copyright 2024 Google LLC. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +#include <linux/acpi.h> |
8 | 9 | #include <linux/container_of.h> |
9 | 10 | #include <linux/dev_printk.h> |
10 | 11 | #include <linux/jiffies.h> |
11 | 12 | #include <linux/mod_devicetable.h> |
12 | 13 | #include <linux/module.h> |
| 14 | +#include <linux/of.h> |
13 | 15 | #include <linux/platform_data/cros_ec_commands.h> |
14 | 16 | #include <linux/platform_data/cros_usbpd_notify.h> |
15 | 17 | #include <linux/platform_data/cros_ec_proto.h> |
@@ -257,17 +259,23 @@ static void cros_ucsi_destroy(struct cros_ucsi_data *udata) |
257 | 259 | static int cros_ucsi_probe(struct platform_device *pdev) |
258 | 260 | { |
259 | 261 | struct device *dev = &pdev->dev; |
260 | | - struct cros_ec_dev *ec_data = dev_get_drvdata(dev->parent); |
261 | 262 | struct cros_ucsi_data *udata; |
262 | 263 | int ret; |
263 | 264 |
|
264 | 265 | udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL); |
265 | 266 | if (!udata) |
266 | 267 | return -ENOMEM; |
267 | 268 |
|
| 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 | + */ |
268 | 273 | 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; |
269 | 278 |
|
270 | | - udata->ec = ec_data->ec_dev; |
271 | 279 | if (!udata->ec) |
272 | 280 | return dev_err_probe(dev, -ENODEV, "couldn't find parent EC device\n"); |
273 | 281 |
|
@@ -348,10 +356,24 @@ static const struct platform_device_id cros_ucsi_id[] = { |
348 | 356 | }; |
349 | 357 | MODULE_DEVICE_TABLE(platform, cros_ucsi_id); |
350 | 358 |
|
| 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 | + |
351 | 371 | static struct platform_driver cros_ucsi_driver = { |
352 | 372 | .driver = { |
353 | 373 | .name = KBUILD_MODNAME, |
354 | 374 | .pm = &cros_ucsi_pm_ops, |
| 375 | + .acpi_match_table = cros_ec_ucsi_acpi_device_ids, |
| 376 | + .of_match_table = cros_ucsi_of_match, |
355 | 377 | }, |
356 | 378 | .id_table = cros_ucsi_id, |
357 | 379 | .probe = cros_ucsi_probe, |
|
0 commit comments