d1f6d68edba1ac6659f7e01f72bd52d4a08dd19c
[openwrt.git] / target / linux / magicbox-2.6 / files / drivers / ide / ppc / magicbox_ide.c
1 /* Driver for MagicBox 2.0 onboard CompactFlash adapter.
2 * Written by Wojtek Kaniewski <wojtekka@toxygen.net>
3 *
4 * GNU General Public License.
5 */
6
7 #include <linux/types.h>
8 #include <linux/mm.h>
9 #include <linux/interrupt.h>
10 #include <linux/blkdev.h>
11 #include <linux/hdreg.h>
12 #include <linux/ide.h>
13 #include <linux/delay.h>
14 #include <linux/platform_device.h>
15
16
17 #define UIC0_PR 0xc4
18 #define UIC0_TR 0xc5
19 #define IRQ 25
20
21 static int ide_offsets[IDE_NR_PORTS] = {0, 2, 4, 6, 8, 10, 12, 14, -1, -1};
22
23 static u8 magicbox_ide_inb (unsigned long port)
24 {
25 return (u8) (readw((void __iomem *) port) >> 8) & 255;
26 }
27
28 static u16 magicbox_ide_inw (unsigned long port)
29 {
30 return (u16) readw((void __iomem *) port);
31 }
32
33 static void magicbox_ide_insw (unsigned long port, void *addr, u32 count)
34 {
35 u16 *ptr;
36
37 for (ptr = addr; count--; ptr++)
38 *ptr = readw((void __iomem *) port);
39 }
40
41 static u32 magicbox_ide_inl (unsigned long port)
42 {
43 return (u32) readl((void __iomem *) port);
44 }
45
46 static void magicbox_ide_insl (unsigned long port, void *addr, u32 count)
47 {
48 u32 *ptr;
49
50 for (ptr = addr; count--; ptr++)
51 *ptr = readl((void __iomem *) port);
52 }
53
54 static void magicbox_ide_outb (u8 value, unsigned long port)
55 {
56 writew(value << 8, (void __iomem *) port);
57 }
58
59 static void magicbox_ide_outbsync (ide_drive_t *drive, u8 value, unsigned long port)
60 {
61 writew(value << 8, (void __iomem *) port);
62 }
63
64 static void magicbox_ide_outw (u16 value, unsigned long port)
65 {
66 writew(value, (void __iomem *) port);
67 }
68
69 static void magicbox_ide_outsw (unsigned long port, void *addr, u32 count)
70 {
71 u16 *ptr;
72
73 for (ptr = addr; count--; ptr++)
74 writew(*ptr, (void __iomem *) port);
75 }
76
77 static void magicbox_ide_outl (u32 value, unsigned long port)
78 {
79 writel(value, (void __iomem *) port);
80 }
81
82 static void magicbox_ide_outsl (unsigned long port, void *addr, u32 count)
83 {
84 u32 *ptr;
85
86 for (ptr = addr; count--; ptr++)
87 writel(*ptr, (void __iomem *) port);
88 }
89
90
91 static void __init ide_magicbox_register(unsigned long addr,
92 unsigned long caddr, int irq)
93 {
94 hw_regs_t hw;
95 ide_hwif_t *hwif;
96
97 memset(&hw, 0, sizeof(hw));
98 ide_setup_ports(&hw, addr, ide_offsets, caddr + 12, 0, NULL,irq);
99
100 if (ide_register_hw(&hw, &hwif) != -1)
101 {
102 printk(KERN_NOTICE "magicbox-ide: Registered IDE-CF driver\n");
103 hwif->mmio = 2;
104 hwif->drives[0].unmask = 1;
105 hwif->OUTB = magicbox_ide_outb;
106 hwif->OUTBSYNC = magicbox_ide_outbsync;
107 hwif->OUTW = magicbox_ide_outw;
108 hwif->OUTSW = magicbox_ide_outsw;
109 hwif->OUTSL = magicbox_ide_outsl;
110 hwif->INB = magicbox_ide_inb;
111 hwif->INW = magicbox_ide_inw;
112 hwif->INSW = magicbox_ide_insw;
113 hwif->INSL = magicbox_ide_insl;
114 }
115 }
116
117 void __init ide_magicbox_init(void)
118 {
119 volatile u16 *addr;
120 volatile u16 *caddr;
121
122 /* Turn on PerWE instead of PCIsomething */
123 mtdcr(DCRN_CPC0_PCI_BASE, mfdcr(DCRN_CPC0_PCI_BASE) | (0x80000000L >> 27));
124
125 /* PerCS1 (CF's CS0): base 0xff100000, 16-bit, rw */
126 mtdcr(DCRN_EBC_BASE, 1);
127 mtdcr(DCRN_EBC_BASE + 1, 0xff11a000);
128 mtdcr(DCRN_EBC_BASE, 0x11);
129 mtdcr(DCRN_EBC_BASE + 1, 0x080bd800);
130
131 /* PerCS2 (CF's CS1): base 0xff200000, 16-bit, rw */
132 mtdcr(DCRN_EBC_BASE, 2);
133 mtdcr(DCRN_EBC_BASE + 1, 0xff21a000);
134 mtdcr(DCRN_EBC_BASE, 0x12);
135 mtdcr(DCRN_EBC_BASE + 1, 0x080bd800);
136
137 /* Remap physical address space */
138 addr = ioremap_nocache(0xff100000, 4096);
139 caddr = ioremap_nocache(0xff200000, 4096);
140
141 /* Set interrupt to low-to-high-edge-triggered */
142 mtdcr(UIC0_TR, mfdcr(UIC0_TR) & ~(0x80000000L >> IRQ));
143 mtdcr(UIC0_PR, mfdcr(UIC0_PR) | (0x80000000L >> IRQ));
144
145 ide_magicbox_register((unsigned long)addr, (unsigned long)caddr, IRQ);
146 }
147
This page took 0.059801 seconds and 3 git commands to generate.