gayle.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * linux/drivers/ide/legacy/gayle.c -- 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 <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. /*
  28. * Offsets from one of the above bases
  29. */
  30. #define GAYLE_DATA 0x00
  31. #define GAYLE_ERROR 0x06 /* see err-bits */
  32. #define GAYLE_NSECTOR 0x0a /* nr of sectors to read/write */
  33. #define GAYLE_SECTOR 0x0e /* starting sector */
  34. #define GAYLE_LCYL 0x12 /* starting cylinder */
  35. #define GAYLE_HCYL 0x16 /* high byte of starting cyl */
  36. #define GAYLE_SELECT 0x1a /* 101dhhhh , d=drive, hhhh=head */
  37. #define GAYLE_STATUS 0x1e /* see status-bits */
  38. #define GAYLE_CONTROL 0x101a
  39. static int gayle_offsets[IDE_NR_PORTS] __initdata = {
  40. GAYLE_DATA, GAYLE_ERROR, GAYLE_NSECTOR, GAYLE_SECTOR, GAYLE_LCYL,
  41. GAYLE_HCYL, GAYLE_SELECT, GAYLE_STATUS, -1, -1
  42. };
  43. /*
  44. * These are at different offsets from the base
  45. */
  46. #define GAYLE_IRQ_4000 0xdd3020 /* MSB = 1, Harddisk is source of */
  47. #define GAYLE_IRQ_1200 0xda9000 /* interrupt */
  48. /*
  49. * Offset of the secondary port for IDE doublers
  50. * Note that GAYLE_CONTROL is NOT available then!
  51. */
  52. #define GAYLE_NEXT_PORT 0x1000
  53. #ifndef CONFIG_BLK_DEV_IDEDOUBLER
  54. #define GAYLE_NUM_HWIFS 1
  55. #define GAYLE_NUM_PROBE_HWIFS GAYLE_NUM_HWIFS
  56. #define GAYLE_HAS_CONTROL_REG 1
  57. #define GAYLE_IDEREG_SIZE 0x2000
  58. #else /* CONFIG_BLK_DEV_IDEDOUBLER */
  59. #define GAYLE_NUM_HWIFS 2
  60. #define GAYLE_NUM_PROBE_HWIFS (ide_doubler ? GAYLE_NUM_HWIFS : \
  61. GAYLE_NUM_HWIFS-1)
  62. #define GAYLE_HAS_CONTROL_REG (!ide_doubler)
  63. #define GAYLE_IDEREG_SIZE (ide_doubler ? 0x1000 : 0x2000)
  64. int ide_doubler = 0; /* support IDE doublers? */
  65. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  66. /*
  67. * Check and acknowledge the interrupt status
  68. */
  69. static int gayle_ack_intr_a4000(ide_hwif_t *hwif)
  70. {
  71. unsigned char ch;
  72. ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]);
  73. if (!(ch & GAYLE_IRQ_IDE))
  74. return 0;
  75. return 1;
  76. }
  77. static int gayle_ack_intr_a1200(ide_hwif_t *hwif)
  78. {
  79. unsigned char ch;
  80. ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]);
  81. if (!(ch & GAYLE_IRQ_IDE))
  82. return 0;
  83. (void)z_readb(hwif->io_ports[IDE_STATUS_OFFSET]);
  84. z_writeb(0x7c, hwif->io_ports[IDE_IRQ_OFFSET]);
  85. return 1;
  86. }
  87. /*
  88. * Probe for a Gayle IDE interface (and optionally for an IDE doubler)
  89. */
  90. void __init gayle_init(void)
  91. {
  92. int a4000, i;
  93. if (!MACH_IS_AMIGA)
  94. return;
  95. if ((a4000 = AMIGAHW_PRESENT(A4000_IDE)) || AMIGAHW_PRESENT(A1200_IDE))
  96. goto found;
  97. #ifdef CONFIG_ZORRO
  98. if (zorro_find_device(ZORRO_PROD_MTEC_VIPER_MK_V_E_MATRIX_530_SCSI_IDE,
  99. NULL))
  100. goto found;
  101. #endif
  102. return;
  103. found:
  104. for (i = 0; i < GAYLE_NUM_PROBE_HWIFS; i++) {
  105. unsigned long base, ctrlport, irqport;
  106. ide_ack_intr_t *ack_intr;
  107. hw_regs_t hw;
  108. ide_hwif_t *hwif;
  109. int index;
  110. unsigned long phys_base, res_start, res_n;
  111. if (a4000) {
  112. phys_base = GAYLE_BASE_4000;
  113. irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_4000);
  114. ack_intr = gayle_ack_intr_a4000;
  115. } else {
  116. phys_base = GAYLE_BASE_1200;
  117. irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_1200);
  118. ack_intr = gayle_ack_intr_a1200;
  119. }
  120. /*
  121. * FIXME: we now have selectable modes between mmio v/s iomio
  122. */
  123. phys_base += i*GAYLE_NEXT_PORT;
  124. res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1);
  125. res_n = GAYLE_IDEREG_SIZE;
  126. if (!request_mem_region(res_start, res_n, "IDE"))
  127. continue;
  128. base = (unsigned long)ZTWO_VADDR(phys_base);
  129. ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0;
  130. ide_setup_ports(&hw, base, gayle_offsets,
  131. ctrlport, irqport, ack_intr,
  132. // &gayle_iops,
  133. IRQ_AMIGA_PORTS);
  134. index = ide_register_hw(&hw, &hwif);
  135. if (index != -1) {
  136. hwif->mmio = 2;
  137. switch (i) {
  138. case 0:
  139. printk("ide%d: Gayle IDE interface (A%d style)\n", index,
  140. a4000 ? 4000 : 1200);
  141. break;
  142. #ifdef CONFIG_BLK_DEV_IDEDOUBLER
  143. case 1:
  144. printk("ide%d: IDE doubler\n", index);
  145. break;
  146. #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
  147. }
  148. } else
  149. release_mem_region(res_start, res_n);
  150. }
  151. }