Skip to content

Commit ebe9b30

Browse files
Linus WalleijVinod Koul
authored andcommitted
dmaengine: pl08x: Make slave engine optional
If the vendor data does not specify any signals, we do not have to support slave DMA. Make the registration of the slave DMA engine optional, so we can use this for the FTDMAC020 in the Gemini that only has memcpy support. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent 9e97257 commit ebe9b30

1 file changed

Lines changed: 78 additions & 50 deletions

File tree

‎drivers/dma/amba-pl08x.c‎

Lines changed: 78 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ struct pl08x_dma_chan {
253253

254254
/**
255255
* struct pl08x_driver_data - the local state holder for the PL08x
256-
* @slave: slave engine for this instance
256+
* @slave: optional slave engine for this instance
257257
* @memcpy: memcpy engine for this instance
258+
* @has_slave: the PL08x has a slave engine (routed signals)
258259
* @base: virtual memory base (remapped) for the PL08x
259260
* @adev: the corresponding AMBA (PrimeCell) bus entry
260261
* @vd: vendor data for this PL08x variant
@@ -269,6 +270,7 @@ struct pl08x_dma_chan {
269270
struct pl08x_driver_data {
270271
struct dma_device slave;
271272
struct dma_device memcpy;
273+
bool has_slave;
272274
void __iomem *base;
273275
struct amba_device *adev;
274276
const struct vendor_data *vd;
@@ -705,7 +707,7 @@ static void pl08x_phy_free(struct pl08x_dma_chan *plchan)
705707
break;
706708
}
707709

708-
if (!next) {
710+
if (!next && pl08x->has_slave) {
709711
list_for_each_entry(p, &pl08x->slave.channels, vc.chan.device_node)
710712
if (p->state == PL08X_CHAN_WAITING) {
711713
next = p;
@@ -2085,12 +2087,15 @@ static int pl08x_debugfs_show(struct seq_file *s, void *data)
20852087
pl08x_state_str(chan->state));
20862088
}
20872089

2088-
seq_printf(s, "\nPL08x virtual slave channels:\n");
2089-
seq_printf(s, "CHANNEL:\tSTATE:\n");
2090-
seq_printf(s, "--------\t------\n");
2091-
list_for_each_entry(chan, &pl08x->slave.channels, vc.chan.device_node) {
2092-
seq_printf(s, "%s\t\t%s\n", chan->name,
2093-
pl08x_state_str(chan->state));
2090+
if (pl08x->has_slave) {
2091+
seq_printf(s, "\nPL08x virtual slave channels:\n");
2092+
seq_printf(s, "CHANNEL:\tSTATE:\n");
2093+
seq_printf(s, "--------\t------\n");
2094+
list_for_each_entry(chan, &pl08x->slave.channels,
2095+
vc.chan.device_node) {
2096+
seq_printf(s, "%s\t\t%s\n", chan->name,
2097+
pl08x_state_str(chan->state));
2098+
}
20942099
}
20952100

20962101
return 0;
@@ -2128,6 +2133,10 @@ static struct dma_chan *pl08x_find_chan_id(struct pl08x_driver_data *pl08x,
21282133
{
21292134
struct pl08x_dma_chan *chan;
21302135

2136+
/* Trying to get a slave channel from something with no slave support */
2137+
if (!pl08x->has_slave)
2138+
return NULL;
2139+
21312140
list_for_each_entry(chan, &pl08x->slave.channels, vc.chan.device_node) {
21322141
if (chan->signal == id)
21332142
return &chan->vc.chan;
@@ -2265,20 +2274,24 @@ static int pl08x_of_probe(struct amba_device *adev,
22652274
* for a device and have it's AHB interfaces set up at
22662275
* translation time.
22672276
*/
2268-
chanp = devm_kcalloc(&adev->dev,
2269-
pl08x->vd->signals,
2270-
sizeof(struct pl08x_channel_data),
2271-
GFP_KERNEL);
2272-
if (!chanp)
2273-
return -ENOMEM;
2277+
if (pl08x->vd->signals) {
2278+
chanp = devm_kcalloc(&adev->dev,
2279+
pl08x->vd->signals,
2280+
sizeof(struct pl08x_channel_data),
2281+
GFP_KERNEL);
2282+
if (!chanp)
2283+
return -ENOMEM;
22742284

2275-
pd->slave_channels = chanp;
2276-
for (i = 0; i < pl08x->vd->signals; i++) {
2277-
/* chanp->periph_buses will be assigned at translation */
2278-
chanp->bus_id = kasprintf(GFP_KERNEL, "slave%d", i);
2279-
chanp++;
2285+
pd->slave_channels = chanp;
2286+
for (i = 0; i < pl08x->vd->signals; i++) {
2287+
/*
2288+
* chanp->periph_buses will be assigned at translation
2289+
*/
2290+
chanp->bus_id = kasprintf(GFP_KERNEL, "slave%d", i);
2291+
chanp++;
2292+
}
2293+
pd->num_slave_channels = pl08x->vd->signals;
22802294
}
2281-
pd->num_slave_channels = pl08x->vd->signals;
22822295

22832296
pl08x->pd = pd;
22842297

@@ -2340,24 +2353,34 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
23402353
pl08x->memcpy.directions = BIT(DMA_MEM_TO_MEM);
23412354
pl08x->memcpy.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
23422355

2343-
/* Initialize slave engine */
2344-
dma_cap_set(DMA_SLAVE, pl08x->slave.cap_mask);
2345-
dma_cap_set(DMA_CYCLIC, pl08x->slave.cap_mask);
2346-
pl08x->slave.dev = &adev->dev;
2347-
pl08x->slave.device_free_chan_resources = pl08x_free_chan_resources;
2348-
pl08x->slave.device_prep_dma_interrupt = pl08x_prep_dma_interrupt;
2349-
pl08x->slave.device_tx_status = pl08x_dma_tx_status;
2350-
pl08x->slave.device_issue_pending = pl08x_issue_pending;
2351-
pl08x->slave.device_prep_slave_sg = pl08x_prep_slave_sg;
2352-
pl08x->slave.device_prep_dma_cyclic = pl08x_prep_dma_cyclic;
2353-
pl08x->slave.device_config = pl08x_config;
2354-
pl08x->slave.device_pause = pl08x_pause;
2355-
pl08x->slave.device_resume = pl08x_resume;
2356-
pl08x->slave.device_terminate_all = pl08x_terminate_all;
2357-
pl08x->slave.src_addr_widths = PL80X_DMA_BUSWIDTHS;
2358-
pl08x->slave.dst_addr_widths = PL80X_DMA_BUSWIDTHS;
2359-
pl08x->slave.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
2360-
pl08x->slave.residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT;
2356+
/*
2357+
* Initialize slave engine, if the block has no signals, that means
2358+
* we have no slave support.
2359+
*/
2360+
if (vd->signals) {
2361+
pl08x->has_slave = true;
2362+
dma_cap_set(DMA_SLAVE, pl08x->slave.cap_mask);
2363+
dma_cap_set(DMA_CYCLIC, pl08x->slave.cap_mask);
2364+
pl08x->slave.dev = &adev->dev;
2365+
pl08x->slave.device_free_chan_resources =
2366+
pl08x_free_chan_resources;
2367+
pl08x->slave.device_prep_dma_interrupt =
2368+
pl08x_prep_dma_interrupt;
2369+
pl08x->slave.device_tx_status = pl08x_dma_tx_status;
2370+
pl08x->slave.device_issue_pending = pl08x_issue_pending;
2371+
pl08x->slave.device_prep_slave_sg = pl08x_prep_slave_sg;
2372+
pl08x->slave.device_prep_dma_cyclic = pl08x_prep_dma_cyclic;
2373+
pl08x->slave.device_config = pl08x_config;
2374+
pl08x->slave.device_pause = pl08x_pause;
2375+
pl08x->slave.device_resume = pl08x_resume;
2376+
pl08x->slave.device_terminate_all = pl08x_terminate_all;
2377+
pl08x->slave.src_addr_widths = PL80X_DMA_BUSWIDTHS;
2378+
pl08x->slave.dst_addr_widths = PL80X_DMA_BUSWIDTHS;
2379+
pl08x->slave.directions =
2380+
BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
2381+
pl08x->slave.residue_granularity =
2382+
DMA_RESIDUE_GRANULARITY_SEGMENT;
2383+
}
23612384

23622385
/* Get the platform data */
23632386
pl08x->pd = dev_get_platdata(&adev->dev);
@@ -2465,13 +2488,15 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
24652488
}
24662489

24672490
/* Register slave channels */
2468-
ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave,
2469-
pl08x->pd->num_slave_channels, true);
2470-
if (ret < 0) {
2471-
dev_warn(&pl08x->adev->dev,
2472-
"%s failed to enumerate slave channels - %d\n",
2473-
__func__, ret);
2474-
goto out_no_slave;
2491+
if (pl08x->has_slave) {
2492+
ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave,
2493+
pl08x->pd->num_slave_channels, true);
2494+
if (ret < 0) {
2495+
dev_warn(&pl08x->adev->dev,
2496+
"%s failed to enumerate slave channels - %d\n",
2497+
__func__, ret);
2498+
goto out_no_slave;
2499+
}
24752500
}
24762501

24772502
ret = dma_async_device_register(&pl08x->memcpy);
@@ -2482,12 +2507,14 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
24822507
goto out_no_memcpy_reg;
24832508
}
24842509

2485-
ret = dma_async_device_register(&pl08x->slave);
2486-
if (ret) {
2487-
dev_warn(&pl08x->adev->dev,
2510+
if (pl08x->has_slave) {
2511+
ret = dma_async_device_register(&pl08x->slave);
2512+
if (ret) {
2513+
dev_warn(&pl08x->adev->dev,
24882514
"%s failed to register slave as an async device - %d\n",
24892515
__func__, ret);
2490-
goto out_no_slave_reg;
2516+
goto out_no_slave_reg;
2517+
}
24912518
}
24922519

24932520
amba_set_drvdata(adev, pl08x);
@@ -2501,7 +2528,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
25012528
out_no_slave_reg:
25022529
dma_async_device_unregister(&pl08x->memcpy);
25032530
out_no_memcpy_reg:
2504-
pl08x_free_virtual_channels(&pl08x->slave);
2531+
if (pl08x->has_slave)
2532+
pl08x_free_virtual_channels(&pl08x->slave);
25052533
out_no_slave:
25062534
pl08x_free_virtual_channels(&pl08x->memcpy);
25072535
out_no_memcpy:

0 commit comments

Comments
 (0)