floppy.h 5.1 KB

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