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 |
| 232 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 233 | struct mxt_info { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 234 | u8 family_id; |
| 235 | u8 variant_id; |
| 236 | u8 version; |
| 237 | u8 build; |
| 238 | u8 matrix_xsize; |
| 239 | u8 matrix_ysize; |
| 240 | u8 object_num; |
| 241 | }; |
| 242 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 243 | struct mxt_object { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 244 | u8 type; |
| 245 | u16 start_address; |
| 246 | u8 size; |
| 247 | u8 instances; |
| 248 | u8 num_report_ids; |
| 249 | |
| 250 | /* to map object and message */ |
| 251 | u8 max_reportid; |
| 252 | }; |
| 253 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 254 | struct mxt_message { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 255 | u8 reportid; |
| 256 | u8 message[7]; |
| 257 | u8 checksum; |
| 258 | }; |
| 259 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 260 | struct mxt_finger { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 261 | int status; |
| 262 | int x; |
| 263 | int y; |
| 264 | int area; |
| 265 | }; |
| 266 | |
| 267 | /* Each client has this additional data */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 268 | struct mxt_data { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 269 | struct i2c_client *client; |
| 270 | struct input_dev *input_dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 271 | const struct mxt_platform_data *pdata; |
| 272 | struct mxt_object *object_table; |
| 273 | struct mxt_info info; |
| 274 | struct mxt_finger finger[MXT_MAX_FINGER]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 275 | unsigned int irq; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 276 | unsigned int max_x; |
| 277 | unsigned int max_y; |
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 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 285 | static bool mxt_object_readable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 286 | { |
| 287 | switch (type) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 288 | case MXT_GEN_MESSAGE: |
| 289 | case MXT_GEN_COMMAND: |
| 290 | case MXT_GEN_POWER: |
| 291 | case MXT_GEN_ACQUIRE: |
| 292 | case MXT_TOUCH_MULTI: |
| 293 | case MXT_TOUCH_KEYARRAY: |
| 294 | case MXT_TOUCH_PROXIMITY: |
| 295 | case MXT_PROCI_GRIPFACE: |
| 296 | case MXT_PROCG_NOISE: |
| 297 | case MXT_PROCI_ONETOUCH: |
| 298 | case MXT_PROCI_TWOTOUCH: |
Joonyoung Shim | 4c75de3 | 2011-03-14 21:41:40 -0700 | [diff] [blame] | 299 | case MXT_PROCI_GRIP: |
| 300 | case MXT_PROCI_PALM: |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 301 | case MXT_SPT_COMMSCONFIG: |
| 302 | case MXT_SPT_GPIOPWM: |
| 303 | case MXT_SPT_SELFTEST: |
| 304 | case MXT_SPT_CTECONFIG: |
| 305 | case MXT_SPT_USERDATA: |
Anirudh Ghayal | ba3bc7a | 2011-09-05 18:34:40 +0530 | [diff] [blame] | 306 | case MXT_SPT_DIGITIZER: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 307 | return true; |
| 308 | default: |
| 309 | return false; |
| 310 | } |
| 311 | } |
| 312 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 313 | static bool mxt_object_writable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 314 | { |
| 315 | switch (type) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 316 | case MXT_GEN_COMMAND: |
| 317 | case MXT_GEN_POWER: |
| 318 | case MXT_GEN_ACQUIRE: |
| 319 | case MXT_TOUCH_MULTI: |
| 320 | case MXT_TOUCH_KEYARRAY: |
| 321 | case MXT_TOUCH_PROXIMITY: |
| 322 | case MXT_PROCI_GRIPFACE: |
| 323 | case MXT_PROCG_NOISE: |
| 324 | case MXT_PROCI_ONETOUCH: |
| 325 | case MXT_PROCI_TWOTOUCH: |
Joonyoung Shim | 4c75de3 | 2011-03-14 21:41:40 -0700 | [diff] [blame] | 326 | case MXT_PROCI_GRIP: |
| 327 | case MXT_PROCI_PALM: |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 328 | case MXT_SPT_GPIOPWM: |
| 329 | case MXT_SPT_SELFTEST: |
| 330 | case MXT_SPT_CTECONFIG: |
Anirudh Ghayal | f1071c0 | 2011-08-09 19:39:36 +0530 | [diff] [blame] | 331 | case MXT_SPT_USERDATA: |
Anirudh Ghayal | ba3bc7a | 2011-09-05 18:34:40 +0530 | [diff] [blame] | 332 | case MXT_SPT_DIGITIZER: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 333 | return true; |
| 334 | default: |
| 335 | return false; |
| 336 | } |
| 337 | } |
| 338 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 339 | static void mxt_dump_message(struct device *dev, |
| 340 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 341 | { |
| 342 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); |
| 343 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); |
| 344 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); |
| 345 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); |
| 346 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); |
| 347 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); |
| 348 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); |
| 349 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); |
| 350 | dev_dbg(dev, "checksum:\t0x%x\n", message->checksum); |
| 351 | } |
| 352 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 353 | static int mxt_check_bootloader(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 354 | unsigned int state) |
| 355 | { |
| 356 | u8 val; |
| 357 | |
| 358 | recheck: |
| 359 | if (i2c_master_recv(client, &val, 1) != 1) { |
| 360 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); |
| 361 | return -EIO; |
| 362 | } |
| 363 | |
| 364 | switch (state) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 365 | case MXT_WAITING_BOOTLOAD_CMD: |
| 366 | case MXT_WAITING_FRAME_DATA: |
| 367 | val &= ~MXT_BOOT_STATUS_MASK; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 368 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 369 | case MXT_FRAME_CRC_PASS: |
| 370 | if (val == MXT_FRAME_CRC_CHECK) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 371 | goto recheck; |
| 372 | break; |
| 373 | default: |
| 374 | return -EINVAL; |
| 375 | } |
| 376 | |
| 377 | if (val != state) { |
| 378 | dev_err(&client->dev, "Unvalid bootloader mode state\n"); |
| 379 | return -EINVAL; |
| 380 | } |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 385 | static int mxt_unlock_bootloader(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 386 | { |
| 387 | u8 buf[2]; |
| 388 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 389 | buf[0] = MXT_UNLOCK_CMD_LSB; |
| 390 | buf[1] = MXT_UNLOCK_CMD_MSB; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 391 | |
| 392 | if (i2c_master_send(client, buf, 2) != 2) { |
| 393 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 394 | return -EIO; |
| 395 | } |
| 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 400 | static int mxt_fw_write(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 401 | const u8 *data, unsigned int frame_size) |
| 402 | { |
| 403 | if (i2c_master_send(client, data, frame_size) != frame_size) { |
| 404 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 405 | return -EIO; |
| 406 | } |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 411 | static int __mxt_read_reg(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 412 | u16 reg, u16 len, void *val) |
| 413 | { |
| 414 | struct i2c_msg xfer[2]; |
| 415 | u8 buf[2]; |
| 416 | |
| 417 | buf[0] = reg & 0xff; |
| 418 | buf[1] = (reg >> 8) & 0xff; |
| 419 | |
| 420 | /* Write register */ |
| 421 | xfer[0].addr = client->addr; |
| 422 | xfer[0].flags = 0; |
| 423 | xfer[0].len = 2; |
| 424 | xfer[0].buf = buf; |
| 425 | |
| 426 | /* Read data */ |
| 427 | xfer[1].addr = client->addr; |
| 428 | xfer[1].flags = I2C_M_RD; |
| 429 | xfer[1].len = len; |
| 430 | xfer[1].buf = val; |
| 431 | |
| 432 | if (i2c_transfer(client->adapter, xfer, 2) != 2) { |
| 433 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); |
| 434 | return -EIO; |
| 435 | } |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 440 | 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] | 441 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 442 | return __mxt_read_reg(client, reg, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 445 | 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] | 446 | { |
| 447 | u8 buf[3]; |
| 448 | |
| 449 | buf[0] = reg & 0xff; |
| 450 | buf[1] = (reg >> 8) & 0xff; |
| 451 | buf[2] = val; |
| 452 | |
| 453 | if (i2c_master_send(client, buf, 3) != 3) { |
| 454 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 455 | return -EIO; |
| 456 | } |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 461 | static int mxt_read_object_table(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 462 | u16 reg, u8 *object_buf) |
| 463 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 464 | return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 465 | object_buf); |
| 466 | } |
| 467 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 468 | static struct mxt_object * |
| 469 | mxt_get_object(struct mxt_data *data, u8 type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 470 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 471 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 472 | int i; |
| 473 | |
| 474 | for (i = 0; i < data->info.object_num; i++) { |
| 475 | object = data->object_table + i; |
| 476 | if (object->type == type) |
| 477 | return object; |
| 478 | } |
| 479 | |
| 480 | dev_err(&data->client->dev, "Invalid object type\n"); |
| 481 | return NULL; |
| 482 | } |
| 483 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 484 | static int mxt_read_message(struct mxt_data *data, |
| 485 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 486 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 487 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 488 | u16 reg; |
| 489 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 490 | object = mxt_get_object(data, MXT_GEN_MESSAGE); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 491 | if (!object) |
| 492 | return -EINVAL; |
| 493 | |
| 494 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 495 | return __mxt_read_reg(data->client, reg, |
| 496 | sizeof(struct mxt_message), message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 499 | static int mxt_read_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 500 | u8 type, u8 offset, u8 *val) |
| 501 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 502 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 503 | u16 reg; |
| 504 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 505 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 506 | if (!object) |
| 507 | return -EINVAL; |
| 508 | |
| 509 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 510 | return __mxt_read_reg(data->client, reg + offset, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 513 | static int mxt_write_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 514 | u8 type, u8 offset, u8 val) |
| 515 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 516 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 517 | u16 reg; |
| 518 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 519 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 520 | if (!object) |
| 521 | return -EINVAL; |
| 522 | |
| 523 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 524 | return mxt_write_reg(data->client, reg + offset, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 527 | static void mxt_input_report(struct mxt_data *data, int single_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 528 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 529 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 530 | struct input_dev *input_dev = data->input_dev; |
| 531 | int status = finger[single_id].status; |
| 532 | int finger_num = 0; |
| 533 | int id; |
| 534 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 535 | for (id = 0; id < MXT_MAX_FINGER; id++) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 536 | if (!finger[id].status) |
| 537 | continue; |
| 538 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 539 | input_mt_slot(input_dev, id); |
| 540 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, |
| 541 | finger[id].status != MXT_RELEASE); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 542 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 543 | if (finger[id].status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 544 | finger_num++; |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 545 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, |
| 546 | finger[id].area); |
| 547 | input_report_abs(input_dev, ABS_MT_POSITION_X, |
| 548 | finger[id].x); |
| 549 | input_report_abs(input_dev, ABS_MT_POSITION_Y, |
| 550 | finger[id].y); |
| 551 | } else { |
| 552 | finger[id].status = 0; |
| 553 | } |
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)); |
| 593 | if (data->max_x < 1024) |
| 594 | x = x >> 2; |
| 595 | if (data->max_y < 1024) |
| 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 void mxt_handle_pdata(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 708 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 709 | const struct mxt_platform_data *pdata = data->pdata; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 710 | u8 voltage; |
| 711 | |
| 712 | /* Set touchscreen lines */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 713 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_XSIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 714 | pdata->x_line); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 715 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_YSIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 716 | pdata->y_line); |
| 717 | |
| 718 | /* Set touchscreen orient */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 719 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_ORIENT, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 720 | pdata->orient); |
| 721 | |
| 722 | /* Set touchscreen burst length */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 723 | mxt_write_object(data, MXT_TOUCH_MULTI, |
| 724 | MXT_TOUCH_BLEN, pdata->blen); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 725 | |
| 726 | /* Set touchscreen threshold */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 727 | mxt_write_object(data, MXT_TOUCH_MULTI, |
| 728 | MXT_TOUCH_TCHTHR, pdata->threshold); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 729 | |
| 730 | /* Set touchscreen resolution */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 731 | mxt_write_object(data, MXT_TOUCH_MULTI, |
| 732 | MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff); |
| 733 | mxt_write_object(data, MXT_TOUCH_MULTI, |
| 734 | MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8); |
| 735 | mxt_write_object(data, MXT_TOUCH_MULTI, |
| 736 | MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff); |
| 737 | mxt_write_object(data, MXT_TOUCH_MULTI, |
| 738 | MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 739 | |
| 740 | /* Set touchscreen voltage */ |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 741 | if (pdata->voltage) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 742 | if (pdata->voltage < MXT_VOLTAGE_DEFAULT) { |
| 743 | voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) / |
| 744 | MXT_VOLTAGE_STEP; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 745 | voltage = 0xff - voltage + 1; |
| 746 | } else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 747 | voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) / |
| 748 | MXT_VOLTAGE_STEP; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 749 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 750 | mxt_write_object(data, MXT_SPT_CTECONFIG, |
| 751 | MXT_CTE_VOLTAGE, voltage); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 755 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 756 | { |
| 757 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 758 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 759 | int error; |
| 760 | u8 val; |
| 761 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 762 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 763 | if (error) |
| 764 | return error; |
| 765 | info->family_id = val; |
| 766 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 767 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 768 | if (error) |
| 769 | return error; |
| 770 | info->variant_id = val; |
| 771 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 772 | error = mxt_read_reg(client, MXT_VERSION, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 773 | if (error) |
| 774 | return error; |
| 775 | info->version = val; |
| 776 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 777 | error = mxt_read_reg(client, MXT_BUILD, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 778 | if (error) |
| 779 | return error; |
| 780 | info->build = val; |
| 781 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 782 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 783 | if (error) |
| 784 | return error; |
| 785 | info->object_num = val; |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 790 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 791 | { |
| 792 | int error; |
| 793 | int i; |
| 794 | u16 reg; |
| 795 | u8 reportid = 0; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 796 | u8 buf[MXT_OBJECT_SIZE]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 797 | |
| 798 | for (i = 0; i < data->info.object_num; i++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 799 | struct mxt_object *object = data->object_table + i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 800 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 801 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; |
| 802 | error = mxt_read_object_table(data->client, reg, buf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 803 | if (error) |
| 804 | return error; |
| 805 | |
| 806 | object->type = buf[0]; |
| 807 | object->start_address = (buf[2] << 8) | buf[1]; |
| 808 | object->size = buf[3]; |
| 809 | object->instances = buf[4]; |
| 810 | object->num_report_ids = buf[5]; |
| 811 | |
| 812 | if (object->num_report_ids) { |
| 813 | reportid += object->num_report_ids * |
| 814 | (object->instances + 1); |
| 815 | object->max_reportid = reportid; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 822 | static void mxt_reset_delay(struct mxt_data *data) |
| 823 | { |
| 824 | struct mxt_info *info = &data->info; |
| 825 | |
| 826 | switch (info->family_id) { |
| 827 | case MXT224_ID: |
| 828 | msleep(MXT224_RESET_TIME); |
| 829 | break; |
| 830 | case MXT1386_ID: |
| 831 | msleep(MXT1386_RESET_TIME); |
| 832 | break; |
| 833 | default: |
| 834 | msleep(MXT_RESET_TIME); |
| 835 | } |
| 836 | } |
| 837 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 838 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 839 | { |
| 840 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 841 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 842 | int error; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 843 | int timeout_counter = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 844 | u8 val; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 845 | u8 command_register; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 846 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 847 | error = mxt_get_info(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 848 | if (error) |
| 849 | return error; |
| 850 | |
| 851 | data->object_table = kcalloc(info->object_num, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 852 | sizeof(struct mxt_object), |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 853 | GFP_KERNEL); |
| 854 | if (!data->object_table) { |
| 855 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 856 | return -ENOMEM; |
| 857 | } |
| 858 | |
| 859 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 860 | error = mxt_get_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 861 | if (error) |
| 862 | return error; |
| 863 | |
| 864 | /* Check register init values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 865 | error = mxt_check_reg_init(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 866 | if (error) |
| 867 | return error; |
| 868 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 869 | mxt_handle_pdata(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 870 | |
| 871 | /* Backup to memory */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 872 | mxt_write_object(data, MXT_GEN_COMMAND, |
| 873 | MXT_COMMAND_BACKUPNV, |
| 874 | MXT_BACKUP_VALUE); |
| 875 | msleep(MXT_BACKUP_TIME); |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 876 | do { |
| 877 | error = mxt_read_object(data, MXT_GEN_COMMAND, |
| 878 | MXT_COMMAND_BACKUPNV, |
| 879 | &command_register); |
| 880 | if (error) |
| 881 | return error; |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 882 | usleep_range(1000, 2000); |
| 883 | } while ((command_register != 0) && (++timeout_counter <= 100)); |
| 884 | if (timeout_counter > 100) { |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 885 | dev_err(&client->dev, "No response after backup!\n"); |
| 886 | return -EIO; |
| 887 | } |
| 888 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 889 | |
| 890 | /* Soft reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 891 | mxt_write_object(data, MXT_GEN_COMMAND, |
| 892 | MXT_COMMAND_RESET, 1); |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 893 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 894 | mxt_reset_delay(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 895 | |
| 896 | /* Update matrix size at info struct */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 897 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 898 | if (error) |
| 899 | return error; |
| 900 | info->matrix_xsize = val; |
| 901 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 902 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 903 | if (error) |
| 904 | return error; |
| 905 | info->matrix_ysize = val; |
| 906 | |
| 907 | dev_info(&client->dev, |
| 908 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", |
| 909 | info->family_id, info->variant_id, info->version, |
| 910 | info->build); |
| 911 | |
| 912 | dev_info(&client->dev, |
| 913 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", |
| 914 | info->matrix_xsize, info->matrix_ysize, |
| 915 | info->object_num); |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 920 | static void mxt_calc_resolution(struct mxt_data *data) |
| 921 | { |
| 922 | unsigned int max_x = data->pdata->x_size - 1; |
| 923 | unsigned int max_y = data->pdata->y_size - 1; |
| 924 | |
| 925 | if (data->pdata->orient & MXT_XY_SWITCH) { |
| 926 | data->max_x = max_y; |
| 927 | data->max_y = max_x; |
| 928 | } else { |
| 929 | data->max_x = max_x; |
| 930 | data->max_y = max_y; |
| 931 | } |
| 932 | } |
| 933 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 934 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 935 | struct device_attribute *attr, char *buf) |
| 936 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 937 | struct mxt_data *data = dev_get_drvdata(dev); |
| 938 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 939 | int count = 0; |
| 940 | int i, j; |
| 941 | int error; |
| 942 | u8 val; |
| 943 | |
| 944 | for (i = 0; i < data->info.object_num; i++) { |
| 945 | object = data->object_table + i; |
| 946 | |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame^] | 947 | count += snprintf(buf + count, MXT_BUFF_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 948 | "Object Table Element %d(Type %d)\n", |
| 949 | i + 1, object->type); |
| 950 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 951 | if (!mxt_object_readable(object->type)) { |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame^] | 952 | count += snprintf(buf + count, MXT_BUFF_SIZE, "\n"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 953 | continue; |
| 954 | } |
| 955 | |
| 956 | for (j = 0; j < object->size + 1; j++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 957 | error = mxt_read_object(data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 958 | object->type, j, &val); |
| 959 | if (error) |
| 960 | return error; |
| 961 | |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame^] | 962 | count += snprintf(buf + count, MXT_BUFF_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 963 | " Byte %d: 0x%x (%d)\n", j, val, val); |
| 964 | } |
| 965 | |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame^] | 966 | count += snprintf(buf + count, MXT_BUFF_SIZE, "\n"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | return count; |
| 970 | } |
| 971 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 972 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 973 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 974 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 975 | struct i2c_client *client = data->client; |
| 976 | const struct firmware *fw = NULL; |
| 977 | unsigned int frame_size; |
| 978 | unsigned int pos = 0; |
| 979 | int ret; |
| 980 | |
| 981 | ret = request_firmware(&fw, fn, dev); |
| 982 | if (ret) { |
| 983 | dev_err(dev, "Unable to open firmware %s\n", fn); |
| 984 | return ret; |
| 985 | } |
| 986 | |
| 987 | /* Change to the bootloader mode */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 988 | mxt_write_object(data, MXT_GEN_COMMAND, |
| 989 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 990 | |
| 991 | mxt_reset_delay(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 992 | |
| 993 | /* Change to slave address of bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 994 | if (client->addr == MXT_APP_LOW) |
| 995 | client->addr = MXT_BOOT_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 996 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 997 | client->addr = MXT_BOOT_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 998 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 999 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1000 | if (ret) |
| 1001 | goto out; |
| 1002 | |
| 1003 | /* Unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1004 | mxt_unlock_bootloader(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1005 | |
| 1006 | while (pos < fw->size) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1007 | ret = mxt_check_bootloader(client, |
| 1008 | MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1009 | if (ret) |
| 1010 | goto out; |
| 1011 | |
| 1012 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); |
| 1013 | |
| 1014 | /* We should add 2 at frame size as the the firmware data is not |
| 1015 | * included the CRC bytes. |
| 1016 | */ |
| 1017 | frame_size += 2; |
| 1018 | |
| 1019 | /* Write one frame to device */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1020 | mxt_fw_write(client, fw->data + pos, frame_size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1021 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1022 | ret = mxt_check_bootloader(client, |
| 1023 | MXT_FRAME_CRC_PASS); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1024 | if (ret) |
| 1025 | goto out; |
| 1026 | |
| 1027 | pos += frame_size; |
| 1028 | |
| 1029 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); |
| 1030 | } |
| 1031 | |
| 1032 | out: |
| 1033 | release_firmware(fw); |
| 1034 | |
| 1035 | /* Change to slave address of application */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1036 | if (client->addr == MXT_BOOT_LOW) |
| 1037 | client->addr = MXT_APP_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1038 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1039 | client->addr = MXT_APP_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1040 | |
| 1041 | return ret; |
| 1042 | } |
| 1043 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1044 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1045 | struct device_attribute *attr, |
| 1046 | const char *buf, size_t count) |
| 1047 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1048 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1049 | int error; |
| 1050 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1051 | disable_irq(data->irq); |
| 1052 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1053 | error = mxt_load_fw(dev, MXT_FW_NAME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1054 | if (error) { |
| 1055 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 1056 | count = error; |
| 1057 | } else { |
| 1058 | dev_dbg(dev, "The firmware update succeeded\n"); |
| 1059 | |
| 1060 | /* Wait for reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1061 | msleep(MXT_FWRESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1062 | |
| 1063 | kfree(data->object_table); |
| 1064 | data->object_table = NULL; |
| 1065 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1066 | mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | enable_irq(data->irq); |
| 1070 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1071 | error = mxt_make_highchg(data); |
| 1072 | if (error) |
| 1073 | return error; |
| 1074 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1075 | return count; |
| 1076 | } |
| 1077 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1078 | static DEVICE_ATTR(object, 0444, mxt_object_show, NULL); |
| 1079 | static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1080 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1081 | static struct attribute *mxt_attrs[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1082 | &dev_attr_object.attr, |
| 1083 | &dev_attr_update_fw.attr, |
| 1084 | NULL |
| 1085 | }; |
| 1086 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1087 | static const struct attribute_group mxt_attr_group = { |
| 1088 | .attrs = mxt_attrs, |
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 void mxt_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1092 | { |
| 1093 | /* Touch enable */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1094 | mxt_write_object(data, |
| 1095 | MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0x83); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1098 | static void mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1099 | { |
| 1100 | /* Touch disable */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1101 | mxt_write_object(data, |
| 1102 | MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1105 | static int mxt_input_open(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); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1108 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1109 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1114 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1115 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1116 | struct mxt_data *data = input_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1117 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1118 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1121 | static int mxt_power_on(struct mxt_data *data, bool on) |
| 1122 | { |
| 1123 | int rc; |
| 1124 | |
| 1125 | if (on == false) |
| 1126 | goto power_off; |
| 1127 | |
| 1128 | rc = regulator_set_optimum_mode(data->vcc, MXT_ACTIVE_LOAD_UA); |
| 1129 | if (rc < 0) { |
| 1130 | dev_err(&data->client->dev, "Regulator set_opt failed rc=%d\n", |
| 1131 | rc); |
| 1132 | return rc; |
| 1133 | } |
| 1134 | |
| 1135 | rc = regulator_enable(data->vcc); |
| 1136 | if (rc) { |
| 1137 | dev_err(&data->client->dev, "Regulator enable failed rc=%d\n", |
| 1138 | rc); |
| 1139 | goto error_reg_en_vcc; |
| 1140 | } |
| 1141 | |
| 1142 | if (data->pdata->i2c_pull_up) { |
| 1143 | rc = regulator_set_optimum_mode(data->vcc_i2c, MXT_I2C_LOAD_UA); |
| 1144 | if (rc < 0) { |
| 1145 | dev_err(&data->client->dev, |
| 1146 | "Regulator set_opt failed rc=%d\n", rc); |
| 1147 | goto error_reg_opt_i2c; |
| 1148 | } |
| 1149 | |
| 1150 | rc = regulator_enable(data->vcc_i2c); |
| 1151 | if (rc) { |
| 1152 | dev_err(&data->client->dev, |
| 1153 | "Regulator enable failed rc=%d\n", rc); |
| 1154 | goto error_reg_en_vcc_i2c; |
| 1155 | } |
| 1156 | } |
| 1157 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1158 | msleep(100); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1159 | |
| 1160 | return 0; |
| 1161 | |
| 1162 | error_reg_en_vcc_i2c: |
| 1163 | if (data->pdata->i2c_pull_up) |
| 1164 | regulator_set_optimum_mode(data->vcc_i2c, 0); |
| 1165 | error_reg_opt_i2c: |
| 1166 | regulator_disable(data->vcc); |
| 1167 | error_reg_en_vcc: |
| 1168 | regulator_set_optimum_mode(data->vcc, 0); |
| 1169 | return rc; |
| 1170 | |
| 1171 | power_off: |
| 1172 | regulator_set_optimum_mode(data->vcc, 0); |
| 1173 | regulator_disable(data->vcc); |
| 1174 | if (data->pdata->i2c_pull_up) { |
| 1175 | regulator_set_optimum_mode(data->vcc_i2c, 0); |
| 1176 | regulator_disable(data->vcc_i2c); |
| 1177 | } |
| 1178 | msleep(50); |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | static int mxt_regulator_configure(struct mxt_data *data, bool on) |
| 1183 | { |
| 1184 | int rc; |
| 1185 | |
| 1186 | if (on == false) |
| 1187 | goto hw_shutdown; |
| 1188 | |
| 1189 | data->vcc = regulator_get(&data->client->dev, "vdd"); |
| 1190 | if (IS_ERR(data->vcc)) { |
| 1191 | rc = PTR_ERR(data->vcc); |
| 1192 | dev_err(&data->client->dev, "Regulator get failed rc=%d\n", |
| 1193 | rc); |
| 1194 | return rc; |
| 1195 | } |
| 1196 | |
| 1197 | if (regulator_count_voltages(data->vcc) > 0) { |
| 1198 | rc = regulator_set_voltage(data->vcc, MXT_VTG_MIN_UV, |
| 1199 | MXT_VTG_MAX_UV); |
| 1200 | if (rc) { |
| 1201 | dev_err(&data->client->dev, |
| 1202 | "regulator set_vtg failed rc=%d\n", rc); |
| 1203 | goto error_set_vtg_vcc; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | if (data->pdata->i2c_pull_up) { |
| 1208 | data->vcc_i2c = regulator_get(&data->client->dev, "vcc_i2c"); |
| 1209 | if (IS_ERR(data->vcc_i2c)) { |
| 1210 | rc = PTR_ERR(data->vcc_i2c); |
| 1211 | dev_err(&data->client->dev, |
| 1212 | "Regulator get failed rc=%d\n", rc); |
| 1213 | goto error_get_vtg_i2c; |
| 1214 | } |
| 1215 | if (regulator_count_voltages(data->vcc_i2c) > 0) { |
| 1216 | rc = regulator_set_voltage(data->vcc_i2c, |
| 1217 | MXT_I2C_VTG_MIN_UV, MXT_I2C_VTG_MAX_UV); |
| 1218 | if (rc) { |
| 1219 | dev_err(&data->client->dev, |
| 1220 | "regulator set_vtg failed rc=%d\n", rc); |
| 1221 | goto error_set_vtg_i2c; |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | return 0; |
| 1227 | |
| 1228 | error_set_vtg_i2c: |
| 1229 | regulator_put(data->vcc_i2c); |
| 1230 | error_get_vtg_i2c: |
| 1231 | if (regulator_count_voltages(data->vcc) > 0) |
| 1232 | regulator_set_voltage(data->vcc, 0, MXT_VTG_MAX_UV); |
| 1233 | error_set_vtg_vcc: |
| 1234 | regulator_put(data->vcc); |
| 1235 | return rc; |
| 1236 | |
| 1237 | hw_shutdown: |
| 1238 | if (regulator_count_voltages(data->vcc) > 0) |
| 1239 | regulator_set_voltage(data->vcc, 0, MXT_VTG_MAX_UV); |
| 1240 | regulator_put(data->vcc); |
| 1241 | if (data->pdata->i2c_pull_up) { |
| 1242 | if (regulator_count_voltages(data->vcc_i2c) > 0) |
| 1243 | regulator_set_voltage(data->vcc_i2c, 0, |
| 1244 | MXT_I2C_VTG_MAX_UV); |
| 1245 | regulator_put(data->vcc_i2c); |
| 1246 | } |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1250 | #ifdef CONFIG_PM |
| 1251 | static int mxt_suspend(struct device *dev) |
| 1252 | { |
| 1253 | struct i2c_client *client = to_i2c_client(dev); |
| 1254 | struct mxt_data *data = i2c_get_clientdata(client); |
| 1255 | struct input_dev *input_dev = data->input_dev; |
| 1256 | |
| 1257 | mutex_lock(&input_dev->mutex); |
| 1258 | |
| 1259 | if (input_dev->users) |
| 1260 | mxt_stop(data); |
| 1261 | |
| 1262 | mutex_unlock(&input_dev->mutex); |
| 1263 | |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
| 1267 | static int mxt_resume(struct device *dev) |
| 1268 | { |
| 1269 | struct i2c_client *client = to_i2c_client(dev); |
| 1270 | struct mxt_data *data = i2c_get_clientdata(client); |
| 1271 | struct input_dev *input_dev = data->input_dev; |
| 1272 | |
| 1273 | /* Soft reset */ |
| 1274 | mxt_write_object(data, MXT_GEN_COMMAND, |
| 1275 | MXT_COMMAND_RESET, 1); |
| 1276 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1277 | mxt_reset_delay(data); |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1278 | |
| 1279 | mutex_lock(&input_dev->mutex); |
| 1280 | |
| 1281 | if (input_dev->users) |
| 1282 | mxt_start(data); |
| 1283 | |
| 1284 | mutex_unlock(&input_dev->mutex); |
| 1285 | |
| 1286 | return 0; |
| 1287 | } |
| 1288 | |
| 1289 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1290 | static void mxt_early_suspend(struct early_suspend *h) |
| 1291 | { |
| 1292 | struct mxt_data *data = container_of(h, struct mxt_data, early_suspend); |
| 1293 | |
| 1294 | mxt_suspend(&data->client->dev); |
| 1295 | } |
| 1296 | |
| 1297 | static void mxt_late_resume(struct early_suspend *h) |
| 1298 | { |
| 1299 | struct mxt_data *data = container_of(h, struct mxt_data, early_suspend); |
| 1300 | |
| 1301 | mxt_resume(&data->client->dev); |
| 1302 | } |
| 1303 | #endif |
| 1304 | |
| 1305 | static const struct dev_pm_ops mxt_pm_ops = { |
| 1306 | #ifndef CONFIG_HAS_EARLYSUSPEND |
| 1307 | .suspend = mxt_suspend, |
| 1308 | .resume = mxt_resume, |
| 1309 | #endif |
| 1310 | }; |
| 1311 | #endif |
| 1312 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1313 | static int __devinit mxt_probe(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1314 | const struct i2c_device_id *id) |
| 1315 | { |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1316 | const struct mxt_platform_data *pdata = client->dev.platform_data; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1317 | struct mxt_data *data; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1318 | struct input_dev *input_dev; |
| 1319 | int error; |
| 1320 | |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1321 | if (!pdata) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1322 | return -EINVAL; |
| 1323 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1324 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1325 | input_dev = input_allocate_device(); |
| 1326 | if (!data || !input_dev) { |
| 1327 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1328 | error = -ENOMEM; |
| 1329 | goto err_free_mem; |
| 1330 | } |
| 1331 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1332 | input_dev->name = "Atmel maXTouch Touchscreen"; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1333 | input_dev->id.bustype = BUS_I2C; |
| 1334 | input_dev->dev.parent = &client->dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1335 | input_dev->open = mxt_input_open; |
| 1336 | input_dev->close = mxt_input_close; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1337 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1338 | data->client = client; |
| 1339 | data->input_dev = input_dev; |
| 1340 | data->pdata = pdata; |
| 1341 | data->irq = client->irq; |
| 1342 | |
| 1343 | mxt_calc_resolution(data); |
| 1344 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1345 | __set_bit(EV_ABS, input_dev->evbit); |
| 1346 | __set_bit(EV_KEY, input_dev->evbit); |
| 1347 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 1348 | |
| 1349 | /* For single touch */ |
| 1350 | input_set_abs_params(input_dev, ABS_X, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1351 | 0, data->max_x, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1352 | input_set_abs_params(input_dev, ABS_Y, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1353 | 0, data->max_y, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1354 | |
| 1355 | /* For multi touch */ |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 1356 | input_mt_init_slots(input_dev, MXT_MAX_FINGER); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1357 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1358 | 0, MXT_MAX_AREA, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1359 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1360 | 0, data->max_x, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1361 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1362 | 0, data->max_y, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1363 | |
| 1364 | input_set_drvdata(input_dev, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1365 | i2c_set_clientdata(client, data); |
| 1366 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1367 | if (pdata->init_hw) |
| 1368 | error = pdata->init_hw(true); |
| 1369 | else |
| 1370 | error = mxt_regulator_configure(data, true); |
| 1371 | if (error) { |
| 1372 | dev_err(&client->dev, "Failed to intialize hardware\n"); |
| 1373 | goto err_free_object; |
| 1374 | } |
| 1375 | |
| 1376 | if (pdata->power_on) |
| 1377 | error = pdata->power_on(true); |
| 1378 | else |
| 1379 | error = mxt_power_on(data, true); |
| 1380 | if (error) { |
| 1381 | dev_err(&client->dev, "Failed to power on hardware\n"); |
| 1382 | goto err_regulator_on; |
| 1383 | } |
| 1384 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1385 | error = mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1386 | if (error) |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1387 | goto err_power_on; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1388 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1389 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1390 | pdata->irqflags, client->dev.driver->name, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1391 | if (error) { |
| 1392 | dev_err(&client->dev, "Failed to register interrupt\n"); |
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 | } |
| 1395 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1396 | error = mxt_make_highchg(data); |
| 1397 | if (error) |
| 1398 | goto err_free_irq; |
| 1399 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1400 | error = input_register_device(input_dev); |
| 1401 | if (error) |
| 1402 | goto err_free_irq; |
| 1403 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1404 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1405 | if (error) |
| 1406 | goto err_unregister_device; |
| 1407 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1408 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1409 | data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + |
| 1410 | MXT_SUSPEND_LEVEL; |
| 1411 | data->early_suspend.suspend = mxt_early_suspend; |
| 1412 | data->early_suspend.resume = mxt_late_resume; |
| 1413 | register_early_suspend(&data->early_suspend); |
| 1414 | #endif |
| 1415 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1416 | return 0; |
| 1417 | |
| 1418 | err_unregister_device: |
| 1419 | input_unregister_device(input_dev); |
| 1420 | input_dev = NULL; |
| 1421 | err_free_irq: |
| 1422 | free_irq(client->irq, data); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1423 | err_power_on: |
| 1424 | if (pdata->power_on) |
| 1425 | pdata->power_on(false); |
| 1426 | else |
| 1427 | mxt_power_on(data, false); |
| 1428 | err_regulator_on: |
| 1429 | if (pdata->init_hw) |
| 1430 | pdata->init_hw(false); |
| 1431 | else |
| 1432 | mxt_regulator_configure(data, false); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1433 | err_free_object: |
| 1434 | kfree(data->object_table); |
| 1435 | err_free_mem: |
| 1436 | input_free_device(input_dev); |
| 1437 | kfree(data); |
| 1438 | return error; |
| 1439 | } |
| 1440 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1441 | static int __devexit mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1442 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1443 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1444 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1445 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1446 | free_irq(data->irq, data); |
| 1447 | input_unregister_device(data->input_dev); |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1448 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1449 | unregister_early_suspend(&data->early_suspend); |
| 1450 | #endif |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1451 | |
| 1452 | if (data->pdata->power_on) |
| 1453 | data->pdata->power_on(false); |
| 1454 | else |
| 1455 | mxt_power_on(data, false); |
| 1456 | |
| 1457 | if (data->pdata->init_hw) |
| 1458 | data->pdata->init_hw(false); |
| 1459 | else |
| 1460 | mxt_regulator_configure(data, false); |
| 1461 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1462 | kfree(data->object_table); |
| 1463 | kfree(data); |
| 1464 | |
| 1465 | return 0; |
| 1466 | } |
| 1467 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1468 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1469 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1470 | { "atmel_mxt_ts", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1471 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1472 | { } |
| 1473 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1474 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1475 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1476 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1477 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1478 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1479 | .owner = THIS_MODULE, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1480 | #ifdef CONFIG_PM |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1481 | .pm = &mxt_pm_ops, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1482 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1483 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1484 | .probe = mxt_probe, |
| 1485 | .remove = __devexit_p(mxt_remove), |
| 1486 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1487 | }; |
| 1488 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1489 | static int __init mxt_init(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1490 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1491 | return i2c_add_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1494 | static void __exit mxt_exit(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1495 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1496 | i2c_del_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1499 | module_init(mxt_init); |
| 1500 | module_exit(mxt_exit); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1501 | |
| 1502 | /* Module information */ |
| 1503 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1504 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1505 | MODULE_LICENSE("GPL"); |