Skip to content

Commit bd3cba0

Browse files
diandersJiri Kosina
authored andcommitted
HID: i2c-hid: elan: Add support for Elan eKTH6915 i2c-hid touchscreens
Like many i2c-hid touchscreen controllers, the Elan eKTH6915 has a reset GPIO hooked up to it. According to the datasheet, the way we're supposed to turn the touchscreen on is: 1. Turn on the 3.3V supply. 2. Turn on the IO supply. It's OK if this is hardwired to the 3.3V supply, but if it's not then it must be turned on _after_ the 3.3V supply. 3. Wait >= 1 ms. 4. Deassert the reset GPIO (reset GPIO is active low, so there would be a leakage path if this was deasserted _before_ the IO supply). 5. Wait 300 ms. Much of the above can be handled by the generic i2c-hid-of driver, but the "reset" GPIO is not supported by that driver. Thus we'll do the same as we did for Goodix and add a new tiny driver that uses the i2c-hid core. NOTE: support for this new touchscreen could theorically fit into the Goodix driver. I've made it a separate driver because the Elan driver supports _two_ regulators and it's unclear exactly how that would fit in with commit 18eeef4 ("HID: i2c-hid: goodix: Tie the reset line to true state of the regulator"). Signed-off-by: Douglas Anderson <[email protected]> Reviewed-by: Dmitry Torokhov <[email protected]> Reviewed-by: Matthias Kaehlcke <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent ded3021 commit bd3cba0

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

drivers/hid/i2c-hid/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ config I2C_HID_OF
3232
will be called i2c-hid-of. It will also build/depend on the
3333
module i2c-hid.
3434

35+
config I2C_HID_OF_ELAN
36+
tristate "Driver for Elan hid-i2c based devices on OF systems"
37+
default n
38+
depends on I2C && INPUT && OF
39+
help
40+
Say Y here if you want support for Elan i2c devices that use
41+
the i2c-hid protocol on Open Firmware (Device Tree)-based
42+
systems.
43+
44+
If unsure, say N.
45+
46+
This support is also available as a module. If so, the module
47+
will be called i2c-hid-of-elan. It will also build/depend on
48+
the module i2c-hid.
49+
3550
config I2C_HID_OF_GOODIX
3651
tristate "Driver for Goodix hid-i2c based devices on OF systems"
3752
default n

drivers/hid/i2c-hid/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ i2c-hid-$(CONFIG_DMI) += i2c-hid-dmi-quirks.o
1010

1111
obj-$(CONFIG_I2C_HID_ACPI) += i2c-hid-acpi.o
1212
obj-$(CONFIG_I2C_HID_OF) += i2c-hid-of.o
13+
obj-$(CONFIG_I2C_HID_OF_ELAN) += i2c-hid-of-elan.o
1314
obj-$(CONFIG_I2C_HID_OF_GOODIX) += i2c-hid-of-goodix.o

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

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Driver for Elan touchscreens that use the i2c-hid protocol.
4+
*
5+
* Copyright 2020 Google LLC
6+
*/
7+
8+
#include <linux/delay.h>
9+
#include <linux/device.h>
10+
#include <linux/gpio/consumer.h>
11+
#include <linux/i2c.h>
12+
#include <linux/kernel.h>
13+
#include <linux/module.h>
14+
#include <linux/of.h>
15+
#include <linux/pm.h>
16+
#include <linux/regulator/consumer.h>
17+
18+
#include "i2c-hid.h"
19+
20+
struct elan_i2c_hid_chip_data {
21+
unsigned int post_gpio_reset_delay_ms;
22+
unsigned int post_power_delay_ms;
23+
u16 hid_descriptor_address;
24+
};
25+
26+
struct i2c_hid_of_elan {
27+
struct i2chid_ops ops;
28+
29+
struct regulator *vcc33;
30+
struct regulator *vccio;
31+
struct gpio_desc *reset_gpio;
32+
const struct elan_i2c_hid_chip_data *chip_data;
33+
};
34+
35+
static int elan_i2c_hid_power_up(struct i2chid_ops *ops)
36+
{
37+
struct i2c_hid_of_elan *ihid_elan =
38+
container_of(ops, struct i2c_hid_of_elan, ops);
39+
int ret;
40+
41+
ret = regulator_enable(ihid_elan->vcc33);
42+
if (ret)
43+
return ret;
44+
45+
ret = regulator_enable(ihid_elan->vccio);
46+
if (ret) {
47+
regulator_disable(ihid_elan->vcc33);
48+
return ret;
49+
}
50+
51+
if (ihid_elan->chip_data->post_power_delay_ms)
52+
msleep(ihid_elan->chip_data->post_power_delay_ms);
53+
54+
gpiod_set_value_cansleep(ihid_elan->reset_gpio, 0);
55+
if (ihid_elan->chip_data->post_gpio_reset_delay_ms)
56+
msleep(ihid_elan->chip_data->post_gpio_reset_delay_ms);
57+
58+
return 0;
59+
}
60+
61+
static void elan_i2c_hid_power_down(struct i2chid_ops *ops)
62+
{
63+
struct i2c_hid_of_elan *ihid_elan =
64+
container_of(ops, struct i2c_hid_of_elan, ops);
65+
66+
gpiod_set_value_cansleep(ihid_elan->reset_gpio, 1);
67+
regulator_disable(ihid_elan->vccio);
68+
regulator_disable(ihid_elan->vcc33);
69+
}
70+
71+
static int i2c_hid_of_elan_probe(struct i2c_client *client,
72+
const struct i2c_device_id *id)
73+
{
74+
struct i2c_hid_of_elan *ihid_elan;
75+
76+
ihid_elan = devm_kzalloc(&client->dev, sizeof(*ihid_elan), GFP_KERNEL);
77+
if (!ihid_elan)
78+
return -ENOMEM;
79+
80+
ihid_elan->ops.power_up = elan_i2c_hid_power_up;
81+
ihid_elan->ops.power_down = elan_i2c_hid_power_down;
82+
83+
/* Start out with reset asserted */
84+
ihid_elan->reset_gpio =
85+
devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
86+
if (IS_ERR(ihid_elan->reset_gpio))
87+
return PTR_ERR(ihid_elan->reset_gpio);
88+
89+
ihid_elan->vccio = devm_regulator_get(&client->dev, "vccio");
90+
if (IS_ERR(ihid_elan->vccio))
91+
return PTR_ERR(ihid_elan->vccio);
92+
93+
ihid_elan->vcc33 = devm_regulator_get(&client->dev, "vcc33");
94+
if (IS_ERR(ihid_elan->vcc33))
95+
return PTR_ERR(ihid_elan->vcc33);
96+
97+
ihid_elan->chip_data = device_get_match_data(&client->dev);
98+
99+
return i2c_hid_core_probe(client, &ihid_elan->ops,
100+
ihid_elan->chip_data->hid_descriptor_address, 0);
101+
}
102+
103+
static const struct elan_i2c_hid_chip_data elan_ekth6915_chip_data = {
104+
.post_power_delay_ms = 1,
105+
.post_gpio_reset_delay_ms = 300,
106+
.hid_descriptor_address = 0x0001,
107+
};
108+
109+
static const struct of_device_id elan_i2c_hid_of_match[] = {
110+
{ .compatible = "elan,ekth6915", .data = &elan_ekth6915_chip_data },
111+
{ }
112+
};
113+
MODULE_DEVICE_TABLE(of, elan_i2c_hid_of_match);
114+
115+
static struct i2c_driver elan_i2c_hid_ts_driver = {
116+
.driver = {
117+
.name = "i2c_hid_of_elan",
118+
.pm = &i2c_hid_core_pm,
119+
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
120+
.of_match_table = of_match_ptr(elan_i2c_hid_of_match),
121+
},
122+
.probe = i2c_hid_of_elan_probe,
123+
.remove = i2c_hid_core_remove,
124+
.shutdown = i2c_hid_core_shutdown,
125+
};
126+
module_i2c_driver(elan_i2c_hid_ts_driver);
127+
128+
MODULE_AUTHOR("Douglas Anderson <[email protected]>");
129+
MODULE_DESCRIPTION("Elan i2c-hid touchscreen driver");
130+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)