OSDN Git Service

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