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