HID: i2c-hid-of: Allow using i2c-hid-of on non OF platforms
authorHans de Goede <hdegoede@redhat.com>
Thu, 13 Apr 2023 09:36:24 +0000 (11:36 +0200)
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>
Thu, 13 Apr 2023 14:27:42 +0000 (16:27 +0200)
There are some x86 tablets / 2-in-1s which ship with Android as their
factory OS image. These have pretty broken ACPI tables, relying on
everything being hardcoded in the factory kernel image.

platform/x86/x86-android-tablets.c manually instantiates i2c-clients for
i2c devices on these tablets to make them work with the mainline kernel.

The Lenovo Yoga Book 1 (yb1-x90f/l) is such a 2-in-1. It has 2 I2C-HID
devices its main touchscreen and a Wacom digitizer. Its main touchscreen
can alternatively also be used in HiDeep's native protocol mode but
for the Wacom digitizer we really need I2C-HID.

This patch allows using i2c-hid-of on non OF platforms so that it can
bind to a non ACPI instantiated i2c_client on x86 for the Wacom digitizer.
Note the driver already has an "i2c-over-hid" i2c_device_id (rather then
an of_device_id).

Besides enabling building on non-OF platforms this also replaces
the only of_property_read_u32() call with device_property_read_u32() note
that other properties where already read using device_property_read_...().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20230413093625.71146-3-hdegoede@redhat.com
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
drivers/hid/i2c-hid/Kconfig
drivers/hid/i2c-hid/i2c-hid-of.c

index 4439be7fa74dd4b748e816d97fdaa41fce6ff71e..3be17109301a69154b8053dae657db3cdd54208b 100644 (file)
@@ -23,12 +23,14 @@ config I2C_HID_ACPI
 
 config I2C_HID_OF
        tristate "HID over I2C transport layer Open Firmware driver"
-       depends on OF
+       # No "depends on OF" because this can also be used for manually
+       # (board-file) instantiated "hid-over-i2c" type i2c-clients.
        select I2C_HID_CORE
        help
          Say Y here if you use a keyboard, a touchpad, a touchscreen, or any
          other HID based devices which is connected to your computer via I2C.
-         This driver supports Open Firmware (Device Tree)-based systems.
+         This driver supports Open Firmware (Device Tree)-based systems as
+         well as binding to manually (board-file) instantiated i2c-hid-clients.
 
          If unsure, say N.
 
index c82a5a54c3e6cbaa840306fd5d33a8e9baa222f0..385f7460e03cdbed774393c75451485b03651943 100644 (file)
@@ -82,7 +82,7 @@ static int i2c_hid_of_probe(struct i2c_client *client)
        ihid_of->ops.power_up = i2c_hid_of_power_up;
        ihid_of->ops.power_down = i2c_hid_of_power_down;
 
-       ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
+       ret = device_property_read_u32(dev, "hid-descr-addr", &val);
        if (ret) {
                dev_err(dev, "HID register address not provided\n");
                return -ENODEV;
@@ -113,11 +113,13 @@ static int i2c_hid_of_probe(struct i2c_client *client)
                                  hid_descriptor_address, quirks);
 }
 
+#ifdef CONFIG_OF
 static const struct of_device_id i2c_hid_of_match[] = {
        { .compatible = "hid-over-i2c" },
        {},
 };
 MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
+#endif
 
 static const struct i2c_device_id i2c_hid_of_id_table[] = {
        { "hid", 0 },