floppy.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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)
  36. {
  37. unsigned char st;
  38. int lcount;
  39. char *lptr;
  40. if (!doing_vdma)
  41. return floppy_interrupt(irq, dev_id);
  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);
  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,
  84. IRQF_DISABLED, "floppy", NULL);
  85. else
  86. return request_irq(FLOPPY_IRQ, floppy_interrupt,
  87. IRQF_DISABLED, "floppy", NULL);
  88. }
  89. static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
  90. {
  91. doing_vdma = 1;
  92. virtual_dma_port = io;
  93. virtual_dma_mode = (mode == DMA_MODE_WRITE);
  94. virtual_dma_addr = addr;
  95. virtual_dma_count = size;
  96. virtual_dma_residue = 0;
  97. return 0;
  98. }
  99. static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
  100. {
  101. /* actual, physical DMA */
  102. doing_vdma = 0;
  103. clear_dma_ff(FLOPPY_DMA);
  104. set_dma_mode(FLOPPY_DMA,mode);
  105. set_dma_addr(FLOPPY_DMA,(unsigned int)virt_to_bus(addr));
  106. set_dma_count(FLOPPY_DMA,size);
  107. enable_dma(FLOPPY_DMA);
  108. return 0;
  109. }
  110. static struct fd_dma_ops real_dma_ops =
  111. {
  112. ._disable_dma = disable_dma,
  113. ._free_dma = free_dma,
  114. ._get_dma_residue = get_dma_residue,
  115. ._dma_setup = hard_dma_setup
  116. };
  117. static struct fd_dma_ops virt_dma_ops =
  118. {
  119. ._disable_dma = vdma_disable_dma,
  120. ._free_dma = vdma_nop,
  121. ._get_dma_residue = vdma_get_dma_residue,
  122. ._dma_setup = vdma_dma_setup
  123. };
  124. static int fd_request_dma()
  125. {
  126. if (can_use_virtual_dma & 1) {
  127. fd_ops = &virt_dma_ops;
  128. return 0;
  129. }
  130. else {
  131. fd_ops = &real_dma_ops;
  132. return request_dma(FLOPPY_DMA, "floppy");
  133. }
  134. }
  135. static int FDC1 = 0x3f0;
  136. static int FDC2 = -1;
  137. /*
  138. * Again, the CMOS information not available
  139. */
  140. #define FLOPPY0_TYPE 6
  141. #define FLOPPY1_TYPE 0
  142. #define N_FDC 2 /* Don't change this! */
  143. #define N_DRIVE 8
  144. #define FLOPPY_MOTOR_MASK 0xf0
  145. /*
  146. * The PowerPC has no problems with floppy DMA crossing 64k borders.
  147. */
  148. #define CROSS_64KB(a,s) (0)
  149. #endif /* __ASM_PPC_FLOPPY_H */
  150. #define EXTRA_FLOPPY_PARAMS
  151. #endif /* __KERNEL__ */