blob: ee37b0b0e0e41cc7b962a95b9ee0a525a8fd89e4 [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_COMMAND_T6:
267 case MXT_GEN_POWER_T7:
268 case MXT_GEN_ACQUIRE_T8:
269 case MXT_GEN_DATASOURCE_T53:
270 case MXT_TOUCH_MULTI_T9:
271 case MXT_TOUCH_KEYARRAY_T15:
272 case MXT_TOUCH_PROXIMITY_T23:
273 case MXT_TOUCH_PROXKEY_T52:
274 case MXT_PROCI_GRIPFACE_T20:
275 case MXT_PROCG_NOISE_T22:
276 case MXT_PROCI_ONETOUCH_T24:
277 case MXT_PROCI_TWOTOUCH_T27:
278 case MXT_PROCI_GRIP_T40:
279 case MXT_PROCI_PALM_T41:
280 case MXT_PROCI_TOUCHSUPPRESSION_T42:
281 case MXT_PROCI_STYLUS_T47:
282 case MXT_PROCG_NOISESUPPRESSION_T48:
283 case MXT_SPT_COMMSCONFIG_T18:
284 case MXT_SPT_GPIOPWM_T19:
285 case MXT_SPT_SELFTEST_T25:
286 case MXT_SPT_CTECONFIG_T28:
287 case MXT_SPT_USERDATA_T38:
288 case MXT_SPT_DIGITIZER_T43:
289 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700290 return true;
291 default:
292 return false;
293 }
294}
295
Iiro Valkonen7686b102011-02-02 23:21:58 -0800296static bool mxt_object_writable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700297{
298 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700299 case MXT_GEN_COMMAND_T6:
300 case MXT_GEN_POWER_T7:
301 case MXT_GEN_ACQUIRE_T8:
302 case MXT_TOUCH_MULTI_T9:
303 case MXT_TOUCH_KEYARRAY_T15:
304 case MXT_TOUCH_PROXIMITY_T23:
305 case MXT_TOUCH_PROXKEY_T52:
306 case MXT_PROCI_GRIPFACE_T20:
307 case MXT_PROCG_NOISE_T22:
308 case MXT_PROCI_ONETOUCH_T24:
309 case MXT_PROCI_TWOTOUCH_T27:
310 case MXT_PROCI_GRIP_T40:
311 case MXT_PROCI_PALM_T41:
312 case MXT_PROCI_TOUCHSUPPRESSION_T42:
313 case MXT_PROCI_STYLUS_T47:
314 case MXT_PROCG_NOISESUPPRESSION_T48:
315 case MXT_SPT_COMMSCONFIG_T18:
316 case MXT_SPT_GPIOPWM_T19:
317 case MXT_SPT_SELFTEST_T25:
318 case MXT_SPT_CTECONFIG_T28:
319 case MXT_SPT_DIGITIZER_T43:
320 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700321 return true;
322 default:
323 return false;
324 }
325}
326
Iiro Valkonen7686b102011-02-02 23:21:58 -0800327static void mxt_dump_message(struct device *dev,
Daniel Kurtz6ee3dbf2012-05-08 22:40:29 -0700328 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700329{
Daniel Kurtz6ee3dbf2012-05-08 22:40:29 -0700330 dev_dbg(dev, "reportid: %u\tmessage: %02x %02x %02x %02x %02x %02x %02x\n",
331 message->reportid, message->message[0], message->message[1],
332 message->message[2], message->message[3], message->message[4],
333 message->message[5], message->message[6]);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700334}
335
Iiro Valkonen7686b102011-02-02 23:21:58 -0800336static int mxt_check_bootloader(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700337 unsigned int state)
338{
339 u8 val;
340
341recheck:
342 if (i2c_master_recv(client, &val, 1) != 1) {
343 dev_err(&client->dev, "%s: i2c recv failed\n", __func__);
344 return -EIO;
345 }
346
347 switch (state) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800348 case MXT_WAITING_BOOTLOAD_CMD:
349 case MXT_WAITING_FRAME_DATA:
350 val &= ~MXT_BOOT_STATUS_MASK;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700351 break;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800352 case MXT_FRAME_CRC_PASS:
353 if (val == MXT_FRAME_CRC_CHECK)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700354 goto recheck;
355 break;
356 default:
357 return -EINVAL;
358 }
359
360 if (val != state) {
361 dev_err(&client->dev, "Unvalid bootloader mode state\n");
362 return -EINVAL;
363 }
364
365 return 0;
366}
367
Iiro Valkonen7686b102011-02-02 23:21:58 -0800368static int mxt_unlock_bootloader(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700369{
370 u8 buf[2];
371
Iiro Valkonen7686b102011-02-02 23:21:58 -0800372 buf[0] = MXT_UNLOCK_CMD_LSB;
373 buf[1] = MXT_UNLOCK_CMD_MSB;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700374
375 if (i2c_master_send(client, buf, 2) != 2) {
376 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
377 return -EIO;
378 }
379
380 return 0;
381}
382
Iiro Valkonen7686b102011-02-02 23:21:58 -0800383static int mxt_fw_write(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700384 const u8 *data, unsigned int frame_size)
385{
386 if (i2c_master_send(client, data, frame_size) != frame_size) {
387 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
388 return -EIO;
389 }
390
391 return 0;
392}
393
Iiro Valkonen7686b102011-02-02 23:21:58 -0800394static int __mxt_read_reg(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700395 u16 reg, u16 len, void *val)
396{
397 struct i2c_msg xfer[2];
398 u8 buf[2];
399
400 buf[0] = reg & 0xff;
401 buf[1] = (reg >> 8) & 0xff;
402
403 /* Write register */
404 xfer[0].addr = client->addr;
405 xfer[0].flags = 0;
406 xfer[0].len = 2;
407 xfer[0].buf = buf;
408
409 /* Read data */
410 xfer[1].addr = client->addr;
411 xfer[1].flags = I2C_M_RD;
412 xfer[1].len = len;
413 xfer[1].buf = val;
414
415 if (i2c_transfer(client->adapter, xfer, 2) != 2) {
416 dev_err(&client->dev, "%s: i2c transfer failed\n", __func__);
417 return -EIO;
418 }
419
420 return 0;
421}
422
Iiro Valkonen7686b102011-02-02 23:21:58 -0800423static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700424{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800425 return __mxt_read_reg(client, reg, 1, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700426}
427
Iiro Valkonen7686b102011-02-02 23:21:58 -0800428static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700429{
430 u8 buf[3];
431
432 buf[0] = reg & 0xff;
433 buf[1] = (reg >> 8) & 0xff;
434 buf[2] = val;
435
436 if (i2c_master_send(client, buf, 3) != 3) {
437 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
438 return -EIO;
439 }
440
441 return 0;
442}
443
Iiro Valkonen7686b102011-02-02 23:21:58 -0800444static int mxt_read_object_table(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700445 u16 reg, u8 *object_buf)
446{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800447 return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700448 object_buf);
449}
450
Iiro Valkonen7686b102011-02-02 23:21:58 -0800451static struct mxt_object *
452mxt_get_object(struct mxt_data *data, u8 type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700453{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800454 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700455 int i;
456
457 for (i = 0; i < data->info.object_num; i++) {
458 object = data->object_table + i;
459 if (object->type == type)
460 return object;
461 }
462
463 dev_err(&data->client->dev, "Invalid object type\n");
464 return NULL;
465}
466
Iiro Valkonen7686b102011-02-02 23:21:58 -0800467static int mxt_read_message(struct mxt_data *data,
468 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700469{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800470 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700471 u16 reg;
472
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700473 object = mxt_get_object(data, MXT_GEN_MESSAGE_T5);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700474 if (!object)
475 return -EINVAL;
476
477 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800478 return __mxt_read_reg(data->client, reg,
479 sizeof(struct mxt_message), message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700480}
481
Iiro Valkonen7686b102011-02-02 23:21:58 -0800482static int mxt_write_object(struct mxt_data *data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700483 u8 type, u8 offset, u8 val)
484{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800485 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700486 u16 reg;
487
Iiro Valkonen7686b102011-02-02 23:21:58 -0800488 object = mxt_get_object(data, type);
Daniel Kurtzd1ff3202012-05-08 22:38:52 -0700489 if (!object || offset >= object->size + 1)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700490 return -EINVAL;
491
492 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800493 return mxt_write_reg(data->client, reg + offset, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700494}
495
Iiro Valkonen7686b102011-02-02 23:21:58 -0800496static void mxt_input_report(struct mxt_data *data, int single_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700497{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800498 struct mxt_finger *finger = data->finger;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700499 struct input_dev *input_dev = data->input_dev;
500 int status = finger[single_id].status;
501 int finger_num = 0;
502 int id;
503
Iiro Valkonen7686b102011-02-02 23:21:58 -0800504 for (id = 0; id < MXT_MAX_FINGER; id++) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700505 if (!finger[id].status)
506 continue;
507
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700508 input_mt_slot(input_dev, id);
509 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
510 finger[id].status != MXT_RELEASE);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700511
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700512 if (finger[id].status != MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700513 finger_num++;
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700514 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
515 finger[id].area);
516 input_report_abs(input_dev, ABS_MT_POSITION_X,
517 finger[id].x);
518 input_report_abs(input_dev, ABS_MT_POSITION_Y,
519 finger[id].y);
Yufeng Shen28ac2932011-08-16 00:40:54 -0700520 input_report_abs(input_dev, ABS_MT_PRESSURE,
521 finger[id].pressure);
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700522 } else {
523 finger[id].status = 0;
524 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700525 }
526
527 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
528
Iiro Valkonen7686b102011-02-02 23:21:58 -0800529 if (status != MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700530 input_report_abs(input_dev, ABS_X, finger[single_id].x);
531 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
Yufeng Shen28ac2932011-08-16 00:40:54 -0700532 input_report_abs(input_dev,
533 ABS_PRESSURE, finger[single_id].pressure);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700534 }
535
536 input_sync(input_dev);
537}
538
Iiro Valkonen7686b102011-02-02 23:21:58 -0800539static void mxt_input_touchevent(struct mxt_data *data,
540 struct mxt_message *message, int id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700541{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800542 struct mxt_finger *finger = data->finger;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700543 struct device *dev = &data->client->dev;
544 u8 status = message->message[0];
545 int x;
546 int y;
547 int area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700548 int pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700549
550 /* Check the touch is present on the screen */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800551 if (!(status & MXT_DETECT)) {
552 if (status & MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700553 dev_dbg(dev, "[%d] released\n", id);
554
Iiro Valkonen7686b102011-02-02 23:21:58 -0800555 finger[id].status = MXT_RELEASE;
556 mxt_input_report(data, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700557 }
558 return;
559 }
560
561 /* Check only AMP detection */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800562 if (!(status & (MXT_PRESS | MXT_MOVE)))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700563 return;
564
Joonyoung Shim910d8052011-04-12 23:14:38 -0700565 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
566 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
567 if (data->max_x < 1024)
568 x = x >> 2;
569 if (data->max_y < 1024)
570 y = y >> 2;
571
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700572 area = message->message[4];
Yufeng Shen28ac2932011-08-16 00:40:54 -0700573 pressure = message->message[5];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700574
575 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800576 status & MXT_MOVE ? "moved" : "pressed",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700577 x, y, area);
578
Iiro Valkonen7686b102011-02-02 23:21:58 -0800579 finger[id].status = status & MXT_MOVE ?
580 MXT_MOVE : MXT_PRESS;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700581 finger[id].x = x;
582 finger[id].y = y;
583 finger[id].area = area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700584 finger[id].pressure = pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700585
Iiro Valkonen7686b102011-02-02 23:21:58 -0800586 mxt_input_report(data, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700587}
588
Iiro Valkonen7686b102011-02-02 23:21:58 -0800589static irqreturn_t mxt_interrupt(int irq, void *dev_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700590{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800591 struct mxt_data *data = dev_id;
592 struct mxt_message message;
593 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700594 struct device *dev = &data->client->dev;
595 int id;
596 u8 reportid;
597 u8 max_reportid;
598 u8 min_reportid;
599
600 do {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800601 if (mxt_read_message(data, &message)) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700602 dev_err(dev, "Failed to read message\n");
603 goto end;
604 }
605
606 reportid = message.reportid;
607
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700608 /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */
609 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700610 if (!object)
611 goto end;
612
613 max_reportid = object->max_reportid;
614 min_reportid = max_reportid - object->num_report_ids + 1;
615 id = reportid - min_reportid;
616
617 if (reportid >= min_reportid && reportid <= max_reportid)
Iiro Valkonen7686b102011-02-02 23:21:58 -0800618 mxt_input_touchevent(data, &message, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700619 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800620 mxt_dump_message(dev, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700621 } while (reportid != 0xff);
622
623end:
624 return IRQ_HANDLED;
625}
626
Iiro Valkonen7686b102011-02-02 23:21:58 -0800627static int mxt_check_reg_init(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700628{
Iiro Valkonen71749f52011-02-15 13:36:52 -0800629 const struct mxt_platform_data *pdata = data->pdata;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800630 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700631 struct device *dev = &data->client->dev;
632 int index = 0;
Iiro Valkonen71749f52011-02-15 13:36:52 -0800633 int i, j, config_offset;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700634
Iiro Valkonen71749f52011-02-15 13:36:52 -0800635 if (!pdata->config) {
636 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
637 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700638 }
639
640 for (i = 0; i < data->info.object_num; i++) {
641 object = data->object_table + i;
642
Iiro Valkonen7686b102011-02-02 23:21:58 -0800643 if (!mxt_object_writable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700644 continue;
645
Iiro Valkonena93d4f22011-07-04 03:16:25 -0700646 for (j = 0;
647 j < (object->size + 1) * (object->instances + 1);
648 j++) {
Iiro Valkonen71749f52011-02-15 13:36:52 -0800649 config_offset = index + j;
650 if (config_offset > pdata->config_length) {
651 dev_err(dev, "Not enough config data!\n");
652 return -EINVAL;
653 }
Iiro Valkonen7686b102011-02-02 23:21:58 -0800654 mxt_write_object(data, object->type, j,
Iiro Valkonen71749f52011-02-15 13:36:52 -0800655 pdata->config[config_offset]);
656 }
Iiro Valkonena93d4f22011-07-04 03:16:25 -0700657 index += (object->size + 1) * (object->instances + 1);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700658 }
659
660 return 0;
661}
662
Iiro Valkonen7686b102011-02-02 23:21:58 -0800663static int mxt_make_highchg(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700664{
665 struct device *dev = &data->client->dev;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800666 struct mxt_message message;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700667 int count = 10;
668 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700669
670 /* Read dummy message to make high CHG pin */
671 do {
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800672 error = mxt_read_message(data, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700673 if (error)
674 return error;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800675 } while (message.reportid != 0xff && --count);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700676
677 if (!count) {
678 dev_err(dev, "CHG pin isn't cleared\n");
679 return -EBUSY;
680 }
681
682 return 0;
683}
684
Iiro Valkonen7686b102011-02-02 23:21:58 -0800685static void mxt_handle_pdata(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700686{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800687 const struct mxt_platform_data *pdata = data->pdata;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700688 u8 voltage;
689
690 /* Set touchscreen lines */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700691 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_XSIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700692 pdata->x_line);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700693 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_YSIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700694 pdata->y_line);
695
696 /* Set touchscreen orient */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700697 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_ORIENT,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700698 pdata->orient);
699
700 /* Set touchscreen burst length */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700701 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800702 MXT_TOUCH_BLEN, pdata->blen);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700703
704 /* Set touchscreen threshold */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700705 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800706 MXT_TOUCH_TCHTHR, pdata->threshold);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700707
708 /* Set touchscreen resolution */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700709 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800710 MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700711 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800712 MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700713 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800714 MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700715 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800716 MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700717
718 /* Set touchscreen voltage */
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700719 if (pdata->voltage) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800720 if (pdata->voltage < MXT_VOLTAGE_DEFAULT) {
721 voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) /
722 MXT_VOLTAGE_STEP;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700723 voltage = 0xff - voltage + 1;
724 } else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800725 voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) /
726 MXT_VOLTAGE_STEP;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700727
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700728 mxt_write_object(data, MXT_SPT_CTECONFIG_T28,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800729 MXT_CTE_VOLTAGE, voltage);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700730 }
731}
732
Iiro Valkonen7686b102011-02-02 23:21:58 -0800733static int mxt_get_info(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700734{
735 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800736 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700737 int error;
738 u8 val;
739
Iiro Valkonen7686b102011-02-02 23:21:58 -0800740 error = mxt_read_reg(client, MXT_FAMILY_ID, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700741 if (error)
742 return error;
743 info->family_id = val;
744
Iiro Valkonen7686b102011-02-02 23:21:58 -0800745 error = mxt_read_reg(client, MXT_VARIANT_ID, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700746 if (error)
747 return error;
748 info->variant_id = val;
749
Iiro Valkonen7686b102011-02-02 23:21:58 -0800750 error = mxt_read_reg(client, MXT_VERSION, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700751 if (error)
752 return error;
753 info->version = val;
754
Iiro Valkonen7686b102011-02-02 23:21:58 -0800755 error = mxt_read_reg(client, MXT_BUILD, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700756 if (error)
757 return error;
758 info->build = val;
759
Iiro Valkonen7686b102011-02-02 23:21:58 -0800760 error = mxt_read_reg(client, MXT_OBJECT_NUM, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700761 if (error)
762 return error;
763 info->object_num = val;
764
765 return 0;
766}
767
Iiro Valkonen7686b102011-02-02 23:21:58 -0800768static int mxt_get_object_table(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700769{
770 int error;
771 int i;
772 u16 reg;
773 u8 reportid = 0;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800774 u8 buf[MXT_OBJECT_SIZE];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700775
776 for (i = 0; i < data->info.object_num; i++) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800777 struct mxt_object *object = data->object_table + i;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700778
Iiro Valkonen7686b102011-02-02 23:21:58 -0800779 reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i;
780 error = mxt_read_object_table(data->client, reg, buf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700781 if (error)
782 return error;
783
784 object->type = buf[0];
785 object->start_address = (buf[2] << 8) | buf[1];
786 object->size = buf[3];
787 object->instances = buf[4];
788 object->num_report_ids = buf[5];
789
790 if (object->num_report_ids) {
791 reportid += object->num_report_ids *
792 (object->instances + 1);
793 object->max_reportid = reportid;
794 }
795 }
796
797 return 0;
798}
799
Iiro Valkonen7686b102011-02-02 23:21:58 -0800800static int mxt_initialize(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700801{
802 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800803 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700804 int error;
805 u8 val;
806
Iiro Valkonen7686b102011-02-02 23:21:58 -0800807 error = mxt_get_info(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700808 if (error)
809 return error;
810
811 data->object_table = kcalloc(info->object_num,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800812 sizeof(struct mxt_object),
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700813 GFP_KERNEL);
814 if (!data->object_table) {
815 dev_err(&client->dev, "Failed to allocate memory\n");
816 return -ENOMEM;
817 }
818
819 /* Get object table information */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800820 error = mxt_get_object_table(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700821 if (error)
822 return error;
823
824 /* Check register init values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800825 error = mxt_check_reg_init(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700826 if (error)
827 return error;
828
Iiro Valkonen7686b102011-02-02 23:21:58 -0800829 mxt_handle_pdata(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700830
831 /* Backup to memory */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700832 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800833 MXT_COMMAND_BACKUPNV,
834 MXT_BACKUP_VALUE);
835 msleep(MXT_BACKUP_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700836
837 /* Soft reset */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700838 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800839 MXT_COMMAND_RESET, 1);
840 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700841
842 /* Update matrix size at info struct */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800843 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700844 if (error)
845 return error;
846 info->matrix_xsize = val;
847
Iiro Valkonen7686b102011-02-02 23:21:58 -0800848 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700849 if (error)
850 return error;
851 info->matrix_ysize = val;
852
853 dev_info(&client->dev,
854 "Family ID: %d Variant ID: %d Version: %d Build: %d\n",
855 info->family_id, info->variant_id, info->version,
856 info->build);
857
858 dev_info(&client->dev,
859 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n",
860 info->matrix_xsize, info->matrix_ysize,
861 info->object_num);
862
863 return 0;
864}
865
Joonyoung Shim910d8052011-04-12 23:14:38 -0700866static void mxt_calc_resolution(struct mxt_data *data)
867{
868 unsigned int max_x = data->pdata->x_size - 1;
869 unsigned int max_y = data->pdata->y_size - 1;
870
871 if (data->pdata->orient & MXT_XY_SWITCH) {
872 data->max_x = max_y;
873 data->max_y = max_x;
874 } else {
875 data->max_x = max_x;
876 data->max_y = max_y;
877 }
878}
879
Daniel Kurtz794eb672012-06-28 21:08:10 +0800880static ssize_t mxt_show_instance(char *buf, int count,
881 struct mxt_object *object, int instance,
882 const u8 *val)
883{
884 int i;
885
886 if (object->instances > 0)
887 count += scnprintf(buf + count, PAGE_SIZE - count,
888 "Instance %u\n", instance);
889
890 for (i = 0; i < object->size + 1; i++)
891 count += scnprintf(buf + count, PAGE_SIZE - count,
892 "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
893 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
894
895 return count;
896}
897
Iiro Valkonen7686b102011-02-02 23:21:58 -0800898static ssize_t mxt_object_show(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700899 struct device_attribute *attr, char *buf)
900{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800901 struct mxt_data *data = dev_get_drvdata(dev);
902 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700903 int count = 0;
904 int i, j;
905 int error;
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800906 u8 *obuf;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700907
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800908 /* Pre-allocate buffer large enough to hold max sized object. */
909 obuf = kmalloc(256, GFP_KERNEL);
910 if (!obuf)
911 return -ENOMEM;
912
913 error = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700914 for (i = 0; i < data->info.object_num; i++) {
915 object = data->object_table + i;
916
Daniel Kurtz91630952012-06-28 21:08:09 +0800917 if (!mxt_object_readable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700918 continue;
Daniel Kurtz91630952012-06-28 21:08:09 +0800919
920 count += scnprintf(buf + count, PAGE_SIZE - count,
921 "T%u:\n", object->type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700922
Daniel Kurtz794eb672012-06-28 21:08:10 +0800923 for (j = 0; j < object->instances + 1; j++) {
924 u16 size = object->size + 1;
925 u16 addr = object->start_address + j * size;
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800926
Daniel Kurtz794eb672012-06-28 21:08:10 +0800927 error = __mxt_read_reg(data->client, addr, size, obuf);
928 if (error)
929 goto done;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700930
Daniel Kurtz794eb672012-06-28 21:08:10 +0800931 count = mxt_show_instance(buf, count, object, j, obuf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700932 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700933 }
934
Daniel Kurtz794eb672012-06-28 21:08:10 +0800935done:
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800936 kfree(obuf);
937 return error ?: count;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700938}
939
Iiro Valkonen7686b102011-02-02 23:21:58 -0800940static int mxt_load_fw(struct device *dev, const char *fn)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700941{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800942 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700943 struct i2c_client *client = data->client;
944 const struct firmware *fw = NULL;
945 unsigned int frame_size;
946 unsigned int pos = 0;
947 int ret;
948
949 ret = request_firmware(&fw, fn, dev);
950 if (ret) {
951 dev_err(dev, "Unable to open firmware %s\n", fn);
952 return ret;
953 }
954
955 /* Change to the bootloader mode */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700956 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800957 MXT_COMMAND_RESET, MXT_BOOT_VALUE);
958 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700959
960 /* Change to slave address of bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800961 if (client->addr == MXT_APP_LOW)
962 client->addr = MXT_BOOT_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700963 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800964 client->addr = MXT_BOOT_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700965
Iiro Valkonen7686b102011-02-02 23:21:58 -0800966 ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700967 if (ret)
968 goto out;
969
970 /* Unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800971 mxt_unlock_bootloader(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700972
973 while (pos < fw->size) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800974 ret = mxt_check_bootloader(client,
975 MXT_WAITING_FRAME_DATA);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700976 if (ret)
977 goto out;
978
979 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
980
981 /* We should add 2 at frame size as the the firmware data is not
982 * included the CRC bytes.
983 */
984 frame_size += 2;
985
986 /* Write one frame to device */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800987 mxt_fw_write(client, fw->data + pos, frame_size);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700988
Iiro Valkonen7686b102011-02-02 23:21:58 -0800989 ret = mxt_check_bootloader(client,
990 MXT_FRAME_CRC_PASS);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700991 if (ret)
992 goto out;
993
994 pos += frame_size;
995
996 dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size);
997 }
998
999out:
1000 release_firmware(fw);
1001
1002 /* Change to slave address of application */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001003 if (client->addr == MXT_BOOT_LOW)
1004 client->addr = MXT_APP_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001005 else
Iiro Valkonen7686b102011-02-02 23:21:58 -08001006 client->addr = MXT_APP_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001007
1008 return ret;
1009}
1010
Iiro Valkonen7686b102011-02-02 23:21:58 -08001011static ssize_t mxt_update_fw_store(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001012 struct device_attribute *attr,
1013 const char *buf, size_t count)
1014{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001015 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001016 int error;
1017
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001018 disable_irq(data->irq);
1019
Iiro Valkonen7686b102011-02-02 23:21:58 -08001020 error = mxt_load_fw(dev, MXT_FW_NAME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001021 if (error) {
1022 dev_err(dev, "The firmware update failed(%d)\n", error);
1023 count = error;
1024 } else {
1025 dev_dbg(dev, "The firmware update succeeded\n");
1026
1027 /* Wait for reset */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001028 msleep(MXT_FWRESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001029
1030 kfree(data->object_table);
1031 data->object_table = NULL;
1032
Iiro Valkonen7686b102011-02-02 23:21:58 -08001033 mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001034 }
1035
1036 enable_irq(data->irq);
1037
Iiro Valkonen08960a02011-04-12 23:16:40 -07001038 error = mxt_make_highchg(data);
1039 if (error)
1040 return error;
1041
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001042 return count;
1043}
1044
Daniel Kurtz71b3e932012-05-08 22:30:14 -07001045static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
1046static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001047
Iiro Valkonen7686b102011-02-02 23:21:58 -08001048static struct attribute *mxt_attrs[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001049 &dev_attr_object.attr,
1050 &dev_attr_update_fw.attr,
1051 NULL
1052};
1053
Iiro Valkonen7686b102011-02-02 23:21:58 -08001054static const struct attribute_group mxt_attr_group = {
1055 .attrs = mxt_attrs,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001056};
1057
Iiro Valkonen7686b102011-02-02 23:21:58 -08001058static void mxt_start(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001059{
1060 /* Touch enable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001061 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001062 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001063}
1064
Iiro Valkonen7686b102011-02-02 23:21:58 -08001065static void mxt_stop(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001066{
1067 /* Touch disable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001068 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001069 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001070}
1071
Iiro Valkonen7686b102011-02-02 23:21:58 -08001072static int mxt_input_open(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001073{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001074 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001075
Iiro Valkonen7686b102011-02-02 23:21:58 -08001076 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001077
1078 return 0;
1079}
1080
Iiro Valkonen7686b102011-02-02 23:21:58 -08001081static void mxt_input_close(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001082{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001083 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001084
Iiro Valkonen7686b102011-02-02 23:21:58 -08001085 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001086}
1087
Iiro Valkonen7686b102011-02-02 23:21:58 -08001088static int __devinit mxt_probe(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001089 const struct i2c_device_id *id)
1090{
Iiro Valkonen919ed892011-02-15 13:36:52 -08001091 const struct mxt_platform_data *pdata = client->dev.platform_data;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001092 struct mxt_data *data;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001093 struct input_dev *input_dev;
1094 int error;
1095
Iiro Valkonen919ed892011-02-15 13:36:52 -08001096 if (!pdata)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001097 return -EINVAL;
1098
Iiro Valkonen7686b102011-02-02 23:21:58 -08001099 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001100 input_dev = input_allocate_device();
1101 if (!data || !input_dev) {
1102 dev_err(&client->dev, "Failed to allocate memory\n");
1103 error = -ENOMEM;
1104 goto err_free_mem;
1105 }
1106
Iiro Valkonen7686b102011-02-02 23:21:58 -08001107 input_dev->name = "Atmel maXTouch Touchscreen";
Daniel Kurtzec02ac22012-06-28 21:08:02 +08001108 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1109 client->adapter->nr, client->addr);
1110 input_dev->phys = data->phys;
1111
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001112 input_dev->id.bustype = BUS_I2C;
1113 input_dev->dev.parent = &client->dev;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001114 input_dev->open = mxt_input_open;
1115 input_dev->close = mxt_input_close;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001116
Joonyoung Shim910d8052011-04-12 23:14:38 -07001117 data->client = client;
1118 data->input_dev = input_dev;
1119 data->pdata = pdata;
1120 data->irq = client->irq;
1121
1122 mxt_calc_resolution(data);
1123
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001124 __set_bit(EV_ABS, input_dev->evbit);
1125 __set_bit(EV_KEY, input_dev->evbit);
1126 __set_bit(BTN_TOUCH, input_dev->keybit);
1127
1128 /* For single touch */
1129 input_set_abs_params(input_dev, ABS_X,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001130 0, data->max_x, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001131 input_set_abs_params(input_dev, ABS_Y,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001132 0, data->max_y, 0, 0);
Yufeng Shen28ac2932011-08-16 00:40:54 -07001133 input_set_abs_params(input_dev, ABS_PRESSURE,
1134 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001135
1136 /* For multi touch */
Daniel Kurtze1e16582012-06-28 21:08:04 +08001137 error = input_mt_init_slots(input_dev, MXT_MAX_FINGER);
1138 if (error)
1139 goto err_free_mem;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001140 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001141 0, MXT_MAX_AREA, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001142 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001143 0, data->max_x, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001144 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001145 0, data->max_y, 0, 0);
Yufeng Shen28ac2932011-08-16 00:40:54 -07001146 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
1147 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001148
1149 input_set_drvdata(input_dev, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001150 i2c_set_clientdata(client, data);
1151
Iiro Valkonen7686b102011-02-02 23:21:58 -08001152 error = mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001153 if (error)
1154 goto err_free_object;
1155
Iiro Valkonen7686b102011-02-02 23:21:58 -08001156 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
Daniel Kurtzc2ef9a12012-06-28 21:08:03 +08001157 pdata->irqflags, client->name, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001158 if (error) {
1159 dev_err(&client->dev, "Failed to register interrupt\n");
1160 goto err_free_object;
1161 }
1162
Iiro Valkonen08960a02011-04-12 23:16:40 -07001163 error = mxt_make_highchg(data);
1164 if (error)
1165 goto err_free_irq;
1166
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001167 error = input_register_device(input_dev);
1168 if (error)
1169 goto err_free_irq;
1170
Iiro Valkonen7686b102011-02-02 23:21:58 -08001171 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001172 if (error)
Daniel Kurtz63990032012-06-28 21:08:05 +08001173 dev_warn(&client->dev, "error creating sysfs entries.\n");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001174
1175 return 0;
1176
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001177err_free_irq:
1178 free_irq(client->irq, data);
1179err_free_object:
1180 kfree(data->object_table);
1181err_free_mem:
1182 input_free_device(input_dev);
1183 kfree(data);
1184 return error;
1185}
1186
Iiro Valkonen7686b102011-02-02 23:21:58 -08001187static int __devexit mxt_remove(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001188{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001189 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001190
Iiro Valkonen7686b102011-02-02 23:21:58 -08001191 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001192 free_irq(data->irq, data);
1193 input_unregister_device(data->input_dev);
1194 kfree(data->object_table);
1195 kfree(data);
1196
1197 return 0;
1198}
1199
Daniel Kurtz3a73c812012-05-08 22:29:14 -07001200#ifdef CONFIG_PM_SLEEP
Iiro Valkonen7686b102011-02-02 23:21:58 -08001201static int mxt_suspend(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001202{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001203 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08001204 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001205 struct input_dev *input_dev = data->input_dev;
1206
1207 mutex_lock(&input_dev->mutex);
1208
1209 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08001210 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001211
1212 mutex_unlock(&input_dev->mutex);
1213
1214 return 0;
1215}
1216
Iiro Valkonen7686b102011-02-02 23:21:58 -08001217static int mxt_resume(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001218{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001219 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08001220 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001221 struct input_dev *input_dev = data->input_dev;
1222
1223 /* Soft reset */
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001224 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001225 MXT_COMMAND_RESET, 1);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001226
Iiro Valkonen7686b102011-02-02 23:21:58 -08001227 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001228
1229 mutex_lock(&input_dev->mutex);
1230
1231 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08001232 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001233
1234 mutex_unlock(&input_dev->mutex);
1235
1236 return 0;
1237}
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001238#endif
1239
Daniel Kurtz3a73c812012-05-08 22:29:14 -07001240static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
1241
Iiro Valkonen7686b102011-02-02 23:21:58 -08001242static const struct i2c_device_id mxt_id[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001243 { "qt602240_ts", 0 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001244 { "atmel_mxt_ts", 0 },
Chris Leech46ee2a02011-02-15 13:36:52 -08001245 { "mXT224", 0 },
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001246 { }
1247};
Iiro Valkonen7686b102011-02-02 23:21:58 -08001248MODULE_DEVICE_TABLE(i2c, mxt_id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001249
Iiro Valkonen7686b102011-02-02 23:21:58 -08001250static struct i2c_driver mxt_driver = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001251 .driver = {
Iiro Valkonen7686b102011-02-02 23:21:58 -08001252 .name = "atmel_mxt_ts",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001253 .owner = THIS_MODULE,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001254 .pm = &mxt_pm_ops,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001255 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001256 .probe = mxt_probe,
1257 .remove = __devexit_p(mxt_remove),
1258 .id_table = mxt_id,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001259};
1260
Axel Lin1b92c1c2012-03-16 23:05:41 -07001261module_i2c_driver(mxt_driver);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001262
1263/* Module information */
1264MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
Iiro Valkonen7686b102011-02-02 23:21:58 -08001265MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001266MODULE_LICENSE("GPL");