Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Uwe Zeisberger | f30c226 | 2006-10-03 23:01:26 +0200 | [diff] [blame] | 2 | * drivers/ide/h8300/ide-h8300.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * H8/300 generic IDE interface |
| 4 | */ |
| 5 | |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/ide.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/irq.h> |
| 11 | |
| 12 | #define bswap(d) \ |
| 13 | ({ \ |
| 14 | u16 r; \ |
| 15 | __asm__("mov.b %w1,r1h\n\t" \ |
| 16 | "mov.b %x1,r1l\n\t" \ |
| 17 | "mov.w r1,%0" \ |
| 18 | :"=r"(r) \ |
| 19 | :"r"(d) \ |
| 20 | :"er1"); \ |
| 21 | (r); \ |
| 22 | }) |
| 23 | |
| 24 | static void mm_outw(u16 d, unsigned long a) |
| 25 | { |
| 26 | __asm__("mov.b %w0,r2h\n\t" |
| 27 | "mov.b %x0,r2l\n\t" |
| 28 | "mov.w r2,@%1" |
| 29 | : |
| 30 | :"r"(d),"r"(a) |
| 31 | :"er2"); |
| 32 | } |
| 33 | |
| 34 | static u16 mm_inw(unsigned long a) |
| 35 | { |
| 36 | register u16 r __asm__("er0"); |
| 37 | __asm__("mov.w @%1,r2\n\t" |
| 38 | "mov.b r2l,%x0\n\t" |
| 39 | "mov.b r2h,%w0" |
| 40 | :"=r"(r) |
| 41 | :"r"(a) |
| 42 | :"er2"); |
| 43 | return r; |
| 44 | } |
| 45 | |
| 46 | static void mm_outsw(unsigned long addr, void *buf, u32 len) |
| 47 | { |
| 48 | unsigned short *bp = (unsigned short *)buf; |
| 49 | for (; len > 0; len--, bp++) |
| 50 | *(volatile u16 *)addr = bswap(*bp); |
| 51 | } |
| 52 | |
| 53 | static void mm_insw(unsigned long addr, void *buf, u32 len) |
| 54 | { |
| 55 | unsigned short *bp = (unsigned short *)buf; |
| 56 | for (; len > 0; len--, bp++) |
| 57 | *bp = bswap(*(volatile u16 *)addr); |
| 58 | } |
| 59 | |
| 60 | #define H8300_IDE_GAP (2) |
| 61 | |
| 62 | static inline void hw_setup(hw_regs_t *hw) |
| 63 | { |
| 64 | int i; |
| 65 | |
| 66 | memset(hw, 0, sizeof(hw_regs_t)); |
| 67 | for (i = 0; i <= IDE_STATUS_OFFSET; i++) |
| 68 | hw->io_ports[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i; |
| 69 | hw->io_ports[IDE_CONTROL_OFFSET] = CONFIG_H8300_IDE_ALT; |
| 70 | hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | hw->chipset = ide_generic; |
| 72 | } |
| 73 | |
| 74 | static inline void hwif_setup(ide_hwif_t *hwif) |
| 75 | { |
| 76 | default_hwif_iops(hwif); |
| 77 | |
Bartlomiej Zolnierkiewicz | 2ad1e55 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 78 | hwif->mmio = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | hwif->OUTW = mm_outw; |
| 80 | hwif->OUTSW = mm_outsw; |
| 81 | hwif->INW = mm_inw; |
| 82 | hwif->INSW = mm_insw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | hwif->OUTSL = NULL; |
| 84 | hwif->INSL = NULL; |
| 85 | } |
| 86 | |
| 87 | void __init h8300_ide_init(void) |
| 88 | { |
| 89 | hw_regs_t hw; |
| 90 | ide_hwif_t *hwif; |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 91 | int index; |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame^] | 92 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300")) |
| 95 | goto out_busy; |
| 96 | if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) { |
| 97 | release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8); |
| 98 | goto out_busy; |
| 99 | } |
| 100 | |
| 101 | hw_setup(&hw); |
| 102 | |
| 103 | /* register if */ |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 104 | hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); |
| 105 | if (hwif == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | printk(KERN_ERR "ide-h8300: IDE I/F register failed\n"); |
| 107 | return; |
| 108 | } |
| 109 | |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 110 | index = hwif->index; |
| 111 | ide_init_port_data(hwif, index); |
| 112 | ide_init_port_hw(hwif, &hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | hwif_setup(hwif); |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 114 | printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", index); |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame^] | 115 | |
| 116 | idx[0] = index; |
| 117 | |
| 118 | ide_device_add(idx); |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | return; |
| 121 | |
| 122 | out_busy: |
| 123 | printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n"); |
| 124 | } |