buddha.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * 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. static const char *buddha_board_name[] = { "Buddha", "Catweasel", "X-Surf" };
  91. /*
  92. * Check and acknowledge the interrupt status
  93. */
  94. static int buddha_ack_intr(ide_hwif_t *hwif)
  95. {
  96. unsigned char ch;
  97. ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]);
  98. if (!(ch & 0x80))
  99. return 0;
  100. return 1;
  101. }
  102. static int xsurf_ack_intr(ide_hwif_t *hwif)
  103. {
  104. unsigned char ch;
  105. ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]);
  106. /* X-Surf needs a 0 written to IRQ register to ensure ISA bit A11 stays at 0 */
  107. z_writeb(0, hwif->io_ports[IDE_IRQ_OFFSET]);
  108. if (!(ch & 0x80))
  109. return 0;
  110. return 1;
  111. }
  112. /*
  113. * Probe for a Buddha or Catweasel IDE interface
  114. */
  115. static int __init buddha_init(void)
  116. {
  117. hw_regs_t hw;
  118. ide_hwif_t *hwif;
  119. int i;
  120. struct zorro_dev *z = NULL;
  121. u_long buddha_board = 0;
  122. BuddhaType type;
  123. int buddha_num_hwifs;
  124. while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
  125. unsigned long board;
  126. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  127. if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) {
  128. buddha_num_hwifs = BUDDHA_NUM_HWIFS;
  129. type=BOARD_BUDDHA;
  130. } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL) {
  131. buddha_num_hwifs = CATWEASEL_NUM_HWIFS;
  132. type=BOARD_CATWEASEL;
  133. } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF) {
  134. buddha_num_hwifs = XSURF_NUM_HWIFS;
  135. type=BOARD_XSURF;
  136. } else
  137. continue;
  138. board = z->resource.start;
  139. /*
  140. * FIXME: we now have selectable mmio v/s iomio transports.
  141. */
  142. if(type != BOARD_XSURF) {
  143. if (!request_mem_region(board+BUDDHA_BASE1, 0x800, "IDE"))
  144. continue;
  145. } else {
  146. if (!request_mem_region(board+XSURF_BASE1, 0x1000, "IDE"))
  147. continue;
  148. if (!request_mem_region(board+XSURF_BASE2, 0x1000, "IDE"))
  149. goto fail_base2;
  150. if (!request_mem_region(board+XSURF_IRQ1, 0x8, "IDE")) {
  151. release_mem_region(board+XSURF_BASE2, 0x1000);
  152. fail_base2:
  153. release_mem_region(board+XSURF_BASE1, 0x1000);
  154. continue;
  155. }
  156. }
  157. buddha_board = ZTWO_VADDR(board);
  158. /* write to BUDDHA_IRQ_MR to enable the board IRQ */
  159. /* X-Surf doesn't have this. IRQs are always on */
  160. if (type != BOARD_XSURF)
  161. z_writeb(0, buddha_board+BUDDHA_IRQ_MR);
  162. printk(KERN_INFO "ide: %s IDE controller\n",
  163. buddha_board_name[type]);
  164. for(i=0;i<buddha_num_hwifs;i++) {
  165. if(type != BOARD_XSURF) {
  166. ide_setup_ports(&hw, (buddha_board+buddha_bases[i]),
  167. buddha_offsets, 0,
  168. (buddha_board+buddha_irqports[i]),
  169. buddha_ack_intr,
  170. // budda_iops,
  171. IRQ_AMIGA_PORTS);
  172. } else {
  173. ide_setup_ports(&hw, (buddha_board+xsurf_bases[i]),
  174. xsurf_offsets, 0,
  175. (buddha_board+xsurf_irqports[i]),
  176. xsurf_ack_intr,
  177. // xsurf_iops,
  178. IRQ_AMIGA_PORTS);
  179. }
  180. hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
  181. if (hwif) {
  182. u8 index = hwif->index;
  183. ide_init_port_data(hwif, index);
  184. ide_init_port_hw(hwif, &hw);
  185. hwif->mmio = 1;
  186. idx[i] = index;
  187. }
  188. }
  189. ide_device_add(idx);
  190. }
  191. return 0;
  192. }
  193. module_init(buddha_init);