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-olympus-i2c.c
1 /*
2  * arch/arm/mach-tegra/board-olympus-i2c.c
3  *
4  * Copyright (C) 2010 Google, Inc.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #include <linux/resource.h>
18 #include <linux/platform_device.h>
19 #include <linux/delay.h>
20 #include <linux/gpio.h>
21 #include <linux/i2c.h>
22 #include <asm/mach-types.h>
23 #include <mach/irqs.h>
24 #include <mach/iomap.h>
25 #include <mach/pinmux.h>
26 #include <linux/qtouch_obp_ts.h>
27 #include <linux/interrupt.h>
28 #include <linux/input.h>
29
30 #include "board-olympus.h"
31 #include "gpio-names.h"
32
33 #define XMEGAT_BL_I2C_ADDR              0x24
34 #define OLYMPUS_TOUCH_IRQ_GPIO TEGRA_GPIO_PF5
35 #define OLYMPUS_TOUCH_RESET_GPIO TEGRA_GPIO_PF4
36 #define OLYMPUS_COMPASS_IRQ_GPIO TEGRA_GPIO_PE2
37
38
39 static int olympus_touch_reset(void)
40 {
41         gpio_set_value(OLYMPUS_TOUCH_RESET_GPIO, 0);
42         msleep(10);
43         gpio_set_value(OLYMPUS_TOUCH_RESET_GPIO, 1);
44         msleep(100);
45
46         return 0;
47 }
48
49 static struct vkey sholes_touch_vkeys[] = {
50         {
51                 .code           = KEY_BACK,
52         },
53         {
54                 .code           = KEY_MENU,
55         },
56         {
57                 .code           = KEY_HOME,
58         },
59         {
60                 .code           = KEY_SEARCH,
61         },
62 };
63
64 static struct qtm_touch_keyarray_cfg sholes_key_array_data[] = {
65         {
66                 .ctrl = 0,
67                 .x_origin = 0,
68                 .y_origin = 0,
69                 .x_size = 0,
70                 .y_size = 0,
71                 .aks_cfg = 0,
72                 .burst_len = 0,
73                 .tch_det_thr = 0,
74                 .tch_det_int = 0,
75                 .reserve9 = 0,
76                 .reserve10 = 0,
77         },
78         {
79                 .ctrl = 0,
80                 .x_origin = 0,
81                 .y_origin = 0,
82                 .x_size = 0,
83                 .y_size = 0,
84                 .aks_cfg = 0,
85                 .burst_len = 0,
86                 .tch_det_thr = 0,
87                 .tch_det_int = 0,
88                 .reserve9 = 0,
89                 .reserve10 = 0,
90         },
91 };
92
93 struct qtouch_ts_platform_data olympus_touch_data = {
94
95         .flags          = (QTOUCH_SWAP_XY |
96                            QTOUCH_USE_MULTITOUCH |
97                            QTOUCH_CFG_BACKUPNV |
98                            QTOUCH_EEPROM_CHECKSUM),
99         .irqflags               = (IRQF_TRIGGER_LOW),
100         .abs_min_x              = 0,
101         .abs_max_x              = 1023,
102         .abs_min_y              = 0,
103         .abs_max_y              = 1023,
104         .abs_min_p              = 0,
105         .abs_max_p              = 255,
106         .abs_min_w              = 0,
107         .abs_max_w              = 15,
108         .x_delta                = 400,
109         .y_delta                = 250,
110         .nv_checksum            = 0xc240,
111         .fuzz_x                 = 0,
112         .fuzz_y                 = 0,
113         .fuzz_p                 = 2,
114         .fuzz_w                 = 2,
115         .boot_i2c_addr  = XMEGAT_BL_I2C_ADDR,
116         .hw_reset               = olympus_touch_reset,
117         .key_array = {
118                 .cfg            = NULL,
119                 .keys           = NULL,
120                 .num_keys       = 0,
121         },
122         .power_cfg      = {
123                 .idle_acq_int   = 0xff,
124                 .active_acq_int = 0xff,
125                 .active_idle_to = 0x01,
126         },
127         .acquire_cfg    = {
128                 .charge_time    = 0x06,
129                 .reserve1       = 0x00,
130                 .touch_drift    = 0x0a,
131                 .drift_susp     = 0x05,
132                 .touch_autocal  = 0x00,
133                 .reserve5       = 0,
134                 .atch_cal_suspend_time  = 0,
135                 .atch_cal_suspend_thres = 0,
136         },
137         .multi_touch_cfg        = {
138                 .ctrl           = 0x0b,
139                 .x_origin       = 0,
140                 .y_origin       = 0,
141                 .x_size         = 0x13,
142                 .y_size         = 0x0b,
143                 .aks_cfg        = 0,
144                 .burst_len      = 0x41,
145                 .tch_det_thr    = 0x14,
146                 .tch_det_int    = 0x2,
147                 .orient         = 4,
148                 .mrg_to         = 0x19,
149                 .mov_hyst_init  = 0x05,
150                 .mov_hyst_next  = 0x05,
151                 .mov_filter     = 0,
152                 .num_touch      = 0x02,
153                 .merge_hyst     = 0x05,
154                 .merge_thresh   = 0x05,
155                 .amp_hyst       = 0,
156                 .x_res          = 0x0000,
157                 .y_res          = 0x0000,
158                 .x_low_clip     = 0x00,
159                 .x_high_clip    = 0x00,
160                 .y_low_clip     = 0x00,
161                 .y_high_clip    = 0x00,
162                 .x_edge_ctrl    = 0,
163                 .x_edge_dist    = 0,
164                 .y_edge_ctrl    = 0,
165                 .y_edge_dist    = 0,
166                 .jump_limit     = 0,
167         },
168         .linear_tbl_cfg = {
169                 .ctrl           = 0x00,
170                 .x_offset       = 0x0000,
171                 .x_segment = {
172                         0x00, 0x00, 0x00, 0x00,
173                         0x00, 0x00, 0x00, 0x00,
174                         0x00, 0x00, 0x00, 0x00,
175                         0x00, 0x00, 0x00, 0x00
176                 },
177                 .y_offset = 0x0000,
178                 .y_segment = {
179                         0x00, 0x00, 0x00, 0x00,
180                         0x00, 0x00, 0x00, 0x00,
181                         0x00, 0x00, 0x00, 0x00,
182                         0x00, 0x00, 0x00, 0x00
183                 },
184         },
185         .comms_config_cfg = {
186                 .ctrl           = 0,
187                 .command        = 0,
188         },
189         .gpio_pwm_cfg = {
190                 .ctrl                   = 0,
191                 .report_mask            = 0,
192                 .pin_direction          = 0,
193                 .internal_pullup        = 0,
194                 .output_value           = 0,
195                 .wake_on_change         = 0,
196                 .pwm_enable             = 0,
197                 .pwm_period             = 0,
198                 .duty_cycle_0           = 0,
199                 .duty_cycle_1           = 0,
200                 .duty_cycle_2           = 0,
201                 .duty_cycle_3           = 0,
202                 .trigger_0              = 0,
203                 .trigger_1              = 0,
204                 .trigger_2              = 0,
205                 .trigger_3              = 0,
206         },
207         .grip_face_suppression_cfg = {
208                 .ctrl           = 0x00,
209                 .xlogrip        = 0x00,
210                 .xhigrip        = 0x00,
211                 .ylogrip        = 0x00,
212                 .yhigrip        = 0x00,
213                 .maxtchs        = 0x00,
214                 .reserve6       = 0x00,
215                 .szthr1         = 0x00,
216                 .szthr2         = 0x00,
217                 .shpthr1        = 0x00,
218                 .shpthr2        = 0x00,
219                 .supextto       = 0x00,
220         },
221         .noise_suppression_cfg = {
222                 .ctrl                   = 0,
223                 .reserve1               = 0,
224                 .reserve2               = 0,
225                 .reserve3               = 0,
226                 .reserve4               = 0,
227                 .reserve5               = 0,
228                 .reserve6               = 0,
229                 .reserve7               = 0,
230                 .noise_thres            = 0,
231                 .reserve9               = 0,
232                 .freq_hop_scale         = 0,
233                 .burst_freq_0           = 0,
234                 .burst_freq_1           = 0,
235                 .burst_freq_2           = 0,
236                 .burst_freq_3           = 0,
237                 .burst_freq_4           = 0,
238                 .reserve16              = 0,
239         },
240         .touch_proximity_cfg = {
241                 .ctrl                   = 0,
242                 .x_origin               = 0,
243                 .y_origin               = 0,
244                 .x_size                 = 0,
245                 .y_size                 = 0,
246                 .reserve5               = 0,
247                 .blen                   = 0,
248                 .tch_thresh             = 0,
249                 .tch_detect_int         = 0,
250                 .average                = 0,
251                 .move_null_rate         = 0,
252                 .move_det_tresh         = 0,
253         },
254         .one_touch_gesture_proc_cfg = {
255                 .ctrl                   = 0,
256                 .num_gestures           = 0,
257                 .gesture_enable         = 0,
258                 .pres_proc              = 0,
259                 .tap_time_out           = 0,
260                 .flick_time_out         = 0,
261                 .drag_time_out          = 0,
262                 .short_press_time_out   = 0,
263                 .long_press_time_out    = 0,
264                 .repeat_press_time_out  = 0,
265                 .flick_threshold        = 0,
266                 .drag_threshold         = 0,
267                 .tap_threshold          = 0,
268                 .throw_threshold        = 0,
269         },
270         .self_test_cfg = {
271                 .ctrl                   = 0,
272                 .command                = 0,
273                 .high_signal_limit_0    = 0,
274                 .low_signal_limit_0     = 0,
275                 .high_signal_limit_1    = 0,
276                 .low_signal_limit_1     = 0,
277                 .high_signal_limit_2    = 0,
278                 .low_signal_limit_2     = 0,
279         },
280         .two_touch_gesture_proc_cfg = {
281                 .ctrl                   = 0,
282                 .num_gestures           = 0,
283                 .reserve2               = 0,
284                 .gesture_enable         = 0,
285                 .rotate_threshold       = 0,
286                 .zoom_threshold         = 0,
287         },
288         .cte_config_cfg = {
289                 .ctrl                   = 1,
290                 .command                = 0,
291                 .reserve2               = 3,
292                 .idle_gcaf_depth        = 4,
293                 .active_gcaf_depth      = 8,
294                 .voltage                = 0,
295         },
296         .noise1_suppression_cfg = {
297                 .ctrl           = 0x01,
298                 .version        = 0x01,
299                 .atch_thr       = 0x64,
300                 .duty_cycle     = 0x08,
301                 .drift_thr      = 0x00,
302                 .clamp_thr      = 0x00,
303                 .diff_thr       = 0x00,
304                 .adjustment     = 0x00,
305                 .average        = 0x0000,
306                 .temp           = 0x00,
307                 .offset = {
308                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
316                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
326                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
329                 },
330                 .bad_chan = {
331                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332                         0x00, 0x00, 0x00
333                 },
334                 .x_short        = 0x00,
335         },
336         .vkeys                  = {
337                 .count          = 0,
338                 .keys           = NULL,
339         },
340 };
341
342 static struct i2c_board_info __initdata sholes_i2c_bus1_board_info[] = {
343         {
344                 I2C_BOARD_INFO(QTOUCH_TS_NAME, 0x4a),
345                 .platform_data = &olympus_touch_data,
346                 .irq = TEGRA_GPIO_TO_IRQ(OLYMPUS_TOUCH_IRQ_GPIO),
347         },
348 };
349
350 static struct i2c_board_info __initdata olympus_i2c_bus4_board_info[] = {
351         {
352                 I2C_BOARD_INFO("akm8973", 0x0C),
353                 .irq = TEGRA_GPIO_TO_IRQ(OLYMPUS_COMPASS_IRQ_GPIO),
354         },
355 };
356
357 void __init olympus_i2c_init(void)
358 {
359         tegra_gpio_enable(OLYMPUS_TOUCH_IRQ_GPIO);
360         gpio_request(OLYMPUS_TOUCH_IRQ_GPIO, "touch_irq");
361         gpio_direction_input(OLYMPUS_TOUCH_IRQ_GPIO);
362
363         tegra_gpio_enable(OLYMPUS_TOUCH_RESET_GPIO);
364         gpio_request(OLYMPUS_TOUCH_RESET_GPIO, "touch_reset");
365         gpio_direction_output(OLYMPUS_TOUCH_RESET_GPIO, 1);
366
367
368         i2c_register_board_info(0, sholes_i2c_bus1_board_info, 1);
369
370         i2c_register_board_info(3, olympus_i2c_bus4_board_info, 1);
371 }
372