Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: i2c-hid: add DT bindings

Add device tree based support for HID over I2C devices.

Tested on an Odroid-X board with a Synaptics touchpad.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

authored by

Benjamin Tissoires and committed by
Jiri Kosina
3d7d248c 3366dd9f

+73 -2
+28
Documentation/devicetree/bindings/hid/hid-over-i2c.txt
··· 1 + * HID over I2C Device-Tree bindings 2 + 3 + HID over I2C provides support for various Human Interface Devices over the 4 + I2C bus. These devices can be for example touchpads, keyboards, touch screens 5 + or sensors. 6 + 7 + The specification has been written by Microsoft and is currently available here: 8 + http://msdn.microsoft.com/en-us/library/windows/hardware/hh852380.aspx 9 + 10 + If this binding is used, the kernel module i2c-hid will handle the communication 11 + with the device and the generic hid core layer will handle the protocol. 12 + 13 + Required properties: 14 + - compatible: must be "hid-over-i2c" 15 + - reg: i2c slave address 16 + - hid-descr-addr: HID descriptor address 17 + - interrupt-parent: the phandle for the interrupt controller 18 + - interrupts: interrupt line 19 + 20 + Example: 21 + 22 + i2c-hid-dev@2c { 23 + compatible = "hid-over-i2c"; 24 + reg = <0x2c>; 25 + hid-descr-addr = <0x0020>; 26 + interrupt-parent = <&gpx3>; 27 + interrupts = <3 2>; 28 + };
+43 -1
drivers/hid/i2c-hid/i2c-hid.c
··· 35 35 #include <linux/hid.h> 36 36 #include <linux/mutex.h> 37 37 #include <linux/acpi.h> 38 + #include <linux/of.h> 38 39 39 40 #include <linux/i2c/i2c-hid.h> 40 41 ··· 934 933 } 935 934 #endif 936 935 936 + #ifdef CONFIG_OF 937 + static int i2c_hid_of_probe(struct i2c_client *client, 938 + struct i2c_hid_platform_data *pdata) 939 + { 940 + struct device *dev = &client->dev; 941 + u32 val; 942 + int ret; 943 + 944 + ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val); 945 + if (ret) { 946 + dev_err(&client->dev, "HID register address not provided\n"); 947 + return -ENODEV; 948 + } 949 + if (val >> 16) { 950 + dev_err(&client->dev, "Bad HID register address: 0x%08x\n", 951 + val); 952 + return -EINVAL; 953 + } 954 + pdata->hid_descriptor_address = val; 955 + 956 + return 0; 957 + } 958 + 959 + static const struct of_device_id i2c_hid_of_match[] = { 960 + { .compatible = "hid-over-i2c" }, 961 + {}, 962 + }; 963 + MODULE_DEVICE_TABLE(of, i2c_hid_of_match); 964 + #else 965 + static inline int i2c_hid_of_probe(struct i2c_client *client, 966 + struct i2c_hid_platform_data *pdata) 967 + { 968 + return -ENODEV; 969 + } 970 + #endif 971 + 937 972 static int i2c_hid_probe(struct i2c_client *client, 938 973 const struct i2c_device_id *dev_id) 939 974 { ··· 991 954 if (!ihid) 992 955 return -ENOMEM; 993 956 994 - if (!platform_data) { 957 + if (client->dev.of_node) { 958 + ret = i2c_hid_of_probe(client, &ihid->pdata); 959 + if (ret) 960 + goto err; 961 + } else if (!platform_data) { 995 962 ret = i2c_hid_acpi_pdata(client, &ihid->pdata); 996 963 if (ret) { 997 964 dev_err(&client->dev, ··· 1136 1095 .owner = THIS_MODULE, 1137 1096 .pm = &i2c_hid_pm, 1138 1097 .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match), 1098 + .of_match_table = of_match_ptr(i2c_hid_of_match), 1139 1099 }, 1140 1100 1141 1101 .probe = i2c_hid_probe,
+2 -1
include/linux/i2c/i2c-hid.h
··· 19 19 * @hid_descriptor_address: i2c register where the HID descriptor is stored. 20 20 * 21 21 * Note that it is the responsibility of the platform driver (or the acpi 5.0 22 - * driver) to setup the irq related to the gpio in the struct i2c_board_info. 22 + * driver, or the flattened device tree) to setup the irq related to the gpio in 23 + * the struct i2c_board_info. 23 24 * The platform driver should also setup the gpio according to the device: 24 25 * 25 26 * A typical example is the following: