[ARM] tegra: stingray: update touch object elements.
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-tegra / board-stingray-touch.c
1 /*
2  * arch/arm/mach-tegra/board-stingray-touch.c
3  *
4  * Copyright (C) 2010 Motorola, Inc.
5  * Copyright (C) 2010 Google, Inc.
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17
18 #include <linux/resource.h>
19 #include <linux/platform_device.h>
20 #include <linux/delay.h>
21 #include <linux/gpio.h>
22 #include <linux/i2c.h>
23 #include <asm/mach-types.h>
24 #include <mach/irqs.h>
25 #include <mach/iomap.h>
26 #include <mach/pinmux.h>
27 #include <linux/qtouch_obp_ts.h>
28 #include <linux/interrupt.h>
29 #include <linux/input.h>
30
31 #include "board-stingray.h"
32 #include "gpio-names.h"
33
34 #define XMEGAT_BL_I2C_ADDR      0x35
35 #define STINGRAY_TOUCH_RESET_N_GPIO     TEGRA_GPIO_PR4
36 #define STINGRAY_TOUCH_INT_N_GPIO       TEGRA_GPIO_PV2
37 #define STINGRAY_TOUCH_WAKE_N_GPIO      TEGRA_GPIO_PJ2
38
39 static int stingray_touch_reset(void)
40 {
41         gpio_set_value(STINGRAY_TOUCH_RESET_N_GPIO, 0);
42         msleep(10);
43         gpio_set_value(STINGRAY_TOUCH_RESET_N_GPIO, 1);
44         msleep(100); /* value from moto */
45         return 0;
46 }
47
48 /* mortable M1 */
49 struct qtouch_ts_platform_data stingray_touch_data_m1 = {
50
51         .flags          = (QTOUCH_USE_MULTITOUCH |
52                            QTOUCH_CFG_BACKUPNV),
53         .irqflags               = (IRQF_TRIGGER_LOW),
54         .abs_min_x              = 0,
55         .abs_max_x              = 4095,
56         .abs_min_y              = 0,
57         .abs_max_y              = 4095,
58         .abs_min_p              = 0,
59         .abs_max_p              = 255,
60         .abs_min_w              = 0,
61         .abs_max_w              = 15,
62         .x_delta                = 400,
63         .y_delta                = 250,
64         .nv_checksum            = 0x2c30,
65         .fuzz_x                 = 0,
66         .fuzz_y                 = 0,
67         .fuzz_p                 = 2,
68         .fuzz_w                 = 2,
69         .boot_i2c_addr  = XMEGAT_BL_I2C_ADDR,
70         .hw_reset               = stingray_touch_reset,
71         .key_array = {
72                 .cfg            = NULL,
73                 .keys           = NULL,
74                 .num_keys       = 0,
75         },
76         .touch_fw_cfg = {
77                 .fw_name = "mXT1386_08_E1.bin",
78                 .family_id = 0xA0,
79                 .variant_id = 0x00,
80                 .fw_version = 0x08,
81                 .fw_build = 0xE1,
82                 .boot_version = 0x20,
83                 .base_fw_version = 0x00,
84         },
85         .power_cfg      = {
86                 .idle_acq_int   = 0xff,
87                 .active_acq_int = 0xff,
88                 .active_idle_to = 0x00,
89         },
90         .acquire_cfg    = {
91                 .charge_time    = 0x0A,
92                 .reserve1       = 0,
93                 .touch_drift    = 0x14,
94                 .drift_susp     = 0x14,
95                 .touch_autocal  = 0x00,
96                 .reserve5       = 0,
97                 .atch_cal_suspend_time  = 0,
98                 .atch_cal_suspend_thres = 0,
99                 .atch_cal_force_thres = 0x10,
100                 .atch_cal_force_ratio = 0,
101         },
102         .multi_touch_cfg        = {
103                 .ctrl           = 0x83,
104                 .x_origin       = 0,
105                 .y_origin       = 0,
106                 .x_size         = 0x1b,
107                 .y_size         = 0x2a,
108                 .aks_cfg        = 0,
109                 .burst_len      = 0x10,
110                 .tch_det_thr    = 45,
111                 .tch_det_int    = 0x3,
112                 .orient         = 7,
113                 .mrg_to         = 0x00,
114                 .mov_hyst_init  = 0x05,
115                 .mov_hyst_next  = 0x02,
116                 .mov_filter     = 0x20,
117                 .num_touch      = 0x01,
118                 .merge_hyst     = 0x0A,
119                 .merge_thresh   = 0x0A,
120                 .amp_hyst       = 0x0A,
121                 .x_res          = 0x0FFF,
122                 .y_res          = 0x0FFF,
123                 .x_low_clip     = 0x00,
124                 .x_high_clip    = 0x00,
125                 .y_low_clip     = 0x00,
126                 .y_high_clip    = 0x00,
127                 .x_edge_ctrl    = 0,
128                 .x_edge_dist    = 0,
129                 .y_edge_ctrl    = 0,
130                 .y_edge_dist    = 0,
131                 .jump_limit     = 0,
132         },
133         .comms_config_cfg = {
134                 .ctrl           = 0,
135                 .command        = 0,
136         },
137         .noise_suppression_cfg = {
138                 .ctrl                   = 0,
139                 .reserve1               = 0,
140                 .reserve2               = 0,
141                 .reserve3               = 0,
142                 .reserve4               = 0,
143                 .reserve5               = 0,
144                 .reserve6               = 0,
145                 .reserve7               = 0,
146                 .noise_thres            = 0,
147                 .reserve9               = 0,
148                 .freq_hop_scale         = 0,
149                 .burst_freq_0           = 0,
150                 .burst_freq_1           = 0,
151                 .burst_freq_2           = 0,
152                 .burst_freq_3           = 0,
153                 .burst_freq_4           = 0,
154                 .reserve16              = 0,
155         },
156         .one_touch_gesture_proc_cfg = {
157                 .ctrl                   = 0,
158                 .num_gestures           = 0,
159                 .gesture_enable         = 0,
160                 .pres_proc              = 0,
161                 .tap_time_out           = 0,
162                 .flick_time_out         = 0,
163                 .drag_time_out          = 0,
164                 .short_press_time_out   = 0,
165                 .long_press_time_out    = 0,
166                 .repeat_press_time_out  = 0,
167                 .flick_threshold        = 0,
168                 .drag_threshold         = 0,
169                 .tap_threshold          = 0,
170                 .throw_threshold        = 0,
171         },
172         .self_test_cfg = {
173                 .ctrl                   = 0,
174                 .command                = 0,
175                 .high_signal_limit_0    = 0,
176                 .low_signal_limit_0     = 0,
177                 .high_signal_limit_1    = 0,
178                 .low_signal_limit_1     = 0,
179                 .high_signal_limit_2    = 0,
180                 .low_signal_limit_2     = 0,
181         },
182         .two_touch_gesture_proc_cfg = {
183                 .ctrl                   = 0,
184                 .num_gestures           = 0,
185                 .reserve2               = 0,
186                 .gesture_enable         = 0,
187                 .rotate_threshold       = 0,
188                 .zoom_threshold         = 0,
189         },
190         .cte_config_cfg = {
191                 .ctrl                   = 0,
192                 .command                = 0,
193                 .reserve2               = 0,
194                 .idle_gcaf_depth        = 16,
195                 .active_gcaf_depth      = 16,
196                 .voltage                = 60,
197         },
198         .gripsuppression_t40_cfg = {
199                 .ctrl                   = 0,
200                 .xlo_grip               = 0,
201                 .xhi_grip               = 0,
202                 .ylo_grip               = 0,
203                 .yhi_grip               = 0,
204         },
205         .palm_suppression_cfg = {
206                 .ctrl                   = 0,
207                 .small_obj_thr          = 0,
208                 .sig_spread_thr         = 0,
209                 .large_obj_thr          = 0,
210                 .distance_thr           = 0,
211                 .sup_ext_to             = 0,
212         },
213         .spt_digitizer_cfg = {
214                 .ctrl                   = 0,
215                 .hid_idlerate           = 0,
216                 .xlength                = 0,
217                 .ylength                = 0,
218         },
219
220         .vkeys                  = {
221                 .count          = 0,
222                 .keys           = NULL,
223         },
224 };
225
226 /* Portable P0 */
227 struct qtouch_ts_platform_data stingray_touch_data_p0 = {
228
229         .flags          = (QTOUCH_USE_MULTITOUCH |
230                            QTOUCH_CFG_BACKUPNV),
231         .irqflags               = (IRQF_TRIGGER_LOW),
232         .abs_min_x              = 0,
233         .abs_max_x              = 4095,
234         .abs_min_y              = 255,
235         .abs_max_y              = 4058,
236         .abs_min_p              = 0,
237         .abs_max_p              = 255,
238         .abs_min_w              = 0,
239         .abs_max_w              = 15,
240         .x_delta                = 400,
241         .y_delta                = 250,
242         .nv_checksum            = 0x6462cb,
243         .fuzz_x                 = 0,
244         .fuzz_y                 = 0,
245         .fuzz_p                 = 2,
246         .fuzz_w                 = 2,
247         .boot_i2c_addr  = XMEGAT_BL_I2C_ADDR,
248         .hw_reset               = stingray_touch_reset,
249         .key_array = {
250                 .cfg            = NULL,
251                 .keys           = NULL,
252                 .num_keys       = 0,
253         },
254         .touch_fw_cfg = {
255                 .fw_name = "mXT1386_09_AA.bin",
256                 .family_id = 0xA0,
257                 .variant_id = 0x00,
258                 .fw_version = 0x09,
259                 .fw_build = 0xAA,
260                 .boot_version = 0x20,
261                 .base_fw_version = 0x00,
262         },
263         .power_cfg      = {
264                 .idle_acq_int   = 0xff,
265                 .active_acq_int = 0xff,
266                 .active_idle_to = 0x00,
267         },
268         .acquire_cfg    = {
269                 .charge_time    = 0x0A,
270                 .reserve1       = 0,
271                 .touch_drift    = 0x14,
272                 .drift_susp     = 0x14,
273                 .touch_autocal  = 0x00,
274                 .reserve5       = 0,
275                 .atch_cal_suspend_time  = 0,
276                 .atch_cal_suspend_thres = 0,
277                 .atch_cal_force_thres = 0x10,
278                 .atch_cal_force_ratio = 0,
279         },
280         .multi_touch_cfg        = {
281                 .ctrl           = 0x83,
282                 .x_origin       = 0,
283                 .y_origin       = 0,
284                 .x_size         = 0x21,
285                 .y_size         = 0x2a,
286                 .aks_cfg        = 0,
287                 .burst_len      = 0x10,
288                 .tch_det_thr    = 45,
289                 .tch_det_int    = 0x3,
290                 .orient         = 1,
291                 .mrg_to         = 0x00,
292                 .mov_hyst_init  = 0x05,
293                 .mov_hyst_next  = 0x02,
294                 .mov_filter     = 0x20,
295                 .num_touch      = 0x05,
296                 .merge_hyst     = 0x0A,
297                 .merge_thresh   = 0x0A,
298                 .amp_hyst       = 0x0A,
299                 .x_res          = 0x0FFF,
300                 .y_res          = 0x0FFF,
301                 .x_low_clip     = 0x00,
302                 .x_high_clip    = 0x00,
303                 .y_low_clip     = 0x00,
304                 .y_high_clip    = 0x00,
305                 .x_edge_ctrl    = 0,
306                 .x_edge_dist    = 0,
307                 .y_edge_ctrl    = 0,
308                 .y_edge_dist    = 0,
309                 .jump_limit     = 0,
310                 .tch_thres_hyst = 0x09,
311                 .xpitch         = 0,
312                 .ypitch         = 0,
313         },
314         .comms_config_cfg = {
315                 .ctrl           = 0,
316                 .command        = 0,
317         },
318         .noise_suppression_cfg = {
319                 .ctrl                   = 0,
320                 .reserve1               = 0,
321                 .reserve2               = 0,
322                 .reserve3               = 0,
323                 .reserve4               = 0,
324                 .reserve5               = 0,
325                 .reserve6               = 0,
326                 .reserve7               = 0,
327                 .noise_thres            = 0,
328                 .reserve9               = 0,
329                 .freq_hop_scale         = 0,
330                 .burst_freq_0           = 0,
331                 .burst_freq_1           = 0,
332                 .burst_freq_2           = 0,
333                 .burst_freq_3           = 0,
334                 .burst_freq_4           = 0,
335                 .reserve16              = 0,
336         },
337         .one_touch_gesture_proc_cfg = {
338                 .ctrl                   = 0,
339                 .num_gestures           = 0,
340                 .gesture_enable         = 0,
341                 .pres_proc              = 0,
342                 .tap_time_out           = 0,
343                 .flick_time_out         = 0,
344                 .drag_time_out          = 0,
345                 .short_press_time_out   = 0,
346                 .long_press_time_out    = 0,
347                 .repeat_press_time_out  = 0,
348                 .flick_threshold        = 0,
349                 .drag_threshold         = 0,
350                 .tap_threshold          = 0,
351                 .throw_threshold        = 0,
352         },
353         .self_test_cfg = {
354                 .ctrl                   = 0,
355                 .command                = 0,
356                 .high_signal_limit_0    = 0,
357                 .low_signal_limit_0     = 0,
358                 .high_signal_limit_1    = 0,
359                 .low_signal_limit_1     = 0,
360                 .high_signal_limit_2    = 0,
361                 .low_signal_limit_2     = 0,
362         },
363         .two_touch_gesture_proc_cfg = {
364                 .ctrl                   = 0,
365                 .num_gestures           = 0,
366                 .reserve2               = 0,
367                 .gesture_enable         = 0,
368                 .rotate_threshold       = 0,
369                 .zoom_threshold         = 0,
370         },
371         .cte_config_cfg = {
372                 .ctrl                   = 0,
373                 .command                = 0,
374                 .reserve2               = 0,
375                 .idle_gcaf_depth        = 16,
376                 .active_gcaf_depth      = 16,
377                 .voltage                = 60,
378         },
379         .gripsuppression_t40_cfg = {
380                 .ctrl                   = 0,
381                 .xlo_grip               = 0,
382                 .xhi_grip               = 0,
383                 .ylo_grip               = 0,
384                 .yhi_grip               = 0,
385         },
386         .palm_suppression_cfg = {
387                 .ctrl                   = 0,
388                 .small_obj_thr          = 0,
389                 .sig_spread_thr         = 0,
390                 .large_obj_thr          = 0,
391                 .distance_thr           = 0,
392                 .sup_ext_to             = 0,
393         },
394         .spt_digitizer_cfg = {
395                 .ctrl                   = 0,
396                 .hid_idlerate           = 0,
397                 .xlength                = 0,
398                 .ylength                = 0,
399         },
400
401         .vkeys                  = {
402                 .count          = 0,
403                 .keys           = NULL,
404         },
405 };
406
407 /* Portable P1 and P2 */
408 struct qtouch_ts_platform_data stingray_touch_data_p1p2 = {
409
410         .flags          = (QTOUCH_USE_MULTITOUCH |
411                            QTOUCH_CFG_BACKUPNV),
412         .irqflags               = (IRQF_TRIGGER_LOW),
413         .abs_min_x              = 0,
414         .abs_max_x              = 4095,
415         .abs_min_y              = 0,
416         .abs_max_y              = 4095,
417         .abs_min_p              = 0,
418         .abs_max_p              = 255,
419         .abs_min_w              = 0,
420         .abs_max_w              = 15,
421         .x_delta                = 400,
422         .y_delta                = 250,
423         .nv_checksum            = 0x6462cb,
424         .fuzz_x                 = 0,
425         .fuzz_y                 = 0,
426         .fuzz_p                 = 2,
427         .fuzz_w                 = 2,
428         .boot_i2c_addr  = XMEGAT_BL_I2C_ADDR,
429         .hw_reset               = stingray_touch_reset,
430         .key_array = {
431                 .cfg            = NULL,
432                 .keys           = NULL,
433                 .num_keys       = 0,
434         },
435         .touch_fw_cfg = {
436                 .fw_name = "mXT1386_09_AA.bin",
437                 .family_id = 0xA0,
438                 .variant_id = 0x00,
439                 .fw_version = 0x09,
440                 .fw_build = 0xAA,
441                 .boot_version = 0x20,
442                 .base_fw_version = 0x00,
443         },
444         .power_cfg      = {
445                 .idle_acq_int   = 0xff,
446                 .active_acq_int = 0xff,
447                 .active_idle_to = 0x00,
448         },
449         .acquire_cfg    = {
450                 .charge_time    = 0x0A,
451                 .reserve1       = 0,
452                 .touch_drift    = 0x14,
453                 .drift_susp     = 0x14,
454                 .touch_autocal  = 0x00,
455                 .reserve5       = 0,
456                 .atch_cal_suspend_time  = 0,
457                 .atch_cal_suspend_thres = 0,
458                 .atch_cal_force_thres = 0x10,
459                 .atch_cal_force_ratio = 0,
460         },
461         .multi_touch_cfg        = {
462                 .ctrl           = 0x83,
463                 .x_origin       = 0,
464                 .y_origin       = 0,
465                 .x_size         = 0x21,
466                 .y_size         = 0x2a,
467                 .aks_cfg        = 0,
468                 .burst_len      = 0x10,
469                 .tch_det_thr    = 45,
470                 .tch_det_int    = 0x3,
471                 .orient         = 1,
472                 .mrg_to         = 0x00,
473                 .mov_hyst_init  = 0x05,
474                 .mov_hyst_next  = 0x02,
475                 .mov_filter     = 0x20,
476                 .num_touch      = 0x05,
477                 .merge_hyst     = 0x0A,
478                 .merge_thresh   = 0x0A,
479                 .amp_hyst       = 0x0A,
480                 .x_res          = 0x0FFF,
481                 .y_res          = 0x0FFF,
482                 .x_low_clip     = 0x00,
483                 .x_high_clip    = 0x00,
484                 .y_low_clip     = 0x00,
485                 .y_high_clip    = 0x00,
486                 .x_edge_ctrl    = 0,
487                 .x_edge_dist    = 0,
488                 .y_edge_ctrl    = 0,
489                 .y_edge_dist    = 0,
490                 .jump_limit     = 0,
491                 .tch_thres_hyst = 0x09,
492                 .xpitch         = 0,
493                 .ypitch         = 0,
494         },
495         .comms_config_cfg = {
496                 .ctrl           = 0,
497                 .command        = 0,
498         },
499         .noise_suppression_cfg = {
500                 .ctrl                   = 0,
501                 .reserve1               = 0,
502                 .reserve2               = 0,
503                 .reserve3               = 0,
504                 .reserve4               = 0,
505                 .reserve5               = 0,
506                 .reserve6               = 0,
507                 .reserve7               = 0,
508                 .noise_thres            = 0,
509                 .reserve9               = 0,
510                 .freq_hop_scale         = 0,
511                 .burst_freq_0           = 0,
512                 .burst_freq_1           = 0,
513                 .burst_freq_2           = 0,
514                 .burst_freq_3           = 0,
515                 .burst_freq_4           = 0,
516                 .reserve16              = 0,
517         },
518         .one_touch_gesture_proc_cfg = {
519                 .ctrl                   = 0,
520                 .num_gestures           = 0,
521                 .gesture_enable         = 0,
522                 .pres_proc              = 0,
523                 .tap_time_out           = 0,
524                 .flick_time_out         = 0,
525                 .drag_time_out          = 0,
526                 .short_press_time_out   = 0,
527                 .long_press_time_out    = 0,
528                 .repeat_press_time_out  = 0,
529                 .flick_threshold        = 0,
530                 .drag_threshold         = 0,
531                 .tap_threshold          = 0,
532                 .throw_threshold        = 0,
533         },
534         .self_test_cfg = {
535                 .ctrl                   = 0,
536                 .command                = 0,
537                 .high_signal_limit_0    = 0,
538                 .low_signal_limit_0     = 0,
539                 .high_signal_limit_1    = 0,
540                 .low_signal_limit_1     = 0,
541                 .high_signal_limit_2    = 0,
542                 .low_signal_limit_2     = 0,
543         },
544         .two_touch_gesture_proc_cfg = {
545                 .ctrl                   = 0,
546                 .num_gestures           = 0,
547                 .reserve2               = 0,
548                 .gesture_enable         = 0,
549                 .rotate_threshold       = 0,
550                 .zoom_threshold         = 0,
551         },
552         .cte_config_cfg = {
553                 .ctrl                   = 0,
554                 .command                = 0,
555                 .reserve2               = 0,
556                 .idle_gcaf_depth        = 16,
557                 .active_gcaf_depth      = 16,
558                 .voltage                = 60,
559         },
560         .gripsuppression_t40_cfg = {
561                 .ctrl                   = 0,
562                 .xlo_grip               = 0,
563                 .xhi_grip               = 0,
564                 .ylo_grip               = 0,
565                 .yhi_grip               = 0,
566                 },
567         .palm_suppression_cfg = {
568                 .ctrl                   = 0,
569                 .small_obj_thr          = 0,
570                 .sig_spread_thr         = 0,
571                 .large_obj_thr          = 0,
572                 .distance_thr           = 0,
573                 .sup_ext_to             = 0,
574         },
575         .spt_digitizer_cfg = {
576                 .ctrl                   = 0,
577                 .hid_idlerate           = 0,
578                 .xlength                = 0,
579                 .ylength                = 0,
580         },
581
582         .vkeys                  = {
583                 .count          = 0,
584                 .keys           = NULL,
585         },
586 };
587
588 static struct i2c_board_info __initdata stingray_i2c_bus1_touch_info[] = {
589         {
590                 I2C_BOARD_INFO(QTOUCH_TS_NAME, 0x5B),
591                 .irq = TEGRA_GPIO_TO_IRQ(STINGRAY_TOUCH_INT_N_GPIO),
592         },
593 };
594
595 int __init stingray_touch_init(void)
596 {
597         tegra_gpio_enable(STINGRAY_TOUCH_INT_N_GPIO);
598         gpio_request(STINGRAY_TOUCH_INT_N_GPIO, "touch_irq");
599         gpio_direction_input(STINGRAY_TOUCH_INT_N_GPIO);
600
601         tegra_gpio_enable(STINGRAY_TOUCH_WAKE_N_GPIO);
602         gpio_request(STINGRAY_TOUCH_WAKE_N_GPIO, "touch_wake");
603         gpio_direction_output(STINGRAY_TOUCH_WAKE_N_GPIO, 0);
604
605         tegra_gpio_enable(STINGRAY_TOUCH_RESET_N_GPIO);
606         gpio_request(STINGRAY_TOUCH_RESET_N_GPIO, "touch_reset");
607         gpio_direction_output(STINGRAY_TOUCH_RESET_N_GPIO, 1);
608
609         if ((stingray_revision() == STINGRAY_REVISION_P1) ||
610                 (stingray_revision() == STINGRAY_REVISION_P2))
611                 stingray_i2c_bus1_touch_info[0].platform_data = &stingray_touch_data_p1p2;
612         else if (stingray_revision() == STINGRAY_REVISION_P0)
613                 stingray_i2c_bus1_touch_info[0].platform_data = &stingray_touch_data_p0;
614         else
615                 stingray_i2c_bus1_touch_info[0].platform_data = &stingray_touch_data_m1;
616
617         i2c_register_board_info(0, stingray_i2c_bus1_touch_info, 1);
618
619         return 0;
620 }