floppy.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Architecture specific parts of the Floppy driver
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 1995
  9. */
  10. #ifdef __KERNEL__
  11. #ifndef __ASM_PPC_FLOPPY_H
  12. #define __ASM_PPC_FLOPPY_H
  13. #define fd_inb(port) inb_p(port)
  14. #define fd_outb(value,port) outb_p(value,port)
  15. #define fd_disable_dma() fd_ops->_disable_dma(FLOPPY_DMA)
  16. #define fd_free_dma() fd_ops->_free_dma(FLOPPY_DMA)
  17. #define fd_get_dma_residue() fd_ops->_get_dma_residue(FLOPPY_DMA)
  18. #define fd_dma_setup(addr, size, mode, io) fd_ops->_dma_setup(addr, size, mode, io)
  19. #define fd_enable_irq() enable_irq(FLOPPY_IRQ)
  20. #define fd_disable_irq() disable_irq(FLOPPY_IRQ)
  21. #define fd_free_irq() free_irq(FLOPPY_IRQ, NULL);
  22. static int fd_request_dma(void);
  23. struct fd_dma_ops {
  24. void (*_disable_dma)(unsigned int dmanr);
  25. void (*_free_dma)(unsigned int dmanr);
  26. int (*_get_dma_residue)(unsigned int dummy);
  27. int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
  28. };
  29. static int virtual_dma_count;
  30. static int virtual_dma_residue;
  31. static char *virtual_dma_addr;
  32. static int virtual_dma_mode;
  33. static int doing_vdma;
  34. static struct fd_dma_ops *fd_ops;
  35. static irqreturn_t floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
  36. {
  37. unsigned char st;
  38. int lcount;
  39. char *lptr;
  40. if (!doing_vdma)
  41. return floppy_interrupt(irq, dev_id, regs);
  42. st = 1;
  43. for (lcount=virtual_dma_count, lptr=virtual_dma_addr;
  44. lcount; lcount--, lptr++) {
  45. st=inb(virtual_dma_port+4) & 0xa0 ;
  46. if (st != 0xa0)
  47. break;
  48. if (virtual_dma_mode)
  49. outb_p(*lptr, virtual_dma_port+5);
  50. else
  51. *lptr = inb_p(virtual_dma_port+5);
  52. }
  53. virtual_dma_count = lcount;
  54. virtual_dma_addr = lptr;
  55. st = inb(virtual_dma_port+4);
  56. if (st == 0x20)
  57. return IRQ_HANDLED;
  58. if (!(st & 0x20)) {
  59. virtual_dma_residue += virtual_dma_count;
  60. virtual_dma_count=0;
  61. doing_vdma = 0;
  62. floppy_interrupt(irq, dev_id, regs);
  63. return IRQ_HANDLED;
  64. }
  65. return IRQ_HANDLED;
  66. }
  67. static void vdma_disable_dma(unsigned int dummy)
  68. {
  69. doing_vdma = 0;
  70. virtual_dma_residue += virtual_dma_count;
  71. virtual_dma_count=0;
  72. }
  73. static void vdma_nop(unsigned int dummy)
  74. {
  75. }
  76. static int vdma_get_dma_residue(unsigned int dummy)
  77. {
  78. return virtual_dma_count + virtual_dma_residue;
  79. }
  80. static int fd_request_irq(void)
  81. {
  82. if (can_use_virtual_dma)
  83. return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
  84. "floppy", NULL);
  85. else
  86. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  87. SA_INTERRUPT|SA_SAMPLE_RANDOM,
  88. "floppy", NULL);
  89. }
  90. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  91. {
  92. doing_vdma = 1;
  93. virtual_dma_port = io;
  94. virtual_dma_mode = (mode == DMA_MODE_WRITE);
  95. virtual_dma_addr = addr;
  96. virtual_dma_count = size;
  97. virtual_dma_residue = 0;
  98. return 0;
  99. }
  100. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  101. {
  102. /* actual, physical DMA */
  103. doing_vdma = 0;
  104. clear_dma_ff(FLOPPY_DMA);
  105. set_dma_mode(FLOPPY_DMA,mode);
  106. set_dma_addr(FLOPPY_DMA,(unsigned int)virt_to_bus(addr));
  107. set_dma_count(FLOPPY_DMA,size);
  108. enable_dma(FLOPPY_DMA);
  109. return 0;
  110. }
  111. static struct fd_dma_ops real_dma_ops =
  112. {
  113. ._disable_dma = disable_dma,
  114. ._free_dma = free_dma,
  115. ._get_dma_residue = get_dma_residue,
  116. ._dma_setup = hard_dma_setup
  117. };
  118. static struct fd_dma_ops virt_dma_ops =
  119. {
  120. ._disable_dma = vdma_disable_dma,
  121. ._free_dma = vdma_nop,
  122. ._get_dma_residue = vdma_get_dma_residue,
  123. ._dma_setup = vdma_dma_setup
  124. };
  125. static int fd_request_dma()
  126. {
  127. if (can_use_virtual_dma & 1) {
  128. fd_ops = &virt_dma_ops;
  129. return 0;
  130. }
  131. else {
  132. fd_ops = &real_dma_ops;
  133. return request_dma(FLOPPY_DMA, "floppy");
  134. }
  135. }
  136. static int FDC1 = 0x3f0;
  137. static int FDC2 = -1;
  138. /*
  139. * Again, the CMOS information not available
  140. */
  141. #define FLOPPY0_TYPE 6
  142. #define FLOPPY1_TYPE 0
  143. #define N_FDC 2 /* Don't change this! */
  144. #define N_DRIVE 8
  145. #define FLOPPY_MOTOR_MASK 0xf0
  146. /*
  147. * The PowerPC has no problems with floppy DMA crossing 64k borders.
  148. */
  149. #define CROSS_64KB(a,s) (0)
  150. #endif /* __ASM_PPC_FLOPPY_H */
  151. #define EXTRA_FLOPPY_PARAMS
  152. #endif /* __KERNEL__ */