ide-h8300.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * drivers/ide/ide-h8300.c
  3. * H8/300 generic IDE interface
  4. */
  5. #include <linux/init.h>
  6. #include <linux/ide.h>
  7. #include <linux/config.h>
  8. #include <asm/io.h>
  9. #include <asm/irq.h>
  10. #define bswap(d) \
  11. ({ \
  12. u16 r; \
  13. __asm__("mov.b %w1,r1h\n\t" \
  14. "mov.b %x1,r1l\n\t" \
  15. "mov.w r1,%0" \
  16. :"=r"(r) \
  17. :"r"(d) \
  18. :"er1"); \
  19. (r); \
  20. })
  21. static void mm_outw(u16 d, unsigned long a)
  22. {
  23. __asm__("mov.b %w0,r2h\n\t"
  24. "mov.b %x0,r2l\n\t"
  25. "mov.w r2,@%1"
  26. :
  27. :"r"(d),"r"(a)
  28. :"er2");
  29. }
  30. static u16 mm_inw(unsigned long a)
  31. {
  32. register u16 r __asm__("er0");
  33. __asm__("mov.w @%1,r2\n\t"
  34. "mov.b r2l,%x0\n\t"
  35. "mov.b r2h,%w0"
  36. :"=r"(r)
  37. :"r"(a)
  38. :"er2");
  39. return r;
  40. }
  41. static void mm_outsw(unsigned long addr, void *buf, u32 len)
  42. {
  43. unsigned short *bp = (unsigned short *)buf;
  44. for (; len > 0; len--, bp++)
  45. *(volatile u16 *)addr = bswap(*bp);
  46. }
  47. static void mm_insw(unsigned long addr, void *buf, u32 len)
  48. {
  49. unsigned short *bp = (unsigned short *)buf;
  50. for (; len > 0; len--, bp++)
  51. *bp = bswap(*(volatile u16 *)addr);
  52. }
  53. #define H8300_IDE_GAP (2)
  54. static inline void hw_setup(hw_regs_t *hw)
  55. {
  56. int i;
  57. memset(hw, 0, sizeof(hw_regs_t));
  58. for (i = 0; i <= IDE_STATUS_OFFSET; i++)
  59. hw->io_ports[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
  60. hw->io_ports[IDE_CONTROL_OFFSET] = CONFIG_H8300_IDE_ALT;
  61. hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
  62. hw->dma = NO_DMA;
  63. hw->chipset = ide_generic;
  64. }
  65. static inline void hwif_setup(ide_hwif_t *hwif)
  66. {
  67. default_hwif_iops(hwif);
  68. hwif->mmio = 2;
  69. hwif->OUTW = mm_outw;
  70. hwif->OUTSW = mm_outsw;
  71. hwif->INW = mm_inw;
  72. hwif->INSW = mm_insw;
  73. hwif->OUTL = NULL;
  74. hwif->INL = NULL;
  75. hwif->OUTSL = NULL;
  76. hwif->INSL = NULL;
  77. }
  78. void __init h8300_ide_init(void)
  79. {
  80. hw_regs_t hw;
  81. ide_hwif_t *hwif;
  82. int idx;
  83. if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
  84. goto out_busy;
  85. if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
  86. release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
  87. goto out_busy;
  88. }
  89. hw_setup(&hw);
  90. /* register if */
  91. idx = ide_register_hw(&hw, &hwif);
  92. if (idx == -1) {
  93. printk(KERN_ERR "ide-h8300: IDE I/F register failed\n");
  94. return;
  95. }
  96. hwif_setup(hwif);
  97. printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", idx);
  98. return;
  99. out_busy:
  100. printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
  101. }