ide-h8300.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 DRV_NAME "ide-h8300"
  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 h8300_tf_load(ide_drive_t *drive, ide_task_t *task)
  41. {
  42. ide_hwif_t *hwif = drive->hwif;
  43. struct ide_io_ports *io_ports = &hwif->io_ports;
  44. struct ide_taskfile *tf = &task->tf;
  45. u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
  46. if (task->tf_flags & IDE_TFLAG_FLAGGED)
  47. HIHI = 0xFF;
  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(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
  86. if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
  87. tf->feature = inb(io_ports->feature_addr);
  88. if (task->tf_flags & IDE_TFLAG_IN_NSECT)
  89. tf->nsect = inb(io_ports->nsect_addr);
  90. if (task->tf_flags & IDE_TFLAG_IN_LBAL)
  91. tf->lbal = inb(io_ports->lbal_addr);
  92. if (task->tf_flags & IDE_TFLAG_IN_LBAM)
  93. tf->lbam = inb(io_ports->lbam_addr);
  94. if (task->tf_flags & IDE_TFLAG_IN_LBAH)
  95. tf->lbah = inb(io_ports->lbah_addr);
  96. if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
  97. tf->device = inb(io_ports->device_addr);
  98. if (task->tf_flags & IDE_TFLAG_LBA48) {
  99. outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
  100. if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
  101. tf->hob_feature = inb(io_ports->feature_addr);
  102. if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
  103. tf->hob_nsect = inb(io_ports->nsect_addr);
  104. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
  105. tf->hob_lbal = inb(io_ports->lbal_addr);
  106. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
  107. tf->hob_lbam = inb(io_ports->lbam_addr);
  108. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
  109. tf->hob_lbah = inb(io_ports->lbah_addr);
  110. }
  111. }
  112. static void mm_outsw(unsigned long addr, void *buf, u32 len)
  113. {
  114. unsigned short *bp = (unsigned short *)buf;
  115. for (; len > 0; len--, bp++)
  116. *(volatile u16 *)addr = bswap(*bp);
  117. }
  118. static void mm_insw(unsigned long addr, void *buf, u32 len)
  119. {
  120. unsigned short *bp = (unsigned short *)buf;
  121. for (; len > 0; len--, bp++)
  122. *bp = bswap(*(volatile u16 *)addr);
  123. }
  124. static void h8300_input_data(ide_drive_t *drive, struct request *rq,
  125. void *buf, unsigned int len)
  126. {
  127. mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  128. }
  129. static void h8300_output_data(ide_drive_t *drive, struct request *rq,
  130. void *buf, unsigned int len)
  131. {
  132. mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  133. }
  134. static const struct ide_tp_ops h8300_tp_ops = {
  135. .exec_command = ide_exec_command,
  136. .read_status = ide_read_status,
  137. .read_altstatus = ide_read_altstatus,
  138. .read_sff_dma_status = ide_read_sff_dma_status,
  139. .set_irq = ide_set_irq,
  140. .tf_load = h8300_tf_load,
  141. .tf_read = h8300_tf_read,
  142. .input_data = h8300_input_data,
  143. .output_data = h8300_output_data,
  144. };
  145. #define H8300_IDE_GAP (2)
  146. static inline void hw_setup(hw_regs_t *hw)
  147. {
  148. int i;
  149. memset(hw, 0, sizeof(hw_regs_t));
  150. for (i = 0; i <= 7; i++)
  151. hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
  152. hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT;
  153. hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
  154. hw->chipset = ide_generic;
  155. }
  156. static const struct ide_port_info h8300_port_info = {
  157. .tp_ops = &h8300_tp_ops,
  158. .host_flags = IDE_HFLAG_NO_IO_32BIT | IDE_HFLAG_NO_DMA,
  159. };
  160. static int __init h8300_ide_init(void)
  161. {
  162. hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
  163. printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n");
  164. if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
  165. goto out_busy;
  166. if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
  167. release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
  168. goto out_busy;
  169. }
  170. hw_setup(&hw);
  171. return ide_host_add(&h8300_port_info, hws, NULL);
  172. out_busy:
  173. printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
  174. return -EBUSY;
  175. }
  176. module_init(h8300_ide_init);
  177. MODULE_LICENSE("GPL");