ide-h8300.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * H8/300 generic IDE interface
  3. */
  4. #include <linux/init.h>
  5. #include <linux/ide.h>
  6. #include <asm/io.h>
  7. #include <asm/irq.h>
  8. #define bswap(d) \
  9. ({ \
  10. u16 r; \
  11. __asm__("mov.b %w1,r1h\n\t" \
  12. "mov.b %x1,r1l\n\t" \
  13. "mov.w r1,%0" \
  14. :"=r"(r) \
  15. :"r"(d) \
  16. :"er1"); \
  17. (r); \
  18. })
  19. static void mm_outw(u16 d, unsigned long a)
  20. {
  21. __asm__("mov.b %w0,r2h\n\t"
  22. "mov.b %x0,r2l\n\t"
  23. "mov.w r2,@%1"
  24. :
  25. :"r"(d),"r"(a)
  26. :"er2");
  27. }
  28. static u16 mm_inw(unsigned long a)
  29. {
  30. register u16 r __asm__("er0");
  31. __asm__("mov.w @%1,r2\n\t"
  32. "mov.b r2l,%x0\n\t"
  33. "mov.b r2h,%w0"
  34. :"=r"(r)
  35. :"r"(a)
  36. :"er2");
  37. return r;
  38. }
  39. static void h8300_tf_load(ide_drive_t *drive, ide_task_t *task)
  40. {
  41. ide_hwif_t *hwif = drive->hwif;
  42. struct ide_io_ports *io_ports = &hwif->io_ports;
  43. struct ide_taskfile *tf = &task->tf;
  44. u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
  45. if (task->tf_flags & IDE_TFLAG_FLAGGED)
  46. HIHI = 0xFF;
  47. ide_set_irq(drive, 1);
  48. if (task->tf_flags & IDE_TFLAG_OUT_DATA)
  49. mm_outw((tf->hob_data << 8) | tf->data, io_ports->data_addr);
  50. if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
  51. outb(tf->hob_feature, io_ports->feature_addr);
  52. if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
  53. outb(tf->hob_nsect, io_ports->nsect_addr);
  54. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
  55. outb(tf->hob_lbal, io_ports->lbal_addr);
  56. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
  57. outb(tf->hob_lbam, io_ports->lbam_addr);
  58. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
  59. outb(tf->hob_lbah, io_ports->lbah_addr);
  60. if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
  61. outb(tf->feature, io_ports->feature_addr);
  62. if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
  63. outb(tf->nsect, io_ports->nsect_addr);
  64. if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
  65. outb(tf->lbal, io_ports->lbal_addr);
  66. if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
  67. outb(tf->lbam, io_ports->lbam_addr);
  68. if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
  69. outb(tf->lbah, io_ports->lbah_addr);
  70. if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
  71. outb((tf->device & HIHI) | drive->select.all,
  72. io_ports->device_addr);
  73. }
  74. static void h8300_tf_read(ide_drive_t *drive, ide_task_t *task)
  75. {
  76. ide_hwif_t *hwif = drive->hwif;
  77. struct ide_io_ports *io_ports = &hwif->io_ports;
  78. struct ide_taskfile *tf = &task->tf;
  79. if (task->tf_flags & IDE_TFLAG_IN_DATA) {
  80. u16 data = mm_inw(io_ports->data_addr);
  81. tf->data = data & 0xff;
  82. tf->hob_data = (data >> 8) & 0xff;
  83. }
  84. /* be sure we're looking at the low order bits */
  85. outb(drive->ctl & ~0x80, io_ports->ctl_addr);
  86. if (task->tf_flags & IDE_TFLAG_IN_NSECT)
  87. tf->nsect = inb(io_ports->nsect_addr);
  88. if (task->tf_flags & IDE_TFLAG_IN_LBAL)
  89. tf->lbal = inb(io_ports->lbal_addr);
  90. if (task->tf_flags & IDE_TFLAG_IN_LBAM)
  91. tf->lbam = inb(io_ports->lbam_addr);
  92. if (task->tf_flags & IDE_TFLAG_IN_LBAH)
  93. tf->lbah = inb(io_ports->lbah_addr);
  94. if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
  95. tf->device = inb(io_ports->device_addr);
  96. if (task->tf_flags & IDE_TFLAG_LBA48) {
  97. outb(drive->ctl | 0x80, io_ports->ctl_addr);
  98. if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
  99. tf->hob_feature = inb(io_ports->feature_addr);
  100. if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
  101. tf->hob_nsect = inb(io_ports->nsect_addr);
  102. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
  103. tf->hob_lbal = inb(io_ports->lbal_addr);
  104. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
  105. tf->hob_lbam = inb(io_ports->lbam_addr);
  106. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
  107. tf->hob_lbah = inb(io_ports->lbah_addr);
  108. }
  109. }
  110. static void mm_outsw(unsigned long addr, void *buf, u32 len)
  111. {
  112. unsigned short *bp = (unsigned short *)buf;
  113. for (; len > 0; len--, bp++)
  114. *(volatile u16 *)addr = bswap(*bp);
  115. }
  116. static void mm_insw(unsigned long addr, void *buf, u32 len)
  117. {
  118. unsigned short *bp = (unsigned short *)buf;
  119. for (; len > 0; len--, bp++)
  120. *bp = bswap(*(volatile u16 *)addr);
  121. }
  122. static void h8300_input_data(ide_drive_t *drive, struct request *rq,
  123. void *buf, unsigned int len)
  124. {
  125. mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  126. }
  127. static void h8300_output_data(ide_drive_t *drive, struct request *rq,
  128. void *buf, unsigned int len)
  129. {
  130. mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  131. }
  132. #define H8300_IDE_GAP (2)
  133. static inline void hw_setup(hw_regs_t *hw)
  134. {
  135. int i;
  136. memset(hw, 0, sizeof(hw_regs_t));
  137. for (i = 0; i <= 7; i++)
  138. hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
  139. hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT;
  140. hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
  141. hw->chipset = ide_generic;
  142. }
  143. static inline void hwif_setup(ide_hwif_t *hwif)
  144. {
  145. default_hwif_iops(hwif);
  146. hwif->tf_load = h8300_tf_load;
  147. hwif->tf_read = h8300_tf_read;
  148. hwif->input_data = h8300_input_data;
  149. hwif->output_data = h8300_output_data;
  150. }
  151. static int __init h8300_ide_init(void)
  152. {
  153. hw_regs_t hw;
  154. ide_hwif_t *hwif;
  155. int index;
  156. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  157. if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
  158. goto out_busy;
  159. if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
  160. release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
  161. goto out_busy;
  162. }
  163. hw_setup(&hw);
  164. hwif = ide_find_port();
  165. if (hwif == NULL) {
  166. printk(KERN_ERR "ide-h8300: IDE I/F register failed\n");
  167. return -ENOENT;
  168. }
  169. index = hwif->index;
  170. ide_init_port_data(hwif, index);
  171. ide_init_port_hw(hwif, &hw);
  172. hwif_setup(hwif);
  173. hwif->host_flags = IDE_HFLAG_NO_IO_32BIT;
  174. printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", index);
  175. idx[0] = index;
  176. ide_device_add(idx, NULL);
  177. return 0;
  178. out_busy:
  179. printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
  180. return -EBUSY;
  181. }
  182. module_init(h8300_ide_init);
  183. MODULE_LICENSE("GPL");