falconide.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 <linux/platform_device.h>
  18. #include <asm/setup.h>
  19. #include <asm/atarihw.h>
  20. #include <asm/atariints.h>
  21. #include <asm/atari_stdma.h>
  22. #include <asm/ide.h>
  23. #define DRV_NAME "falconide"
  24. /*
  25. * Offsets from base address
  26. */
  27. #define ATA_HD_CONTROL 0x39
  28. /*
  29. * falconide_intr_lock is used to obtain access to the IDE interrupt,
  30. * which is shared between several drivers.
  31. */
  32. static int falconide_intr_lock;
  33. static void falconide_release_lock(void)
  34. {
  35. if (falconide_intr_lock == 0) {
  36. printk(KERN_ERR "%s: bug\n", __func__);
  37. return;
  38. }
  39. falconide_intr_lock = 0;
  40. stdma_release();
  41. }
  42. static void falconide_get_lock(irq_handler_t handler, void *data)
  43. {
  44. if (falconide_intr_lock == 0) {
  45. if (in_interrupt() > 0)
  46. panic("Falcon IDE hasn't ST-DMA lock in interrupt");
  47. stdma_lock(handler, data);
  48. falconide_intr_lock = 1;
  49. }
  50. }
  51. static void falconide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
  52. void *buf, unsigned int len)
  53. {
  54. unsigned long data_addr = drive->hwif->io_ports.data_addr;
  55. if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS)) {
  56. __ide_mm_insw(data_addr, buf, (len + 1) / 2);
  57. return;
  58. }
  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. __ide_mm_outsw(data_addr, buf, (len + 1) / 2);
  67. return;
  68. }
  69. raw_outsw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
  70. }
  71. /* Atari has a byte-swapped IDE interface */
  72. static const struct ide_tp_ops falconide_tp_ops = {
  73. .exec_command = ide_exec_command,
  74. .read_status = ide_read_status,
  75. .read_altstatus = ide_read_altstatus,
  76. .write_devctl = ide_write_devctl,
  77. .dev_select = ide_dev_select,
  78. .tf_load = ide_tf_load,
  79. .tf_read = ide_tf_read,
  80. .input_data = falconide_input_data,
  81. .output_data = falconide_output_data,
  82. };
  83. static const struct ide_port_info falconide_port_info = {
  84. .get_lock = falconide_get_lock,
  85. .release_lock = falconide_release_lock,
  86. .tp_ops = &falconide_tp_ops,
  87. .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE |
  88. IDE_HFLAG_NO_DMA,
  89. .irq_flags = IRQF_SHARED,
  90. .chipset = ide_generic,
  91. };
  92. static void __init falconide_setup_ports(struct ide_hw *hw, unsigned long base)
  93. {
  94. int i;
  95. memset(hw, 0, sizeof(*hw));
  96. hw->io_ports.data_addr = base;
  97. for (i = 1; i < 8; i++)
  98. hw->io_ports_array[i] = base + 1 + i * 4;
  99. hw->io_ports.ctl_addr = base + ATA_HD_CONTROL;
  100. hw->irq = IRQ_MFP_IDE;
  101. }
  102. /*
  103. * Probe for a Falcon IDE interface
  104. */
  105. static int __init falconide_init(struct platform_device *pdev)
  106. {
  107. struct resource *res;
  108. struct ide_host *host;
  109. struct ide_hw hw, *hws[] = { &hw };
  110. unsigned long base;
  111. int rc;
  112. dev_info(&pdev->dev, "Atari Falcon IDE controller\n");
  113. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  114. if (!res)
  115. return -ENODEV;
  116. if (!devm_request_mem_region(&pdev->dev, res->start,
  117. resource_size(res), DRV_NAME)) {
  118. dev_err(&pdev->dev, "resources busy\n");
  119. return -EBUSY;
  120. }
  121. base = (unsigned long)res->start;
  122. falconide_setup_ports(&hw, base);
  123. host = ide_host_alloc(&falconide_port_info, hws, 1);
  124. if (host == NULL) {
  125. rc = -ENOMEM;
  126. goto err;
  127. }
  128. falconide_get_lock(NULL, NULL);
  129. rc = ide_host_register(host, &falconide_port_info, hws);
  130. falconide_release_lock();
  131. if (rc)
  132. goto err_free;
  133. platform_set_drvdata(pdev, host);
  134. return 0;
  135. err_free:
  136. ide_host_free(host);
  137. err:
  138. release_mem_region(res->start, resource_size(res));
  139. return rc;
  140. }
  141. static int falconide_remove(struct platform_device *pdev)
  142. {
  143. struct ide_host *host = platform_get_drvdata(pdev);
  144. ide_host_remove(host);
  145. return 0;
  146. }
  147. static struct platform_driver ide_falcon_driver = {
  148. .remove = falconide_remove,
  149. .driver = {
  150. .name = "atari-falcon-ide",
  151. },
  152. };
  153. module_platform_driver_probe(ide_falcon_driver, falconide_init);
  154. MODULE_AUTHOR("Geert Uytterhoeven");
  155. MODULE_DESCRIPTION("low-level driver for Atari Falcon IDE");
  156. MODULE_LICENSE("GPL");
  157. MODULE_ALIAS("platform:atari-falcon-ide");