Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes...
[linux-2.6] / arch / arm / mach-pxa / trizeps4.c
1 /*
2  *  linux/arch/arm/mach-pxa/trizeps4.c
3  *
4  *  Support for the Keith und Koep Trizeps4 Module Platform.
5  *
6  *  Author:     Jürgen Schindele
7  *  Created:    20 02, 2006
8  *  Copyright:  Jürgen Schindele
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License version 2 as
12  *  published by the Free Software Foundation.
13  */
14
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/platform_device.h>
18 #include <linux/sysdev.h>
19 #include <linux/interrupt.h>
20 #include <linux/sched.h>
21 #include <linux/bitops.h>
22 #include <linux/fb.h>
23 #include <linux/ioport.h>
24 #include <linux/delay.h>
25 #include <linux/serial_8250.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/mtd/partitions.h>
29
30 #include <asm/types.h>
31 #include <asm/setup.h>
32 #include <asm/memory.h>
33 #include <asm/mach-types.h>
34 #include <asm/hardware.h>
35 #include <asm/irq.h>
36 #include <asm/sizes.h>
37
38 #include <asm/mach/arch.h>
39 #include <asm/mach/map.h>
40 #include <asm/mach/irq.h>
41 #include <asm/mach/flash.h>
42
43 #include <asm/arch/pxa-regs.h>
44 #include <asm/arch/pxa2xx-gpio.h>
45 #include <asm/arch/trizeps4.h>
46 #include <asm/arch/audio.h>
47 #include <asm/arch/pxafb.h>
48 #include <asm/arch/mmc.h>
49 #include <asm/arch/irda.h>
50 #include <asm/arch/ohci.h>
51
52 #include "generic.h"
53 #include "devices.h"
54
55 /********************************************************************************************
56  * ONBOARD FLASH
57  ********************************************************************************************/
58 static struct mtd_partition trizeps4_partitions[] = {
59         {
60                 .name =         "Bootloader",
61                 .offset =       0x00000000,
62                 .size =         0x00040000,
63                 .mask_flags =   MTD_WRITEABLE  /* force read-only */
64         },{
65                 .name =         "Backup",
66                 .offset =       0x00040000,
67                 .size =         0x00040000,
68         },{
69                 .name =         "Image",
70                 .offset =       0x00080000,
71                 .size =         0x01080000,
72         },{
73                 .name =         "IPSM",
74                 .offset =       0x01100000,
75                 .size =         0x00e00000,
76         },{
77                 .name =         "Registry",
78                 .offset =       0x01f00000,
79                 .size =         MTDPART_SIZ_FULL,
80         }
81 };
82
83 static struct physmap_flash_data trizeps4_flash_data[] = {
84         {
85                 .width          = 4,                    /* bankwidth in bytes */
86                 .parts          = trizeps4_partitions,
87                 .nr_parts       = ARRAY_SIZE(trizeps4_partitions)
88         }
89 };
90
91 static struct resource flash_resource = {
92         .start  = PXA_CS0_PHYS,
93         .end    = PXA_CS0_PHYS + SZ_32M - 1,
94         .flags  = IORESOURCE_MEM,
95 };
96
97 static struct platform_device flash_device = {
98         .name           = "physmap-flash",
99         .id             = 0,
100         .dev = {
101                 .platform_data = trizeps4_flash_data,
102         },
103         .resource = &flash_resource,
104         .num_resources = 1,
105 };
106
107 /********************************************************************************************
108  * DAVICOM DM9000 Ethernet
109  ********************************************************************************************/
110 static struct resource dm9000_resources[] = {
111         [0] = {
112                 .start  = TRIZEPS4_ETH_PHYS+0x300,
113                 .end    = TRIZEPS4_ETH_PHYS+0x400-1,
114                 .flags  = IORESOURCE_MEM,
115         },
116         [1] = {
117                 .start  = TRIZEPS4_ETH_PHYS+0x8300,
118                 .end    = TRIZEPS4_ETH_PHYS+0x8400-1,
119                 .flags  = IORESOURCE_MEM,
120         },
121         [2] = {
122                 .start  = TRIZEPS4_ETH_IRQ,
123                 .end    = TRIZEPS4_ETH_IRQ,
124                 .flags  = (IORESOURCE_IRQ | IRQT_RISING),
125         },
126 };
127
128 static struct platform_device dm9000_device = {
129         .name           = "dm9000",
130         .id             = -1,
131         .num_resources  = ARRAY_SIZE(dm9000_resources),
132         .resource       = dm9000_resources,
133 };
134
135 /********************************************************************************************
136  * PXA270 serial ports
137  ********************************************************************************************/
138 static struct plat_serial8250_port tri_serial_ports[] = {
139 #ifdef CONFIG_SERIAL_PXA
140         /* this uses the own PXA driver */
141         {
142                 0,
143         },
144 #else
145         /* this uses the generic 8520 driver */
146         [0] = {
147                 .membase        = (void *)&FFUART,
148                 .irq            = IRQ_FFUART,
149                 .flags          = UPF_BOOT_AUTOCONF,
150                 .iotype         = UPIO_MEM32,
151                 .regshift       = 2,
152                 .uartclk        = (921600*16),
153         },
154         [1] = {
155                 .membase        = (void *)&BTUART,
156                 .irq            = IRQ_BTUART,
157                 .flags          = UPF_BOOT_AUTOCONF,
158                 .iotype         = UPIO_MEM32,
159                 .regshift       = 2,
160                 .uartclk        = (921600*16),
161         },
162         {
163                 0,
164         },
165 #endif
166 };
167
168 static struct platform_device uart_devices = {
169         .name           = "serial8250",
170         .id             = 0,
171         .dev            = {
172                 .platform_data  = tri_serial_ports,
173         },
174         .num_resources  = 0,
175         .resource       = NULL,
176 };
177
178 /********************************************************************************************
179  * PXA270 ac97 sound codec
180  ********************************************************************************************/
181 static struct platform_device ac97_audio_device = {
182         .name           = "pxa2xx-ac97",
183         .id             = -1,
184 };
185
186 static struct platform_device * trizeps4_devices[] __initdata = {
187         &flash_device,
188         &uart_devices,
189         &dm9000_device,
190         &ac97_audio_device,
191 };
192
193 #ifdef CONFIG_MACH_TRIZEPS4_CONXS
194 static short trizeps_conxs_bcr;
195
196 /* PCCARD power switching supports only 3,3V */
197 void board_pcmcia_power(int power)
198 {
199         if (power) {
200                 /* switch power on, put in reset and enable buffers */
201                 trizeps_conxs_bcr |= power;
202                 trizeps_conxs_bcr |= ConXS_BCR_CF_RESET;
203                 trizeps_conxs_bcr &= ~(ConXS_BCR_CF_BUF_EN);
204                 ConXS_BCR = trizeps_conxs_bcr;
205                 /* wait a little */
206                 udelay(2000);
207                 /* take reset away */
208                 trizeps_conxs_bcr &= ~(ConXS_BCR_CF_RESET);
209                 ConXS_BCR = trizeps_conxs_bcr;
210                 udelay(2000);
211         } else {
212                 /* put in reset */
213                 trizeps_conxs_bcr |= ConXS_BCR_CF_RESET;
214                 ConXS_BCR = trizeps_conxs_bcr;
215                 udelay(1000);
216                 /* switch power off */
217                 trizeps_conxs_bcr &= ~(0xf);
218                 ConXS_BCR = trizeps_conxs_bcr;
219
220         }
221         pr_debug("%s: o%s 0x%x\n", __func__, power ? "n": "ff", trizeps_conxs_bcr);
222 }
223
224 /* backlight power switching for LCD panel */
225 static void board_backlight_power(int on)
226 {
227         if (on) {
228                 trizeps_conxs_bcr |= ConXS_BCR_L_DISP;
229         } else {
230                 trizeps_conxs_bcr &= ~ConXS_BCR_L_DISP;
231         }
232         pr_debug("%s: o%s 0x%x\n", __func__, on ? "n" : "ff", trizeps_conxs_bcr);
233         ConXS_BCR = trizeps_conxs_bcr;
234 }
235
236 /* Powersupply for MMC/SD cardslot */
237 static void board_mci_power(struct device *dev, unsigned int vdd)
238 {
239         struct pxamci_platform_data* p_d = dev->platform_data;
240
241         if (( 1 << vdd) & p_d->ocr_mask) {
242                 pr_debug("%s: on\n", __func__);
243                 /* FIXME fill in values here */
244         } else {
245                 pr_debug("%s: off\n", __func__);
246                 /* FIXME fill in values here */
247         }
248 }
249
250 static short trizeps_conxs_ircr;
251
252 /* Switch modes and Power for IRDA receiver */
253 static void board_irda_mode(struct device *dev, int mode)
254 {
255         unsigned long flags;
256
257         local_irq_save(flags);
258         if (mode & IR_SIRMODE) {
259                 /* Slow mode */
260                 trizeps_conxs_ircr &= ~ConXS_IRCR_MODE;
261         } else if (mode & IR_FIRMODE) {
262                 /* Fast mode */
263                 trizeps_conxs_ircr |= ConXS_IRCR_MODE;
264         }
265         if (mode & IR_OFF) {
266                 trizeps_conxs_ircr |= ConXS_IRCR_SD;
267         } else {
268                 trizeps_conxs_ircr &= ~ConXS_IRCR_SD;
269         }
270         /* FIXME write values to register */
271         local_irq_restore(flags);
272 }
273
274 #else
275 /* for other baseboards define dummies */
276 void board_pcmcia_power(int power)      {;}
277 #define board_backlight_power           NULL
278 #define board_mci_power                 NULL
279 #define board_irda_mode                 NULL
280
281 #endif          /* CONFIG_MACH_TRIZEPS4_CONXS */
282 EXPORT_SYMBOL(board_pcmcia_power);
283
284 static int trizeps4_mci_init(struct device *dev, irq_handler_t mci_detect_int, void *data)
285 {
286         int err;
287         /* setup GPIO for PXA27x MMC controller */
288         pxa_gpio_mode(GPIO32_MMCCLK_MD);
289         pxa_gpio_mode(GPIO112_MMCCMD_MD);
290         pxa_gpio_mode(GPIO92_MMCDAT0_MD);
291         pxa_gpio_mode(GPIO109_MMCDAT1_MD);
292         pxa_gpio_mode(GPIO110_MMCDAT2_MD);
293         pxa_gpio_mode(GPIO111_MMCDAT3_MD);
294
295         pxa_gpio_mode(GPIO_MMC_DET | GPIO_IN);
296
297         err = request_irq(TRIZEPS4_MMC_IRQ, mci_detect_int,
298                           IRQF_DISABLED | IRQF_TRIGGER_RISING,
299                           "MMC card detect", data);
300         if (err)
301                 printk(KERN_ERR "trizeps4_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
302
303         return err;
304 }
305
306 static void trizeps4_mci_exit(struct device *dev, void *data)
307 {
308         free_irq(TRIZEPS4_MMC_IRQ, data);
309 }
310
311 static struct pxamci_platform_data trizeps4_mci_platform_data = {
312         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
313         .init           = trizeps4_mci_init,
314         .exit           = trizeps4_mci_exit,
315         .setpower       = board_mci_power,
316 };
317
318 static struct pxaficp_platform_data trizeps4_ficp_platform_data = {
319         .transceiver_cap  = IR_SIRMODE | IR_FIRMODE | IR_OFF,
320         .transceiver_mode = board_irda_mode,
321 };
322
323 static int trizeps4_ohci_init(struct device *dev)
324 {
325         /* setup Port1 GPIO pin. */
326         pxa_gpio_mode( 88 | GPIO_ALT_FN_1_IN);  /* USBHPWR1 */
327         pxa_gpio_mode( 89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */
328
329         /* Set the Power Control Polarity Low and Power Sense
330            Polarity Low to active low. */
331         UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
332                 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
333
334         return 0;
335 }
336
337 static void trizeps4_ohci_exit(struct device *dev)
338 {
339         ;
340 }
341
342 static struct pxaohci_platform_data trizeps4_ohci_platform_data = {
343         .port_mode      = PMM_PERPORT_MODE,
344         .init           = trizeps4_ohci_init,
345         .exit           = trizeps4_ohci_exit,
346 };
347
348 static struct map_desc trizeps4_io_desc[] __initdata = {
349         {       /* ConXS CFSR */
350                 .virtual        = TRIZEPS4_CFSR_VIRT,
351                 .pfn            = __phys_to_pfn(TRIZEPS4_CFSR_PHYS),
352                 .length         = 0x00001000,
353                 .type           = MT_DEVICE
354         },
355         {       /* ConXS BCR */
356                 .virtual        = TRIZEPS4_BOCR_VIRT,
357                 .pfn            = __phys_to_pfn(TRIZEPS4_BOCR_PHYS),
358                 .length         = 0x00001000,
359                 .type           = MT_DEVICE
360         },
361         {       /* ConXS IRCR */
362                 .virtual        = TRIZEPS4_IRCR_VIRT,
363                 .pfn            = __phys_to_pfn(TRIZEPS4_IRCR_PHYS),
364                 .length         = 0x00001000,
365                 .type           = MT_DEVICE
366         },
367         {       /* ConXS DCR */
368                 .virtual        = TRIZEPS4_DICR_VIRT,
369                 .pfn            = __phys_to_pfn(TRIZEPS4_DICR_PHYS),
370                 .length         = 0x00001000,
371                 .type           = MT_DEVICE
372         },
373         {       /* ConXS UPSR */
374                 .virtual        = TRIZEPS4_UPSR_VIRT,
375                 .pfn            = __phys_to_pfn(TRIZEPS4_UPSR_PHYS),
376                 .length         = 0x00001000,
377                 .type           = MT_DEVICE
378         }
379 };
380
381 static struct pxafb_mode_info sharp_lcd_mode = {
382     .pixclock           = 78000,
383     .xres               = 640,
384     .yres               = 480,
385     .bpp                = 8,
386     .hsync_len          = 4,
387     .left_margin        = 4,
388     .right_margin       = 4,
389     .vsync_len          = 2,
390     .upper_margin       = 0,
391     .lower_margin       = 0,
392     .sync               = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
393     .cmap_greyscale     = 0,
394 };
395
396 static struct pxafb_mach_info sharp_lcd = {
397     .modes              = &sharp_lcd_mode,
398     .num_modes  = 1,
399     .cmap_inverse       = 0,
400     .cmap_static        = 0,
401     .lccr0              = LCCR0_Color | LCCR0_Pas | LCCR0_Dual,
402     .lccr3              = 0x0340ff02,
403     .pxafb_backlight_power = board_backlight_power,
404 };
405
406 static struct pxafb_mode_info toshiba_lcd_mode = {
407     .pixclock           = 39720,
408     .xres               = 640,
409     .yres               = 480,
410     .bpp                = 8,
411     .hsync_len          = 63,
412     .left_margin        = 12,
413     .right_margin       = 12,
414     .vsync_len          = 4,
415     .upper_margin       = 32,
416     .lower_margin       = 10,
417     .sync               = 0,
418     .cmap_greyscale     = 0,
419 };
420
421 static struct pxafb_mach_info toshiba_lcd = {
422     .modes              = &toshiba_lcd_mode,
423     .num_modes  = 1,
424     .cmap_inverse       = 0,
425     .cmap_static        = 0,
426     .lccr0              = LCCR0_Color | LCCR0_Act,
427     .lccr3              = 0x03400002,
428     .pxafb_backlight_power = board_backlight_power,
429 };
430
431 static void __init trizeps4_init(void)
432 {
433         platform_add_devices(trizeps4_devices, ARRAY_SIZE(trizeps4_devices));
434
435 /*      set_pxa_fb_info(&sharp_lcd); */
436         set_pxa_fb_info(&toshiba_lcd);
437
438         pxa_set_mci_info(&trizeps4_mci_platform_data);
439         pxa_set_ficp_info(&trizeps4_ficp_platform_data);
440         pxa_set_ohci_info(&trizeps4_ohci_platform_data);
441 }
442
443 static void __init trizeps4_map_io(void)
444 {
445         pxa_map_io();
446         iotable_init(trizeps4_io_desc, ARRAY_SIZE(trizeps4_io_desc));
447
448         /* for DiskOnChip */
449         pxa_gpio_mode(GPIO15_nCS_1_MD);
450
451         /* for off-module PIC on ConXS board */
452         pxa_gpio_mode(GPIO_PIC | GPIO_IN);
453
454         /* UCB1400 irq */
455         pxa_gpio_mode(GPIO_UCB1400 | GPIO_IN);
456
457         /* for DM9000 LAN */
458         pxa_gpio_mode(GPIO78_nCS_2_MD);
459         pxa_gpio_mode(GPIO_DM9000 | GPIO_IN);
460
461         /* for PCMCIA device */
462         pxa_gpio_mode(GPIO_PCD | GPIO_IN);
463         pxa_gpio_mode(GPIO_PRDY | GPIO_IN);
464
465         /* for I2C adapter */
466         pxa_gpio_mode(GPIO117_I2CSCL_MD);
467         pxa_gpio_mode(GPIO118_I2CSDA_MD);
468
469         /* MMC_DET s.o. */
470         pxa_gpio_mode(GPIO_MMC_DET | GPIO_IN);
471
472         /* whats that for ??? */
473         pxa_gpio_mode(GPIO79_nCS_3_MD);
474
475 #ifdef CONFIG_LEDS
476         pxa_gpio_mode( GPIO_SYS_BUSY_LED  | GPIO_OUT);          /* LED1 */
477         pxa_gpio_mode( GPIO_HEARTBEAT_LED | GPIO_OUT);          /* LED2 */
478 #endif
479 #ifdef CONFIG_MACH_TRIZEPS4_CONXS
480 #ifdef CONFIG_IDE_PXA_CF
481         /* if boot direct from compact flash dont disable power */
482         trizeps_conxs_bcr = 0x0009;
483 #else
484         /* this is the reset value */
485         trizeps_conxs_bcr = 0x00A0;
486 #endif
487         ConXS_BCR = trizeps_conxs_bcr;
488 #endif
489
490         PWER  = 0x00000002;
491         PFER  = 0x00000000;
492         PRER  = 0x00000002;
493         PGSR0 = 0x0158C000;
494         PGSR1 = 0x00FF0080;
495         PGSR2 = 0x0001C004;
496         /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
497         PCFR |= PCFR_OPDE;
498 }
499
500 MACHINE_START(TRIZEPS4, "Keith und Koep Trizeps IV module")
501         /* MAINTAINER("Jürgen Schindele") */
502         .phys_io        = 0x40000000,
503         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
504         .boot_params    = TRIZEPS4_SDRAM_BASE + 0x100,
505         .init_machine   = trizeps4_init,
506         .map_io         = trizeps4_map_io,
507         .init_irq       = pxa27x_init_irq,
508         .timer          = &pxa_timer,
509 MACHINE_END
510