Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/arm/mach-sa1100/badge4.c | |
3 | * | |
4 | * BadgePAD 4 specific initialization | |
5 | * | |
6 | * Tim Connors <connors@hpl.hp.com> | |
7 | * Christopher Hoover <ch@hpl.hp.com> | |
8 | * | |
9 | * Copyright (C) 2002 Hewlett-Packard Company | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License version 2 as | |
13 | * published by the Free Software Foundation. | |
14 | * | |
15 | */ | |
16 | #include <linux/module.h> | |
17 | #include <linux/init.h> | |
18 | #include <linux/kernel.h> | |
6920b5a7 | 19 | #include <linux/platform_data/sa11x0-serial.h> |
d052d1be | 20 | #include <linux/platform_device.h> |
1da177e4 LT |
21 | #include <linux/delay.h> |
22 | #include <linux/tty.h> | |
23 | #include <linux/mtd/mtd.h> | |
24 | #include <linux/mtd/partitions.h> | |
25 | #include <linux/errno.h> | |
18775a7b BW |
26 | #include <linux/gpio.h> |
27 | #include <linux/leds.h> | |
1da177e4 | 28 | |
a09e64fb | 29 | #include <mach/hardware.h> |
1da177e4 LT |
30 | #include <asm/mach-types.h> |
31 | #include <asm/setup.h> | |
a09e64fb | 32 | #include <mach/irqs.h> |
1da177e4 LT |
33 | |
34 | #include <asm/mach/arch.h> | |
35 | #include <asm/mach/flash.h> | |
36 | #include <asm/mach/map.h> | |
37 | #include <asm/hardware/sa1111.h> | |
1da177e4 | 38 | |
a09e64fb | 39 | #include <mach/badge4.h> |
1da177e4 LT |
40 | |
41 | #include "generic.h" | |
42 | ||
43 | static struct resource sa1111_resources[] = { | |
a181099e RK |
44 | [0] = DEFINE_RES_MEM(BADGE4_SA1111_BASE, 0x2000), |
45 | [1] = DEFINE_RES_IRQ(BADGE4_IRQ_GPIO_SA1111), | |
1da177e4 LT |
46 | }; |
47 | ||
3259701c RK |
48 | static int badge4_sa1111_enable(void *data, unsigned devid) |
49 | { | |
50 | if (devid == SA1111_DEVID_USB) | |
51 | badge4_set_5V(BADGE4_5V_USB, 1); | |
52 | return 0; | |
53 | } | |
54 | ||
55 | static void badge4_sa1111_disable(void *data, unsigned devid) | |
56 | { | |
57 | if (devid == SA1111_DEVID_USB) | |
58 | badge4_set_5V(BADGE4_5V_USB, 0); | |
59 | } | |
60 | ||
19851c58 | 61 | static struct sa1111_platform_data sa1111_info = { |
07be45f5 | 62 | .disable_devs = SA1111_DEVID_PS2_MSE, |
3259701c RK |
63 | .enable = badge4_sa1111_enable, |
64 | .disable = badge4_sa1111_disable, | |
19851c58 EM |
65 | }; |
66 | ||
1da177e4 LT |
67 | static u64 sa1111_dmamask = 0xffffffffUL; |
68 | ||
69 | static struct platform_device sa1111_device = { | |
70 | .name = "sa1111", | |
71 | .id = 0, | |
72 | .dev = { | |
73 | .dma_mask = &sa1111_dmamask, | |
74 | .coherent_dma_mask = 0xffffffff, | |
19851c58 | 75 | .platform_data = &sa1111_info, |
1da177e4 LT |
76 | }, |
77 | .num_resources = ARRAY_SIZE(sa1111_resources), | |
78 | .resource = sa1111_resources, | |
79 | }; | |
80 | ||
18775a7b BW |
81 | /* LEDs */ |
82 | struct gpio_led badge4_gpio_leds[] = { | |
83 | { | |
84 | .name = "badge4:red", | |
85 | .default_trigger = "heartbeat", | |
86 | .gpio = 7, | |
87 | }, | |
88 | { | |
89 | .name = "badge4:green", | |
90 | .default_trigger = "cpu0", | |
91 | .gpio = 9, | |
92 | }, | |
93 | }; | |
94 | ||
95 | static struct gpio_led_platform_data badge4_gpio_led_info = { | |
96 | .leds = badge4_gpio_leds, | |
97 | .num_leds = ARRAY_SIZE(badge4_gpio_leds), | |
98 | }; | |
99 | ||
100 | static struct platform_device badge4_leds = { | |
101 | .name = "leds-gpio", | |
102 | .id = -1, | |
103 | .dev = { | |
104 | .platform_data = &badge4_gpio_led_info, | |
105 | } | |
106 | }; | |
107 | ||
1da177e4 LT |
108 | static struct platform_device *devices[] __initdata = { |
109 | &sa1111_device, | |
18775a7b | 110 | &badge4_leds, |
1da177e4 LT |
111 | }; |
112 | ||
113 | static int __init badge4_sa1111_init(void) | |
114 | { | |
115 | /* | |
116 | * Ensure that the memory bus request/grant signals are setup, | |
117 | * and the grant is held in its inactive state | |
118 | */ | |
119 | sa1110_mb_disable(); | |
120 | ||
121 | /* | |
122 | * Probe for SA1111. | |
123 | */ | |
124 | return platform_add_devices(devices, ARRAY_SIZE(devices)); | |
125 | } | |
126 | ||
127 | ||
128 | /* | |
129 | * 1 x Intel 28F320C3 Advanced+ Boot Block Flash (32 Mi bit) | |
130 | * Eight 4 KiW Parameter Bottom Blocks (64 KiB) | |
131 | * Sixty-three 32 KiW Main Blocks (4032 Ki b) | |
132 | * | |
133 | * <or> | |
134 | * | |
135 | * 1 x Intel 28F640C3 Advanced+ Boot Block Flash (64 Mi bit) | |
136 | * Eight 4 KiW Parameter Bottom Blocks (64 KiB) | |
137 | * One-hundred-twenty-seven 32 KiW Main Blocks (8128 Ki b) | |
138 | */ | |
139 | static struct mtd_partition badge4_partitions[] = { | |
bda03086 KE |
140 | { |
141 | .name = "BLOB boot loader", | |
142 | .offset = 0, | |
143 | .size = 0x0000A000 | |
144 | }, { | |
145 | .name = "params", | |
146 | .offset = MTDPART_OFS_APPEND, | |
147 | .size = 0x00006000 | |
148 | }, { | |
149 | .name = "root", | |
150 | .offset = MTDPART_OFS_APPEND, | |
151 | .size = MTDPART_SIZ_FULL | |
152 | } | |
1da177e4 LT |
153 | }; |
154 | ||
155 | static struct flash_platform_data badge4_flash_data = { | |
156 | .map_name = "cfi_probe", | |
157 | .parts = badge4_partitions, | |
158 | .nr_parts = ARRAY_SIZE(badge4_partitions), | |
159 | }; | |
160 | ||
a181099e RK |
161 | static struct resource badge4_flash_resource = |
162 | DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_64M); | |
1da177e4 LT |
163 | |
164 | static int five_v_on __initdata = 0; | |
165 | ||
166 | static int __init five_v_on_setup(char *ignore) | |
167 | { | |
bda03086 | 168 | five_v_on = 1; |
1da177e4 LT |
169 | return 1; |
170 | } | |
171 | __setup("five_v_on", five_v_on_setup); | |
172 | ||
173 | ||
174 | static int __init badge4_init(void) | |
175 | { | |
176 | int ret; | |
177 | ||
178 | if (!machine_is_badge4()) | |
179 | return -ENODEV; | |
180 | ||
181 | /* LCD */ | |
182 | GPCR = (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 | | |
183 | BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 | | |
184 | BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 | | |
185 | BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 | | |
186 | BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID | | |
187 | BADGE4_GPIO_GPC_VID); | |
188 | GPDR &= ~BADGE4_GPIO_INT_VID; | |
189 | GPDR |= (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 | | |
190 | BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 | | |
191 | BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 | | |
192 | BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 | | |
193 | BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID | | |
194 | BADGE4_GPIO_GPC_VID); | |
195 | ||
196 | /* SDRAM SPD i2c */ | |
197 | GPCR = (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL); | |
198 | GPDR |= (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL); | |
199 | ||
200 | /* uart */ | |
201 | GPCR = (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2); | |
202 | GPDR |= (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2); | |
203 | ||
204 | /* CPLD muxsel0 input for mux/adc chip select */ | |
205 | GPCR = BADGE4_GPIO_MUXSEL0; | |
206 | GPDR |= BADGE4_GPIO_MUXSEL0; | |
207 | ||
208 | /* test points: J5, J6 as inputs, J7 outputs */ | |
209 | GPDR &= ~(BADGE4_GPIO_TESTPT_J5 | BADGE4_GPIO_TESTPT_J6); | |
210 | GPCR = BADGE4_GPIO_TESTPT_J7; | |
211 | GPDR |= BADGE4_GPIO_TESTPT_J7; | |
212 | ||
bda03086 KE |
213 | /* 5V supply rail. */ |
214 | GPCR = BADGE4_GPIO_PCMEN5V; /* initially off */ | |
215 | GPDR |= BADGE4_GPIO_PCMEN5V; | |
1da177e4 LT |
216 | |
217 | /* CPLD sdram type inputs; set up by blob */ | |
218 | //GPDR |= (BADGE4_GPIO_SDTYP1 | BADGE4_GPIO_SDTYP0); | |
219 | printk(KERN_DEBUG __FILE__ ": SDRAM CPLD typ1=%d typ0=%d\n", | |
bda03086 KE |
220 | !!(GPLR & BADGE4_GPIO_SDTYP1), |
221 | !!(GPLR & BADGE4_GPIO_SDTYP0)); | |
1da177e4 LT |
222 | |
223 | /* SA1111 reset pin; set up by blob */ | |
224 | //GPSR = BADGE4_GPIO_SA1111_NRST; | |
225 | //GPDR |= BADGE4_GPIO_SA1111_NRST; | |
226 | ||
227 | ||
228 | /* power management cruft */ | |
229 | PGSR = 0; | |
230 | PWER = 0; | |
231 | PCFR = 0; | |
232 | PSDR = 0; | |
233 | ||
234 | PWER |= PWER_GPIO26; /* wake up on an edge from TESTPT_J5 */ | |
235 | PWER |= PWER_RTC; /* wake up if rtc fires */ | |
236 | ||
237 | /* drive sa1111_nrst during sleep */ | |
238 | PGSR |= BADGE4_GPIO_SA1111_NRST; | |
239 | /* drive CPLD as is during sleep */ | |
240 | PGSR |= (GPLR & (BADGE4_GPIO_SDTYP0|BADGE4_GPIO_SDTYP1)); | |
241 | ||
242 | ||
243 | /* Now bring up the SA-1111. */ | |
244 | ret = badge4_sa1111_init(); | |
245 | if (ret < 0) | |
246 | printk(KERN_ERR | |
bda03086 KE |
247 | "%s: SA-1111 initialization failed (%d)\n", |
248 | __func__, ret); | |
1da177e4 LT |
249 | |
250 | ||
251 | /* maybe turn on 5v0 from the start */ | |
252 | badge4_set_5V(BADGE4_5V_INITIALLY, five_v_on); | |
253 | ||
7a5b4e16 | 254 | sa11x0_register_mtd(&badge4_flash_data, &badge4_flash_resource, 1); |
1da177e4 LT |
255 | |
256 | return 0; | |
257 | } | |
258 | ||
259 | arch_initcall(badge4_init); | |
260 | ||
261 | ||
262 | static unsigned badge4_5V_bitmap = 0; | |
263 | ||
264 | void badge4_set_5V(unsigned subsystem, int on) | |
265 | { | |
266 | unsigned long flags; | |
267 | unsigned old_5V_bitmap; | |
268 | ||
269 | local_irq_save(flags); | |
270 | ||
271 | old_5V_bitmap = badge4_5V_bitmap; | |
272 | ||
273 | if (on) { | |
274 | badge4_5V_bitmap |= subsystem; | |
275 | } else { | |
276 | badge4_5V_bitmap &= ~subsystem; | |
277 | } | |
278 | ||
279 | /* detect on->off and off->on transitions */ | |
280 | if ((!old_5V_bitmap) && (badge4_5V_bitmap)) { | |
281 | /* was off, now on */ | |
8e86f427 | 282 | printk(KERN_INFO "%s: enabling 5V supply rail\n", __func__); |
1da177e4 LT |
283 | GPSR = BADGE4_GPIO_PCMEN5V; |
284 | } else if ((old_5V_bitmap) && (!badge4_5V_bitmap)) { | |
285 | /* was on, now off */ | |
8e86f427 | 286 | printk(KERN_INFO "%s: disabling 5V supply rail\n", __func__); |
1da177e4 LT |
287 | GPCR = BADGE4_GPIO_PCMEN5V; |
288 | } | |
289 | ||
290 | local_irq_restore(flags); | |
291 | } | |
292 | EXPORT_SYMBOL(badge4_set_5V); | |
293 | ||
294 | ||
295 | static struct map_desc badge4_io_desc[] __initdata = { | |
bda03086 | 296 | { /* SRAM bank 1 */ |
92519d82 DS |
297 | .virtual = 0xf1000000, |
298 | .pfn = __phys_to_pfn(0x08000000), | |
299 | .length = 0x00100000, | |
300 | .type = MT_DEVICE | |
301 | }, { /* SRAM bank 2 */ | |
302 | .virtual = 0xf2000000, | |
303 | .pfn = __phys_to_pfn(0x10000000), | |
304 | .length = 0x00100000, | |
305 | .type = MT_DEVICE | |
92519d82 | 306 | } |
1da177e4 LT |
307 | }; |
308 | ||
309 | static void | |
310 | badge4_uart_pm(struct uart_port *port, u_int state, u_int oldstate) | |
311 | { | |
312 | if (!state) { | |
313 | Ser1SDCR0 |= SDCR0_UART; | |
314 | } | |
315 | } | |
316 | ||
317 | static struct sa1100_port_fns badge4_port_fns __initdata = { | |
318 | //.get_mctrl = badge4_get_mctrl, | |
319 | //.set_mctrl = badge4_set_mctrl, | |
320 | .pm = badge4_uart_pm, | |
321 | }; | |
322 | ||
323 | static void __init badge4_map_io(void) | |
324 | { | |
325 | sa1100_map_io(); | |
326 | iotable_init(badge4_io_desc, ARRAY_SIZE(badge4_io_desc)); | |
327 | ||
328 | sa1100_register_uart_fns(&badge4_port_fns); | |
329 | sa1100_register_uart(0, 3); | |
330 | sa1100_register_uart(1, 1); | |
331 | } | |
332 | ||
333 | MACHINE_START(BADGE4, "Hewlett-Packard Laboratories BadgePAD 4") | |
17f4425d | 334 | .atag_offset = 0x100, |
e9dea0c6 | 335 | .map_io = badge4_map_io, |
f314f33b | 336 | .nr_irqs = SA1100_NR_IRQS, |
e9dea0c6 | 337 | .init_irq = sa1100_init_irq, |
7fea1ba5 | 338 | .init_late = sa11x0_init_late, |
1da177e4 | 339 | .timer = &sa1100_timer, |
e9107ab6 NP |
340 | #ifdef CONFIG_SA1111 |
341 | .dma_zone_size = SZ_1M, | |
342 | #endif | |
d9ca5839 | 343 | .restart = sa11x0_restart, |
1da177e4 | 344 | MACHINE_END |