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
|
/*
* arch/arm/mach-tegra/board-whistler-sensors.c
*
* Copyright (c) 2010, 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/i2c.h>
#include <mach/gpio.h>
#include <media/ov5650.h>
#include <linux/regulator/consumer.h>
#include <linux/err.h>
#include "gpio-names.h"
#define CAMERA1_PWDN_GPIO TEGRA_GPIO_PT2
#define CAMERA1_RESET_GPIO TEGRA_GPIO_PD2
#define CAMERA_AF_PD_GPIO TEGRA_GPIO_PT3
#define CAMERA_FLASH_EN1_GPIO TEGRA_GPIO_PBB4
#define CAMERA_FLASH_EN2_GPIO TEGRA_GPIO_PA0
#define ADXL34X_IRQ_GPIO TEGRA_GPIO_PAA1
#define ISL29018_IRQ_GPIO TEGRA_GPIO_PK2
static struct regulator *reg_avdd_cam1; /* LDO9 */
static struct regulator *reg_vdd_af; /* LDO13 */
static int whistler_camera_init(void)
{
tegra_gpio_enable(CAMERA1_PWDN_GPIO);
gpio_request(CAMERA1_PWDN_GPIO, "camera1_powerdown");
gpio_direction_output(CAMERA1_PWDN_GPIO, 0);
tegra_gpio_enable(CAMERA1_RESET_GPIO);
gpio_request(CAMERA1_RESET_GPIO, "camera1_reset");
gpio_direction_output(CAMERA1_RESET_GPIO, 0);
tegra_gpio_enable(CAMERA_AF_PD_GPIO);
gpio_request(CAMERA_AF_PD_GPIO, "camera_autofocus");
gpio_direction_output(CAMERA_AF_PD_GPIO, 0);
gpio_export(CAMERA_AF_PD_GPIO, false);
tegra_gpio_enable(CAMERA_FLASH_EN1_GPIO);
gpio_request(CAMERA_FLASH_EN1_GPIO, "camera_flash_en1");
gpio_direction_output(CAMERA_FLASH_EN1_GPIO, 0);
gpio_export(CAMERA_FLASH_EN1_GPIO, false);
tegra_gpio_enable(CAMERA_FLASH_EN2_GPIO);
gpio_request(CAMERA_FLASH_EN2_GPIO, "camera_flash_en2");
gpio_direction_output(CAMERA_FLASH_EN2_GPIO, 0);
gpio_export(CAMERA_FLASH_EN2_GPIO, false);
return 0;
}
static int whistler_ov5650_power_on(void)
{
gpio_set_value(CAMERA1_PWDN_GPIO, 1);
gpio_set_value(CAMERA1_RESET_GPIO, 1);
gpio_set_value(CAMERA_AF_PD_GPIO, 1);
if (!reg_avdd_cam1) {
reg_avdd_cam1 = regulator_get(NULL, "vdd_cam1");
if (IS_ERR_OR_NULL(reg_avdd_cam1)) {
pr_err("whistler_ov5650_power_on: vdd_cam1 failed\n");
reg_avdd_cam1 = NULL;
return PTR_ERR(reg_avdd_cam1);
}
regulator_enable(reg_avdd_cam1);
}
if (!reg_vdd_af) {
reg_vdd_af = regulator_get(NULL, "vdd_vcore_af");
if (IS_ERR_OR_NULL(reg_vdd_af)) {
pr_err("whistler_ov5650_power_on: vdd_vcore_af failed\n");
reg_vdd_af = NULL;
return PTR_ERR(reg_vdd_af);
}
regulator_enable(reg_vdd_af);
}
return 0;
}
static int whistler_ov5650_power_off(void)
{
gpio_set_value(CAMERA1_PWDN_GPIO, 0);
gpio_set_value(CAMERA1_RESET_GPIO, 0);
gpio_set_value(CAMERA_AF_PD_GPIO, 0);
if (reg_avdd_cam1) {
regulator_disable(reg_avdd_cam1);
regulator_put(reg_avdd_cam1);
reg_avdd_cam1 = NULL;
}
if (reg_vdd_af) {
regulator_disable(reg_vdd_af);
regulator_put(reg_vdd_af);
reg_vdd_af = NULL;
}
return 0;
}
struct ov5650_platform_data whistler_ov5650_data = {
.power_on = whistler_ov5650_power_on,
.power_off = whistler_ov5650_power_off,
};
static struct i2c_board_info whistler_i2c3_board_info[] = {
{
I2C_BOARD_INFO("ov5650", 0x36),
.platform_data = &whistler_ov5650_data,
},
};
static void whistler_adxl34x_init(void)
{
tegra_gpio_enable(ADXL34X_IRQ_GPIO);
gpio_request(ADXL34X_IRQ_GPIO, "adxl34x");
gpio_direction_input(ADXL34X_IRQ_GPIO);
}
static void whistler_isl29018_init(void)
{
tegra_gpio_enable(ISL29018_IRQ_GPIO);
gpio_request(ISL29018_IRQ_GPIO, "isl29018");
gpio_direction_input(ISL29018_IRQ_GPIO);
}
static struct i2c_board_info whistler_i2c1_board_info[] = {
{
I2C_BOARD_INFO("adxl34x", 0x1D),
.irq = TEGRA_GPIO_TO_IRQ(ADXL34X_IRQ_GPIO),
},
{
I2C_BOARD_INFO("isl29018", 0x44),
.irq = TEGRA_GPIO_TO_IRQ(ISL29018_IRQ_GPIO),
},
};
int __init whistler_sensors_init(void)
{
whistler_camera_init();
whistler_adxl34x_init();
whistler_isl29018_init();
i2c_register_board_info(0, whistler_i2c1_board_info,
ARRAY_SIZE(whistler_i2c1_board_info));
i2c_register_board_info(3, whistler_i2c3_board_info,
ARRAY_SIZE(whistler_i2c3_board_info));
return 0;
}
|