[mach-tegra/whistler] Mux i2c bus i2c2
[linux-2.6.git] / arch / arm / mach-tegra / board-whistler.c
1 /*
2  * arch/arm/mach-tegra/board-whistler.c
3  *
4  * Copyright (c) 2010, NVIDIA Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/ctype.h>
25 #include <linux/platform_device.h>
26 #include <linux/clk.h>
27 #include <linux/serial_8250.h>
28 #include <linux/i2c.h>
29 #include <linux/i2c/panjit_ts.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/delay.h>
32 #include <linux/i2c-tegra.h>
33 #include <linux/gpio.h>
34 #include <linux/gpio_scrollwheel.h>
35 #include <linux/input.h>
36 #include <linux/tegra_usb.h>
37 #include <linux/memblock.h>
38
39 #include <mach/clk.h>
40 #include <mach/iomap.h>
41 #include <mach/irqs.h>
42 #include <mach/pinmux.h>
43 #include <mach/iomap.h>
44 #include <mach/io.h>
45
46 #include <asm/mach-types.h>
47 #include <asm/mach/arch.h>
48 #include <mach/usb_phy.h>
49
50 #include "board.h"
51 #include "clock.h"
52 #include "board-whistler.h"
53 #include "devices.h"
54 #include "gpio-names.h"
55 #include "fuse.h"
56
57 static struct plat_serial8250_port debug_uart_platform_data[] = {
58         {
59                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
60                 .mapbase        = TEGRA_UARTA_BASE,
61                 .irq            = INT_UARTA,
62                 .flags          = UPF_BOOT_AUTOCONF,
63                 .iotype         = UPIO_MEM,
64                 .regshift       = 2,
65                 .uartclk        = 216000000,
66         }, {
67                 .flags          = 0,
68         }
69 };
70
71 static struct platform_device debug_uart = {
72         .name = "serial8250",
73         .id = PLAT8250_DEV_PLATFORM,
74         .dev = {
75                 .platform_data = debug_uart_platform_data,
76         },
77 };
78
79 #ifdef CONFIG_BCM4329_RFKILL
80
81 static struct resource whistler_bcm4329_rfkill_resources[] = {
82         {
83                 .name   = "bcm4329_nshutdown_gpio",
84                 .start  = TEGRA_GPIO_PU0,
85                 .end    = TEGRA_GPIO_PU0,
86                 .flags  = IORESOURCE_IO,
87         },
88 };
89
90 static struct platform_device whistler_bcm4329_rfkill_device = {
91         .name           = "bcm4329_rfkill",
92         .id             = -1,
93         .num_resources  = ARRAY_SIZE(whistler_bcm4329_rfkill_resources),
94         .resource       = whistler_bcm4329_rfkill_resources,
95 };
96
97 static noinline void __init whistler_bt_rfkill(void)
98 {
99         platform_device_register(&whistler_bcm4329_rfkill_device);
100         return;
101 }
102 #else
103 static inline void whistler_bt_rfkill(void) { }
104 #endif
105
106 static struct tegra_utmip_config utmi_phy_config[] = {
107         [0] = {
108                         .hssync_start_delay = 0,
109                         .idle_wait_delay = 17,
110                         .elastic_limit = 16,
111                         .term_range_adj = 6,
112                         .xcvr_setup = 15,
113                         .xcvr_lsfslew = 2,
114                         .xcvr_lsrslew = 2,
115                 },
116         [1] = {
117                         .hssync_start_delay = 0,
118                         .idle_wait_delay = 17,
119                         .elastic_limit = 16,
120                         .term_range_adj = 6,
121                         .xcvr_setup = 8,
122                         .xcvr_lsfslew = 2,
123                         .xcvr_lsrslew = 2,
124                 },
125 };
126
127 static struct tegra_ulpi_config ulpi_phy_config = {
128         .reset_gpio = TEGRA_GPIO_PG2,
129         .clk = "clk_dev2",
130 };
131
132 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
133         /* name         parent          rate            enabled */
134         { "uarta",      "pll_p",        216000000,      true},
135         { "uartc",      "pll_m",        600000000,      false},
136         { "pwm",        "clk_32k",      32768,          false},
137         { "kbc",        "clk_32k",      32768,          true},
138         { "sdmmc2",     "pll_p",        25000000,       false},
139         { NULL,         NULL,           0,              0},
140 };
141
142 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
143         .adapter_nr     = 0,
144         .bus_count      = 1,
145         .bus_clk_rate   = { 400000, 0 },
146 };
147
148 static const struct tegra_pingroup_config i2c2_ddc = {
149         .pingroup       = TEGRA_PINGROUP_DDC,
150         .func           = TEGRA_MUX_I2C2,
151 };
152
153 static const struct tegra_pingroup_config i2c2_gen2 = {
154         .pingroup       = TEGRA_PINGROUP_PTA,
155         .func           = TEGRA_MUX_I2C2,
156 };
157
158 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
159         .adapter_nr     = 1,
160         .bus_count      = 2,
161         .bus_clk_rate   = { 400000, 100000 },
162         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
163         .bus_mux_len    = { 1, 1 },
164 };
165
166 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
167         .adapter_nr     = 3,
168         .bus_count      = 1,
169         .bus_clk_rate   = { 400000, 0 },
170 };
171
172 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
173         .adapter_nr     = 4,
174         .bus_count      = 1,
175         .bus_clk_rate   = { 400000, 0 },
176         .is_dvc         = true,
177 };
178
179 static void whistler_i2c_init(void)
180 {
181         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
182         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
183         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
184         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
185
186         platform_device_register(&tegra_i2c_device4);
187         platform_device_register(&tegra_i2c_device3);
188         platform_device_register(&tegra_i2c_device2);
189         platform_device_register(&tegra_i2c_device1);
190 }
191
192 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
193 {       \
194         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
195         .gpio = TEGRA_GPIO_##_gpio,     \
196         .desc = _desc,  \
197         .active_low = 1,        \
198         .debounce_interval = 2, \
199 }
200
201 static struct gpio_scrollwheel_button scroll_keys[] = {
202         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
203         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
204         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
205         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
206 };
207
208 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
209         .buttons = scroll_keys,
210         .nbuttons = ARRAY_SIZE(scroll_keys),
211 };
212
213 static struct platform_device whistler_scroll_device = {
214         .name   = "alps-gpio-scrollwheel",
215         .id     = 0,
216         .dev    = {
217                 .platform_data  = &whistler_scroll_platform_data,
218         },
219 };
220
221 static struct platform_device tegra_camera = {
222         .name = "tegra_camera",
223         .id = -1,
224 };
225
226 static struct platform_device *whistler_devices[] __initdata = {
227         &debug_uart,
228         &tegra_uartb_device,
229         &tegra_uartc_device,
230         &pmu_device,
231         &tegra_udc_device,
232         &tegra_gart_device,
233         &tegra_wdt_device,
234         &tegra_avp_device,
235         &whistler_scroll_device,
236         &tegra_camera,
237 };
238
239 static int __init whistler_scroll_init(void)
240 {
241         int i;
242         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
243                 tegra_gpio_enable(scroll_keys[i].gpio);
244
245         return 0;
246 }
247
248
249 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
250         [0] = {
251                         .phy_config = &utmi_phy_config[0],
252                         .operating_mode = TEGRA_USB_HOST,
253                         .power_down_on_bus_suspend = 0,
254                 },
255         [1] = {
256                         .phy_config = &ulpi_phy_config,
257                         .operating_mode = TEGRA_USB_HOST,
258                         .power_down_on_bus_suspend = 1,
259                 },
260         [2] = {
261                         .phy_config = &utmi_phy_config[1],
262                         .operating_mode = TEGRA_USB_HOST,
263                         .power_down_on_bus_suspend = 0,
264         },
265 };
266
267 static struct platform_device *tegra_usb_otg_host_register(void)
268 {
269         struct platform_device *pdev;
270         void *platform_data;
271         int val;
272
273         pdev = platform_device_alloc(tegra_ehci1_device.name,
274                         tegra_ehci1_device.id);
275         if (!pdev)
276                 return NULL;
277
278         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
279                 tegra_ehci1_device.num_resources);
280         if (val)
281                 goto error;
282
283         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
284         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
285
286         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
287                                 GFP_KERNEL);
288         if (!platform_data)
289                 goto error;
290
291         memcpy(platform_data, &tegra_ehci_pdata[0],
292                                 sizeof(struct tegra_ehci_platform_data));
293         pdev->dev.platform_data = platform_data;
294
295         val = platform_device_add(pdev);
296         if (val)
297                 goto error_add;
298
299         return pdev;
300
301 error_add:
302         kfree(platform_data);
303 error:
304         pr_err("%s: failed to add the host contoller device\n", __func__);
305         platform_device_put(pdev);
306         return NULL;
307 }
308
309 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
310 {
311         kfree(pdev->dev.platform_data);
312         platform_device_unregister(pdev);
313 }
314
315 static struct tegra_otg_platform_data tegra_otg_pdata = {
316         .host_register = &tegra_usb_otg_host_register,
317         .host_unregister = &tegra_usb_otg_host_unregister,
318 };
319
320 static int __init whistler_gps_init(void)
321 {
322         tegra_gpio_enable(TEGRA_GPIO_PU4);
323         return 0;
324 }
325
326 static void whistler_usb_init(void)
327 {
328         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
329         platform_device_register(&tegra_otg_device);
330
331         tegra_ehci3_device.dev.platform_data=&tegra_ehci_pdata[2];
332         platform_device_register(&tegra_ehci3_device);
333 }
334
335 static void __init tegra_whistler_init(void)
336 {
337         char serial[20];
338
339         tegra_common_init();
340         tegra_clk_init_from_table(whistler_clk_init_table);
341         whistler_pinmux_init();
342         whistler_i2c_init();
343         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
344
345         whistler_sdhci_init();
346         whistler_regulator_init();
347         whistler_panel_init();
348         whistler_sensors_init();
349         whistler_kbc_init();
350         whistler_bt_rfkill();
351         whistler_gps_init();
352         whistler_usb_init();
353         whistler_scroll_init();
354 }
355
356 int __init tegra_whistler_protected_aperture_init(void)
357 {
358         tegra_protected_aperture_init(tegra_grhost_aperture);
359         return 0;
360 }
361
362 void __init tegra_whistler_reserve(void)
363 {
364         if (memblock_reserve(0x0, 4096) < 0)
365                 pr_warn("Cannot reserve first 4K of memory for safety\n");
366
367         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
368 }
369
370 MACHINE_START(WHISTLER, "whistler")
371         .boot_params    = 0x00000100,
372         .phys_io        = IO_APB_PHYS,
373         .io_pg_offst    = ((IO_APB_VIRT) >> 18) & 0xfffc,
374         .init_irq       = tegra_init_irq,
375         .init_machine   = tegra_whistler_init,
376         .map_io         = tegra_map_common_io,
377         .reserve        = tegra_whistler_reserve,
378         .timer          = &tegra_timer,
379 MACHINE_END