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