gayle.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Amiga Gayle IDE Driver
  3. *
  4. * Created 9 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/types.h>
  11. #include <linux/mm.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/blkdev.h>
  14. #include <linux/ide.h>
  15. #include <linux/init.h>
  16. #include <linux/zorro.h>
  17. #include <linux/module.h>
  18. #include <linux/platform_device.h>
  19. #include <asm/setup.h>
  20. #include <asm/amigahw.h>
  21. #include <asm/amigaints.h>
  22. #include <asm/amigayle.h>
  23. /*
  24. * Offsets from one of the above bases
  25. */
  26. #define GAYLE_CONTROL 0x101a
  27. /*
  28. * These are at different offsets from the base
  29. */
  30. #define GAYLE_IRQ_4000 0xdd3020 /* MSB = 1, Harddisk is source of */
  31. #define GAYLE_IRQ_1200 0xda9000 /* interrupt */
  32. /*
  33. * Offset of the secondary port for IDE doublers
  34. * Note that GAYLE_CONTROL is NOT available then!
  35. */
  36. #define GAYLE_NEXT_PORT 0x1000
  37. #define GAYLE_NUM_HWIFS 2
  38. #define GAYLE_NUM_PROBE_HWIFS (ide_doubler ? GAYLE_NUM_HWIFS : \
  39. GAYLE_NUM_HWIFS-1)
  40. #define GAYLE_HAS_CONTROL_REG (!ide_doubler)
  41. static bool ide_doubler;
  42. module_param_named(doubler, ide_doubler, bool, 0);
  43. MODULE_PARM_DESC(doubler, "enable support for IDE doublers");
  44. /*
  45. * Check and acknowledge the interrupt status
  46. */
  47. static int gayle_test_irq(ide_hwif_t *hwif)
  48. {
  49. unsigned char ch;
  50. ch = z_readb(hwif->io_ports.irq_addr);
  51. if (!(ch & GAYLE_IRQ_IDE))
  52. return 0;
  53. return 1;
  54. }
  55. static void gayle_a1200_clear_irq(ide_drive_t *drive)
  56. {
  57. ide_hwif_t *hwif = drive->hwif;
  58. (void)z_readb(hwif->io_ports.status_addr);
  59. z_writeb(0x7c, hwif->io_ports.irq_addr);
  60. }
  61. static void __init gayle_setup_ports(struct ide_hw *hw, unsigned long base,
  62. unsigned long ctl, unsigned long irq_port)
  63. {
  64. int i;
  65. memset(hw, 0, sizeof(*hw));
  66. hw->io_ports.data_addr = base;
  67. for (i = 1; i < 8; i++)
  68. hw->io_ports_array[i] = base + 2 + i * 4;
  69. hw->io_ports.ctl_addr = ctl;
  70. hw->io_ports.irq_addr = irq_port;
  71. hw->irq = IRQ_AMIGA_PORTS;
  72. }
  73. static const struct ide_port_ops gayle_a4000_port_ops = {
  74. .test_irq = gayle_test_irq,
  75. };
  76. static const struct ide_port_ops gayle_a1200_port_ops = {
  77. .clear_irq = gayle_a1200_clear_irq,
  78. .test_irq = gayle_test_irq,
  79. };
  80. static const struct ide_port_info gayle_port_info = {
  81. .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE |
  82. IDE_HFLAG_NO_DMA,
  83. .irq_flags = IRQF_SHARED,
  84. .chipset = ide_generic,
  85. };
  86. /*
  87. * Probe for a Gayle IDE interface (and optionally for an IDE doubler)
  88. */
  89. static int __init amiga_gayle_ide_probe(struct platform_device *pdev)
  90. {
  91. struct resource *res;
  92. struct gayle_ide_platform_data *pdata;
  93. unsigned long base, ctrlport, irqport;
  94. unsigned int i;
  95. int error;
  96. struct ide_hw hw[GAYLE_NUM_HWIFS], *hws[GAYLE_NUM_HWIFS];
  97. struct ide_port_info d = gayle_port_info;
  98. struct ide_host *host;
  99. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  100. if (!res)
  101. return -ENODEV;
  102. if (!request_mem_region(res->start, resource_size(res), "IDE"))
  103. return -EBUSY;
  104. pdata = dev_get_platdata(&pdev->dev);
  105. pr_info("ide: Gayle IDE controller (A%u style%s)\n",
  106. pdata->explicit_ack ? 1200 : 4000,
  107. ide_doubler ? ", IDE doubler" : "");
  108. base = (unsigned long)ZTWO_VADDR(pdata->base);
  109. ctrlport = 0;
  110. irqport = (unsigned long)ZTWO_VADDR(pdata->irqport);
  111. if (pdata->explicit_ack)
  112. d.port_ops = &gayle_a1200_port_ops;
  113. else
  114. d.port_ops = &gayle_a4000_port_ops;
  115. for (i = 0; i < GAYLE_NUM_PROBE_HWIFS; i++, base += GAYLE_NEXT_PORT) {
  116. if (GAYLE_HAS_CONTROL_REG)
  117. ctrlport = base + GAYLE_CONTROL;
  118. gayle_setup_ports(&hw[i], base, ctrlport, irqport);
  119. hws[i] = &hw[i];
  120. }
  121. error = ide_host_add(&d, hws, i, &host);
  122. if (error)
  123. goto out;
  124. platform_set_drvdata(pdev, host);
  125. return 0;
  126. out:
  127. release_mem_region(res->start, resource_size(res));
  128. return error;
  129. }
  130. static int __exit amiga_gayle_ide_remove(struct platform_device *pdev)
  131. {
  132. struct ide_host *host = platform_get_drvdata(pdev);
  133. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  134. ide_host_remove(host);
  135. release_mem_region(res->start, resource_size(res));
  136. return 0;
  137. }
  138. static struct platform_driver amiga_gayle_ide_driver = {
  139. .remove = __exit_p(amiga_gayle_ide_remove),
  140. .driver = {
  141. .name = "amiga-gayle-ide",
  142. },
  143. };
  144. module_platform_driver_probe(amiga_gayle_ide_driver, amiga_gayle_ide_probe);
  145. MODULE_LICENSE("GPL");
  146. MODULE_ALIAS("platform:amiga-gayle-ide");