isadma.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * ISA DMA support functions
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. /*
  22. * Defining following add some delay. Maybe this helps for some broken
  23. * ISA DMA controllers.
  24. */
  25. #undef HAVE_REALLY_SLOW_DMA_CONTROLLER
  26. #include <sound/core.h>
  27. #include <asm/dma.h>
  28. /**
  29. * snd_dma_program - program an ISA DMA transfer
  30. * @dma: the dma number
  31. * @addr: the physical address of the buffer
  32. * @size: the DMA transfer size
  33. * @mode: the DMA transfer mode, DMA_MODE_XXX
  34. *
  35. * Programs an ISA DMA transfer for the given buffer.
  36. */
  37. void snd_dma_program(unsigned long dma,
  38. unsigned long addr, unsigned int size,
  39. unsigned short mode)
  40. {
  41. unsigned long flags;
  42. flags = claim_dma_lock();
  43. disable_dma(dma);
  44. clear_dma_ff(dma);
  45. set_dma_mode(dma, mode);
  46. set_dma_addr(dma, addr);
  47. set_dma_count(dma, size);
  48. if (!(mode & DMA_MODE_NO_ENABLE))
  49. enable_dma(dma);
  50. release_dma_lock(flags);
  51. }
  52. EXPORT_SYMBOL(snd_dma_program);
  53. /**
  54. * snd_dma_disable - stop the ISA DMA transfer
  55. * @dma: the dma number
  56. *
  57. * Stops the ISA DMA transfer.
  58. */
  59. void snd_dma_disable(unsigned long dma)
  60. {
  61. unsigned long flags;
  62. flags = claim_dma_lock();
  63. clear_dma_ff(dma);
  64. disable_dma(dma);
  65. release_dma_lock(flags);
  66. }
  67. EXPORT_SYMBOL(snd_dma_disable);
  68. /**
  69. * snd_dma_pointer - return the current pointer to DMA transfer buffer in bytes
  70. * @dma: the dma number
  71. * @size: the dma transfer size
  72. *
  73. * Returns the current pointer in DMA tranfer buffer in bytes
  74. */
  75. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
  76. {
  77. unsigned long flags;
  78. unsigned int result, result1;
  79. flags = claim_dma_lock();
  80. clear_dma_ff(dma);
  81. if (!isa_dma_bridge_buggy)
  82. disable_dma(dma);
  83. result = get_dma_residue(dma);
  84. /*
  85. * HACK - read the counter again and choose higher value in order to
  86. * avoid reading during counter lower byte roll over if the
  87. * isa_dma_bridge_buggy is set.
  88. */
  89. result1 = get_dma_residue(dma);
  90. if (!isa_dma_bridge_buggy)
  91. enable_dma(dma);
  92. release_dma_lock(flags);
  93. if (unlikely(result < result1))
  94. result = result1;
  95. #ifdef CONFIG_SND_DEBUG
  96. if (result > size)
  97. snd_printk(KERN_ERR "pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size);
  98. #endif
  99. if (result >= size || result == 0)
  100. return 0;
  101. else
  102. return size - result;
  103. }
  104. EXPORT_SYMBOL(snd_dma_pointer);