From da2d341c2857cd8fb09d41b2832bf2a33d543af3 Mon Sep 17 00:00:00 2001 From: kaloz Date: Thu, 24 May 2007 12:44:44 +0000 Subject: fix Magicbox for .21 and convert to the new structure git-svn-id: svn://svn.openwrt.org/openwrt/trunk@7328 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- .../files/drivers/ide/ppc/magicbox_ide.c | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 target/linux/magicbox-2.6/files/drivers/ide/ppc/magicbox_ide.c (limited to 'target/linux/magicbox-2.6/files/drivers/ide') 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 + * + * GNU General Public License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +#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); +} + -- cgit v1.2.3