blob: fac379146546df6617aaf11c9d671d3240fad7b3 [file] [log] [blame]
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001/*
Iiro Valkonen7686b102011-02-02 23:21:58 -08002 * Atmel maXTouch Touchscreen driver
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/firmware.h>
18#include <linux/i2c.h>
Dmitry Torokhov964de522011-02-02 23:21:58 -080019#include <linux/i2c/atmel_mxt_ts.h>
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -070020#include <linux/input/mt.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070021#include <linux/interrupt.h>
22#include <linux/slab.h>
23
24/* Version */
Iiro Valkonen7686b102011-02-02 23:21:58 -080025#define MXT_VER_20 20
26#define MXT_VER_21 21
27#define MXT_VER_22 22
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070028
29/* Slave addresses */
Iiro Valkonen7686b102011-02-02 23:21:58 -080030#define MXT_APP_LOW 0x4a
31#define MXT_APP_HIGH 0x4b
32#define MXT_BOOT_LOW 0x24
33#define MXT_BOOT_HIGH 0x25
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070034
35/* Firmware */
Iiro Valkonen7686b102011-02-02 23:21:58 -080036#define MXT_FW_NAME "maxtouch.fw"
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070037
38/* Registers */
Daniel Kurtz23003a842012-06-28 21:08:14 +080039#define MXT_INFO 0x00
Iiro Valkonen7686b102011-02-02 23:21:58 -080040#define MXT_FAMILY_ID 0x00
41#define MXT_VARIANT_ID 0x01
42#define MXT_VERSION 0x02
43#define MXT_BUILD 0x03
44#define MXT_MATRIX_X_SIZE 0x04
45#define MXT_MATRIX_Y_SIZE 0x05
46#define MXT_OBJECT_NUM 0x06
47#define MXT_OBJECT_START 0x07
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070048
Iiro Valkonen7686b102011-02-02 23:21:58 -080049#define MXT_OBJECT_SIZE 6
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070050
51/* Object types */
Iiro Valkonen81c88a72011-07-04 03:08:25 -070052#define MXT_DEBUG_DIAGNOSTIC_T37 37
53#define MXT_GEN_MESSAGE_T5 5
54#define MXT_GEN_COMMAND_T6 6
55#define MXT_GEN_POWER_T7 7
56#define MXT_GEN_ACQUIRE_T8 8
57#define MXT_GEN_DATASOURCE_T53 53
58#define MXT_TOUCH_MULTI_T9 9
59#define MXT_TOUCH_KEYARRAY_T15 15
60#define MXT_TOUCH_PROXIMITY_T23 23
61#define MXT_TOUCH_PROXKEY_T52 52
62#define MXT_PROCI_GRIPFACE_T20 20
63#define MXT_PROCG_NOISE_T22 22
64#define MXT_PROCI_ONETOUCH_T24 24
65#define MXT_PROCI_TWOTOUCH_T27 27
66#define MXT_PROCI_GRIP_T40 40
67#define MXT_PROCI_PALM_T41 41
68#define MXT_PROCI_TOUCHSUPPRESSION_T42 42
69#define MXT_PROCI_STYLUS_T47 47
70#define MXT_PROCG_NOISESUPPRESSION_T48 48
71#define MXT_SPT_COMMSCONFIG_T18 18
72#define MXT_SPT_GPIOPWM_T19 19
73#define MXT_SPT_SELFTEST_T25 25
74#define MXT_SPT_CTECONFIG_T28 28
75#define MXT_SPT_USERDATA_T38 38
76#define MXT_SPT_DIGITIZER_T43 43
77#define MXT_SPT_MESSAGECOUNT_T44 44
78#define MXT_SPT_CTECONFIG_T46 46
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070079
Iiro Valkonen81c88a72011-07-04 03:08:25 -070080/* MXT_GEN_COMMAND_T6 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080081#define MXT_COMMAND_RESET 0
82#define MXT_COMMAND_BACKUPNV 1
83#define MXT_COMMAND_CALIBRATE 2
84#define MXT_COMMAND_REPORTALL 3
85#define MXT_COMMAND_DIAGNOSTIC 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070086
Iiro Valkonen81c88a72011-07-04 03:08:25 -070087/* MXT_GEN_POWER_T7 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080088#define MXT_POWER_IDLEACQINT 0
89#define MXT_POWER_ACTVACQINT 1
90#define MXT_POWER_ACTV2IDLETO 2
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070091
Iiro Valkonen81c88a72011-07-04 03:08:25 -070092/* MXT_GEN_ACQUIRE_T8 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080093#define MXT_ACQUIRE_CHRGTIME 0
94#define MXT_ACQUIRE_TCHDRIFT 2
95#define MXT_ACQUIRE_DRIFTST 3
96#define MXT_ACQUIRE_TCHAUTOCAL 4
97#define MXT_ACQUIRE_SYNC 5
98#define MXT_ACQUIRE_ATCHCALST 6
99#define MXT_ACQUIRE_ATCHCALSTHR 7
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700100
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700101/* MXT_TOUCH_MULTI_T9 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800102#define MXT_TOUCH_CTRL 0
103#define MXT_TOUCH_XORIGIN 1
104#define MXT_TOUCH_YORIGIN 2
105#define MXT_TOUCH_XSIZE 3
106#define MXT_TOUCH_YSIZE 4
107#define MXT_TOUCH_BLEN 6
108#define MXT_TOUCH_TCHTHR 7
109#define MXT_TOUCH_TCHDI 8
110#define MXT_TOUCH_ORIENT 9
111#define MXT_TOUCH_MOVHYSTI 11
112#define MXT_TOUCH_MOVHYSTN 12
113#define MXT_TOUCH_NUMTOUCH 14
114#define MXT_TOUCH_MRGHYST 15
115#define MXT_TOUCH_MRGTHR 16
116#define MXT_TOUCH_AMPHYST 17
117#define MXT_TOUCH_XRANGE_LSB 18
118#define MXT_TOUCH_XRANGE_MSB 19
119#define MXT_TOUCH_YRANGE_LSB 20
120#define MXT_TOUCH_YRANGE_MSB 21
121#define MXT_TOUCH_XLOCLIP 22
122#define MXT_TOUCH_XHICLIP 23
123#define MXT_TOUCH_YLOCLIP 24
124#define MXT_TOUCH_YHICLIP 25
125#define MXT_TOUCH_XEDGECTRL 26
126#define MXT_TOUCH_XEDGEDIST 27
127#define MXT_TOUCH_YEDGECTRL 28
128#define MXT_TOUCH_YEDGEDIST 29
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700129#define MXT_TOUCH_JUMPLIMIT 30
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700130
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700131/* MXT_PROCI_GRIPFACE_T20 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800132#define MXT_GRIPFACE_CTRL 0
133#define MXT_GRIPFACE_XLOGRIP 1
134#define MXT_GRIPFACE_XHIGRIP 2
135#define MXT_GRIPFACE_YLOGRIP 3
136#define MXT_GRIPFACE_YHIGRIP 4
137#define MXT_GRIPFACE_MAXTCHS 5
138#define MXT_GRIPFACE_SZTHR1 7
139#define MXT_GRIPFACE_SZTHR2 8
140#define MXT_GRIPFACE_SHPTHR1 9
141#define MXT_GRIPFACE_SHPTHR2 10
142#define MXT_GRIPFACE_SUPEXTTO 11
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700143
Iiro Valkonen7686b102011-02-02 23:21:58 -0800144/* MXT_PROCI_NOISE field */
145#define MXT_NOISE_CTRL 0
146#define MXT_NOISE_OUTFLEN 1
147#define MXT_NOISE_GCAFUL_LSB 3
148#define MXT_NOISE_GCAFUL_MSB 4
149#define MXT_NOISE_GCAFLL_LSB 5
150#define MXT_NOISE_GCAFLL_MSB 6
151#define MXT_NOISE_ACTVGCAFVALID 7
152#define MXT_NOISE_NOISETHR 8
153#define MXT_NOISE_FREQHOPSCALE 10
154#define MXT_NOISE_FREQ0 11
155#define MXT_NOISE_FREQ1 12
156#define MXT_NOISE_FREQ2 13
157#define MXT_NOISE_FREQ3 14
158#define MXT_NOISE_FREQ4 15
159#define MXT_NOISE_IDLEGCAFVALID 16
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700160
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700161/* MXT_SPT_COMMSCONFIG_T18 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800162#define MXT_COMMS_CTRL 0
163#define MXT_COMMS_CMD 1
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700164
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700165/* MXT_SPT_CTECONFIG_T28 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800166#define MXT_CTE_CTRL 0
167#define MXT_CTE_CMD 1
168#define MXT_CTE_MODE 2
169#define MXT_CTE_IDLEGCAFDEPTH 3
170#define MXT_CTE_ACTVGCAFDEPTH 4
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700171#define MXT_CTE_VOLTAGE 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700172
Iiro Valkonen7686b102011-02-02 23:21:58 -0800173#define MXT_VOLTAGE_DEFAULT 2700000
174#define MXT_VOLTAGE_STEP 10000
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700175
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700176/* Define for MXT_GEN_COMMAND_T6 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800177#define MXT_BOOT_VALUE 0xa5
178#define MXT_BACKUP_VALUE 0x55
179#define MXT_BACKUP_TIME 25 /* msec */
180#define MXT_RESET_TIME 65 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700181
Iiro Valkonen7686b102011-02-02 23:21:58 -0800182#define MXT_FWRESET_TIME 175 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700183
184/* Command to unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800185#define MXT_UNLOCK_CMD_MSB 0xaa
186#define MXT_UNLOCK_CMD_LSB 0xdc
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700187
188/* Bootloader mode status */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800189#define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
190#define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
191#define MXT_FRAME_CRC_CHECK 0x02
192#define MXT_FRAME_CRC_FAIL 0x03
193#define MXT_FRAME_CRC_PASS 0x04
194#define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
195#define MXT_BOOT_STATUS_MASK 0x3f
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700196
197/* Touch status */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800198#define MXT_SUPPRESS (1 << 1)
199#define MXT_AMP (1 << 2)
200#define MXT_VECTOR (1 << 3)
201#define MXT_MOVE (1 << 4)
202#define MXT_RELEASE (1 << 5)
203#define MXT_PRESS (1 << 6)
204#define MXT_DETECT (1 << 7)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700205
Joonyoung Shim910d8052011-04-12 23:14:38 -0700206/* Touch orient bits */
207#define MXT_XY_SWITCH (1 << 0)
208#define MXT_X_INVERT (1 << 1)
209#define MXT_Y_INVERT (1 << 2)
210
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700211/* Touchscreen absolute values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800212#define MXT_MAX_AREA 0xff
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700213
Iiro Valkonen7686b102011-02-02 23:21:58 -0800214#define MXT_MAX_FINGER 10
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700215
Iiro Valkonen7686b102011-02-02 23:21:58 -0800216struct mxt_info {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700217 u8 family_id;
218 u8 variant_id;
219 u8 version;
220 u8 build;
221 u8 matrix_xsize;
222 u8 matrix_ysize;
223 u8 object_num;
224};
225
Iiro Valkonen7686b102011-02-02 23:21:58 -0800226struct mxt_object {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700227 u8 type;
228 u16 start_address;
229 u8 size;
230 u8 instances;
231 u8 num_report_ids;
232
233 /* to map object and message */
234 u8 max_reportid;
235};
236
Iiro Valkonen7686b102011-02-02 23:21:58 -0800237struct mxt_message {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700238 u8 reportid;
239 u8 message[7];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700240};
241
Iiro Valkonen7686b102011-02-02 23:21:58 -0800242struct mxt_finger {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700243 int status;
244 int x;
245 int y;
246 int area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700247 int pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700248};
249
250/* Each client has this additional data */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800251struct mxt_data {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700252 struct i2c_client *client;
253 struct input_dev *input_dev;
Daniel Kurtzec02ac22012-06-28 21:08:02 +0800254 char phys[64]; /* device physical location */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800255 const struct mxt_platform_data *pdata;
256 struct mxt_object *object_table;
257 struct mxt_info info;
258 struct mxt_finger finger[MXT_MAX_FINGER];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700259 unsigned int irq;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700260 unsigned int max_x;
261 unsigned int max_y;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700262};
263
Iiro Valkonen7686b102011-02-02 23:21:58 -0800264static bool mxt_object_readable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700265{
266 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700267 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];
Daniel Kurtz771733e2012-06-28 21:08:11 +0800400 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700401
402 buf[0] = reg & 0xff;
403 buf[1] = (reg >> 8) & 0xff;
404
405 /* Write register */
406 xfer[0].addr = client->addr;
407 xfer[0].flags = 0;
408 xfer[0].len = 2;
409 xfer[0].buf = buf;
410
411 /* Read data */
412 xfer[1].addr = client->addr;
413 xfer[1].flags = I2C_M_RD;
414 xfer[1].len = len;
415 xfer[1].buf = val;
416
Daniel Kurtz771733e2012-06-28 21:08:11 +0800417 ret = i2c_transfer(client->adapter, xfer, 2);
418 if (ret == 2) {
419 ret = 0;
420 } else {
421 if (ret >= 0)
422 ret = -EIO;
423 dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
424 __func__, ret);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700425 }
426
Daniel Kurtz771733e2012-06-28 21:08:11 +0800427 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700428}
429
Iiro Valkonen7686b102011-02-02 23:21:58 -0800430static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700431{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800432 return __mxt_read_reg(client, reg, 1, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700433}
434
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800435static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
436 const void *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700437{
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800438 u8 *buf;
439 size_t count;
Daniel Kurtz771733e2012-06-28 21:08:11 +0800440 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700441
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800442 count = len + 2;
443 buf = kmalloc(count, GFP_KERNEL);
444 if (!buf)
445 return -ENOMEM;
446
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700447 buf[0] = reg & 0xff;
448 buf[1] = (reg >> 8) & 0xff;
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800449 memcpy(&buf[2], val, len);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700450
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800451 ret = i2c_master_send(client, buf, count);
452 if (ret == count) {
Daniel Kurtz771733e2012-06-28 21:08:11 +0800453 ret = 0;
454 } else {
455 if (ret >= 0)
456 ret = -EIO;
457 dev_err(&client->dev, "%s: i2c send failed (%d)\n",
458 __func__, ret);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700459 }
460
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800461 kfree(buf);
Daniel Kurtz771733e2012-06-28 21:08:11 +0800462 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700463}
464
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800465static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
466{
467 return __mxt_write_reg(client, reg, 1, &val);
468}
469
Iiro Valkonen7686b102011-02-02 23:21:58 -0800470static int mxt_read_object_table(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700471 u16 reg, u8 *object_buf)
472{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800473 return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700474 object_buf);
475}
476
Iiro Valkonen7686b102011-02-02 23:21:58 -0800477static struct mxt_object *
478mxt_get_object(struct mxt_data *data, u8 type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700479{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800480 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700481 int i;
482
483 for (i = 0; i < data->info.object_num; i++) {
484 object = data->object_table + i;
485 if (object->type == type)
486 return object;
487 }
488
489 dev_err(&data->client->dev, "Invalid object type\n");
490 return NULL;
491}
492
Iiro Valkonen7686b102011-02-02 23:21:58 -0800493static int mxt_read_message(struct mxt_data *data,
494 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700495{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800496 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700497 u16 reg;
498
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700499 object = mxt_get_object(data, MXT_GEN_MESSAGE_T5);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700500 if (!object)
501 return -EINVAL;
502
503 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800504 return __mxt_read_reg(data->client, reg,
505 sizeof(struct mxt_message), message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700506}
507
Iiro Valkonen7686b102011-02-02 23:21:58 -0800508static int mxt_write_object(struct mxt_data *data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700509 u8 type, u8 offset, u8 val)
510{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800511 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700512 u16 reg;
513
Iiro Valkonen7686b102011-02-02 23:21:58 -0800514 object = mxt_get_object(data, type);
Daniel Kurtzd1ff3202012-05-08 22:38:52 -0700515 if (!object || offset >= object->size + 1)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700516 return -EINVAL;
517
518 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800519 return mxt_write_reg(data->client, reg + offset, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700520}
521
Iiro Valkonen7686b102011-02-02 23:21:58 -0800522static void mxt_input_report(struct mxt_data *data, int single_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700523{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800524 struct mxt_finger *finger = data->finger;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700525 struct input_dev *input_dev = data->input_dev;
526 int status = finger[single_id].status;
527 int finger_num = 0;
528 int id;
529
Iiro Valkonen7686b102011-02-02 23:21:58 -0800530 for (id = 0; id < MXT_MAX_FINGER; id++) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700531 if (!finger[id].status)
532 continue;
533
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700534 input_mt_slot(input_dev, id);
535 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
536 finger[id].status != MXT_RELEASE);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700537
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700538 if (finger[id].status != MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700539 finger_num++;
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700540 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
541 finger[id].area);
542 input_report_abs(input_dev, ABS_MT_POSITION_X,
543 finger[id].x);
544 input_report_abs(input_dev, ABS_MT_POSITION_Y,
545 finger[id].y);
Yufeng Shen28ac2932011-08-16 00:40:54 -0700546 input_report_abs(input_dev, ABS_MT_PRESSURE,
547 finger[id].pressure);
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700548 } else {
549 finger[id].status = 0;
550 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700551 }
552
553 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
554
Iiro Valkonen7686b102011-02-02 23:21:58 -0800555 if (status != MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700556 input_report_abs(input_dev, ABS_X, finger[single_id].x);
557 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
Yufeng Shen28ac2932011-08-16 00:40:54 -0700558 input_report_abs(input_dev,
559 ABS_PRESSURE, finger[single_id].pressure);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700560 }
561
562 input_sync(input_dev);
563}
564
Iiro Valkonen7686b102011-02-02 23:21:58 -0800565static void mxt_input_touchevent(struct mxt_data *data,
566 struct mxt_message *message, int id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700567{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800568 struct mxt_finger *finger = data->finger;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700569 struct device *dev = &data->client->dev;
570 u8 status = message->message[0];
571 int x;
572 int y;
573 int area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700574 int pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700575
576 /* Check the touch is present on the screen */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800577 if (!(status & MXT_DETECT)) {
578 if (status & MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700579 dev_dbg(dev, "[%d] released\n", id);
580
Iiro Valkonen7686b102011-02-02 23:21:58 -0800581 finger[id].status = MXT_RELEASE;
582 mxt_input_report(data, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700583 }
584 return;
585 }
586
587 /* Check only AMP detection */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800588 if (!(status & (MXT_PRESS | MXT_MOVE)))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700589 return;
590
Joonyoung Shim910d8052011-04-12 23:14:38 -0700591 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
592 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
593 if (data->max_x < 1024)
594 x = x >> 2;
595 if (data->max_y < 1024)
596 y = y >> 2;
597
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700598 area = message->message[4];
Yufeng Shen28ac2932011-08-16 00:40:54 -0700599 pressure = message->message[5];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700600
601 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800602 status & MXT_MOVE ? "moved" : "pressed",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700603 x, y, area);
604
Iiro Valkonen7686b102011-02-02 23:21:58 -0800605 finger[id].status = status & MXT_MOVE ?
606 MXT_MOVE : MXT_PRESS;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700607 finger[id].x = x;
608 finger[id].y = y;
609 finger[id].area = area;
Yufeng Shen28ac2932011-08-16 00:40:54 -0700610 finger[id].pressure = pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700611
Iiro Valkonen7686b102011-02-02 23:21:58 -0800612 mxt_input_report(data, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700613}
614
Iiro Valkonen7686b102011-02-02 23:21:58 -0800615static irqreturn_t mxt_interrupt(int irq, void *dev_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700616{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800617 struct mxt_data *data = dev_id;
618 struct mxt_message message;
619 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700620 struct device *dev = &data->client->dev;
621 int id;
622 u8 reportid;
623 u8 max_reportid;
624 u8 min_reportid;
625
626 do {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800627 if (mxt_read_message(data, &message)) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700628 dev_err(dev, "Failed to read message\n");
629 goto end;
630 }
631
632 reportid = message.reportid;
633
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700634 /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */
635 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700636 if (!object)
637 goto end;
638
639 max_reportid = object->max_reportid;
640 min_reportid = max_reportid - object->num_report_ids + 1;
641 id = reportid - min_reportid;
642
643 if (reportid >= min_reportid && reportid <= max_reportid)
Iiro Valkonen7686b102011-02-02 23:21:58 -0800644 mxt_input_touchevent(data, &message, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700645 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800646 mxt_dump_message(dev, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700647 } while (reportid != 0xff);
648
649end:
650 return IRQ_HANDLED;
651}
652
Iiro Valkonen7686b102011-02-02 23:21:58 -0800653static int mxt_check_reg_init(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700654{
Iiro Valkonen71749f52011-02-15 13:36:52 -0800655 const struct mxt_platform_data *pdata = data->pdata;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800656 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700657 struct device *dev = &data->client->dev;
658 int index = 0;
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800659 int i, size;
660 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700661
Iiro Valkonen71749f52011-02-15 13:36:52 -0800662 if (!pdata->config) {
663 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
664 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700665 }
666
667 for (i = 0; i < data->info.object_num; i++) {
668 object = data->object_table + i;
669
Iiro Valkonen7686b102011-02-02 23:21:58 -0800670 if (!mxt_object_writable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700671 continue;
672
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800673 size = (object->size + 1) * (object->instances + 1);
674 if (index + size > pdata->config_length) {
675 dev_err(dev, "Not enough config data!\n");
676 return -EINVAL;
Iiro Valkonen71749f52011-02-15 13:36:52 -0800677 }
Daniel Kurtzcf94bc02012-06-28 21:08:13 +0800678
679 ret = __mxt_write_reg(data->client, object->start_address,
680 size, &pdata->config[index]);
681 if (ret)
682 return ret;
683 index += size;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700684 }
685
686 return 0;
687}
688
Iiro Valkonen7686b102011-02-02 23:21:58 -0800689static int mxt_make_highchg(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700690{
691 struct device *dev = &data->client->dev;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800692 struct mxt_message message;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700693 int count = 10;
694 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700695
696 /* Read dummy message to make high CHG pin */
697 do {
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800698 error = mxt_read_message(data, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700699 if (error)
700 return error;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800701 } while (message.reportid != 0xff && --count);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700702
703 if (!count) {
704 dev_err(dev, "CHG pin isn't cleared\n");
705 return -EBUSY;
706 }
707
708 return 0;
709}
710
Iiro Valkonen7686b102011-02-02 23:21:58 -0800711static void mxt_handle_pdata(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700712{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800713 const struct mxt_platform_data *pdata = data->pdata;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700714 u8 voltage;
715
716 /* Set touchscreen lines */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700717 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_XSIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700718 pdata->x_line);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700719 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_YSIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700720 pdata->y_line);
721
722 /* Set touchscreen orient */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700723 mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_ORIENT,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700724 pdata->orient);
725
726 /* Set touchscreen burst length */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700727 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800728 MXT_TOUCH_BLEN, pdata->blen);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700729
730 /* Set touchscreen threshold */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700731 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800732 MXT_TOUCH_TCHTHR, pdata->threshold);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700733
734 /* Set touchscreen resolution */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700735 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800736 MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700737 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800738 MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700739 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800740 MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff);
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700741 mxt_write_object(data, MXT_TOUCH_MULTI_T9,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800742 MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700743
744 /* Set touchscreen voltage */
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700745 if (pdata->voltage) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800746 if (pdata->voltage < MXT_VOLTAGE_DEFAULT) {
747 voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) /
748 MXT_VOLTAGE_STEP;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700749 voltage = 0xff - voltage + 1;
750 } else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800751 voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) /
752 MXT_VOLTAGE_STEP;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700753
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700754 mxt_write_object(data, MXT_SPT_CTECONFIG_T28,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800755 MXT_CTE_VOLTAGE, voltage);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700756 }
757}
758
Iiro Valkonen7686b102011-02-02 23:21:58 -0800759static int mxt_get_info(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700760{
761 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800762 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700763 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700764
Daniel Kurtz23003a842012-06-28 21:08:14 +0800765 /* Read 7-byte info block starting at address 0 */
766 error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700767 if (error)
768 return error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700769
770 return 0;
771}
772
Iiro Valkonen7686b102011-02-02 23:21:58 -0800773static int mxt_get_object_table(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700774{
775 int error;
776 int i;
777 u16 reg;
778 u8 reportid = 0;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800779 u8 buf[MXT_OBJECT_SIZE];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700780
781 for (i = 0; i < data->info.object_num; i++) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800782 struct mxt_object *object = data->object_table + i;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700783
Iiro Valkonen7686b102011-02-02 23:21:58 -0800784 reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i;
785 error = mxt_read_object_table(data->client, reg, buf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700786 if (error)
787 return error;
788
789 object->type = buf[0];
790 object->start_address = (buf[2] << 8) | buf[1];
791 object->size = buf[3];
792 object->instances = buf[4];
793 object->num_report_ids = buf[5];
794
795 if (object->num_report_ids) {
796 reportid += object->num_report_ids *
797 (object->instances + 1);
798 object->max_reportid = reportid;
799 }
800 }
801
802 return 0;
803}
804
Iiro Valkonen7686b102011-02-02 23:21:58 -0800805static int mxt_initialize(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700806{
807 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800808 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700809 int error;
810 u8 val;
811
Iiro Valkonen7686b102011-02-02 23:21:58 -0800812 error = mxt_get_info(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700813 if (error)
814 return error;
815
816 data->object_table = kcalloc(info->object_num,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800817 sizeof(struct mxt_object),
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700818 GFP_KERNEL);
819 if (!data->object_table) {
820 dev_err(&client->dev, "Failed to allocate memory\n");
821 return -ENOMEM;
822 }
823
824 /* Get object table information */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800825 error = mxt_get_object_table(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700826 if (error)
827 return error;
828
829 /* Check register init values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800830 error = mxt_check_reg_init(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700831 if (error)
832 return error;
833
Iiro Valkonen7686b102011-02-02 23:21:58 -0800834 mxt_handle_pdata(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700835
836 /* Backup to memory */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700837 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800838 MXT_COMMAND_BACKUPNV,
839 MXT_BACKUP_VALUE);
840 msleep(MXT_BACKUP_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700841
842 /* Soft reset */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700843 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800844 MXT_COMMAND_RESET, 1);
845 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700846
847 /* Update matrix size at info struct */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800848 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700849 if (error)
850 return error;
851 info->matrix_xsize = val;
852
Iiro Valkonen7686b102011-02-02 23:21:58 -0800853 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700854 if (error)
855 return error;
856 info->matrix_ysize = val;
857
858 dev_info(&client->dev,
859 "Family ID: %d Variant ID: %d Version: %d Build: %d\n",
860 info->family_id, info->variant_id, info->version,
861 info->build);
862
863 dev_info(&client->dev,
864 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n",
865 info->matrix_xsize, info->matrix_ysize,
866 info->object_num);
867
868 return 0;
869}
870
Joonyoung Shim910d8052011-04-12 23:14:38 -0700871static void mxt_calc_resolution(struct mxt_data *data)
872{
873 unsigned int max_x = data->pdata->x_size - 1;
874 unsigned int max_y = data->pdata->y_size - 1;
875
876 if (data->pdata->orient & MXT_XY_SWITCH) {
877 data->max_x = max_y;
878 data->max_y = max_x;
879 } else {
880 data->max_x = max_x;
881 data->max_y = max_y;
882 }
883}
884
Daniel Kurtz794eb672012-06-28 21:08:10 +0800885static ssize_t mxt_show_instance(char *buf, int count,
886 struct mxt_object *object, int instance,
887 const u8 *val)
888{
889 int i;
890
891 if (object->instances > 0)
892 count += scnprintf(buf + count, PAGE_SIZE - count,
893 "Instance %u\n", instance);
894
895 for (i = 0; i < object->size + 1; i++)
896 count += scnprintf(buf + count, PAGE_SIZE - count,
897 "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
898 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
899
900 return count;
901}
902
Iiro Valkonen7686b102011-02-02 23:21:58 -0800903static ssize_t mxt_object_show(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700904 struct device_attribute *attr, char *buf)
905{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800906 struct mxt_data *data = dev_get_drvdata(dev);
907 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700908 int count = 0;
909 int i, j;
910 int error;
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800911 u8 *obuf;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700912
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800913 /* Pre-allocate buffer large enough to hold max sized object. */
914 obuf = kmalloc(256, GFP_KERNEL);
915 if (!obuf)
916 return -ENOMEM;
917
918 error = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700919 for (i = 0; i < data->info.object_num; i++) {
920 object = data->object_table + i;
921
Daniel Kurtz91630952012-06-28 21:08:09 +0800922 if (!mxt_object_readable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700923 continue;
Daniel Kurtz91630952012-06-28 21:08:09 +0800924
925 count += scnprintf(buf + count, PAGE_SIZE - count,
926 "T%u:\n", object->type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700927
Daniel Kurtz794eb672012-06-28 21:08:10 +0800928 for (j = 0; j < object->instances + 1; j++) {
929 u16 size = object->size + 1;
930 u16 addr = object->start_address + j * size;
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800931
Daniel Kurtz794eb672012-06-28 21:08:10 +0800932 error = __mxt_read_reg(data->client, addr, size, obuf);
933 if (error)
934 goto done;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700935
Daniel Kurtz794eb672012-06-28 21:08:10 +0800936 count = mxt_show_instance(buf, count, object, j, obuf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700937 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700938 }
939
Daniel Kurtz794eb672012-06-28 21:08:10 +0800940done:
Daniel Kurtz43a91d52012-06-28 21:08:08 +0800941 kfree(obuf);
942 return error ?: count;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700943}
944
Iiro Valkonen7686b102011-02-02 23:21:58 -0800945static int mxt_load_fw(struct device *dev, const char *fn)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700946{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800947 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700948 struct i2c_client *client = data->client;
949 const struct firmware *fw = NULL;
950 unsigned int frame_size;
951 unsigned int pos = 0;
952 int ret;
953
954 ret = request_firmware(&fw, fn, dev);
955 if (ret) {
956 dev_err(dev, "Unable to open firmware %s\n", fn);
957 return ret;
958 }
959
960 /* Change to the bootloader mode */
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700961 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800962 MXT_COMMAND_RESET, MXT_BOOT_VALUE);
963 msleep(MXT_RESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700964
965 /* Change to slave address of bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800966 if (client->addr == MXT_APP_LOW)
967 client->addr = MXT_BOOT_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700968 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800969 client->addr = MXT_BOOT_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700970
Iiro Valkonen7686b102011-02-02 23:21:58 -0800971 ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700972 if (ret)
973 goto out;
974
975 /* Unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800976 mxt_unlock_bootloader(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700977
978 while (pos < fw->size) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800979 ret = mxt_check_bootloader(client,
980 MXT_WAITING_FRAME_DATA);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700981 if (ret)
982 goto out;
983
984 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
985
986 /* We should add 2 at frame size as the the firmware data is not
987 * included the CRC bytes.
988 */
989 frame_size += 2;
990
991 /* Write one frame to device */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800992 mxt_fw_write(client, fw->data + pos, frame_size);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700993
Iiro Valkonen7686b102011-02-02 23:21:58 -0800994 ret = mxt_check_bootloader(client,
995 MXT_FRAME_CRC_PASS);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700996 if (ret)
997 goto out;
998
999 pos += frame_size;
1000
1001 dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size);
1002 }
1003
1004out:
1005 release_firmware(fw);
1006
1007 /* Change to slave address of application */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001008 if (client->addr == MXT_BOOT_LOW)
1009 client->addr = MXT_APP_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001010 else
Iiro Valkonen7686b102011-02-02 23:21:58 -08001011 client->addr = MXT_APP_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001012
1013 return ret;
1014}
1015
Iiro Valkonen7686b102011-02-02 23:21:58 -08001016static ssize_t mxt_update_fw_store(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001017 struct device_attribute *attr,
1018 const char *buf, size_t count)
1019{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001020 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001021 int error;
1022
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001023 disable_irq(data->irq);
1024
Iiro Valkonen7686b102011-02-02 23:21:58 -08001025 error = mxt_load_fw(dev, MXT_FW_NAME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001026 if (error) {
1027 dev_err(dev, "The firmware update failed(%d)\n", error);
1028 count = error;
1029 } else {
1030 dev_dbg(dev, "The firmware update succeeded\n");
1031
1032 /* Wait for reset */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001033 msleep(MXT_FWRESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001034
1035 kfree(data->object_table);
1036 data->object_table = NULL;
1037
Iiro Valkonen7686b102011-02-02 23:21:58 -08001038 mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001039 }
1040
1041 enable_irq(data->irq);
1042
Iiro Valkonen08960a02011-04-12 23:16:40 -07001043 error = mxt_make_highchg(data);
1044 if (error)
1045 return error;
1046
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001047 return count;
1048}
1049
Daniel Kurtz71b3e932012-05-08 22:30:14 -07001050static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
1051static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001052
Iiro Valkonen7686b102011-02-02 23:21:58 -08001053static struct attribute *mxt_attrs[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001054 &dev_attr_object.attr,
1055 &dev_attr_update_fw.attr,
1056 NULL
1057};
1058
Iiro Valkonen7686b102011-02-02 23:21:58 -08001059static const struct attribute_group mxt_attr_group = {
1060 .attrs = mxt_attrs,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001061};
1062
Iiro Valkonen7686b102011-02-02 23:21:58 -08001063static void mxt_start(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001064{
1065 /* Touch enable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001066 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001067 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001068}
1069
Iiro Valkonen7686b102011-02-02 23:21:58 -08001070static void mxt_stop(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001071{
1072 /* Touch disable */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001073 mxt_write_object(data,
Iiro Valkonen81c88a72011-07-04 03:08:25 -07001074 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001075}
1076
Iiro Valkonen7686b102011-02-02 23:21:58 -08001077static int mxt_input_open(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001078{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001079 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001080
Iiro Valkonen7686b102011-02-02 23:21:58 -08001081 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001082
1083 return 0;
1084}
1085
Iiro Valkonen7686b102011-02-02 23:21:58 -08001086static void mxt_input_close(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001087{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001088 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001089
Iiro Valkonen7686b102011-02-02 23:21:58 -08001090 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001091}
1092
Iiro Valkonen7686b102011-02-02 23:21:58 -08001093static int __devinit mxt_probe(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001094 const struct i2c_device_id *id)
1095{
Iiro Valkonen919ed892011-02-15 13:36:52 -08001096 const struct mxt_platform_data *pdata = client->dev.platform_data;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001097 struct mxt_data *data;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001098 struct input_dev *input_dev;
1099 int error;
1100
Iiro Valkonen919ed892011-02-15 13:36:52 -08001101 if (!pdata)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001102 return -EINVAL;
1103
Iiro Valkonen7686b102011-02-02 23:21:58 -08001104 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001105 input_dev = input_allocate_device();
1106 if (!data || !input_dev) {
1107 dev_err(&client->dev, "Failed to allocate memory\n");
1108 error = -ENOMEM;
1109 goto err_free_mem;
1110 }
1111
Iiro Valkonen7686b102011-02-02 23:21:58 -08001112 input_dev->name = "Atmel maXTouch Touchscreen";
Daniel Kurtzec02ac22012-06-28 21:08:02 +08001113 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1114 client->adapter->nr, client->addr);
1115 input_dev->phys = data->phys;
1116
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001117 input_dev->id.bustype = BUS_I2C;
1118 input_dev->dev.parent = &client->dev;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001119 input_dev->open = mxt_input_open;
1120 input_dev->close = mxt_input_close;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001121
Joonyoung Shim910d8052011-04-12 23:14:38 -07001122 data->client = client;
1123 data->input_dev = input_dev;
1124 data->pdata = pdata;
1125 data->irq = client->irq;
1126
1127 mxt_calc_resolution(data);
1128
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001129 __set_bit(EV_ABS, input_dev->evbit);
1130 __set_bit(EV_KEY, input_dev->evbit);
1131 __set_bit(BTN_TOUCH, input_dev->keybit);
1132
1133 /* For single touch */
1134 input_set_abs_params(input_dev, ABS_X,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001135 0, data->max_x, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001136 input_set_abs_params(input_dev, ABS_Y,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001137 0, data->max_y, 0, 0);
Yufeng Shen28ac2932011-08-16 00:40:54 -07001138 input_set_abs_params(input_dev, ABS_PRESSURE,
1139 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001140
1141 /* For multi touch */
Daniel Kurtze1e16582012-06-28 21:08:04 +08001142 error = input_mt_init_slots(input_dev, MXT_MAX_FINGER);
1143 if (error)
1144 goto err_free_mem;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001145 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001146 0, MXT_MAX_AREA, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001147 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001148 0, data->max_x, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001149 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
Joonyoung Shim910d8052011-04-12 23:14:38 -07001150 0, data->max_y, 0, 0);
Yufeng Shen28ac2932011-08-16 00:40:54 -07001151 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
1152 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001153
1154 input_set_drvdata(input_dev, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001155 i2c_set_clientdata(client, data);
1156
Iiro Valkonen7686b102011-02-02 23:21:58 -08001157 error = mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001158 if (error)
1159 goto err_free_object;
1160
Iiro Valkonen7686b102011-02-02 23:21:58 -08001161 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
Daniel Kurtzc2ef9a12012-06-28 21:08:03 +08001162 pdata->irqflags, client->name, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001163 if (error) {
1164 dev_err(&client->dev, "Failed to register interrupt\n");
1165 goto err_free_object;
1166 }
1167
Iiro Valkonen08960a02011-04-12 23:16:40 -07001168 error = mxt_make_highchg(data);
1169 if (error)
1170 goto err_free_irq;
1171
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001172 error = input_register_device(input_dev);
1173 if (error)
1174 goto err_free_irq;
1175
Iiro Valkonen7686b102011-02-02 23:21:58 -08001176 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001177 if (error)
Daniel Kurtz63990032012-06-28 21:08:05 +08001178 dev_warn(&client->dev, "error creating sysfs entries.\n");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001179
1180 return 0;
1181
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001182err_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");