gayle.c 4.4 KB

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