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 | |
| 45 | static void mm_outsw(unsigned long addr, void *buf, u32 len) |
| 46 | { |
| 47 | unsigned short *bp = (unsigned short *)buf; |
| 48 | for (; len > 0; len--, bp++) |
| 49 | *(volatile u16 *)addr = bswap(*bp); |
| 50 | } |
| 51 | |
| 52 | static void mm_insw(unsigned long addr, void *buf, u32 len) |
| 53 | { |
| 54 | unsigned short *bp = (unsigned short *)buf; |
| 55 | for (; len > 0; len--, bp++) |
| 56 | *bp = bswap(*(volatile u16 *)addr); |
| 57 | } |
| 58 | |
Bartlomiej Zolnierkiewicz | f04ff9c | 2008-04-28 23:44:37 +0200 | [diff] [blame^] | 59 | static void h8300_input_data(ide_drive_t *drive, struct request *rq, |
| 60 | void *buf, unsigned int len) |
| 61 | { |
| 62 | mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2); |
| 63 | } |
| 64 | |
| 65 | static void h8300_output_data(ide_drive_t *drive, struct request *rq, |
| 66 | void *buf, unsigned int len) |
| 67 | { |
| 68 | mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2); |
| 69 | } |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define H8300_IDE_GAP (2) |
| 72 | |
| 73 | static inline void hw_setup(hw_regs_t *hw) |
| 74 | { |
| 75 | int i; |
| 76 | |
| 77 | memset(hw, 0, sizeof(hw_regs_t)); |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 78 | for (i = 0; i <= 7; i++) |
| 79 | hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i; |
| 80 | hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | hw->chipset = ide_generic; |
| 83 | } |
| 84 | |
| 85 | static inline void hwif_setup(ide_hwif_t *hwif) |
| 86 | { |
| 87 | default_hwif_iops(hwif); |
| 88 | |
Bartlomiej Zolnierkiewicz | f04ff9c | 2008-04-28 23:44:37 +0200 | [diff] [blame^] | 89 | hwif->input_data = h8300_input_data; |
| 90 | hwif->output_data = h8300_output_data; |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | hwif->OUTW = mm_outw; |
| 93 | hwif->OUTSW = mm_outsw; |
| 94 | hwif->INW = mm_inw; |
| 95 | hwif->INSW = mm_insw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | hwif->OUTSL = NULL; |
| 97 | hwif->INSL = NULL; |
| 98 | } |
| 99 | |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 100 | static int __init h8300_ide_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | hw_regs_t hw; |
| 103 | ide_hwif_t *hwif; |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 104 | int index; |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 105 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300")) |
| 108 | goto out_busy; |
| 109 | if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) { |
| 110 | release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8); |
| 111 | goto out_busy; |
| 112 | } |
| 113 | |
| 114 | hw_setup(&hw); |
| 115 | |
Bartlomiej Zolnierkiewicz | 59bff5b | 2008-04-26 17:36:32 +0200 | [diff] [blame] | 116 | hwif = ide_find_port(); |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 117 | if (hwif == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | printk(KERN_ERR "ide-h8300: IDE I/F register failed\n"); |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 119 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 122 | index = hwif->index; |
| 123 | ide_init_port_data(hwif, index); |
| 124 | ide_init_port_hw(hwif, &hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | hwif_setup(hwif); |
Bartlomiej Zolnierkiewicz | 430c5d2 | 2008-04-02 21:22:04 +0200 | [diff] [blame] | 126 | hwif->host_flags = IDE_HFLAG_NO_IO_32BIT; |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 127 | printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", index); |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 128 | |
| 129 | idx[0] = index; |
| 130 | |
Bartlomiej Zolnierkiewicz | c413b9b | 2008-02-02 19:56:31 +0100 | [diff] [blame] | 131 | ide_device_add(idx, NULL); |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 132 | |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 133 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | out_busy: |
| 136 | printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n"); |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 137 | |
| 138 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 140 | |
| 141 | module_init(h8300_ide_init); |
Adrian Bunk | f95dc32 | 2008-04-02 21:22:03 +0200 | [diff] [blame] | 142 | |
| 143 | MODULE_LICENSE("GPL"); |