23 #include <linux/kernel.h>
24 #include <linux/module.h>
26 #include <linux/slab.h>
27 #include <linux/input.h>
29 #include <linux/i2c.h>
42 #define AUO_PIXCIR_REG_X1_LSB 0x00
43 #define AUO_PIXCIR_REG_X1_MSB 0x01
44 #define AUO_PIXCIR_REG_Y1_LSB 0x02
45 #define AUO_PIXCIR_REG_Y1_MSB 0x03
46 #define AUO_PIXCIR_REG_X2_LSB 0x04
47 #define AUO_PIXCIR_REG_X2_MSB 0x05
48 #define AUO_PIXCIR_REG_Y2_LSB 0x06
49 #define AUO_PIXCIR_REG_Y2_MSB 0x07
51 #define AUO_PIXCIR_REG_STRENGTH 0x0d
52 #define AUO_PIXCIR_REG_STRENGTH_X1_LSB 0x0e
53 #define AUO_PIXCIR_REG_STRENGTH_X1_MSB 0x0f
55 #define AUO_PIXCIR_REG_RAW_DATA_X 0x2b
56 #define AUO_PIXCIR_REG_RAW_DATA_Y 0x4f
58 #define AUO_PIXCIR_REG_X_SENSITIVITY 0x6f
59 #define AUO_PIXCIR_REG_Y_SENSITIVITY 0x70
60 #define AUO_PIXCIR_REG_INT_SETTING 0x71
61 #define AUO_PIXCIR_REG_INT_WIDTH 0x72
62 #define AUO_PIXCIR_REG_POWER_MODE 0x73
64 #define AUO_PIXCIR_REG_VERSION 0x77
65 #define AUO_PIXCIR_REG_CALIBRATE 0x78
67 #define AUO_PIXCIR_REG_TOUCHAREA_X1 0x1e
68 #define AUO_PIXCIR_REG_TOUCHAREA_Y1 0x1f
69 #define AUO_PIXCIR_REG_TOUCHAREA_X2 0x20
70 #define AUO_PIXCIR_REG_TOUCHAREA_Y2 0x21
72 #define AUO_PIXCIR_REG_EEPROM_CALIB_X 0x42
73 #define AUO_PIXCIR_REG_EEPROM_CALIB_Y 0xad
75 #define AUO_PIXCIR_INT_TPNUM_MASK 0xe0
76 #define AUO_PIXCIR_INT_TPNUM_SHIFT 5
77 #define AUO_PIXCIR_INT_RELEASE (1 << 4)
78 #define AUO_PIXCIR_INT_ENABLE (1 << 3)
79 #define AUO_PIXCIR_INT_POL_HIGH (1 << 2)
80 #define AUO_PIXCIR_INT_MODE_MASK 0x03
88 #define AUO_PIXCIR_POWER_ACTIVE 0x00
89 #define AUO_PIXCIR_POWER_SLEEP 0x01
90 #define AUO_PIXCIR_POWER_DEEP_SLEEP 0x02
91 #define AUO_PIXCIR_POWER_MASK 0x03
93 #define AUO_PIXCIR_POWER_ALLOW_SLEEP (1 << 2)
94 #define AUO_PIXCIR_POWER_IDLE_TIME(ms) ((ms & 0xf) << 4)
96 #define AUO_PIXCIR_CALIBRATE 0x03
98 #define AUO_PIXCIR_EEPROM_CALIB_X_LEN 62
99 #define AUO_PIXCIR_EEPROM_CALIB_Y_LEN 36
101 #define AUO_PIXCIR_RAW_DATA_X_LEN 18
102 #define AUO_PIXCIR_RAW_DATA_Y_LEN 11
104 #define AUO_PIXCIR_STRENGTH_ENABLE (1 << 0)
107 #define AUO_PIXCIR_REPORT_POINTS 2
108 #define AUO_PIXCIR_MAX_AREA 0xff
109 #define AUO_PIXCIR_PENUP_TIMEOUT_MS 10
144 dev_err(&client->
dev,
"failed to read coordinate, %d\n", ret);
152 dev_err(&client->
dev,
"could not read touch area, %d\n", ret);
158 raw_coord[4 * i + 1] << 8 | raw_coord[4 *
i];
160 raw_coord[4 * i + 3] << 8 | raw_coord[4 * i + 2];
162 if (point[i].coord_x > pdata->
x_max ||
164 dev_warn(&client->
dev,
"coordinates (%d,%d) invalid\n",
172 point[
i].
orientation = raw_area[2 *
i] > raw_area[2 * i + 1];
183 struct auo_point_t point[AUO_PIXCIR_REPORT_POINTS];
194 input_mt_sync(ts->
input);
196 input_sync(ts->
input);
201 ret = auo_pixcir_collect_data(ts, point);
224 input_mt_sync(ts->
input);
244 input_sync(ts->
input);
271 dev_err(&client->
dev,
"unable to read reg %Xh, %d\n",
281 dev_err(&client->
dev,
"unable to write reg %Xh, %d\n",
298 dev_err(&client->
dev,
"unable to read reg %Xh, %d\n",
310 dev_err(&client->
dev,
"unable to write reg %Xh, %d\n",
328 dev_err(&client->
dev,
"unable to read reg %Xh, %d\n",
341 dev_err(&client->
dev,
"unable to write reg %Xh, %d\n",
356 dev_err(&client->
dev,
"could not set power mode, %d\n",
365 ret = auo_pixcir_int_toggle(ts, 1);
367 dev_err(&client->
dev,
"could not enable interrupt, %d\n",
381 ret = auo_pixcir_int_toggle(ts, 0);
383 dev_err(&client->
dev,
"could not disable interrupt, %d\n",
397 static int auo_pixcir_input_open(
struct input_dev *
dev)
402 ret = auo_pixcir_start(ts);
409 static void auo_pixcir_input_close(
struct input_dev *dev)
418 #ifdef CONFIG_PM_SLEEP
419 static int auo_pixcir_suspend(
struct device *dev)
431 if (device_may_wakeup(&client->
dev)) {
434 ret = auo_pixcir_start(ts);
439 enable_irq_wake(client->
irq);
441 }
else if (input->users) {
442 ret = auo_pixcir_stop(ts);
451 static int auo_pixcir_resume(
struct device *dev)
455 struct input_dev *input = ts->
input;
460 if (device_may_wakeup(&client->
dev)) {
461 disable_irq_wake(client->
irq);
465 ret = auo_pixcir_stop(ts);
471 }
else if (input->users) {
472 ret = auo_pixcir_start(ts);
490 struct input_dev *input_dev;
502 dev_err(&client->
dev,
"request of gpio %d failed, %d\n",
515 "%s/input0", dev_name(&client->
dev));
517 input_dev = input_allocate_device();
519 dev_err(&client->
dev,
"could not allocate input device\n");
520 goto err_input_alloc;
523 ts->
input = input_dev;
525 input_dev->name =
"AUO-Pixcir touchscreen";
526 input_dev->phys = ts->
phys;
527 input_dev->id.bustype =
BUS_I2C;
528 input_dev->dev.parent = &client->
dev;
530 input_dev->open = auo_pixcir_input_open;
531 input_dev->close = auo_pixcir_input_close;
539 input_set_abs_params(input_dev,
ABS_X, 0, pdata->
x_max, 0, 0);
540 input_set_abs_params(input_dev,
ABS_Y, 0, pdata->
y_max, 0, 0);
556 dev_info(&client->
dev,
"firmware version 0x%X\n", ret);
558 ret = auo_pixcir_int_config(ts, pdata->
int_setting);
562 input_set_drvdata(ts->
input, ts);
567 input_dev->name, ts);
569 dev_err(&client->
dev,
"irq %d requested failed\n", client->
irq);
574 ret = auo_pixcir_stop(ts);
576 goto err_input_register;
578 ret = input_register_device(input_dev);
580 dev_err(&client->
dev,
"could not register input device\n");
581 goto err_input_register;
584 i2c_set_clientdata(client, ts);
591 input_free_device(input_dev);
609 input_unregister_device(ts->
input);
622 {
"auo_pixcir_ts", 0 },
627 static struct i2c_driver auo_pixcir_driver = {
630 .name =
"auo_pixcir_ts",
631 .pm = &auo_pixcir_pm_ops,
633 .probe = auo_pixcir_probe,
635 .id_table = auo_pixcir_idtable,