gayle.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 <asm/setup.h>
  19. #include <asm/amigahw.h>
  20. #include <asm/amigaints.h>
  21. #include <asm/amigayle.h>
  22. /*
  23. * Bases of the IDE interfaces
  24. */
  25. #define GAYLE_BASE_4000 0xdd2020 /* A4000/A4000T */
  26. #define GAYLE_BASE_1200 0xda0000 /* A1200/A600 and E-Matrix 530 */
  27. #define GAYLE_IDEREG_SIZE 0x2000
  28. /*
  29. * Offsets from one of the above bases
  30. */
  31. #define GAYLE_CONTROL 0x101a
  32. /*
  33. * These are at different offsets from the base
  34. */
  35. #define GAYLE_IRQ_4000 0xdd3020 /* MSB = 1, Harddisk is source of */
  36. #define GAYLE_IRQ_1200 0xda9000 /* interrupt */
  37. /*
  38. * Offset of the secondary port for IDE doublers
  39. * Note that GAYLE_CONTROL is NOT available then!
  40. */
  41. #define GAYLE_NEXT_PORT 0x1000
  42. #define GAYLE_NUM_HWIFS 2
  43. #define GAYLE_NUM_PROBE_HWIFS (ide_doubler ? GAYLE_NUM_HWIFS : \
  44. GAYLE_NUM_HWIFS-1)
  45. #define GAYLE_HAS_CONTROL_REG (!ide_doubler)
  46. static int ide_doubler;
  47. module_param_named(doubler, ide_doubler, bool, 0);
  48. MODULE_PARM_DESC(doubler, "enable support for IDE doublers");
  49. /*
  50. * Check and acknowledge the interrupt status
  51. */
  52. static int gayle_ack_intr(ide_hwif_t *hwif)
  53. {
  54. unsigned char ch;
  55. ch = z_readb(hwif->io_ports.irq_addr);
  56. if (!(ch & GAYLE_IRQ_IDE))
  57. return 0;
  58. return 1;
  59. }
  60. static void gayle_a1200_clear_irq(ide_drive_t *drive)
  61. {
  62. ide_hwif_t *hwif = drive->hwif;
  63. (void)z_readb(hwif->io_ports.status_addr);
  64. z_writeb(0x7c, hwif->io_ports.irq_addr);
  65. }
  66. static void __init gayle_setup_ports(struct ide_hw *hw, unsigned long base,
  67. unsigned long ctl, unsigned long irq_port,
  68. ide_ack_intr_t *ack_intr)
  69. {
  70. int i;
  71. memset(hw, 0, sizeof(*hw));
  72. hw->io_ports.data_addr = base;
  73. for (i = 1; i < 8; i++)
  74. hw->io_ports_array[i] = base + 2 + i * 4;
  75. hw->io_ports.ctl_addr = ctl;
  76. hw->io_ports.irq_addr = irq_port;
  77. hw->irq = IRQ_AMIGA_PORTS;
  78. hw->ack_intr = ack_intr;
  79. }
  80. static const struct ide_port_ops gayle_a1200_port_ops = {
  81. .clear_irq = gayle_a1200_clear_irq,
  82. };
  83. static const struct ide_port_info gayle_port_info = {
  84. .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE |
  85. IDE_HFLAG_NO_DMA,
  86. .irq_flags = IRQF_SHARED,
  87. .chipset = ide_generic,
  88. };
  89. /*
  90. * Probe for a Gayle IDE interface (and optionally for an IDE doubler)
  91. */
  92. static int __init gayle_init(void)
  93. {
  94. unsigned long phys_base, res_start, res_n;
  95. unsigned long base, ctrlport, irqport;
  96. int a4000, i, rc;
  97. struct ide_hw hw[GAYLE_NUM_HWIFS], *hws[GAYLE_NUM_HWIFS];
  98. struct ide_port_info d = gayle_port_info;
  99. if (!MACH_IS_AMIGA)
  100. return -ENODEV;
  101. if ((a4000 = AMIGAHW_PRESENT(A4000_IDE)) || AMIGAHW_PRESENT(A1200_IDE))
  102. goto found;
  103. #ifdef CONFIG_ZORRO
  104. if (zorro_find_device(ZORRO_PROD_MTEC_VIPER_MK_V_E_MATRIX_530_SCSI_IDE,
  105. NULL))
  106. goto found;
  107. #endif
  108. return -ENODEV;
  109. found:
  110. printk(KERN_INFO "ide: Gayle IDE controller (A%d style%s)\n",
  111. a4000 ? 4000 : 1200,
  112. ide_doubler ? ", IDE doubler" : "");
  113. if (a4000) {
  114. phys_base = GAYLE_BASE_4000;
  115. irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_4000);
  116. } else {
  117. phys_base = GAYLE_BASE_1200;
  118. irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_1200);
  119. d.port_ops = &gayle_a1200_port_ops;
  120. }
  121. res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1);
  122. res_n = GAYLE_IDEREG_SIZE;
  123. if (!request_mem_region(res_start, res_n, "IDE"))
  124. return -EBUSY;
  125. for (i = 0; i < GAYLE_NUM_PROBE_HWIFS; i++) {
  126. base = (unsigned long)ZTWO_VADDR(phys_base + i * GAYLE_NEXT_PORT);
  127. ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0;
  128. gayle_setup_ports(&hw[i], base, ctrlport, irqport, gayle_ack_intr);
  129. hws[i] = &hw[i];
  130. }
  131. rc = ide_host_add(&d, hws, i, NULL);
  132. if (rc)
  133. release_mem_region(res_start, res_n);
  134. return rc;
  135. }
  136. module_init(gayle_init);
  137. MODULE_LICENSE("GPL");