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