buddha.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * linux/drivers/ide/legacy/buddha.c -- Amiga Buddha, Catweasel and X-Surf IDE Driver
  3. *
  4. * Copyright (C) 1997, 2001 by Geert Uytterhoeven and others
  5. *
  6. * This driver was written based on the specifications in README.buddha and
  7. * the X-Surf info from Inside_XSurf.txt available at
  8. * http://www.jschoenfeld.com
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file COPYING in the main directory of this archive for
  12. * more details.
  13. *
  14. * TODO:
  15. * - test it :-)
  16. * - tune the timings using the speed-register
  17. */
  18. #include <linux/types.h>
  19. #include <linux/mm.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/blkdev.h>
  22. #include <linux/hdreg.h>
  23. #include <linux/zorro.h>
  24. #include <linux/ide.h>
  25. #include <linux/init.h>
  26. #include <asm/amigahw.h>
  27. #include <asm/amigaints.h>
  28. /*
  29. * The Buddha has 2 IDE interfaces, the Catweasel has 3, X-Surf has 2
  30. */
  31. #define BUDDHA_NUM_HWIFS 2
  32. #define CATWEASEL_NUM_HWIFS 3
  33. #define XSURF_NUM_HWIFS 2
  34. /*
  35. * Bases of the IDE interfaces (relative to the board address)
  36. */
  37. #define BUDDHA_BASE1 0x800
  38. #define BUDDHA_BASE2 0xa00
  39. #define BUDDHA_BASE3 0xc00
  40. #define XSURF_BASE1 0xb000 /* 2.5" Interface */
  41. #define XSURF_BASE2 0xd000 /* 3.5" Interface */
  42. static u_int buddha_bases[CATWEASEL_NUM_HWIFS] __initdata = {
  43. BUDDHA_BASE1, BUDDHA_BASE2, BUDDHA_BASE3
  44. };
  45. static u_int xsurf_bases[XSURF_NUM_HWIFS] __initdata = {
  46. XSURF_BASE1, XSURF_BASE2
  47. };
  48. /*
  49. * Offsets from one of the above bases
  50. */
  51. #define BUDDHA_DATA 0x00
  52. #define BUDDHA_ERROR 0x06 /* see err-bits */
  53. #define BUDDHA_NSECTOR 0x0a /* nr of sectors to read/write */
  54. #define BUDDHA_SECTOR 0x0e /* starting sector */
  55. #define BUDDHA_LCYL 0x12 /* starting cylinder */
  56. #define BUDDHA_HCYL 0x16 /* high byte of starting cyl */
  57. #define BUDDHA_SELECT 0x1a /* 101dhhhh , d=drive, hhhh=head */
  58. #define BUDDHA_STATUS 0x1e /* see status-bits */
  59. #define BUDDHA_CONTROL 0x11a
  60. #define XSURF_CONTROL -1 /* X-Surf has no CS1* (Control/AltStat) */
  61. static int buddha_offsets[IDE_NR_PORTS] __initdata = {
  62. BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL,
  63. BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, BUDDHA_CONTROL, -1
  64. };
  65. static int xsurf_offsets[IDE_NR_PORTS] __initdata = {
  66. BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL,
  67. BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, XSURF_CONTROL, -1
  68. };
  69. /*
  70. * Other registers
  71. */
  72. #define BUDDHA_IRQ1 0xf00 /* MSB = 1, Harddisk is source of */
  73. #define BUDDHA_IRQ2 0xf40 /* interrupt */
  74. #define BUDDHA_IRQ3 0xf80
  75. #define XSURF_IRQ1 0x7e
  76. #define XSURF_IRQ2 0x7e
  77. static int buddha_irqports[CATWEASEL_NUM_HWIFS] __initdata = {
  78. BUDDHA_IRQ1, BUDDHA_IRQ2, BUDDHA_IRQ3
  79. };
  80. static int xsurf_irqports[XSURF_NUM_HWIFS] __initdata = {
  81. XSURF_IRQ1, XSURF_IRQ2
  82. };
  83. #define BUDDHA_IRQ_MR 0xfc0 /* master interrupt enable */
  84. /*
  85. * Board information
  86. */
  87. typedef enum BuddhaType_Enum {
  88. BOARD_BUDDHA, BOARD_CATWEASEL, BOARD_XSURF
  89. } BuddhaType;
  90. /*
  91. * Check and acknowledge the interrupt status
  92. */
  93. static int buddha_ack_intr(ide_hwif_t *hwif)
  94. {
  95. unsigned char ch;
  96. ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]);
  97. if (!(ch & 0x80))
  98. return 0;
  99. return 1;
  100. }
  101. static int xsurf_ack_intr(ide_hwif_t *hwif)
  102. {
  103. unsigned char ch;
  104. ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]);
  105. /* X-Surf needs a 0 written to IRQ register to ensure ISA bit A11 stays at 0 */
  106. z_writeb(0, hwif->io_ports[IDE_IRQ_OFFSET]);
  107. if (!(ch & 0x80))
  108. return 0;
  109. return 1;
  110. }
  111. /*
  112. * Probe for a Buddha or Catweasel IDE interface
  113. */
  114. void __init buddha_init(void)
  115. {
  116. hw_regs_t hw;
  117. ide_hwif_t *hwif;
  118. int i, index;
  119. struct zorro_dev *z = NULL;
  120. u_long buddha_board = 0;
  121. BuddhaType type;
  122. int buddha_num_hwifs;
  123. while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
  124. unsigned long board;
  125. if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) {
  126. buddha_num_hwifs = BUDDHA_NUM_HWIFS;
  127. type=BOARD_BUDDHA;
  128. } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL) {
  129. buddha_num_hwifs = CATWEASEL_NUM_HWIFS;
  130. type=BOARD_CATWEASEL;
  131. } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF) {
  132. buddha_num_hwifs = XSURF_NUM_HWIFS;
  133. type=BOARD_XSURF;
  134. } else
  135. continue;
  136. board = z->resource.start;
  137. /*
  138. * FIXME: we now have selectable mmio v/s iomio transports.
  139. */
  140. if(type != BOARD_XSURF) {
  141. if (!request_mem_region(board+BUDDHA_BASE1, 0x800, "IDE"))
  142. continue;
  143. } else {
  144. if (!request_mem_region(board+XSURF_BASE1, 0x1000, "IDE"))
  145. continue;
  146. if (!request_mem_region(board+XSURF_BASE2, 0x1000, "IDE"))
  147. goto fail_base2;
  148. if (!request_mem_region(board+XSURF_IRQ1, 0x8, "IDE")) {
  149. release_mem_region(board+XSURF_BASE2, 0x1000);
  150. fail_base2:
  151. release_mem_region(board+XSURF_BASE1, 0x1000);
  152. continue;
  153. }
  154. }
  155. buddha_board = ZTWO_VADDR(board);
  156. /* write to BUDDHA_IRQ_MR to enable the board IRQ */
  157. /* X-Surf doesn't have this. IRQs are always on */
  158. if (type != BOARD_XSURF)
  159. z_writeb(0, buddha_board+BUDDHA_IRQ_MR);
  160. for(i=0;i<buddha_num_hwifs;i++) {
  161. if(type != BOARD_XSURF) {
  162. ide_setup_ports(&hw, (buddha_board+buddha_bases[i]),
  163. buddha_offsets, 0,
  164. (buddha_board+buddha_irqports[i]),
  165. buddha_ack_intr,
  166. // budda_iops,
  167. IRQ_AMIGA_PORTS);
  168. } else {
  169. ide_setup_ports(&hw, (buddha_board+xsurf_bases[i]),
  170. xsurf_offsets, 0,
  171. (buddha_board+xsurf_irqports[i]),
  172. xsurf_ack_intr,
  173. // xsurf_iops,
  174. IRQ_AMIGA_PORTS);
  175. }
  176. index = ide_register_hw(&hw, &hwif);
  177. if (index != -1) {
  178. hwif->mmio = 2;
  179. printk("ide%d: ", index);
  180. switch(type) {
  181. case BOARD_BUDDHA:
  182. printk("Buddha");
  183. break;
  184. case BOARD_CATWEASEL:
  185. printk("Catweasel");
  186. break;
  187. case BOARD_XSURF:
  188. printk("X-Surf");
  189. break;
  190. }
  191. printk(" IDE interface\n");
  192. }
  193. }
  194. }
  195. }