gayle.c 4.6 KB

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