add broadcom b44 driver support
[openwrt.git] / target / linux / magicbox / 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/version.h>
8 #include <linux/types.h>
9 #include <linux/mm.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>
16
17
18 #define UIC0_PR 0xc4
19 #define UIC0_TR 0xc5
20 #define IRQ 25
21
22 static int ide_offsets[IDE_NR_PORTS] = {0, 2, 4, 6, 8, 10, 12, 14, -1, -1};
23
24 static u8 magicbox_ide_inb (unsigned long port)
25 {
26 return (u8) (readw((void __iomem *) port) >> 8) & 255;
27 }
28
29 static u16 magicbox_ide_inw (unsigned long port)
30 {
31 return (u16) readw((void __iomem *) port);
32 }
33
34 static void magicbox_ide_insw (unsigned long port, void *addr, u32 count)
35 {
36 u16 *ptr;
37
38 for (ptr = addr; count--; ptr++)
39 *ptr = readw((void __iomem *) port);
40 }
41
42 static u32 magicbox_ide_inl (unsigned long port)
43 {
44 return (u32) readl((void __iomem *) port);
45 }
46
47 static void magicbox_ide_insl (unsigned long port, void *addr, u32 count)
48 {
49 u32 *ptr;
50
51 for (ptr = addr; count--; ptr++)
52 *ptr = readl((void __iomem *) port);
53 }
54
55 static void magicbox_ide_outb (u8 value, unsigned long port)
56 {
57 writew(value << 8, (void __iomem *) port);
58 }
59
60 static void magicbox_ide_outbsync (ide_drive_t *drive, u8 value, unsigned long port)
61 {
62 writew(value << 8, (void __iomem *) port);
63 }
64
65 static void magicbox_ide_outw (u16 value, unsigned long port)
66 {
67 writew(value, (void __iomem *) port);
68 }
69
70 static void magicbox_ide_outsw (unsigned long port, void *addr, u32 count)
71 {
72 u16 *ptr;
73
74 for (ptr = addr; count--; ptr++)
75 writew(*ptr, (void __iomem *) port);
76 }
77
78 static void magicbox_ide_outl (u32 value, unsigned long port)
79 {
80 writel(value, (void __iomem *) port);
81 }
82
83 static void magicbox_ide_outsl (unsigned long port, void *addr, u32 count)
84 {
85 u32 *ptr;
86
87 for (ptr = addr; count--; ptr++)
88 writel(*ptr, (void __iomem *) port);
89 }
90
91
92 static void __init ide_magicbox_register(unsigned long addr,
93 unsigned long caddr, int irq)
94 {
95 hw_regs_t hw;
96 ide_hwif_t *hwif;
97
98 memset(&hw, 0, sizeof(hw));
99 ide_setup_ports(&hw, addr, ide_offsets, caddr + 12, 0, NULL,irq);
100
101 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
102 if (ide_register_hw(&hw, &hwif) != -1)
103 #else
104 if (ide_register_hw(&hw, 1, &hwif) != -1)
105 #endif
106 {
107 printk(KERN_NOTICE "magicbox-ide: Registered IDE-CF driver\n");
108 hwif->mmio = 2;
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;
119 }
120 }
121
122 void __init ide_magicbox_init(void)
123 {
124 volatile u16 *addr;
125 volatile u16 *caddr;
126
127 /* Turn on PerWE instead of PCIsomething */
128 mtdcr(DCRN_CPC0_PCI_BASE, mfdcr(DCRN_CPC0_PCI_BASE) | (0x80000000L >> 27));
129
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);
135
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);
141
142 /* Remap physical address space */
143 addr = ioremap_nocache(0xff100000, 4096);
144 caddr = ioremap_nocache(0xff200000, 4096);
145
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));
149
150 ide_magicbox_register((unsigned long)addr, (unsigned long)caddr, IRQ);
151 }
152
This page took 0.065349 seconds and 5 git commands to generate.