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/consumer.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>
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
;
120 struct regulator
*reg_vdd
;
122 struct gpio_desc
*gpio_int
;
123 struct gpio_desc
*gpio_rst
;
129 /* Firmware version information */
135 struct mutex access_mutex
;
137 struct completion command_done
;
138 struct mutex command_mutex
;
143 static int zforce_command(struct zforce_ts
*ts
, u8 cmd
)
145 struct i2c_client
*client
= ts
->client
;
149 dev_dbg(&client
->dev
, "%s: 0x%x\n", __func__
, cmd
);
151 buf
[0] = FRAME_START
;
152 buf
[1] = 1; /* data size, command only */
155 mutex_lock(&ts
->access_mutex
);
156 ret
= i2c_master_send(client
, &buf
[0], ARRAY_SIZE(buf
));
157 mutex_unlock(&ts
->access_mutex
);
159 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
166 static void zforce_reset_assert(struct zforce_ts
*ts
)
168 gpiod_set_value_cansleep(ts
->gpio_rst
, 1);
171 static void zforce_reset_deassert(struct zforce_ts
*ts
)
173 gpiod_set_value_cansleep(ts
->gpio_rst
, 0);
176 static int zforce_send_wait(struct zforce_ts
*ts
, const char *buf
, int len
)
178 struct i2c_client
*client
= ts
->client
;
181 ret
= mutex_trylock(&ts
->command_mutex
);
183 dev_err(&client
->dev
, "already waiting for a command\n");
187 dev_dbg(&client
->dev
, "sending %d bytes for command 0x%x\n",
190 ts
->command_waiting
= buf
[2];
192 mutex_lock(&ts
->access_mutex
);
193 ret
= i2c_master_send(client
, buf
, len
);
194 mutex_unlock(&ts
->access_mutex
);
196 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
200 dev_dbg(&client
->dev
, "waiting for result for command 0x%x\n", buf
[2]);
202 if (wait_for_completion_timeout(&ts
->command_done
, WAIT_TIMEOUT
) == 0) {
207 ret
= ts
->command_result
;
210 mutex_unlock(&ts
->command_mutex
);
214 static int zforce_command_wait(struct zforce_ts
*ts
, u8 cmd
)
216 struct i2c_client
*client
= ts
->client
;
220 dev_dbg(&client
->dev
, "%s: 0x%x\n", __func__
, cmd
);
222 buf
[0] = FRAME_START
;
223 buf
[1] = 1; /* data size, command only */
226 ret
= zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
228 dev_err(&client
->dev
, "i2c send data request error: %d\n", ret
);
235 static int zforce_resolution(struct zforce_ts
*ts
, u16 x
, u16 y
)
237 struct i2c_client
*client
= ts
->client
;
238 char buf
[7] = { FRAME_START
, 5, COMMAND_RESOLUTION
,
239 (x
& 0xff), ((x
>> 8) & 0xff),
240 (y
& 0xff), ((y
>> 8) & 0xff) };
242 dev_dbg(&client
->dev
, "set resolution to (%d,%d)\n", x
, y
);
244 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
247 static int zforce_scan_frequency(struct zforce_ts
*ts
, u16 idle
, u16 finger
,
250 struct i2c_client
*client
= ts
->client
;
251 char buf
[9] = { FRAME_START
, 7, COMMAND_SCANFREQ
,
252 (idle
& 0xff), ((idle
>> 8) & 0xff),
253 (finger
& 0xff), ((finger
>> 8) & 0xff),
254 (stylus
& 0xff), ((stylus
>> 8) & 0xff) };
256 dev_dbg(&client
->dev
,
257 "set scan frequency to (idle: %d, finger: %d, stylus: %d)\n",
258 idle
, finger
, stylus
);
260 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
263 static int zforce_setconfig(struct zforce_ts
*ts
, char b1
)
265 struct i2c_client
*client
= ts
->client
;
266 char buf
[7] = { FRAME_START
, 5, COMMAND_SETCONFIG
,
269 dev_dbg(&client
->dev
, "set config to (%d)\n", b1
);
271 return zforce_send_wait(ts
, &buf
[0], ARRAY_SIZE(buf
));
274 static int zforce_start(struct zforce_ts
*ts
)
276 struct i2c_client
*client
= ts
->client
;
277 const struct zforce_ts_platdata
*pdata
= ts
->pdata
;
280 dev_dbg(&client
->dev
, "starting device\n");
282 ret
= zforce_command_wait(ts
, COMMAND_INITIALIZE
);
284 dev_err(&client
->dev
, "Unable to initialize, %d\n", ret
);
288 ret
= zforce_resolution(ts
, pdata
->x_max
, pdata
->y_max
);
290 dev_err(&client
->dev
, "Unable to set resolution, %d\n", ret
);
294 ret
= zforce_scan_frequency(ts
, 10, 50, 50);
296 dev_err(&client
->dev
, "Unable to set scan frequency, %d\n",
301 ret
= zforce_setconfig(ts
, SETCONFIG_DUALTOUCH
);
303 dev_err(&client
->dev
, "Unable to set config\n");
307 /* start sending touch events */
308 ret
= zforce_command(ts
, COMMAND_DATAREQUEST
);
310 dev_err(&client
->dev
, "Unable to request data\n");
315 * Per NN, initial cal. take max. of 200msec.
316 * Allow time to complete this calibration
323 zforce_command_wait(ts
, COMMAND_DEACTIVATE
);
327 static int zforce_stop(struct zforce_ts
*ts
)
329 struct i2c_client
*client
= ts
->client
;
332 dev_dbg(&client
->dev
, "stopping device\n");
334 /* Deactivates touch sensing and puts the device into sleep. */
335 ret
= zforce_command_wait(ts
, COMMAND_DEACTIVATE
);
337 dev_err(&client
->dev
, "could not deactivate device, %d\n",
345 static int zforce_touch_event(struct zforce_ts
*ts
, u8
*payload
)
347 struct i2c_client
*client
= ts
->client
;
348 const struct zforce_ts_platdata
*pdata
= ts
->pdata
;
349 struct zforce_point point
;
350 int count
, i
, num
= 0;
353 if (count
> ZFORCE_REPORT_POINTS
) {
354 dev_warn(&client
->dev
,
355 "too many coordinates %d, expected max %d\n",
356 count
, ZFORCE_REPORT_POINTS
);
357 count
= ZFORCE_REPORT_POINTS
;
360 for (i
= 0; i
< count
; i
++) {
362 payload
[9 * i
+ 2] << 8 | payload
[9 * i
+ 1];
364 payload
[9 * i
+ 4] << 8 | payload
[9 * i
+ 3];
366 if (point
.coord_x
> pdata
->x_max
||
367 point
.coord_y
> pdata
->y_max
) {
368 dev_warn(&client
->dev
, "coordinates (%d,%d) invalid\n",
369 point
.coord_x
, point
.coord_y
);
370 point
.coord_x
= point
.coord_y
= 0;
373 point
.state
= payload
[9 * i
+ 5] & 0x03;
374 point
.id
= (payload
[9 * i
+ 5] & 0xfc) >> 2;
376 /* determine touch major, minor and orientation */
377 point
.area_major
= max(payload
[9 * i
+ 6],
379 point
.area_minor
= min(payload
[9 * i
+ 6],
381 point
.orientation
= payload
[9 * i
+ 6] > payload
[9 * i
+ 7];
383 point
.pressure
= payload
[9 * i
+ 8];
384 point
.prblty
= payload
[9 * i
+ 9];
386 dev_dbg(&client
->dev
,
387 "point %d/%d: state %d, id %d, pressure %d, prblty %d, x %d, y %d, amajor %d, aminor %d, ori %d\n",
388 i
, count
, point
.state
, point
.id
,
389 point
.pressure
, point
.prblty
,
390 point
.coord_x
, point
.coord_y
,
391 point
.area_major
, point
.area_minor
,
394 /* the zforce id starts with "1", so needs to be decreased */
395 input_mt_slot(ts
->input
, point
.id
- 1);
397 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
,
398 point
.state
!= STATE_UP
);
400 if (point
.state
!= STATE_UP
) {
401 input_report_abs(ts
->input
, ABS_MT_POSITION_X
,
403 input_report_abs(ts
->input
, ABS_MT_POSITION_Y
,
405 input_report_abs(ts
->input
, ABS_MT_TOUCH_MAJOR
,
407 input_report_abs(ts
->input
, ABS_MT_TOUCH_MINOR
,
409 input_report_abs(ts
->input
, ABS_MT_ORIENTATION
,
415 input_mt_sync_frame(ts
->input
);
417 input_mt_report_finger_count(ts
->input
, num
);
419 input_sync(ts
->input
);
424 static int zforce_read_packet(struct zforce_ts
*ts
, u8
*buf
)
426 struct i2c_client
*client
= ts
->client
;
429 mutex_lock(&ts
->access_mutex
);
431 /* read 2 byte message header */
432 ret
= i2c_master_recv(client
, buf
, 2);
434 dev_err(&client
->dev
, "error reading header: %d\n", ret
);
438 if (buf
[PAYLOAD_HEADER
] != FRAME_START
) {
439 dev_err(&client
->dev
, "invalid frame start: %d\n", buf
[0]);
444 if (buf
[PAYLOAD_LENGTH
] == 0) {
445 dev_err(&client
->dev
, "invalid payload length: %d\n",
446 buf
[PAYLOAD_LENGTH
]);
451 /* read the message */
452 ret
= i2c_master_recv(client
, &buf
[PAYLOAD_BODY
], buf
[PAYLOAD_LENGTH
]);
454 dev_err(&client
->dev
, "error reading payload: %d\n", ret
);
458 dev_dbg(&client
->dev
, "read %d bytes for response command 0x%x\n",
459 buf
[PAYLOAD_LENGTH
], buf
[PAYLOAD_BODY
]);
462 mutex_unlock(&ts
->access_mutex
);
466 static void zforce_complete(struct zforce_ts
*ts
, int cmd
, int result
)
468 struct i2c_client
*client
= ts
->client
;
470 if (ts
->command_waiting
== cmd
) {
471 dev_dbg(&client
->dev
, "completing command 0x%x\n", cmd
);
472 ts
->command_result
= result
;
473 complete(&ts
->command_done
);
475 dev_dbg(&client
->dev
, "command %d not for us\n", cmd
);
479 static irqreturn_t
zforce_irq(int irq
, void *dev_id
)
481 struct zforce_ts
*ts
= dev_id
;
482 struct i2c_client
*client
= ts
->client
;
484 if (ts
->suspended
&& device_may_wakeup(&client
->dev
))
485 pm_wakeup_event(&client
->dev
, 500);
487 return IRQ_WAKE_THREAD
;
490 static irqreturn_t
zforce_irq_thread(int irq
, void *dev_id
)
492 struct zforce_ts
*ts
= dev_id
;
493 struct i2c_client
*client
= ts
->client
;
495 u8 payload_buffer
[FRAME_MAXSIZE
];
499 * When still suspended, return.
500 * Due to the level-interrupt we will get re-triggered later.
507 dev_dbg(&client
->dev
, "handling interrupt\n");
509 /* Don't emit wakeup events from commands run by zforce_suspend */
510 if (!ts
->suspending
&& device_may_wakeup(&client
->dev
))
511 pm_stay_awake(&client
->dev
);
514 * Run at least once and exit the loop if
515 * - the optional interrupt GPIO isn't specified
516 * (there is only one packet read per ISR invocation, then)
518 * - the GPIO isn't active any more
519 * (packet read until the level GPIO indicates that there is
523 ret
= zforce_read_packet(ts
, payload_buffer
);
525 dev_err(&client
->dev
,
526 "could not read packet, ret: %d\n", ret
);
530 payload
= &payload_buffer
[PAYLOAD_BODY
];
532 switch (payload
[RESPONSE_ID
]) {
533 case NOTIFICATION_TOUCH
:
535 * Always report touch-events received while
536 * suspending, when being a wakeup source
538 if (ts
->suspending
&& device_may_wakeup(&client
->dev
))
539 pm_wakeup_event(&client
->dev
, 500);
540 zforce_touch_event(ts
, &payload
[RESPONSE_DATA
]);
543 case NOTIFICATION_BOOTCOMPLETE
:
544 ts
->boot_complete
= payload
[RESPONSE_DATA
];
545 zforce_complete(ts
, payload
[RESPONSE_ID
], 0);
548 case RESPONSE_INITIALIZE
:
549 case RESPONSE_DEACTIVATE
:
550 case RESPONSE_SETCONFIG
:
551 case RESPONSE_RESOLUTION
:
552 case RESPONSE_SCANFREQ
:
553 zforce_complete(ts
, payload
[RESPONSE_ID
],
554 payload
[RESPONSE_DATA
]);
557 case RESPONSE_STATUS
:
559 * Version Payload Results
560 * [2:major] [2:minor] [2:build] [2:rev]
562 ts
->version_major
= (payload
[RESPONSE_DATA
+ 1] << 8) |
563 payload
[RESPONSE_DATA
];
564 ts
->version_minor
= (payload
[RESPONSE_DATA
+ 3] << 8) |
565 payload
[RESPONSE_DATA
+ 2];
566 ts
->version_build
= (payload
[RESPONSE_DATA
+ 5] << 8) |
567 payload
[RESPONSE_DATA
+ 4];
568 ts
->version_rev
= (payload
[RESPONSE_DATA
+ 7] << 8) |
569 payload
[RESPONSE_DATA
+ 6];
570 dev_dbg(&ts
->client
->dev
,
571 "Firmware Version %04x:%04x %04x:%04x\n",
572 ts
->version_major
, ts
->version_minor
,
573 ts
->version_build
, ts
->version_rev
);
575 zforce_complete(ts
, payload
[RESPONSE_ID
], 0);
578 case NOTIFICATION_INVALID_COMMAND
:
579 dev_err(&ts
->client
->dev
, "invalid command: 0x%x\n",
580 payload
[RESPONSE_DATA
]);
584 dev_err(&ts
->client
->dev
,
585 "unrecognized response id: 0x%x\n",
586 payload
[RESPONSE_ID
]);
589 } while (gpiod_get_value_cansleep(ts
->gpio_int
));
591 if (!ts
->suspending
&& device_may_wakeup(&client
->dev
))
592 pm_relax(&client
->dev
);
594 dev_dbg(&client
->dev
, "finished interrupt\n");
599 static int zforce_input_open(struct input_dev
*dev
)
601 struct zforce_ts
*ts
= input_get_drvdata(dev
);
604 ret
= zforce_start(ts
);
611 static void zforce_input_close(struct input_dev
*dev
)
613 struct zforce_ts
*ts
= input_get_drvdata(dev
);
614 struct i2c_client
*client
= ts
->client
;
617 ret
= zforce_stop(ts
);
619 dev_warn(&client
->dev
, "stopping zforce failed\n");
624 static int __maybe_unused
zforce_suspend(struct device
*dev
)
626 struct i2c_client
*client
= to_i2c_client(dev
);
627 struct zforce_ts
*ts
= i2c_get_clientdata(client
);
628 struct input_dev
*input
= ts
->input
;
631 mutex_lock(&input
->mutex
);
632 ts
->suspending
= true;
635 * When configured as a wakeup source device should always wake
636 * the system, therefore start device if necessary.
638 if (device_may_wakeup(&client
->dev
)) {
639 dev_dbg(&client
->dev
, "suspend while being a wakeup source\n");
641 /* Need to start device, if not open, to be a wakeup source. */
643 ret
= zforce_start(ts
);
648 enable_irq_wake(client
->irq
);
649 } else if (input
->users
) {
650 dev_dbg(&client
->dev
,
651 "suspend without being a wakeup source\n");
653 ret
= zforce_stop(ts
);
657 disable_irq(client
->irq
);
660 ts
->suspended
= true;
663 ts
->suspending
= false;
664 mutex_unlock(&input
->mutex
);
669 static int __maybe_unused
zforce_resume(struct device
*dev
)
671 struct i2c_client
*client
= to_i2c_client(dev
);
672 struct zforce_ts
*ts
= i2c_get_clientdata(client
);
673 struct input_dev
*input
= ts
->input
;
676 mutex_lock(&input
->mutex
);
678 ts
->suspended
= false;
680 if (device_may_wakeup(&client
->dev
)) {
681 dev_dbg(&client
->dev
, "resume from being a wakeup source\n");
683 disable_irq_wake(client
->irq
);
685 /* need to stop device if it was not open on suspend */
687 ret
= zforce_stop(ts
);
691 } else if (input
->users
) {
692 dev_dbg(&client
->dev
, "resume without being a wakeup source\n");
694 enable_irq(client
->irq
);
696 ret
= zforce_start(ts
);
702 mutex_unlock(&input
->mutex
);
707 static SIMPLE_DEV_PM_OPS(zforce_pm_ops
, zforce_suspend
, zforce_resume
);
709 static void zforce_reset(void *data
)
711 struct zforce_ts
*ts
= data
;
713 zforce_reset_assert(ts
);
717 if (!IS_ERR(ts
->reg_vdd
))
718 regulator_disable(ts
->reg_vdd
);
721 static struct zforce_ts_platdata
*zforce_parse_dt(struct device
*dev
)
723 struct zforce_ts_platdata
*pdata
;
724 struct device_node
*np
= dev
->of_node
;
727 return ERR_PTR(-ENOENT
);
729 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
731 dev_err(dev
, "failed to allocate platform data\n");
732 return ERR_PTR(-ENOMEM
);
735 if (of_property_read_u32(np
, "x-size", &pdata
->x_max
)) {
736 dev_err(dev
, "failed to get x-size property\n");
737 return ERR_PTR(-EINVAL
);
740 if (of_property_read_u32(np
, "y-size", &pdata
->y_max
)) {
741 dev_err(dev
, "failed to get y-size property\n");
742 return ERR_PTR(-EINVAL
);
748 static int zforce_probe(struct i2c_client
*client
,
749 const struct i2c_device_id
*id
)
751 const struct zforce_ts_platdata
*pdata
= dev_get_platdata(&client
->dev
);
752 struct zforce_ts
*ts
;
753 struct input_dev
*input_dev
;
757 pdata
= zforce_parse_dt(&client
->dev
);
759 return PTR_ERR(pdata
);
762 ts
= devm_kzalloc(&client
->dev
, sizeof(struct zforce_ts
), GFP_KERNEL
);
766 ts
->gpio_rst
= devm_gpiod_get_optional(&client
->dev
, "reset",
768 if (IS_ERR(ts
->gpio_rst
)) {
769 ret
= PTR_ERR(ts
->gpio_rst
);
770 dev_err(&client
->dev
,
771 "failed to request reset GPIO: %d\n", ret
);
776 ts
->gpio_int
= devm_gpiod_get_optional(&client
->dev
, "irq",
778 if (IS_ERR(ts
->gpio_int
)) {
779 ret
= PTR_ERR(ts
->gpio_int
);
780 dev_err(&client
->dev
,
781 "failed to request interrupt GPIO: %d\n", ret
);
786 * Deprecated GPIO handling for compatibility
787 * with legacy binding.
791 ts
->gpio_int
= devm_gpiod_get_index(&client
->dev
, NULL
, 0,
793 if (IS_ERR(ts
->gpio_int
)) {
794 ret
= PTR_ERR(ts
->gpio_int
);
795 dev_err(&client
->dev
,
796 "failed to request interrupt GPIO: %d\n", ret
);
801 ts
->gpio_rst
= devm_gpiod_get_index(&client
->dev
, NULL
, 1,
803 if (IS_ERR(ts
->gpio_rst
)) {
804 ret
= PTR_ERR(ts
->gpio_rst
);
805 dev_err(&client
->dev
,
806 "failed to request reset GPIO: %d\n", ret
);
811 ts
->reg_vdd
= devm_regulator_get_optional(&client
->dev
, "vdd");
812 if (IS_ERR(ts
->reg_vdd
)) {
813 ret
= PTR_ERR(ts
->reg_vdd
);
814 if (ret
== -EPROBE_DEFER
)
817 ret
= regulator_enable(ts
->reg_vdd
);
822 * according to datasheet add 100us grace time after regular
823 * regulator enable delay.
828 ret
= devm_add_action(&client
->dev
, zforce_reset
, ts
);
830 dev_err(&client
->dev
, "failed to register reset action, %d\n",
833 /* hereafter the regulator will be disabled by the action */
834 if (!IS_ERR(ts
->reg_vdd
))
835 regulator_disable(ts
->reg_vdd
);
840 snprintf(ts
->phys
, sizeof(ts
->phys
),
841 "%s/input0", dev_name(&client
->dev
));
843 input_dev
= devm_input_allocate_device(&client
->dev
);
845 dev_err(&client
->dev
, "could not allocate input device\n");
849 mutex_init(&ts
->access_mutex
);
850 mutex_init(&ts
->command_mutex
);
854 ts
->input
= input_dev
;
856 input_dev
->name
= "Neonode zForce touchscreen";
857 input_dev
->phys
= ts
->phys
;
858 input_dev
->id
.bustype
= BUS_I2C
;
860 input_dev
->open
= zforce_input_open
;
861 input_dev
->close
= zforce_input_close
;
863 __set_bit(EV_KEY
, input_dev
->evbit
);
864 __set_bit(EV_SYN
, input_dev
->evbit
);
865 __set_bit(EV_ABS
, input_dev
->evbit
);
867 /* For multi touch */
868 input_set_abs_params(input_dev
, ABS_MT_POSITION_X
, 0,
870 input_set_abs_params(input_dev
, ABS_MT_POSITION_Y
, 0,
873 input_set_abs_params(input_dev
, ABS_MT_TOUCH_MAJOR
, 0,
874 ZFORCE_MAX_AREA
, 0, 0);
875 input_set_abs_params(input_dev
, ABS_MT_TOUCH_MINOR
, 0,
876 ZFORCE_MAX_AREA
, 0, 0);
877 input_set_abs_params(input_dev
, ABS_MT_ORIENTATION
, 0, 1, 0, 0);
878 input_mt_init_slots(input_dev
, ZFORCE_REPORT_POINTS
, INPUT_MT_DIRECT
);
880 input_set_drvdata(ts
->input
, ts
);
882 init_completion(&ts
->command_done
);
885 * The zforce pulls the interrupt low when it has data ready.
886 * After it is triggered the isr thread runs until all the available
887 * packets have been read and the interrupt is high again.
888 * Therefore we can trigger the interrupt anytime it is low and do
889 * not need to limit it to the interrupt edge.
891 ret
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
892 zforce_irq
, zforce_irq_thread
,
893 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
894 input_dev
->name
, ts
);
896 dev_err(&client
->dev
, "irq %d request failed\n", client
->irq
);
900 i2c_set_clientdata(client
, ts
);
902 /* let the controller boot */
903 zforce_reset_deassert(ts
);
905 ts
->command_waiting
= NOTIFICATION_BOOTCOMPLETE
;
906 if (wait_for_completion_timeout(&ts
->command_done
, WAIT_TIMEOUT
) == 0)
907 dev_warn(&client
->dev
, "bootcomplete timed out\n");
909 /* need to start device to get version information */
910 ret
= zforce_command_wait(ts
, COMMAND_INITIALIZE
);
912 dev_err(&client
->dev
, "unable to initialize, %d\n", ret
);
916 /* this gets the firmware version among other information */
917 ret
= zforce_command_wait(ts
, COMMAND_STATUS
);
919 dev_err(&client
->dev
, "couldn't get status, %d\n", ret
);
924 /* stop device and put it into sleep until it is opened */
925 ret
= zforce_stop(ts
);
929 device_set_wakeup_capable(&client
->dev
, true);
931 ret
= input_register_device(input_dev
);
933 dev_err(&client
->dev
, "could not register input device, %d\n",
941 static struct i2c_device_id zforce_idtable
[] = {
945 MODULE_DEVICE_TABLE(i2c
, zforce_idtable
);
948 static const struct of_device_id zforce_dt_idtable
[] = {
949 { .compatible
= "neonode,zforce" },
952 MODULE_DEVICE_TABLE(of
, zforce_dt_idtable
);
955 static struct i2c_driver zforce_driver
= {
958 .pm
= &zforce_pm_ops
,
959 .of_match_table
= of_match_ptr(zforce_dt_idtable
),
961 .probe
= zforce_probe
,
962 .id_table
= zforce_idtable
,
965 module_i2c_driver(zforce_driver
);
967 MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
968 MODULE_DESCRIPTION("zForce TouchScreen Driver");
969 MODULE_LICENSE("GPL");