falconide.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Atari Falcon IDE Driver
  3. *
  4. * Created 12 Jul 1997 by Geert Uytterhoeven
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive for
  8. * more details.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/mm.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/blkdev.h>
  15. #include <linux/ide.h>
  16. #include <linux/init.h>
  17. #include <asm/setup.h>
  18. #include <asm/atarihw.h>
  19. #include <asm/atariints.h>
  20. #include <asm/atari_stdma.h>
  21. #define DRV_NAME "falconide"
  22. /*
  23. * Base of the IDE interface
  24. */
  25. #define ATA_HD_BASE 0xfff00000
  26. /*
  27. * Offsets from the above base
  28. */
  29. #define ATA_HD_CONTROL 0x39
  30. /*
  31. * falconide_intr_lock is used to obtain access to the IDE interrupt,
  32. * which is shared between several drivers.
  33. */
  34. static int falconide_intr_lock;
  35. static void falconide_release_lock(void)
  36. {
  37. if (falconide_intr_lock == 0) {
  38. printk(KERN_ERR "%s: bug\n", __func__);
  39. return;
  40. }
  41. falconide_intr_lock = 0;
  42. stdma_release();
  43. }
  44. static void falconide_get_lock(irq_handler_t handler, void *data)
  45. {
  46. if (falconide_intr_lock == 0) {
  47. if (in_interrupt() > 0)
  48. panic("Falcon IDE hasn't ST-DMA lock in interrupt");
  49. stdma_lock(handler, data);
  50. falconide_intr_lock = 1;
  51. }
  52. }
  53. static void falconide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
  54. void *buf, unsigned int len)
  55. {
  56. unsigned long data_addr = drive->hwif->io_ports.data_addr;
  57. if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS))
  58. return insw(data_addr, buf, (len + 1) / 2);
  59. raw_insw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
  60. }
  61. static void falconide_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
  62. void *buf, unsigned int len)
  63. {
  64. unsigned long data_addr = drive->hwif->io_ports.data_addr;
  65. if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS))
  66. return outsw(data_addr, buf, (len + 1) / 2);
  67. raw_outsw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
  68. }
  69. /* Atari has a byte-swapped IDE interface */
  70. static const struct ide_tp_ops falconide_tp_ops = {
  71. .exec_command = ide_exec_command,
  72. .read_status = ide_read_status,
  73. .read_altstatus = ide_read_altstatus,
  74. .write_devctl = ide_write_devctl,
  75. .dev_select = ide_dev_select,
  76. .tf_load = ide_tf_load,
  77. .tf_read = ide_tf_read,
  78. .input_data = falconide_input_data,
  79. .output_data = falconide_output_data,
  80. };
  81. static const struct ide_port_info falconide_port_info = {
  82. .get_lock = falconide_get_lock,
  83. .release_lock = falconide_release_lock,
  84. .tp_ops = &falconide_tp_ops,
  85. .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE |
  86. IDE_HFLAG_NO_DMA,
  87. .irq_flags = IRQF_SHARED,
  88. };
  89. static void __init falconide_setup_ports(hw_regs_t *hw)
  90. {
  91. int i;
  92. memset(hw, 0, sizeof(*hw));
  93. hw->io_ports.data_addr = ATA_HD_BASE;
  94. for (i = 1; i < 8; i++)
  95. hw->io_ports_array[i] = ATA_HD_BASE + 1 + i * 4;
  96. hw->io_ports.ctl_addr = ATA_HD_BASE + ATA_HD_CONTROL;
  97. hw->irq = IRQ_MFP_IDE;
  98. hw->ack_intr = NULL;
  99. hw->chipset = ide_generic;
  100. }
  101. /*
  102. * Probe for a Falcon IDE interface
  103. */
  104. static int __init falconide_init(void)
  105. {
  106. struct ide_host *host;
  107. hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
  108. int rc;
  109. if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE))
  110. return -ENODEV;
  111. printk(KERN_INFO "ide: Falcon IDE controller\n");
  112. if (!request_mem_region(ATA_HD_BASE, 0x40, DRV_NAME)) {
  113. printk(KERN_ERR "%s: resources busy\n", DRV_NAME);
  114. return -EBUSY;
  115. }
  116. falconide_setup_ports(&hw);
  117. host = ide_host_alloc(&falconide_port_info, hws);
  118. if (host == NULL) {
  119. rc = -ENOMEM;
  120. goto err;
  121. }
  122. falconide_get_lock(NULL, NULL);
  123. rc = ide_host_register(host, &falconide_port_info, hws);
  124. falconide_release_lock();
  125. if (rc)
  126. goto err_free;
  127. return 0;
  128. err_free:
  129. ide_host_free(host);
  130. err:
  131. release_mem_region(ATA_HD_BASE, 0x40);
  132. return rc;
  133. }
  134. module_init(falconide_init);
  135. MODULE_LICENSE("GPL");