ide-h8300.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. if (task->tf_flags & IDE_TFLAG_OUT_DATA)
  48. mm_outw((tf->hob_data << 8) | tf->data, io_ports->data_addr);
  49. if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
  50. outb(tf->hob_feature, io_ports->feature_addr);
  51. if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
  52. outb(tf->hob_nsect, io_ports->nsect_addr);
  53. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
  54. outb(tf->hob_lbal, io_ports->lbal_addr);
  55. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
  56. outb(tf->hob_lbam, io_ports->lbam_addr);
  57. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
  58. outb(tf->hob_lbah, io_ports->lbah_addr);
  59. if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
  60. outb(tf->feature, io_ports->feature_addr);
  61. if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
  62. outb(tf->nsect, io_ports->nsect_addr);
  63. if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
  64. outb(tf->lbal, io_ports->lbal_addr);
  65. if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
  66. outb(tf->lbam, io_ports->lbam_addr);
  67. if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
  68. outb(tf->lbah, io_ports->lbah_addr);
  69. if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
  70. outb((tf->device & HIHI) | drive->select.all,
  71. io_ports->device_addr);
  72. }
  73. static void h8300_tf_read(ide_drive_t *drive, ide_task_t *task)
  74. {
  75. ide_hwif_t *hwif = drive->hwif;
  76. struct ide_io_ports *io_ports = &hwif->io_ports;
  77. struct ide_taskfile *tf = &task->tf;
  78. if (task->tf_flags & IDE_TFLAG_IN_DATA) {
  79. u16 data = mm_inw(io_ports->data_addr);
  80. tf->data = data & 0xff;
  81. tf->hob_data = (data >> 8) & 0xff;
  82. }
  83. /* be sure we're looking at the low order bits */
  84. outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
  85. if (task->tf_flags & IDE_TFLAG_IN_NSECT)
  86. tf->nsect = inb(io_ports->nsect_addr);
  87. if (task->tf_flags & IDE_TFLAG_IN_LBAL)
  88. tf->lbal = inb(io_ports->lbal_addr);
  89. if (task->tf_flags & IDE_TFLAG_IN_LBAM)
  90. tf->lbam = inb(io_ports->lbam_addr);
  91. if (task->tf_flags & IDE_TFLAG_IN_LBAH)
  92. tf->lbah = inb(io_ports->lbah_addr);
  93. if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
  94. tf->device = inb(io_ports->device_addr);
  95. if (task->tf_flags & IDE_TFLAG_LBA48) {
  96. outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
  97. if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
  98. tf->hob_feature = inb(io_ports->feature_addr);
  99. if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
  100. tf->hob_nsect = inb(io_ports->nsect_addr);
  101. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
  102. tf->hob_lbal = inb(io_ports->lbal_addr);
  103. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
  104. tf->hob_lbam = inb(io_ports->lbam_addr);
  105. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
  106. tf->hob_lbah = inb(io_ports->lbah_addr);
  107. }
  108. }
  109. static void mm_outsw(unsigned long addr, void *buf, u32 len)
  110. {
  111. unsigned short *bp = (unsigned short *)buf;
  112. for (; len > 0; len--, bp++)
  113. *(volatile u16 *)addr = bswap(*bp);
  114. }
  115. static void mm_insw(unsigned long addr, void *buf, u32 len)
  116. {
  117. unsigned short *bp = (unsigned short *)buf;
  118. for (; len > 0; len--, bp++)
  119. *bp = bswap(*(volatile u16 *)addr);
  120. }
  121. static void h8300_input_data(ide_drive_t *drive, struct request *rq,
  122. void *buf, unsigned int len)
  123. {
  124. mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  125. }
  126. static void h8300_output_data(ide_drive_t *drive, struct request *rq,
  127. void *buf, unsigned int len)
  128. {
  129. mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  130. }
  131. #define H8300_IDE_GAP (2)
  132. static inline void hw_setup(hw_regs_t *hw)
  133. {
  134. int i;
  135. memset(hw, 0, sizeof(hw_regs_t));
  136. for (i = 0; i <= 7; i++)
  137. hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
  138. hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT;
  139. hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
  140. hw->chipset = ide_generic;
  141. }
  142. static inline void hwif_setup(ide_hwif_t *hwif)
  143. {
  144. default_hwif_iops(hwif);
  145. hwif->tf_load = h8300_tf_load;
  146. hwif->tf_read = h8300_tf_read;
  147. hwif->input_data = h8300_input_data;
  148. hwif->output_data = h8300_output_data;
  149. }
  150. static int __init h8300_ide_init(void)
  151. {
  152. hw_regs_t hw;
  153. ide_hwif_t *hwif;
  154. int index;
  155. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  156. if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
  157. goto out_busy;
  158. if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
  159. release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
  160. goto out_busy;
  161. }
  162. hw_setup(&hw);
  163. hwif = ide_find_port();
  164. if (hwif == NULL) {
  165. printk(KERN_ERR "ide-h8300: IDE I/F register failed\n");
  166. return -ENOENT;
  167. }
  168. index = hwif->index;
  169. ide_init_port_data(hwif, index);
  170. ide_init_port_hw(hwif, &hw);
  171. hwif_setup(hwif);
  172. hwif->host_flags = IDE_HFLAG_NO_IO_32BIT;
  173. printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", index);
  174. idx[0] = index;
  175. ide_device_add(idx, NULL);
  176. return 0;
  177. out_busy:
  178. printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
  179. return -EBUSY;
  180. }
  181. module_init(h8300_ide_init);
  182. MODULE_LICENSE("GPL");