2 * HID over I2C Open Firmware Subclass
5 * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
6 * Copyright (c) 2012 Red Hat, Inc
8 * This code was forked out of the core code, which was partly based on
9 * "USB HID support for Linux":
11 * Copyright (c) 1999 Andreas Gal
14 * Copyright (c) 2007-2008 Oliver Neukum
15 * Copyright (c) 2006-2010 Jiri Kosina
17 * This file is subject to the terms and conditions of the GNU General Public
18 * License. See the file COPYING in the main directory of this archive for
22 #include <linux/delay.h>
23 #include <linux/device.h>
24 #include <linux/hid.h>
25 #include <linux/i2c.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
30 #include <linux/regulator/consumer.h>
35 struct i2chid_ops ops;
37 struct i2c_client *client;
38 struct regulator_bulk_data supplies[2];
39 int post_power_delay_ms;
42 static int i2c_hid_of_power_up(struct i2chid_ops *ops)
44 struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops);
45 struct device *dev = &ihid_of->client->dev;
48 ret = regulator_bulk_enable(ARRAY_SIZE(ihid_of->supplies),
51 dev_warn(dev, "Failed to enable supplies: %d\n", ret);
55 if (ihid_of->post_power_delay_ms)
56 msleep(ihid_of->post_power_delay_ms);
61 static void i2c_hid_of_power_down(struct i2chid_ops *ops)
63 struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops);
65 regulator_bulk_disable(ARRAY_SIZE(ihid_of->supplies),
69 static int i2c_hid_of_probe(struct i2c_client *client,
70 const struct i2c_device_id *dev_id)
72 struct device *dev = &client->dev;
73 struct i2c_hid_of *ihid_of;
74 u16 hid_descriptor_address;
79 ihid_of = devm_kzalloc(&client->dev, sizeof(*ihid_of), GFP_KERNEL);
83 ihid_of->ops.power_up = i2c_hid_of_power_up;
84 ihid_of->ops.power_down = i2c_hid_of_power_down;
86 ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
88 dev_err(&client->dev, "HID register address not provided\n");
92 dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
96 hid_descriptor_address = val;
98 if (!device_property_read_u32(&client->dev, "post-power-on-delay-ms",
100 ihid_of->post_power_delay_ms = val;
102 ihid_of->supplies[0].supply = "vdd";
103 ihid_of->supplies[1].supply = "vddl";
104 ret = devm_regulator_bulk_get(&client->dev,
105 ARRAY_SIZE(ihid_of->supplies),
110 if (device_property_read_bool(dev, "touchscreen-inverted-x"))
111 quirks |= HID_QUIRK_X_INVERT;
113 if (device_property_read_bool(dev, "touchscreen-inverted-y"))
114 quirks |= HID_QUIRK_Y_INVERT;
116 return i2c_hid_core_probe(client, &ihid_of->ops,
117 hid_descriptor_address, quirks);
120 static const struct of_device_id i2c_hid_of_match[] = {
121 { .compatible = "hid-over-i2c" },
124 MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
126 static const struct i2c_device_id i2c_hid_of_id_table[] = {
128 { "hid-over-i2c", 0 },
131 MODULE_DEVICE_TABLE(i2c, i2c_hid_of_id_table);
133 static struct i2c_driver i2c_hid_of_driver = {
135 .name = "i2c_hid_of",
136 .pm = &i2c_hid_core_pm,
137 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
138 .of_match_table = of_match_ptr(i2c_hid_of_match),
141 .probe = i2c_hid_of_probe,
142 .remove = i2c_hid_core_remove,
143 .shutdown = i2c_hid_core_shutdown,
144 .id_table = i2c_hid_of_id_table,
147 module_i2c_driver(i2c_hid_of_driver);
149 MODULE_DESCRIPTION("HID over I2C OF driver");
151 MODULE_LICENSE("GPL");