ide-h8300.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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->chipset = ide_generic;
  62. }
  63. static inline void hwif_setup(ide_hwif_t *hwif)
  64. {
  65. default_hwif_iops(hwif);
  66. hwif->mmio = 1;
  67. hwif->OUTW = mm_outw;
  68. hwif->OUTSW = mm_outsw;
  69. hwif->INW = mm_inw;
  70. hwif->INSW = mm_insw;
  71. hwif->OUTSL = NULL;
  72. hwif->INSL = NULL;
  73. }
  74. void __init h8300_ide_init(void)
  75. {
  76. hw_regs_t hw;
  77. ide_hwif_t *hwif;
  78. int idx;
  79. if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
  80. goto out_busy;
  81. if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
  82. release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
  83. goto out_busy;
  84. }
  85. hw_setup(&hw);
  86. /* register if */
  87. idx = ide_register_hw(&hw, NULL, 1, &hwif);
  88. if (idx == -1) {
  89. printk(KERN_ERR "ide-h8300: IDE I/F register failed\n");
  90. return;
  91. }
  92. hwif_setup(hwif);
  93. printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", idx);
  94. return;
  95. out_busy:
  96. printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
  97. }