Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/arm/mach-sa1100/assabet.c | |
3 | * | |
4 | * Author: Nicolas Pitre | |
5 | * | |
6 | * This file contains all Assabet-specific tweaks. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | */ | |
1da177e4 LT |
12 | #include <linux/init.h> |
13 | #include <linux/kernel.h> | |
14 | #include <linux/module.h> | |
15 | #include <linux/errno.h> | |
16 | #include <linux/ioport.h> | |
17 | #include <linux/serial_core.h> | |
18 | #include <linux/mtd/mtd.h> | |
19 | #include <linux/mtd/partitions.h> | |
20 | #include <linux/delay.h> | |
21 | #include <linux/mm.h> | |
22 | ||
a09e64fb | 23 | #include <mach/hardware.h> |
1da177e4 LT |
24 | #include <asm/mach-types.h> |
25 | #include <asm/irq.h> | |
26 | #include <asm/setup.h> | |
27 | #include <asm/page.h> | |
74945c86 | 28 | #include <asm/pgtable-hwdef.h> |
1da177e4 LT |
29 | #include <asm/pgtable.h> |
30 | #include <asm/tlbflush.h> | |
31 | ||
32 | #include <asm/mach/arch.h> | |
33 | #include <asm/mach/flash.h> | |
34 | #include <asm/mach/irda.h> | |
35 | #include <asm/mach/map.h> | |
36 | #include <asm/mach/serial_sa1100.h> | |
a09e64fb RK |
37 | #include <mach/assabet.h> |
38 | #include <mach/mcp.h> | |
1da177e4 LT |
39 | |
40 | #include "generic.h" | |
41 | ||
42 | #define ASSABET_BCR_DB1110 \ | |
7186fb9f | 43 | (ASSABET_BCR_SPK_OFF | \ |
1da177e4 LT |
44 | ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \ |
45 | ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \ | |
46 | ASSABET_BCR_IRDA_MD0) | |
47 | ||
48 | #define ASSABET_BCR_DB1111 \ | |
7186fb9f | 49 | (ASSABET_BCR_SPK_OFF | \ |
1da177e4 LT |
50 | ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \ |
51 | ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \ | |
52 | ASSABET_BCR_CF_BUS_OFF | ASSABET_BCR_STEREO_LB | \ | |
53 | ASSABET_BCR_IRDA_MD0 | ASSABET_BCR_CF_RST) | |
54 | ||
55 | unsigned long SCR_value = ASSABET_SCR_INIT; | |
56 | EXPORT_SYMBOL(SCR_value); | |
57 | ||
58 | static unsigned long BCR_value = ASSABET_BCR_DB1110; | |
59 | ||
60 | void ASSABET_BCR_frob(unsigned int mask, unsigned int val) | |
61 | { | |
62 | unsigned long flags; | |
63 | ||
64 | local_irq_save(flags); | |
65 | BCR_value = (BCR_value & ~mask) | val; | |
66 | ASSABET_BCR = BCR_value; | |
67 | local_irq_restore(flags); | |
68 | } | |
69 | ||
70 | EXPORT_SYMBOL(ASSABET_BCR_frob); | |
71 | ||
72 | static void assabet_backlight_power(int on) | |
73 | { | |
74 | #ifndef ASSABET_PAL_VIDEO | |
75 | if (on) | |
76 | ASSABET_BCR_set(ASSABET_BCR_LIGHT_ON); | |
77 | else | |
78 | #endif | |
79 | ASSABET_BCR_clear(ASSABET_BCR_LIGHT_ON); | |
80 | } | |
81 | ||
82 | /* | |
83 | * Turn on/off the backlight. When turning the backlight on, | |
84 | * we wait 500us after turning it on so we don't cause the | |
85 | * supplies to droop when we enable the LCD controller (and | |
86 | * cause a hard reset.) | |
87 | */ | |
88 | static void assabet_lcd_power(int on) | |
89 | { | |
90 | #ifndef ASSABET_PAL_VIDEO | |
91 | if (on) { | |
92 | ASSABET_BCR_set(ASSABET_BCR_LCD_ON); | |
93 | udelay(500); | |
94 | } else | |
95 | #endif | |
96 | ASSABET_BCR_clear(ASSABET_BCR_LCD_ON); | |
97 | } | |
98 | ||
99 | ||
100 | /* | |
101 | * Assabet flash support code. | |
102 | */ | |
103 | ||
104 | #ifdef ASSABET_REV_4 | |
105 | /* | |
106 | * Phase 4 Assabet has two 28F160B3 flash parts in bank 0: | |
107 | */ | |
108 | static struct mtd_partition assabet_partitions[] = { | |
109 | { | |
110 | .name = "bootloader", | |
111 | .size = 0x00020000, | |
112 | .offset = 0, | |
113 | .mask_flags = MTD_WRITEABLE, | |
114 | }, { | |
115 | .name = "bootloader params", | |
116 | .size = 0x00020000, | |
117 | .offset = MTDPART_OFS_APPEND, | |
118 | .mask_flags = MTD_WRITEABLE, | |
119 | }, { | |
120 | .name = "jffs", | |
121 | .size = MTDPART_SIZ_FULL, | |
122 | .offset = MTDPART_OFS_APPEND, | |
123 | } | |
124 | }; | |
125 | #else | |
126 | /* | |
127 | * Phase 5 Assabet has two 28F128J3A flash parts in bank 0: | |
128 | */ | |
129 | static struct mtd_partition assabet_partitions[] = { | |
130 | { | |
131 | .name = "bootloader", | |
132 | .size = 0x00040000, | |
133 | .offset = 0, | |
134 | .mask_flags = MTD_WRITEABLE, | |
135 | }, { | |
136 | .name = "bootloader params", | |
137 | .size = 0x00040000, | |
138 | .offset = MTDPART_OFS_APPEND, | |
139 | .mask_flags = MTD_WRITEABLE, | |
140 | }, { | |
141 | .name = "jffs", | |
142 | .size = MTDPART_SIZ_FULL, | |
143 | .offset = MTDPART_OFS_APPEND, | |
144 | } | |
145 | }; | |
146 | #endif | |
147 | ||
148 | static struct flash_platform_data assabet_flash_data = { | |
149 | .map_name = "cfi_probe", | |
150 | .parts = assabet_partitions, | |
151 | .nr_parts = ARRAY_SIZE(assabet_partitions), | |
152 | }; | |
153 | ||
154 | static struct resource assabet_flash_resources[] = { | |
a181099e RK |
155 | DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M), |
156 | DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_32M), | |
1da177e4 LT |
157 | }; |
158 | ||
159 | ||
160 | /* | |
161 | * Assabet IrDA support code. | |
162 | */ | |
163 | ||
164 | static int assabet_irda_set_power(struct device *dev, unsigned int state) | |
165 | { | |
166 | static unsigned int bcr_state[4] = { | |
167 | ASSABET_BCR_IRDA_MD0, | |
168 | ASSABET_BCR_IRDA_MD1|ASSABET_BCR_IRDA_MD0, | |
169 | ASSABET_BCR_IRDA_MD1, | |
170 | 0 | |
171 | }; | |
172 | ||
173 | if (state < 4) { | |
174 | state = bcr_state[state]; | |
175 | ASSABET_BCR_clear(state ^ (ASSABET_BCR_IRDA_MD1| | |
176 | ASSABET_BCR_IRDA_MD0)); | |
177 | ASSABET_BCR_set(state); | |
178 | } | |
179 | return 0; | |
180 | } | |
181 | ||
182 | static void assabet_irda_set_speed(struct device *dev, unsigned int speed) | |
183 | { | |
184 | if (speed < 4000000) | |
185 | ASSABET_BCR_clear(ASSABET_BCR_IRDA_FSEL); | |
186 | else | |
187 | ASSABET_BCR_set(ASSABET_BCR_IRDA_FSEL); | |
188 | } | |
189 | ||
190 | static struct irda_platform_data assabet_irda_data = { | |
191 | .set_power = assabet_irda_set_power, | |
192 | .set_speed = assabet_irda_set_speed, | |
193 | }; | |
194 | ||
323cdfc1 RK |
195 | static struct mcp_plat_data assabet_mcp_data = { |
196 | .mccr0 = MCCR0_ADM, | |
197 | .sclk_rate = 11981000, | |
198 | }; | |
199 | ||
1da177e4 LT |
200 | static void __init assabet_init(void) |
201 | { | |
202 | /* | |
203 | * Ensure that the power supply is in "high power" mode. | |
204 | */ | |
1da177e4 | 205 | GPSR = GPIO_GPIO16; |
4f592e6d | 206 | GPDR |= GPIO_GPIO16; |
1da177e4 LT |
207 | |
208 | /* | |
209 | * Ensure that these pins are set as outputs and are driving | |
210 | * logic 0. This ensures that we won't inadvertently toggle | |
211 | * the WS latch in the CPLD, and we don't float causing | |
212 | * excessive power drain. --rmk | |
213 | */ | |
1da177e4 | 214 | GPCR = GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM; |
4f592e6d | 215 | GPDR |= GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM; |
1da177e4 LT |
216 | |
217 | /* | |
218 | * Set up registers for sleep mode. | |
219 | */ | |
220 | PWER = PWER_GPIO0; | |
221 | PGSR = 0; | |
222 | PCFR = 0; | |
223 | PSDR = 0; | |
224 | PPDR |= PPC_TXD3 | PPC_TXD1; | |
225 | PPSR |= PPC_TXD3 | PPC_TXD1; | |
226 | ||
227 | sa1100fb_lcd_power = assabet_lcd_power; | |
228 | sa1100fb_backlight_power = assabet_backlight_power; | |
229 | ||
230 | if (machine_has_neponset()) { | |
231 | /* | |
232 | * Angel sets this, but other bootloaders may not. | |
233 | * | |
234 | * This must precede any driver calls to BCR_set() | |
235 | * or BCR_clear(). | |
236 | */ | |
237 | ASSABET_BCR = BCR_value = ASSABET_BCR_DB1111; | |
238 | ||
239 | #ifndef CONFIG_ASSABET_NEPONSET | |
240 | printk( "Warning: Neponset detected but full support " | |
241 | "hasn't been configured in the kernel\n" ); | |
242 | #endif | |
243 | } | |
244 | ||
7a5b4e16 RK |
245 | sa11x0_register_mtd(&assabet_flash_data, assabet_flash_resources, |
246 | ARRAY_SIZE(assabet_flash_resources)); | |
247 | sa11x0_register_irda(&assabet_irda_data); | |
248 | sa11x0_register_mcp(&assabet_mcp_data); | |
1da177e4 LT |
249 | } |
250 | ||
251 | /* | |
252 | * On Assabet, we must probe for the Neponset board _before_ | |
253 | * paging_init() has occurred to actually determine the amount | |
254 | * of RAM available. To do so, we map the appropriate IO section | |
255 | * in the page table here in order to access GPIO registers. | |
256 | */ | |
257 | static void __init map_sa1100_gpio_regs( void ) | |
258 | { | |
259 | unsigned long phys = __PREG(GPLR) & PMD_MASK; | |
260 | unsigned long virt = io_p2v(phys); | |
261 | int prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_DOMAIN(DOMAIN_IO); | |
262 | pmd_t *pmd; | |
263 | ||
a61c2332 | 264 | pmd = pmd_offset(pud_offset(pgd_offset_k(virt), virt), virt); |
1da177e4 LT |
265 | *pmd = __pmd(phys | prot); |
266 | flush_pmd_entry(pmd); | |
267 | } | |
268 | ||
269 | /* | |
270 | * Read System Configuration "Register" | |
271 | * (taken from "Intel StrongARM SA-1110 Microprocessor Development Board | |
272 | * User's Guide", section 4.4.1) | |
273 | * | |
274 | * This same scan is performed in arch/arm/boot/compressed/head-sa1100.S | |
275 | * to set up the serial port for decompression status messages. We | |
276 | * repeat it here because the kernel may not be loaded as a zImage, and | |
277 | * also because it's a hassle to communicate the SCR value to the kernel | |
278 | * from the decompressor. | |
279 | * | |
280 | * Note that IRQs are guaranteed to be disabled. | |
281 | */ | |
282 | static void __init get_assabet_scr(void) | |
283 | { | |
284 | unsigned long scr, i; | |
285 | ||
286 | GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */ | |
287 | GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */ | |
288 | GPDR &= ~(0x3fc); /* Configure GPIO 9:2 as inputs */ | |
2f3eca8b RK |
289 | for(i = 100; i--; ) /* Read GPIO 9:2 */ |
290 | scr = GPLR; | |
1da177e4 LT |
291 | GPDR |= 0x3fc; /* restore correct pin direction */ |
292 | scr &= 0x3fc; /* save as system configuration byte. */ | |
293 | SCR_value = scr; | |
294 | } | |
295 | ||
296 | static void __init | |
0744a3ee | 297 | fixup_assabet(struct tag *tags, char **cmdline, struct meminfo *mi) |
1da177e4 LT |
298 | { |
299 | /* This must be done before any call to machine_has_neponset() */ | |
300 | map_sa1100_gpio_regs(); | |
301 | get_assabet_scr(); | |
302 | ||
303 | if (machine_has_neponset()) | |
304 | printk("Neponset expansion board detected\n"); | |
305 | } | |
306 | ||
307 | ||
308 | static void assabet_uart_pm(struct uart_port *port, u_int state, u_int oldstate) | |
309 | { | |
310 | if (port->mapbase == _Ser1UTCR0) { | |
311 | if (state) | |
312 | ASSABET_BCR_clear(ASSABET_BCR_RS232EN | | |
313 | ASSABET_BCR_COM_RTS | | |
314 | ASSABET_BCR_COM_DTR); | |
315 | else | |
316 | ASSABET_BCR_set(ASSABET_BCR_RS232EN | | |
317 | ASSABET_BCR_COM_RTS | | |
318 | ASSABET_BCR_COM_DTR); | |
319 | } | |
320 | } | |
321 | ||
322 | /* | |
323 | * Assabet uses COM_RTS and COM_DTR for both UART1 (com port) | |
324 | * and UART3 (radio module). We only handle them for UART1 here. | |
325 | */ | |
326 | static void assabet_set_mctrl(struct uart_port *port, u_int mctrl) | |
327 | { | |
328 | if (port->mapbase == _Ser1UTCR0) { | |
329 | u_int set = 0, clear = 0; | |
330 | ||
331 | if (mctrl & TIOCM_RTS) | |
332 | clear |= ASSABET_BCR_COM_RTS; | |
333 | else | |
334 | set |= ASSABET_BCR_COM_RTS; | |
335 | ||
336 | if (mctrl & TIOCM_DTR) | |
337 | clear |= ASSABET_BCR_COM_DTR; | |
338 | else | |
339 | set |= ASSABET_BCR_COM_DTR; | |
340 | ||
341 | ASSABET_BCR_clear(clear); | |
342 | ASSABET_BCR_set(set); | |
343 | } | |
344 | } | |
345 | ||
346 | static u_int assabet_get_mctrl(struct uart_port *port) | |
347 | { | |
348 | u_int ret = 0; | |
349 | u_int bsr = ASSABET_BSR; | |
350 | ||
351 | /* need 2 reads to read current value */ | |
352 | bsr = ASSABET_BSR; | |
353 | ||
354 | if (port->mapbase == _Ser1UTCR0) { | |
355 | if (bsr & ASSABET_BSR_COM_DCD) | |
356 | ret |= TIOCM_CD; | |
357 | if (bsr & ASSABET_BSR_COM_CTS) | |
358 | ret |= TIOCM_CTS; | |
359 | if (bsr & ASSABET_BSR_COM_DSR) | |
360 | ret |= TIOCM_DSR; | |
361 | } else if (port->mapbase == _Ser3UTCR0) { | |
362 | if (bsr & ASSABET_BSR_RAD_DCD) | |
363 | ret |= TIOCM_CD; | |
364 | if (bsr & ASSABET_BSR_RAD_CTS) | |
365 | ret |= TIOCM_CTS; | |
366 | if (bsr & ASSABET_BSR_RAD_DSR) | |
367 | ret |= TIOCM_DSR; | |
368 | if (bsr & ASSABET_BSR_RAD_RI) | |
369 | ret |= TIOCM_RI; | |
370 | } else { | |
371 | ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR; | |
372 | } | |
373 | ||
374 | return ret; | |
375 | } | |
376 | ||
377 | static struct sa1100_port_fns assabet_port_fns __initdata = { | |
378 | .set_mctrl = assabet_set_mctrl, | |
379 | .get_mctrl = assabet_get_mctrl, | |
380 | .pm = assabet_uart_pm, | |
381 | }; | |
382 | ||
383 | static struct map_desc assabet_io_desc[] __initdata = { | |
92519d82 DS |
384 | { /* Board Control Register */ |
385 | .virtual = 0xf1000000, | |
386 | .pfn = __phys_to_pfn(0x12000000), | |
387 | .length = 0x00100000, | |
388 | .type = MT_DEVICE | |
389 | }, { /* MQ200 */ | |
390 | .virtual = 0xf2800000, | |
391 | .pfn = __phys_to_pfn(0x4b800000), | |
392 | .length = 0x00800000, | |
393 | .type = MT_DEVICE | |
394 | } | |
1da177e4 LT |
395 | }; |
396 | ||
397 | static void __init assabet_map_io(void) | |
398 | { | |
399 | sa1100_map_io(); | |
400 | iotable_init(assabet_io_desc, ARRAY_SIZE(assabet_io_desc)); | |
401 | ||
402 | /* | |
403 | * Set SUS bit in SDCR0 so serial port 1 functions. | |
404 | * Its called GPCLKR0 in my SA1110 manual. | |
405 | */ | |
406 | Ser1SDCR0 |= SDCR0_SUS; | |
407 | ||
408 | if (machine_has_neponset()) { | |
409 | #ifdef CONFIG_ASSABET_NEPONSET | |
410 | extern void neponset_map_io(void); | |
411 | ||
412 | /* | |
413 | * We map Neponset registers even if it isn't present since | |
414 | * many drivers will try to probe their stuff (and fail). | |
415 | * This is still more friendly than a kernel paging request | |
416 | * crash. | |
417 | */ | |
418 | neponset_map_io(); | |
419 | #endif | |
420 | } else { | |
421 | sa1100_register_uart_fns(&assabet_port_fns); | |
422 | } | |
423 | ||
424 | /* | |
425 | * When Neponset is attached, the first UART should be | |
426 | * UART3. That's what Angel is doing and many documents | |
427 | * are stating this. | |
428 | * | |
429 | * We do the Neponset mapping even if Neponset support | |
430 | * isn't compiled in so the user will still get something on | |
431 | * the expected physical serial port. | |
432 | * | |
433 | * We no longer do this; not all boot loaders support it, | |
434 | * and UART3 appears to be somewhat unreliable with blob. | |
435 | */ | |
436 | sa1100_register_uart(0, 1); | |
437 | sa1100_register_uart(2, 3); | |
438 | } | |
439 | ||
440 | ||
441 | MACHINE_START(ASSABET, "Intel-Assabet") | |
17f4425d | 442 | .atag_offset = 0x100, |
e9dea0c6 RK |
443 | .fixup = fixup_assabet, |
444 | .map_io = assabet_map_io, | |
445 | .init_irq = sa1100_init_irq, | |
1da177e4 LT |
446 | .timer = &sa1100_timer, |
447 | .init_machine = assabet_init, | |
e9107ab6 NP |
448 | #ifdef CONFIG_SA1111 |
449 | .dma_zone_size = SZ_1M, | |
450 | #endif | |
d9ca5839 | 451 | .restart = sa11x0_restart, |
1da177e4 | 452 | MACHINE_END |