^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * cy8c4014/cy8c4024 touch pad driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * the Free Software Foundation; either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/async.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "tp_suspend.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/wakelock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct cy8c_chipdef {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int max_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int max_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int multi_touch_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) u8 reg_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct cy8c_touch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct workqueue_struct *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct tp_device tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) const struct cy8c_chipdef *cdef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static const struct cy8c_chipdef cy8c4014_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .max_x = 0xfe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .max_y = 0xfe, /* only have x axis */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .multi_touch_num = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .reg_base = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static u32 i2c_cy8ctouch_read(struct cy8c_touch *ts, u8 *buf, u32 num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u8 reg = ts->cdef->reg_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct i2c_msg xfer_msg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) xfer_msg[0].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) xfer_msg[0].len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) xfer_msg[0].flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) xfer_msg[0].buf = ®
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) xfer_msg[1].addr = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) xfer_msg[1].len = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) xfer_msg[1].flags = I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) xfer_msg[1].buf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ret = i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (ret != ARRAY_SIZE(xfer_msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static irqreturn_t cy8ctouch_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct cy8c_touch *ts = (struct cy8c_touch *)dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) disable_irq_nosync(ts->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) queue_work(ts->wq, &ts->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static void cy8ctouch_ts_worker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct cy8c_touch *ts = container_of(work, struct cy8c_touch, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct i2c_client *client = ts->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) const struct cy8c_chipdef *cdef = ts->cdef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) u8 cur_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) u8 cur_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) } pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) rc = i2c_cy8ctouch_read(ts, (u8 *)&pos, sizeof(pos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) dev_err(&client->dev, "i2c read failed, ret = %d, line:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) rc, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) enable_irq(ts->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (pos.cur_x <= cdef->max_x && pos.cur_y <= cdef->max_y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* finger down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dev_dbg(&client->dev, "Touch down, position is %d : %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) pos.cur_x, pos.cur_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) input_report_abs(ts->input, ABS_X, pos.cur_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) input_report_abs(ts->input, ABS_Y, pos.cur_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) input_report_key(ts->input, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) input_sync(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) } else if (pos.cur_x == 0xff && pos.cur_y == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* finger up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) dev_dbg(&client->dev, "Touch up, position is %d : %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) pos.cur_x, pos.cur_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) input_report_key(ts->input, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) input_sync(ts->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) enable_irq(ts->irq);
^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) static int cy8ctouch_init(struct i2c_client *client, struct cy8c_touch *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct input_dev *input_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) INIT_WORK(&ts->work, cy8ctouch_ts_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ts->wq = create_singlethread_workqueue("cy8c_touchpad_wq");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!ts->wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) dev_err(&client->dev, "Create workqueue failed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) input_device = devm_input_allocate_device(&ts->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!input_device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) dev_err(&client->dev, "Allocate input device failed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) destroy_workqueue(ts->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return -ENOMEM;
^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) ts->input = input_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) input_device->name = "cy8c_touchpad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) input_device->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) input_device->dev.parent = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) input_set_drvdata(input_device, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) __set_bit(EV_ABS, input_device->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) __set_bit(EV_KEY, input_device->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) __set_bit(BTN_TOUCH, input_device->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (ts->cdef->max_x > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) __set_bit(ABS_X, input_device->absbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) input_set_abs_params(input_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ABS_X, 0, ts->cdef->max_x, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) dev_err(&client->dev, "max_x is zero, touchpad don't have x axis\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (ts->cdef->max_y > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) __set_bit(ABS_Y, input_device->absbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) input_set_abs_params(input_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ABS_Y, 0, ts->cdef->max_y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) dev_err(&client->dev, "max_y is zero, touchpad don't have y axis\n");
^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) rc = input_register_device(input_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) goto error_unreg_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) error_unreg_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) destroy_workqueue(ts->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return rc;
^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) static int cy8ctouch_suspend(struct tp_device *tp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct cy8c_touch *ts = container_of(tp_dev, struct cy8c_touch, tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) dev_info(&ts->client->dev, "[cy8ctouch] Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int cy8ctouch_resume(struct tp_device *tp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct cy8c_touch *ts = container_of(tp_dev, struct cy8c_touch, tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) dev_info(&ts->client->dev, "[cy8ctouch] Enter %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static const struct of_device_id of_cy8ctouch_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {.compatible = "cypress,cy8c4014", .data = &cy8c4014_data},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {.compatible = "cypress,cy8c4024", .data = &cy8c4014_data},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) MODULE_DEVICE_TABLE(of, of_cy8ctouch_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) cy8ctouch_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) const struct of_device_id *of_dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct cy8c_touch *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) dev_err(&client->dev, "cy8ctouch I2C functionality not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) of_dev_id = of_match_device(of_cy8ctouch_dt_ids, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (!of_dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ts->tp.tp_suspend = cy8ctouch_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ts->tp.tp_resume = cy8ctouch_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) tp_register_fb(&ts->tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) i2c_set_clientdata(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ts->cdef = of_dev_id->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) rc = cy8ctouch_init(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) dev_err(&client->dev, "cy8ctouch init failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) goto porbe_err_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (client->irq > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) rc = devm_request_irq(dev, client->irq, cy8ctouch_irq, IRQF_TRIGGER_FALLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) client->name, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) dev_err(&client->dev, "cy8ctouch_probe: request irq failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) goto porbe_err_ret;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) porbe_err_ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int cy8ctouch_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct cy8c_touch *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) cancel_work_sync(&ts->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) destroy_workqueue(ts->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^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 cy8ctouch_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) { "cy8c4014", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) { "cy8c4024", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) { },
^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 struct i2c_driver cy8ctouch_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .name = "cy8c_touchpad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .of_match_table = of_match_ptr(of_cy8ctouch_dt_ids),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .probe = cy8ctouch_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .remove = cy8ctouch_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .id_table = cy8ctouch_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) module_i2c_driver(cy8ctouch_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) MODULE_AUTHOR("Wenping Zhang <zwp@rock-chips.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) MODULE_DESCRIPTION("Cypress Cy8cxxxx touchpad driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) MODULE_LICENSE("GPL v2");