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/module.h>
18 #include <linux/init.h>
19 #include <linux/completion.h>
20 #include <linux/delay.h>
21 #include <linux/firmware.h>
22 #include <linux/i2c.h>
23 #include <linux/i2c/atmel_mxt_ts.h>
24 #include <linux/input/mt.h>
25 #include <linux/interrupt.h>
27 #include <linux/slab.h>
35 #define MXT_FW_NAME "maxtouch.fw"
36 #define MXT_CFG_NAME "maxtouch.cfg"
37 #define MXT_CFG_MAGIC "OBP_RAW V1"
41 #define MXT_FAMILY_ID 0x00
42 #define MXT_VARIANT_ID 0x01
43 #define MXT_VERSION 0x02
44 #define MXT_BUILD 0x03
45 #define MXT_MATRIX_X_SIZE 0x04
46 #define MXT_MATRIX_Y_SIZE 0x05
47 #define MXT_OBJECT_NUM 0x06
48 #define MXT_OBJECT_START 0x07
50 #define MXT_OBJECT_SIZE 6
51 #define MXT_INFO_CHECKSUM_SIZE 3
52 #define MXT_MAX_BLOCK_WRITE 256
55 #define MXT_DEBUG_DIAGNOSTIC_T37 37
56 #define MXT_GEN_MESSAGE_T5 5
57 #define MXT_GEN_COMMAND_T6 6
58 #define MXT_GEN_POWER_T7 7
59 #define MXT_GEN_ACQUIRE_T8 8
60 #define MXT_GEN_DATASOURCE_T53 53
61 #define MXT_TOUCH_MULTI_T9 9
62 #define MXT_TOUCH_KEYARRAY_T15 15
63 #define MXT_TOUCH_PROXIMITY_T23 23
64 #define MXT_TOUCH_PROXKEY_T52 52
65 #define MXT_PROCI_GRIPFACE_T20 20
66 #define MXT_PROCG_NOISE_T22 22
67 #define MXT_PROCI_ONETOUCH_T24 24
68 #define MXT_PROCI_TWOTOUCH_T27 27
69 #define MXT_PROCI_GRIP_T40 40
70 #define MXT_PROCI_PALM_T41 41
71 #define MXT_PROCI_TOUCHSUPPRESSION_T42 42
72 #define MXT_PROCI_STYLUS_T47 47
73 #define MXT_PROCG_NOISESUPPRESSION_T48 48
74 #define MXT_SPT_COMMSCONFIG_T18 18
75 #define MXT_SPT_GPIOPWM_T19 19
76 #define MXT_SPT_SELFTEST_T25 25
77 #define MXT_SPT_CTECONFIG_T28 28
78 #define MXT_SPT_USERDATA_T38 38
79 #define MXT_SPT_DIGITIZER_T43 43
80 #define MXT_SPT_MESSAGECOUNT_T44 44
81 #define MXT_SPT_CTECONFIG_T46 46
83 /* MXT_GEN_COMMAND_T6 field */
84 #define MXT_COMMAND_RESET 0
85 #define MXT_COMMAND_BACKUPNV 1
86 #define MXT_COMMAND_CALIBRATE 2
87 #define MXT_COMMAND_REPORTALL 3
88 #define MXT_COMMAND_DIAGNOSTIC 5
90 /* Define for T6 status byte */
91 #define MXT_T6_STATUS_RESET (1 << 7)
93 /* MXT_GEN_POWER_T7 field */
94 #define MXT_POWER_IDLEACQINT 0
95 #define MXT_POWER_ACTVACQINT 1
96 #define MXT_POWER_ACTV2IDLETO 2
98 /* MXT_GEN_ACQUIRE_T8 field */
99 #define MXT_ACQUIRE_CHRGTIME 0
100 #define MXT_ACQUIRE_TCHDRIFT 2
101 #define MXT_ACQUIRE_DRIFTST 3
102 #define MXT_ACQUIRE_TCHAUTOCAL 4
103 #define MXT_ACQUIRE_SYNC 5
104 #define MXT_ACQUIRE_ATCHCALST 6
105 #define MXT_ACQUIRE_ATCHCALSTHR 7
107 /* MXT_TOUCH_MULTI_T9 field */
108 #define MXT_TOUCH_CTRL 0
109 #define MXT_T9_ORIENT 9
110 #define MXT_T9_RANGE 18
112 /* MXT_TOUCH_MULTI_T9 status */
113 #define MXT_T9_UNGRIP (1 << 0)
114 #define MXT_T9_SUPPRESS (1 << 1)
115 #define MXT_T9_AMP (1 << 2)
116 #define MXT_T9_VECTOR (1 << 3)
117 #define MXT_T9_MOVE (1 << 4)
118 #define MXT_T9_RELEASE (1 << 5)
119 #define MXT_T9_PRESS (1 << 6)
120 #define MXT_T9_DETECT (1 << 7)
127 /* MXT_TOUCH_MULTI_T9 orient */
128 #define MXT_T9_ORIENT_SWITCH (1 << 0)
130 /* MXT_PROCI_GRIPFACE_T20 field */
131 #define MXT_GRIPFACE_CTRL 0
132 #define MXT_GRIPFACE_XLOGRIP 1
133 #define MXT_GRIPFACE_XHIGRIP 2
134 #define MXT_GRIPFACE_YLOGRIP 3
135 #define MXT_GRIPFACE_YHIGRIP 4
136 #define MXT_GRIPFACE_MAXTCHS 5
137 #define MXT_GRIPFACE_SZTHR1 7
138 #define MXT_GRIPFACE_SZTHR2 8
139 #define MXT_GRIPFACE_SHPTHR1 9
140 #define MXT_GRIPFACE_SHPTHR2 10
141 #define MXT_GRIPFACE_SUPEXTTO 11
143 /* MXT_PROCI_NOISE field */
144 #define MXT_NOISE_CTRL 0
145 #define MXT_NOISE_OUTFLEN 1
146 #define MXT_NOISE_GCAFUL_LSB 3
147 #define MXT_NOISE_GCAFUL_MSB 4
148 #define MXT_NOISE_GCAFLL_LSB 5
149 #define MXT_NOISE_GCAFLL_MSB 6
150 #define MXT_NOISE_ACTVGCAFVALID 7
151 #define MXT_NOISE_NOISETHR 8
152 #define MXT_NOISE_FREQHOPSCALE 10
153 #define MXT_NOISE_FREQ0 11
154 #define MXT_NOISE_FREQ1 12
155 #define MXT_NOISE_FREQ2 13
156 #define MXT_NOISE_FREQ3 14
157 #define MXT_NOISE_FREQ4 15
158 #define MXT_NOISE_IDLEGCAFVALID 16
160 /* MXT_SPT_COMMSCONFIG_T18 */
161 #define MXT_COMMS_CTRL 0
162 #define MXT_COMMS_CMD 1
164 /* MXT_SPT_CTECONFIG_T28 field */
165 #define MXT_CTE_CTRL 0
166 #define MXT_CTE_CMD 1
167 #define MXT_CTE_MODE 2
168 #define MXT_CTE_IDLEGCAFDEPTH 3
169 #define MXT_CTE_ACTVGCAFDEPTH 4
170 #define MXT_CTE_VOLTAGE 5
172 #define MXT_VOLTAGE_DEFAULT 2700000
173 #define MXT_VOLTAGE_STEP 10000
175 /* Define for MXT_GEN_COMMAND_T6 */
176 #define MXT_BOOT_VALUE 0xa5
177 #define MXT_RESET_VALUE 0x01
178 #define MXT_BACKUP_VALUE 0x55
181 #define MXT_BACKUP_TIME 50 /* msec */
182 #define MXT_RESET_TIME 200 /* msec */
183 #define MXT_RESET_TIMEOUT 3000 /* msec */
184 #define MXT_CRC_TIMEOUT 1000 /* msec */
185 #define MXT_FW_RESET_TIME 3000 /* msec */
186 #define MXT_FW_CHG_TIMEOUT 300 /* msec */
188 /* Command to unlock bootloader */
189 #define MXT_UNLOCK_CMD_MSB 0xaa
190 #define MXT_UNLOCK_CMD_LSB 0xdc
192 /* Bootloader mode status */
193 #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
194 #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
195 #define MXT_FRAME_CRC_CHECK 0x02
196 #define MXT_FRAME_CRC_FAIL 0x03
197 #define MXT_FRAME_CRC_PASS 0x04
198 #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
199 #define MXT_BOOT_STATUS_MASK 0x3f
200 #define MXT_BOOT_EXTENDED_ID (1 << 5)
201 #define MXT_BOOT_ID_MASK 0x1f
203 /* Touchscreen absolute values */
204 #define MXT_MAX_AREA 0xff
206 #define MXT_PIXELS_PER_MM 20
222 u8 instances_minus_one;
231 /* Each client has this additional data */
233 struct i2c_client *client;
234 struct input_dev *input_dev;
235 char phys[64]; /* device physical location */
236 const struct mxt_platform_data *pdata;
237 struct mxt_object *object_table;
238 struct mxt_info info;
248 /* Cached parameters from object table */
256 /* for fw update in bootloader */
257 struct completion bl_completion;
259 /* for reset handling */
260 struct completion reset_completion;
262 /* for config update handling */
263 struct completion crc_completion;
266 static size_t mxt_obj_size(const struct mxt_object *obj)
268 return obj->size_minus_one + 1;
271 static size_t mxt_obj_instances(const struct mxt_object *obj)
273 return obj->instances_minus_one + 1;
276 static bool mxt_object_readable(unsigned int type)
279 case MXT_GEN_COMMAND_T6:
280 case MXT_GEN_POWER_T7:
281 case MXT_GEN_ACQUIRE_T8:
282 case MXT_GEN_DATASOURCE_T53:
283 case MXT_TOUCH_MULTI_T9:
284 case MXT_TOUCH_KEYARRAY_T15:
285 case MXT_TOUCH_PROXIMITY_T23:
286 case MXT_TOUCH_PROXKEY_T52:
287 case MXT_PROCI_GRIPFACE_T20:
288 case MXT_PROCG_NOISE_T22:
289 case MXT_PROCI_ONETOUCH_T24:
290 case MXT_PROCI_TWOTOUCH_T27:
291 case MXT_PROCI_GRIP_T40:
292 case MXT_PROCI_PALM_T41:
293 case MXT_PROCI_TOUCHSUPPRESSION_T42:
294 case MXT_PROCI_STYLUS_T47:
295 case MXT_PROCG_NOISESUPPRESSION_T48:
296 case MXT_SPT_COMMSCONFIG_T18:
297 case MXT_SPT_GPIOPWM_T19:
298 case MXT_SPT_SELFTEST_T25:
299 case MXT_SPT_CTECONFIG_T28:
300 case MXT_SPT_USERDATA_T38:
301 case MXT_SPT_DIGITIZER_T43:
302 case MXT_SPT_CTECONFIG_T46:
309 static void mxt_dump_message(struct device *dev,
310 struct mxt_message *message)
312 dev_dbg(dev, "reportid: %u\tmessage: %*ph\n",
313 message->reportid, 7, message->message);
316 static int mxt_wait_for_completion(struct mxt_data *data,
317 struct completion *comp,
318 unsigned int timeout_ms)
320 struct device *dev = &data->client->dev;
321 unsigned long timeout = msecs_to_jiffies(timeout_ms);
324 ret = wait_for_completion_interruptible_timeout(comp, timeout);
327 } else if (ret == 0) {
328 dev_err(dev, "Wait for completion timed out.\n");
334 static int mxt_bootloader_read(struct mxt_data *data,
335 u8 *val, unsigned int count)
340 msg.addr = data->bootloader_addr;
341 msg.flags = data->client->flags & I2C_M_TEN;
342 msg.flags |= I2C_M_RD;
346 ret = i2c_transfer(data->client->adapter, &msg, 1);
351 ret = ret < 0 ? ret : -EIO;
352 dev_err(&data->client->dev, "%s: i2c recv failed (%d)\n",
359 static int mxt_bootloader_write(struct mxt_data *data,
360 const u8 * const val, unsigned int count)
365 msg.addr = data->bootloader_addr;
366 msg.flags = data->client->flags & I2C_M_TEN;
370 ret = i2c_transfer(data->client->adapter, &msg, 1);
374 ret = ret < 0 ? ret : -EIO;
375 dev_err(&data->client->dev, "%s: i2c send failed (%d)\n",
382 static int mxt_lookup_bootloader_address(struct mxt_data *data)
384 u8 appmode = data->client->addr;
394 bootloader = appmode - 0x26;
397 dev_err(&data->client->dev,
398 "Appmode i2c address 0x%02x not found\n",
403 data->bootloader_addr = bootloader;
407 static int mxt_probe_bootloader(struct mxt_data *data)
409 struct device *dev = &data->client->dev;
414 ret = mxt_lookup_bootloader_address(data);
418 ret = mxt_bootloader_read(data, &val, 1);
422 /* Check app crc fail mode */
423 crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL;
425 dev_err(dev, "Detected bootloader, status:%02X%s\n",
426 val, crc_failure ? ", APP_CRC_FAIL" : "");
431 static u8 mxt_get_bootloader_version(struct mxt_data *data, u8 val)
433 struct device *dev = &data->client->dev;
436 if (val & MXT_BOOT_EXTENDED_ID) {
437 if (mxt_bootloader_read(data, &buf[0], 3) != 0) {
438 dev_err(dev, "%s: i2c failure\n", __func__);
442 dev_dbg(dev, "Bootloader ID:%d Version:%d\n", buf[1], buf[2]);
446 dev_dbg(dev, "Bootloader ID:%d\n", val & MXT_BOOT_ID_MASK);
452 static int mxt_check_bootloader(struct mxt_data *data, unsigned int state)
454 struct device *dev = &data->client->dev;
459 if (state != MXT_WAITING_BOOTLOAD_CMD) {
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_unlock_bootloader(struct mxt_data *data)
519 buf[0] = MXT_UNLOCK_CMD_LSB;
520 buf[1] = MXT_UNLOCK_CMD_MSB;
522 ret = mxt_bootloader_write(data, buf, 2);
529 static int __mxt_read_reg(struct i2c_client *client,
530 u16 reg, u16 len, void *val)
532 struct i2c_msg xfer[2];
537 buf[1] = (reg >> 8) & 0xff;
540 xfer[0].addr = client->addr;
546 xfer[1].addr = client->addr;
547 xfer[1].flags = I2C_M_RD;
551 ret = i2c_transfer(client->adapter, xfer, 2);
557 dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
564 static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
572 buf = kmalloc(count, GFP_KERNEL);
577 buf[1] = (reg >> 8) & 0xff;
578 memcpy(&buf[2], val, len);
580 ret = i2c_master_send(client, buf, count);
586 dev_err(&client->dev, "%s: i2c send failed (%d)\n",
594 static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
596 return __mxt_write_reg(client, reg, 1, &val);
599 static struct mxt_object *
600 mxt_get_object(struct mxt_data *data, u8 type)
602 struct mxt_object *object;
605 for (i = 0; i < data->info.object_num; i++) {
606 object = data->object_table + i;
607 if (object->type == type)
611 dev_warn(&data->client->dev, "Invalid object type T%u\n", type);
615 static int mxt_read_message(struct mxt_data *data,
616 struct mxt_message *message)
618 struct mxt_object *object;
621 object = mxt_get_object(data, MXT_GEN_MESSAGE_T5);
625 reg = object->start_address;
626 return __mxt_read_reg(data->client, reg,
627 sizeof(struct mxt_message), message);
630 static int mxt_write_object(struct mxt_data *data,
631 u8 type, u8 offset, u8 val)
633 struct mxt_object *object;
636 object = mxt_get_object(data, type);
637 if (!object || offset >= mxt_obj_size(object))
640 reg = object->start_address;
641 return mxt_write_reg(data->client, reg + offset, val);
644 static void mxt_input_button(struct mxt_data *data, struct mxt_message *message)
646 struct input_dev *input = data->input_dev;
647 const struct mxt_platform_data *pdata = data->pdata;
651 /* Active-low switch */
652 for (i = 0; i < pdata->t19_num_keys; i++) {
653 if (pdata->t19_keymap[i] == KEY_RESERVED)
655 button = !(message->message[0] & (1 << i));
656 input_report_key(input, pdata->t19_keymap[i], button);
660 static void mxt_input_sync(struct mxt_data *data)
662 input_mt_report_pointer_emulation(data->input_dev,
663 data->pdata->t19_num_keys);
664 input_sync(data->input_dev);
667 static void mxt_input_touchevent(struct mxt_data *data,
668 struct mxt_message *message, int id)
670 struct device *dev = &data->client->dev;
671 u8 status = message->message[0];
672 struct input_dev *input_dev = data->input_dev;
678 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
679 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
681 /* Handle 10/12 bit switching */
682 if (data->max_x < 1024)
684 if (data->max_y < 1024)
687 area = message->message[4];
688 amplitude = message->message[5];
691 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
693 (status & MXT_T9_DETECT) ? 'D' : '.',
694 (status & MXT_T9_PRESS) ? 'P' : '.',
695 (status & MXT_T9_RELEASE) ? 'R' : '.',
696 (status & MXT_T9_MOVE) ? 'M' : '.',
697 (status & MXT_T9_VECTOR) ? 'V' : '.',
698 (status & MXT_T9_AMP) ? 'A' : '.',
699 (status & MXT_T9_SUPPRESS) ? 'S' : '.',
700 (status & MXT_T9_UNGRIP) ? 'U' : '.',
701 x, y, area, amplitude);
703 input_mt_slot(input_dev, id);
705 if (status & MXT_T9_DETECT) {
707 * Multiple bits may be set if the host is slow to read
708 * the status messages, indicating all the events that
711 if (status & MXT_T9_RELEASE) {
712 input_mt_report_slot_state(input_dev,
714 mxt_input_sync(data);
718 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1);
719 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
720 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
721 input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude);
722 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
724 /* Touch no longer active, close out slot */
725 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0);
729 static u16 mxt_extract_T6_csum(const u8 *csum)
731 return csum[0] | (csum[1] << 8) | (csum[2] << 16);
734 static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg)
736 u8 id = msg->reportid;
737 return (id >= data->T9_reportid_min && id <= data->T9_reportid_max);
740 static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
742 struct mxt_message message;
743 const u8 *payload = &message.message[0];
744 struct device *dev = &data->client->dev;
746 bool update_input = false;
750 if (mxt_read_message(data, &message)) {
751 dev_err(dev, "Failed to read message\n");
755 reportid = message.reportid;
757 if (reportid == data->T6_reportid) {
758 u8 status = payload[0];
760 crc = mxt_extract_T6_csum(&payload[1]);
761 if (crc != data->config_crc) {
762 data->config_crc = crc;
763 complete(&data->crc_completion);
766 dev_dbg(dev, "Status: %02x Config Checksum: %06x\n",
767 status, data->config_crc);
769 if (status & MXT_T6_STATUS_RESET)
770 complete(&data->reset_completion);
771 } else if (!data->input_dev) {
773 * do not report events if input device
774 * is not yet registered
776 mxt_dump_message(dev, &message);
777 } else if (mxt_is_T9_message(data, &message)) {
778 int id = reportid - data->T9_reportid_min;
779 mxt_input_touchevent(data, &message, id);
781 } else if (message.reportid == data->T19_reportid) {
782 mxt_input_button(data, &message);
785 mxt_dump_message(dev, &message);
787 } while (reportid != 0xff);
790 mxt_input_sync(data);
795 static irqreturn_t mxt_interrupt(int irq, void *dev_id)
797 struct mxt_data *data = dev_id;
799 if (data->in_bootloader) {
800 /* bootloader state transition completion */
801 complete(&data->bl_completion);
805 if (!data->object_table)
808 return mxt_process_messages_until_invalid(data);
811 static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset,
816 int timeout_counter = 0;
819 reg = data->T6_address + cmd_offset;
821 ret = mxt_write_reg(data->client, reg, value);
830 ret = __mxt_read_reg(data->client, reg, 1, &command_register);
833 } while (command_register != 0 && timeout_counter++ <= 100);
835 if (timeout_counter > 100) {
836 dev_err(&data->client->dev, "Command failed!\n");
843 static int mxt_soft_reset(struct mxt_data *data)
845 struct device *dev = &data->client->dev;
848 dev_info(dev, "Resetting chip\n");
850 reinit_completion(&data->reset_completion);
852 ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_RESET_VALUE, false);
856 ret = mxt_wait_for_completion(data, &data->reset_completion,
864 static void mxt_update_crc(struct mxt_data *data, u8 cmd, u8 value)
867 * On failure, CRC is set to 0 and config will always be
870 data->config_crc = 0;
871 reinit_completion(&data->crc_completion);
873 mxt_t6_command(data, cmd, value, true);
876 * Wait for crc message. On failure, CRC is set to 0 and config will
877 * always be downloaded.
879 mxt_wait_for_completion(data, &data->crc_completion, MXT_CRC_TIMEOUT);
882 static void mxt_calc_crc24(u32 *crc, u8 firstbyte, u8 secondbyte)
884 static const unsigned int crcpoly = 0x80001B;
888 data_word = (secondbyte << 8) | firstbyte;
889 result = ((*crc << 1) ^ data_word);
891 if (result & 0x1000000)
897 static u32 mxt_calculate_crc(u8 *base, off_t start_off, off_t end_off)
900 u8 *ptr = base + start_off;
901 u8 *last_val = base + end_off - 1;
903 if (end_off < start_off)
906 while (ptr < last_val) {
907 mxt_calc_crc24(&crc, *ptr, *(ptr + 1));
911 /* if len is odd, fill the last byte with 0 */
913 mxt_calc_crc24(&crc, *ptr, 0);
922 * mxt_update_cfg - download configuration to chip
924 * Atmel Raw Config File Format
926 * The first four lines of the raw config file contain:
928 * 2) Chip ID Information (first 7 bytes of device memory)
929 * 3) Chip Information Block 24-bit CRC Checksum
930 * 4) Chip Configuration 24-bit CRC Checksum
932 * The rest of the file consists of one line per object instance:
933 * <TYPE> <INSTANCE> <SIZE> <CONTENTS>
935 * <TYPE> - 2-byte object type as hex
936 * <INSTANCE> - 2-byte object instance number as hex
937 * <SIZE> - 2-byte object size as hex
938 * <CONTENTS> - array of <SIZE> 1-byte hex values
940 static int mxt_update_cfg(struct mxt_data *data, const struct firmware *cfg)
942 struct device *dev = &data->client->dev;
943 struct mxt_info cfg_info;
944 struct mxt_object *object;
951 u32 info_crc, config_crc, calculated_crc;
953 size_t config_mem_size;
954 unsigned int type, instance, size;
958 mxt_update_crc(data, MXT_COMMAND_REPORTALL, 1);
960 if (strncmp(cfg->data, MXT_CFG_MAGIC, strlen(MXT_CFG_MAGIC))) {
961 dev_err(dev, "Unrecognised config file\n");
966 data_pos = strlen(MXT_CFG_MAGIC);
968 /* Load information block and check */
969 for (i = 0; i < sizeof(struct mxt_info); i++) {
970 ret = sscanf(cfg->data + data_pos, "%hhx%n",
971 (unsigned char *)&cfg_info + i,
974 dev_err(dev, "Bad format\n");
982 if (cfg_info.family_id != data->info.family_id) {
983 dev_err(dev, "Family ID mismatch!\n");
988 if (cfg_info.variant_id != data->info.variant_id) {
989 dev_err(dev, "Variant ID mismatch!\n");
995 ret = sscanf(cfg->data + data_pos, "%x%n", &info_crc, &offset);
997 dev_err(dev, "Bad format: failed to parse Info CRC\n");
1003 ret = sscanf(cfg->data + data_pos, "%x%n", &config_crc, &offset);
1005 dev_err(dev, "Bad format: failed to parse Config CRC\n");
1012 * The Info Block CRC is calculated over mxt_info and the object
1013 * table. If it does not match then we are trying to load the
1014 * configuration from a different chip or firmware version, so
1015 * the configuration CRC is invalid anyway.
1017 if (info_crc == data->info_crc) {
1018 if (config_crc == 0 || data->config_crc == 0) {
1019 dev_info(dev, "CRC zero, attempting to apply config\n");
1020 } else if (config_crc == data->config_crc) {
1021 dev_dbg(dev, "Config CRC 0x%06X: OK\n",
1026 dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n",
1027 data->config_crc, config_crc);
1031 "Warning: Info CRC error - device=0x%06X file=0x%06X\n",
1032 data->info_crc, info_crc);
1035 /* Malloc memory to store configuration */
1036 cfg_start_ofs = MXT_OBJECT_START +
1037 data->info.object_num * sizeof(struct mxt_object) +
1038 MXT_INFO_CHECKSUM_SIZE;
1039 config_mem_size = data->mem_size - cfg_start_ofs;
1040 config_mem = kzalloc(config_mem_size, GFP_KERNEL);
1042 dev_err(dev, "Failed to allocate memory\n");
1047 while (data_pos < cfg->size) {
1048 /* Read type, instance, length */
1049 ret = sscanf(cfg->data + data_pos, "%x %x %x%n",
1050 &type, &instance, &size, &offset);
1054 } else if (ret != 3) {
1055 dev_err(dev, "Bad format: failed to parse object\n");
1061 object = mxt_get_object(data, type);
1064 for (i = 0; i < size; i++) {
1065 ret = sscanf(cfg->data + data_pos, "%hhx%n",
1073 if (size > mxt_obj_size(object)) {
1075 * Either we are in fallback mode due to wrong
1076 * config or config from a later fw version,
1077 * or the file is corrupt or hand-edited.
1079 dev_warn(dev, "Discarding %zu byte(s) in T%u\n",
1080 size - mxt_obj_size(object), type);
1081 } else if (mxt_obj_size(object) > size) {
1083 * If firmware is upgraded, new bytes may be added to
1084 * end of objects. It is generally forward compatible
1085 * to zero these bytes - previous behaviour will be
1086 * retained. However this does invalidate the CRC and
1087 * will force fallback mode until the configuration is
1088 * updated. We warn here but do nothing else - the
1089 * malloc has zeroed the entire configuration.
1091 dev_warn(dev, "Zeroing %zu byte(s) in T%d\n",
1092 mxt_obj_size(object) - size, type);
1095 if (instance >= mxt_obj_instances(object)) {
1096 dev_err(dev, "Object instances exceeded!\n");
1101 reg = object->start_address + mxt_obj_size(object) * instance;
1103 for (i = 0; i < size; i++) {
1104 ret = sscanf(cfg->data + data_pos, "%hhx%n",
1108 dev_err(dev, "Bad format in T%d\n", type);
1114 if (i > mxt_obj_size(object))
1117 byte_offset = reg + i - cfg_start_ofs;
1119 if ((byte_offset >= 0)
1120 && (byte_offset <= config_mem_size)) {
1121 *(config_mem + byte_offset) = val;
1123 dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n",
1124 reg, object->type, byte_offset);
1131 /* Calculate crc of the received configs (not the raw config file) */
1132 if (data->T7_address < cfg_start_ofs) {
1133 dev_err(dev, "Bad T7 address, T7addr = %x, config offset %x\n",
1134 data->T7_address, cfg_start_ofs);
1139 calculated_crc = mxt_calculate_crc(config_mem,
1140 data->T7_address - cfg_start_ofs,
1143 if (config_crc > 0 && (config_crc != calculated_crc))
1144 dev_warn(dev, "Config CRC error, calculated=%06X, file=%06X\n",
1145 calculated_crc, config_crc);
1147 /* Write configuration as blocks */
1149 while (byte_offset < config_mem_size) {
1150 size = config_mem_size - byte_offset;
1152 if (size > MXT_MAX_BLOCK_WRITE)
1153 size = MXT_MAX_BLOCK_WRITE;
1155 ret = __mxt_write_reg(data->client,
1156 cfg_start_ofs + byte_offset,
1157 size, config_mem + byte_offset);
1159 dev_err(dev, "Config write error, ret=%d\n", ret);
1163 byte_offset += size;
1166 mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE);
1168 ret = mxt_soft_reset(data);
1172 dev_info(dev, "Config successfully updated\n");
1177 release_firmware(cfg);
1181 static int mxt_make_highchg(struct mxt_data *data)
1183 struct device *dev = &data->client->dev;
1184 struct mxt_message message;
1188 /* Read dummy message to make high CHG pin */
1190 error = mxt_read_message(data, &message);
1193 } while (message.reportid != 0xff && --count);
1196 dev_err(dev, "CHG pin isn't cleared\n");
1203 static int mxt_acquire_irq(struct mxt_data *data)
1207 enable_irq(data->irq);
1209 error = mxt_make_highchg(data);
1216 static int mxt_get_info(struct mxt_data *data)
1218 struct i2c_client *client = data->client;
1219 struct mxt_info *info = &data->info;
1222 /* Read 7-byte info block starting at address 0 */
1223 error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info);
1230 static int mxt_get_object_table(struct mxt_data *data)
1232 struct i2c_client *client = data->client;
1234 struct mxt_object *object_table;
1240 table_size = data->info.object_num * sizeof(struct mxt_object);
1241 object_table = kzalloc(table_size, GFP_KERNEL);
1242 if (!object_table) {
1243 dev_err(&data->client->dev, "Failed to allocate memory\n");
1247 error = __mxt_read_reg(client, MXT_OBJECT_START, table_size,
1250 kfree(object_table);
1254 /* Valid Report IDs start counting from 1 */
1257 for (i = 0; i < data->info.object_num; i++) {
1258 struct mxt_object *object = object_table + i;
1261 le16_to_cpus(&object->start_address);
1263 if (object->num_report_ids) {
1265 reportid += object->num_report_ids *
1266 mxt_obj_instances(object);
1267 max_id = reportid - 1;
1273 dev_dbg(&data->client->dev,
1274 "T%u Start:%u Size:%zu Instances:%zu Report IDs:%u-%u\n",
1275 object->type, object->start_address,
1276 mxt_obj_size(object), mxt_obj_instances(object),
1279 switch (object->type) {
1280 case MXT_GEN_COMMAND_T6:
1281 data->T6_reportid = min_id;
1282 data->T6_address = object->start_address;
1284 case MXT_GEN_POWER_T7:
1285 data->T7_address = object->start_address;
1287 case MXT_TOUCH_MULTI_T9:
1288 data->T9_reportid_min = min_id;
1289 data->T9_reportid_max = max_id;
1291 case MXT_SPT_GPIOPWM_T19:
1292 data->T19_reportid = min_id;
1296 end_address = object->start_address
1297 + mxt_obj_size(object) * mxt_obj_instances(object) - 1;
1299 if (end_address >= data->mem_size)
1300 data->mem_size = end_address + 1;
1303 data->object_table = object_table;
1308 static void mxt_free_object_table(struct mxt_data *data)
1310 input_unregister_device(data->input_dev);
1311 data->input_dev = NULL;
1313 kfree(data->object_table);
1314 data->object_table = NULL;
1315 data->T6_reportid = 0;
1316 data->T9_reportid_min = 0;
1317 data->T9_reportid_max = 0;
1318 data->T19_reportid = 0;
1321 static int mxt_read_t9_resolution(struct mxt_data *data)
1323 struct i2c_client *client = data->client;
1325 struct t9_range range;
1326 unsigned char orient;
1327 struct mxt_object *object;
1329 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
1333 error = __mxt_read_reg(client,
1334 object->start_address + MXT_T9_RANGE,
1335 sizeof(range), &range);
1339 le16_to_cpus(&range.x);
1340 le16_to_cpus(&range.y);
1342 error = __mxt_read_reg(client,
1343 object->start_address + MXT_T9_ORIENT,
1348 /* Handle default values */
1355 if (orient & MXT_T9_ORIENT_SWITCH) {
1356 data->max_x = range.y;
1357 data->max_y = range.x;
1359 data->max_x = range.x;
1360 data->max_y = range.y;
1363 dev_dbg(&client->dev,
1364 "Touchscreen size X%uY%u\n", data->max_x, data->max_y);
1369 static int mxt_input_open(struct input_dev *dev);
1370 static void mxt_input_close(struct input_dev *dev);
1372 static int mxt_initialize_t9_input_device(struct mxt_data *data)
1374 struct device *dev = &data->client->dev;
1375 const struct mxt_platform_data *pdata = data->pdata;
1376 struct input_dev *input_dev;
1378 unsigned int num_mt_slots;
1379 unsigned int mt_flags = 0;
1382 error = mxt_read_t9_resolution(data);
1384 dev_warn(dev, "Failed to initialize T9 resolution\n");
1386 input_dev = input_allocate_device();
1388 dev_err(dev, "Failed to allocate memory\n");
1392 input_dev->name = "Atmel maXTouch Touchscreen";
1393 input_dev->phys = data->phys;
1394 input_dev->id.bustype = BUS_I2C;
1395 input_dev->dev.parent = dev;
1396 input_dev->open = mxt_input_open;
1397 input_dev->close = mxt_input_close;
1399 __set_bit(EV_ABS, input_dev->evbit);
1400 __set_bit(EV_KEY, input_dev->evbit);
1401 __set_bit(BTN_TOUCH, input_dev->keybit);
1403 if (pdata->t19_num_keys) {
1404 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
1406 for (i = 0; i < pdata->t19_num_keys; i++)
1407 if (pdata->t19_keymap[i] != KEY_RESERVED)
1408 input_set_capability(input_dev, EV_KEY,
1409 pdata->t19_keymap[i]);
1411 mt_flags |= INPUT_MT_POINTER;
1413 input_abs_set_res(input_dev, ABS_X, MXT_PIXELS_PER_MM);
1414 input_abs_set_res(input_dev, ABS_Y, MXT_PIXELS_PER_MM);
1415 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
1417 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
1420 input_dev->name = "Atmel maXTouch Touchpad";
1423 /* For single touch */
1424 input_set_abs_params(input_dev, ABS_X,
1425 0, data->max_x, 0, 0);
1426 input_set_abs_params(input_dev, ABS_Y,
1427 0, data->max_y, 0, 0);
1428 input_set_abs_params(input_dev, ABS_PRESSURE,
1431 /* For multi touch */
1432 num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
1433 error = input_mt_init_slots(input_dev, num_mt_slots, mt_flags);
1435 dev_err(dev, "Error %d initialising slots\n", error);
1439 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1440 0, MXT_MAX_AREA, 0, 0);
1441 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1442 0, data->max_x, 0, 0);
1443 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1444 0, data->max_y, 0, 0);
1445 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
1448 input_set_drvdata(input_dev, data);
1450 error = input_register_device(input_dev);
1452 dev_err(dev, "Error %d registering input device\n", error);
1456 data->input_dev = input_dev;
1461 input_free_device(input_dev);
1465 static int mxt_configure_objects(struct mxt_data *data,
1466 const struct firmware *cfg);
1468 static void mxt_config_cb(const struct firmware *cfg, void *ctx)
1470 mxt_configure_objects(ctx, cfg);
1473 static int mxt_initialize(struct mxt_data *data)
1475 struct i2c_client *client = data->client;
1478 error = mxt_get_info(data);
1480 error = mxt_probe_bootloader(data);
1484 data->in_bootloader = true;
1488 /* Get object table information */
1489 error = mxt_get_object_table(data);
1491 dev_err(&client->dev, "Error %d reading object table\n", error);
1495 mxt_acquire_irq(data);
1497 goto err_free_object_table;
1499 request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME,
1500 &data->client->dev, GFP_KERNEL, data,
1505 err_free_object_table:
1506 mxt_free_object_table(data);
1510 static int mxt_configure_objects(struct mxt_data *data,
1511 const struct firmware *cfg)
1513 struct device *dev = &data->client->dev;
1514 struct mxt_info *info = &data->info;
1518 error = mxt_update_cfg(data, cfg);
1520 dev_warn(dev, "Error %d updating config\n", error);
1523 error = mxt_initialize_t9_input_device(data);
1528 "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n",
1529 info->family_id, info->variant_id, info->version >> 4,
1530 info->version & 0xf, info->build, info->object_num);
1535 /* Firmware Version is returned as Major.Minor.Build */
1536 static ssize_t mxt_fw_version_show(struct device *dev,
1537 struct device_attribute *attr, char *buf)
1539 struct mxt_data *data = dev_get_drvdata(dev);
1540 struct mxt_info *info = &data->info;
1541 return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n",
1542 info->version >> 4, info->version & 0xf, info->build);
1545 /* Hardware Version is returned as FamilyID.VariantID */
1546 static ssize_t mxt_hw_version_show(struct device *dev,
1547 struct device_attribute *attr, char *buf)
1549 struct mxt_data *data = dev_get_drvdata(dev);
1550 struct mxt_info *info = &data->info;
1551 return scnprintf(buf, PAGE_SIZE, "%u.%u\n",
1552 info->family_id, info->variant_id);
1555 static ssize_t mxt_show_instance(char *buf, int count,
1556 struct mxt_object *object, int instance,
1561 if (mxt_obj_instances(object) > 1)
1562 count += scnprintf(buf + count, PAGE_SIZE - count,
1563 "Instance %u\n", instance);
1565 for (i = 0; i < mxt_obj_size(object); i++)
1566 count += scnprintf(buf + count, PAGE_SIZE - count,
1567 "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
1568 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
1573 static ssize_t mxt_object_show(struct device *dev,
1574 struct device_attribute *attr, char *buf)
1576 struct mxt_data *data = dev_get_drvdata(dev);
1577 struct mxt_object *object;
1583 /* Pre-allocate buffer large enough to hold max sized object. */
1584 obuf = kmalloc(256, GFP_KERNEL);
1589 for (i = 0; i < data->info.object_num; i++) {
1590 object = data->object_table + i;
1592 if (!mxt_object_readable(object->type))
1595 count += scnprintf(buf + count, PAGE_SIZE - count,
1596 "T%u:\n", object->type);
1598 for (j = 0; j < mxt_obj_instances(object); j++) {
1599 u16 size = mxt_obj_size(object);
1600 u16 addr = object->start_address + j * size;
1602 error = __mxt_read_reg(data->client, addr, size, obuf);
1606 count = mxt_show_instance(buf, count, object, j, obuf);
1612 return error ?: count;
1615 static int mxt_check_firmware_format(struct device *dev,
1616 const struct firmware *fw)
1618 unsigned int pos = 0;
1621 while (pos < fw->size) {
1622 c = *(fw->data + pos);
1624 if (c < '0' || (c > '9' && c < 'A') || c > 'F')
1631 * To convert file try:
1632 * xxd -r -p mXTXXX__APP_VX-X-XX.enc > maxtouch.fw
1634 dev_err(dev, "Aborting: firmware file must be in binary format\n");
1639 static int mxt_load_fw(struct device *dev, const char *fn)
1641 struct mxt_data *data = dev_get_drvdata(dev);
1642 const struct firmware *fw = NULL;
1643 unsigned int frame_size;
1644 unsigned int pos = 0;
1645 unsigned int retry = 0;
1646 unsigned int frame = 0;
1649 ret = request_firmware(&fw, fn, dev);
1651 dev_err(dev, "Unable to open firmware %s\n", fn);
1655 /* Check for incorrect enc file */
1656 ret = mxt_check_firmware_format(dev, fw);
1658 goto release_firmware;
1660 ret = mxt_lookup_bootloader_address(data);
1662 goto release_firmware;
1664 if (!data->in_bootloader) {
1665 /* Change to the bootloader mode */
1666 data->in_bootloader = true;
1668 ret = mxt_t6_command(data, MXT_COMMAND_RESET,
1669 MXT_BOOT_VALUE, false);
1671 goto release_firmware;
1673 msleep(MXT_RESET_TIME);
1676 mxt_free_object_table(data);
1677 reinit_completion(&data->bl_completion);
1679 ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD);
1683 /* Unlock bootloader */
1684 mxt_unlock_bootloader(data);
1686 while (pos < fw->size) {
1687 ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA);
1691 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
1693 /* Take account of CRC bytes */
1696 /* Write one frame to device */
1697 ret = mxt_bootloader_write(data, fw->data + pos, frame_size);
1701 ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS);
1705 /* Back off by 20ms per retry */
1709 dev_err(dev, "Retry count exceeded\n");
1718 if (frame % 50 == 0)
1719 dev_dbg(dev, "Sent %d frames, %d/%zd bytes\n",
1720 frame, pos, fw->size);
1723 /* Wait for flash. */
1724 ret = mxt_wait_for_completion(data, &data->bl_completion,
1729 dev_dbg(dev, "Sent %d frames, %d bytes\n", frame, pos);
1732 * Wait for device to reset. Some bootloader versions do not assert
1733 * the CHG line after bootloading has finished, so ignore potential
1736 mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME);
1738 data->in_bootloader = false;
1741 disable_irq(data->irq);
1743 release_firmware(fw);
1747 static ssize_t mxt_update_fw_store(struct device *dev,
1748 struct device_attribute *attr,
1749 const char *buf, size_t count)
1751 struct mxt_data *data = dev_get_drvdata(dev);
1754 error = mxt_load_fw(dev, MXT_FW_NAME);
1756 dev_err(dev, "The firmware update failed(%d)\n", error);
1759 dev_info(dev, "The firmware update succeeded\n");
1761 error = mxt_initialize(data);
1769 static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
1770 static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
1771 static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
1772 static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
1774 static struct attribute *mxt_attrs[] = {
1775 &dev_attr_fw_version.attr,
1776 &dev_attr_hw_version.attr,
1777 &dev_attr_object.attr,
1778 &dev_attr_update_fw.attr,
1782 static const struct attribute_group mxt_attr_group = {
1786 static void mxt_start(struct mxt_data *data)
1789 mxt_write_object(data,
1790 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83);
1793 static void mxt_stop(struct mxt_data *data)
1796 mxt_write_object(data,
1797 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
1800 static int mxt_input_open(struct input_dev *dev)
1802 struct mxt_data *data = input_get_drvdata(dev);
1809 static void mxt_input_close(struct input_dev *dev)
1811 struct mxt_data *data = input_get_drvdata(dev);
1817 static struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
1819 struct mxt_platform_data *pdata;
1822 int proplen, i, ret;
1824 if (!client->dev.of_node)
1825 return ERR_PTR(-ENODEV);
1827 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
1829 return ERR_PTR(-ENOMEM);
1831 if (of_find_property(client->dev.of_node, "linux,gpio-keymap",
1833 pdata->t19_num_keys = proplen / sizeof(u32);
1835 keymap = devm_kzalloc(&client->dev,
1836 pdata->t19_num_keys * sizeof(keymap[0]),
1839 return ERR_PTR(-ENOMEM);
1841 for (i = 0; i < pdata->t19_num_keys; i++) {
1842 ret = of_property_read_u32_index(client->dev.of_node,
1843 "linux,gpio-keymap", i, &keycode);
1845 keycode = KEY_RESERVED;
1847 keymap[i] = keycode;
1850 pdata->t19_keymap = keymap;
1856 static struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
1858 dev_dbg(&client->dev, "No platform data specified\n");
1859 return ERR_PTR(-EINVAL);
1863 static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
1865 struct mxt_data *data;
1866 const struct mxt_platform_data *pdata;
1869 pdata = dev_get_platdata(&client->dev);
1871 pdata = mxt_parse_dt(client);
1873 return PTR_ERR(pdata);
1876 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
1878 dev_err(&client->dev, "Failed to allocate memory\n");
1882 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1883 client->adapter->nr, client->addr);
1885 data->client = client;
1886 data->pdata = pdata;
1887 data->irq = client->irq;
1888 i2c_set_clientdata(client, data);
1890 init_completion(&data->bl_completion);
1891 init_completion(&data->reset_completion);
1892 init_completion(&data->crc_completion);
1894 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
1895 pdata->irqflags | IRQF_ONESHOT,
1896 client->name, data);
1898 dev_err(&client->dev, "Failed to register interrupt\n");
1902 disable_irq(client->irq);
1904 error = mxt_initialize(data);
1908 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
1910 dev_err(&client->dev, "Failure %d creating sysfs group\n",
1912 goto err_free_object;
1918 kfree(data->object_table);
1920 free_irq(client->irq, data);
1926 static int mxt_remove(struct i2c_client *client)
1928 struct mxt_data *data = i2c_get_clientdata(client);
1930 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
1931 free_irq(data->irq, data);
1932 input_unregister_device(data->input_dev);
1933 kfree(data->object_table);
1939 #ifdef CONFIG_PM_SLEEP
1940 static int mxt_suspend(struct device *dev)
1942 struct i2c_client *client = to_i2c_client(dev);
1943 struct mxt_data *data = i2c_get_clientdata(client);
1944 struct input_dev *input_dev = data->input_dev;
1946 mutex_lock(&input_dev->mutex);
1948 if (input_dev->users)
1951 mutex_unlock(&input_dev->mutex);
1956 static int mxt_resume(struct device *dev)
1958 struct i2c_client *client = to_i2c_client(dev);
1959 struct mxt_data *data = i2c_get_clientdata(client);
1960 struct input_dev *input_dev = data->input_dev;
1962 mxt_soft_reset(data);
1964 mutex_lock(&input_dev->mutex);
1966 if (input_dev->users)
1969 mutex_unlock(&input_dev->mutex);
1975 static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
1977 static const struct of_device_id mxt_of_match[] = {
1978 { .compatible = "atmel,maxtouch", },
1981 MODULE_DEVICE_TABLE(of, mxt_of_match);
1983 static const struct i2c_device_id mxt_id[] = {
1984 { "qt602240_ts", 0 },
1985 { "atmel_mxt_ts", 0 },
1986 { "atmel_mxt_tp", 0 },
1990 MODULE_DEVICE_TABLE(i2c, mxt_id);
1992 static struct i2c_driver mxt_driver = {
1994 .name = "atmel_mxt_ts",
1995 .owner = THIS_MODULE,
1996 .of_match_table = of_match_ptr(mxt_of_match),
2000 .remove = mxt_remove,
2004 module_i2c_driver(mxt_driver);
2006 /* Module information */
2007 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
2008 MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
2009 MODULE_LICENSE("GPL");