^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for cypress touch screen controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2009 Aava Mobile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Some cleanups by Alan Cox <alan@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/input/cy8ctmg110_pdata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define CY8CTMG110_DRIVER_NAME "cy8ctmg110"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Touch coordinates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define CY8CTMG110_X_MIN 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define CY8CTMG110_Y_MIN 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define CY8CTMG110_X_MAX 759
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define CY8CTMG110_Y_MAX 465
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* cy8ctmg110 register definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define CY8CTMG110_TOUCH_WAKEUP_TIME 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define CY8CTMG110_TOUCH_SLEEP_TIME 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define CY8CTMG110_TOUCH_X1 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define CY8CTMG110_TOUCH_Y1 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define CY8CTMG110_TOUCH_X2 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define CY8CTMG110_TOUCH_Y2 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define CY8CTMG110_FINGERS 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define CY8CTMG110_GESTURE 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define CY8CTMG110_REG_MAX 13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * The touch driver structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct cy8ctmg110 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int reset_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int irq_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * cy8ctmg110_power is the routine that is called when touch hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * will powered off or on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void cy8ctmg110_power(struct cy8ctmg110 *ts, bool poweron)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (ts->reset_pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) gpio_direction_output(ts->reset_pin, 1 - poweron);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int cy8ctmg110_write_regs(struct cy8ctmg110 *tsc, unsigned char reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) unsigned char len, unsigned char *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct i2c_client *client = tsc->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned char i2c_data[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) BUG_ON(len > 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) i2c_data[0] = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) memcpy(i2c_data + 1, value, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ret = i2c_master_send(client, i2c_data, len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (ret != len + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) dev_err(&client->dev, "i2c write data cmd failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return ret < 0 ? ret : -EIO;
^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) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static int cy8ctmg110_read_regs(struct cy8ctmg110 *tsc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unsigned char *data, unsigned char len, unsigned char cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct i2c_client *client = tsc->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct i2c_msg msg[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* first write slave position to i2c devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .buf = &cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* Second read data from position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .len = len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .buf = data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ret = i2c_transfer(client->adapter, msg, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int cy8ctmg110_touch_pos(struct cy8ctmg110 *tsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct input_dev *input = tsc->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) unsigned char reg_p[CY8CTMG110_REG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) memset(reg_p, 0, CY8CTMG110_REG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* Reading coordinates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (cy8ctmg110_read_regs(tsc, reg_p, 9, CY8CTMG110_TOUCH_X1) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) y = reg_p[2] << 8 | reg_p[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) x = reg_p[0] << 8 | reg_p[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* Number of touch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (reg_p[8] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) input_report_key(input, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) input_report_key(input, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) input_report_abs(input, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) input_report_abs(input, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static int cy8ctmg110_set_sleepmode(struct cy8ctmg110 *ts, bool sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) unsigned char reg_p[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (sleep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) reg_p[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) reg_p[1] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) reg_p[2] = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) reg_p[0] = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) reg_p[1] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) reg_p[2] = 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) return cy8ctmg110_write_regs(ts, CY8CTMG110_TOUCH_WAKEUP_TIME, 3, reg_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static irqreturn_t cy8ctmg110_irq_thread(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct cy8ctmg110 *tsc = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) cy8ctmg110_touch_pos(tsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int cy8ctmg110_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) const struct cy8ctmg110_pdata *pdata = dev_get_platdata(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct cy8ctmg110 *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* No pdata no way forward */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (pdata == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) dev_err(&client->dev, "no pdata\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!i2c_check_functionality(client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) I2C_FUNC_SMBUS_READ_WORD_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ts = kzalloc(sizeof(struct cy8ctmg110), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!ts || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ts->input = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ts->reset_pin = pdata->reset_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ts->irq_pin = pdata->irq_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) snprintf(ts->phys, sizeof(ts->phys),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) "%s/input0", dev_name(&client->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) input_dev->name = CY8CTMG110_DRIVER_NAME " Touchscreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) input_dev->phys = ts->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) input_dev->dev.parent = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) input_set_abs_params(input_dev, ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) CY8CTMG110_X_MIN, CY8CTMG110_X_MAX, 4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) input_set_abs_params(input_dev, ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) CY8CTMG110_Y_MIN, CY8CTMG110_Y_MAX, 4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (ts->reset_pin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) err = gpio_request(ts->reset_pin, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) "Unable to request GPIO pin %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ts->reset_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) cy8ctmg110_power(ts, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) cy8ctmg110_set_sleepmode(ts, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) err = gpio_request(ts->irq_pin, "touch_irq_key");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) "Failed to request GPIO %d, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) ts->irq_pin, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto err_shutoff_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) err = gpio_direction_input(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) "Failed to configure input direction for GPIO %d, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ts->irq_pin, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) goto err_free_irq_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) client->irq = gpio_to_irq(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (client->irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) err = client->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) "Unable to get irq number for GPIO %d, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ts->irq_pin, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) goto err_free_irq_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) err = request_threaded_irq(client->irq, NULL, cy8ctmg110_irq_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) IRQF_TRIGGER_RISING | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) "touch_reset_key", ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) "irq %d busy? error %d\n", client->irq, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) goto err_free_irq_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) err = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) i2c_set_clientdata(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) device_init_wakeup(&client->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) free_irq(client->irq, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) err_free_irq_gpio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) gpio_free(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) err_shutoff_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) cy8ctmg110_set_sleepmode(ts, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) cy8ctmg110_power(ts, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (ts->reset_pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) gpio_free(ts->reset_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) kfree(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int __maybe_unused cy8ctmg110_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct cy8ctmg110 *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) enable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) cy8ctmg110_set_sleepmode(ts, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) cy8ctmg110_power(ts, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static int __maybe_unused cy8ctmg110_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct cy8ctmg110 *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) disable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) cy8ctmg110_power(ts, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) cy8ctmg110_set_sleepmode(ts, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static SIMPLE_DEV_PM_OPS(cy8ctmg110_pm, cy8ctmg110_suspend, cy8ctmg110_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static int cy8ctmg110_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct cy8ctmg110 *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) cy8ctmg110_set_sleepmode(ts, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) cy8ctmg110_power(ts, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) free_irq(client->irq, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) input_unregister_device(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) gpio_free(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (ts->reset_pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) gpio_free(ts->reset_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) kfree(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static const struct i2c_device_id cy8ctmg110_idtable[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) { CY8CTMG110_DRIVER_NAME, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) MODULE_DEVICE_TABLE(i2c, cy8ctmg110_idtable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static struct i2c_driver cy8ctmg110_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .name = CY8CTMG110_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .pm = &cy8ctmg110_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .id_table = cy8ctmg110_idtable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .probe = cy8ctmg110_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .remove = cy8ctmg110_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) module_i2c_driver(cy8ctmg110_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) MODULE_AUTHOR("Samuli Konttila <samuli.konttila@aavamobile.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) MODULE_DESCRIPTION("cy8ctmg110 TouchScreen Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) MODULE_LICENSE("GPL v2");