Linux 2.6.20.7
[linux/fpc-iii.git] / drivers / ide / h8300 / ide-h8300.c
blob608ca871744b1a7e4ca81ec468e9fc8702343fe0
1 /*
2 * drivers/ide/h8300/ide-h8300.c
3 * H8/300 generic IDE interface
4 */
6 #include <linux/init.h>
7 #include <linux/ide.h>
9 #include <asm/io.h>
10 #include <asm/irq.h>
12 #define bswap(d) \
13 ({ \
14 u16 r; \
15 __asm__("mov.b %w1,r1h\n\t" \
16 "mov.b %x1,r1l\n\t" \
17 "mov.w r1,%0" \
18 :"=r"(r) \
19 :"r"(d) \
20 :"er1"); \
21 (r); \
24 static void mm_outw(u16 d, unsigned long a)
26 __asm__("mov.b %w0,r2h\n\t"
27 "mov.b %x0,r2l\n\t"
28 "mov.w r2,@%1"
30 :"r"(d),"r"(a)
31 :"er2");
34 static u16 mm_inw(unsigned long a)
36 register u16 r __asm__("er0");
37 __asm__("mov.w @%1,r2\n\t"
38 "mov.b r2l,%x0\n\t"
39 "mov.b r2h,%w0"
40 :"=r"(r)
41 :"r"(a)
42 :"er2");
43 return r;
46 static void mm_outsw(unsigned long addr, void *buf, u32 len)
48 unsigned short *bp = (unsigned short *)buf;
49 for (; len > 0; len--, bp++)
50 *(volatile u16 *)addr = bswap(*bp);
53 static void mm_insw(unsigned long addr, void *buf, u32 len)
55 unsigned short *bp = (unsigned short *)buf;
56 for (; len > 0; len--, bp++)
57 *bp = bswap(*(volatile u16 *)addr);
60 #define H8300_IDE_GAP (2)
62 static inline void hw_setup(hw_regs_t *hw)
64 int i;
66 memset(hw, 0, sizeof(hw_regs_t));
67 for (i = 0; i <= IDE_STATUS_OFFSET; i++)
68 hw->io_ports[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
69 hw->io_ports[IDE_CONTROL_OFFSET] = CONFIG_H8300_IDE_ALT;
70 hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
71 hw->dma = NO_DMA;
72 hw->chipset = ide_generic;
75 static inline void hwif_setup(ide_hwif_t *hwif)
77 default_hwif_iops(hwif);
79 hwif->mmio = 2;
80 hwif->OUTW = mm_outw;
81 hwif->OUTSW = mm_outsw;
82 hwif->INW = mm_inw;
83 hwif->INSW = mm_insw;
84 hwif->OUTL = NULL;
85 hwif->INL = NULL;
86 hwif->OUTSL = NULL;
87 hwif->INSL = NULL;
90 void __init h8300_ide_init(void)
92 hw_regs_t hw;
93 ide_hwif_t *hwif;
94 int idx;
96 if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
97 goto out_busy;
98 if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
99 release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
100 goto out_busy;
103 hw_setup(&hw);
105 /* register if */
106 idx = ide_register_hw(&hw, &hwif);
107 if (idx == -1) {
108 printk(KERN_ERR "ide-h8300: IDE I/F register failed\n");
109 return;
112 hwif_setup(hwif);
113 printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", idx);
114 return;
116 out_busy:
117 printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");