ide-h8300.c 5.6 KB

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