Loading...
1/*
2 * Driver for AUO in-cell touchscreens
3 *
4 * Copyright (c) 2011 Heiko Stuebner <heiko@sntech.de>
5 *
6 * loosely based on auo_touch.c from Dell Streak vendor-kernel
7 *
8 * Copyright (c) 2008 QUALCOMM Incorporated.
9 * Copyright (c) 2008 QUALCOMM USA, INC.
10 *
11 *
12 * This software is licensed under the terms of the GNU General Public
13 * License version 2, as published by the Free Software Foundation, and
14 * may be copied, distributed, and modified under those terms.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/interrupt.h>
26#include <linux/slab.h>
27#include <linux/input.h>
28#include <linux/jiffies.h>
29#include <linux/i2c.h>
30#include <linux/mutex.h>
31#include <linux/delay.h>
32#include <linux/gpio.h>
33#include <linux/input/auo-pixcir-ts.h>
34#include <linux/of.h>
35#include <linux/of_gpio.h>
36
37/*
38 * Coordinate calculation:
39 * X1 = X1_LSB + X1_MSB*256
40 * Y1 = Y1_LSB + Y1_MSB*256
41 * X2 = X2_LSB + X2_MSB*256
42 * Y2 = Y2_LSB + Y2_MSB*256
43 */
44#define AUO_PIXCIR_REG_X1_LSB 0x00
45#define AUO_PIXCIR_REG_X1_MSB 0x01
46#define AUO_PIXCIR_REG_Y1_LSB 0x02
47#define AUO_PIXCIR_REG_Y1_MSB 0x03
48#define AUO_PIXCIR_REG_X2_LSB 0x04
49#define AUO_PIXCIR_REG_X2_MSB 0x05
50#define AUO_PIXCIR_REG_Y2_LSB 0x06
51#define AUO_PIXCIR_REG_Y2_MSB 0x07
52
53#define AUO_PIXCIR_REG_STRENGTH 0x0d
54#define AUO_PIXCIR_REG_STRENGTH_X1_LSB 0x0e
55#define AUO_PIXCIR_REG_STRENGTH_X1_MSB 0x0f
56
57#define AUO_PIXCIR_REG_RAW_DATA_X 0x2b
58#define AUO_PIXCIR_REG_RAW_DATA_Y 0x4f
59
60#define AUO_PIXCIR_REG_X_SENSITIVITY 0x6f
61#define AUO_PIXCIR_REG_Y_SENSITIVITY 0x70
62#define AUO_PIXCIR_REG_INT_SETTING 0x71
63#define AUO_PIXCIR_REG_INT_WIDTH 0x72
64#define AUO_PIXCIR_REG_POWER_MODE 0x73
65
66#define AUO_PIXCIR_REG_VERSION 0x77
67#define AUO_PIXCIR_REG_CALIBRATE 0x78
68
69#define AUO_PIXCIR_REG_TOUCHAREA_X1 0x1e
70#define AUO_PIXCIR_REG_TOUCHAREA_Y1 0x1f
71#define AUO_PIXCIR_REG_TOUCHAREA_X2 0x20
72#define AUO_PIXCIR_REG_TOUCHAREA_Y2 0x21
73
74#define AUO_PIXCIR_REG_EEPROM_CALIB_X 0x42
75#define AUO_PIXCIR_REG_EEPROM_CALIB_Y 0xad
76
77#define AUO_PIXCIR_INT_TPNUM_MASK 0xe0
78#define AUO_PIXCIR_INT_TPNUM_SHIFT 5
79#define AUO_PIXCIR_INT_RELEASE (1 << 4)
80#define AUO_PIXCIR_INT_ENABLE (1 << 3)
81#define AUO_PIXCIR_INT_POL_HIGH (1 << 2)
82#define AUO_PIXCIR_INT_MODE_MASK 0x03
83
84/*
85 * Power modes:
86 * active: scan speed 60Hz
87 * sleep: scan speed 10Hz can be auto-activated, wakeup on 1st touch
88 * deep sleep: scan speed 1Hz can only be entered or left manually.
89 */
90#define AUO_PIXCIR_POWER_ACTIVE 0x00
91#define AUO_PIXCIR_POWER_SLEEP 0x01
92#define AUO_PIXCIR_POWER_DEEP_SLEEP 0x02
93#define AUO_PIXCIR_POWER_MASK 0x03
94
95#define AUO_PIXCIR_POWER_ALLOW_SLEEP (1 << 2)
96#define AUO_PIXCIR_POWER_IDLE_TIME(ms) ((ms & 0xf) << 4)
97
98#define AUO_PIXCIR_CALIBRATE 0x03
99
100#define AUO_PIXCIR_EEPROM_CALIB_X_LEN 62
101#define AUO_PIXCIR_EEPROM_CALIB_Y_LEN 36
102
103#define AUO_PIXCIR_RAW_DATA_X_LEN 18
104#define AUO_PIXCIR_RAW_DATA_Y_LEN 11
105
106#define AUO_PIXCIR_STRENGTH_ENABLE (1 << 0)
107
108/* Touchscreen absolute values */
109#define AUO_PIXCIR_REPORT_POINTS 2
110#define AUO_PIXCIR_MAX_AREA 0xff
111#define AUO_PIXCIR_PENUP_TIMEOUT_MS 10
112
113struct auo_pixcir_ts {
114 struct i2c_client *client;
115 struct input_dev *input;
116 const struct auo_pixcir_ts_platdata *pdata;
117 char phys[32];
118
119 /* special handling for touch_indicate interupt mode */
120 bool touch_ind_mode;
121
122 wait_queue_head_t wait;
123 bool stopped;
124};
125
126struct auo_point_t {
127 int coord_x;
128 int coord_y;
129 int area_major;
130 int area_minor;
131 int orientation;
132};
133
134static int auo_pixcir_collect_data(struct auo_pixcir_ts *ts,
135 struct auo_point_t *point)
136{
137 struct i2c_client *client = ts->client;
138 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
139 uint8_t raw_coord[8];
140 uint8_t raw_area[4];
141 int i, ret;
142
143 /* touch coordinates */
144 ret = i2c_smbus_read_i2c_block_data(client, AUO_PIXCIR_REG_X1_LSB,
145 8, raw_coord);
146 if (ret < 0) {
147 dev_err(&client->dev, "failed to read coordinate, %d\n", ret);
148 return ret;
149 }
150
151 /* touch area */
152 ret = i2c_smbus_read_i2c_block_data(client, AUO_PIXCIR_REG_TOUCHAREA_X1,
153 4, raw_area);
154 if (ret < 0) {
155 dev_err(&client->dev, "could not read touch area, %d\n", ret);
156 return ret;
157 }
158
159 for (i = 0; i < AUO_PIXCIR_REPORT_POINTS; i++) {
160 point[i].coord_x =
161 raw_coord[4 * i + 1] << 8 | raw_coord[4 * i];
162 point[i].coord_y =
163 raw_coord[4 * i + 3] << 8 | raw_coord[4 * i + 2];
164
165 if (point[i].coord_x > pdata->x_max ||
166 point[i].coord_y > pdata->y_max) {
167 dev_warn(&client->dev, "coordinates (%d,%d) invalid\n",
168 point[i].coord_x, point[i].coord_y);
169 point[i].coord_x = point[i].coord_y = 0;
170 }
171
172 /* determine touch major, minor and orientation */
173 point[i].area_major = max(raw_area[2 * i], raw_area[2 * i + 1]);
174 point[i].area_minor = min(raw_area[2 * i], raw_area[2 * i + 1]);
175 point[i].orientation = raw_area[2 * i] > raw_area[2 * i + 1];
176 }
177
178 return 0;
179}
180
181static irqreturn_t auo_pixcir_interrupt(int irq, void *dev_id)
182{
183 struct auo_pixcir_ts *ts = dev_id;
184 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
185 struct auo_point_t point[AUO_PIXCIR_REPORT_POINTS];
186 int i;
187 int ret;
188 int fingers = 0;
189 int abs = -1;
190
191 while (!ts->stopped) {
192
193 /* check for up event in touch touch_ind_mode */
194 if (ts->touch_ind_mode) {
195 if (gpio_get_value(pdata->gpio_int) == 0) {
196 input_mt_sync(ts->input);
197 input_report_key(ts->input, BTN_TOUCH, 0);
198 input_sync(ts->input);
199 break;
200 }
201 }
202
203 ret = auo_pixcir_collect_data(ts, point);
204 if (ret < 0) {
205 /* we want to loop only in touch_ind_mode */
206 if (!ts->touch_ind_mode)
207 break;
208
209 wait_event_timeout(ts->wait, ts->stopped,
210 msecs_to_jiffies(AUO_PIXCIR_PENUP_TIMEOUT_MS));
211 continue;
212 }
213
214 for (i = 0; i < AUO_PIXCIR_REPORT_POINTS; i++) {
215 if (point[i].coord_x > 0 || point[i].coord_y > 0) {
216 input_report_abs(ts->input, ABS_MT_POSITION_X,
217 point[i].coord_x);
218 input_report_abs(ts->input, ABS_MT_POSITION_Y,
219 point[i].coord_y);
220 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
221 point[i].area_major);
222 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR,
223 point[i].area_minor);
224 input_report_abs(ts->input, ABS_MT_ORIENTATION,
225 point[i].orientation);
226 input_mt_sync(ts->input);
227
228 /* use first finger as source for singletouch */
229 if (fingers == 0)
230 abs = i;
231
232 /* number of touch points could also be queried
233 * via i2c but would require an additional call
234 */
235 fingers++;
236 }
237 }
238
239 input_report_key(ts->input, BTN_TOUCH, fingers > 0);
240
241 if (abs > -1) {
242 input_report_abs(ts->input, ABS_X, point[abs].coord_x);
243 input_report_abs(ts->input, ABS_Y, point[abs].coord_y);
244 }
245
246 input_sync(ts->input);
247
248 /* we want to loop only in touch_ind_mode */
249 if (!ts->touch_ind_mode)
250 break;
251
252 wait_event_timeout(ts->wait, ts->stopped,
253 msecs_to_jiffies(AUO_PIXCIR_PENUP_TIMEOUT_MS));
254 }
255
256 return IRQ_HANDLED;
257}
258
259/*
260 * Set the power mode of the device.
261 * Valid modes are
262 * - AUO_PIXCIR_POWER_ACTIVE
263 * - AUO_PIXCIR_POWER_SLEEP - automatically left on first touch
264 * - AUO_PIXCIR_POWER_DEEP_SLEEP
265 */
266static int auo_pixcir_power_mode(struct auo_pixcir_ts *ts, int mode)
267{
268 struct i2c_client *client = ts->client;
269 int ret;
270
271 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_POWER_MODE);
272 if (ret < 0) {
273 dev_err(&client->dev, "unable to read reg %Xh, %d\n",
274 AUO_PIXCIR_REG_POWER_MODE, ret);
275 return ret;
276 }
277
278 ret &= ~AUO_PIXCIR_POWER_MASK;
279 ret |= mode;
280
281 ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_POWER_MODE, ret);
282 if (ret) {
283 dev_err(&client->dev, "unable to write reg %Xh, %d\n",
284 AUO_PIXCIR_REG_POWER_MODE, ret);
285 return ret;
286 }
287
288 return 0;
289}
290
291static int auo_pixcir_int_config(struct auo_pixcir_ts *ts,
292 int int_setting)
293{
294 struct i2c_client *client = ts->client;
295 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
296 int ret;
297
298 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
299 if (ret < 0) {
300 dev_err(&client->dev, "unable to read reg %Xh, %d\n",
301 AUO_PIXCIR_REG_INT_SETTING, ret);
302 return ret;
303 }
304
305 ret &= ~AUO_PIXCIR_INT_MODE_MASK;
306 ret |= int_setting;
307 ret |= AUO_PIXCIR_INT_POL_HIGH; /* always use high for interrupts */
308
309 ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_INT_SETTING,
310 ret);
311 if (ret < 0) {
312 dev_err(&client->dev, "unable to write reg %Xh, %d\n",
313 AUO_PIXCIR_REG_INT_SETTING, ret);
314 return ret;
315 }
316
317 ts->touch_ind_mode = pdata->int_setting == AUO_PIXCIR_INT_TOUCH_IND;
318
319 return 0;
320}
321
322/* control the generation of interrupts on the device side */
323static int auo_pixcir_int_toggle(struct auo_pixcir_ts *ts, bool enable)
324{
325 struct i2c_client *client = ts->client;
326 int ret;
327
328 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
329 if (ret < 0) {
330 dev_err(&client->dev, "unable to read reg %Xh, %d\n",
331 AUO_PIXCIR_REG_INT_SETTING, ret);
332 return ret;
333 }
334
335 if (enable)
336 ret |= AUO_PIXCIR_INT_ENABLE;
337 else
338 ret &= ~AUO_PIXCIR_INT_ENABLE;
339
340 ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_INT_SETTING,
341 ret);
342 if (ret < 0) {
343 dev_err(&client->dev, "unable to write reg %Xh, %d\n",
344 AUO_PIXCIR_REG_INT_SETTING, ret);
345 return ret;
346 }
347
348 return 0;
349}
350
351static int auo_pixcir_start(struct auo_pixcir_ts *ts)
352{
353 struct i2c_client *client = ts->client;
354 int ret;
355
356 ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_ACTIVE);
357 if (ret < 0) {
358 dev_err(&client->dev, "could not set power mode, %d\n",
359 ret);
360 return ret;
361 }
362
363 ts->stopped = false;
364 mb();
365 enable_irq(client->irq);
366
367 ret = auo_pixcir_int_toggle(ts, 1);
368 if (ret < 0) {
369 dev_err(&client->dev, "could not enable interrupt, %d\n",
370 ret);
371 disable_irq(client->irq);
372 return ret;
373 }
374
375 return 0;
376}
377
378static int auo_pixcir_stop(struct auo_pixcir_ts *ts)
379{
380 struct i2c_client *client = ts->client;
381 int ret;
382
383 ret = auo_pixcir_int_toggle(ts, 0);
384 if (ret < 0) {
385 dev_err(&client->dev, "could not disable interrupt, %d\n",
386 ret);
387 return ret;
388 }
389
390 /* disable receiving of interrupts */
391 disable_irq(client->irq);
392 ts->stopped = true;
393 mb();
394 wake_up(&ts->wait);
395
396 return auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_DEEP_SLEEP);
397}
398
399static int auo_pixcir_input_open(struct input_dev *dev)
400{
401 struct auo_pixcir_ts *ts = input_get_drvdata(dev);
402 int ret;
403
404 ret = auo_pixcir_start(ts);
405 if (ret)
406 return ret;
407
408 return 0;
409}
410
411static void auo_pixcir_input_close(struct input_dev *dev)
412{
413 struct auo_pixcir_ts *ts = input_get_drvdata(dev);
414
415 auo_pixcir_stop(ts);
416
417 return;
418}
419
420#ifdef CONFIG_PM_SLEEP
421static int auo_pixcir_suspend(struct device *dev)
422{
423 struct i2c_client *client = to_i2c_client(dev);
424 struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
425 struct input_dev *input = ts->input;
426 int ret = 0;
427
428 mutex_lock(&input->mutex);
429
430 /* when configured as wakeup source, device should always wake system
431 * therefore start device if necessary
432 */
433 if (device_may_wakeup(&client->dev)) {
434 /* need to start device if not open, to be wakeup source */
435 if (!input->users) {
436 ret = auo_pixcir_start(ts);
437 if (ret)
438 goto unlock;
439 }
440
441 enable_irq_wake(client->irq);
442 ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_SLEEP);
443 } else if (input->users) {
444 ret = auo_pixcir_stop(ts);
445 }
446
447unlock:
448 mutex_unlock(&input->mutex);
449
450 return ret;
451}
452
453static int auo_pixcir_resume(struct device *dev)
454{
455 struct i2c_client *client = to_i2c_client(dev);
456 struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
457 struct input_dev *input = ts->input;
458 int ret = 0;
459
460 mutex_lock(&input->mutex);
461
462 if (device_may_wakeup(&client->dev)) {
463 disable_irq_wake(client->irq);
464
465 /* need to stop device if it was not open on suspend */
466 if (!input->users) {
467 ret = auo_pixcir_stop(ts);
468 if (ret)
469 goto unlock;
470 }
471
472 /* device wakes automatically from SLEEP */
473 } else if (input->users) {
474 ret = auo_pixcir_start(ts);
475 }
476
477unlock:
478 mutex_unlock(&input->mutex);
479
480 return ret;
481}
482#endif
483
484static SIMPLE_DEV_PM_OPS(auo_pixcir_pm_ops,
485 auo_pixcir_suspend, auo_pixcir_resume);
486
487#ifdef CONFIG_OF
488static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
489{
490 struct auo_pixcir_ts_platdata *pdata;
491 struct device_node *np = dev->of_node;
492
493 if (!np)
494 return ERR_PTR(-ENOENT);
495
496 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
497 if (!pdata) {
498 dev_err(dev, "failed to allocate platform data\n");
499 return ERR_PTR(-ENOMEM);
500 }
501
502 pdata->gpio_int = of_get_gpio(np, 0);
503 if (!gpio_is_valid(pdata->gpio_int)) {
504 dev_err(dev, "failed to get interrupt gpio\n");
505 return ERR_PTR(-EINVAL);
506 }
507
508 pdata->gpio_rst = of_get_gpio(np, 1);
509 if (!gpio_is_valid(pdata->gpio_rst)) {
510 dev_err(dev, "failed to get reset gpio\n");
511 return ERR_PTR(-EINVAL);
512 }
513
514 if (of_property_read_u32(np, "x-size", &pdata->x_max)) {
515 dev_err(dev, "failed to get x-size property\n");
516 return ERR_PTR(-EINVAL);
517 }
518
519 if (of_property_read_u32(np, "y-size", &pdata->y_max)) {
520 dev_err(dev, "failed to get y-size property\n");
521 return ERR_PTR(-EINVAL);
522 }
523
524 /* default to asserting the interrupt when the screen is touched */
525 pdata->int_setting = AUO_PIXCIR_INT_TOUCH_IND;
526
527 return pdata;
528}
529#else
530static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
531{
532 return ERR_PTR(-EINVAL);
533}
534#endif
535
536static void auo_pixcir_reset(void *data)
537{
538 struct auo_pixcir_ts *ts = data;
539
540 gpio_set_value(ts->pdata->gpio_rst, 0);
541}
542
543static int auo_pixcir_probe(struct i2c_client *client,
544 const struct i2c_device_id *id)
545{
546 const struct auo_pixcir_ts_platdata *pdata;
547 struct auo_pixcir_ts *ts;
548 struct input_dev *input_dev;
549 int version;
550 int error;
551
552 pdata = dev_get_platdata(&client->dev);
553 if (!pdata) {
554 pdata = auo_pixcir_parse_dt(&client->dev);
555 if (IS_ERR(pdata))
556 return PTR_ERR(pdata);
557 }
558
559 ts = devm_kzalloc(&client->dev,
560 sizeof(struct auo_pixcir_ts), GFP_KERNEL);
561 if (!ts)
562 return -ENOMEM;
563
564 input_dev = devm_input_allocate_device(&client->dev);
565 if (!input_dev) {
566 dev_err(&client->dev, "could not allocate input device\n");
567 return -ENOMEM;
568 }
569
570 ts->pdata = pdata;
571 ts->client = client;
572 ts->input = input_dev;
573 ts->touch_ind_mode = 0;
574 ts->stopped = true;
575 init_waitqueue_head(&ts->wait);
576
577 snprintf(ts->phys, sizeof(ts->phys),
578 "%s/input0", dev_name(&client->dev));
579
580 input_dev->name = "AUO-Pixcir touchscreen";
581 input_dev->phys = ts->phys;
582 input_dev->id.bustype = BUS_I2C;
583
584 input_dev->open = auo_pixcir_input_open;
585 input_dev->close = auo_pixcir_input_close;
586
587 __set_bit(EV_ABS, input_dev->evbit);
588 __set_bit(EV_KEY, input_dev->evbit);
589
590 __set_bit(BTN_TOUCH, input_dev->keybit);
591
592 /* For single touch */
593 input_set_abs_params(input_dev, ABS_X, 0, pdata->x_max, 0, 0);
594 input_set_abs_params(input_dev, ABS_Y, 0, pdata->y_max, 0, 0);
595
596 /* For multi touch */
597 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
598 pdata->x_max, 0, 0);
599 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
600 pdata->y_max, 0, 0);
601 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
602 AUO_PIXCIR_MAX_AREA, 0, 0);
603 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0,
604 AUO_PIXCIR_MAX_AREA, 0, 0);
605 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
606
607 input_set_drvdata(ts->input, ts);
608
609 error = devm_gpio_request_one(&client->dev, pdata->gpio_int,
610 GPIOF_DIR_IN, "auo_pixcir_ts_int");
611 if (error) {
612 dev_err(&client->dev, "request of gpio %d failed, %d\n",
613 pdata->gpio_int, error);
614 return error;
615 }
616
617 error = devm_gpio_request_one(&client->dev, pdata->gpio_rst,
618 GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
619 "auo_pixcir_ts_rst");
620 if (error) {
621 dev_err(&client->dev, "request of gpio %d failed, %d\n",
622 pdata->gpio_rst, error);
623 return error;
624 }
625
626 error = devm_add_action(&client->dev, auo_pixcir_reset, ts);
627 if (error) {
628 auo_pixcir_reset(ts);
629 dev_err(&client->dev, "failed to register reset action, %d\n",
630 error);
631 return error;
632 }
633
634 msleep(200);
635
636 version = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
637 if (version < 0) {
638 error = version;
639 return error;
640 }
641
642 dev_info(&client->dev, "firmware version 0x%X\n", version);
643
644 error = auo_pixcir_int_config(ts, pdata->int_setting);
645 if (error)
646 return error;
647
648 error = devm_request_threaded_irq(&client->dev, client->irq,
649 NULL, auo_pixcir_interrupt,
650 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
651 input_dev->name, ts);
652 if (error) {
653 dev_err(&client->dev, "irq %d requested failed, %d\n",
654 client->irq, error);
655 return error;
656 }
657
658 /* stop device and put it into deep sleep until it is opened */
659 error = auo_pixcir_stop(ts);
660 if (error)
661 return error;
662
663 error = input_register_device(input_dev);
664 if (error) {
665 dev_err(&client->dev, "could not register input device, %d\n",
666 error);
667 return error;
668 }
669
670 i2c_set_clientdata(client, ts);
671
672 return 0;
673}
674
675static const struct i2c_device_id auo_pixcir_idtable[] = {
676 { "auo_pixcir_ts", 0 },
677 { }
678};
679MODULE_DEVICE_TABLE(i2c, auo_pixcir_idtable);
680
681#ifdef CONFIG_OF
682static struct of_device_id auo_pixcir_ts_dt_idtable[] = {
683 { .compatible = "auo,auo_pixcir_ts" },
684 {},
685};
686MODULE_DEVICE_TABLE(of, auo_pixcir_ts_dt_idtable);
687#endif
688
689static struct i2c_driver auo_pixcir_driver = {
690 .driver = {
691 .owner = THIS_MODULE,
692 .name = "auo_pixcir_ts",
693 .pm = &auo_pixcir_pm_ops,
694 .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable),
695 },
696 .probe = auo_pixcir_probe,
697 .id_table = auo_pixcir_idtable,
698};
699
700module_i2c_driver(auo_pixcir_driver);
701
702MODULE_DESCRIPTION("AUO-PIXCIR touchscreen driver");
703MODULE_LICENSE("GPL v2");
704MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Driver for AUO in-cell touchscreens
4 *
5 * Copyright (c) 2011 Heiko Stuebner <heiko@sntech.de>
6 *
7 * loosely based on auo_touch.c from Dell Streak vendor-kernel
8 *
9 * Copyright (c) 2008 QUALCOMM Incorporated.
10 * Copyright (c) 2008 QUALCOMM USA, INC.
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/interrupt.h>
16#include <linux/slab.h>
17#include <linux/input.h>
18#include <linux/jiffies.h>
19#include <linux/i2c.h>
20#include <linux/mutex.h>
21#include <linux/delay.h>
22#include <linux/gpio.h>
23#include <linux/input/auo-pixcir-ts.h>
24#include <linux/of.h>
25#include <linux/of_gpio.h>
26
27/*
28 * Coordinate calculation:
29 * X1 = X1_LSB + X1_MSB*256
30 * Y1 = Y1_LSB + Y1_MSB*256
31 * X2 = X2_LSB + X2_MSB*256
32 * Y2 = Y2_LSB + Y2_MSB*256
33 */
34#define AUO_PIXCIR_REG_X1_LSB 0x00
35#define AUO_PIXCIR_REG_X1_MSB 0x01
36#define AUO_PIXCIR_REG_Y1_LSB 0x02
37#define AUO_PIXCIR_REG_Y1_MSB 0x03
38#define AUO_PIXCIR_REG_X2_LSB 0x04
39#define AUO_PIXCIR_REG_X2_MSB 0x05
40#define AUO_PIXCIR_REG_Y2_LSB 0x06
41#define AUO_PIXCIR_REG_Y2_MSB 0x07
42
43#define AUO_PIXCIR_REG_STRENGTH 0x0d
44#define AUO_PIXCIR_REG_STRENGTH_X1_LSB 0x0e
45#define AUO_PIXCIR_REG_STRENGTH_X1_MSB 0x0f
46
47#define AUO_PIXCIR_REG_RAW_DATA_X 0x2b
48#define AUO_PIXCIR_REG_RAW_DATA_Y 0x4f
49
50#define AUO_PIXCIR_REG_X_SENSITIVITY 0x6f
51#define AUO_PIXCIR_REG_Y_SENSITIVITY 0x70
52#define AUO_PIXCIR_REG_INT_SETTING 0x71
53#define AUO_PIXCIR_REG_INT_WIDTH 0x72
54#define AUO_PIXCIR_REG_POWER_MODE 0x73
55
56#define AUO_PIXCIR_REG_VERSION 0x77
57#define AUO_PIXCIR_REG_CALIBRATE 0x78
58
59#define AUO_PIXCIR_REG_TOUCHAREA_X1 0x1e
60#define AUO_PIXCIR_REG_TOUCHAREA_Y1 0x1f
61#define AUO_PIXCIR_REG_TOUCHAREA_X2 0x20
62#define AUO_PIXCIR_REG_TOUCHAREA_Y2 0x21
63
64#define AUO_PIXCIR_REG_EEPROM_CALIB_X 0x42
65#define AUO_PIXCIR_REG_EEPROM_CALIB_Y 0xad
66
67#define AUO_PIXCIR_INT_TPNUM_MASK 0xe0
68#define AUO_PIXCIR_INT_TPNUM_SHIFT 5
69#define AUO_PIXCIR_INT_RELEASE (1 << 4)
70#define AUO_PIXCIR_INT_ENABLE (1 << 3)
71#define AUO_PIXCIR_INT_POL_HIGH (1 << 2)
72#define AUO_PIXCIR_INT_MODE_MASK 0x03
73
74/*
75 * Power modes:
76 * active: scan speed 60Hz
77 * sleep: scan speed 10Hz can be auto-activated, wakeup on 1st touch
78 * deep sleep: scan speed 1Hz can only be entered or left manually.
79 */
80#define AUO_PIXCIR_POWER_ACTIVE 0x00
81#define AUO_PIXCIR_POWER_SLEEP 0x01
82#define AUO_PIXCIR_POWER_DEEP_SLEEP 0x02
83#define AUO_PIXCIR_POWER_MASK 0x03
84
85#define AUO_PIXCIR_POWER_ALLOW_SLEEP (1 << 2)
86#define AUO_PIXCIR_POWER_IDLE_TIME(ms) ((ms & 0xf) << 4)
87
88#define AUO_PIXCIR_CALIBRATE 0x03
89
90#define AUO_PIXCIR_EEPROM_CALIB_X_LEN 62
91#define AUO_PIXCIR_EEPROM_CALIB_Y_LEN 36
92
93#define AUO_PIXCIR_RAW_DATA_X_LEN 18
94#define AUO_PIXCIR_RAW_DATA_Y_LEN 11
95
96#define AUO_PIXCIR_STRENGTH_ENABLE (1 << 0)
97
98/* Touchscreen absolute values */
99#define AUO_PIXCIR_REPORT_POINTS 2
100#define AUO_PIXCIR_MAX_AREA 0xff
101#define AUO_PIXCIR_PENUP_TIMEOUT_MS 10
102
103struct auo_pixcir_ts {
104 struct i2c_client *client;
105 struct input_dev *input;
106 const struct auo_pixcir_ts_platdata *pdata;
107 char phys[32];
108
109 /* special handling for touch_indicate interupt mode */
110 bool touch_ind_mode;
111
112 wait_queue_head_t wait;
113 bool stopped;
114};
115
116struct auo_point_t {
117 int coord_x;
118 int coord_y;
119 int area_major;
120 int area_minor;
121 int orientation;
122};
123
124static int auo_pixcir_collect_data(struct auo_pixcir_ts *ts,
125 struct auo_point_t *point)
126{
127 struct i2c_client *client = ts->client;
128 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
129 uint8_t raw_coord[8];
130 uint8_t raw_area[4];
131 int i, ret;
132
133 /* touch coordinates */
134 ret = i2c_smbus_read_i2c_block_data(client, AUO_PIXCIR_REG_X1_LSB,
135 8, raw_coord);
136 if (ret < 0) {
137 dev_err(&client->dev, "failed to read coordinate, %d\n", ret);
138 return ret;
139 }
140
141 /* touch area */
142 ret = i2c_smbus_read_i2c_block_data(client, AUO_PIXCIR_REG_TOUCHAREA_X1,
143 4, raw_area);
144 if (ret < 0) {
145 dev_err(&client->dev, "could not read touch area, %d\n", ret);
146 return ret;
147 }
148
149 for (i = 0; i < AUO_PIXCIR_REPORT_POINTS; i++) {
150 point[i].coord_x =
151 raw_coord[4 * i + 1] << 8 | raw_coord[4 * i];
152 point[i].coord_y =
153 raw_coord[4 * i + 3] << 8 | raw_coord[4 * i + 2];
154
155 if (point[i].coord_x > pdata->x_max ||
156 point[i].coord_y > pdata->y_max) {
157 dev_warn(&client->dev, "coordinates (%d,%d) invalid\n",
158 point[i].coord_x, point[i].coord_y);
159 point[i].coord_x = point[i].coord_y = 0;
160 }
161
162 /* determine touch major, minor and orientation */
163 point[i].area_major = max(raw_area[2 * i], raw_area[2 * i + 1]);
164 point[i].area_minor = min(raw_area[2 * i], raw_area[2 * i + 1]);
165 point[i].orientation = raw_area[2 * i] > raw_area[2 * i + 1];
166 }
167
168 return 0;
169}
170
171static irqreturn_t auo_pixcir_interrupt(int irq, void *dev_id)
172{
173 struct auo_pixcir_ts *ts = dev_id;
174 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
175 struct auo_point_t point[AUO_PIXCIR_REPORT_POINTS];
176 int i;
177 int ret;
178 int fingers = 0;
179 int abs = -1;
180
181 while (!ts->stopped) {
182
183 /* check for up event in touch touch_ind_mode */
184 if (ts->touch_ind_mode) {
185 if (gpio_get_value(pdata->gpio_int) == 0) {
186 input_mt_sync(ts->input);
187 input_report_key(ts->input, BTN_TOUCH, 0);
188 input_sync(ts->input);
189 break;
190 }
191 }
192
193 ret = auo_pixcir_collect_data(ts, point);
194 if (ret < 0) {
195 /* we want to loop only in touch_ind_mode */
196 if (!ts->touch_ind_mode)
197 break;
198
199 wait_event_timeout(ts->wait, ts->stopped,
200 msecs_to_jiffies(AUO_PIXCIR_PENUP_TIMEOUT_MS));
201 continue;
202 }
203
204 for (i = 0; i < AUO_PIXCIR_REPORT_POINTS; i++) {
205 if (point[i].coord_x > 0 || point[i].coord_y > 0) {
206 input_report_abs(ts->input, ABS_MT_POSITION_X,
207 point[i].coord_x);
208 input_report_abs(ts->input, ABS_MT_POSITION_Y,
209 point[i].coord_y);
210 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
211 point[i].area_major);
212 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR,
213 point[i].area_minor);
214 input_report_abs(ts->input, ABS_MT_ORIENTATION,
215 point[i].orientation);
216 input_mt_sync(ts->input);
217
218 /* use first finger as source for singletouch */
219 if (fingers == 0)
220 abs = i;
221
222 /* number of touch points could also be queried
223 * via i2c but would require an additional call
224 */
225 fingers++;
226 }
227 }
228
229 input_report_key(ts->input, BTN_TOUCH, fingers > 0);
230
231 if (abs > -1) {
232 input_report_abs(ts->input, ABS_X, point[abs].coord_x);
233 input_report_abs(ts->input, ABS_Y, point[abs].coord_y);
234 }
235
236 input_sync(ts->input);
237
238 /* we want to loop only in touch_ind_mode */
239 if (!ts->touch_ind_mode)
240 break;
241
242 wait_event_timeout(ts->wait, ts->stopped,
243 msecs_to_jiffies(AUO_PIXCIR_PENUP_TIMEOUT_MS));
244 }
245
246 return IRQ_HANDLED;
247}
248
249/*
250 * Set the power mode of the device.
251 * Valid modes are
252 * - AUO_PIXCIR_POWER_ACTIVE
253 * - AUO_PIXCIR_POWER_SLEEP - automatically left on first touch
254 * - AUO_PIXCIR_POWER_DEEP_SLEEP
255 */
256static int auo_pixcir_power_mode(struct auo_pixcir_ts *ts, int mode)
257{
258 struct i2c_client *client = ts->client;
259 int ret;
260
261 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_POWER_MODE);
262 if (ret < 0) {
263 dev_err(&client->dev, "unable to read reg %Xh, %d\n",
264 AUO_PIXCIR_REG_POWER_MODE, ret);
265 return ret;
266 }
267
268 ret &= ~AUO_PIXCIR_POWER_MASK;
269 ret |= mode;
270
271 ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_POWER_MODE, ret);
272 if (ret) {
273 dev_err(&client->dev, "unable to write reg %Xh, %d\n",
274 AUO_PIXCIR_REG_POWER_MODE, ret);
275 return ret;
276 }
277
278 return 0;
279}
280
281static int auo_pixcir_int_config(struct auo_pixcir_ts *ts,
282 int int_setting)
283{
284 struct i2c_client *client = ts->client;
285 const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
286 int ret;
287
288 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
289 if (ret < 0) {
290 dev_err(&client->dev, "unable to read reg %Xh, %d\n",
291 AUO_PIXCIR_REG_INT_SETTING, ret);
292 return ret;
293 }
294
295 ret &= ~AUO_PIXCIR_INT_MODE_MASK;
296 ret |= int_setting;
297 ret |= AUO_PIXCIR_INT_POL_HIGH; /* always use high for interrupts */
298
299 ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_INT_SETTING,
300 ret);
301 if (ret < 0) {
302 dev_err(&client->dev, "unable to write reg %Xh, %d\n",
303 AUO_PIXCIR_REG_INT_SETTING, ret);
304 return ret;
305 }
306
307 ts->touch_ind_mode = pdata->int_setting == AUO_PIXCIR_INT_TOUCH_IND;
308
309 return 0;
310}
311
312/* control the generation of interrupts on the device side */
313static int auo_pixcir_int_toggle(struct auo_pixcir_ts *ts, bool enable)
314{
315 struct i2c_client *client = ts->client;
316 int ret;
317
318 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
319 if (ret < 0) {
320 dev_err(&client->dev, "unable to read reg %Xh, %d\n",
321 AUO_PIXCIR_REG_INT_SETTING, ret);
322 return ret;
323 }
324
325 if (enable)
326 ret |= AUO_PIXCIR_INT_ENABLE;
327 else
328 ret &= ~AUO_PIXCIR_INT_ENABLE;
329
330 ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_INT_SETTING,
331 ret);
332 if (ret < 0) {
333 dev_err(&client->dev, "unable to write reg %Xh, %d\n",
334 AUO_PIXCIR_REG_INT_SETTING, ret);
335 return ret;
336 }
337
338 return 0;
339}
340
341static int auo_pixcir_start(struct auo_pixcir_ts *ts)
342{
343 struct i2c_client *client = ts->client;
344 int ret;
345
346 ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_ACTIVE);
347 if (ret < 0) {
348 dev_err(&client->dev, "could not set power mode, %d\n",
349 ret);
350 return ret;
351 }
352
353 ts->stopped = false;
354 mb();
355 enable_irq(client->irq);
356
357 ret = auo_pixcir_int_toggle(ts, 1);
358 if (ret < 0) {
359 dev_err(&client->dev, "could not enable interrupt, %d\n",
360 ret);
361 disable_irq(client->irq);
362 return ret;
363 }
364
365 return 0;
366}
367
368static int auo_pixcir_stop(struct auo_pixcir_ts *ts)
369{
370 struct i2c_client *client = ts->client;
371 int ret;
372
373 ret = auo_pixcir_int_toggle(ts, 0);
374 if (ret < 0) {
375 dev_err(&client->dev, "could not disable interrupt, %d\n",
376 ret);
377 return ret;
378 }
379
380 /* disable receiving of interrupts */
381 disable_irq(client->irq);
382 ts->stopped = true;
383 mb();
384 wake_up(&ts->wait);
385
386 return auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_DEEP_SLEEP);
387}
388
389static int auo_pixcir_input_open(struct input_dev *dev)
390{
391 struct auo_pixcir_ts *ts = input_get_drvdata(dev);
392
393 return auo_pixcir_start(ts);
394}
395
396static void auo_pixcir_input_close(struct input_dev *dev)
397{
398 struct auo_pixcir_ts *ts = input_get_drvdata(dev);
399
400 auo_pixcir_stop(ts);
401}
402
403static int __maybe_unused auo_pixcir_suspend(struct device *dev)
404{
405 struct i2c_client *client = to_i2c_client(dev);
406 struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
407 struct input_dev *input = ts->input;
408 int ret = 0;
409
410 mutex_lock(&input->mutex);
411
412 /* when configured as wakeup source, device should always wake system
413 * therefore start device if necessary
414 */
415 if (device_may_wakeup(&client->dev)) {
416 /* need to start device if not open, to be wakeup source */
417 if (!input->users) {
418 ret = auo_pixcir_start(ts);
419 if (ret)
420 goto unlock;
421 }
422
423 enable_irq_wake(client->irq);
424 ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_SLEEP);
425 } else if (input->users) {
426 ret = auo_pixcir_stop(ts);
427 }
428
429unlock:
430 mutex_unlock(&input->mutex);
431
432 return ret;
433}
434
435static int __maybe_unused auo_pixcir_resume(struct device *dev)
436{
437 struct i2c_client *client = to_i2c_client(dev);
438 struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
439 struct input_dev *input = ts->input;
440 int ret = 0;
441
442 mutex_lock(&input->mutex);
443
444 if (device_may_wakeup(&client->dev)) {
445 disable_irq_wake(client->irq);
446
447 /* need to stop device if it was not open on suspend */
448 if (!input->users) {
449 ret = auo_pixcir_stop(ts);
450 if (ret)
451 goto unlock;
452 }
453
454 /* device wakes automatically from SLEEP */
455 } else if (input->users) {
456 ret = auo_pixcir_start(ts);
457 }
458
459unlock:
460 mutex_unlock(&input->mutex);
461
462 return ret;
463}
464
465static SIMPLE_DEV_PM_OPS(auo_pixcir_pm_ops,
466 auo_pixcir_suspend, auo_pixcir_resume);
467
468#ifdef CONFIG_OF
469static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
470{
471 struct auo_pixcir_ts_platdata *pdata;
472 struct device_node *np = dev->of_node;
473
474 if (!np)
475 return ERR_PTR(-ENOENT);
476
477 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
478 if (!pdata)
479 return ERR_PTR(-ENOMEM);
480
481 pdata->gpio_int = of_get_gpio(np, 0);
482 if (!gpio_is_valid(pdata->gpio_int)) {
483 dev_err(dev, "failed to get interrupt gpio\n");
484 return ERR_PTR(-EINVAL);
485 }
486
487 pdata->gpio_rst = of_get_gpio(np, 1);
488 if (!gpio_is_valid(pdata->gpio_rst)) {
489 dev_err(dev, "failed to get reset gpio\n");
490 return ERR_PTR(-EINVAL);
491 }
492
493 if (of_property_read_u32(np, "x-size", &pdata->x_max)) {
494 dev_err(dev, "failed to get x-size property\n");
495 return ERR_PTR(-EINVAL);
496 }
497
498 if (of_property_read_u32(np, "y-size", &pdata->y_max)) {
499 dev_err(dev, "failed to get y-size property\n");
500 return ERR_PTR(-EINVAL);
501 }
502
503 /* default to asserting the interrupt when the screen is touched */
504 pdata->int_setting = AUO_PIXCIR_INT_TOUCH_IND;
505
506 return pdata;
507}
508#else
509static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
510{
511 return ERR_PTR(-EINVAL);
512}
513#endif
514
515static void auo_pixcir_reset(void *data)
516{
517 struct auo_pixcir_ts *ts = data;
518
519 gpio_set_value(ts->pdata->gpio_rst, 0);
520}
521
522static int auo_pixcir_probe(struct i2c_client *client,
523 const struct i2c_device_id *id)
524{
525 const struct auo_pixcir_ts_platdata *pdata;
526 struct auo_pixcir_ts *ts;
527 struct input_dev *input_dev;
528 int version;
529 int error;
530
531 pdata = dev_get_platdata(&client->dev);
532 if (!pdata) {
533 pdata = auo_pixcir_parse_dt(&client->dev);
534 if (IS_ERR(pdata))
535 return PTR_ERR(pdata);
536 }
537
538 ts = devm_kzalloc(&client->dev,
539 sizeof(struct auo_pixcir_ts), GFP_KERNEL);
540 if (!ts)
541 return -ENOMEM;
542
543 input_dev = devm_input_allocate_device(&client->dev);
544 if (!input_dev) {
545 dev_err(&client->dev, "could not allocate input device\n");
546 return -ENOMEM;
547 }
548
549 ts->pdata = pdata;
550 ts->client = client;
551 ts->input = input_dev;
552 ts->touch_ind_mode = 0;
553 ts->stopped = true;
554 init_waitqueue_head(&ts->wait);
555
556 snprintf(ts->phys, sizeof(ts->phys),
557 "%s/input0", dev_name(&client->dev));
558
559 input_dev->name = "AUO-Pixcir touchscreen";
560 input_dev->phys = ts->phys;
561 input_dev->id.bustype = BUS_I2C;
562
563 input_dev->open = auo_pixcir_input_open;
564 input_dev->close = auo_pixcir_input_close;
565
566 __set_bit(EV_ABS, input_dev->evbit);
567 __set_bit(EV_KEY, input_dev->evbit);
568
569 __set_bit(BTN_TOUCH, input_dev->keybit);
570
571 /* For single touch */
572 input_set_abs_params(input_dev, ABS_X, 0, pdata->x_max, 0, 0);
573 input_set_abs_params(input_dev, ABS_Y, 0, pdata->y_max, 0, 0);
574
575 /* For multi touch */
576 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
577 pdata->x_max, 0, 0);
578 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
579 pdata->y_max, 0, 0);
580 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
581 AUO_PIXCIR_MAX_AREA, 0, 0);
582 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0,
583 AUO_PIXCIR_MAX_AREA, 0, 0);
584 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
585
586 input_set_drvdata(ts->input, ts);
587
588 error = devm_gpio_request_one(&client->dev, pdata->gpio_int,
589 GPIOF_DIR_IN, "auo_pixcir_ts_int");
590 if (error) {
591 dev_err(&client->dev, "request of gpio %d failed, %d\n",
592 pdata->gpio_int, error);
593 return error;
594 }
595
596 error = devm_gpio_request_one(&client->dev, pdata->gpio_rst,
597 GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
598 "auo_pixcir_ts_rst");
599 if (error) {
600 dev_err(&client->dev, "request of gpio %d failed, %d\n",
601 pdata->gpio_rst, error);
602 return error;
603 }
604
605 error = devm_add_action_or_reset(&client->dev, auo_pixcir_reset, ts);
606 if (error) {
607 dev_err(&client->dev, "failed to register reset action, %d\n",
608 error);
609 return error;
610 }
611
612 msleep(200);
613
614 version = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
615 if (version < 0) {
616 error = version;
617 return error;
618 }
619
620 dev_info(&client->dev, "firmware version 0x%X\n", version);
621
622 error = auo_pixcir_int_config(ts, pdata->int_setting);
623 if (error)
624 return error;
625
626 error = devm_request_threaded_irq(&client->dev, client->irq,
627 NULL, auo_pixcir_interrupt,
628 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
629 input_dev->name, ts);
630 if (error) {
631 dev_err(&client->dev, "irq %d requested failed, %d\n",
632 client->irq, error);
633 return error;
634 }
635
636 /* stop device and put it into deep sleep until it is opened */
637 error = auo_pixcir_stop(ts);
638 if (error)
639 return error;
640
641 error = input_register_device(input_dev);
642 if (error) {
643 dev_err(&client->dev, "could not register input device, %d\n",
644 error);
645 return error;
646 }
647
648 i2c_set_clientdata(client, ts);
649
650 return 0;
651}
652
653static const struct i2c_device_id auo_pixcir_idtable[] = {
654 { "auo_pixcir_ts", 0 },
655 { }
656};
657MODULE_DEVICE_TABLE(i2c, auo_pixcir_idtable);
658
659#ifdef CONFIG_OF
660static const struct of_device_id auo_pixcir_ts_dt_idtable[] = {
661 { .compatible = "auo,auo_pixcir_ts" },
662 {},
663};
664MODULE_DEVICE_TABLE(of, auo_pixcir_ts_dt_idtable);
665#endif
666
667static struct i2c_driver auo_pixcir_driver = {
668 .driver = {
669 .name = "auo_pixcir_ts",
670 .pm = &auo_pixcir_pm_ops,
671 .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable),
672 },
673 .probe = auo_pixcir_probe,
674 .id_table = auo_pixcir_idtable,
675};
676
677module_i2c_driver(auo_pixcir_driver);
678
679MODULE_DESCRIPTION("AUO-PIXCIR touchscreen driver");
680MODULE_LICENSE("GPL v2");
681MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");