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