blob: 26af3fe7b5f5aae09150c4f6d72672dbc08c3bf5 [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>
Jing Lin2f863172011-10-17 10:56:58 -07006 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07007 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/firmware.h>
19#include <linux/i2c.h>
Dmitry Torokhov964de522011-02-02 23:21:58 -080020#include <linux/i2c/atmel_mxt_ts.h>
Amy Maloche2b59bab2011-10-13 16:08:16 -070021#include <linux/input.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070022#include <linux/interrupt.h>
23#include <linux/slab.h>
Anirudh Ghayala498e4d2011-08-09 19:10:12 +053024#include <linux/regulator/consumer.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070025
Anirudh Ghayal253ce122011-08-09 19:32:57 +053026#if defined(CONFIG_HAS_EARLYSUSPEND)
27#include <linux/earlysuspend.h>
28/* Early-suspend level */
29#define MXT_SUSPEND_LEVEL 1
30#endif
31
Iiro Valkonen4ac053c2011-09-08 11:10:52 -070032/* Family ID */
33#define MXT224_ID 0x80
34#define MXT1386_ID 0xA0
35
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070036/* Version */
Iiro Valkonen7686b102011-02-02 23:21:58 -080037#define MXT_VER_20 20
38#define MXT_VER_21 21
39#define MXT_VER_22 22
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070040
41/* Slave addresses */
Iiro Valkonen7686b102011-02-02 23:21:58 -080042#define MXT_APP_LOW 0x4a
43#define MXT_APP_HIGH 0x4b
44#define MXT_BOOT_LOW 0x24
45#define MXT_BOOT_HIGH 0x25
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070046
47/* Firmware */
Iiro Valkonen7686b102011-02-02 23:21:58 -080048#define MXT_FW_NAME "maxtouch.fw"
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070049
50/* Registers */
Iiro Valkonen7686b102011-02-02 23:21:58 -080051#define MXT_FAMILY_ID 0x00
52#define MXT_VARIANT_ID 0x01
53#define MXT_VERSION 0x02
54#define MXT_BUILD 0x03
55#define MXT_MATRIX_X_SIZE 0x04
56#define MXT_MATRIX_Y_SIZE 0x05
57#define MXT_OBJECT_NUM 0x06
58#define MXT_OBJECT_START 0x07
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070059
Iiro Valkonen7686b102011-02-02 23:21:58 -080060#define MXT_OBJECT_SIZE 6
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070061
62/* Object types */
Iiro Valkonene8645592011-11-18 12:56:19 -080063#define MXT_DEBUG_DIAGNOSTIC_T37 37
64#define MXT_GEN_MESSAGE_T5 5
65#define MXT_GEN_COMMAND_T6 6
66#define MXT_GEN_POWER_T7 7
67#define MXT_GEN_ACQUIRE_T8 8
68#define MXT_GEN_DATASOURCE_T53 53
69#define MXT_TOUCH_MULTI_T9 9
70#define MXT_TOUCH_KEYARRAY_T15 15
71#define MXT_TOUCH_PROXIMITY_T23 23
72#define MXT_TOUCH_PROXKEY_T52 52
73#define MXT_PROCI_GRIPFACE_T20 20
74#define MXT_PROCG_NOISE_T22 22
75#define MXT_PROCI_ONETOUCH_T24 24
76#define MXT_PROCI_TWOTOUCH_T27 27
77#define MXT_PROCI_GRIP_T40 40
78#define MXT_PROCI_PALM_T41 41
79#define MXT_PROCI_TOUCHSUPPRESSION_T42 42
80#define MXT_PROCI_STYLUS_T47 47
81#define MXT_PROCG_NOISESUPPRESSION_T48 48
82#define MXT_SPT_COMMSCONFIG_T18 18
83#define MXT_SPT_GPIOPWM_T19 19
84#define MXT_SPT_SELFTEST_T25 25
85#define MXT_SPT_CTECONFIG_T28 28
86#define MXT_SPT_USERDATA_T38 38
87#define MXT_SPT_DIGITIZER_T43 43
88#define MXT_SPT_MESSAGECOUNT_T44 44
89#define MXT_SPT_CTECONFIG_T46 46
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070090
Iiro Valkonene8645592011-11-18 12:56:19 -080091/* MXT_GEN_COMMAND_T6 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080092#define MXT_COMMAND_RESET 0
93#define MXT_COMMAND_BACKUPNV 1
94#define MXT_COMMAND_CALIBRATE 2
95#define MXT_COMMAND_REPORTALL 3
96#define MXT_COMMAND_DIAGNOSTIC 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070097
Iiro Valkonene8645592011-11-18 12:56:19 -080098/* MXT_GEN_POWER_T7 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080099#define MXT_POWER_IDLEACQINT 0
100#define MXT_POWER_ACTVACQINT 1
101#define MXT_POWER_ACTV2IDLETO 2
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700102
Iiro Valkonene8645592011-11-18 12:56:19 -0800103/* MXT_GEN_ACQUIRE_T8 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800104#define MXT_ACQUIRE_CHRGTIME 0
105#define MXT_ACQUIRE_TCHDRIFT 2
106#define MXT_ACQUIRE_DRIFTST 3
107#define MXT_ACQUIRE_TCHAUTOCAL 4
108#define MXT_ACQUIRE_SYNC 5
109#define MXT_ACQUIRE_ATCHCALST 6
110#define MXT_ACQUIRE_ATCHCALSTHR 7
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700111
Iiro Valkonene8645592011-11-18 12:56:19 -0800112/* MXT_TOUCH_MULT_T9 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800113#define MXT_TOUCH_CTRL 0
114#define MXT_TOUCH_XORIGIN 1
115#define MXT_TOUCH_YORIGIN 2
116#define MXT_TOUCH_XSIZE 3
117#define MXT_TOUCH_YSIZE 4
118#define MXT_TOUCH_BLEN 6
119#define MXT_TOUCH_TCHTHR 7
120#define MXT_TOUCH_TCHDI 8
121#define MXT_TOUCH_ORIENT 9
122#define MXT_TOUCH_MOVHYSTI 11
123#define MXT_TOUCH_MOVHYSTN 12
124#define MXT_TOUCH_NUMTOUCH 14
125#define MXT_TOUCH_MRGHYST 15
126#define MXT_TOUCH_MRGTHR 16
127#define MXT_TOUCH_AMPHYST 17
128#define MXT_TOUCH_XRANGE_LSB 18
129#define MXT_TOUCH_XRANGE_MSB 19
130#define MXT_TOUCH_YRANGE_LSB 20
131#define MXT_TOUCH_YRANGE_MSB 21
132#define MXT_TOUCH_XLOCLIP 22
133#define MXT_TOUCH_XHICLIP 23
134#define MXT_TOUCH_YLOCLIP 24
135#define MXT_TOUCH_YHICLIP 25
136#define MXT_TOUCH_XEDGECTRL 26
137#define MXT_TOUCH_XEDGEDIST 27
138#define MXT_TOUCH_YEDGECTRL 28
139#define MXT_TOUCH_YEDGEDIST 29
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700140#define MXT_TOUCH_JUMPLIMIT 30
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700141
Iiro Valkonene8645592011-11-18 12:56:19 -0800142/* MXT_PROCI_GRIPFACE_T20 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800143#define MXT_GRIPFACE_CTRL 0
144#define MXT_GRIPFACE_XLOGRIP 1
145#define MXT_GRIPFACE_XHIGRIP 2
146#define MXT_GRIPFACE_YLOGRIP 3
147#define MXT_GRIPFACE_YHIGRIP 4
148#define MXT_GRIPFACE_MAXTCHS 5
149#define MXT_GRIPFACE_SZTHR1 7
150#define MXT_GRIPFACE_SZTHR2 8
151#define MXT_GRIPFACE_SHPTHR1 9
152#define MXT_GRIPFACE_SHPTHR2 10
153#define MXT_GRIPFACE_SUPEXTTO 11
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700154
Iiro Valkonen7686b102011-02-02 23:21:58 -0800155/* MXT_PROCI_NOISE field */
156#define MXT_NOISE_CTRL 0
157#define MXT_NOISE_OUTFLEN 1
158#define MXT_NOISE_GCAFUL_LSB 3
159#define MXT_NOISE_GCAFUL_MSB 4
160#define MXT_NOISE_GCAFLL_LSB 5
161#define MXT_NOISE_GCAFLL_MSB 6
162#define MXT_NOISE_ACTVGCAFVALID 7
163#define MXT_NOISE_NOISETHR 8
164#define MXT_NOISE_FREQHOPSCALE 10
165#define MXT_NOISE_FREQ0 11
166#define MXT_NOISE_FREQ1 12
167#define MXT_NOISE_FREQ2 13
168#define MXT_NOISE_FREQ3 14
169#define MXT_NOISE_FREQ4 15
170#define MXT_NOISE_IDLEGCAFVALID 16
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700171
Iiro Valkonene8645592011-11-18 12:56:19 -0800172/* MXT_SPT_COMMSCONFIG_T18 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800173#define MXT_COMMS_CTRL 0
174#define MXT_COMMS_CMD 1
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700175
Iiro Valkonene8645592011-11-18 12:56:19 -0800176/* MXT_SPT_CTECONFIG_T28 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800177#define MXT_CTE_CTRL 0
178#define MXT_CTE_CMD 1
179#define MXT_CTE_MODE 2
180#define MXT_CTE_IDLEGCAFDEPTH 3
181#define MXT_CTE_ACTVGCAFDEPTH 4
Joonyoung Shim979a72d2011-03-14 21:41:34 -0700182#define MXT_CTE_VOLTAGE 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700183
Iiro Valkonen7686b102011-02-02 23:21:58 -0800184#define MXT_VOLTAGE_DEFAULT 2700000
185#define MXT_VOLTAGE_STEP 10000
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700186
Amy Maloche21115eb2011-11-02 09:04:37 -0700187/* Analog voltage @2.7 V */
Anirudh Ghayala498e4d2011-08-09 19:10:12 +0530188#define MXT_VTG_MIN_UV 2700000
189#define MXT_VTG_MAX_UV 3300000
190#define MXT_ACTIVE_LOAD_UA 15000
Jing Linbace50b2011-10-18 22:55:47 -0700191#define MXT_LPM_LOAD_UA 10
Amy Maloche21115eb2011-11-02 09:04:37 -0700192/* Digital voltage @1.8 V */
193#define MXT_VTG_DIG_MIN_UV 1800000
194#define MXT_VTG_DIG_MAX_UV 1800000
195#define MXT_ACTIVE_LOAD_DIG_UA 10000
196#define MXT_LPM_LOAD_DIG_UA 10
Anirudh Ghayala498e4d2011-08-09 19:10:12 +0530197
198#define MXT_I2C_VTG_MIN_UV 1800000
199#define MXT_I2C_VTG_MAX_UV 1800000
200#define MXT_I2C_LOAD_UA 10000
Jing Linbace50b2011-10-18 22:55:47 -0700201#define MXT_I2C_LPM_LOAD_UA 10
Anirudh Ghayala498e4d2011-08-09 19:10:12 +0530202
Iiro Valkonene8645592011-11-18 12:56:19 -0800203/* Define for MXT_GEN_COMMAND_T6 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800204#define MXT_BOOT_VALUE 0xa5
205#define MXT_BACKUP_VALUE 0x55
206#define MXT_BACKUP_TIME 25 /* msec */
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700207#define MXT224_RESET_TIME 65 /* msec */
Amy Maloche7e447432011-09-14 11:36:30 -0700208#define MXT1386_RESET_TIME 250 /* msec */
209#define MXT_RESET_TIME 250 /* msec */
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700210#define MXT_RESET_NOCHGREAD 400 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700211
Iiro Valkonen7686b102011-02-02 23:21:58 -0800212#define MXT_FWRESET_TIME 175 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700213
Jing Lin36aee812011-10-17 17:17:28 -0700214#define MXT_WAKE_TIME 25
215
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700216/* Command to unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800217#define MXT_UNLOCK_CMD_MSB 0xaa
218#define MXT_UNLOCK_CMD_LSB 0xdc
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700219
220/* Bootloader mode status */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800221#define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
222#define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
223#define MXT_FRAME_CRC_CHECK 0x02
224#define MXT_FRAME_CRC_FAIL 0x03
225#define MXT_FRAME_CRC_PASS 0x04
226#define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
227#define MXT_BOOT_STATUS_MASK 0x3f
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700228
229/* Touch status */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800230#define MXT_SUPPRESS (1 << 1)
231#define MXT_AMP (1 << 2)
232#define MXT_VECTOR (1 << 3)
233#define MXT_MOVE (1 << 4)
234#define MXT_RELEASE (1 << 5)
235#define MXT_PRESS (1 << 6)
236#define MXT_DETECT (1 << 7)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700237
Joonyoung Shim910d8052011-04-12 23:14:38 -0700238/* Touch orient bits */
239#define MXT_XY_SWITCH (1 << 0)
240#define MXT_X_INVERT (1 << 1)
241#define MXT_Y_INVERT (1 << 2)
242
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700243/* Touchscreen absolute values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800244#define MXT_MAX_AREA 0xff
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700245
Iiro Valkonen7686b102011-02-02 23:21:58 -0800246#define MXT_MAX_FINGER 10
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700247
Jing Lin36aee812011-10-17 17:17:28 -0700248#define T7_DATA_SIZE 3
249#define MXT_MAX_RW_TRIES 3
250#define MXT_BLOCK_SIZE 256
Mohan Pallakaab51f2b2011-09-29 18:17:35 +0530251
Iiro Valkonen7686b102011-02-02 23:21:58 -0800252struct mxt_info {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700253 u8 family_id;
254 u8 variant_id;
255 u8 version;
256 u8 build;
257 u8 matrix_xsize;
258 u8 matrix_ysize;
259 u8 object_num;
260};
261
Iiro Valkonen7686b102011-02-02 23:21:58 -0800262struct mxt_object {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700263 u8 type;
264 u16 start_address;
265 u8 size;
266 u8 instances;
267 u8 num_report_ids;
268
269 /* to map object and message */
270 u8 max_reportid;
271};
272
Iiro Valkonen7686b102011-02-02 23:21:58 -0800273struct mxt_message {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700274 u8 reportid;
275 u8 message[7];
276 u8 checksum;
277};
278
Iiro Valkonen7686b102011-02-02 23:21:58 -0800279struct mxt_finger {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700280 int status;
281 int x;
282 int y;
283 int area;
Yufeng Shene6eb36a2011-10-11 12:28:21 -0700284 int pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700285};
286
287/* Each client has this additional data */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800288struct mxt_data {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700289 struct i2c_client *client;
290 struct input_dev *input_dev;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800291 const struct mxt_platform_data *pdata;
292 struct mxt_object *object_table;
293 struct mxt_info info;
294 struct mxt_finger finger[MXT_MAX_FINGER];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700295 unsigned int irq;
Amy Maloche21115eb2011-11-02 09:04:37 -0700296 struct regulator *vcc_ana;
297 struct regulator *vcc_dig;
Anirudh Ghayala498e4d2011-08-09 19:10:12 +0530298 struct regulator *vcc_i2c;
Anirudh Ghayal253ce122011-08-09 19:32:57 +0530299#if defined(CONFIG_HAS_EARLYSUSPEND)
300 struct early_suspend early_suspend;
301#endif
Jing Lin36aee812011-10-17 17:17:28 -0700302
Amy Maloche52262212011-09-15 16:46:57 -0700303 u8 t7_data[T7_DATA_SIZE];
Jing Lin36aee812011-10-17 17:17:28 -0700304 u16 t7_start_addr;
Amy Maloche52262212011-09-15 16:46:57 -0700305 u8 t9_ctrl;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700306};
307
Iiro Valkonen7686b102011-02-02 23:21:58 -0800308static bool mxt_object_readable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700309{
310 switch (type) {
Iiro Valkonene8645592011-11-18 12:56:19 -0800311 case MXT_GEN_MESSAGE_T5:
312 case MXT_GEN_COMMAND_T6:
313 case MXT_GEN_POWER_T7:
314 case MXT_GEN_ACQUIRE_T8:
315 case MXT_GEN_DATASOURCE_T53:
316 case MXT_TOUCH_MULTI_T9:
317 case MXT_TOUCH_KEYARRAY_T15:
318 case MXT_TOUCH_PROXIMITY_T23:
319 case MXT_TOUCH_PROXKEY_T52:
320 case MXT_PROCI_GRIPFACE_T20:
321 case MXT_PROCG_NOISE_T22:
322 case MXT_PROCI_ONETOUCH_T24:
323 case MXT_PROCI_TWOTOUCH_T27:
324 case MXT_PROCI_GRIP_T40:
325 case MXT_PROCI_PALM_T41:
326 case MXT_PROCI_TOUCHSUPPRESSION_T42:
327 case MXT_PROCI_STYLUS_T47:
328 case MXT_PROCG_NOISESUPPRESSION_T48:
329 case MXT_SPT_COMMSCONFIG_T18:
330 case MXT_SPT_GPIOPWM_T19:
331 case MXT_SPT_SELFTEST_T25:
332 case MXT_SPT_CTECONFIG_T28:
333 case MXT_SPT_USERDATA_T38:
334 case MXT_SPT_DIGITIZER_T43:
335 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700336 return true;
337 default:
338 return false;
339 }
340}
341
Iiro Valkonen7686b102011-02-02 23:21:58 -0800342static bool mxt_object_writable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700343{
344 switch (type) {
Iiro Valkonene8645592011-11-18 12:56:19 -0800345 case MXT_GEN_COMMAND_T6:
346 case MXT_GEN_POWER_T7:
347 case MXT_GEN_ACQUIRE_T8:
348 case MXT_TOUCH_MULTI_T9:
349 case MXT_TOUCH_KEYARRAY_T15:
350 case MXT_TOUCH_PROXIMITY_T23:
351 case MXT_TOUCH_PROXKEY_T52:
352 case MXT_PROCI_GRIPFACE_T20:
353 case MXT_PROCG_NOISE_T22:
354 case MXT_PROCI_ONETOUCH_T24:
355 case MXT_PROCI_TWOTOUCH_T27:
356 case MXT_PROCI_GRIP_T40:
357 case MXT_PROCI_PALM_T41:
358 case MXT_PROCI_TOUCHSUPPRESSION_T42:
359 case MXT_PROCI_STYLUS_T47:
360 case MXT_PROCG_NOISESUPPRESSION_T48:
361 case MXT_SPT_COMMSCONFIG_T18:
362 case MXT_SPT_GPIOPWM_T19:
363 case MXT_SPT_SELFTEST_T25:
364 case MXT_SPT_CTECONFIG_T28:
365 case MXT_SPT_USERDATA_T38:
366 case MXT_SPT_DIGITIZER_T43:
367 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700368 return true;
369 default:
370 return false;
371 }
372}
373
Iiro Valkonen7686b102011-02-02 23:21:58 -0800374static void mxt_dump_message(struct device *dev,
375 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700376{
377 dev_dbg(dev, "reportid:\t0x%x\n", message->reportid);
378 dev_dbg(dev, "message1:\t0x%x\n", message->message[0]);
379 dev_dbg(dev, "message2:\t0x%x\n", message->message[1]);
380 dev_dbg(dev, "message3:\t0x%x\n", message->message[2]);
381 dev_dbg(dev, "message4:\t0x%x\n", message->message[3]);
382 dev_dbg(dev, "message5:\t0x%x\n", message->message[4]);
383 dev_dbg(dev, "message6:\t0x%x\n", message->message[5]);
384 dev_dbg(dev, "message7:\t0x%x\n", message->message[6]);
385 dev_dbg(dev, "checksum:\t0x%x\n", message->checksum);
386}
387
Iiro Valkonen7686b102011-02-02 23:21:58 -0800388static int mxt_check_bootloader(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700389 unsigned int state)
390{
391 u8 val;
392
393recheck:
394 if (i2c_master_recv(client, &val, 1) != 1) {
395 dev_err(&client->dev, "%s: i2c recv failed\n", __func__);
396 return -EIO;
397 }
398
399 switch (state) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800400 case MXT_WAITING_BOOTLOAD_CMD:
401 case MXT_WAITING_FRAME_DATA:
402 val &= ~MXT_BOOT_STATUS_MASK;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700403 break;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800404 case MXT_FRAME_CRC_PASS:
405 if (val == MXT_FRAME_CRC_CHECK)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700406 goto recheck;
407 break;
408 default:
409 return -EINVAL;
410 }
411
412 if (val != state) {
413 dev_err(&client->dev, "Unvalid bootloader mode state\n");
414 return -EINVAL;
415 }
416
417 return 0;
418}
419
Iiro Valkonen7686b102011-02-02 23:21:58 -0800420static int mxt_unlock_bootloader(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700421{
422 u8 buf[2];
423
Iiro Valkonen7686b102011-02-02 23:21:58 -0800424 buf[0] = MXT_UNLOCK_CMD_LSB;
425 buf[1] = MXT_UNLOCK_CMD_MSB;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700426
427 if (i2c_master_send(client, buf, 2) != 2) {
428 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
429 return -EIO;
430 }
431
432 return 0;
433}
434
Iiro Valkonen7686b102011-02-02 23:21:58 -0800435static int mxt_fw_write(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700436 const u8 *data, unsigned int frame_size)
437{
438 if (i2c_master_send(client, data, frame_size) != frame_size) {
439 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
440 return -EIO;
441 }
442
443 return 0;
444}
445
Iiro Valkonen7686b102011-02-02 23:21:58 -0800446static int __mxt_read_reg(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700447 u16 reg, u16 len, void *val)
448{
449 struct i2c_msg xfer[2];
450 u8 buf[2];
Jing Lin36aee812011-10-17 17:17:28 -0700451 int i = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700452
453 buf[0] = reg & 0xff;
454 buf[1] = (reg >> 8) & 0xff;
455
456 /* Write register */
457 xfer[0].addr = client->addr;
458 xfer[0].flags = 0;
459 xfer[0].len = 2;
460 xfer[0].buf = buf;
461
462 /* Read data */
463 xfer[1].addr = client->addr;
464 xfer[1].flags = I2C_M_RD;
465 xfer[1].len = len;
466 xfer[1].buf = val;
467
Jing Lin36aee812011-10-17 17:17:28 -0700468 do {
469 if (i2c_transfer(client->adapter, xfer, 2) == 2)
470 return 0;
471 msleep(MXT_WAKE_TIME);
472 } while (++i < MXT_MAX_RW_TRIES);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700473
Jing Lin36aee812011-10-17 17:17:28 -0700474 dev_err(&client->dev, "%s: i2c transfer failed\n", __func__);
475 return -EIO;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700476}
477
Iiro Valkonen7686b102011-02-02 23:21:58 -0800478static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700479{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800480 return __mxt_read_reg(client, reg, 1, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700481}
482
Jing Lin36aee812011-10-17 17:17:28 -0700483static int __mxt_write_reg(struct i2c_client *client,
484 u16 addr, u16 length, u8 *value)
485{
486 u8 buf[MXT_BLOCK_SIZE + 2];
487 int i, tries = 0;
488
489 if (length > MXT_BLOCK_SIZE)
490 return -EINVAL;
491
492 buf[0] = addr & 0xff;
493 buf[1] = (addr >> 8) & 0xff;
494 for (i = 0; i < length; i++)
495 buf[i + 2] = *value++;
496
497 do {
498 if (i2c_master_send(client, buf, length + 2) == (length + 2))
499 return 0;
500 msleep(MXT_WAKE_TIME);
501 } while (++tries < MXT_MAX_RW_TRIES);
502
503 dev_err(&client->dev, "%s: i2c send failed\n", __func__);
504 return -EIO;
505}
506
Iiro Valkonen7686b102011-02-02 23:21:58 -0800507static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700508{
Jing Lin36aee812011-10-17 17:17:28 -0700509 return __mxt_write_reg(client, reg, 1, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700510}
511
Iiro Valkonen7686b102011-02-02 23:21:58 -0800512static int mxt_read_object_table(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700513 u16 reg, u8 *object_buf)
514{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800515 return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700516 object_buf);
517}
518
Iiro Valkonen7686b102011-02-02 23:21:58 -0800519static struct mxt_object *
520mxt_get_object(struct mxt_data *data, u8 type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700521{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800522 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700523 int i;
524
525 for (i = 0; i < data->info.object_num; i++) {
526 object = data->object_table + i;
527 if (object->type == type)
528 return object;
529 }
530
531 dev_err(&data->client->dev, "Invalid object type\n");
532 return NULL;
533}
534
Iiro Valkonen7686b102011-02-02 23:21:58 -0800535static int mxt_read_message(struct mxt_data *data,
536 struct mxt_message *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700537{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800538 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700539 u16 reg;
540
Iiro Valkonene8645592011-11-18 12:56:19 -0800541 object = mxt_get_object(data, MXT_GEN_MESSAGE_T5);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700542 if (!object)
543 return -EINVAL;
544
545 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800546 return __mxt_read_reg(data->client, reg,
547 sizeof(struct mxt_message), message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700548}
549
Iiro Valkonen7686b102011-02-02 23:21:58 -0800550static int mxt_read_object(struct mxt_data *data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700551 u8 type, u8 offset, u8 *val)
552{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800553 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700554 u16 reg;
555
Iiro Valkonen7686b102011-02-02 23:21:58 -0800556 object = mxt_get_object(data, type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700557 if (!object)
558 return -EINVAL;
559
560 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800561 return __mxt_read_reg(data->client, reg + offset, 1, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700562}
563
Iiro Valkonen7686b102011-02-02 23:21:58 -0800564static int mxt_write_object(struct mxt_data *data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700565 u8 type, u8 offset, u8 val)
566{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800567 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700568 u16 reg;
569
Iiro Valkonen7686b102011-02-02 23:21:58 -0800570 object = mxt_get_object(data, type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700571 if (!object)
572 return -EINVAL;
573
574 reg = object->start_address;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800575 return mxt_write_reg(data->client, reg + offset, val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700576}
577
Iiro Valkonen7686b102011-02-02 23:21:58 -0800578static void mxt_input_report(struct mxt_data *data, int single_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700579{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800580 struct mxt_finger *finger = data->finger;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700581 struct input_dev *input_dev = data->input_dev;
582 int status = finger[single_id].status;
583 int finger_num = 0;
584 int id;
585
Iiro Valkonen7686b102011-02-02 23:21:58 -0800586 for (id = 0; id < MXT_MAX_FINGER; id++) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700587 if (!finger[id].status)
588 continue;
589
Amy Maloche2b59bab2011-10-13 16:08:16 -0700590 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
591 finger[id].status != MXT_RELEASE ?
592 finger[id].area : 0);
593 input_report_abs(input_dev, ABS_MT_POSITION_X,
594 finger[id].x);
595 input_report_abs(input_dev, ABS_MT_POSITION_Y,
596 finger[id].y);
Yufeng Shene6eb36a2011-10-11 12:28:21 -0700597 input_report_abs(input_dev, ABS_MT_PRESSURE,
598 finger[id].pressure);
Amy Maloche2b59bab2011-10-13 16:08:16 -0700599 input_mt_sync(input_dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700600
Amy Maloche2b59bab2011-10-13 16:08:16 -0700601 if (finger[id].status == MXT_RELEASE)
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -0700602 finger[id].status = 0;
Amy Maloche2b59bab2011-10-13 16:08:16 -0700603 else
604 finger_num++;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700605 }
606
607 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
608
Iiro Valkonen7686b102011-02-02 23:21:58 -0800609 if (status != MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700610 input_report_abs(input_dev, ABS_X, finger[single_id].x);
611 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
Yufeng Shene6eb36a2011-10-11 12:28:21 -0700612 input_report_abs(input_dev,
613 ABS_PRESSURE, finger[single_id].pressure);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700614 }
615
616 input_sync(input_dev);
617}
618
Iiro Valkonen7686b102011-02-02 23:21:58 -0800619static void mxt_input_touchevent(struct mxt_data *data,
620 struct mxt_message *message, int id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700621{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800622 struct mxt_finger *finger = data->finger;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700623 struct device *dev = &data->client->dev;
624 u8 status = message->message[0];
625 int x;
626 int y;
627 int area;
Yufeng Shene6eb36a2011-10-11 12:28:21 -0700628 int pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700629
630 /* Check the touch is present on the screen */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800631 if (!(status & MXT_DETECT)) {
632 if (status & MXT_RELEASE) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700633 dev_dbg(dev, "[%d] released\n", id);
634
Iiro Valkonen7686b102011-02-02 23:21:58 -0800635 finger[id].status = MXT_RELEASE;
636 mxt_input_report(data, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700637 }
638 return;
639 }
640
641 /* Check only AMP detection */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800642 if (!(status & (MXT_PRESS | MXT_MOVE)))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700643 return;
644
Joonyoung Shim910d8052011-04-12 23:14:38 -0700645 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
646 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
Jing Lin2f863172011-10-17 10:56:58 -0700647 if (data->pdata->x_size < 1024)
Joonyoung Shim910d8052011-04-12 23:14:38 -0700648 x = x >> 2;
Jing Lin2f863172011-10-17 10:56:58 -0700649 if (data->pdata->y_size < 1024)
Joonyoung Shim910d8052011-04-12 23:14:38 -0700650 y = y >> 2;
651
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700652 area = message->message[4];
Yufeng Shene6eb36a2011-10-11 12:28:21 -0700653 pressure = message->message[5];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700654
655 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800656 status & MXT_MOVE ? "moved" : "pressed",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700657 x, y, area);
658
Iiro Valkonen7686b102011-02-02 23:21:58 -0800659 finger[id].status = status & MXT_MOVE ?
660 MXT_MOVE : MXT_PRESS;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700661 finger[id].x = x;
662 finger[id].y = y;
663 finger[id].area = area;
Yufeng Shene6eb36a2011-10-11 12:28:21 -0700664 finger[id].pressure = pressure;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700665
Iiro Valkonen7686b102011-02-02 23:21:58 -0800666 mxt_input_report(data, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700667}
668
Iiro Valkonen7686b102011-02-02 23:21:58 -0800669static irqreturn_t mxt_interrupt(int irq, void *dev_id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700670{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800671 struct mxt_data *data = dev_id;
672 struct mxt_message message;
673 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700674 struct device *dev = &data->client->dev;
675 int id;
676 u8 reportid;
677 u8 max_reportid;
678 u8 min_reportid;
679
680 do {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800681 if (mxt_read_message(data, &message)) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700682 dev_err(dev, "Failed to read message\n");
683 goto end;
684 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700685 reportid = message.reportid;
686
Iiro Valkonene8645592011-11-18 12:56:19 -0800687 /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */
688 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700689 if (!object)
690 goto end;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700691 max_reportid = object->max_reportid;
692 min_reportid = max_reportid - object->num_report_ids + 1;
693 id = reportid - min_reportid;
694
695 if (reportid >= min_reportid && reportid <= max_reportid)
Iiro Valkonen7686b102011-02-02 23:21:58 -0800696 mxt_input_touchevent(data, &message, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700697 else
Iiro Valkonen7686b102011-02-02 23:21:58 -0800698 mxt_dump_message(dev, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700699 } while (reportid != 0xff);
700
701end:
702 return IRQ_HANDLED;
703}
704
Iiro Valkonen7686b102011-02-02 23:21:58 -0800705static int mxt_check_reg_init(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700706{
Iiro Valkonen71749f52011-02-15 13:36:52 -0800707 const struct mxt_platform_data *pdata = data->pdata;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800708 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700709 struct device *dev = &data->client->dev;
710 int index = 0;
Iiro Valkonen71749f52011-02-15 13:36:52 -0800711 int i, j, config_offset;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700712
Iiro Valkonen71749f52011-02-15 13:36:52 -0800713 if (!pdata->config) {
714 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
715 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700716 }
717
718 for (i = 0; i < data->info.object_num; i++) {
719 object = data->object_table + i;
720
Iiro Valkonen7686b102011-02-02 23:21:58 -0800721 if (!mxt_object_writable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700722 continue;
723
Iiro Valkonen71749f52011-02-15 13:36:52 -0800724 for (j = 0; j < object->size + 1; j++) {
725 config_offset = index + j;
726 if (config_offset > pdata->config_length) {
727 dev_err(dev, "Not enough config data!\n");
728 return -EINVAL;
729 }
Iiro Valkonen7686b102011-02-02 23:21:58 -0800730 mxt_write_object(data, object->type, j,
Iiro Valkonen71749f52011-02-15 13:36:52 -0800731 pdata->config[config_offset]);
732 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700733 index += object->size + 1;
734 }
735
736 return 0;
737}
738
Iiro Valkonen7686b102011-02-02 23:21:58 -0800739static int mxt_make_highchg(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700740{
741 struct device *dev = &data->client->dev;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800742 struct mxt_message message;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700743 int count = 10;
744 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700745
746 /* Read dummy message to make high CHG pin */
747 do {
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800748 error = mxt_read_message(data, &message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700749 if (error)
750 return error;
Iiro Valkonen26cdb1a2011-02-04 00:51:05 -0800751 } while (message.reportid != 0xff && --count);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700752
753 if (!count) {
754 dev_err(dev, "CHG pin isn't cleared\n");
755 return -EBUSY;
756 }
757
758 return 0;
759}
760
Iiro Valkonen7686b102011-02-02 23:21:58 -0800761static int mxt_get_info(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700762{
763 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800764 struct mxt_info *info = &data->info;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700765 int error;
766 u8 val;
767
Iiro Valkonen7686b102011-02-02 23:21:58 -0800768 error = mxt_read_reg(client, MXT_FAMILY_ID, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700769 if (error)
770 return error;
771 info->family_id = val;
772
Iiro Valkonen7686b102011-02-02 23:21:58 -0800773 error = mxt_read_reg(client, MXT_VARIANT_ID, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700774 if (error)
775 return error;
776 info->variant_id = val;
777
Iiro Valkonen7686b102011-02-02 23:21:58 -0800778 error = mxt_read_reg(client, MXT_VERSION, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700779 if (error)
780 return error;
781 info->version = val;
782
Iiro Valkonen7686b102011-02-02 23:21:58 -0800783 error = mxt_read_reg(client, MXT_BUILD, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700784 if (error)
785 return error;
786 info->build = val;
787
Iiro Valkonen7686b102011-02-02 23:21:58 -0800788 error = mxt_read_reg(client, MXT_OBJECT_NUM, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700789 if (error)
790 return error;
791 info->object_num = val;
792
793 return 0;
794}
795
Iiro Valkonen7686b102011-02-02 23:21:58 -0800796static int mxt_get_object_table(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700797{
798 int error;
799 int i;
800 u16 reg;
801 u8 reportid = 0;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800802 u8 buf[MXT_OBJECT_SIZE];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700803
804 for (i = 0; i < data->info.object_num; i++) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800805 struct mxt_object *object = data->object_table + i;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700806
Iiro Valkonen7686b102011-02-02 23:21:58 -0800807 reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i;
808 error = mxt_read_object_table(data->client, reg, buf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700809 if (error)
810 return error;
811
812 object->type = buf[0];
813 object->start_address = (buf[2] << 8) | buf[1];
814 object->size = buf[3];
815 object->instances = buf[4];
816 object->num_report_ids = buf[5];
817
818 if (object->num_report_ids) {
819 reportid += object->num_report_ids *
820 (object->instances + 1);
821 object->max_reportid = reportid;
822 }
823 }
824
825 return 0;
826}
827
Amy Maloche7e447432011-09-14 11:36:30 -0700828static void mxt_reset_delay(struct mxt_data *data)
829{
830 struct mxt_info *info = &data->info;
831
832 switch (info->family_id) {
833 case MXT224_ID:
834 msleep(MXT224_RESET_TIME);
835 break;
836 case MXT1386_ID:
837 msleep(MXT1386_RESET_TIME);
838 break;
839 default:
840 msleep(MXT_RESET_TIME);
841 }
842}
843
Iiro Valkonen7686b102011-02-02 23:21:58 -0800844static int mxt_initialize(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700845{
846 struct i2c_client *client = data->client;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800847 struct mxt_info *info = &data->info;
Jing Lin36aee812011-10-17 17:17:28 -0700848 int error;
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700849 int timeout_counter = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700850 u8 val;
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700851 u8 command_register;
Jing Lin36aee812011-10-17 17:17:28 -0700852 struct mxt_object *t7_object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700853
Iiro Valkonen7686b102011-02-02 23:21:58 -0800854 error = mxt_get_info(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700855 if (error)
856 return error;
857
858 data->object_table = kcalloc(info->object_num,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800859 sizeof(struct mxt_object),
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700860 GFP_KERNEL);
861 if (!data->object_table) {
862 dev_err(&client->dev, "Failed to allocate memory\n");
863 return -ENOMEM;
864 }
865
866 /* Get object table information */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800867 error = mxt_get_object_table(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700868 if (error)
Jing Lin32c72532011-11-03 12:02:33 -0700869 goto free_object_table;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700870
871 /* Check register init values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800872 error = mxt_check_reg_init(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700873 if (error)
Jing Lin32c72532011-11-03 12:02:33 -0700874 goto free_object_table;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700875
Amy Maloche52262212011-09-15 16:46:57 -0700876 /* Store T7 and T9 locally, used in suspend/resume operations */
Iiro Valkonene8645592011-11-18 12:56:19 -0800877 t7_object = mxt_get_object(data, MXT_GEN_POWER_T7);
Jing Lin36aee812011-10-17 17:17:28 -0700878 if (!t7_object) {
879 dev_err(&client->dev, "Failed to get T7 object\n");
Jing Lin32c72532011-11-03 12:02:33 -0700880 error = -EINVAL;
881 goto free_object_table;
Jing Lin36aee812011-10-17 17:17:28 -0700882 }
883
884 data->t7_start_addr = t7_object->start_address;
885 error = __mxt_read_reg(client, data->t7_start_addr,
886 T7_DATA_SIZE, data->t7_data);
887 if (error < 0) {
888 dev_err(&client->dev,
Jing Lin32c72532011-11-03 12:02:33 -0700889 "Failed to save current power state\n");
890 goto free_object_table;
Amy Maloche52262212011-09-15 16:46:57 -0700891 }
Iiro Valkonene8645592011-11-18 12:56:19 -0800892 error = mxt_read_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL,
Amy Maloche52262212011-09-15 16:46:57 -0700893 &data->t9_ctrl);
894 if (error < 0) {
Jing Lin32c72532011-11-03 12:02:33 -0700895 dev_err(&client->dev, "Failed to save current touch object\n");
896 goto free_object_table;
Amy Maloche52262212011-09-15 16:46:57 -0700897 }
898
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700899 /* Backup to memory */
Iiro Valkonene8645592011-11-18 12:56:19 -0800900 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800901 MXT_COMMAND_BACKUPNV,
902 MXT_BACKUP_VALUE);
903 msleep(MXT_BACKUP_TIME);
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700904 do {
Iiro Valkonene8645592011-11-18 12:56:19 -0800905 error = mxt_read_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700906 MXT_COMMAND_BACKUPNV,
907 &command_register);
908 if (error)
Jing Lin32c72532011-11-03 12:02:33 -0700909 goto free_object_table;
Amy Maloche7e447432011-09-14 11:36:30 -0700910 usleep_range(1000, 2000);
911 } while ((command_register != 0) && (++timeout_counter <= 100));
912 if (timeout_counter > 100) {
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700913 dev_err(&client->dev, "No response after backup!\n");
Jing Lin32c72532011-11-03 12:02:33 -0700914 error = -EIO;
915 goto free_object_table;
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700916 }
917
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700918
919 /* Soft reset */
Iiro Valkonene8645592011-11-18 12:56:19 -0800920 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -0800921 MXT_COMMAND_RESET, 1);
Iiro Valkonen4ac053c2011-09-08 11:10:52 -0700922
Amy Maloche7e447432011-09-14 11:36:30 -0700923 mxt_reset_delay(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700924
925 /* Update matrix size at info struct */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800926 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700927 if (error)
Jing Lin32c72532011-11-03 12:02:33 -0700928 goto free_object_table;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700929 info->matrix_xsize = val;
930
Iiro Valkonen7686b102011-02-02 23:21:58 -0800931 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700932 if (error)
Jing Lin32c72532011-11-03 12:02:33 -0700933 goto free_object_table;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700934 info->matrix_ysize = val;
935
936 dev_info(&client->dev,
937 "Family ID: %d Variant ID: %d Version: %d Build: %d\n",
938 info->family_id, info->variant_id, info->version,
939 info->build);
940
941 dev_info(&client->dev,
942 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n",
943 info->matrix_xsize, info->matrix_ysize,
944 info->object_num);
945
946 return 0;
Jing Lin32c72532011-11-03 12:02:33 -0700947
948free_object_table:
949 kfree(data->object_table);
950 return error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700951}
952
Iiro Valkonen7686b102011-02-02 23:21:58 -0800953static ssize_t mxt_object_show(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700954 struct device_attribute *attr, char *buf)
955{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800956 struct mxt_data *data = dev_get_drvdata(dev);
957 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700958 int count = 0;
959 int i, j;
960 int error;
961 u8 val;
962
963 for (i = 0; i < data->info.object_num; i++) {
964 object = data->object_table + i;
965
Daniel Kurtz4ef11a82011-11-02 10:43:08 -0700966 count += snprintf(buf + count, PAGE_SIZE - count,
967 "Object[%d] (Type %d)\n",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700968 i + 1, object->type);
Daniel Kurtz4ef11a82011-11-02 10:43:08 -0700969 if (count >= PAGE_SIZE)
970 return PAGE_SIZE - 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700971
Iiro Valkonen7686b102011-02-02 23:21:58 -0800972 if (!mxt_object_readable(object->type)) {
Daniel Kurtz4ef11a82011-11-02 10:43:08 -0700973 count += snprintf(buf + count, PAGE_SIZE - count,
974 "\n");
975 if (count >= PAGE_SIZE)
976 return PAGE_SIZE - 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700977 continue;
978 }
979
980 for (j = 0; j < object->size + 1; j++) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800981 error = mxt_read_object(data,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700982 object->type, j, &val);
983 if (error)
984 return error;
985
Daniel Kurtz4ef11a82011-11-02 10:43:08 -0700986 count += snprintf(buf + count, PAGE_SIZE - count,
987 "\t[%2d]: %02x (%d)\n", j, val, val);
988 if (count >= PAGE_SIZE)
989 return PAGE_SIZE - 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700990 }
991
Daniel Kurtz4ef11a82011-11-02 10:43:08 -0700992 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
993 if (count >= PAGE_SIZE)
994 return PAGE_SIZE - 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700995 }
996
997 return count;
998}
999
Iiro Valkonen7686b102011-02-02 23:21:58 -08001000static int mxt_load_fw(struct device *dev, const char *fn)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001001{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001002 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001003 struct i2c_client *client = data->client;
1004 const struct firmware *fw = NULL;
1005 unsigned int frame_size;
1006 unsigned int pos = 0;
1007 int ret;
1008
1009 ret = request_firmware(&fw, fn, dev);
1010 if (ret) {
1011 dev_err(dev, "Unable to open firmware %s\n", fn);
1012 return ret;
1013 }
1014
1015 /* Change to the bootloader mode */
Iiro Valkonene8645592011-11-18 12:56:19 -08001016 mxt_write_object(data, MXT_GEN_COMMAND_T6,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001017 MXT_COMMAND_RESET, MXT_BOOT_VALUE);
Amy Maloche7e447432011-09-14 11:36:30 -07001018
1019 mxt_reset_delay(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001020
1021 /* Change to slave address of bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001022 if (client->addr == MXT_APP_LOW)
1023 client->addr = MXT_BOOT_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001024 else
Iiro Valkonen7686b102011-02-02 23:21:58 -08001025 client->addr = MXT_BOOT_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001026
Iiro Valkonen7686b102011-02-02 23:21:58 -08001027 ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001028 if (ret)
1029 goto out;
1030
1031 /* Unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001032 mxt_unlock_bootloader(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001033
1034 while (pos < fw->size) {
Iiro Valkonen7686b102011-02-02 23:21:58 -08001035 ret = mxt_check_bootloader(client,
1036 MXT_WAITING_FRAME_DATA);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001037 if (ret)
1038 goto out;
1039
1040 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
1041
1042 /* We should add 2 at frame size as the the firmware data is not
1043 * included the CRC bytes.
1044 */
1045 frame_size += 2;
1046
1047 /* Write one frame to device */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001048 mxt_fw_write(client, fw->data + pos, frame_size);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001049
Iiro Valkonen7686b102011-02-02 23:21:58 -08001050 ret = mxt_check_bootloader(client,
1051 MXT_FRAME_CRC_PASS);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001052 if (ret)
1053 goto out;
1054
1055 pos += frame_size;
1056
1057 dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size);
1058 }
1059
1060out:
1061 release_firmware(fw);
1062
1063 /* Change to slave address of application */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001064 if (client->addr == MXT_BOOT_LOW)
1065 client->addr = MXT_APP_LOW;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001066 else
Iiro Valkonen7686b102011-02-02 23:21:58 -08001067 client->addr = MXT_APP_HIGH;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001068
1069 return ret;
1070}
1071
Iiro Valkonen7686b102011-02-02 23:21:58 -08001072static ssize_t mxt_update_fw_store(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001073 struct device_attribute *attr,
1074 const char *buf, size_t count)
1075{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001076 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001077 int error;
1078
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001079 disable_irq(data->irq);
1080
Iiro Valkonen7686b102011-02-02 23:21:58 -08001081 error = mxt_load_fw(dev, MXT_FW_NAME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001082 if (error) {
1083 dev_err(dev, "The firmware update failed(%d)\n", error);
1084 count = error;
1085 } else {
1086 dev_dbg(dev, "The firmware update succeeded\n");
1087
1088 /* Wait for reset */
Iiro Valkonen7686b102011-02-02 23:21:58 -08001089 msleep(MXT_FWRESET_TIME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001090
1091 kfree(data->object_table);
1092 data->object_table = NULL;
1093
Iiro Valkonen7686b102011-02-02 23:21:58 -08001094 mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001095 }
1096
1097 enable_irq(data->irq);
1098
Iiro Valkonen08960a02011-04-12 23:16:40 -07001099 error = mxt_make_highchg(data);
1100 if (error)
1101 return error;
1102
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001103 return count;
1104}
1105
Iiro Valkonen7686b102011-02-02 23:21:58 -08001106static DEVICE_ATTR(object, 0444, mxt_object_show, NULL);
1107static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001108
Iiro Valkonen7686b102011-02-02 23:21:58 -08001109static struct attribute *mxt_attrs[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001110 &dev_attr_object.attr,
1111 &dev_attr_update_fw.attr,
1112 NULL
1113};
1114
Iiro Valkonen7686b102011-02-02 23:21:58 -08001115static const struct attribute_group mxt_attr_group = {
1116 .attrs = mxt_attrs,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001117};
1118
Amy Maloche52262212011-09-15 16:46:57 -07001119static int mxt_start(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001120{
Jing Lin36aee812011-10-17 17:17:28 -07001121 int error;
1122
Amy Maloche52262212011-09-15 16:46:57 -07001123 /* restore the old power state values and reenable touch */
Jing Lin36aee812011-10-17 17:17:28 -07001124 error = __mxt_write_reg(data->client, data->t7_start_addr,
1125 T7_DATA_SIZE, data->t7_data);
1126 if (error < 0) {
1127 dev_err(&data->client->dev,
1128 "failed to restore old power state\n");
1129 return error;
Amy Maloche52262212011-09-15 16:46:57 -07001130 }
Jing Lin36aee812011-10-17 17:17:28 -07001131
Amy Maloche52262212011-09-15 16:46:57 -07001132 error = mxt_write_object(data,
Iiro Valkonene8645592011-11-18 12:56:19 -08001133 MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, data->t9_ctrl);
Amy Maloche52262212011-09-15 16:46:57 -07001134 if (error < 0) {
1135 dev_err(&data->client->dev, "failed to restore touch\n");
1136 return error;
1137 }
1138
1139 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001140}
1141
Amy Maloche52262212011-09-15 16:46:57 -07001142static int mxt_stop(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001143{
Jing Lin36aee812011-10-17 17:17:28 -07001144 int error;
1145 u8 t7_data[T7_DATA_SIZE] = {0};
1146
1147 /* disable touch and configure deep sleep mode */
Iiro Valkonene8645592011-11-18 12:56:19 -08001148 error = mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
Jing Lin36aee812011-10-17 17:17:28 -07001149 if (error < 0) {
1150 dev_err(&data->client->dev, "failed to disable touch\n");
1151 return error;
Amy Maloche52262212011-09-15 16:46:57 -07001152 }
1153
Jing Lin36aee812011-10-17 17:17:28 -07001154 error = __mxt_write_reg(data->client, data->t7_start_addr,
1155 T7_DATA_SIZE, t7_data);
Amy Maloche52262212011-09-15 16:46:57 -07001156 if (error < 0) {
1157 dev_err(&data->client->dev,
Jing Lin36aee812011-10-17 17:17:28 -07001158 "failed to configure deep sleep mode\n");
Amy Maloche52262212011-09-15 16:46:57 -07001159 return error;
1160 }
1161
1162 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001163}
1164
Iiro Valkonen7686b102011-02-02 23:21:58 -08001165static int mxt_input_open(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001166{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001167 struct mxt_data *data = input_get_drvdata(dev);
Amy Maloche52262212011-09-15 16:46:57 -07001168 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001169
Amy Maloche52262212011-09-15 16:46:57 -07001170 error = mxt_start(data);
1171 if (error < 0) {
1172 dev_err(&data->client->dev, "mxt_start failed in input_open\n");
1173 return error;
1174 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001175
1176 return 0;
1177}
1178
Iiro Valkonen7686b102011-02-02 23:21:58 -08001179static void mxt_input_close(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001180{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001181 struct mxt_data *data = input_get_drvdata(dev);
Amy Maloche52262212011-09-15 16:46:57 -07001182 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001183
Amy Maloche52262212011-09-15 16:46:57 -07001184 error = mxt_stop(data);
1185 if (error < 0)
1186 dev_err(&data->client->dev, "mxt_stop failed in input_close\n");
1187
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001188}
1189
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301190static int mxt_power_on(struct mxt_data *data, bool on)
1191{
1192 int rc;
1193
1194 if (on == false)
1195 goto power_off;
1196
Amy Maloche21115eb2011-11-02 09:04:37 -07001197 rc = regulator_set_optimum_mode(data->vcc_ana, MXT_ACTIVE_LOAD_UA);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301198 if (rc < 0) {
Amy Maloche21115eb2011-11-02 09:04:37 -07001199 dev_err(&data->client->dev,
1200 "Regulator vcc_ana set_opt failed rc=%d\n", rc);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301201 return rc;
1202 }
1203
Amy Maloche21115eb2011-11-02 09:04:37 -07001204 rc = regulator_enable(data->vcc_ana);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301205 if (rc) {
Amy Maloche21115eb2011-11-02 09:04:37 -07001206 dev_err(&data->client->dev,
1207 "Regulator vcc_ana enable failed rc=%d\n", rc);
1208 goto error_reg_en_vcc_ana;
1209 }
1210
1211 if (data->pdata->digital_pwr_regulator) {
1212 rc = regulator_set_optimum_mode(data->vcc_dig,
1213 MXT_ACTIVE_LOAD_DIG_UA);
1214 if (rc < 0) {
1215 dev_err(&data->client->dev,
1216 "Regulator vcc_dig set_opt failed rc=%d\n",
1217 rc);
1218 goto error_reg_opt_vcc_dig;
1219 }
1220
1221 rc = regulator_enable(data->vcc_dig);
1222 if (rc) {
1223 dev_err(&data->client->dev,
1224 "Regulator vcc_dig enable failed rc=%d\n", rc);
1225 goto error_reg_en_vcc_dig;
1226 }
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301227 }
1228
1229 if (data->pdata->i2c_pull_up) {
1230 rc = regulator_set_optimum_mode(data->vcc_i2c, MXT_I2C_LOAD_UA);
1231 if (rc < 0) {
1232 dev_err(&data->client->dev,
Amy Maloche21115eb2011-11-02 09:04:37 -07001233 "Regulator vcc_i2c set_opt failed rc=%d\n", rc);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301234 goto error_reg_opt_i2c;
1235 }
1236
1237 rc = regulator_enable(data->vcc_i2c);
1238 if (rc) {
1239 dev_err(&data->client->dev,
Amy Maloche21115eb2011-11-02 09:04:37 -07001240 "Regulator vcc_i2c enable failed rc=%d\n", rc);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301241 goto error_reg_en_vcc_i2c;
1242 }
1243 }
1244
Amy Malochef0d7b8d2011-10-17 12:10:51 -07001245 msleep(130);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301246
1247 return 0;
1248
1249error_reg_en_vcc_i2c:
1250 if (data->pdata->i2c_pull_up)
1251 regulator_set_optimum_mode(data->vcc_i2c, 0);
1252error_reg_opt_i2c:
Amy Maloche21115eb2011-11-02 09:04:37 -07001253 if (data->pdata->digital_pwr_regulator)
1254 regulator_disable(data->vcc_dig);
1255error_reg_en_vcc_dig:
1256 if (data->pdata->digital_pwr_regulator)
1257 regulator_set_optimum_mode(data->vcc_dig, 0);
1258error_reg_opt_vcc_dig:
1259 regulator_disable(data->vcc_ana);
1260error_reg_en_vcc_ana:
1261 regulator_set_optimum_mode(data->vcc_ana, 0);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301262 return rc;
1263
1264power_off:
Amy Maloche21115eb2011-11-02 09:04:37 -07001265 regulator_set_optimum_mode(data->vcc_ana, 0);
1266 regulator_disable(data->vcc_ana);
1267 if (data->pdata->digital_pwr_regulator) {
1268 regulator_set_optimum_mode(data->vcc_dig, 0);
1269 regulator_disable(data->vcc_dig);
1270 }
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301271 if (data->pdata->i2c_pull_up) {
1272 regulator_set_optimum_mode(data->vcc_i2c, 0);
1273 regulator_disable(data->vcc_i2c);
1274 }
1275 msleep(50);
1276 return 0;
1277}
1278
1279static int mxt_regulator_configure(struct mxt_data *data, bool on)
1280{
1281 int rc;
1282
1283 if (on == false)
1284 goto hw_shutdown;
1285
Amy Maloche21115eb2011-11-02 09:04:37 -07001286 data->vcc_ana = regulator_get(&data->client->dev, "vdd_ana");
1287 if (IS_ERR(data->vcc_ana)) {
1288 rc = PTR_ERR(data->vcc_ana);
1289 dev_err(&data->client->dev,
1290 "Regulator get failed vcc_ana rc=%d\n", rc);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301291 return rc;
1292 }
1293
Amy Maloche21115eb2011-11-02 09:04:37 -07001294 if (regulator_count_voltages(data->vcc_ana) > 0) {
1295 rc = regulator_set_voltage(data->vcc_ana, MXT_VTG_MIN_UV,
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301296 MXT_VTG_MAX_UV);
1297 if (rc) {
1298 dev_err(&data->client->dev,
1299 "regulator set_vtg failed rc=%d\n", rc);
Amy Maloche21115eb2011-11-02 09:04:37 -07001300 goto error_set_vtg_vcc_ana;
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301301 }
1302 }
Amy Maloche21115eb2011-11-02 09:04:37 -07001303 if (data->pdata->digital_pwr_regulator) {
1304 data->vcc_dig = regulator_get(&data->client->dev, "vdd_dig");
1305 if (IS_ERR(data->vcc_dig)) {
1306 rc = PTR_ERR(data->vcc_dig);
1307 dev_err(&data->client->dev,
1308 "Regulator get dig failed rc=%d\n", rc);
1309 goto error_get_vtg_vcc_dig;
1310 }
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301311
Amy Maloche21115eb2011-11-02 09:04:37 -07001312 if (regulator_count_voltages(data->vcc_dig) > 0) {
1313 rc = regulator_set_voltage(data->vcc_dig,
1314 MXT_VTG_DIG_MIN_UV, MXT_VTG_DIG_MAX_UV);
1315 if (rc) {
1316 dev_err(&data->client->dev,
1317 "regulator set_vtg failed rc=%d\n", rc);
1318 goto error_set_vtg_vcc_dig;
1319 }
1320 }
1321 }
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301322 if (data->pdata->i2c_pull_up) {
1323 data->vcc_i2c = regulator_get(&data->client->dev, "vcc_i2c");
1324 if (IS_ERR(data->vcc_i2c)) {
1325 rc = PTR_ERR(data->vcc_i2c);
1326 dev_err(&data->client->dev,
1327 "Regulator get failed rc=%d\n", rc);
1328 goto error_get_vtg_i2c;
1329 }
1330 if (regulator_count_voltages(data->vcc_i2c) > 0) {
1331 rc = regulator_set_voltage(data->vcc_i2c,
1332 MXT_I2C_VTG_MIN_UV, MXT_I2C_VTG_MAX_UV);
1333 if (rc) {
1334 dev_err(&data->client->dev,
1335 "regulator set_vtg failed rc=%d\n", rc);
1336 goto error_set_vtg_i2c;
1337 }
1338 }
1339 }
1340
1341 return 0;
1342
1343error_set_vtg_i2c:
1344 regulator_put(data->vcc_i2c);
1345error_get_vtg_i2c:
Amy Maloche21115eb2011-11-02 09:04:37 -07001346 if (data->pdata->digital_pwr_regulator)
1347 if (regulator_count_voltages(data->vcc_dig) > 0)
1348 regulator_set_voltage(data->vcc_dig, 0,
1349 MXT_VTG_DIG_MAX_UV);
1350error_set_vtg_vcc_dig:
1351 if (data->pdata->digital_pwr_regulator)
1352 regulator_put(data->vcc_dig);
1353error_get_vtg_vcc_dig:
1354 if (regulator_count_voltages(data->vcc_ana) > 0)
1355 regulator_set_voltage(data->vcc_ana, 0, MXT_VTG_MAX_UV);
1356error_set_vtg_vcc_ana:
1357 regulator_put(data->vcc_ana);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301358 return rc;
1359
1360hw_shutdown:
Amy Maloche21115eb2011-11-02 09:04:37 -07001361 if (regulator_count_voltages(data->vcc_ana) > 0)
1362 regulator_set_voltage(data->vcc_ana, 0, MXT_VTG_MAX_UV);
1363 regulator_put(data->vcc_ana);
1364 if (data->pdata->digital_pwr_regulator) {
1365 if (regulator_count_voltages(data->vcc_dig) > 0)
1366 regulator_set_voltage(data->vcc_dig, 0,
1367 MXT_VTG_DIG_MAX_UV);
1368 regulator_put(data->vcc_dig);
1369 }
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301370 if (data->pdata->i2c_pull_up) {
1371 if (regulator_count_voltages(data->vcc_i2c) > 0)
1372 regulator_set_voltage(data->vcc_i2c, 0,
1373 MXT_I2C_VTG_MAX_UV);
1374 regulator_put(data->vcc_i2c);
1375 }
1376 return 0;
1377}
1378
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301379#ifdef CONFIG_PM
Jing Linbace50b2011-10-18 22:55:47 -07001380static int mxt_regulator_lpm(struct mxt_data *data, bool on)
1381{
1382
1383 int rc;
1384
1385 if (on == false)
1386 goto regulator_hpm;
1387
Amy Maloche21115eb2011-11-02 09:04:37 -07001388 rc = regulator_set_optimum_mode(data->vcc_ana, MXT_LPM_LOAD_UA);
Jing Linbace50b2011-10-18 22:55:47 -07001389 if (rc < 0) {
1390 dev_err(&data->client->dev,
Amy Maloche21115eb2011-11-02 09:04:37 -07001391 "Regulator vcc_ana set_opt failed rc=%d\n", rc);
Jing Linbace50b2011-10-18 22:55:47 -07001392 goto fail_regulator_lpm;
1393 }
1394
Amy Maloche21115eb2011-11-02 09:04:37 -07001395 if (data->pdata->digital_pwr_regulator) {
1396 rc = regulator_set_optimum_mode(data->vcc_dig,
1397 MXT_LPM_LOAD_DIG_UA);
1398 if (rc < 0) {
1399 dev_err(&data->client->dev,
1400 "Regulator vcc_dig set_opt failed rc=%d\n", rc);
1401 goto fail_regulator_lpm;
1402 }
1403 }
1404
Jing Linbace50b2011-10-18 22:55:47 -07001405 if (data->pdata->i2c_pull_up) {
1406 rc = regulator_set_optimum_mode(data->vcc_i2c,
1407 MXT_I2C_LPM_LOAD_UA);
1408 if (rc < 0) {
1409 dev_err(&data->client->dev,
Amy Maloche21115eb2011-11-02 09:04:37 -07001410 "Regulator vcc_i2c set_opt failed rc=%d\n", rc);
Jing Linbace50b2011-10-18 22:55:47 -07001411 goto fail_regulator_lpm;
1412 }
1413 }
1414
1415 return 0;
1416
1417regulator_hpm:
1418
Amy Maloche21115eb2011-11-02 09:04:37 -07001419 rc = regulator_set_optimum_mode(data->vcc_ana, MXT_ACTIVE_LOAD_UA);
Jing Linbace50b2011-10-18 22:55:47 -07001420 if (rc < 0) {
1421 dev_err(&data->client->dev,
Amy Maloche21115eb2011-11-02 09:04:37 -07001422 "Regulator vcc_ana set_opt failed rc=%d\n", rc);
Jing Linbace50b2011-10-18 22:55:47 -07001423 goto fail_regulator_hpm;
1424 }
1425
Amy Maloche21115eb2011-11-02 09:04:37 -07001426 if (data->pdata->digital_pwr_regulator) {
1427 rc = regulator_set_optimum_mode(data->vcc_dig,
1428 MXT_ACTIVE_LOAD_DIG_UA);
1429 if (rc < 0) {
1430 dev_err(&data->client->dev,
1431 "Regulator vcc_dig set_opt failed rc=%d\n", rc);
1432 goto fail_regulator_hpm;
1433 }
1434 }
1435
Jing Linbace50b2011-10-18 22:55:47 -07001436 if (data->pdata->i2c_pull_up) {
1437 rc = regulator_set_optimum_mode(data->vcc_i2c, MXT_I2C_LOAD_UA);
1438 if (rc < 0) {
1439 dev_err(&data->client->dev,
Amy Maloche21115eb2011-11-02 09:04:37 -07001440 "Regulator vcc_i2c set_opt failed rc=%d\n", rc);
Jing Linbace50b2011-10-18 22:55:47 -07001441 goto fail_regulator_hpm;
1442 }
1443 }
1444
1445 return 0;
1446
1447fail_regulator_lpm:
Amy Maloche21115eb2011-11-02 09:04:37 -07001448 regulator_set_optimum_mode(data->vcc_ana, MXT_ACTIVE_LOAD_UA);
1449 if (data->pdata->digital_pwr_regulator)
1450 regulator_set_optimum_mode(data->vcc_dig,
1451 MXT_ACTIVE_LOAD_DIG_UA);
Jing Linbace50b2011-10-18 22:55:47 -07001452 if (data->pdata->i2c_pull_up)
1453 regulator_set_optimum_mode(data->vcc_i2c, MXT_I2C_LOAD_UA);
1454
1455 return rc;
1456
1457fail_regulator_hpm:
Amy Maloche21115eb2011-11-02 09:04:37 -07001458 regulator_set_optimum_mode(data->vcc_ana, MXT_LPM_LOAD_UA);
1459 if (data->pdata->digital_pwr_regulator)
1460 regulator_set_optimum_mode(data->vcc_dig, MXT_LPM_LOAD_DIG_UA);
Jing Linbace50b2011-10-18 22:55:47 -07001461 if (data->pdata->i2c_pull_up)
1462 regulator_set_optimum_mode(data->vcc_i2c, MXT_I2C_LPM_LOAD_UA);
1463
1464 return rc;
1465}
1466
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301467static int mxt_suspend(struct device *dev)
1468{
1469 struct i2c_client *client = to_i2c_client(dev);
1470 struct mxt_data *data = i2c_get_clientdata(client);
1471 struct input_dev *input_dev = data->input_dev;
Amy Maloche52262212011-09-15 16:46:57 -07001472 int error;
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301473
1474 mutex_lock(&input_dev->mutex);
1475
Amy Maloche52262212011-09-15 16:46:57 -07001476 if (input_dev->users) {
1477 error = mxt_stop(data);
1478 if (error < 0) {
Jing Lin36aee812011-10-17 17:17:28 -07001479 dev_err(dev, "mxt_stop failed in suspend\n");
Amy Maloche52262212011-09-15 16:46:57 -07001480 mutex_unlock(&input_dev->mutex);
1481 return error;
1482 }
1483
1484 }
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301485
1486 mutex_unlock(&input_dev->mutex);
1487
Jing Linbace50b2011-10-18 22:55:47 -07001488 /* put regulators in low power mode */
1489 error = mxt_regulator_lpm(data, true);
1490 if (error < 0) {
1491 dev_err(dev, "failed to enter low power mode\n");
1492 return error;
1493 }
1494
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301495 return 0;
1496}
1497
1498static int mxt_resume(struct device *dev)
1499{
1500 struct i2c_client *client = to_i2c_client(dev);
1501 struct mxt_data *data = i2c_get_clientdata(client);
1502 struct input_dev *input_dev = data->input_dev;
Amy Maloche52262212011-09-15 16:46:57 -07001503 int error;
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301504
Jing Linbace50b2011-10-18 22:55:47 -07001505 /* put regulators in high power mode */
1506 error = mxt_regulator_lpm(data, false);
1507 if (error < 0) {
1508 dev_err(dev, "failed to enter high power mode\n");
1509 return error;
1510 }
1511
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301512 mutex_lock(&input_dev->mutex);
1513
Amy Maloche52262212011-09-15 16:46:57 -07001514 if (input_dev->users) {
1515 error = mxt_start(data);
1516 if (error < 0) {
Jing Lin36aee812011-10-17 17:17:28 -07001517 dev_err(dev, "mxt_start failed in resume\n");
Amy Maloche52262212011-09-15 16:46:57 -07001518 mutex_unlock(&input_dev->mutex);
1519 return error;
1520 }
1521 }
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301522
1523 mutex_unlock(&input_dev->mutex);
1524
1525 return 0;
1526}
1527
1528#if defined(CONFIG_HAS_EARLYSUSPEND)
1529static void mxt_early_suspend(struct early_suspend *h)
1530{
1531 struct mxt_data *data = container_of(h, struct mxt_data, early_suspend);
1532
1533 mxt_suspend(&data->client->dev);
1534}
1535
1536static void mxt_late_resume(struct early_suspend *h)
1537{
1538 struct mxt_data *data = container_of(h, struct mxt_data, early_suspend);
1539
1540 mxt_resume(&data->client->dev);
1541}
1542#endif
1543
1544static const struct dev_pm_ops mxt_pm_ops = {
1545#ifndef CONFIG_HAS_EARLYSUSPEND
1546 .suspend = mxt_suspend,
1547 .resume = mxt_resume,
1548#endif
1549};
1550#endif
1551
Iiro Valkonen7686b102011-02-02 23:21:58 -08001552static int __devinit mxt_probe(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001553 const struct i2c_device_id *id)
1554{
Iiro Valkonen919ed892011-02-15 13:36:52 -08001555 const struct mxt_platform_data *pdata = client->dev.platform_data;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001556 struct mxt_data *data;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001557 struct input_dev *input_dev;
1558 int error;
1559
Iiro Valkonen919ed892011-02-15 13:36:52 -08001560 if (!pdata)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001561 return -EINVAL;
1562
Iiro Valkonen7686b102011-02-02 23:21:58 -08001563 data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001564 input_dev = input_allocate_device();
1565 if (!data || !input_dev) {
1566 dev_err(&client->dev, "Failed to allocate memory\n");
1567 error = -ENOMEM;
1568 goto err_free_mem;
1569 }
1570
Iiro Valkonen7686b102011-02-02 23:21:58 -08001571 input_dev->name = "Atmel maXTouch Touchscreen";
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001572 input_dev->id.bustype = BUS_I2C;
1573 input_dev->dev.parent = &client->dev;
Iiro Valkonen7686b102011-02-02 23:21:58 -08001574 input_dev->open = mxt_input_open;
1575 input_dev->close = mxt_input_close;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001576
Joonyoung Shim910d8052011-04-12 23:14:38 -07001577 data->client = client;
1578 data->input_dev = input_dev;
1579 data->pdata = pdata;
1580 data->irq = client->irq;
1581
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001582 __set_bit(EV_ABS, input_dev->evbit);
1583 __set_bit(EV_KEY, input_dev->evbit);
1584 __set_bit(BTN_TOUCH, input_dev->keybit);
1585
1586 /* For single touch */
1587 input_set_abs_params(input_dev, ABS_X,
Jing Lin2f863172011-10-17 10:56:58 -07001588 0, data->pdata->x_size, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001589 input_set_abs_params(input_dev, ABS_Y,
Jing Lin2f863172011-10-17 10:56:58 -07001590 0, data->pdata->y_size, 0, 0);
Yufeng Shene6eb36a2011-10-11 12:28:21 -07001591 input_set_abs_params(input_dev, ABS_PRESSURE,
1592 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001593
1594 /* For multi touch */
1595 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
Iiro Valkonen7686b102011-02-02 23:21:58 -08001596 0, MXT_MAX_AREA, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001597 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
Jing Lin2f863172011-10-17 10:56:58 -07001598 0, data->pdata->x_size, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001599 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
Jing Lin2f863172011-10-17 10:56:58 -07001600 0, data->pdata->y_size, 0, 0);
Yufeng Shene6eb36a2011-10-11 12:28:21 -07001601 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
1602 0, 255, 0, 0);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001603
1604 input_set_drvdata(input_dev, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001605 i2c_set_clientdata(client, data);
1606
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301607 if (pdata->init_hw)
1608 error = pdata->init_hw(true);
1609 else
1610 error = mxt_regulator_configure(data, true);
1611 if (error) {
1612 dev_err(&client->dev, "Failed to intialize hardware\n");
Jing Lin32c72532011-11-03 12:02:33 -07001613 goto err_free_mem;
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301614 }
1615
1616 if (pdata->power_on)
1617 error = pdata->power_on(true);
1618 else
1619 error = mxt_power_on(data, true);
1620 if (error) {
1621 dev_err(&client->dev, "Failed to power on hardware\n");
1622 goto err_regulator_on;
1623 }
1624
Iiro Valkonen7686b102011-02-02 23:21:58 -08001625 error = mxt_initialize(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001626 if (error)
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301627 goto err_power_on;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001628
Iiro Valkonen7686b102011-02-02 23:21:58 -08001629 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
Iiro Valkonen919ed892011-02-15 13:36:52 -08001630 pdata->irqflags, client->dev.driver->name, data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001631 if (error) {
1632 dev_err(&client->dev, "Failed to register interrupt\n");
Jing Lin32c72532011-11-03 12:02:33 -07001633 goto err_free_object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001634 }
1635
Iiro Valkonen08960a02011-04-12 23:16:40 -07001636 error = mxt_make_highchg(data);
1637 if (error)
1638 goto err_free_irq;
1639
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001640 error = input_register_device(input_dev);
1641 if (error)
1642 goto err_free_irq;
1643
Iiro Valkonen7686b102011-02-02 23:21:58 -08001644 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001645 if (error)
1646 goto err_unregister_device;
1647
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301648#if defined(CONFIG_HAS_EARLYSUSPEND)
1649 data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN +
1650 MXT_SUSPEND_LEVEL;
1651 data->early_suspend.suspend = mxt_early_suspend;
1652 data->early_suspend.resume = mxt_late_resume;
1653 register_early_suspend(&data->early_suspend);
1654#endif
1655
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001656 return 0;
1657
1658err_unregister_device:
1659 input_unregister_device(input_dev);
1660 input_dev = NULL;
1661err_free_irq:
1662 free_irq(client->irq, data);
Jing Lin32c72532011-11-03 12:02:33 -07001663err_free_object:
1664 kfree(data->object_table);
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301665err_power_on:
1666 if (pdata->power_on)
1667 pdata->power_on(false);
1668 else
1669 mxt_power_on(data, false);
1670err_regulator_on:
1671 if (pdata->init_hw)
1672 pdata->init_hw(false);
1673 else
1674 mxt_regulator_configure(data, false);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001675err_free_mem:
1676 input_free_device(input_dev);
1677 kfree(data);
1678 return error;
1679}
1680
Iiro Valkonen7686b102011-02-02 23:21:58 -08001681static int __devexit mxt_remove(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001682{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001683 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001684
Iiro Valkonen7686b102011-02-02 23:21:58 -08001685 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001686 free_irq(data->irq, data);
1687 input_unregister_device(data->input_dev);
Anirudh Ghayal253ce122011-08-09 19:32:57 +05301688#if defined(CONFIG_HAS_EARLYSUSPEND)
1689 unregister_early_suspend(&data->early_suspend);
1690#endif
Anirudh Ghayala498e4d2011-08-09 19:10:12 +05301691
1692 if (data->pdata->power_on)
1693 data->pdata->power_on(false);
1694 else
1695 mxt_power_on(data, false);
1696
1697 if (data->pdata->init_hw)
1698 data->pdata->init_hw(false);
1699 else
1700 mxt_regulator_configure(data, false);
1701
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001702 kfree(data->object_table);
1703 kfree(data);
1704
1705 return 0;
1706}
1707
Iiro Valkonen7686b102011-02-02 23:21:58 -08001708static const struct i2c_device_id mxt_id[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001709 { "qt602240_ts", 0 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001710 { "atmel_mxt_ts", 0 },
Chris Leech46ee2a02011-02-15 13:36:52 -08001711 { "mXT224", 0 },
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001712 { }
1713};
Iiro Valkonen7686b102011-02-02 23:21:58 -08001714MODULE_DEVICE_TABLE(i2c, mxt_id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001715
Iiro Valkonen7686b102011-02-02 23:21:58 -08001716static struct i2c_driver mxt_driver = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001717 .driver = {
Iiro Valkonen7686b102011-02-02 23:21:58 -08001718 .name = "atmel_mxt_ts",
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001719 .owner = THIS_MODULE,
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001720#ifdef CONFIG_PM
Iiro Valkonen7686b102011-02-02 23:21:58 -08001721 .pm = &mxt_pm_ops,
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08001722#endif
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001723 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08001724 .probe = mxt_probe,
1725 .remove = __devexit_p(mxt_remove),
1726 .id_table = mxt_id,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001727};
1728
Iiro Valkonen7686b102011-02-02 23:21:58 -08001729static int __init mxt_init(void)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001730{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001731 return i2c_add_driver(&mxt_driver);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001732}
1733
Iiro Valkonen7686b102011-02-02 23:21:58 -08001734static void __exit mxt_exit(void)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001735{
Iiro Valkonen7686b102011-02-02 23:21:58 -08001736 i2c_del_driver(&mxt_driver);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001737}
1738
Iiro Valkonen7686b102011-02-02 23:21:58 -08001739module_init(mxt_init);
1740module_exit(mxt_exit);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001741
1742/* Module information */
1743MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
Iiro Valkonen7686b102011-02-02 23:21:58 -08001744MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001745MODULE_LICENSE("GPL");