Commit c1c63a14 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Vinod Koul

DMA: shdma: switch to managed resource allocation

Switch shdma to using devm_* managed functions for allocation of memory,
requesting IRQs, mapping IO resources etc.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
parent ca8b3878
...@@ -831,8 +831,8 @@ static irqreturn_t chan_irqt(int irq, void *dev) ...@@ -831,8 +831,8 @@ static irqreturn_t chan_irqt(int irq, void *dev)
int shdma_request_irq(struct shdma_chan *schan, int irq, int shdma_request_irq(struct shdma_chan *schan, int irq,
unsigned long flags, const char *name) unsigned long flags, const char *name)
{ {
int ret = request_threaded_irq(irq, chan_irq, chan_irqt, int ret = devm_request_threaded_irq(schan->dev, irq, chan_irq,
flags, name, schan); chan_irqt, flags, name, schan);
schan->irq = ret < 0 ? ret : irq; schan->irq = ret < 0 ? ret : irq;
...@@ -840,13 +840,6 @@ int shdma_request_irq(struct shdma_chan *schan, int irq, ...@@ -840,13 +840,6 @@ int shdma_request_irq(struct shdma_chan *schan, int irq,
} }
EXPORT_SYMBOL(shdma_request_irq); EXPORT_SYMBOL(shdma_request_irq);
void shdma_free_irq(struct shdma_chan *schan)
{
if (schan->irq >= 0)
free_irq(schan->irq, schan);
}
EXPORT_SYMBOL(shdma_free_irq);
void shdma_chan_probe(struct shdma_dev *sdev, void shdma_chan_probe(struct shdma_dev *sdev,
struct shdma_chan *schan, int id) struct shdma_chan *schan, int id)
{ {
......
...@@ -515,7 +515,8 @@ static int sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id, ...@@ -515,7 +515,8 @@ static int sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id,
struct shdma_chan *schan; struct shdma_chan *schan;
int err; int err;
sh_chan = kzalloc(sizeof(struct sh_dmae_chan), GFP_KERNEL); sh_chan = devm_kzalloc(sdev->dma_dev.dev, sizeof(struct sh_dmae_chan),
GFP_KERNEL);
if (!sh_chan) { if (!sh_chan) {
dev_err(sdev->dma_dev.dev, dev_err(sdev->dma_dev.dev,
"No free memory for allocating dma channels!\n"); "No free memory for allocating dma channels!\n");
...@@ -551,7 +552,6 @@ static int sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id, ...@@ -551,7 +552,6 @@ static int sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id,
err_no_irq: err_no_irq:
/* remove from dmaengine device node */ /* remove from dmaengine device node */
shdma_chan_remove(schan); shdma_chan_remove(schan);
kfree(sh_chan);
return err; return err;
} }
...@@ -562,14 +562,9 @@ static void sh_dmae_chan_remove(struct sh_dmae_device *shdev) ...@@ -562,14 +562,9 @@ static void sh_dmae_chan_remove(struct sh_dmae_device *shdev)
int i; int i;
shdma_for_each_chan(schan, &shdev->shdma_dev, i) { shdma_for_each_chan(schan, &shdev->shdma_dev, i) {
struct sh_dmae_chan *sh_chan = container_of(schan,
struct sh_dmae_chan, shdma_chan);
BUG_ON(!schan); BUG_ON(!schan);
shdma_free_irq(&sh_chan->shdma_chan);
shdma_chan_remove(schan); shdma_chan_remove(schan);
kfree(sh_chan);
} }
dma_dev->chancnt = 0; dma_dev->chancnt = 0;
} }
...@@ -706,33 +701,22 @@ static int sh_dmae_probe(struct platform_device *pdev) ...@@ -706,33 +701,22 @@ static int sh_dmae_probe(struct platform_device *pdev)
if (!chan || !errirq_res) if (!chan || !errirq_res)
return -ENODEV; return -ENODEV;
if (!request_mem_region(chan->start, resource_size(chan), pdev->name)) { shdev = devm_kzalloc(&pdev->dev, sizeof(struct sh_dmae_device),
dev_err(&pdev->dev, "DMAC register region already claimed\n"); GFP_KERNEL);
return -EBUSY;
}
if (dmars && !request_mem_region(dmars->start, resource_size(dmars), pdev->name)) {
dev_err(&pdev->dev, "DMAC DMARS region already claimed\n");
err = -EBUSY;
goto ermrdmars;
}
err = -ENOMEM;
shdev = kzalloc(sizeof(struct sh_dmae_device), GFP_KERNEL);
if (!shdev) { if (!shdev) {
dev_err(&pdev->dev, "Not enough memory\n"); dev_err(&pdev->dev, "Not enough memory\n");
goto ealloc; return -ENOMEM;
} }
dma_dev = &shdev->shdma_dev.dma_dev; dma_dev = &shdev->shdma_dev.dma_dev;
shdev->chan_reg = ioremap(chan->start, resource_size(chan)); shdev->chan_reg = devm_ioremap_resource(&pdev->dev, chan);
if (!shdev->chan_reg) if (IS_ERR(shdev->chan_reg))
goto emapchan; return PTR_ERR(shdev->chan_reg);
if (dmars) { if (dmars) {
shdev->dmars = ioremap(dmars->start, resource_size(dmars)); shdev->dmars = devm_ioremap_resource(&pdev->dev, dmars);
if (!shdev->dmars) if (IS_ERR(shdev->dmars))
goto emapdmars; return PTR_ERR(shdev->dmars);
} }
if (!pdata->slave_only) if (!pdata->slave_only)
...@@ -793,8 +777,8 @@ static int sh_dmae_probe(struct platform_device *pdev) ...@@ -793,8 +777,8 @@ static int sh_dmae_probe(struct platform_device *pdev)
errirq = errirq_res->start; errirq = errirq_res->start;
err = request_irq(errirq, sh_dmae_err, irqflags, err = devm_request_irq(&pdev->dev, errirq, sh_dmae_err, irqflags,
"DMAC Address Error", shdev); "DMAC Address Error", shdev);
if (err) { if (err) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"DMA failed requesting irq #%d, error %d\n", "DMA failed requesting irq #%d, error %d\n",
...@@ -872,7 +856,6 @@ static int sh_dmae_probe(struct platform_device *pdev) ...@@ -872,7 +856,6 @@ static int sh_dmae_probe(struct platform_device *pdev)
sh_dmae_chan_remove(shdev); sh_dmae_chan_remove(shdev);
#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE) #if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
free_irq(errirq, shdev);
eirq_err: eirq_err:
#endif #endif
rst_err: rst_err:
...@@ -886,18 +869,7 @@ static int sh_dmae_probe(struct platform_device *pdev) ...@@ -886,18 +869,7 @@ static int sh_dmae_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
shdma_cleanup(&shdev->shdma_dev); shdma_cleanup(&shdev->shdma_dev);
eshdma: eshdma:
if (dmars)
iounmap(shdev->dmars);
emapdmars:
iounmap(shdev->chan_reg);
synchronize_rcu(); synchronize_rcu();
emapchan:
kfree(shdev);
ealloc:
if (dmars)
release_mem_region(dmars->start, resource_size(dmars));
ermrdmars:
release_mem_region(chan->start, resource_size(chan));
return err; return err;
} }
...@@ -923,21 +895,9 @@ static int sh_dmae_remove(struct platform_device *pdev) ...@@ -923,21 +895,9 @@ static int sh_dmae_remove(struct platform_device *pdev)
sh_dmae_chan_remove(shdev); sh_dmae_chan_remove(shdev);
shdma_cleanup(&shdev->shdma_dev); shdma_cleanup(&shdev->shdma_dev);
if (shdev->dmars)
iounmap(shdev->dmars);
iounmap(shdev->chan_reg);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
synchronize_rcu(); synchronize_rcu();
kfree(shdev);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res)
release_mem_region(res->start, resource_size(res));
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (res)
release_mem_region(res->start, resource_size(res));
return 0; return 0;
} }
......
...@@ -302,7 +302,6 @@ static void sudmac_chan_remove(struct sudmac_device *su_dev) ...@@ -302,7 +302,6 @@ static void sudmac_chan_remove(struct sudmac_device *su_dev)
BUG_ON(!schan); BUG_ON(!schan);
shdma_free_irq(&sc->shdma_chan);
shdma_chan_remove(schan); shdma_chan_remove(schan);
} }
dma_dev->chancnt = 0; dma_dev->chancnt = 0;
......
...@@ -116,7 +116,6 @@ struct shdma_dev { ...@@ -116,7 +116,6 @@ struct shdma_dev {
int shdma_request_irq(struct shdma_chan *, int, int shdma_request_irq(struct shdma_chan *, int,
unsigned long, const char *); unsigned long, const char *);
void shdma_free_irq(struct shdma_chan *);
bool shdma_reset(struct shdma_dev *sdev); bool shdma_reset(struct shdma_dev *sdev);
void shdma_chan_probe(struct shdma_dev *sdev, void shdma_chan_probe(struct shdma_dev *sdev,
struct shdma_chan *schan, int id); struct shdma_chan *schan, int id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment