1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
|
/*
* arch/arm/mach-tegra/board-ventana-sensors.c
*
* Copyright (c) 2011, NVIDIA, All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/akm8975.h>
#include <linux/mpu.h>
#include <linux/i2c/pca954x.h>
#include <linux/i2c/pca953x.h>
#include <linux/nct1008.h>
#include <linux/err.h>
#include <linux/regulator/consumer.h>
#include <mach/gpio.h>
#include <media/ov5650.h>
#include <media/ov2710.h>
#include <media/ssl3250a.h>
#include <generated/mach-types.h>
#include "gpio-names.h"
#include "board.h"
#include "board-ventana.h"
#define ISL29018_IRQ_GPIO TEGRA_GPIO_PZ2
#define AKM8975_IRQ_GPIO TEGRA_GPIO_PN5
#define CAMERA_POWER_GPIO TEGRA_GPIO_PV4
#define CAMERA_CSI_MUX_SEL_GPIO TEGRA_GPIO_PBB4
#define CAMERA_FLASH_ACT_GPIO TEGRA_GPIO_PD2
#define CAMERA_FLASH_STRB_GPIO TEGRA_GPIO_PA0
#define AC_PRESENT_GPIO TEGRA_GPIO_PV3
#define NCT1008_THERM2_GPIO TEGRA_GPIO_PN6
#define CAMERA_FLASH_OP_MODE 0 /*0=I2C mode, 1=GPIO mode*/
#define CAMERA_FLASH_MAX_LED_AMP 7
#define CAMERA_FLASH_MAX_TORCH_AMP 11
#define CAMERA_FLASH_MAX_FLASH_AMP 31
extern void tegra_throttling_enable(bool enable);
static int ventana_camera_init(void)
{
tegra_gpio_enable(CAMERA_POWER_GPIO);
gpio_request(CAMERA_POWER_GPIO, "camera_power_en");
gpio_direction_output(CAMERA_POWER_GPIO, 1);
gpio_export(CAMERA_POWER_GPIO, false);
tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
return 0;
}
/* left ov5650 is CAM2 which is on csi_a */
static int ventana_left_ov5650_power_on(void)
{
gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 1);
gpio_direction_output(CAM2_LDO_SHUTDN_L_GPIO, 1);
mdelay(5);
gpio_direction_output(CAM2_PWR_DN_GPIO, 0);
mdelay(5);
gpio_direction_output(CAM2_RST_L_GPIO, 0);
mdelay(1);
gpio_direction_output(CAM2_RST_L_GPIO, 1);
mdelay(20);
return 0;
}
static int ventana_left_ov5650_power_off(void)
{
gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 0);
gpio_direction_output(CAM2_RST_L_GPIO, 0);
gpio_direction_output(CAM2_PWR_DN_GPIO, 1);
gpio_direction_output(CAM2_LDO_SHUTDN_L_GPIO, 0);
return 0;
}
struct ov5650_platform_data ventana_left_ov5650_data = {
.power_on = ventana_left_ov5650_power_on,
.power_off = ventana_left_ov5650_power_off,
};
/* right ov5650 is CAM1 which is on csi_b */
static int ventana_right_ov5650_power_on(void)
{
gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 1);
gpio_direction_output(CAM1_LDO_SHUTDN_L_GPIO, 1);
mdelay(5);
gpio_direction_output(CAM1_PWR_DN_GPIO, 0);
mdelay(5);
gpio_direction_output(CAM1_RST_L_GPIO, 0);
mdelay(1);
gpio_direction_output(CAM1_RST_L_GPIO, 1);
mdelay(20);
return 0;
}
static int ventana_right_ov5650_power_off(void)
{
gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 0);
gpio_direction_output(CAM1_RST_L_GPIO, 0);
gpio_direction_output(CAM1_PWR_DN_GPIO, 1);
gpio_direction_output(CAM1_LDO_SHUTDN_L_GPIO, 0);
return 0;
}
struct ov5650_platform_data ventana_right_ov5650_data = {
.power_on = ventana_right_ov5650_power_on,
.power_off = ventana_right_ov5650_power_off,
};
static int ventana_ov2710_power_on(void)
{
gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 1);
gpio_direction_output(CAM3_LDO_SHUTDN_L_GPIO, 1);
mdelay(5);
gpio_direction_output(CAM3_PWR_DN_GPIO, 0);
mdelay(5);
gpio_direction_output(CAM3_RST_L_GPIO, 0);
mdelay(1);
gpio_direction_output(CAM3_RST_L_GPIO, 1);
mdelay(20);
return 0;
}
static int ventana_ov2710_power_off(void)
{
gpio_direction_output(CAM3_RST_L_GPIO, 0);
gpio_direction_output(CAM3_PWR_DN_GPIO, 1);
gpio_direction_output(CAM3_LDO_SHUTDN_L_GPIO, 0);
gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 0);
gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
return 0;
}
struct ov2710_platform_data ventana_ov2710_data = {
.power_on = ventana_ov2710_power_on,
.power_off = ventana_ov2710_power_off,
};
static int ventana_ssl3250a_init(void)
{
gpio_request(CAMERA_FLASH_ACT_GPIO, "torch_gpio_act");
gpio_direction_output(CAMERA_FLASH_ACT_GPIO, 0);
tegra_gpio_enable(CAMERA_FLASH_ACT_GPIO);
gpio_request(CAMERA_FLASH_STRB_GPIO, "torch_gpio_strb");
gpio_direction_output(CAMERA_FLASH_STRB_GPIO, 0);
tegra_gpio_enable(CAMERA_FLASH_STRB_GPIO);
gpio_export(CAMERA_FLASH_STRB_GPIO, false);
return 0;
}
static void ventana_ssl3250a_exit(void)
{
gpio_set_value(CAMERA_FLASH_STRB_GPIO, 0);
gpio_free(CAMERA_FLASH_STRB_GPIO);
tegra_gpio_disable(CAMERA_FLASH_STRB_GPIO);
gpio_set_value(CAMERA_FLASH_ACT_GPIO, 0);
gpio_free(CAMERA_FLASH_ACT_GPIO);
tegra_gpio_disable(CAMERA_FLASH_ACT_GPIO);
}
static int ventana_ssl3250a_gpio_strb(int val)
{
int prev_val;
prev_val = gpio_get_value(CAMERA_FLASH_STRB_GPIO);
gpio_set_value(CAMERA_FLASH_STRB_GPIO, val);
return prev_val;
};
static int ventana_ssl3250a_gpio_act(int val)
{
int prev_val;
prev_val = gpio_get_value(CAMERA_FLASH_ACT_GPIO);
gpio_set_value(CAMERA_FLASH_ACT_GPIO, val);
return prev_val;
};
static struct ssl3250a_platform_data ventana_ssl3250a_data = {
.config = CAMERA_FLASH_OP_MODE,
.max_amp_indic = CAMERA_FLASH_MAX_LED_AMP,
.max_amp_torch = CAMERA_FLASH_MAX_TORCH_AMP,
.max_amp_flash = CAMERA_FLASH_MAX_FLASH_AMP,
.init = ventana_ssl3250a_init,
.exit = ventana_ssl3250a_exit,
.gpio_act = ventana_ssl3250a_gpio_act,
.gpio_en1 = NULL,
.gpio_en2 = NULL,
.gpio_strb = ventana_ssl3250a_gpio_strb,
};
static void ventana_isl29018_init(void)
{
tegra_gpio_enable(ISL29018_IRQ_GPIO);
gpio_request(ISL29018_IRQ_GPIO, "isl29018");
gpio_direction_input(ISL29018_IRQ_GPIO);
}
#ifdef CONFIG_SENSORS_AK8975
static void ventana_akm8975_init(void)
{
tegra_gpio_enable(AKM8975_IRQ_GPIO);
gpio_request(AKM8975_IRQ_GPIO, "akm8975");
gpio_direction_input(AKM8975_IRQ_GPIO);
}
#endif
static void ventana_bq20z75_init(void)
{
tegra_gpio_enable(AC_PRESENT_GPIO);
gpio_request(AC_PRESENT_GPIO, "ac_present");
gpio_direction_input(AC_PRESENT_GPIO);
}
static void ventana_nct1008_init(void)
{
tegra_gpio_enable(NCT1008_THERM2_GPIO);
gpio_request(NCT1008_THERM2_GPIO, "temp_alert");
gpio_direction_input(NCT1008_THERM2_GPIO);
}
static struct nct1008_platform_data ventana_nct1008_pdata = {
.supported_hwrev = true,
.ext_range = false,
.conv_rate = 0x08,
.offset = 0,
.hysteresis = 0,
.shutdown_ext_limit = 115,
.shutdown_local_limit = 120,
.throttling_ext_limit = 90,
.alarm_fn = tegra_throttling_enable,
};
static const struct i2c_board_info ventana_i2c0_board_info[] = {
{
I2C_BOARD_INFO("isl29018", 0x44),
.irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PZ2),
},
};
static const struct i2c_board_info ventana_i2c2_board_info[] = {
{
I2C_BOARD_INFO("bq20z75-battery", 0x0B),
.irq = TEGRA_GPIO_TO_IRQ(AC_PRESENT_GPIO),
},
};
static struct pca953x_platform_data ventana_tca6416_data = {
.gpio_base = TEGRA_NR_GPIOS + 4, /* 4 gpios are already requested by tps6586x */
};
static struct pca954x_platform_mode ventana_pca9546_modes[] = {
{ .adap_id = 6, .deselect_on_exit = 1 }, /* REAR CAM1 */
{ .adap_id = 7, .deselect_on_exit = 1 }, /* REAR CAM2 */
{ .adap_id = 8, .deselect_on_exit = 1 }, /* FRONT CAM3 */
};
static struct pca954x_platform_data ventana_pca9546_data = {
.modes = ventana_pca9546_modes,
.num_modes = ARRAY_SIZE(ventana_pca9546_modes),
};
static const struct i2c_board_info ventana_i2c3_board_info_tca6416[] = {
{
I2C_BOARD_INFO("tca6416", 0x20),
.platform_data = &ventana_tca6416_data,
},
};
static const struct i2c_board_info ventana_i2c3_board_info_pca9546[] = {
{
I2C_BOARD_INFO("pca9546", 0x70),
.platform_data = &ventana_pca9546_data,
},
};
static const struct i2c_board_info ventana_i2c3_board_info_ssl3250a[] = {
{
I2C_BOARD_INFO("ssl3250a", 0x30),
.platform_data = &ventana_ssl3250a_data,
},
};
static struct i2c_board_info ventana_i2c4_board_info[] = {
{
I2C_BOARD_INFO("nct1008", 0x4C),
.irq = TEGRA_GPIO_TO_IRQ(NCT1008_THERM2_GPIO),
.platform_data = &ventana_nct1008_pdata,
},
#ifdef CONFIG_SENSORS_AK8975
{
I2C_BOARD_INFO("akm8975", 0x0C),
.irq = TEGRA_GPIO_TO_IRQ(AKM8975_IRQ_GPIO),
},
#endif
};
static struct i2c_board_info ventana_i2c6_board_info[] = {
{
I2C_BOARD_INFO("ov5650R", 0x36),
.platform_data = &ventana_right_ov5650_data,
},
};
static struct i2c_board_info ventana_i2c7_board_info[] = {
{
I2C_BOARD_INFO("ov5650L", 0x36),
.platform_data = &ventana_left_ov5650_data,
},
{
I2C_BOARD_INFO("sh532u", 0x72),
},
};
static struct i2c_board_info ventana_i2c8_board_info[] = {
{
I2C_BOARD_INFO("ov2710", 0x36),
.platform_data = &ventana_ov2710_data,
},
};
#ifdef CONFIG_MPU_SENSORS_MPU3050
#define SENSOR_MPU_NAME "mpu3050"
static struct mpu3050_platform_data mpu3050_data = {
.int_config = 0x10,
.orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 }, /* Orientation matrix for MPU on ventana */
.level_shifter = 0,
.accel = {
#ifdef CONFIG_MPU_SENSORS_KXTF9
.get_slave_descr = get_accel_slave_descr,
#else
.get_slave_descr = NULL,
#endif
.adapt_num = 0,
.bus = EXT_SLAVE_BUS_SECONDARY,
.address = 0x0F,
.orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 }, /* Orientation matrix for Kionix on ventana */
},
.compass = {
#ifdef CONFIG_MPU_SENSORS_AK8975
.get_slave_descr = get_compass_slave_descr,
#else
.get_slave_descr = NULL,
#endif
.adapt_num = 4, /* bus number 4 on ventana */
.bus = EXT_SLAVE_BUS_PRIMARY,
.address = 0x0C,
.orientation = { 1, 0, 0, 0, -1, 0, 0, 0, -1 }, /* Orientation matrix for AKM on ventana */
},
};
static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
{
I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
.irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PZ4),
.platform_data = &mpu3050_data,
},
};
static void ventana_mpuirq_init(void)
{
pr_info("*** MPU START *** ventana_mpuirq_init...\n");
tegra_gpio_enable(TEGRA_GPIO_PZ4);
gpio_request(TEGRA_GPIO_PZ4, SENSOR_MPU_NAME);
gpio_direction_input(TEGRA_GPIO_PZ4);
pr_info("*** MPU END *** ventana_mpuirq_init...\n");
}
#endif
int __init ventana_sensors_init(void)
{
struct board_info BoardInfo;
ventana_isl29018_init();
#ifdef CONFIG_SENSORS_AK8975
ventana_akm8975_init();
#endif
#ifdef CONFIG_MPU_SENSORS_MPU3050
ventana_mpuirq_init();
#endif
ventana_camera_init();
ventana_nct1008_init();
i2c_register_board_info(0, ventana_i2c0_board_info,
ARRAY_SIZE(ventana_i2c0_board_info));
tegra_get_board_info(&BoardInfo);
/*
* battery driver is supported on FAB.D boards and above only,
* since they have the necessary hardware rework
*/
if (BoardInfo.sku > 0) {
ventana_bq20z75_init();
i2c_register_board_info(2, ventana_i2c2_board_info,
ARRAY_SIZE(ventana_i2c2_board_info));
}
i2c_register_board_info(3, ventana_i2c3_board_info_ssl3250a,
ARRAY_SIZE(ventana_i2c3_board_info_ssl3250a));
i2c_register_board_info(4, ventana_i2c4_board_info,
ARRAY_SIZE(ventana_i2c4_board_info));
i2c_register_board_info(6, ventana_i2c6_board_info,
ARRAY_SIZE(ventana_i2c6_board_info));
i2c_register_board_info(7, ventana_i2c7_board_info,
ARRAY_SIZE(ventana_i2c7_board_info));
i2c_register_board_info(8, ventana_i2c8_board_info,
ARRAY_SIZE(ventana_i2c8_board_info));
#ifdef CONFIG_MPU_SENSORS_MPU3050
i2c_register_board_info(0, mpu3050_i2c0_boardinfo,
ARRAY_SIZE(mpu3050_i2c0_boardinfo));
#endif
return 0;
}
#ifdef CONFIG_TEGRA_CAMERA
struct tegra_camera_gpios {
const char *name;
int gpio;
int enabled;
};
#define TEGRA_CAMERA_GPIO(_name, _gpio, _enabled) \
{ \
.name = _name, \
.gpio = _gpio, \
.enabled = _enabled, \
}
static struct tegra_camera_gpios ventana_camera_gpio_keys[] = {
[0] = TEGRA_CAMERA_GPIO("en_avdd_csi", AVDD_DSI_CSI_ENB_GPIO, 1),
[1] = TEGRA_CAMERA_GPIO("cam_i2c_mux_rst_lo", CAM_I2C_MUX_RST_GPIO, 1),
[2] = TEGRA_CAMERA_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 0),
[3] = TEGRA_CAMERA_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
[4] = TEGRA_CAMERA_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
[5] = TEGRA_CAMERA_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
[6] = TEGRA_CAMERA_GPIO("cam3_ldo_shdn_lo", CAM3_LDO_SHUTDN_L_GPIO, 0),
[7] = TEGRA_CAMERA_GPIO("cam3_af_pwdn_lo", CAM3_AF_PWR_DN_L_GPIO, 0),
[8] = TEGRA_CAMERA_GPIO("cam3_pwdn", CAM3_PWR_DN_GPIO, 0),
[9] = TEGRA_CAMERA_GPIO("cam3_rst_lo", CAM3_RST_L_GPIO, 1),
[10] = TEGRA_CAMERA_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 0),
[11] = TEGRA_CAMERA_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
[12] = TEGRA_CAMERA_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
[13] = TEGRA_CAMERA_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
};
int __init ventana_camera_late_init(void)
{
int ret;
int i;
struct regulator *cam_ldo6 = NULL;
if (!machine_is_ventana())
return 0;
cam_ldo6 = regulator_get(NULL, "vdd_ldo6");
if (IS_ERR_OR_NULL(cam_ldo6)) {
pr_err("%s: Couldn't get regulator ldo6\n", __func__);
return PTR_ERR(cam_ldo6);
}
ret = regulator_set_voltage(cam_ldo6, 1800*1000, 1800*1000);
if (ret){
pr_err("%s: Failed to set ldo6 to 1.8v\n", __func__);
goto fail_put_regulator;
}
ret = regulator_enable(cam_ldo6);
if (ret){
pr_err("%s: Failed to enable ldo6\n", __func__);
goto fail_put_regulator;
}
i2c_new_device(i2c_get_adapter(3), ventana_i2c3_board_info_tca6416);
for (i = 0; i < ARRAY_SIZE(ventana_camera_gpio_keys); i++) {
ret = gpio_request(ventana_camera_gpio_keys[i].gpio,
ventana_camera_gpio_keys[i].name);
if (ret < 0) {
pr_err("%s: gpio_request failed for gpio #%d\n",
__func__, i);
goto fail_free_gpio;
}
gpio_direction_output(ventana_camera_gpio_keys[i].gpio,
ventana_camera_gpio_keys[i].enabled);
gpio_export(ventana_camera_gpio_keys[i].gpio, false);
}
i2c_new_device(i2c_get_adapter(3), ventana_i2c3_board_info_pca9546);
ventana_ov2710_power_off();
ventana_left_ov5650_power_off();
ventana_right_ov5650_power_off();
ret = regulator_disable(cam_ldo6);
if (ret){
pr_err("%s: Failed to disable ldo6\n", __func__);
goto fail_free_gpio;
}
regulator_put(cam_ldo6);
return 0;
fail_free_gpio:
while (i--)
gpio_free(ventana_camera_gpio_keys[i].gpio);
fail_put_regulator:
regulator_put(cam_ldo6);
return ret;
}
late_initcall(ventana_camera_late_init);
#endif /* CONFIG_TEGRA_CAMERA */
|