bcm963xx: serial port 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 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
104 if (ide_register_hw(&hw, 1, &hwif) != -1)
105 #else
106 if (ide_register_hw(&hw, NULL, 1, &hwif) != -1)
107 #endif
108 {
109 printk(KERN_NOTICE "magicbox-ide: Registered IDE-CF driver\n");
110 hwif->mmio = 2;
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;
121 }
122 }
123
124 void __init ide_magicbox_init(void)
125 {
126 volatile u16 *addr;
127 volatile u16 *caddr;
128
129 /* Turn on PerWE instead of PCIsomething */
130 mtdcr(DCRN_CPC0_PCI_BASE, mfdcr(DCRN_CPC0_PCI_BASE) | (0x80000000L >> 27));
131
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);
137
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);
143
144 /* Remap physical address space */
145 addr = ioremap_nocache(0xff100000, 4096);
146 caddr = ioremap_nocache(0xff200000, 4096);
147
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));
151
152 ide_magicbox_register((unsigned long)addr, (unsigned long)caddr, IRQ);
153 }
154
This page took 0.052534 seconds and 5 git commands to generate.