Skip to content

Commit 784f5f8

Browse files
koalopopcornmix
authored andcommitted
dmaengine: Add support for BCM2708
Add support for DMA controller of BCM2708 as used in the Raspberry Pi. Currently it only supports cyclic DMA. Signed-off-by: Florian Meier <[email protected]> dmaengine: expand functionality by supporting scatter/gather transfers sdhci-bcm2708 and dma.c: fix for LITE channels DMA: fix cyclic LITE length overflow bug dmaengine: bcm2708: Remove chancnt affectations Mirror bcm2835-dma.c commit 9eba553: chancnt is already filled by dma_async_device_register, which uses the channel list to know how much channels there is. Since it's already filled, we can safely remove it from the drivers' probe function. Signed-off-by: Noralf Trønnes <[email protected]> dmaengine: bcm2708: overwrite dreq only if it is not set dreq is set when the DMA channel is fetched from Device Tree. slave_id is set using dmaengine_slave_config(). Only overwrite dreq with slave_id if it is not set. dreq/slave_id in the cyclic DMA case is not touched, because I don't have hardware to test with. Signed-off-by: Noralf Trønnes <[email protected]> dmaengine: bcm2708: do device registration in the board file Don't register the device in the driver. Do it in the board file. Signed-off-by: Noralf Trønnes <[email protected]> dmaengine: bcm2708: don't restrict DT support to ARCH_BCM2835 Both ARCH_BCM2835 and ARCH_BCM270x are built with OF now. Add Device Tree support to the non ARCH_BCM2835 case. Use the same driver name regardless of architecture. Signed-off-by: Noralf Trønnes <[email protected]> BCM270x_DT: add bcm2835-dma entry Add Device Tree entry for bcm2835-dma. The entry doesn't contain any resources since they are handled by the arch/arm/mach-bcm270x/dma.c driver. In non-DT mode, don't add the device in the board file. Signed-off-by: Noralf Trønnes <[email protected]> bcm2708-dmaengine: Add debug options BCM270x: Add memory and irq resources to dmaengine device and DT Prepare for merging of the legacy DMA API arch driver dma.c with bcm2708-dmaengine by adding memory and irq resources both to platform file device and Device Tree node. Don't use BCM_DMAMAN_DRIVER_NAME so we don't have to include mach/dma.h Signed-off-by: Noralf Trønnes <[email protected]> dmaengine: bcm2708: Merge with arch dma.c driver and disable dma.c Merge the legacy DMA API driver with bcm2708-dmaengine. This is done so we can use bcm2708_fb on ARCH_BCM2835 (mailbox driver is also needed). Changes to the dma.c code: - Use BIT() macro. - Cutdown some comments to one line. - Add mutex to vc_dmaman and use this, since the dev lock is locked during probing of the engine part. - Add global g_dmaman variable since drvdata is used by the engine part. - Restructure for readability: vc_dmaman_chan_alloc() vc_dmaman_chan_free() bcm_dma_chan_free() - Restructure bcm_dma_chan_alloc() to simplify error handling. - Use device irq resources instead of hardcoded bcm_dma_irqs table. - Remove dev_dmaman_register() and code it directly. - Remove dev_dmaman_deregister() and code it directly. - Simplify bcm_dmaman_probe() using devm_* functions. - Get dmachans from DT if available. - Keep 'dma.dmachans' module argument name for backwards compatibility. Make it available on ARCH_BCM2835 as well. Signed-off-by: Noralf Trønnes <[email protected]> dmaengine: bcm2708: set residue_granularity field bcm2708-dmaengine supports residue reporting at burst level but didn't report this via the residue_granularity field. Without this field set properly we get playback issues with I2S cards. dmaengine: bcm2708-dmaengine: Fix memory leak when stopping a running transfer bcm2708-dmaengine: Use more DMA channels (but not 12) 1) Only the bcm2708_fb drivers uses the legacy DMA API, and it requires a BULK-capable channel, so all other types (FAST, NORMAL and LITE) can be made available to the regular DMA API. 2) DMA channels 11-14 share an interrupt. The driver can't handle this, so don't use channels 12-14 (12 was used, probably because it appears to have an interrupt, but in reality that interrupt is for activity on ANY channel). This may explain a lockup encountered when running out of DMA channels. The combined effect of this patch is to leave 7 DMA channels available + channel 0 for bcm2708_fb via the legacy API. See: #1110 #1108 dmaengine: bcm2708: Make legacy API available for bcm2835-dma bcm2708_fb uses the legacy DMA API, so in order to start using bcm2835-dma, bcm2835-dma has to support the legacy API. Make this possible by exporting bcm_dmaman_probe() and bcm_dmaman_remove(). Signed-off-by: Noralf Trønnes <[email protected]> dmaengine: bcm2708: Change DT compatible string Both bcm2835-dma and bcm2708-dmaengine have the same compatible string. So change compatible to "brcm,bcm2708-dma". Signed-off-by: Noralf Trønnes <[email protected]> dmaengine: bcm2708: Remove driver but keep legacy API Dropping non-DT support means we don't need this driver, but we still need the legacy DMA API. Signed-off-by: Noralf Trønnes <[email protected]> bcm2708-dmaengine - Fix arm64 portability/build issues dma-bcm2708: Fix module compilation of CONFIG_DMA_BCM2708 bcm2708-dmaengine.c defines functions like bcm_dma_start which are defined as well in dma-bcm2708.h as inline versions when CONFIG_DMA_BCM2708 is not defined. This works fine when CONFIG_DMA_BCM2708 is built in, but when it is selected as module build fails with redefinition errors because in the build system when CONFIG_DMA_BCM2708 is selected as module, the macro becomes CONFIG_DMA_BCM2708_MODULE. This patch makes the header use CONFIG_DMA_BCM2708_MODULE too when available. Fixes #2056 Signed-off-by: Andrei Gherzan <[email protected]> bcm2708-dmaengine: Use platform_get_irq The platform driver framework no longer creates IRQ resources for platform devices because they are expected to use platform_get_irq. This causes the bcm2808_fb acceleration to fail. Fix the problem by calling platform_get_irq as intended. See: #5131 Signed-off-by: Phil Elwell <[email protected]>
1 parent 5c16b50 commit 784f5f8

File tree

4 files changed

+430
-1
lines changed

4 files changed

+430
-1
lines changed

drivers/dma/Kconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ config BCM_SBA_RAID
136136

137137
config DMA_BCM2835
138138
tristate "BCM2835 DMA engine support"
139-
depends on ARCH_BCM2835 || ARCH_BCM2708 || ARCH_BCM2709
139+
depends on ARCH_BCM2835
140140
select DMA_ENGINE
141141
select DMA_VIRTUAL_CHANNELS
142142

@@ -669,6 +669,10 @@ config UNIPHIER_XDMAC
669669
UniPhier platform. This DMA controller can transfer data from
670670
memory to memory, memory to peripheral and peripheral to memory.
671671

672+
config DMA_BCM2708
673+
tristate "BCM2708 DMA legacy API support"
674+
depends on DMA_BCM2835
675+
672676
config XGENE_DMA
673677
tristate "APM X-Gene DMA support"
674678
depends on ARCH_XGENE || COMPILE_TEST

drivers/dma/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
2121
obj-$(CONFIG_AT_XDMAC) += at_xdmac.o
2222
obj-$(CONFIG_AXI_DMAC) += dma-axi-dmac.o
2323
obj-$(CONFIG_BCM_SBA_RAID) += bcm-sba-raid.o
24+
obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
2425
obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o
2526
obj-$(CONFIG_DMA_JZ4780) += dma-jz4780.o
2627
obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o

drivers/dma/bcm2708-dmaengine.c

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
/*
2+
* BCM2708 legacy DMA API
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*/
14+
15+
#include <linux/init.h>
16+
#include <linux/interrupt.h>
17+
#include <linux/list.h>
18+
#include <linux/module.h>
19+
#include <linux/platform_data/dma-bcm2708.h>
20+
#include <linux/platform_device.h>
21+
#include <linux/slab.h>
22+
#include <linux/io.h>
23+
#include <linux/spinlock.h>
24+
25+
#include "virt-dma.h"
26+
27+
#define CACHE_LINE_MASK 31
28+
#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
29+
30+
/* valid only for channels 0 - 14, 15 has its own base address */
31+
#define BCM2708_DMA_CHAN(n) ((n) << 8) /* base address */
32+
#define BCM2708_DMA_CHANIO(dma_base, n) \
33+
((void __iomem *)((char *)(dma_base) + BCM2708_DMA_CHAN(n)))
34+
35+
struct vc_dmaman {
36+
void __iomem *dma_base;
37+
u32 chan_available; /* bitmap of available channels */
38+
u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
39+
struct mutex lock;
40+
};
41+
42+
static struct device *dmaman_dev; /* we assume there's only one! */
43+
static struct vc_dmaman *g_dmaman; /* DMA manager */
44+
45+
/* DMA Auxiliary Functions */
46+
47+
/* A DMA buffer on an arbitrary boundary may separate a cache line into a
48+
section inside the DMA buffer and another section outside it.
49+
Even if we flush DMA buffers from the cache there is always the chance that
50+
during a DMA someone will access the part of a cache line that is outside
51+
the DMA buffer - which will then bring in unwelcome data.
52+
Without being able to dictate our own buffer pools we must insist that
53+
DMA buffers consist of a whole number of cache lines.
54+
*/
55+
extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
56+
{
57+
int i;
58+
59+
for (i = 0; i < sg_len; i++) {
60+
if (sg_ptr[i].offset & CACHE_LINE_MASK ||
61+
sg_ptr[i].length & CACHE_LINE_MASK)
62+
return 0;
63+
}
64+
65+
return 1;
66+
}
67+
EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
68+
69+
extern void bcm_dma_start(void __iomem *dma_chan_base,
70+
dma_addr_t control_block)
71+
{
72+
dsb(sy); /* ARM data synchronization (push) operation */
73+
74+
writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
75+
writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
76+
}
77+
EXPORT_SYMBOL_GPL(bcm_dma_start);
78+
79+
extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
80+
{
81+
dsb(sy);
82+
83+
/* ugly busy wait only option for now */
84+
while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
85+
cpu_relax();
86+
}
87+
EXPORT_SYMBOL_GPL(bcm_dma_wait_idle);
88+
89+
extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
90+
{
91+
dsb(sy);
92+
93+
return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
94+
}
95+
EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
96+
97+
/* Complete an ongoing DMA (assuming its results are to be ignored)
98+
Does nothing if there is no DMA in progress.
99+
This routine waits for the current AXI transfer to complete before
100+
terminating the current DMA. If the current transfer is hung on a DREQ used
101+
by an uncooperative peripheral the AXI transfer may never complete. In this
102+
case the routine times out and return a non-zero error code.
103+
Use of this routine doesn't guarantee that the ongoing or aborted DMA
104+
does not produce an interrupt.
105+
*/
106+
extern int bcm_dma_abort(void __iomem *dma_chan_base)
107+
{
108+
unsigned long int cs;
109+
int rc = 0;
110+
111+
cs = readl(dma_chan_base + BCM2708_DMA_CS);
112+
113+
if (BCM2708_DMA_ACTIVE & cs) {
114+
long int timeout = 10000;
115+
116+
/* write 0 to the active bit - pause the DMA */
117+
writel(0, dma_chan_base + BCM2708_DMA_CS);
118+
119+
/* wait for any current AXI transfer to complete */
120+
while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
121+
cs = readl(dma_chan_base + BCM2708_DMA_CS);
122+
123+
if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
124+
/* we'll un-pause when we set of our next DMA */
125+
rc = -ETIMEDOUT;
126+
127+
} else if (BCM2708_DMA_ACTIVE & cs) {
128+
/* terminate the control block chain */
129+
writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
130+
131+
/* abort the whole DMA */
132+
writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
133+
dma_chan_base + BCM2708_DMA_CS);
134+
}
135+
}
136+
137+
return rc;
138+
}
139+
EXPORT_SYMBOL_GPL(bcm_dma_abort);
140+
141+
/* DMA Manager Device Methods */
142+
143+
static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
144+
u32 chans_available)
145+
{
146+
dmaman->dma_base = dma_base;
147+
dmaman->chan_available = chans_available;
148+
dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* 2 & 3 */
149+
dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* 0 */
150+
dmaman->has_feature[BCM_DMA_FEATURE_NORMAL_ORD] = 0xfe; /* 1 to 7 */
151+
dmaman->has_feature[BCM_DMA_FEATURE_LITE_ORD] = 0x7f00; /* 8 to 14 */
152+
}
153+
154+
static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
155+
unsigned required_feature_set)
156+
{
157+
u32 chans;
158+
int chan = 0;
159+
int feature;
160+
161+
chans = dmaman->chan_available;
162+
for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
163+
/* select the subset of available channels with the desired
164+
features */
165+
if (required_feature_set & (1 << feature))
166+
chans &= dmaman->has_feature[feature];
167+
168+
if (!chans)
169+
return -ENOENT;
170+
171+
/* return the ordinal of the first channel in the bitmap */
172+
while (chans != 0 && (chans & 1) == 0) {
173+
chans >>= 1;
174+
chan++;
175+
}
176+
/* claim the channel */
177+
dmaman->chan_available &= ~(1 << chan);
178+
179+
return chan;
180+
}
181+
182+
static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
183+
{
184+
if (chan < 0)
185+
return -EINVAL;
186+
187+
if ((1 << chan) & dmaman->chan_available)
188+
return -EIDRM;
189+
190+
dmaman->chan_available |= (1 << chan);
191+
192+
return 0;
193+
}
194+
195+
/* DMA Manager Monitor */
196+
197+
extern int bcm_dma_chan_alloc(unsigned required_feature_set,
198+
void __iomem **out_dma_base, int *out_dma_irq)
199+
{
200+
struct vc_dmaman *dmaman = g_dmaman;
201+
struct platform_device *pdev = to_platform_device(dmaman_dev);
202+
int chan;
203+
int irq;
204+
205+
if (!dmaman_dev)
206+
return -ENODEV;
207+
208+
mutex_lock(&dmaman->lock);
209+
chan = vc_dmaman_chan_alloc(dmaman, required_feature_set);
210+
if (chan < 0)
211+
goto out;
212+
213+
irq = platform_get_irq(pdev, (unsigned int)chan);
214+
if (irq < 0) {
215+
dev_err(dmaman_dev, "failed to get irq for DMA channel %d\n",
216+
chan);
217+
vc_dmaman_chan_free(dmaman, chan);
218+
chan = -ENOENT;
219+
goto out;
220+
}
221+
222+
*out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base, chan);
223+
*out_dma_irq = irq;
224+
dev_dbg(dmaman_dev,
225+
"Legacy API allocated channel=%d, base=%p, irq=%i\n",
226+
chan, *out_dma_base, *out_dma_irq);
227+
228+
out:
229+
mutex_unlock(&dmaman->lock);
230+
231+
return chan;
232+
}
233+
EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
234+
235+
extern int bcm_dma_chan_free(int channel)
236+
{
237+
struct vc_dmaman *dmaman = g_dmaman;
238+
int rc;
239+
240+
if (!dmaman_dev)
241+
return -ENODEV;
242+
243+
mutex_lock(&dmaman->lock);
244+
rc = vc_dmaman_chan_free(dmaman, channel);
245+
mutex_unlock(&dmaman->lock);
246+
247+
return rc;
248+
}
249+
EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
250+
251+
int bcm_dmaman_probe(struct platform_device *pdev, void __iomem *base,
252+
u32 chans_available)
253+
{
254+
struct device *dev = &pdev->dev;
255+
struct vc_dmaman *dmaman;
256+
257+
dmaman = devm_kzalloc(dev, sizeof(*dmaman), GFP_KERNEL);
258+
if (!dmaman)
259+
return -ENOMEM;
260+
261+
mutex_init(&dmaman->lock);
262+
vc_dmaman_init(dmaman, base, chans_available);
263+
g_dmaman = dmaman;
264+
dmaman_dev = dev;
265+
266+
dev_info(dev, "DMA legacy API manager, dmachans=0x%x\n",
267+
chans_available);
268+
269+
return 0;
270+
}
271+
EXPORT_SYMBOL(bcm_dmaman_probe);
272+
273+
int bcm_dmaman_remove(struct platform_device *pdev)
274+
{
275+
dmaman_dev = NULL;
276+
277+
return 0;
278+
}
279+
EXPORT_SYMBOL(bcm_dmaman_remove);
280+
281+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)