Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1 | /* |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2 | * Atmel maXTouch Touchscreen driver |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd |
| 5 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame^] | 6 | * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 7 | * |
| 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 Torokhov | 964de52 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 20 | #include <linux/i2c/atmel_mxt_ts.h> |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 21 | #include <linux/input.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/slab.h> |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 24 | #include <linux/regulator/consumer.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 25 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 26 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 27 | #include <linux/earlysuspend.h> |
| 28 | /* Early-suspend level */ |
| 29 | #define MXT_SUSPEND_LEVEL 1 |
| 30 | #endif |
| 31 | |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 32 | /* Family ID */ |
| 33 | #define MXT224_ID 0x80 |
| 34 | #define MXT1386_ID 0xA0 |
| 35 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 36 | /* Version */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 37 | #define MXT_VER_20 20 |
| 38 | #define MXT_VER_21 21 |
| 39 | #define MXT_VER_22 22 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 40 | |
| 41 | /* Slave addresses */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 42 | #define MXT_APP_LOW 0x4a |
| 43 | #define MXT_APP_HIGH 0x4b |
| 44 | #define MXT_BOOT_LOW 0x24 |
| 45 | #define MXT_BOOT_HIGH 0x25 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 46 | |
| 47 | /* Firmware */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 48 | #define MXT_FW_NAME "maxtouch.fw" |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 49 | |
| 50 | /* Registers */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 51 | #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 Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 59 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 60 | #define MXT_OBJECT_SIZE 6 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 61 | |
| 62 | /* Object types */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 63 | #define MXT_DEBUG_DIAGNOSTIC 37 |
| 64 | #define MXT_GEN_MESSAGE 5 |
| 65 | #define MXT_GEN_COMMAND 6 |
| 66 | #define MXT_GEN_POWER 7 |
| 67 | #define MXT_GEN_ACQUIRE 8 |
| 68 | #define MXT_TOUCH_MULTI 9 |
| 69 | #define MXT_TOUCH_KEYARRAY 15 |
| 70 | #define MXT_TOUCH_PROXIMITY 23 |
| 71 | #define MXT_PROCI_GRIPFACE 20 |
| 72 | #define MXT_PROCG_NOISE 22 |
| 73 | #define MXT_PROCI_ONETOUCH 24 |
| 74 | #define MXT_PROCI_TWOTOUCH 27 |
Joonyoung Shim | 4c75de3 | 2011-03-14 21:41:40 -0700 | [diff] [blame] | 75 | #define MXT_PROCI_GRIP 40 |
| 76 | #define MXT_PROCI_PALM 41 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 77 | #define MXT_SPT_COMMSCONFIG 18 |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 78 | #define MXT_SPT_GPIOPWM 19 |
| 79 | #define MXT_SPT_SELFTEST 25 |
| 80 | #define MXT_SPT_CTECONFIG 28 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 81 | #define MXT_SPT_USERDATA 38 |
Joonyoung Shim | 4c75de3 | 2011-03-14 21:41:40 -0700 | [diff] [blame] | 82 | #define MXT_SPT_DIGITIZER 43 |
| 83 | #define MXT_SPT_MESSAGECOUNT 44 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 84 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 85 | /* MXT_GEN_COMMAND field */ |
| 86 | #define MXT_COMMAND_RESET 0 |
| 87 | #define MXT_COMMAND_BACKUPNV 1 |
| 88 | #define MXT_COMMAND_CALIBRATE 2 |
| 89 | #define MXT_COMMAND_REPORTALL 3 |
| 90 | #define MXT_COMMAND_DIAGNOSTIC 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 91 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 92 | /* MXT_GEN_POWER field */ |
| 93 | #define MXT_POWER_IDLEACQINT 0 |
| 94 | #define MXT_POWER_ACTVACQINT 1 |
| 95 | #define MXT_POWER_ACTV2IDLETO 2 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 96 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 97 | /* MXT_GEN_ACQUIRE field */ |
| 98 | #define MXT_ACQUIRE_CHRGTIME 0 |
| 99 | #define MXT_ACQUIRE_TCHDRIFT 2 |
| 100 | #define MXT_ACQUIRE_DRIFTST 3 |
| 101 | #define MXT_ACQUIRE_TCHAUTOCAL 4 |
| 102 | #define MXT_ACQUIRE_SYNC 5 |
| 103 | #define MXT_ACQUIRE_ATCHCALST 6 |
| 104 | #define MXT_ACQUIRE_ATCHCALSTHR 7 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 105 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 106 | /* MXT_TOUCH_MULTI field */ |
| 107 | #define MXT_TOUCH_CTRL 0 |
| 108 | #define MXT_TOUCH_XORIGIN 1 |
| 109 | #define MXT_TOUCH_YORIGIN 2 |
| 110 | #define MXT_TOUCH_XSIZE 3 |
| 111 | #define MXT_TOUCH_YSIZE 4 |
| 112 | #define MXT_TOUCH_BLEN 6 |
| 113 | #define MXT_TOUCH_TCHTHR 7 |
| 114 | #define MXT_TOUCH_TCHDI 8 |
| 115 | #define MXT_TOUCH_ORIENT 9 |
| 116 | #define MXT_TOUCH_MOVHYSTI 11 |
| 117 | #define MXT_TOUCH_MOVHYSTN 12 |
| 118 | #define MXT_TOUCH_NUMTOUCH 14 |
| 119 | #define MXT_TOUCH_MRGHYST 15 |
| 120 | #define MXT_TOUCH_MRGTHR 16 |
| 121 | #define MXT_TOUCH_AMPHYST 17 |
| 122 | #define MXT_TOUCH_XRANGE_LSB 18 |
| 123 | #define MXT_TOUCH_XRANGE_MSB 19 |
| 124 | #define MXT_TOUCH_YRANGE_LSB 20 |
| 125 | #define MXT_TOUCH_YRANGE_MSB 21 |
| 126 | #define MXT_TOUCH_XLOCLIP 22 |
| 127 | #define MXT_TOUCH_XHICLIP 23 |
| 128 | #define MXT_TOUCH_YLOCLIP 24 |
| 129 | #define MXT_TOUCH_YHICLIP 25 |
| 130 | #define MXT_TOUCH_XEDGECTRL 26 |
| 131 | #define MXT_TOUCH_XEDGEDIST 27 |
| 132 | #define MXT_TOUCH_YEDGECTRL 28 |
| 133 | #define MXT_TOUCH_YEDGEDIST 29 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 134 | #define MXT_TOUCH_JUMPLIMIT 30 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 135 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 136 | /* MXT_PROCI_GRIPFACE field */ |
| 137 | #define MXT_GRIPFACE_CTRL 0 |
| 138 | #define MXT_GRIPFACE_XLOGRIP 1 |
| 139 | #define MXT_GRIPFACE_XHIGRIP 2 |
| 140 | #define MXT_GRIPFACE_YLOGRIP 3 |
| 141 | #define MXT_GRIPFACE_YHIGRIP 4 |
| 142 | #define MXT_GRIPFACE_MAXTCHS 5 |
| 143 | #define MXT_GRIPFACE_SZTHR1 7 |
| 144 | #define MXT_GRIPFACE_SZTHR2 8 |
| 145 | #define MXT_GRIPFACE_SHPTHR1 9 |
| 146 | #define MXT_GRIPFACE_SHPTHR2 10 |
| 147 | #define MXT_GRIPFACE_SUPEXTTO 11 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 148 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 149 | /* MXT_PROCI_NOISE field */ |
| 150 | #define MXT_NOISE_CTRL 0 |
| 151 | #define MXT_NOISE_OUTFLEN 1 |
| 152 | #define MXT_NOISE_GCAFUL_LSB 3 |
| 153 | #define MXT_NOISE_GCAFUL_MSB 4 |
| 154 | #define MXT_NOISE_GCAFLL_LSB 5 |
| 155 | #define MXT_NOISE_GCAFLL_MSB 6 |
| 156 | #define MXT_NOISE_ACTVGCAFVALID 7 |
| 157 | #define MXT_NOISE_NOISETHR 8 |
| 158 | #define MXT_NOISE_FREQHOPSCALE 10 |
| 159 | #define MXT_NOISE_FREQ0 11 |
| 160 | #define MXT_NOISE_FREQ1 12 |
| 161 | #define MXT_NOISE_FREQ2 13 |
| 162 | #define MXT_NOISE_FREQ3 14 |
| 163 | #define MXT_NOISE_FREQ4 15 |
| 164 | #define MXT_NOISE_IDLEGCAFVALID 16 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 165 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 166 | /* MXT_SPT_COMMSCONFIG */ |
| 167 | #define MXT_COMMS_CTRL 0 |
| 168 | #define MXT_COMMS_CMD 1 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 169 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 170 | /* MXT_SPT_CTECONFIG field */ |
| 171 | #define MXT_CTE_CTRL 0 |
| 172 | #define MXT_CTE_CMD 1 |
| 173 | #define MXT_CTE_MODE 2 |
| 174 | #define MXT_CTE_IDLEGCAFDEPTH 3 |
| 175 | #define MXT_CTE_ACTVGCAFDEPTH 4 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 176 | #define MXT_CTE_VOLTAGE 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 177 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 178 | #define MXT_VOLTAGE_DEFAULT 2700000 |
| 179 | #define MXT_VOLTAGE_STEP 10000 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 180 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 181 | #define MXT_VTG_MIN_UV 2700000 |
| 182 | #define MXT_VTG_MAX_UV 3300000 |
| 183 | #define MXT_ACTIVE_LOAD_UA 15000 |
| 184 | |
| 185 | #define MXT_I2C_VTG_MIN_UV 1800000 |
| 186 | #define MXT_I2C_VTG_MAX_UV 1800000 |
| 187 | #define MXT_I2C_LOAD_UA 10000 |
| 188 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 189 | /* Define for MXT_GEN_COMMAND */ |
| 190 | #define MXT_BOOT_VALUE 0xa5 |
| 191 | #define MXT_BACKUP_VALUE 0x55 |
| 192 | #define MXT_BACKUP_TIME 25 /* msec */ |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 193 | #define MXT224_RESET_TIME 65 /* msec */ |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 194 | #define MXT1386_RESET_TIME 250 /* msec */ |
| 195 | #define MXT_RESET_TIME 250 /* msec */ |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 196 | #define MXT_RESET_NOCHGREAD 400 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 197 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 198 | #define MXT_FWRESET_TIME 175 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 199 | |
| 200 | /* Command to unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 201 | #define MXT_UNLOCK_CMD_MSB 0xaa |
| 202 | #define MXT_UNLOCK_CMD_LSB 0xdc |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 203 | |
| 204 | /* Bootloader mode status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 205 | #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ |
| 206 | #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ |
| 207 | #define MXT_FRAME_CRC_CHECK 0x02 |
| 208 | #define MXT_FRAME_CRC_FAIL 0x03 |
| 209 | #define MXT_FRAME_CRC_PASS 0x04 |
| 210 | #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ |
| 211 | #define MXT_BOOT_STATUS_MASK 0x3f |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 212 | |
| 213 | /* Touch status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 214 | #define MXT_SUPPRESS (1 << 1) |
| 215 | #define MXT_AMP (1 << 2) |
| 216 | #define MXT_VECTOR (1 << 3) |
| 217 | #define MXT_MOVE (1 << 4) |
| 218 | #define MXT_RELEASE (1 << 5) |
| 219 | #define MXT_PRESS (1 << 6) |
| 220 | #define MXT_DETECT (1 << 7) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 221 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 222 | /* Touch orient bits */ |
| 223 | #define MXT_XY_SWITCH (1 << 0) |
| 224 | #define MXT_X_INVERT (1 << 1) |
| 225 | #define MXT_Y_INVERT (1 << 2) |
| 226 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 227 | /* Touchscreen absolute values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 228 | #define MXT_MAX_AREA 0xff |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 229 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 230 | #define MXT_MAX_FINGER 10 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 231 | |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame] | 232 | #define MXT_BUFF_SIZE 100 |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 233 | #define T7_DATA_SIZE 3 |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame] | 234 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 235 | struct mxt_info { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 236 | u8 family_id; |
| 237 | u8 variant_id; |
| 238 | u8 version; |
| 239 | u8 build; |
| 240 | u8 matrix_xsize; |
| 241 | u8 matrix_ysize; |
| 242 | u8 object_num; |
| 243 | }; |
| 244 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 245 | struct mxt_object { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 246 | u8 type; |
| 247 | u16 start_address; |
| 248 | u8 size; |
| 249 | u8 instances; |
| 250 | u8 num_report_ids; |
| 251 | |
| 252 | /* to map object and message */ |
| 253 | u8 max_reportid; |
| 254 | }; |
| 255 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 256 | struct mxt_message { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 257 | u8 reportid; |
| 258 | u8 message[7]; |
| 259 | u8 checksum; |
| 260 | }; |
| 261 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 262 | struct mxt_finger { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 263 | int status; |
| 264 | int x; |
| 265 | int y; |
| 266 | int area; |
| 267 | }; |
| 268 | |
| 269 | /* Each client has this additional data */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 270 | struct mxt_data { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 271 | struct i2c_client *client; |
| 272 | struct input_dev *input_dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 273 | const struct mxt_platform_data *pdata; |
| 274 | struct mxt_object *object_table; |
| 275 | struct mxt_info info; |
| 276 | struct mxt_finger finger[MXT_MAX_FINGER]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 277 | unsigned int irq; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 278 | struct regulator *vcc; |
| 279 | struct regulator *vcc_i2c; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 280 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 281 | struct early_suspend early_suspend; |
| 282 | #endif |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 283 | u8 t7_data[T7_DATA_SIZE]; |
| 284 | u8 t9_ctrl; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 287 | static bool mxt_object_readable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 288 | { |
| 289 | switch (type) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 290 | case MXT_GEN_MESSAGE: |
| 291 | case MXT_GEN_COMMAND: |
| 292 | case MXT_GEN_POWER: |
| 293 | case MXT_GEN_ACQUIRE: |
| 294 | case MXT_TOUCH_MULTI: |
| 295 | case MXT_TOUCH_KEYARRAY: |
| 296 | case MXT_TOUCH_PROXIMITY: |
| 297 | case MXT_PROCI_GRIPFACE: |
| 298 | case MXT_PROCG_NOISE: |
| 299 | case MXT_PROCI_ONETOUCH: |
| 300 | case MXT_PROCI_TWOTOUCH: |
Joonyoung Shim | 4c75de3 | 2011-03-14 21:41:40 -0700 | [diff] [blame] | 301 | case MXT_PROCI_GRIP: |
| 302 | case MXT_PROCI_PALM: |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 303 | case MXT_SPT_COMMSCONFIG: |
| 304 | case MXT_SPT_GPIOPWM: |
| 305 | case MXT_SPT_SELFTEST: |
| 306 | case MXT_SPT_CTECONFIG: |
| 307 | case MXT_SPT_USERDATA: |
Anirudh Ghayal | ba3bc7a | 2011-09-05 18:34:40 +0530 | [diff] [blame] | 308 | case MXT_SPT_DIGITIZER: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 309 | return true; |
| 310 | default: |
| 311 | return false; |
| 312 | } |
| 313 | } |
| 314 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 315 | static bool mxt_object_writable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 316 | { |
| 317 | switch (type) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 318 | case MXT_GEN_COMMAND: |
| 319 | case MXT_GEN_POWER: |
| 320 | case MXT_GEN_ACQUIRE: |
| 321 | case MXT_TOUCH_MULTI: |
| 322 | case MXT_TOUCH_KEYARRAY: |
| 323 | case MXT_TOUCH_PROXIMITY: |
| 324 | case MXT_PROCI_GRIPFACE: |
| 325 | case MXT_PROCG_NOISE: |
| 326 | case MXT_PROCI_ONETOUCH: |
| 327 | case MXT_PROCI_TWOTOUCH: |
Joonyoung Shim | 4c75de3 | 2011-03-14 21:41:40 -0700 | [diff] [blame] | 328 | case MXT_PROCI_GRIP: |
| 329 | case MXT_PROCI_PALM: |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 330 | case MXT_SPT_GPIOPWM: |
| 331 | case MXT_SPT_SELFTEST: |
| 332 | case MXT_SPT_CTECONFIG: |
Anirudh Ghayal | f1071c0 | 2011-08-09 19:39:36 +0530 | [diff] [blame] | 333 | case MXT_SPT_USERDATA: |
Anirudh Ghayal | ba3bc7a | 2011-09-05 18:34:40 +0530 | [diff] [blame] | 334 | case MXT_SPT_DIGITIZER: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 335 | return true; |
| 336 | default: |
| 337 | return false; |
| 338 | } |
| 339 | } |
| 340 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 341 | static void mxt_dump_message(struct device *dev, |
| 342 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 343 | { |
| 344 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); |
| 345 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); |
| 346 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); |
| 347 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); |
| 348 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); |
| 349 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); |
| 350 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); |
| 351 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); |
| 352 | dev_dbg(dev, "checksum:\t0x%x\n", message->checksum); |
| 353 | } |
| 354 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 355 | static int mxt_check_bootloader(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 356 | unsigned int state) |
| 357 | { |
| 358 | u8 val; |
| 359 | |
| 360 | recheck: |
| 361 | if (i2c_master_recv(client, &val, 1) != 1) { |
| 362 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); |
| 363 | return -EIO; |
| 364 | } |
| 365 | |
| 366 | switch (state) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 367 | case MXT_WAITING_BOOTLOAD_CMD: |
| 368 | case MXT_WAITING_FRAME_DATA: |
| 369 | val &= ~MXT_BOOT_STATUS_MASK; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 370 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 371 | case MXT_FRAME_CRC_PASS: |
| 372 | if (val == MXT_FRAME_CRC_CHECK) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 373 | goto recheck; |
| 374 | break; |
| 375 | default: |
| 376 | return -EINVAL; |
| 377 | } |
| 378 | |
| 379 | if (val != state) { |
| 380 | dev_err(&client->dev, "Unvalid bootloader mode state\n"); |
| 381 | return -EINVAL; |
| 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 387 | static int mxt_unlock_bootloader(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 388 | { |
| 389 | u8 buf[2]; |
| 390 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 391 | buf[0] = MXT_UNLOCK_CMD_LSB; |
| 392 | buf[1] = MXT_UNLOCK_CMD_MSB; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 393 | |
| 394 | if (i2c_master_send(client, buf, 2) != 2) { |
| 395 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 396 | return -EIO; |
| 397 | } |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 402 | static int mxt_fw_write(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 403 | const u8 *data, unsigned int frame_size) |
| 404 | { |
| 405 | if (i2c_master_send(client, data, frame_size) != frame_size) { |
| 406 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 407 | return -EIO; |
| 408 | } |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 413 | static int __mxt_read_reg(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 414 | u16 reg, u16 len, void *val) |
| 415 | { |
| 416 | struct i2c_msg xfer[2]; |
| 417 | u8 buf[2]; |
| 418 | |
| 419 | buf[0] = reg & 0xff; |
| 420 | buf[1] = (reg >> 8) & 0xff; |
| 421 | |
| 422 | /* Write register */ |
| 423 | xfer[0].addr = client->addr; |
| 424 | xfer[0].flags = 0; |
| 425 | xfer[0].len = 2; |
| 426 | xfer[0].buf = buf; |
| 427 | |
| 428 | /* Read data */ |
| 429 | xfer[1].addr = client->addr; |
| 430 | xfer[1].flags = I2C_M_RD; |
| 431 | xfer[1].len = len; |
| 432 | xfer[1].buf = val; |
| 433 | |
| 434 | if (i2c_transfer(client->adapter, xfer, 2) != 2) { |
| 435 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); |
| 436 | return -EIO; |
| 437 | } |
| 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 442 | static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 443 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 444 | return __mxt_read_reg(client, reg, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 447 | static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 448 | { |
| 449 | u8 buf[3]; |
| 450 | |
| 451 | buf[0] = reg & 0xff; |
| 452 | buf[1] = (reg >> 8) & 0xff; |
| 453 | buf[2] = val; |
| 454 | |
| 455 | if (i2c_master_send(client, buf, 3) != 3) { |
| 456 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 457 | return -EIO; |
| 458 | } |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 463 | static int mxt_read_object_table(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 464 | u16 reg, u8 *object_buf) |
| 465 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 466 | return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 467 | object_buf); |
| 468 | } |
| 469 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 470 | static struct mxt_object * |
| 471 | mxt_get_object(struct mxt_data *data, u8 type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 472 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 473 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 474 | int i; |
| 475 | |
| 476 | for (i = 0; i < data->info.object_num; i++) { |
| 477 | object = data->object_table + i; |
| 478 | if (object->type == type) |
| 479 | return object; |
| 480 | } |
| 481 | |
| 482 | dev_err(&data->client->dev, "Invalid object type\n"); |
| 483 | return NULL; |
| 484 | } |
| 485 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 486 | static int mxt_read_message(struct mxt_data *data, |
| 487 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 488 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 489 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 490 | u16 reg; |
| 491 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 492 | object = mxt_get_object(data, MXT_GEN_MESSAGE); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 493 | if (!object) |
| 494 | return -EINVAL; |
| 495 | |
| 496 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 497 | return __mxt_read_reg(data->client, reg, |
| 498 | sizeof(struct mxt_message), message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 501 | static int mxt_read_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 502 | u8 type, u8 offset, u8 *val) |
| 503 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 504 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 505 | u16 reg; |
| 506 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 507 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 508 | if (!object) |
| 509 | return -EINVAL; |
| 510 | |
| 511 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 512 | return __mxt_read_reg(data->client, reg + offset, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 515 | static int mxt_write_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 516 | u8 type, u8 offset, u8 val) |
| 517 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 518 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 519 | u16 reg; |
| 520 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 521 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 522 | if (!object) |
| 523 | return -EINVAL; |
| 524 | |
| 525 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 526 | return mxt_write_reg(data->client, reg + offset, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 529 | static void mxt_input_report(struct mxt_data *data, int single_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 530 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 531 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 532 | struct input_dev *input_dev = data->input_dev; |
| 533 | int status = finger[single_id].status; |
| 534 | int finger_num = 0; |
| 535 | int id; |
| 536 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 537 | for (id = 0; id < MXT_MAX_FINGER; id++) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 538 | if (!finger[id].status) |
| 539 | continue; |
| 540 | |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 541 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, |
| 542 | finger[id].status != MXT_RELEASE ? |
| 543 | finger[id].area : 0); |
| 544 | input_report_abs(input_dev, ABS_MT_POSITION_X, |
| 545 | finger[id].x); |
| 546 | input_report_abs(input_dev, ABS_MT_POSITION_Y, |
| 547 | finger[id].y); |
| 548 | input_mt_sync(input_dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 549 | |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 550 | if (finger[id].status == MXT_RELEASE) |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 551 | finger[id].status = 0; |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 552 | else |
| 553 | finger_num++; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); |
| 557 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 558 | if (status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 559 | input_report_abs(input_dev, ABS_X, finger[single_id].x); |
| 560 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); |
| 561 | } |
| 562 | |
| 563 | input_sync(input_dev); |
| 564 | } |
| 565 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 566 | static void mxt_input_touchevent(struct mxt_data *data, |
| 567 | struct mxt_message *message, int id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 568 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 569 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 570 | struct device *dev = &data->client->dev; |
| 571 | u8 status = message->message[0]; |
| 572 | int x; |
| 573 | int y; |
| 574 | int area; |
| 575 | |
| 576 | /* Check the touch is present on the screen */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 577 | if (!(status & MXT_DETECT)) { |
| 578 | if (status & MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 579 | dev_dbg(dev, "[%d] released\n", id); |
| 580 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 581 | finger[id].status = MXT_RELEASE; |
| 582 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 583 | } |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | /* Check only AMP detection */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 588 | if (!(status & (MXT_PRESS | MXT_MOVE))) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 589 | return; |
| 590 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 591 | x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); |
| 592 | y = (message->message[2] << 4) | ((message->message[3] & 0xf)); |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame^] | 593 | if (data->pdata->x_size < 1024) |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 594 | x = x >> 2; |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame^] | 595 | if (data->pdata->y_size < 1024) |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 596 | y = y >> 2; |
| 597 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 598 | area = message->message[4]; |
| 599 | |
| 600 | dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 601 | status & MXT_MOVE ? "moved" : "pressed", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 602 | x, y, area); |
| 603 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 604 | finger[id].status = status & MXT_MOVE ? |
| 605 | MXT_MOVE : MXT_PRESS; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 606 | finger[id].x = x; |
| 607 | finger[id].y = y; |
| 608 | finger[id].area = area; |
| 609 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 610 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 613 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 614 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 615 | struct mxt_data *data = dev_id; |
| 616 | struct mxt_message message; |
| 617 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 618 | struct device *dev = &data->client->dev; |
| 619 | int id; |
| 620 | u8 reportid; |
| 621 | u8 max_reportid; |
| 622 | u8 min_reportid; |
| 623 | |
| 624 | do { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 625 | if (mxt_read_message(data, &message)) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 626 | dev_err(dev, "Failed to read message\n"); |
| 627 | goto end; |
| 628 | } |
| 629 | |
| 630 | reportid = message.reportid; |
| 631 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 632 | /* whether reportid is thing of MXT_TOUCH_MULTI */ |
| 633 | object = mxt_get_object(data, MXT_TOUCH_MULTI); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 634 | if (!object) |
| 635 | goto end; |
| 636 | |
| 637 | max_reportid = object->max_reportid; |
| 638 | min_reportid = max_reportid - object->num_report_ids + 1; |
| 639 | id = reportid - min_reportid; |
| 640 | |
| 641 | if (reportid >= min_reportid && reportid <= max_reportid) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 642 | mxt_input_touchevent(data, &message, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 643 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 644 | mxt_dump_message(dev, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 645 | } while (reportid != 0xff); |
| 646 | |
| 647 | end: |
| 648 | return IRQ_HANDLED; |
| 649 | } |
| 650 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 651 | static int mxt_check_reg_init(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 652 | { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 653 | const struct mxt_platform_data *pdata = data->pdata; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 654 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 655 | struct device *dev = &data->client->dev; |
| 656 | int index = 0; |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 657 | int i, j, config_offset; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 658 | |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 659 | if (!pdata->config) { |
| 660 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); |
| 661 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | for (i = 0; i < data->info.object_num; i++) { |
| 665 | object = data->object_table + i; |
| 666 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 667 | if (!mxt_object_writable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 668 | continue; |
| 669 | |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 670 | for (j = 0; j < object->size + 1; j++) { |
| 671 | config_offset = index + j; |
| 672 | if (config_offset > pdata->config_length) { |
| 673 | dev_err(dev, "Not enough config data!\n"); |
| 674 | return -EINVAL; |
| 675 | } |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 676 | mxt_write_object(data, object->type, j, |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 677 | pdata->config[config_offset]); |
| 678 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 679 | index += object->size + 1; |
| 680 | } |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 685 | static int mxt_make_highchg(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 686 | { |
| 687 | struct device *dev = &data->client->dev; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 688 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 689 | int count = 10; |
| 690 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 691 | |
| 692 | /* Read dummy message to make high CHG pin */ |
| 693 | do { |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 694 | error = mxt_read_message(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 695 | if (error) |
| 696 | return error; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 697 | } while (message.reportid != 0xff && --count); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 698 | |
| 699 | if (!count) { |
| 700 | dev_err(dev, "CHG pin isn't cleared\n"); |
| 701 | return -EBUSY; |
| 702 | } |
| 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 707 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 708 | { |
| 709 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 710 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 711 | int error; |
| 712 | u8 val; |
| 713 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 714 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 715 | if (error) |
| 716 | return error; |
| 717 | info->family_id = val; |
| 718 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 719 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 720 | if (error) |
| 721 | return error; |
| 722 | info->variant_id = val; |
| 723 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 724 | error = mxt_read_reg(client, MXT_VERSION, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 725 | if (error) |
| 726 | return error; |
| 727 | info->version = val; |
| 728 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 729 | error = mxt_read_reg(client, MXT_BUILD, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 730 | if (error) |
| 731 | return error; |
| 732 | info->build = val; |
| 733 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 734 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 735 | if (error) |
| 736 | return error; |
| 737 | info->object_num = val; |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 742 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 743 | { |
| 744 | int error; |
| 745 | int i; |
| 746 | u16 reg; |
| 747 | u8 reportid = 0; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 748 | u8 buf[MXT_OBJECT_SIZE]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 749 | |
| 750 | for (i = 0; i < data->info.object_num; i++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 751 | struct mxt_object *object = data->object_table + i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 752 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 753 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; |
| 754 | error = mxt_read_object_table(data->client, reg, buf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 755 | if (error) |
| 756 | return error; |
| 757 | |
| 758 | object->type = buf[0]; |
| 759 | object->start_address = (buf[2] << 8) | buf[1]; |
| 760 | object->size = buf[3]; |
| 761 | object->instances = buf[4]; |
| 762 | object->num_report_ids = buf[5]; |
| 763 | |
| 764 | if (object->num_report_ids) { |
| 765 | reportid += object->num_report_ids * |
| 766 | (object->instances + 1); |
| 767 | object->max_reportid = reportid; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | return 0; |
| 772 | } |
| 773 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 774 | static void mxt_reset_delay(struct mxt_data *data) |
| 775 | { |
| 776 | struct mxt_info *info = &data->info; |
| 777 | |
| 778 | switch (info->family_id) { |
| 779 | case MXT224_ID: |
| 780 | msleep(MXT224_RESET_TIME); |
| 781 | break; |
| 782 | case MXT1386_ID: |
| 783 | msleep(MXT1386_RESET_TIME); |
| 784 | break; |
| 785 | default: |
| 786 | msleep(MXT_RESET_TIME); |
| 787 | } |
| 788 | } |
| 789 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 790 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 791 | { |
| 792 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 793 | struct mxt_info *info = &data->info; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 794 | int error, i; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 795 | int timeout_counter = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 796 | u8 val; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 797 | u8 command_register; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 798 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 799 | error = mxt_get_info(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 800 | if (error) |
| 801 | return error; |
| 802 | |
| 803 | data->object_table = kcalloc(info->object_num, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 804 | sizeof(struct mxt_object), |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 805 | GFP_KERNEL); |
| 806 | if (!data->object_table) { |
| 807 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 808 | return -ENOMEM; |
| 809 | } |
| 810 | |
| 811 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 812 | error = mxt_get_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 813 | if (error) |
| 814 | return error; |
| 815 | |
| 816 | /* Check register init values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 817 | error = mxt_check_reg_init(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 818 | if (error) |
| 819 | return error; |
| 820 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 821 | /* Store T7 and T9 locally, used in suspend/resume operations */ |
| 822 | for (i = 0; i < T7_DATA_SIZE; i++) { |
| 823 | error = mxt_read_object(data, MXT_GEN_POWER, i, |
| 824 | &data->t7_data[i]); |
| 825 | if (error < 0) { |
| 826 | dev_err(&client->dev, |
| 827 | "failed to save current power state\n"); |
| 828 | return error; |
| 829 | } |
| 830 | } |
| 831 | error = mxt_read_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, |
| 832 | &data->t9_ctrl); |
| 833 | if (error < 0) { |
| 834 | dev_err(&client->dev, "failed to save current touch object\n"); |
| 835 | return error; |
| 836 | } |
| 837 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 838 | /* Backup to memory */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 839 | mxt_write_object(data, MXT_GEN_COMMAND, |
| 840 | MXT_COMMAND_BACKUPNV, |
| 841 | MXT_BACKUP_VALUE); |
| 842 | msleep(MXT_BACKUP_TIME); |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 843 | do { |
| 844 | error = mxt_read_object(data, MXT_GEN_COMMAND, |
| 845 | MXT_COMMAND_BACKUPNV, |
| 846 | &command_register); |
| 847 | if (error) |
| 848 | return error; |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 849 | usleep_range(1000, 2000); |
| 850 | } while ((command_register != 0) && (++timeout_counter <= 100)); |
| 851 | if (timeout_counter > 100) { |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 852 | dev_err(&client->dev, "No response after backup!\n"); |
| 853 | return -EIO; |
| 854 | } |
| 855 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 856 | |
| 857 | /* Soft reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 858 | mxt_write_object(data, MXT_GEN_COMMAND, |
| 859 | MXT_COMMAND_RESET, 1); |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 860 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 861 | mxt_reset_delay(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 862 | |
| 863 | /* Update matrix size at info struct */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 864 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 865 | if (error) |
| 866 | return error; |
| 867 | info->matrix_xsize = val; |
| 868 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 869 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 870 | if (error) |
| 871 | return error; |
| 872 | info->matrix_ysize = val; |
| 873 | |
| 874 | dev_info(&client->dev, |
| 875 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", |
| 876 | info->family_id, info->variant_id, info->version, |
| 877 | info->build); |
| 878 | |
| 879 | dev_info(&client->dev, |
| 880 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", |
| 881 | info->matrix_xsize, info->matrix_ysize, |
| 882 | info->object_num); |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 887 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 888 | struct device_attribute *attr, char *buf) |
| 889 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 890 | struct mxt_data *data = dev_get_drvdata(dev); |
| 891 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 892 | int count = 0; |
| 893 | int i, j; |
| 894 | int error; |
| 895 | u8 val; |
| 896 | |
| 897 | for (i = 0; i < data->info.object_num; i++) { |
| 898 | object = data->object_table + i; |
| 899 | |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame] | 900 | count += snprintf(buf + count, MXT_BUFF_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 901 | "Object Table Element %d(Type %d)\n", |
| 902 | i + 1, object->type); |
| 903 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 904 | if (!mxt_object_readable(object->type)) { |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame] | 905 | count += snprintf(buf + count, MXT_BUFF_SIZE, "\n"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 906 | continue; |
| 907 | } |
| 908 | |
| 909 | for (j = 0; j < object->size + 1; j++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 910 | error = mxt_read_object(data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 911 | object->type, j, &val); |
| 912 | if (error) |
| 913 | return error; |
| 914 | |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame] | 915 | count += snprintf(buf + count, MXT_BUFF_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 916 | " Byte %d: 0x%x (%d)\n", j, val, val); |
| 917 | } |
| 918 | |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame] | 919 | count += snprintf(buf + count, MXT_BUFF_SIZE, "\n"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | return count; |
| 923 | } |
| 924 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 925 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 926 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 927 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 928 | struct i2c_client *client = data->client; |
| 929 | const struct firmware *fw = NULL; |
| 930 | unsigned int frame_size; |
| 931 | unsigned int pos = 0; |
| 932 | int ret; |
| 933 | |
| 934 | ret = request_firmware(&fw, fn, dev); |
| 935 | if (ret) { |
| 936 | dev_err(dev, "Unable to open firmware %s\n", fn); |
| 937 | return ret; |
| 938 | } |
| 939 | |
| 940 | /* Change to the bootloader mode */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 941 | mxt_write_object(data, MXT_GEN_COMMAND, |
| 942 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 943 | |
| 944 | mxt_reset_delay(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 945 | |
| 946 | /* Change to slave address of bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 947 | if (client->addr == MXT_APP_LOW) |
| 948 | client->addr = MXT_BOOT_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 949 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 950 | client->addr = MXT_BOOT_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 951 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 952 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 953 | if (ret) |
| 954 | goto out; |
| 955 | |
| 956 | /* Unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 957 | mxt_unlock_bootloader(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 958 | |
| 959 | while (pos < fw->size) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 960 | ret = mxt_check_bootloader(client, |
| 961 | MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 962 | if (ret) |
| 963 | goto out; |
| 964 | |
| 965 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); |
| 966 | |
| 967 | /* We should add 2 at frame size as the the firmware data is not |
| 968 | * included the CRC bytes. |
| 969 | */ |
| 970 | frame_size += 2; |
| 971 | |
| 972 | /* Write one frame to device */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 973 | mxt_fw_write(client, fw->data + pos, frame_size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 974 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 975 | ret = mxt_check_bootloader(client, |
| 976 | MXT_FRAME_CRC_PASS); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 977 | if (ret) |
| 978 | goto out; |
| 979 | |
| 980 | pos += frame_size; |
| 981 | |
| 982 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); |
| 983 | } |
| 984 | |
| 985 | out: |
| 986 | release_firmware(fw); |
| 987 | |
| 988 | /* Change to slave address of application */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 989 | if (client->addr == MXT_BOOT_LOW) |
| 990 | client->addr = MXT_APP_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 991 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 992 | client->addr = MXT_APP_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 993 | |
| 994 | return ret; |
| 995 | } |
| 996 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 997 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 998 | struct device_attribute *attr, |
| 999 | const char *buf, size_t count) |
| 1000 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1001 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1002 | int error; |
| 1003 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1004 | disable_irq(data->irq); |
| 1005 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1006 | error = mxt_load_fw(dev, MXT_FW_NAME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1007 | if (error) { |
| 1008 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 1009 | count = error; |
| 1010 | } else { |
| 1011 | dev_dbg(dev, "The firmware update succeeded\n"); |
| 1012 | |
| 1013 | /* Wait for reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1014 | msleep(MXT_FWRESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1015 | |
| 1016 | kfree(data->object_table); |
| 1017 | data->object_table = NULL; |
| 1018 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1019 | mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | enable_irq(data->irq); |
| 1023 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1024 | error = mxt_make_highchg(data); |
| 1025 | if (error) |
| 1026 | return error; |
| 1027 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1028 | return count; |
| 1029 | } |
| 1030 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1031 | static DEVICE_ATTR(object, 0444, mxt_object_show, NULL); |
| 1032 | static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1033 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1034 | static struct attribute *mxt_attrs[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1035 | &dev_attr_object.attr, |
| 1036 | &dev_attr_update_fw.attr, |
| 1037 | NULL |
| 1038 | }; |
| 1039 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1040 | static const struct attribute_group mxt_attr_group = { |
| 1041 | .attrs = mxt_attrs, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1042 | }; |
| 1043 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1044 | static int mxt_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1045 | { |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1046 | int i, error; |
| 1047 | /* restore the old power state values and reenable touch */ |
| 1048 | for (i = 0; i < T7_DATA_SIZE; i++) { |
| 1049 | error = mxt_write_object(data, MXT_GEN_POWER, i, |
| 1050 | data->t7_data[i]); |
| 1051 | if (error < 0) { |
| 1052 | dev_err(&data->client->dev, |
| 1053 | "failed to restore old power state\n"); |
| 1054 | return error; |
| 1055 | } |
| 1056 | } |
| 1057 | error = mxt_write_object(data, |
| 1058 | MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, data->t9_ctrl); |
| 1059 | if (error < 0) { |
| 1060 | dev_err(&data->client->dev, "failed to restore touch\n"); |
| 1061 | return error; |
| 1062 | } |
| 1063 | |
| 1064 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1067 | static int mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1068 | { |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1069 | int i, error; |
| 1070 | /* configure deep sleep mode and disable touch */ |
| 1071 | for (i = 0; i < T7_DATA_SIZE; i++) { |
| 1072 | error = mxt_write_object(data, MXT_GEN_POWER, i, 0); |
| 1073 | if (error < 0) { |
| 1074 | dev_err(&data->client->dev, |
| 1075 | "failed to configure deep sleep mode\n"); |
| 1076 | return error; |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | error = mxt_write_object(data, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1081 | MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1082 | if (error < 0) { |
| 1083 | dev_err(&data->client->dev, |
| 1084 | "failed to disable touch\n"); |
| 1085 | return error; |
| 1086 | } |
| 1087 | |
| 1088 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1091 | static int mxt_input_open(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1092 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1093 | struct mxt_data *data = input_get_drvdata(dev); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1094 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1095 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1096 | error = mxt_start(data); |
| 1097 | if (error < 0) { |
| 1098 | dev_err(&data->client->dev, "mxt_start failed in input_open\n"); |
| 1099 | return error; |
| 1100 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1101 | |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1105 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1106 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1107 | struct mxt_data *data = input_get_drvdata(dev); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1108 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1109 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1110 | error = mxt_stop(data); |
| 1111 | if (error < 0) |
| 1112 | dev_err(&data->client->dev, "mxt_stop failed in input_close\n"); |
| 1113 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1116 | static int mxt_power_on(struct mxt_data *data, bool on) |
| 1117 | { |
| 1118 | int rc; |
| 1119 | |
| 1120 | if (on == false) |
| 1121 | goto power_off; |
| 1122 | |
| 1123 | rc = regulator_set_optimum_mode(data->vcc, MXT_ACTIVE_LOAD_UA); |
| 1124 | if (rc < 0) { |
| 1125 | dev_err(&data->client->dev, "Regulator set_opt failed rc=%d\n", |
| 1126 | rc); |
| 1127 | return rc; |
| 1128 | } |
| 1129 | |
| 1130 | rc = regulator_enable(data->vcc); |
| 1131 | if (rc) { |
| 1132 | dev_err(&data->client->dev, "Regulator enable failed rc=%d\n", |
| 1133 | rc); |
| 1134 | goto error_reg_en_vcc; |
| 1135 | } |
| 1136 | |
| 1137 | if (data->pdata->i2c_pull_up) { |
| 1138 | rc = regulator_set_optimum_mode(data->vcc_i2c, MXT_I2C_LOAD_UA); |
| 1139 | if (rc < 0) { |
| 1140 | dev_err(&data->client->dev, |
| 1141 | "Regulator set_opt failed rc=%d\n", rc); |
| 1142 | goto error_reg_opt_i2c; |
| 1143 | } |
| 1144 | |
| 1145 | rc = regulator_enable(data->vcc_i2c); |
| 1146 | if (rc) { |
| 1147 | dev_err(&data->client->dev, |
| 1148 | "Regulator enable failed rc=%d\n", rc); |
| 1149 | goto error_reg_en_vcc_i2c; |
| 1150 | } |
| 1151 | } |
| 1152 | |
Amy Maloche | f0d7b8d | 2011-10-17 12:10:51 -0700 | [diff] [blame] | 1153 | msleep(130); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1154 | |
| 1155 | return 0; |
| 1156 | |
| 1157 | error_reg_en_vcc_i2c: |
| 1158 | if (data->pdata->i2c_pull_up) |
| 1159 | regulator_set_optimum_mode(data->vcc_i2c, 0); |
| 1160 | error_reg_opt_i2c: |
| 1161 | regulator_disable(data->vcc); |
| 1162 | error_reg_en_vcc: |
| 1163 | regulator_set_optimum_mode(data->vcc, 0); |
| 1164 | return rc; |
| 1165 | |
| 1166 | power_off: |
| 1167 | regulator_set_optimum_mode(data->vcc, 0); |
| 1168 | regulator_disable(data->vcc); |
| 1169 | if (data->pdata->i2c_pull_up) { |
| 1170 | regulator_set_optimum_mode(data->vcc_i2c, 0); |
| 1171 | regulator_disable(data->vcc_i2c); |
| 1172 | } |
| 1173 | msleep(50); |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | static int mxt_regulator_configure(struct mxt_data *data, bool on) |
| 1178 | { |
| 1179 | int rc; |
| 1180 | |
| 1181 | if (on == false) |
| 1182 | goto hw_shutdown; |
| 1183 | |
| 1184 | data->vcc = regulator_get(&data->client->dev, "vdd"); |
| 1185 | if (IS_ERR(data->vcc)) { |
| 1186 | rc = PTR_ERR(data->vcc); |
| 1187 | dev_err(&data->client->dev, "Regulator get failed rc=%d\n", |
| 1188 | rc); |
| 1189 | return rc; |
| 1190 | } |
| 1191 | |
| 1192 | if (regulator_count_voltages(data->vcc) > 0) { |
| 1193 | rc = regulator_set_voltage(data->vcc, MXT_VTG_MIN_UV, |
| 1194 | MXT_VTG_MAX_UV); |
| 1195 | if (rc) { |
| 1196 | dev_err(&data->client->dev, |
| 1197 | "regulator set_vtg failed rc=%d\n", rc); |
| 1198 | goto error_set_vtg_vcc; |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | if (data->pdata->i2c_pull_up) { |
| 1203 | data->vcc_i2c = regulator_get(&data->client->dev, "vcc_i2c"); |
| 1204 | if (IS_ERR(data->vcc_i2c)) { |
| 1205 | rc = PTR_ERR(data->vcc_i2c); |
| 1206 | dev_err(&data->client->dev, |
| 1207 | "Regulator get failed rc=%d\n", rc); |
| 1208 | goto error_get_vtg_i2c; |
| 1209 | } |
| 1210 | if (regulator_count_voltages(data->vcc_i2c) > 0) { |
| 1211 | rc = regulator_set_voltage(data->vcc_i2c, |
| 1212 | MXT_I2C_VTG_MIN_UV, MXT_I2C_VTG_MAX_UV); |
| 1213 | if (rc) { |
| 1214 | dev_err(&data->client->dev, |
| 1215 | "regulator set_vtg failed rc=%d\n", rc); |
| 1216 | goto error_set_vtg_i2c; |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | return 0; |
| 1222 | |
| 1223 | error_set_vtg_i2c: |
| 1224 | regulator_put(data->vcc_i2c); |
| 1225 | error_get_vtg_i2c: |
| 1226 | if (regulator_count_voltages(data->vcc) > 0) |
| 1227 | regulator_set_voltage(data->vcc, 0, MXT_VTG_MAX_UV); |
| 1228 | error_set_vtg_vcc: |
| 1229 | regulator_put(data->vcc); |
| 1230 | return rc; |
| 1231 | |
| 1232 | hw_shutdown: |
| 1233 | if (regulator_count_voltages(data->vcc) > 0) |
| 1234 | regulator_set_voltage(data->vcc, 0, MXT_VTG_MAX_UV); |
| 1235 | regulator_put(data->vcc); |
| 1236 | if (data->pdata->i2c_pull_up) { |
| 1237 | if (regulator_count_voltages(data->vcc_i2c) > 0) |
| 1238 | regulator_set_voltage(data->vcc_i2c, 0, |
| 1239 | MXT_I2C_VTG_MAX_UV); |
| 1240 | regulator_put(data->vcc_i2c); |
| 1241 | } |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1245 | #ifdef CONFIG_PM |
| 1246 | static int mxt_suspend(struct device *dev) |
| 1247 | { |
| 1248 | struct i2c_client *client = to_i2c_client(dev); |
| 1249 | struct mxt_data *data = i2c_get_clientdata(client); |
| 1250 | struct input_dev *input_dev = data->input_dev; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1251 | int error; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1252 | |
| 1253 | mutex_lock(&input_dev->mutex); |
| 1254 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1255 | if (input_dev->users) { |
| 1256 | error = mxt_stop(data); |
| 1257 | if (error < 0) { |
| 1258 | dev_err(&client->dev, "mxt_stop failed in suspend\n"); |
| 1259 | mutex_unlock(&input_dev->mutex); |
| 1260 | return error; |
| 1261 | } |
| 1262 | |
| 1263 | } |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1264 | |
| 1265 | mutex_unlock(&input_dev->mutex); |
| 1266 | |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | static int mxt_resume(struct device *dev) |
| 1271 | { |
| 1272 | struct i2c_client *client = to_i2c_client(dev); |
| 1273 | struct mxt_data *data = i2c_get_clientdata(client); |
| 1274 | struct input_dev *input_dev = data->input_dev; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1275 | int error; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1276 | /* Soft reset */ |
| 1277 | mxt_write_object(data, MXT_GEN_COMMAND, |
| 1278 | MXT_COMMAND_RESET, 1); |
| 1279 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1280 | mxt_reset_delay(data); |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1281 | |
| 1282 | mutex_lock(&input_dev->mutex); |
| 1283 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1284 | if (input_dev->users) { |
| 1285 | error = mxt_start(data); |
| 1286 | if (error < 0) { |
| 1287 | dev_err(&client->dev, "mxt_start failed in resume\n"); |
| 1288 | mutex_unlock(&input_dev->mutex); |
| 1289 | return error; |
| 1290 | } |
| 1291 | } |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1292 | |
| 1293 | mutex_unlock(&input_dev->mutex); |
| 1294 | |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
| 1298 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1299 | static void mxt_early_suspend(struct early_suspend *h) |
| 1300 | { |
| 1301 | struct mxt_data *data = container_of(h, struct mxt_data, early_suspend); |
| 1302 | |
| 1303 | mxt_suspend(&data->client->dev); |
| 1304 | } |
| 1305 | |
| 1306 | static void mxt_late_resume(struct early_suspend *h) |
| 1307 | { |
| 1308 | struct mxt_data *data = container_of(h, struct mxt_data, early_suspend); |
| 1309 | |
| 1310 | mxt_resume(&data->client->dev); |
| 1311 | } |
| 1312 | #endif |
| 1313 | |
| 1314 | static const struct dev_pm_ops mxt_pm_ops = { |
| 1315 | #ifndef CONFIG_HAS_EARLYSUSPEND |
| 1316 | .suspend = mxt_suspend, |
| 1317 | .resume = mxt_resume, |
| 1318 | #endif |
| 1319 | }; |
| 1320 | #endif |
| 1321 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1322 | static int __devinit mxt_probe(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1323 | const struct i2c_device_id *id) |
| 1324 | { |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1325 | const struct mxt_platform_data *pdata = client->dev.platform_data; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1326 | struct mxt_data *data; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1327 | struct input_dev *input_dev; |
| 1328 | int error; |
| 1329 | |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1330 | if (!pdata) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1331 | return -EINVAL; |
| 1332 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1333 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1334 | input_dev = input_allocate_device(); |
| 1335 | if (!data || !input_dev) { |
| 1336 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1337 | error = -ENOMEM; |
| 1338 | goto err_free_mem; |
| 1339 | } |
| 1340 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1341 | input_dev->name = "Atmel maXTouch Touchscreen"; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1342 | input_dev->id.bustype = BUS_I2C; |
| 1343 | input_dev->dev.parent = &client->dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1344 | input_dev->open = mxt_input_open; |
| 1345 | input_dev->close = mxt_input_close; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1346 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1347 | data->client = client; |
| 1348 | data->input_dev = input_dev; |
| 1349 | data->pdata = pdata; |
| 1350 | data->irq = client->irq; |
| 1351 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1352 | __set_bit(EV_ABS, input_dev->evbit); |
| 1353 | __set_bit(EV_KEY, input_dev->evbit); |
| 1354 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 1355 | |
| 1356 | /* For single touch */ |
| 1357 | input_set_abs_params(input_dev, ABS_X, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame^] | 1358 | 0, data->pdata->x_size, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1359 | input_set_abs_params(input_dev, ABS_Y, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame^] | 1360 | 0, data->pdata->y_size, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1361 | |
| 1362 | /* For multi touch */ |
| 1363 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1364 | 0, MXT_MAX_AREA, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1365 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame^] | 1366 | 0, data->pdata->x_size, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1367 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame^] | 1368 | 0, data->pdata->y_size, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1369 | |
| 1370 | input_set_drvdata(input_dev, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1371 | i2c_set_clientdata(client, data); |
| 1372 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1373 | if (pdata->init_hw) |
| 1374 | error = pdata->init_hw(true); |
| 1375 | else |
| 1376 | error = mxt_regulator_configure(data, true); |
| 1377 | if (error) { |
| 1378 | dev_err(&client->dev, "Failed to intialize hardware\n"); |
| 1379 | goto err_free_object; |
| 1380 | } |
| 1381 | |
| 1382 | if (pdata->power_on) |
| 1383 | error = pdata->power_on(true); |
| 1384 | else |
| 1385 | error = mxt_power_on(data, true); |
| 1386 | if (error) { |
| 1387 | dev_err(&client->dev, "Failed to power on hardware\n"); |
| 1388 | goto err_regulator_on; |
| 1389 | } |
| 1390 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1391 | error = mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1392 | if (error) |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1393 | goto err_power_on; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1394 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1395 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1396 | pdata->irqflags, client->dev.driver->name, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1397 | if (error) { |
| 1398 | dev_err(&client->dev, "Failed to register interrupt\n"); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1399 | goto err_power_on; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1402 | error = mxt_make_highchg(data); |
| 1403 | if (error) |
| 1404 | goto err_free_irq; |
| 1405 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1406 | error = input_register_device(input_dev); |
| 1407 | if (error) |
| 1408 | goto err_free_irq; |
| 1409 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1410 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1411 | if (error) |
| 1412 | goto err_unregister_device; |
| 1413 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1414 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1415 | data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + |
| 1416 | MXT_SUSPEND_LEVEL; |
| 1417 | data->early_suspend.suspend = mxt_early_suspend; |
| 1418 | data->early_suspend.resume = mxt_late_resume; |
| 1419 | register_early_suspend(&data->early_suspend); |
| 1420 | #endif |
| 1421 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1422 | return 0; |
| 1423 | |
| 1424 | err_unregister_device: |
| 1425 | input_unregister_device(input_dev); |
| 1426 | input_dev = NULL; |
| 1427 | err_free_irq: |
| 1428 | free_irq(client->irq, data); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1429 | err_power_on: |
| 1430 | if (pdata->power_on) |
| 1431 | pdata->power_on(false); |
| 1432 | else |
| 1433 | mxt_power_on(data, false); |
| 1434 | err_regulator_on: |
| 1435 | if (pdata->init_hw) |
| 1436 | pdata->init_hw(false); |
| 1437 | else |
| 1438 | mxt_regulator_configure(data, false); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1439 | err_free_object: |
| 1440 | kfree(data->object_table); |
| 1441 | err_free_mem: |
| 1442 | input_free_device(input_dev); |
| 1443 | kfree(data); |
| 1444 | return error; |
| 1445 | } |
| 1446 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1447 | static int __devexit mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1448 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1449 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1450 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1451 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1452 | free_irq(data->irq, data); |
| 1453 | input_unregister_device(data->input_dev); |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1454 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1455 | unregister_early_suspend(&data->early_suspend); |
| 1456 | #endif |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1457 | |
| 1458 | if (data->pdata->power_on) |
| 1459 | data->pdata->power_on(false); |
| 1460 | else |
| 1461 | mxt_power_on(data, false); |
| 1462 | |
| 1463 | if (data->pdata->init_hw) |
| 1464 | data->pdata->init_hw(false); |
| 1465 | else |
| 1466 | mxt_regulator_configure(data, false); |
| 1467 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1468 | kfree(data->object_table); |
| 1469 | kfree(data); |
| 1470 | |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1474 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1475 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1476 | { "atmel_mxt_ts", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1477 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1478 | { } |
| 1479 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1480 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1481 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1482 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1483 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1484 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1485 | .owner = THIS_MODULE, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1486 | #ifdef CONFIG_PM |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1487 | .pm = &mxt_pm_ops, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1488 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1489 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1490 | .probe = mxt_probe, |
| 1491 | .remove = __devexit_p(mxt_remove), |
| 1492 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1493 | }; |
| 1494 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1495 | static int __init mxt_init(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1496 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1497 | return i2c_add_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1500 | static void __exit mxt_exit(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1501 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1502 | i2c_del_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1505 | module_init(mxt_init); |
| 1506 | module_exit(mxt_exit); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1507 | |
| 1508 | /* Module information */ |
| 1509 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1510 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1511 | MODULE_LICENSE("GPL"); |