2 * Atmel maXTouch Touchscreen driver
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Copyright (C) 2011-2014 Atmel Corporation
6 * Copyright (C) 2012 Google, Inc.
8 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
17 #include <linux/acpi.h>
18 #include <linux/dmi.h>
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/completion.h>
22 #include <linux/delay.h>
23 #include <linux/firmware.h>
24 #include <linux/i2c.h>
25 #include <linux/platform_data/atmel_mxt_ts.h>
26 #include <linux/input/mt.h>
27 #include <linux/interrupt.h>
29 #include <linux/slab.h>
30 #include <asm/unaligned.h>
33 #define MXT_FW_NAME "maxtouch.fw"
34 #define MXT_CFG_NAME "maxtouch.cfg"
35 #define MXT_CFG_MAGIC "OBP_RAW V1"
38 #define MXT_OBJECT_START 0x07
39 #define MXT_OBJECT_SIZE 6
40 #define MXT_INFO_CHECKSUM_SIZE 3
41 #define MXT_MAX_BLOCK_WRITE 256
44 #define MXT_DEBUG_DIAGNOSTIC_T37 37
45 #define MXT_GEN_MESSAGE_T5 5
46 #define MXT_GEN_COMMAND_T6 6
47 #define MXT_GEN_POWER_T7 7
48 #define MXT_GEN_ACQUIRE_T8 8
49 #define MXT_GEN_DATASOURCE_T53 53
50 #define MXT_TOUCH_MULTI_T9 9
51 #define MXT_TOUCH_KEYARRAY_T15 15
52 #define MXT_TOUCH_PROXIMITY_T23 23
53 #define MXT_TOUCH_PROXKEY_T52 52
54 #define MXT_PROCI_GRIPFACE_T20 20
55 #define MXT_PROCG_NOISE_T22 22
56 #define MXT_PROCI_ONETOUCH_T24 24
57 #define MXT_PROCI_TWOTOUCH_T27 27
58 #define MXT_PROCI_GRIP_T40 40
59 #define MXT_PROCI_PALM_T41 41
60 #define MXT_PROCI_TOUCHSUPPRESSION_T42 42
61 #define MXT_PROCI_STYLUS_T47 47
62 #define MXT_PROCG_NOISESUPPRESSION_T48 48
63 #define MXT_SPT_COMMSCONFIG_T18 18
64 #define MXT_SPT_GPIOPWM_T19 19
65 #define MXT_SPT_SELFTEST_T25 25
66 #define MXT_SPT_CTECONFIG_T28 28
67 #define MXT_SPT_USERDATA_T38 38
68 #define MXT_SPT_DIGITIZER_T43 43
69 #define MXT_SPT_MESSAGECOUNT_T44 44
70 #define MXT_SPT_CTECONFIG_T46 46
71 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100
73 /* MXT_GEN_MESSAGE_T5 object */
74 #define MXT_RPTID_NOMSG 0xff
76 /* MXT_GEN_COMMAND_T6 field */
77 #define MXT_COMMAND_RESET 0
78 #define MXT_COMMAND_BACKUPNV 1
79 #define MXT_COMMAND_CALIBRATE 2
80 #define MXT_COMMAND_REPORTALL 3
81 #define MXT_COMMAND_DIAGNOSTIC 5
83 /* Define for T6 status byte */
84 #define MXT_T6_STATUS_RESET (1 << 7)
85 #define MXT_T6_STATUS_OFL (1 << 6)
86 #define MXT_T6_STATUS_SIGERR (1 << 5)
87 #define MXT_T6_STATUS_CAL (1 << 4)
88 #define MXT_T6_STATUS_CFGERR (1 << 3)
89 #define MXT_T6_STATUS_COMSERR (1 << 2)
91 /* MXT_GEN_POWER_T7 field */
97 #define MXT_POWER_CFG_RUN 0
98 #define MXT_POWER_CFG_DEEPSLEEP 1
100 /* MXT_TOUCH_MULTI_T9 field */
101 #define MXT_T9_CTRL 0
102 #define MXT_T9_ORIENT 9
103 #define MXT_T9_RANGE 18
105 /* MXT_TOUCH_MULTI_T9 status */
106 #define MXT_T9_UNGRIP (1 << 0)
107 #define MXT_T9_SUPPRESS (1 << 1)
108 #define MXT_T9_AMP (1 << 2)
109 #define MXT_T9_VECTOR (1 << 3)
110 #define MXT_T9_MOVE (1 << 4)
111 #define MXT_T9_RELEASE (1 << 5)
112 #define MXT_T9_PRESS (1 << 6)
113 #define MXT_T9_DETECT (1 << 7)
120 /* MXT_TOUCH_MULTI_T9 orient */
121 #define MXT_T9_ORIENT_SWITCH (1 << 0)
123 /* MXT_SPT_COMMSCONFIG_T18 */
124 #define MXT_COMMS_CTRL 0
125 #define MXT_COMMS_CMD 1
127 /* Define for MXT_GEN_COMMAND_T6 */
128 #define MXT_BOOT_VALUE 0xa5
129 #define MXT_RESET_VALUE 0x01
130 #define MXT_BACKUP_VALUE 0x55
132 /* T100 Multiple Touch Touchscreen */
133 #define MXT_T100_CTRL 0
134 #define MXT_T100_CFG1 1
135 #define MXT_T100_TCHAUX 3
136 #define MXT_T100_XRANGE 13
137 #define MXT_T100_YRANGE 24
139 #define MXT_T100_CFG_SWITCHXY BIT(5)
141 #define MXT_T100_TCHAUX_VECT BIT(0)
142 #define MXT_T100_TCHAUX_AMPL BIT(1)
143 #define MXT_T100_TCHAUX_AREA BIT(2)
145 #define MXT_T100_DETECT BIT(7)
146 #define MXT_T100_TYPE_MASK 0x70
149 MXT_T100_TYPE_FINGER
= 1,
150 MXT_T100_TYPE_PASSIVE_STYLUS
= 2,
151 MXT_T100_TYPE_HOVERING_FINGER
= 4,
152 MXT_T100_TYPE_GLOVE
= 5,
153 MXT_T100_TYPE_LARGE_TOUCH
= 6,
156 #define MXT_DISTANCE_ACTIVE_TOUCH 0
157 #define MXT_DISTANCE_HOVERING 1
159 #define MXT_TOUCH_MAJOR_DEFAULT 1
160 #define MXT_PRESSURE_DEFAULT 1
163 #define MXT_BACKUP_TIME 50 /* msec */
164 #define MXT_RESET_TIME 200 /* msec */
165 #define MXT_RESET_TIMEOUT 3000 /* msec */
166 #define MXT_CRC_TIMEOUT 1000 /* msec */
167 #define MXT_FW_RESET_TIME 3000 /* msec */
168 #define MXT_FW_CHG_TIMEOUT 300 /* msec */
170 /* Command to unlock bootloader */
171 #define MXT_UNLOCK_CMD_MSB 0xaa
172 #define MXT_UNLOCK_CMD_LSB 0xdc
174 /* Bootloader mode status */
175 #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
176 #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
177 #define MXT_FRAME_CRC_CHECK 0x02
178 #define MXT_FRAME_CRC_FAIL 0x03
179 #define MXT_FRAME_CRC_PASS 0x04
180 #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
181 #define MXT_BOOT_STATUS_MASK 0x3f
182 #define MXT_BOOT_EXTENDED_ID (1 << 5)
183 #define MXT_BOOT_ID_MASK 0x1f
185 /* Touchscreen absolute values */
186 #define MXT_MAX_AREA 0xff
188 #define MXT_PIXELS_PER_MM 20
204 u8 instances_minus_one
;
208 /* Each client has this additional data */
210 struct i2c_client
*client
;
211 struct input_dev
*input_dev
;
212 char phys
[64]; /* device physical location */
213 const struct mxt_platform_data
*pdata
;
214 struct mxt_object
*object_table
;
215 struct mxt_info info
;
232 u8 last_message_count
;
235 struct t7_config t7_cfg
;
237 /* Cached parameters from object table */
247 u8 T100_reportid_min
;
248 u8 T100_reportid_max
;
250 /* for fw update in bootloader */
251 struct completion bl_completion
;
253 /* for reset handling */
254 struct completion reset_completion
;
256 /* for config update handling */
257 struct completion crc_completion
;
260 static size_t mxt_obj_size(const struct mxt_object
*obj
)
262 return obj
->size_minus_one
+ 1;
265 static size_t mxt_obj_instances(const struct mxt_object
*obj
)
267 return obj
->instances_minus_one
+ 1;
270 static bool mxt_object_readable(unsigned int type
)
273 case MXT_GEN_COMMAND_T6
:
274 case MXT_GEN_POWER_T7
:
275 case MXT_GEN_ACQUIRE_T8
:
276 case MXT_GEN_DATASOURCE_T53
:
277 case MXT_TOUCH_MULTI_T9
:
278 case MXT_TOUCH_KEYARRAY_T15
:
279 case MXT_TOUCH_PROXIMITY_T23
:
280 case MXT_TOUCH_PROXKEY_T52
:
281 case MXT_PROCI_GRIPFACE_T20
:
282 case MXT_PROCG_NOISE_T22
:
283 case MXT_PROCI_ONETOUCH_T24
:
284 case MXT_PROCI_TWOTOUCH_T27
:
285 case MXT_PROCI_GRIP_T40
:
286 case MXT_PROCI_PALM_T41
:
287 case MXT_PROCI_TOUCHSUPPRESSION_T42
:
288 case MXT_PROCI_STYLUS_T47
:
289 case MXT_PROCG_NOISESUPPRESSION_T48
:
290 case MXT_SPT_COMMSCONFIG_T18
:
291 case MXT_SPT_GPIOPWM_T19
:
292 case MXT_SPT_SELFTEST_T25
:
293 case MXT_SPT_CTECONFIG_T28
:
294 case MXT_SPT_USERDATA_T38
:
295 case MXT_SPT_DIGITIZER_T43
:
296 case MXT_SPT_CTECONFIG_T46
:
303 static void mxt_dump_message(struct mxt_data
*data
, u8
*message
)
305 dev_dbg(&data
->client
->dev
, "message: %*ph\n",
306 data
->T5_msg_size
, message
);
309 static int mxt_wait_for_completion(struct mxt_data
*data
,
310 struct completion
*comp
,
311 unsigned int timeout_ms
)
313 struct device
*dev
= &data
->client
->dev
;
314 unsigned long timeout
= msecs_to_jiffies(timeout_ms
);
317 ret
= wait_for_completion_interruptible_timeout(comp
, timeout
);
320 } else if (ret
== 0) {
321 dev_err(dev
, "Wait for completion timed out.\n");
327 static int mxt_bootloader_read(struct mxt_data
*data
,
328 u8
*val
, unsigned int count
)
333 msg
.addr
= data
->bootloader_addr
;
334 msg
.flags
= data
->client
->flags
& I2C_M_TEN
;
335 msg
.flags
|= I2C_M_RD
;
339 ret
= i2c_transfer(data
->client
->adapter
, &msg
, 1);
343 ret
= ret
< 0 ? ret
: -EIO
;
344 dev_err(&data
->client
->dev
, "%s: i2c recv failed (%d)\n",
351 static int mxt_bootloader_write(struct mxt_data
*data
,
352 const u8
* const val
, unsigned int count
)
357 msg
.addr
= data
->bootloader_addr
;
358 msg
.flags
= data
->client
->flags
& I2C_M_TEN
;
362 ret
= i2c_transfer(data
->client
->adapter
, &msg
, 1);
366 ret
= ret
< 0 ? ret
: -EIO
;
367 dev_err(&data
->client
->dev
, "%s: i2c send failed (%d)\n",
374 static int mxt_lookup_bootloader_address(struct mxt_data
*data
, bool retry
)
376 u8 appmode
= data
->client
->addr
;
382 /* Chips after 1664S use different scheme */
383 if (retry
|| data
->info
.family_id
>= 0xa2) {
384 bootloader
= appmode
- 0x24;
387 /* Fall through for normal case */
392 bootloader
= appmode
- 0x26;
396 dev_err(&data
->client
->dev
,
397 "Appmode i2c address 0x%02x not found\n",
402 data
->bootloader_addr
= bootloader
;
406 static int mxt_probe_bootloader(struct mxt_data
*data
, bool alt_address
)
408 struct device
*dev
= &data
->client
->dev
;
413 error
= mxt_lookup_bootloader_address(data
, alt_address
);
417 error
= mxt_bootloader_read(data
, &val
, 1);
421 /* Check app crc fail mode */
422 crc_failure
= (val
& ~MXT_BOOT_STATUS_MASK
) == MXT_APP_CRC_FAIL
;
424 dev_err(dev
, "Detected bootloader, status:%02X%s\n",
425 val
, crc_failure
? ", APP_CRC_FAIL" : "");
430 static u8
mxt_get_bootloader_version(struct mxt_data
*data
, u8 val
)
432 struct device
*dev
= &data
->client
->dev
;
435 if (val
& MXT_BOOT_EXTENDED_ID
) {
436 if (mxt_bootloader_read(data
, &buf
[0], 3) != 0) {
437 dev_err(dev
, "%s: i2c failure\n", __func__
);
441 dev_dbg(dev
, "Bootloader ID:%d Version:%d\n", buf
[1], buf
[2]);
445 dev_dbg(dev
, "Bootloader ID:%d\n", val
& MXT_BOOT_ID_MASK
);
451 static int mxt_check_bootloader(struct mxt_data
*data
, unsigned int state
,
454 struct device
*dev
= &data
->client
->dev
;
461 * In application update mode, the interrupt
462 * line signals state transitions. We must wait for the
463 * CHG assertion before reading the status byte.
464 * Once the status byte has been read, the line is deasserted.
466 ret
= mxt_wait_for_completion(data
, &data
->bl_completion
,
470 * TODO: handle -ERESTARTSYS better by terminating
471 * fw update process before returning to userspace
472 * by writing length 0x000 to device (iff we are in
473 * WAITING_FRAME_DATA state).
475 dev_err(dev
, "Update wait error %d\n", ret
);
480 ret
= mxt_bootloader_read(data
, &val
, 1);
484 if (state
== MXT_WAITING_BOOTLOAD_CMD
)
485 val
= mxt_get_bootloader_version(data
, val
);
488 case MXT_WAITING_BOOTLOAD_CMD
:
489 case MXT_WAITING_FRAME_DATA
:
490 case MXT_APP_CRC_FAIL
:
491 val
&= ~MXT_BOOT_STATUS_MASK
;
493 case MXT_FRAME_CRC_PASS
:
494 if (val
== MXT_FRAME_CRC_CHECK
) {
496 } else if (val
== MXT_FRAME_CRC_FAIL
) {
497 dev_err(dev
, "Bootloader CRC fail\n");
506 dev_err(dev
, "Invalid bootloader state %02X != %02X\n",
514 static int mxt_send_bootloader_cmd(struct mxt_data
*data
, bool unlock
)
520 buf
[0] = MXT_UNLOCK_CMD_LSB
;
521 buf
[1] = MXT_UNLOCK_CMD_MSB
;
527 ret
= mxt_bootloader_write(data
, buf
, 2);
534 static int __mxt_read_reg(struct i2c_client
*client
,
535 u16 reg
, u16 len
, void *val
)
537 struct i2c_msg xfer
[2];
542 buf
[1] = (reg
>> 8) & 0xff;
545 xfer
[0].addr
= client
->addr
;
551 xfer
[1].addr
= client
->addr
;
552 xfer
[1].flags
= I2C_M_RD
;
556 ret
= i2c_transfer(client
->adapter
, xfer
, 2);
562 dev_err(&client
->dev
, "%s: i2c transfer failed (%d)\n",
569 static int __mxt_write_reg(struct i2c_client
*client
, u16 reg
, u16 len
,
577 buf
= kmalloc(count
, GFP_KERNEL
);
582 buf
[1] = (reg
>> 8) & 0xff;
583 memcpy(&buf
[2], val
, len
);
585 ret
= i2c_master_send(client
, buf
, count
);
591 dev_err(&client
->dev
, "%s: i2c send failed (%d)\n",
599 static int mxt_write_reg(struct i2c_client
*client
, u16 reg
, u8 val
)
601 return __mxt_write_reg(client
, reg
, 1, &val
);
604 static struct mxt_object
*
605 mxt_get_object(struct mxt_data
*data
, u8 type
)
607 struct mxt_object
*object
;
610 for (i
= 0; i
< data
->info
.object_num
; i
++) {
611 object
= data
->object_table
+ i
;
612 if (object
->type
== type
)
616 dev_warn(&data
->client
->dev
, "Invalid object type T%u\n", type
);
620 static void mxt_proc_t6_messages(struct mxt_data
*data
, u8
*msg
)
622 struct device
*dev
= &data
->client
->dev
;
624 u32 crc
= msg
[2] | (msg
[3] << 8) | (msg
[4] << 16);
626 complete(&data
->crc_completion
);
628 if (crc
!= data
->config_crc
) {
629 data
->config_crc
= crc
;
630 dev_dbg(dev
, "T6 Config Checksum: 0x%06X\n", crc
);
634 if (status
& MXT_T6_STATUS_RESET
)
635 complete(&data
->reset_completion
);
637 /* Output debug if status has changed */
638 if (status
!= data
->t6_status
)
639 dev_dbg(dev
, "T6 Status 0x%02X%s%s%s%s%s%s%s\n",
641 status
== 0 ? " OK" : "",
642 status
& MXT_T6_STATUS_RESET
? " RESET" : "",
643 status
& MXT_T6_STATUS_OFL
? " OFL" : "",
644 status
& MXT_T6_STATUS_SIGERR
? " SIGERR" : "",
645 status
& MXT_T6_STATUS_CAL
? " CAL" : "",
646 status
& MXT_T6_STATUS_CFGERR
? " CFGERR" : "",
647 status
& MXT_T6_STATUS_COMSERR
? " COMSERR" : "");
649 /* Save current status */
650 data
->t6_status
= status
;
653 static int mxt_write_object(struct mxt_data
*data
,
654 u8 type
, u8 offset
, u8 val
)
656 struct mxt_object
*object
;
659 object
= mxt_get_object(data
, type
);
660 if (!object
|| offset
>= mxt_obj_size(object
))
663 reg
= object
->start_address
;
664 return mxt_write_reg(data
->client
, reg
+ offset
, val
);
667 static void mxt_input_button(struct mxt_data
*data
, u8
*message
)
669 struct input_dev
*input
= data
->input_dev
;
670 const struct mxt_platform_data
*pdata
= data
->pdata
;
673 for (i
= 0; i
< pdata
->t19_num_keys
; i
++) {
674 if (pdata
->t19_keymap
[i
] == KEY_RESERVED
)
677 /* Active-low switch */
678 input_report_key(input
, pdata
->t19_keymap
[i
],
679 !(message
[1] & BIT(i
)));
683 static void mxt_input_sync(struct mxt_data
*data
)
685 input_mt_report_pointer_emulation(data
->input_dev
,
686 data
->pdata
->t19_num_keys
);
687 input_sync(data
->input_dev
);
690 static void mxt_proc_t9_message(struct mxt_data
*data
, u8
*message
)
692 struct device
*dev
= &data
->client
->dev
;
693 struct input_dev
*input_dev
= data
->input_dev
;
701 id
= message
[0] - data
->T9_reportid_min
;
703 x
= (message
[2] << 4) | ((message
[4] >> 4) & 0xf);
704 y
= (message
[3] << 4) | ((message
[4] & 0xf));
706 /* Handle 10/12 bit switching */
707 if (data
->max_x
< 1024)
709 if (data
->max_y
< 1024)
713 amplitude
= message
[6];
716 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
718 (status
& MXT_T9_DETECT
) ? 'D' : '.',
719 (status
& MXT_T9_PRESS
) ? 'P' : '.',
720 (status
& MXT_T9_RELEASE
) ? 'R' : '.',
721 (status
& MXT_T9_MOVE
) ? 'M' : '.',
722 (status
& MXT_T9_VECTOR
) ? 'V' : '.',
723 (status
& MXT_T9_AMP
) ? 'A' : '.',
724 (status
& MXT_T9_SUPPRESS
) ? 'S' : '.',
725 (status
& MXT_T9_UNGRIP
) ? 'U' : '.',
726 x
, y
, area
, amplitude
);
728 input_mt_slot(input_dev
, id
);
730 if (status
& MXT_T9_DETECT
) {
732 * Multiple bits may be set if the host is slow to read
733 * the status messages, indicating all the events that
736 if (status
& MXT_T9_RELEASE
) {
737 input_mt_report_slot_state(input_dev
,
739 mxt_input_sync(data
);
743 input_mt_report_slot_state(input_dev
, MT_TOOL_FINGER
, 1);
744 input_report_abs(input_dev
, ABS_MT_POSITION_X
, x
);
745 input_report_abs(input_dev
, ABS_MT_POSITION_Y
, y
);
746 input_report_abs(input_dev
, ABS_MT_PRESSURE
, amplitude
);
747 input_report_abs(input_dev
, ABS_MT_TOUCH_MAJOR
, area
);
749 /* Touch no longer active, close out slot */
750 input_mt_report_slot_state(input_dev
, MT_TOOL_FINGER
, 0);
753 data
->update_input
= true;
756 static void mxt_proc_t100_message(struct mxt_data
*data
, u8
*message
)
758 struct device
*dev
= &data
->client
->dev
;
759 struct input_dev
*input_dev
= data
->input_dev
;
771 id
= message
[0] - data
->T100_reportid_min
- 2;
773 /* ignore SCRSTATUS events */
778 x
= get_unaligned_le16(&message
[2]);
779 y
= get_unaligned_le16(&message
[4]);
781 if (status
& MXT_T100_DETECT
) {
782 type
= (status
& MXT_T100_TYPE_MASK
) >> 4;
785 case MXT_T100_TYPE_HOVERING_FINGER
:
786 tool
= MT_TOOL_FINGER
;
787 distance
= MXT_DISTANCE_HOVERING
;
789 if (data
->t100_aux_vect
)
790 orientation
= message
[data
->t100_aux_vect
];
794 case MXT_T100_TYPE_FINGER
:
795 case MXT_T100_TYPE_GLOVE
:
796 tool
= MT_TOOL_FINGER
;
797 distance
= MXT_DISTANCE_ACTIVE_TOUCH
;
799 if (data
->t100_aux_area
)
800 major
= message
[data
->t100_aux_area
];
802 if (data
->t100_aux_ampl
)
803 pressure
= message
[data
->t100_aux_ampl
];
805 if (data
->t100_aux_vect
)
806 orientation
= message
[data
->t100_aux_vect
];
810 case MXT_T100_TYPE_PASSIVE_STYLUS
:
814 * Passive stylus is reported with size zero so
817 major
= MXT_TOUCH_MAJOR_DEFAULT
;
819 if (data
->t100_aux_ampl
)
820 pressure
= message
[data
->t100_aux_ampl
];
824 case MXT_T100_TYPE_LARGE_TOUCH
:
825 /* Ignore suppressed touch */
829 dev_dbg(dev
, "Unexpected T100 type\n");
835 * Values reported should be non-zero if tool is touching the
838 if (!pressure
&& type
!= MXT_T100_TYPE_HOVERING_FINGER
)
839 pressure
= MXT_PRESSURE_DEFAULT
;
841 input_mt_slot(input_dev
, id
);
843 if (status
& MXT_T100_DETECT
) {
844 dev_dbg(dev
, "[%u] type:%u x:%u y:%u a:%02X p:%02X v:%02X\n",
845 id
, type
, x
, y
, major
, pressure
, orientation
);
847 input_mt_report_slot_state(input_dev
, tool
, 1);
848 input_report_abs(input_dev
, ABS_MT_POSITION_X
, x
);
849 input_report_abs(input_dev
, ABS_MT_POSITION_Y
, y
);
850 input_report_abs(input_dev
, ABS_MT_TOUCH_MAJOR
, major
);
851 input_report_abs(input_dev
, ABS_MT_PRESSURE
, pressure
);
852 input_report_abs(input_dev
, ABS_MT_DISTANCE
, distance
);
853 input_report_abs(input_dev
, ABS_MT_ORIENTATION
, orientation
);
855 dev_dbg(dev
, "[%u] release\n", id
);
858 input_mt_report_slot_state(input_dev
, 0, 0);
861 data
->update_input
= true;
864 static int mxt_proc_message(struct mxt_data
*data
, u8
*message
)
866 u8 report_id
= message
[0];
868 if (report_id
== MXT_RPTID_NOMSG
)
871 if (report_id
== data
->T6_reportid
) {
872 mxt_proc_t6_messages(data
, message
);
873 } else if (!data
->input_dev
) {
875 * Do not report events if input device
876 * is not yet registered.
878 mxt_dump_message(data
, message
);
879 } else if (report_id
>= data
->T9_reportid_min
&&
880 report_id
<= data
->T9_reportid_max
) {
881 mxt_proc_t9_message(data
, message
);
882 } else if (report_id
>= data
->T100_reportid_min
&&
883 report_id
<= data
->T100_reportid_max
) {
884 mxt_proc_t100_message(data
, message
);
885 } else if (report_id
== data
->T19_reportid
) {
886 mxt_input_button(data
, message
);
887 data
->update_input
= true;
889 mxt_dump_message(data
, message
);
895 static int mxt_read_and_process_messages(struct mxt_data
*data
, u8 count
)
897 struct device
*dev
= &data
->client
->dev
;
902 /* Safety check for msg_buf */
903 if (count
> data
->max_reportid
)
906 /* Process remaining messages if necessary */
907 ret
= __mxt_read_reg(data
->client
, data
->T5_address
,
908 data
->T5_msg_size
* count
, data
->msg_buf
);
910 dev_err(dev
, "Failed to read %u messages (%d)\n", count
, ret
);
914 for (i
= 0; i
< count
; i
++) {
915 ret
= mxt_proc_message(data
,
916 data
->msg_buf
+ data
->T5_msg_size
* i
);
922 /* return number of messages read */
926 static irqreturn_t
mxt_process_messages_t44(struct mxt_data
*data
)
928 struct device
*dev
= &data
->client
->dev
;
932 /* Read T44 and T5 together */
933 ret
= __mxt_read_reg(data
->client
, data
->T44_address
,
934 data
->T5_msg_size
+ 1, data
->msg_buf
);
936 dev_err(dev
, "Failed to read T44 and T5 (%d)\n", ret
);
940 count
= data
->msg_buf
[0];
943 * This condition may be caused by the CHG line being configured in
944 * Mode 0. It results in unnecessary I2C operations but it is benign.
949 if (count
> data
->max_reportid
) {
950 dev_warn(dev
, "T44 count %d exceeded max report id\n", count
);
951 count
= data
->max_reportid
;
954 /* Process first message */
955 ret
= mxt_proc_message(data
, data
->msg_buf
+ 1);
957 dev_warn(dev
, "Unexpected invalid message\n");
961 num_left
= count
- 1;
963 /* Process remaining messages if necessary */
965 ret
= mxt_read_and_process_messages(data
, num_left
);
968 else if (ret
!= num_left
)
969 dev_warn(dev
, "Unexpected invalid message\n");
973 if (data
->update_input
) {
974 mxt_input_sync(data
);
975 data
->update_input
= false;
981 static int mxt_process_messages_until_invalid(struct mxt_data
*data
)
983 struct device
*dev
= &data
->client
->dev
;
987 count
= data
->max_reportid
;
989 /* Read messages until we force an invalid */
991 read
= mxt_read_and_process_messages(data
, count
);
996 if (data
->update_input
) {
997 mxt_input_sync(data
);
998 data
->update_input
= false;
1001 dev_err(dev
, "CHG pin isn't cleared\n");
1005 static irqreturn_t
mxt_process_messages(struct mxt_data
*data
)
1007 int total_handled
, num_handled
;
1008 u8 count
= data
->last_message_count
;
1010 if (count
< 1 || count
> data
->max_reportid
)
1013 /* include final invalid message */
1014 total_handled
= mxt_read_and_process_messages(data
, count
+ 1);
1015 if (total_handled
< 0)
1017 /* if there were invalid messages, then we are done */
1018 else if (total_handled
<= count
)
1021 /* keep reading two msgs until one is invalid or reportid limit */
1023 num_handled
= mxt_read_and_process_messages(data
, 2);
1024 if (num_handled
< 0)
1027 total_handled
+= num_handled
;
1029 if (num_handled
< 2)
1031 } while (total_handled
< data
->num_touchids
);
1034 data
->last_message_count
= total_handled
;
1036 if (data
->update_input
) {
1037 mxt_input_sync(data
);
1038 data
->update_input
= false;
1044 static irqreturn_t
mxt_interrupt(int irq
, void *dev_id
)
1046 struct mxt_data
*data
= dev_id
;
1048 if (data
->in_bootloader
) {
1049 /* bootloader state transition completion */
1050 complete(&data
->bl_completion
);
1054 if (!data
->object_table
)
1057 if (data
->T44_address
) {
1058 return mxt_process_messages_t44(data
);
1060 return mxt_process_messages(data
);
1064 static int mxt_t6_command(struct mxt_data
*data
, u16 cmd_offset
,
1065 u8 value
, bool wait
)
1068 u8 command_register
;
1069 int timeout_counter
= 0;
1072 reg
= data
->T6_address
+ cmd_offset
;
1074 ret
= mxt_write_reg(data
->client
, reg
, value
);
1083 ret
= __mxt_read_reg(data
->client
, reg
, 1, &command_register
);
1086 } while (command_register
!= 0 && timeout_counter
++ <= 100);
1088 if (timeout_counter
> 100) {
1089 dev_err(&data
->client
->dev
, "Command failed!\n");
1096 static int mxt_acquire_irq(struct mxt_data
*data
)
1100 enable_irq(data
->irq
);
1102 error
= mxt_process_messages_until_invalid(data
);
1109 static int mxt_soft_reset(struct mxt_data
*data
)
1111 struct device
*dev
= &data
->client
->dev
;
1114 dev_info(dev
, "Resetting device\n");
1116 disable_irq(data
->irq
);
1118 reinit_completion(&data
->reset_completion
);
1120 ret
= mxt_t6_command(data
, MXT_COMMAND_RESET
, MXT_RESET_VALUE
, false);
1124 /* Ignore CHG line for 100ms after reset */
1127 mxt_acquire_irq(data
);
1129 ret
= mxt_wait_for_completion(data
, &data
->reset_completion
,
1137 static void mxt_update_crc(struct mxt_data
*data
, u8 cmd
, u8 value
)
1140 * On failure, CRC is set to 0 and config will always be
1143 data
->config_crc
= 0;
1144 reinit_completion(&data
->crc_completion
);
1146 mxt_t6_command(data
, cmd
, value
, true);
1149 * Wait for crc message. On failure, CRC is set to 0 and config will
1150 * always be downloaded.
1152 mxt_wait_for_completion(data
, &data
->crc_completion
, MXT_CRC_TIMEOUT
);
1155 static void mxt_calc_crc24(u32
*crc
, u8 firstbyte
, u8 secondbyte
)
1157 static const unsigned int crcpoly
= 0x80001B;
1161 data_word
= (secondbyte
<< 8) | firstbyte
;
1162 result
= ((*crc
<< 1) ^ data_word
);
1164 if (result
& 0x1000000)
1170 static u32
mxt_calculate_crc(u8
*base
, off_t start_off
, off_t end_off
)
1173 u8
*ptr
= base
+ start_off
;
1174 u8
*last_val
= base
+ end_off
- 1;
1176 if (end_off
< start_off
)
1179 while (ptr
< last_val
) {
1180 mxt_calc_crc24(&crc
, *ptr
, *(ptr
+ 1));
1184 /* if len is odd, fill the last byte with 0 */
1185 if (ptr
== last_val
)
1186 mxt_calc_crc24(&crc
, *ptr
, 0);
1188 /* Mask to 24-bit */
1194 static int mxt_prepare_cfg_mem(struct mxt_data
*data
,
1195 const struct firmware
*cfg
,
1196 unsigned int data_pos
,
1197 unsigned int cfg_start_ofs
,
1199 size_t config_mem_size
)
1201 struct device
*dev
= &data
->client
->dev
;
1202 struct mxt_object
*object
;
1203 unsigned int type
, instance
, size
, byte_offset
;
1210 while (data_pos
< cfg
->size
) {
1211 /* Read type, instance, length */
1212 ret
= sscanf(cfg
->data
+ data_pos
, "%x %x %x%n",
1213 &type
, &instance
, &size
, &offset
);
1217 } else if (ret
!= 3) {
1218 dev_err(dev
, "Bad format: failed to parse object\n");
1223 object
= mxt_get_object(data
, type
);
1226 for (i
= 0; i
< size
; i
++) {
1227 ret
= sscanf(cfg
->data
+ data_pos
, "%hhx%n",
1230 dev_err(dev
, "Bad format in T%d at %d\n",
1239 if (size
> mxt_obj_size(object
)) {
1241 * Either we are in fallback mode due to wrong
1242 * config or config from a later fw version,
1243 * or the file is corrupt or hand-edited.
1245 dev_warn(dev
, "Discarding %zu byte(s) in T%u\n",
1246 size
- mxt_obj_size(object
), type
);
1247 } else if (mxt_obj_size(object
) > size
) {
1249 * If firmware is upgraded, new bytes may be added to
1250 * end of objects. It is generally forward compatible
1251 * to zero these bytes - previous behaviour will be
1252 * retained. However this does invalidate the CRC and
1253 * will force fallback mode until the configuration is
1254 * updated. We warn here but do nothing else - the
1255 * malloc has zeroed the entire configuration.
1257 dev_warn(dev
, "Zeroing %zu byte(s) in T%d\n",
1258 mxt_obj_size(object
) - size
, type
);
1261 if (instance
>= mxt_obj_instances(object
)) {
1262 dev_err(dev
, "Object instances exceeded!\n");
1266 reg
= object
->start_address
+ mxt_obj_size(object
) * instance
;
1268 for (i
= 0; i
< size
; i
++) {
1269 ret
= sscanf(cfg
->data
+ data_pos
, "%hhx%n",
1273 dev_err(dev
, "Bad format in T%d at %d\n",
1279 if (i
> mxt_obj_size(object
))
1282 byte_offset
= reg
+ i
- cfg_start_ofs
;
1284 if (byte_offset
>= 0 && byte_offset
< config_mem_size
) {
1285 *(config_mem
+ byte_offset
) = val
;
1287 dev_err(dev
, "Bad object: reg:%d, T%d, ofs=%d\n",
1288 reg
, object
->type
, byte_offset
);
1297 static int mxt_upload_cfg_mem(struct mxt_data
*data
, unsigned int cfg_start
,
1298 u8
*config_mem
, size_t config_mem_size
)
1300 unsigned int byte_offset
= 0;
1303 /* Write configuration as blocks */
1304 while (byte_offset
< config_mem_size
) {
1305 unsigned int size
= config_mem_size
- byte_offset
;
1307 if (size
> MXT_MAX_BLOCK_WRITE
)
1308 size
= MXT_MAX_BLOCK_WRITE
;
1310 error
= __mxt_write_reg(data
->client
,
1311 cfg_start
+ byte_offset
,
1312 size
, config_mem
+ byte_offset
);
1314 dev_err(&data
->client
->dev
,
1315 "Config write error, ret=%d\n", error
);
1319 byte_offset
+= size
;
1325 static int mxt_init_t7_power_cfg(struct mxt_data
*data
);
1328 * mxt_update_cfg - download configuration to chip
1330 * Atmel Raw Config File Format
1332 * The first four lines of the raw config file contain:
1334 * 2) Chip ID Information (first 7 bytes of device memory)
1335 * 3) Chip Information Block 24-bit CRC Checksum
1336 * 4) Chip Configuration 24-bit CRC Checksum
1338 * The rest of the file consists of one line per object instance:
1339 * <TYPE> <INSTANCE> <SIZE> <CONTENTS>
1341 * <TYPE> - 2-byte object type as hex
1342 * <INSTANCE> - 2-byte object instance number as hex
1343 * <SIZE> - 2-byte object size as hex
1344 * <CONTENTS> - array of <SIZE> 1-byte hex values
1346 static int mxt_update_cfg(struct mxt_data
*data
, const struct firmware
*cfg
)
1348 struct device
*dev
= &data
->client
->dev
;
1349 struct mxt_info cfg_info
;
1355 u32 info_crc
, config_crc
, calculated_crc
;
1357 size_t config_mem_size
;
1359 mxt_update_crc(data
, MXT_COMMAND_REPORTALL
, 1);
1361 if (strncmp(cfg
->data
, MXT_CFG_MAGIC
, strlen(MXT_CFG_MAGIC
))) {
1362 dev_err(dev
, "Unrecognised config file\n");
1366 data_pos
= strlen(MXT_CFG_MAGIC
);
1368 /* Load information block and check */
1369 for (i
= 0; i
< sizeof(struct mxt_info
); i
++) {
1370 ret
= sscanf(cfg
->data
+ data_pos
, "%hhx%n",
1371 (unsigned char *)&cfg_info
+ i
,
1374 dev_err(dev
, "Bad format\n");
1381 if (cfg_info
.family_id
!= data
->info
.family_id
) {
1382 dev_err(dev
, "Family ID mismatch!\n");
1386 if (cfg_info
.variant_id
!= data
->info
.variant_id
) {
1387 dev_err(dev
, "Variant ID mismatch!\n");
1392 ret
= sscanf(cfg
->data
+ data_pos
, "%x%n", &info_crc
, &offset
);
1394 dev_err(dev
, "Bad format: failed to parse Info CRC\n");
1399 ret
= sscanf(cfg
->data
+ data_pos
, "%x%n", &config_crc
, &offset
);
1401 dev_err(dev
, "Bad format: failed to parse Config CRC\n");
1407 * The Info Block CRC is calculated over mxt_info and the object
1408 * table. If it does not match then we are trying to load the
1409 * configuration from a different chip or firmware version, so
1410 * the configuration CRC is invalid anyway.
1412 if (info_crc
== data
->info_crc
) {
1413 if (config_crc
== 0 || data
->config_crc
== 0) {
1414 dev_info(dev
, "CRC zero, attempting to apply config\n");
1415 } else if (config_crc
== data
->config_crc
) {
1416 dev_dbg(dev
, "Config CRC 0x%06X: OK\n",
1420 dev_info(dev
, "Config CRC 0x%06X: does not match file 0x%06X\n",
1421 data
->config_crc
, config_crc
);
1425 "Warning: Info CRC error - device=0x%06X file=0x%06X\n",
1426 data
->info_crc
, info_crc
);
1429 /* Malloc memory to store configuration */
1430 cfg_start_ofs
= MXT_OBJECT_START
+
1431 data
->info
.object_num
* sizeof(struct mxt_object
) +
1432 MXT_INFO_CHECKSUM_SIZE
;
1433 config_mem_size
= data
->mem_size
- cfg_start_ofs
;
1434 config_mem
= kzalloc(config_mem_size
, GFP_KERNEL
);
1436 dev_err(dev
, "Failed to allocate memory\n");
1440 ret
= mxt_prepare_cfg_mem(data
, cfg
, data_pos
, cfg_start_ofs
,
1441 config_mem
, config_mem_size
);
1445 /* Calculate crc of the received configs (not the raw config file) */
1446 if (data
->T7_address
< cfg_start_ofs
) {
1447 dev_err(dev
, "Bad T7 address, T7addr = %x, config offset %x\n",
1448 data
->T7_address
, cfg_start_ofs
);
1453 calculated_crc
= mxt_calculate_crc(config_mem
,
1454 data
->T7_address
- cfg_start_ofs
,
1457 if (config_crc
> 0 && config_crc
!= calculated_crc
)
1458 dev_warn(dev
, "Config CRC error, calculated=%06X, file=%06X\n",
1459 calculated_crc
, config_crc
);
1461 ret
= mxt_upload_cfg_mem(data
, cfg_start_ofs
,
1462 config_mem
, config_mem_size
);
1466 mxt_update_crc(data
, MXT_COMMAND_BACKUPNV
, MXT_BACKUP_VALUE
);
1468 ret
= mxt_soft_reset(data
);
1472 dev_info(dev
, "Config successfully updated\n");
1474 /* T7 config may have changed */
1475 mxt_init_t7_power_cfg(data
);
1482 static int mxt_get_info(struct mxt_data
*data
)
1484 struct i2c_client
*client
= data
->client
;
1485 struct mxt_info
*info
= &data
->info
;
1488 /* Read 7-byte info block starting at address 0 */
1489 error
= __mxt_read_reg(client
, 0, sizeof(*info
), info
);
1496 static void mxt_free_input_device(struct mxt_data
*data
)
1498 if (data
->input_dev
) {
1499 input_unregister_device(data
->input_dev
);
1500 data
->input_dev
= NULL
;
1504 static void mxt_free_object_table(struct mxt_data
*data
)
1506 kfree(data
->object_table
);
1507 data
->object_table
= NULL
;
1508 kfree(data
->msg_buf
);
1509 data
->msg_buf
= NULL
;
1510 data
->T5_address
= 0;
1511 data
->T5_msg_size
= 0;
1512 data
->T6_reportid
= 0;
1513 data
->T7_address
= 0;
1514 data
->T9_reportid_min
= 0;
1515 data
->T9_reportid_max
= 0;
1516 data
->T19_reportid
= 0;
1517 data
->T44_address
= 0;
1518 data
->T100_reportid_min
= 0;
1519 data
->T100_reportid_max
= 0;
1520 data
->max_reportid
= 0;
1523 static int mxt_get_object_table(struct mxt_data
*data
)
1525 struct i2c_client
*client
= data
->client
;
1527 struct mxt_object
*object_table
;
1533 table_size
= data
->info
.object_num
* sizeof(struct mxt_object
);
1534 object_table
= kzalloc(table_size
, GFP_KERNEL
);
1535 if (!object_table
) {
1536 dev_err(&data
->client
->dev
, "Failed to allocate memory\n");
1540 error
= __mxt_read_reg(client
, MXT_OBJECT_START
, table_size
,
1543 kfree(object_table
);
1547 /* Valid Report IDs start counting from 1 */
1550 for (i
= 0; i
< data
->info
.object_num
; i
++) {
1551 struct mxt_object
*object
= object_table
+ i
;
1554 le16_to_cpus(&object
->start_address
);
1556 if (object
->num_report_ids
) {
1558 reportid
+= object
->num_report_ids
*
1559 mxt_obj_instances(object
);
1560 max_id
= reportid
- 1;
1566 dev_dbg(&data
->client
->dev
,
1567 "T%u Start:%u Size:%zu Instances:%zu Report IDs:%u-%u\n",
1568 object
->type
, object
->start_address
,
1569 mxt_obj_size(object
), mxt_obj_instances(object
),
1572 switch (object
->type
) {
1573 case MXT_GEN_MESSAGE_T5
:
1574 if (data
->info
.family_id
== 0x80 &&
1575 data
->info
.version
< 0x20) {
1577 * On mXT224 firmware versions prior to V2.0
1578 * read and discard unused CRC byte otherwise
1579 * DMA reads are misaligned.
1581 data
->T5_msg_size
= mxt_obj_size(object
);
1583 /* CRC not enabled, so skip last byte */
1584 data
->T5_msg_size
= mxt_obj_size(object
) - 1;
1586 data
->T5_address
= object
->start_address
;
1588 case MXT_GEN_COMMAND_T6
:
1589 data
->T6_reportid
= min_id
;
1590 data
->T6_address
= object
->start_address
;
1592 case MXT_GEN_POWER_T7
:
1593 data
->T7_address
= object
->start_address
;
1595 case MXT_TOUCH_MULTI_T9
:
1596 data
->multitouch
= MXT_TOUCH_MULTI_T9
;
1597 data
->T9_reportid_min
= min_id
;
1598 data
->T9_reportid_max
= max_id
;
1599 data
->num_touchids
= object
->num_report_ids
1600 * mxt_obj_instances(object
);
1602 case MXT_SPT_MESSAGECOUNT_T44
:
1603 data
->T44_address
= object
->start_address
;
1605 case MXT_SPT_GPIOPWM_T19
:
1606 data
->T19_reportid
= min_id
;
1608 case MXT_TOUCH_MULTITOUCHSCREEN_T100
:
1609 data
->multitouch
= MXT_TOUCH_MULTITOUCHSCREEN_T100
;
1610 data
->T100_reportid_min
= min_id
;
1611 data
->T100_reportid_max
= max_id
;
1612 /* first two report IDs reserved */
1613 data
->num_touchids
= object
->num_report_ids
- 2;
1617 end_address
= object
->start_address
1618 + mxt_obj_size(object
) * mxt_obj_instances(object
) - 1;
1620 if (end_address
>= data
->mem_size
)
1621 data
->mem_size
= end_address
+ 1;
1624 /* Store maximum reportid */
1625 data
->max_reportid
= reportid
;
1627 /* If T44 exists, T5 position has to be directly after */
1628 if (data
->T44_address
&& (data
->T5_address
!= data
->T44_address
+ 1)) {
1629 dev_err(&client
->dev
, "Invalid T44 position\n");
1631 goto free_object_table
;
1634 data
->msg_buf
= kcalloc(data
->max_reportid
,
1635 data
->T5_msg_size
, GFP_KERNEL
);
1636 if (!data
->msg_buf
) {
1637 dev_err(&client
->dev
, "Failed to allocate message buffer\n");
1639 goto free_object_table
;
1642 data
->object_table
= object_table
;
1647 mxt_free_object_table(data
);
1651 static int mxt_read_t9_resolution(struct mxt_data
*data
)
1653 struct i2c_client
*client
= data
->client
;
1655 struct t9_range range
;
1656 unsigned char orient
;
1657 struct mxt_object
*object
;
1659 object
= mxt_get_object(data
, MXT_TOUCH_MULTI_T9
);
1663 error
= __mxt_read_reg(client
,
1664 object
->start_address
+ MXT_T9_RANGE
,
1665 sizeof(range
), &range
);
1669 data
->max_x
= get_unaligned_le16(&range
.x
);
1670 data
->max_y
= get_unaligned_le16(&range
.y
);
1672 error
= __mxt_read_reg(client
,
1673 object
->start_address
+ MXT_T9_ORIENT
,
1678 data
->xy_switch
= orient
& MXT_T9_ORIENT_SWITCH
;
1683 static int mxt_read_t100_config(struct mxt_data
*data
)
1685 struct i2c_client
*client
= data
->client
;
1687 struct mxt_object
*object
;
1688 u16 range_x
, range_y
;
1692 object
= mxt_get_object(data
, MXT_TOUCH_MULTITOUCHSCREEN_T100
);
1696 /* read touchscreen dimensions */
1697 error
= __mxt_read_reg(client
,
1698 object
->start_address
+ MXT_T100_XRANGE
,
1699 sizeof(range_x
), &range_x
);
1703 data
->max_x
= get_unaligned_le16(&range_x
);
1705 error
= __mxt_read_reg(client
,
1706 object
->start_address
+ MXT_T100_YRANGE
,
1707 sizeof(range_y
), &range_y
);
1711 data
->max_y
= get_unaligned_le16(&range_y
);
1713 /* read orientation config */
1714 error
= __mxt_read_reg(client
,
1715 object
->start_address
+ MXT_T100_CFG1
,
1720 data
->xy_switch
= cfg
& MXT_T100_CFG_SWITCHXY
;
1722 /* allocate aux bytes */
1723 error
= __mxt_read_reg(client
,
1724 object
->start_address
+ MXT_T100_TCHAUX
,
1731 if (tchaux
& MXT_T100_TCHAUX_VECT
)
1732 data
->t100_aux_vect
= aux
++;
1734 if (tchaux
& MXT_T100_TCHAUX_AMPL
)
1735 data
->t100_aux_ampl
= aux
++;
1737 if (tchaux
& MXT_T100_TCHAUX_AREA
)
1738 data
->t100_aux_area
= aux
++;
1740 dev_dbg(&client
->dev
,
1741 "T100 aux mappings vect:%u ampl:%u area:%u\n",
1742 data
->t100_aux_vect
, data
->t100_aux_ampl
, data
->t100_aux_area
);
1747 static int mxt_input_open(struct input_dev
*dev
);
1748 static void mxt_input_close(struct input_dev
*dev
);
1750 static void mxt_set_up_as_touchpad(struct input_dev
*input_dev
,
1751 struct mxt_data
*data
)
1753 const struct mxt_platform_data
*pdata
= data
->pdata
;
1756 input_dev
->name
= "Atmel maXTouch Touchpad";
1758 __set_bit(INPUT_PROP_BUTTONPAD
, input_dev
->propbit
);
1760 input_abs_set_res(input_dev
, ABS_X
, MXT_PIXELS_PER_MM
);
1761 input_abs_set_res(input_dev
, ABS_Y
, MXT_PIXELS_PER_MM
);
1762 input_abs_set_res(input_dev
, ABS_MT_POSITION_X
,
1764 input_abs_set_res(input_dev
, ABS_MT_POSITION_Y
,
1767 for (i
= 0; i
< pdata
->t19_num_keys
; i
++)
1768 if (pdata
->t19_keymap
[i
] != KEY_RESERVED
)
1769 input_set_capability(input_dev
, EV_KEY
,
1770 pdata
->t19_keymap
[i
]);
1773 static int mxt_initialize_input_device(struct mxt_data
*data
)
1775 const struct mxt_platform_data
*pdata
= data
->pdata
;
1776 struct device
*dev
= &data
->client
->dev
;
1777 struct input_dev
*input_dev
;
1779 unsigned int num_mt_slots
;
1780 unsigned int mt_flags
= 0;
1782 switch (data
->multitouch
) {
1783 case MXT_TOUCH_MULTI_T9
:
1784 num_mt_slots
= data
->T9_reportid_max
- data
->T9_reportid_min
+ 1;
1785 error
= mxt_read_t9_resolution(data
);
1787 dev_warn(dev
, "Failed to initialize T9 resolution\n");
1790 case MXT_TOUCH_MULTITOUCHSCREEN_T100
:
1791 num_mt_slots
= data
->num_touchids
;
1792 error
= mxt_read_t100_config(data
);
1794 dev_warn(dev
, "Failed to read T100 config\n");
1798 dev_err(dev
, "Invalid multitouch object\n");
1802 /* Handle default values and orientation switch */
1803 if (data
->max_x
== 0)
1806 if (data
->max_y
== 0)
1809 if (data
->xy_switch
)
1810 swap(data
->max_x
, data
->max_y
);
1812 dev_info(dev
, "Touchscreen size X%uY%u\n", data
->max_x
, data
->max_y
);
1814 /* Register input device */
1815 input_dev
= input_allocate_device();
1817 dev_err(dev
, "Failed to allocate memory\n");
1821 input_dev
->name
= "Atmel maXTouch Touchscreen";
1822 input_dev
->phys
= data
->phys
;
1823 input_dev
->id
.bustype
= BUS_I2C
;
1824 input_dev
->dev
.parent
= dev
;
1825 input_dev
->open
= mxt_input_open
;
1826 input_dev
->close
= mxt_input_close
;
1828 input_set_capability(input_dev
, EV_KEY
, BTN_TOUCH
);
1830 /* For single touch */
1831 input_set_abs_params(input_dev
, ABS_X
, 0, data
->max_x
, 0, 0);
1832 input_set_abs_params(input_dev
, ABS_Y
, 0, data
->max_y
, 0, 0);
1834 if (data
->multitouch
== MXT_TOUCH_MULTI_T9
||
1835 (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1836 data
->t100_aux_ampl
)) {
1837 input_set_abs_params(input_dev
, ABS_PRESSURE
, 0, 255, 0, 0);
1840 /* If device has buttons we assume it is a touchpad */
1841 if (pdata
->t19_num_keys
) {
1842 mxt_set_up_as_touchpad(input_dev
, data
);
1843 mt_flags
|= INPUT_MT_POINTER
;
1845 mt_flags
|= INPUT_MT_DIRECT
;
1848 /* For multi touch */
1849 error
= input_mt_init_slots(input_dev
, num_mt_slots
, mt_flags
);
1851 dev_err(dev
, "Error %d initialising slots\n", error
);
1855 if (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
) {
1856 input_set_abs_params(input_dev
, ABS_MT_TOOL_TYPE
,
1857 0, MT_TOOL_MAX
, 0, 0);
1858 input_set_abs_params(input_dev
, ABS_MT_DISTANCE
,
1859 MXT_DISTANCE_ACTIVE_TOUCH
,
1860 MXT_DISTANCE_HOVERING
,
1864 input_set_abs_params(input_dev
, ABS_MT_POSITION_X
,
1865 0, data
->max_x
, 0, 0);
1866 input_set_abs_params(input_dev
, ABS_MT_POSITION_Y
,
1867 0, data
->max_y
, 0, 0);
1869 if (data
->multitouch
== MXT_TOUCH_MULTI_T9
||
1870 (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1871 data
->t100_aux_area
)) {
1872 input_set_abs_params(input_dev
, ABS_MT_TOUCH_MAJOR
,
1873 0, MXT_MAX_AREA
, 0, 0);
1876 if (data
->multitouch
== MXT_TOUCH_MULTI_T9
||
1877 (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1878 data
->t100_aux_ampl
)) {
1879 input_set_abs_params(input_dev
, ABS_MT_PRESSURE
,
1883 if (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1884 data
->t100_aux_vect
) {
1885 input_set_abs_params(input_dev
, ABS_MT_ORIENTATION
,
1889 if (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1890 data
->t100_aux_ampl
) {
1891 input_set_abs_params(input_dev
, ABS_MT_PRESSURE
,
1895 if (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1896 data
->t100_aux_vect
) {
1897 input_set_abs_params(input_dev
, ABS_MT_ORIENTATION
,
1901 input_set_drvdata(input_dev
, data
);
1903 error
= input_register_device(input_dev
);
1905 dev_err(dev
, "Error %d registering input device\n", error
);
1909 data
->input_dev
= input_dev
;
1914 input_free_device(input_dev
);
1918 static int mxt_configure_objects(struct mxt_data
*data
,
1919 const struct firmware
*cfg
);
1921 static void mxt_config_cb(const struct firmware
*cfg
, void *ctx
)
1923 mxt_configure_objects(ctx
, cfg
);
1924 release_firmware(cfg
);
1927 static int mxt_initialize(struct mxt_data
*data
)
1929 struct i2c_client
*client
= data
->client
;
1930 int recovery_attempts
= 0;
1934 error
= mxt_get_info(data
);
1938 /* Check bootloader state */
1939 error
= mxt_probe_bootloader(data
, false);
1941 dev_info(&client
->dev
, "Trying alternate bootloader address\n");
1942 error
= mxt_probe_bootloader(data
, true);
1944 /* Chip is not in appmode or bootloader mode */
1949 /* OK, we are in bootloader, see if we can recover */
1950 if (++recovery_attempts
> 1) {
1951 dev_err(&client
->dev
, "Could not recover from bootloader mode\n");
1953 * We can reflash from this state, so do not
1954 * abort initialization.
1956 data
->in_bootloader
= true;
1960 /* Attempt to exit bootloader into app mode */
1961 mxt_send_bootloader_cmd(data
, false);
1962 msleep(MXT_FW_RESET_TIME
);
1965 /* Get object table information */
1966 error
= mxt_get_object_table(data
);
1968 dev_err(&client
->dev
, "Error %d reading object table\n", error
);
1972 error
= mxt_acquire_irq(data
);
1974 goto err_free_object_table
;
1976 error
= request_firmware_nowait(THIS_MODULE
, true, MXT_CFG_NAME
,
1977 &client
->dev
, GFP_KERNEL
, data
,
1980 dev_err(&client
->dev
, "Failed to invoke firmware loader: %d\n",
1982 goto err_free_object_table
;
1987 err_free_object_table
:
1988 mxt_free_object_table(data
);
1992 static int mxt_set_t7_power_cfg(struct mxt_data
*data
, u8 sleep
)
1994 struct device
*dev
= &data
->client
->dev
;
1996 struct t7_config
*new_config
;
1997 struct t7_config deepsleep
= { .active
= 0, .idle
= 0 };
1999 if (sleep
== MXT_POWER_CFG_DEEPSLEEP
)
2000 new_config
= &deepsleep
;
2002 new_config
= &data
->t7_cfg
;
2004 error
= __mxt_write_reg(data
->client
, data
->T7_address
,
2005 sizeof(data
->t7_cfg
), new_config
);
2009 dev_dbg(dev
, "Set T7 ACTV:%d IDLE:%d\n",
2010 new_config
->active
, new_config
->idle
);
2015 static int mxt_init_t7_power_cfg(struct mxt_data
*data
)
2017 struct device
*dev
= &data
->client
->dev
;
2022 error
= __mxt_read_reg(data
->client
, data
->T7_address
,
2023 sizeof(data
->t7_cfg
), &data
->t7_cfg
);
2027 if (data
->t7_cfg
.active
== 0 || data
->t7_cfg
.idle
== 0) {
2029 dev_dbg(dev
, "T7 cfg zero, resetting\n");
2030 mxt_soft_reset(data
);
2034 dev_dbg(dev
, "T7 cfg zero after reset, overriding\n");
2035 data
->t7_cfg
.active
= 20;
2036 data
->t7_cfg
.idle
= 100;
2037 return mxt_set_t7_power_cfg(data
, MXT_POWER_CFG_RUN
);
2041 dev_dbg(dev
, "Initialized power cfg: ACTV %d, IDLE %d\n",
2042 data
->t7_cfg
.active
, data
->t7_cfg
.idle
);
2046 static int mxt_configure_objects(struct mxt_data
*data
,
2047 const struct firmware
*cfg
)
2049 struct device
*dev
= &data
->client
->dev
;
2050 struct mxt_info
*info
= &data
->info
;
2053 error
= mxt_init_t7_power_cfg(data
);
2055 dev_err(dev
, "Failed to initialize power cfg\n");
2060 error
= mxt_update_cfg(data
, cfg
);
2062 dev_warn(dev
, "Error %d updating config\n", error
);
2065 if (data
->multitouch
) {
2066 error
= mxt_initialize_input_device(data
);
2070 dev_warn(dev
, "No touch object detected\n");
2074 "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n",
2075 info
->family_id
, info
->variant_id
, info
->version
>> 4,
2076 info
->version
& 0xf, info
->build
, info
->object_num
);
2081 /* Firmware Version is returned as Major.Minor.Build */
2082 static ssize_t
mxt_fw_version_show(struct device
*dev
,
2083 struct device_attribute
*attr
, char *buf
)
2085 struct mxt_data
*data
= dev_get_drvdata(dev
);
2086 struct mxt_info
*info
= &data
->info
;
2087 return scnprintf(buf
, PAGE_SIZE
, "%u.%u.%02X\n",
2088 info
->version
>> 4, info
->version
& 0xf, info
->build
);
2091 /* Hardware Version is returned as FamilyID.VariantID */
2092 static ssize_t
mxt_hw_version_show(struct device
*dev
,
2093 struct device_attribute
*attr
, char *buf
)
2095 struct mxt_data
*data
= dev_get_drvdata(dev
);
2096 struct mxt_info
*info
= &data
->info
;
2097 return scnprintf(buf
, PAGE_SIZE
, "%u.%u\n",
2098 info
->family_id
, info
->variant_id
);
2101 static ssize_t
mxt_show_instance(char *buf
, int count
,
2102 struct mxt_object
*object
, int instance
,
2107 if (mxt_obj_instances(object
) > 1)
2108 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
2109 "Instance %u\n", instance
);
2111 for (i
= 0; i
< mxt_obj_size(object
); i
++)
2112 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
2113 "\t[%2u]: %02x (%d)\n", i
, val
[i
], val
[i
]);
2114 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
, "\n");
2119 static ssize_t
mxt_object_show(struct device
*dev
,
2120 struct device_attribute
*attr
, char *buf
)
2122 struct mxt_data
*data
= dev_get_drvdata(dev
);
2123 struct mxt_object
*object
;
2129 /* Pre-allocate buffer large enough to hold max sized object. */
2130 obuf
= kmalloc(256, GFP_KERNEL
);
2135 for (i
= 0; i
< data
->info
.object_num
; i
++) {
2136 object
= data
->object_table
+ i
;
2138 if (!mxt_object_readable(object
->type
))
2141 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
2142 "T%u:\n", object
->type
);
2144 for (j
= 0; j
< mxt_obj_instances(object
); j
++) {
2145 u16 size
= mxt_obj_size(object
);
2146 u16 addr
= object
->start_address
+ j
* size
;
2148 error
= __mxt_read_reg(data
->client
, addr
, size
, obuf
);
2152 count
= mxt_show_instance(buf
, count
, object
, j
, obuf
);
2158 return error
?: count
;
2161 static int mxt_check_firmware_format(struct device
*dev
,
2162 const struct firmware
*fw
)
2164 unsigned int pos
= 0;
2167 while (pos
< fw
->size
) {
2168 c
= *(fw
->data
+ pos
);
2170 if (c
< '0' || (c
> '9' && c
< 'A') || c
> 'F')
2177 * To convert file try:
2178 * xxd -r -p mXTXXX__APP_VX-X-XX.enc > maxtouch.fw
2180 dev_err(dev
, "Aborting: firmware file must be in binary format\n");
2185 static int mxt_load_fw(struct device
*dev
, const char *fn
)
2187 struct mxt_data
*data
= dev_get_drvdata(dev
);
2188 const struct firmware
*fw
= NULL
;
2189 unsigned int frame_size
;
2190 unsigned int pos
= 0;
2191 unsigned int retry
= 0;
2192 unsigned int frame
= 0;
2195 ret
= request_firmware(&fw
, fn
, dev
);
2197 dev_err(dev
, "Unable to open firmware %s\n", fn
);
2201 /* Check for incorrect enc file */
2202 ret
= mxt_check_firmware_format(dev
, fw
);
2204 goto release_firmware
;
2206 if (!data
->in_bootloader
) {
2207 /* Change to the bootloader mode */
2208 data
->in_bootloader
= true;
2210 ret
= mxt_t6_command(data
, MXT_COMMAND_RESET
,
2211 MXT_BOOT_VALUE
, false);
2213 goto release_firmware
;
2215 msleep(MXT_RESET_TIME
);
2217 /* Do not need to scan since we know family ID */
2218 ret
= mxt_lookup_bootloader_address(data
, 0);
2220 goto release_firmware
;
2222 mxt_free_input_device(data
);
2223 mxt_free_object_table(data
);
2225 enable_irq(data
->irq
);
2228 reinit_completion(&data
->bl_completion
);
2230 ret
= mxt_check_bootloader(data
, MXT_WAITING_BOOTLOAD_CMD
, false);
2232 /* Bootloader may still be unlocked from previous attempt */
2233 ret
= mxt_check_bootloader(data
, MXT_WAITING_FRAME_DATA
, false);
2237 dev_info(dev
, "Unlocking bootloader\n");
2239 /* Unlock bootloader */
2240 ret
= mxt_send_bootloader_cmd(data
, true);
2245 while (pos
< fw
->size
) {
2246 ret
= mxt_check_bootloader(data
, MXT_WAITING_FRAME_DATA
, true);
2250 frame_size
= ((*(fw
->data
+ pos
) << 8) | *(fw
->data
+ pos
+ 1));
2252 /* Take account of CRC bytes */
2255 /* Write one frame to device */
2256 ret
= mxt_bootloader_write(data
, fw
->data
+ pos
, frame_size
);
2260 ret
= mxt_check_bootloader(data
, MXT_FRAME_CRC_PASS
, true);
2264 /* Back off by 20ms per retry */
2268 dev_err(dev
, "Retry count exceeded\n");
2277 if (frame
% 50 == 0)
2278 dev_dbg(dev
, "Sent %d frames, %d/%zd bytes\n",
2279 frame
, pos
, fw
->size
);
2282 /* Wait for flash. */
2283 ret
= mxt_wait_for_completion(data
, &data
->bl_completion
,
2288 dev_dbg(dev
, "Sent %d frames, %d bytes\n", frame
, pos
);
2291 * Wait for device to reset. Some bootloader versions do not assert
2292 * the CHG line after bootloading has finished, so ignore potential
2295 mxt_wait_for_completion(data
, &data
->bl_completion
, MXT_FW_RESET_TIME
);
2297 data
->in_bootloader
= false;
2300 disable_irq(data
->irq
);
2302 release_firmware(fw
);
2306 static ssize_t
mxt_update_fw_store(struct device
*dev
,
2307 struct device_attribute
*attr
,
2308 const char *buf
, size_t count
)
2310 struct mxt_data
*data
= dev_get_drvdata(dev
);
2313 error
= mxt_load_fw(dev
, MXT_FW_NAME
);
2315 dev_err(dev
, "The firmware update failed(%d)\n", error
);
2318 dev_info(dev
, "The firmware update succeeded\n");
2320 error
= mxt_initialize(data
);
2328 static DEVICE_ATTR(fw_version
, S_IRUGO
, mxt_fw_version_show
, NULL
);
2329 static DEVICE_ATTR(hw_version
, S_IRUGO
, mxt_hw_version_show
, NULL
);
2330 static DEVICE_ATTR(object
, S_IRUGO
, mxt_object_show
, NULL
);
2331 static DEVICE_ATTR(update_fw
, S_IWUSR
, NULL
, mxt_update_fw_store
);
2333 static struct attribute
*mxt_attrs
[] = {
2334 &dev_attr_fw_version
.attr
,
2335 &dev_attr_hw_version
.attr
,
2336 &dev_attr_object
.attr
,
2337 &dev_attr_update_fw
.attr
,
2341 static const struct attribute_group mxt_attr_group
= {
2345 static void mxt_start(struct mxt_data
*data
)
2347 switch (data
->pdata
->suspend_mode
) {
2348 case MXT_SUSPEND_T9_CTRL
:
2349 mxt_soft_reset(data
);
2352 /* 0x83 = SCANEN | RPTEN | ENABLE */
2353 mxt_write_object(data
,
2354 MXT_TOUCH_MULTI_T9
, MXT_T9_CTRL
, 0x83);
2357 case MXT_SUSPEND_DEEP_SLEEP
:
2359 mxt_set_t7_power_cfg(data
, MXT_POWER_CFG_RUN
);
2361 /* Recalibrate since chip has been in deep sleep */
2362 mxt_t6_command(data
, MXT_COMMAND_CALIBRATE
, 1, false);
2368 static void mxt_stop(struct mxt_data
*data
)
2370 switch (data
->pdata
->suspend_mode
) {
2371 case MXT_SUSPEND_T9_CTRL
:
2373 mxt_write_object(data
,
2374 MXT_TOUCH_MULTI_T9
, MXT_T9_CTRL
, 0);
2377 case MXT_SUSPEND_DEEP_SLEEP
:
2379 mxt_set_t7_power_cfg(data
, MXT_POWER_CFG_DEEPSLEEP
);
2384 static int mxt_input_open(struct input_dev
*dev
)
2386 struct mxt_data
*data
= input_get_drvdata(dev
);
2393 static void mxt_input_close(struct input_dev
*dev
)
2395 struct mxt_data
*data
= input_get_drvdata(dev
);
2401 static const struct mxt_platform_data
*mxt_parse_dt(struct i2c_client
*client
)
2403 struct mxt_platform_data
*pdata
;
2404 struct device_node
*np
= client
->dev
.of_node
;
2409 return ERR_PTR(-ENOENT
);
2411 pdata
= devm_kzalloc(&client
->dev
, sizeof(*pdata
), GFP_KERNEL
);
2413 return ERR_PTR(-ENOMEM
);
2415 if (of_find_property(np
, "linux,gpio-keymap", &proplen
)) {
2416 pdata
->t19_num_keys
= proplen
/ sizeof(u32
);
2418 keymap
= devm_kzalloc(&client
->dev
,
2419 pdata
->t19_num_keys
* sizeof(keymap
[0]),
2422 return ERR_PTR(-ENOMEM
);
2424 ret
= of_property_read_u32_array(np
, "linux,gpio-keymap",
2425 keymap
, pdata
->t19_num_keys
);
2427 dev_warn(&client
->dev
,
2428 "Couldn't read linux,gpio-keymap: %d\n", ret
);
2430 pdata
->t19_keymap
= keymap
;
2433 pdata
->suspend_mode
= MXT_SUSPEND_DEEP_SLEEP
;
2438 static const struct mxt_platform_data
*mxt_parse_dt(struct i2c_client
*client
)
2440 return ERR_PTR(-ENOENT
);
2446 struct mxt_acpi_platform_data
{
2448 struct mxt_platform_data pdata
;
2451 static unsigned int samus_touchpad_buttons
[] = {
2458 static struct mxt_acpi_platform_data samus_platform_data
[] = {
2463 .t19_num_keys
= ARRAY_SIZE(samus_touchpad_buttons
),
2464 .t19_keymap
= samus_touchpad_buttons
,
2474 static unsigned int chromebook_tp_buttons
[] = {
2483 static struct mxt_acpi_platform_data chromebook_platform_data
[] = {
2488 .t19_num_keys
= ARRAY_SIZE(chromebook_tp_buttons
),
2489 .t19_keymap
= chromebook_tp_buttons
,
2499 static const struct dmi_system_id mxt_dmi_table
[] = {
2501 /* 2015 Google Pixel */
2502 .ident
= "Chromebook Pixel 2",
2504 DMI_MATCH(DMI_SYS_VENDOR
, "GOOGLE"),
2505 DMI_MATCH(DMI_PRODUCT_NAME
, "Samus"),
2507 .driver_data
= samus_platform_data
,
2510 /* Other Google Chromebooks */
2511 .ident
= "Chromebook",
2513 DMI_MATCH(DMI_SYS_VENDOR
, "GOOGLE"),
2515 .driver_data
= chromebook_platform_data
,
2520 static const struct mxt_platform_data
*mxt_parse_acpi(struct i2c_client
*client
)
2522 struct acpi_device
*adev
;
2523 const struct dmi_system_id
*system_id
;
2524 const struct mxt_acpi_platform_data
*acpi_pdata
;
2527 * Ignore ACPI devices representing bootloader mode.
2529 * This is a bit of a hack: Google Chromebook BIOS creates ACPI
2530 * devices for both application and bootloader modes, but we are
2531 * interested in application mode only (if device is in bootloader
2532 * mode we'll end up switching into application anyway). So far
2533 * application mode addresses were all above 0x40, so we'll use it
2536 if (client
->addr
< 0x40)
2537 return ERR_PTR(-ENXIO
);
2539 adev
= ACPI_COMPANION(&client
->dev
);
2541 return ERR_PTR(-ENOENT
);
2543 system_id
= dmi_first_match(mxt_dmi_table
);
2545 return ERR_PTR(-ENOENT
);
2547 acpi_pdata
= system_id
->driver_data
;
2549 return ERR_PTR(-ENOENT
);
2551 while (acpi_pdata
->hid
) {
2552 if (!strcmp(acpi_device_hid(adev
), acpi_pdata
->hid
))
2553 return &acpi_pdata
->pdata
;
2558 return ERR_PTR(-ENOENT
);
2561 static const struct mxt_platform_data
*mxt_parse_acpi(struct i2c_client
*client
)
2563 return ERR_PTR(-ENOENT
);
2567 static const struct mxt_platform_data
*
2568 mxt_get_platform_data(struct i2c_client
*client
)
2570 const struct mxt_platform_data
*pdata
;
2572 pdata
= dev_get_platdata(&client
->dev
);
2576 pdata
= mxt_parse_dt(client
);
2577 if (!IS_ERR(pdata
) || PTR_ERR(pdata
) != -ENOENT
)
2580 pdata
= mxt_parse_acpi(client
);
2581 if (!IS_ERR(pdata
) || PTR_ERR(pdata
) != -ENOENT
)
2584 dev_err(&client
->dev
, "No platform data specified\n");
2585 return ERR_PTR(-EINVAL
);
2588 static int mxt_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
2590 struct mxt_data
*data
;
2591 const struct mxt_platform_data
*pdata
;
2594 pdata
= mxt_get_platform_data(client
);
2596 return PTR_ERR(pdata
);
2598 data
= kzalloc(sizeof(struct mxt_data
), GFP_KERNEL
);
2600 dev_err(&client
->dev
, "Failed to allocate memory\n");
2604 snprintf(data
->phys
, sizeof(data
->phys
), "i2c-%u-%04x/input0",
2605 client
->adapter
->nr
, client
->addr
);
2607 data
->client
= client
;
2608 data
->pdata
= pdata
;
2609 data
->irq
= client
->irq
;
2610 i2c_set_clientdata(client
, data
);
2612 init_completion(&data
->bl_completion
);
2613 init_completion(&data
->reset_completion
);
2614 init_completion(&data
->crc_completion
);
2616 error
= request_threaded_irq(client
->irq
, NULL
, mxt_interrupt
,
2617 pdata
->irqflags
| IRQF_ONESHOT
,
2618 client
->name
, data
);
2620 dev_err(&client
->dev
, "Failed to register interrupt\n");
2624 disable_irq(client
->irq
);
2626 error
= mxt_initialize(data
);
2630 error
= sysfs_create_group(&client
->dev
.kobj
, &mxt_attr_group
);
2632 dev_err(&client
->dev
, "Failure %d creating sysfs group\n",
2634 goto err_free_object
;
2640 mxt_free_input_device(data
);
2641 mxt_free_object_table(data
);
2643 free_irq(client
->irq
, data
);
2649 static int mxt_remove(struct i2c_client
*client
)
2651 struct mxt_data
*data
= i2c_get_clientdata(client
);
2653 sysfs_remove_group(&client
->dev
.kobj
, &mxt_attr_group
);
2654 free_irq(data
->irq
, data
);
2655 mxt_free_input_device(data
);
2656 mxt_free_object_table(data
);
2662 static int __maybe_unused
mxt_suspend(struct device
*dev
)
2664 struct i2c_client
*client
= to_i2c_client(dev
);
2665 struct mxt_data
*data
= i2c_get_clientdata(client
);
2666 struct input_dev
*input_dev
= data
->input_dev
;
2671 mutex_lock(&input_dev
->mutex
);
2673 if (input_dev
->users
)
2676 mutex_unlock(&input_dev
->mutex
);
2681 static int __maybe_unused
mxt_resume(struct device
*dev
)
2683 struct i2c_client
*client
= to_i2c_client(dev
);
2684 struct mxt_data
*data
= i2c_get_clientdata(client
);
2685 struct input_dev
*input_dev
= data
->input_dev
;
2690 mutex_lock(&input_dev
->mutex
);
2692 if (input_dev
->users
)
2695 mutex_unlock(&input_dev
->mutex
);
2700 static SIMPLE_DEV_PM_OPS(mxt_pm_ops
, mxt_suspend
, mxt_resume
);
2702 static const struct of_device_id mxt_of_match
[] = {
2703 { .compatible
= "atmel,maxtouch", },
2706 MODULE_DEVICE_TABLE(of
, mxt_of_match
);
2709 static const struct acpi_device_id mxt_acpi_id
[] = {
2710 { "ATML0000", 0 }, /* Touchpad */
2711 { "ATML0001", 0 }, /* Touchscreen */
2714 MODULE_DEVICE_TABLE(acpi
, mxt_acpi_id
);
2717 static const struct i2c_device_id mxt_id
[] = {
2718 { "qt602240_ts", 0 },
2719 { "atmel_mxt_ts", 0 },
2720 { "atmel_mxt_tp", 0 },
2725 MODULE_DEVICE_TABLE(i2c
, mxt_id
);
2727 static struct i2c_driver mxt_driver
= {
2729 .name
= "atmel_mxt_ts",
2730 .of_match_table
= of_match_ptr(mxt_of_match
),
2731 .acpi_match_table
= ACPI_PTR(mxt_acpi_id
),
2735 .remove
= mxt_remove
,
2739 module_i2c_driver(mxt_driver
);
2741 /* Module information */
2742 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
2743 MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
2744 MODULE_LICENSE("GPL");