Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / arch / arm / mach-pxa / lubbock.c
index 28c9677..3e26d7c 100644 (file)
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/sysdev.h>
 #include <linux/major.h>
 #include <linux/fb.h>
 #include <linux/interrupt.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
 
 #include <asm/setup.h>
 #include <asm/memory.h>
 #include <asm/mach-types.h>
 #include <asm/hardware.h>
 #include <asm/irq.h>
+#include <asm/sizes.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
 #include <asm/mach/irq.h>
+#include <asm/mach/flash.h>
 
+#include <asm/hardware/sa1111.h>
+
+#include <asm/arch/pxa-regs.h>
 #include <asm/arch/lubbock.h>
 #include <asm/arch/udc.h>
+#include <asm/arch/irda.h>
 #include <asm/arch/pxafb.h>
-#include <asm/hardware/sa1111.h>
+#include <asm/arch/mmc.h>
 
 #include "generic.h"
 
 
+#define LUB_MISC_WR            __LUB_REG(LUBBOCK_FPGA_PHYS + 0x080)
+
 void lubbock_set_misc_wr(unsigned int mask, unsigned int set)
 {
        unsigned long flags;
@@ -78,7 +89,7 @@ static void lubbock_irq_handler(unsigned int irq, struct irqdesc *desc,
                if (likely(pending)) {
                        irq = LUBBOCK_IRQ(0) + __ffs(pending);
                        desc = irq_desc + irq;
-                       desc->handle(irq, desc, regs);
+                       desc_handle_irq(irq, desc, regs);
                }
                pending = LUB_IRQ_SET_CLR & lubbock_irq_enabled;
        } while (pending);
@@ -101,6 +112,35 @@ static void __init lubbock_init_irq(void)
        set_irq_type(IRQ_GPIO(0), IRQT_FALLING);
 }
 
+#ifdef CONFIG_PM
+
+static int lubbock_irq_resume(struct sys_device *dev)
+{
+       LUB_IRQ_MASK_EN = lubbock_irq_enabled;
+       return 0;
+}
+
+static struct sysdev_class lubbock_irq_sysclass = {
+       set_kset_name("cpld_irq"),
+       .resume = lubbock_irq_resume,
+};
+
+static struct sys_device lubbock_irq_device = {
+       .cls = &lubbock_irq_sysclass,
+};
+
+static int __init lubbock_irq_device_init(void)
+{
+       int ret = sysdev_class_register(&lubbock_irq_sysclass);
+       if (ret == 0)
+               ret = sysdev_register(&lubbock_irq_device);
+       return ret;
+}
+
+device_initcall(lubbock_irq_device_init);
+
+#endif
+
 static int lubbock_udc_is_connected(void)
 {
        return (LUB_MISC_RD & (1 << 9)) == 0;
@@ -111,6 +151,11 @@ static struct pxa2xx_udc_mach_info udc_info __initdata = {
        // no D+ pullup; lubbock can't connect/disconnect in software
 };
 
+static struct platform_device lub_audio_device = {
+       .name           = "pxa2xx-ac97",
+       .id             = -1,
+};
+
 static struct resource sa1111_resources[] = {
        [0] = {
                .start  = 0x10000000,
@@ -133,7 +178,8 @@ static struct platform_device sa1111_device = {
 
 static struct resource smc91x_resources[] = {
        [0] = {
-               .start  = 0x0c000000,
+               .name   = "smc91x-regs",
+               .start  = 0x0c000c00,
                .end    = 0x0c0fffff,
                .flags  = IORESOURCE_MEM,
        },
@@ -143,6 +189,7 @@ static struct resource smc91x_resources[] = {
                .flags  = IORESOURCE_IRQ,
        },
        [2] = {
+               .name   = "smc91x-attrib",
                .start  = 0x0e000000,
                .end    = 0x0e0fffff,
                .flags  = IORESOURCE_MEM,
@@ -156,9 +203,75 @@ static struct platform_device smc91x_device = {
        .resource       = smc91x_resources,
 };
 
+static struct resource flash_resources[] = {
+       [0] = {
+               .start  = 0x00000000,
+               .end    = SZ_64M - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = 0x04000000,
+               .end    = 0x04000000 + SZ_64M - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct mtd_partition lubbock_partitions[] = {
+       {
+               .name =         "Bootloader",
+               .size =         0x00040000,
+               .offset =       0,
+               .mask_flags =   MTD_WRITEABLE  /* force read-only */
+       },{
+               .name =         "Kernel",
+               .size =         0x00100000,
+               .offset =       0x00040000,
+       },{
+               .name =         "Filesystem",
+               .size =         MTDPART_SIZ_FULL,
+               .offset =       0x00140000
+       }
+};
+
+static struct flash_platform_data lubbock_flash_data[2] = {
+       {
+               .map_name       = "cfi_probe",
+               .parts          = lubbock_partitions,
+               .nr_parts       = ARRAY_SIZE(lubbock_partitions),
+       }, {
+               .map_name       = "cfi_probe",
+               .parts          = NULL,
+               .nr_parts       = 0,
+       }
+};
+
+static struct platform_device lubbock_flash_device[2] = {
+       {
+               .name           = "pxa2xx-flash",
+               .id             = 0,
+               .dev = {
+                       .platform_data = &lubbock_flash_data[0],
+               },
+               .resource = &flash_resources[0],
+               .num_resources = 1,
+       },
+       {
+               .name           = "pxa2xx-flash",
+               .id             = 1,
+               .dev = {
+                       .platform_data = &lubbock_flash_data[1],
+               },
+               .resource = &flash_resources[1],
+               .num_resources = 1,
+       },
+};
+
 static struct platform_device *devices[] __initdata = {
        &sa1111_device,
+       &lub_audio_device,
        &smc91x_device,
+       &lubbock_flash_device[0],
+       &lubbock_flash_device[1],
 };
 
 static struct pxafb_mach_info sharp_lm8v31 __initdata = {
@@ -180,15 +293,122 @@ static struct pxafb_mach_info sharp_lm8v31 __initdata = {
        .lccr3          = LCCR3_PCP | LCCR3_Acb(255),
 };
 
+#define        MMC_POLL_RATE           msecs_to_jiffies(1000)
+
+static void lubbock_mmc_poll(unsigned long);
+static irqreturn_t (*mmc_detect_int)(int, void *, struct pt_regs *);
+
+static struct timer_list mmc_timer = {
+       .function       = lubbock_mmc_poll,
+};
+
+static void lubbock_mmc_poll(unsigned long data)
+{
+       unsigned long flags;
+
+       /* clear any previous irq state, then ... */
+       local_irq_save(flags);
+       LUB_IRQ_SET_CLR &= ~(1 << 0);
+       local_irq_restore(flags);
+
+       /* poll until mmc/sd card is removed */
+       if (LUB_IRQ_SET_CLR & (1 << 0))
+               mod_timer(&mmc_timer, jiffies + MMC_POLL_RATE);
+       else {
+               (void) mmc_detect_int(LUBBOCK_SD_IRQ, (void *)data, NULL);
+               enable_irq(LUBBOCK_SD_IRQ);
+       }
+}
+
+static irqreturn_t lubbock_detect_int(int irq, void *data, struct pt_regs *regs)
+{
+       /* IRQ is level triggered; disable, and poll for removal */
+       disable_irq(irq);
+       mod_timer(&mmc_timer, jiffies + MMC_POLL_RATE);
+
+       return mmc_detect_int(irq, data, regs);
+}
+
+static int lubbock_mci_init(struct device *dev,
+               irqreturn_t (*detect_int)(int, void *, struct pt_regs *),
+               void *data)
+{
+       /* setup GPIO for PXA25x MMC controller */
+       pxa_gpio_mode(GPIO6_MMCCLK_MD);
+       pxa_gpio_mode(GPIO8_MMCCS0_MD);
+
+       /* detect card insert/eject */
+       mmc_detect_int = detect_int;
+       init_timer(&mmc_timer);
+       mmc_timer.data = (unsigned long) data;
+       return request_irq(LUBBOCK_SD_IRQ, lubbock_detect_int,
+                       SA_SAMPLE_RANDOM, "lubbock-sd-detect", data);
+}
+
+static int lubbock_mci_get_ro(struct device *dev)
+{
+       return (LUB_MISC_RD & (1 << 2)) != 0;
+}
+
+static void lubbock_mci_exit(struct device *dev, void *data)
+{
+       free_irq(LUBBOCK_SD_IRQ, data);
+       del_timer_sync(&mmc_timer);
+}
+
+static struct pxamci_platform_data lubbock_mci_platform_data = {
+       .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
+       .detect_delay   = 1,
+       .init           = lubbock_mci_init,
+       .get_ro         = lubbock_mci_get_ro,
+       .exit           = lubbock_mci_exit,
+};
+
+static void lubbock_irda_transceiver_mode(struct device *dev, int mode)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       if (mode & IR_SIRMODE) {
+               LUB_MISC_WR &= ~(1 << 4);
+       } else if (mode & IR_FIRMODE) {
+               LUB_MISC_WR |= 1 << 4;
+       }
+       local_irq_restore(flags);
+}
+
+static struct pxaficp_platform_data lubbock_ficp_platform_data = {
+       .transceiver_cap  = IR_SIRMODE | IR_FIRMODE,
+       .transceiver_mode = lubbock_irda_transceiver_mode,
+};
+
 static void __init lubbock_init(void)
 {
+       int flashboot = (LUB_CONF_SWITCHES & 1);
+
        pxa_set_udc_info(&udc_info);
        set_pxa_fb_info(&sharp_lm8v31);
+       pxa_set_mci_info(&lubbock_mci_platform_data);
+       pxa_set_ficp_info(&lubbock_ficp_platform_data);
+
+       lubbock_flash_data[0].width = lubbock_flash_data[1].width =
+               (BOOT_DEF & 1) ? 2 : 4;
+       /* Compensate for the nROMBT switch which swaps the flash banks */
+       printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
+              flashboot?"Flash":"ROM", flashboot);
+
+       lubbock_flash_data[flashboot^1].name = "application-flash";
+       lubbock_flash_data[flashboot].name = "boot-rom";
        (void) platform_add_devices(devices, ARRAY_SIZE(devices));
 }
 
 static struct map_desc lubbock_io_desc[] __initdata = {
-  { LUBBOCK_FPGA_VIRT, LUBBOCK_FPGA_PHYS, 0x00100000, MT_DEVICE }, /* CPLD */
+       {       /* CPLD */
+               .virtual        =  LUBBOCK_FPGA_VIRT,
+               .pfn            = __phys_to_pfn(LUBBOCK_FPGA_PHYS),
+               .length         = 0x00100000,
+               .type           = MT_DEVICE
+       }
 };
 
 static void __init lubbock_map_io(void)
@@ -216,10 +436,11 @@ static void __init lubbock_map_io(void)
 }
 
 MACHINE_START(LUBBOCK, "Intel DBPXA250 Development Platform (aka Lubbock)")
-       MAINTAINER("MontaVista Software Inc.")
-       BOOT_MEM(0xa0000000, 0x40000000, io_p2v(0x40000000))
-       MAPIO(lubbock_map_io)
-       INITIRQ(lubbock_init_irq)
-       INITTIME(pxa_init_time)
-       INIT_MACHINE(lubbock_init)
+       /* Maintainer: MontaVista Software Inc. */
+       .phys_io        = 0x40000000,
+       .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
+       .map_io         = lubbock_map_io,
+       .init_irq       = lubbock_init_irq,
+       .timer          = &pxa_timer,
+       .init_machine   = lubbock_init,
 MACHINE_END