floppy.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Implementation independent bits of the Floppy driver.
  3. *
  4. * much of this file is derived from what was originally the Q40 floppy driver.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (C) 1999, 2000, 2001
  11. *
  12. * Sun3x support added 2/4/2000 Sam Creasey (sammy@sammy.net)
  13. *
  14. */
  15. #include <asm/io.h>
  16. #include <linux/vmalloc.h>
  17. asmlinkage irqreturn_t floppy_hardint(int irq, void *dev_id);
  18. /* constants... */
  19. #undef MAX_DMA_ADDRESS
  20. #define MAX_DMA_ADDRESS 0x00 /* nothing like that */
  21. /*
  22. * Again, the CMOS information doesn't work on m68k..
  23. */
  24. #define FLOPPY0_TYPE (MACH_IS_Q40 ? 6 : 4)
  25. #define FLOPPY1_TYPE 0
  26. /* basically PC init + set use_virtual_dma */
  27. #define FDC1 m68k_floppy_init()
  28. #define N_FDC 1
  29. #define N_DRIVE 8
  30. /* vdma globals adapted from asm-i386/floppy.h */
  31. static int virtual_dma_count=0;
  32. static int virtual_dma_residue=0;
  33. static char *virtual_dma_addr=NULL;
  34. static int virtual_dma_mode=0;
  35. static int doing_pdma=0;
  36. #include <asm/sun3xflop.h>
  37. extern spinlock_t dma_spin_lock;
  38. static __inline__ unsigned long claim_dma_lock(void)
  39. {
  40. unsigned long flags;
  41. spin_lock_irqsave(&dma_spin_lock, flags);
  42. return flags;
  43. }
  44. static __inline__ void release_dma_lock(unsigned long flags)
  45. {
  46. spin_unlock_irqrestore(&dma_spin_lock, flags);
  47. }
  48. static __inline__ unsigned char fd_inb(int port)
  49. {
  50. if(MACH_IS_Q40)
  51. return inb_p(port);
  52. else if(MACH_IS_SUN3X)
  53. return sun3x_82072_fd_inb(port);
  54. return 0;
  55. }
  56. static __inline__ void fd_outb(unsigned char value, int port)
  57. {
  58. if(MACH_IS_Q40)
  59. outb_p(value, port);
  60. else if(MACH_IS_SUN3X)
  61. sun3x_82072_fd_outb(value, port);
  62. }
  63. static int fd_request_irq(void)
  64. {
  65. if(MACH_IS_Q40)
  66. return request_irq(FLOPPY_IRQ, floppy_hardint,
  67. 0, "floppy", floppy_hardint);
  68. else if(MACH_IS_SUN3X)
  69. return sun3xflop_request_irq();
  70. return -ENXIO;
  71. }
  72. static void fd_free_irq(void)
  73. {
  74. if(MACH_IS_Q40)
  75. free_irq(FLOPPY_IRQ, floppy_hardint);
  76. }
  77. #define fd_request_dma() vdma_request_dma(FLOPPY_DMA,"floppy")
  78. #define fd_get_dma_residue() vdma_get_dma_residue(FLOPPY_DMA)
  79. #define fd_dma_mem_alloc(size) vdma_mem_alloc(size)
  80. #define fd_dma_setup(addr, size, mode, io) vdma_dma_setup(addr, size, mode, io)
  81. #define fd_enable_irq() /* nothing... */
  82. #define fd_disable_irq() /* nothing... */
  83. #define fd_free_dma() /* nothing */
  84. /* No 64k boundary crossing problems on Q40 - no DMA at all */
  85. #define CROSS_64KB(a,s) (0)
  86. #define DMA_MODE_READ 0x44 /* i386 look-alike */
  87. #define DMA_MODE_WRITE 0x48
  88. static int m68k_floppy_init(void)
  89. {
  90. use_virtual_dma =1;
  91. can_use_virtual_dma = 1;
  92. if (MACH_IS_Q40)
  93. return 0x3f0;
  94. else if(MACH_IS_SUN3X)
  95. return sun3xflop_init();
  96. else
  97. return -1;
  98. }
  99. static int vdma_request_dma(unsigned int dmanr, const char * device_id)
  100. {
  101. return 0;
  102. }
  103. static int vdma_get_dma_residue(unsigned int dummy)
  104. {
  105. return virtual_dma_count + virtual_dma_residue;
  106. }
  107. static unsigned long vdma_mem_alloc(unsigned long size)
  108. {
  109. return (unsigned long) vmalloc(size);
  110. }
  111. static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
  112. {
  113. vfree((void *)addr);
  114. }
  115. #define fd_dma_mem_free(addr,size) _fd_dma_mem_free(addr, size)
  116. /* choose_dma_mode ???*/
  117. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  118. {
  119. doing_pdma = 1;
  120. virtual_dma_port = (MACH_IS_Q40 ? io : 0);
  121. virtual_dma_mode = (mode == DMA_MODE_WRITE);
  122. virtual_dma_addr = addr;
  123. virtual_dma_count = size;
  124. virtual_dma_residue = 0;
  125. return 0;
  126. }
  127. static void fd_disable_dma(void)
  128. {
  129. doing_pdma = 0;
  130. virtual_dma_residue += virtual_dma_count;
  131. virtual_dma_count=0;
  132. }
  133. /* this is the only truly Q40 specific function */
  134. asmlinkage irqreturn_t floppy_hardint(int irq, void *dev_id)
  135. {
  136. register unsigned char st;
  137. #undef TRACE_FLPY_INT
  138. #define NO_FLOPPY_ASSEMBLER
  139. #ifdef TRACE_FLPY_INT
  140. static int calls=0;
  141. static int bytes=0;
  142. static int dma_wait=0;
  143. #endif
  144. if(!doing_pdma) {
  145. floppy_interrupt(irq, dev_id);
  146. return IRQ_HANDLED;
  147. }
  148. #ifdef TRACE_FLPY_INT
  149. if(!calls)
  150. bytes = virtual_dma_count;
  151. #endif
  152. {
  153. register int lcount;
  154. register char *lptr;
  155. /* serve 1st byte fast: */
  156. st=1;
  157. for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
  158. lcount; lcount--, lptr++) {
  159. st=inb(virtual_dma_port+4) & 0xa0 ;
  160. if(st != 0xa0)
  161. break;
  162. if(virtual_dma_mode)
  163. outb_p(*lptr, virtual_dma_port+5);
  164. else
  165. *lptr = inb_p(virtual_dma_port+5);
  166. }
  167. virtual_dma_count = lcount;
  168. virtual_dma_addr = lptr;
  169. st = inb(virtual_dma_port+4);
  170. }
  171. #ifdef TRACE_FLPY_INT
  172. calls++;
  173. #endif
  174. if(st == 0x20)
  175. return IRQ_HANDLED;
  176. if(!(st & 0x20)) {
  177. virtual_dma_residue += virtual_dma_count;
  178. virtual_dma_count=0;
  179. #ifdef TRACE_FLPY_INT
  180. printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
  181. virtual_dma_count, virtual_dma_residue, calls, bytes,
  182. dma_wait);
  183. calls = 0;
  184. dma_wait=0;
  185. #endif
  186. doing_pdma = 0;
  187. floppy_interrupt(irq, dev_id);
  188. return IRQ_HANDLED;
  189. }
  190. #ifdef TRACE_FLPY_INT
  191. if(!virtual_dma_count)
  192. dma_wait++;
  193. #endif
  194. return IRQ_HANDLED;
  195. }
  196. #define EXTRA_FLOPPY_PARAMS