isadma.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * ISA DMA support functions
  3. * Copyright (c) by Jaroslav Kysela <perex@suse.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/driver.h>
  27. #include <sound/core.h>
  28. #include <asm/dma.h>
  29. /**
  30. * snd_dma_program - program an ISA DMA transfer
  31. * @dma: the dma number
  32. * @addr: the physical address of the buffer
  33. * @size: the DMA transfer size
  34. * @mode: the DMA transfer mode, DMA_MODE_XXX
  35. *
  36. * Programs an ISA DMA transfer for the given buffer.
  37. */
  38. void snd_dma_program(unsigned long dma,
  39. unsigned long addr, unsigned int size,
  40. unsigned short mode)
  41. {
  42. unsigned long flags;
  43. flags = claim_dma_lock();
  44. disable_dma(dma);
  45. clear_dma_ff(dma);
  46. set_dma_mode(dma, mode);
  47. set_dma_addr(dma, addr);
  48. set_dma_count(dma, size);
  49. if (!(mode & DMA_MODE_NO_ENABLE))
  50. enable_dma(dma);
  51. release_dma_lock(flags);
  52. }
  53. EXPORT_SYMBOL(snd_dma_program);
  54. /**
  55. * snd_dma_disable - stop the ISA DMA transfer
  56. * @dma: the dma number
  57. *
  58. * Stops the ISA DMA transfer.
  59. */
  60. void snd_dma_disable(unsigned long dma)
  61. {
  62. unsigned long flags;
  63. flags = claim_dma_lock();
  64. clear_dma_ff(dma);
  65. disable_dma(dma);
  66. release_dma_lock(flags);
  67. }
  68. EXPORT_SYMBOL(snd_dma_disable);
  69. /**
  70. * snd_dma_pointer - return the current pointer to DMA transfer buffer in bytes
  71. * @dma: the dma number
  72. * @size: the dma transfer size
  73. *
  74. * Returns the current pointer in DMA tranfer buffer in bytes
  75. */
  76. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
  77. {
  78. unsigned long flags;
  79. unsigned int result;
  80. flags = claim_dma_lock();
  81. clear_dma_ff(dma);
  82. if (!isa_dma_bridge_buggy)
  83. disable_dma(dma);
  84. result = get_dma_residue(dma);
  85. if (!isa_dma_bridge_buggy)
  86. enable_dma(dma);
  87. release_dma_lock(flags);
  88. #ifdef CONFIG_SND_DEBUG
  89. if (result > size)
  90. snd_printk(KERN_ERR "pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size);
  91. #endif
  92. if (result >= size || result == 0)
  93. return 0;
  94. else
  95. return size - result;
  96. }
  97. EXPORT_SYMBOL(snd_dma_pointer);