ide-h8300.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_outsw(unsigned long addr, void *buf, u32 len)
  21. {
  22. unsigned short *bp = (unsigned short *)buf;
  23. for (; len > 0; len--, bp++)
  24. *(volatile u16 *)addr = bswap(*bp);
  25. }
  26. static void mm_insw(unsigned long addr, void *buf, u32 len)
  27. {
  28. unsigned short *bp = (unsigned short *)buf;
  29. for (; len > 0; len--, bp++)
  30. *bp = bswap(*(volatile u16 *)addr);
  31. }
  32. static void h8300_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
  33. void *buf, unsigned int len)
  34. {
  35. mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  36. }
  37. static void h8300_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
  38. void *buf, unsigned int len)
  39. {
  40. mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
  41. }
  42. static const struct ide_tp_ops h8300_tp_ops = {
  43. .exec_command = ide_exec_command,
  44. .read_status = ide_read_status,
  45. .read_altstatus = ide_read_altstatus,
  46. .write_devctl = ide_write_devctl,
  47. .dev_select = ide_dev_select,
  48. .tf_load = ide_tf_load,
  49. .tf_read = ide_tf_read,
  50. .input_data = h8300_input_data,
  51. .output_data = h8300_output_data,
  52. };
  53. #define H8300_IDE_GAP (2)
  54. static inline void hw_setup(struct ide_hw *hw)
  55. {
  56. int i;
  57. memset(hw, 0, sizeof(*hw));
  58. for (i = 0; i <= 7; i++)
  59. hw->io_ports_array[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i;
  60. hw->io_ports.ctl_addr = CONFIG_H8300_IDE_ALT;
  61. hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ;
  62. }
  63. static const struct ide_port_info h8300_port_info = {
  64. .tp_ops = &h8300_tp_ops,
  65. .host_flags = IDE_HFLAG_NO_IO_32BIT | IDE_HFLAG_NO_DMA,
  66. .chipset = ide_generic,
  67. };
  68. static int __init h8300_ide_init(void)
  69. {
  70. struct ide_hw hw, *hws[] = { &hw };
  71. printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n");
  72. if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300"))
  73. goto out_busy;
  74. if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) {
  75. release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8);
  76. goto out_busy;
  77. }
  78. hw_setup(&hw);
  79. return ide_host_add(&h8300_port_info, hws, 1, NULL);
  80. out_busy:
  81. printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n");
  82. return -EBUSY;
  83. }
  84. module_init(h8300_ide_init);
  85. MODULE_LICENSE("GPL");