gayle.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. /*
  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. #ifndef CONFIG_BLK_DEV_IDEDOUBLER
  43. #define GAYLE_NUM_HWIFS 1
  44. #define GAYLE_NUM_PROBE_HWIFS GAYLE_NUM_HWIFS
  45. #define GAYLE_HAS_CONTROL_REG 1
  46. #define GAYLE_IDEREG_SIZE 0x2000
  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. #define GAYLE_IDEREG_SIZE (ide_doubler ? 0x1000 : 0x2000)
  53. static int ide_doubler;
  54. module_param_named(doubler, ide_doubler, bool, 0);
  55. MODULE_PARM_DESC(doubler, "enable support for IDE doublers");
  56. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  57. /*
  58. * Check and acknowledge the interrupt status
  59. */
  60. static int gayle_ack_intr_a4000(ide_hwif_t *hwif)
  61. {
  62. unsigned char ch;
  63. ch = z_readb(hwif->io_ports.irq_addr);
  64. if (!(ch & GAYLE_IRQ_IDE))
  65. return 0;
  66. return 1;
  67. }
  68. static int gayle_ack_intr_a1200(ide_hwif_t *hwif)
  69. {
  70. unsigned char ch;
  71. ch = z_readb(hwif->io_ports.irq_addr);
  72. if (!(ch & GAYLE_IRQ_IDE))
  73. return 0;
  74. (void)z_readb(hwif->io_ports.status_addr);
  75. z_writeb(0x7c, hwif->io_ports.irq_addr);
  76. return 1;
  77. }
  78. static void __init gayle_setup_ports(hw_regs_t *hw, unsigned long base,
  79. unsigned long ctl, unsigned long irq_port,
  80. ide_ack_intr_t *ack_intr)
  81. {
  82. int i;
  83. memset(hw, 0, sizeof(*hw));
  84. hw->io_ports.data_addr = base;
  85. for (i = 1; i < 8; i++)
  86. hw->io_ports_array[i] = base + 2 + i * 4;
  87. hw->io_ports.ctl_addr = ctl;
  88. hw->io_ports.irq_addr = irq_port;
  89. hw->irq = IRQ_AMIGA_PORTS;
  90. hw->ack_intr = ack_intr;
  91. hw->chipset = ide_generic;
  92. }
  93. /*
  94. * Probe for a Gayle IDE interface (and optionally for an IDE doubler)
  95. */
  96. static int __init gayle_init(void)
  97. {
  98. int a4000, i;
  99. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  100. if (!MACH_IS_AMIGA)
  101. return -ENODEV;
  102. if ((a4000 = AMIGAHW_PRESENT(A4000_IDE)) || AMIGAHW_PRESENT(A1200_IDE))
  103. goto found;
  104. #ifdef CONFIG_ZORRO
  105. if (zorro_find_device(ZORRO_PROD_MTEC_VIPER_MK_V_E_MATRIX_530_SCSI_IDE,
  106. NULL))
  107. goto found;
  108. #endif
  109. return -ENODEV;
  110. found:
  111. printk(KERN_INFO "ide: Gayle IDE controller (A%d style%s)\n",
  112. a4000 ? 4000 : 1200,
  113. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  114. ide_doubler ? ", IDE doubler" :
  115. #endif
  116. "");
  117. for (i = 0; i < GAYLE_NUM_PROBE_HWIFS; i++) {
  118. unsigned long base, ctrlport, irqport;
  119. ide_ack_intr_t *ack_intr;
  120. hw_regs_t hw;
  121. ide_hwif_t *hwif;
  122. unsigned long phys_base, res_start, res_n;
  123. if (a4000) {
  124. phys_base = GAYLE_BASE_4000;
  125. irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_4000);
  126. ack_intr = gayle_ack_intr_a4000;
  127. } else {
  128. phys_base = GAYLE_BASE_1200;
  129. irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_1200);
  130. ack_intr = gayle_ack_intr_a1200;
  131. }
  132. /*
  133. * FIXME: we now have selectable modes between mmio v/s iomio
  134. */
  135. phys_base += i*GAYLE_NEXT_PORT;
  136. res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1);
  137. res_n = GAYLE_IDEREG_SIZE;
  138. if (!request_mem_region(res_start, res_n, "IDE"))
  139. continue;
  140. base = (unsigned long)ZTWO_VADDR(phys_base);
  141. ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0;
  142. gayle_setup_ports(&hw, base, ctrlport, irqport, ack_intr);
  143. hwif = ide_find_port();
  144. if (hwif) {
  145. u8 index = hwif->index;
  146. ide_init_port_hw(hwif, &hw);
  147. idx[i] = index;
  148. } else
  149. release_mem_region(res_start, res_n);
  150. }
  151. ide_device_add(idx, NULL);
  152. return 0;
  153. }
  154. module_init(gayle_init);
  155. MODULE_LICENSE("GPL");