sun3xflop.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* sun3xflop.h: Sun3/80 specific parts of the floppy driver.
  3. *
  4. * Derived partially from asm-sparc/floppy.h, which is:
  5. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6. *
  7. * Sun3x version 2/4/2000 Sam Creasey (sammy@sammy.net)
  8. */
  9. #ifndef __ASM_SUN3X_FLOPPY_H
  10. #define __ASM_SUN3X_FLOPPY_H
  11. #include <asm/page.h>
  12. #include <asm/pgtable.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. pr_crit("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. pr_crit("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. {
  101. register unsigned char st;
  102. #undef TRACE_FLPY_INT
  103. #define NO_FLOPPY_ASSEMBLER
  104. #ifdef TRACE_FLPY_INT
  105. static int calls=0;
  106. static int bytes=0;
  107. static int dma_wait=0;
  108. #endif
  109. if(!doing_pdma) {
  110. floppy_interrupt(irq, dev_id);
  111. return IRQ_HANDLED;
  112. }
  113. // pr_info("doing pdma\n");// st %x\n", sun_fdc->status_82072);
  114. #ifdef TRACE_FLPY_INT
  115. if(!calls)
  116. bytes = virtual_dma_count;
  117. #endif
  118. {
  119. register int lcount;
  120. register char *lptr;
  121. for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
  122. lcount; lcount--, lptr++) {
  123. /* st=fd_inb(virtual_dma_port+4) & 0x80 ; */
  124. st = *(sun3x_fdc.status_r);
  125. /* if(st != 0xa0) */
  126. /* break; */
  127. if((st & 0x80) == 0) {
  128. virtual_dma_count = lcount;
  129. virtual_dma_addr = lptr;
  130. return IRQ_HANDLED;
  131. }
  132. if((st & 0x20) == 0)
  133. break;
  134. if(virtual_dma_mode)
  135. /* fd_outb(*lptr, virtual_dma_port+5); */
  136. *(sun3x_fdc.data_r) = *lptr;
  137. else
  138. /* *lptr = fd_inb(virtual_dma_port+5); */
  139. *lptr = *(sun3x_fdc.data_r);
  140. }
  141. virtual_dma_count = lcount;
  142. virtual_dma_addr = lptr;
  143. /* st = fd_inb(virtual_dma_port+4); */
  144. st = *(sun3x_fdc.status_r);
  145. }
  146. #ifdef TRACE_FLPY_INT
  147. calls++;
  148. #endif
  149. // pr_info("st=%02x\n", st);
  150. if(st == 0x20)
  151. return IRQ_HANDLED;
  152. if(!(st & 0x20)) {
  153. virtual_dma_residue += virtual_dma_count;
  154. virtual_dma_count=0;
  155. doing_pdma = 0;
  156. #ifdef TRACE_FLPY_INT
  157. pr_info("count=%x, residue=%x calls=%d bytes=%x dma_wait=%d\n",
  158. virtual_dma_count, virtual_dma_residue, calls, bytes,
  159. dma_wait);
  160. calls = 0;
  161. dma_wait=0;
  162. #endif
  163. floppy_interrupt(irq, dev_id);
  164. return IRQ_HANDLED;
  165. }
  166. #ifdef TRACE_FLPY_INT
  167. if(!virtual_dma_count)
  168. dma_wait++;
  169. #endif
  170. return IRQ_HANDLED;
  171. }
  172. static int sun3xflop_request_irq(void)
  173. {
  174. static int once = 0;
  175. int error;
  176. if(!once) {
  177. once = 1;
  178. error = request_irq(FLOPPY_IRQ, sun3xflop_hardint,
  179. 0, "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) */