sun3xflop.h 5.7 KB

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