ide-h8300.c 5.3 KB

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