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