Skip to content

Commit ba984d2

Browse files
author
Jiri Kosina
committed
Merge branch 'for-6.4/i2c-hid' into for-linus
- reset GPIO support (Hans de Goede)
2 parents 63f7cf6 + 2be4044 commit ba984d2

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

drivers/hid/i2c-hid/Kconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ config I2C_HID_ACPI
2323

2424
config I2C_HID_OF
2525
tristate "HID over I2C transport layer Open Firmware driver"
26-
depends on OF
26+
# No "depends on OF" because this can also be used for manually
27+
# (board-file) instantiated "hid-over-i2c" type i2c-clients.
2728
select I2C_HID_CORE
2829
help
2930
Say Y here if you use a keyboard, a touchpad, a touchscreen, or any
3031
other HID based devices which is connected to your computer via I2C.
31-
This driver supports Open Firmware (Device Tree)-based systems.
32+
This driver supports Open Firmware (Device Tree)-based systems as
33+
well as binding to manually (board-file) instantiated i2c-hid-clients.
3234

3335
If unsure, say N.
3436

drivers/hid/i2c-hid/i2c-hid-of.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <linux/delay.h>
2323
#include <linux/device.h>
24+
#include <linux/gpio/consumer.h>
2425
#include <linux/hid.h>
2526
#include <linux/i2c.h>
2627
#include <linux/kernel.h>
@@ -35,8 +36,10 @@ struct i2c_hid_of {
3536
struct i2chid_ops ops;
3637

3738
struct i2c_client *client;
39+
struct gpio_desc *reset_gpio;
3840
struct regulator_bulk_data supplies[2];
3941
int post_power_delay_ms;
42+
int post_reset_delay_ms;
4043
};
4144

4245
static int i2c_hid_of_power_up(struct i2chid_ops *ops)
@@ -55,13 +58,18 @@ static int i2c_hid_of_power_up(struct i2chid_ops *ops)
5558
if (ihid_of->post_power_delay_ms)
5659
msleep(ihid_of->post_power_delay_ms);
5760

61+
gpiod_set_value_cansleep(ihid_of->reset_gpio, 0);
62+
if (ihid_of->post_reset_delay_ms)
63+
msleep(ihid_of->post_reset_delay_ms);
64+
5865
return 0;
5966
}
6067

6168
static void i2c_hid_of_power_down(struct i2chid_ops *ops)
6269
{
6370
struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops);
6471

72+
gpiod_set_value_cansleep(ihid_of->reset_gpio, 1);
6573
regulator_bulk_disable(ARRAY_SIZE(ihid_of->supplies),
6674
ihid_of->supplies);
6775
}
@@ -75,33 +83,43 @@ static int i2c_hid_of_probe(struct i2c_client *client)
7583
int ret;
7684
u32 val;
7785

78-
ihid_of = devm_kzalloc(&client->dev, sizeof(*ihid_of), GFP_KERNEL);
86+
ihid_of = devm_kzalloc(dev, sizeof(*ihid_of), GFP_KERNEL);
7987
if (!ihid_of)
8088
return -ENOMEM;
8189

8290
ihid_of->ops.power_up = i2c_hid_of_power_up;
8391
ihid_of->ops.power_down = i2c_hid_of_power_down;
8492

85-
ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
93+
ret = device_property_read_u32(dev, "hid-descr-addr", &val);
8694
if (ret) {
87-
dev_err(&client->dev, "HID register address not provided\n");
95+
dev_err(dev, "HID register address not provided\n");
8896
return -ENODEV;
8997
}
9098
if (val >> 16) {
91-
dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
92-
val);
99+
dev_err(dev, "Bad HID register address: 0x%08x\n", val);
93100
return -EINVAL;
94101
}
95102
hid_descriptor_address = val;
96103

97-
if (!device_property_read_u32(&client->dev, "post-power-on-delay-ms",
98-
&val))
104+
if (!device_property_read_u32(dev, "post-power-on-delay-ms", &val))
99105
ihid_of->post_power_delay_ms = val;
100106

107+
/*
108+
* Note this is a kernel internal device-property set by x86 platform code,
109+
* this MUST not be used in devicetree files without first adding it to
110+
* the DT bindings.
111+
*/
112+
if (!device_property_read_u32(dev, "post-reset-deassert-delay-ms", &val))
113+
ihid_of->post_reset_delay_ms = val;
114+
115+
/* Start out with reset asserted */
116+
ihid_of->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
117+
if (IS_ERR(ihid_of->reset_gpio))
118+
return PTR_ERR(ihid_of->reset_gpio);
119+
101120
ihid_of->supplies[0].supply = "vdd";
102121
ihid_of->supplies[1].supply = "vddl";
103-
ret = devm_regulator_bulk_get(&client->dev,
104-
ARRAY_SIZE(ihid_of->supplies),
122+
ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ihid_of->supplies),
105123
ihid_of->supplies);
106124
if (ret)
107125
return ret;
@@ -116,11 +134,13 @@ static int i2c_hid_of_probe(struct i2c_client *client)
116134
hid_descriptor_address, quirks);
117135
}
118136

137+
#ifdef CONFIG_OF
119138
static const struct of_device_id i2c_hid_of_match[] = {
120139
{ .compatible = "hid-over-i2c" },
121140
{},
122141
};
123142
MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
143+
#endif
124144

125145
static const struct i2c_device_id i2c_hid_of_id_table[] = {
126146
{ "hid", 0 },

0 commit comments

Comments
 (0)