2 * Copyright (C) 2012-2013 MundoReader S.L.
3 * Author: Heiko Stuebner <heiko@sntech.de>
5 * based in parts on Nook zforce driver
7 * Copyright (C) 2010 Barnes & Noble, Inc.
8 * Author: Pieter Truter<ptruter@intrinsyc.com>
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #include <linux/module.h>
21 #include <linux/hrtimer.h>
22 #include <linux/slab.h>
23 #include <linux/input.h>
24 #include <linux/interrupt.h>
25 #include <linux/i2c.h>
26 #include <linux/delay.h>
27 #include <linux/gpio.h>
28 #include <linux/device.h>
29 #include <linux/sysfs.h>
30 #include <linux/input/mt.h>
31 #include <linux/platform_data/zforce_ts.h>
32 #include <linux/regulator/consumer.h>
33 #include <linux/delay.h>
35 #include <linux/of_gpio.h>
37 #define WAIT_TIMEOUT msecs_to_jiffies(1000)
39 #define FRAME_START 0xee
40 #define FRAME_MAXSIZE 257
42 /* Offsets of the different parts of the payload the controller sends */
43 #define PAYLOAD_HEADER 0
44 #define PAYLOAD_LENGTH 1
45 #define PAYLOAD_BODY 2
47 /* Response offsets */
49 #define RESPONSE_DATA 1
52 #define COMMAND_DEACTIVATE 0x00
53 #define COMMAND_INITIALIZE 0x01
54 #define COMMAND_RESOLUTION 0x02
55 #define COMMAND_SETCONFIG 0x03
56 #define COMMAND_DATAREQUEST 0x04
57 #define COMMAND_SCANFREQ 0x08
58 #define COMMAND_STATUS 0X1e
61 * Responses the controller sends as a result of
64 #define RESPONSE_DEACTIVATE 0x00
65 #define RESPONSE_INITIALIZE 0x01
66 #define RESPONSE_RESOLUTION 0x02
67 #define RESPONSE_SETCONFIG 0x03
68 #define RESPONSE_SCANFREQ 0x08
69 #define RESPONSE_STATUS 0X1e
72 * Notifications are sent by the touch controller without
73 * being requested by the driver and include for example
76 #define NOTIFICATION_TOUCH 0x04
77 #define NOTIFICATION_BOOTCOMPLETE 0x07
78 #define NOTIFICATION_OVERRUN 0x25
79 #define NOTIFICATION_PROXIMITY 0x26
80 #define NOTIFICATION_INVALID_COMMAND 0xfe
82 #define ZFORCE_REPORT_POINTS 2
83 #define ZFORCE_MAX_AREA 0xff
89 #define SETCONFIG_DUALTOUCH (1 << 0)
104 * @client the i2c_client
105 * @input the input device
106 * @suspending in the process of going to suspend (don't emit wakeup
107 * events for commands executed to suspend the device)
108 * @suspended device suspended
109 * @access_mutex serialize i2c-access, to keep multipart reads together
110 * @command_done completion to wait for the command result
111 * @command_mutex serialize commands sent to the ic
112 * @command_waiting the id of the command that is currently waiting
114 * @command_result returned result of the command
117 struct i2c_client
*client
;
118 struct input_dev
*input
;
119 const struct zforce_ts_platdata
*pdata
;
122 struct regulator
*reg_vdd
;
128 /* Firmware version information */
134 struct mutex access_mutex
;
136 struct completion command_done
;
137 struct mutex command_mutex
;
142 static int zforce_command(struct zforce_ts
*ts
, u8 cmd
)
144 struct i2c_client
*client
= ts
->client
;
148 dev_dbg(&client
->dev
, "%s: 0x%x\n", __func__
, cmd
);
150 buf
[0] = FRAME_START
;
151 buf
[1] = 1; /* data size, command only */
154 mutex_lock(&ts
->access_mutex
);
155 ret
= i2c_master_send(client
, &buf
[0], ARRAY_SIZE(buf
));
156 mutex_unlock(&ts
->access_mutex
);
158 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
165 static int zforce_send_wait(struct zforce_ts
*ts
, const char *buf
, int len
)
167 struct i2c_client
*client
= ts
->client
;
170 ret
= mutex_trylock(&ts
->command_mutex
);
172 dev_err(&client
->dev
, "already waiting for a command\n");
176 dev_dbg(&client
->dev
, "sending %d bytes for command 0x%x\n",
179 ts
->command_waiting
= buf
[2];
181 mutex_lock(&ts
->access_mutex
);
182 ret
= i2c_master_send(client
, buf
, len
);
183 mutex_unlock(&ts
->access_mutex
);
185 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
189 dev_dbg(&client
->dev
, "waiting for result for command 0x%x\n", buf
[2]);
191 if (wait_for_completion_timeout(&ts
->command_done
, WAIT_TIMEOUT
) == 0) {
196 ret
= ts
->command_result
;
199 mutex_unlock(&ts
->command_mutex
);
203 static int zforce_command_wait(struct zforce_ts
*ts
, u8 cmd
)
205 struct i2c_client
*client
= ts
->client
;
209 dev_dbg(&client
->dev
, "%s: 0x%x\n", __func__
, cmd
);
211 buf
[0] = FRAME_START
;
212 buf
[1] = 1; /* data size, command only */
215 ret
= zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
217 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
224 static int zforce_resolution(struct zforce_ts
*ts
, u16 x
, u16 y
)
226 struct i2c_client
*client
= ts
->client
;
227 char buf
[7] = { FRAME_START
, 5, COMMAND_RESOLUTION
,
228 (x
& 0xff), ((x
>> 8) & 0xff),
229 (y
& 0xff), ((y
>> 8) & 0xff) };
231 dev_dbg(&client
->dev
, "set resolution to (%d,%d)\n", x
, y
);
233 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
236 static int zforce_scan_frequency(struct zforce_ts
*ts
, u16 idle
, u16 finger
,
239 struct i2c_client
*client
= ts
->client
;
240 char buf
[9] = { FRAME_START
, 7, COMMAND_SCANFREQ
,
241 (idle
& 0xff), ((idle
>> 8) & 0xff),
242 (finger
& 0xff), ((finger
>> 8) & 0xff),
243 (stylus
& 0xff), ((stylus
>> 8) & 0xff) };
245 dev_dbg(&client
->dev
,
246 "set scan frequency to (idle: %d, finger: %d, stylus: %d)\n",
247 idle
, finger
, stylus
);
249 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
252 static int zforce_setconfig(struct zforce_ts
*ts
, char b1
)
254 struct i2c_client
*client
= ts
->client
;
255 char buf
[7] = { FRAME_START
, 5, COMMAND_SETCONFIG
,
258 dev_dbg(&client
->dev
, "set config to (%d)\n", b1
);
260 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
263 static int zforce_start(struct zforce_ts
*ts
)
265 struct i2c_client
*client
= ts
->client
;
266 const struct zforce_ts_platdata
*pdata
= ts
->pdata
;
269 dev_dbg(&client
->dev
, "starting device\n");
271 ret
= zforce_command_wait(ts
, COMMAND_INITIALIZE
);
273 dev_err(&client
->dev
, "Unable to initialize, %d\n", ret
);
277 ret
= zforce_resolution(ts
, pdata
->x_max
, pdata
->y_max
);
279 dev_err(&client
->dev
, "Unable to set resolution, %d\n", ret
);
283 ret
= zforce_scan_frequency(ts
, 10, 50, 50);
285 dev_err(&client
->dev
, "Unable to set scan frequency, %d\n",
290 ret
= zforce_setconfig(ts
, SETCONFIG_DUALTOUCH
);
292 dev_err(&client
->dev
, "Unable to set config\n");
296 /* start sending touch events */
297 ret
= zforce_command(ts
, COMMAND_DATAREQUEST
);
299 dev_err(&client
->dev
, "Unable to request data\n");
304 * Per NN, initial cal. take max. of 200msec.
305 * Allow time to complete this calibration
312 zforce_command_wait(ts
, COMMAND_DEACTIVATE
);
316 static int zforce_stop(struct zforce_ts
*ts
)
318 struct i2c_client
*client
= ts
->client
;
321 dev_dbg(&client
->dev
, "stopping device\n");
323 /* Deactivates touch sensing and puts the device into sleep. */
324 ret
= zforce_command_wait(ts
, COMMAND_DEACTIVATE
);
326 dev_err(&client
->dev
, "could not deactivate device, %d\n",
334 static int zforce_touch_event(struct zforce_ts
*ts
, u8
*payload
)
336 struct i2c_client
*client
= ts
->client
;
337 const struct zforce_ts_platdata
*pdata
= ts
->pdata
;
338 struct zforce_point point
;
339 int count
, i
, num
= 0;
342 if (count
> ZFORCE_REPORT_POINTS
) {
343 dev_warn(&client
->dev
,
344 "too many coordinates %d, expected max %d\n",
345 count
, ZFORCE_REPORT_POINTS
);
346 count
= ZFORCE_REPORT_POINTS
;
349 for (i
= 0; i
< count
; i
++) {
351 payload
[9 * i
+ 2] << 8 | payload
[9 * i
+ 1];
353 payload
[9 * i
+ 4] << 8 | payload
[9 * i
+ 3];
355 if (point
.coord_x
> pdata
->x_max
||
356 point
.coord_y
> pdata
->y_max
) {
357 dev_warn(&client
->dev
, "coordinates (%d,%d) invalid\n",
358 point
.coord_x
, point
.coord_y
);
359 point
.coord_x
= point
.coord_y
= 0;
362 point
.state
= payload
[9 * i
+ 5] & 0x03;
363 point
.id
= (payload
[9 * i
+ 5] & 0xfc) >> 2;
365 /* determine touch major, minor and orientation */
366 point
.area_major
= max(payload
[9 * i
+ 6],
368 point
.area_minor
= min(payload
[9 * i
+ 6],
370 point
.orientation
= payload
[9 * i
+ 6] > payload
[9 * i
+ 7];
372 point
.pressure
= payload
[9 * i
+ 8];
373 point
.prblty
= payload
[9 * i
+ 9];
375 dev_dbg(&client
->dev
,
376 "point %d/%d: state %d, id %d, pressure %d, prblty %d, x %d, y %d, amajor %d, aminor %d, ori %d\n",
377 i
, count
, point
.state
, point
.id
,
378 point
.pressure
, point
.prblty
,
379 point
.coord_x
, point
.coord_y
,
380 point
.area_major
, point
.area_minor
,
383 /* the zforce id starts with "1", so needs to be decreased */
384 input_mt_slot(ts
->input
, point
.id
- 1);
386 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
,
387 point
.state
!= STATE_UP
);
389 if (point
.state
!= STATE_UP
) {
390 input_report_abs(ts
->input
, ABS_MT_POSITION_X
,
392 input_report_abs(ts
->input
, ABS_MT_POSITION_Y
,
394 input_report_abs(ts
->input
, ABS_MT_TOUCH_MAJOR
,
396 input_report_abs(ts
->input
, ABS_MT_TOUCH_MINOR
,
398 input_report_abs(ts
->input
, ABS_MT_ORIENTATION
,
404 input_mt_sync_frame(ts
->input
);
406 input_mt_report_finger_count(ts
->input
, num
);
408 input_sync(ts
->input
);
413 static int zforce_read_packet(struct zforce_ts
*ts
, u8
*buf
)
415 struct i2c_client
*client
= ts
->client
;
418 mutex_lock(&ts
->access_mutex
);
420 /* read 2 byte message header */
421 ret
= i2c_master_recv(client
, buf
, 2);
423 dev_err(&client
->dev
, "error reading header: %d\n", ret
);
427 if (buf
[PAYLOAD_HEADER
] != FRAME_START
) {
428 dev_err(&client
->dev
, "invalid frame start: %d\n", buf
[0]);
433 if (buf
[PAYLOAD_LENGTH
] == 0) {
434 dev_err(&client
->dev
, "invalid payload length: %d\n",
435 buf
[PAYLOAD_LENGTH
]);
440 /* read the message */
441 ret
= i2c_master_recv(client
, &buf
[PAYLOAD_BODY
], buf
[PAYLOAD_LENGTH
]);
443 dev_err(&client
->dev
, "error reading payload: %d\n", ret
);
447 dev_dbg(&client
->dev
, "read %d bytes for response command 0x%x\n",
448 buf
[PAYLOAD_LENGTH
], buf
[PAYLOAD_BODY
]);
451 mutex_unlock(&ts
->access_mutex
);
455 static void zforce_complete(struct zforce_ts
*ts
, int cmd
, int result
)
457 struct i2c_client
*client
= ts
->client
;
459 if (ts
->command_waiting
== cmd
) {
460 dev_dbg(&client
->dev
, "completing command 0x%x\n", cmd
);
461 ts
->command_result
= result
;
462 complete(&ts
->command_done
);
464 dev_dbg(&client
->dev
, "command %d not for us\n", cmd
);
468 static irqreturn_t
zforce_irq(int irq
, void *dev_id
)
470 struct zforce_ts
*ts
= dev_id
;
471 struct i2c_client
*client
= ts
->client
;
473 if (ts
->suspended
&& device_may_wakeup(&client
->dev
))
474 pm_wakeup_event(&client
->dev
, 500);
476 return IRQ_WAKE_THREAD
;
479 static irqreturn_t
zforce_irq_thread(int irq
, void *dev_id
)
481 struct zforce_ts
*ts
= dev_id
;
482 struct i2c_client
*client
= ts
->client
;
483 const struct zforce_ts_platdata
*pdata
= ts
->pdata
;
485 u8 payload_buffer
[FRAME_MAXSIZE
];
489 * When still suspended, return.
490 * Due to the level-interrupt we will get re-triggered later.
497 dev_dbg(&client
->dev
, "handling interrupt\n");
499 /* Don't emit wakeup events from commands run by zforce_suspend */
500 if (!ts
->suspending
&& device_may_wakeup(&client
->dev
))
501 pm_stay_awake(&client
->dev
);
503 while (!gpio_get_value(pdata
->gpio_int
)) {
504 ret
= zforce_read_packet(ts
, payload_buffer
);
506 dev_err(&client
->dev
,
507 "could not read packet, ret: %d\n", ret
);
511 payload
= &payload_buffer
[PAYLOAD_BODY
];
513 switch (payload
[RESPONSE_ID
]) {
514 case NOTIFICATION_TOUCH
:
516 * Always report touch-events received while
517 * suspending, when being a wakeup source
519 if (ts
->suspending
&& device_may_wakeup(&client
->dev
))
520 pm_wakeup_event(&client
->dev
, 500);
521 zforce_touch_event(ts
, &payload
[RESPONSE_DATA
]);
524 case NOTIFICATION_BOOTCOMPLETE
:
525 ts
->boot_complete
= payload
[RESPONSE_DATA
];
526 zforce_complete(ts
, payload
[RESPONSE_ID
], 0);
529 case RESPONSE_INITIALIZE
:
530 case RESPONSE_DEACTIVATE
:
531 case RESPONSE_SETCONFIG
:
532 case RESPONSE_RESOLUTION
:
533 case RESPONSE_SCANFREQ
:
534 zforce_complete(ts
, payload
[RESPONSE_ID
],
535 payload
[RESPONSE_DATA
]);
538 case RESPONSE_STATUS
:
540 * Version Payload Results
541 * [2:major] [2:minor] [2:build] [2:rev]
543 ts
->version_major
= (payload
[RESPONSE_DATA
+ 1] << 8) |
544 payload
[RESPONSE_DATA
];
545 ts
->version_minor
= (payload
[RESPONSE_DATA
+ 3] << 8) |
546 payload
[RESPONSE_DATA
+ 2];
547 ts
->version_build
= (payload
[RESPONSE_DATA
+ 5] << 8) |
548 payload
[RESPONSE_DATA
+ 4];
549 ts
->version_rev
= (payload
[RESPONSE_DATA
+ 7] << 8) |
550 payload
[RESPONSE_DATA
+ 6];
551 dev_dbg(&ts
->client
->dev
,
552 "Firmware Version %04x:%04x %04x:%04x\n",
553 ts
->version_major
, ts
->version_minor
,
554 ts
->version_build
, ts
->version_rev
);
556 zforce_complete(ts
, payload
[RESPONSE_ID
], 0);
559 case NOTIFICATION_INVALID_COMMAND
:
560 dev_err(&ts
->client
->dev
, "invalid command: 0x%x\n",
561 payload
[RESPONSE_DATA
]);
565 dev_err(&ts
->client
->dev
,
566 "unrecognized response id: 0x%x\n",
567 payload
[RESPONSE_ID
]);
572 if (!ts
->suspending
&& device_may_wakeup(&client
->dev
))
573 pm_relax(&client
->dev
);
575 dev_dbg(&client
->dev
, "finished interrupt\n");
580 static int zforce_input_open(struct input_dev
*dev
)
582 struct zforce_ts
*ts
= input_get_drvdata(dev
);
585 ret
= zforce_start(ts
);
592 static void zforce_input_close(struct input_dev
*dev
)
594 struct zforce_ts
*ts
= input_get_drvdata(dev
);
595 struct i2c_client
*client
= ts
->client
;
598 ret
= zforce_stop(ts
);
600 dev_warn(&client
->dev
, "stopping zforce failed\n");
605 static int __maybe_unused
zforce_suspend(struct device
*dev
)
607 struct i2c_client
*client
= to_i2c_client(dev
);
608 struct zforce_ts
*ts
= i2c_get_clientdata(client
);
609 struct input_dev
*input
= ts
->input
;
612 mutex_lock(&input
->mutex
);
613 ts
->suspending
= true;
616 * When configured as a wakeup source device should always wake
617 * the system, therefore start device if necessary.
619 if (device_may_wakeup(&client
->dev
)) {
620 dev_dbg(&client
->dev
, "suspend while being a wakeup source\n");
622 /* Need to start device, if not open, to be a wakeup source. */
624 ret
= zforce_start(ts
);
629 enable_irq_wake(client
->irq
);
630 } else if (input
->users
) {
631 dev_dbg(&client
->dev
,
632 "suspend without being a wakeup source\n");
634 ret
= zforce_stop(ts
);
638 disable_irq(client
->irq
);
641 ts
->suspended
= true;
644 ts
->suspending
= false;
645 mutex_unlock(&input
->mutex
);
650 static int __maybe_unused
zforce_resume(struct device
*dev
)
652 struct i2c_client
*client
= to_i2c_client(dev
);
653 struct zforce_ts
*ts
= i2c_get_clientdata(client
);
654 struct input_dev
*input
= ts
->input
;
657 mutex_lock(&input
->mutex
);
659 ts
->suspended
= false;
661 if (device_may_wakeup(&client
->dev
)) {
662 dev_dbg(&client
->dev
, "resume from being a wakeup source\n");
664 disable_irq_wake(client
->irq
);
666 /* need to stop device if it was not open on suspend */
668 ret
= zforce_stop(ts
);
672 } else if (input
->users
) {
673 dev_dbg(&client
->dev
, "resume without being a wakeup source\n");
675 enable_irq(client
->irq
);
677 ret
= zforce_start(ts
);
683 mutex_unlock(&input
->mutex
);
688 static SIMPLE_DEV_PM_OPS(zforce_pm_ops
, zforce_suspend
, zforce_resume
);
690 static void zforce_reset(void *data
)
692 struct zforce_ts
*ts
= data
;
694 gpio_set_value(ts
->pdata
->gpio_rst
, 0);
698 if (!IS_ERR(ts
->reg_vdd
))
699 regulator_disable(ts
->reg_vdd
);
702 static struct zforce_ts_platdata
*zforce_parse_dt(struct device
*dev
)
704 struct zforce_ts_platdata
*pdata
;
705 struct device_node
*np
= dev
->of_node
;
708 return ERR_PTR(-ENOENT
);
710 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
712 dev_err(dev
, "failed to allocate platform data\n");
713 return ERR_PTR(-ENOMEM
);
716 pdata
->gpio_int
= of_get_gpio(np
, 0);
717 if (!gpio_is_valid(pdata
->gpio_int
)) {
718 dev_err(dev
, "failed to get interrupt gpio\n");
719 return ERR_PTR(-EINVAL
);
722 pdata
->gpio_rst
= of_get_gpio(np
, 1);
723 if (!gpio_is_valid(pdata
->gpio_rst
)) {
724 dev_err(dev
, "failed to get reset gpio\n");
725 return ERR_PTR(-EINVAL
);
728 if (of_property_read_u32(np
, "x-size", &pdata
->x_max
)) {
729 dev_err(dev
, "failed to get x-size property\n");
730 return ERR_PTR(-EINVAL
);
733 if (of_property_read_u32(np
, "y-size", &pdata
->y_max
)) {
734 dev_err(dev
, "failed to get y-size property\n");
735 return ERR_PTR(-EINVAL
);
741 static int zforce_probe(struct i2c_client
*client
,
742 const struct i2c_device_id
*id
)
744 const struct zforce_ts_platdata
*pdata
= dev_get_platdata(&client
->dev
);
745 struct zforce_ts
*ts
;
746 struct input_dev
*input_dev
;
750 pdata
= zforce_parse_dt(&client
->dev
);
752 return PTR_ERR(pdata
);
755 ts
= devm_kzalloc(&client
->dev
, sizeof(struct zforce_ts
), GFP_KERNEL
);
759 ret
= devm_gpio_request_one(&client
->dev
, pdata
->gpio_int
, GPIOF_IN
,
762 dev_err(&client
->dev
, "request of gpio %d failed, %d\n",
763 pdata
->gpio_int
, ret
);
767 ret
= devm_gpio_request_one(&client
->dev
, pdata
->gpio_rst
,
768 GPIOF_OUT_INIT_LOW
, "zforce_ts_rst");
770 dev_err(&client
->dev
, "request of gpio %d failed, %d\n",
771 pdata
->gpio_rst
, ret
);
775 ts
->reg_vdd
= devm_regulator_get_optional(&client
->dev
, "vdd");
776 if (IS_ERR(ts
->reg_vdd
)) {
777 ret
= PTR_ERR(ts
->reg_vdd
);
778 if (ret
== -EPROBE_DEFER
)
781 ret
= regulator_enable(ts
->reg_vdd
);
786 * according to datasheet add 100us grace time after regular
787 * regulator enable delay.
792 ret
= devm_add_action(&client
->dev
, zforce_reset
, ts
);
794 dev_err(&client
->dev
, "failed to register reset action, %d\n",
797 /* hereafter the regulator will be disabled by the action */
798 if (!IS_ERR(ts
->reg_vdd
))
799 regulator_disable(ts
->reg_vdd
);
804 snprintf(ts
->phys
, sizeof(ts
->phys
),
805 "%s/input0", dev_name(&client
->dev
));
807 input_dev
= devm_input_allocate_device(&client
->dev
);
809 dev_err(&client
->dev
, "could not allocate input device\n");
813 mutex_init(&ts
->access_mutex
);
814 mutex_init(&ts
->command_mutex
);
818 ts
->input
= input_dev
;
820 input_dev
->name
= "Neonode zForce touchscreen";
821 input_dev
->phys
= ts
->phys
;
822 input_dev
->id
.bustype
= BUS_I2C
;
824 input_dev
->open
= zforce_input_open
;
825 input_dev
->close
= zforce_input_close
;
827 __set_bit(EV_KEY
, input_dev
->evbit
);
828 __set_bit(EV_SYN
, input_dev
->evbit
);
829 __set_bit(EV_ABS
, input_dev
->evbit
);
831 /* For multi touch */
832 input_set_abs_params(input_dev
, ABS_MT_POSITION_X
, 0,
834 input_set_abs_params(input_dev
, ABS_MT_POSITION_Y
, 0,
837 input_set_abs_params(input_dev
, ABS_MT_TOUCH_MAJOR
, 0,
838 ZFORCE_MAX_AREA
, 0, 0);
839 input_set_abs_params(input_dev
, ABS_MT_TOUCH_MINOR
, 0,
840 ZFORCE_MAX_AREA
, 0, 0);
841 input_set_abs_params(input_dev
, ABS_MT_ORIENTATION
, 0, 1, 0, 0);
842 input_mt_init_slots(input_dev
, ZFORCE_REPORT_POINTS
, INPUT_MT_DIRECT
);
844 input_set_drvdata(ts
->input
, ts
);
846 init_completion(&ts
->command_done
);
849 * The zforce pulls the interrupt low when it has data ready.
850 * After it is triggered the isr thread runs until all the available
851 * packets have been read and the interrupt is high again.
852 * Therefore we can trigger the interrupt anytime it is low and do
853 * not need to limit it to the interrupt edge.
855 ret
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
856 zforce_irq
, zforce_irq_thread
,
857 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
858 input_dev
->name
, ts
);
860 dev_err(&client
->dev
, "irq %d request failed\n", client
->irq
);
864 i2c_set_clientdata(client
, ts
);
866 /* let the controller boot */
867 gpio_set_value(pdata
->gpio_rst
, 1);
869 ts
->command_waiting
= NOTIFICATION_BOOTCOMPLETE
;
870 if (wait_for_completion_timeout(&ts
->command_done
, WAIT_TIMEOUT
) == 0)
871 dev_warn(&client
->dev
, "bootcomplete timed out\n");
873 /* need to start device to get version information */
874 ret
= zforce_command_wait(ts
, COMMAND_INITIALIZE
);
876 dev_err(&client
->dev
, "unable to initialize, %d\n", ret
);
880 /* this gets the firmware version among other information */
881 ret
= zforce_command_wait(ts
, COMMAND_STATUS
);
883 dev_err(&client
->dev
, "couldn't get status, %d\n", ret
);
888 /* stop device and put it into sleep until it is opened */
889 ret
= zforce_stop(ts
);
893 device_set_wakeup_capable(&client
->dev
, true);
895 ret
= input_register_device(input_dev
);
897 dev_err(&client
->dev
, "could not register input device, %d\n",
905 static struct i2c_device_id zforce_idtable
[] = {
909 MODULE_DEVICE_TABLE(i2c
, zforce_idtable
);
912 static const struct of_device_id zforce_dt_idtable
[] = {
913 { .compatible
= "neonode,zforce" },
916 MODULE_DEVICE_TABLE(of
, zforce_dt_idtable
);
919 static struct i2c_driver zforce_driver
= {
921 .owner
= THIS_MODULE
,
923 .pm
= &zforce_pm_ops
,
924 .of_match_table
= of_match_ptr(zforce_dt_idtable
),
926 .probe
= zforce_probe
,
927 .id_table
= zforce_idtable
,
930 module_i2c_driver(zforce_driver
);
932 MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
933 MODULE_DESCRIPTION("zForce TouchScreen Driver");
934 MODULE_LICENSE("GPL");