blob: f2030bc22cde06f1a9afdeba9b81ef953389aee3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#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
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/mach-types.h>
25#include <asm/irq.h>
26#include <asm/setup.h>
27#include <asm/page.h>
Russell King74945c82006-03-16 14:44:36 +000028#include <asm/pgtable-hwdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#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>
Russell Kinga09e64f2008-08-05 16:14:15 +010037#include <mach/assabet.h>
38#include <mach/mcp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include "generic.h"
41
42#define ASSABET_BCR_DB1110 \
Russell King7186fb92012-01-21 21:17:06 +000043 (ASSABET_BCR_SPK_OFF | \
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 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 \
Russell King7186fb92012-01-21 21:17:06 +000049 (ASSABET_BCR_SPK_OFF | \
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 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
55unsigned long SCR_value = ASSABET_SCR_INIT;
56EXPORT_SYMBOL(SCR_value);
57
58static unsigned long BCR_value = ASSABET_BCR_DB1110;
59
60void 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
70EXPORT_SYMBOL(ASSABET_BCR_frob);
71
72static 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 */
88static 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 */
108static 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 */
129static 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
148static 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
154static struct resource assabet_flash_resources[] = {
Russell Kinga1810992012-01-12 10:25:29 +0000155 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M),
156 DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_32M),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157};
158
159
160/*
161 * Assabet IrDA support code.
162 */
163
164static 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
182static 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
190static struct irda_platform_data assabet_irda_data = {
191 .set_power = assabet_irda_set_power,
192 .set_speed = assabet_irda_set_speed,
193};
194
Russell King323cdfc2005-08-18 10:10:46 +0100195static struct mcp_plat_data assabet_mcp_data = {
196 .mccr0 = MCCR0_ADM,
197 .sclk_rate = 11981000,
198};
199
Russell Kingbab50a32012-01-26 11:50:23 +0000200#ifdef CONFIG_ASSABET_NEPONSET
201static struct resource neponset_resources[] = {
202 DEFINE_RES_MEM(0x10000000, 0x08000000),
203 DEFINE_RES_MEM(0x18000000, 0x04000000),
204 DEFINE_RES_MEM(0x40000000, SZ_8K),
205 DEFINE_RES_IRQ(IRQ_GPIO25),
206};
207#endif
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static void __init assabet_init(void)
210{
211 /*
212 * Ensure that the power supply is in "high power" mode.
213 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 GPSR = GPIO_GPIO16;
Russell King4f592e62012-01-24 09:23:19 +0000215 GPDR |= GPIO_GPIO16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 /*
218 * Ensure that these pins are set as outputs and are driving
219 * logic 0. This ensures that we won't inadvertently toggle
220 * the WS latch in the CPLD, and we don't float causing
221 * excessive power drain. --rmk
222 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 GPCR = GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
Russell King4f592e62012-01-24 09:23:19 +0000224 GPDR |= GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 /*
Russell King49e01e32012-01-24 09:25:57 +0000227 * Also set GPIO27 as an output; this is used to clock UART3
228 * via the FPGA and as otherwise has no pullups or pulldowns,
229 * so stop it floating.
230 */
231 GPCR = GPIO_GPIO27;
232 GPDR |= GPIO_GPIO27;
233
234 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 * Set up registers for sleep mode.
236 */
237 PWER = PWER_GPIO0;
238 PGSR = 0;
239 PCFR = 0;
240 PSDR = 0;
241 PPDR |= PPC_TXD3 | PPC_TXD1;
242 PPSR |= PPC_TXD3 | PPC_TXD1;
243
244 sa1100fb_lcd_power = assabet_lcd_power;
245 sa1100fb_backlight_power = assabet_backlight_power;
246
247 if (machine_has_neponset()) {
248 /*
249 * Angel sets this, but other bootloaders may not.
250 *
251 * This must precede any driver calls to BCR_set()
252 * or BCR_clear().
253 */
254 ASSABET_BCR = BCR_value = ASSABET_BCR_DB1111;
255
256#ifndef CONFIG_ASSABET_NEPONSET
257 printk( "Warning: Neponset detected but full support "
258 "hasn't been configured in the kernel\n" );
Russell Kingbab50a32012-01-26 11:50:23 +0000259#else
260 platform_device_register_simple("neponset", 0,
261 neponset_resources, ARRAY_SIZE(neponset_resources));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#endif
263 }
264
Russell King7a5b4e12009-10-06 14:55:53 +0100265 sa11x0_register_mtd(&assabet_flash_data, assabet_flash_resources,
266 ARRAY_SIZE(assabet_flash_resources));
267 sa11x0_register_irda(&assabet_irda_data);
268 sa11x0_register_mcp(&assabet_mcp_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
271/*
272 * On Assabet, we must probe for the Neponset board _before_
273 * paging_init() has occurred to actually determine the amount
274 * of RAM available. To do so, we map the appropriate IO section
275 * in the page table here in order to access GPIO registers.
276 */
277static void __init map_sa1100_gpio_regs( void )
278{
279 unsigned long phys = __PREG(GPLR) & PMD_MASK;
280 unsigned long virt = io_p2v(phys);
281 int prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_DOMAIN(DOMAIN_IO);
282 pmd_t *pmd;
283
Russell Kinga61c2332012-01-14 16:10:53 +0000284 pmd = pmd_offset(pud_offset(pgd_offset_k(virt), virt), virt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 *pmd = __pmd(phys | prot);
286 flush_pmd_entry(pmd);
287}
288
289/*
290 * Read System Configuration "Register"
291 * (taken from "Intel StrongARM SA-1110 Microprocessor Development Board
292 * User's Guide", section 4.4.1)
293 *
294 * This same scan is performed in arch/arm/boot/compressed/head-sa1100.S
295 * to set up the serial port for decompression status messages. We
296 * repeat it here because the kernel may not be loaded as a zImage, and
297 * also because it's a hassle to communicate the SCR value to the kernel
298 * from the decompressor.
299 *
300 * Note that IRQs are guaranteed to be disabled.
301 */
302static void __init get_assabet_scr(void)
303{
304 unsigned long scr, i;
305
306 GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */
307 GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */
308 GPDR &= ~(0x3fc); /* Configure GPIO 9:2 as inputs */
Russell King2f3eca82005-11-21 17:01:13 +0000309 for(i = 100; i--; ) /* Read GPIO 9:2 */
310 scr = GPLR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 GPDR |= 0x3fc; /* restore correct pin direction */
312 scr &= 0x3fc; /* save as system configuration byte. */
313 SCR_value = scr;
314}
315
316static void __init
Russell King0744a3e2010-12-20 10:37:50 +0000317fixup_assabet(struct tag *tags, char **cmdline, struct meminfo *mi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
319 /* This must be done before any call to machine_has_neponset() */
320 map_sa1100_gpio_regs();
321 get_assabet_scr();
322
323 if (machine_has_neponset())
324 printk("Neponset expansion board detected\n");
325}
326
327
328static void assabet_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
329{
330 if (port->mapbase == _Ser1UTCR0) {
331 if (state)
332 ASSABET_BCR_clear(ASSABET_BCR_RS232EN |
333 ASSABET_BCR_COM_RTS |
334 ASSABET_BCR_COM_DTR);
335 else
336 ASSABET_BCR_set(ASSABET_BCR_RS232EN |
337 ASSABET_BCR_COM_RTS |
338 ASSABET_BCR_COM_DTR);
339 }
340}
341
342/*
343 * Assabet uses COM_RTS and COM_DTR for both UART1 (com port)
344 * and UART3 (radio module). We only handle them for UART1 here.
345 */
346static void assabet_set_mctrl(struct uart_port *port, u_int mctrl)
347{
348 if (port->mapbase == _Ser1UTCR0) {
349 u_int set = 0, clear = 0;
350
351 if (mctrl & TIOCM_RTS)
352 clear |= ASSABET_BCR_COM_RTS;
353 else
354 set |= ASSABET_BCR_COM_RTS;
355
356 if (mctrl & TIOCM_DTR)
357 clear |= ASSABET_BCR_COM_DTR;
358 else
359 set |= ASSABET_BCR_COM_DTR;
360
361 ASSABET_BCR_clear(clear);
362 ASSABET_BCR_set(set);
363 }
364}
365
366static u_int assabet_get_mctrl(struct uart_port *port)
367{
368 u_int ret = 0;
369 u_int bsr = ASSABET_BSR;
370
371 /* need 2 reads to read current value */
372 bsr = ASSABET_BSR;
373
374 if (port->mapbase == _Ser1UTCR0) {
375 if (bsr & ASSABET_BSR_COM_DCD)
376 ret |= TIOCM_CD;
377 if (bsr & ASSABET_BSR_COM_CTS)
378 ret |= TIOCM_CTS;
379 if (bsr & ASSABET_BSR_COM_DSR)
380 ret |= TIOCM_DSR;
381 } else if (port->mapbase == _Ser3UTCR0) {
382 if (bsr & ASSABET_BSR_RAD_DCD)
383 ret |= TIOCM_CD;
384 if (bsr & ASSABET_BSR_RAD_CTS)
385 ret |= TIOCM_CTS;
386 if (bsr & ASSABET_BSR_RAD_DSR)
387 ret |= TIOCM_DSR;
388 if (bsr & ASSABET_BSR_RAD_RI)
389 ret |= TIOCM_RI;
390 } else {
391 ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
392 }
393
394 return ret;
395}
396
397static struct sa1100_port_fns assabet_port_fns __initdata = {
398 .set_mctrl = assabet_set_mctrl,
399 .get_mctrl = assabet_get_mctrl,
400 .pm = assabet_uart_pm,
401};
402
403static struct map_desc assabet_io_desc[] __initdata = {
Deepak Saxena92519d82005-10-28 15:19:04 +0100404 { /* Board Control Register */
405 .virtual = 0xf1000000,
406 .pfn = __phys_to_pfn(0x12000000),
407 .length = 0x00100000,
408 .type = MT_DEVICE
409 }, { /* MQ200 */
410 .virtual = 0xf2800000,
411 .pfn = __phys_to_pfn(0x4b800000),
412 .length = 0x00800000,
413 .type = MT_DEVICE
414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415};
416
417static void __init assabet_map_io(void)
418{
419 sa1100_map_io();
420 iotable_init(assabet_io_desc, ARRAY_SIZE(assabet_io_desc));
421
422 /*
423 * Set SUS bit in SDCR0 so serial port 1 functions.
424 * Its called GPCLKR0 in my SA1110 manual.
425 */
426 Ser1SDCR0 |= SDCR0_SUS;
427
428 if (machine_has_neponset()) {
429#ifdef CONFIG_ASSABET_NEPONSET
430 extern void neponset_map_io(void);
431
432 /*
433 * We map Neponset registers even if it isn't present since
434 * many drivers will try to probe their stuff (and fail).
435 * This is still more friendly than a kernel paging request
436 * crash.
437 */
438 neponset_map_io();
439#endif
440 } else {
441 sa1100_register_uart_fns(&assabet_port_fns);
442 }
443
444 /*
445 * When Neponset is attached, the first UART should be
446 * UART3. That's what Angel is doing and many documents
447 * are stating this.
448 *
449 * We do the Neponset mapping even if Neponset support
450 * isn't compiled in so the user will still get something on
451 * the expected physical serial port.
452 *
453 * We no longer do this; not all boot loaders support it,
454 * and UART3 appears to be somewhat unreliable with blob.
455 */
456 sa1100_register_uart(0, 1);
457 sa1100_register_uart(2, 3);
458}
459
460
461MACHINE_START(ASSABET, "Intel-Assabet")
Nicolas Pitre17f44252011-07-05 22:38:17 -0400462 .atag_offset = 0x100,
Russell Kinge9dea0c2005-07-03 17:38:58 +0100463 .fixup = fixup_assabet,
464 .map_io = assabet_map_io,
465 .init_irq = sa1100_init_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 .timer = &sa1100_timer,
467 .init_machine = assabet_init,
Nicolas Pitree9107ab2011-07-05 22:28:09 -0400468#ifdef CONFIG_SA1111
469 .dma_zone_size = SZ_1M,
470#endif
Russell Kingd9ca5832011-11-05 10:28:50 +0000471 .restart = sa11x0_restart,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472MACHINE_END