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