blob: d6b64a0fed457d182742143e84493f0576b5834e [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
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/firmware.h>
18#include <linux/i2c.h>
Dmitry Torokhov964de522011-02-02 23:21:58 -080019#include <linux/i2c/atmel_mxt_ts.h>
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -070020#include <linux/input/mt.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070021#include <linux/interrupt.h>
22#include <linux/slab.h>
23
24/* Version */
Iiro Valkonen7686b102011-02-02 23:21:58 -080025#define MXT_VER_20 20
26#define MXT_VER_21 21
27#define MXT_VER_22 22
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070028
29/* Slave addresses */
Iiro Valkonen7686b102011-02-02 23:21:58 -080030#define MXT_APP_LOW 0x4a
31#define MXT_APP_HIGH 0x4b
32#define MXT_BOOT_LOW 0x24
33#define MXT_BOOT_HIGH 0x25
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070034
35/* Firmware */
Iiro Valkonen7686b102011-02-02 23:21:58 -080036#define MXT_FW_NAME "maxtouch.fw"
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070037
38/* Registers */
Daniel Kurtz23003a842012-06-28 21:08:14 +080039#define MXT_INFO 0x00
Iiro Valkonen7686b102011-02-02 23:21:58 -080040#define MXT_FAMILY_ID 0x00
41#define MXT_VARIANT_ID 0x01
42#define MXT_VERSION 0x02
43#define MXT_BUILD 0x03
44#define MXT_MATRIX_X_SIZE 0x04
45#define MXT_MATRIX_Y_SIZE 0x05
46#define MXT_OBJECT_NUM 0x06
47#define MXT_OBJECT_START 0x07
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070048
Iiro Valkonen7686b102011-02-02 23:21:58 -080049#define MXT_OBJECT_SIZE 6
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070050
51/* Object types */
Iiro Valkonen81c88a72011-07-04 03:08:25 -070052#define MXT_DEBUG_DIAGNOSTIC_T37 37
53#define MXT_GEN_MESSAGE_T5 5
54#define MXT_GEN_COMMAND_T6 6
55#define MXT_GEN_POWER_T7 7
56#define MXT_GEN_ACQUIRE_T8 8
57#define MXT_GEN_DATASOURCE_T53 53
58#define MXT_TOUCH_MULTI_T9 9
59#define MXT_TOUCH_KEYARRAY_T15 15
60#define MXT_TOUCH_PROXIMITY_T23 23
61#define MXT_TOUCH_PROXKEY_T52 52
62#define MXT_PROCI_GRIPFACE_T20 20
63#define MXT_PROCG_NOISE_T22 22
64#define MXT_PROCI_ONETOUCH_T24 24
65#define MXT_PROCI_TWOTOUCH_T27 27
66#define MXT_PROCI_GRIP_T40 40
67#define MXT_PROCI_PALM_T41 41
68#define MXT_PROCI_TOUCHSUPPRESSION_T42 42
69#define MXT_PROCI_STYLUS_T47 47
70#define MXT_PROCG_NOISESUPPRESSION_T48 48
71#define MXT_SPT_COMMSCONFIG_T18 18
72#define MXT_SPT_GPIOPWM_T19 19
73#define MXT_SPT_SELFTEST_T25 25
74#define MXT_SPT_CTECONFIG_T28 28
75#define MXT_SPT_USERDATA_T38 38
76#define MXT_SPT_DIGITIZER_T43 43
77#define MXT_SPT_MESSAGECOUNT_T44 44
78#define MXT_SPT_CTECONFIG_T46 46
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070079
Iiro Valkonen81c88a72011-07-04 03:08:25 -070080/* MXT_GEN_COMMAND_T6 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080081#define MXT_COMMAND_RESET 0
82#define MXT_COMMAND_BACKUPNV 1
83#define MXT_COMMAND_CALIBRATE 2
84#define MXT_COMMAND_REPORTALL 3
85#define MXT_COMMAND_DIAGNOSTIC 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070086
Iiro Valkonen81c88a72011-07-04 03:08:25 -070087/* MXT_GEN_POWER_T7 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080088#define MXT_POWER_IDLEACQINT 0
89#define MXT_POWER_ACTVACQINT 1
90#define MXT_POWER_ACTV2IDLETO 2
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070091
Iiro Valkonen81c88a72011-07-04 03:08:25 -070092/* MXT_GEN_ACQUIRE_T8 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080093#define MXT_ACQUIRE_CHRGTIME 0
94#define MXT_ACQUIRE_TCHDRIFT 2
95#define MXT_ACQUIRE_DRIFTST 3
96#define MXT_ACQUIRE_TCHAUTOCAL 4
97#define MXT_ACQUIRE_SYNC 5
98#define MXT_ACQUIRE_ATCHCALST 6
99#define MXT_ACQUIRE_ATCHCALSTHR 7
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700100
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700101/* MXT_TOUCH_MULTI_T9 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800102#define MXT_TOUCH_CTRL 0
103#define MXT_TOUCH_XORIGIN 1
104#define MXT_TOUCH_YORIGIN 2
105#define MXT_TOUCH_XSIZE 3
106#define MXT_TOUCH_YSIZE 4
107#define MXT_TOUCH_BLEN 6
108#define MXT_TOUCH_TCHTHR 7
109#define MXT_TOUCH_TCHDI 8
110#define MXT_TOUCH_ORIENT 9
111#define MXT_TOUCH_MOVHYSTI 11
112#define MXT_TOUCH_MOVHYSTN 12
113#define MXT_TOUCH_NUMTOUCH 14
114#define MXT_TOUCH_MRGHYST 15
115#define MXT_TOUCH_MRGTHR 16
116#define MXT_TOUCH_AMPHYST 17
117#define MXT_TOUCH_XRANGE_LSB 18
118#define MXT_TOUCH_XRANGE_MSB 19
119#define MXT_TOUCH_YRANGE_LSB 20
120#define MXT_TOUCH_YRANGE_MSB 21
121#define MXT_TOUCH_XLOCLIP 22
122#define MXT_TOUCH_XHICLIP 23
123#define MXT_TOUCH_YLOCLIP 24
124#define MXT_TOUCH_YHICLIP 25
125#define MXT_TOUCH_XEDGECTRL 26
126#define MXT_TOUCH_XEDGEDIST 27
127#define MXT_TOUCH_YEDGECTRL 28
128#define MXT_TOUCH_YEDGEDIST 29
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700129#define MXT_TOUCH_JUMPLIMIT 30
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700130
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700131/* MXT_PROCI_GRIPFACE_T20 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800132#define MXT_GRIPFACE_CTRL 0
133#define MXT_GRIPFACE_XLOGRIP 1
134#define MXT_GRIPFACE_XHIGRIP 2
135#define MXT_GRIPFACE_YLOGRIP 3
136#define MXT_GRIPFACE_YHIGRIP 4
137#define MXT_GRIPFACE_MAXTCHS 5
138#define MXT_GRIPFACE_SZTHR1 7
139#define MXT_GRIPFACE_SZTHR2 8
140#define MXT_GRIPFACE_SHPTHR1 9
141#define MXT_GRIPFACE_SHPTHR2 10
142#define MXT_GRIPFACE_SUPEXTTO 11
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700143
Iiro Valkonen7686b102011-02-02 23:21:58 -0800144/* MXT_PROCI_NOISE field */
145#define MXT_NOISE_CTRL 0
146#define MXT_NOISE_OUTFLEN 1
147#define MXT_NOISE_GCAFUL_LSB 3
148#define MXT_NOISE_GCAFUL_MSB 4
149#define MXT_NOISE_GCAFLL_LSB 5
150#define MXT_NOISE_GCAFLL_MSB 6
151#define MXT_NOISE_ACTVGCAFVALID 7
152#define MXT_NOISE_NOISETHR 8
153#define MXT_NOISE_FREQHOPSCALE 10
154#define MXT_NOISE_FREQ0 11
155#define MXT_NOISE_FREQ1 12
156#define MXT_NOISE_FREQ2 13
157#define MXT_NOISE_FREQ3 14
158#define MXT_NOISE_FREQ4 15
159#define MXT_NOISE_IDLEGCAFVALID 16
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700160
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700161/* MXT_SPT_COMMSCONFIG_T18 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800162#define MXT_COMMS_CTRL 0
163#define MXT_COMMS_CMD 1
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700164
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700165/* MXT_SPT_CTECONFIG_T28 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800166#define MXT_CTE_CTRL 0
167#define MXT_CTE_CMD 1
168#define MXT_CTE_MODE 2
169#define MXT_CTE_IDLEGCAFDEPTH 3
170#define MXT_CTE_ACTVGCAFDEPTH 4
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700171#define MXT_CTE_VOLTAGE 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700172
Iiro Valkonen7686b102011-02-02 23:21:58 -0800173#define MXT_VOLTAGE_DEFAULT 2700000
174#define MXT_VOLTAGE_STEP 10000
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700175
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700176/* Define for MXT_GEN_COMMAND_T6 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800177#define MXT_BOOT_VALUE 0xa5
178#define MXT_BACKUP_VALUE 0x55
179#define MXT_BACKUP_TIME 25 /* msec */
180#define MXT_RESET_TIME 65 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700181
Iiro Valkonen7686b102011-02-02 23:21:58 -0800182#define MXT_FWRESET_TIME 175 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700183
184/* Command to unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800185#define MXT_UNLOCK_CMD_MSB 0xaa
186#define MXT_UNLOCK_CMD_LSB 0xdc
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700187
188/* Bootloader mode status */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800189#define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
190#define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
191#define MXT_FRAME_CRC_CHECK 0x02
192#define MXT_FRAME_CRC_FAIL 0x03
193#define MXT_FRAME_CRC_PASS 0x04
194#define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
195#define MXT_BOOT_STATUS_MASK 0x3f
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700196
197/* Touch status */
Daniel Kurtzb2e459b2012-06-28 21:08:18 +0800198#define MXT_UNGRIP (1 << 0)
Iiro Valkonen7686b102011-02-02 23:21:58 -0800199#define MXT_SUPPRESS (1 << 1)
200#define MXT_AMP (1 << 2)
201#define MXT_VECTOR (1 << 3)
202#define MXT_MOVE (1 << 4)
203#define MXT_RELEASE (1 << 5)
204#define MXT_PRESS (1 << 6)
205#define MXT_DETECT (1 << 7)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700206
Joonyoung Shim910d8052011-04-12 23:14:38 -0700207/* Touch orient bits */
208#define MXT_XY_SWITCH (1 << 0)
209#define MXT_X_INVERT (1 << 1)
210#define MXT_Y_INVERT (1 << 2)
211
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700212/* Touchscreen absolute values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800213#define MXT_MAX_AREA 0xff
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700214
Iiro Valkonen7686b102011-02-02 23:21:58 -0800215#define MXT_MAX_FINGER 10
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700216
Iiro Valkonen7686b102011-02-02 23:21:58 -0800217struct mxt_info {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700218 u8 family_id;
219 u8 variant_id;
220 u8 version;
221 u8 build;
222 u8 matrix_xsize;
223 u8 matrix_ysize;
224 u8 object_num;
225};
226
Iiro Valkonen7686b102011-02-02 23:21:58 -0800227struct mxt_object {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700228 u8 type;
229 u16 start_address;
230 u8 size;
231 u8 instances;
232 u8 num_report_ids;
233
234 /* to map object and message */
235 u8 max_reportid;
236};
237
Iiro Valkonen7686b102011-02-02 23:21:58 -0800238struct mxt_message {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700239 u8 reportid;
240 u8 message[7];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700241};
242
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700243/* Each client has this additional data */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800244struct mxt_data {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700245 struct i2c_client *client;
246 struct input_dev *input_dev;
Daniel Kurtzec02ac22012-06-28 21:08:02 +0800247 char phys[64]; /* device physical location */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800248 const struct mxt_platform_data *pdata;
249 struct mxt_object *object_table;
250 struct mxt_info info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700251 unsigned int irq;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700252 unsigned int max_x;
253 unsigned int max_y;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700254};
255
Iiro Valkonen7686b102011-02-02 23:21:58 -0800256static bool mxt_object_readable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700257{
258 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700259 case MXT_GEN_COMMAND_T6:
260 case MXT_GEN_POWER_T7:
261 case MXT_GEN_ACQUIRE_T8:
262 case MXT_GEN_DATASOURCE_T53:
263 case MXT_TOUCH_MULTI_T9:
264 case MXT_TOUCH_KEYARRAY_T15:
265 case MXT_TOUCH_PROXIMITY_T23:
266 case MXT_TOUCH_PROXKEY_T52:
267 case MXT_PROCI_GRIPFACE_T20:
268 case MXT_PROCG_NOISE_T22:
269 case MXT_PROCI_ONETOUCH_T24:
270 case MXT_PROCI_TWOTOUCH_T27:
271 case MXT_PROCI_GRIP_T40:
272 case MXT_PROCI_PALM_T41:
273 case MXT_PROCI_TOUCHSUPPRESSION_T42:
274 case MXT_PROCI_STYLUS_T47:
275 case MXT_PROCG_NOISESUPPRESSION_T48:
276 case MXT_SPT_COMMSCONFIG_T18:
277 case MXT_SPT_GPIOPWM_T19:
278 case MXT_SPT_SELFTEST_T25:
279 case MXT_SPT_CTECONFIG_T28:
280 case MXT_SPT_USERDATA_T38:
281 case MXT_SPT_DIGITIZER_T43:
282 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700283 return true;
284 default:
285 return false;
286 }
287}
288
Iiro Valkonen7686b102011-02-02 23:21:58 -0800289static bool mxt_object_writable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700290{
291 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700292 case MXT_GEN_COMMAND_T6:
293 case MXT_GEN_POWER_T7:
294 case MXT_GEN_ACQUIRE_T8:
295 case MXT_TOUCH_MULTI_T9:
296 case MXT_TOUCH_KEYARRAY_T15:
297 case MXT_TOUCH_PROXIMITY_T23:
298 case MXT_TOUCH_PROXKEY_T52:
299 case MXT_PROCI_GRIPFACE_T20:
300 case MXT_PROCG_NOISE_T22:
301 case MXT_PROCI_ONETOUCH_T24:
302 case MXT_PROCI_TWOTOUCH_T27:
303 case MXT_PROCI_GRIP_T40:
304 case MXT_PROCI_PALM_T41:
305 case MXT_PROCI_TOUCHSUPPRESSION_T42:
306 case MXT_PROCI_STYLUS_T47:
307 case MXT_PROCG_NOISESUPPRESSION_T48:
308 case MXT_SPT_COMMSCONFIG_T18:
309 case MXT_SPT_GPIOPWM_T19:
310 case MXT_SPT_SELFTEST_T25:
311 case MXT_SPT_CTECONFIG_T28:
312 case MXT_SPT_DIGITIZER_T43:
313 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700314 return true;
315 default:
316 return false;
317 }
318}
319
Iiro Valkonen7686b102011-02-02 23:21:58 -0800320static void mxt_dump_message(struct device *dev,
Daniel Kurtz6ee3dbf2012-05-08 22:40:29 -0700321 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700322{
Daniel Kurtz6ee3dbf2012-05-08 22:40:29 -0700323 dev_dbg(dev, "reportid: %u\tmessage: %02x %02x %02x %02x %02x %02x %02x\n",
324 message->reportid, message->message[0], message->message[1],
325 message->message[2], message->message[3], message->message[4],
326 message->message[5], message->message[6]);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700327}
328
Iiro Valkonen7686b102011-02-02 23:21:58 -0800329static int mxt_check_bootloader(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700330 unsigned int state)
331{
332 u8 val;
333
334recheck:
335 if (i2c_master_recv(client, &val, 1) != 1) {
336 dev_err(&client->dev, "%s: i2c recv failed\n", __func__);
337 return -EIO;
338 }
339
340 switch (state) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800341 case MXT_WAITING_BOOTLOAD_CMD:
342 case MXT_WAITING_FRAME_DATA:
343 val &= ~MXT_BOOT_STATUS_MASK;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700344 break;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800345 case MXT_FRAME_CRC_PASS:
346 if (val == MXT_FRAME_CRC_CHECK)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700347 goto recheck;
348 break;
349 default:
350 return -EINVAL;
351 }
352
353 if (val != state) {
354 dev_err(&client->dev, "Unvalid bootloader mode state\n");
355 return -EINVAL;
356 }
357
358 return 0;
359}
360
Iiro Valkonen7686b102011-02-02 23:21:58 -0800361static int mxt_unlock_bootloader(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700362{
363 u8 buf[2];
364
Iiro Valkonen7686b102011-02-02 23:21:58 -0800365 buf[0] = MXT_UNLOCK_CMD_LSB;
366 buf[1] = MXT_UNLOCK_CMD_MSB;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700367
368 if (i2c_master_send(client, buf, 2) != 2) {
369 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
370 return -EIO;
371 }
372
373 return 0;
374}
375
Iiro Valkonen7686b102011-02-02 23:21:58 -0800376static int mxt_fw_write(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700377 const u8 *data, unsigned int frame_size)
378{
379 if (i2c_master_send(client, data, frame_size) != frame_size) {
380 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
381 return -EIO;
382 }
383
384 return 0;
385}
386
Iiro Valkonen7686b102011-02-02 23:21:58 -0800387static int __mxt_read_reg(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700388 u16 reg, u16 len, void *val)
389{
390 struct i2c_msg xfer[2];
391 u8 buf[2];
Daniel Kurtz771733e2012-06-28 21:08:11 +0800392 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700393
394 buf[0] = reg & 0xff;
395 buf[1] = (reg >> 8) & 0xff;
396
397 /* Write register */
398 xfer[0].addr = client->addr;
399 xfer[0].flags = 0;
400 xfer[0].len = 2;
401 xfer[0].buf = buf;
402
403 /* Read data */
404 xfer[1].addr = client->addr;
405 xfer[1].flags = I2C_M_RD;
406 xfer[1].len = len;
407 xfer[1].buf = val;
408
Daniel Kurtz771733e2012-06-28 21:08:11 +0800409 ret = i2c_transfer(client->adapter, xfer, 2);
410 if (ret == 2) {
411 ret = 0;
412 } else {
413 if (ret >= 0)
414 ret = -EIO;
415 dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
416 __func__, ret);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700417 }
418
Daniel Kurtz771733e2012-06-28 21:08:11 +0800419 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700420}
421
Iiro Valkonen7686b102011-02-02 23:21:58 -0800422static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700423{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800424 return __mxt_read_reg(client, reg, 1, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700425}
426
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800427static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
428 const void *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700429{
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800430 u8 *buf;
431 size_t count;
Daniel Kurtz771733e2012-06-28 21:08:11 +0800432 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700433
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800434 count = len + 2;
435 buf = kmalloc(count, GFP_KERNEL);
436 if (!buf)
437 return -ENOMEM;
438
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700439 buf[0] = reg & 0xff;
440 buf[1] = (reg >> 8) & 0xff;
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800441 memcpy(&buf[2], val, len);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700442
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800443 ret = i2c_master_send(client, buf, count);
444 if (ret == count) {
Daniel Kurtz771733e2012-06-28 21:08:11 +0800445 ret = 0;
446 } else {
447 if (ret >= 0)
448 ret = -EIO;
449 dev_err(&client->dev, "%s: i2c send failed (%d)\n",
450 __func__, ret);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700451 }
452
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800453 kfree(buf);
Daniel Kurtz771733e2012-06-28 21:08:11 +0800454 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700455}
456
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800457static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
458{
459 return __mxt_write_reg(client, reg, 1, &val);
460}
461
Iiro Valkonen7686b102011-02-02 23:21:58 -0800462static int mxt_read_object_table(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700463 u16 reg, u8 *object_buf)
464{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800465 return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700466 object_buf);
467}
468
Iiro Valkonen7686b102011-02-02 23:21:58 -0800469static struct mxt_object *
470mxt_get_object(struct mxt_data *data, u8 type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700471{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800472 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700473 int i;
474
475 for (i = 0; i < data->info.object_num; i++) {
476 object = data->object_table + i;
477 if (object->type == type)
478 return object;
479 }
480
481 dev_err(&data->client->dev, "Invalid object type\n");
482 return NULL;
483}
484
Iiro Valkonen7686b102011-02-02 23:21:58 -0800485static int mxt_read_message(struct mxt_data *data,
486 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700487{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800488 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700489 u16 reg;
490
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700491 object = mxt_get_object(data, MXT_GEN_MESSAGE_T5);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700492 if (!object)
493 return -EINVAL;
494
495 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800496 return __mxt_read_reg(data->client, reg,
497 sizeof(struct mxt_message), message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700498}
499
Iiro Valkonen7686b102011-02-02 23:21:58 -0800500static int mxt_write_object(struct mxt_data *data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700501 u8 type, u8 offset, u8 val)
502{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800503 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700504 u16 reg;
505
Iiro Valkonen7686b102011-02-02 23:21:58 -0800506 object = mxt_get_object(data, type);
Daniel Kurtzd1ff3202012-05-08 22:38:52 -0700507 if (!object || offset >= object->size + 1)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700508 return -EINVAL;
509
510 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800511 return mxt_write_reg(data->client, reg + offset, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700512}
513
Iiro Valkonen7686b102011-02-02 23:21:58 -0800514static void mxt_input_touchevent(struct mxt_data *data,
515 struct mxt_message *message, int id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700516{
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700517 struct device *dev = &data->client->dev;
518 u8 status = message->message[0];
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800519 struct input_dev *input_dev = data->input_dev;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700520 int x;
521 int y;
522 int area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700523 int pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700524
Joonyoung Shim910d8052011-04-12 23:14:38 -0700525 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
526 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
527 if (data->max_x < 1024)
528 x = x >> 2;
529 if (data->max_y < 1024)
530 y = y >> 2;
531
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700532 area = message->message[4];
Yufeng Shen28ac2932011-08-16 00:40:54 -0700533 pressure = message->message[5];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700534
Daniel Kurtzb2e459b2012-06-28 21:08:18 +0800535 dev_dbg(dev,
536 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
537 id,
538 (status & MXT_DETECT) ? 'D' : '.',
539 (status & MXT_PRESS) ? 'P' : '.',
540 (status & MXT_RELEASE) ? 'R' : '.',
541 (status & MXT_MOVE) ? 'M' : '.',
542 (status & MXT_VECTOR) ? 'V' : '.',
543 (status & MXT_AMP) ? 'A' : '.',
544 (status & MXT_SUPPRESS) ? 'S' : '.',
545 (status & MXT_UNGRIP) ? 'U' : '.',
546 x, y, area, pressure);
547
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800548 input_mt_slot(input_dev, id);
549 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
550 status & MXT_DETECT);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700551
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800552 if (status & MXT_DETECT) {
553 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
554 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
555 input_report_abs(input_dev, ABS_MT_PRESSURE, pressure);
556 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
557 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700558
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800559 input_mt_report_pointer_emulation(input_dev, false);
560 input_sync(input_dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700561}
562
Iiro Valkonen7686b102011-02-02 23:21:58 -0800563static irqreturn_t mxt_interrupt(int irq, void *dev_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700564{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800565 struct mxt_data *data = dev_id;
566 struct mxt_message message;
567 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700568 struct device *dev = &data->client->dev;
569 int id;
570 u8 reportid;
571 u8 max_reportid;
572 u8 min_reportid;
573
574 do {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800575 if (mxt_read_message(data, &message)) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700576 dev_err(dev, "Failed to read message\n");
577 goto end;
578 }
579
580 reportid = message.reportid;
581
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700582 /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */
583 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700584 if (!object)
585 goto end;
586
587 max_reportid = object->max_reportid;
588 min_reportid = max_reportid - object->num_report_ids + 1;
589 id = reportid - min_reportid;
590
591 if (reportid >= min_reportid && reportid <= max_reportid)
Iiro Valkonen7686b102011-02-02 23:21:58 -0800592 mxt_input_touchevent(data, &message, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700593 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800594 mxt_dump_message(dev, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700595 } while (reportid != 0xff);
596
597end:
598 return IRQ_HANDLED;
599}
600
Iiro Valkonen7686b102011-02-02 23:21:58 -0800601static int mxt_check_reg_init(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700602{
Iiro Valkonen71749f52011-02-15 13:36:52 -0800603 const struct mxt_platform_data *pdata = data->pdata;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800604 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700605 struct device *dev = &data->client->dev;
606 int index = 0;
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800607 int i, size;
608 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700609
Iiro Valkonen71749f52011-02-15 13:36:52 -0800610 if (!pdata->config) {
611 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
612 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700613 }
614
615 for (i = 0; i < data->info.object_num; i++) {
616 object = data->object_table + i;
617
Iiro Valkonen7686b102011-02-02 23:21:58 -0800618 if (!mxt_object_writable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700619 continue;
620
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800621 size = (object->size + 1) * (object->instances + 1);
622 if (index + size > pdata->config_length) {
623 dev_err(dev, "Not enough config data!\n");
624 return -EINVAL;
Iiro Valkonen71749f52011-02-15 13:36:52 -0800625 }
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800626
627 ret = __mxt_write_reg(data->client, object->start_address,
628 size, &pdata->config[index]);
629 if (ret)
630 return ret;
631 index += size;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700632 }
633
634 return 0;
635}
636
Iiro Valkonen7686b102011-02-02 23:21:58 -0800637static int mxt_make_highchg(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700638{
639 struct device *dev = &data->client->dev;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800640 struct mxt_message message;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700641 int count = 10;
642 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700643
644 /* Read dummy message to make high CHG pin */
645 do {
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800646 error = mxt_read_message(data, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700647 if (error)
648 return error;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800649 } while (message.reportid != 0xff && --count);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700650
651 if (!count) {
652 dev_err(dev, "CHG pin isn't cleared\n");
653 return -EBUSY;
654 }
655
656 return 0;
657}
658
Iiro Valkonen7686b102011-02-02 23:21:58 -0800659static void mxt_handle_pdata(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700660{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800661 const struct mxt_platform_data *pdata = data->pdata;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700662 u8 voltage;
663
664 /* Set touchscreen lines */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700665 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_XSIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700666 pdata->x_line);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700667 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_YSIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700668 pdata->y_line);
669
670 /* Set touchscreen orient */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700671 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_ORIENT,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700672 pdata->orient);
673
674 /* Set touchscreen burst length */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700675 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800676 MXT_TOUCH_BLEN, pdata->blen);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700677
678 /* Set touchscreen threshold */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700679 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800680 MXT_TOUCH_TCHTHR, pdata->threshold);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700681
682 /* Set touchscreen resolution */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700683 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800684 MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700685 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800686 MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700687 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800688 MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700689 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800690 MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700691
692 /* Set touchscreen voltage */
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700693 if (pdata->voltage) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800694 if (pdata->voltage < MXT_VOLTAGE_DEFAULT) {
695 voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) /
696 MXT_VOLTAGE_STEP;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700697 voltage = 0xff - voltage + 1;
698 } else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800699 voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) /
700 MXT_VOLTAGE_STEP;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700701
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700702 mxt_write_object(data, MXT_SPT_CTECONFIG_T28,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800703 MXT_CTE_VOLTAGE, voltage);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700704 }
705}
706
Iiro Valkonen7686b102011-02-02 23:21:58 -0800707static int mxt_get_info(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700708{
709 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800710 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700711 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700712
Daniel Kurtz23003a842012-06-28 21:08:14 +0800713 /* Read 7-byte info block starting at address 0 */
714 error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700715 if (error)
716 return error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700717
718 return 0;
719}
720
Iiro Valkonen7686b102011-02-02 23:21:58 -0800721static int mxt_get_object_table(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700722{
723 int error;
724 int i;
725 u16 reg;
726 u8 reportid = 0;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800727 u8 buf[MXT_OBJECT_SIZE];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700728
729 for (i = 0; i < data->info.object_num; i++) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800730 struct mxt_object *object = data->object_table + i;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700731
Iiro Valkonen7686b102011-02-02 23:21:58 -0800732 reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i;
733 error = mxt_read_object_table(data->client, reg, buf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700734 if (error)
735 return error;
736
737 object->type = buf[0];
738 object->start_address = (buf[2] << 8) | buf[1];
739 object->size = buf[3];
740 object->instances = buf[4];
741 object->num_report_ids = buf[5];
742
743 if (object->num_report_ids) {
744 reportid += object->num_report_ids *
745 (object->instances + 1);
746 object->max_reportid = reportid;
747 }
748 }
749
750 return 0;
751}
752
Iiro Valkonen7686b102011-02-02 23:21:58 -0800753static int mxt_initialize(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700754{
755 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800756 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700757 int error;
758 u8 val;
759
Iiro Valkonen7686b102011-02-02 23:21:58 -0800760 error = mxt_get_info(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700761 if (error)
762 return error;
763
764 data->object_table = kcalloc(info->object_num,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800765 sizeof(struct mxt_object),
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700766 GFP_KERNEL);
767 if (!data->object_table) {
768 dev_err(&client->dev, "Failed to allocate memory\n");
769 return -ENOMEM;
770 }
771
772 /* Get object table information */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800773 error = mxt_get_object_table(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700774 if (error)
775 return error;
776
777 /* Check register init values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800778 error = mxt_check_reg_init(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700779 if (error)
780 return error;
781
Iiro Valkonen7686b102011-02-02 23:21:58 -0800782 mxt_handle_pdata(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700783
784 /* Backup to memory */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700785 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800786 MXT_COMMAND_BACKUPNV,
787 MXT_BACKUP_VALUE);
788 msleep(MXT_BACKUP_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700789
790 /* Soft reset */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700791 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800792 MXT_COMMAND_RESET, 1);
793 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700794
795 /* Update matrix size at info struct */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800796 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700797 if (error)
798 return error;
799 info->matrix_xsize = val;
800
Iiro Valkonen7686b102011-02-02 23:21:58 -0800801 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700802 if (error)
803 return error;
804 info->matrix_ysize = val;
805
806 dev_info(&client->dev,
Daniel Kurtze0e02692012-06-28 21:08:15 +0800807 "Family ID: %u Variant ID: %u Major.Minor.Build: %u.%u.%02X\n",
808 info->family_id, info->variant_id, info->version >> 4,
809 info->version & 0xf, info->build);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700810
811 dev_info(&client->dev,
Daniel Kurtze0e02692012-06-28 21:08:15 +0800812 "Matrix X Size: %u Matrix Y Size: %u Object Num: %u\n",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700813 info->matrix_xsize, info->matrix_ysize,
814 info->object_num);
815
816 return 0;
817}
818
Joonyoung Shim910d8052011-04-12 23:14:38 -0700819static void mxt_calc_resolution(struct mxt_data *data)
820{
821 unsigned int max_x = data->pdata->x_size - 1;
822 unsigned int max_y = data->pdata->y_size - 1;
823
824 if (data->pdata->orient & MXT_XY_SWITCH) {
825 data->max_x = max_y;
826 data->max_y = max_x;
827 } else {
828 data->max_x = max_x;
829 data->max_y = max_y;
830 }
831}
832
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +0800833/* Firmware Version is returned as Major.Minor.Build */
834static ssize_t mxt_fw_version_show(struct device *dev,
835 struct device_attribute *attr, char *buf)
836{
837 struct mxt_data *data = dev_get_drvdata(dev);
838 struct mxt_info *info = &data->info;
839 return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n",
840 info->version >> 4, info->version & 0xf, info->build);
841}
842
843/* Hardware Version is returned as FamilyID.VariantID */
844static ssize_t mxt_hw_version_show(struct device *dev,
845 struct device_attribute *attr, char *buf)
846{
847 struct mxt_data *data = dev_get_drvdata(dev);
848 struct mxt_info *info = &data->info;
849 return scnprintf(buf, PAGE_SIZE, "%u.%u\n",
850 info->family_id, info->variant_id);
851}
852
Daniel Kurtz794eb672012-06-28 21:08:10 +0800853static ssize_t mxt_show_instance(char *buf, int count,
854 struct mxt_object *object, int instance,
855 const u8 *val)
856{
857 int i;
858
859 if (object->instances > 0)
860 count += scnprintf(buf + count, PAGE_SIZE - count,
861 "Instance %u\n", instance);
862
863 for (i = 0; i < object->size + 1; i++)
864 count += scnprintf(buf + count, PAGE_SIZE - count,
865 "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
866 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
867
868 return count;
869}
870
Iiro Valkonen7686b102011-02-02 23:21:58 -0800871static ssize_t mxt_object_show(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700872 struct device_attribute *attr, char *buf)
873{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800874 struct mxt_data *data = dev_get_drvdata(dev);
875 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700876 int count = 0;
877 int i, j;
878 int error;
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800879 u8 *obuf;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700880
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800881 /* Pre-allocate buffer large enough to hold max sized object. */
882 obuf = kmalloc(256, GFP_KERNEL);
883 if (!obuf)
884 return -ENOMEM;
885
886 error = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700887 for (i = 0; i < data->info.object_num; i++) {
888 object = data->object_table + i;
889
Daniel Kurtz91630952012-06-28 21:08:09 +0800890 if (!mxt_object_readable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700891 continue;
Daniel Kurtz91630952012-06-28 21:08:09 +0800892
893 count += scnprintf(buf + count, PAGE_SIZE - count,
894 "T%u:\n", object->type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700895
Daniel Kurtz794eb672012-06-28 21:08:10 +0800896 for (j = 0; j < object->instances + 1; j++) {
897 u16 size = object->size + 1;
898 u16 addr = object->start_address + j * size;
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800899
Daniel Kurtz794eb672012-06-28 21:08:10 +0800900 error = __mxt_read_reg(data->client, addr, size, obuf);
901 if (error)
902 goto done;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700903
Daniel Kurtz794eb672012-06-28 21:08:10 +0800904 count = mxt_show_instance(buf, count, object, j, obuf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700905 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700906 }
907
Daniel Kurtz794eb672012-06-28 21:08:10 +0800908done:
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800909 kfree(obuf);
910 return error ?: count;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700911}
912
Iiro Valkonen7686b102011-02-02 23:21:58 -0800913static int mxt_load_fw(struct device *dev, const char *fn)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700914{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800915 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700916 struct i2c_client *client = data->client;
917 const struct firmware *fw = NULL;
918 unsigned int frame_size;
919 unsigned int pos = 0;
920 int ret;
921
922 ret = request_firmware(&fw, fn, dev);
923 if (ret) {
924 dev_err(dev, "Unable to open firmware %s\n", fn);
925 return ret;
926 }
927
928 /* Change to the bootloader mode */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700929 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800930 MXT_COMMAND_RESET, MXT_BOOT_VALUE);
931 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700932
933 /* Change to slave address of bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800934 if (client->addr == MXT_APP_LOW)
935 client->addr = MXT_BOOT_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700936 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800937 client->addr = MXT_BOOT_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700938
Iiro Valkonen7686b102011-02-02 23:21:58 -0800939 ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700940 if (ret)
941 goto out;
942
943 /* Unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800944 mxt_unlock_bootloader(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700945
946 while (pos < fw->size) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800947 ret = mxt_check_bootloader(client,
948 MXT_WAITING_FRAME_DATA);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700949 if (ret)
950 goto out;
951
952 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
953
954 /* We should add 2 at frame size as the the firmware data is not
955 * included the CRC bytes.
956 */
957 frame_size += 2;
958
959 /* Write one frame to device */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800960 mxt_fw_write(client, fw->data + pos, frame_size);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700961
Iiro Valkonen7686b102011-02-02 23:21:58 -0800962 ret = mxt_check_bootloader(client,
963 MXT_FRAME_CRC_PASS);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700964 if (ret)
965 goto out;
966
967 pos += frame_size;
968
969 dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size);
970 }
971
972out:
973 release_firmware(fw);
974
975 /* Change to slave address of application */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800976 if (client->addr == MXT_BOOT_LOW)
977 client->addr = MXT_APP_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700978 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800979 client->addr = MXT_APP_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700980
981 return ret;
982}
983
Iiro Valkonen7686b102011-02-02 23:21:58 -0800984static ssize_t mxt_update_fw_store(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700985 struct device_attribute *attr,
986 const char *buf, size_t count)
987{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800988 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700989 int error;
990
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700991 disable_irq(data->irq);
992
Iiro Valkonen7686b102011-02-02 23:21:58 -0800993 error = mxt_load_fw(dev, MXT_FW_NAME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700994 if (error) {
995 dev_err(dev, "The firmware update failed(%d)\n", error);
996 count = error;
997 } else {
998 dev_dbg(dev, "The firmware update succeeded\n");
999
1000 /* Wait for reset */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001001 msleep(MXT_FWRESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001002
1003 kfree(data->object_table);
1004 data->object_table = NULL;
1005
Iiro Valkonen7686b102011-02-02 23:21:58 -08001006 mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001007 }
1008
1009 enable_irq(data->irq);
1010
Iiro Valkonen08960a02011-04-12 23:16:40 -07001011 error = mxt_make_highchg(data);
1012 if (error)
1013 return error;
1014
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001015 return count;
1016}
1017
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08001018static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
1019static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
Daniel Kurtz71b3e932012-05-08 22:30:14 -07001020static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
1021static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001022
Iiro Valkonen7686b102011-02-02 23:21:58 -08001023static struct attribute *mxt_attrs[] = {
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08001024 &dev_attr_fw_version.attr,
1025 &dev_attr_hw_version.attr,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001026 &dev_attr_object.attr,
1027 &dev_attr_update_fw.attr,
1028 NULL
1029};
1030
Iiro Valkonen7686b102011-02-02 23:21:58 -08001031static const struct attribute_group mxt_attr_group = {
1032 .attrs = mxt_attrs,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001033};
1034
Iiro Valkonen7686b102011-02-02 23:21:58 -08001035static void mxt_start(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001036{
1037 /* Touch enable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001038 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001039 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001040}
1041
Iiro Valkonen7686b102011-02-02 23:21:58 -08001042static void mxt_stop(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001043{
1044 /* Touch disable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001045 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001046 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001047}
1048
Iiro Valkonen7686b102011-02-02 23:21:58 -08001049static int mxt_input_open(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001050{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001051 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001052
Iiro Valkonen7686b102011-02-02 23:21:58 -08001053 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001054
1055 return 0;
1056}
1057
Iiro Valkonen7686b102011-02-02 23:21:58 -08001058static void mxt_input_close(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001059{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001060 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001061
Iiro Valkonen7686b102011-02-02 23:21:58 -08001062 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001063}
1064
Iiro Valkonen7686b102011-02-02 23:21:58 -08001065static int __devinit mxt_probe(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001066 const struct i2c_device_id *id)
1067{
Iiro Valkonen919ed892011-02-15 13:36:52 -08001068 const struct mxt_platform_data *pdata = client->dev.platform_data;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001069 struct mxt_data *data;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001070 struct input_dev *input_dev;
1071 int error;
1072
Iiro Valkonen919ed892011-02-15 13:36:52 -08001073 if (!pdata)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001074 return -EINVAL;
1075
Iiro Valkonen7686b102011-02-02 23:21:58 -08001076 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001077 input_dev = input_allocate_device();
1078 if (!data || !input_dev) {
1079 dev_err(&client->dev, "Failed to allocate memory\n");
1080 error = -ENOMEM;
1081 goto err_free_mem;
1082 }
1083
Iiro Valkonen7686b102011-02-02 23:21:58 -08001084 input_dev->name = "Atmel maXTouch Touchscreen";
Daniel Kurtzec02ac22012-06-28 21:08:02 +08001085 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1086 client->adapter->nr, client->addr);
1087 input_dev->phys = data->phys;
1088
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001089 input_dev->id.bustype = BUS_I2C;
1090 input_dev->dev.parent = &client->dev;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001091 input_dev->open = mxt_input_open;
1092 input_dev->close = mxt_input_close;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001093
Joonyoung Shim910d8052011-04-12 23:14:38 -07001094 data->client = client;
1095 data->input_dev = input_dev;
1096 data->pdata = pdata;
1097 data->irq = client->irq;
1098
1099 mxt_calc_resolution(data);
1100
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001101 __set_bit(EV_ABS, input_dev->evbit);
1102 __set_bit(EV_KEY, input_dev->evbit);
1103 __set_bit(BTN_TOUCH, input_dev->keybit);
1104
1105 /* For single touch */
1106 input_set_abs_params(input_dev, ABS_X,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001107 0, data->max_x, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001108 input_set_abs_params(input_dev, ABS_Y,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001109 0, data->max_y, 0, 0);
Yufeng Shen28ac2932011-08-16 00:40:54 -07001110 input_set_abs_params(input_dev, ABS_PRESSURE,
1111 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001112
1113 /* For multi touch */
Daniel Kurtze1e16582012-06-28 21:08:04 +08001114 error = input_mt_init_slots(input_dev, MXT_MAX_FINGER);
1115 if (error)
1116 goto err_free_mem;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001117 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001118 0, MXT_MAX_AREA, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001119 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001120 0, data->max_x, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001121 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001122 0, data->max_y, 0, 0);
Yufeng Shen28ac2932011-08-16 00:40:54 -07001123 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
1124 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001125
1126 input_set_drvdata(input_dev, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001127 i2c_set_clientdata(client, data);
1128
Iiro Valkonen7686b102011-02-02 23:21:58 -08001129 error = mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001130 if (error)
1131 goto err_free_object;
1132
Iiro Valkonen7686b102011-02-02 23:21:58 -08001133 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
Daniel Kurtzc2ef9a12012-06-28 21:08:03 +08001134 pdata->irqflags, client->name, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001135 if (error) {
1136 dev_err(&client->dev, "Failed to register interrupt\n");
1137 goto err_free_object;
1138 }
1139
Iiro Valkonen08960a02011-04-12 23:16:40 -07001140 error = mxt_make_highchg(data);
1141 if (error)
1142 goto err_free_irq;
1143
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001144 error = input_register_device(input_dev);
1145 if (error)
1146 goto err_free_irq;
1147
Iiro Valkonen7686b102011-02-02 23:21:58 -08001148 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001149 if (error)
Daniel Kurtz63990032012-06-28 21:08:05 +08001150 dev_warn(&client->dev, "error creating sysfs entries.\n");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001151
1152 return 0;
1153
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001154err_free_irq:
1155 free_irq(client->irq, data);
1156err_free_object:
1157 kfree(data->object_table);
1158err_free_mem:
1159 input_free_device(input_dev);
1160 kfree(data);
1161 return error;
1162}
1163
Iiro Valkonen7686b102011-02-02 23:21:58 -08001164static int __devexit mxt_remove(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001165{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001166 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001167
Iiro Valkonen7686b102011-02-02 23:21:58 -08001168 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001169 free_irq(data->irq, data);
1170 input_unregister_device(data->input_dev);
1171 kfree(data->object_table);
1172 kfree(data);
1173
1174 return 0;
1175}
1176
Daniel Kurtz3a73c812012-05-08 22:29:14 -07001177#ifdef CONFIG_PM_SLEEP
Iiro Valkonen7686b102011-02-02 23:21:58 -08001178static int mxt_suspend(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001179{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001180 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08001181 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001182 struct input_dev *input_dev = data->input_dev;
1183
1184 mutex_lock(&input_dev->mutex);
1185
1186 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08001187 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001188
1189 mutex_unlock(&input_dev->mutex);
1190
1191 return 0;
1192}
1193
Iiro Valkonen7686b102011-02-02 23:21:58 -08001194static int mxt_resume(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001195{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001196 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08001197 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001198 struct input_dev *input_dev = data->input_dev;
1199
1200 /* Soft reset */
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001201 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001202 MXT_COMMAND_RESET, 1);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001203
Iiro Valkonen7686b102011-02-02 23:21:58 -08001204 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001205
1206 mutex_lock(&input_dev->mutex);
1207
1208 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08001209 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001210
1211 mutex_unlock(&input_dev->mutex);
1212
1213 return 0;
1214}
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001215#endif
1216
Daniel Kurtz3a73c812012-05-08 22:29:14 -07001217static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
1218
Iiro Valkonen7686b102011-02-02 23:21:58 -08001219static const struct i2c_device_id mxt_id[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001220 { "qt602240_ts", 0 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001221 { "atmel_mxt_ts", 0 },
Chris Leech46ee2a02011-02-15 13:36:52 -08001222 { "mXT224", 0 },
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001223 { }
1224};
Iiro Valkonen7686b102011-02-02 23:21:58 -08001225MODULE_DEVICE_TABLE(i2c, mxt_id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001226
Iiro Valkonen7686b102011-02-02 23:21:58 -08001227static struct i2c_driver mxt_driver = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001228 .driver = {
Iiro Valkonen7686b102011-02-02 23:21:58 -08001229 .name = "atmel_mxt_ts",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001230 .owner = THIS_MODULE,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001231 .pm = &mxt_pm_ops,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001232 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001233 .probe = mxt_probe,
1234 .remove = __devexit_p(mxt_remove),
1235 .id_table = mxt_id,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001236};
1237
Axel Lin1b92c1c2012-03-16 23:05:41 -07001238module_i2c_driver(mxt_driver);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001239
1240/* Module information */
1241MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
Iiro Valkonen7686b102011-02-02 23:21:58 -08001242MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001243MODULE_LICENSE("GPL");