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