isadma.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /**
  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. /**
  68. * snd_dma_pointer - return the current pointer to DMA transfer buffer in bytes
  69. * @dma: the dma number
  70. * @size: the dma transfer size
  71. *
  72. * Returns the current pointer in DMA tranfer buffer in bytes
  73. */
  74. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
  75. {
  76. unsigned long flags;
  77. unsigned int result;
  78. flags = claim_dma_lock();
  79. clear_dma_ff(dma);
  80. if (!isa_dma_bridge_buggy)
  81. disable_dma(dma);
  82. result = get_dma_residue(dma);
  83. if (!isa_dma_bridge_buggy)
  84. enable_dma(dma);
  85. release_dma_lock(flags);
  86. #ifdef CONFIG_SND_DEBUG
  87. if (result > size)
  88. snd_printk(KERN_ERR "pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size);
  89. #endif
  90. if (result >= size || result == 0)
  91. return 0;
  92. else
  93. return size - result;
  94. }