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
|
/*
* arch/arm/mach-tegra/board-kai-sensors.c
*
* Copyright (c) 2012, NVIDIA Corporation.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/nct1008.h>
#include <linux/cm3217.h>
#include <linux/mpu.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <asm/mach-types.h>
#include <mach/gpio.h>
#include <mach/thermal.h>
#include <media/ov2710.h>
#include "board.h"
#include "board-kai.h"
#include "cpu-tegra.h"
static struct regulator *kai_1v8_cam3;
static struct regulator *kai_vdd_cam3;
#ifndef CONFIG_TEGRA_INTERNAL_TSENSOR_EDP_SUPPORT
static int nct_get_temp(void *_data, long *temp)
{
struct nct1008_data *data = _data;
return nct1008_thermal_get_temp(data, temp);
}
static int nct_get_temp_low(void *_data, long *temp)
{
struct nct1008_data *data = _data;
return nct1008_thermal_get_temp_low(data, temp);
}
static int nct_set_limits(void *_data,
long lo_limit_milli,
long hi_limit_milli)
{
struct nct1008_data *data = _data;
return nct1008_thermal_set_limits(data,
lo_limit_milli,
hi_limit_milli);
}
static int nct_set_alert(void *_data,
void (*alert_func)(void *),
void *alert_data)
{
struct nct1008_data *data = _data;
return nct1008_thermal_set_alert(data, alert_func, alert_data);
}
static int nct_set_shutdown_temp(void *_data, long shutdown_temp)
{
struct nct1008_data *data = _data;
return nct1008_thermal_set_shutdown_temp(data, shutdown_temp);
}
static void nct1008_probe_callback(struct nct1008_data *data)
{
struct tegra_thermal_device *thermal_device;
thermal_device = kzalloc(sizeof(struct tegra_thermal_device),
GFP_KERNEL);
if (!thermal_device) {
pr_err("unable to allocate thermal device\n");
return;
}
thermal_device->name = "nct72";
thermal_device->data = data;
thermal_device->id = THERMAL_DEVICE_ID_NCT_EXT;
thermal_device->offset = TDIODE_OFFSET;
thermal_device->get_temp = nct_get_temp;
thermal_device->get_temp_low = nct_get_temp_low;
thermal_device->set_limits = nct_set_limits;
thermal_device->set_alert = nct_set_alert;
thermal_device->set_shutdown_temp = nct_set_shutdown_temp;
tegra_thermal_device_register(thermal_device);
}
#endif
static struct nct1008_platform_data kai_nct1008_pdata = {
.supported_hwrev = true,
.ext_range = true,
.conv_rate = 0x09, /* 0x09 corresponds to 32Hz conversion rate */
.offset = 8, /* 4 * 2C. 1C for device accuracies */
#ifndef CONFIG_TEGRA_INTERNAL_TSENSOR_EDP_SUPPORT
.probe_callback = nct1008_probe_callback,
#endif
};
static struct i2c_board_info kai_i2c4_nct1008_board_info[] = {
{
I2C_BOARD_INFO("nct72", 0x4C),
.platform_data = &kai_nct1008_pdata,
.irq = -1,
}
};
static int kai_nct1008_init(void)
{
int ret = 0;
/* FIXME: enable irq when throttling is supported */
kai_i2c4_nct1008_board_info[0].irq =
TEGRA_GPIO_TO_IRQ(KAI_TEMP_ALERT_GPIO);
ret = gpio_request(KAI_TEMP_ALERT_GPIO, "temp_alert");
if (ret < 0) {
pr_err("%s: gpio_request failed\n", __func__);
return ret;
}
ret = gpio_direction_input(KAI_TEMP_ALERT_GPIO);
if (ret < 0) {
pr_err("%s: set gpio to input failed\n", __func__);
gpio_free(KAI_TEMP_ALERT_GPIO);
}
return ret;
}
static struct cm3217_platform_data kai_cm3217_pdata = {
.levels = {10, 160, 225, 320, 640, 1280, 2600, 5800, 8000, 10240},
.golden_adc = 0,
.power = 0,
};
static struct i2c_board_info kai_i2c0_cm3217_board_info[] = {
{
I2C_BOARD_INFO("cm3217", 0x10),
.platform_data = &kai_cm3217_pdata,
},
};
static int kai_camera_init(void)
{
int ret;
ret = gpio_request(CAM2_POWER_DWN_GPIO, "cam2_power_en");
if (ret < 0) {
pr_err("%s: gpio_request failed for gpio %s\n",
__func__, "CAM2_POWER_DWN_GPIO");
}
gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
mdelay(10);
ret = gpio_request(CAM2_RST_GPIO, "cam2_reset");
if (ret < 0) {
pr_err("%s: gpio_request failed for gpio %s\n",
__func__, "CAM2_RST_GPIO");
}
gpio_direction_output(CAM2_RST_GPIO, 0);
mdelay(5);
return 0;
}
static int kai_ov2710_power_on(void)
{
gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
mdelay(10);
if (kai_vdd_cam3 == NULL) {
kai_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
if (WARN_ON(IS_ERR(kai_vdd_cam3))) {
pr_err("%s: couldn't get regulator vdd_cam3: %d\n",
__func__, (int)PTR_ERR(kai_vdd_cam3));
goto reg_get_vdd_cam3_fail;
}
}
regulator_enable(kai_vdd_cam3);
if (kai_1v8_cam3 == NULL) {
kai_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
if (WARN_ON(IS_ERR(kai_1v8_cam3))) {
pr_err("%s: couldn't get regulator vdd_1v8_cam3: %d\n",
__func__, (int)PTR_ERR(kai_1v8_cam3));
goto reg_get_vdd_1v8_cam3_fail;
}
}
regulator_enable(kai_1v8_cam3);
mdelay(5);
gpio_direction_output(CAM2_RST_GPIO, 1);
mdelay(10);
return 0;
reg_get_vdd_1v8_cam3_fail:
kai_1v8_cam3 = NULL;
regulator_put(kai_vdd_cam3);
reg_get_vdd_cam3_fail:
kai_vdd_cam3 = NULL;
return -ENODEV;
}
static int kai_ov2710_power_off(void)
{
gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
gpio_direction_output(CAM2_RST_GPIO, 0);
if (kai_1v8_cam3)
regulator_disable(kai_1v8_cam3);
if (kai_vdd_cam3)
regulator_disable(kai_vdd_cam3);
return 0;
}
struct ov2710_platform_data kai_ov2710_data = {
.power_on = kai_ov2710_power_on,
.power_off = kai_ov2710_power_off,
};
static struct i2c_board_info kai_i2c2_board_info[] = {
{
I2C_BOARD_INFO("ov2710", 0x36),
.platform_data = &kai_ov2710_data,
},
};
/* MPU board file definition */
#if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
#define MPU_GYRO_NAME "mpu3050"
#endif
#if (MPU_GYRO_TYPE == MPU_TYPE_MPU6050)
#define MPU_GYRO_NAME "mpu6050"
#endif
static struct mpu_platform_data mpu_gyro_data = {
.int_config = 0x10,
.level_shifter = 0,
.orientation = MPU_GYRO_ORIENTATION,
};
#if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
static struct ext_slave_platform_data mpu_accel_data = {
.address = MPU_ACCEL_ADDR,
.irq = 0,
.adapt_num = MPU_ACCEL_BUS_NUM,
.bus = EXT_SLAVE_BUS_SECONDARY,
.orientation = MPU_ACCEL_ORIENTATION,
};
#endif
static struct ext_slave_platform_data mpu_compass_data = {
.address = MPU_COMPASS_ADDR,
.irq = 0,
.adapt_num = MPU_COMPASS_BUS_NUM,
.bus = EXT_SLAVE_BUS_PRIMARY,
.orientation = MPU_COMPASS_ORIENTATION,
};
static struct i2c_board_info __initdata inv_mpu_i2c0_board_info[] = {
{
I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
.irq = TEGRA_GPIO_TO_IRQ(MPU_GYRO_IRQ_GPIO),
.platform_data = &mpu_gyro_data,
},
#if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
{
I2C_BOARD_INFO(MPU_ACCEL_NAME, MPU_ACCEL_ADDR),
#if MPU_ACCEL_IRQ_GPIO
.irq = TEGRA_GPIO_TO_IRQ(MPU_ACCEL_IRQ_GPIO),
#endif
.platform_data = &mpu_accel_data,
},
#endif
{
I2C_BOARD_INFO(MPU_COMPASS_NAME, MPU_COMPASS_ADDR),
#if MPU_COMPASS_IRQ_GPIO
.irq = TEGRA_GPIO_TO_IRQ(MPU_COMPASS_IRQ_GPIO),
#endif
.platform_data = &mpu_compass_data,
},
};
static void mpuirq_init(void)
{
int ret = 0;
pr_info("*** MPU START *** mpuirq_init...\n");
#if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
#if MPU_ACCEL_IRQ_GPIO
/* ACCEL-IRQ assignment */
ret = gpio_request(MPU_ACCEL_IRQ_GPIO, MPU_ACCEL_NAME);
if (ret < 0) {
pr_err("%s: gpio_request failed %d\n", __func__, ret);
return;
}
ret = gpio_direction_input(MPU_ACCEL_IRQ_GPIO);
if (ret < 0) {
pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
gpio_free(MPU_ACCEL_IRQ_GPIO);
return;
}
#endif
#endif
/* MPU-IRQ assignment */
ret = gpio_request(MPU_GYRO_IRQ_GPIO, MPU_GYRO_NAME);
if (ret < 0) {
pr_err("%s: gpio_request failed %d\n", __func__, ret);
return;
}
ret = gpio_direction_input(MPU_GYRO_IRQ_GPIO);
if (ret < 0) {
pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
gpio_free(MPU_GYRO_IRQ_GPIO);
return;
}
pr_info("*** MPU END *** mpuirq_init...\n");
i2c_register_board_info(MPU_GYRO_BUS_NUM, inv_mpu_i2c0_board_info,
ARRAY_SIZE(inv_mpu_i2c0_board_info));
}
int __init kai_sensors_init(void)
{
int err;
err = kai_nct1008_init();
if (err)
pr_err("%s: nct1008 init failed\n", __func__);
else
i2c_register_board_info(4, kai_i2c4_nct1008_board_info,
ARRAY_SIZE(kai_i2c4_nct1008_board_info));
kai_camera_init();
i2c_register_board_info(2, kai_i2c2_board_info,
ARRAY_SIZE(kai_i2c2_board_info));
i2c_register_board_info(0, kai_i2c0_cm3217_board_info,
ARRAY_SIZE(kai_i2c0_cm3217_board_info));
mpuirq_init();
return 0;
}
|