V4L/DVB (10725): saa7185: convert to v4l2_subdev.
[linux-2.6.git] / drivers / ide / ide-io-std.c
blob45b43dd49cda1ef132f811211ae5775f3bfa95d2
2 #include <linux/kernel.h>
3 #include <linux/ide.h>
5 /*
6 * Conventional PIO operations for ATA devices
7 */
9 static u8 ide_inb(unsigned long port)
11 return (u8) inb(port);
14 static void ide_outb(u8 val, unsigned long port)
16 outb(val, port);
20 * MMIO operations, typically used for SATA controllers
23 static u8 ide_mm_inb(unsigned long port)
25 return (u8) readb((void __iomem *) port);
28 static void ide_mm_outb(u8 value, unsigned long port)
30 writeb(value, (void __iomem *) port);
33 void ide_exec_command(ide_hwif_t *hwif, u8 cmd)
35 if (hwif->host_flags & IDE_HFLAG_MMIO)
36 writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
37 else
38 outb(cmd, hwif->io_ports.command_addr);
40 EXPORT_SYMBOL_GPL(ide_exec_command);
42 u8 ide_read_status(ide_hwif_t *hwif)
44 if (hwif->host_flags & IDE_HFLAG_MMIO)
45 return readb((void __iomem *)hwif->io_ports.status_addr);
46 else
47 return inb(hwif->io_ports.status_addr);
49 EXPORT_SYMBOL_GPL(ide_read_status);
51 u8 ide_read_altstatus(ide_hwif_t *hwif)
53 if (hwif->host_flags & IDE_HFLAG_MMIO)
54 return readb((void __iomem *)hwif->io_ports.ctl_addr);
55 else
56 return inb(hwif->io_ports.ctl_addr);
58 EXPORT_SYMBOL_GPL(ide_read_altstatus);
60 void ide_set_irq(ide_hwif_t *hwif, int on)
62 u8 ctl = ATA_DEVCTL_OBS;
64 if (on == 4) { /* hack for SRST */
65 ctl |= 4;
66 on &= ~4;
69 ctl |= on ? 0 : 2;
71 if (hwif->host_flags & IDE_HFLAG_MMIO)
72 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
73 else
74 outb(ctl, hwif->io_ports.ctl_addr);
76 EXPORT_SYMBOL_GPL(ide_set_irq);
78 void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
80 ide_hwif_t *hwif = drive->hwif;
81 struct ide_io_ports *io_ports = &hwif->io_ports;
82 struct ide_taskfile *tf = &task->tf;
83 void (*tf_outb)(u8 addr, unsigned long port);
84 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
85 u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
87 if (mmio)
88 tf_outb = ide_mm_outb;
89 else
90 tf_outb = ide_outb;
92 if (task->tf_flags & IDE_TFLAG_FLAGGED)
93 HIHI = 0xFF;
95 if (task->tf_flags & IDE_TFLAG_OUT_DATA) {
96 u16 data = (tf->hob_data << 8) | tf->data;
98 if (mmio)
99 writew(data, (void __iomem *)io_ports->data_addr);
100 else
101 outw(data, io_ports->data_addr);
104 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
105 tf_outb(tf->hob_feature, io_ports->feature_addr);
106 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
107 tf_outb(tf->hob_nsect, io_ports->nsect_addr);
108 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
109 tf_outb(tf->hob_lbal, io_ports->lbal_addr);
110 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
111 tf_outb(tf->hob_lbam, io_ports->lbam_addr);
112 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
113 tf_outb(tf->hob_lbah, io_ports->lbah_addr);
115 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
116 tf_outb(tf->feature, io_ports->feature_addr);
117 if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
118 tf_outb(tf->nsect, io_ports->nsect_addr);
119 if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
120 tf_outb(tf->lbal, io_ports->lbal_addr);
121 if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
122 tf_outb(tf->lbam, io_ports->lbam_addr);
123 if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
124 tf_outb(tf->lbah, io_ports->lbah_addr);
126 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
127 tf_outb((tf->device & HIHI) | drive->select,
128 io_ports->device_addr);
130 EXPORT_SYMBOL_GPL(ide_tf_load);
132 void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
134 ide_hwif_t *hwif = drive->hwif;
135 struct ide_io_ports *io_ports = &hwif->io_ports;
136 struct ide_taskfile *tf = &task->tf;
137 void (*tf_outb)(u8 addr, unsigned long port);
138 u8 (*tf_inb)(unsigned long port);
139 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
141 if (mmio) {
142 tf_outb = ide_mm_outb;
143 tf_inb = ide_mm_inb;
144 } else {
145 tf_outb = ide_outb;
146 tf_inb = ide_inb;
149 if (task->tf_flags & IDE_TFLAG_IN_DATA) {
150 u16 data;
152 if (mmio)
153 data = readw((void __iomem *)io_ports->data_addr);
154 else
155 data = inw(io_ports->data_addr);
157 tf->data = data & 0xff;
158 tf->hob_data = (data >> 8) & 0xff;
161 /* be sure we're looking at the low order bits */
162 tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
164 if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
165 tf->feature = tf_inb(io_ports->feature_addr);
166 if (task->tf_flags & IDE_TFLAG_IN_NSECT)
167 tf->nsect = tf_inb(io_ports->nsect_addr);
168 if (task->tf_flags & IDE_TFLAG_IN_LBAL)
169 tf->lbal = tf_inb(io_ports->lbal_addr);
170 if (task->tf_flags & IDE_TFLAG_IN_LBAM)
171 tf->lbam = tf_inb(io_ports->lbam_addr);
172 if (task->tf_flags & IDE_TFLAG_IN_LBAH)
173 tf->lbah = tf_inb(io_ports->lbah_addr);
174 if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
175 tf->device = tf_inb(io_ports->device_addr);
177 if (task->tf_flags & IDE_TFLAG_LBA48) {
178 tf_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
180 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
181 tf->hob_feature = tf_inb(io_ports->feature_addr);
182 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
183 tf->hob_nsect = tf_inb(io_ports->nsect_addr);
184 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
185 tf->hob_lbal = tf_inb(io_ports->lbal_addr);
186 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
187 tf->hob_lbam = tf_inb(io_ports->lbam_addr);
188 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
189 tf->hob_lbah = tf_inb(io_ports->lbah_addr);
192 EXPORT_SYMBOL_GPL(ide_tf_read);
195 * Some localbus EIDE interfaces require a special access sequence
196 * when using 32-bit I/O instructions to transfer data. We call this
197 * the "vlb_sync" sequence, which consists of three successive reads
198 * of the sector count register location, with interrupts disabled
199 * to ensure that the reads all happen together.
201 static void ata_vlb_sync(unsigned long port)
203 (void)inb(port);
204 (void)inb(port);
205 (void)inb(port);
209 * This is used for most PIO data transfers *from* the IDE interface
211 * These routines will round up any request for an odd number of bytes,
212 * so if an odd len is specified, be sure that there's at least one
213 * extra byte allocated for the buffer.
215 void ide_input_data(ide_drive_t *drive, struct request *rq, void *buf,
216 unsigned int len)
218 ide_hwif_t *hwif = drive->hwif;
219 struct ide_io_ports *io_ports = &hwif->io_ports;
220 unsigned long data_addr = io_ports->data_addr;
221 u8 io_32bit = drive->io_32bit;
222 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
224 len++;
226 if (io_32bit) {
227 unsigned long uninitialized_var(flags);
229 if ((io_32bit & 2) && !mmio) {
230 local_irq_save(flags);
231 ata_vlb_sync(io_ports->nsect_addr);
234 if (mmio)
235 __ide_mm_insl((void __iomem *)data_addr, buf, len / 4);
236 else
237 insl(data_addr, buf, len / 4);
239 if ((io_32bit & 2) && !mmio)
240 local_irq_restore(flags);
242 if ((len & 3) >= 2) {
243 if (mmio)
244 __ide_mm_insw((void __iomem *)data_addr,
245 (u8 *)buf + (len & ~3), 1);
246 else
247 insw(data_addr, (u8 *)buf + (len & ~3), 1);
249 } else {
250 if (mmio)
251 __ide_mm_insw((void __iomem *)data_addr, buf, len / 2);
252 else
253 insw(data_addr, buf, len / 2);
256 EXPORT_SYMBOL_GPL(ide_input_data);
259 * This is used for most PIO data transfers *to* the IDE interface
261 void ide_output_data(ide_drive_t *drive, struct request *rq, void *buf,
262 unsigned int len)
264 ide_hwif_t *hwif = drive->hwif;
265 struct ide_io_ports *io_ports = &hwif->io_ports;
266 unsigned long data_addr = io_ports->data_addr;
267 u8 io_32bit = drive->io_32bit;
268 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
270 len++;
272 if (io_32bit) {
273 unsigned long uninitialized_var(flags);
275 if ((io_32bit & 2) && !mmio) {
276 local_irq_save(flags);
277 ata_vlb_sync(io_ports->nsect_addr);
280 if (mmio)
281 __ide_mm_outsl((void __iomem *)data_addr, buf, len / 4);
282 else
283 outsl(data_addr, buf, len / 4);
285 if ((io_32bit & 2) && !mmio)
286 local_irq_restore(flags);
288 if ((len & 3) >= 2) {
289 if (mmio)
290 __ide_mm_outsw((void __iomem *)data_addr,
291 (u8 *)buf + (len & ~3), 1);
292 else
293 outsw(data_addr, (u8 *)buf + (len & ~3), 1);
295 } else {
296 if (mmio)
297 __ide_mm_outsw((void __iomem *)data_addr, buf, len / 2);
298 else
299 outsw(data_addr, buf, len / 2);
302 EXPORT_SYMBOL_GPL(ide_output_data);
304 const struct ide_tp_ops default_tp_ops = {
305 .exec_command = ide_exec_command,
306 .read_status = ide_read_status,
307 .read_altstatus = ide_read_altstatus,
309 .set_irq = ide_set_irq,
311 .tf_load = ide_tf_load,
312 .tf_read = ide_tf_read,
314 .input_data = ide_input_data,
315 .output_data = ide_output_data,