^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Touch Screen driver for EETI's I2C connected touch screen panels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2009,2018 Daniel Mack <daniel@zonque.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * See EETI's software guide for the protocol specification:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * http://home.eeti.com.tw/documentation.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Based on migor_ts.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (c) 2008 Magnus Damm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (c) 2007 Ujjwal Pande <ujjwal@kenati.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/input/touchscreen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct eeti_ts {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct gpio_desc *attn_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct touchscreen_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) bool running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define EETI_TS_BITDEPTH (11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define EETI_MAXVAL ((1 << (EETI_TS_BITDEPTH + 1)) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define REPORT_BIT_PRESSED BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define REPORT_BIT_AD0 BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define REPORT_BIT_AD1 BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define REPORT_BIT_HAS_PRESSURE BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define REPORT_RES_BITS(v) (((v) >> 1) + EETI_TS_BITDEPTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void eeti_ts_report_event(struct eeti_ts *eeti, u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u16 x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) res = REPORT_RES_BITS(buf[0] & (REPORT_BIT_AD0 | REPORT_BIT_AD1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) x = get_unaligned_be16(&buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) y = get_unaligned_be16(&buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* fix the range to 11 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) x >>= res - EETI_TS_BITDEPTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) y >>= res - EETI_TS_BITDEPTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (buf[0] & REPORT_BIT_HAS_PRESSURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) input_report_abs(eeti->input, ABS_PRESSURE, buf[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) touchscreen_report_pos(eeti->input, &eeti->props, x, y, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) input_report_key(eeti->input, BTN_TOUCH, buf[0] & REPORT_BIT_PRESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) input_sync(eeti->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int eeti_ts_read(struct eeti_ts *eeti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int len, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) char buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) len = i2c_master_recv(eeti->client, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (len != sizeof(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) error = len < 0 ? len : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) dev_err(&eeti->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) "failed to read touchscreen data: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* Motion packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (buf[0] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) eeti_ts_report_event(eeti, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static irqreturn_t eeti_ts_isr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct eeti_ts *eeti = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) mutex_lock(&eeti->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * If we have attention GPIO, trust it. Otherwise we'll read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * once and exit. We assume that in this case we are using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * level triggered interrupt and it will get raised again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * if/when there is more data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (eeti->attn_gpio &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) !gpiod_get_value_cansleep(eeti->attn_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) error = eeti_ts_read(eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) } while (eeti->running && eeti->attn_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mutex_unlock(&eeti->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static void eeti_ts_start(struct eeti_ts *eeti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) mutex_lock(&eeti->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) eeti->running = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) enable_irq(eeti->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * Kick the controller in case we are using edge interrupt and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * we missed our edge while interrupt was disabled. We expect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * the attention GPIO to be wired in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (eeti->attn_gpio && gpiod_get_value_cansleep(eeti->attn_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) eeti_ts_read(eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) mutex_unlock(&eeti->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static void eeti_ts_stop(struct eeti_ts *eeti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * Not locking here, just setting a flag and expect that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * interrupt thread will notice the flag eventually.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) eeti->running = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) disable_irq(eeti->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int eeti_ts_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct eeti_ts *eeti = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) eeti_ts_start(eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void eeti_ts_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct eeti_ts *eeti = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) eeti_ts_stop(eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int eeti_ts_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) const struct i2c_device_id *idp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct eeti_ts *eeti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * In contrast to what's described in the datasheet, there seems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * to be no way of probing the presence of that device using I2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * commands. So we need to blindly believe it is there, and wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * for interrupts to occur.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) eeti = devm_kzalloc(dev, sizeof(*eeti), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (!eeti) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) dev_err(dev, "failed to allocate driver data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) mutex_init(&eeti->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) input = devm_input_allocate_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (!input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) dev_err(dev, "Failed to allocate input device.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) input_set_capability(input, EV_KEY, BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) input_set_abs_params(input, ABS_X, 0, EETI_MAXVAL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) input_set_abs_params(input, ABS_Y, 0, EETI_MAXVAL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) input_set_abs_params(input, ABS_PRESSURE, 0, 0xff, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) touchscreen_parse_properties(input, false, &eeti->props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) input->name = client->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) input->open = eeti_ts_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) input->close = eeti_ts_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) eeti->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) eeti->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) eeti->attn_gpio = devm_gpiod_get_optional(dev, "attn", GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (IS_ERR(eeti->attn_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return PTR_ERR(eeti->attn_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) i2c_set_clientdata(client, eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) input_set_drvdata(input, eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) error = devm_request_threaded_irq(dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) NULL, eeti_ts_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) client->name, eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) dev_err(dev, "Unable to request touchscreen IRQ: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Disable the device for now. It will be enabled once the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * input device is opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) eeti_ts_stop(eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static int __maybe_unused eeti_ts_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct eeti_ts *eeti = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct input_dev *input_dev = eeti->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) mutex_lock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (input_dev->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) eeti_ts_stop(eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) mutex_unlock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) enable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int __maybe_unused eeti_ts_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct eeti_ts *eeti = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct input_dev *input_dev = eeti->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) disable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) mutex_lock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (input_dev->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) eeti_ts_start(eeti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) mutex_unlock(&input_dev->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static SIMPLE_DEV_PM_OPS(eeti_ts_pm, eeti_ts_suspend, eeti_ts_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static const struct i2c_device_id eeti_ts_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) { "eeti_ts", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) MODULE_DEVICE_TABLE(i2c, eeti_ts_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static const struct of_device_id of_eeti_ts_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) { .compatible = "eeti,exc3000-i2c", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static struct i2c_driver eeti_ts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .name = "eeti_ts",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .pm = &eeti_ts_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .of_match_table = of_match_ptr(of_eeti_ts_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .probe = eeti_ts_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .id_table = eeti_ts_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) module_i2c_driver(eeti_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) MODULE_DESCRIPTION("EETI Touchscreen driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) MODULE_AUTHOR("Daniel Mack <daniel@zonque.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) MODULE_LICENSE("GPL");