Linux v2.6.13
[linux-2.6/next.git] / drivers / ide / h8300 / ide-h8300.c
blobfb91cb8bf2d29613624f3df1710685e9a040431a
1 /*
2 * drivers/ide/ide-h8300.c
3 * H8/300 generic IDE interface
4 */
6 #include <linux/init.h>
7 #include <linux/ide.h>
8 #include <linux/config.h>
10 #include <asm/io.h>
11 #include <asm/irq.h>
13 #define bswap(d) \
14 ({ \
15 u16 r; \
16 __asm__("mov.b %w1,r1h\n\t" \
17 "mov.b %x1,r1l\n\t" \
18 "mov.w r1,%0" \
19 :"=r"(r) \
20 :"r"(d) \
21 :"er1"); \
22 (r); \
25 static void mm_outw(u16 d, unsigned long a)
27 __asm__("mov.b %w0,r2h\n\t"
28 "mov.b %x0,r2l\n\t"
29 "mov.w r2,@%1"
31 :"r"(d),"r"(a)
32 :"er2");
35 static u16 mm_inw(unsigned long a)
37 register u16 r __asm__("er0");
38 __asm__("mov.w @%1,r2\n\t"
39 "mov.b r2l,%x0\n\t"
40 "mov.b r2h,%w0"
41 :"=r"(r)
42 :"r"(a)
43 :"er2");
44 return r;
47 static void mm_outsw(unsigned long addr, void *buf, u32 len)
49 unsigned short *bp = (unsigned short *)buf;
50 for (; len > 0; len--, bp++)
51 *(volatile u16 *)addr = bswap(*bp);
54 static void mm_insw(unsigned long addr, void *buf, u32 len)
56 unsigned short *bp = (unsigned short *)buf;
57 for (; len > 0; len--, bp++)
58 *bp = bswap(*(volatile u16 *)addr);
61 #define H8300_IDE_GAP (2)
63 static inline void hw_setup(hw_regs_t *hw)
65 int i;
67 memset(hw, 0, sizeof(hw_regs_t));
68 for (i = 0; i <= IDE_STATUS_OFFSET; i++)
69 hw->io_ports[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
70 hw->io_ports[IDE_CONTROL_OFFSET] = CONFIG_H8300_IDE_ALT;
71 hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
72 hw->dma = NO_DMA;
73 hw->chipset = ide_generic;
76 static inline void hwif_setup(ide_hwif_t *hwif)
78 default_hwif_iops(hwif);
80 hwif->mmio = 2;
81 hwif->OUTW = mm_outw;
82 hwif->OUTSW = mm_outsw;
83 hwif->INW = mm_inw;
84 hwif->INSW = mm_insw;
85 hwif->OUTL = NULL;
86 hwif->INL = NULL;
87 hwif->OUTSL = NULL;
88 hwif->INSL = NULL;
91 void __init h8300_ide_init(void)
93 hw_regs_t hw;
94 ide_hwif_t *hwif;
95 int idx;
97 if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
98 goto out_busy;
99 if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
100 release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
101 goto out_busy;
104 hw_setup(&hw);
106 /* register if */
107 idx = ide_register_hw(&hw, &hwif);
108 if (idx == -1) {
109 printk(KERN_ERR "ide-h8300: IDE I/F register failed\n");
110 return;
113 hwif_setup(hwif);
114 printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", idx);
115 return;
117 out_busy:
118 printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");