ide-h8300.c 2.2 KB

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