Skip to content

Commit 3d7d248

Browse files
bentissJiri Kosina
authored andcommitted
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>
1 parent 3366dd9 commit 3d7d248

3 files changed

Lines changed: 73 additions & 2 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
};

‎drivers/hid/i2c-hid/i2c-hid.c‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/hid.h>
3636
#include <linux/mutex.h>
3737
#include <linux/acpi.h>
38+
#include <linux/of.h>
3839

3940
#include <linux/i2c/i2c-hid.h>
4041

@@ -933,6 +934,42 @@ static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
933934
}
934935
#endif
935936

937+
#ifdef CONFIG_OF
938+
static int i2c_hid_of_probe(struct i2c_client *client,
939+
struct i2c_hid_platform_data *pdata)
940+
{
941+
struct device *dev = &client->dev;
942+
u32 val;
943+
int ret;
944+
945+
ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
946+
if (ret) {
947+
dev_err(&client->dev, "HID register address not provided\n");
948+
return -ENODEV;
949+
}
950+
if (val >> 16) {
951+
dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
952+
val);
953+
return -EINVAL;
954+
}
955+
pdata->hid_descriptor_address = val;
956+
957+
return 0;
958+
}
959+
960+
static const struct of_device_id i2c_hid_of_match[] = {
961+
{ .compatible = "hid-over-i2c" },
962+
{},
963+
};
964+
MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
965+
#else
966+
static inline int i2c_hid_of_probe(struct i2c_client *client,
967+
struct i2c_hid_platform_data *pdata)
968+
{
969+
return -ENODEV;
970+
}
971+
#endif
972+
936973
static int i2c_hid_probe(struct i2c_client *client,
937974
const struct i2c_device_id *dev_id)
938975
{
@@ -954,7 +991,11 @@ static int i2c_hid_probe(struct i2c_client *client,
954991
if (!ihid)
955992
return -ENOMEM;
956993

957-
if (!platform_data) {
994+
if (client->dev.of_node) {
995+
ret = i2c_hid_of_probe(client, &ihid->pdata);
996+
if (ret)
997+
goto err;
998+
} else if (!platform_data) {
958999
ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
9591000
if (ret) {
9601001
dev_err(&client->dev,
@@ -1095,6 +1136,7 @@ static struct i2c_driver i2c_hid_driver = {
10951136
.owner = THIS_MODULE,
10961137
.pm = &i2c_hid_pm,
10971138
.acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
1139+
.of_match_table = of_match_ptr(i2c_hid_of_match),
10981140
},
10991141

11001142
.probe = i2c_hid_probe,

‎include/linux/i2c/i2c-hid.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
* @hid_descriptor_address: i2c register where the HID descriptor is stored.
2020
*
2121
* 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.
2324
* The platform driver should also setup the gpio according to the device:
2425
*
2526
* A typical example is the following:

0 commit comments

Comments
 (0)