floppy.h 5.2 KB

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