diff options
Diffstat (limited to 'target/linux/magicbox-2.6/files/drivers')
-rw-r--r-- | target/linux/magicbox-2.6/files/drivers/ide/ppc/magicbox_ide.c | 147 | ||||
-rw-r--r-- | target/linux/magicbox-2.6/files/drivers/mtd/maps/magicmap.c | 113 |
2 files changed, 260 insertions, 0 deletions
diff --git a/target/linux/magicbox-2.6/files/drivers/ide/ppc/magicbox_ide.c b/target/linux/magicbox-2.6/files/drivers/ide/ppc/magicbox_ide.c new file mode 100644 index 000000000..d1f6d68ed --- /dev/null +++ b/target/linux/magicbox-2.6/files/drivers/ide/ppc/magicbox_ide.c @@ -0,0 +1,147 @@ +/* Driver for MagicBox 2.0 onboard CompactFlash adapter. + * Written by Wojtek Kaniewski <wojtekka@toxygen.net> + * + * GNU General Public License. + */ + +#include <linux/types.h> +#include <linux/mm.h> +#include <linux/interrupt.h> +#include <linux/blkdev.h> +#include <linux/hdreg.h> +#include <linux/ide.h> +#include <linux/delay.h> +#include <linux/platform_device.h> + + +#define UIC0_PR 0xc4 +#define UIC0_TR 0xc5 +#define IRQ 25 + +static int ide_offsets[IDE_NR_PORTS] = {0, 2, 4, 6, 8, 10, 12, 14, -1, -1}; + +static u8 magicbox_ide_inb (unsigned long port) +{ + return (u8) (readw((void __iomem *) port) >> 8) & 255; +} + +static u16 magicbox_ide_inw (unsigned long port) +{ + return (u16) readw((void __iomem *) port); +} + +static void magicbox_ide_insw (unsigned long port, void *addr, u32 count) +{ + u16 *ptr; + + for (ptr = addr; count--; ptr++) + *ptr = readw((void __iomem *) port); +} + +static u32 magicbox_ide_inl (unsigned long port) +{ + return (u32) readl((void __iomem *) port); +} + +static void magicbox_ide_insl (unsigned long port, void *addr, u32 count) +{ + u32 *ptr; + + for (ptr = addr; count--; ptr++) + *ptr = readl((void __iomem *) port); +} + +static void magicbox_ide_outb (u8 value, unsigned long port) +{ + writew(value << 8, (void __iomem *) port); +} + +static void magicbox_ide_outbsync (ide_drive_t *drive, u8 value, unsigned long port) +{ + writew(value << 8, (void __iomem *) port); +} + +static void magicbox_ide_outw (u16 value, unsigned long port) +{ + writew(value, (void __iomem *) port); +} + +static void magicbox_ide_outsw (unsigned long port, void *addr, u32 count) +{ + u16 *ptr; + + for (ptr = addr; count--; ptr++) + writew(*ptr, (void __iomem *) port); +} + +static void magicbox_ide_outl (u32 value, unsigned long port) +{ + writel(value, (void __iomem *) port); +} + +static void magicbox_ide_outsl (unsigned long port, void *addr, u32 count) +{ + u32 *ptr; + + for (ptr = addr; count--; ptr++) + writel(*ptr, (void __iomem *) port); +} + + +static void __init ide_magicbox_register(unsigned long addr, + unsigned long caddr, int irq) +{ + hw_regs_t hw; + ide_hwif_t *hwif; + + memset(&hw, 0, sizeof(hw)); + ide_setup_ports(&hw, addr, ide_offsets, caddr + 12, 0, NULL,irq); + + if (ide_register_hw(&hw, &hwif) != -1) + { + printk(KERN_NOTICE "magicbox-ide: Registered IDE-CF driver\n"); + hwif->mmio = 2; + hwif->drives[0].unmask = 1; + hwif->OUTB = magicbox_ide_outb; + hwif->OUTBSYNC = magicbox_ide_outbsync; + hwif->OUTW = magicbox_ide_outw; + hwif->OUTSW = magicbox_ide_outsw; + hwif->OUTSL = magicbox_ide_outsl; + hwif->INB = magicbox_ide_inb; + hwif->INW = magicbox_ide_inw; + hwif->INSW = magicbox_ide_insw; + hwif->INSL = magicbox_ide_insl; + } +} + +void __init ide_magicbox_init(void) +{ + volatile u16 *addr; + volatile u16 *caddr; + + /* Turn on PerWE instead of PCIsomething */ + mtdcr(DCRN_CPC0_PCI_BASE, mfdcr(DCRN_CPC0_PCI_BASE) | (0x80000000L >> 27)); + + /* PerCS1 (CF's CS0): base 0xff100000, 16-bit, rw */ + mtdcr(DCRN_EBC_BASE, 1); + mtdcr(DCRN_EBC_BASE + 1, 0xff11a000); + mtdcr(DCRN_EBC_BASE, 0x11); + mtdcr(DCRN_EBC_BASE + 1, 0x080bd800); + + /* PerCS2 (CF's CS1): base 0xff200000, 16-bit, rw */ + mtdcr(DCRN_EBC_BASE, 2); + mtdcr(DCRN_EBC_BASE + 1, 0xff21a000); + mtdcr(DCRN_EBC_BASE, 0x12); + mtdcr(DCRN_EBC_BASE + 1, 0x080bd800); + + /* Remap physical address space */ + addr = ioremap_nocache(0xff100000, 4096); + caddr = ioremap_nocache(0xff200000, 4096); + + /* Set interrupt to low-to-high-edge-triggered */ + mtdcr(UIC0_TR, mfdcr(UIC0_TR) & ~(0x80000000L >> IRQ)); + mtdcr(UIC0_PR, mfdcr(UIC0_PR) | (0x80000000L >> IRQ)); + + ide_magicbox_register((unsigned long)addr, (unsigned long)caddr, IRQ); +} + diff --git a/target/linux/magicbox-2.6/files/drivers/mtd/maps/magicmap.c b/target/linux/magicbox-2.6/files/drivers/mtd/maps/magicmap.c new file mode 100644 index 000000000..b654a3d9b --- /dev/null +++ b/target/linux/magicbox-2.6/files/drivers/mtd/maps/magicmap.c @@ -0,0 +1,113 @@ +/* + * magicmap.c: Copyleft 2005 Karol Lewandowski + * + * Mapping for MagicBox flash. + * Based on walnut.c. + * + * Heikki Lindholm <holindho@infradead.org> + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#include <linux/module.h> +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/mtd/mtd.h> +#include <linux/mtd/map.h> +#include <linux/mtd/partitions.h> +#include <linux/autoconf.h> +#include <asm/io.h> + +static struct mtd_info *flash; + +static struct map_info magic_map = { + .name = "Magically mapped flash", + .phys = 0xffc00000, + .size = 0x400000, + .bankwidth = 2, +}; + +static struct mtd_partition magic_partitions[] = { + { + .name = "linux", + .offset = 0x0, + .size = 0x3c0000, + }, + { + .name = "rootfs", + .offset = 0x100000, + .size = 0x2c0000, + }, + { + .name = "bootloader", + .offset = 0x3c0000, + .size = 0x040000, + .mask_flags = MTD_WRITEABLE, + }, +}; + +int __init init_magic(void) +{ + u32 size, len; + + magic_map.virt = + (void __iomem *)ioremap(magic_map.phys, magic_map.size); + + if (!magic_map.virt) { + printk("Failed to ioremap flash.\n"); + return -EIO; + } + + simple_map_init(&magic_map); + + flash = do_map_probe("cfi_probe", &magic_map); + if (flash) { + flash->owner = THIS_MODULE; + if (flash->read(flash, 12, sizeof(u32), &len, (char *) &size) || + len != 4) + return -ENXIO; + size += 0x40; /* header size of the uImage */ + if (size < 0x400000) { + /* skip to next erase block */ + if (size & (flash->erasesize - 1)) { + size |= (flash->erasesize - 1); + size += 1; + } + magic_partitions[1].offset = size; + magic_partitions[1].size = magic_partitions[2].offset - size; + } + + add_mtd_partitions(flash, magic_partitions, + ARRAY_SIZE(magic_partitions)); + } else { + printk("map probe failed for flash\n"); + return -ENXIO; + } + + return 0; +} + +static void __exit cleanup_magic(void) +{ + if (flash) { + del_mtd_partitions(flash); + map_destroy(flash); + } + + if (magic_map.virt) { + iounmap((void *)magic_map.virt); + magic_map.virt = NULL; + } +} + +module_init(init_magic); +module_exit(cleanup_magic); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Karol Lewandowski"); +MODULE_DESCRIPTION("MTD map and partitions for IBM 405EP MagicBox boards"); |