Linux Audio

Check our new training course

Loading...
v5.4
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 *  ISA DMA support functions
 4 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 5 */
 6
 7/*
 8 * Defining following add some delay. Maybe this helps for some broken
 9 * ISA DMA controllers.
10 */
11
12#undef HAVE_REALLY_SLOW_DMA_CONTROLLER
13
14#include <linux/export.h>
15#include <sound/core.h>
16#include <asm/dma.h>
17
18/**
19 * snd_dma_program - program an ISA DMA transfer
20 * @dma: the dma number
21 * @addr: the physical address of the buffer
22 * @size: the DMA transfer size
23 * @mode: the DMA transfer mode, DMA_MODE_XXX
24 *
25 * Programs an ISA DMA transfer for the given buffer.
26 */
27void snd_dma_program(unsigned long dma,
28		     unsigned long addr, unsigned int size,
29                     unsigned short mode)
30{
31	unsigned long flags;
32
33	flags = claim_dma_lock();
34	disable_dma(dma);
35	clear_dma_ff(dma);
36	set_dma_mode(dma, mode);
37	set_dma_addr(dma, addr);
38	set_dma_count(dma, size);
39	if (!(mode & DMA_MODE_NO_ENABLE))
40		enable_dma(dma);
41	release_dma_lock(flags);
42}
 
43EXPORT_SYMBOL(snd_dma_program);
44
45/**
46 * snd_dma_disable - stop the ISA DMA transfer
47 * @dma: the dma number
48 *
49 * Stops the ISA DMA transfer.
50 */
51void snd_dma_disable(unsigned long dma)
52{
53	unsigned long flags;
54
55	flags = claim_dma_lock();
56	clear_dma_ff(dma);
57	disable_dma(dma);
58	release_dma_lock(flags);
59}
 
60EXPORT_SYMBOL(snd_dma_disable);
61
62/**
63 * snd_dma_pointer - return the current pointer to DMA transfer buffer in bytes
64 * @dma: the dma number
65 * @size: the dma transfer size
66 *
67 * Return: The current pointer in DMA transfer buffer in bytes.
68 */
69unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
70{
71	unsigned long flags;
72	unsigned int result, result1;
73
74	flags = claim_dma_lock();
75	clear_dma_ff(dma);
76	if (!isa_dma_bridge_buggy)
77		disable_dma(dma);
78	result = get_dma_residue(dma);
79	/*
80	 * HACK - read the counter again and choose higher value in order to
81	 * avoid reading during counter lower byte roll over if the
82	 * isa_dma_bridge_buggy is set.
83	 */
84	result1 = get_dma_residue(dma);
85	if (!isa_dma_bridge_buggy)
86		enable_dma(dma);
87	release_dma_lock(flags);
88	if (unlikely(result < result1))
89		result = result1;
90#ifdef CONFIG_SND_DEBUG
91	if (result > size)
92		pr_err("ALSA: pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size);
93#endif
94	if (result >= size || result == 0)
95		return 0;
96	else
97		return size - result;
98}
 
99EXPORT_SYMBOL(snd_dma_pointer);
v3.15
 
  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/*
 23 * Defining following add some delay. Maybe this helps for some broken
 24 * ISA DMA controllers.
 25 */
 26
 27#undef HAVE_REALLY_SLOW_DMA_CONTROLLER
 28
 29#include <linux/export.h>
 30#include <sound/core.h>
 31#include <asm/dma.h>
 32
 33/**
 34 * snd_dma_program - program an ISA DMA transfer
 35 * @dma: the dma number
 36 * @addr: the physical address of the buffer
 37 * @size: the DMA transfer size
 38 * @mode: the DMA transfer mode, DMA_MODE_XXX
 39 *
 40 * Programs an ISA DMA transfer for the given buffer.
 41 */
 42void snd_dma_program(unsigned long dma,
 43		     unsigned long addr, unsigned int size,
 44                     unsigned short mode)
 45{
 46	unsigned long flags;
 47
 48	flags = claim_dma_lock();
 49	disable_dma(dma);
 50	clear_dma_ff(dma);
 51	set_dma_mode(dma, mode);
 52	set_dma_addr(dma, addr);
 53	set_dma_count(dma, size);
 54	if (!(mode & DMA_MODE_NO_ENABLE))
 55		enable_dma(dma);
 56	release_dma_lock(flags);
 57}
 58
 59EXPORT_SYMBOL(snd_dma_program);
 60
 61/**
 62 * snd_dma_disable - stop the ISA DMA transfer
 63 * @dma: the dma number
 64 *
 65 * Stops the ISA DMA transfer.
 66 */
 67void snd_dma_disable(unsigned long dma)
 68{
 69	unsigned long flags;
 70
 71	flags = claim_dma_lock();
 72	clear_dma_ff(dma);
 73	disable_dma(dma);
 74	release_dma_lock(flags);
 75}
 76
 77EXPORT_SYMBOL(snd_dma_disable);
 78
 79/**
 80 * snd_dma_pointer - return the current pointer to DMA transfer buffer in bytes
 81 * @dma: the dma number
 82 * @size: the dma transfer size
 83 *
 84 * Return: The current pointer in DMA transfer buffer in bytes.
 85 */
 86unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
 87{
 88	unsigned long flags;
 89	unsigned int result, result1;
 90
 91	flags = claim_dma_lock();
 92	clear_dma_ff(dma);
 93	if (!isa_dma_bridge_buggy)
 94		disable_dma(dma);
 95	result = get_dma_residue(dma);
 96	/*
 97	 * HACK - read the counter again and choose higher value in order to
 98	 * avoid reading during counter lower byte roll over if the
 99	 * isa_dma_bridge_buggy is set.
100	 */
101	result1 = get_dma_residue(dma);
102	if (!isa_dma_bridge_buggy)
103		enable_dma(dma);
104	release_dma_lock(flags);
105	if (unlikely(result < result1))
106		result = result1;
107#ifdef CONFIG_SND_DEBUG
108	if (result > size)
109		pr_err("ALSA: pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size);
110#endif
111	if (result >= size || result == 0)
112		return 0;
113	else
114		return size - result;
115}
116
117EXPORT_SYMBOL(snd_dma_pointer);