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>
33 #include <linux/of_gpio.h>
35 #define WAIT_TIMEOUT msecs_to_jiffies(1000)
37 #define FRAME_START 0xee
38 #define FRAME_MAXSIZE 257
40 /* Offsets of the different parts of the payload the controller sends */
41 #define PAYLOAD_HEADER 0
42 #define PAYLOAD_LENGTH 1
43 #define PAYLOAD_BODY 2
45 /* Response offsets */
47 #define RESPONSE_DATA 1
50 #define COMMAND_DEACTIVATE 0x00
51 #define COMMAND_INITIALIZE 0x01
52 #define COMMAND_RESOLUTION 0x02
53 #define COMMAND_SETCONFIG 0x03
54 #define COMMAND_DATAREQUEST 0x04
55 #define COMMAND_SCANFREQ 0x08
56 #define COMMAND_STATUS 0X1e
59 * Responses the controller sends as a result of
62 #define RESPONSE_DEACTIVATE 0x00
63 #define RESPONSE_INITIALIZE 0x01
64 #define RESPONSE_RESOLUTION 0x02
65 #define RESPONSE_SETCONFIG 0x03
66 #define RESPONSE_SCANFREQ 0x08
67 #define RESPONSE_STATUS 0X1e
70 * Notifications are sent by the touch controller without
71 * being requested by the driver and include for example
74 #define NOTIFICATION_TOUCH 0x04
75 #define NOTIFICATION_BOOTCOMPLETE 0x07
76 #define NOTIFICATION_OVERRUN 0x25
77 #define NOTIFICATION_PROXIMITY 0x26
78 #define NOTIFICATION_INVALID_COMMAND 0xfe
80 #define ZFORCE_REPORT_POINTS 2
81 #define ZFORCE_MAX_AREA 0xff
87 #define SETCONFIG_DUALTOUCH (1 << 0)
102 * @client the i2c_client
103 * @input the input device
104 * @suspending in the process of going to suspend (don't emit wakeup
105 * events for commands executed to suspend the device)
106 * @suspended device suspended
107 * @access_mutex serialize i2c-access, to keep multipart reads together
108 * @command_done completion to wait for the command result
109 * @command_mutex serialize commands sent to the ic
110 * @command_waiting the id of the command that is currently waiting
112 * @command_result returned result of the command
115 struct i2c_client
*client
;
116 struct input_dev
*input
;
117 const struct zforce_ts_platdata
*pdata
;
124 /* Firmware version information */
130 struct mutex access_mutex
;
132 struct completion command_done
;
133 struct mutex command_mutex
;
138 static int zforce_command(struct zforce_ts
*ts
, u8 cmd
)
140 struct i2c_client
*client
= ts
->client
;
144 dev_dbg(&client
->dev
, "%s: 0x%x\n", __func__
, cmd
);
146 buf
[0] = FRAME_START
;
147 buf
[1] = 1; /* data size, command only */
150 mutex_lock(&ts
->access_mutex
);
151 ret
= i2c_master_send(client
, &buf
[0], ARRAY_SIZE(buf
));
152 mutex_unlock(&ts
->access_mutex
);
154 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
161 static int zforce_send_wait(struct zforce_ts
*ts
, const char *buf
, int len
)
163 struct i2c_client
*client
= ts
->client
;
166 ret
= mutex_trylock(&ts
->command_mutex
);
168 dev_err(&client
->dev
, "already waiting for a command\n");
172 dev_dbg(&client
->dev
, "sending %d bytes for command 0x%x\n",
175 ts
->command_waiting
= buf
[2];
177 mutex_lock(&ts
->access_mutex
);
178 ret
= i2c_master_send(client
, buf
, len
);
179 mutex_unlock(&ts
->access_mutex
);
181 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
185 dev_dbg(&client
->dev
, "waiting for result for command 0x%x\n", buf
[2]);
187 if (wait_for_completion_timeout(&ts
->command_done
, WAIT_TIMEOUT
) == 0) {
192 ret
= ts
->command_result
;
195 mutex_unlock(&ts
->command_mutex
);
199 static int zforce_command_wait(struct zforce_ts
*ts
, u8 cmd
)
201 struct i2c_client
*client
= ts
->client
;
205 dev_dbg(&client
->dev
, "%s: 0x%x\n", __func__
, cmd
);
207 buf
[0] = FRAME_START
;
208 buf
[1] = 1; /* data size, command only */
211 ret
= zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
213 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
220 static int zforce_resolution(struct zforce_ts
*ts
, u16 x
, u16 y
)
222 struct i2c_client
*client
= ts
->client
;
223 char buf
[7] = { FRAME_START
, 5, COMMAND_RESOLUTION
,
224 (x
& 0xff), ((x
>> 8) & 0xff),
225 (y
& 0xff), ((y
>> 8) & 0xff) };
227 dev_dbg(&client
->dev
, "set resolution to (%d,%d)\n", x
, y
);
229 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
232 static int zforce_scan_frequency(struct zforce_ts
*ts
, u16 idle
, u16 finger
,
235 struct i2c_client
*client
= ts
->client
;
236 char buf
[9] = { FRAME_START
, 7, COMMAND_SCANFREQ
,
237 (idle
& 0xff), ((idle
>> 8) & 0xff),
238 (finger
& 0xff), ((finger
>> 8) & 0xff),
239 (stylus
& 0xff), ((stylus
>> 8) & 0xff) };
241 dev_dbg(&client
->dev
,
242 "set scan frequency to (idle: %d, finger: %d, stylus: %d)\n",
243 idle
, finger
, stylus
);
245 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
248 static int zforce_setconfig(struct zforce_ts
*ts
, char b1
)
250 struct i2c_client
*client
= ts
->client
;
251 char buf
[7] = { FRAME_START
, 5, COMMAND_SETCONFIG
,
254 dev_dbg(&client
->dev
, "set config to (%d)\n", b1
);
256 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
259 static int zforce_start(struct zforce_ts
*ts
)
261 struct i2c_client
*client
= ts
->client
;
262 const struct zforce_ts_platdata
*pdata
= ts
->pdata
;
265 dev_dbg(&client
->dev
, "starting device\n");
267 ret
= zforce_command_wait(ts
, COMMAND_INITIALIZE
);
269 dev_err(&client
->dev
, "Unable to initialize, %d\n", ret
);
273 ret
= zforce_resolution(ts
, pdata
->x_max
, pdata
->y_max
);
275 dev_err(&client
->dev
, "Unable to set resolution, %d\n", ret
);
279 ret
= zforce_scan_frequency(ts
, 10, 50, 50);
281 dev_err(&client
->dev
, "Unable to set scan frequency, %d\n",
286 ret
= zforce_setconfig(ts
, SETCONFIG_DUALTOUCH
);
288 dev_err(&client
->dev
, "Unable to set config\n");
292 /* start sending touch events */
293 ret
= zforce_command(ts
, COMMAND_DATAREQUEST
);
295 dev_err(&client
->dev
, "Unable to request data\n");
300 * Per NN, initial cal. take max. of 200msec.
301 * Allow time to complete this calibration
308 zforce_command_wait(ts
, COMMAND_DEACTIVATE
);
312 static int zforce_stop(struct zforce_ts
*ts
)
314 struct i2c_client
*client
= ts
->client
;
317 dev_dbg(&client
->dev
, "stopping device\n");
319 /* Deactivates touch sensing and puts the device into sleep. */
320 ret
= zforce_command_wait(ts
, COMMAND_DEACTIVATE
);
322 dev_err(&client
->dev
, "could not deactivate device, %d\n",
330 static int zforce_touch_event(struct zforce_ts
*ts
, u8
*payload
)
332 struct i2c_client
*client
= ts
->client
;
333 const struct zforce_ts_platdata
*pdata
= ts
->pdata
;
334 struct zforce_point point
;
335 int count
, i
, num
= 0;
338 if (count
> ZFORCE_REPORT_POINTS
) {
339 dev_warn(&client
->dev
,
340 "too many coordinates %d, expected max %d\n",
341 count
, ZFORCE_REPORT_POINTS
);
342 count
= ZFORCE_REPORT_POINTS
;
345 for (i
= 0; i
< count
; i
++) {
347 payload
[9 * i
+ 2] << 8 | payload
[9 * i
+ 1];
349 payload
[9 * i
+ 4] << 8 | payload
[9 * i
+ 3];
351 if (point
.coord_x
> pdata
->x_max
||
352 point
.coord_y
> pdata
->y_max
) {
353 dev_warn(&client
->dev
, "coordinates (%d,%d) invalid\n",
354 point
.coord_x
, point
.coord_y
);
355 point
.coord_x
= point
.coord_y
= 0;
358 point
.state
= payload
[9 * i
+ 5] & 0x03;
359 point
.id
= (payload
[9 * i
+ 5] & 0xfc) >> 2;
361 /* determine touch major, minor and orientation */
362 point
.area_major
= max(payload
[9 * i
+ 6],
364 point
.area_minor
= min(payload
[9 * i
+ 6],
366 point
.orientation
= payload
[9 * i
+ 6] > payload
[9 * i
+ 7];
368 point
.pressure
= payload
[9 * i
+ 8];
369 point
.prblty
= payload
[9 * i
+ 9];
371 dev_dbg(&client
->dev
,
372 "point %d/%d: state %d, id %d, pressure %d, prblty %d, x %d, y %d, amajor %d, aminor %d, ori %d\n",
373 i
, count
, point
.state
, point
.id
,
374 point
.pressure
, point
.prblty
,
375 point
.coord_x
, point
.coord_y
,
376 point
.area_major
, point
.area_minor
,
379 /* the zforce id starts with "1", so needs to be decreased */
380 input_mt_slot(ts
->input
, point
.id
- 1);
382 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
,
383 point
.state
!= STATE_UP
);
385 if (point
.state
!= STATE_UP
) {
386 input_report_abs(ts
->input
, ABS_MT_POSITION_X
,
388 input_report_abs(ts
->input
, ABS_MT_POSITION_Y
,
390 input_report_abs(ts
->input
, ABS_MT_TOUCH_MAJOR
,
392 input_report_abs(ts
->input
, ABS_MT_TOUCH_MINOR
,
394 input_report_abs(ts
->input
, ABS_MT_ORIENTATION
,
400 input_mt_sync_frame(ts
->input
);
402 input_mt_report_finger_count(ts
->input
, num
);
404 input_sync(ts
->input
);
409 static int zforce_read_packet(struct zforce_ts
*ts
, u8
*buf
)
411 struct i2c_client
*client
= ts
->client
;
414 mutex_lock(&ts
->access_mutex
);
416 /* read 2 byte message header */
417 ret
= i2c_master_recv(client
, buf
, 2);
419 dev_err(&client
->dev
, "error reading header: %d\n", ret
);
423 if (buf
[PAYLOAD_HEADER
] != FRAME_START
) {
424 dev_err(&client
->dev
, "invalid frame start: %d\n", buf
[0]);
429 if (buf
[PAYLOAD_LENGTH
] == 0) {
430 dev_err(&client
->dev
, "invalid payload length: %d\n",
431 buf
[PAYLOAD_LENGTH
]);
436 /* read the message */
437 ret
= i2c_master_recv(client
, &buf
[PAYLOAD_BODY
], buf
[PAYLOAD_LENGTH
]);
439 dev_err(&client
->dev
, "error reading payload: %d\n", ret
);
443 dev_dbg(&client
->dev
, "read %d bytes for response command 0x%x\n",
444 buf
[PAYLOAD_LENGTH
], buf
[PAYLOAD_BODY
]);
447 mutex_unlock(&ts
->access_mutex
);
451 static void zforce_complete(struct zforce_ts
*ts
, int cmd
, int result
)
453 struct i2c_client
*client
= ts
->client
;
455 if (ts
->command_waiting
== cmd
) {
456 dev_dbg(&client
->dev
, "completing command 0x%x\n", cmd
);
457 ts
->command_result
= result
;
458 complete(&ts
->command_done
);
460 dev_dbg(&client
->dev
, "command %d not for us\n", cmd
);
464 static irqreturn_t
zforce_irq(int irq
, void *dev_id
)
466 struct zforce_ts
*ts
= dev_id
;
467 struct i2c_client
*client
= ts
->client
;
469 if (ts
->suspended
&& device_may_wakeup(&client
->dev
))
470 pm_wakeup_event(&client
->dev
, 500);
472 return IRQ_WAKE_THREAD
;
475 static irqreturn_t
zforce_irq_thread(int irq
, void *dev_id
)
477 struct zforce_ts
*ts
= dev_id
;
478 struct i2c_client
*client
= ts
->client
;
479 const struct zforce_ts_platdata
*pdata
= ts
->pdata
;
481 u8 payload_buffer
[FRAME_MAXSIZE
];
485 * When still suspended, return.
486 * Due to the level-interrupt we will get re-triggered later.
493 dev_dbg(&client
->dev
, "handling interrupt\n");
495 /* Don't emit wakeup events from commands run by zforce_suspend */
496 if (!ts
->suspending
&& device_may_wakeup(&client
->dev
))
497 pm_stay_awake(&client
->dev
);
499 while (!gpio_get_value(pdata
->gpio_int
)) {
500 ret
= zforce_read_packet(ts
, payload_buffer
);
502 dev_err(&client
->dev
,
503 "could not read packet, ret: %d\n", ret
);
507 payload
= &payload_buffer
[PAYLOAD_BODY
];
509 switch (payload
[RESPONSE_ID
]) {
510 case NOTIFICATION_TOUCH
:
512 * Always report touch-events received while
513 * suspending, when being a wakeup source
515 if (ts
->suspending
&& device_may_wakeup(&client
->dev
))
516 pm_wakeup_event(&client
->dev
, 500);
517 zforce_touch_event(ts
, &payload
[RESPONSE_DATA
]);
520 case NOTIFICATION_BOOTCOMPLETE
:
521 ts
->boot_complete
= payload
[RESPONSE_DATA
];
522 zforce_complete(ts
, payload
[RESPONSE_ID
], 0);
525 case RESPONSE_INITIALIZE
:
526 case RESPONSE_DEACTIVATE
:
527 case RESPONSE_SETCONFIG
:
528 case RESPONSE_RESOLUTION
:
529 case RESPONSE_SCANFREQ
:
530 zforce_complete(ts
, payload
[RESPONSE_ID
],
531 payload
[RESPONSE_DATA
]);
534 case RESPONSE_STATUS
:
536 * Version Payload Results
537 * [2:major] [2:minor] [2:build] [2:rev]
539 ts
->version_major
= (payload
[RESPONSE_DATA
+ 1] << 8) |
540 payload
[RESPONSE_DATA
];
541 ts
->version_minor
= (payload
[RESPONSE_DATA
+ 3] << 8) |
542 payload
[RESPONSE_DATA
+ 2];
543 ts
->version_build
= (payload
[RESPONSE_DATA
+ 5] << 8) |
544 payload
[RESPONSE_DATA
+ 4];
545 ts
->version_rev
= (payload
[RESPONSE_DATA
+ 7] << 8) |
546 payload
[RESPONSE_DATA
+ 6];
547 dev_dbg(&ts
->client
->dev
,
548 "Firmware Version %04x:%04x %04x:%04x\n",
549 ts
->version_major
, ts
->version_minor
,
550 ts
->version_build
, ts
->version_rev
);
552 zforce_complete(ts
, payload
[RESPONSE_ID
], 0);
555 case NOTIFICATION_INVALID_COMMAND
:
556 dev_err(&ts
->client
->dev
, "invalid command: 0x%x\n",
557 payload
[RESPONSE_DATA
]);
561 dev_err(&ts
->client
->dev
,
562 "unrecognized response id: 0x%x\n",
563 payload
[RESPONSE_ID
]);
568 if (!ts
->suspending
&& device_may_wakeup(&client
->dev
))
569 pm_relax(&client
->dev
);
571 dev_dbg(&client
->dev
, "finished interrupt\n");
576 static int zforce_input_open(struct input_dev
*dev
)
578 struct zforce_ts
*ts
= input_get_drvdata(dev
);
581 ret
= zforce_start(ts
);
588 static void zforce_input_close(struct input_dev
*dev
)
590 struct zforce_ts
*ts
= input_get_drvdata(dev
);
591 struct i2c_client
*client
= ts
->client
;
594 ret
= zforce_stop(ts
);
596 dev_warn(&client
->dev
, "stopping zforce failed\n");
601 #ifdef CONFIG_PM_SLEEP
602 static int zforce_suspend(struct device
*dev
)
604 struct i2c_client
*client
= to_i2c_client(dev
);
605 struct zforce_ts
*ts
= i2c_get_clientdata(client
);
606 struct input_dev
*input
= ts
->input
;
609 mutex_lock(&input
->mutex
);
610 ts
->suspending
= true;
613 * When configured as a wakeup source device should always wake
614 * the system, therefore start device if necessary.
616 if (device_may_wakeup(&client
->dev
)) {
617 dev_dbg(&client
->dev
, "suspend while being a wakeup source\n");
619 /* Need to start device, if not open, to be a wakeup source. */
621 ret
= zforce_start(ts
);
626 enable_irq_wake(client
->irq
);
627 } else if (input
->users
) {
628 dev_dbg(&client
->dev
,
629 "suspend without being a wakeup source\n");
631 ret
= zforce_stop(ts
);
635 disable_irq(client
->irq
);
638 ts
->suspended
= true;
641 ts
->suspending
= false;
642 mutex_unlock(&input
->mutex
);
647 static int zforce_resume(struct device
*dev
)
649 struct i2c_client
*client
= to_i2c_client(dev
);
650 struct zforce_ts
*ts
= i2c_get_clientdata(client
);
651 struct input_dev
*input
= ts
->input
;
654 mutex_lock(&input
->mutex
);
656 ts
->suspended
= false;
658 if (device_may_wakeup(&client
->dev
)) {
659 dev_dbg(&client
->dev
, "resume from being a wakeup source\n");
661 disable_irq_wake(client
->irq
);
663 /* need to stop device if it was not open on suspend */
665 ret
= zforce_stop(ts
);
669 } else if (input
->users
) {
670 dev_dbg(&client
->dev
, "resume without being a wakeup source\n");
672 enable_irq(client
->irq
);
674 ret
= zforce_start(ts
);
680 mutex_unlock(&input
->mutex
);
686 static SIMPLE_DEV_PM_OPS(zforce_pm_ops
, zforce_suspend
, zforce_resume
);
688 static void zforce_reset(void *data
)
690 struct zforce_ts
*ts
= data
;
692 gpio_set_value(ts
->pdata
->gpio_rst
, 0);
695 static struct zforce_ts_platdata
*zforce_parse_dt(struct device
*dev
)
697 struct zforce_ts_platdata
*pdata
;
698 struct device_node
*np
= dev
->of_node
;
701 return ERR_PTR(-ENOENT
);
703 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
705 dev_err(dev
, "failed to allocate platform data\n");
706 return ERR_PTR(-ENOMEM
);
709 pdata
->gpio_int
= of_get_gpio(np
, 0);
710 if (!gpio_is_valid(pdata
->gpio_int
)) {
711 dev_err(dev
, "failed to get interrupt gpio\n");
712 return ERR_PTR(-EINVAL
);
715 pdata
->gpio_rst
= of_get_gpio(np
, 1);
716 if (!gpio_is_valid(pdata
->gpio_rst
)) {
717 dev_err(dev
, "failed to get reset gpio\n");
718 return ERR_PTR(-EINVAL
);
721 if (of_property_read_u32(np
, "x-size", &pdata
->x_max
)) {
722 dev_err(dev
, "failed to get x-size property\n");
723 return ERR_PTR(-EINVAL
);
726 if (of_property_read_u32(np
, "y-size", &pdata
->y_max
)) {
727 dev_err(dev
, "failed to get y-size property\n");
728 return ERR_PTR(-EINVAL
);
734 static int zforce_probe(struct i2c_client
*client
,
735 const struct i2c_device_id
*id
)
737 const struct zforce_ts_platdata
*pdata
= dev_get_platdata(&client
->dev
);
738 struct zforce_ts
*ts
;
739 struct input_dev
*input_dev
;
743 pdata
= zforce_parse_dt(&client
->dev
);
745 return PTR_ERR(pdata
);
748 ts
= devm_kzalloc(&client
->dev
, sizeof(struct zforce_ts
), GFP_KERNEL
);
752 ret
= devm_gpio_request_one(&client
->dev
, pdata
->gpio_int
, GPIOF_IN
,
755 dev_err(&client
->dev
, "request of gpio %d failed, %d\n",
756 pdata
->gpio_int
, ret
);
760 ret
= devm_gpio_request_one(&client
->dev
, pdata
->gpio_rst
,
761 GPIOF_OUT_INIT_LOW
, "zforce_ts_rst");
763 dev_err(&client
->dev
, "request of gpio %d failed, %d\n",
764 pdata
->gpio_rst
, ret
);
768 ret
= devm_add_action(&client
->dev
, zforce_reset
, ts
);
770 dev_err(&client
->dev
, "failed to register reset action, %d\n",
775 snprintf(ts
->phys
, sizeof(ts
->phys
),
776 "%s/input0", dev_name(&client
->dev
));
778 input_dev
= devm_input_allocate_device(&client
->dev
);
780 dev_err(&client
->dev
, "could not allocate input device\n");
784 mutex_init(&ts
->access_mutex
);
785 mutex_init(&ts
->command_mutex
);
789 ts
->input
= input_dev
;
791 input_dev
->name
= "Neonode zForce touchscreen";
792 input_dev
->phys
= ts
->phys
;
793 input_dev
->id
.bustype
= BUS_I2C
;
795 input_dev
->open
= zforce_input_open
;
796 input_dev
->close
= zforce_input_close
;
798 __set_bit(EV_KEY
, input_dev
->evbit
);
799 __set_bit(EV_SYN
, input_dev
->evbit
);
800 __set_bit(EV_ABS
, input_dev
->evbit
);
802 /* For multi touch */
803 input_set_abs_params(input_dev
, ABS_MT_POSITION_X
, 0,
805 input_set_abs_params(input_dev
, ABS_MT_POSITION_Y
, 0,
808 input_set_abs_params(input_dev
, ABS_MT_TOUCH_MAJOR
, 0,
809 ZFORCE_MAX_AREA
, 0, 0);
810 input_set_abs_params(input_dev
, ABS_MT_TOUCH_MINOR
, 0,
811 ZFORCE_MAX_AREA
, 0, 0);
812 input_set_abs_params(input_dev
, ABS_MT_ORIENTATION
, 0, 1, 0, 0);
813 input_mt_init_slots(input_dev
, ZFORCE_REPORT_POINTS
, INPUT_MT_DIRECT
);
815 input_set_drvdata(ts
->input
, ts
);
817 init_completion(&ts
->command_done
);
820 * The zforce pulls the interrupt low when it has data ready.
821 * After it is triggered the isr thread runs until all the available
822 * packets have been read and the interrupt is high again.
823 * Therefore we can trigger the interrupt anytime it is low and do
824 * not need to limit it to the interrupt edge.
826 ret
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
827 zforce_irq
, zforce_irq_thread
,
828 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
829 input_dev
->name
, ts
);
831 dev_err(&client
->dev
, "irq %d request failed\n", client
->irq
);
835 i2c_set_clientdata(client
, ts
);
837 /* let the controller boot */
838 gpio_set_value(pdata
->gpio_rst
, 1);
840 ts
->command_waiting
= NOTIFICATION_BOOTCOMPLETE
;
841 if (wait_for_completion_timeout(&ts
->command_done
, WAIT_TIMEOUT
) == 0)
842 dev_warn(&client
->dev
, "bootcomplete timed out\n");
844 /* need to start device to get version information */
845 ret
= zforce_command_wait(ts
, COMMAND_INITIALIZE
);
847 dev_err(&client
->dev
, "unable to initialize, %d\n", ret
);
851 /* this gets the firmware version among other information */
852 ret
= zforce_command_wait(ts
, COMMAND_STATUS
);
854 dev_err(&client
->dev
, "couldn't get status, %d\n", ret
);
859 /* stop device and put it into sleep until it is opened */
860 ret
= zforce_stop(ts
);
864 device_set_wakeup_capable(&client
->dev
, true);
866 ret
= input_register_device(input_dev
);
868 dev_err(&client
->dev
, "could not register input device, %d\n",
876 static struct i2c_device_id zforce_idtable
[] = {
880 MODULE_DEVICE_TABLE(i2c
, zforce_idtable
);
883 static const struct of_device_id zforce_dt_idtable
[] = {
884 { .compatible
= "neonode,zforce" },
887 MODULE_DEVICE_TABLE(of
, zforce_dt_idtable
);
890 static struct i2c_driver zforce_driver
= {
892 .owner
= THIS_MODULE
,
894 .pm
= &zforce_pm_ops
,
895 .of_match_table
= of_match_ptr(zforce_dt_idtable
),
897 .probe
= zforce_probe
,
898 .id_table
= zforce_idtable
,
901 module_i2c_driver(zforce_driver
);
903 MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
904 MODULE_DESCRIPTION("zForce TouchScreen Driver");
905 MODULE_LICENSE("GPL");