blob: 9555947a2d4677cc710f84597579ce4aed34f79b [file] [log] [blame]
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001/*
Iiro Valkonen7686b102011-02-02 23:21:58 -08002 * Atmel maXTouch Touchscreen driver
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
Nick Dyer50a77c62014-07-23 12:38:48 -07005 * Copyright (C) 2011-2014 Atmel Corporation
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07006 * Copyright (C) 2012 Google, Inc.
Nick Dyerf3c4a8f2016-09-15 17:30:43 -03007 * Copyright (C) 2016 Zodiac Inflight Innovations
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07008 *
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07009 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
Dmitry Torokhov4f8d8082015-04-07 16:30:01 -070018#include <linux/acpi.h>
19#include <linux/dmi.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070020#include <linux/module.h>
Benson Leungd79e7e42014-05-18 23:02:52 -070021#include <linux/init.h>
22#include <linux/completion.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070023#include <linux/delay.h>
24#include <linux/firmware.h>
25#include <linux/i2c.h>
Joonyoung Shim8b86c1c2011-04-12 23:18:59 -070026#include <linux/input/mt.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070027#include <linux/interrupt.h>
Stephen Warren78188be2014-07-23 12:23:23 -070028#include <linux/of.h>
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -070029#include <linux/property.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070030#include <linux/slab.h>
Sebastian Reichelf657b002017-07-25 14:11:34 -070031#include <linux/gpio/consumer.h>
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -070032#include <linux/property.h>
Nick Dyerb23157d2015-04-06 11:25:13 -070033#include <asm/unaligned.h>
Nick Dyerecfdd7e2016-07-18 18:10:32 -030034#include <media/v4l2-device.h>
35#include <media/v4l2-ioctl.h>
36#include <media/videobuf2-v4l2.h>
37#include <media/videobuf2-vmalloc.h>
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070038
Nick Dyer50a77c62014-07-23 12:38:48 -070039/* Firmware files */
Iiro Valkonen7686b102011-02-02 23:21:58 -080040#define MXT_FW_NAME "maxtouch.fw"
Nick Dyer50a77c62014-07-23 12:38:48 -070041#define MXT_CFG_NAME "maxtouch.cfg"
42#define MXT_CFG_MAGIC "OBP_RAW V1"
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070043
44/* Registers */
Iiro Valkonen7686b102011-02-02 23:21:58 -080045#define MXT_OBJECT_START 0x07
Iiro Valkonen7686b102011-02-02 23:21:58 -080046#define MXT_OBJECT_SIZE 6
Nick Dyer4ce6fa02014-07-23 12:40:09 -070047#define MXT_INFO_CHECKSUM_SIZE 3
48#define MXT_MAX_BLOCK_WRITE 256
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070049
50/* Object types */
Iiro Valkonen81c88a72011-07-04 03:08:25 -070051#define MXT_DEBUG_DIAGNOSTIC_T37 37
52#define MXT_GEN_MESSAGE_T5 5
53#define MXT_GEN_COMMAND_T6 6
54#define MXT_GEN_POWER_T7 7
55#define MXT_GEN_ACQUIRE_T8 8
56#define MXT_GEN_DATASOURCE_T53 53
57#define MXT_TOUCH_MULTI_T9 9
58#define MXT_TOUCH_KEYARRAY_T15 15
59#define MXT_TOUCH_PROXIMITY_T23 23
60#define MXT_TOUCH_PROXKEY_T52 52
61#define MXT_PROCI_GRIPFACE_T20 20
62#define MXT_PROCG_NOISE_T22 22
63#define MXT_PROCI_ONETOUCH_T24 24
64#define MXT_PROCI_TWOTOUCH_T27 27
65#define MXT_PROCI_GRIP_T40 40
66#define MXT_PROCI_PALM_T41 41
67#define MXT_PROCI_TOUCHSUPPRESSION_T42 42
68#define MXT_PROCI_STYLUS_T47 47
69#define MXT_PROCG_NOISESUPPRESSION_T48 48
70#define MXT_SPT_COMMSCONFIG_T18 18
71#define MXT_SPT_GPIOPWM_T19 19
72#define MXT_SPT_SELFTEST_T25 25
73#define MXT_SPT_CTECONFIG_T28 28
74#define MXT_SPT_USERDATA_T38 38
75#define MXT_SPT_DIGITIZER_T43 43
76#define MXT_SPT_MESSAGECOUNT_T44 44
77#define MXT_SPT_CTECONFIG_T46 46
Nick Dyerb23157d2015-04-06 11:25:13 -070078#define MXT_TOUCH_MULTITOUCHSCREEN_T100 100
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070079
Nick Dyer5f3f9bc2014-07-23 12:46:55 -070080/* MXT_GEN_MESSAGE_T5 object */
81#define MXT_RPTID_NOMSG 0xff
82
Iiro Valkonen81c88a72011-07-04 03:08:25 -070083/* MXT_GEN_COMMAND_T6 field */
Iiro Valkonen7686b102011-02-02 23:21:58 -080084#define MXT_COMMAND_RESET 0
85#define MXT_COMMAND_BACKUPNV 1
86#define MXT_COMMAND_CALIBRATE 2
87#define MXT_COMMAND_REPORTALL 3
88#define MXT_COMMAND_DIAGNOSTIC 5
Joonyoung Shim4cf51c32010-07-14 21:55:30 -070089
Iiro Valkonena4a2ef42014-05-18 23:03:44 -070090/* Define for T6 status byte */
Nick Dyer204b4ea2018-07-27 11:44:41 -070091#define MXT_T6_STATUS_RESET BIT(7)
92#define MXT_T6_STATUS_OFL BIT(6)
93#define MXT_T6_STATUS_SIGERR BIT(5)
94#define MXT_T6_STATUS_CAL BIT(4)
95#define MXT_T6_STATUS_CFGERR BIT(3)
96#define MXT_T6_STATUS_COMSERR BIT(2)
Iiro Valkonena4a2ef42014-05-18 23:03:44 -070097
Iiro Valkonen81c88a72011-07-04 03:08:25 -070098/* MXT_GEN_POWER_T7 field */
Nick Dyer7f3884f72015-08-04 16:36:29 -070099struct t7_config {
100 u8 idle;
101 u8 active;
102} __packed;
103
104#define MXT_POWER_CFG_RUN 0
105#define MXT_POWER_CFG_DEEPSLEEP 1
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700106
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700107/* MXT_TOUCH_MULTI_T9 field */
Nick Dyer7f3884f72015-08-04 16:36:29 -0700108#define MXT_T9_CTRL 0
Nick Dyer27864892016-07-18 18:10:33 -0300109#define MXT_T9_XSIZE 3
110#define MXT_T9_YSIZE 4
Nick Dyer61dc1ab2014-05-18 23:16:49 -0700111#define MXT_T9_ORIENT 9
112#define MXT_T9_RANGE 18
113
Nick Dyerf3889ed2014-05-18 23:22:04 -0700114/* MXT_TOUCH_MULTI_T9 status */
Nick Dyer204b4ea2018-07-27 11:44:41 -0700115#define MXT_T9_UNGRIP BIT(0)
116#define MXT_T9_SUPPRESS BIT(1)
117#define MXT_T9_AMP BIT(2)
118#define MXT_T9_VECTOR BIT(3)
119#define MXT_T9_MOVE BIT(4)
120#define MXT_T9_RELEASE BIT(5)
121#define MXT_T9_PRESS BIT(6)
122#define MXT_T9_DETECT BIT(7)
Nick Dyerf3889ed2014-05-18 23:22:04 -0700123
Nick Dyer61dc1ab2014-05-18 23:16:49 -0700124struct t9_range {
Nick Dyer1c0276d2016-01-10 18:29:34 -0800125 __le16 x;
126 __le16 y;
Nick Dyer61dc1ab2014-05-18 23:16:49 -0700127} __packed;
128
Nick Dyerf3889ed2014-05-18 23:22:04 -0700129/* MXT_TOUCH_MULTI_T9 orient */
Nick Dyer204b4ea2018-07-27 11:44:41 -0700130#define MXT_T9_ORIENT_SWITCH BIT(0)
131#define MXT_T9_ORIENT_INVERTX BIT(1)
132#define MXT_T9_ORIENT_INVERTY BIT(2)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700133
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700134/* MXT_SPT_COMMSCONFIG_T18 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800135#define MXT_COMMS_CTRL 0
136#define MXT_COMMS_CMD 1
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700137
Nick Dyerd6a39402016-07-18 18:10:31 -0300138/* MXT_DEBUG_DIAGNOSTIC_T37 */
139#define MXT_DIAGNOSTIC_PAGEUP 0x01
140#define MXT_DIAGNOSTIC_DELTAS 0x10
Nick Dyer06b3d3f2016-07-18 18:10:36 -0300141#define MXT_DIAGNOSTIC_REFS 0x11
Nick Dyerd6a39402016-07-18 18:10:31 -0300142#define MXT_DIAGNOSTIC_SIZE 128
143
Nick Dyer566d5332016-07-18 18:10:35 -0300144#define MXT_FAMILY_1386 160
145#define MXT1386_COLUMNS 3
146#define MXT1386_PAGES_PER_COLUMN 8
147
Nick Dyerd6a39402016-07-18 18:10:31 -0300148struct t37_debug {
149#ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37
150 u8 mode;
151 u8 page;
152 u8 data[MXT_DIAGNOSTIC_SIZE];
153#endif
154};
155
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700156/* Define for MXT_GEN_COMMAND_T6 */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800157#define MXT_BOOT_VALUE 0xa5
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700158#define MXT_RESET_VALUE 0x01
Iiro Valkonen7686b102011-02-02 23:21:58 -0800159#define MXT_BACKUP_VALUE 0x55
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700160
Nick Dyerb23157d2015-04-06 11:25:13 -0700161/* T100 Multiple Touch Touchscreen */
162#define MXT_T100_CTRL 0
163#define MXT_T100_CFG1 1
164#define MXT_T100_TCHAUX 3
Nick Dyer27864892016-07-18 18:10:33 -0300165#define MXT_T100_XSIZE 9
Nick Dyerb23157d2015-04-06 11:25:13 -0700166#define MXT_T100_XRANGE 13
Nick Dyer27864892016-07-18 18:10:33 -0300167#define MXT_T100_YSIZE 20
Nick Dyerb23157d2015-04-06 11:25:13 -0700168#define MXT_T100_YRANGE 24
169
170#define MXT_T100_CFG_SWITCHXY BIT(5)
Nick Dyerde601f72016-07-18 18:10:34 -0300171#define MXT_T100_CFG_INVERTY BIT(6)
172#define MXT_T100_CFG_INVERTX BIT(7)
Nick Dyerb23157d2015-04-06 11:25:13 -0700173
174#define MXT_T100_TCHAUX_VECT BIT(0)
175#define MXT_T100_TCHAUX_AMPL BIT(1)
176#define MXT_T100_TCHAUX_AREA BIT(2)
177
178#define MXT_T100_DETECT BIT(7)
179#define MXT_T100_TYPE_MASK 0x70
180
181enum t100_type {
182 MXT_T100_TYPE_FINGER = 1,
183 MXT_T100_TYPE_PASSIVE_STYLUS = 2,
184 MXT_T100_TYPE_HOVERING_FINGER = 4,
185 MXT_T100_TYPE_GLOVE = 5,
186 MXT_T100_TYPE_LARGE_TOUCH = 6,
187};
188
189#define MXT_DISTANCE_ACTIVE_TOUCH 0
190#define MXT_DISTANCE_HOVERING 1
191
192#define MXT_TOUCH_MAJOR_DEFAULT 1
193#define MXT_PRESSURE_DEFAULT 1
194
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700195/* Delay times */
Linus Torvalds8343bce2013-03-09 10:31:01 -0800196#define MXT_BACKUP_TIME 50 /* msec */
Sebastian Reichelca1cd362018-05-24 09:33:36 -0700197#define MXT_RESET_GPIO_TIME 20 /* msec */
198#define MXT_RESET_INVALID_CHG 100 /* msec */
Linus Torvalds8343bce2013-03-09 10:31:01 -0800199#define MXT_RESET_TIME 200 /* msec */
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700200#define MXT_RESET_TIMEOUT 3000 /* msec */
Nick Dyerc3f78042014-05-18 23:04:46 -0700201#define MXT_CRC_TIMEOUT 1000 /* msec */
Benson Leunga0434b72014-05-18 23:03:09 -0700202#define MXT_FW_RESET_TIME 3000 /* msec */
203#define MXT_FW_CHG_TIMEOUT 300 /* msec */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700204
205/* Command to unlock bootloader */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800206#define MXT_UNLOCK_CMD_MSB 0xaa
207#define MXT_UNLOCK_CMD_LSB 0xdc
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700208
209/* Bootloader mode status */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800210#define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
211#define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
212#define MXT_FRAME_CRC_CHECK 0x02
213#define MXT_FRAME_CRC_FAIL 0x03
214#define MXT_FRAME_CRC_PASS 0x04
215#define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
216#define MXT_BOOT_STATUS_MASK 0x3f
Nick Dyer204b4ea2018-07-27 11:44:41 -0700217#define MXT_BOOT_EXTENDED_ID BIT(5)
Nick Dyere57a66a2014-05-18 23:13:40 -0700218#define MXT_BOOT_ID_MASK 0x1f
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700219
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700220/* Touchscreen absolute values */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800221#define MXT_MAX_AREA 0xff
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700222
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800223#define MXT_PIXELS_PER_MM 20
224
Iiro Valkonen7686b102011-02-02 23:21:58 -0800225struct mxt_info {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700226 u8 family_id;
227 u8 variant_id;
228 u8 version;
229 u8 build;
230 u8 matrix_xsize;
231 u8 matrix_ysize;
232 u8 object_num;
233};
234
Iiro Valkonen7686b102011-02-02 23:21:58 -0800235struct mxt_object {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700236 u8 type;
237 u16 start_address;
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -0700238 u8 size_minus_one;
239 u8 instances_minus_one;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700240 u8 num_report_ids;
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800241} __packed;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700242
Nick Dyerd6a39402016-07-18 18:10:31 -0300243struct mxt_dbg {
244 u16 t37_address;
245 u16 diag_cmd_address;
246 struct t37_debug *t37_buf;
247 unsigned int t37_pages;
248 unsigned int t37_nodes;
Nick Dyerecfdd7e2016-07-18 18:10:32 -0300249
250 struct v4l2_device v4l2;
251 struct v4l2_pix_format format;
252 struct video_device vdev;
253 struct vb2_queue queue;
254 struct mutex lock;
255 int input;
256};
257
Nick Dyer06b3d3f2016-07-18 18:10:36 -0300258enum v4l_dbg_inputs {
259 MXT_V4L_INPUT_DELTAS,
260 MXT_V4L_INPUT_REFS,
261 MXT_V4L_INPUT_MAX,
262};
263
Nick Dyerecfdd7e2016-07-18 18:10:32 -0300264static const struct v4l2_file_operations mxt_video_fops = {
265 .owner = THIS_MODULE,
266 .open = v4l2_fh_open,
267 .release = vb2_fop_release,
268 .unlocked_ioctl = video_ioctl2,
269 .read = vb2_fop_read,
270 .mmap = vb2_fop_mmap,
271 .poll = vb2_fop_poll,
Nick Dyerd6a39402016-07-18 18:10:31 -0300272};
273
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -0700274enum mxt_suspend_mode {
275 MXT_SUSPEND_DEEP_SLEEP = 0,
276 MXT_SUSPEND_T9_CTRL = 1,
277};
278
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700279/* Each client has this additional data */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800280struct mxt_data {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700281 struct i2c_client *client;
282 struct input_dev *input_dev;
Daniel Kurtzec02ac22012-06-28 21:08:02 +0800283 char phys[64]; /* device physical location */
Iiro Valkonen7686b102011-02-02 23:21:58 -0800284 struct mxt_object *object_table;
Nick Dyer068bdb62018-05-01 11:40:18 -0700285 struct mxt_info *info;
286 void *raw_info_block;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700287 unsigned int irq;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700288 unsigned int max_x;
289 unsigned int max_y;
Nick Dyerde601f72016-07-18 18:10:34 -0300290 bool invertx;
291 bool inverty;
Nick Dyer1c0276d2016-01-10 18:29:34 -0800292 bool xy_switch;
Nick Dyer27864892016-07-18 18:10:33 -0300293 u8 xsize;
294 u8 ysize;
Benson Leungd79e7e42014-05-18 23:02:52 -0700295 bool in_bootloader;
Nick Dyer4ce6fa02014-07-23 12:40:09 -0700296 u16 mem_size;
Nick Dyerb23157d2015-04-06 11:25:13 -0700297 u8 t100_aux_ampl;
298 u8 t100_aux_area;
299 u8 t100_aux_vect;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -0700300 u8 max_reportid;
Nick Dyerc3f78042014-05-18 23:04:46 -0700301 u32 config_crc;
Nick Dyer4ce6fa02014-07-23 12:40:09 -0700302 u32 info_crc;
Nick Dyerf28a8422014-05-18 23:10:49 -0700303 u8 bootloader_addr;
Nick Dyer5f3f9bc2014-07-23 12:46:55 -0700304 u8 *msg_buf;
Nick Dyer497767d2014-07-23 12:47:50 -0700305 u8 t6_status;
Nick Dyerb9b05a82014-07-23 12:48:13 -0700306 bool update_input;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -0700307 u8 last_message_count;
308 u8 num_touchids;
Nick Dyerb23157d2015-04-06 11:25:13 -0700309 u8 multitouch;
Nick Dyer7f3884f72015-08-04 16:36:29 -0700310 struct t7_config t7_cfg;
Nick Dyerd6a39402016-07-18 18:10:31 -0300311 struct mxt_dbg dbg;
Sebastian Reichelf657b002017-07-25 14:11:34 -0700312 struct gpio_desc *reset_gpio;
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800313
314 /* Cached parameters from object table */
Nick Dyerb9b05a82014-07-23 12:48:13 -0700315 u16 T5_address;
Nick Dyer5f3f9bc2014-07-23 12:46:55 -0700316 u8 T5_msg_size;
Daniel Kurtzfdf804212012-06-28 21:08:24 +0800317 u8 T6_reportid;
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700318 u16 T6_address;
Nick Dyer4ce6fa02014-07-23 12:40:09 -0700319 u16 T7_address;
Daniel Kurtz333e5a92012-06-28 21:08:20 +0800320 u8 T9_reportid_min;
321 u8 T9_reportid_max;
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800322 u8 T19_reportid;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -0700323 u16 T44_address;
Nick Dyerb23157d2015-04-06 11:25:13 -0700324 u8 T100_reportid_min;
325 u8 T100_reportid_max;
Benson Leungd79e7e42014-05-18 23:02:52 -0700326
327 /* for fw update in bootloader */
328 struct completion bl_completion;
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700329
330 /* for reset handling */
331 struct completion reset_completion;
Nick Dyerc3f78042014-05-18 23:04:46 -0700332
333 /* for config update handling */
334 struct completion crc_completion;
Dmitry Torokhovd80808e2018-03-20 15:31:25 -0700335
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -0700336 u32 *t19_keymap;
337 unsigned int t19_num_keys;
338
Dmitry Torokhovd80808e2018-03-20 15:31:25 -0700339 enum mxt_suspend_mode suspend_mode;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700340};
341
Nick Dyerecfdd7e2016-07-18 18:10:32 -0300342struct mxt_vb2_buffer {
343 struct vb2_buffer vb;
344 struct list_head list;
345};
346
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -0700347static size_t mxt_obj_size(const struct mxt_object *obj)
348{
349 return obj->size_minus_one + 1;
350}
351
352static size_t mxt_obj_instances(const struct mxt_object *obj)
353{
354 return obj->instances_minus_one + 1;
355}
356
Iiro Valkonen7686b102011-02-02 23:21:58 -0800357static bool mxt_object_readable(unsigned int type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700358{
359 switch (type) {
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700360 case MXT_GEN_COMMAND_T6:
361 case MXT_GEN_POWER_T7:
362 case MXT_GEN_ACQUIRE_T8:
363 case MXT_GEN_DATASOURCE_T53:
364 case MXT_TOUCH_MULTI_T9:
365 case MXT_TOUCH_KEYARRAY_T15:
366 case MXT_TOUCH_PROXIMITY_T23:
367 case MXT_TOUCH_PROXKEY_T52:
Maxime Roussin-Bélanger089b50d2017-05-19 14:59:03 -0700368 case MXT_TOUCH_MULTITOUCHSCREEN_T100:
Iiro Valkonen81c88a72011-07-04 03:08:25 -0700369 case MXT_PROCI_GRIPFACE_T20:
370 case MXT_PROCG_NOISE_T22:
371 case MXT_PROCI_ONETOUCH_T24:
372 case MXT_PROCI_TWOTOUCH_T27:
373 case MXT_PROCI_GRIP_T40:
374 case MXT_PROCI_PALM_T41:
375 case MXT_PROCI_TOUCHSUPPRESSION_T42:
376 case MXT_PROCI_STYLUS_T47:
377 case MXT_PROCG_NOISESUPPRESSION_T48:
378 case MXT_SPT_COMMSCONFIG_T18:
379 case MXT_SPT_GPIOPWM_T19:
380 case MXT_SPT_SELFTEST_T25:
381 case MXT_SPT_CTECONFIG_T28:
382 case MXT_SPT_USERDATA_T38:
383 case MXT_SPT_DIGITIZER_T43:
384 case MXT_SPT_CTECONFIG_T46:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700385 return true;
386 default:
387 return false;
388 }
389}
390
Nick Dyer5f3f9bc2014-07-23 12:46:55 -0700391static void mxt_dump_message(struct mxt_data *data, u8 *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700392{
Nick Dyer5f3f9bc2014-07-23 12:46:55 -0700393 dev_dbg(&data->client->dev, "message: %*ph\n",
394 data->T5_msg_size, message);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700395}
396
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700397static int mxt_wait_for_completion(struct mxt_data *data,
398 struct completion *comp,
399 unsigned int timeout_ms)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700400{
Benson Leungd79e7e42014-05-18 23:02:52 -0700401 struct device *dev = &data->client->dev;
Benson Leungd79e7e42014-05-18 23:02:52 -0700402 unsigned long timeout = msecs_to_jiffies(timeout_ms);
403 long ret;
404
405 ret = wait_for_completion_interruptible_timeout(comp, timeout);
406 if (ret < 0) {
407 return ret;
408 } else if (ret == 0) {
409 dev_err(dev, "Wait for completion timed out.\n");
410 return -ETIMEDOUT;
411 }
412 return 0;
413}
414
Nick Dyerf28a8422014-05-18 23:10:49 -0700415static int mxt_bootloader_read(struct mxt_data *data,
416 u8 *val, unsigned int count)
417{
418 int ret;
419 struct i2c_msg msg;
420
421 msg.addr = data->bootloader_addr;
422 msg.flags = data->client->flags & I2C_M_TEN;
423 msg.flags |= I2C_M_RD;
424 msg.len = count;
425 msg.buf = val;
426
427 ret = i2c_transfer(data->client->adapter, &msg, 1);
Nick Dyerf28a8422014-05-18 23:10:49 -0700428 if (ret == 1) {
429 ret = 0;
430 } else {
431 ret = ret < 0 ? ret : -EIO;
432 dev_err(&data->client->dev, "%s: i2c recv failed (%d)\n",
433 __func__, ret);
434 }
435
436 return ret;
437}
438
439static int mxt_bootloader_write(struct mxt_data *data,
440 const u8 * const val, unsigned int count)
441{
442 int ret;
443 struct i2c_msg msg;
444
445 msg.addr = data->bootloader_addr;
446 msg.flags = data->client->flags & I2C_M_TEN;
447 msg.len = count;
448 msg.buf = (u8 *)val;
449
450 ret = i2c_transfer(data->client->adapter, &msg, 1);
451 if (ret == 1) {
452 ret = 0;
453 } else {
454 ret = ret < 0 ? ret : -EIO;
455 dev_err(&data->client->dev, "%s: i2c send failed (%d)\n",
456 __func__, ret);
457 }
458
459 return ret;
460}
461
Nick Dyer8efaa5e2014-07-23 12:45:49 -0700462static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry)
Nick Dyerf28a8422014-05-18 23:10:49 -0700463{
464 u8 appmode = data->client->addr;
465 u8 bootloader;
Nick Dyer068bdb62018-05-01 11:40:18 -0700466 u8 family_id = data->info ? data->info->family_id : 0;
Nick Dyerf28a8422014-05-18 23:10:49 -0700467
468 switch (appmode) {
469 case 0x4a:
470 case 0x4b:
Nick Dyer44a0bab2014-07-23 12:45:26 -0700471 /* Chips after 1664S use different scheme */
Nick Dyer068bdb62018-05-01 11:40:18 -0700472 if (retry || family_id >= 0xa2) {
Nick Dyer44a0bab2014-07-23 12:45:26 -0700473 bootloader = appmode - 0x24;
474 break;
475 }
476 /* Fall through for normal case */
Nick Dyerf28a8422014-05-18 23:10:49 -0700477 case 0x4c:
478 case 0x4d:
479 case 0x5a:
480 case 0x5b:
481 bootloader = appmode - 0x26;
482 break;
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -0700483
Nick Dyerf28a8422014-05-18 23:10:49 -0700484 default:
485 dev_err(&data->client->dev,
486 "Appmode i2c address 0x%02x not found\n",
487 appmode);
488 return -EINVAL;
489 }
490
491 data->bootloader_addr = bootloader;
492 return 0;
493}
494
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -0700495static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address)
Nick Dyera9fdd1e2014-07-23 12:41:58 -0700496{
497 struct device *dev = &data->client->dev;
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -0700498 int error;
Nick Dyera9fdd1e2014-07-23 12:41:58 -0700499 u8 val;
500 bool crc_failure;
501
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -0700502 error = mxt_lookup_bootloader_address(data, alt_address);
503 if (error)
504 return error;
Nick Dyera9fdd1e2014-07-23 12:41:58 -0700505
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -0700506 error = mxt_bootloader_read(data, &val, 1);
507 if (error)
508 return error;
Nick Dyera9fdd1e2014-07-23 12:41:58 -0700509
510 /* Check app crc fail mode */
511 crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL;
512
513 dev_err(dev, "Detected bootloader, status:%02X%s\n",
514 val, crc_failure ? ", APP_CRC_FAIL" : "");
515
516 return 0;
517}
518
Nick Dyere57a66a2014-05-18 23:13:40 -0700519static u8 mxt_get_bootloader_version(struct mxt_data *data, u8 val)
520{
521 struct device *dev = &data->client->dev;
522 u8 buf[3];
523
524 if (val & MXT_BOOT_EXTENDED_ID) {
525 if (mxt_bootloader_read(data, &buf[0], 3) != 0) {
526 dev_err(dev, "%s: i2c failure\n", __func__);
Nick Dyer68807a02014-06-07 23:17:26 -0700527 return val;
Nick Dyere57a66a2014-05-18 23:13:40 -0700528 }
529
530 dev_dbg(dev, "Bootloader ID:%d Version:%d\n", buf[1], buf[2]);
531
532 return buf[0];
533 } else {
534 dev_dbg(dev, "Bootloader ID:%d\n", val & MXT_BOOT_ID_MASK);
535
536 return val;
537 }
538}
539
Nick Dyer385deb92014-07-23 12:42:40 -0700540static int mxt_check_bootloader(struct mxt_data *data, unsigned int state,
541 bool wait)
Benson Leungd79e7e42014-05-18 23:02:52 -0700542{
Nick Dyerf28a8422014-05-18 23:10:49 -0700543 struct device *dev = &data->client->dev;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700544 u8 val;
Benson Leungd79e7e42014-05-18 23:02:52 -0700545 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700546
547recheck:
Nick Dyer385deb92014-07-23 12:42:40 -0700548 if (wait) {
Benson Leungd79e7e42014-05-18 23:02:52 -0700549 /*
550 * In application update mode, the interrupt
551 * line signals state transitions. We must wait for the
552 * CHG assertion before reading the status byte.
553 * Once the status byte has been read, the line is deasserted.
554 */
Iiro Valkonena4a2ef42014-05-18 23:03:44 -0700555 ret = mxt_wait_for_completion(data, &data->bl_completion,
556 MXT_FW_CHG_TIMEOUT);
Benson Leungd79e7e42014-05-18 23:02:52 -0700557 if (ret) {
558 /*
559 * TODO: handle -ERESTARTSYS better by terminating
560 * fw update process before returning to userspace
561 * by writing length 0x000 to device (iff we are in
562 * WAITING_FRAME_DATA state).
563 */
Nick Dyerf28a8422014-05-18 23:10:49 -0700564 dev_err(dev, "Update wait error %d\n", ret);
Benson Leungd79e7e42014-05-18 23:02:52 -0700565 return ret;
566 }
567 }
568
Nick Dyerf28a8422014-05-18 23:10:49 -0700569 ret = mxt_bootloader_read(data, &val, 1);
570 if (ret)
571 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700572
Nick Dyere57a66a2014-05-18 23:13:40 -0700573 if (state == MXT_WAITING_BOOTLOAD_CMD)
574 val = mxt_get_bootloader_version(data, val);
575
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700576 switch (state) {
Iiro Valkonen7686b102011-02-02 23:21:58 -0800577 case MXT_WAITING_BOOTLOAD_CMD:
578 case MXT_WAITING_FRAME_DATA:
Nick Dyera9fdd1e2014-07-23 12:41:58 -0700579 case MXT_APP_CRC_FAIL:
Iiro Valkonen7686b102011-02-02 23:21:58 -0800580 val &= ~MXT_BOOT_STATUS_MASK;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700581 break;
Iiro Valkonen7686b102011-02-02 23:21:58 -0800582 case MXT_FRAME_CRC_PASS:
Nick Dyerf943c742014-05-18 23:14:20 -0700583 if (val == MXT_FRAME_CRC_CHECK) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700584 goto recheck;
Nick Dyerf943c742014-05-18 23:14:20 -0700585 } else if (val == MXT_FRAME_CRC_FAIL) {
586 dev_err(dev, "Bootloader CRC fail\n");
587 return -EINVAL;
588 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700589 break;
590 default:
591 return -EINVAL;
592 }
593
594 if (val != state) {
Nick Dyerf28a8422014-05-18 23:10:49 -0700595 dev_err(dev, "Invalid bootloader state %02X != %02X\n",
Nick Dyer7bed6802014-05-18 23:04:09 -0700596 val, state);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700597 return -EINVAL;
598 }
599
600 return 0;
601}
602
Nick Dyer8efaa5e2014-07-23 12:45:49 -0700603static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700604{
Nick Dyerf28a8422014-05-18 23:10:49 -0700605 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700606 u8 buf[2];
607
Nick Dyer8efaa5e2014-07-23 12:45:49 -0700608 if (unlock) {
609 buf[0] = MXT_UNLOCK_CMD_LSB;
610 buf[1] = MXT_UNLOCK_CMD_MSB;
611 } else {
612 buf[0] = 0x01;
613 buf[1] = 0x01;
614 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700615
Nick Dyerf28a8422014-05-18 23:10:49 -0700616 ret = mxt_bootloader_write(data, buf, 2);
617 if (ret)
618 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700619
620 return 0;
621}
622
Iiro Valkonen7686b102011-02-02 23:21:58 -0800623static int __mxt_read_reg(struct i2c_client *client,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700624 u16 reg, u16 len, void *val)
625{
626 struct i2c_msg xfer[2];
627 u8 buf[2];
Daniel Kurtz771733e2012-06-28 21:08:11 +0800628 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700629
630 buf[0] = reg & 0xff;
631 buf[1] = (reg >> 8) & 0xff;
632
633 /* Write register */
634 xfer[0].addr = client->addr;
635 xfer[0].flags = 0;
636 xfer[0].len = 2;
637 xfer[0].buf = buf;
638
639 /* Read data */
640 xfer[1].addr = client->addr;
641 xfer[1].flags = I2C_M_RD;
642 xfer[1].len = len;
643 xfer[1].buf = val;
644
Daniel Kurtz771733e2012-06-28 21:08:11 +0800645 ret = i2c_transfer(client->adapter, xfer, 2);
646 if (ret == 2) {
647 ret = 0;
648 } else {
649 if (ret >= 0)
650 ret = -EIO;
651 dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
652 __func__, ret);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700653 }
654
Daniel Kurtz771733e2012-06-28 21:08:11 +0800655 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700656}
657
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800658static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
659 const void *val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700660{
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800661 u8 *buf;
662 size_t count;
Daniel Kurtz771733e2012-06-28 21:08:11 +0800663 int ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700664
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800665 count = len + 2;
666 buf = kmalloc(count, GFP_KERNEL);
667 if (!buf)
668 return -ENOMEM;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700669
670 buf[0] = reg & 0xff;
671 buf[1] = (reg >> 8) & 0xff;
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800672 memcpy(&buf[2], val, len);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700673
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800674 ret = i2c_master_send(client, buf, count);
675 if (ret == count) {
Daniel Kurtz771733e2012-06-28 21:08:11 +0800676 ret = 0;
677 } else {
678 if (ret >= 0)
679 ret = -EIO;
680 dev_err(&client->dev, "%s: i2c send failed (%d)\n",
681 __func__, ret);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700682 }
683
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800684 kfree(buf);
Daniel Kurtz771733e2012-06-28 21:08:11 +0800685 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700686}
687
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800688static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700689{
Daniel Kurtz9638ab72012-06-28 21:08:12 +0800690 return __mxt_write_reg(client, reg, 1, &val);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700691}
692
Iiro Valkonen7686b102011-02-02 23:21:58 -0800693static struct mxt_object *
694mxt_get_object(struct mxt_data *data, u8 type)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700695{
Iiro Valkonen7686b102011-02-02 23:21:58 -0800696 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700697 int i;
698
Nick Dyer068bdb62018-05-01 11:40:18 -0700699 for (i = 0; i < data->info->object_num; i++) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700700 object = data->object_table + i;
701 if (object->type == type)
702 return object;
703 }
704
Nick Dyer50a77c62014-07-23 12:38:48 -0700705 dev_warn(&data->client->dev, "Invalid object type T%u\n", type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700706 return NULL;
707}
708
Nick Dyer497767d2014-07-23 12:47:50 -0700709static void mxt_proc_t6_messages(struct mxt_data *data, u8 *msg)
710{
711 struct device *dev = &data->client->dev;
712 u8 status = msg[1];
713 u32 crc = msg[2] | (msg[3] << 8) | (msg[4] << 16);
714
715 complete(&data->crc_completion);
716
717 if (crc != data->config_crc) {
718 data->config_crc = crc;
719 dev_dbg(dev, "T6 Config Checksum: 0x%06X\n", crc);
720 }
721
722 /* Detect reset */
723 if (status & MXT_T6_STATUS_RESET)
724 complete(&data->reset_completion);
725
726 /* Output debug if status has changed */
727 if (status != data->t6_status)
728 dev_dbg(dev, "T6 Status 0x%02X%s%s%s%s%s%s%s\n",
729 status,
730 status == 0 ? " OK" : "",
731 status & MXT_T6_STATUS_RESET ? " RESET" : "",
732 status & MXT_T6_STATUS_OFL ? " OFL" : "",
733 status & MXT_T6_STATUS_SIGERR ? " SIGERR" : "",
734 status & MXT_T6_STATUS_CAL ? " CAL" : "",
735 status & MXT_T6_STATUS_CFGERR ? " CFGERR" : "",
736 status & MXT_T6_STATUS_COMSERR ? " COMSERR" : "");
737
738 /* Save current status */
739 data->t6_status = status;
740}
741
Linus Torvalds7f405482014-12-31 12:59:34 -0800742static int mxt_write_object(struct mxt_data *data,
743 u8 type, u8 offset, u8 val)
744{
745 struct mxt_object *object;
746 u16 reg;
747
748 object = mxt_get_object(data, type);
749 if (!object || offset >= mxt_obj_size(object))
750 return -EINVAL;
751
752 reg = object->start_address;
753 return mxt_write_reg(data->client, reg + offset, val);
754}
755
Nick Dyer5f3f9bc2014-07-23 12:46:55 -0700756static void mxt_input_button(struct mxt_data *data, u8 *message)
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800757{
758 struct input_dev *input = data->input_dev;
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800759 int i;
760
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -0700761 for (i = 0; i < data->t19_num_keys; i++) {
762 if (data->t19_keymap[i] == KEY_RESERVED)
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800763 continue;
Dmitry Torokhovc37f6d32015-04-15 10:31:10 -0700764
765 /* Active-low switch */
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -0700766 input_report_key(input, data->t19_keymap[i],
Dmitry Torokhovc37f6d32015-04-15 10:31:10 -0700767 !(message[1] & BIT(i)));
Daniel Kurtz22dfab72013-03-07 19:43:33 -0800768 }
769}
770
Benson Leungb735fbe2014-07-23 12:22:27 -0700771static void mxt_input_sync(struct mxt_data *data)
Nick Dyereef820d2014-05-18 23:22:22 -0700772{
Benson Leungb735fbe2014-07-23 12:22:27 -0700773 input_mt_report_pointer_emulation(data->input_dev,
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -0700774 data->t19_num_keys);
Benson Leungb735fbe2014-07-23 12:22:27 -0700775 input_sync(data->input_dev);
Nick Dyereef820d2014-05-18 23:22:22 -0700776}
777
Nick Dyerb9b05a82014-07-23 12:48:13 -0700778static void mxt_proc_t9_message(struct mxt_data *data, u8 *message)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700779{
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700780 struct device *dev = &data->client->dev;
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800781 struct input_dev *input_dev = data->input_dev;
Nick Dyer5f3f9bc2014-07-23 12:46:55 -0700782 int id;
783 u8 status;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700784 int x;
785 int y;
786 int area;
Nick Dyerfea9e462014-05-18 23:21:48 -0700787 int amplitude;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700788
Nick Dyer5f3f9bc2014-07-23 12:46:55 -0700789 id = message[0] - data->T9_reportid_min;
790 status = message[1];
791 x = (message[2] << 4) | ((message[4] >> 4) & 0xf);
792 y = (message[3] << 4) | ((message[4] & 0xf));
Nick Dyereef820d2014-05-18 23:22:22 -0700793
794 /* Handle 10/12 bit switching */
Joonyoung Shim910d8052011-04-12 23:14:38 -0700795 if (data->max_x < 1024)
Nick Dyereef820d2014-05-18 23:22:22 -0700796 x >>= 2;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700797 if (data->max_y < 1024)
Nick Dyereef820d2014-05-18 23:22:22 -0700798 y >>= 2;
Joonyoung Shim910d8052011-04-12 23:14:38 -0700799
Nick Dyer5f3f9bc2014-07-23 12:46:55 -0700800 area = message[5];
801 amplitude = message[6];
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700802
Daniel Kurtzb2e459b2012-06-28 21:08:18 +0800803 dev_dbg(dev,
804 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
805 id,
Nick Dyerf3889ed2014-05-18 23:22:04 -0700806 (status & MXT_T9_DETECT) ? 'D' : '.',
807 (status & MXT_T9_PRESS) ? 'P' : '.',
808 (status & MXT_T9_RELEASE) ? 'R' : '.',
809 (status & MXT_T9_MOVE) ? 'M' : '.',
810 (status & MXT_T9_VECTOR) ? 'V' : '.',
811 (status & MXT_T9_AMP) ? 'A' : '.',
812 (status & MXT_T9_SUPPRESS) ? 'S' : '.',
813 (status & MXT_T9_UNGRIP) ? 'U' : '.',
Nick Dyerfea9e462014-05-18 23:21:48 -0700814 x, y, area, amplitude);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700815
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800816 input_mt_slot(input_dev, id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700817
Nick Dyerf3889ed2014-05-18 23:22:04 -0700818 if (status & MXT_T9_DETECT) {
Nick Dyereef820d2014-05-18 23:22:22 -0700819 /*
820 * Multiple bits may be set if the host is slow to read
821 * the status messages, indicating all the events that
822 * have happened.
823 */
824 if (status & MXT_T9_RELEASE) {
825 input_mt_report_slot_state(input_dev,
826 MT_TOOL_FINGER, 0);
Benson Leungb735fbe2014-07-23 12:22:27 -0700827 mxt_input_sync(data);
Nick Dyereef820d2014-05-18 23:22:22 -0700828 }
829
830 /* Touch active */
831 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1);
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800832 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
833 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
Nick Dyerfea9e462014-05-18 23:21:48 -0700834 input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude);
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800835 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
Nick Dyereef820d2014-05-18 23:22:22 -0700836 } else {
837 /* Touch no longer active, close out slot */
838 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0);
Daniel Kurtzfba5bc32012-06-28 21:08:17 +0800839 }
Nick Dyerb9b05a82014-07-23 12:48:13 -0700840
841 data->update_input = true;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -0700842}
843
Nick Dyerb23157d2015-04-06 11:25:13 -0700844static void mxt_proc_t100_message(struct mxt_data *data, u8 *message)
845{
846 struct device *dev = &data->client->dev;
847 struct input_dev *input_dev = data->input_dev;
848 int id;
849 u8 status;
850 u8 type = 0;
851 u16 x;
852 u16 y;
853 int distance = 0;
854 int tool = 0;
855 u8 major = 0;
856 u8 pressure = 0;
857 u8 orientation = 0;
858
859 id = message[0] - data->T100_reportid_min - 2;
860
861 /* ignore SCRSTATUS events */
862 if (id < 0)
863 return;
864
865 status = message[1];
866 x = get_unaligned_le16(&message[2]);
867 y = get_unaligned_le16(&message[4]);
868
869 if (status & MXT_T100_DETECT) {
870 type = (status & MXT_T100_TYPE_MASK) >> 4;
871
872 switch (type) {
873 case MXT_T100_TYPE_HOVERING_FINGER:
874 tool = MT_TOOL_FINGER;
875 distance = MXT_DISTANCE_HOVERING;
876
877 if (data->t100_aux_vect)
878 orientation = message[data->t100_aux_vect];
879
880 break;
881
882 case MXT_T100_TYPE_FINGER:
883 case MXT_T100_TYPE_GLOVE:
884 tool = MT_TOOL_FINGER;
885 distance = MXT_DISTANCE_ACTIVE_TOUCH;
886
887 if (data->t100_aux_area)
888 major = message[data->t100_aux_area];
889
890 if (data->t100_aux_ampl)
891 pressure = message[data->t100_aux_ampl];
892
893 if (data->t100_aux_vect)
894 orientation = message[data->t100_aux_vect];
895
896 break;
897
898 case MXT_T100_TYPE_PASSIVE_STYLUS:
899 tool = MT_TOOL_PEN;
900
901 /*
902 * Passive stylus is reported with size zero so
903 * hardcode.
904 */
905 major = MXT_TOUCH_MAJOR_DEFAULT;
906
907 if (data->t100_aux_ampl)
908 pressure = message[data->t100_aux_ampl];
909
910 break;
911
912 case MXT_T100_TYPE_LARGE_TOUCH:
913 /* Ignore suppressed touch */
914 break;
915
916 default:
917 dev_dbg(dev, "Unexpected T100 type\n");
918 return;
919 }
920 }
921
922 /*
923 * Values reported should be non-zero if tool is touching the
924 * device
925 */
926 if (!pressure && type != MXT_T100_TYPE_HOVERING_FINGER)
927 pressure = MXT_PRESSURE_DEFAULT;
928
929 input_mt_slot(input_dev, id);
930
931 if (status & MXT_T100_DETECT) {
932 dev_dbg(dev, "[%u] type:%u x:%u y:%u a:%02X p:%02X v:%02X\n",
933 id, type, x, y, major, pressure, orientation);
934
935 input_mt_report_slot_state(input_dev, tool, 1);
936 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
937 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
938 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, major);
939 input_report_abs(input_dev, ABS_MT_PRESSURE, pressure);
940 input_report_abs(input_dev, ABS_MT_DISTANCE, distance);
941 input_report_abs(input_dev, ABS_MT_ORIENTATION, orientation);
942 } else {
943 dev_dbg(dev, "[%u] release\n", id);
944
945 /* close out slot */
946 input_mt_report_slot_state(input_dev, 0, 0);
947 }
948
949 data->update_input = true;
950}
951
Nick Dyerb9b05a82014-07-23 12:48:13 -0700952static int mxt_proc_message(struct mxt_data *data, u8 *message)
Daniel Kurtz04a79182012-06-28 21:08:21 +0800953{
Nick Dyerb9b05a82014-07-23 12:48:13 -0700954 u8 report_id = message[0];
955
956 if (report_id == MXT_RPTID_NOMSG)
957 return 0;
958
959 if (report_id == data->T6_reportid) {
960 mxt_proc_t6_messages(data, message);
961 } else if (!data->input_dev) {
962 /*
963 * Do not report events if input device
964 * is not yet registered.
965 */
966 mxt_dump_message(data, message);
Nick Dyerb23157d2015-04-06 11:25:13 -0700967 } else if (report_id >= data->T9_reportid_min &&
968 report_id <= data->T9_reportid_max) {
Nick Dyerb9b05a82014-07-23 12:48:13 -0700969 mxt_proc_t9_message(data, message);
Nick Dyerb23157d2015-04-06 11:25:13 -0700970 } else if (report_id >= data->T100_reportid_min &&
971 report_id <= data->T100_reportid_max) {
972 mxt_proc_t100_message(data, message);
Nick Dyerb9b05a82014-07-23 12:48:13 -0700973 } else if (report_id == data->T19_reportid) {
974 mxt_input_button(data, message);
975 data->update_input = true;
976 } else {
977 mxt_dump_message(data, message);
978 }
979
980 return 1;
981}
982
Nick Dyer9d8dc3e2014-07-23 12:49:04 -0700983static int mxt_read_and_process_messages(struct mxt_data *data, u8 count)
Nick Dyerb9b05a82014-07-23 12:48:13 -0700984{
985 struct device *dev = &data->client->dev;
986 int ret;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -0700987 int i;
988 u8 num_valid = 0;
Nick Dyerb9b05a82014-07-23 12:48:13 -0700989
Nick Dyer9d8dc3e2014-07-23 12:49:04 -0700990 /* Safety check for msg_buf */
991 if (count > data->max_reportid)
992 return -EINVAL;
993
994 /* Process remaining messages if necessary */
Nick Dyerb9b05a82014-07-23 12:48:13 -0700995 ret = __mxt_read_reg(data->client, data->T5_address,
Nick Dyer9d8dc3e2014-07-23 12:49:04 -0700996 data->T5_msg_size * count, data->msg_buf);
Nick Dyerb9b05a82014-07-23 12:48:13 -0700997 if (ret) {
Nick Dyer9d8dc3e2014-07-23 12:49:04 -0700998 dev_err(dev, "Failed to read %u messages (%d)\n", count, ret);
Nick Dyerb9b05a82014-07-23 12:48:13 -0700999 return ret;
1000 }
1001
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001002 for (i = 0; i < count; i++) {
1003 ret = mxt_proc_message(data,
1004 data->msg_buf + data->T5_msg_size * i);
1005
1006 if (ret == 1)
1007 num_valid++;
1008 }
1009
1010 /* return number of messages read */
1011 return num_valid;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001012}
1013
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001014static irqreturn_t mxt_process_messages_t44(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001015{
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001016 struct device *dev = &data->client->dev;
Nick Dyerb9b05a82014-07-23 12:48:13 -07001017 int ret;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001018 u8 count, num_left;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001019
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001020 /* Read T44 and T5 together */
1021 ret = __mxt_read_reg(data->client, data->T44_address,
1022 data->T5_msg_size + 1, data->msg_buf);
1023 if (ret) {
1024 dev_err(dev, "Failed to read T44 and T5 (%d)\n", ret);
1025 return IRQ_NONE;
1026 }
1027
1028 count = data->msg_buf[0];
1029
Nick Dyer507584e2015-08-04 16:58:05 -07001030 /*
1031 * This condition may be caused by the CHG line being configured in
1032 * Mode 0. It results in unnecessary I2C operations but it is benign.
1033 */
1034 if (count == 0)
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001035 return IRQ_NONE;
Nick Dyer507584e2015-08-04 16:58:05 -07001036
1037 if (count > data->max_reportid) {
1038 dev_warn(dev, "T44 count %d exceeded max report id\n", count);
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001039 count = data->max_reportid;
1040 }
1041
1042 /* Process first message */
1043 ret = mxt_proc_message(data, data->msg_buf + 1);
1044 if (ret < 0) {
1045 dev_warn(dev, "Unexpected invalid message\n");
1046 return IRQ_NONE;
1047 }
1048
1049 num_left = count - 1;
1050
1051 /* Process remaining messages if necessary */
1052 if (num_left) {
1053 ret = mxt_read_and_process_messages(data, num_left);
Nick Dyerb9b05a82014-07-23 12:48:13 -07001054 if (ret < 0)
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001055 goto end;
1056 else if (ret != num_left)
1057 dev_warn(dev, "Unexpected invalid message\n");
1058 }
1059
1060end:
1061 if (data->update_input) {
1062 mxt_input_sync(data);
1063 data->update_input = false;
1064 }
1065
1066 return IRQ_HANDLED;
1067}
1068
1069static int mxt_process_messages_until_invalid(struct mxt_data *data)
1070{
1071 struct device *dev = &data->client->dev;
1072 int count, read;
1073 u8 tries = 2;
1074
1075 count = data->max_reportid;
1076
1077 /* Read messages until we force an invalid */
1078 do {
1079 read = mxt_read_and_process_messages(data, count);
1080 if (read < count)
1081 return 0;
1082 } while (--tries);
1083
1084 if (data->update_input) {
1085 mxt_input_sync(data);
1086 data->update_input = false;
1087 }
1088
1089 dev_err(dev, "CHG pin isn't cleared\n");
1090 return -EBUSY;
1091}
1092
1093static irqreturn_t mxt_process_messages(struct mxt_data *data)
1094{
1095 int total_handled, num_handled;
1096 u8 count = data->last_message_count;
1097
1098 if (count < 1 || count > data->max_reportid)
1099 count = 1;
1100
1101 /* include final invalid message */
1102 total_handled = mxt_read_and_process_messages(data, count + 1);
1103 if (total_handled < 0)
1104 return IRQ_NONE;
1105 /* if there were invalid messages, then we are done */
1106 else if (total_handled <= count)
1107 goto update_count;
1108
1109 /* keep reading two msgs until one is invalid or reportid limit */
1110 do {
1111 num_handled = mxt_read_and_process_messages(data, 2);
1112 if (num_handled < 0)
Nick Dyer8d4e1632014-05-18 23:00:56 -07001113 return IRQ_NONE;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001114
1115 total_handled += num_handled;
1116
1117 if (num_handled < 2)
1118 break;
1119 } while (total_handled < data->num_touchids);
1120
1121update_count:
1122 data->last_message_count = total_handled;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001123
Nick Dyerb9b05a82014-07-23 12:48:13 -07001124 if (data->update_input) {
Benson Leungb735fbe2014-07-23 12:22:27 -07001125 mxt_input_sync(data);
Nick Dyerb9b05a82014-07-23 12:48:13 -07001126 data->update_input = false;
1127 }
Daniel Kurtz64464ae2012-06-28 21:08:23 +08001128
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001129 return IRQ_HANDLED;
1130}
1131
Benson Leungd79e7e42014-05-18 23:02:52 -07001132static irqreturn_t mxt_interrupt(int irq, void *dev_id)
1133{
1134 struct mxt_data *data = dev_id;
1135
1136 if (data->in_bootloader) {
1137 /* bootloader state transition completion */
1138 complete(&data->bl_completion);
1139 return IRQ_HANDLED;
1140 }
1141
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001142 if (!data->object_table)
1143 return IRQ_HANDLED;
1144
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001145 if (data->T44_address) {
1146 return mxt_process_messages_t44(data);
1147 } else {
1148 return mxt_process_messages(data);
1149 }
Benson Leungd79e7e42014-05-18 23:02:52 -07001150}
1151
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001152static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset,
1153 u8 value, bool wait)
1154{
1155 u16 reg;
1156 u8 command_register;
1157 int timeout_counter = 0;
1158 int ret;
1159
1160 reg = data->T6_address + cmd_offset;
1161
1162 ret = mxt_write_reg(data->client, reg, value);
1163 if (ret)
1164 return ret;
1165
1166 if (!wait)
1167 return 0;
1168
1169 do {
1170 msleep(20);
1171 ret = __mxt_read_reg(data->client, reg, 1, &command_register);
1172 if (ret)
1173 return ret;
1174 } while (command_register != 0 && timeout_counter++ <= 100);
1175
1176 if (timeout_counter > 100) {
1177 dev_err(&data->client->dev, "Command failed!\n");
1178 return -EIO;
1179 }
1180
1181 return 0;
1182}
1183
Nick Dyereb433352016-04-25 14:18:52 -07001184static int mxt_acquire_irq(struct mxt_data *data)
1185{
1186 int error;
1187
1188 enable_irq(data->irq);
1189
1190 error = mxt_process_messages_until_invalid(data);
1191 if (error)
1192 return error;
1193
1194 return 0;
1195}
1196
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001197static int mxt_soft_reset(struct mxt_data *data)
1198{
1199 struct device *dev = &data->client->dev;
1200 int ret = 0;
1201
Nick Dyer885f3fb2015-08-04 16:57:25 -07001202 dev_info(dev, "Resetting device\n");
1203
1204 disable_irq(data->irq);
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001205
1206 reinit_completion(&data->reset_completion);
1207
1208 ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_RESET_VALUE, false);
1209 if (ret)
1210 return ret;
1211
Nick Dyer885f3fb2015-08-04 16:57:25 -07001212 /* Ignore CHG line for 100ms after reset */
Sebastian Reichelca1cd362018-05-24 09:33:36 -07001213 msleep(MXT_RESET_INVALID_CHG);
Nick Dyer885f3fb2015-08-04 16:57:25 -07001214
Nick Dyereb433352016-04-25 14:18:52 -07001215 mxt_acquire_irq(data);
Nick Dyer885f3fb2015-08-04 16:57:25 -07001216
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001217 ret = mxt_wait_for_completion(data, &data->reset_completion,
1218 MXT_RESET_TIMEOUT);
1219 if (ret)
1220 return ret;
1221
1222 return 0;
1223}
1224
Nick Dyerc3f78042014-05-18 23:04:46 -07001225static void mxt_update_crc(struct mxt_data *data, u8 cmd, u8 value)
1226{
1227 /*
1228 * On failure, CRC is set to 0 and config will always be
1229 * downloaded.
1230 */
1231 data->config_crc = 0;
1232 reinit_completion(&data->crc_completion);
1233
1234 mxt_t6_command(data, cmd, value, true);
1235
1236 /*
1237 * Wait for crc message. On failure, CRC is set to 0 and config will
1238 * always be downloaded.
1239 */
1240 mxt_wait_for_completion(data, &data->crc_completion, MXT_CRC_TIMEOUT);
1241}
1242
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001243static void mxt_calc_crc24(u32 *crc, u8 firstbyte, u8 secondbyte)
1244{
1245 static const unsigned int crcpoly = 0x80001B;
1246 u32 result;
1247 u32 data_word;
1248
1249 data_word = (secondbyte << 8) | firstbyte;
1250 result = ((*crc << 1) ^ data_word);
1251
1252 if (result & 0x1000000)
1253 result ^= crcpoly;
1254
1255 *crc = result;
1256}
1257
1258static u32 mxt_calculate_crc(u8 *base, off_t start_off, off_t end_off)
1259{
1260 u32 crc = 0;
1261 u8 *ptr = base + start_off;
1262 u8 *last_val = base + end_off - 1;
1263
1264 if (end_off < start_off)
1265 return -EINVAL;
1266
1267 while (ptr < last_val) {
1268 mxt_calc_crc24(&crc, *ptr, *(ptr + 1));
1269 ptr += 2;
1270 }
1271
1272 /* if len is odd, fill the last byte with 0 */
1273 if (ptr == last_val)
1274 mxt_calc_crc24(&crc, *ptr, 0);
1275
1276 /* Mask to 24-bit */
1277 crc &= 0x00FFFFFF;
1278
1279 return crc;
1280}
1281
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001282static int mxt_prepare_cfg_mem(struct mxt_data *data,
1283 const struct firmware *cfg,
1284 unsigned int data_pos,
1285 unsigned int cfg_start_ofs,
1286 u8 *config_mem,
1287 size_t config_mem_size)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001288{
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001289 struct device *dev = &data->client->dev;
Nick Dyer50a77c62014-07-23 12:38:48 -07001290 struct mxt_object *object;
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001291 unsigned int type, instance, size, byte_offset;
Nick Dyer50a77c62014-07-23 12:38:48 -07001292 int offset;
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001293 int ret;
Nick Dyer50a77c62014-07-23 12:38:48 -07001294 int i;
Nick Dyer50a77c62014-07-23 12:38:48 -07001295 u16 reg;
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001296 u8 val;
Nick Dyer50a77c62014-07-23 12:38:48 -07001297
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001298 while (data_pos < cfg->size) {
Nick Dyer50a77c62014-07-23 12:38:48 -07001299 /* Read type, instance, length */
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001300 ret = sscanf(cfg->data + data_pos, "%x %x %x%n",
Nick Dyer50a77c62014-07-23 12:38:48 -07001301 &type, &instance, &size, &offset);
1302 if (ret == 0) {
1303 /* EOF */
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001304 break;
Nick Dyer50a77c62014-07-23 12:38:48 -07001305 } else if (ret != 3) {
1306 dev_err(dev, "Bad format: failed to parse object\n");
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001307 return -EINVAL;
Nick Dyer50a77c62014-07-23 12:38:48 -07001308 }
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001309 data_pos += offset;
Nick Dyer50a77c62014-07-23 12:38:48 -07001310
1311 object = mxt_get_object(data, type);
1312 if (!object) {
1313 /* Skip object */
1314 for (i = 0; i < size; i++) {
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001315 ret = sscanf(cfg->data + data_pos, "%hhx%n",
Dmitry Torokhov041fa152014-08-11 10:58:29 -07001316 &val, &offset);
1317 if (ret != 1) {
1318 dev_err(dev, "Bad format in T%d at %d\n",
1319 type, i);
1320 return -EINVAL;
1321 }
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001322 data_pos += offset;
Nick Dyer50a77c62014-07-23 12:38:48 -07001323 }
1324 continue;
1325 }
1326
1327 if (size > mxt_obj_size(object)) {
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001328 /*
1329 * Either we are in fallback mode due to wrong
1330 * config or config from a later fw version,
1331 * or the file is corrupt or hand-edited.
1332 */
1333 dev_warn(dev, "Discarding %zu byte(s) in T%u\n",
1334 size - mxt_obj_size(object), type);
1335 } else if (mxt_obj_size(object) > size) {
1336 /*
1337 * If firmware is upgraded, new bytes may be added to
1338 * end of objects. It is generally forward compatible
1339 * to zero these bytes - previous behaviour will be
1340 * retained. However this does invalidate the CRC and
1341 * will force fallback mode until the configuration is
1342 * updated. We warn here but do nothing else - the
1343 * malloc has zeroed the entire configuration.
1344 */
1345 dev_warn(dev, "Zeroing %zu byte(s) in T%d\n",
1346 mxt_obj_size(object) - size, type);
Nick Dyer50a77c62014-07-23 12:38:48 -07001347 }
1348
1349 if (instance >= mxt_obj_instances(object)) {
1350 dev_err(dev, "Object instances exceeded!\n");
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001351 return -EINVAL;
Nick Dyer50a77c62014-07-23 12:38:48 -07001352 }
1353
1354 reg = object->start_address + mxt_obj_size(object) * instance;
1355
1356 for (i = 0; i < size; i++) {
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001357 ret = sscanf(cfg->data + data_pos, "%hhx%n",
Nick Dyer50a77c62014-07-23 12:38:48 -07001358 &val,
1359 &offset);
1360 if (ret != 1) {
Dmitry Torokhov041fa152014-08-11 10:58:29 -07001361 dev_err(dev, "Bad format in T%d at %d\n",
1362 type, i);
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001363 return -EINVAL;
Nick Dyer50a77c62014-07-23 12:38:48 -07001364 }
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001365 data_pos += offset;
Nick Dyer50a77c62014-07-23 12:38:48 -07001366
1367 if (i > mxt_obj_size(object))
1368 continue;
1369
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001370 byte_offset = reg + i - cfg_start_ofs;
Nick Dyer50a77c62014-07-23 12:38:48 -07001371
Dmitry Torokhov041fa152014-08-11 10:58:29 -07001372 if (byte_offset >= 0 && byte_offset < config_mem_size) {
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001373 *(config_mem + byte_offset) = val;
1374 } else {
1375 dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n",
1376 reg, object->type, byte_offset);
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001377 return -EINVAL;
Nick Dyer50a77c62014-07-23 12:38:48 -07001378 }
1379 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001380 }
1381
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001382 return 0;
1383}
1384
1385static int mxt_upload_cfg_mem(struct mxt_data *data, unsigned int cfg_start,
1386 u8 *config_mem, size_t config_mem_size)
1387{
1388 unsigned int byte_offset = 0;
1389 int error;
1390
1391 /* Write configuration as blocks */
1392 while (byte_offset < config_mem_size) {
1393 unsigned int size = config_mem_size - byte_offset;
1394
1395 if (size > MXT_MAX_BLOCK_WRITE)
1396 size = MXT_MAX_BLOCK_WRITE;
1397
1398 error = __mxt_write_reg(data->client,
1399 cfg_start + byte_offset,
1400 size, config_mem + byte_offset);
1401 if (error) {
1402 dev_err(&data->client->dev,
1403 "Config write error, ret=%d\n", error);
1404 return error;
1405 }
1406
1407 byte_offset += size;
1408 }
1409
1410 return 0;
1411}
1412
Nick Dyer7f3884f72015-08-04 16:36:29 -07001413static int mxt_init_t7_power_cfg(struct mxt_data *data);
1414
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001415/*
1416 * mxt_update_cfg - download configuration to chip
1417 *
1418 * Atmel Raw Config File Format
1419 *
1420 * The first four lines of the raw config file contain:
1421 * 1) Version
1422 * 2) Chip ID Information (first 7 bytes of device memory)
1423 * 3) Chip Information Block 24-bit CRC Checksum
1424 * 4) Chip Configuration 24-bit CRC Checksum
1425 *
1426 * The rest of the file consists of one line per object instance:
1427 * <TYPE> <INSTANCE> <SIZE> <CONTENTS>
1428 *
1429 * <TYPE> - 2-byte object type as hex
1430 * <INSTANCE> - 2-byte object instance number as hex
1431 * <SIZE> - 2-byte object size as hex
1432 * <CONTENTS> - array of <SIZE> 1-byte hex values
1433 */
1434static int mxt_update_cfg(struct mxt_data *data, const struct firmware *cfg)
1435{
1436 struct device *dev = &data->client->dev;
1437 struct mxt_info cfg_info;
1438 int ret;
1439 int offset;
1440 int data_pos;
1441 int i;
1442 int cfg_start_ofs;
1443 u32 info_crc, config_crc, calculated_crc;
1444 u8 *config_mem;
1445 size_t config_mem_size;
1446
1447 mxt_update_crc(data, MXT_COMMAND_REPORTALL, 1);
1448
1449 if (strncmp(cfg->data, MXT_CFG_MAGIC, strlen(MXT_CFG_MAGIC))) {
1450 dev_err(dev, "Unrecognised config file\n");
1451 return -EINVAL;
1452 }
1453
1454 data_pos = strlen(MXT_CFG_MAGIC);
1455
1456 /* Load information block and check */
1457 for (i = 0; i < sizeof(struct mxt_info); i++) {
1458 ret = sscanf(cfg->data + data_pos, "%hhx%n",
1459 (unsigned char *)&cfg_info + i,
1460 &offset);
1461 if (ret != 1) {
1462 dev_err(dev, "Bad format\n");
1463 return -EINVAL;
1464 }
1465
1466 data_pos += offset;
1467 }
1468
Nick Dyer068bdb62018-05-01 11:40:18 -07001469 if (cfg_info.family_id != data->info->family_id) {
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001470 dev_err(dev, "Family ID mismatch!\n");
1471 return -EINVAL;
1472 }
1473
Nick Dyer068bdb62018-05-01 11:40:18 -07001474 if (cfg_info.variant_id != data->info->variant_id) {
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001475 dev_err(dev, "Variant ID mismatch!\n");
1476 return -EINVAL;
1477 }
1478
1479 /* Read CRCs */
1480 ret = sscanf(cfg->data + data_pos, "%x%n", &info_crc, &offset);
1481 if (ret != 1) {
1482 dev_err(dev, "Bad format: failed to parse Info CRC\n");
1483 return -EINVAL;
1484 }
1485 data_pos += offset;
1486
1487 ret = sscanf(cfg->data + data_pos, "%x%n", &config_crc, &offset);
1488 if (ret != 1) {
1489 dev_err(dev, "Bad format: failed to parse Config CRC\n");
1490 return -EINVAL;
1491 }
1492 data_pos += offset;
1493
1494 /*
1495 * The Info Block CRC is calculated over mxt_info and the object
1496 * table. If it does not match then we are trying to load the
1497 * configuration from a different chip or firmware version, so
1498 * the configuration CRC is invalid anyway.
1499 */
1500 if (info_crc == data->info_crc) {
1501 if (config_crc == 0 || data->config_crc == 0) {
1502 dev_info(dev, "CRC zero, attempting to apply config\n");
1503 } else if (config_crc == data->config_crc) {
1504 dev_dbg(dev, "Config CRC 0x%06X: OK\n",
1505 data->config_crc);
1506 return 0;
1507 } else {
1508 dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n",
1509 data->config_crc, config_crc);
1510 }
1511 } else {
1512 dev_warn(dev,
1513 "Warning: Info CRC error - device=0x%06X file=0x%06X\n",
1514 data->info_crc, info_crc);
1515 }
1516
1517 /* Malloc memory to store configuration */
1518 cfg_start_ofs = MXT_OBJECT_START +
Nick Dyer068bdb62018-05-01 11:40:18 -07001519 data->info->object_num * sizeof(struct mxt_object) +
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001520 MXT_INFO_CHECKSUM_SIZE;
1521 config_mem_size = data->mem_size - cfg_start_ofs;
1522 config_mem = kzalloc(config_mem_size, GFP_KERNEL);
1523 if (!config_mem) {
1524 dev_err(dev, "Failed to allocate memory\n");
1525 return -ENOMEM;
1526 }
1527
1528 ret = mxt_prepare_cfg_mem(data, cfg, data_pos, cfg_start_ofs,
1529 config_mem, config_mem_size);
1530 if (ret)
1531 goto release_mem;
1532
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001533 /* Calculate crc of the received configs (not the raw config file) */
1534 if (data->T7_address < cfg_start_ofs) {
1535 dev_err(dev, "Bad T7 address, T7addr = %x, config offset %x\n",
1536 data->T7_address, cfg_start_ofs);
1537 ret = 0;
1538 goto release_mem;
1539 }
1540
1541 calculated_crc = mxt_calculate_crc(config_mem,
1542 data->T7_address - cfg_start_ofs,
1543 config_mem_size);
1544
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001545 if (config_crc > 0 && config_crc != calculated_crc)
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001546 dev_warn(dev, "Config CRC error, calculated=%06X, file=%06X\n",
1547 calculated_crc, config_crc);
1548
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07001549 ret = mxt_upload_cfg_mem(data, cfg_start_ofs,
1550 config_mem, config_mem_size);
1551 if (ret)
1552 goto release_mem;
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001553
Nick Dyerc3f78042014-05-18 23:04:46 -07001554 mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE);
1555
1556 ret = mxt_soft_reset(data);
1557 if (ret)
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001558 goto release_mem;
Nick Dyerc3f78042014-05-18 23:04:46 -07001559
1560 dev_info(dev, "Config successfully updated\n");
1561
Nick Dyer7f3884f72015-08-04 16:36:29 -07001562 /* T7 config may have changed */
1563 mxt_init_t7_power_cfg(data);
1564
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001565release_mem:
1566 kfree(config_mem);
Nick Dyer50a77c62014-07-23 12:38:48 -07001567 return ret;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001568}
1569
Stephen Warren58e4aeee2014-09-10 10:01:10 -07001570static void mxt_free_input_device(struct mxt_data *data)
1571{
1572 if (data->input_dev) {
1573 input_unregister_device(data->input_dev);
1574 data->input_dev = NULL;
1575 }
1576}
1577
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001578static void mxt_free_object_table(struct mxt_data *data)
1579{
Nick Dyerecfdd7e2016-07-18 18:10:32 -03001580#ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37
1581 video_unregister_device(&data->dbg.vdev);
1582 v4l2_device_unregister(&data->dbg.v4l2);
1583#endif
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001584 data->object_table = NULL;
Nick Dyer068bdb62018-05-01 11:40:18 -07001585 data->info = NULL;
1586 kfree(data->raw_info_block);
1587 data->raw_info_block = NULL;
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001588 kfree(data->msg_buf);
1589 data->msg_buf = NULL;
Nick Dyerb9b05a82014-07-23 12:48:13 -07001590 data->T5_address = 0;
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001591 data->T5_msg_size = 0;
1592 data->T6_reportid = 0;
1593 data->T7_address = 0;
1594 data->T9_reportid_min = 0;
1595 data->T9_reportid_max = 0;
1596 data->T19_reportid = 0;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001597 data->T44_address = 0;
Nick Dyerb23157d2015-04-06 11:25:13 -07001598 data->T100_reportid_min = 0;
1599 data->T100_reportid_max = 0;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001600 data->max_reportid = 0;
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001601}
1602
Nick Dyer068bdb62018-05-01 11:40:18 -07001603static int mxt_parse_object_table(struct mxt_data *data,
1604 struct mxt_object *object_table)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001605{
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001606 struct i2c_client *client = data->client;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001607 int i;
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001608 u8 reportid;
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001609 u16 end_address;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001610
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001611 /* Valid Report IDs start counting from 1 */
1612 reportid = 1;
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001613 data->mem_size = 0;
Nick Dyer068bdb62018-05-01 11:40:18 -07001614 for (i = 0; i < data->info->object_num; i++) {
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001615 struct mxt_object *object = object_table + i;
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001616 u8 min_id, max_id;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001617
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001618 le16_to_cpus(&object->start_address);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001619
1620 if (object->num_report_ids) {
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001621 min_id = reportid;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001622 reportid += object->num_report_ids *
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07001623 mxt_obj_instances(object);
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001624 max_id = reportid - 1;
1625 } else {
1626 min_id = 0;
1627 max_id = 0;
1628 }
1629
1630 dev_dbg(&data->client->dev,
Nick Dyer7bed6802014-05-18 23:04:09 -07001631 "T%u Start:%u Size:%zu Instances:%zu Report IDs:%u-%u\n",
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07001632 object->type, object->start_address,
1633 mxt_obj_size(object), mxt_obj_instances(object),
1634 min_id, max_id);
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001635
1636 switch (object->type) {
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001637 case MXT_GEN_MESSAGE_T5:
Nick Dyer068bdb62018-05-01 11:40:18 -07001638 if (data->info->family_id == 0x80 &&
1639 data->info->version < 0x20) {
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001640 /*
Nick Dyer437d4f32014-08-07 09:56:01 -07001641 * On mXT224 firmware versions prior to V2.0
1642 * read and discard unused CRC byte otherwise
1643 * DMA reads are misaligned.
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001644 */
1645 data->T5_msg_size = mxt_obj_size(object);
1646 } else {
1647 /* CRC not enabled, so skip last byte */
1648 data->T5_msg_size = mxt_obj_size(object) - 1;
1649 }
Nick Dyerb9b05a82014-07-23 12:48:13 -07001650 data->T5_address = object->start_address;
Dmitry Torokhov041fa152014-08-11 10:58:29 -07001651 break;
Daniel Kurtzfdf804212012-06-28 21:08:24 +08001652 case MXT_GEN_COMMAND_T6:
1653 data->T6_reportid = min_id;
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07001654 data->T6_address = object->start_address;
Daniel Kurtzfdf804212012-06-28 21:08:24 +08001655 break;
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001656 case MXT_GEN_POWER_T7:
1657 data->T7_address = object->start_address;
1658 break;
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001659 case MXT_TOUCH_MULTI_T9:
Nick Dyerb23157d2015-04-06 11:25:13 -07001660 data->multitouch = MXT_TOUCH_MULTI_T9;
Nick Dyer36f5d9e2018-07-27 11:44:20 -07001661 /* Only handle messages from first T9 instance */
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001662 data->T9_reportid_min = min_id;
Nick Dyer36f5d9e2018-07-27 11:44:20 -07001663 data->T9_reportid_max = min_id +
1664 object->num_report_ids - 1;
1665 data->num_touchids = object->num_report_ids;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001666 break;
1667 case MXT_SPT_MESSAGECOUNT_T44:
1668 data->T44_address = object->start_address;
Daniel Kurtz333e5a92012-06-28 21:08:20 +08001669 break;
Daniel Kurtz22dfab72013-03-07 19:43:33 -08001670 case MXT_SPT_GPIOPWM_T19:
1671 data->T19_reportid = min_id;
1672 break;
Nick Dyerb23157d2015-04-06 11:25:13 -07001673 case MXT_TOUCH_MULTITOUCHSCREEN_T100:
1674 data->multitouch = MXT_TOUCH_MULTITOUCHSCREEN_T100;
1675 data->T100_reportid_min = min_id;
1676 data->T100_reportid_max = max_id;
1677 /* first two report IDs reserved */
1678 data->num_touchids = object->num_report_ids - 2;
1679 break;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001680 }
Nick Dyer4ce6fa02014-07-23 12:40:09 -07001681
1682 end_address = object->start_address
1683 + mxt_obj_size(object) * mxt_obj_instances(object) - 1;
1684
1685 if (end_address >= data->mem_size)
1686 data->mem_size = end_address + 1;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001687 }
1688
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001689 /* Store maximum reportid */
1690 data->max_reportid = reportid;
1691
1692 /* If T44 exists, T5 position has to be directly after */
1693 if (data->T44_address && (data->T5_address != data->T44_address + 1)) {
1694 dev_err(&client->dev, "Invalid T44 position\n");
Nick Dyer068bdb62018-05-01 11:40:18 -07001695 return -EINVAL;
Nick Dyer9d8dc3e2014-07-23 12:49:04 -07001696 }
1697
1698 data->msg_buf = kcalloc(data->max_reportid,
1699 data->T5_msg_size, GFP_KERNEL);
Nick Dyer068bdb62018-05-01 11:40:18 -07001700 if (!data->msg_buf)
1701 return -ENOMEM;
1702
1703 return 0;
1704}
1705
1706static int mxt_read_info_block(struct mxt_data *data)
1707{
1708 struct i2c_client *client = data->client;
1709 int error;
1710 size_t size;
1711 void *id_buf, *buf;
1712 uint8_t num_objects;
1713 u32 calculated_crc;
1714 u8 *crc_ptr;
1715
1716 /* If info block already allocated, free it */
1717 if (data->raw_info_block)
1718 mxt_free_object_table(data);
1719
1720 /* Read 7-byte ID information block starting at address 0 */
1721 size = sizeof(struct mxt_info);
1722 id_buf = kzalloc(size, GFP_KERNEL);
1723 if (!id_buf)
1724 return -ENOMEM;
1725
1726 error = __mxt_read_reg(client, 0, size, id_buf);
1727 if (error)
1728 goto err_free_mem;
1729
1730 /* Resize buffer to give space for rest of info block */
1731 num_objects = ((struct mxt_info *)id_buf)->object_num;
1732 size += (num_objects * sizeof(struct mxt_object))
1733 + MXT_INFO_CHECKSUM_SIZE;
1734
1735 buf = krealloc(id_buf, size, GFP_KERNEL);
1736 if (!buf) {
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001737 error = -ENOMEM;
Nick Dyer068bdb62018-05-01 11:40:18 -07001738 goto err_free_mem;
1739 }
1740 id_buf = buf;
1741
1742 /* Read rest of info block */
1743 error = __mxt_read_reg(client, MXT_OBJECT_START,
1744 size - MXT_OBJECT_START,
1745 id_buf + MXT_OBJECT_START);
1746 if (error)
1747 goto err_free_mem;
1748
1749 /* Extract & calculate checksum */
1750 crc_ptr = id_buf + size - MXT_INFO_CHECKSUM_SIZE;
1751 data->info_crc = crc_ptr[0] | (crc_ptr[1] << 8) | (crc_ptr[2] << 16);
1752
1753 calculated_crc = mxt_calculate_crc(id_buf, 0,
1754 size - MXT_INFO_CHECKSUM_SIZE);
1755
1756 /*
1757 * CRC mismatch can be caused by data corruption due to I2C comms
1758 * issue or else device is not using Object Based Protocol (eg i2c-hid)
1759 */
1760 if ((data->info_crc == 0) || (data->info_crc != calculated_crc)) {
1761 dev_err(&client->dev,
1762 "Info Block CRC error calculated=0x%06X read=0x%06X\n",
1763 calculated_crc, data->info_crc);
1764 error = -EIO;
1765 goto err_free_mem;
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001766 }
1767
Nick Dyer068bdb62018-05-01 11:40:18 -07001768 data->raw_info_block = id_buf;
1769 data->info = (struct mxt_info *)id_buf;
1770
1771 dev_info(&client->dev,
1772 "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n",
1773 data->info->family_id, data->info->variant_id,
1774 data->info->version >> 4, data->info->version & 0xf,
1775 data->info->build, data->info->object_num);
1776
1777 /* Parse object table information */
1778 error = mxt_parse_object_table(data, id_buf + MXT_OBJECT_START);
1779 if (error) {
1780 dev_err(&client->dev, "Error %d parsing object table\n", error);
1781 mxt_free_object_table(data);
1782 goto err_free_mem;
1783 }
1784
1785 data->object_table = (struct mxt_object *)(id_buf + MXT_OBJECT_START);
Nick Dyerdd24dcf2014-07-23 11:25:55 -07001786
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001787 return 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07001788
Nick Dyer068bdb62018-05-01 11:40:18 -07001789err_free_mem:
1790 kfree(id_buf);
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07001791 return error;
Daniel Kurtz7d4fa102012-06-28 21:08:19 +08001792}
1793
Nick Dyer61dc1ab2014-05-18 23:16:49 -07001794static int mxt_read_t9_resolution(struct mxt_data *data)
1795{
1796 struct i2c_client *client = data->client;
1797 int error;
1798 struct t9_range range;
1799 unsigned char orient;
1800 struct mxt_object *object;
1801
1802 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
1803 if (!object)
1804 return -EINVAL;
1805
1806 error = __mxt_read_reg(client,
Nick Dyer27864892016-07-18 18:10:33 -03001807 object->start_address + MXT_T9_XSIZE,
1808 sizeof(data->xsize), &data->xsize);
1809 if (error)
1810 return error;
1811
1812 error = __mxt_read_reg(client,
1813 object->start_address + MXT_T9_YSIZE,
1814 sizeof(data->ysize), &data->ysize);
1815 if (error)
1816 return error;
1817
1818 error = __mxt_read_reg(client,
Nick Dyer61dc1ab2014-05-18 23:16:49 -07001819 object->start_address + MXT_T9_RANGE,
1820 sizeof(range), &range);
1821 if (error)
1822 return error;
1823
Nick Dyer1c0276d2016-01-10 18:29:34 -08001824 data->max_x = get_unaligned_le16(&range.x);
1825 data->max_y = get_unaligned_le16(&range.y);
Nick Dyer61dc1ab2014-05-18 23:16:49 -07001826
1827 error = __mxt_read_reg(client,
1828 object->start_address + MXT_T9_ORIENT,
1829 1, &orient);
1830 if (error)
1831 return error;
1832
Nick Dyer1c0276d2016-01-10 18:29:34 -08001833 data->xy_switch = orient & MXT_T9_ORIENT_SWITCH;
Nick Dyerde601f72016-07-18 18:10:34 -03001834 data->invertx = orient & MXT_T9_ORIENT_INVERTX;
1835 data->inverty = orient & MXT_T9_ORIENT_INVERTY;
Nick Dyer61dc1ab2014-05-18 23:16:49 -07001836
1837 return 0;
1838}
1839
Nick Dyerb23157d2015-04-06 11:25:13 -07001840static int mxt_read_t100_config(struct mxt_data *data)
1841{
1842 struct i2c_client *client = data->client;
1843 int error;
1844 struct mxt_object *object;
1845 u16 range_x, range_y;
1846 u8 cfg, tchaux;
1847 u8 aux;
1848
1849 object = mxt_get_object(data, MXT_TOUCH_MULTITOUCHSCREEN_T100);
1850 if (!object)
1851 return -EINVAL;
1852
Nick Dyer1c0276d2016-01-10 18:29:34 -08001853 /* read touchscreen dimensions */
Nick Dyerb23157d2015-04-06 11:25:13 -07001854 error = __mxt_read_reg(client,
1855 object->start_address + MXT_T100_XRANGE,
1856 sizeof(range_x), &range_x);
1857 if (error)
1858 return error;
1859
Nick Dyer1c0276d2016-01-10 18:29:34 -08001860 data->max_x = get_unaligned_le16(&range_x);
Nick Dyerb23157d2015-04-06 11:25:13 -07001861
1862 error = __mxt_read_reg(client,
1863 object->start_address + MXT_T100_YRANGE,
1864 sizeof(range_y), &range_y);
1865 if (error)
1866 return error;
1867
Nick Dyer1c0276d2016-01-10 18:29:34 -08001868 data->max_y = get_unaligned_le16(&range_y);
Nick Dyerb23157d2015-04-06 11:25:13 -07001869
Nick Dyer27864892016-07-18 18:10:33 -03001870 error = __mxt_read_reg(client,
1871 object->start_address + MXT_T100_XSIZE,
1872 sizeof(data->xsize), &data->xsize);
1873 if (error)
1874 return error;
1875
1876 error = __mxt_read_reg(client,
1877 object->start_address + MXT_T100_YSIZE,
1878 sizeof(data->ysize), &data->ysize);
1879 if (error)
1880 return error;
1881
Nick Dyer1c0276d2016-01-10 18:29:34 -08001882 /* read orientation config */
Nick Dyerb23157d2015-04-06 11:25:13 -07001883 error = __mxt_read_reg(client,
1884 object->start_address + MXT_T100_CFG1,
1885 1, &cfg);
1886 if (error)
1887 return error;
1888
Nick Dyer1c0276d2016-01-10 18:29:34 -08001889 data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY;
Nick Dyerde601f72016-07-18 18:10:34 -03001890 data->invertx = cfg & MXT_T100_CFG_INVERTX;
1891 data->inverty = cfg & MXT_T100_CFG_INVERTY;
Nick Dyer1c0276d2016-01-10 18:29:34 -08001892
1893 /* allocate aux bytes */
Nick Dyerb23157d2015-04-06 11:25:13 -07001894 error = __mxt_read_reg(client,
1895 object->start_address + MXT_T100_TCHAUX,
1896 1, &tchaux);
1897 if (error)
1898 return error;
1899
Nick Dyerb23157d2015-04-06 11:25:13 -07001900 aux = 6;
1901
1902 if (tchaux & MXT_T100_TCHAUX_VECT)
1903 data->t100_aux_vect = aux++;
1904
1905 if (tchaux & MXT_T100_TCHAUX_AMPL)
1906 data->t100_aux_ampl = aux++;
1907
1908 if (tchaux & MXT_T100_TCHAUX_AREA)
1909 data->t100_aux_area = aux++;
1910
1911 dev_dbg(&client->dev,
1912 "T100 aux mappings vect:%u ampl:%u area:%u\n",
1913 data->t100_aux_vect, data->t100_aux_ampl, data->t100_aux_area);
1914
Nick Dyerb23157d2015-04-06 11:25:13 -07001915 return 0;
1916}
1917
Nick Dyer7a53d602014-07-23 12:21:26 -07001918static int mxt_input_open(struct input_dev *dev);
1919static void mxt_input_close(struct input_dev *dev);
1920
Sjoerd Simonsb6d2d322015-04-06 13:10:30 -07001921static void mxt_set_up_as_touchpad(struct input_dev *input_dev,
1922 struct mxt_data *data)
1923{
Sjoerd Simonsb6d2d322015-04-06 13:10:30 -07001924 int i;
1925
1926 input_dev->name = "Atmel maXTouch Touchpad";
1927
1928 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
1929
1930 input_abs_set_res(input_dev, ABS_X, MXT_PIXELS_PER_MM);
1931 input_abs_set_res(input_dev, ABS_Y, MXT_PIXELS_PER_MM);
1932 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
1933 MXT_PIXELS_PER_MM);
1934 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
1935 MXT_PIXELS_PER_MM);
1936
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07001937 for (i = 0; i < data->t19_num_keys; i++)
1938 if (data->t19_keymap[i] != KEY_RESERVED)
Sjoerd Simonsb6d2d322015-04-06 13:10:30 -07001939 input_set_capability(input_dev, EV_KEY,
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07001940 data->t19_keymap[i]);
Sjoerd Simonsb6d2d322015-04-06 13:10:30 -07001941}
1942
Nick Dyerb23157d2015-04-06 11:25:13 -07001943static int mxt_initialize_input_device(struct mxt_data *data)
Nick Dyer7a53d602014-07-23 12:21:26 -07001944{
Sjoerd Simonsb6d2d322015-04-06 13:10:30 -07001945 struct device *dev = &data->client->dev;
Nick Dyer7a53d602014-07-23 12:21:26 -07001946 struct input_dev *input_dev;
1947 int error;
1948 unsigned int num_mt_slots;
1949 unsigned int mt_flags = 0;
Nick Dyer7a53d602014-07-23 12:21:26 -07001950
Nick Dyerb23157d2015-04-06 11:25:13 -07001951 switch (data->multitouch) {
1952 case MXT_TOUCH_MULTI_T9:
1953 num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
1954 error = mxt_read_t9_resolution(data);
1955 if (error)
1956 dev_warn(dev, "Failed to initialize T9 resolution\n");
1957 break;
1958
1959 case MXT_TOUCH_MULTITOUCHSCREEN_T100:
1960 num_mt_slots = data->num_touchids;
1961 error = mxt_read_t100_config(data);
1962 if (error)
1963 dev_warn(dev, "Failed to read T100 config\n");
1964 break;
1965
1966 default:
1967 dev_err(dev, "Invalid multitouch object\n");
1968 return -EINVAL;
1969 }
Nick Dyer7a53d602014-07-23 12:21:26 -07001970
Nick Dyer1c0276d2016-01-10 18:29:34 -08001971 /* Handle default values and orientation switch */
1972 if (data->max_x == 0)
1973 data->max_x = 1023;
1974
1975 if (data->max_y == 0)
1976 data->max_y = 1023;
1977
1978 if (data->xy_switch)
1979 swap(data->max_x, data->max_y);
1980
1981 dev_info(dev, "Touchscreen size X%uY%u\n", data->max_x, data->max_y);
1982
1983 /* Register input device */
Nick Dyer7a53d602014-07-23 12:21:26 -07001984 input_dev = input_allocate_device();
1985 if (!input_dev) {
1986 dev_err(dev, "Failed to allocate memory\n");
1987 return -ENOMEM;
1988 }
1989
1990 input_dev->name = "Atmel maXTouch Touchscreen";
1991 input_dev->phys = data->phys;
1992 input_dev->id.bustype = BUS_I2C;
1993 input_dev->dev.parent = dev;
1994 input_dev->open = mxt_input_open;
1995 input_dev->close = mxt_input_close;
1996
Nick Dyerb23157d2015-04-06 11:25:13 -07001997 input_set_capability(input_dev, EV_KEY, BTN_TOUCH);
Nick Dyer7a53d602014-07-23 12:21:26 -07001998
Nick Dyer7a53d602014-07-23 12:21:26 -07001999 /* For single touch */
Nick Dyerb23157d2015-04-06 11:25:13 -07002000 input_set_abs_params(input_dev, ABS_X, 0, data->max_x, 0, 0);
2001 input_set_abs_params(input_dev, ABS_Y, 0, data->max_y, 0, 0);
2002
2003 if (data->multitouch == MXT_TOUCH_MULTI_T9 ||
2004 (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 &&
2005 data->t100_aux_ampl)) {
2006 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 255, 0, 0);
2007 }
Nick Dyer7a53d602014-07-23 12:21:26 -07002008
Sjoerd Simonsb6d2d322015-04-06 13:10:30 -07002009 /* If device has buttons we assume it is a touchpad */
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002010 if (data->t19_num_keys) {
Sjoerd Simonsb6d2d322015-04-06 13:10:30 -07002011 mxt_set_up_as_touchpad(input_dev, data);
2012 mt_flags |= INPUT_MT_POINTER;
Nick Dyereafc0c82015-08-04 16:57:40 -07002013 } else {
2014 mt_flags |= INPUT_MT_DIRECT;
Sjoerd Simonsb6d2d322015-04-06 13:10:30 -07002015 }
2016
Nick Dyer7a53d602014-07-23 12:21:26 -07002017 /* For multi touch */
Nick Dyer7a53d602014-07-23 12:21:26 -07002018 error = input_mt_init_slots(input_dev, num_mt_slots, mt_flags);
2019 if (error) {
2020 dev_err(dev, "Error %d initialising slots\n", error);
2021 goto err_free_mem;
2022 }
2023
Nick Dyerb23157d2015-04-06 11:25:13 -07002024 if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100) {
2025 input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE,
2026 0, MT_TOOL_MAX, 0, 0);
2027 input_set_abs_params(input_dev, ABS_MT_DISTANCE,
2028 MXT_DISTANCE_ACTIVE_TOUCH,
2029 MXT_DISTANCE_HOVERING,
2030 0, 0);
2031 }
2032
Nick Dyer7a53d602014-07-23 12:21:26 -07002033 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
2034 0, data->max_x, 0, 0);
2035 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
2036 0, data->max_y, 0, 0);
Nick Dyerb23157d2015-04-06 11:25:13 -07002037
2038 if (data->multitouch == MXT_TOUCH_MULTI_T9 ||
2039 (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 &&
2040 data->t100_aux_area)) {
2041 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
2042 0, MXT_MAX_AREA, 0, 0);
2043 }
2044
2045 if (data->multitouch == MXT_TOUCH_MULTI_T9 ||
2046 (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 &&
2047 data->t100_aux_ampl)) {
2048 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
2049 0, 255, 0, 0);
2050 }
2051
2052 if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 &&
2053 data->t100_aux_vect) {
2054 input_set_abs_params(input_dev, ABS_MT_ORIENTATION,
2055 0, 255, 0, 0);
2056 }
2057
2058 if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 &&
2059 data->t100_aux_ampl) {
2060 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
2061 0, 255, 0, 0);
2062 }
2063
2064 if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 &&
2065 data->t100_aux_vect) {
2066 input_set_abs_params(input_dev, ABS_MT_ORIENTATION,
2067 0, 255, 0, 0);
2068 }
Nick Dyer7a53d602014-07-23 12:21:26 -07002069
2070 input_set_drvdata(input_dev, data);
2071
2072 error = input_register_device(input_dev);
2073 if (error) {
2074 dev_err(dev, "Error %d registering input device\n", error);
2075 goto err_free_mem;
2076 }
2077
2078 data->input_dev = input_dev;
2079
2080 return 0;
2081
2082err_free_mem:
2083 input_free_device(input_dev);
2084 return error;
2085}
2086
Nick Dyer50a77c62014-07-23 12:38:48 -07002087static int mxt_configure_objects(struct mxt_data *data,
2088 const struct firmware *cfg);
2089
2090static void mxt_config_cb(const struct firmware *cfg, void *ctx)
2091{
2092 mxt_configure_objects(ctx, cfg);
Dmitry Torokhovefdbd7a2014-08-08 09:29:06 -07002093 release_firmware(cfg);
Nick Dyer50a77c62014-07-23 12:38:48 -07002094}
2095
Iiro Valkonen7686b102011-02-02 23:21:58 -08002096static int mxt_initialize(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002097{
2098 struct i2c_client *client = data->client;
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -07002099 int recovery_attempts = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002100 int error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002101
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -07002102 while (1) {
Nick Dyer068bdb62018-05-01 11:40:18 -07002103 error = mxt_read_info_block(data);
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -07002104 if (!error)
2105 break;
2106
2107 /* Check bootloader state */
2108 error = mxt_probe_bootloader(data, false);
Nick Dyer8efaa5e2014-07-23 12:45:49 -07002109 if (error) {
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -07002110 dev_info(&client->dev, "Trying alternate bootloader address\n");
2111 error = mxt_probe_bootloader(data, true);
2112 if (error) {
Nick Dyer8efaa5e2014-07-23 12:45:49 -07002113 /* Chip is not in appmode or bootloader mode */
2114 return error;
2115 }
Nick Dyer8efaa5e2014-07-23 12:45:49 -07002116 }
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -07002117
2118 /* OK, we are in bootloader, see if we can recover */
2119 if (++recovery_attempts > 1) {
2120 dev_err(&client->dev, "Could not recover from bootloader mode\n");
2121 /*
2122 * We can reflash from this state, so do not
2123 * abort initialization.
2124 */
2125 data->in_bootloader = true;
2126 return 0;
2127 }
2128
2129 /* Attempt to exit bootloader into app mode */
2130 mxt_send_bootloader_cmd(data, false);
2131 msleep(MXT_FW_RESET_TIME);
Nick Dyera9fdd1e2014-07-23 12:41:58 -07002132 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002133
Dmitry Torokhov041fa152014-08-11 10:58:29 -07002134 error = mxt_acquire_irq(data);
Nick Dyerdd24dcf2014-07-23 11:25:55 -07002135 if (error)
Nick Dyer068bdb62018-05-01 11:40:18 -07002136 return error;
Nick Dyerdd24dcf2014-07-23 11:25:55 -07002137
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -07002138 error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME,
2139 &client->dev, GFP_KERNEL, data,
2140 mxt_config_cb);
2141 if (error) {
2142 dev_err(&client->dev, "Failed to invoke firmware loader: %d\n",
2143 error);
Nick Dyer068bdb62018-05-01 11:40:18 -07002144 return error;
Dmitry Torokhov6cd1ab02014-08-08 09:28:45 -07002145 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002146
2147 return 0;
2148}
2149
Nick Dyer7f3884f72015-08-04 16:36:29 -07002150static int mxt_set_t7_power_cfg(struct mxt_data *data, u8 sleep)
2151{
2152 struct device *dev = &data->client->dev;
2153 int error;
2154 struct t7_config *new_config;
2155 struct t7_config deepsleep = { .active = 0, .idle = 0 };
2156
2157 if (sleep == MXT_POWER_CFG_DEEPSLEEP)
2158 new_config = &deepsleep;
2159 else
2160 new_config = &data->t7_cfg;
2161
2162 error = __mxt_write_reg(data->client, data->T7_address,
2163 sizeof(data->t7_cfg), new_config);
2164 if (error)
2165 return error;
2166
2167 dev_dbg(dev, "Set T7 ACTV:%d IDLE:%d\n",
2168 new_config->active, new_config->idle);
2169
2170 return 0;
2171}
2172
2173static int mxt_init_t7_power_cfg(struct mxt_data *data)
2174{
2175 struct device *dev = &data->client->dev;
2176 int error;
2177 bool retry = false;
2178
2179recheck:
2180 error = __mxt_read_reg(data->client, data->T7_address,
2181 sizeof(data->t7_cfg), &data->t7_cfg);
2182 if (error)
2183 return error;
2184
2185 if (data->t7_cfg.active == 0 || data->t7_cfg.idle == 0) {
2186 if (!retry) {
2187 dev_dbg(dev, "T7 cfg zero, resetting\n");
2188 mxt_soft_reset(data);
2189 retry = true;
2190 goto recheck;
2191 } else {
2192 dev_dbg(dev, "T7 cfg zero after reset, overriding\n");
2193 data->t7_cfg.active = 20;
2194 data->t7_cfg.idle = 100;
2195 return mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN);
2196 }
2197 }
2198
2199 dev_dbg(dev, "Initialized power cfg: ACTV %d, IDLE %d\n",
2200 data->t7_cfg.active, data->t7_cfg.idle);
2201 return 0;
2202}
2203
Nick Dyerd6a39402016-07-18 18:10:31 -03002204#ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37
2205static u16 mxt_get_debug_value(struct mxt_data *data, unsigned int x,
2206 unsigned int y)
2207{
Nick Dyer068bdb62018-05-01 11:40:18 -07002208 struct mxt_info *info = data->info;
Nick Dyerd6a39402016-07-18 18:10:31 -03002209 struct mxt_dbg *dbg = &data->dbg;
2210 unsigned int ofs, page;
Nick Dyer566d5332016-07-18 18:10:35 -03002211 unsigned int col = 0;
2212 unsigned int col_width;
Nick Dyerd6a39402016-07-18 18:10:31 -03002213
Nick Dyer566d5332016-07-18 18:10:35 -03002214 if (info->family_id == MXT_FAMILY_1386) {
2215 col_width = info->matrix_ysize / MXT1386_COLUMNS;
2216 col = y / col_width;
2217 y = y % col_width;
2218 } else {
2219 col_width = info->matrix_ysize;
2220 }
2221
2222 ofs = (y + (x * col_width)) * sizeof(u16);
Nick Dyerd6a39402016-07-18 18:10:31 -03002223 page = ofs / MXT_DIAGNOSTIC_SIZE;
2224 ofs %= MXT_DIAGNOSTIC_SIZE;
2225
Nick Dyer566d5332016-07-18 18:10:35 -03002226 if (info->family_id == MXT_FAMILY_1386)
2227 page += col * MXT1386_PAGES_PER_COLUMN;
2228
Nick Dyerd6a39402016-07-18 18:10:31 -03002229 return get_unaligned_le16(&dbg->t37_buf[page].data[ofs]);
2230}
2231
2232static int mxt_convert_debug_pages(struct mxt_data *data, u16 *outbuf)
2233{
2234 struct mxt_dbg *dbg = &data->dbg;
2235 unsigned int x = 0;
2236 unsigned int y = 0;
Nick Dyerde601f72016-07-18 18:10:34 -03002237 unsigned int i, rx, ry;
Nick Dyerd6a39402016-07-18 18:10:31 -03002238
2239 for (i = 0; i < dbg->t37_nodes; i++) {
Nick Dyerde601f72016-07-18 18:10:34 -03002240 /* Handle orientation */
2241 rx = data->xy_switch ? y : x;
2242 ry = data->xy_switch ? x : y;
2243 rx = data->invertx ? (data->xsize - 1 - rx) : rx;
2244 ry = data->inverty ? (data->ysize - 1 - ry) : ry;
2245
2246 outbuf[i] = mxt_get_debug_value(data, rx, ry);
Nick Dyerd6a39402016-07-18 18:10:31 -03002247
2248 /* Next value */
Nick Dyerde601f72016-07-18 18:10:34 -03002249 if (++x >= (data->xy_switch ? data->ysize : data->xsize)) {
Nick Dyerd6a39402016-07-18 18:10:31 -03002250 x = 0;
2251 y++;
2252 }
2253 }
2254
2255 return 0;
2256}
2257
2258static int mxt_read_diagnostic_debug(struct mxt_data *data, u8 mode,
2259 u16 *outbuf)
2260{
2261 struct mxt_dbg *dbg = &data->dbg;
2262 int retries = 0;
2263 int page;
2264 int ret;
2265 u8 cmd = mode;
2266 struct t37_debug *p;
2267 u8 cmd_poll;
2268
2269 for (page = 0; page < dbg->t37_pages; page++) {
2270 p = dbg->t37_buf + page;
2271
2272 ret = mxt_write_reg(data->client, dbg->diag_cmd_address,
2273 cmd);
2274 if (ret)
2275 return ret;
2276
2277 retries = 0;
2278 msleep(20);
2279wait_cmd:
2280 /* Read back command byte */
2281 ret = __mxt_read_reg(data->client, dbg->diag_cmd_address,
2282 sizeof(cmd_poll), &cmd_poll);
2283 if (ret)
2284 return ret;
2285
2286 /* Field is cleared once the command has been processed */
2287 if (cmd_poll) {
2288 if (retries++ > 100)
2289 return -EINVAL;
2290
2291 msleep(20);
2292 goto wait_cmd;
2293 }
2294
2295 /* Read T37 page */
2296 ret = __mxt_read_reg(data->client, dbg->t37_address,
2297 sizeof(struct t37_debug), p);
2298 if (ret)
2299 return ret;
2300
2301 if (p->mode != mode || p->page != page) {
2302 dev_err(&data->client->dev, "T37 page mismatch\n");
2303 return -EINVAL;
2304 }
2305
2306 dev_dbg(&data->client->dev, "%s page:%d retries:%d\n",
2307 __func__, page, retries);
2308
2309 /* For remaining pages, write PAGEUP rather than mode */
2310 cmd = MXT_DIAGNOSTIC_PAGEUP;
2311 }
2312
2313 return mxt_convert_debug_pages(data, outbuf);
2314}
2315
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002316static int mxt_queue_setup(struct vb2_queue *q,
2317 unsigned int *nbuffers, unsigned int *nplanes,
2318 unsigned int sizes[], struct device *alloc_devs[])
2319{
2320 struct mxt_data *data = q->drv_priv;
2321 size_t size = data->dbg.t37_nodes * sizeof(u16);
2322
2323 if (*nplanes)
2324 return sizes[0] < size ? -EINVAL : 0;
2325
2326 *nplanes = 1;
2327 sizes[0] = size;
2328
2329 return 0;
2330}
2331
2332static void mxt_buffer_queue(struct vb2_buffer *vb)
2333{
2334 struct mxt_data *data = vb2_get_drv_priv(vb->vb2_queue);
2335 u16 *ptr;
2336 int ret;
Nick Dyer06b3d3f2016-07-18 18:10:36 -03002337 u8 mode;
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002338
2339 ptr = vb2_plane_vaddr(vb, 0);
2340 if (!ptr) {
2341 dev_err(&data->client->dev, "Error acquiring frame ptr\n");
2342 goto fault;
2343 }
2344
Nick Dyer06b3d3f2016-07-18 18:10:36 -03002345 switch (data->dbg.input) {
2346 case MXT_V4L_INPUT_DELTAS:
2347 default:
2348 mode = MXT_DIAGNOSTIC_DELTAS;
2349 break;
2350
2351 case MXT_V4L_INPUT_REFS:
2352 mode = MXT_DIAGNOSTIC_REFS;
2353 break;
2354 }
2355
2356 ret = mxt_read_diagnostic_debug(data, mode, ptr);
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002357 if (ret)
2358 goto fault;
2359
2360 vb2_set_plane_payload(vb, 0, data->dbg.t37_nodes * sizeof(u16));
2361 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
2362 return;
2363
2364fault:
2365 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
2366}
2367
2368/* V4L2 structures */
2369static const struct vb2_ops mxt_queue_ops = {
2370 .queue_setup = mxt_queue_setup,
2371 .buf_queue = mxt_buffer_queue,
2372 .wait_prepare = vb2_ops_wait_prepare,
2373 .wait_finish = vb2_ops_wait_finish,
2374};
2375
2376static const struct vb2_queue mxt_queue = {
2377 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
2378 .io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ,
2379 .buf_struct_size = sizeof(struct mxt_vb2_buffer),
2380 .ops = &mxt_queue_ops,
2381 .mem_ops = &vb2_vmalloc_memops,
2382 .timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC,
2383 .min_buffers_needed = 1,
2384};
2385
2386static int mxt_vidioc_querycap(struct file *file, void *priv,
2387 struct v4l2_capability *cap)
2388{
2389 struct mxt_data *data = video_drvdata(file);
2390
2391 strlcpy(cap->driver, "atmel_mxt_ts", sizeof(cap->driver));
2392 strlcpy(cap->card, "atmel_mxt_ts touch", sizeof(cap->card));
2393 snprintf(cap->bus_info, sizeof(cap->bus_info),
2394 "I2C:%s", dev_name(&data->client->dev));
2395 return 0;
2396}
2397
2398static int mxt_vidioc_enum_input(struct file *file, void *priv,
2399 struct v4l2_input *i)
2400{
Nick Dyer06b3d3f2016-07-18 18:10:36 -03002401 if (i->index >= MXT_V4L_INPUT_MAX)
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002402 return -EINVAL;
2403
2404 i->type = V4L2_INPUT_TYPE_TOUCH;
Nick Dyer06b3d3f2016-07-18 18:10:36 -03002405
2406 switch (i->index) {
2407 case MXT_V4L_INPUT_REFS:
2408 strlcpy(i->name, "Mutual Capacitance References",
2409 sizeof(i->name));
2410 break;
2411 case MXT_V4L_INPUT_DELTAS:
2412 strlcpy(i->name, "Mutual Capacitance Deltas", sizeof(i->name));
2413 break;
2414 }
2415
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002416 return 0;
2417}
2418
2419static int mxt_set_input(struct mxt_data *data, unsigned int i)
2420{
2421 struct v4l2_pix_format *f = &data->dbg.format;
2422
Nick Dyer06b3d3f2016-07-18 18:10:36 -03002423 if (i >= MXT_V4L_INPUT_MAX)
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002424 return -EINVAL;
2425
Nick Dyer06b3d3f2016-07-18 18:10:36 -03002426 if (i == MXT_V4L_INPUT_DELTAS)
2427 f->pixelformat = V4L2_TCH_FMT_DELTA_TD16;
2428 else
2429 f->pixelformat = V4L2_TCH_FMT_TU16;
2430
Nick Dyerde601f72016-07-18 18:10:34 -03002431 f->width = data->xy_switch ? data->ysize : data->xsize;
2432 f->height = data->xy_switch ? data->xsize : data->ysize;
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002433 f->field = V4L2_FIELD_NONE;
2434 f->colorspace = V4L2_COLORSPACE_RAW;
2435 f->bytesperline = f->width * sizeof(u16);
2436 f->sizeimage = f->width * f->height * sizeof(u16);
2437
2438 data->dbg.input = i;
2439
2440 return 0;
2441}
2442
2443static int mxt_vidioc_s_input(struct file *file, void *priv, unsigned int i)
2444{
2445 return mxt_set_input(video_drvdata(file), i);
2446}
2447
2448static int mxt_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
2449{
2450 struct mxt_data *data = video_drvdata(file);
2451
2452 *i = data->dbg.input;
2453
2454 return 0;
2455}
2456
2457static int mxt_vidioc_fmt(struct file *file, void *priv, struct v4l2_format *f)
2458{
2459 struct mxt_data *data = video_drvdata(file);
2460
2461 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2462 f->fmt.pix = data->dbg.format;
2463
2464 return 0;
2465}
2466
2467static int mxt_vidioc_enum_fmt(struct file *file, void *priv,
2468 struct v4l2_fmtdesc *fmt)
2469{
2470 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
2471 return -EINVAL;
2472
Nick Dyer06b3d3f2016-07-18 18:10:36 -03002473 switch (fmt->index) {
2474 case 0:
2475 fmt->pixelformat = V4L2_TCH_FMT_TU16;
2476 break;
2477
2478 case 1:
2479 fmt->pixelformat = V4L2_TCH_FMT_DELTA_TD16;
2480 break;
2481
2482 default:
2483 return -EINVAL;
2484 }
2485
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002486 return 0;
2487}
2488
2489static int mxt_vidioc_g_parm(struct file *file, void *fh,
2490 struct v4l2_streamparm *a)
2491{
2492 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
2493 return -EINVAL;
2494
2495 a->parm.capture.readbuffers = 1;
2496 a->parm.capture.timeperframe.numerator = 1;
2497 a->parm.capture.timeperframe.denominator = 10;
2498 return 0;
2499}
2500
2501static const struct v4l2_ioctl_ops mxt_video_ioctl_ops = {
2502 .vidioc_querycap = mxt_vidioc_querycap,
2503
2504 .vidioc_enum_fmt_vid_cap = mxt_vidioc_enum_fmt,
2505 .vidioc_s_fmt_vid_cap = mxt_vidioc_fmt,
2506 .vidioc_g_fmt_vid_cap = mxt_vidioc_fmt,
2507 .vidioc_try_fmt_vid_cap = mxt_vidioc_fmt,
2508 .vidioc_g_parm = mxt_vidioc_g_parm,
2509
2510 .vidioc_enum_input = mxt_vidioc_enum_input,
2511 .vidioc_g_input = mxt_vidioc_g_input,
2512 .vidioc_s_input = mxt_vidioc_s_input,
2513
2514 .vidioc_reqbufs = vb2_ioctl_reqbufs,
2515 .vidioc_create_bufs = vb2_ioctl_create_bufs,
2516 .vidioc_querybuf = vb2_ioctl_querybuf,
2517 .vidioc_qbuf = vb2_ioctl_qbuf,
2518 .vidioc_dqbuf = vb2_ioctl_dqbuf,
2519 .vidioc_expbuf = vb2_ioctl_expbuf,
2520
2521 .vidioc_streamon = vb2_ioctl_streamon,
2522 .vidioc_streamoff = vb2_ioctl_streamoff,
2523};
2524
2525static const struct video_device mxt_video_device = {
2526 .name = "Atmel maxTouch",
2527 .fops = &mxt_video_fops,
2528 .ioctl_ops = &mxt_video_ioctl_ops,
2529 .release = video_device_release_empty,
2530 .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TOUCH |
2531 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING,
2532};
2533
Nick Dyerd6a39402016-07-18 18:10:31 -03002534static void mxt_debug_init(struct mxt_data *data)
2535{
Nick Dyer068bdb62018-05-01 11:40:18 -07002536 struct mxt_info *info = data->info;
Nick Dyerd6a39402016-07-18 18:10:31 -03002537 struct mxt_dbg *dbg = &data->dbg;
2538 struct mxt_object *object;
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002539 int error;
Nick Dyerd6a39402016-07-18 18:10:31 -03002540
2541 object = mxt_get_object(data, MXT_GEN_COMMAND_T6);
2542 if (!object)
2543 goto error;
2544
2545 dbg->diag_cmd_address = object->start_address + MXT_COMMAND_DIAGNOSTIC;
2546
2547 object = mxt_get_object(data, MXT_DEBUG_DIAGNOSTIC_T37);
2548 if (!object)
2549 goto error;
2550
2551 if (mxt_obj_size(object) != sizeof(struct t37_debug)) {
2552 dev_warn(&data->client->dev, "Bad T37 size");
2553 goto error;
2554 }
2555
2556 dbg->t37_address = object->start_address;
2557
2558 /* Calculate size of data and allocate buffer */
Nick Dyer27864892016-07-18 18:10:33 -03002559 dbg->t37_nodes = data->xsize * data->ysize;
Nick Dyer566d5332016-07-18 18:10:35 -03002560
2561 if (info->family_id == MXT_FAMILY_1386)
2562 dbg->t37_pages = MXT1386_COLUMNS * MXT1386_PAGES_PER_COLUMN;
2563 else
2564 dbg->t37_pages = DIV_ROUND_UP(data->xsize *
Guenter Roeckd7ddf152017-01-21 23:46:47 -08002565 info->matrix_ysize *
Nick Dyer566d5332016-07-18 18:10:35 -03002566 sizeof(u16),
2567 sizeof(dbg->t37_buf->data));
Nick Dyerd6a39402016-07-18 18:10:31 -03002568
2569 dbg->t37_buf = devm_kmalloc_array(&data->client->dev, dbg->t37_pages,
2570 sizeof(struct t37_debug), GFP_KERNEL);
2571 if (!dbg->t37_buf)
2572 goto error;
2573
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002574 /* init channel to zero */
2575 mxt_set_input(data, 0);
2576
2577 /* register video device */
2578 snprintf(dbg->v4l2.name, sizeof(dbg->v4l2.name), "%s", "atmel_mxt_ts");
2579 error = v4l2_device_register(&data->client->dev, &dbg->v4l2);
2580 if (error)
2581 goto error;
2582
2583 /* initialize the queue */
2584 mutex_init(&dbg->lock);
2585 dbg->queue = mxt_queue;
2586 dbg->queue.drv_priv = data;
2587 dbg->queue.lock = &dbg->lock;
2588 dbg->queue.dev = &data->client->dev;
2589
2590 error = vb2_queue_init(&dbg->queue);
2591 if (error)
2592 goto error_unreg_v4l2;
2593
2594 dbg->vdev = mxt_video_device;
2595 dbg->vdev.v4l2_dev = &dbg->v4l2;
2596 dbg->vdev.lock = &dbg->lock;
2597 dbg->vdev.vfl_dir = VFL_DIR_RX;
2598 dbg->vdev.queue = &dbg->queue;
2599 video_set_drvdata(&dbg->vdev, data);
2600
2601 error = video_register_device(&dbg->vdev, VFL_TYPE_TOUCH, -1);
2602 if (error)
2603 goto error_unreg_v4l2;
2604
Nick Dyerd6a39402016-07-18 18:10:31 -03002605 return;
2606
Nick Dyerecfdd7e2016-07-18 18:10:32 -03002607error_unreg_v4l2:
2608 v4l2_device_unregister(&dbg->v4l2);
Nick Dyerd6a39402016-07-18 18:10:31 -03002609error:
2610 dev_warn(&data->client->dev, "Error initializing T37\n");
2611}
2612#else
2613static void mxt_debug_init(struct mxt_data *data)
2614{
2615}
2616#endif
2617
Nick Dyer50a77c62014-07-23 12:38:48 -07002618static int mxt_configure_objects(struct mxt_data *data,
2619 const struct firmware *cfg)
2620{
2621 struct device *dev = &data->client->dev;
Nick Dyer50a77c62014-07-23 12:38:48 -07002622 int error;
2623
Nick Dyer7f3884f72015-08-04 16:36:29 -07002624 error = mxt_init_t7_power_cfg(data);
2625 if (error) {
2626 dev_err(dev, "Failed to initialize power cfg\n");
2627 return error;
2628 }
2629
Nick Dyer50a77c62014-07-23 12:38:48 -07002630 if (cfg) {
2631 error = mxt_update_cfg(data, cfg);
2632 if (error)
2633 dev_warn(dev, "Error %d updating config\n", error);
2634 }
2635
Nick Dyerb23157d2015-04-06 11:25:13 -07002636 if (data->multitouch) {
2637 error = mxt_initialize_input_device(data);
2638 if (error)
2639 return error;
2640 } else {
2641 dev_warn(dev, "No touch object detected\n");
2642 }
Nick Dyer50a77c62014-07-23 12:38:48 -07002643
Nick Dyerd6a39402016-07-18 18:10:31 -03002644 mxt_debug_init(data);
2645
Nick Dyer50a77c62014-07-23 12:38:48 -07002646 return 0;
2647}
2648
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08002649/* Firmware Version is returned as Major.Minor.Build */
2650static ssize_t mxt_fw_version_show(struct device *dev,
2651 struct device_attribute *attr, char *buf)
2652{
2653 struct mxt_data *data = dev_get_drvdata(dev);
Nick Dyer068bdb62018-05-01 11:40:18 -07002654 struct mxt_info *info = data->info;
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08002655 return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n",
2656 info->version >> 4, info->version & 0xf, info->build);
2657}
2658
2659/* Hardware Version is returned as FamilyID.VariantID */
2660static ssize_t mxt_hw_version_show(struct device *dev,
2661 struct device_attribute *attr, char *buf)
2662{
2663 struct mxt_data *data = dev_get_drvdata(dev);
Nick Dyer068bdb62018-05-01 11:40:18 -07002664 struct mxt_info *info = data->info;
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08002665 return scnprintf(buf, PAGE_SIZE, "%u.%u\n",
2666 info->family_id, info->variant_id);
2667}
2668
Daniel Kurtz794eb672012-06-28 21:08:10 +08002669static ssize_t mxt_show_instance(char *buf, int count,
2670 struct mxt_object *object, int instance,
2671 const u8 *val)
2672{
2673 int i;
2674
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07002675 if (mxt_obj_instances(object) > 1)
Daniel Kurtz794eb672012-06-28 21:08:10 +08002676 count += scnprintf(buf + count, PAGE_SIZE - count,
2677 "Instance %u\n", instance);
2678
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07002679 for (i = 0; i < mxt_obj_size(object); i++)
Daniel Kurtz794eb672012-06-28 21:08:10 +08002680 count += scnprintf(buf + count, PAGE_SIZE - count,
2681 "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
2682 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
2683
2684 return count;
2685}
2686
Iiro Valkonen7686b102011-02-02 23:21:58 -08002687static ssize_t mxt_object_show(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002688 struct device_attribute *attr, char *buf)
2689{
Iiro Valkonen7686b102011-02-02 23:21:58 -08002690 struct mxt_data *data = dev_get_drvdata(dev);
2691 struct mxt_object *object;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002692 int count = 0;
2693 int i, j;
2694 int error;
Daniel Kurtz43a91d52012-06-28 21:08:08 +08002695 u8 *obuf;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002696
Daniel Kurtz43a91d52012-06-28 21:08:08 +08002697 /* Pre-allocate buffer large enough to hold max sized object. */
2698 obuf = kmalloc(256, GFP_KERNEL);
2699 if (!obuf)
2700 return -ENOMEM;
2701
2702 error = 0;
Nick Dyer068bdb62018-05-01 11:40:18 -07002703 for (i = 0; i < data->info->object_num; i++) {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002704 object = data->object_table + i;
2705
Daniel Kurtz91630952012-06-28 21:08:09 +08002706 if (!mxt_object_readable(object->type))
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002707 continue;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002708
Daniel Kurtz91630952012-06-28 21:08:09 +08002709 count += scnprintf(buf + count, PAGE_SIZE - count,
2710 "T%u:\n", object->type);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002711
Daniel Kurtz1e0c0c52014-05-18 23:01:12 -07002712 for (j = 0; j < mxt_obj_instances(object); j++) {
2713 u16 size = mxt_obj_size(object);
Daniel Kurtz794eb672012-06-28 21:08:10 +08002714 u16 addr = object->start_address + j * size;
Daniel Kurtz43a91d52012-06-28 21:08:08 +08002715
Daniel Kurtz794eb672012-06-28 21:08:10 +08002716 error = __mxt_read_reg(data->client, addr, size, obuf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002717 if (error)
Daniel Kurtz794eb672012-06-28 21:08:10 +08002718 goto done;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002719
Daniel Kurtz794eb672012-06-28 21:08:10 +08002720 count = mxt_show_instance(buf, count, object, j, obuf);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002721 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002722 }
2723
Daniel Kurtz794eb672012-06-28 21:08:10 +08002724done:
Daniel Kurtz43a91d52012-06-28 21:08:08 +08002725 kfree(obuf);
2726 return error ?: count;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002727}
2728
Nick Dyerf2ac6cb2014-05-18 23:15:01 -07002729static int mxt_check_firmware_format(struct device *dev,
2730 const struct firmware *fw)
2731{
2732 unsigned int pos = 0;
2733 char c;
2734
2735 while (pos < fw->size) {
2736 c = *(fw->data + pos);
2737
2738 if (c < '0' || (c > '9' && c < 'A') || c > 'F')
2739 return 0;
2740
2741 pos++;
2742 }
2743
2744 /*
2745 * To convert file try:
2746 * xxd -r -p mXTXXX__APP_VX-X-XX.enc > maxtouch.fw
2747 */
2748 dev_err(dev, "Aborting: firmware file must be in binary format\n");
2749
2750 return -EINVAL;
2751}
2752
Iiro Valkonen7686b102011-02-02 23:21:58 -08002753static int mxt_load_fw(struct device *dev, const char *fn)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002754{
Iiro Valkonen7686b102011-02-02 23:21:58 -08002755 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002756 const struct firmware *fw = NULL;
2757 unsigned int frame_size;
2758 unsigned int pos = 0;
Nick Dyerf943c742014-05-18 23:14:20 -07002759 unsigned int retry = 0;
Nick Dyerf477c752014-05-18 23:14:45 -07002760 unsigned int frame = 0;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002761 int ret;
2762
2763 ret = request_firmware(&fw, fn, dev);
2764 if (ret) {
2765 dev_err(dev, "Unable to open firmware %s\n", fn);
2766 return ret;
2767 }
2768
Nick Dyerf2ac6cb2014-05-18 23:15:01 -07002769 /* Check for incorrect enc file */
2770 ret = mxt_check_firmware_format(dev, fw);
2771 if (ret)
2772 goto release_firmware;
2773
Nick Dyera9fdd1e2014-07-23 12:41:58 -07002774 if (!data->in_bootloader) {
2775 /* Change to the bootloader mode */
2776 data->in_bootloader = true;
Benson Leungd79e7e42014-05-18 23:02:52 -07002777
Nick Dyera9fdd1e2014-07-23 12:41:58 -07002778 ret = mxt_t6_command(data, MXT_COMMAND_RESET,
2779 MXT_BOOT_VALUE, false);
2780 if (ret)
2781 goto release_firmware;
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07002782
Nick Dyera9fdd1e2014-07-23 12:41:58 -07002783 msleep(MXT_RESET_TIME);
Nick Dyer8efaa5e2014-07-23 12:45:49 -07002784
2785 /* Do not need to scan since we know family ID */
2786 ret = mxt_lookup_bootloader_address(data, 0);
2787 if (ret)
2788 goto release_firmware;
Stephen Warren58e4aeee2014-09-10 10:01:10 -07002789
2790 mxt_free_input_device(data);
2791 mxt_free_object_table(data);
Nick Dyer8efaa5e2014-07-23 12:45:49 -07002792 } else {
2793 enable_irq(data->irq);
Nick Dyera9fdd1e2014-07-23 12:41:58 -07002794 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002795
Benson Leungd79e7e42014-05-18 23:02:52 -07002796 reinit_completion(&data->bl_completion);
2797
Nick Dyer385deb92014-07-23 12:42:40 -07002798 ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false);
2799 if (ret) {
2800 /* Bootloader may still be unlocked from previous attempt */
2801 ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, false);
2802 if (ret)
2803 goto disable_irq;
2804 } else {
2805 dev_info(dev, "Unlocking bootloader\n");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002806
Nick Dyer385deb92014-07-23 12:42:40 -07002807 /* Unlock bootloader */
Nick Dyer8efaa5e2014-07-23 12:45:49 -07002808 ret = mxt_send_bootloader_cmd(data, true);
Nick Dyer385deb92014-07-23 12:42:40 -07002809 if (ret)
2810 goto disable_irq;
2811 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002812
2813 while (pos < fw->size) {
Nick Dyer385deb92014-07-23 12:42:40 -07002814 ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002815 if (ret)
Benson Leungd79e7e42014-05-18 23:02:52 -07002816 goto disable_irq;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002817
2818 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
2819
Nick Dyerf943c742014-05-18 23:14:20 -07002820 /* Take account of CRC bytes */
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002821 frame_size += 2;
2822
2823 /* Write one frame to device */
Nick Dyerf28a8422014-05-18 23:10:49 -07002824 ret = mxt_bootloader_write(data, fw->data + pos, frame_size);
2825 if (ret)
2826 goto disable_irq;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002827
Nick Dyer385deb92014-07-23 12:42:40 -07002828 ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true);
Nick Dyerf943c742014-05-18 23:14:20 -07002829 if (ret) {
2830 retry++;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002831
Nick Dyerf943c742014-05-18 23:14:20 -07002832 /* Back off by 20ms per retry */
2833 msleep(retry * 20);
2834
2835 if (retry > 20) {
2836 dev_err(dev, "Retry count exceeded\n");
2837 goto disable_irq;
2838 }
2839 } else {
2840 retry = 0;
2841 pos += frame_size;
Nick Dyerf477c752014-05-18 23:14:45 -07002842 frame++;
Nick Dyerf943c742014-05-18 23:14:20 -07002843 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002844
Nick Dyerf477c752014-05-18 23:14:45 -07002845 if (frame % 50 == 0)
2846 dev_dbg(dev, "Sent %d frames, %d/%zd bytes\n",
2847 frame, pos, fw->size);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002848 }
2849
Benson Leunga0434b72014-05-18 23:03:09 -07002850 /* Wait for flash. */
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07002851 ret = mxt_wait_for_completion(data, &data->bl_completion,
2852 MXT_FW_RESET_TIME);
Benson Leunga0434b72014-05-18 23:03:09 -07002853 if (ret)
2854 goto disable_irq;
2855
Nick Dyerf477c752014-05-18 23:14:45 -07002856 dev_dbg(dev, "Sent %d frames, %d bytes\n", frame, pos);
2857
Benson Leunga0434b72014-05-18 23:03:09 -07002858 /*
2859 * Wait for device to reset. Some bootloader versions do not assert
2860 * the CHG line after bootloading has finished, so ignore potential
2861 * errors.
2862 */
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07002863 mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME);
Benson Leunga0434b72014-05-18 23:03:09 -07002864
Benson Leungd79e7e42014-05-18 23:02:52 -07002865 data->in_bootloader = false;
2866
2867disable_irq:
2868 disable_irq(data->irq);
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07002869release_firmware:
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002870 release_firmware(fw);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002871 return ret;
2872}
2873
Iiro Valkonen7686b102011-02-02 23:21:58 -08002874static ssize_t mxt_update_fw_store(struct device *dev,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002875 struct device_attribute *attr,
2876 const char *buf, size_t count)
2877{
Iiro Valkonen7686b102011-02-02 23:21:58 -08002878 struct mxt_data *data = dev_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002879 int error;
2880
Iiro Valkonen7686b102011-02-02 23:21:58 -08002881 error = mxt_load_fw(dev, MXT_FW_NAME);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002882 if (error) {
2883 dev_err(dev, "The firmware update failed(%d)\n", error);
2884 count = error;
2885 } else {
Nick Dyer7bed6802014-05-18 23:04:09 -07002886 dev_info(dev, "The firmware update succeeded\n");
2887
Nick Dyerdd24dcf2014-07-23 11:25:55 -07002888 error = mxt_initialize(data);
Benson Leungd79e7e42014-05-18 23:02:52 -07002889 if (error)
2890 return error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002891 }
2892
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002893 return count;
2894}
2895
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08002896static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
2897static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
Daniel Kurtz71b3e932012-05-08 22:30:14 -07002898static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
2899static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002900
Iiro Valkonen7686b102011-02-02 23:21:58 -08002901static struct attribute *mxt_attrs[] = {
Daniel Kurtzb19fc9e2012-06-28 21:08:16 +08002902 &dev_attr_fw_version.attr,
2903 &dev_attr_hw_version.attr,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002904 &dev_attr_object.attr,
2905 &dev_attr_update_fw.attr,
2906 NULL
2907};
2908
Iiro Valkonen7686b102011-02-02 23:21:58 -08002909static const struct attribute_group mxt_attr_group = {
2910 .attrs = mxt_attrs,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002911};
2912
Iiro Valkonen7686b102011-02-02 23:21:58 -08002913static void mxt_start(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002914{
Dmitry Torokhovd80808e2018-03-20 15:31:25 -07002915 switch (data->suspend_mode) {
Nick Dyer7f3884f72015-08-04 16:36:29 -07002916 case MXT_SUSPEND_T9_CTRL:
2917 mxt_soft_reset(data);
2918
2919 /* Touch enable */
2920 /* 0x83 = SCANEN | RPTEN | ENABLE */
2921 mxt_write_object(data,
2922 MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0x83);
2923 break;
2924
2925 case MXT_SUSPEND_DEEP_SLEEP:
2926 default:
2927 mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN);
2928
2929 /* Recalibrate since chip has been in deep sleep */
2930 mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false);
2931 break;
2932 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002933}
2934
Iiro Valkonen7686b102011-02-02 23:21:58 -08002935static void mxt_stop(struct mxt_data *data)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002936{
Dmitry Torokhovd80808e2018-03-20 15:31:25 -07002937 switch (data->suspend_mode) {
Nick Dyer7f3884f72015-08-04 16:36:29 -07002938 case MXT_SUSPEND_T9_CTRL:
2939 /* Touch disable */
2940 mxt_write_object(data,
2941 MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0);
2942 break;
2943
2944 case MXT_SUSPEND_DEEP_SLEEP:
2945 default:
2946 mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP);
2947 break;
2948 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002949}
2950
Iiro Valkonen7686b102011-02-02 23:21:58 -08002951static int mxt_input_open(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002952{
Iiro Valkonen7686b102011-02-02 23:21:58 -08002953 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002954
Iiro Valkonen7686b102011-02-02 23:21:58 -08002955 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002956
2957 return 0;
2958}
2959
Iiro Valkonen7686b102011-02-02 23:21:58 -08002960static void mxt_input_close(struct input_dev *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002961{
Iiro Valkonen7686b102011-02-02 23:21:58 -08002962 struct mxt_data *data = input_get_drvdata(dev);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002963
Iiro Valkonen7686b102011-02-02 23:21:58 -08002964 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07002965}
2966
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002967static int mxt_parse_device_properties(struct mxt_data *data)
Stephen Warren78188be2014-07-23 12:23:23 -07002968{
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002969 static const char keymap_property[] = "linux,gpio-keymap";
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002970 struct device *dev = &data->client->dev;
Stephen Warren78188be2014-07-23 12:23:23 -07002971 u32 *keymap;
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002972 int n_keys;
2973 int error;
Stephen Warren78188be2014-07-23 12:23:23 -07002974
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002975 if (device_property_present(dev, keymap_property)) {
2976 n_keys = device_property_read_u32_array(dev, keymap_property,
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002977 NULL, 0);
2978 if (n_keys <= 0) {
2979 error = n_keys < 0 ? n_keys : -EINVAL;
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002980 dev_err(dev, "invalid/malformed '%s' property: %d\n",
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002981 keymap_property, error);
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002982 return error;
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002983 }
Stephen Warren78188be2014-07-23 12:23:23 -07002984
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002985 keymap = devm_kmalloc_array(dev, n_keys, sizeof(*keymap),
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002986 GFP_KERNEL);
Stephen Warren78188be2014-07-23 12:23:23 -07002987 if (!keymap)
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002988 return -ENOMEM;
Stephen Warren78188be2014-07-23 12:23:23 -07002989
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002990 error = device_property_read_u32_array(dev, keymap_property,
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002991 keymap, n_keys);
2992 if (error) {
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002993 dev_err(dev, "failed to parse '%s' property: %d\n",
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002994 keymap_property, error);
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002995 return error;
Dmitry Torokhov93afb1d2018-03-20 15:31:26 -07002996 }
Stephen Warren78188be2014-07-23 12:23:23 -07002997
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07002998 data->t19_keymap = keymap;
2999 data->t19_num_keys = n_keys;
Stephen Warren78188be2014-07-23 12:23:23 -07003000 }
3001
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07003002 return 0;
Stephen Warren78188be2014-07-23 12:23:23 -07003003}
Stephen Warren78188be2014-07-23 12:23:23 -07003004
Dmitry Torokhovd80808e2018-03-20 15:31:25 -07003005static const struct dmi_system_id chromebook_T9_suspend_dmi[] = {
3006 {
3007 .matches = {
3008 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
3009 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
3010 },
3011 },
3012 {
3013 .matches = {
3014 DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"),
3015 },
3016 },
3017 { }
3018};
3019
Stephen Warren78188be2014-07-23 12:23:23 -07003020static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003021{
Iiro Valkonen7686b102011-02-02 23:21:58 -08003022 struct mxt_data *data;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003023 int error;
3024
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07003025 /*
Dmitry Torokhov7cf432b2018-05-03 17:14:51 -07003026 * Ignore devices that do not have device properties attached to
3027 * them, as we need help determining whether we are dealing with
3028 * touch screen or touchpad.
3029 *
3030 * So far on x86 the only users of Atmel touch controllers are
3031 * Chromebooks, and chromeos_laptop driver will ensure that
3032 * necessary properties are provided (if firmware does not do that).
3033 */
3034 if (!device_property_present(&client->dev, "compatible"))
3035 return -ENXIO;
3036
3037 /*
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07003038 * Ignore ACPI devices representing bootloader mode.
3039 *
3040 * This is a bit of a hack: Google Chromebook BIOS creates ACPI
3041 * devices for both application and bootloader modes, but we are
3042 * interested in application mode only (if device is in bootloader
3043 * mode we'll end up switching into application anyway). So far
3044 * application mode addresses were all above 0x40, so we'll use it
3045 * as a threshold.
3046 */
3047 if (ACPI_COMPANION(&client->dev) && client->addr < 0x40)
3048 return -ENXIO;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003049
Sebastian Reichel8cc84462017-07-25 14:08:48 -07003050 data = devm_kzalloc(&client->dev, sizeof(struct mxt_data), GFP_KERNEL);
3051 if (!data)
Nick Dyer7a53d602014-07-23 12:21:26 -07003052 return -ENOMEM;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003053
Daniel Kurtzec02ac22012-06-28 21:08:02 +08003054 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
3055 client->adapter->nr, client->addr);
Daniel Kurtz22dfab72013-03-07 19:43:33 -08003056
Joonyoung Shim910d8052011-04-12 23:14:38 -07003057 data->client = client;
Joonyoung Shim910d8052011-04-12 23:14:38 -07003058 data->irq = client->irq;
Nick Dyer7a53d602014-07-23 12:21:26 -07003059 i2c_set_clientdata(client, data);
Joonyoung Shim910d8052011-04-12 23:14:38 -07003060
Benson Leungd79e7e42014-05-18 23:02:52 -07003061 init_completion(&data->bl_completion);
Iiro Valkonena4a2ef42014-05-18 23:03:44 -07003062 init_completion(&data->reset_completion);
Nick Dyerc3f78042014-05-18 23:04:46 -07003063 init_completion(&data->crc_completion);
Benson Leungd79e7e42014-05-18 23:02:52 -07003064
Dmitry Torokhovd80808e2018-03-20 15:31:25 -07003065 data->suspend_mode = dmi_check_system(chromebook_T9_suspend_dmi) ?
3066 MXT_SUSPEND_T9_CTRL : MXT_SUSPEND_DEEP_SLEEP;
3067
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07003068 error = mxt_parse_device_properties(data);
3069 if (error)
3070 return error;
3071
Sebastian Reichelf657b002017-07-25 14:11:34 -07003072 data->reset_gpio = devm_gpiod_get_optional(&client->dev,
3073 "reset", GPIOD_OUT_LOW);
3074 if (IS_ERR(data->reset_gpio)) {
3075 error = PTR_ERR(data->reset_gpio);
3076 dev_err(&client->dev, "Failed to get reset gpio: %d\n", error);
3077 return error;
3078 }
3079
Sebastian Reichel8cc84462017-07-25 14:08:48 -07003080 error = devm_request_threaded_irq(&client->dev, client->irq,
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07003081 NULL, mxt_interrupt, IRQF_ONESHOT,
Sebastian Reichel8cc84462017-07-25 14:08:48 -07003082 client->name, data);
Nick Dyerdd24dcf2014-07-23 11:25:55 -07003083 if (error) {
3084 dev_err(&client->dev, "Failed to register interrupt\n");
Sebastian Reichel8cc84462017-07-25 14:08:48 -07003085 return error;
Nick Dyerdd24dcf2014-07-23 11:25:55 -07003086 }
3087
3088 disable_irq(client->irq);
3089
Sebastian Reichelca1cd362018-05-24 09:33:36 -07003090 if (data->reset_gpio) {
3091 msleep(MXT_RESET_GPIO_TIME);
3092 gpiod_set_value(data->reset_gpio, 1);
3093 msleep(MXT_RESET_INVALID_CHG);
3094 }
3095
Daniel Kurtzcb159112012-06-28 21:08:22 +08003096 error = mxt_initialize(data);
3097 if (error)
Sebastian Reichel8cc84462017-07-25 14:08:48 -07003098 return error;
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003099
Iiro Valkonen7686b102011-02-02 23:21:58 -08003100 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
Nick Dyer7bed6802014-05-18 23:04:09 -07003101 if (error) {
3102 dev_err(&client->dev, "Failure %d creating sysfs group\n",
3103 error);
Nick Dyer7a53d602014-07-23 12:21:26 -07003104 goto err_free_object;
Nick Dyer7bed6802014-05-18 23:04:09 -07003105 }
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003106
3107 return 0;
3108
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003109err_free_object:
Stephen Warren58e4aeee2014-09-10 10:01:10 -07003110 mxt_free_input_device(data);
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07003111 mxt_free_object_table(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003112 return error;
3113}
3114
Bill Pembertone2619cf2012-11-23 21:50:47 -08003115static int mxt_remove(struct i2c_client *client)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003116{
Iiro Valkonen7686b102011-02-02 23:21:58 -08003117 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003118
Sebastian Reichel8cc84462017-07-25 14:08:48 -07003119 disable_irq(data->irq);
Iiro Valkonen7686b102011-02-02 23:21:58 -08003120 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
Stephen Warren58e4aeee2014-09-10 10:01:10 -07003121 mxt_free_input_device(data);
Nick Dyer5f3f9bc2014-07-23 12:46:55 -07003122 mxt_free_object_table(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003123
3124 return 0;
3125}
3126
Jingoo Han02b6a582014-11-02 00:04:14 -07003127static int __maybe_unused mxt_suspend(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003128{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08003129 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08003130 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003131 struct input_dev *input_dev = data->input_dev;
3132
Pan Xinhui50fabb02015-08-04 16:53:04 -07003133 if (!input_dev)
3134 return 0;
3135
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003136 mutex_lock(&input_dev->mutex);
3137
3138 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08003139 mxt_stop(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003140
3141 mutex_unlock(&input_dev->mutex);
3142
3143 return 0;
3144}
3145
Jingoo Han02b6a582014-11-02 00:04:14 -07003146static int __maybe_unused mxt_resume(struct device *dev)
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003147{
Dmitry Torokhov8b5fce02010-11-18 00:14:03 -08003148 struct i2c_client *client = to_i2c_client(dev);
Iiro Valkonen7686b102011-02-02 23:21:58 -08003149 struct mxt_data *data = i2c_get_clientdata(client);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003150 struct input_dev *input_dev = data->input_dev;
3151
Pan Xinhui50fabb02015-08-04 16:53:04 -07003152 if (!input_dev)
3153 return 0;
3154
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003155 mutex_lock(&input_dev->mutex);
3156
3157 if (input_dev->users)
Iiro Valkonen7686b102011-02-02 23:21:58 -08003158 mxt_start(data);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003159
3160 mutex_unlock(&input_dev->mutex);
3161
3162 return 0;
3163}
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003164
Daniel Kurtz3a73c812012-05-08 22:29:14 -07003165static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
3166
Stephen Warren78188be2014-07-23 12:23:23 -07003167static const struct of_device_id mxt_of_match[] = {
3168 { .compatible = "atmel,maxtouch", },
Javier Martinez Canillasf6eeb9e2018-05-01 11:44:53 -07003169 /* Compatibles listed below are deprecated */
3170 { .compatible = "atmel,qt602240_ts", },
3171 { .compatible = "atmel,atmel_mxt_ts", },
3172 { .compatible = "atmel,atmel_mxt_tp", },
3173 { .compatible = "atmel,mXT224", },
Stephen Warren78188be2014-07-23 12:23:23 -07003174 {},
3175};
3176MODULE_DEVICE_TABLE(of, mxt_of_match);
3177
Dmitry Torokhov4f8d8082015-04-07 16:30:01 -07003178#ifdef CONFIG_ACPI
3179static const struct acpi_device_id mxt_acpi_id[] = {
3180 { "ATML0000", 0 }, /* Touchpad */
3181 { "ATML0001", 0 }, /* Touchscreen */
3182 { }
3183};
3184MODULE_DEVICE_TABLE(acpi, mxt_acpi_id);
3185#endif
3186
Iiro Valkonen7686b102011-02-02 23:21:58 -08003187static const struct i2c_device_id mxt_id[] = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003188 { "qt602240_ts", 0 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08003189 { "atmel_mxt_ts", 0 },
Daniel Kurtz22dfab72013-03-07 19:43:33 -08003190 { "atmel_mxt_tp", 0 },
Javier Martinez Canillasb7d21052015-12-11 13:22:39 -08003191 { "maxtouch", 0 },
Chris Leech46ee2a02011-02-15 13:36:52 -08003192 { "mXT224", 0 },
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003193 { }
3194};
Iiro Valkonen7686b102011-02-02 23:21:58 -08003195MODULE_DEVICE_TABLE(i2c, mxt_id);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003196
Iiro Valkonen7686b102011-02-02 23:21:58 -08003197static struct i2c_driver mxt_driver = {
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003198 .driver = {
Iiro Valkonen7686b102011-02-02 23:21:58 -08003199 .name = "atmel_mxt_ts",
Dmitry Torokhov96a938aa2018-03-20 15:31:38 -07003200 .of_match_table = mxt_of_match,
Dmitry Torokhov4f8d8082015-04-07 16:30:01 -07003201 .acpi_match_table = ACPI_PTR(mxt_acpi_id),
Iiro Valkonen7686b102011-02-02 23:21:58 -08003202 .pm = &mxt_pm_ops,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003203 },
Iiro Valkonen7686b102011-02-02 23:21:58 -08003204 .probe = mxt_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -08003205 .remove = mxt_remove,
Iiro Valkonen7686b102011-02-02 23:21:58 -08003206 .id_table = mxt_id,
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003207};
3208
Axel Lin1b92c1c2012-03-16 23:05:41 -07003209module_i2c_driver(mxt_driver);
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003210
3211/* Module information */
3212MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
Iiro Valkonen7686b102011-02-02 23:21:58 -08003213MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver");
Joonyoung Shim4cf51c32010-07-14 21:55:30 -07003214MODULE_LICENSE("GPL");