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)
104 if (ide_register_hw(&hw
, 1, &hwif
) != -1)
107 printk(KERN_NOTICE
"magicbox-ide: Registered IDE-CF driver\n");
109 hwif
->drives
[0].unmask
= 1;
110 hwif
->OUTB
= magicbox_ide_outb
;
111 hwif
->OUTBSYNC
= magicbox_ide_outbsync
;
112 hwif
->OUTW
= magicbox_ide_outw
;
113 hwif
->OUTSW
= magicbox_ide_outsw
;
114 hwif
->OUTSL
= magicbox_ide_outsl
;
115 hwif
->INB
= magicbox_ide_inb
;
116 hwif
->INW
= magicbox_ide_inw
;
117 hwif
->INSW
= magicbox_ide_insw
;
118 hwif
->INSL
= magicbox_ide_insl
;
122 void __init
ide_magicbox_init(void)
127 /* Turn on PerWE instead of PCIsomething */
128 mtdcr(DCRN_CPC0_PCI_BASE
, mfdcr(DCRN_CPC0_PCI_BASE
) | (0x80000000L
>> 27));
130 /* PerCS1 (CF's CS0): base 0xff100000, 16-bit, rw */
131 mtdcr(DCRN_EBC_BASE
, 1);
132 mtdcr(DCRN_EBC_BASE
+ 1, 0xff11a000);
133 mtdcr(DCRN_EBC_BASE
, 0x11);
134 mtdcr(DCRN_EBC_BASE
+ 1, 0x080bd800);
136 /* PerCS2 (CF's CS1): base 0xff200000, 16-bit, rw */
137 mtdcr(DCRN_EBC_BASE
, 2);
138 mtdcr(DCRN_EBC_BASE
+ 1, 0xff21a000);
139 mtdcr(DCRN_EBC_BASE
, 0x12);
140 mtdcr(DCRN_EBC_BASE
+ 1, 0x080bd800);
142 /* Remap physical address space */
143 addr
= ioremap_nocache(0xff100000, 4096);
144 caddr
= ioremap_nocache(0xff200000, 4096);
146 /* Set interrupt to low-to-high-edge-triggered */
147 mtdcr(UIC0_TR
, mfdcr(UIC0_TR
) & ~(0x80000000L
>> IRQ
));
148 mtdcr(UIC0_PR
, mfdcr(UIC0_PR
) | (0x80000000L
>> IRQ
));
150 ide_magicbox_register((unsigned long)addr
, (unsigned long)caddr
, IRQ
);
This page took 0.164925 seconds and 5 git commands to generate.