ARM: OMAP: Allow platforms to hook reset cleanly
[linux-2.6.git] / arch / arm / mach-omap1 / board-voiceblue.c
1 /*
2  * linux/arch/arm/mach-omap1/board-voiceblue.c
3  *
4  * Modified from board-generic.c
5  *
6  * Copyright (C) 2004 2N Telekomunikace, Ladislav Michl <michl@2n.cz>
7  *
8  * Code for OMAP5910 based VoiceBlue board (VoIP to GSM gateway).
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/delay.h>
16 #include <linux/platform_device.h>
17 #include <linux/interrupt.h>
18 #include <linux/irq.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/mtd/physmap.h>
22 #include <linux/notifier.h>
23 #include <linux/reboot.h>
24 #include <linux/serial_8250.h>
25 #include <linux/serial_reg.h>
26 #include <linux/smc91x.h>
27
28 #include <mach/hardware.h>
29 #include <mach/system.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33
34 #include <plat/common.h>
35 #include <mach/gpio.h>
36 #include <plat/flash.h>
37 #include <plat/mux.h>
38 #include <plat/tc.h>
39 #include <plat/usb.h>
40
41 static struct plat_serial8250_port voiceblue_ports[] = {
42         {
43                 .mapbase        = (unsigned long)(OMAP_CS1_PHYS + 0x40000),
44                 .irq            = OMAP_GPIO_IRQ(12),
45                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
46                 .iotype         = UPIO_MEM,
47                 .regshift       = 1,
48                 .uartclk        = 3686400,
49         },
50         {
51                 .mapbase        = (unsigned long)(OMAP_CS1_PHYS + 0x50000),
52                 .irq            = OMAP_GPIO_IRQ(13),
53                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
54                 .iotype         = UPIO_MEM,
55                 .regshift       = 1,
56                 .uartclk        = 3686400,
57         },
58         {
59                 .mapbase        = (unsigned long)(OMAP_CS1_PHYS + 0x60000),
60                 .irq            = OMAP_GPIO_IRQ(14),
61                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
62                 .iotype         = UPIO_MEM,
63                 .regshift       = 1,
64                 .uartclk        = 3686400,
65         },
66         {
67                 .mapbase        = (unsigned long)(OMAP_CS1_PHYS + 0x70000),
68                 .irq            = OMAP_GPIO_IRQ(15),
69                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
70                 .iotype         = UPIO_MEM,
71                 .regshift       = 1,
72                 .uartclk        = 3686400,
73         },
74         { },
75 };
76
77 static struct platform_device serial_device = {
78         .name                   = "serial8250",
79         .id                     = PLAT8250_DEV_PLATFORM1,
80         .dev                    = {
81                 .platform_data  = voiceblue_ports,
82         },
83 };
84
85 static int __init ext_uart_init(void)
86 {
87         if (!machine_is_voiceblue())
88                 return -ENODEV;
89
90         return platform_device_register(&serial_device);
91 }
92 arch_initcall(ext_uart_init);
93
94 static struct physmap_flash_data voiceblue_flash_data = {
95         .width          = 2,
96         .set_vpp        = omap1_set_vpp,
97 };
98
99 static struct resource voiceblue_flash_resource = {
100         .start  = OMAP_CS0_PHYS,
101         .end    = OMAP_CS0_PHYS + SZ_32M - 1,
102         .flags  = IORESOURCE_MEM,
103 };
104
105 static struct platform_device voiceblue_flash_device = {
106         .name           = "physmap-flash",
107         .id             = 0,
108         .dev            = {
109                 .platform_data  = &voiceblue_flash_data,
110         },
111         .num_resources  = 1,
112         .resource       = &voiceblue_flash_resource,
113 };
114
115 static struct smc91x_platdata voiceblue_smc91x_info = {
116         .flags  = SMC91X_USE_16BIT | SMC91X_NOWAIT,
117         .leda   = RPC_LED_100_10,
118         .ledb   = RPC_LED_TX_RX,
119 };
120
121 static struct resource voiceblue_smc91x_resources[] = {
122         [0] = {
123                 .start  = OMAP_CS2_PHYS + 0x300,
124                 .end    = OMAP_CS2_PHYS + 0x300 + 16,
125                 .flags  = IORESOURCE_MEM,
126         },
127         [1] = {
128                 .start  = OMAP_GPIO_IRQ(8),
129                 .end    = OMAP_GPIO_IRQ(8),
130                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
131         },
132 };
133
134 static struct platform_device voiceblue_smc91x_device = {
135         .name           = "smc91x",
136         .id             = 0,
137         .dev    = {
138                 .platform_data  = &voiceblue_smc91x_info,
139         },
140         .num_resources  = ARRAY_SIZE(voiceblue_smc91x_resources),
141         .resource       = voiceblue_smc91x_resources,
142 };
143
144 static struct platform_device *voiceblue_devices[] __initdata = {
145         &voiceblue_flash_device,
146         &voiceblue_smc91x_device,
147 };
148
149 static struct omap_usb_config voiceblue_usb_config __initdata = {
150         .hmc_mode       = 3,
151         .register_host  = 1,
152         .register_dev   = 1,
153         .pins[0]        = 2,
154         .pins[1]        = 6,
155         .pins[2]        = 6,
156 };
157
158 static struct omap_board_config_kernel voiceblue_config[] = {
159 };
160
161 static void __init voiceblue_init_irq(void)
162 {
163         omap1_init_common_hw();
164         omap_init_irq();
165 }
166
167 static void __init voiceblue_map_io(void)
168 {
169         omap1_map_common_io();
170 }
171
172 #define MACHINE_PANICED         1
173 #define MACHINE_REBOOTING       2
174 #define MACHINE_REBOOT          4
175 static unsigned long machine_state;
176
177 static int panic_event(struct notifier_block *this, unsigned long event,
178          void *ptr)
179 {
180         if (test_and_set_bit(MACHINE_PANICED, &machine_state))
181                 return NOTIFY_DONE;
182
183         /* Flash power LED */
184         omap_writeb(0x78, OMAP_LPG1_LCR);
185         omap_writeb(0x01, OMAP_LPG1_PMR);       /* Enable clock */
186
187         return NOTIFY_DONE;
188 }
189
190 static struct notifier_block panic_block = {
191         .notifier_call  = panic_event,
192 };
193
194 static int __init voiceblue_setup(void)
195 {
196         if (!machine_is_voiceblue())
197                 return -ENODEV;
198
199         /* Setup panic notifier */
200         atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
201
202         return 0;
203 }
204 postcore_initcall(voiceblue_setup);
205
206 static int wdt_gpio_state;
207
208 void voiceblue_wdt_enable(void)
209 {
210         gpio_direction_output(0, 0);
211         gpio_set_value(0, 1);
212         gpio_set_value(0, 0);
213         wdt_gpio_state = 0;
214 }
215
216 void voiceblue_wdt_disable(void)
217 {
218         gpio_set_value(0, 0);
219         gpio_set_value(0, 1);
220         gpio_set_value(0, 0);
221         gpio_direction_input(0);
222 }
223
224 void voiceblue_wdt_ping(void)
225 {
226         if (test_bit(MACHINE_REBOOT, &machine_state))
227                 return;
228
229         wdt_gpio_state = !wdt_gpio_state;
230         gpio_set_value(0, wdt_gpio_state);
231 }
232
233 static void voiceblue_reset(char mode, const char *cmd)
234 {
235         /*
236          * Workaround for 5912/1611b bug mentioned in sprz209d.pdf p. 28
237          * "Global Software Reset Affects Traffic Controller Frequency".
238          */
239         if (cpu_is_omap5912()) {
240                 omap_writew(omap_readw(DPLL_CTL) & ~(1 << 4), DPLL_CTL);
241                 omap_writew(0x8, ARM_RSTCT1);
242         }
243
244         set_bit(MACHINE_REBOOT, &machine_state);
245         voiceblue_wdt_enable();
246         while (1) ;
247 }
248
249 EXPORT_SYMBOL(voiceblue_wdt_enable);
250 EXPORT_SYMBOL(voiceblue_wdt_disable);
251 EXPORT_SYMBOL(voiceblue_wdt_ping);
252
253 static void __init voiceblue_init(void)
254 {
255         /* mux pins for uarts */
256         omap_cfg_reg(UART1_TX);
257         omap_cfg_reg(UART1_RTS);
258         omap_cfg_reg(UART2_TX);
259         omap_cfg_reg(UART2_RTS);
260         omap_cfg_reg(UART3_TX);
261         omap_cfg_reg(UART3_RX);
262
263         /* Watchdog */
264         gpio_request(0, "Watchdog");
265         /* smc91x reset */
266         gpio_request(7, "SMC91x reset");
267         gpio_direction_output(7, 1);
268         udelay(2);      /* wait at least 100ns */
269         gpio_set_value(7, 0);
270         mdelay(50);     /* 50ms until PHY ready */
271         /* smc91x interrupt pin */
272         gpio_request(8, "SMC91x irq");
273         /* 16C554 reset*/
274         gpio_request(6, "16C554 reset");
275         gpio_direction_output(6, 0);
276         /* 16C554 interrupt pins */
277         gpio_request(12, "16C554 irq");
278         gpio_request(13, "16C554 irq");
279         gpio_request(14, "16C554 irq");
280         gpio_request(15, "16C554 irq");
281         set_irq_type(gpio_to_irq(12), IRQ_TYPE_EDGE_RISING);
282         set_irq_type(gpio_to_irq(13), IRQ_TYPE_EDGE_RISING);
283         set_irq_type(gpio_to_irq(14), IRQ_TYPE_EDGE_RISING);
284         set_irq_type(gpio_to_irq(15), IRQ_TYPE_EDGE_RISING);
285
286         platform_add_devices(voiceblue_devices, ARRAY_SIZE(voiceblue_devices));
287         omap_board_config = voiceblue_config;
288         omap_board_config_size = ARRAY_SIZE(voiceblue_config);
289         omap_serial_init();
290         omap1_usb_init(&voiceblue_usb_config);
291         omap_register_i2c_bus(1, 100, NULL, 0);
292
293         /* There is a good chance board is going up, so enable power LED
294          * (it is connected through invertor) */
295         omap_writeb(0x00, OMAP_LPG1_LCR);
296         omap_writeb(0x00, OMAP_LPG1_PMR);       /* Disable clock */
297
298         arch_reset = voiceblue_reset;
299 }
300
301 MACHINE_START(VOICEBLUE, "VoiceBlue OMAP5910")
302         /* Maintainer: Ladislav Michl <michl@2n.cz> */
303         .boot_params    = 0x10000100,
304         .map_io         = voiceblue_map_io,
305         .reserve        = omap_reserve,
306         .init_irq       = voiceblue_init_irq,
307         .init_machine   = voiceblue_init,
308         .timer          = &omap_timer,
309 MACHINE_END