1 /* Driver for MagicBox 2.0 onboard CompactFlash adapter.
2 * Written by Wojtek Kaniewski <wojtekka@toxygen.net>
4 * GNU General Public License.
7 #include <linux/version.h>
8 #include <linux/types.h>
10 #include <linux/interrupt.h>
11 #include <linux/blkdev.h>
12 #include <linux/hdreg.h>
13 #include <linux/ide.h>
14 #include <linux/delay.h>
15 #include <linux/platform_device.h>
22 static int ide_offsets
[IDE_NR_PORTS
] = {0, 2, 4, 6, 8, 10, 12, 14, -1, -1};
24 static u8
magicbox_ide_inb (unsigned long port
)
26 return (u8
) (readw((void __iomem
*) port
) >> 8) & 255;
29 static u16
magicbox_ide_inw (unsigned long port
)
31 return (u16
) readw((void __iomem
*) port
);
34 static void magicbox_ide_insw (unsigned long port
, void *addr
, u32 count
)
38 for (ptr
= addr
; count
--; ptr
++)
39 *ptr
= readw((void __iomem
*) port
);
42 static u32
magicbox_ide_inl (unsigned long port
)
44 return (u32
) readl((void __iomem
*) port
);
47 static void magicbox_ide_insl (unsigned long port
, void *addr
, u32 count
)
51 for (ptr
= addr
; count
--; ptr
++)
52 *ptr
= readl((void __iomem
*) port
);
55 static void magicbox_ide_outb (u8 value
, unsigned long port
)
57 writew(value
<< 8, (void __iomem
*) port
);
60 static void magicbox_ide_outbsync (ide_drive_t
*drive
, u8 value
, unsigned long port
)
62 writew(value
<< 8, (void __iomem
*) port
);
65 static void magicbox_ide_outw (u16 value
, unsigned long port
)
67 writew(value
, (void __iomem
*) port
);
70 static void magicbox_ide_outsw (unsigned long port
, void *addr
, u32 count
)
74 for (ptr
= addr
; count
--; ptr
++)
75 writew(*ptr
, (void __iomem
*) port
);
78 static void magicbox_ide_outl (u32 value
, unsigned long port
)
80 writel(value
, (void __iomem
*) port
);
83 static void magicbox_ide_outsl (unsigned long port
, void *addr
, u32 count
)
87 for (ptr
= addr
; count
--; ptr
++)
88 writel(*ptr
, (void __iomem
*) port
);
92 static void __init
ide_magicbox_register(unsigned long addr
,
93 unsigned long caddr
, int irq
)
98 memset(&hw
, 0, sizeof(hw
));
99 ide_setup_ports(&hw
, addr
, ide_offsets
, caddr
+ 12, 0, NULL
,irq
);
101 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
102 if (ide_register_hw(&hw
, &hwif
) != -1)
103 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
104 if (ide_register_hw(&hw
, 1, &hwif
) != -1)
106 if (ide_register_hw(&hw
, NULL
, 1, &hwif
) != -1)
109 printk(KERN_NOTICE
"magicbox-ide: Registered IDE-CF driver\n");
111 hwif
->drives
[0].unmask
= 1;
112 hwif
->OUTB
= magicbox_ide_outb
;
113 hwif
->OUTBSYNC
= magicbox_ide_outbsync
;
114 hwif
->OUTW
= magicbox_ide_outw
;
115 hwif
->OUTSW
= magicbox_ide_outsw
;
116 hwif
->OUTSL
= magicbox_ide_outsl
;
117 hwif
->INB
= magicbox_ide_inb
;
118 hwif
->INW
= magicbox_ide_inw
;
119 hwif
->INSW
= magicbox_ide_insw
;
120 hwif
->INSL
= magicbox_ide_insl
;
124 void __init
ide_magicbox_init(void)
129 /* Turn on PerWE instead of PCIsomething */
130 mtdcr(DCRN_CPC0_PCI_BASE
, mfdcr(DCRN_CPC0_PCI_BASE
) | (0x80000000L
>> 27));
132 /* PerCS1 (CF's CS0): base 0xff100000, 16-bit, rw */
133 mtdcr(DCRN_EBC_BASE
, 1);
134 mtdcr(DCRN_EBC_BASE
+ 1, 0xff11a000);
135 mtdcr(DCRN_EBC_BASE
, 0x11);
136 mtdcr(DCRN_EBC_BASE
+ 1, 0x080bd800);
138 /* PerCS2 (CF's CS1): base 0xff200000, 16-bit, rw */
139 mtdcr(DCRN_EBC_BASE
, 2);
140 mtdcr(DCRN_EBC_BASE
+ 1, 0xff21a000);
141 mtdcr(DCRN_EBC_BASE
, 0x12);
142 mtdcr(DCRN_EBC_BASE
+ 1, 0x080bd800);
144 /* Remap physical address space */
145 addr
= ioremap_nocache(0xff100000, 4096);
146 caddr
= ioremap_nocache(0xff200000, 4096);
148 /* Set interrupt to low-to-high-edge-triggered */
149 mtdcr(UIC0_TR
, mfdcr(UIC0_TR
) & ~(0x80000000L
>> IRQ
));
150 mtdcr(UIC0_PR
, mfdcr(UIC0_PR
) | (0x80000000L
>> IRQ
));
152 ide_magicbox_register((unsigned long)addr
, (unsigned long)caddr
, IRQ
);
This page took 0.052534 seconds and 5 git commands to generate.