Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * H8/300 generic IDE interface |
3 | */ | |
4 | ||
5 | #include <linux/init.h> | |
6 | #include <linux/ide.h> | |
1da177e4 LT |
7 | |
8 | #include <asm/io.h> | |
9 | #include <asm/irq.h> | |
10 | ||
eb3aff55 BZ |
11 | #define DRV_NAME "ide-h8300" |
12 | ||
1da177e4 LT |
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); \ | |
23 | }) | |
24 | ||
25 | static void mm_outw(u16 d, unsigned long a) | |
26 | { | |
27 | __asm__("mov.b %w0,r2h\n\t" | |
28 | "mov.b %x0,r2l\n\t" | |
29 | "mov.w r2,@%1" | |
30 | : | |
31 | :"r"(d),"r"(a) | |
32 | :"er2"); | |
33 | } | |
34 | ||
35 | static u16 mm_inw(unsigned long a) | |
36 | { | |
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; | |
45 | } | |
46 | ||
92fcaaa8 BZ |
47 | static void h8300_tf_load(ide_drive_t *drive, ide_task_t *task) |
48 | { | |
49 | ide_hwif_t *hwif = drive->hwif; | |
50 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
51 | struct ide_taskfile *tf = &task->tf; | |
52 | u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; | |
53 | ||
54 | if (task->tf_flags & IDE_TFLAG_FLAGGED) | |
55 | HIHI = 0xFF; | |
56 | ||
92fcaaa8 BZ |
57 | if (task->tf_flags & IDE_TFLAG_OUT_DATA) |
58 | mm_outw((tf->hob_data << 8) | tf->data, io_ports->data_addr); | |
59 | ||
60 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) | |
61 | outb(tf->hob_feature, io_ports->feature_addr); | |
62 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) | |
63 | outb(tf->hob_nsect, io_ports->nsect_addr); | |
64 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) | |
65 | outb(tf->hob_lbal, io_ports->lbal_addr); | |
66 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) | |
67 | outb(tf->hob_lbam, io_ports->lbam_addr); | |
68 | if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) | |
69 | outb(tf->hob_lbah, io_ports->lbah_addr); | |
70 | ||
71 | if (task->tf_flags & IDE_TFLAG_OUT_FEATURE) | |
72 | outb(tf->feature, io_ports->feature_addr); | |
73 | if (task->tf_flags & IDE_TFLAG_OUT_NSECT) | |
74 | outb(tf->nsect, io_ports->nsect_addr); | |
75 | if (task->tf_flags & IDE_TFLAG_OUT_LBAL) | |
76 | outb(tf->lbal, io_ports->lbal_addr); | |
77 | if (task->tf_flags & IDE_TFLAG_OUT_LBAM) | |
78 | outb(tf->lbam, io_ports->lbam_addr); | |
79 | if (task->tf_flags & IDE_TFLAG_OUT_LBAH) | |
80 | outb(tf->lbah, io_ports->lbah_addr); | |
81 | ||
82 | if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) | |
83 | outb((tf->device & HIHI) | drive->select.all, | |
84 | io_ports->device_addr); | |
85 | } | |
86 | ||
87 | static void h8300_tf_read(ide_drive_t *drive, ide_task_t *task) | |
88 | { | |
89 | ide_hwif_t *hwif = drive->hwif; | |
90 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
91 | struct ide_taskfile *tf = &task->tf; | |
92 | ||
93 | if (task->tf_flags & IDE_TFLAG_IN_DATA) { | |
94 | u16 data = mm_inw(io_ports->data_addr); | |
95 | ||
96 | tf->data = data & 0xff; | |
97 | tf->hob_data = (data >> 8) & 0xff; | |
98 | } | |
99 | ||
100 | /* be sure we're looking at the low order bits */ | |
ff074883 | 101 | outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); |
92fcaaa8 | 102 | |
92eb4380 BZ |
103 | if (task->tf_flags & IDE_TFLAG_IN_FEATURE) |
104 | tf->feature = inb(io_ports->feature_addr); | |
92fcaaa8 BZ |
105 | if (task->tf_flags & IDE_TFLAG_IN_NSECT) |
106 | tf->nsect = inb(io_ports->nsect_addr); | |
107 | if (task->tf_flags & IDE_TFLAG_IN_LBAL) | |
108 | tf->lbal = inb(io_ports->lbal_addr); | |
109 | if (task->tf_flags & IDE_TFLAG_IN_LBAM) | |
110 | tf->lbam = inb(io_ports->lbam_addr); | |
111 | if (task->tf_flags & IDE_TFLAG_IN_LBAH) | |
112 | tf->lbah = inb(io_ports->lbah_addr); | |
113 | if (task->tf_flags & IDE_TFLAG_IN_DEVICE) | |
114 | tf->device = inb(io_ports->device_addr); | |
115 | ||
116 | if (task->tf_flags & IDE_TFLAG_LBA48) { | |
ff074883 | 117 | outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); |
92fcaaa8 BZ |
118 | |
119 | if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) | |
120 | tf->hob_feature = inb(io_ports->feature_addr); | |
121 | if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT) | |
122 | tf->hob_nsect = inb(io_ports->nsect_addr); | |
123 | if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL) | |
124 | tf->hob_lbal = inb(io_ports->lbal_addr); | |
125 | if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM) | |
126 | tf->hob_lbam = inb(io_ports->lbam_addr); | |
127 | if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH) | |
128 | tf->hob_lbah = inb(io_ports->lbah_addr); | |
129 | } | |
130 | } | |
131 | ||
1da177e4 LT |
132 | static void mm_outsw(unsigned long addr, void *buf, u32 len) |
133 | { | |
134 | unsigned short *bp = (unsigned short *)buf; | |
135 | for (; len > 0; len--, bp++) | |
136 | *(volatile u16 *)addr = bswap(*bp); | |
137 | } | |
138 | ||
139 | static void mm_insw(unsigned long addr, void *buf, u32 len) | |
140 | { | |
141 | unsigned short *bp = (unsigned short *)buf; | |
142 | for (; len > 0; len--, bp++) | |
143 | *bp = bswap(*(volatile u16 *)addr); | |
144 | } | |
145 | ||
f04ff9cb BZ |
146 | static void h8300_input_data(ide_drive_t *drive, struct request *rq, |
147 | void *buf, unsigned int len) | |
148 | { | |
149 | mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2); | |
150 | } | |
151 | ||
152 | static void h8300_output_data(ide_drive_t *drive, struct request *rq, | |
153 | void *buf, unsigned int len) | |
154 | { | |
155 | mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2); | |
156 | } | |
157 | ||
1da177e4 LT |
158 | #define H8300_IDE_GAP (2) |
159 | ||
160 | static inline void hw_setup(hw_regs_t *hw) | |
161 | { | |
162 | int i; | |
163 | ||
164 | memset(hw, 0, sizeof(hw_regs_t)); | |
4c3032d8 BZ |
165 | for (i = 0; i <= 7; i++) |
166 | hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i; | |
167 | hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT; | |
1da177e4 | 168 | hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ; |
1da177e4 LT |
169 | hw->chipset = ide_generic; |
170 | } | |
171 | ||
172 | static inline void hwif_setup(ide_hwif_t *hwif) | |
173 | { | |
174 | default_hwif_iops(hwif); | |
175 | ||
92fcaaa8 BZ |
176 | hwif->tf_load = h8300_tf_load; |
177 | hwif->tf_read = h8300_tf_read; | |
178 | ||
f04ff9cb BZ |
179 | hwif->input_data = h8300_input_data; |
180 | hwif->output_data = h8300_output_data; | |
1da177e4 LT |
181 | } |
182 | ||
f81eb80b BZ |
183 | static const struct ide_port_info h8300_port_info = { |
184 | .host_flags = IDE_HFLAG_NO_IO_32BIT | IDE_HFLAG_NO_DMA, | |
185 | }; | |
186 | ||
ade2daf9 | 187 | static int __init h8300_ide_init(void) |
1da177e4 | 188 | { |
1da177e4 | 189 | ide_hwif_t *hwif; |
cbb010c1 | 190 | int index; |
c97c6aca | 191 | hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; |
8ac4ce74 | 192 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
1da177e4 | 193 | |
740c397c BZ |
194 | printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n"); |
195 | ||
1da177e4 LT |
196 | if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300")) |
197 | goto out_busy; | |
198 | if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) { | |
199 | release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8); | |
200 | goto out_busy; | |
201 | } | |
202 | ||
203 | hw_setup(&hw); | |
204 | ||
eb3aff55 BZ |
205 | hwif = ide_find_port_slot(&h8300_port_info); |
206 | if (hwif == NULL) | |
ade2daf9 | 207 | return -ENOENT; |
1da177e4 | 208 | |
cbb010c1 | 209 | index = hwif->index; |
1da177e4 | 210 | hwif_setup(hwif); |
8ac4ce74 BZ |
211 | |
212 | idx[0] = index; | |
213 | ||
c97c6aca | 214 | ide_device_add(idx, &h8300_port_info, hws); |
8ac4ce74 | 215 | |
ade2daf9 | 216 | return 0; |
1da177e4 LT |
217 | |
218 | out_busy: | |
219 | printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n"); | |
ade2daf9 BZ |
220 | |
221 | return -EBUSY; | |
1da177e4 | 222 | } |
ade2daf9 BZ |
223 | |
224 | module_init(h8300_ide_init); | |
f95dc320 AB |
225 | |
226 | MODULE_LICENSE("GPL"); |