[PATCH] IB: Update FMR functions
[linux-2.6] / 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/device.h>
17 #include <linux/interrupt.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/notifier.h>
21 #include <linux/reboot.h>
22 #include <linux/serial_8250.h>
23 #include <linux/serial_reg.h>
24
25 #include <asm/hardware.h>
26 #include <asm/mach-types.h>
27 #include <asm/mach/arch.h>
28 #include <asm/mach/map.h>
29
30 #include <asm/arch/gpio.h>
31 #include <asm/arch/tc.h>
32 #include <asm/arch/mux.h>
33 #include <asm/arch/usb.h>
34 #include <asm/arch/common.h>
35
36 extern void omap_init_time(void);
37 extern int omap_gpio_init(void);
38
39 static struct plat_serial8250_port voiceblue_ports[] = {
40         {
41                 .mapbase        = (unsigned long)(OMAP_CS1_PHYS + 0x40000),
42                 .irq            = OMAP_GPIO_IRQ(12),
43                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
44                 .iotype         = UPIO_MEM,
45                 .regshift       = 1,
46                 .uartclk        = 3686400,
47         },
48         {
49                 .mapbase        = (unsigned long)(OMAP_CS1_PHYS + 0x50000),
50                 .irq            = OMAP_GPIO_IRQ(13),
51                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
52                 .iotype         = UPIO_MEM,
53                 .regshift       = 1,
54                 .uartclk        = 3686400,
55         },
56         {
57                 .mapbase        = (unsigned long)(OMAP_CS1_PHYS + 0x60000),
58                 .irq            = OMAP_GPIO_IRQ(14),
59                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
60                 .iotype         = UPIO_MEM,
61                 .regshift       = 1,
62                 .uartclk        = 3686400,
63         },
64         {
65                 .mapbase        = (unsigned long)(OMAP_CS1_PHYS + 0x70000),
66                 .irq            = OMAP_GPIO_IRQ(15),
67                 .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
68                 .iotype         = UPIO_MEM,
69                 .regshift       = 1,
70                 .uartclk        = 3686400,
71         },
72         { },
73 };
74
75 static struct platform_device serial_device = {
76         .name                   = "serial8250",
77         .id                     = 1,
78         .dev                    = {
79                 .platform_data  = voiceblue_ports,
80         },
81 };
82
83 static int __init ext_uart_init(void)
84 {
85         return platform_device_register(&serial_device);
86 }
87 arch_initcall(ext_uart_init);
88
89 static struct resource voiceblue_smc91x_resources[] = {
90         [0] = {
91                 .start  = OMAP_CS2_PHYS + 0x300,
92                 .end    = OMAP_CS2_PHYS + 0x300 + 16,
93                 .flags  = IORESOURCE_MEM,
94         },
95         [1] = {
96                 .start  = OMAP_GPIO_IRQ(8),
97                 .end    = OMAP_GPIO_IRQ(8),
98                 .flags  = IORESOURCE_IRQ,
99         },
100 };
101
102 static struct platform_device voiceblue_smc91x_device = {
103         .name           = "smc91x",
104         .id             = 0,
105         .num_resources  = ARRAY_SIZE(voiceblue_smc91x_resources),
106         .resource       = voiceblue_smc91x_resources,
107 };
108
109 static struct platform_device *voiceblue_devices[] __initdata = {
110         &voiceblue_smc91x_device,
111 };
112
113 static struct omap_usb_config voiceblue_usb_config __initdata = {
114         .hmc_mode       = 3,
115         .register_host  = 1,
116         .register_dev   = 1,
117         .pins[0]        = 2,
118         .pins[1]        = 6,
119         .pins[2]        = 6,
120 };
121
122 static struct omap_board_config_kernel voiceblue_config[] = {
123         { OMAP_TAG_USB, &voiceblue_usb_config },
124 };
125
126 static void __init voiceblue_init_irq(void)
127 {
128         omap_init_irq();
129         omap_gpio_init();
130 }
131
132 static void __init voiceblue_init(void)
133 {
134         /* There is a good chance board is going up, so enable Power LED
135          * (it is connected through invertor) */
136         omap_writeb(0x00, OMAP_LPG1_LCR);
137         /* Watchdog */
138         omap_request_gpio(0);
139         /* smc91x reset */
140         omap_request_gpio(7);
141         omap_set_gpio_direction(7, 0);
142         omap_set_gpio_dataout(7, 1);
143         udelay(2);      /* wait at least 100ns */
144         omap_set_gpio_dataout(7, 0);
145         mdelay(50);     /* 50ms until PHY ready */
146         /* smc91x interrupt pin */
147         omap_request_gpio(8);
148         omap_set_gpio_edge_ctrl(8, OMAP_GPIO_RISING_EDGE);
149         /* 16C554 reset*/
150         omap_request_gpio(6);
151         omap_set_gpio_direction(6, 0);
152         omap_set_gpio_dataout(6, 0);
153         /* 16C554 interrupt pins */
154         omap_request_gpio(12);
155         omap_request_gpio(13);
156         omap_request_gpio(14);
157         omap_request_gpio(15);
158         omap_set_gpio_edge_ctrl(12, OMAP_GPIO_RISING_EDGE);
159         omap_set_gpio_edge_ctrl(13, OMAP_GPIO_RISING_EDGE);
160         omap_set_gpio_edge_ctrl(14, OMAP_GPIO_RISING_EDGE);
161         omap_set_gpio_edge_ctrl(15, OMAP_GPIO_RISING_EDGE);
162
163         platform_add_devices(voiceblue_devices, ARRAY_SIZE(voiceblue_devices));
164         omap_board_config = voiceblue_config;
165         omap_board_config_size = ARRAY_SIZE(voiceblue_config);
166 }
167
168 static int __initdata omap_serial_ports[OMAP_MAX_NR_PORTS] = {1, 1, 1};
169
170 static void __init voiceblue_map_io(void)
171 {
172         omap_map_common_io();
173         omap_serial_init(omap_serial_ports);
174 }
175
176 #define MACHINE_PANICED         1
177 #define MACHINE_REBOOTING       2
178 #define MACHINE_REBOOT          4
179 static unsigned long machine_state;
180
181 static int panic_event(struct notifier_block *this, unsigned long event,
182          void *ptr)
183 {
184         if (test_and_set_bit(MACHINE_PANICED, &machine_state))
185                 return NOTIFY_DONE;
186
187         /* Flash Power LED
188          * (TODO: Enable clock right way (enabled in bootloader already)) */
189         omap_writeb(0x78, OMAP_LPG1_LCR);
190
191         return NOTIFY_DONE;
192 }
193
194 static struct notifier_block panic_block = {
195         .notifier_call  = panic_event,
196 };
197
198 static int __init setup_notifier(void)
199 {
200         /* Setup panic notifier */
201         notifier_chain_register(&panic_notifier_list, &panic_block);
202
203         return 0;
204 }
205
206 postcore_initcall(setup_notifier);
207
208 static int wdt_gpio_state;
209
210 void voiceblue_wdt_enable(void)
211 {
212         omap_set_gpio_direction(0, 0);
213         omap_set_gpio_dataout(0, 0);
214         omap_set_gpio_dataout(0, 1);
215         omap_set_gpio_dataout(0, 0);
216         wdt_gpio_state = 0;
217 }
218
219 void voiceblue_wdt_disable(void)
220 {
221         omap_set_gpio_dataout(0, 0);
222         omap_set_gpio_dataout(0, 1);
223         omap_set_gpio_dataout(0, 0);
224         omap_set_gpio_direction(0, 1);
225 }
226
227 void voiceblue_wdt_ping(void)
228 {
229         if (test_bit(MACHINE_REBOOT, &machine_state))
230                 return;
231
232         wdt_gpio_state = !wdt_gpio_state;
233         omap_set_gpio_dataout(0, wdt_gpio_state);
234 }
235
236 void voiceblue_reset(void)
237 {
238         set_bit(MACHINE_REBOOT, &machine_state);
239         voiceblue_wdt_enable();
240         while (1) ;
241 }
242
243 EXPORT_SYMBOL(voiceblue_wdt_enable);
244 EXPORT_SYMBOL(voiceblue_wdt_disable);
245 EXPORT_SYMBOL(voiceblue_wdt_ping);
246
247 MACHINE_START(VOICEBLUE, "VoiceBlue OMAP5910")
248         /* Maintainer: Ladislav Michl <michl@2n.cz> */
249         .phys_ram       = 0x10000000,
250         .phys_io        = 0xfff00000,
251         .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
252         .boot_params    = 0x10000100,
253         .map_io         = voiceblue_map_io,
254         .init_irq       = voiceblue_init_irq,
255         .init_machine   = voiceblue_init,
256         .timer          = &omap_timer,
257 MACHINE_END