26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/input.h>
31 #include <linux/i2c.h>
34 #include <linux/hrtimer.h>
37 #include <linux/slab.h>
40 #define CPTM1217_DEVICE_NAME "cptm1217"
41 #define CPTM1217_DRIVER_NAME CPTM1217_DEVICE_NAME
43 #define MAX_TOUCH_SUPPORTED 2
44 #define TOUCH_SUPPORTED 1
45 #define SAMPLING_FREQ 80
46 #define DELAY_BTWIN_SAMPLE (1000 / SAMPLING_FREQ)
47 #define WAIT_FOR_RESPONSE 5
49 #define INCREMENTAL_DELAY 5
52 #define TMA1217_DEV_STATUS 0x13
53 #define TMA1217_INT_STATUS 0x14
58 #define TMA1217_FINGER_STATE 0x18
59 #define TMA1217_FINGER1_X_HIGHER8 0x19
60 #define TMA1217_FINGER1_Y_HIGHER8 0x1A
61 #define TMA1217_FINGER1_XY_LOWER4 0x1B
62 #define TMA1217_FINGER1_Z_VALUE 0x1D
63 #define TMA1217_FINGER2_X_HIGHER8 0x1E
64 #define TMA1217_FINGER2_Y_HIGHER8 0x1F
65 #define TMA1217_FINGER2_XY_LOWER4 0x20
66 #define TMA1217_FINGER2_Z_VALUE 0x22
67 #define TMA1217_DEVICE_CTRL 0x23
68 #define TMA1217_INTERRUPT_ENABLE 0x24
69 #define TMA1217_REPORT_MODE 0x2B
70 #define TMA1217_MAX_X_LOWER8 0x31
71 #define TMA1217_MAX_X_HIGHER4 0x32
72 #define TMA1217_MAX_Y_LOWER8 0x33
73 #define TMA1217_MAX_Y_HIGHER4 0x34
74 #define TMA1217_DEVICE_CMD_RESET 0x67
75 #define TMA1217_DEVICE_CMD_REZERO 0x69
77 #define TMA1217_MANUFACTURER_ID 0x73
78 #define TMA1217_PRODUCT_FAMILY 0x75
79 #define TMA1217_FIRMWARE_REVISION 0x76
80 #define TMA1217_SERIAL_NO_HIGH 0x7C
81 #define TMA1217_SERIAL_NO_LOW 0x7D
82 #define TMA1217_PRODUCT_ID_START 0x7E
83 #define TMA1217_DEVICE_CAPABILITY 0x8B
144 dev_err(ts->
dev,
"cp_tm1217: I2C send failed\n");
150 if (retval == size) {
154 dev_dbg(ts->
dev,
"cp_tm1217: Retry count is %d\n", i);
158 dev_err(ts->
dev,
"cp_tm1217: Read from device failed\n");
170 if (retval != size + 1) {
171 dev_err(ts->
dev,
"cp_tm1217: I2C write failed: %d\n", retval);
187 retval = cp_tm1217_write(ts, req, 1);
201 retval = cp_tm1217_write(ts, req, 1);
211 struct input_dev_info *input_info =
220 retval = cp_tm1217_read(ts, xy_data, 5);
222 dev_err(ts->
dev,
"cp_tm1217: XY read from device failed\n");
228 input_info->touch.x = (xy_data[1] << 4)
229 | (xy_data[3] & 0x0F);
230 input_info->touch.y = (xy_data[2] << 4)
231 | ((xy_data[3] & 0xF0) >> 4);
232 input_report_abs(input_info->input,
ABS_X, input_info->touch.x);
233 input_report_abs(input_info->input,
ABS_Y, input_info->touch.y);
234 input_sync(input_info->input);
240 int retval,
i, finger_touched = 0;
244 retval = cp_tm1217_read(ts, req, 1);
247 "cp_tm1217: Read from device failed\n");
263 process_touch(ts, i);
274 req[1] = req[1] >> 2;
277 }
while (finger_touched > 0);
297 retval = cp_tm1217_mask_interrupt(ts);
302 retval = cp_tm1217_read(ts, req, 1);
309 cp_tm1217_get_data(ts);
313 retval = cp_tm1217_unmask_interrupt(ts);
330 retval = cp_tm1217_read(ts, req, 1);
331 ts->
vinfo.vendor_id = req[1];
334 retval = cp_tm1217_read(ts, req, 1);
335 ts->
vinfo.product_family = req[1];
338 retval = cp_tm1217_read(ts, req, 1);
339 ts->
vinfo.firmware_rev = req[1];
342 retval = cp_tm1217_read(ts, req, 1);
343 ts->
vinfo.serial_no = (req[1] << 8);
346 retval = cp_tm1217_read(ts, req, 1);
347 ts->
vinfo.serial_no = ts->
vinfo.serial_no | req[1];
350 retval = cp_tm1217_read(ts, req, 1);
351 ts->
dinfo.maxX = (req[1] & 0xF) << 8;
354 retval = cp_tm1217_read(ts, req, 1);
358 retval = cp_tm1217_read(ts, req, 1);
359 ts->
dinfo.maxY = (req[1] & 0xF) << 8;
362 retval = cp_tm1217_read(ts, req, 1);
383 dev_err(ts->
dev,
"cp_tm1217: GPIO request failed error %d\n",
391 "cp_tm1217: GPIO direction configuration failed, error %d\n",
400 "cp_tm1217: GPIO to IRQ failed, error %d\n", retval);
404 "cp_tm1217: Got IRQ number is %d for GPIO %d\n",
413 struct input_dev *input_dev;
414 struct input_dev_info *input_info;
421 pdata = client->
dev.platform_data;
426 "cp_tm1217: Private Device Struct alloc failed\n");
432 i2c_set_clientdata(client, ts);
440 retval = cp_tm1217_write(ts, req, 1);
442 dev_err(ts->
dev,
"cp_tm1217: Controller reset failed\n");
449 retval = cp_tm1217_read(ts, req, 1);
452 retval = cp_tm1217_mask_interrupt(ts);
455 cp_tm1217_init_data(ts);
461 input_dev = input_allocate_device();
462 if (input_dev ==
NULL) {
464 "cp_tm1217:Input Device Struct alloc failed\n");
469 snprintf(input_info->name,
sizeof(input_info->name),
470 "cp_tm1217_touchscreen_%d", i);
471 input_dev->name = input_info->name;
472 snprintf(input_info->phys,
sizeof(input_info->phys),
473 "%s/input%d", dev_name(&client->
dev), i);
475 input_dev->phys = input_info->phys;
476 input_dev->id.bustype =
BUS_I2C;
481 input_set_abs_params(input_dev,
ABS_X, 0, ts->
dinfo.maxX, 0, 0);
482 input_set_abs_params(input_dev,
ABS_Y, 0, ts->
dinfo.maxY, 0, 0);
484 retval = input_register_device(input_dev);
487 "Input dev registration failed for %s\n",
489 input_free_device(input_dev);
492 input_info->input = input_dev;
499 retval = cp_tm1217_write(ts, req, 1);
504 retval = cp_tm1217_write(ts, req, 1);
508 retval = cp_tm1217_read(ts, req, 1);
511 "cp_tm1217: Device Status 0x%x != 0: config failed\n",
518 if (pdata && pdata->
gpio) {
520 retval = cp_tm1217_setup_gpio_irq(ts);
522 retval = client->
irq;
525 dev_err(ts->
dev,
"cp_tm1217: GPIO request failed error %d\n",
534 NULL, cp_tm1217_sample_thread,
537 dev_err(ts->
dev,
"cp_tm1217: Request IRQ error %d\n", retval);
542 retval = cp_tm1217_unmask_interrupt(ts);
575 retval = cp_tm1217_read(ts, req, 1);
576 req[1] = (req[1] & 0xF8) | 0x1;
577 retval = cp_tm1217_write(ts, req, 1);
579 if (device_may_wakeup(&client->
dev))
580 enable_irq_wake(client->
irq);
589 static int cp_tm1217_resume(
struct i2c_client *client)
597 retval = cp_tm1217_read(ts, req, 1);
598 req[1] = (req[1] & 0xF8) | 0x4;
599 retval = cp_tm1217_write(ts, req, 1);
608 retval = cp_tm1217_write(ts, req, 1);
613 retval = cp_tm1217_write(ts, req, 1);
616 retval = cp_tm1217_unmask_interrupt(ts);
618 if (device_may_wakeup(&client->
dev))
619 disable_irq_wake(client->
irq);
628 static int cp_tm1217_remove(
struct i2c_client *client)
654 .id_table = cp_tm1217_idtable,
655 .probe = cp_tm1217_probe,
656 .remove = cp_tm1217_remove,
657 .suspend = cp_tm1217_suspend,
658 .resume = cp_tm1217_resume,