blob: ff8339ed59ab0b2afe072904690de895c67dcc7c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * H8/300 generic IDE interface
3 */
4
5#include <linux/init.h>
6#include <linux/ide.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8#include <asm/io.h>
9#include <asm/irq.h>
10
Bartlomiej Zolnierkiewiczeb3aff52008-07-16 20:33:42 +020011#define DRV_NAME "ide-h8300"
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#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
25static 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
35static 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
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010047static void h8300_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020048{
49 ide_hwif_t *hwif = drive->hwif;
50 struct ide_io_ports *io_ports = &hwif->io_ports;
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010051 struct ide_taskfile *tf = &cmd->tf;
52 u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020053
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010054 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020055 HIHI = 0xFF;
56
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010057 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020058 mm_outw((tf->hob_data << 8) | tf->data, io_ports->data_addr);
59
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010060 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020061 outb(tf->hob_feature, io_ports->feature_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010062 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020063 outb(tf->hob_nsect, io_ports->nsect_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010064 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020065 outb(tf->hob_lbal, io_ports->lbal_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010066 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020067 outb(tf->hob_lbam, io_ports->lbam_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010068 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020069 outb(tf->hob_lbah, io_ports->lbah_addr);
70
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010071 if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020072 outb(tf->feature, io_ports->feature_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010073 if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020074 outb(tf->nsect, io_ports->nsect_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010075 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020076 outb(tf->lbal, io_ports->lbal_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010077 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020078 outb(tf->lbam, io_ports->lbam_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010079 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020080 outb(tf->lbah, io_ports->lbah_addr);
81
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010082 if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE)
Bartlomiej Zolnierkiewicz7f612f22008-10-13 21:39:40 +020083 outb((tf->device & HIHI) | drive->select,
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020084 io_ports->device_addr);
85}
86
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010087static void h8300_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020088{
89 ide_hwif_t *hwif = drive->hwif;
90 struct ide_io_ports *io_ports = &hwif->io_ports;
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010091 struct ide_taskfile *tf = &cmd->tf;
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020092
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010093 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +020094 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 */
Bartlomiej Zolnierkiewiczff074882008-07-15 21:21:50 +0200101 outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200102
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100103 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE)
Bartlomiej Zolnierkiewicz92eb4382008-07-23 19:55:53 +0200104 tf->feature = inb(io_ports->feature_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100105 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200106 tf->nsect = inb(io_ports->nsect_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100107 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200108 tf->lbal = inb(io_ports->lbal_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100109 if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200110 tf->lbam = inb(io_ports->lbam_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100111 if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200112 tf->lbah = inb(io_ports->lbah_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100113 if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200114 tf->device = inb(io_ports->device_addr);
115
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100116 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
Bartlomiej Zolnierkiewiczff074882008-07-15 21:21:50 +0200117 outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200118
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100119 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200120 tf->hob_feature = inb(io_ports->feature_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100121 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200122 tf->hob_nsect = inb(io_ports->nsect_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100123 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200124 tf->hob_lbal = inb(io_ports->lbal_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100125 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200126 tf->hob_lbam = inb(io_ports->lbam_addr);
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +0100127 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
Bartlomiej Zolnierkiewicz92fcaaa2008-04-28 23:44:40 +0200128 tf->hob_lbah = inb(io_ports->lbah_addr);
129 }
130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132static 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
139static 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
Bartlomiej Zolnierkiewiczadb1af92009-03-27 12:46:38 +0100146static void h8300_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
Bartlomiej Zolnierkiewiczf04ff9c2008-04-28 23:44:37 +0200147 void *buf, unsigned int len)
148{
149 mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
150}
151
Bartlomiej Zolnierkiewiczadb1af92009-03-27 12:46:38 +0100152static void h8300_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
Bartlomiej Zolnierkiewiczf04ff9c2008-04-28 23:44:37 +0200153 void *buf, unsigned int len)
154{
155 mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
156}
157
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200158static const struct ide_tp_ops h8300_tp_ops = {
159 .exec_command = ide_exec_command,
160 .read_status = ide_read_status,
161 .read_altstatus = ide_read_altstatus,
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200162
163 .set_irq = ide_set_irq,
164
165 .tf_load = h8300_tf_load,
166 .tf_read = h8300_tf_read,
167
168 .input_data = h8300_input_data,
169 .output_data = h8300_output_data,
170};
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#define H8300_IDE_GAP (2)
173
174static inline void hw_setup(hw_regs_t *hw)
175{
176 int i;
177
178 memset(hw, 0, sizeof(hw_regs_t));
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +0200179 for (i = 0; i <= 7; i++)
180 hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
181 hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 hw->chipset = ide_generic;
184}
185
Bartlomiej Zolnierkiewiczf81eb802008-07-16 20:33:42 +0200186static const struct ide_port_info h8300_port_info = {
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200187 .tp_ops = &h8300_tp_ops,
Bartlomiej Zolnierkiewiczf81eb802008-07-16 20:33:42 +0200188 .host_flags = IDE_HFLAG_NO_IO_32BIT | IDE_HFLAG_NO_DMA,
189};
190
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100191static int __init h8300_ide_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Bartlomiej Zolnierkiewiczc97c6ac2008-07-23 19:55:50 +0200193 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Bartlomiej Zolnierkiewicz740c3972008-07-16 20:33:43 +0200195 printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n");
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
198 goto out_busy;
199 if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
200 release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
201 goto out_busy;
202 }
203
204 hw_setup(&hw);
205
Bartlomiej Zolnierkiewicz6f904d02008-07-23 19:55:57 +0200206 return ide_host_add(&h8300_port_info, hws, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208out_busy:
209 printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100210
211 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100213
214module_init(h8300_ide_init);
Adrian Bunkf95dc322008-04-02 21:22:03 +0200215
216MODULE_LICENSE("GPL");