Skip to content

Commit 74465b4

Browse files
committed
atmel-mci: convert to dma_request_channel and down-level dma_slave
dma_request_channel provides an exclusive channel, so we no longer need to pass slave data through dmaengine. Cc: Haavard Skinnemoen <haavard.skinnemoen@atmel.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 33df8ca commit 74465b4

7 files changed

Lines changed: 62 additions & 159 deletions

File tree

‎arch/avr32/include/asm/atmel-mci.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define ATMEL_MCI_MAX_NR_SLOTS 2
55

6-
struct dma_slave;
6+
#include <linux/dw_dmac.h>
77

88
/**
99
* struct mci_slot_pdata - board-specific per-slot configuration
@@ -28,11 +28,11 @@ struct mci_slot_pdata {
2828

2929
/**
3030
* struct mci_platform_data - board-specific MMC/SDcard configuration
31-
* @dma_slave: DMA slave interface to use in data transfers, or NULL.
31+
* @dma_slave: DMA slave interface to use in data transfers.
3232
* @slot: Per-slot configuration data.
3333
*/
3434
struct mci_platform_data {
35-
struct dma_slave *dma_slave;
35+
struct dw_dma_slave dma_slave;
3636
struct mci_slot_pdata slot[ATMEL_MCI_MAX_NR_SLOTS];
3737
};
3838

‎arch/avr32/mach-at32ap/at32ap700x.c‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ struct platform_device *__init
13051305
at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
13061306
{
13071307
struct platform_device *pdev;
1308-
struct dw_dma_slave *dws;
1308+
struct dw_dma_slave *dws = &data->dma_slave;
13091309
u32 pioa_mask;
13101310
u32 piob_mask;
13111311

@@ -1324,22 +1324,13 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
13241324
ARRAY_SIZE(atmel_mci0_resource)))
13251325
goto fail;
13261326

1327-
if (data->dma_slave)
1328-
dws = kmemdup(to_dw_dma_slave(data->dma_slave),
1329-
sizeof(struct dw_dma_slave), GFP_KERNEL);
1330-
else
1331-
dws = kzalloc(sizeof(struct dw_dma_slave), GFP_KERNEL);
1332-
1333-
dws->slave.dev = &pdev->dev;
1334-
dws->slave.dma_dev = &dw_dmac0_device.dev;
1335-
dws->slave.reg_width = DMA_SLAVE_WIDTH_32BIT;
1327+
dws->dma_dev = &dw_dmac0_device.dev;
1328+
dws->reg_width = DW_DMA_SLAVE_WIDTH_32BIT;
13361329
dws->cfg_hi = (DWC_CFGH_SRC_PER(0)
13371330
| DWC_CFGH_DST_PER(1));
13381331
dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL
13391332
| DWC_CFGL_HS_SRC_POL);
13401333

1341-
data->dma_slave = &dws->slave;
1342-
13431334
if (platform_device_add_data(pdev, data,
13441335
sizeof(struct mci_platform_data)))
13451336
goto fail;

‎drivers/dma/dmaengine.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,6 @@ static void dma_client_chan_alloc(struct dma_client *client)
234234
list_for_each_entry(device, &dma_device_list, global_node) {
235235
if (dma_has_cap(DMA_PRIVATE, device->cap_mask))
236236
continue;
237-
/* Does the client require a specific DMA controller? */
238-
if (client->slave && client->slave->dma_dev
239-
&& client->slave->dma_dev != device->dev)
240-
continue;
241237
if (!dma_device_satisfies_mask(device, client->cap_mask))
242238
continue;
243239

@@ -613,10 +609,6 @@ void dma_async_client_register(struct dma_client *client)
613609
struct dma_chan *chan;
614610
int err;
615611

616-
/* validate client data */
617-
BUG_ON(dma_has_cap(DMA_SLAVE, client->cap_mask) &&
618-
!client->slave);
619-
620612
mutex_lock(&dma_list_mutex);
621613
dmaengine_ref_count++;
622614

‎drivers/dma/dw_dmac.c‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
567567
if (unlikely(!dws || !sg_len))
568568
return NULL;
569569

570-
reg_width = dws->slave.reg_width;
570+
reg_width = dws->reg_width;
571571
prev = first = NULL;
572572

573573
sg_len = dma_map_sg(chan->dev.parent, sgl, sg_len, direction);
@@ -579,7 +579,7 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
579579
| DWC_CTLL_DST_FIX
580580
| DWC_CTLL_SRC_INC
581581
| DWC_CTLL_FC_M2P);
582-
reg = dws->slave.tx_reg;
582+
reg = dws->tx_reg;
583583
for_each_sg(sgl, sg, sg_len, i) {
584584
struct dw_desc *desc;
585585
u32 len;
@@ -625,7 +625,7 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
625625
| DWC_CTLL_SRC_FIX
626626
| DWC_CTLL_FC_P2M);
627627

628-
reg = dws->slave.rx_reg;
628+
reg = dws->rx_reg;
629629
for_each_sg(sgl, sg, sg_len, i) {
630630
struct dw_desc *desc;
631631
u32 len;
@@ -764,20 +764,13 @@ static int dwc_alloc_chan_resources(struct dma_chan *chan,
764764
struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
765765
struct dw_dma *dw = to_dw_dma(chan->device);
766766
struct dw_desc *desc;
767-
struct dma_slave *slave;
768767
struct dw_dma_slave *dws;
769768
int i;
770769
u32 cfghi;
771770
u32 cfglo;
772771

773772
dev_vdbg(&chan->dev, "alloc_chan_resources\n");
774773

775-
/* Channels doing slave DMA can only handle one client. */
776-
if (dwc->dws || (client && client->slave)) {
777-
if (chan->client_count)
778-
return -EBUSY;
779-
}
780-
781774
/* ASSERT: channel is idle */
782775
if (dma_readl(dw, CH_EN) & dwc->mask) {
783776
dev_dbg(&chan->dev, "DMA channel not idle?\n");
@@ -789,23 +782,17 @@ static int dwc_alloc_chan_resources(struct dma_chan *chan,
789782
cfghi = DWC_CFGH_FIFO_MODE;
790783
cfglo = 0;
791784

792-
slave = client->slave;
793-
if (slave) {
785+
dws = dwc->dws;
786+
if (dws) {
794787
/*
795788
* We need controller-specific data to set up slave
796789
* transfers.
797790
*/
798-
BUG_ON(!slave->dma_dev || slave->dma_dev != dw->dma.dev);
799-
800-
dws = container_of(slave, struct dw_dma_slave, slave);
791+
BUG_ON(!dws->dma_dev || dws->dma_dev != dw->dma.dev);
801792

802-
dwc->dws = dws;
803793
cfghi = dws->cfg_hi;
804794
cfglo = dws->cfg_lo;
805-
} else {
806-
dwc->dws = NULL;
807795
}
808-
809796
channel_writel(dwc, CFG_LO, cfglo);
810797
channel_writel(dwc, CFG_HI, cfghi);
811798

‎drivers/mmc/host/atmel-mci.c‎

Lines changed: 27 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,60 +1441,6 @@ static irqreturn_t atmci_detect_interrupt(int irq, void *dev_id)
14411441
return IRQ_HANDLED;
14421442
}
14431443

1444-
#ifdef CONFIG_MMC_ATMELMCI_DMA
1445-
1446-
static inline struct atmel_mci *
1447-
dma_client_to_atmel_mci(struct dma_client *client)
1448-
{
1449-
return container_of(client, struct atmel_mci, dma.client);
1450-
}
1451-
1452-
static enum dma_state_client atmci_dma_event(struct dma_client *client,
1453-
struct dma_chan *chan, enum dma_state state)
1454-
{
1455-
struct atmel_mci *host;
1456-
enum dma_state_client ret = DMA_NAK;
1457-
1458-
host = dma_client_to_atmel_mci(client);
1459-
1460-
switch (state) {
1461-
case DMA_RESOURCE_AVAILABLE:
1462-
spin_lock_bh(&host->lock);
1463-
if (!host->dma.chan) {
1464-
host->dma.chan = chan;
1465-
ret = DMA_ACK;
1466-
}
1467-
spin_unlock_bh(&host->lock);
1468-
1469-
if (ret == DMA_ACK)
1470-
dev_info(&host->pdev->dev,
1471-
"Using %s for DMA transfers\n",
1472-
chan->dev.bus_id);
1473-
break;
1474-
1475-
case DMA_RESOURCE_REMOVED:
1476-
spin_lock_bh(&host->lock);
1477-
if (host->dma.chan == chan) {
1478-
host->dma.chan = NULL;
1479-
ret = DMA_ACK;
1480-
}
1481-
spin_unlock_bh(&host->lock);
1482-
1483-
if (ret == DMA_ACK)
1484-
dev_info(&host->pdev->dev,
1485-
"Lost %s, falling back to PIO\n",
1486-
chan->dev.bus_id);
1487-
break;
1488-
1489-
default:
1490-
break;
1491-
}
1492-
1493-
1494-
return ret;
1495-
}
1496-
#endif /* CONFIG_MMC_ATMELMCI_DMA */
1497-
14981444
static int __init atmci_init_slot(struct atmel_mci *host,
14991445
struct mci_slot_pdata *slot_data, unsigned int id,
15001446
u32 sdc_reg)
@@ -1598,6 +1544,18 @@ static void __exit atmci_cleanup_slot(struct atmel_mci_slot *slot,
15981544
mmc_free_host(slot->mmc);
15991545
}
16001546

1547+
#ifdef CONFIG_MMC_ATMELMCI_DMA
1548+
static enum dma_state_client filter(struct dma_chan *chan, void *slave)
1549+
{
1550+
struct dw_dma_slave *dws = slave;
1551+
1552+
if (dws->dma_dev == chan->device->dev)
1553+
return DMA_ACK;
1554+
else
1555+
return DMA_DUP;
1556+
}
1557+
#endif
1558+
16011559
static int __init atmci_probe(struct platform_device *pdev)
16021560
{
16031561
struct mci_platform_data *pdata;
@@ -1650,22 +1608,20 @@ static int __init atmci_probe(struct platform_device *pdev)
16501608
goto err_request_irq;
16511609

16521610
#ifdef CONFIG_MMC_ATMELMCI_DMA
1653-
if (pdata->dma_slave) {
1654-
struct dma_slave *slave = pdata->dma_slave;
1611+
if (pdata->dma_slave.dma_dev) {
1612+
struct dw_dma_slave *dws = &pdata->dma_slave;
1613+
dma_cap_mask_t mask;
16551614

1656-
slave->tx_reg = regs->start + MCI_TDR;
1657-
slave->rx_reg = regs->start + MCI_RDR;
1615+
dws->tx_reg = regs->start + MCI_TDR;
1616+
dws->rx_reg = regs->start + MCI_RDR;
16581617

16591618
/* Try to grab a DMA channel */
1660-
host->dma.client.event_callback = atmci_dma_event;
1661-
dma_cap_set(DMA_SLAVE, host->dma.client.cap_mask);
1662-
host->dma.client.slave = slave;
1663-
1664-
dma_async_client_register(&host->dma.client);
1665-
dma_async_client_chan_request(&host->dma.client);
1666-
} else {
1667-
dev_notice(&pdev->dev, "DMA not available, using PIO\n");
1619+
dma_cap_zero(mask);
1620+
dma_cap_set(DMA_SLAVE, mask);
1621+
host->dma.chan = dma_request_channel(mask, filter, dws);
16681622
}
1623+
if (!host->dma.chan)
1624+
dev_notice(&pdev->dev, "DMA not available, using PIO\n");
16691625
#endif /* CONFIG_MMC_ATMELMCI_DMA */
16701626

16711627
platform_set_drvdata(pdev, host);
@@ -1697,8 +1653,8 @@ static int __init atmci_probe(struct platform_device *pdev)
16971653

16981654
err_init_slot:
16991655
#ifdef CONFIG_MMC_ATMELMCI_DMA
1700-
if (pdata->dma_slave)
1701-
dma_async_client_unregister(&host->dma.client);
1656+
if (host->dma.chan)
1657+
dma_release_channel(host->dma.chan);
17021658
#endif
17031659
free_irq(irq, host);
17041660
err_request_irq:
@@ -1729,8 +1685,8 @@ static int __exit atmci_remove(struct platform_device *pdev)
17291685
clk_disable(host->mck);
17301686

17311687
#ifdef CONFIG_MMC_ATMELMCI_DMA
1732-
if (host->dma.client.slave)
1733-
dma_async_client_unregister(&host->dma.client);
1688+
if (host->dma.chan)
1689+
dma_release_channel(host->dma.chan);
17341690
#endif
17351691

17361692
free_irq(platform_get_irq(pdev, 0), host);
@@ -1759,7 +1715,7 @@ static void __exit atmci_exit(void)
17591715
platform_driver_unregister(&atmci_driver);
17601716
}
17611717

1762-
module_init(atmci_init);
1718+
late_initcall(atmci_init); /* try to load after dma driver when built-in */
17631719
module_exit(atmci_exit);
17641720

17651721
MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");

‎include/linux/dmaengine.h‎

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ enum dma_transaction_type {
9696
/* last transaction type for creation of the capabilities mask */
9797
#define DMA_TX_TYPE_END (DMA_SLAVE + 1)
9898

99-
/**
100-
* enum dma_slave_width - DMA slave register access width.
101-
* @DMA_SLAVE_WIDTH_8BIT: Do 8-bit slave register accesses
102-
* @DMA_SLAVE_WIDTH_16BIT: Do 16-bit slave register accesses
103-
* @DMA_SLAVE_WIDTH_32BIT: Do 32-bit slave register accesses
104-
*/
105-
enum dma_slave_width {
106-
DMA_SLAVE_WIDTH_8BIT,
107-
DMA_SLAVE_WIDTH_16BIT,
108-
DMA_SLAVE_WIDTH_32BIT,
109-
};
11099

111100
/**
112101
* enum dma_ctrl_flags - DMA flags to augment operation preparation,
@@ -132,32 +121,6 @@ enum dma_ctrl_flags {
132121
*/
133122
typedef struct { DECLARE_BITMAP(bits, DMA_TX_TYPE_END); } dma_cap_mask_t;
134123

135-
/**
136-
* struct dma_slave - Information about a DMA slave
137-
* @dev: device acting as DMA slave
138-
* @dma_dev: required DMA master device. If non-NULL, the client can not be
139-
* bound to other masters than this.
140-
* @tx_reg: physical address of data register used for
141-
* memory-to-peripheral transfers
142-
* @rx_reg: physical address of data register used for
143-
* peripheral-to-memory transfers
144-
* @reg_width: peripheral register width
145-
*
146-
* If dma_dev is non-NULL, the client can not be bound to other DMA
147-
* masters than the one corresponding to this device. The DMA master
148-
* driver may use this to determine if there is controller-specific
149-
* data wrapped around this struct. Drivers of platform code that sets
150-
* the dma_dev field must therefore make sure to use an appropriate
151-
* controller-specific dma slave structure wrapping this struct.
152-
*/
153-
struct dma_slave {
154-
struct device *dev;
155-
struct device *dma_dev;
156-
dma_addr_t tx_reg;
157-
dma_addr_t rx_reg;
158-
enum dma_slave_width reg_width;
159-
};
160-
161124
/**
162125
* struct dma_chan_percpu - the per-CPU part of struct dma_chan
163126
* @refcount: local_t used for open-coded "bigref" counting
@@ -248,7 +211,6 @@ typedef enum dma_state_client (*dma_filter_fn)(struct dma_chan *chan, void *filt
248211
struct dma_client {
249212
dma_event_callback event_callback;
250213
dma_cap_mask_t cap_mask;
251-
struct dma_slave *slave;
252214
struct list_head global_node;
253215
};
254216

0 commit comments

Comments
 (0)