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