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