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
|
/*
* arch/arm/mach-tegra/board-generic.c
*
* Copyright (C) 2010 Google, Inc.
* Copyright (C) 2010 NVIDIA Corporation
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/serial_8250.h>
#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/pda_power.h>
#include <linux/io.h>
#include <linux/usb/android_composite.h>
#include <linux/i2c.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/time.h>
#include <asm/setup.h>
#include <mach/gpio.h>
#include "gpio-names.h"
#include <mach/iomap.h>
#include <mach/irqs.h>
#include <mach/nvrm_linux.h>
#include <nvrm_module.h>
#include <linux/spi/spi.h>
#include "nvodm_query.h"
#include "nvodm_query_discovery.h"
#include "board.h"
#ifdef CONFIG_USB_ANDROID
static char *tegra_android_functions_ums[] = {
#ifdef CONFIG_USB_ANDROID_MASS_STORAGE
"usb_mass_storage",
#endif
};
static char *tegra_android_functions_ums_adb[] = {
#ifdef CONFIG_USB_ANDROID_MASS_STORAGE
"usb_mass_storage",
#endif
#ifdef CONFIG_USB_ANDROID_ADB
"adb",
#endif
};
static char *tegra_android_functions_rndis[] = {
#ifdef CONFIG_USB_ANDROID_RNDIS
"rndis",
#endif
};
static char *tegra_android_functions_rndis_adb[] = {
#ifdef CONFIG_USB_ANDROID_RNDIS
"rndis",
#endif
#ifdef CONFIG_USB_ANDROID_ADB
"adb",
#endif
};
static char *tegra_android_functions_all[] = {
#ifdef CONFIG_USB_ANDROID_RNDIS
"rndis",
#endif
#ifdef CONFIG_USB_ANDROID_MASS_STORAGE
"usb_mass_storage",
#endif
#ifdef CONFIG_USB_ANDROID_ADB
"adb",
#endif
};
static struct android_usb_product tegra_android_products[] = {
[0] = {
.product_id = 0x7100,
.num_functions = ARRAY_SIZE(tegra_android_functions_ums),
.functions = tegra_android_functions_ums,
},
[1] = {
.product_id = 0x7100,
.num_functions = ARRAY_SIZE(tegra_android_functions_ums_adb),
.functions = tegra_android_functions_ums_adb,
},
[2] = {
.product_id = 0x7102,
.num_functions = ARRAY_SIZE(tegra_android_functions_rndis),
.functions = tegra_android_functions_rndis,
},
[3] = {
.product_id = 0x7103,
.num_functions = ARRAY_SIZE(tegra_android_functions_rndis_adb),
.functions = tegra_android_functions_rndis_adb,
},
};
static char *harmony_dev = "NVIDIA Harmony";
static char *ventana_dev = "NVIDIA Ventana";
static char *generic_dev = "NVIDIA Tegra 2";
static struct android_usb_platform_data tegra_android_platform = {
.vendor_id = 0x955,
.product_id = 0x7100,
.manufacturer_name = "NVIDIA",
.num_products = ARRAY_SIZE(tegra_android_products),
.products = tegra_android_products,
.num_functions = ARRAY_SIZE(tegra_android_functions_all),
.functions = tegra_android_functions_all,
};
static struct platform_device tegra_android_device = {
.name = "android_usb",
.id = -1,
.dev = {
.platform_data = &tegra_android_platform,
},
};
#ifdef CONFIG_USB_ANDROID_MASS_STORAGE
static struct usb_mass_storage_platform_data tegra_usb_fsg_platform = {
.vendor = "NVIDIA",
.product = "Tegra 2",
.nluns = 1,
.bulk_size = 16384,
};
static struct platform_device tegra_usb_fsg_device = {
.name = "usb_mass_storage",
.id = -1,
.dev = {
.platform_data = &tegra_usb_fsg_platform,
},
};
#endif
#ifdef CONFIG_USB_ANDROID_RNDIS
static struct usb_ether_platform_data tegra_usb_rndis_platform = {
.ethaddr = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
.vendorID = 0x7100,
.vendorDescr = "Tegra 2 RNDIS",
};
static struct platform_device tegra_usb_rndis_device = {
.name = "rndis",
.id = -1,
.dev = {
.platform_data = &tegra_usb_rndis_platform,
},
};
#endif
#endif
static struct platform_device *platform_devices[] = {
#ifdef CONFIG_USB_ANDROID
#ifdef CONFIG_USB_ANDROID_RNDIS
&tegra_usb_rndis_device,
#endif
#ifdef CONFIG_USB_ANDROID_MASS_STORAGE
&tegra_usb_fsg_device,
#endif
&tegra_android_device,
#endif
};
static struct i2c_board_info bus0_i2c_devices[] = {
#ifdef CONFIG_ISL29018
{
I2C_BOARD_INFO("isl29018", 0x44),
.irq = (INT_GPIO_BASE + TEGRA_GPIO_PZ2),
},
#endif
};
static struct i2c_board_info bus3_i2c_devices[] = {
#ifdef CONFIG_SENSORS_AK8975
{
I2C_BOARD_INFO("mm_ak8975", 0x0C),
.irq = (INT_GPIO_BASE + TEGRA_GPIO_PN5),
},
#endif
#ifdef CONFIG_SENSORS_LM90
{
I2C_BOARD_INFO("nct1008", 0x4C),
},
#endif
};
void __init i2c_device_setup(void)
{
if (ARRAY_SIZE(bus0_i2c_devices))
i2c_register_board_info(0, bus0_i2c_devices,
ARRAY_SIZE(bus0_i2c_devices));
if (ARRAY_SIZE(bus3_i2c_devices))
i2c_register_board_info(3, bus3_i2c_devices,
ARRAY_SIZE(bus3_i2c_devices));
}
// enable 32Khz clock used by bcm4329 wifi, bluetooth and gps
static void __init tegra_setup_32khz_clock(void)
{
int RequestedPeriod, ReturnedPeriod;
NvOdmServicesPwmHandle hOdmPwm = NULL;
hOdmPwm = NvOdmPwmOpen();
if (!hOdmPwm) {
pr_err("%s: failed to open NvOdmPwmOpen\n", __func__);
return;
}
RequestedPeriod = 0;
NvOdmPwmConfig(hOdmPwm, NvOdmPwmOutputId_Blink,
NvOdmPwmMode_Blink_32KHzClockOutput, 0, &RequestedPeriod, &ReturnedPeriod);
NvOdmPwmClose(hOdmPwm);
}
extern void __init tegra_setup_nvodm(bool standard_i2c, bool standard_spi);
extern void __init tegra_register_socdev(void);
static struct spi_board_info tegra_spi_ipc_devices[] __initdata = {
{
.modalias = "spi_ipc",
.bus_num = 0,
.chip_select = 0,
.mode = SPI_MODE_1,
.max_speed_hz = 12000000,
.platform_data = NULL,
.irq = 0,
},
};
static void __init register_spi_ipc_devices(void)
{
unsigned long instance = 0xFFFF;
unsigned long cs = 0xFFFF;
const NvOdmPeripheralConnectivity *pConnectivity = NULL;
int i;
pConnectivity =
NvOdmPeripheralGetGuid(NV_ODM_GUID('s','p','i',' ','_','i','p','c'));
if (!pConnectivity)
return;
for (i = 0; i < pConnectivity->NumAddress; i++) {
switch (pConnectivity->AddressList[i].Interface) {
case NvOdmIoModule_Spi:
instance = pConnectivity->AddressList[i].Instance;
cs = pConnectivity->AddressList[i].Address;
break;
default:
break;
}
}
if (instance == 0xffff || cs == 0xffff) {
pr_err("%s: SPI IPC Protocol driver: Instance and CS are Invalid\n", __func__);
return;
}
tegra_spi_ipc_devices[0].bus_num = instance;
tegra_spi_ipc_devices[0].chip_select = cs;
if (spi_register_board_info(tegra_spi_ipc_devices, ARRAY_SIZE(tegra_spi_ipc_devices)) != 0) {
pr_err("%s: spi_register_board_info returned error\n", __func__);
}
}
static void __init do_system_init(bool standard_i2c, bool standard_spi)
{
unsigned int chip_id[2];
char serial[17];
tegra_common_init();
tegra_setup_nvodm(true, true);
tegra_register_socdev();
NvRmQueryChipUniqueId(s_hRmGlobal, sizeof(chip_id), (void*)chip_id);
snprintf(serial, sizeof(serial), "%08x%08x", chip_id[1], chip_id[0]);
#ifdef CONFIG_USB_ANDROID
tegra_android_platform.serial_number = kstrdup(serial, GFP_KERNEL);
#endif
platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
}
#ifdef CONFIG_BT_BLUESLEEP
static noinline void __init tegra_setup_bluesleep(void)
{
struct platform_device *pdev = NULL;
struct resource *res;
pdev = platform_device_alloc("bluesleep", 0);
if (!pdev) {
pr_err("unable to allocate platform device for bluesleep");
return;
}
res = kzalloc(sizeof(struct resource) * 3, GFP_KERNEL);
if (!res) {
pr_err("unable to allocate resource for bluesleep\n");
goto err_free_dev;
}
res[0].name = "gpio_host_wake";
res[0].start = TEGRA_GPIO_PU6;
res[0].end = TEGRA_GPIO_PU6;
res[0].flags = IORESOURCE_IO;
res[1].name = "gpio_ext_wake";
res[1].start = TEGRA_GPIO_PU1;
res[1].end = TEGRA_GPIO_PU1;
res[1].flags = IORESOURCE_IO;
res[2].name = "host_wake";
res[2].start = gpio_to_irq(TEGRA_GPIO_PU6);
res[2].end = gpio_to_irq(TEGRA_GPIO_PU6);
res[2].flags = IORESOURCE_IRQ;
if (platform_device_add_resources(pdev, res, 3)) {
pr_err("unable to add resources to bluesleep device\n");
goto err_free_res;
}
if (platform_device_add(pdev)) {
pr_err("unable to add bluesleep device\n");
goto err_free_res;
}
return;
err_free_res:
kfree(res);
err_free_dev:
platform_device_put(pdev);
return;
}
#else
static inline void tegra_setup_bluesleep(void) { }
#endif
static void __init tegra_harmony_init(void)
{
#ifdef CONFIG_USB_ANDROID
tegra_android_platform.product_name = harmony_dev;
#endif
do_system_init(true, true);
}
static void __init tegra_ventana_init(void)
{
#ifdef CONFIG_USB_ANDROID
tegra_android_platform.product_name = ventana_dev;
#endif
do_system_init(false, true);
i2c_device_setup();
tegra_setup_32khz_clock();
tegra_setup_bluesleep();
ventana_setup_wifi();
}
static void __init tegra_generic_init(void)
{
#ifdef CONFIG_USB_ANDROID
tegra_android_platform.product_name = generic_dev;
#endif
do_system_init(true, true);
register_spi_ipc_devices();
}
MACHINE_START(VENTANA, "NVIDIA Ventana Development System")
.boot_params = 0x00000100,
.phys_io = IO_APB_PHYS,
.io_pg_offst = ((IO_APB_VIRT) >> 18) & 0xfffc,
.init_irq = tegra_init_irq,
.init_machine = tegra_ventana_init,
.map_io = tegra_map_common_io,
.timer = &tegra_timer,
MACHINE_END
MACHINE_START(HARMONY, "NVIDIA Harmony Development System")
.boot_params = 0x00000100,
.phys_io = IO_APB_PHYS,
.io_pg_offst = ((IO_APB_VIRT) >> 18) & 0xfffc,
.init_irq = tegra_init_irq,
.init_machine = tegra_harmony_init,
.map_io = tegra_map_common_io,
.timer = &tegra_timer,
MACHINE_END
MACHINE_START(TEGRA_GENERIC, "Tegra 2 Development System")
.boot_params = 0x00000100,
.phys_io = IO_APB_PHYS,
.io_pg_offst = ((IO_APB_VIRT) >> 18) & 0xfffc,
.init_irq = tegra_init_irq,
.init_machine = tegra_generic_init,
.map_io = tegra_map_common_io,
.timer = &tegra_timer,
MACHINE_END
|