MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / ide / pci / p20575.c
blob8525a2c00ca1b5e7fd6508d7e78ed40b3ce115b3
1 /*
2 * linux/drivers/ide/pci/p20575.c
3 */
5 #include <linux/module.h>
6 #include <linux/types.h>
7 #include <linux/kernel.h>
8 #include <linux/init.h>
9 #include <linux/interrupt.h>
10 #include <linux/blkdev.h>
11 #include <linux/hdreg.h>
12 #include <linux/pci.h>
13 #include <linux/delay.h>
14 #include <linux/ide.h>
15 #include <linux/ioport.h>
16 #include <asm/io.h>
18 #if 0
19 #define PRINTK(x...) printk(x)
20 #else
21 #define PRINTK(x...) do { } while (0)
22 #endif
24 #if 0
25 static void hexdump(void *v, unsigned int len)
27 unsigned int p = (unsigned int) v;
28 int i;
30 for (i = 0; (i < (len/4)); i++) {
31 if ((i % 4) == 0) printk("%08x: ", (int)p);
32 printk("%08x ", readl(p));
33 p += 4;
34 if (((i+1) % 4) == 0) printk("\n");
36 if ((i % 4) != 0) printk("\n");
38 #endif
40 void *p20575_iomap;
42 static u8 p20575_inb(unsigned long port)
44 u8 v;
45 PRINTK("p20575_inb(port=%x)", (int)port);
46 v = readl(p20575_iomap+port);
47 PRINTK("=%x\n", (int)v);
48 return v;
51 static u16 p20575_inw(unsigned long port)
53 u16 v;
54 PRINTK("p20575_inw(port=%x)", (int)port);
55 v = readl(p20575_iomap+port);
56 PRINTK("=%x\n", (int)v);
57 return v;
60 static u32 p20575_inl(unsigned long port)
62 u32 v;
63 PRINTK("p20575_inl(port=%x)", (int)port);
64 v = readl(p20575_iomap+port);
65 PRINTK("=%x\n", (int)v);
66 return v;
69 static void p20575_outb(u8 val, unsigned long port)
71 PRINTK("p20575_outb(val=%x,port=%x)\n", (int)val, (int)port);
72 writel(val, p20575_iomap+port);
75 static void p20575_outbsync(ide_drive_t *drive, u8 val, unsigned long port)
77 PRINTK("p20575_outb(val=%x,port=%x)\n", (int)val, (int)port);
78 writel(val, p20575_iomap+port);
81 static void p20575_outw(u16 val, unsigned long port)
83 PRINTK("p20575_outw(val=%x,port=%x)\n", (int)val, (int)port);
84 writel(val, p20575_iomap+port);
87 static void p20575_outl(u32 val, unsigned long port)
89 PRINTK("p20575_outl(val=%x,port=%x)\n", (int)val, (int)port);
90 writel(val, p20575_iomap+port);
93 static void p20575_outsw(unsigned long port, void *buf, u32 len)
95 u16 w, *wp = buf;
96 PRINTK("p20575_outsw(port=%x,buf=%x,len=%x)\n", (int)port, (int)buf, len);
97 while (len--) {
98 w = *wp++;
99 w = (w << 8) | (w >> 8);
100 writel(w, p20575_iomap+port);
104 static void p20575_insw(unsigned long port, void *buf, u32 len)
106 u16 w, *wp = buf;
107 PRINTK("p20575_insw(port=%x,buf=%x,len=%x)\n", (int)port, (int)buf, len);
108 while (len--) {
109 w = readl(p20575_iomap+port);
110 *wp++ = (w << 8) | (w >> 8);
114 static int p20575_ack_intr(ide_hwif_t *hwif)
116 unsigned int v;
118 v = readl(p20575_iomap+0x40);
119 writel(v, p20575_iomap+0x40);
120 writel(1, p20575_iomap+(2*4));
121 return 1;
124 static void __devinit p20575_init_iops(ide_hwif_t *hwif)
126 hw_regs_t hw;
128 PRINTK("%s(%d): p20575_init_iops()\n", __FILE__, __LINE__);
130 memset(&hw, 0, sizeof(hw));
131 hw.io_ports[IDE_DATA_OFFSET] = 0x300;
132 hw.io_ports[IDE_ERROR_OFFSET] = 0x304;
133 hw.io_ports[IDE_NSECTOR_OFFSET] = 0x308;
134 hw.io_ports[IDE_SECTOR_OFFSET] = 0x30c;
135 hw.io_ports[IDE_LCYL_OFFSET] = 0x310;
136 hw.io_ports[IDE_HCYL_OFFSET] = 0x314;
137 hw.io_ports[IDE_SELECT_OFFSET] = 0x318;
138 hw.io_ports[IDE_STATUS_OFFSET] = 0x31C;
139 hw.io_ports[IDE_CONTROL_OFFSET] = 0x338;
140 hw.irq = hwif->pci_dev->irq;
141 hw.ack_intr = p20575_ack_intr;
143 hwif->INB = p20575_inb;
144 hwif->INW = p20575_inw;
145 hwif->INL = p20575_inl;
146 hwif->OUTB = p20575_outb;
147 hwif->OUTBSYNC = p20575_outbsync;
148 hwif->OUTW = p20575_outw;
149 hwif->OUTL = p20575_outl;
150 hwif->OUTSW = p20575_outsw;
151 hwif->INSW = p20575_insw;
153 hwif->mmio = 2;
155 memcpy(&hwif->hw, &hw, sizeof(hw));
156 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
159 static unsigned int __devinit p20575_init_chipset(struct pci_dev *dev, const char *name)
161 PRINTK("%s(%d): p20575_init_chipset(name=%s) -> irq=%d\n", __FILE__, __LINE__, name, dev->irq);
163 p20575_iomap = ioremap(0x48060000, 0x1000);
164 PRINTK("%s(%d): iomap=%x\n", __FILE__, __LINE__, (int)p20575_iomap);
166 writel(2, p20575_iomap+0x360);
167 writel(1, p20575_iomap+(2*4));
169 return dev->irq;
172 static void __devinit p20575_init_hwif(ide_hwif_t *hwif)
174 PRINTK("%s(%d): p20575_init_hwif()\n", __FILE__, __LINE__);
176 hwif->autodma = 0;
177 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
180 static int __devinit p20575_init_setup(struct pci_dev *dev, ide_pci_device_t *d)
182 PRINTK("%s(%d): p20575_init_setup()\n", __FILE__, __LINE__);
183 return ide_setup_pci_device(dev, d);
186 static ide_pci_device_t p20575_chipset __devinitdata = {
187 .name = "P20575",
188 .init_setup = p20575_init_setup,
189 .init_chipset = p20575_init_chipset,
190 .init_iops = p20575_init_iops,
191 .init_hwif = p20575_init_hwif,
192 .channels = 1,
193 .autodma = AUTODMA,
194 .bootable = ON_BOARD,
195 .flags = IDEPCI_FLAG_ISA_PORTS,
198 static int __devinit p20575_init_one(struct pci_dev *dev, const struct pci_device_id *id)
200 PRINTK("%s(%d): p20575_init_one()\n", __FILE__, __LINE__);
201 return p20575_chipset.init_setup(dev, &p20575_chipset);
204 static struct pci_device_id p20575_pci_tbl[] = {
205 { PCI_VENDOR_ID_PROMISE, 0x3575, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
206 { 0, },
209 MODULE_DEVICE_TABLE(pci, p20575_pci_tbl);
211 static struct pci_driver driver = {
212 .name = "P20575-IDE",
213 .id_table = p20575_pci_tbl,
214 .probe = p20575_init_one,
217 static int p20575_ide_init(void)
219 PRINTK("%s(%d): p20575_ide_init()\n", __FILE__, __LINE__);
220 return ide_pci_register_driver(&driver);
223 module_init(p20575_ide_init);
225 MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
226 MODULE_DESCRIPTION("PCI driver module for PATA channel of Promise 20575");
227 MODULE_LICENSE("GPL");