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