aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma/coh901318.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2012-06-12 14:19:24 -0400
committerVinod Koul <vinod.koul@linux.intel.com>2012-06-13 23:12:26 -0400
commitf7ceb362c4d2f4e613982148ddb143ad6a205485 (patch)
treee8a7a60df04d48769d87495cc43cf4d08c77e1e4 /drivers/dma/coh901318.c
parent9102d8715e5c10db37d81ab75285a2f6746360b2 (diff)
dma: coh901318: use devm allocation
Allocate memory, region, remap and irq for device state using devm_* helpers to simplify memory accounting. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
Diffstat (limited to 'drivers/dma/coh901318.c')
-rw-r--r--drivers/dma/coh901318.c72
1 files changed, 24 insertions, 48 deletions
diff --git a/drivers/dma/coh901318.c b/drivers/dma/coh901318.c
index e67b4e06a918..aa384e53b7ac 100644
--- a/drivers/dma/coh901318.c
+++ b/drivers/dma/coh901318.c
@@ -1438,34 +1438,32 @@ static int __init coh901318_probe(struct platform_device *pdev)
1438 1438
1439 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1439 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1440 if (!io) 1440 if (!io)
1441 goto err_get_resource; 1441 return -ENODEV;
1442 1442
1443 /* Map DMA controller registers to virtual memory */ 1443 /* Map DMA controller registers to virtual memory */
1444 if (request_mem_region(io->start, 1444 if (devm_request_mem_region(&pdev->dev,
1445 resource_size(io), 1445 io->start,
1446 pdev->dev.driver->name) == NULL) { 1446 resource_size(io),
1447 err = -EBUSY; 1447 pdev->dev.driver->name) == NULL)
1448 goto err_request_mem; 1448 return -ENOMEM;
1449 }
1450 1449
1451 pdata = pdev->dev.platform_data; 1450 pdata = pdev->dev.platform_data;
1452 if (!pdata) 1451 if (!pdata)
1453 goto err_no_platformdata; 1452 return -ENODEV;
1454 1453
1455 base = kmalloc(ALIGN(sizeof(struct coh901318_base), 4) + 1454 base = devm_kzalloc(&pdev->dev,
1456 pdata->max_channels * 1455 ALIGN(sizeof(struct coh901318_base), 4) +
1457 sizeof(struct coh901318_chan), 1456 pdata->max_channels *
1458 GFP_KERNEL); 1457 sizeof(struct coh901318_chan),
1458 GFP_KERNEL);
1459 if (!base) 1459 if (!base)
1460 goto err_alloc_coh_dma_channels; 1460 return -ENOMEM;
1461 1461
1462 base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4); 1462 base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4);
1463 1463
1464 base->virtbase = ioremap(io->start, resource_size(io)); 1464 base->virtbase = devm_ioremap(&pdev->dev, io->start, resource_size(io));
1465 if (!base->virtbase) { 1465 if (!base->virtbase)
1466 err = -ENOMEM; 1466 return -ENOMEM;
1467 goto err_no_ioremap;
1468 }
1469 1467
1470 base->dev = &pdev->dev; 1468 base->dev = &pdev->dev;
1471 base->platform = pdata; 1469 base->platform = pdata;
@@ -1474,25 +1472,20 @@ static int __init coh901318_probe(struct platform_device *pdev)
1474 1472
1475 COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base); 1473 COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base);
1476 1474
1477 platform_set_drvdata(pdev, base);
1478
1479 irq = platform_get_irq(pdev, 0); 1475 irq = platform_get_irq(pdev, 0);
1480 if (irq < 0) 1476 if (irq < 0)
1481 goto err_no_irq; 1477 return irq;
1482 1478
1483 err = request_irq(irq, dma_irq_handler, IRQF_DISABLED, 1479 err = devm_request_irq(&pdev->dev, irq, dma_irq_handler, IRQF_DISABLED,
1484 "coh901318", base); 1480 "coh901318", base);
1485 if (err) { 1481 if (err)
1486 dev_crit(&pdev->dev, 1482 return err;
1487 "Cannot allocate IRQ for DMA controller!\n");
1488 goto err_request_irq;
1489 }
1490 1483
1491 err = coh901318_pool_create(&base->pool, &pdev->dev, 1484 err = coh901318_pool_create(&base->pool, &pdev->dev,
1492 sizeof(struct coh901318_lli), 1485 sizeof(struct coh901318_lli),
1493 32); 1486 32);
1494 if (err) 1487 if (err)
1495 goto err_pool_create; 1488 return err;
1496 1489
1497 /* init channels for device transfers */ 1490 /* init channels for device transfers */
1498 coh901318_base_init(&base->dma_slave, base->platform->chans_slave, 1491 coh901318_base_init(&base->dma_slave, base->platform->chans_slave,
@@ -1538,6 +1531,7 @@ static int __init coh901318_probe(struct platform_device *pdev)
1538 if (err) 1531 if (err)
1539 goto err_register_memcpy; 1532 goto err_register_memcpy;
1540 1533
1534 platform_set_drvdata(pdev, base);
1541 dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n", 1535 dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n",
1542 (u32) base->virtbase); 1536 (u32) base->virtbase);
1543 1537
@@ -1547,19 +1541,6 @@ static int __init coh901318_probe(struct platform_device *pdev)
1547 dma_async_device_unregister(&base->dma_slave); 1541 dma_async_device_unregister(&base->dma_slave);
1548 err_register_slave: 1542 err_register_slave:
1549 coh901318_pool_destroy(&base->pool); 1543 coh901318_pool_destroy(&base->pool);
1550 err_pool_create:
1551 free_irq(platform_get_irq(pdev, 0), base);
1552 err_request_irq:
1553 err_no_irq:
1554 iounmap(base->virtbase);
1555 err_no_ioremap:
1556 kfree(base);
1557 err_alloc_coh_dma_channels:
1558 err_no_platformdata:
1559 release_mem_region(pdev->resource->start,
1560 resource_size(pdev->resource));
1561 err_request_mem:
1562 err_get_resource:
1563 return err; 1544 return err;
1564} 1545}
1565 1546
@@ -1570,11 +1551,6 @@ static int __exit coh901318_remove(struct platform_device *pdev)
1570 dma_async_device_unregister(&base->dma_memcpy); 1551 dma_async_device_unregister(&base->dma_memcpy);
1571 dma_async_device_unregister(&base->dma_slave); 1552 dma_async_device_unregister(&base->dma_slave);
1572 coh901318_pool_destroy(&base->pool); 1553 coh901318_pool_destroy(&base->pool);
1573 free_irq(platform_get_irq(pdev, 0), base);
1574 iounmap(base->virtbase);
1575 kfree(base);
1576 release_mem_region(pdev->resource->start,
1577 resource_size(pdev->resource));
1578 return 0; 1554 return 0;
1579} 1555}
1580 1556