blob: 926209cba77de6e9b66f177d824d9cb4c38b1213 [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 */
Iiro Valkonen7686b102011-02-02 23:21:58 -080039#define MXT_FAMILY_ID 0x00
40#define MXT_VARIANT_ID 0x01
41#define MXT_VERSION 0x02
42#define MXT_BUILD 0x03
43#define MXT_MATRIX_X_SIZE 0x04
44#define MXT_MATRIX_Y_SIZE 0x05
45#define MXT_OBJECT_NUM 0x06
46#define MXT_OBJECT_START 0x07
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070047
Iiro Valkonen7686b102011-02-02 23:21:58 -080048#define MXT_OBJECT_SIZE 6
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070049
50/* Object types */
Iiro Valkonen81c88a72011-07-04 03:08:25 -070051#define MXT_DEBUG_DIAGNOSTIC_T37 37
52#define MXT_GEN_MESSAGE_T5 5
53#define MXT_GEN_COMMAND_T6 6
54#define MXT_GEN_POWER_T7 7
55#define MXT_GEN_ACQUIRE_T8 8
56#define MXT_GEN_DATASOURCE_T53 53
57#define MXT_TOUCH_MULTI_T9 9
58#define MXT_TOUCH_KEYARRAY_T15 15
59#define MXT_TOUCH_PROXIMITY_T23 23
60#define MXT_TOUCH_PROXKEY_T52 52
61#define MXT_PROCI_GRIPFACE_T20 20
62#define MXT_PROCG_NOISE_T22 22
63#define MXT_PROCI_ONETOUCH_T24 24
64#define MXT_PROCI_TWOTOUCH_T27 27
65#define MXT_PROCI_GRIP_T40 40
66#define MXT_PROCI_PALM_T41 41
67#define MXT_PROCI_TOUCHSUPPRESSION_T42 42
68#define MXT_PROCI_STYLUS_T47 47
69#define MXT_PROCG_NOISESUPPRESSION_T48 48
70#define MXT_SPT_COMMSCONFIG_T18 18
71#define MXT_SPT_GPIOPWM_T19 19
72#define MXT_SPT_SELFTEST_T25 25
73#define MXT_SPT_CTECONFIG_T28 28
74#define MXT_SPT_USERDATA_T38 38
75#define MXT_SPT_DIGITIZER_T43 43
76#define MXT_SPT_MESSAGECOUNT_T44 44
77#define MXT_SPT_CTECONFIG_T46 46
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070078
Iiro Valkonen81c88a72011-07-04 03:08:25 -070079/* MXT_GEN_COMMAND_T6 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080080#define MXT_COMMAND_RESET 0
81#define MXT_COMMAND_BACKUPNV 1
82#define MXT_COMMAND_CALIBRATE 2
83#define MXT_COMMAND_REPORTALL 3
84#define MXT_COMMAND_DIAGNOSTIC 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070085
Iiro Valkonen81c88a72011-07-04 03:08:25 -070086/* MXT_GEN_POWER_T7 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080087#define MXT_POWER_IDLEACQINT 0
88#define MXT_POWER_ACTVACQINT 1
89#define MXT_POWER_ACTV2IDLETO 2
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070090
Iiro Valkonen81c88a72011-07-04 03:08:25 -070091/* MXT_GEN_ACQUIRE_T8 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080092#define MXT_ACQUIRE_CHRGTIME 0
93#define MXT_ACQUIRE_TCHDRIFT 2
94#define MXT_ACQUIRE_DRIFTST 3
95#define MXT_ACQUIRE_TCHAUTOCAL 4
96#define MXT_ACQUIRE_SYNC 5
97#define MXT_ACQUIRE_ATCHCALST 6
98#define MXT_ACQUIRE_ATCHCALSTHR 7
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070099
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700100/* MXT_TOUCH_MULTI_T9 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800101#define MXT_TOUCH_CTRL 0
102#define MXT_TOUCH_XORIGIN 1
103#define MXT_TOUCH_YORIGIN 2
104#define MXT_TOUCH_XSIZE 3
105#define MXT_TOUCH_YSIZE 4
106#define MXT_TOUCH_BLEN 6
107#define MXT_TOUCH_TCHTHR 7
108#define MXT_TOUCH_TCHDI 8
109#define MXT_TOUCH_ORIENT 9
110#define MXT_TOUCH_MOVHYSTI 11
111#define MXT_TOUCH_MOVHYSTN 12
112#define MXT_TOUCH_NUMTOUCH 14
113#define MXT_TOUCH_MRGHYST 15
114#define MXT_TOUCH_MRGTHR 16
115#define MXT_TOUCH_AMPHYST 17
116#define MXT_TOUCH_XRANGE_LSB 18
117#define MXT_TOUCH_XRANGE_MSB 19
118#define MXT_TOUCH_YRANGE_LSB 20
119#define MXT_TOUCH_YRANGE_MSB 21
120#define MXT_TOUCH_XLOCLIP 22
121#define MXT_TOUCH_XHICLIP 23
122#define MXT_TOUCH_YLOCLIP 24
123#define MXT_TOUCH_YHICLIP 25
124#define MXT_TOUCH_XEDGECTRL 26
125#define MXT_TOUCH_XEDGEDIST 27
126#define MXT_TOUCH_YEDGECTRL 28
127#define MXT_TOUCH_YEDGEDIST 29
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700128#define MXT_TOUCH_JUMPLIMIT 30
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700129
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700130/* MXT_PROCI_GRIPFACE_T20 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800131#define MXT_GRIPFACE_CTRL 0
132#define MXT_GRIPFACE_XLOGRIP 1
133#define MXT_GRIPFACE_XHIGRIP 2
134#define MXT_GRIPFACE_YLOGRIP 3
135#define MXT_GRIPFACE_YHIGRIP 4
136#define MXT_GRIPFACE_MAXTCHS 5
137#define MXT_GRIPFACE_SZTHR1 7
138#define MXT_GRIPFACE_SZTHR2 8
139#define MXT_GRIPFACE_SHPTHR1 9
140#define MXT_GRIPFACE_SHPTHR2 10
141#define MXT_GRIPFACE_SUPEXTTO 11
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700142
Iiro Valkonen7686b102011-02-02 23:21:58 -0800143/* MXT_PROCI_NOISE field */
144#define MXT_NOISE_CTRL 0
145#define MXT_NOISE_OUTFLEN 1
146#define MXT_NOISE_GCAFUL_LSB 3
147#define MXT_NOISE_GCAFUL_MSB 4
148#define MXT_NOISE_GCAFLL_LSB 5
149#define MXT_NOISE_GCAFLL_MSB 6
150#define MXT_NOISE_ACTVGCAFVALID 7
151#define MXT_NOISE_NOISETHR 8
152#define MXT_NOISE_FREQHOPSCALE 10
153#define MXT_NOISE_FREQ0 11
154#define MXT_NOISE_FREQ1 12
155#define MXT_NOISE_FREQ2 13
156#define MXT_NOISE_FREQ3 14
157#define MXT_NOISE_FREQ4 15
158#define MXT_NOISE_IDLEGCAFVALID 16
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700159
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700160/* MXT_SPT_COMMSCONFIG_T18 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800161#define MXT_COMMS_CTRL 0
162#define MXT_COMMS_CMD 1
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700163
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700164/* MXT_SPT_CTECONFIG_T28 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800165#define MXT_CTE_CTRL 0
166#define MXT_CTE_CMD 1
167#define MXT_CTE_MODE 2
168#define MXT_CTE_IDLEGCAFDEPTH 3
169#define MXT_CTE_ACTVGCAFDEPTH 4
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700170#define MXT_CTE_VOLTAGE 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700171
Iiro Valkonen7686b102011-02-02 23:21:58 -0800172#define MXT_VOLTAGE_DEFAULT 2700000
173#define MXT_VOLTAGE_STEP 10000
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700174
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700175/* Define for MXT_GEN_COMMAND_T6 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800176#define MXT_BOOT_VALUE 0xa5
177#define MXT_BACKUP_VALUE 0x55
178#define MXT_BACKUP_TIME 25 /* msec */
179#define MXT_RESET_TIME 65 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700180
Iiro Valkonen7686b102011-02-02 23:21:58 -0800181#define MXT_FWRESET_TIME 175 /* 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
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700195
196/* Touch status */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800197#define MXT_SUPPRESS (1 << 1)
198#define MXT_AMP (1 << 2)
199#define MXT_VECTOR (1 << 3)
200#define MXT_MOVE (1 << 4)
201#define MXT_RELEASE (1 << 5)
202#define MXT_PRESS (1 << 6)
203#define MXT_DETECT (1 << 7)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700204
Joonyoung Shim910d8052011-04-12 23:14:38 -0700205/* Touch orient bits */
206#define MXT_XY_SWITCH (1 << 0)
207#define MXT_X_INVERT (1 << 1)
208#define MXT_Y_INVERT (1 << 2)
209
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700210/* Touchscreen absolute values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800211#define MXT_MAX_AREA 0xff
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700212
Iiro Valkonen7686b102011-02-02 23:21:58 -0800213#define MXT_MAX_FINGER 10
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700214
Iiro Valkonen7686b102011-02-02 23:21:58 -0800215struct mxt_info {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700216 u8 family_id;
217 u8 variant_id;
218 u8 version;
219 u8 build;
220 u8 matrix_xsize;
221 u8 matrix_ysize;
222 u8 object_num;
223};
224
Iiro Valkonen7686b102011-02-02 23:21:58 -0800225struct mxt_object {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700226 u8 type;
227 u16 start_address;
228 u8 size;
229 u8 instances;
230 u8 num_report_ids;
231
232 /* to map object and message */
233 u8 max_reportid;
234};
235
Iiro Valkonen7686b102011-02-02 23:21:58 -0800236struct mxt_message {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700237 u8 reportid;
238 u8 message[7];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700239};
240
Iiro Valkonen7686b102011-02-02 23:21:58 -0800241struct mxt_finger {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700242 int status;
243 int x;
244 int y;
245 int area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700246 int pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700247};
248
249/* Each client has this additional data */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800250struct mxt_data {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700251 struct i2c_client *client;
252 struct input_dev *input_dev;
Daniel Kurtzec02ac22012-06-28 21:08:02 +0800253 char phys[64]; /* device physical location */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800254 const struct mxt_platform_data *pdata;
255 struct mxt_object *object_table;
256 struct mxt_info info;
257 struct mxt_finger finger[MXT_MAX_FINGER];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700258 unsigned int irq;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700259 unsigned int max_x;
260 unsigned int max_y;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700261};
262
Iiro Valkonen7686b102011-02-02 23:21:58 -0800263static bool mxt_object_readable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700264{
265 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700266 case MXT_GEN_MESSAGE_T5:
267 case MXT_GEN_COMMAND_T6:
268 case MXT_GEN_POWER_T7:
269 case MXT_GEN_ACQUIRE_T8:
270 case MXT_GEN_DATASOURCE_T53:
271 case MXT_TOUCH_MULTI_T9:
272 case MXT_TOUCH_KEYARRAY_T15:
273 case MXT_TOUCH_PROXIMITY_T23:
274 case MXT_TOUCH_PROXKEY_T52:
275 case MXT_PROCI_GRIPFACE_T20:
276 case MXT_PROCG_NOISE_T22:
277 case MXT_PROCI_ONETOUCH_T24:
278 case MXT_PROCI_TWOTOUCH_T27:
279 case MXT_PROCI_GRIP_T40:
280 case MXT_PROCI_PALM_T41:
281 case MXT_PROCI_TOUCHSUPPRESSION_T42:
282 case MXT_PROCI_STYLUS_T47:
283 case MXT_PROCG_NOISESUPPRESSION_T48:
284 case MXT_SPT_COMMSCONFIG_T18:
285 case MXT_SPT_GPIOPWM_T19:
286 case MXT_SPT_SELFTEST_T25:
287 case MXT_SPT_CTECONFIG_T28:
288 case MXT_SPT_USERDATA_T38:
289 case MXT_SPT_DIGITIZER_T43:
290 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700291 return true;
292 default:
293 return false;
294 }
295}
296
Iiro Valkonen7686b102011-02-02 23:21:58 -0800297static bool mxt_object_writable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700298{
299 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700300 case MXT_GEN_COMMAND_T6:
301 case MXT_GEN_POWER_T7:
302 case MXT_GEN_ACQUIRE_T8:
303 case MXT_TOUCH_MULTI_T9:
304 case MXT_TOUCH_KEYARRAY_T15:
305 case MXT_TOUCH_PROXIMITY_T23:
306 case MXT_TOUCH_PROXKEY_T52:
307 case MXT_PROCI_GRIPFACE_T20:
308 case MXT_PROCG_NOISE_T22:
309 case MXT_PROCI_ONETOUCH_T24:
310 case MXT_PROCI_TWOTOUCH_T27:
311 case MXT_PROCI_GRIP_T40:
312 case MXT_PROCI_PALM_T41:
313 case MXT_PROCI_TOUCHSUPPRESSION_T42:
314 case MXT_PROCI_STYLUS_T47:
315 case MXT_PROCG_NOISESUPPRESSION_T48:
316 case MXT_SPT_COMMSCONFIG_T18:
317 case MXT_SPT_GPIOPWM_T19:
318 case MXT_SPT_SELFTEST_T25:
319 case MXT_SPT_CTECONFIG_T28:
320 case MXT_SPT_DIGITIZER_T43:
321 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700322 return true;
323 default:
324 return false;
325 }
326}
327
Iiro Valkonen7686b102011-02-02 23:21:58 -0800328static void mxt_dump_message(struct device *dev,
Daniel Kurtz6ee3dbf2012-05-08 22:40:29 -0700329 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700330{
Daniel Kurtz6ee3dbf2012-05-08 22:40:29 -0700331 dev_dbg(dev, "reportid: %u\tmessage: %02x %02x %02x %02x %02x %02x %02x\n",
332 message->reportid, message->message[0], message->message[1],
333 message->message[2], message->message[3], message->message[4],
334 message->message[5], message->message[6]);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700335}
336
Iiro Valkonen7686b102011-02-02 23:21:58 -0800337static int mxt_check_bootloader(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700338 unsigned int state)
339{
340 u8 val;
341
342recheck:
343 if (i2c_master_recv(client, &val, 1) != 1) {
344 dev_err(&client->dev, "%s: i2c recv failed\n", __func__);
345 return -EIO;
346 }
347
348 switch (state) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800349 case MXT_WAITING_BOOTLOAD_CMD:
350 case MXT_WAITING_FRAME_DATA:
351 val &= ~MXT_BOOT_STATUS_MASK;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700352 break;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800353 case MXT_FRAME_CRC_PASS:
354 if (val == MXT_FRAME_CRC_CHECK)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700355 goto recheck;
356 break;
357 default:
358 return -EINVAL;
359 }
360
361 if (val != state) {
362 dev_err(&client->dev, "Unvalid bootloader mode state\n");
363 return -EINVAL;
364 }
365
366 return 0;
367}
368
Iiro Valkonen7686b102011-02-02 23:21:58 -0800369static int mxt_unlock_bootloader(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700370{
371 u8 buf[2];
372
Iiro Valkonen7686b102011-02-02 23:21:58 -0800373 buf[0] = MXT_UNLOCK_CMD_LSB;
374 buf[1] = MXT_UNLOCK_CMD_MSB;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700375
376 if (i2c_master_send(client, buf, 2) != 2) {
377 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
378 return -EIO;
379 }
380
381 return 0;
382}
383
Iiro Valkonen7686b102011-02-02 23:21:58 -0800384static int mxt_fw_write(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700385 const u8 *data, unsigned int frame_size)
386{
387 if (i2c_master_send(client, data, frame_size) != frame_size) {
388 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
389 return -EIO;
390 }
391
392 return 0;
393}
394
Iiro Valkonen7686b102011-02-02 23:21:58 -0800395static int __mxt_read_reg(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700396 u16 reg, u16 len, void *val)
397{
398 struct i2c_msg xfer[2];
399 u8 buf[2];
400
401 buf[0] = reg & 0xff;
402 buf[1] = (reg >> 8) & 0xff;
403
404 /* Write register */
405 xfer[0].addr = client->addr;
406 xfer[0].flags = 0;
407 xfer[0].len = 2;
408 xfer[0].buf = buf;
409
410 /* Read data */
411 xfer[1].addr = client->addr;
412 xfer[1].flags = I2C_M_RD;
413 xfer[1].len = len;
414 xfer[1].buf = val;
415
416 if (i2c_transfer(client->adapter, xfer, 2) != 2) {
417 dev_err(&client->dev, "%s: i2c transfer failed\n", __func__);
418 return -EIO;
419 }
420
421 return 0;
422}
423
Iiro Valkonen7686b102011-02-02 23:21:58 -0800424static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700425{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800426 return __mxt_read_reg(client, reg, 1, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700427}
428
Iiro Valkonen7686b102011-02-02 23:21:58 -0800429static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700430{
431 u8 buf[3];
432
433 buf[0] = reg & 0xff;
434 buf[1] = (reg >> 8) & 0xff;
435 buf[2] = val;
436
437 if (i2c_master_send(client, buf, 3) != 3) {
438 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
439 return -EIO;
440 }
441
442 return 0;
443}
444
Iiro Valkonen7686b102011-02-02 23:21:58 -0800445static int mxt_read_object_table(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700446 u16 reg, u8 *object_buf)
447{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800448 return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700449 object_buf);
450}
451
Iiro Valkonen7686b102011-02-02 23:21:58 -0800452static struct mxt_object *
453mxt_get_object(struct mxt_data *data, u8 type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700454{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800455 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700456 int i;
457
458 for (i = 0; i < data->info.object_num; i++) {
459 object = data->object_table + i;
460 if (object->type == type)
461 return object;
462 }
463
464 dev_err(&data->client->dev, "Invalid object type\n");
465 return NULL;
466}
467
Iiro Valkonen7686b102011-02-02 23:21:58 -0800468static int mxt_read_message(struct mxt_data *data,
469 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700470{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800471 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700472 u16 reg;
473
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700474 object = mxt_get_object(data, MXT_GEN_MESSAGE_T5);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700475 if (!object)
476 return -EINVAL;
477
478 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800479 return __mxt_read_reg(data->client, reg,
480 sizeof(struct mxt_message), message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700481}
482
Iiro Valkonen7686b102011-02-02 23:21:58 -0800483static int mxt_read_object(struct mxt_data *data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700484 u8 type, u8 offset, u8 *val)
485{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800486 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700487 u16 reg;
488
Iiro Valkonen7686b102011-02-02 23:21:58 -0800489 object = mxt_get_object(data, type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700490 if (!object)
491 return -EINVAL;
492
493 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800494 return __mxt_read_reg(data->client, reg + offset, 1, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700495}
496
Iiro Valkonen7686b102011-02-02 23:21:58 -0800497static int mxt_write_object(struct mxt_data *data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700498 u8 type, u8 offset, u8 val)
499{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800500 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700501 u16 reg;
502
Iiro Valkonen7686b102011-02-02 23:21:58 -0800503 object = mxt_get_object(data, type);
Daniel Kurtzd1ff3202012-05-08 22:38:52 -0700504 if (!object || offset >= object->size + 1)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700505 return -EINVAL;
506
507 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800508 return mxt_write_reg(data->client, reg + offset, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700509}
510
Iiro Valkonen7686b102011-02-02 23:21:58 -0800511static void mxt_input_report(struct mxt_data *data, int single_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700512{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800513 struct mxt_finger *finger = data->finger;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700514 struct input_dev *input_dev = data->input_dev;
515 int status = finger[single_id].status;
516 int finger_num = 0;
517 int id;
518
Iiro Valkonen7686b102011-02-02 23:21:58 -0800519 for (id = 0; id < MXT_MAX_FINGER; id++) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700520 if (!finger[id].status)
521 continue;
522
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700523 input_mt_slot(input_dev, id);
524 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
525 finger[id].status != MXT_RELEASE);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700526
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700527 if (finger[id].status != MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700528 finger_num++;
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700529 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
530 finger[id].area);
531 input_report_abs(input_dev, ABS_MT_POSITION_X,
532 finger[id].x);
533 input_report_abs(input_dev, ABS_MT_POSITION_Y,
534 finger[id].y);
Yufeng Shen28ac2932011-08-16 00:40:54 -0700535 input_report_abs(input_dev, ABS_MT_PRESSURE,
536 finger[id].pressure);
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700537 } else {
538 finger[id].status = 0;
539 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700540 }
541
542 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
543
Iiro Valkonen7686b102011-02-02 23:21:58 -0800544 if (status != MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700545 input_report_abs(input_dev, ABS_X, finger[single_id].x);
546 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
Yufeng Shen28ac2932011-08-16 00:40:54 -0700547 input_report_abs(input_dev,
548 ABS_PRESSURE, finger[single_id].pressure);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700549 }
550
551 input_sync(input_dev);
552}
553
Iiro Valkonen7686b102011-02-02 23:21:58 -0800554static void mxt_input_touchevent(struct mxt_data *data,
555 struct mxt_message *message, int id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700556{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800557 struct mxt_finger *finger = data->finger;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700558 struct device *dev = &data->client->dev;
559 u8 status = message->message[0];
560 int x;
561 int y;
562 int area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700563 int pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700564
565 /* Check the touch is present on the screen */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800566 if (!(status & MXT_DETECT)) {
567 if (status & MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700568 dev_dbg(dev, "[%d] released\n", id);
569
Iiro Valkonen7686b102011-02-02 23:21:58 -0800570 finger[id].status = MXT_RELEASE;
571 mxt_input_report(data, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700572 }
573 return;
574 }
575
576 /* Check only AMP detection */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800577 if (!(status & (MXT_PRESS | MXT_MOVE)))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700578 return;
579
Joonyoung Shim910d8052011-04-12 23:14:38 -0700580 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
581 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
582 if (data->max_x < 1024)
583 x = x >> 2;
584 if (data->max_y < 1024)
585 y = y >> 2;
586
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700587 area = message->message[4];
Yufeng Shen28ac2932011-08-16 00:40:54 -0700588 pressure = message->message[5];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700589
590 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800591 status & MXT_MOVE ? "moved" : "pressed",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700592 x, y, area);
593
Iiro Valkonen7686b102011-02-02 23:21:58 -0800594 finger[id].status = status & MXT_MOVE ?
595 MXT_MOVE : MXT_PRESS;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700596 finger[id].x = x;
597 finger[id].y = y;
598 finger[id].area = area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700599 finger[id].pressure = pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700600
Iiro Valkonen7686b102011-02-02 23:21:58 -0800601 mxt_input_report(data, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700602}
603
Iiro Valkonen7686b102011-02-02 23:21:58 -0800604static irqreturn_t mxt_interrupt(int irq, void *dev_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700605{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800606 struct mxt_data *data = dev_id;
607 struct mxt_message message;
608 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700609 struct device *dev = &data->client->dev;
610 int id;
611 u8 reportid;
612 u8 max_reportid;
613 u8 min_reportid;
614
615 do {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800616 if (mxt_read_message(data, &message)) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700617 dev_err(dev, "Failed to read message\n");
618 goto end;
619 }
620
621 reportid = message.reportid;
622
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700623 /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */
624 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700625 if (!object)
626 goto end;
627
628 max_reportid = object->max_reportid;
629 min_reportid = max_reportid - object->num_report_ids + 1;
630 id = reportid - min_reportid;
631
632 if (reportid >= min_reportid && reportid <= max_reportid)
Iiro Valkonen7686b102011-02-02 23:21:58 -0800633 mxt_input_touchevent(data, &message, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700634 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800635 mxt_dump_message(dev, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700636 } while (reportid != 0xff);
637
638end:
639 return IRQ_HANDLED;
640}
641
Iiro Valkonen7686b102011-02-02 23:21:58 -0800642static int mxt_check_reg_init(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700643{
Iiro Valkonen71749f52011-02-15 13:36:52 -0800644 const struct mxt_platform_data *pdata = data->pdata;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800645 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700646 struct device *dev = &data->client->dev;
647 int index = 0;
Iiro Valkonen71749f52011-02-15 13:36:52 -0800648 int i, j, config_offset;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700649
Iiro Valkonen71749f52011-02-15 13:36:52 -0800650 if (!pdata->config) {
651 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
652 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700653 }
654
655 for (i = 0; i < data->info.object_num; i++) {
656 object = data->object_table + i;
657
Iiro Valkonen7686b102011-02-02 23:21:58 -0800658 if (!mxt_object_writable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700659 continue;
660
Iiro Valkonena93d4f22011-07-04 03:16:25 -0700661 for (j = 0;
662 j < (object->size + 1) * (object->instances + 1);
663 j++) {
Iiro Valkonen71749f52011-02-15 13:36:52 -0800664 config_offset = index + j;
665 if (config_offset > pdata->config_length) {
666 dev_err(dev, "Not enough config data!\n");
667 return -EINVAL;
668 }
Iiro Valkonen7686b102011-02-02 23:21:58 -0800669 mxt_write_object(data, object->type, j,
Iiro Valkonen71749f52011-02-15 13:36:52 -0800670 pdata->config[config_offset]);
671 }
Iiro Valkonena93d4f22011-07-04 03:16:25 -0700672 index += (object->size + 1) * (object->instances + 1);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700673 }
674
675 return 0;
676}
677
Iiro Valkonen7686b102011-02-02 23:21:58 -0800678static int mxt_make_highchg(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700679{
680 struct device *dev = &data->client->dev;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800681 struct mxt_message message;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700682 int count = 10;
683 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700684
685 /* Read dummy message to make high CHG pin */
686 do {
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800687 error = mxt_read_message(data, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700688 if (error)
689 return error;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800690 } while (message.reportid != 0xff && --count);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700691
692 if (!count) {
693 dev_err(dev, "CHG pin isn't cleared\n");
694 return -EBUSY;
695 }
696
697 return 0;
698}
699
Iiro Valkonen7686b102011-02-02 23:21:58 -0800700static void mxt_handle_pdata(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700701{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800702 const struct mxt_platform_data *pdata = data->pdata;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700703 u8 voltage;
704
705 /* Set touchscreen lines */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700706 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_XSIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700707 pdata->x_line);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700708 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_YSIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700709 pdata->y_line);
710
711 /* Set touchscreen orient */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700712 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_ORIENT,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700713 pdata->orient);
714
715 /* Set touchscreen burst length */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700716 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800717 MXT_TOUCH_BLEN, pdata->blen);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700718
719 /* Set touchscreen threshold */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700720 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800721 MXT_TOUCH_TCHTHR, pdata->threshold);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700722
723 /* Set touchscreen resolution */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700724 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800725 MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700726 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800727 MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700728 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800729 MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700730 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800731 MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700732
733 /* Set touchscreen voltage */
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700734 if (pdata->voltage) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800735 if (pdata->voltage < MXT_VOLTAGE_DEFAULT) {
736 voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) /
737 MXT_VOLTAGE_STEP;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700738 voltage = 0xff - voltage + 1;
739 } else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800740 voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) /
741 MXT_VOLTAGE_STEP;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700742
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700743 mxt_write_object(data, MXT_SPT_CTECONFIG_T28,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800744 MXT_CTE_VOLTAGE, voltage);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700745 }
746}
747
Iiro Valkonen7686b102011-02-02 23:21:58 -0800748static int mxt_get_info(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700749{
750 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800751 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700752 int error;
753 u8 val;
754
Iiro Valkonen7686b102011-02-02 23:21:58 -0800755 error = mxt_read_reg(client, MXT_FAMILY_ID, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700756 if (error)
757 return error;
758 info->family_id = val;
759
Iiro Valkonen7686b102011-02-02 23:21:58 -0800760 error = mxt_read_reg(client, MXT_VARIANT_ID, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700761 if (error)
762 return error;
763 info->variant_id = val;
764
Iiro Valkonen7686b102011-02-02 23:21:58 -0800765 error = mxt_read_reg(client, MXT_VERSION, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700766 if (error)
767 return error;
768 info->version = val;
769
Iiro Valkonen7686b102011-02-02 23:21:58 -0800770 error = mxt_read_reg(client, MXT_BUILD, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700771 if (error)
772 return error;
773 info->build = val;
774
Iiro Valkonen7686b102011-02-02 23:21:58 -0800775 error = mxt_read_reg(client, MXT_OBJECT_NUM, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700776 if (error)
777 return error;
778 info->object_num = val;
779
780 return 0;
781}
782
Iiro Valkonen7686b102011-02-02 23:21:58 -0800783static int mxt_get_object_table(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700784{
785 int error;
786 int i;
787 u16 reg;
788 u8 reportid = 0;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800789 u8 buf[MXT_OBJECT_SIZE];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700790
791 for (i = 0; i < data->info.object_num; i++) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800792 struct mxt_object *object = data->object_table + i;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700793
Iiro Valkonen7686b102011-02-02 23:21:58 -0800794 reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i;
795 error = mxt_read_object_table(data->client, reg, buf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700796 if (error)
797 return error;
798
799 object->type = buf[0];
800 object->start_address = (buf[2] << 8) | buf[1];
801 object->size = buf[3];
802 object->instances = buf[4];
803 object->num_report_ids = buf[5];
804
805 if (object->num_report_ids) {
806 reportid += object->num_report_ids *
807 (object->instances + 1);
808 object->max_reportid = reportid;
809 }
810 }
811
812 return 0;
813}
814
Iiro Valkonen7686b102011-02-02 23:21:58 -0800815static int mxt_initialize(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700816{
817 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800818 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700819 int error;
820 u8 val;
821
Iiro Valkonen7686b102011-02-02 23:21:58 -0800822 error = mxt_get_info(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700823 if (error)
824 return error;
825
826 data->object_table = kcalloc(info->object_num,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800827 sizeof(struct mxt_object),
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700828 GFP_KERNEL);
829 if (!data->object_table) {
830 dev_err(&client->dev, "Failed to allocate memory\n");
831 return -ENOMEM;
832 }
833
834 /* Get object table information */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800835 error = mxt_get_object_table(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700836 if (error)
837 return error;
838
839 /* Check register init values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800840 error = mxt_check_reg_init(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700841 if (error)
842 return error;
843
Iiro Valkonen7686b102011-02-02 23:21:58 -0800844 mxt_handle_pdata(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700845
846 /* Backup to memory */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700847 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800848 MXT_COMMAND_BACKUPNV,
849 MXT_BACKUP_VALUE);
850 msleep(MXT_BACKUP_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700851
852 /* Soft reset */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700853 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800854 MXT_COMMAND_RESET, 1);
855 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700856
857 /* Update matrix size at info struct */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800858 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700859 if (error)
860 return error;
861 info->matrix_xsize = val;
862
Iiro Valkonen7686b102011-02-02 23:21:58 -0800863 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700864 if (error)
865 return error;
866 info->matrix_ysize = val;
867
868 dev_info(&client->dev,
869 "Family ID: %d Variant ID: %d Version: %d Build: %d\n",
870 info->family_id, info->variant_id, info->version,
871 info->build);
872
873 dev_info(&client->dev,
874 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n",
875 info->matrix_xsize, info->matrix_ysize,
876 info->object_num);
877
878 return 0;
879}
880
Joonyoung Shim910d8052011-04-12 23:14:38 -0700881static void mxt_calc_resolution(struct mxt_data *data)
882{
883 unsigned int max_x = data->pdata->x_size - 1;
884 unsigned int max_y = data->pdata->y_size - 1;
885
886 if (data->pdata->orient & MXT_XY_SWITCH) {
887 data->max_x = max_y;
888 data->max_y = max_x;
889 } else {
890 data->max_x = max_x;
891 data->max_y = max_y;
892 }
893}
894
Iiro Valkonen7686b102011-02-02 23:21:58 -0800895static ssize_t mxt_object_show(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700896 struct device_attribute *attr, char *buf)
897{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800898 struct mxt_data *data = dev_get_drvdata(dev);
899 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700900 int count = 0;
901 int i, j;
902 int error;
903 u8 val;
904
905 for (i = 0; i < data->info.object_num; i++) {
906 object = data->object_table + i;
907
Daniel Kurtz626af862011-10-06 15:43:20 -0700908 count += snprintf(buf + count, PAGE_SIZE - count,
909 "Object[%d] (Type %d)\n",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700910 i + 1, object->type);
Daniel Kurtz626af862011-10-06 15:43:20 -0700911 if (count >= PAGE_SIZE)
912 return PAGE_SIZE - 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700913
Iiro Valkonen7686b102011-02-02 23:21:58 -0800914 if (!mxt_object_readable(object->type)) {
Daniel Kurtz626af862011-10-06 15:43:20 -0700915 count += snprintf(buf + count, PAGE_SIZE - count,
916 "\n");
917 if (count >= PAGE_SIZE)
918 return PAGE_SIZE - 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700919 continue;
920 }
921
922 for (j = 0; j < object->size + 1; j++) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800923 error = mxt_read_object(data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700924 object->type, j, &val);
925 if (error)
926 return error;
927
Daniel Kurtz626af862011-10-06 15:43:20 -0700928 count += snprintf(buf + count, PAGE_SIZE - count,
929 "\t[%2d]: %02x (%d)\n", j, val, val);
930 if (count >= PAGE_SIZE)
931 return PAGE_SIZE - 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700932 }
933
Daniel Kurtz626af862011-10-06 15:43:20 -0700934 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
935 if (count >= PAGE_SIZE)
936 return PAGE_SIZE - 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700937 }
938
939 return count;
940}
941
Iiro Valkonen7686b102011-02-02 23:21:58 -0800942static int mxt_load_fw(struct device *dev, const char *fn)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700943{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800944 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700945 struct i2c_client *client = data->client;
946 const struct firmware *fw = NULL;
947 unsigned int frame_size;
948 unsigned int pos = 0;
949 int ret;
950
951 ret = request_firmware(&fw, fn, dev);
952 if (ret) {
953 dev_err(dev, "Unable to open firmware %s\n", fn);
954 return ret;
955 }
956
957 /* Change to the bootloader mode */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700958 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800959 MXT_COMMAND_RESET, MXT_BOOT_VALUE);
960 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700961
962 /* Change to slave address of bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800963 if (client->addr == MXT_APP_LOW)
964 client->addr = MXT_BOOT_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700965 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800966 client->addr = MXT_BOOT_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700967
Iiro Valkonen7686b102011-02-02 23:21:58 -0800968 ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700969 if (ret)
970 goto out;
971
972 /* Unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800973 mxt_unlock_bootloader(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700974
975 while (pos < fw->size) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800976 ret = mxt_check_bootloader(client,
977 MXT_WAITING_FRAME_DATA);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700978 if (ret)
979 goto out;
980
981 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
982
983 /* We should add 2 at frame size as the the firmware data is not
984 * included the CRC bytes.
985 */
986 frame_size += 2;
987
988 /* Write one frame to device */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800989 mxt_fw_write(client, fw->data + pos, frame_size);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700990
Iiro Valkonen7686b102011-02-02 23:21:58 -0800991 ret = mxt_check_bootloader(client,
992 MXT_FRAME_CRC_PASS);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700993 if (ret)
994 goto out;
995
996 pos += frame_size;
997
998 dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size);
999 }
1000
1001out:
1002 release_firmware(fw);
1003
1004 /* Change to slave address of application */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001005 if (client->addr == MXT_BOOT_LOW)
1006 client->addr = MXT_APP_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001007 else
Iiro Valkonen7686b102011-02-02 23:21:58 -08001008 client->addr = MXT_APP_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001009
1010 return ret;
1011}
1012
Iiro Valkonen7686b102011-02-02 23:21:58 -08001013static ssize_t mxt_update_fw_store(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001014 struct device_attribute *attr,
1015 const char *buf, size_t count)
1016{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001017 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001018 int error;
1019
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001020 disable_irq(data->irq);
1021
Iiro Valkonen7686b102011-02-02 23:21:58 -08001022 error = mxt_load_fw(dev, MXT_FW_NAME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001023 if (error) {
1024 dev_err(dev, "The firmware update failed(%d)\n", error);
1025 count = error;
1026 } else {
1027 dev_dbg(dev, "The firmware update succeeded\n");
1028
1029 /* Wait for reset */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001030 msleep(MXT_FWRESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001031
1032 kfree(data->object_table);
1033 data->object_table = NULL;
1034
Iiro Valkonen7686b102011-02-02 23:21:58 -08001035 mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001036 }
1037
1038 enable_irq(data->irq);
1039
Iiro Valkonen08960a02011-04-12 23:16:40 -07001040 error = mxt_make_highchg(data);
1041 if (error)
1042 return error;
1043
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001044 return count;
1045}
1046
Daniel Kurtz71b3e932012-05-08 22:30:14 -07001047static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
1048static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001049
Iiro Valkonen7686b102011-02-02 23:21:58 -08001050static struct attribute *mxt_attrs[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001051 &dev_attr_object.attr,
1052 &dev_attr_update_fw.attr,
1053 NULL
1054};
1055
Iiro Valkonen7686b102011-02-02 23:21:58 -08001056static const struct attribute_group mxt_attr_group = {
1057 .attrs = mxt_attrs,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001058};
1059
Iiro Valkonen7686b102011-02-02 23:21:58 -08001060static void mxt_start(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001061{
1062 /* Touch enable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001063 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001064 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001065}
1066
Iiro Valkonen7686b102011-02-02 23:21:58 -08001067static void mxt_stop(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001068{
1069 /* Touch disable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001070 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001071 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001072}
1073
Iiro Valkonen7686b102011-02-02 23:21:58 -08001074static int mxt_input_open(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001075{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001076 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001077
Iiro Valkonen7686b102011-02-02 23:21:58 -08001078 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001079
1080 return 0;
1081}
1082
Iiro Valkonen7686b102011-02-02 23:21:58 -08001083static void mxt_input_close(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001084{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001085 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001086
Iiro Valkonen7686b102011-02-02 23:21:58 -08001087 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001088}
1089
Iiro Valkonen7686b102011-02-02 23:21:58 -08001090static int __devinit mxt_probe(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001091 const struct i2c_device_id *id)
1092{
Iiro Valkonen919ed892011-02-15 13:36:52 -08001093 const struct mxt_platform_data *pdata = client->dev.platform_data;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001094 struct mxt_data *data;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001095 struct input_dev *input_dev;
1096 int error;
1097
Iiro Valkonen919ed892011-02-15 13:36:52 -08001098 if (!pdata)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001099 return -EINVAL;
1100
Iiro Valkonen7686b102011-02-02 23:21:58 -08001101 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001102 input_dev = input_allocate_device();
1103 if (!data || !input_dev) {
1104 dev_err(&client->dev, "Failed to allocate memory\n");
1105 error = -ENOMEM;
1106 goto err_free_mem;
1107 }
1108
Iiro Valkonen7686b102011-02-02 23:21:58 -08001109 input_dev->name = "Atmel maXTouch Touchscreen";
Daniel Kurtzec02ac22012-06-28 21:08:02 +08001110 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1111 client->adapter->nr, client->addr);
1112 input_dev->phys = data->phys;
1113
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001114 input_dev->id.bustype = BUS_I2C;
1115 input_dev->dev.parent = &client->dev;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001116 input_dev->open = mxt_input_open;
1117 input_dev->close = mxt_input_close;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001118
Joonyoung Shim910d8052011-04-12 23:14:38 -07001119 data->client = client;
1120 data->input_dev = input_dev;
1121 data->pdata = pdata;
1122 data->irq = client->irq;
1123
1124 mxt_calc_resolution(data);
1125
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001126 __set_bit(EV_ABS, input_dev->evbit);
1127 __set_bit(EV_KEY, input_dev->evbit);
1128 __set_bit(BTN_TOUCH, input_dev->keybit);
1129
1130 /* For single touch */
1131 input_set_abs_params(input_dev, ABS_X,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001132 0, data->max_x, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001133 input_set_abs_params(input_dev, ABS_Y,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001134 0, data->max_y, 0, 0);
Yufeng Shen28ac2932011-08-16 00:40:54 -07001135 input_set_abs_params(input_dev, ABS_PRESSURE,
1136 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001137
1138 /* For multi touch */
Daniel Kurtze1e16582012-06-28 21:08:04 +08001139 error = input_mt_init_slots(input_dev, MXT_MAX_FINGER);
1140 if (error)
1141 goto err_free_mem;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001142 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001143 0, MXT_MAX_AREA, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001144 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001145 0, data->max_x, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001146 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001147 0, data->max_y, 0, 0);
Yufeng Shen28ac2932011-08-16 00:40:54 -07001148 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
1149 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001150
1151 input_set_drvdata(input_dev, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001152 i2c_set_clientdata(client, data);
1153
Iiro Valkonen7686b102011-02-02 23:21:58 -08001154 error = mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001155 if (error)
1156 goto err_free_object;
1157
Iiro Valkonen7686b102011-02-02 23:21:58 -08001158 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
Daniel Kurtzc2ef9a12012-06-28 21:08:03 +08001159 pdata->irqflags, client->name, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001160 if (error) {
1161 dev_err(&client->dev, "Failed to register interrupt\n");
1162 goto err_free_object;
1163 }
1164
Iiro Valkonen08960a02011-04-12 23:16:40 -07001165 error = mxt_make_highchg(data);
1166 if (error)
1167 goto err_free_irq;
1168
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001169 error = input_register_device(input_dev);
1170 if (error)
1171 goto err_free_irq;
1172
Iiro Valkonen7686b102011-02-02 23:21:58 -08001173 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001174 if (error)
1175 goto err_unregister_device;
1176
1177 return 0;
1178
1179err_unregister_device:
1180 input_unregister_device(input_dev);
1181 input_dev = NULL;
1182err_free_irq:
1183 free_irq(client->irq, data);
1184err_free_object:
1185 kfree(data->object_table);
1186err_free_mem:
1187 input_free_device(input_dev);
1188 kfree(data);
1189 return error;
1190}
1191
Iiro Valkonen7686b102011-02-02 23:21:58 -08001192static int __devexit mxt_remove(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001193{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001194 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001195
Iiro Valkonen7686b102011-02-02 23:21:58 -08001196 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001197 free_irq(data->irq, data);
1198 input_unregister_device(data->input_dev);
1199 kfree(data->object_table);
1200 kfree(data);
1201
1202 return 0;
1203}
1204
Daniel Kurtz3a73c812012-05-08 22:29:14 -07001205#ifdef CONFIG_PM_SLEEP
Iiro Valkonen7686b102011-02-02 23:21:58 -08001206static int mxt_suspend(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001207{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001208 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08001209 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001210 struct input_dev *input_dev = data->input_dev;
1211
1212 mutex_lock(&input_dev->mutex);
1213
1214 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08001215 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001216
1217 mutex_unlock(&input_dev->mutex);
1218
1219 return 0;
1220}
1221
Iiro Valkonen7686b102011-02-02 23:21:58 -08001222static int mxt_resume(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001223{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001224 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08001225 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001226 struct input_dev *input_dev = data->input_dev;
1227
1228 /* Soft reset */
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001229 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001230 MXT_COMMAND_RESET, 1);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001231
Iiro Valkonen7686b102011-02-02 23:21:58 -08001232 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001233
1234 mutex_lock(&input_dev->mutex);
1235
1236 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08001237 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001238
1239 mutex_unlock(&input_dev->mutex);
1240
1241 return 0;
1242}
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001243#endif
1244
Daniel Kurtz3a73c812012-05-08 22:29:14 -07001245static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
1246
Iiro Valkonen7686b102011-02-02 23:21:58 -08001247static const struct i2c_device_id mxt_id[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001248 { "qt602240_ts", 0 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001249 { "atmel_mxt_ts", 0 },
Chris Leech46ee2a02011-02-15 13:36:52 -08001250 { "mXT224", 0 },
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001251 { }
1252};
Iiro Valkonen7686b102011-02-02 23:21:58 -08001253MODULE_DEVICE_TABLE(i2c, mxt_id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001254
Iiro Valkonen7686b102011-02-02 23:21:58 -08001255static struct i2c_driver mxt_driver = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001256 .driver = {
Iiro Valkonen7686b102011-02-02 23:21:58 -08001257 .name = "atmel_mxt_ts",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001258 .owner = THIS_MODULE,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001259 .pm = &mxt_pm_ops,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001260 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001261 .probe = mxt_probe,
1262 .remove = __devexit_p(mxt_remove),
1263 .id_table = mxt_id,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001264};
1265
Axel Lin1b92c1c2012-03-16 23:05:41 -07001266module_i2c_driver(mxt_driver);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001267
1268/* Module information */
1269MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
Iiro Valkonen7686b102011-02-02 23:21:58 -08001270MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001271MODULE_LICENSE("GPL");