sun3xflop.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* sun3xflop.h: Sun3/80 specific parts of the floppy driver.
  2. *
  3. * Derived partially from asm-sparc/floppy.h, which is:
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. *
  6. * Sun3x version 2/4/2000 Sam Creasey (sammy@sammy.net)
  7. */
  8. #ifndef __ASM_SUN3X_FLOPPY_H
  9. #define __ASM_SUN3X_FLOPPY_H
  10. #include <asm/page.h>
  11. #include <asm/pgtable.h>
  12. #include <asm/irq.h>
  13. #include <asm/sun3x.h>
  14. /* default interrupt vector */
  15. #define SUN3X_FDC_IRQ 0x40
  16. /* some constants */
  17. #define FCR_TC 0x1
  18. #define FCR_EJECT 0x2
  19. #define FCR_MTRON 0x4
  20. #define FCR_DSEL1 0x8
  21. #define FCR_DSEL0 0x10
  22. /* We don't need no stinkin' I/O port allocation crap. */
  23. #undef release_region
  24. #undef request_region
  25. #define release_region(X, Y) do { } while(0)
  26. #define request_region(X, Y, Z) (1)
  27. struct sun3xflop_private {
  28. volatile unsigned char *status_r;
  29. volatile unsigned char *data_r;
  30. volatile unsigned char *fcr_r;
  31. volatile unsigned char *fvr_r;
  32. unsigned char fcr;
  33. } sun3x_fdc;
  34. /* Super paranoid... */
  35. #undef HAVE_DISABLE_HLT
  36. /* Routines unique to each controller type on a Sun. */
  37. static unsigned char sun3x_82072_fd_inb(int port)
  38. {
  39. static int once = 0;
  40. // udelay(5);
  41. switch(port & 7) {
  42. default:
  43. printk("floppy: Asked to read unknown port %d\n", port);
  44. panic("floppy: Port bolixed.");
  45. case 4: /* FD_STATUS */
  46. return (*sun3x_fdc.status_r) & ~STATUS_DMA;
  47. case 5: /* FD_DATA */
  48. return (*sun3x_fdc.data_r);
  49. case 7: /* FD_DIR */
  50. /* ugly hack, I can't find a way to actually detect the disk */
  51. if(!once) {
  52. once = 1;
  53. return 0x80;
  54. }
  55. return 0;
  56. };
  57. panic("sun_82072_fd_inb: How did I get here?");
  58. }
  59. static void sun3x_82072_fd_outb(unsigned char value, int port)
  60. {
  61. // udelay(5);
  62. switch(port & 7) {
  63. default:
  64. printk("floppy: Asked to write to unknown port %d\n", port);
  65. panic("floppy: Port bolixed.");
  66. case 2: /* FD_DOR */
  67. /* Oh geese, 82072 on the Sun has no DOR register,
  68. * so we make do with taunting the FCR.
  69. *
  70. * ASSUMPTIONS: There will only ever be one floppy
  71. * drive attached to a Sun controller
  72. * and it will be at drive zero.
  73. */
  74. {
  75. unsigned char fcr = sun3x_fdc.fcr;
  76. if(value & 0x10) {
  77. fcr |= (FCR_DSEL0 | FCR_MTRON);
  78. } else
  79. fcr &= ~(FCR_DSEL0 | FCR_MTRON);
  80. if(fcr != sun3x_fdc.fcr) {
  81. *(sun3x_fdc.fcr_r) = fcr;
  82. sun3x_fdc.fcr = fcr;
  83. }
  84. }
  85. break;
  86. case 5: /* FD_DATA */
  87. *(sun3x_fdc.data_r) = value;
  88. break;
  89. case 7: /* FD_DCR */
  90. *(sun3x_fdc.status_r) = value;
  91. break;
  92. case 4: /* FD_STATUS */
  93. *(sun3x_fdc.status_r) = value;
  94. break;
  95. };
  96. return;
  97. }
  98. asmlinkage irqreturn_t sun3xflop_hardint(int irq, void *dev_id)
  99. {
  100. register unsigned char st;
  101. #undef TRACE_FLPY_INT
  102. #define NO_FLOPPY_ASSEMBLER
  103. #ifdef TRACE_FLPY_INT
  104. static int calls=0;
  105. static int bytes=0;
  106. static int dma_wait=0;
  107. #endif
  108. if(!doing_pdma) {
  109. floppy_interrupt(irq, dev_id);
  110. return IRQ_HANDLED;
  111. }
  112. // printk("doing pdma\n");// st %x\n", sun_fdc->status_82072);
  113. #ifdef TRACE_FLPY_INT
  114. if(!calls)
  115. bytes = virtual_dma_count;
  116. #endif
  117. {
  118. register int lcount;
  119. register char *lptr;
  120. for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
  121. lcount; lcount--, lptr++) {
  122. /* st=fd_inb(virtual_dma_port+4) & 0x80 ; */
  123. st = *(sun3x_fdc.status_r);
  124. /* if(st != 0xa0) */
  125. /* break; */
  126. if((st & 0x80) == 0) {
  127. virtual_dma_count = lcount;
  128. virtual_dma_addr = lptr;
  129. return IRQ_HANDLED;
  130. }
  131. if((st & 0x20) == 0)
  132. break;
  133. if(virtual_dma_mode)
  134. /* fd_outb(*lptr, virtual_dma_port+5); */
  135. *(sun3x_fdc.data_r) = *lptr;
  136. else
  137. /* *lptr = fd_inb(virtual_dma_port+5); */
  138. *lptr = *(sun3x_fdc.data_r);
  139. }
  140. virtual_dma_count = lcount;
  141. virtual_dma_addr = lptr;
  142. /* st = fd_inb(virtual_dma_port+4); */
  143. st = *(sun3x_fdc.status_r);
  144. }
  145. #ifdef TRACE_FLPY_INT
  146. calls++;
  147. #endif
  148. // printk("st=%02x\n", st);
  149. if(st == 0x20)
  150. return IRQ_HANDLED;
  151. if(!(st & 0x20)) {
  152. virtual_dma_residue += virtual_dma_count;
  153. virtual_dma_count=0;
  154. doing_pdma = 0;
  155. #ifdef TRACE_FLPY_INT
  156. printk("count=%x, residue=%x calls=%d bytes=%x dma_wait=%d\n",
  157. virtual_dma_count, virtual_dma_residue, calls, bytes,
  158. dma_wait);
  159. calls = 0;
  160. dma_wait=0;
  161. #endif
  162. floppy_interrupt(irq, dev_id);
  163. return IRQ_HANDLED;
  164. }
  165. #ifdef TRACE_FLPY_INT
  166. if(!virtual_dma_count)
  167. dma_wait++;
  168. #endif
  169. return IRQ_HANDLED;
  170. }
  171. static int sun3xflop_request_irq(void)
  172. {
  173. static int once = 0;
  174. int error;
  175. if(!once) {
  176. once = 1;
  177. error = request_irq(FLOPPY_IRQ, sun3xflop_hardint,
  178. 0, "floppy", NULL);
  179. return ((error == 0) ? 0 : -1);
  180. } else return 0;
  181. }
  182. static void __init floppy_set_flags(int *ints,int param, int param2);
  183. static int sun3xflop_init(void)
  184. {
  185. if(FLOPPY_IRQ < 0x40)
  186. FLOPPY_IRQ = SUN3X_FDC_IRQ;
  187. sun3x_fdc.status_r = (volatile unsigned char *)SUN3X_FDC;
  188. sun3x_fdc.data_r = (volatile unsigned char *)(SUN3X_FDC+1);
  189. sun3x_fdc.fcr_r = (volatile unsigned char *)SUN3X_FDC_FCR;
  190. sun3x_fdc.fvr_r = (volatile unsigned char *)SUN3X_FDC_FVR;
  191. sun3x_fdc.fcr = 0;
  192. /* Last minute sanity check... */
  193. if(*sun3x_fdc.status_r == 0xff) {
  194. return -1;
  195. }
  196. *sun3x_fdc.fvr_r = FLOPPY_IRQ;
  197. *sun3x_fdc.fcr_r = FCR_TC;
  198. udelay(10);
  199. *sun3x_fdc.fcr_r = 0;
  200. /* Success... */
  201. floppy_set_flags(NULL, 1, FD_BROKEN_DCL); // I don't know how to detect this.
  202. allowed_drive_mask = 0x01;
  203. return (int) SUN3X_FDC;
  204. }
  205. /* I'm not precisely sure this eject routine works */
  206. static int sun3x_eject(void)
  207. {
  208. if(MACH_IS_SUN3X) {
  209. sun3x_fdc.fcr |= (FCR_DSEL0 | FCR_EJECT);
  210. *(sun3x_fdc.fcr_r) = sun3x_fdc.fcr;
  211. udelay(10);
  212. sun3x_fdc.fcr &= ~(FCR_DSEL0 | FCR_EJECT);
  213. *(sun3x_fdc.fcr_r) = sun3x_fdc.fcr;
  214. }
  215. return 0;
  216. }
  217. #define fd_eject(drive) sun3x_eject()
  218. #endif /* !(__ASM_SUN3X_FLOPPY_H) */