blob: 4317273c2138cd561c9223f85920ab6d1ac29098 [file] [log] [blame]
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001/*
Iiro Valkonen7686b102011-02-02 23:21:58 -08002 * Atmel maXTouch Touchscreen driver
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07005 * Copyright (C) 2012 Google, Inc.
6 *
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07007 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#include <linux/module.h>
Benson Leungd79e7e42014-05-18 23:02:52 -070017#include <linux/init.h>
18#include <linux/completion.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070019#include <linux/delay.h>
20#include <linux/firmware.h>
21#include <linux/i2c.h>
Dmitry Torokhov964de522011-02-02 23:21:58 -080022#include <linux/i2c/atmel_mxt_ts.h>
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -070023#include <linux/input/mt.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070024#include <linux/interrupt.h>
Stephen Warren78188be2014-07-23 12:23:23 -070025#include <linux/of.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070026#include <linux/slab.h>
27
28/* Version */
Iiro Valkonen7686b102011-02-02 23:21:58 -080029#define MXT_VER_20 20
30#define MXT_VER_21 21
31#define MXT_VER_22 22
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070032
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070033/* Firmware */
Iiro Valkonen7686b102011-02-02 23:21:58 -080034#define MXT_FW_NAME "maxtouch.fw"
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070035
36/* Registers */
Daniel Kurtz23003a842012-06-28 21:08:14 +080037#define MXT_INFO 0x00
Iiro Valkonen7686b102011-02-02 23:21:58 -080038#define MXT_FAMILY_ID 0x00
39#define MXT_VARIANT_ID 0x01
40#define MXT_VERSION 0x02
41#define MXT_BUILD 0x03
42#define MXT_MATRIX_X_SIZE 0x04
43#define MXT_MATRIX_Y_SIZE 0x05
44#define MXT_OBJECT_NUM 0x06
45#define MXT_OBJECT_START 0x07
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070046
Iiro Valkonen7686b102011-02-02 23:21:58 -080047#define MXT_OBJECT_SIZE 6
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070048
49/* Object types */
Iiro Valkonen81c88a72011-07-04 03:08:25 -070050#define MXT_DEBUG_DIAGNOSTIC_T37 37
51#define MXT_GEN_MESSAGE_T5 5
52#define MXT_GEN_COMMAND_T6 6
53#define MXT_GEN_POWER_T7 7
54#define MXT_GEN_ACQUIRE_T8 8
55#define MXT_GEN_DATASOURCE_T53 53
56#define MXT_TOUCH_MULTI_T9 9
57#define MXT_TOUCH_KEYARRAY_T15 15
58#define MXT_TOUCH_PROXIMITY_T23 23
59#define MXT_TOUCH_PROXKEY_T52 52
60#define MXT_PROCI_GRIPFACE_T20 20
61#define MXT_PROCG_NOISE_T22 22
62#define MXT_PROCI_ONETOUCH_T24 24
63#define MXT_PROCI_TWOTOUCH_T27 27
64#define MXT_PROCI_GRIP_T40 40
65#define MXT_PROCI_PALM_T41 41
66#define MXT_PROCI_TOUCHSUPPRESSION_T42 42
67#define MXT_PROCI_STYLUS_T47 47
68#define MXT_PROCG_NOISESUPPRESSION_T48 48
69#define MXT_SPT_COMMSCONFIG_T18 18
70#define MXT_SPT_GPIOPWM_T19 19
71#define MXT_SPT_SELFTEST_T25 25
72#define MXT_SPT_CTECONFIG_T28 28
73#define MXT_SPT_USERDATA_T38 38
74#define MXT_SPT_DIGITIZER_T43 43
75#define MXT_SPT_MESSAGECOUNT_T44 44
76#define MXT_SPT_CTECONFIG_T46 46
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070077
Iiro Valkonen81c88a72011-07-04 03:08:25 -070078/* MXT_GEN_COMMAND_T6 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080079#define MXT_COMMAND_RESET 0
80#define MXT_COMMAND_BACKUPNV 1
81#define MXT_COMMAND_CALIBRATE 2
82#define MXT_COMMAND_REPORTALL 3
83#define MXT_COMMAND_DIAGNOSTIC 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070084
Iiro Valkonena4a2ef42014-05-18 23:03:44 -070085/* Define for T6 status byte */
86#define MXT_T6_STATUS_RESET (1 << 7)
87
Iiro Valkonen81c88a72011-07-04 03:08:25 -070088/* MXT_GEN_POWER_T7 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080089#define MXT_POWER_IDLEACQINT 0
90#define MXT_POWER_ACTVACQINT 1
91#define MXT_POWER_ACTV2IDLETO 2
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070092
Iiro Valkonen81c88a72011-07-04 03:08:25 -070093/* MXT_GEN_ACQUIRE_T8 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080094#define MXT_ACQUIRE_CHRGTIME 0
95#define MXT_ACQUIRE_TCHDRIFT 2
96#define MXT_ACQUIRE_DRIFTST 3
97#define MXT_ACQUIRE_TCHAUTOCAL 4
98#define MXT_ACQUIRE_SYNC 5
99#define MXT_ACQUIRE_ATCHCALST 6
100#define MXT_ACQUIRE_ATCHCALSTHR 7
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700101
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700102/* MXT_TOUCH_MULTI_T9 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800103#define MXT_TOUCH_CTRL 0
Nick Dyer61dc1ab2014-05-18 23:16:49 -0700104#define MXT_T9_ORIENT 9
105#define MXT_T9_RANGE 18
106
Nick Dyerf3889ed2014-05-18 23:22:04 -0700107/* MXT_TOUCH_MULTI_T9 status */
108#define MXT_T9_UNGRIP (1 << 0)
109#define MXT_T9_SUPPRESS (1 << 1)
110#define MXT_T9_AMP (1 << 2)
111#define MXT_T9_VECTOR (1 << 3)
112#define MXT_T9_MOVE (1 << 4)
113#define MXT_T9_RELEASE (1 << 5)
114#define MXT_T9_PRESS (1 << 6)
115#define MXT_T9_DETECT (1 << 7)
116
Nick Dyer61dc1ab2014-05-18 23:16:49 -0700117struct t9_range {
118 u16 x;
119 u16 y;
120} __packed;
121
Nick Dyerf3889ed2014-05-18 23:22:04 -0700122/* MXT_TOUCH_MULTI_T9 orient */
123#define MXT_T9_ORIENT_SWITCH (1 << 0)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700124
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700125/* MXT_PROCI_GRIPFACE_T20 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800126#define MXT_GRIPFACE_CTRL 0
127#define MXT_GRIPFACE_XLOGRIP 1
128#define MXT_GRIPFACE_XHIGRIP 2
129#define MXT_GRIPFACE_YLOGRIP 3
130#define MXT_GRIPFACE_YHIGRIP 4
131#define MXT_GRIPFACE_MAXTCHS 5
132#define MXT_GRIPFACE_SZTHR1 7
133#define MXT_GRIPFACE_SZTHR2 8
134#define MXT_GRIPFACE_SHPTHR1 9
135#define MXT_GRIPFACE_SHPTHR2 10
136#define MXT_GRIPFACE_SUPEXTTO 11
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700137
Iiro Valkonen7686b102011-02-02 23:21:58 -0800138/* MXT_PROCI_NOISE field */
139#define MXT_NOISE_CTRL 0
140#define MXT_NOISE_OUTFLEN 1
141#define MXT_NOISE_GCAFUL_LSB 3
142#define MXT_NOISE_GCAFUL_MSB 4
143#define MXT_NOISE_GCAFLL_LSB 5
144#define MXT_NOISE_GCAFLL_MSB 6
145#define MXT_NOISE_ACTVGCAFVALID 7
146#define MXT_NOISE_NOISETHR 8
147#define MXT_NOISE_FREQHOPSCALE 10
148#define MXT_NOISE_FREQ0 11
149#define MXT_NOISE_FREQ1 12
150#define MXT_NOISE_FREQ2 13
151#define MXT_NOISE_FREQ3 14
152#define MXT_NOISE_FREQ4 15
153#define MXT_NOISE_IDLEGCAFVALID 16
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700154
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700155/* MXT_SPT_COMMSCONFIG_T18 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800156#define MXT_COMMS_CTRL 0
157#define MXT_COMMS_CMD 1
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700158
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700159/* MXT_SPT_CTECONFIG_T28 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800160#define MXT_CTE_CTRL 0
161#define MXT_CTE_CMD 1
162#define MXT_CTE_MODE 2
163#define MXT_CTE_IDLEGCAFDEPTH 3
164#define MXT_CTE_ACTVGCAFDEPTH 4
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700165#define MXT_CTE_VOLTAGE 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700166
Iiro Valkonen7686b102011-02-02 23:21:58 -0800167#define MXT_VOLTAGE_DEFAULT 2700000
168#define MXT_VOLTAGE_STEP 10000
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700169
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700170/* Define for MXT_GEN_COMMAND_T6 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800171#define MXT_BOOT_VALUE 0xa5
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700172#define MXT_RESET_VALUE 0x01
Iiro Valkonen7686b102011-02-02 23:21:58 -0800173#define MXT_BACKUP_VALUE 0x55
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700174
175/* Delay times */
Linus Torvalds8343bce2013-03-09 10:31:01 -0800176#define MXT_BACKUP_TIME 50 /* msec */
177#define MXT_RESET_TIME 200 /* msec */
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700178#define MXT_RESET_TIMEOUT 3000 /* msec */
Nick Dyerc3f78042014-05-18 23:04:46 -0700179#define MXT_CRC_TIMEOUT 1000 /* msec */
Benson Leunga0434b72014-05-18 23:03:09 -0700180#define MXT_FW_RESET_TIME 3000 /* msec */
181#define MXT_FW_CHG_TIMEOUT 300 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700182
183/* Command to unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800184#define MXT_UNLOCK_CMD_MSB 0xaa
185#define MXT_UNLOCK_CMD_LSB 0xdc
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700186
187/* Bootloader mode status */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800188#define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
189#define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
190#define MXT_FRAME_CRC_CHECK 0x02
191#define MXT_FRAME_CRC_FAIL 0x03
192#define MXT_FRAME_CRC_PASS 0x04
193#define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
194#define MXT_BOOT_STATUS_MASK 0x3f
Nick Dyere57a66a2014-05-18 23:13:40 -0700195#define MXT_BOOT_EXTENDED_ID (1 << 5)
196#define MXT_BOOT_ID_MASK 0x1f
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700197
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700198/* Touchscreen absolute values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800199#define MXT_MAX_AREA 0xff
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700200
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800201#define MXT_PIXELS_PER_MM 20
202
Iiro Valkonen7686b102011-02-02 23:21:58 -0800203struct mxt_info {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700204 u8 family_id;
205 u8 variant_id;
206 u8 version;
207 u8 build;
208 u8 matrix_xsize;
209 u8 matrix_ysize;
210 u8 object_num;
211};
212
Iiro Valkonen7686b102011-02-02 23:21:58 -0800213struct mxt_object {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700214 u8 type;
215 u16 start_address;
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -0700216 u8 size_minus_one;
217 u8 instances_minus_one;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700218 u8 num_report_ids;
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800219} __packed;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700220
Iiro Valkonen7686b102011-02-02 23:21:58 -0800221struct mxt_message {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700222 u8 reportid;
223 u8 message[7];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700224};
225
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700226/* Each client has this additional data */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800227struct mxt_data {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700228 struct i2c_client *client;
229 struct input_dev *input_dev;
Daniel Kurtzec02ac22012-06-28 21:08:02 +0800230 char phys[64]; /* device physical location */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800231 const struct mxt_platform_data *pdata;
232 struct mxt_object *object_table;
233 struct mxt_info info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700234 unsigned int irq;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700235 unsigned int max_x;
236 unsigned int max_y;
Benson Leungd79e7e42014-05-18 23:02:52 -0700237 bool in_bootloader;
Nick Dyerc3f78042014-05-18 23:04:46 -0700238 u32 config_crc;
Nick Dyerf28a8422014-05-18 23:10:49 -0700239 u8 bootloader_addr;
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800240
241 /* Cached parameters from object table */
Daniel Kurtzfdf804212012-06-28 21:08:24 +0800242 u8 T6_reportid;
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700243 u16 T6_address;
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800244 u8 T9_reportid_min;
245 u8 T9_reportid_max;
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800246 u8 T19_reportid;
Benson Leungd79e7e42014-05-18 23:02:52 -0700247
248 /* for fw update in bootloader */
249 struct completion bl_completion;
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700250
251 /* for reset handling */
252 struct completion reset_completion;
Nick Dyerc3f78042014-05-18 23:04:46 -0700253
254 /* for config update handling */
255 struct completion crc_completion;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700256};
257
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -0700258static size_t mxt_obj_size(const struct mxt_object *obj)
259{
260 return obj->size_minus_one + 1;
261}
262
263static size_t mxt_obj_instances(const struct mxt_object *obj)
264{
265 return obj->instances_minus_one + 1;
266}
267
Iiro Valkonen7686b102011-02-02 23:21:58 -0800268static bool mxt_object_readable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700269{
270 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700271 case MXT_GEN_COMMAND_T6:
272 case MXT_GEN_POWER_T7:
273 case MXT_GEN_ACQUIRE_T8:
274 case MXT_GEN_DATASOURCE_T53:
275 case MXT_TOUCH_MULTI_T9:
276 case MXT_TOUCH_KEYARRAY_T15:
277 case MXT_TOUCH_PROXIMITY_T23:
278 case MXT_TOUCH_PROXKEY_T52:
279 case MXT_PROCI_GRIPFACE_T20:
280 case MXT_PROCG_NOISE_T22:
281 case MXT_PROCI_ONETOUCH_T24:
282 case MXT_PROCI_TWOTOUCH_T27:
283 case MXT_PROCI_GRIP_T40:
284 case MXT_PROCI_PALM_T41:
285 case MXT_PROCI_TOUCHSUPPRESSION_T42:
286 case MXT_PROCI_STYLUS_T47:
287 case MXT_PROCG_NOISESUPPRESSION_T48:
288 case MXT_SPT_COMMSCONFIG_T18:
289 case MXT_SPT_GPIOPWM_T19:
290 case MXT_SPT_SELFTEST_T25:
291 case MXT_SPT_CTECONFIG_T28:
292 case MXT_SPT_USERDATA_T38:
293 case MXT_SPT_DIGITIZER_T43:
294 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700295 return true;
296 default:
297 return false;
298 }
299}
300
Iiro Valkonen7686b102011-02-02 23:21:58 -0800301static bool mxt_object_writable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700302{
303 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700304 case MXT_GEN_COMMAND_T6:
305 case MXT_GEN_POWER_T7:
306 case MXT_GEN_ACQUIRE_T8:
307 case MXT_TOUCH_MULTI_T9:
308 case MXT_TOUCH_KEYARRAY_T15:
309 case MXT_TOUCH_PROXIMITY_T23:
310 case MXT_TOUCH_PROXKEY_T52:
311 case MXT_PROCI_GRIPFACE_T20:
312 case MXT_PROCG_NOISE_T22:
313 case MXT_PROCI_ONETOUCH_T24:
314 case MXT_PROCI_TWOTOUCH_T27:
315 case MXT_PROCI_GRIP_T40:
316 case MXT_PROCI_PALM_T41:
317 case MXT_PROCI_TOUCHSUPPRESSION_T42:
318 case MXT_PROCI_STYLUS_T47:
319 case MXT_PROCG_NOISESUPPRESSION_T48:
320 case MXT_SPT_COMMSCONFIG_T18:
321 case MXT_SPT_GPIOPWM_T19:
322 case MXT_SPT_SELFTEST_T25:
323 case MXT_SPT_CTECONFIG_T28:
324 case MXT_SPT_DIGITIZER_T43:
325 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700326 return true;
327 default:
328 return false;
329 }
330}
331
Iiro Valkonen7686b102011-02-02 23:21:58 -0800332static void mxt_dump_message(struct device *dev,
Daniel Kurtz6ee3dbf2012-05-08 22:40:29 -0700333 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700334{
Andy Shevchenkoeb007c82012-10-04 00:02:59 -0700335 dev_dbg(dev, "reportid: %u\tmessage: %*ph\n",
336 message->reportid, 7, message->message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700337}
338
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700339static int mxt_wait_for_completion(struct mxt_data *data,
340 struct completion *comp,
341 unsigned int timeout_ms)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700342{
Benson Leungd79e7e42014-05-18 23:02:52 -0700343 struct device *dev = &data->client->dev;
Benson Leungd79e7e42014-05-18 23:02:52 -0700344 unsigned long timeout = msecs_to_jiffies(timeout_ms);
345 long ret;
346
347 ret = wait_for_completion_interruptible_timeout(comp, timeout);
348 if (ret < 0) {
349 return ret;
350 } else if (ret == 0) {
351 dev_err(dev, "Wait for completion timed out.\n");
352 return -ETIMEDOUT;
353 }
354 return 0;
355}
356
Nick Dyerf28a8422014-05-18 23:10:49 -0700357static int mxt_bootloader_read(struct mxt_data *data,
358 u8 *val, unsigned int count)
359{
360 int ret;
361 struct i2c_msg msg;
362
363 msg.addr = data->bootloader_addr;
364 msg.flags = data->client->flags & I2C_M_TEN;
365 msg.flags |= I2C_M_RD;
366 msg.len = count;
367 msg.buf = val;
368
369 ret = i2c_transfer(data->client->adapter, &msg, 1);
370
371 if (ret == 1) {
372 ret = 0;
373 } else {
374 ret = ret < 0 ? ret : -EIO;
375 dev_err(&data->client->dev, "%s: i2c recv failed (%d)\n",
376 __func__, ret);
377 }
378
379 return ret;
380}
381
382static int mxt_bootloader_write(struct mxt_data *data,
383 const u8 * const val, unsigned int count)
384{
385 int ret;
386 struct i2c_msg msg;
387
388 msg.addr = data->bootloader_addr;
389 msg.flags = data->client->flags & I2C_M_TEN;
390 msg.len = count;
391 msg.buf = (u8 *)val;
392
393 ret = i2c_transfer(data->client->adapter, &msg, 1);
394 if (ret == 1) {
395 ret = 0;
396 } else {
397 ret = ret < 0 ? ret : -EIO;
398 dev_err(&data->client->dev, "%s: i2c send failed (%d)\n",
399 __func__, ret);
400 }
401
402 return ret;
403}
404
405static int mxt_lookup_bootloader_address(struct mxt_data *data)
406{
407 u8 appmode = data->client->addr;
408 u8 bootloader;
409
410 switch (appmode) {
411 case 0x4a:
412 case 0x4b:
413 case 0x4c:
414 case 0x4d:
415 case 0x5a:
416 case 0x5b:
417 bootloader = appmode - 0x26;
418 break;
419 default:
420 dev_err(&data->client->dev,
421 "Appmode i2c address 0x%02x not found\n",
422 appmode);
423 return -EINVAL;
424 }
425
426 data->bootloader_addr = bootloader;
427 return 0;
428}
429
Nick Dyere57a66a2014-05-18 23:13:40 -0700430static u8 mxt_get_bootloader_version(struct mxt_data *data, u8 val)
431{
432 struct device *dev = &data->client->dev;
433 u8 buf[3];
434
435 if (val & MXT_BOOT_EXTENDED_ID) {
436 if (mxt_bootloader_read(data, &buf[0], 3) != 0) {
437 dev_err(dev, "%s: i2c failure\n", __func__);
Nick Dyer68807a02014-06-07 23:17:26 -0700438 return val;
Nick Dyere57a66a2014-05-18 23:13:40 -0700439 }
440
441 dev_dbg(dev, "Bootloader ID:%d Version:%d\n", buf[1], buf[2]);
442
443 return buf[0];
444 } else {
445 dev_dbg(dev, "Bootloader ID:%d\n", val & MXT_BOOT_ID_MASK);
446
447 return val;
448 }
449}
450
Benson Leungd79e7e42014-05-18 23:02:52 -0700451static int mxt_check_bootloader(struct mxt_data *data, unsigned int state)
452{
Nick Dyerf28a8422014-05-18 23:10:49 -0700453 struct device *dev = &data->client->dev;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700454 u8 val;
Benson Leungd79e7e42014-05-18 23:02:52 -0700455 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700456
457recheck:
Benson Leungd79e7e42014-05-18 23:02:52 -0700458 if (state != MXT_WAITING_BOOTLOAD_CMD) {
459 /*
460 * In application update mode, the interrupt
461 * line signals state transitions. We must wait for the
462 * CHG assertion before reading the status byte.
463 * Once the status byte has been read, the line is deasserted.
464 */
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700465 ret = mxt_wait_for_completion(data, &data->bl_completion,
466 MXT_FW_CHG_TIMEOUT);
Benson Leungd79e7e42014-05-18 23:02:52 -0700467 if (ret) {
468 /*
469 * TODO: handle -ERESTARTSYS better by terminating
470 * fw update process before returning to userspace
471 * by writing length 0x000 to device (iff we are in
472 * WAITING_FRAME_DATA state).
473 */
Nick Dyerf28a8422014-05-18 23:10:49 -0700474 dev_err(dev, "Update wait error %d\n", ret);
Benson Leungd79e7e42014-05-18 23:02:52 -0700475 return ret;
476 }
477 }
478
Nick Dyerf28a8422014-05-18 23:10:49 -0700479 ret = mxt_bootloader_read(data, &val, 1);
480 if (ret)
481 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700482
Nick Dyere57a66a2014-05-18 23:13:40 -0700483 if (state == MXT_WAITING_BOOTLOAD_CMD)
484 val = mxt_get_bootloader_version(data, val);
485
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700486 switch (state) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800487 case MXT_WAITING_BOOTLOAD_CMD:
488 case MXT_WAITING_FRAME_DATA:
489 val &= ~MXT_BOOT_STATUS_MASK;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700490 break;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800491 case MXT_FRAME_CRC_PASS:
Nick Dyerf943c742014-05-18 23:14:20 -0700492 if (val == MXT_FRAME_CRC_CHECK) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700493 goto recheck;
Nick Dyerf943c742014-05-18 23:14:20 -0700494 } else if (val == MXT_FRAME_CRC_FAIL) {
495 dev_err(dev, "Bootloader CRC fail\n");
496 return -EINVAL;
497 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700498 break;
499 default:
500 return -EINVAL;
501 }
502
503 if (val != state) {
Nick Dyerf28a8422014-05-18 23:10:49 -0700504 dev_err(dev, "Invalid bootloader state %02X != %02X\n",
Nick Dyer7bed6802014-05-18 23:04:09 -0700505 val, state);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700506 return -EINVAL;
507 }
508
509 return 0;
510}
511
Nick Dyerf28a8422014-05-18 23:10:49 -0700512static int mxt_unlock_bootloader(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700513{
Nick Dyerf28a8422014-05-18 23:10:49 -0700514 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700515 u8 buf[2];
516
Iiro Valkonen7686b102011-02-02 23:21:58 -0800517 buf[0] = MXT_UNLOCK_CMD_LSB;
518 buf[1] = MXT_UNLOCK_CMD_MSB;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700519
Nick Dyerf28a8422014-05-18 23:10:49 -0700520 ret = mxt_bootloader_write(data, buf, 2);
521 if (ret)
522 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700523
524 return 0;
525}
526
Iiro Valkonen7686b102011-02-02 23:21:58 -0800527static int __mxt_read_reg(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700528 u16 reg, u16 len, void *val)
529{
530 struct i2c_msg xfer[2];
531 u8 buf[2];
Daniel Kurtz771733e2012-06-28 21:08:11 +0800532 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700533
534 buf[0] = reg & 0xff;
535 buf[1] = (reg >> 8) & 0xff;
536
537 /* Write register */
538 xfer[0].addr = client->addr;
539 xfer[0].flags = 0;
540 xfer[0].len = 2;
541 xfer[0].buf = buf;
542
543 /* Read data */
544 xfer[1].addr = client->addr;
545 xfer[1].flags = I2C_M_RD;
546 xfer[1].len = len;
547 xfer[1].buf = val;
548
Daniel Kurtz771733e2012-06-28 21:08:11 +0800549 ret = i2c_transfer(client->adapter, xfer, 2);
550 if (ret == 2) {
551 ret = 0;
552 } else {
553 if (ret >= 0)
554 ret = -EIO;
555 dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
556 __func__, ret);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700557 }
558
Daniel Kurtz771733e2012-06-28 21:08:11 +0800559 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700560}
561
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800562static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
563 const void *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700564{
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800565 u8 *buf;
566 size_t count;
Daniel Kurtz771733e2012-06-28 21:08:11 +0800567 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700568
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800569 count = len + 2;
570 buf = kmalloc(count, GFP_KERNEL);
571 if (!buf)
572 return -ENOMEM;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700573
574 buf[0] = reg & 0xff;
575 buf[1] = (reg >> 8) & 0xff;
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800576 memcpy(&buf[2], val, len);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700577
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800578 ret = i2c_master_send(client, buf, count);
579 if (ret == count) {
Daniel Kurtz771733e2012-06-28 21:08:11 +0800580 ret = 0;
581 } else {
582 if (ret >= 0)
583 ret = -EIO;
584 dev_err(&client->dev, "%s: i2c send failed (%d)\n",
585 __func__, ret);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700586 }
587
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800588 kfree(buf);
Daniel Kurtz771733e2012-06-28 21:08:11 +0800589 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700590}
591
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800592static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700593{
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800594 return __mxt_write_reg(client, reg, 1, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700595}
596
Iiro Valkonen7686b102011-02-02 23:21:58 -0800597static struct mxt_object *
598mxt_get_object(struct mxt_data *data, u8 type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700599{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800600 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700601 int i;
602
603 for (i = 0; i < data->info.object_num; i++) {
604 object = data->object_table + i;
605 if (object->type == type)
606 return object;
607 }
608
Nick Dyer7bed6802014-05-18 23:04:09 -0700609 dev_err(&data->client->dev, "Invalid object type T%u\n", type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700610 return NULL;
611}
612
Iiro Valkonen7686b102011-02-02 23:21:58 -0800613static int mxt_read_message(struct mxt_data *data,
614 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700615{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800616 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700617 u16 reg;
618
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700619 object = mxt_get_object(data, MXT_GEN_MESSAGE_T5);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700620 if (!object)
621 return -EINVAL;
622
623 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800624 return __mxt_read_reg(data->client, reg,
625 sizeof(struct mxt_message), message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700626}
627
Iiro Valkonen7686b102011-02-02 23:21:58 -0800628static int mxt_write_object(struct mxt_data *data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700629 u8 type, u8 offset, u8 val)
630{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800631 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700632 u16 reg;
633
Iiro Valkonen7686b102011-02-02 23:21:58 -0800634 object = mxt_get_object(data, type);
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -0700635 if (!object || offset >= mxt_obj_size(object))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700636 return -EINVAL;
637
638 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800639 return mxt_write_reg(data->client, reg + offset, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700640}
641
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800642static void mxt_input_button(struct mxt_data *data, struct mxt_message *message)
643{
644 struct input_dev *input = data->input_dev;
Nick Dyerfb5e4c3e2014-05-18 23:00:15 -0700645 const struct mxt_platform_data *pdata = data->pdata;
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800646 bool button;
647 int i;
648
649 /* Active-low switch */
Nick Dyerfb5e4c3e2014-05-18 23:00:15 -0700650 for (i = 0; i < pdata->t19_num_keys; i++) {
651 if (pdata->t19_keymap[i] == KEY_RESERVED)
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800652 continue;
Nick Dyerfb5e4c3e2014-05-18 23:00:15 -0700653 button = !(message->message[0] & (1 << i));
654 input_report_key(input, pdata->t19_keymap[i], button);
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800655 }
656}
657
Benson Leungb735fbe2014-07-23 12:22:27 -0700658static void mxt_input_sync(struct mxt_data *data)
Nick Dyereef820d2014-05-18 23:22:22 -0700659{
Benson Leungb735fbe2014-07-23 12:22:27 -0700660 input_mt_report_pointer_emulation(data->input_dev,
661 data->pdata->t19_num_keys);
662 input_sync(data->input_dev);
Nick Dyereef820d2014-05-18 23:22:22 -0700663}
664
Iiro Valkonen7686b102011-02-02 23:21:58 -0800665static void mxt_input_touchevent(struct mxt_data *data,
666 struct mxt_message *message, int id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700667{
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700668 struct device *dev = &data->client->dev;
669 u8 status = message->message[0];
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800670 struct input_dev *input_dev = data->input_dev;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700671 int x;
672 int y;
673 int area;
Nick Dyerfea9e462014-05-18 23:21:48 -0700674 int amplitude;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700675
Joonyoung Shim910d8052011-04-12 23:14:38 -0700676 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
677 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
Nick Dyereef820d2014-05-18 23:22:22 -0700678
679 /* Handle 10/12 bit switching */
Joonyoung Shim910d8052011-04-12 23:14:38 -0700680 if (data->max_x < 1024)
Nick Dyereef820d2014-05-18 23:22:22 -0700681 x >>= 2;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700682 if (data->max_y < 1024)
Nick Dyereef820d2014-05-18 23:22:22 -0700683 y >>= 2;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700684
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700685 area = message->message[4];
Nick Dyerfea9e462014-05-18 23:21:48 -0700686 amplitude = message->message[5];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700687
Daniel Kurtzb2e459b2012-06-28 21:08:18 +0800688 dev_dbg(dev,
689 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
690 id,
Nick Dyerf3889ed2014-05-18 23:22:04 -0700691 (status & MXT_T9_DETECT) ? 'D' : '.',
692 (status & MXT_T9_PRESS) ? 'P' : '.',
693 (status & MXT_T9_RELEASE) ? 'R' : '.',
694 (status & MXT_T9_MOVE) ? 'M' : '.',
695 (status & MXT_T9_VECTOR) ? 'V' : '.',
696 (status & MXT_T9_AMP) ? 'A' : '.',
697 (status & MXT_T9_SUPPRESS) ? 'S' : '.',
698 (status & MXT_T9_UNGRIP) ? 'U' : '.',
Nick Dyerfea9e462014-05-18 23:21:48 -0700699 x, y, area, amplitude);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700700
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800701 input_mt_slot(input_dev, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700702
Nick Dyerf3889ed2014-05-18 23:22:04 -0700703 if (status & MXT_T9_DETECT) {
Nick Dyereef820d2014-05-18 23:22:22 -0700704 /*
705 * Multiple bits may be set if the host is slow to read
706 * the status messages, indicating all the events that
707 * have happened.
708 */
709 if (status & MXT_T9_RELEASE) {
710 input_mt_report_slot_state(input_dev,
711 MT_TOOL_FINGER, 0);
Benson Leungb735fbe2014-07-23 12:22:27 -0700712 mxt_input_sync(data);
Nick Dyereef820d2014-05-18 23:22:22 -0700713 }
714
715 /* Touch active */
716 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1);
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800717 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
718 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
Nick Dyerfea9e462014-05-18 23:21:48 -0700719 input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude);
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800720 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
Nick Dyereef820d2014-05-18 23:22:22 -0700721 } else {
722 /* Touch no longer active, close out slot */
723 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0);
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800724 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700725}
726
Nick Dyerc3f78042014-05-18 23:04:46 -0700727static u16 mxt_extract_T6_csum(const u8 *csum)
Daniel Kurtzfdf804212012-06-28 21:08:24 +0800728{
729 return csum[0] | (csum[1] << 8) | (csum[2] << 16);
730}
731
Daniel Kurtz04a79182012-06-28 21:08:21 +0800732static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg)
733{
734 u8 id = msg->reportid;
735 return (id >= data->T9_reportid_min && id <= data->T9_reportid_max);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700736}
737
Benson Leungd79e7e42014-05-18 23:02:52 -0700738static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700739{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800740 struct mxt_message message;
Daniel Kurtzfdf804212012-06-28 21:08:24 +0800741 const u8 *payload = &message.message[0];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700742 struct device *dev = &data->client->dev;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700743 u8 reportid;
Daniel Kurtz64464ae2012-06-28 21:08:23 +0800744 bool update_input = false;
Nick Dyerc3f78042014-05-18 23:04:46 -0700745 u32 crc;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700746
747 do {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800748 if (mxt_read_message(data, &message)) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700749 dev_err(dev, "Failed to read message\n");
Nick Dyer8d4e1632014-05-18 23:00:56 -0700750 return IRQ_NONE;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700751 }
752
753 reportid = message.reportid;
754
Daniel Kurtzfdf804212012-06-28 21:08:24 +0800755 if (reportid == data->T6_reportid) {
756 u8 status = payload[0];
Nick Dyerc3f78042014-05-18 23:04:46 -0700757
758 crc = mxt_extract_T6_csum(&payload[1]);
759 if (crc != data->config_crc) {
760 data->config_crc = crc;
761 complete(&data->crc_completion);
762 }
763
Daniel Kurtzfdf804212012-06-28 21:08:24 +0800764 dev_dbg(dev, "Status: %02x Config Checksum: %06x\n",
Nick Dyerc3f78042014-05-18 23:04:46 -0700765 status, data->config_crc);
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700766
767 if (status & MXT_T6_STATUS_RESET)
768 complete(&data->reset_completion);
Nick Dyerdd24dcf2014-07-23 11:25:55 -0700769 } else if (!data->input_dev) {
770 /*
771 * do not report events if input device
772 * is not yet registered
773 */
774 mxt_dump_message(dev, &message);
Daniel Kurtzfdf804212012-06-28 21:08:24 +0800775 } else if (mxt_is_T9_message(data, &message)) {
776 int id = reportid - data->T9_reportid_min;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800777 mxt_input_touchevent(data, &message, id);
Daniel Kurtz64464ae2012-06-28 21:08:23 +0800778 update_input = true;
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800779 } else if (message.reportid == data->T19_reportid) {
780 mxt_input_button(data, &message);
781 update_input = true;
Daniel Kurtz64464ae2012-06-28 21:08:23 +0800782 } else {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800783 mxt_dump_message(dev, &message);
Daniel Kurtz64464ae2012-06-28 21:08:23 +0800784 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700785 } while (reportid != 0xff);
786
Nick Dyereef820d2014-05-18 23:22:22 -0700787 if (update_input)
Benson Leungb735fbe2014-07-23 12:22:27 -0700788 mxt_input_sync(data);
Daniel Kurtz64464ae2012-06-28 21:08:23 +0800789
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700790 return IRQ_HANDLED;
791}
792
Benson Leungd79e7e42014-05-18 23:02:52 -0700793static irqreturn_t mxt_interrupt(int irq, void *dev_id)
794{
795 struct mxt_data *data = dev_id;
796
797 if (data->in_bootloader) {
798 /* bootloader state transition completion */
799 complete(&data->bl_completion);
800 return IRQ_HANDLED;
801 }
802
Nick Dyerdd24dcf2014-07-23 11:25:55 -0700803 if (!data->object_table)
804 return IRQ_HANDLED;
805
Benson Leungd79e7e42014-05-18 23:02:52 -0700806 return mxt_process_messages_until_invalid(data);
807}
808
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700809static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset,
810 u8 value, bool wait)
811{
812 u16 reg;
813 u8 command_register;
814 int timeout_counter = 0;
815 int ret;
816
817 reg = data->T6_address + cmd_offset;
818
819 ret = mxt_write_reg(data->client, reg, value);
820 if (ret)
821 return ret;
822
823 if (!wait)
824 return 0;
825
826 do {
827 msleep(20);
828 ret = __mxt_read_reg(data->client, reg, 1, &command_register);
829 if (ret)
830 return ret;
831 } while (command_register != 0 && timeout_counter++ <= 100);
832
833 if (timeout_counter > 100) {
834 dev_err(&data->client->dev, "Command failed!\n");
835 return -EIO;
836 }
837
838 return 0;
839}
840
841static int mxt_soft_reset(struct mxt_data *data)
842{
843 struct device *dev = &data->client->dev;
844 int ret = 0;
845
846 dev_info(dev, "Resetting chip\n");
847
848 reinit_completion(&data->reset_completion);
849
850 ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_RESET_VALUE, false);
851 if (ret)
852 return ret;
853
854 ret = mxt_wait_for_completion(data, &data->reset_completion,
855 MXT_RESET_TIMEOUT);
856 if (ret)
857 return ret;
858
859 return 0;
860}
861
Nick Dyerc3f78042014-05-18 23:04:46 -0700862static void mxt_update_crc(struct mxt_data *data, u8 cmd, u8 value)
863{
864 /*
865 * On failure, CRC is set to 0 and config will always be
866 * downloaded.
867 */
868 data->config_crc = 0;
869 reinit_completion(&data->crc_completion);
870
871 mxt_t6_command(data, cmd, value, true);
872
873 /*
874 * Wait for crc message. On failure, CRC is set to 0 and config will
875 * always be downloaded.
876 */
877 mxt_wait_for_completion(data, &data->crc_completion, MXT_CRC_TIMEOUT);
878}
879
Iiro Valkonen7686b102011-02-02 23:21:58 -0800880static int mxt_check_reg_init(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700881{
Iiro Valkonen71749f52011-02-15 13:36:52 -0800882 const struct mxt_platform_data *pdata = data->pdata;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800883 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700884 struct device *dev = &data->client->dev;
885 int index = 0;
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800886 int i, size;
887 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700888
Iiro Valkonen71749f52011-02-15 13:36:52 -0800889 if (!pdata->config) {
890 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
891 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700892 }
893
Nick Dyerc3f78042014-05-18 23:04:46 -0700894 mxt_update_crc(data, MXT_COMMAND_REPORTALL, 1);
895
896 if (data->config_crc == pdata->config_crc) {
897 dev_info(dev, "Config CRC 0x%06X: OK\n", data->config_crc);
898 return 0;
899 }
900
901 dev_info(dev, "Config CRC 0x%06X: does not match 0x%06X\n",
902 data->config_crc, pdata->config_crc);
903
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700904 for (i = 0; i < data->info.object_num; i++) {
905 object = data->object_table + i;
906
Iiro Valkonen7686b102011-02-02 23:21:58 -0800907 if (!mxt_object_writable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700908 continue;
909
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -0700910 size = mxt_obj_size(object) * mxt_obj_instances(object);
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800911 if (index + size > pdata->config_length) {
912 dev_err(dev, "Not enough config data!\n");
913 return -EINVAL;
Iiro Valkonen71749f52011-02-15 13:36:52 -0800914 }
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800915
916 ret = __mxt_write_reg(data->client, object->start_address,
917 size, &pdata->config[index]);
918 if (ret)
919 return ret;
920 index += size;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700921 }
922
Nick Dyerc3f78042014-05-18 23:04:46 -0700923 mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE);
924
925 ret = mxt_soft_reset(data);
926 if (ret)
927 return ret;
928
929 dev_info(dev, "Config successfully updated\n");
930
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700931 return 0;
932}
933
Iiro Valkonen7686b102011-02-02 23:21:58 -0800934static int mxt_make_highchg(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700935{
936 struct device *dev = &data->client->dev;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800937 struct mxt_message message;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700938 int count = 10;
939 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700940
941 /* Read dummy message to make high CHG pin */
942 do {
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800943 error = mxt_read_message(data, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700944 if (error)
945 return error;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800946 } while (message.reportid != 0xff && --count);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700947
948 if (!count) {
949 dev_err(dev, "CHG pin isn't cleared\n");
950 return -EBUSY;
951 }
952
953 return 0;
954}
955
Nick Dyerdd24dcf2014-07-23 11:25:55 -0700956static int mxt_acquire_irq(struct mxt_data *data)
957{
958 int error;
959
960 enable_irq(data->irq);
961
962 error = mxt_make_highchg(data);
963 if (error)
964 return error;
965
966 return 0;
967}
968
Iiro Valkonen7686b102011-02-02 23:21:58 -0800969static int mxt_get_info(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700970{
971 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800972 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700973 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700974
Daniel Kurtz23003a842012-06-28 21:08:14 +0800975 /* Read 7-byte info block starting at address 0 */
976 error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700977 if (error)
978 return error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700979
980 return 0;
981}
982
Iiro Valkonen7686b102011-02-02 23:21:58 -0800983static int mxt_get_object_table(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700984{
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800985 struct i2c_client *client = data->client;
986 size_t table_size;
Nick Dyerdd24dcf2014-07-23 11:25:55 -0700987 struct mxt_object *object_table;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700988 int error;
989 int i;
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800990 u8 reportid;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700991
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800992 table_size = data->info.object_num * sizeof(struct mxt_object);
Nick Dyerdd24dcf2014-07-23 11:25:55 -0700993 object_table = kzalloc(table_size, GFP_KERNEL);
994 if (!object_table) {
995 dev_err(&data->client->dev, "Failed to allocate memory\n");
996 return -ENOMEM;
997 }
998
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800999 error = __mxt_read_reg(client, MXT_OBJECT_START, table_size,
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001000 object_table);
1001 if (error) {
1002 kfree(object_table);
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001003 return error;
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001004 }
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001005
1006 /* Valid Report IDs start counting from 1 */
1007 reportid = 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001008 for (i = 0; i < data->info.object_num; i++) {
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001009 struct mxt_object *object = object_table + i;
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001010 u8 min_id, max_id;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001011
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001012 le16_to_cpus(&object->start_address);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001013
1014 if (object->num_report_ids) {
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001015 min_id = reportid;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001016 reportid += object->num_report_ids *
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07001017 mxt_obj_instances(object);
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001018 max_id = reportid - 1;
1019 } else {
1020 min_id = 0;
1021 max_id = 0;
1022 }
1023
1024 dev_dbg(&data->client->dev,
Nick Dyer7bed6802014-05-18 23:04:09 -07001025 "T%u Start:%u Size:%zu Instances:%zu Report IDs:%u-%u\n",
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07001026 object->type, object->start_address,
1027 mxt_obj_size(object), mxt_obj_instances(object),
1028 min_id, max_id);
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001029
1030 switch (object->type) {
Daniel Kurtzfdf804212012-06-28 21:08:24 +08001031 case MXT_GEN_COMMAND_T6:
1032 data->T6_reportid = min_id;
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001033 data->T6_address = object->start_address;
Daniel Kurtzfdf804212012-06-28 21:08:24 +08001034 break;
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001035 case MXT_TOUCH_MULTI_T9:
1036 data->T9_reportid_min = min_id;
1037 data->T9_reportid_max = max_id;
1038 break;
Daniel Kurtz22dfab72013-03-07 19:43:33 -08001039 case MXT_SPT_GPIOPWM_T19:
1040 data->T19_reportid = min_id;
1041 break;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001042 }
1043 }
1044
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001045 data->object_table = object_table;
1046
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001047 return 0;
1048}
1049
Daniel Kurtz7d4fa102012-06-28 21:08:19 +08001050static void mxt_free_object_table(struct mxt_data *data)
1051{
Nick Dyer7a53d602014-07-23 12:21:26 -07001052 input_unregister_device(data->input_dev);
1053 data->input_dev = NULL;
1054
Daniel Kurtz7d4fa102012-06-28 21:08:19 +08001055 kfree(data->object_table);
1056 data->object_table = NULL;
Daniel Kurtzfdf804212012-06-28 21:08:24 +08001057 data->T6_reportid = 0;
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001058 data->T9_reportid_min = 0;
1059 data->T9_reportid_max = 0;
Daniel Kurtz22dfab72013-03-07 19:43:33 -08001060 data->T19_reportid = 0;
Daniel Kurtz7d4fa102012-06-28 21:08:19 +08001061}
1062
Nick Dyer61dc1ab2014-05-18 23:16:49 -07001063static int mxt_read_t9_resolution(struct mxt_data *data)
1064{
1065 struct i2c_client *client = data->client;
1066 int error;
1067 struct t9_range range;
1068 unsigned char orient;
1069 struct mxt_object *object;
1070
1071 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
1072 if (!object)
1073 return -EINVAL;
1074
1075 error = __mxt_read_reg(client,
1076 object->start_address + MXT_T9_RANGE,
1077 sizeof(range), &range);
1078 if (error)
1079 return error;
1080
1081 le16_to_cpus(&range.x);
1082 le16_to_cpus(&range.y);
1083
1084 error = __mxt_read_reg(client,
1085 object->start_address + MXT_T9_ORIENT,
1086 1, &orient);
1087 if (error)
1088 return error;
1089
1090 /* Handle default values */
1091 if (range.x == 0)
1092 range.x = 1023;
1093
1094 if (range.y == 0)
1095 range.y = 1023;
1096
Nick Dyerf3889ed2014-05-18 23:22:04 -07001097 if (orient & MXT_T9_ORIENT_SWITCH) {
Nick Dyer61dc1ab2014-05-18 23:16:49 -07001098 data->max_x = range.y;
1099 data->max_y = range.x;
1100 } else {
1101 data->max_x = range.x;
1102 data->max_y = range.y;
1103 }
1104
1105 dev_dbg(&client->dev,
1106 "Touchscreen size X%uY%u\n", data->max_x, data->max_y);
1107
1108 return 0;
1109}
1110
Nick Dyer7a53d602014-07-23 12:21:26 -07001111static int mxt_input_open(struct input_dev *dev);
1112static void mxt_input_close(struct input_dev *dev);
1113
1114static int mxt_initialize_t9_input_device(struct mxt_data *data)
1115{
1116 struct device *dev = &data->client->dev;
1117 const struct mxt_platform_data *pdata = data->pdata;
1118 struct input_dev *input_dev;
1119 int error;
1120 unsigned int num_mt_slots;
1121 unsigned int mt_flags = 0;
1122 int i;
1123
1124 error = mxt_read_t9_resolution(data);
1125 if (error)
1126 dev_warn(dev, "Failed to initialize T9 resolution\n");
1127
1128 input_dev = input_allocate_device();
1129 if (!input_dev) {
1130 dev_err(dev, "Failed to allocate memory\n");
1131 return -ENOMEM;
1132 }
1133
1134 input_dev->name = "Atmel maXTouch Touchscreen";
1135 input_dev->phys = data->phys;
1136 input_dev->id.bustype = BUS_I2C;
1137 input_dev->dev.parent = dev;
1138 input_dev->open = mxt_input_open;
1139 input_dev->close = mxt_input_close;
1140
1141 __set_bit(EV_ABS, input_dev->evbit);
1142 __set_bit(EV_KEY, input_dev->evbit);
1143 __set_bit(BTN_TOUCH, input_dev->keybit);
1144
1145 if (pdata->t19_num_keys) {
1146 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
1147
1148 for (i = 0; i < pdata->t19_num_keys; i++)
1149 if (pdata->t19_keymap[i] != KEY_RESERVED)
1150 input_set_capability(input_dev, EV_KEY,
1151 pdata->t19_keymap[i]);
1152
1153 mt_flags |= INPUT_MT_POINTER;
1154
1155 input_abs_set_res(input_dev, ABS_X, MXT_PIXELS_PER_MM);
1156 input_abs_set_res(input_dev, ABS_Y, MXT_PIXELS_PER_MM);
1157 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
1158 MXT_PIXELS_PER_MM);
1159 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
1160 MXT_PIXELS_PER_MM);
1161
1162 input_dev->name = "Atmel maXTouch Touchpad";
1163 }
1164
1165 /* For single touch */
1166 input_set_abs_params(input_dev, ABS_X,
1167 0, data->max_x, 0, 0);
1168 input_set_abs_params(input_dev, ABS_Y,
1169 0, data->max_y, 0, 0);
1170 input_set_abs_params(input_dev, ABS_PRESSURE,
1171 0, 255, 0, 0);
1172
1173 /* For multi touch */
1174 num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
1175 error = input_mt_init_slots(input_dev, num_mt_slots, mt_flags);
1176 if (error) {
1177 dev_err(dev, "Error %d initialising slots\n", error);
1178 goto err_free_mem;
1179 }
1180
1181 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1182 0, MXT_MAX_AREA, 0, 0);
1183 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1184 0, data->max_x, 0, 0);
1185 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1186 0, data->max_y, 0, 0);
1187 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
1188 0, 255, 0, 0);
1189
1190 input_set_drvdata(input_dev, data);
1191
1192 error = input_register_device(input_dev);
1193 if (error) {
1194 dev_err(dev, "Error %d registering input device\n", error);
1195 goto err_free_mem;
1196 }
1197
1198 data->input_dev = input_dev;
1199
1200 return 0;
1201
1202err_free_mem:
1203 input_free_device(input_dev);
1204 return error;
1205}
1206
Iiro Valkonen7686b102011-02-02 23:21:58 -08001207static int mxt_initialize(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001208{
1209 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001210 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001211 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001212
Iiro Valkonen7686b102011-02-02 23:21:58 -08001213 error = mxt_get_info(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001214 if (error)
1215 return error;
1216
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001217 /* Get object table information */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001218 error = mxt_get_object_table(data);
Nick Dyer7bed6802014-05-18 23:04:09 -07001219 if (error) {
1220 dev_err(&client->dev, "Error %d reading object table\n", error);
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001221 return error;
Nick Dyer7bed6802014-05-18 23:04:09 -07001222 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001223
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001224 mxt_acquire_irq(data);
1225 if (error)
1226 goto err_free_object_table;
1227
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001228 /* Check register init values */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001229 error = mxt_check_reg_init(data);
Nick Dyer7bed6802014-05-18 23:04:09 -07001230 if (error) {
1231 dev_err(&client->dev, "Error %d initializing configuration\n",
1232 error);
Daniel Kurtz7d4fa102012-06-28 21:08:19 +08001233 goto err_free_object_table;
Nick Dyer7bed6802014-05-18 23:04:09 -07001234 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001235
Nick Dyer7a53d602014-07-23 12:21:26 -07001236 error = mxt_initialize_t9_input_device(data);
1237 if (error)
Daniel Kurtz7d4fa102012-06-28 21:08:19 +08001238 goto err_free_object_table;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001239
1240 dev_info(&client->dev,
Nick Dyer61dc1ab2014-05-18 23:16:49 -07001241 "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n",
1242 info->family_id, info->variant_id, info->version >> 4,
1243 info->version & 0xf, info->build, info->object_num);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001244
1245 return 0;
Daniel Kurtz7d4fa102012-06-28 21:08:19 +08001246
1247err_free_object_table:
1248 mxt_free_object_table(data);
1249 return error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001250}
1251
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08001252/* Firmware Version is returned as Major.Minor.Build */
1253static ssize_t mxt_fw_version_show(struct device *dev,
1254 struct device_attribute *attr, char *buf)
1255{
1256 struct mxt_data *data = dev_get_drvdata(dev);
1257 struct mxt_info *info = &data->info;
1258 return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n",
1259 info->version >> 4, info->version & 0xf, info->build);
1260}
1261
1262/* Hardware Version is returned as FamilyID.VariantID */
1263static ssize_t mxt_hw_version_show(struct device *dev,
1264 struct device_attribute *attr, char *buf)
1265{
1266 struct mxt_data *data = dev_get_drvdata(dev);
1267 struct mxt_info *info = &data->info;
1268 return scnprintf(buf, PAGE_SIZE, "%u.%u\n",
1269 info->family_id, info->variant_id);
1270}
1271
Daniel Kurtz794eb672012-06-28 21:08:10 +08001272static ssize_t mxt_show_instance(char *buf, int count,
1273 struct mxt_object *object, int instance,
1274 const u8 *val)
1275{
1276 int i;
1277
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07001278 if (mxt_obj_instances(object) > 1)
Daniel Kurtz794eb672012-06-28 21:08:10 +08001279 count += scnprintf(buf + count, PAGE_SIZE - count,
1280 "Instance %u\n", instance);
1281
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07001282 for (i = 0; i < mxt_obj_size(object); i++)
Daniel Kurtz794eb672012-06-28 21:08:10 +08001283 count += scnprintf(buf + count, PAGE_SIZE - count,
1284 "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
1285 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
1286
1287 return count;
1288}
1289
Iiro Valkonen7686b102011-02-02 23:21:58 -08001290static ssize_t mxt_object_show(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001291 struct device_attribute *attr, char *buf)
1292{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001293 struct mxt_data *data = dev_get_drvdata(dev);
1294 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001295 int count = 0;
1296 int i, j;
1297 int error;
Daniel Kurtz43a91d52012-06-28 21:08:08 +08001298 u8 *obuf;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001299
Daniel Kurtz43a91d52012-06-28 21:08:08 +08001300 /* Pre-allocate buffer large enough to hold max sized object. */
1301 obuf = kmalloc(256, GFP_KERNEL);
1302 if (!obuf)
1303 return -ENOMEM;
1304
1305 error = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001306 for (i = 0; i < data->info.object_num; i++) {
1307 object = data->object_table + i;
1308
Daniel Kurtz91630952012-06-28 21:08:09 +08001309 if (!mxt_object_readable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001310 continue;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001311
Daniel Kurtz91630952012-06-28 21:08:09 +08001312 count += scnprintf(buf + count, PAGE_SIZE - count,
1313 "T%u:\n", object->type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001314
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07001315 for (j = 0; j < mxt_obj_instances(object); j++) {
1316 u16 size = mxt_obj_size(object);
Daniel Kurtz794eb672012-06-28 21:08:10 +08001317 u16 addr = object->start_address + j * size;
Daniel Kurtz43a91d52012-06-28 21:08:08 +08001318
Daniel Kurtz794eb672012-06-28 21:08:10 +08001319 error = __mxt_read_reg(data->client, addr, size, obuf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001320 if (error)
Daniel Kurtz794eb672012-06-28 21:08:10 +08001321 goto done;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001322
Daniel Kurtz794eb672012-06-28 21:08:10 +08001323 count = mxt_show_instance(buf, count, object, j, obuf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001324 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001325 }
1326
Daniel Kurtz794eb672012-06-28 21:08:10 +08001327done:
Daniel Kurtz43a91d52012-06-28 21:08:08 +08001328 kfree(obuf);
1329 return error ?: count;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001330}
1331
Nick Dyerf2ac6cb2014-05-18 23:15:01 -07001332static int mxt_check_firmware_format(struct device *dev,
1333 const struct firmware *fw)
1334{
1335 unsigned int pos = 0;
1336 char c;
1337
1338 while (pos < fw->size) {
1339 c = *(fw->data + pos);
1340
1341 if (c < '0' || (c > '9' && c < 'A') || c > 'F')
1342 return 0;
1343
1344 pos++;
1345 }
1346
1347 /*
1348 * To convert file try:
1349 * xxd -r -p mXTXXX__APP_VX-X-XX.enc > maxtouch.fw
1350 */
1351 dev_err(dev, "Aborting: firmware file must be in binary format\n");
1352
1353 return -EINVAL;
1354}
1355
Iiro Valkonen7686b102011-02-02 23:21:58 -08001356static int mxt_load_fw(struct device *dev, const char *fn)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001357{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001358 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001359 const struct firmware *fw = NULL;
1360 unsigned int frame_size;
1361 unsigned int pos = 0;
Nick Dyerf943c742014-05-18 23:14:20 -07001362 unsigned int retry = 0;
Nick Dyerf477c752014-05-18 23:14:45 -07001363 unsigned int frame = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001364 int ret;
1365
1366 ret = request_firmware(&fw, fn, dev);
1367 if (ret) {
1368 dev_err(dev, "Unable to open firmware %s\n", fn);
1369 return ret;
1370 }
1371
Nick Dyerf2ac6cb2014-05-18 23:15:01 -07001372 /* Check for incorrect enc file */
1373 ret = mxt_check_firmware_format(dev, fw);
1374 if (ret)
1375 goto release_firmware;
1376
Nick Dyerf28a8422014-05-18 23:10:49 -07001377 ret = mxt_lookup_bootloader_address(data);
1378 if (ret)
1379 goto release_firmware;
1380
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001381 /* Change to the bootloader mode */
Benson Leungd79e7e42014-05-18 23:02:52 -07001382 data->in_bootloader = true;
1383
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001384 ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_BOOT_VALUE, false);
1385 if (ret)
1386 goto release_firmware;
1387
Iiro Valkonen7686b102011-02-02 23:21:58 -08001388 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001389
Benson Leungd79e7e42014-05-18 23:02:52 -07001390 reinit_completion(&data->bl_completion);
1391
1392 ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001393 if (ret)
Benson Leungd79e7e42014-05-18 23:02:52 -07001394 goto disable_irq;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001395
1396 /* Unlock bootloader */
Nick Dyerf28a8422014-05-18 23:10:49 -07001397 mxt_unlock_bootloader(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001398
1399 while (pos < fw->size) {
Benson Leungd79e7e42014-05-18 23:02:52 -07001400 ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001401 if (ret)
Benson Leungd79e7e42014-05-18 23:02:52 -07001402 goto disable_irq;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001403
1404 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
1405
Nick Dyerf943c742014-05-18 23:14:20 -07001406 /* Take account of CRC bytes */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001407 frame_size += 2;
1408
1409 /* Write one frame to device */
Nick Dyerf28a8422014-05-18 23:10:49 -07001410 ret = mxt_bootloader_write(data, fw->data + pos, frame_size);
1411 if (ret)
1412 goto disable_irq;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001413
Benson Leungd79e7e42014-05-18 23:02:52 -07001414 ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS);
Nick Dyerf943c742014-05-18 23:14:20 -07001415 if (ret) {
1416 retry++;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001417
Nick Dyerf943c742014-05-18 23:14:20 -07001418 /* Back off by 20ms per retry */
1419 msleep(retry * 20);
1420
1421 if (retry > 20) {
1422 dev_err(dev, "Retry count exceeded\n");
1423 goto disable_irq;
1424 }
1425 } else {
1426 retry = 0;
1427 pos += frame_size;
Nick Dyerf477c752014-05-18 23:14:45 -07001428 frame++;
Nick Dyerf943c742014-05-18 23:14:20 -07001429 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001430
Nick Dyerf477c752014-05-18 23:14:45 -07001431 if (frame % 50 == 0)
1432 dev_dbg(dev, "Sent %d frames, %d/%zd bytes\n",
1433 frame, pos, fw->size);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001434 }
1435
Benson Leunga0434b72014-05-18 23:03:09 -07001436 /* Wait for flash. */
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001437 ret = mxt_wait_for_completion(data, &data->bl_completion,
1438 MXT_FW_RESET_TIME);
Benson Leunga0434b72014-05-18 23:03:09 -07001439 if (ret)
1440 goto disable_irq;
1441
Nick Dyerf477c752014-05-18 23:14:45 -07001442 dev_dbg(dev, "Sent %d frames, %d bytes\n", frame, pos);
1443
Benson Leunga0434b72014-05-18 23:03:09 -07001444 /*
1445 * Wait for device to reset. Some bootloader versions do not assert
1446 * the CHG line after bootloading has finished, so ignore potential
1447 * errors.
1448 */
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001449 mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME);
Benson Leunga0434b72014-05-18 23:03:09 -07001450
Benson Leungd79e7e42014-05-18 23:02:52 -07001451 data->in_bootloader = false;
1452
1453disable_irq:
1454 disable_irq(data->irq);
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001455release_firmware:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001456 release_firmware(fw);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001457 return ret;
1458}
1459
Iiro Valkonen7686b102011-02-02 23:21:58 -08001460static ssize_t mxt_update_fw_store(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001461 struct device_attribute *attr,
1462 const char *buf, size_t count)
1463{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001464 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001465 int error;
1466
Iiro Valkonen7686b102011-02-02 23:21:58 -08001467 error = mxt_load_fw(dev, MXT_FW_NAME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001468 if (error) {
1469 dev_err(dev, "The firmware update failed(%d)\n", error);
1470 count = error;
1471 } else {
Nick Dyer7bed6802014-05-18 23:04:09 -07001472 dev_info(dev, "The firmware update succeeded\n");
1473
Daniel Kurtz7d4fa102012-06-28 21:08:19 +08001474 mxt_free_object_table(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001475
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001476 error = mxt_initialize(data);
Benson Leungd79e7e42014-05-18 23:02:52 -07001477 if (error)
1478 return error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001479 }
1480
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001481 return count;
1482}
1483
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08001484static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
1485static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
Daniel Kurtz71b3e932012-05-08 22:30:14 -07001486static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
1487static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001488
Iiro Valkonen7686b102011-02-02 23:21:58 -08001489static struct attribute *mxt_attrs[] = {
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08001490 &dev_attr_fw_version.attr,
1491 &dev_attr_hw_version.attr,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001492 &dev_attr_object.attr,
1493 &dev_attr_update_fw.attr,
1494 NULL
1495};
1496
Iiro Valkonen7686b102011-02-02 23:21:58 -08001497static const struct attribute_group mxt_attr_group = {
1498 .attrs = mxt_attrs,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001499};
1500
Iiro Valkonen7686b102011-02-02 23:21:58 -08001501static void mxt_start(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001502{
1503 /* Touch enable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001504 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001505 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001506}
1507
Iiro Valkonen7686b102011-02-02 23:21:58 -08001508static void mxt_stop(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001509{
1510 /* Touch disable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001511 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001512 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001513}
1514
Iiro Valkonen7686b102011-02-02 23:21:58 -08001515static int mxt_input_open(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001516{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001517 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001518
Iiro Valkonen7686b102011-02-02 23:21:58 -08001519 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001520
1521 return 0;
1522}
1523
Iiro Valkonen7686b102011-02-02 23:21:58 -08001524static void mxt_input_close(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001525{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001526 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001527
Iiro Valkonen7686b102011-02-02 23:21:58 -08001528 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001529}
1530
Stephen Warren78188be2014-07-23 12:23:23 -07001531#ifdef CONFIG_OF
1532static struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
1533{
1534 struct mxt_platform_data *pdata;
1535 u32 *keymap;
1536 u32 keycode;
1537 int proplen, i, ret;
1538
1539 if (!client->dev.of_node)
1540 return ERR_PTR(-ENODEV);
1541
1542 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
1543 if (!pdata)
1544 return ERR_PTR(-ENOMEM);
1545
1546 if (of_find_property(client->dev.of_node, "linux,gpio-keymap",
1547 &proplen)) {
1548 pdata->t19_num_keys = proplen / sizeof(u32);
1549
1550 keymap = devm_kzalloc(&client->dev,
1551 pdata->t19_num_keys * sizeof(keymap[0]),
1552 GFP_KERNEL);
1553 if (!keymap)
1554 return ERR_PTR(-ENOMEM);
1555
1556 for (i = 0; i < pdata->t19_num_keys; i++) {
1557 ret = of_property_read_u32_index(client->dev.of_node,
1558 "linux,gpio-keymap", i, &keycode);
1559 if (ret)
1560 keycode = KEY_RESERVED;
1561
1562 keymap[i] = keycode;
1563 }
1564
1565 pdata->t19_keymap = keymap;
1566 }
1567
1568 return pdata;
1569}
1570#else
1571static struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
1572{
1573 dev_dbg(&client->dev, "No platform data specified\n");
1574 return ERR_PTR(-EINVAL);
1575}
1576#endif
1577
1578static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001579{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001580 struct mxt_data *data;
Stephen Warren78188be2014-07-23 12:23:23 -07001581 const struct mxt_platform_data *pdata;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001582 int error;
1583
Stephen Warren78188be2014-07-23 12:23:23 -07001584 pdata = dev_get_platdata(&client->dev);
1585 if (!pdata) {
1586 pdata = mxt_parse_dt(client);
1587 if (IS_ERR(pdata))
1588 return PTR_ERR(pdata);
1589 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001590
Iiro Valkonen7686b102011-02-02 23:21:58 -08001591 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
Nick Dyer7a53d602014-07-23 12:21:26 -07001592 if (!data) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001593 dev_err(&client->dev, "Failed to allocate memory\n");
Nick Dyer7a53d602014-07-23 12:21:26 -07001594 return -ENOMEM;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001595 }
1596
Daniel Kurtzec02ac22012-06-28 21:08:02 +08001597 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1598 client->adapter->nr, client->addr);
Daniel Kurtz22dfab72013-03-07 19:43:33 -08001599
Joonyoung Shim910d8052011-04-12 23:14:38 -07001600 data->client = client;
Joonyoung Shim910d8052011-04-12 23:14:38 -07001601 data->pdata = pdata;
1602 data->irq = client->irq;
Nick Dyer7a53d602014-07-23 12:21:26 -07001603 i2c_set_clientdata(client, data);
Joonyoung Shim910d8052011-04-12 23:14:38 -07001604
Benson Leungd79e7e42014-05-18 23:02:52 -07001605 init_completion(&data->bl_completion);
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001606 init_completion(&data->reset_completion);
Nick Dyerc3f78042014-05-18 23:04:46 -07001607 init_completion(&data->crc_completion);
Benson Leungd79e7e42014-05-18 23:02:52 -07001608
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001609 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
1610 pdata->irqflags | IRQF_ONESHOT,
1611 client->name, data);
1612 if (error) {
1613 dev_err(&client->dev, "Failed to register interrupt\n");
1614 goto err_free_mem;
1615 }
1616
1617 disable_irq(client->irq);
1618
Daniel Kurtzcb159112012-06-28 21:08:22 +08001619 error = mxt_initialize(data);
1620 if (error)
Nick Dyer7a53d602014-07-23 12:21:26 -07001621 goto err_free_irq;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001622
Iiro Valkonen7686b102011-02-02 23:21:58 -08001623 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
Nick Dyer7bed6802014-05-18 23:04:09 -07001624 if (error) {
1625 dev_err(&client->dev, "Failure %d creating sysfs group\n",
1626 error);
Nick Dyer7a53d602014-07-23 12:21:26 -07001627 goto err_free_object;
Nick Dyer7bed6802014-05-18 23:04:09 -07001628 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001629
1630 return 0;
1631
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001632err_free_object:
1633 kfree(data->object_table);
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001634err_free_irq:
1635 free_irq(client->irq, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001636err_free_mem:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001637 kfree(data);
1638 return error;
1639}
1640
Bill Pembertone2619cf2012-11-23 21:50:47 -08001641static int mxt_remove(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001642{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001643 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001644
Iiro Valkonen7686b102011-02-02 23:21:58 -08001645 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001646 free_irq(data->irq, data);
1647 input_unregister_device(data->input_dev);
1648 kfree(data->object_table);
1649 kfree(data);
1650
1651 return 0;
1652}
1653
Daniel Kurtz3a73c812012-05-08 22:29:14 -07001654#ifdef CONFIG_PM_SLEEP
Iiro Valkonen7686b102011-02-02 23:21:58 -08001655static int mxt_suspend(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001656{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001657 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08001658 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001659 struct input_dev *input_dev = data->input_dev;
1660
1661 mutex_lock(&input_dev->mutex);
1662
1663 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08001664 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001665
1666 mutex_unlock(&input_dev->mutex);
1667
1668 return 0;
1669}
1670
Iiro Valkonen7686b102011-02-02 23:21:58 -08001671static int mxt_resume(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001672{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001673 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08001674 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001675 struct input_dev *input_dev = data->input_dev;
1676
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001677 mxt_soft_reset(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001678
1679 mutex_lock(&input_dev->mutex);
1680
1681 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08001682 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001683
1684 mutex_unlock(&input_dev->mutex);
1685
1686 return 0;
1687}
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001688#endif
1689
Daniel Kurtz3a73c812012-05-08 22:29:14 -07001690static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
1691
Stephen Warren78188be2014-07-23 12:23:23 -07001692static const struct of_device_id mxt_of_match[] = {
1693 { .compatible = "atmel,maxtouch", },
1694 {},
1695};
1696MODULE_DEVICE_TABLE(of, mxt_of_match);
1697
Iiro Valkonen7686b102011-02-02 23:21:58 -08001698static const struct i2c_device_id mxt_id[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001699 { "qt602240_ts", 0 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001700 { "atmel_mxt_ts", 0 },
Daniel Kurtz22dfab72013-03-07 19:43:33 -08001701 { "atmel_mxt_tp", 0 },
Chris Leech46ee2a02011-02-15 13:36:52 -08001702 { "mXT224", 0 },
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001703 { }
1704};
Iiro Valkonen7686b102011-02-02 23:21:58 -08001705MODULE_DEVICE_TABLE(i2c, mxt_id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001706
Iiro Valkonen7686b102011-02-02 23:21:58 -08001707static struct i2c_driver mxt_driver = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001708 .driver = {
Iiro Valkonen7686b102011-02-02 23:21:58 -08001709 .name = "atmel_mxt_ts",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001710 .owner = THIS_MODULE,
Stephen Warren78188be2014-07-23 12:23:23 -07001711 .of_match_table = of_match_ptr(mxt_of_match),
Iiro Valkonen7686b102011-02-02 23:21:58 -08001712 .pm = &mxt_pm_ops,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001713 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001714 .probe = mxt_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -08001715 .remove = mxt_remove,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001716 .id_table = mxt_id,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001717};
1718
Axel Lin1b92c1c2012-03-16 23:05:41 -07001719module_i2c_driver(mxt_driver);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001720
1721/* Module information */
1722MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
Iiro Valkonen7686b102011-02-02 23:21:58 -08001723MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001724MODULE_LICENSE("GPL");