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/i2c/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>
38 #define MXT_FW_NAME "maxtouch.fw"
39 #define MXT_CFG_NAME "maxtouch.cfg"
40 #define MXT_CFG_MAGIC "OBP_RAW V1"
44 #define MXT_FAMILY_ID 0x00
45 #define MXT_VARIANT_ID 0x01
46 #define MXT_VERSION 0x02
47 #define MXT_BUILD 0x03
48 #define MXT_MATRIX_X_SIZE 0x04
49 #define MXT_MATRIX_Y_SIZE 0x05
50 #define MXT_OBJECT_NUM 0x06
51 #define MXT_OBJECT_START 0x07
53 #define MXT_OBJECT_SIZE 6
54 #define MXT_INFO_CHECKSUM_SIZE 3
55 #define MXT_MAX_BLOCK_WRITE 256
58 #define MXT_DEBUG_DIAGNOSTIC_T37 37
59 #define MXT_GEN_MESSAGE_T5 5
60 #define MXT_GEN_COMMAND_T6 6
61 #define MXT_GEN_POWER_T7 7
62 #define MXT_GEN_ACQUIRE_T8 8
63 #define MXT_GEN_DATASOURCE_T53 53
64 #define MXT_TOUCH_MULTI_T9 9
65 #define MXT_TOUCH_KEYARRAY_T15 15
66 #define MXT_TOUCH_PROXIMITY_T23 23
67 #define MXT_TOUCH_PROXKEY_T52 52
68 #define MXT_PROCI_GRIPFACE_T20 20
69 #define MXT_PROCG_NOISE_T22 22
70 #define MXT_PROCI_ONETOUCH_T24 24
71 #define MXT_PROCI_TWOTOUCH_T27 27
72 #define MXT_PROCI_GRIP_T40 40
73 #define MXT_PROCI_PALM_T41 41
74 #define MXT_PROCI_TOUCHSUPPRESSION_T42 42
75 #define MXT_PROCI_STYLUS_T47 47
76 #define MXT_PROCG_NOISESUPPRESSION_T48 48
77 #define MXT_SPT_COMMSCONFIG_T18 18
78 #define MXT_SPT_GPIOPWM_T19 19
79 #define MXT_SPT_SELFTEST_T25 25
80 #define MXT_SPT_CTECONFIG_T28 28
81 #define MXT_SPT_USERDATA_T38 38
82 #define MXT_SPT_DIGITIZER_T43 43
83 #define MXT_SPT_MESSAGECOUNT_T44 44
84 #define MXT_SPT_CTECONFIG_T46 46
85 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100
87 /* MXT_GEN_MESSAGE_T5 object */
88 #define MXT_RPTID_NOMSG 0xff
90 /* MXT_GEN_COMMAND_T6 field */
91 #define MXT_COMMAND_RESET 0
92 #define MXT_COMMAND_BACKUPNV 1
93 #define MXT_COMMAND_CALIBRATE 2
94 #define MXT_COMMAND_REPORTALL 3
95 #define MXT_COMMAND_DIAGNOSTIC 5
97 /* Define for T6 status byte */
98 #define MXT_T6_STATUS_RESET (1 << 7)
99 #define MXT_T6_STATUS_OFL (1 << 6)
100 #define MXT_T6_STATUS_SIGERR (1 << 5)
101 #define MXT_T6_STATUS_CAL (1 << 4)
102 #define MXT_T6_STATUS_CFGERR (1 << 3)
103 #define MXT_T6_STATUS_COMSERR (1 << 2)
105 /* MXT_GEN_POWER_T7 field */
106 #define MXT_POWER_IDLEACQINT 0
107 #define MXT_POWER_ACTVACQINT 1
108 #define MXT_POWER_ACTV2IDLETO 2
110 /* MXT_GEN_ACQUIRE_T8 field */
111 #define MXT_ACQUIRE_CHRGTIME 0
112 #define MXT_ACQUIRE_TCHDRIFT 2
113 #define MXT_ACQUIRE_DRIFTST 3
114 #define MXT_ACQUIRE_TCHAUTOCAL 4
115 #define MXT_ACQUIRE_SYNC 5
116 #define MXT_ACQUIRE_ATCHCALST 6
117 #define MXT_ACQUIRE_ATCHCALSTHR 7
119 /* MXT_TOUCH_MULTI_T9 field */
120 #define MXT_TOUCH_CTRL 0
121 #define MXT_T9_ORIENT 9
122 #define MXT_T9_RANGE 18
124 /* MXT_TOUCH_MULTI_T9 status */
125 #define MXT_T9_UNGRIP (1 << 0)
126 #define MXT_T9_SUPPRESS (1 << 1)
127 #define MXT_T9_AMP (1 << 2)
128 #define MXT_T9_VECTOR (1 << 3)
129 #define MXT_T9_MOVE (1 << 4)
130 #define MXT_T9_RELEASE (1 << 5)
131 #define MXT_T9_PRESS (1 << 6)
132 #define MXT_T9_DETECT (1 << 7)
139 /* MXT_TOUCH_MULTI_T9 orient */
140 #define MXT_T9_ORIENT_SWITCH (1 << 0)
142 /* MXT_PROCI_GRIPFACE_T20 field */
143 #define MXT_GRIPFACE_CTRL 0
144 #define MXT_GRIPFACE_XLOGRIP 1
145 #define MXT_GRIPFACE_XHIGRIP 2
146 #define MXT_GRIPFACE_YLOGRIP 3
147 #define MXT_GRIPFACE_YHIGRIP 4
148 #define MXT_GRIPFACE_MAXTCHS 5
149 #define MXT_GRIPFACE_SZTHR1 7
150 #define MXT_GRIPFACE_SZTHR2 8
151 #define MXT_GRIPFACE_SHPTHR1 9
152 #define MXT_GRIPFACE_SHPTHR2 10
153 #define MXT_GRIPFACE_SUPEXTTO 11
155 /* MXT_PROCI_NOISE field */
156 #define MXT_NOISE_CTRL 0
157 #define MXT_NOISE_OUTFLEN 1
158 #define MXT_NOISE_GCAFUL_LSB 3
159 #define MXT_NOISE_GCAFUL_MSB 4
160 #define MXT_NOISE_GCAFLL_LSB 5
161 #define MXT_NOISE_GCAFLL_MSB 6
162 #define MXT_NOISE_ACTVGCAFVALID 7
163 #define MXT_NOISE_NOISETHR 8
164 #define MXT_NOISE_FREQHOPSCALE 10
165 #define MXT_NOISE_FREQ0 11
166 #define MXT_NOISE_FREQ1 12
167 #define MXT_NOISE_FREQ2 13
168 #define MXT_NOISE_FREQ3 14
169 #define MXT_NOISE_FREQ4 15
170 #define MXT_NOISE_IDLEGCAFVALID 16
172 /* MXT_SPT_COMMSCONFIG_T18 */
173 #define MXT_COMMS_CTRL 0
174 #define MXT_COMMS_CMD 1
176 /* MXT_SPT_CTECONFIG_T28 field */
177 #define MXT_CTE_CTRL 0
178 #define MXT_CTE_CMD 1
179 #define MXT_CTE_MODE 2
180 #define MXT_CTE_IDLEGCAFDEPTH 3
181 #define MXT_CTE_ACTVGCAFDEPTH 4
182 #define MXT_CTE_VOLTAGE 5
184 #define MXT_VOLTAGE_DEFAULT 2700000
185 #define MXT_VOLTAGE_STEP 10000
187 /* Define for MXT_GEN_COMMAND_T6 */
188 #define MXT_BOOT_VALUE 0xa5
189 #define MXT_RESET_VALUE 0x01
190 #define MXT_BACKUP_VALUE 0x55
192 /* T100 Multiple Touch Touchscreen */
193 #define MXT_T100_CTRL 0
194 #define MXT_T100_CFG1 1
195 #define MXT_T100_TCHAUX 3
196 #define MXT_T100_XRANGE 13
197 #define MXT_T100_YRANGE 24
199 #define MXT_T100_CFG_SWITCHXY BIT(5)
201 #define MXT_T100_TCHAUX_VECT BIT(0)
202 #define MXT_T100_TCHAUX_AMPL BIT(1)
203 #define MXT_T100_TCHAUX_AREA BIT(2)
205 #define MXT_T100_DETECT BIT(7)
206 #define MXT_T100_TYPE_MASK 0x70
209 MXT_T100_TYPE_FINGER
= 1,
210 MXT_T100_TYPE_PASSIVE_STYLUS
= 2,
211 MXT_T100_TYPE_HOVERING_FINGER
= 4,
212 MXT_T100_TYPE_GLOVE
= 5,
213 MXT_T100_TYPE_LARGE_TOUCH
= 6,
216 #define MXT_DISTANCE_ACTIVE_TOUCH 0
217 #define MXT_DISTANCE_HOVERING 1
219 #define MXT_TOUCH_MAJOR_DEFAULT 1
220 #define MXT_PRESSURE_DEFAULT 1
223 #define MXT_BACKUP_TIME 50 /* msec */
224 #define MXT_RESET_TIME 200 /* msec */
225 #define MXT_RESET_TIMEOUT 3000 /* msec */
226 #define MXT_CRC_TIMEOUT 1000 /* msec */
227 #define MXT_FW_RESET_TIME 3000 /* msec */
228 #define MXT_FW_CHG_TIMEOUT 300 /* msec */
230 /* Command to unlock bootloader */
231 #define MXT_UNLOCK_CMD_MSB 0xaa
232 #define MXT_UNLOCK_CMD_LSB 0xdc
234 /* Bootloader mode status */
235 #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
236 #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
237 #define MXT_FRAME_CRC_CHECK 0x02
238 #define MXT_FRAME_CRC_FAIL 0x03
239 #define MXT_FRAME_CRC_PASS 0x04
240 #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
241 #define MXT_BOOT_STATUS_MASK 0x3f
242 #define MXT_BOOT_EXTENDED_ID (1 << 5)
243 #define MXT_BOOT_ID_MASK 0x1f
245 /* Touchscreen absolute values */
246 #define MXT_MAX_AREA 0xff
248 #define MXT_PIXELS_PER_MM 20
264 u8 instances_minus_one
;
268 /* Each client has this additional data */
270 struct i2c_client
*client
;
271 struct input_dev
*input_dev
;
272 char phys
[64]; /* device physical location */
273 const struct mxt_platform_data
*pdata
;
274 struct mxt_object
*object_table
;
275 struct mxt_info info
;
291 u8 last_message_count
;
295 /* Cached parameters from object table */
305 u8 T100_reportid_min
;
306 u8 T100_reportid_max
;
308 /* for fw update in bootloader */
309 struct completion bl_completion
;
311 /* for reset handling */
312 struct completion reset_completion
;
314 /* for config update handling */
315 struct completion crc_completion
;
318 static size_t mxt_obj_size(const struct mxt_object
*obj
)
320 return obj
->size_minus_one
+ 1;
323 static size_t mxt_obj_instances(const struct mxt_object
*obj
)
325 return obj
->instances_minus_one
+ 1;
328 static bool mxt_object_readable(unsigned int type
)
331 case MXT_GEN_COMMAND_T6
:
332 case MXT_GEN_POWER_T7
:
333 case MXT_GEN_ACQUIRE_T8
:
334 case MXT_GEN_DATASOURCE_T53
:
335 case MXT_TOUCH_MULTI_T9
:
336 case MXT_TOUCH_KEYARRAY_T15
:
337 case MXT_TOUCH_PROXIMITY_T23
:
338 case MXT_TOUCH_PROXKEY_T52
:
339 case MXT_PROCI_GRIPFACE_T20
:
340 case MXT_PROCG_NOISE_T22
:
341 case MXT_PROCI_ONETOUCH_T24
:
342 case MXT_PROCI_TWOTOUCH_T27
:
343 case MXT_PROCI_GRIP_T40
:
344 case MXT_PROCI_PALM_T41
:
345 case MXT_PROCI_TOUCHSUPPRESSION_T42
:
346 case MXT_PROCI_STYLUS_T47
:
347 case MXT_PROCG_NOISESUPPRESSION_T48
:
348 case MXT_SPT_COMMSCONFIG_T18
:
349 case MXT_SPT_GPIOPWM_T19
:
350 case MXT_SPT_SELFTEST_T25
:
351 case MXT_SPT_CTECONFIG_T28
:
352 case MXT_SPT_USERDATA_T38
:
353 case MXT_SPT_DIGITIZER_T43
:
354 case MXT_SPT_CTECONFIG_T46
:
361 static void mxt_dump_message(struct mxt_data
*data
, u8
*message
)
363 dev_dbg(&data
->client
->dev
, "message: %*ph\n",
364 data
->T5_msg_size
, message
);
367 static int mxt_wait_for_completion(struct mxt_data
*data
,
368 struct completion
*comp
,
369 unsigned int timeout_ms
)
371 struct device
*dev
= &data
->client
->dev
;
372 unsigned long timeout
= msecs_to_jiffies(timeout_ms
);
375 ret
= wait_for_completion_interruptible_timeout(comp
, timeout
);
378 } else if (ret
== 0) {
379 dev_err(dev
, "Wait for completion timed out.\n");
385 static int mxt_bootloader_read(struct mxt_data
*data
,
386 u8
*val
, unsigned int count
)
391 msg
.addr
= data
->bootloader_addr
;
392 msg
.flags
= data
->client
->flags
& I2C_M_TEN
;
393 msg
.flags
|= I2C_M_RD
;
397 ret
= i2c_transfer(data
->client
->adapter
, &msg
, 1);
401 ret
= ret
< 0 ? ret
: -EIO
;
402 dev_err(&data
->client
->dev
, "%s: i2c recv failed (%d)\n",
409 static int mxt_bootloader_write(struct mxt_data
*data
,
410 const u8
* const val
, unsigned int count
)
415 msg
.addr
= data
->bootloader_addr
;
416 msg
.flags
= data
->client
->flags
& I2C_M_TEN
;
420 ret
= i2c_transfer(data
->client
->adapter
, &msg
, 1);
424 ret
= ret
< 0 ? ret
: -EIO
;
425 dev_err(&data
->client
->dev
, "%s: i2c send failed (%d)\n",
432 static int mxt_lookup_bootloader_address(struct mxt_data
*data
, bool retry
)
434 u8 appmode
= data
->client
->addr
;
440 /* Chips after 1664S use different scheme */
441 if (retry
|| data
->info
.family_id
>= 0xa2) {
442 bootloader
= appmode
- 0x24;
445 /* Fall through for normal case */
450 bootloader
= appmode
- 0x26;
454 dev_err(&data
->client
->dev
,
455 "Appmode i2c address 0x%02x not found\n",
460 data
->bootloader_addr
= bootloader
;
464 static int mxt_probe_bootloader(struct mxt_data
*data
, bool alt_address
)
466 struct device
*dev
= &data
->client
->dev
;
471 error
= mxt_lookup_bootloader_address(data
, alt_address
);
475 error
= mxt_bootloader_read(data
, &val
, 1);
479 /* Check app crc fail mode */
480 crc_failure
= (val
& ~MXT_BOOT_STATUS_MASK
) == MXT_APP_CRC_FAIL
;
482 dev_err(dev
, "Detected bootloader, status:%02X%s\n",
483 val
, crc_failure
? ", APP_CRC_FAIL" : "");
488 static u8
mxt_get_bootloader_version(struct mxt_data
*data
, u8 val
)
490 struct device
*dev
= &data
->client
->dev
;
493 if (val
& MXT_BOOT_EXTENDED_ID
) {
494 if (mxt_bootloader_read(data
, &buf
[0], 3) != 0) {
495 dev_err(dev
, "%s: i2c failure\n", __func__
);
499 dev_dbg(dev
, "Bootloader ID:%d Version:%d\n", buf
[1], buf
[2]);
503 dev_dbg(dev
, "Bootloader ID:%d\n", val
& MXT_BOOT_ID_MASK
);
509 static int mxt_check_bootloader(struct mxt_data
*data
, unsigned int state
,
512 struct device
*dev
= &data
->client
->dev
;
519 * In application update mode, the interrupt
520 * line signals state transitions. We must wait for the
521 * CHG assertion before reading the status byte.
522 * Once the status byte has been read, the line is deasserted.
524 ret
= mxt_wait_for_completion(data
, &data
->bl_completion
,
528 * TODO: handle -ERESTARTSYS better by terminating
529 * fw update process before returning to userspace
530 * by writing length 0x000 to device (iff we are in
531 * WAITING_FRAME_DATA state).
533 dev_err(dev
, "Update wait error %d\n", ret
);
538 ret
= mxt_bootloader_read(data
, &val
, 1);
542 if (state
== MXT_WAITING_BOOTLOAD_CMD
)
543 val
= mxt_get_bootloader_version(data
, val
);
546 case MXT_WAITING_BOOTLOAD_CMD
:
547 case MXT_WAITING_FRAME_DATA
:
548 case MXT_APP_CRC_FAIL
:
549 val
&= ~MXT_BOOT_STATUS_MASK
;
551 case MXT_FRAME_CRC_PASS
:
552 if (val
== MXT_FRAME_CRC_CHECK
) {
554 } else if (val
== MXT_FRAME_CRC_FAIL
) {
555 dev_err(dev
, "Bootloader CRC fail\n");
564 dev_err(dev
, "Invalid bootloader state %02X != %02X\n",
572 static int mxt_send_bootloader_cmd(struct mxt_data
*data
, bool unlock
)
578 buf
[0] = MXT_UNLOCK_CMD_LSB
;
579 buf
[1] = MXT_UNLOCK_CMD_MSB
;
585 ret
= mxt_bootloader_write(data
, buf
, 2);
592 static int __mxt_read_reg(struct i2c_client
*client
,
593 u16 reg
, u16 len
, void *val
)
595 struct i2c_msg xfer
[2];
600 buf
[1] = (reg
>> 8) & 0xff;
603 xfer
[0].addr
= client
->addr
;
609 xfer
[1].addr
= client
->addr
;
610 xfer
[1].flags
= I2C_M_RD
;
614 ret
= i2c_transfer(client
->adapter
, xfer
, 2);
620 dev_err(&client
->dev
, "%s: i2c transfer failed (%d)\n",
627 static int __mxt_write_reg(struct i2c_client
*client
, u16 reg
, u16 len
,
635 buf
= kmalloc(count
, GFP_KERNEL
);
640 buf
[1] = (reg
>> 8) & 0xff;
641 memcpy(&buf
[2], val
, len
);
643 ret
= i2c_master_send(client
, buf
, count
);
649 dev_err(&client
->dev
, "%s: i2c send failed (%d)\n",
657 static int mxt_write_reg(struct i2c_client
*client
, u16 reg
, u8 val
)
659 return __mxt_write_reg(client
, reg
, 1, &val
);
662 static struct mxt_object
*
663 mxt_get_object(struct mxt_data
*data
, u8 type
)
665 struct mxt_object
*object
;
668 for (i
= 0; i
< data
->info
.object_num
; i
++) {
669 object
= data
->object_table
+ i
;
670 if (object
->type
== type
)
674 dev_warn(&data
->client
->dev
, "Invalid object type T%u\n", type
);
678 static void mxt_proc_t6_messages(struct mxt_data
*data
, u8
*msg
)
680 struct device
*dev
= &data
->client
->dev
;
682 u32 crc
= msg
[2] | (msg
[3] << 8) | (msg
[4] << 16);
684 complete(&data
->crc_completion
);
686 if (crc
!= data
->config_crc
) {
687 data
->config_crc
= crc
;
688 dev_dbg(dev
, "T6 Config Checksum: 0x%06X\n", crc
);
692 if (status
& MXT_T6_STATUS_RESET
)
693 complete(&data
->reset_completion
);
695 /* Output debug if status has changed */
696 if (status
!= data
->t6_status
)
697 dev_dbg(dev
, "T6 Status 0x%02X%s%s%s%s%s%s%s\n",
699 status
== 0 ? " OK" : "",
700 status
& MXT_T6_STATUS_RESET
? " RESET" : "",
701 status
& MXT_T6_STATUS_OFL
? " OFL" : "",
702 status
& MXT_T6_STATUS_SIGERR
? " SIGERR" : "",
703 status
& MXT_T6_STATUS_CAL
? " CAL" : "",
704 status
& MXT_T6_STATUS_CFGERR
? " CFGERR" : "",
705 status
& MXT_T6_STATUS_COMSERR
? " COMSERR" : "");
707 /* Save current status */
708 data
->t6_status
= status
;
711 static int mxt_write_object(struct mxt_data
*data
,
712 u8 type
, u8 offset
, u8 val
)
714 struct mxt_object
*object
;
717 object
= mxt_get_object(data
, type
);
718 if (!object
|| offset
>= mxt_obj_size(object
))
721 reg
= object
->start_address
;
722 return mxt_write_reg(data
->client
, reg
+ offset
, val
);
725 static void mxt_input_button(struct mxt_data
*data
, u8
*message
)
727 struct input_dev
*input
= data
->input_dev
;
728 const struct mxt_platform_data
*pdata
= data
->pdata
;
732 /* Active-low switch */
733 for (i
= 0; i
< pdata
->t19_num_keys
; i
++) {
734 if (pdata
->t19_keymap
[i
] == KEY_RESERVED
)
736 button
= !(message
[1] & (1 << i
));
737 input_report_key(input
, pdata
->t19_keymap
[i
], button
);
741 static void mxt_input_sync(struct mxt_data
*data
)
743 input_mt_report_pointer_emulation(data
->input_dev
,
744 data
->pdata
->t19_num_keys
);
745 input_sync(data
->input_dev
);
748 static void mxt_proc_t9_message(struct mxt_data
*data
, u8
*message
)
750 struct device
*dev
= &data
->client
->dev
;
751 struct input_dev
*input_dev
= data
->input_dev
;
759 id
= message
[0] - data
->T9_reportid_min
;
761 x
= (message
[2] << 4) | ((message
[4] >> 4) & 0xf);
762 y
= (message
[3] << 4) | ((message
[4] & 0xf));
764 /* Handle 10/12 bit switching */
765 if (data
->max_x
< 1024)
767 if (data
->max_y
< 1024)
771 amplitude
= message
[6];
774 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
776 (status
& MXT_T9_DETECT
) ? 'D' : '.',
777 (status
& MXT_T9_PRESS
) ? 'P' : '.',
778 (status
& MXT_T9_RELEASE
) ? 'R' : '.',
779 (status
& MXT_T9_MOVE
) ? 'M' : '.',
780 (status
& MXT_T9_VECTOR
) ? 'V' : '.',
781 (status
& MXT_T9_AMP
) ? 'A' : '.',
782 (status
& MXT_T9_SUPPRESS
) ? 'S' : '.',
783 (status
& MXT_T9_UNGRIP
) ? 'U' : '.',
784 x
, y
, area
, amplitude
);
786 input_mt_slot(input_dev
, id
);
788 if (status
& MXT_T9_DETECT
) {
790 * Multiple bits may be set if the host is slow to read
791 * the status messages, indicating all the events that
794 if (status
& MXT_T9_RELEASE
) {
795 input_mt_report_slot_state(input_dev
,
797 mxt_input_sync(data
);
801 input_mt_report_slot_state(input_dev
, MT_TOOL_FINGER
, 1);
802 input_report_abs(input_dev
, ABS_MT_POSITION_X
, x
);
803 input_report_abs(input_dev
, ABS_MT_POSITION_Y
, y
);
804 input_report_abs(input_dev
, ABS_MT_PRESSURE
, amplitude
);
805 input_report_abs(input_dev
, ABS_MT_TOUCH_MAJOR
, area
);
807 /* Touch no longer active, close out slot */
808 input_mt_report_slot_state(input_dev
, MT_TOOL_FINGER
, 0);
811 data
->update_input
= true;
814 static void mxt_proc_t100_message(struct mxt_data
*data
, u8
*message
)
816 struct device
*dev
= &data
->client
->dev
;
817 struct input_dev
*input_dev
= data
->input_dev
;
829 id
= message
[0] - data
->T100_reportid_min
- 2;
831 /* ignore SCRSTATUS events */
836 x
= get_unaligned_le16(&message
[2]);
837 y
= get_unaligned_le16(&message
[4]);
839 if (status
& MXT_T100_DETECT
) {
840 type
= (status
& MXT_T100_TYPE_MASK
) >> 4;
843 case MXT_T100_TYPE_HOVERING_FINGER
:
844 tool
= MT_TOOL_FINGER
;
845 distance
= MXT_DISTANCE_HOVERING
;
847 if (data
->t100_aux_vect
)
848 orientation
= message
[data
->t100_aux_vect
];
852 case MXT_T100_TYPE_FINGER
:
853 case MXT_T100_TYPE_GLOVE
:
854 tool
= MT_TOOL_FINGER
;
855 distance
= MXT_DISTANCE_ACTIVE_TOUCH
;
857 if (data
->t100_aux_area
)
858 major
= message
[data
->t100_aux_area
];
860 if (data
->t100_aux_ampl
)
861 pressure
= message
[data
->t100_aux_ampl
];
863 if (data
->t100_aux_vect
)
864 orientation
= message
[data
->t100_aux_vect
];
868 case MXT_T100_TYPE_PASSIVE_STYLUS
:
872 * Passive stylus is reported with size zero so
875 major
= MXT_TOUCH_MAJOR_DEFAULT
;
877 if (data
->t100_aux_ampl
)
878 pressure
= message
[data
->t100_aux_ampl
];
882 case MXT_T100_TYPE_LARGE_TOUCH
:
883 /* Ignore suppressed touch */
887 dev_dbg(dev
, "Unexpected T100 type\n");
893 * Values reported should be non-zero if tool is touching the
896 if (!pressure
&& type
!= MXT_T100_TYPE_HOVERING_FINGER
)
897 pressure
= MXT_PRESSURE_DEFAULT
;
899 input_mt_slot(input_dev
, id
);
901 if (status
& MXT_T100_DETECT
) {
902 dev_dbg(dev
, "[%u] type:%u x:%u y:%u a:%02X p:%02X v:%02X\n",
903 id
, type
, x
, y
, major
, pressure
, orientation
);
905 input_mt_report_slot_state(input_dev
, tool
, 1);
906 input_report_abs(input_dev
, ABS_MT_POSITION_X
, x
);
907 input_report_abs(input_dev
, ABS_MT_POSITION_Y
, y
);
908 input_report_abs(input_dev
, ABS_MT_TOUCH_MAJOR
, major
);
909 input_report_abs(input_dev
, ABS_MT_PRESSURE
, pressure
);
910 input_report_abs(input_dev
, ABS_MT_DISTANCE
, distance
);
911 input_report_abs(input_dev
, ABS_MT_ORIENTATION
, orientation
);
913 dev_dbg(dev
, "[%u] release\n", id
);
916 input_mt_report_slot_state(input_dev
, 0, 0);
919 data
->update_input
= true;
922 static int mxt_proc_message(struct mxt_data
*data
, u8
*message
)
924 u8 report_id
= message
[0];
926 if (report_id
== MXT_RPTID_NOMSG
)
929 if (report_id
== data
->T6_reportid
) {
930 mxt_proc_t6_messages(data
, message
);
931 } else if (!data
->input_dev
) {
933 * Do not report events if input device
934 * is not yet registered.
936 mxt_dump_message(data
, message
);
937 } else if (report_id
>= data
->T9_reportid_min
&&
938 report_id
<= data
->T9_reportid_max
) {
939 mxt_proc_t9_message(data
, message
);
940 } else if (report_id
>= data
->T100_reportid_min
&&
941 report_id
<= data
->T100_reportid_max
) {
942 mxt_proc_t100_message(data
, message
);
943 } else if (report_id
== data
->T19_reportid
) {
944 mxt_input_button(data
, message
);
945 data
->update_input
= true;
947 mxt_dump_message(data
, message
);
953 static int mxt_read_and_process_messages(struct mxt_data
*data
, u8 count
)
955 struct device
*dev
= &data
->client
->dev
;
960 /* Safety check for msg_buf */
961 if (count
> data
->max_reportid
)
964 /* Process remaining messages if necessary */
965 ret
= __mxt_read_reg(data
->client
, data
->T5_address
,
966 data
->T5_msg_size
* count
, data
->msg_buf
);
968 dev_err(dev
, "Failed to read %u messages (%d)\n", count
, ret
);
972 for (i
= 0; i
< count
; i
++) {
973 ret
= mxt_proc_message(data
,
974 data
->msg_buf
+ data
->T5_msg_size
* i
);
980 /* return number of messages read */
984 static irqreturn_t
mxt_process_messages_t44(struct mxt_data
*data
)
986 struct device
*dev
= &data
->client
->dev
;
990 /* Read T44 and T5 together */
991 ret
= __mxt_read_reg(data
->client
, data
->T44_address
,
992 data
->T5_msg_size
+ 1, data
->msg_buf
);
994 dev_err(dev
, "Failed to read T44 and T5 (%d)\n", ret
);
998 count
= data
->msg_buf
[0];
1002 * This condition is caused by the CHG line being configured
1003 * in Mode 0. It results in unnecessary I2C operations but it
1006 dev_dbg(dev
, "Interrupt triggered but zero messages\n");
1008 } else if (count
> data
->max_reportid
) {
1009 dev_err(dev
, "T44 count %d exceeded max report id\n", count
);
1010 count
= data
->max_reportid
;
1013 /* Process first message */
1014 ret
= mxt_proc_message(data
, data
->msg_buf
+ 1);
1016 dev_warn(dev
, "Unexpected invalid message\n");
1020 num_left
= count
- 1;
1022 /* Process remaining messages if necessary */
1024 ret
= mxt_read_and_process_messages(data
, num_left
);
1027 else if (ret
!= num_left
)
1028 dev_warn(dev
, "Unexpected invalid message\n");
1032 if (data
->update_input
) {
1033 mxt_input_sync(data
);
1034 data
->update_input
= false;
1040 static int mxt_process_messages_until_invalid(struct mxt_data
*data
)
1042 struct device
*dev
= &data
->client
->dev
;
1046 count
= data
->max_reportid
;
1048 /* Read messages until we force an invalid */
1050 read
= mxt_read_and_process_messages(data
, count
);
1055 if (data
->update_input
) {
1056 mxt_input_sync(data
);
1057 data
->update_input
= false;
1060 dev_err(dev
, "CHG pin isn't cleared\n");
1064 static irqreturn_t
mxt_process_messages(struct mxt_data
*data
)
1066 int total_handled
, num_handled
;
1067 u8 count
= data
->last_message_count
;
1069 if (count
< 1 || count
> data
->max_reportid
)
1072 /* include final invalid message */
1073 total_handled
= mxt_read_and_process_messages(data
, count
+ 1);
1074 if (total_handled
< 0)
1076 /* if there were invalid messages, then we are done */
1077 else if (total_handled
<= count
)
1080 /* keep reading two msgs until one is invalid or reportid limit */
1082 num_handled
= mxt_read_and_process_messages(data
, 2);
1083 if (num_handled
< 0)
1086 total_handled
+= num_handled
;
1088 if (num_handled
< 2)
1090 } while (total_handled
< data
->num_touchids
);
1093 data
->last_message_count
= total_handled
;
1095 if (data
->update_input
) {
1096 mxt_input_sync(data
);
1097 data
->update_input
= false;
1103 static irqreturn_t
mxt_interrupt(int irq
, void *dev_id
)
1105 struct mxt_data
*data
= dev_id
;
1107 if (data
->in_bootloader
) {
1108 /* bootloader state transition completion */
1109 complete(&data
->bl_completion
);
1113 if (!data
->object_table
)
1116 if (data
->T44_address
) {
1117 return mxt_process_messages_t44(data
);
1119 return mxt_process_messages(data
);
1123 static int mxt_t6_command(struct mxt_data
*data
, u16 cmd_offset
,
1124 u8 value
, bool wait
)
1127 u8 command_register
;
1128 int timeout_counter
= 0;
1131 reg
= data
->T6_address
+ cmd_offset
;
1133 ret
= mxt_write_reg(data
->client
, reg
, value
);
1142 ret
= __mxt_read_reg(data
->client
, reg
, 1, &command_register
);
1145 } while (command_register
!= 0 && timeout_counter
++ <= 100);
1147 if (timeout_counter
> 100) {
1148 dev_err(&data
->client
->dev
, "Command failed!\n");
1155 static int mxt_soft_reset(struct mxt_data
*data
)
1157 struct device
*dev
= &data
->client
->dev
;
1160 dev_info(dev
, "Resetting chip\n");
1162 reinit_completion(&data
->reset_completion
);
1164 ret
= mxt_t6_command(data
, MXT_COMMAND_RESET
, MXT_RESET_VALUE
, false);
1168 ret
= mxt_wait_for_completion(data
, &data
->reset_completion
,
1176 static void mxt_update_crc(struct mxt_data
*data
, u8 cmd
, u8 value
)
1179 * On failure, CRC is set to 0 and config will always be
1182 data
->config_crc
= 0;
1183 reinit_completion(&data
->crc_completion
);
1185 mxt_t6_command(data
, cmd
, value
, true);
1188 * Wait for crc message. On failure, CRC is set to 0 and config will
1189 * always be downloaded.
1191 mxt_wait_for_completion(data
, &data
->crc_completion
, MXT_CRC_TIMEOUT
);
1194 static void mxt_calc_crc24(u32
*crc
, u8 firstbyte
, u8 secondbyte
)
1196 static const unsigned int crcpoly
= 0x80001B;
1200 data_word
= (secondbyte
<< 8) | firstbyte
;
1201 result
= ((*crc
<< 1) ^ data_word
);
1203 if (result
& 0x1000000)
1209 static u32
mxt_calculate_crc(u8
*base
, off_t start_off
, off_t end_off
)
1212 u8
*ptr
= base
+ start_off
;
1213 u8
*last_val
= base
+ end_off
- 1;
1215 if (end_off
< start_off
)
1218 while (ptr
< last_val
) {
1219 mxt_calc_crc24(&crc
, *ptr
, *(ptr
+ 1));
1223 /* if len is odd, fill the last byte with 0 */
1224 if (ptr
== last_val
)
1225 mxt_calc_crc24(&crc
, *ptr
, 0);
1227 /* Mask to 24-bit */
1233 static int mxt_prepare_cfg_mem(struct mxt_data
*data
,
1234 const struct firmware
*cfg
,
1235 unsigned int data_pos
,
1236 unsigned int cfg_start_ofs
,
1238 size_t config_mem_size
)
1240 struct device
*dev
= &data
->client
->dev
;
1241 struct mxt_object
*object
;
1242 unsigned int type
, instance
, size
, byte_offset
;
1249 while (data_pos
< cfg
->size
) {
1250 /* Read type, instance, length */
1251 ret
= sscanf(cfg
->data
+ data_pos
, "%x %x %x%n",
1252 &type
, &instance
, &size
, &offset
);
1256 } else if (ret
!= 3) {
1257 dev_err(dev
, "Bad format: failed to parse object\n");
1262 object
= mxt_get_object(data
, type
);
1265 for (i
= 0; i
< size
; i
++) {
1266 ret
= sscanf(cfg
->data
+ data_pos
, "%hhx%n",
1269 dev_err(dev
, "Bad format in T%d at %d\n",
1278 if (size
> mxt_obj_size(object
)) {
1280 * Either we are in fallback mode due to wrong
1281 * config or config from a later fw version,
1282 * or the file is corrupt or hand-edited.
1284 dev_warn(dev
, "Discarding %zu byte(s) in T%u\n",
1285 size
- mxt_obj_size(object
), type
);
1286 } else if (mxt_obj_size(object
) > size
) {
1288 * If firmware is upgraded, new bytes may be added to
1289 * end of objects. It is generally forward compatible
1290 * to zero these bytes - previous behaviour will be
1291 * retained. However this does invalidate the CRC and
1292 * will force fallback mode until the configuration is
1293 * updated. We warn here but do nothing else - the
1294 * malloc has zeroed the entire configuration.
1296 dev_warn(dev
, "Zeroing %zu byte(s) in T%d\n",
1297 mxt_obj_size(object
) - size
, type
);
1300 if (instance
>= mxt_obj_instances(object
)) {
1301 dev_err(dev
, "Object instances exceeded!\n");
1305 reg
= object
->start_address
+ mxt_obj_size(object
) * instance
;
1307 for (i
= 0; i
< size
; i
++) {
1308 ret
= sscanf(cfg
->data
+ data_pos
, "%hhx%n",
1312 dev_err(dev
, "Bad format in T%d at %d\n",
1318 if (i
> mxt_obj_size(object
))
1321 byte_offset
= reg
+ i
- cfg_start_ofs
;
1323 if (byte_offset
>= 0 && byte_offset
< config_mem_size
) {
1324 *(config_mem
+ byte_offset
) = val
;
1326 dev_err(dev
, "Bad object: reg:%d, T%d, ofs=%d\n",
1327 reg
, object
->type
, byte_offset
);
1336 static int mxt_upload_cfg_mem(struct mxt_data
*data
, unsigned int cfg_start
,
1337 u8
*config_mem
, size_t config_mem_size
)
1339 unsigned int byte_offset
= 0;
1342 /* Write configuration as blocks */
1343 while (byte_offset
< config_mem_size
) {
1344 unsigned int size
= config_mem_size
- byte_offset
;
1346 if (size
> MXT_MAX_BLOCK_WRITE
)
1347 size
= MXT_MAX_BLOCK_WRITE
;
1349 error
= __mxt_write_reg(data
->client
,
1350 cfg_start
+ byte_offset
,
1351 size
, config_mem
+ byte_offset
);
1353 dev_err(&data
->client
->dev
,
1354 "Config write error, ret=%d\n", error
);
1358 byte_offset
+= size
;
1365 * mxt_update_cfg - download configuration to chip
1367 * Atmel Raw Config File Format
1369 * The first four lines of the raw config file contain:
1371 * 2) Chip ID Information (first 7 bytes of device memory)
1372 * 3) Chip Information Block 24-bit CRC Checksum
1373 * 4) Chip Configuration 24-bit CRC Checksum
1375 * The rest of the file consists of one line per object instance:
1376 * <TYPE> <INSTANCE> <SIZE> <CONTENTS>
1378 * <TYPE> - 2-byte object type as hex
1379 * <INSTANCE> - 2-byte object instance number as hex
1380 * <SIZE> - 2-byte object size as hex
1381 * <CONTENTS> - array of <SIZE> 1-byte hex values
1383 static int mxt_update_cfg(struct mxt_data
*data
, const struct firmware
*cfg
)
1385 struct device
*dev
= &data
->client
->dev
;
1386 struct mxt_info cfg_info
;
1392 u32 info_crc
, config_crc
, calculated_crc
;
1394 size_t config_mem_size
;
1396 mxt_update_crc(data
, MXT_COMMAND_REPORTALL
, 1);
1398 if (strncmp(cfg
->data
, MXT_CFG_MAGIC
, strlen(MXT_CFG_MAGIC
))) {
1399 dev_err(dev
, "Unrecognised config file\n");
1403 data_pos
= strlen(MXT_CFG_MAGIC
);
1405 /* Load information block and check */
1406 for (i
= 0; i
< sizeof(struct mxt_info
); i
++) {
1407 ret
= sscanf(cfg
->data
+ data_pos
, "%hhx%n",
1408 (unsigned char *)&cfg_info
+ i
,
1411 dev_err(dev
, "Bad format\n");
1418 if (cfg_info
.family_id
!= data
->info
.family_id
) {
1419 dev_err(dev
, "Family ID mismatch!\n");
1423 if (cfg_info
.variant_id
!= data
->info
.variant_id
) {
1424 dev_err(dev
, "Variant ID mismatch!\n");
1429 ret
= sscanf(cfg
->data
+ data_pos
, "%x%n", &info_crc
, &offset
);
1431 dev_err(dev
, "Bad format: failed to parse Info CRC\n");
1436 ret
= sscanf(cfg
->data
+ data_pos
, "%x%n", &config_crc
, &offset
);
1438 dev_err(dev
, "Bad format: failed to parse Config CRC\n");
1444 * The Info Block CRC is calculated over mxt_info and the object
1445 * table. If it does not match then we are trying to load the
1446 * configuration from a different chip or firmware version, so
1447 * the configuration CRC is invalid anyway.
1449 if (info_crc
== data
->info_crc
) {
1450 if (config_crc
== 0 || data
->config_crc
== 0) {
1451 dev_info(dev
, "CRC zero, attempting to apply config\n");
1452 } else if (config_crc
== data
->config_crc
) {
1453 dev_dbg(dev
, "Config CRC 0x%06X: OK\n",
1457 dev_info(dev
, "Config CRC 0x%06X: does not match file 0x%06X\n",
1458 data
->config_crc
, config_crc
);
1462 "Warning: Info CRC error - device=0x%06X file=0x%06X\n",
1463 data
->info_crc
, info_crc
);
1466 /* Malloc memory to store configuration */
1467 cfg_start_ofs
= MXT_OBJECT_START
+
1468 data
->info
.object_num
* sizeof(struct mxt_object
) +
1469 MXT_INFO_CHECKSUM_SIZE
;
1470 config_mem_size
= data
->mem_size
- cfg_start_ofs
;
1471 config_mem
= kzalloc(config_mem_size
, GFP_KERNEL
);
1473 dev_err(dev
, "Failed to allocate memory\n");
1477 ret
= mxt_prepare_cfg_mem(data
, cfg
, data_pos
, cfg_start_ofs
,
1478 config_mem
, config_mem_size
);
1482 /* Calculate crc of the received configs (not the raw config file) */
1483 if (data
->T7_address
< cfg_start_ofs
) {
1484 dev_err(dev
, "Bad T7 address, T7addr = %x, config offset %x\n",
1485 data
->T7_address
, cfg_start_ofs
);
1490 calculated_crc
= mxt_calculate_crc(config_mem
,
1491 data
->T7_address
- cfg_start_ofs
,
1494 if (config_crc
> 0 && config_crc
!= calculated_crc
)
1495 dev_warn(dev
, "Config CRC error, calculated=%06X, file=%06X\n",
1496 calculated_crc
, config_crc
);
1498 ret
= mxt_upload_cfg_mem(data
, cfg_start_ofs
,
1499 config_mem
, config_mem_size
);
1503 mxt_update_crc(data
, MXT_COMMAND_BACKUPNV
, MXT_BACKUP_VALUE
);
1505 ret
= mxt_soft_reset(data
);
1509 dev_info(dev
, "Config successfully updated\n");
1516 static int mxt_acquire_irq(struct mxt_data
*data
)
1520 enable_irq(data
->irq
);
1522 error
= mxt_process_messages_until_invalid(data
);
1529 static int mxt_get_info(struct mxt_data
*data
)
1531 struct i2c_client
*client
= data
->client
;
1532 struct mxt_info
*info
= &data
->info
;
1535 /* Read 7-byte info block starting at address 0 */
1536 error
= __mxt_read_reg(client
, MXT_INFO
, sizeof(*info
), info
);
1543 static void mxt_free_input_device(struct mxt_data
*data
)
1545 if (data
->input_dev
) {
1546 input_unregister_device(data
->input_dev
);
1547 data
->input_dev
= NULL
;
1551 static void mxt_free_object_table(struct mxt_data
*data
)
1553 kfree(data
->object_table
);
1554 data
->object_table
= NULL
;
1555 kfree(data
->msg_buf
);
1556 data
->msg_buf
= NULL
;
1557 data
->T5_address
= 0;
1558 data
->T5_msg_size
= 0;
1559 data
->T6_reportid
= 0;
1560 data
->T7_address
= 0;
1561 data
->T9_reportid_min
= 0;
1562 data
->T9_reportid_max
= 0;
1563 data
->T19_reportid
= 0;
1564 data
->T44_address
= 0;
1565 data
->T100_reportid_min
= 0;
1566 data
->T100_reportid_max
= 0;
1567 data
->max_reportid
= 0;
1570 static int mxt_get_object_table(struct mxt_data
*data
)
1572 struct i2c_client
*client
= data
->client
;
1574 struct mxt_object
*object_table
;
1580 table_size
= data
->info
.object_num
* sizeof(struct mxt_object
);
1581 object_table
= kzalloc(table_size
, GFP_KERNEL
);
1582 if (!object_table
) {
1583 dev_err(&data
->client
->dev
, "Failed to allocate memory\n");
1587 error
= __mxt_read_reg(client
, MXT_OBJECT_START
, table_size
,
1590 kfree(object_table
);
1594 /* Valid Report IDs start counting from 1 */
1597 for (i
= 0; i
< data
->info
.object_num
; i
++) {
1598 struct mxt_object
*object
= object_table
+ i
;
1601 le16_to_cpus(&object
->start_address
);
1603 if (object
->num_report_ids
) {
1605 reportid
+= object
->num_report_ids
*
1606 mxt_obj_instances(object
);
1607 max_id
= reportid
- 1;
1613 dev_dbg(&data
->client
->dev
,
1614 "T%u Start:%u Size:%zu Instances:%zu Report IDs:%u-%u\n",
1615 object
->type
, object
->start_address
,
1616 mxt_obj_size(object
), mxt_obj_instances(object
),
1619 switch (object
->type
) {
1620 case MXT_GEN_MESSAGE_T5
:
1621 if (data
->info
.family_id
== 0x80 &&
1622 data
->info
.version
< 0x20) {
1624 * On mXT224 firmware versions prior to V2.0
1625 * read and discard unused CRC byte otherwise
1626 * DMA reads are misaligned.
1628 data
->T5_msg_size
= mxt_obj_size(object
);
1630 /* CRC not enabled, so skip last byte */
1631 data
->T5_msg_size
= mxt_obj_size(object
) - 1;
1633 data
->T5_address
= object
->start_address
;
1635 case MXT_GEN_COMMAND_T6
:
1636 data
->T6_reportid
= min_id
;
1637 data
->T6_address
= object
->start_address
;
1639 case MXT_GEN_POWER_T7
:
1640 data
->T7_address
= object
->start_address
;
1642 case MXT_TOUCH_MULTI_T9
:
1643 data
->multitouch
= MXT_TOUCH_MULTI_T9
;
1644 data
->T9_reportid_min
= min_id
;
1645 data
->T9_reportid_max
= max_id
;
1646 data
->num_touchids
= object
->num_report_ids
1647 * mxt_obj_instances(object
);
1649 case MXT_SPT_MESSAGECOUNT_T44
:
1650 data
->T44_address
= object
->start_address
;
1652 case MXT_SPT_GPIOPWM_T19
:
1653 data
->T19_reportid
= min_id
;
1655 case MXT_TOUCH_MULTITOUCHSCREEN_T100
:
1656 data
->multitouch
= MXT_TOUCH_MULTITOUCHSCREEN_T100
;
1657 data
->T100_reportid_min
= min_id
;
1658 data
->T100_reportid_max
= max_id
;
1659 /* first two report IDs reserved */
1660 data
->num_touchids
= object
->num_report_ids
- 2;
1664 end_address
= object
->start_address
1665 + mxt_obj_size(object
) * mxt_obj_instances(object
) - 1;
1667 if (end_address
>= data
->mem_size
)
1668 data
->mem_size
= end_address
+ 1;
1671 /* Store maximum reportid */
1672 data
->max_reportid
= reportid
;
1674 /* If T44 exists, T5 position has to be directly after */
1675 if (data
->T44_address
&& (data
->T5_address
!= data
->T44_address
+ 1)) {
1676 dev_err(&client
->dev
, "Invalid T44 position\n");
1678 goto free_object_table
;
1681 data
->msg_buf
= kcalloc(data
->max_reportid
,
1682 data
->T5_msg_size
, GFP_KERNEL
);
1683 if (!data
->msg_buf
) {
1684 dev_err(&client
->dev
, "Failed to allocate message buffer\n");
1686 goto free_object_table
;
1689 data
->object_table
= object_table
;
1694 mxt_free_object_table(data
);
1698 static int mxt_read_t9_resolution(struct mxt_data
*data
)
1700 struct i2c_client
*client
= data
->client
;
1702 struct t9_range range
;
1703 unsigned char orient
;
1704 struct mxt_object
*object
;
1706 object
= mxt_get_object(data
, MXT_TOUCH_MULTI_T9
);
1710 error
= __mxt_read_reg(client
,
1711 object
->start_address
+ MXT_T9_RANGE
,
1712 sizeof(range
), &range
);
1716 le16_to_cpus(&range
.x
);
1717 le16_to_cpus(&range
.y
);
1719 error
= __mxt_read_reg(client
,
1720 object
->start_address
+ MXT_T9_ORIENT
,
1725 /* Handle default values */
1732 if (orient
& MXT_T9_ORIENT_SWITCH
) {
1733 data
->max_x
= range
.y
;
1734 data
->max_y
= range
.x
;
1736 data
->max_x
= range
.x
;
1737 data
->max_y
= range
.y
;
1740 dev_dbg(&client
->dev
,
1741 "Touchscreen size X%uY%u\n", data
->max_x
, data
->max_y
);
1746 static int mxt_read_t100_config(struct mxt_data
*data
)
1748 struct i2c_client
*client
= data
->client
;
1750 struct mxt_object
*object
;
1751 u16 range_x
, range_y
;
1755 object
= mxt_get_object(data
, MXT_TOUCH_MULTITOUCHSCREEN_T100
);
1759 error
= __mxt_read_reg(client
,
1760 object
->start_address
+ MXT_T100_XRANGE
,
1761 sizeof(range_x
), &range_x
);
1765 le16_to_cpus(&range_x
);
1767 error
= __mxt_read_reg(client
,
1768 object
->start_address
+ MXT_T100_YRANGE
,
1769 sizeof(range_y
), &range_y
);
1773 le16_to_cpus(&range_y
);
1775 error
= __mxt_read_reg(client
,
1776 object
->start_address
+ MXT_T100_CFG1
,
1781 error
= __mxt_read_reg(client
,
1782 object
->start_address
+ MXT_T100_TCHAUX
,
1787 /* Handle default values */
1794 if (cfg
& MXT_T100_CFG_SWITCHXY
) {
1795 data
->max_x
= range_y
;
1796 data
->max_y
= range_x
;
1798 data
->max_x
= range_x
;
1799 data
->max_y
= range_y
;
1802 /* allocate aux bytes */
1805 if (tchaux
& MXT_T100_TCHAUX_VECT
)
1806 data
->t100_aux_vect
= aux
++;
1808 if (tchaux
& MXT_T100_TCHAUX_AMPL
)
1809 data
->t100_aux_ampl
= aux
++;
1811 if (tchaux
& MXT_T100_TCHAUX_AREA
)
1812 data
->t100_aux_area
= aux
++;
1814 dev_dbg(&client
->dev
,
1815 "T100 aux mappings vect:%u ampl:%u area:%u\n",
1816 data
->t100_aux_vect
, data
->t100_aux_ampl
, data
->t100_aux_area
);
1818 dev_info(&client
->dev
,
1819 "T100 Touchscreen size X%uY%u\n", data
->max_x
, data
->max_y
);
1824 static int mxt_input_open(struct input_dev
*dev
);
1825 static void mxt_input_close(struct input_dev
*dev
);
1827 static void mxt_set_up_as_touchpad(struct input_dev
*input_dev
,
1828 struct mxt_data
*data
)
1830 const struct mxt_platform_data
*pdata
= data
->pdata
;
1833 input_dev
->name
= "Atmel maXTouch Touchpad";
1835 __set_bit(INPUT_PROP_BUTTONPAD
, input_dev
->propbit
);
1837 input_abs_set_res(input_dev
, ABS_X
, MXT_PIXELS_PER_MM
);
1838 input_abs_set_res(input_dev
, ABS_Y
, MXT_PIXELS_PER_MM
);
1839 input_abs_set_res(input_dev
, ABS_MT_POSITION_X
,
1841 input_abs_set_res(input_dev
, ABS_MT_POSITION_Y
,
1844 for (i
= 0; i
< pdata
->t19_num_keys
; i
++)
1845 if (pdata
->t19_keymap
[i
] != KEY_RESERVED
)
1846 input_set_capability(input_dev
, EV_KEY
,
1847 pdata
->t19_keymap
[i
]);
1850 static int mxt_initialize_input_device(struct mxt_data
*data
)
1852 const struct mxt_platform_data
*pdata
= data
->pdata
;
1853 struct device
*dev
= &data
->client
->dev
;
1854 struct input_dev
*input_dev
;
1856 unsigned int num_mt_slots
;
1857 unsigned int mt_flags
= 0;
1859 switch (data
->multitouch
) {
1860 case MXT_TOUCH_MULTI_T9
:
1861 num_mt_slots
= data
->T9_reportid_max
- data
->T9_reportid_min
+ 1;
1862 error
= mxt_read_t9_resolution(data
);
1864 dev_warn(dev
, "Failed to initialize T9 resolution\n");
1867 case MXT_TOUCH_MULTITOUCHSCREEN_T100
:
1868 num_mt_slots
= data
->num_touchids
;
1869 error
= mxt_read_t100_config(data
);
1871 dev_warn(dev
, "Failed to read T100 config\n");
1875 dev_err(dev
, "Invalid multitouch object\n");
1879 input_dev
= input_allocate_device();
1881 dev_err(dev
, "Failed to allocate memory\n");
1885 input_dev
->name
= "Atmel maXTouch Touchscreen";
1886 input_dev
->phys
= data
->phys
;
1887 input_dev
->id
.bustype
= BUS_I2C
;
1888 input_dev
->dev
.parent
= dev
;
1889 input_dev
->open
= mxt_input_open
;
1890 input_dev
->close
= mxt_input_close
;
1892 input_set_capability(input_dev
, EV_KEY
, BTN_TOUCH
);
1894 /* For single touch */
1895 input_set_abs_params(input_dev
, ABS_X
, 0, data
->max_x
, 0, 0);
1896 input_set_abs_params(input_dev
, ABS_Y
, 0, data
->max_y
, 0, 0);
1898 if (data
->multitouch
== MXT_TOUCH_MULTI_T9
||
1899 (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1900 data
->t100_aux_ampl
)) {
1901 input_set_abs_params(input_dev
, ABS_PRESSURE
, 0, 255, 0, 0);
1904 /* If device has buttons we assume it is a touchpad */
1905 if (pdata
->t19_num_keys
) {
1906 mxt_set_up_as_touchpad(input_dev
, data
);
1907 mt_flags
|= INPUT_MT_POINTER
;
1910 /* For multi touch */
1911 error
= input_mt_init_slots(input_dev
, num_mt_slots
, mt_flags
);
1913 dev_err(dev
, "Error %d initialising slots\n", error
);
1917 if (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
) {
1918 input_set_abs_params(input_dev
, ABS_MT_TOOL_TYPE
,
1919 0, MT_TOOL_MAX
, 0, 0);
1920 input_set_abs_params(input_dev
, ABS_MT_DISTANCE
,
1921 MXT_DISTANCE_ACTIVE_TOUCH
,
1922 MXT_DISTANCE_HOVERING
,
1926 input_set_abs_params(input_dev
, ABS_MT_POSITION_X
,
1927 0, data
->max_x
, 0, 0);
1928 input_set_abs_params(input_dev
, ABS_MT_POSITION_Y
,
1929 0, data
->max_y
, 0, 0);
1931 if (data
->multitouch
== MXT_TOUCH_MULTI_T9
||
1932 (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1933 data
->t100_aux_area
)) {
1934 input_set_abs_params(input_dev
, ABS_MT_TOUCH_MAJOR
,
1935 0, MXT_MAX_AREA
, 0, 0);
1938 if (data
->multitouch
== MXT_TOUCH_MULTI_T9
||
1939 (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1940 data
->t100_aux_ampl
)) {
1941 input_set_abs_params(input_dev
, ABS_MT_PRESSURE
,
1945 if (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1946 data
->t100_aux_vect
) {
1947 input_set_abs_params(input_dev
, ABS_MT_ORIENTATION
,
1951 if (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1952 data
->t100_aux_ampl
) {
1953 input_set_abs_params(input_dev
, ABS_MT_PRESSURE
,
1957 if (data
->multitouch
== MXT_TOUCH_MULTITOUCHSCREEN_T100
&&
1958 data
->t100_aux_vect
) {
1959 input_set_abs_params(input_dev
, ABS_MT_ORIENTATION
,
1963 input_set_drvdata(input_dev
, data
);
1965 error
= input_register_device(input_dev
);
1967 dev_err(dev
, "Error %d registering input device\n", error
);
1971 data
->input_dev
= input_dev
;
1976 input_free_device(input_dev
);
1980 static int mxt_configure_objects(struct mxt_data
*data
,
1981 const struct firmware
*cfg
);
1983 static void mxt_config_cb(const struct firmware
*cfg
, void *ctx
)
1985 mxt_configure_objects(ctx
, cfg
);
1986 release_firmware(cfg
);
1989 static int mxt_initialize(struct mxt_data
*data
)
1991 struct i2c_client
*client
= data
->client
;
1992 int recovery_attempts
= 0;
1996 error
= mxt_get_info(data
);
2000 /* Check bootloader state */
2001 error
= mxt_probe_bootloader(data
, false);
2003 dev_info(&client
->dev
, "Trying alternate bootloader address\n");
2004 error
= mxt_probe_bootloader(data
, true);
2006 /* Chip is not in appmode or bootloader mode */
2011 /* OK, we are in bootloader, see if we can recover */
2012 if (++recovery_attempts
> 1) {
2013 dev_err(&client
->dev
, "Could not recover from bootloader mode\n");
2015 * We can reflash from this state, so do not
2016 * abort initialization.
2018 data
->in_bootloader
= true;
2022 /* Attempt to exit bootloader into app mode */
2023 mxt_send_bootloader_cmd(data
, false);
2024 msleep(MXT_FW_RESET_TIME
);
2027 /* Get object table information */
2028 error
= mxt_get_object_table(data
);
2030 dev_err(&client
->dev
, "Error %d reading object table\n", error
);
2034 error
= mxt_acquire_irq(data
);
2036 goto err_free_object_table
;
2038 error
= request_firmware_nowait(THIS_MODULE
, true, MXT_CFG_NAME
,
2039 &client
->dev
, GFP_KERNEL
, data
,
2042 dev_err(&client
->dev
, "Failed to invoke firmware loader: %d\n",
2044 goto err_free_object_table
;
2049 err_free_object_table
:
2050 mxt_free_object_table(data
);
2054 static int mxt_configure_objects(struct mxt_data
*data
,
2055 const struct firmware
*cfg
)
2057 struct device
*dev
= &data
->client
->dev
;
2058 struct mxt_info
*info
= &data
->info
;
2062 error
= mxt_update_cfg(data
, cfg
);
2064 dev_warn(dev
, "Error %d updating config\n", error
);
2067 if (data
->multitouch
) {
2068 error
= mxt_initialize_input_device(data
);
2072 dev_warn(dev
, "No touch object detected\n");
2076 "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n",
2077 info
->family_id
, info
->variant_id
, info
->version
>> 4,
2078 info
->version
& 0xf, info
->build
, info
->object_num
);
2083 /* Firmware Version is returned as Major.Minor.Build */
2084 static ssize_t
mxt_fw_version_show(struct device
*dev
,
2085 struct device_attribute
*attr
, char *buf
)
2087 struct mxt_data
*data
= dev_get_drvdata(dev
);
2088 struct mxt_info
*info
= &data
->info
;
2089 return scnprintf(buf
, PAGE_SIZE
, "%u.%u.%02X\n",
2090 info
->version
>> 4, info
->version
& 0xf, info
->build
);
2093 /* Hardware Version is returned as FamilyID.VariantID */
2094 static ssize_t
mxt_hw_version_show(struct device
*dev
,
2095 struct device_attribute
*attr
, char *buf
)
2097 struct mxt_data
*data
= dev_get_drvdata(dev
);
2098 struct mxt_info
*info
= &data
->info
;
2099 return scnprintf(buf
, PAGE_SIZE
, "%u.%u\n",
2100 info
->family_id
, info
->variant_id
);
2103 static ssize_t
mxt_show_instance(char *buf
, int count
,
2104 struct mxt_object
*object
, int instance
,
2109 if (mxt_obj_instances(object
) > 1)
2110 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
2111 "Instance %u\n", instance
);
2113 for (i
= 0; i
< mxt_obj_size(object
); i
++)
2114 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
2115 "\t[%2u]: %02x (%d)\n", i
, val
[i
], val
[i
]);
2116 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
, "\n");
2121 static ssize_t
mxt_object_show(struct device
*dev
,
2122 struct device_attribute
*attr
, char *buf
)
2124 struct mxt_data
*data
= dev_get_drvdata(dev
);
2125 struct mxt_object
*object
;
2131 /* Pre-allocate buffer large enough to hold max sized object. */
2132 obuf
= kmalloc(256, GFP_KERNEL
);
2137 for (i
= 0; i
< data
->info
.object_num
; i
++) {
2138 object
= data
->object_table
+ i
;
2140 if (!mxt_object_readable(object
->type
))
2143 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
2144 "T%u:\n", object
->type
);
2146 for (j
= 0; j
< mxt_obj_instances(object
); j
++) {
2147 u16 size
= mxt_obj_size(object
);
2148 u16 addr
= object
->start_address
+ j
* size
;
2150 error
= __mxt_read_reg(data
->client
, addr
, size
, obuf
);
2154 count
= mxt_show_instance(buf
, count
, object
, j
, obuf
);
2160 return error
?: count
;
2163 static int mxt_check_firmware_format(struct device
*dev
,
2164 const struct firmware
*fw
)
2166 unsigned int pos
= 0;
2169 while (pos
< fw
->size
) {
2170 c
= *(fw
->data
+ pos
);
2172 if (c
< '0' || (c
> '9' && c
< 'A') || c
> 'F')
2179 * To convert file try:
2180 * xxd -r -p mXTXXX__APP_VX-X-XX.enc > maxtouch.fw
2182 dev_err(dev
, "Aborting: firmware file must be in binary format\n");
2187 static int mxt_load_fw(struct device
*dev
, const char *fn
)
2189 struct mxt_data
*data
= dev_get_drvdata(dev
);
2190 const struct firmware
*fw
= NULL
;
2191 unsigned int frame_size
;
2192 unsigned int pos
= 0;
2193 unsigned int retry
= 0;
2194 unsigned int frame
= 0;
2197 ret
= request_firmware(&fw
, fn
, dev
);
2199 dev_err(dev
, "Unable to open firmware %s\n", fn
);
2203 /* Check for incorrect enc file */
2204 ret
= mxt_check_firmware_format(dev
, fw
);
2206 goto release_firmware
;
2208 if (!data
->in_bootloader
) {
2209 /* Change to the bootloader mode */
2210 data
->in_bootloader
= true;
2212 ret
= mxt_t6_command(data
, MXT_COMMAND_RESET
,
2213 MXT_BOOT_VALUE
, false);
2215 goto release_firmware
;
2217 msleep(MXT_RESET_TIME
);
2219 /* Do not need to scan since we know family ID */
2220 ret
= mxt_lookup_bootloader_address(data
, 0);
2222 goto release_firmware
;
2224 mxt_free_input_device(data
);
2225 mxt_free_object_table(data
);
2227 enable_irq(data
->irq
);
2230 reinit_completion(&data
->bl_completion
);
2232 ret
= mxt_check_bootloader(data
, MXT_WAITING_BOOTLOAD_CMD
, false);
2234 /* Bootloader may still be unlocked from previous attempt */
2235 ret
= mxt_check_bootloader(data
, MXT_WAITING_FRAME_DATA
, false);
2239 dev_info(dev
, "Unlocking bootloader\n");
2241 /* Unlock bootloader */
2242 ret
= mxt_send_bootloader_cmd(data
, true);
2247 while (pos
< fw
->size
) {
2248 ret
= mxt_check_bootloader(data
, MXT_WAITING_FRAME_DATA
, true);
2252 frame_size
= ((*(fw
->data
+ pos
) << 8) | *(fw
->data
+ pos
+ 1));
2254 /* Take account of CRC bytes */
2257 /* Write one frame to device */
2258 ret
= mxt_bootloader_write(data
, fw
->data
+ pos
, frame_size
);
2262 ret
= mxt_check_bootloader(data
, MXT_FRAME_CRC_PASS
, true);
2266 /* Back off by 20ms per retry */
2270 dev_err(dev
, "Retry count exceeded\n");
2279 if (frame
% 50 == 0)
2280 dev_dbg(dev
, "Sent %d frames, %d/%zd bytes\n",
2281 frame
, pos
, fw
->size
);
2284 /* Wait for flash. */
2285 ret
= mxt_wait_for_completion(data
, &data
->bl_completion
,
2290 dev_dbg(dev
, "Sent %d frames, %d bytes\n", frame
, pos
);
2293 * Wait for device to reset. Some bootloader versions do not assert
2294 * the CHG line after bootloading has finished, so ignore potential
2297 mxt_wait_for_completion(data
, &data
->bl_completion
, MXT_FW_RESET_TIME
);
2299 data
->in_bootloader
= false;
2302 disable_irq(data
->irq
);
2304 release_firmware(fw
);
2308 static ssize_t
mxt_update_fw_store(struct device
*dev
,
2309 struct device_attribute
*attr
,
2310 const char *buf
, size_t count
)
2312 struct mxt_data
*data
= dev_get_drvdata(dev
);
2315 error
= mxt_load_fw(dev
, MXT_FW_NAME
);
2317 dev_err(dev
, "The firmware update failed(%d)\n", error
);
2320 dev_info(dev
, "The firmware update succeeded\n");
2322 error
= mxt_initialize(data
);
2330 static DEVICE_ATTR(fw_version
, S_IRUGO
, mxt_fw_version_show
, NULL
);
2331 static DEVICE_ATTR(hw_version
, S_IRUGO
, mxt_hw_version_show
, NULL
);
2332 static DEVICE_ATTR(object
, S_IRUGO
, mxt_object_show
, NULL
);
2333 static DEVICE_ATTR(update_fw
, S_IWUSR
, NULL
, mxt_update_fw_store
);
2335 static struct attribute
*mxt_attrs
[] = {
2336 &dev_attr_fw_version
.attr
,
2337 &dev_attr_hw_version
.attr
,
2338 &dev_attr_object
.attr
,
2339 &dev_attr_update_fw
.attr
,
2343 static const struct attribute_group mxt_attr_group
= {
2347 static void mxt_start(struct mxt_data
*data
)
2350 mxt_write_object(data
, data
->multitouch
, MXT_TOUCH_CTRL
, 0x83);
2353 static void mxt_stop(struct mxt_data
*data
)
2356 mxt_write_object(data
, data
->multitouch
, MXT_TOUCH_CTRL
, 0);
2359 static int mxt_input_open(struct input_dev
*dev
)
2361 struct mxt_data
*data
= input_get_drvdata(dev
);
2368 static void mxt_input_close(struct input_dev
*dev
)
2370 struct mxt_data
*data
= input_get_drvdata(dev
);
2376 static const struct mxt_platform_data
*mxt_parse_dt(struct i2c_client
*client
)
2378 struct mxt_platform_data
*pdata
;
2381 int proplen
, i
, ret
;
2383 if (!client
->dev
.of_node
)
2384 return ERR_PTR(-ENOENT
);
2386 pdata
= devm_kzalloc(&client
->dev
, sizeof(*pdata
), GFP_KERNEL
);
2388 return ERR_PTR(-ENOMEM
);
2390 if (of_find_property(client
->dev
.of_node
, "linux,gpio-keymap",
2392 pdata
->t19_num_keys
= proplen
/ sizeof(u32
);
2394 keymap
= devm_kzalloc(&client
->dev
,
2395 pdata
->t19_num_keys
* sizeof(keymap
[0]),
2398 return ERR_PTR(-ENOMEM
);
2400 for (i
= 0; i
< pdata
->t19_num_keys
; i
++) {
2401 ret
= of_property_read_u32_index(client
->dev
.of_node
,
2402 "linux,gpio-keymap", i
, &keycode
);
2404 keycode
= KEY_RESERVED
;
2406 keymap
[i
] = keycode
;
2409 pdata
->t19_keymap
= keymap
;
2415 static const struct mxt_platform_data
*mxt_parse_dt(struct i2c_client
*client
)
2417 return ERR_PTR(-ENOENT
);
2423 struct mxt_acpi_platform_data
{
2425 struct mxt_platform_data pdata
;
2428 static unsigned int samus_touchpad_buttons
[] = {
2435 static struct mxt_acpi_platform_data samus_platform_data
[] = {
2440 .t19_num_keys
= ARRAY_SIZE(samus_touchpad_buttons
),
2441 .t19_keymap
= samus_touchpad_buttons
,
2451 static const struct dmi_system_id mxt_dmi_table
[] = {
2453 /* 2015 Google Pixel */
2454 .ident
= "Chromebook Pixel 2",
2456 DMI_MATCH(DMI_SYS_VENDOR
, "GOOGLE"),
2457 DMI_MATCH(DMI_PRODUCT_NAME
, "Samus"),
2459 .driver_data
= samus_platform_data
,
2464 static const struct mxt_platform_data
*mxt_parse_acpi(struct i2c_client
*client
)
2466 struct acpi_device
*adev
;
2467 const struct dmi_system_id
*system_id
;
2468 const struct mxt_acpi_platform_data
*acpi_pdata
;
2471 * Ignore ACPI devices representing bootloader mode.
2473 * This is a bit of a hack: Google Chromebook BIOS creates ACPI
2474 * devices for both application and bootloader modes, but we are
2475 * interested in application mode only (if device is in bootloader
2476 * mode we'll end up switching into application anyway). So far
2477 * application mode addresses were all above 0x40, so we'll use it
2480 if (client
->addr
< 0x40)
2481 return ERR_PTR(-ENXIO
);
2483 adev
= ACPI_COMPANION(&client
->dev
);
2485 return ERR_PTR(-ENOENT
);
2487 system_id
= dmi_first_match(mxt_dmi_table
);
2489 return ERR_PTR(-ENOENT
);
2491 acpi_pdata
= system_id
->driver_data
;
2493 return ERR_PTR(-ENOENT
);
2495 while (acpi_pdata
->hid
) {
2496 if (!strcmp(acpi_device_hid(adev
), acpi_pdata
->hid
))
2497 return &acpi_pdata
->pdata
;
2502 return ERR_PTR(-ENOENT
);
2505 static const struct mxt_platform_data
*mxt_parse_acpi(struct i2c_client
*client
)
2507 return ERR_PTR(-ENOENT
);
2511 static const struct mxt_platform_data
*
2512 mxt_get_platform_data(struct i2c_client
*client
)
2514 const struct mxt_platform_data
*pdata
;
2516 pdata
= dev_get_platdata(&client
->dev
);
2520 pdata
= mxt_parse_dt(client
);
2521 if (!IS_ERR(pdata
) || PTR_ERR(pdata
) != -ENOENT
)
2524 pdata
= mxt_parse_acpi(client
);
2525 if (!IS_ERR(pdata
) || PTR_ERR(pdata
) != -ENOENT
)
2528 dev_err(&client
->dev
, "No platform data specified\n");
2529 return ERR_PTR(-EINVAL
);
2532 static int mxt_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
2534 struct mxt_data
*data
;
2535 const struct mxt_platform_data
*pdata
;
2538 pdata
= mxt_get_platform_data(client
);
2540 return PTR_ERR(pdata
);
2542 data
= kzalloc(sizeof(struct mxt_data
), GFP_KERNEL
);
2544 dev_err(&client
->dev
, "Failed to allocate memory\n");
2548 snprintf(data
->phys
, sizeof(data
->phys
), "i2c-%u-%04x/input0",
2549 client
->adapter
->nr
, client
->addr
);
2551 data
->client
= client
;
2552 data
->pdata
= pdata
;
2553 data
->irq
= client
->irq
;
2554 i2c_set_clientdata(client
, data
);
2556 init_completion(&data
->bl_completion
);
2557 init_completion(&data
->reset_completion
);
2558 init_completion(&data
->crc_completion
);
2560 error
= request_threaded_irq(client
->irq
, NULL
, mxt_interrupt
,
2561 pdata
->irqflags
| IRQF_ONESHOT
,
2562 client
->name
, data
);
2564 dev_err(&client
->dev
, "Failed to register interrupt\n");
2568 disable_irq(client
->irq
);
2570 error
= mxt_initialize(data
);
2574 error
= sysfs_create_group(&client
->dev
.kobj
, &mxt_attr_group
);
2576 dev_err(&client
->dev
, "Failure %d creating sysfs group\n",
2578 goto err_free_object
;
2584 mxt_free_input_device(data
);
2585 mxt_free_object_table(data
);
2587 free_irq(client
->irq
, data
);
2593 static int mxt_remove(struct i2c_client
*client
)
2595 struct mxt_data
*data
= i2c_get_clientdata(client
);
2597 sysfs_remove_group(&client
->dev
.kobj
, &mxt_attr_group
);
2598 free_irq(data
->irq
, data
);
2599 mxt_free_input_device(data
);
2600 mxt_free_object_table(data
);
2606 static int __maybe_unused
mxt_suspend(struct device
*dev
)
2608 struct i2c_client
*client
= to_i2c_client(dev
);
2609 struct mxt_data
*data
= i2c_get_clientdata(client
);
2610 struct input_dev
*input_dev
= data
->input_dev
;
2612 mutex_lock(&input_dev
->mutex
);
2614 if (input_dev
->users
)
2617 mutex_unlock(&input_dev
->mutex
);
2622 static int __maybe_unused
mxt_resume(struct device
*dev
)
2624 struct i2c_client
*client
= to_i2c_client(dev
);
2625 struct mxt_data
*data
= i2c_get_clientdata(client
);
2626 struct input_dev
*input_dev
= data
->input_dev
;
2628 mxt_soft_reset(data
);
2630 mutex_lock(&input_dev
->mutex
);
2632 if (input_dev
->users
)
2635 mutex_unlock(&input_dev
->mutex
);
2640 static SIMPLE_DEV_PM_OPS(mxt_pm_ops
, mxt_suspend
, mxt_resume
);
2642 static const struct of_device_id mxt_of_match
[] = {
2643 { .compatible
= "atmel,maxtouch", },
2646 MODULE_DEVICE_TABLE(of
, mxt_of_match
);
2649 static const struct acpi_device_id mxt_acpi_id
[] = {
2650 { "ATML0000", 0 }, /* Touchpad */
2651 { "ATML0001", 0 }, /* Touchscreen */
2654 MODULE_DEVICE_TABLE(acpi
, mxt_acpi_id
);
2657 static const struct i2c_device_id mxt_id
[] = {
2658 { "qt602240_ts", 0 },
2659 { "atmel_mxt_ts", 0 },
2660 { "atmel_mxt_tp", 0 },
2664 MODULE_DEVICE_TABLE(i2c
, mxt_id
);
2666 static struct i2c_driver mxt_driver
= {
2668 .name
= "atmel_mxt_ts",
2669 .owner
= THIS_MODULE
,
2670 .of_match_table
= of_match_ptr(mxt_of_match
),
2671 .acpi_match_table
= ACPI_PTR(mxt_acpi_id
),
2675 .remove
= mxt_remove
,
2679 module_i2c_driver(mxt_driver
);
2681 /* Module information */
2682 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
2683 MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
2684 MODULE_LICENSE("GPL");