@@ -27,6 +27,22 @@
#include <linux/usb/ch9.h>
#include "hid-ids.h"
+/**
+ * enum cp2112_child_acpi_cell_addrs - Child ACPI addresses for CP2112 sub-functions
+ * @CP2112_I2C_ADR: Address for I2C node
+ */
+enum cp2112_child_acpi_cell_addrs {
+ CP2112_I2C_ADR = 0,
+};
+
+/*
+ * CP2112 Fwnode child names.
+ * CP2112 sub-functions can be described by named fwnode children or by ACPI _ADR
+ */
+static const char * const cp2112_cell_names[] = {
+ [CP2112_I2C_ADR] = "i2c",
+};
+
#define CP2112_REPORT_MAX_LENGTH 64
#define CP2112_GPIO_CONFIG_LENGTH 5
#define CP2112_GPIO_GET_LENGTH 2
@@ -1195,7 +1211,10 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
struct cp2112_device *dev;
u8 buf[3];
struct cp2112_smbus_config_report config;
+ struct fwnode_handle *child;
struct gpio_irq_chip *girq;
+ const char *name;
+ u32 addr;
int ret;
dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL);
@@ -1209,6 +1228,26 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
mutex_init(&dev->lock);
+ device_for_each_child_node(&hdev->dev, child) {
+ ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr);
+ if (ret) {
+ name = fwnode_get_name(child);
+ if (!name)
+ continue;
+ ret = match_string(cp2112_cell_names,
+ ARRAY_SIZE(cp2112_cell_names), name);
+ if (ret < 0)
+ continue;
+ addr = ret;
+ }
+
+ switch (addr) {
+ case CP2112_I2C_ADR:
+ device_set_node(&dev->adap.dev, child);
+ break;
+ }
+ }
+
ret = hid_parse(hdev);
if (ret) {
hid_err(hdev, "parse failed\n");
Support describing the CP2112's I2C and GPIO interfaces in firmware. The GPIO chip shares a firmware node with the CP2112. The I2C child node can either be a child with the name "i2c" or, in ACPI, a device node with _ADR Zero. Signed-off-by: Danny Kaehn <danny.kaehn@plexus.com> --- drivers/hid/hid-cp2112.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)