Merge branch 'android-tegra-2.6.36' into android-tegra-moto-2.6.36
[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(20);
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              = 0,
242         .abs_max_x              = 4095,
243         .abs_min_y              = 255,
244         .abs_max_y              = 4058,
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            = 0xEB8169,
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_AA.bin",
266                 .family_id = 0xA0,
267                 .variant_id = 0x00,
268                 .fw_version = 0x10,
269                 .fw_build = 0xAA,
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           = 0x8B,
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         = 0x00,
302                 .mov_hyst_init  = 0x32,
303                 .mov_hyst_next  = 0x14,
304                 .mov_filter     = 0x3D,
305                 .num_touch      = 0x0A,
306                 .merge_hyst     = 0x0A,
307                 .merge_thresh   = 0x0A,
308                 .amp_hyst       = 0x0A,
309                 .x_res          = 0x0FFF,
310                 .y_res          = 0x0FFF,
311                 .x_low_clip     = 0x06,
312                 .x_high_clip    = 0x0A,
313                 .y_low_clip     = 0x05,
314                 .y_high_clip    = 0xFF,
315                 .x_edge_ctrl    = 0xD2,
316                 .x_edge_dist    = 0x28,
317                 .y_edge_ctrl    = 0x2E,
318                 .y_edge_dist    = 0x0A,
319                 .jump_limit     = 0x20,
320                 .tch_thres_hyst = 0,
321                 .xpitch         = 0,
322                 .ypitch         = 0,
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                   = 0,
398                 .small_obj_thr          = 0,
399                 .sig_spread_thr         = 0,
400                 .large_obj_thr          = 0,
401                 .distance_thr           = 0,
402                 .sup_ext_to             = 0,
403         },
404         .spt_digitizer_cfg = {
405                 .ctrl                   = 0,
406                 .hid_idlerate           = 0,
407                 .xlength                = 0,
408                 .ylength                = 0,
409         },
410
411         .vkeys                  = {
412                 .count          = 0,
413                 .keys           = NULL,
414         },
415 };
416
417 /* Portable P1 and later versions */
418 struct qtouch_ts_platform_data stingray_touch_data_p1_or_later = {
419
420         .flags          = (QTOUCH_USE_MULTITOUCH |
421                            QTOUCH_CFG_BACKUPNV),
422         .irqflags               = (IRQF_TRIGGER_LOW),
423         .abs_min_x              = 0,
424         .abs_max_x              = 4095,
425         .abs_min_y              = 0,
426         .abs_max_y              = 4095,
427         .abs_min_p              = 0,
428         .abs_max_p              = 255,
429         .abs_min_w              = 0,
430         .abs_max_w              = 15,
431         .x_delta                = 400,
432         .y_delta                = 250,
433         .nv_checksum            = 0xEB8169,
434         .fuzz_x                 = 0,
435         .fuzz_y                 = 0,
436         .fuzz_p                 = 2,
437         .fuzz_w                 = 2,
438         .boot_i2c_addr  = XMEGAT_BL_I2C_ADDR,
439         .hw_reset               = stingray_touch_reset,
440         .hw_suspend             = stingray_touch_suspend,
441         .key_array = {
442                 .cfg            = NULL,
443                 .keys           = NULL,
444                 .num_keys       = 0,
445         },
446         .touch_fw_cfg = {
447                 .fw_name = "mXT1386_10_AA.bin",
448                 .family_id = 0xA0,
449                 .variant_id = 0x00,
450                 .fw_version = 0x10,
451                 .fw_build = 0xAA,
452                 .boot_version = 0x20,
453                 .base_fw_version = 0x00,
454         },
455         .power_cfg      = {
456                 .idle_acq_int   = 0x12,
457                 .active_acq_int = 0xFF,
458                 .active_idle_to = 0x0A,
459         },
460         .acquire_cfg    = {
461                 .charge_time    = 0x0A,
462                 .reserve1       = 0,
463                 .touch_drift    = 0x14,
464                 .drift_susp     = 0x14,
465                 .touch_autocal  = 0x4B,
466                 .reserve5       = 0,
467                 .atch_cal_suspend_time  = 0,
468                 .atch_cal_suspend_thres = 0,
469                 .atch_cal_force_thres = 0x10,
470                 .atch_cal_force_ratio = 0x10,
471         },
472         .multi_touch_cfg        = {
473                 .ctrl           = 0x8B,
474                 .x_origin       = 0,
475                 .y_origin       = 0,
476                 .x_size         = 0x21,
477                 .y_size         = 0x2a,
478                 .aks_cfg        = 0,
479                 .burst_len      = 0x20,
480                 .tch_det_thr    = 0x2d,
481                 .tch_det_int    = 0x2,
482                 .orient         = 1,
483                 .mrg_to         = 0x00,
484                 .mov_hyst_init  = 0x32,
485                 .mov_hyst_next  = 0x14,
486                 .mov_filter     = 0x3D,
487                 .num_touch      = 0x0A,
488                 .merge_hyst     = 0x0A,
489                 .merge_thresh   = 0x0A,
490                 .amp_hyst       = 0x0A,
491                 .x_res          = 0x0FFF,
492                 .y_res          = 0x0FFF,
493                 .x_low_clip     = 0x06,
494                 .x_high_clip    = 0x0A,
495                 .y_low_clip     = 0x05,
496                 .y_high_clip    = 0xFF,
497                 .x_edge_ctrl    = 0xD2,
498                 .x_edge_dist    = 0x28,
499                 .y_edge_ctrl    = 0x2E,
500                 .y_edge_dist    = 0x0A,
501                 .jump_limit     = 0x20,
502                 .tch_thres_hyst = 0,
503                 .xpitch         = 0,
504                 .ypitch         = 0,
505         },
506         .comms_config_cfg = {
507                 .ctrl           = 0,
508                 .command        = 0,
509         },
510         .noise_suppression_cfg = {
511                 .ctrl                   = 5,
512                 .reserve1               = 0,
513                 .reserve2               = 0,
514                 .reserve3               = 0,
515                 .reserve4               = 0,
516                 .reserve5               = 0,
517                 .reserve6               = 0,
518                 .reserve7               = 0,
519                 .noise_thres            = 32,
520                 .reserve9               = 0,
521                 .freq_hop_scale         = 0,
522                 .burst_freq_0           = 10,
523                 .burst_freq_1           = 15,
524                 .burst_freq_2           = 19,
525                 .burst_freq_3           = 25,
526                 .burst_freq_4           = 30,
527                 .reserve16              = 0,
528         },
529         .one_touch_gesture_proc_cfg = {
530                 .ctrl                   = 0,
531                 .num_gestures           = 0,
532                 .gesture_enable         = 0,
533                 .pres_proc              = 0,
534                 .tap_time_out           = 0,
535                 .flick_time_out         = 0,
536                 .drag_time_out          = 0,
537                 .short_press_time_out   = 0,
538                 .long_press_time_out    = 0,
539                 .repeat_press_time_out  = 0,
540                 .flick_threshold        = 0,
541                 .drag_threshold         = 0,
542                 .tap_threshold          = 0,
543                 .throw_threshold        = 0,
544         },
545         .self_test_cfg = {
546                 .ctrl                   = 0,
547                 .command                = 0,
548                 .high_signal_limit_0    = 0,
549                 .low_signal_limit_0     = 0,
550                 .high_signal_limit_1    = 0,
551                 .low_signal_limit_1     = 0,
552                 .high_signal_limit_2    = 0,
553                 .low_signal_limit_2     = 0,
554         },
555         .two_touch_gesture_proc_cfg = {
556                 .ctrl                   = 0,
557                 .num_gestures           = 0,
558                 .reserve2               = 0,
559                 .gesture_enable         = 0,
560                 .rotate_threshold       = 0,
561                 .zoom_threshold         = 0,
562         },
563         .cte_config_cfg = {
564                 .ctrl                   = 0,
565                 .command                = 0,
566                 .reserve2               = 0,
567                 .idle_gcaf_depth        = 20,
568                 .active_gcaf_depth      = 20,
569                 .voltage                = 60,
570         },
571         .gripsuppression_t40_cfg = {
572                 .ctrl                   = 0,
573                 .xlo_grip               = 0,
574                 .xhi_grip               = 0,
575                 .ylo_grip               = 0,
576                 .yhi_grip               = 0,
577                 },
578         .palm_suppression_cfg = {
579                 .ctrl                   = 0,
580                 .small_obj_thr          = 0,
581                 .sig_spread_thr         = 0,
582                 .large_obj_thr          = 0,
583                 .distance_thr           = 0,
584                 .sup_ext_to             = 0,
585         },
586         .spt_digitizer_cfg = {
587                 .ctrl                   = 0,
588                 .hid_idlerate           = 0,
589                 .xlength                = 0,
590                 .ylength                = 0,
591         },
592
593         .vkeys                  = {
594                 .count          = 0,
595                 .keys           = NULL,
596         },
597 };
598
599 static struct i2c_board_info __initdata stingray_i2c_bus1_touch_info[] = {
600         {
601                 I2C_BOARD_INFO(QTOUCH_TS_NAME, 0x5B),
602         },
603 };
604
605 int __init stingray_touch_init(void)
606 {
607         unsigned touch_int_gpio;
608
609         if (stingray_revision() == STINGRAY_REVISION_P2)
610                 touch_int_gpio = STINGRAY_TOUCH_INT_N_GPIO_P2;
611         else
612                 touch_int_gpio = STINGRAY_TOUCH_INT_N_GPIO;
613
614         tegra_gpio_enable(touch_int_gpio);
615         gpio_request(touch_int_gpio, "touch_irq");
616         gpio_direction_input(touch_int_gpio);
617
618         tegra_gpio_enable(STINGRAY_TOUCH_WAKE_N_GPIO);
619         gpio_request(STINGRAY_TOUCH_WAKE_N_GPIO, "touch_wake");
620         gpio_direction_output(STINGRAY_TOUCH_WAKE_N_GPIO, 0);
621
622         tegra_gpio_enable(STINGRAY_TOUCH_RESET_N_GPIO);
623         gpio_request(STINGRAY_TOUCH_RESET_N_GPIO, "touch_reset");
624         gpio_direction_output(STINGRAY_TOUCH_RESET_N_GPIO, 1);
625
626         stingray_i2c_bus1_touch_info[0].irq =
627                  TEGRA_GPIO_TO_IRQ(touch_int_gpio);
628
629         if ((stingray_revision() == STINGRAY_REVISION_P1) ||
630                 (stingray_revision() == STINGRAY_REVISION_P2) ||
631                 (stingray_revision() == STINGRAY_REVISION_P3))
632                 stingray_i2c_bus1_touch_info[0].platform_data =
633                                  &stingray_touch_data_p1_or_later;
634         else if (stingray_revision() == STINGRAY_REVISION_P0)
635                 stingray_i2c_bus1_touch_info[0].platform_data = &stingray_touch_data_p0;
636         else
637                 stingray_i2c_bus1_touch_info[0].platform_data = &stingray_touch_data_m1;
638
639         i2c_register_board_info(0, stingray_i2c_bus1_touch_info, 1);
640
641         return 0;
642 }