]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
HID: cp2112: Add fwnode support
authorDanny Kaehn <danny.kaehn@plexus.com>
Wed, 20 May 2026 16:13:06 +0000 (11:13 -0500)
committerJiri Kosina <jkosina@suse.com>
Wed, 10 Jun 2026 15:34:39 +0000 (17:34 +0200)
Support describing the CP2112's I2C and GPIO interfaces in firmware.

Bindings between the firmware nodes and the functions of the device
are distinct between ACPI and DeviceTree.

For ACPI, the i2c_adapter will use the child with _ADR equal to Zero
and the gpio_chip will use the child with _ADR equal to One.

For DeviceTree, the i2c_adapter will use the child with name "i2c",
but the gpio_chip will share a firmware node with the CP2112.

Signed-off-by: Danny Kaehn <danny.kaehn@plexus.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Tested-by: Jacky Huang <jackyhuang@nvidia.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
drivers/hid/hid-cp2112.c

index 803b883ae8750f39e9748f4f89b37c5971b4cbec..e960fc988058f945a8f0ca735a6e55fa7f906f89 100644 (file)
 #include <linux/usb/ch9.h>
 #include "hid-ids.h"
 
+/**
+ * enum cp2112_child_acpi_cell_addrs - Child ACPI addresses for CP2112 sub-functions
+ * Note that the enum values are explicitly defined, as this defines the interface
+ * between ACPI and Linux
+ * @CP2112_I2C_ADR: Address for I2C node
+ * @CP2112_GPIO_ADR: Address for GPIO node
+ */
+enum cp2112_child_acpi_cell_addrs {
+       CP2112_I2C_ADR = 0,
+       CP2112_GPIO_ADR = 1,
+};
+
 #define CP2112_REPORT_MAX_LENGTH               64
 #define CP2112_GPIO_CONFIG_LENGTH              5
 #define CP2112_GPIO_GET_LENGTH                 2
@@ -1208,7 +1220,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 *cp2112_fwnode;
+       struct fwnode_handle *child;
        struct gpio_irq_chip *girq;
+       u32 addr;
        int ret;
 
        dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL);
@@ -1226,6 +1241,28 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
                return ret;
        }
 
+       cp2112_fwnode = dev_fwnode(&hdev->dev);
+       if (is_acpi_device_node(cp2112_fwnode)) {
+               fwnode_for_each_child_node(cp2112_fwnode, child) {
+                       ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr);
+                       if (ret)
+                               continue;
+
+                       switch (addr) {
+                       case CP2112_I2C_ADR:
+                               device_set_node(&dev->adap.dev, child);
+                               break;
+                       case CP2112_GPIO_ADR:
+                               dev->gc.fwnode = child;
+                               break;
+                       }
+               }
+       } else if (is_of_node(cp2112_fwnode)) {
+               child = fwnode_get_named_child_node(cp2112_fwnode, "i2c");
+               device_set_node(&dev->adap.dev, child);
+               fwnode_handle_put(child);
+       }
+
        ret = hid_parse(hdev);
        if (ret) {
                hid_err(hdev, "parse failed\n");