diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2012-10-16 00:19:17 -0400 |
---|---|---|
committer | Vinod Koul <vinod.koul@intel.com> | 2013-01-08 01:04:14 -0500 |
commit | a9ddb575d6d6c58c39e8c44a22b84445fedb0521 (patch) | |
tree | 3c3b520bb61163d963c417c5355ac7c7cb5ad049 /drivers/dma | |
parent | 177d2bf5c7d3ab41bfb4ce2597dde668225958dd (diff) |
dmaengine: dw_dmac: Enhance device tree support
dw_dmac driver already supports device tree but it used to have its platform
data passed the non-DT way.
This patch does following changes:
- pass platform data via DT, non-DT way still takes precedence if both are used.
- create generic filter routine
- Earlier slave information was made available by slave specific filter routines
in chan->private field. Now, this information would be passed from within dmac
DT node. Slave drivers would now be required to pass bus_id (a string) as
parameter to this generic filter(), which would be compared against the slave
data passed from DT, by the generic filter routine.
- Update binding document
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
[Fixed __devinit usage]
Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
Diffstat (limited to 'drivers/dma')
-rw-r--r-- | drivers/dma/dw_dmac.c | 134 | ||||
-rw-r--r-- | drivers/dma/dw_dmac_regs.h | 4 |
2 files changed, 138 insertions, 0 deletions
diff --git a/drivers/dma/dw_dmac.c b/drivers/dma/dw_dmac.c index 8f0b111af4de..27b8e1d1845e 100644 --- a/drivers/dma/dw_dmac.c +++ b/drivers/dma/dw_dmac.c | |||
@@ -1179,6 +1179,50 @@ static void dwc_free_chan_resources(struct dma_chan *chan) | |||
1179 | dev_vdbg(chan2dev(chan), "%s: done\n", __func__); | 1179 | dev_vdbg(chan2dev(chan), "%s: done\n", __func__); |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | bool dw_dma_generic_filter(struct dma_chan *chan, void *param) | ||
1183 | { | ||
1184 | struct dw_dma *dw = to_dw_dma(chan->device); | ||
1185 | static struct dw_dma *last_dw; | ||
1186 | static char *last_bus_id; | ||
1187 | int i = -1; | ||
1188 | |||
1189 | /* | ||
1190 | * dmaengine framework calls this routine for all channels of all dma | ||
1191 | * controller, until true is returned. If 'param' bus_id is not | ||
1192 | * registered with a dma controller (dw), then there is no need of | ||
1193 | * running below function for all channels of dw. | ||
1194 | * | ||
1195 | * This block of code does this by saving the parameters of last | ||
1196 | * failure. If dw and param are same, i.e. trying on same dw with | ||
1197 | * different channel, return false. | ||
1198 | */ | ||
1199 | if ((last_dw == dw) && (last_bus_id == param)) | ||
1200 | return false; | ||
1201 | /* | ||
1202 | * Return true: | ||
1203 | * - If dw_dma's platform data is not filled with slave info, then all | ||
1204 | * dma controllers are fine for transfer. | ||
1205 | * - Or if param is NULL | ||
1206 | */ | ||
1207 | if (!dw->sd || !param) | ||
1208 | return true; | ||
1209 | |||
1210 | while (++i < dw->sd_count) { | ||
1211 | if (!strcmp(dw->sd[i].bus_id, param)) { | ||
1212 | chan->private = &dw->sd[i]; | ||
1213 | last_dw = NULL; | ||
1214 | last_bus_id = NULL; | ||
1215 | |||
1216 | return true; | ||
1217 | } | ||
1218 | } | ||
1219 | |||
1220 | last_dw = dw; | ||
1221 | last_bus_id = param; | ||
1222 | return false; | ||
1223 | } | ||
1224 | EXPORT_SYMBOL(dw_dma_generic_filter); | ||
1225 | |||
1182 | /* --------------------- Cyclic DMA API extensions -------------------- */ | 1226 | /* --------------------- Cyclic DMA API extensions -------------------- */ |
1183 | 1227 | ||
1184 | /** | 1228 | /** |
@@ -1462,6 +1506,91 @@ static void dw_dma_off(struct dw_dma *dw) | |||
1462 | dw->chan[i].initialized = false; | 1506 | dw->chan[i].initialized = false; |
1463 | } | 1507 | } |
1464 | 1508 | ||
1509 | #ifdef CONFIG_OF | ||
1510 | static struct dw_dma_platform_data * | ||
1511 | dw_dma_parse_dt(struct platform_device *pdev) | ||
1512 | { | ||
1513 | struct device_node *sn, *cn, *np = pdev->dev.of_node; | ||
1514 | struct dw_dma_platform_data *pdata; | ||
1515 | struct dw_dma_slave *sd; | ||
1516 | u32 tmp, arr[4]; | ||
1517 | |||
1518 | if (!np) { | ||
1519 | dev_err(&pdev->dev, "Missing DT data\n"); | ||
1520 | return NULL; | ||
1521 | } | ||
1522 | |||
1523 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | ||
1524 | if (!pdata) | ||
1525 | return NULL; | ||
1526 | |||
1527 | if (of_property_read_u32(np, "nr_channels", &pdata->nr_channels)) | ||
1528 | return NULL; | ||
1529 | |||
1530 | if (of_property_read_bool(np, "is_private")) | ||
1531 | pdata->is_private = true; | ||
1532 | |||
1533 | if (!of_property_read_u32(np, "chan_allocation_order", &tmp)) | ||
1534 | pdata->chan_allocation_order = (unsigned char)tmp; | ||
1535 | |||
1536 | if (!of_property_read_u32(np, "chan_priority", &tmp)) | ||
1537 | pdata->chan_priority = tmp; | ||
1538 | |||
1539 | if (!of_property_read_u32(np, "block_size", &tmp)) | ||
1540 | pdata->block_size = tmp; | ||
1541 | |||
1542 | if (!of_property_read_u32(np, "nr_masters", &tmp)) { | ||
1543 | if (tmp > 4) | ||
1544 | return NULL; | ||
1545 | |||
1546 | pdata->nr_masters = tmp; | ||
1547 | } | ||
1548 | |||
1549 | if (!of_property_read_u32_array(np, "data_width", arr, | ||
1550 | pdata->nr_masters)) | ||
1551 | for (tmp = 0; tmp < pdata->nr_masters; tmp++) | ||
1552 | pdata->data_width[tmp] = arr[tmp]; | ||
1553 | |||
1554 | /* parse slave data */ | ||
1555 | sn = of_find_node_by_name(np, "slave_info"); | ||
1556 | if (!sn) | ||
1557 | return pdata; | ||
1558 | |||
1559 | /* calculate number of slaves */ | ||
1560 | tmp = of_get_child_count(sn); | ||
1561 | if (!tmp) | ||
1562 | return NULL; | ||
1563 | |||
1564 | sd = devm_kzalloc(&pdev->dev, sizeof(*sd) * tmp, GFP_KERNEL); | ||
1565 | if (!sd) | ||
1566 | return NULL; | ||
1567 | |||
1568 | pdata->sd = sd; | ||
1569 | pdata->sd_count = tmp; | ||
1570 | |||
1571 | for_each_child_of_node(sn, cn) { | ||
1572 | sd->dma_dev = &pdev->dev; | ||
1573 | of_property_read_string(cn, "bus_id", &sd->bus_id); | ||
1574 | of_property_read_u32(cn, "cfg_hi", &sd->cfg_hi); | ||
1575 | of_property_read_u32(cn, "cfg_lo", &sd->cfg_lo); | ||
1576 | if (!of_property_read_u32(cn, "src_master", &tmp)) | ||
1577 | sd->src_master = tmp; | ||
1578 | |||
1579 | if (!of_property_read_u32(cn, "dst_master", &tmp)) | ||
1580 | sd->dst_master = tmp; | ||
1581 | sd++; | ||
1582 | } | ||
1583 | |||
1584 | return pdata; | ||
1585 | } | ||
1586 | #else | ||
1587 | static inline struct dw_dma_platform_data * | ||
1588 | dw_dma_parse_dt(struct platform_device *pdev) | ||
1589 | { | ||
1590 | return NULL; | ||
1591 | } | ||
1592 | #endif | ||
1593 | |||
1465 | static int dw_probe(struct platform_device *pdev) | 1594 | static int dw_probe(struct platform_device *pdev) |
1466 | { | 1595 | { |
1467 | struct dw_dma_platform_data *pdata; | 1596 | struct dw_dma_platform_data *pdata; |
@@ -1478,6 +1607,9 @@ static int dw_probe(struct platform_device *pdev) | |||
1478 | int i; | 1607 | int i; |
1479 | 1608 | ||
1480 | pdata = dev_get_platdata(&pdev->dev); | 1609 | pdata = dev_get_platdata(&pdev->dev); |
1610 | if (!pdata) | ||
1611 | pdata = dw_dma_parse_dt(pdev); | ||
1612 | |||
1481 | if (!pdata || pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) | 1613 | if (!pdata || pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) |
1482 | return -EINVAL; | 1614 | return -EINVAL; |
1483 | 1615 | ||
@@ -1512,6 +1644,8 @@ static int dw_probe(struct platform_device *pdev) | |||
1512 | clk_prepare_enable(dw->clk); | 1644 | clk_prepare_enable(dw->clk); |
1513 | 1645 | ||
1514 | dw->regs = regs; | 1646 | dw->regs = regs; |
1647 | dw->sd = pdata->sd; | ||
1648 | dw->sd_count = pdata->sd_count; | ||
1515 | 1649 | ||
1516 | /* get hardware configuration parameters */ | 1650 | /* get hardware configuration parameters */ |
1517 | if (autocfg) { | 1651 | if (autocfg) { |
diff --git a/drivers/dma/dw_dmac_regs.h b/drivers/dma/dw_dmac_regs.h index 88965597b7d0..88a069f66b89 100644 --- a/drivers/dma/dw_dmac_regs.h +++ b/drivers/dma/dw_dmac_regs.h | |||
@@ -239,6 +239,10 @@ struct dw_dma { | |||
239 | struct tasklet_struct tasklet; | 239 | struct tasklet_struct tasklet; |
240 | struct clk *clk; | 240 | struct clk *clk; |
241 | 241 | ||
242 | /* slave information */ | ||
243 | struct dw_dma_slave *sd; | ||
244 | unsigned int sd_count; | ||
245 | |||
242 | u8 all_chan_mask; | 246 | u8 all_chan_mask; |
243 | 247 | ||
244 | /* hardware configuration */ | 248 | /* hardware configuration */ |