22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/input.h>
25 #include <linux/slab.h>
28 #include <linux/i2c.h>
32 #define CY8CTMG110_DRIVER_NAME "cy8ctmg110"
35 #define CY8CTMG110_X_MIN 0
36 #define CY8CTMG110_Y_MIN 0
37 #define CY8CTMG110_X_MAX 759
38 #define CY8CTMG110_Y_MAX 465
42 #define CY8CTMG110_TOUCH_WAKEUP_TIME 0
43 #define CY8CTMG110_TOUCH_SLEEP_TIME 2
44 #define CY8CTMG110_TOUCH_X1 3
45 #define CY8CTMG110_TOUCH_Y1 5
46 #define CY8CTMG110_TOUCH_X2 7
47 #define CY8CTMG110_TOUCH_Y2 9
48 #define CY8CTMG110_FINGERS 11
49 #define CY8CTMG110_GESTURE 12
50 #define CY8CTMG110_REG_MAX 13
68 static void cy8ctmg110_power(
struct cy8ctmg110 *
ts,
bool poweron)
75 unsigned char len,
unsigned char *
value)
84 memcpy(i2c_data + 1, value, len);
88 dev_err(&client->
dev,
"i2c write data cmd failed\n");
89 return ret < 0 ? ret : -
EIO;
95 static int cy8ctmg110_read_regs(
struct cy8ctmg110 *tsc,
96 unsigned char *
data,
unsigned char len,
unsigned char cmd)
102 { client->
addr, 0, 1, &cmd },
114 static int cy8ctmg110_touch_pos(
struct cy8ctmg110 *tsc)
126 y = reg_p[2] << 8 | reg_p[3];
127 x = reg_p[0] << 8 | reg_p[1];
134 input_report_abs(input,
ABS_X, x);
135 input_report_abs(input,
ABS_Y, y);
143 static int cy8ctmg110_set_sleepmode(
struct cy8ctmg110 *
ts,
bool sleep)
145 unsigned char reg_p[3];
164 cy8ctmg110_touch_pos(tsc);
174 struct input_dev *input_dev;
183 if (!i2c_check_functionality(client->
adapter,
188 input_dev = input_allocate_device();
189 if (!ts || !input_dev) {
195 ts->
input = input_dev;
200 "%s/input0", dev_name(&client->
dev));
203 input_dev->phys = ts->
phys;
204 input_dev->id.bustype =
BUS_I2C;
205 input_dev->dev.parent = &client->
dev;
210 input_set_abs_params(input_dev,
ABS_X,
212 input_set_abs_params(input_dev,
ABS_Y,
219 "Unable to request GPIO pin %d.\n",
225 cy8ctmg110_power(ts,
true);
226 cy8ctmg110_set_sleepmode(ts,
false);
231 "Failed to request GPIO %d, error %d\n",
233 goto err_shutoff_device;
239 "Failed to configure input direction for GPIO %d, error %d\n",
241 goto err_free_irq_gpio;
245 if (client->
irq < 0) {
248 "Unable to get irq number for GPIO %d, error %d\n",
250 goto err_free_irq_gpio;
255 "touch_reset_key", ts);
258 "irq %d busy? error %d\n", client->
irq, err);
259 goto err_free_irq_gpio;
262 err = input_register_device(input_dev);
266 i2c_set_clientdata(client, ts);
275 cy8ctmg110_set_sleepmode(ts,
true);
276 cy8ctmg110_power(ts,
false);
280 input_free_device(input_dev);
286 static int cy8ctmg110_suspend(
struct device *
dev)
289 struct cy8ctmg110 *ts = i2c_get_clientdata(client);
291 if (device_may_wakeup(&client->
dev))
292 enable_irq_wake(client->
irq);
294 cy8ctmg110_set_sleepmode(ts,
true);
295 cy8ctmg110_power(ts,
false);
300 static int cy8ctmg110_resume(
struct device *dev)
303 struct cy8ctmg110 *ts = i2c_get_clientdata(client);
305 if (device_may_wakeup(&client->
dev))
306 disable_irq_wake(client->
irq);
308 cy8ctmg110_power(ts,
true);
309 cy8ctmg110_set_sleepmode(ts,
false);
319 struct cy8ctmg110 *ts = i2c_get_clientdata(client);
321 cy8ctmg110_set_sleepmode(ts,
true);
322 cy8ctmg110_power(ts,
false);
325 input_unregister_device(ts->
input);
341 static struct i2c_driver cy8ctmg110_driver = {
346 .pm = &cy8ctmg110_pm,
349 .id_table = cy8ctmg110_idtable,
350 .probe = cy8ctmg110_probe,