Commit 2ee65950 authored by Peter Ujfalusi's avatar Peter Ujfalusi Committed by Liam Girdwood

ASoC: omap-mcbsp: Cleanup of module probe/remove code

Use devm_* where it is possible to save on cleanup path.
Start merging the two mcbsp file content.
Move pm_runtime_enable/disable calls to ASoC probe, remove from module
probe/remove time.
Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@ti.com>
Tested-by: default avatarGrazvydas Ignotas <notasas@gmail.com>
Tested-by: default avatarJanusz Krzysztofik <jkrzyszt@tis.icnet.pl>
Acked-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: default avatarJarkko Nikula <jarkko.nikula@bitmer.com>
Signed-off-by: default avatarLiam Girdwood <lrg@ti.com>
parent cb40b63a
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <plat/mcbsp.h> #include <plat/mcbsp.h>
#include <linux/pm_runtime.h>
#include "mcbsp.h" #include "mcbsp.h"
...@@ -915,90 +914,56 @@ static int __devinit omap_st_add(struct omap_mcbsp *mcbsp, ...@@ -915,90 +914,56 @@ static int __devinit omap_st_add(struct omap_mcbsp *mcbsp,
struct omap_mcbsp_st_data *st_data; struct omap_mcbsp_st_data *st_data;
int err; int err;
st_data = kzalloc(sizeof(*mcbsp->st_data), GFP_KERNEL); st_data = devm_kzalloc(mcbsp->dev, sizeof(*mcbsp->st_data), GFP_KERNEL);
if (!st_data) { if (!st_data)
err = -ENOMEM; return -ENOMEM;
goto err1;
}
st_data->io_base_st = ioremap(res->start, resource_size(res)); st_data->io_base_st = devm_ioremap(mcbsp->dev, res->start,
if (!st_data->io_base_st) { resource_size(res));
err = -ENOMEM; if (!st_data->io_base_st)
goto err2; return -ENOMEM;
}
err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group); err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group);
if (err) if (err)
goto err3; return err;
mcbsp->st_data = st_data; mcbsp->st_data = st_data;
return 0; return 0;
err3:
iounmap(st_data->io_base_st);
err2:
kfree(st_data);
err1:
return err;
}
static void __devexit omap_st_remove(struct omap_mcbsp *mcbsp)
{
struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group);
iounmap(st_data->io_base_st);
kfree(st_data);
} }
/* /*
* McBSP1 and McBSP3 are directly mapped on 1610 and 1510. * McBSP1 and McBSP3 are directly mapped on 1610 and 1510.
* 730 has only 2 McBSP, and both of them are MPU peripherals. * 730 has only 2 McBSP, and both of them are MPU peripherals.
*/ */
int __devinit omap_mcbsp_probe(struct platform_device *pdev) int __devinit omap_mcbsp_init(struct platform_device *pdev)
{ {
struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data; struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
struct omap_mcbsp *mcbsp;
struct resource *res; struct resource *res;
int ret = 0; int ret = 0;
if (!pdata) {
dev_err(&pdev->dev, "McBSP device initialized without"
"platform data\n");
ret = -EINVAL;
goto exit;
}
dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id);
mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL);
if (!mcbsp) {
ret = -ENOMEM;
goto exit;
}
spin_lock_init(&mcbsp->lock); spin_lock_init(&mcbsp->lock);
mcbsp->id = pdev->id;
mcbsp->free = true; mcbsp->free = true;
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
if (!res) { if (!res) {
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!res) {
dev_err(&pdev->dev, "%s:mcbsp%d has invalid memory" dev_err(mcbsp->dev, "invalid memory resource\n");
"resource\n", __func__, pdev->id); return -ENOMEM;
ret = -ENOMEM;
goto exit;
} }
} }
if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
dev_name(&pdev->dev))) {
dev_err(mcbsp->dev, "memory region already claimed\n");
return -ENODEV;
}
mcbsp->phys_base = res->start; mcbsp->phys_base = res->start;
mcbsp->reg_cache_size = resource_size(res); mcbsp->reg_cache_size = resource_size(res);
mcbsp->io_base = ioremap(res->start, resource_size(res)); mcbsp->io_base = devm_ioremap(&pdev->dev, res->start,
if (!mcbsp->io_base) { resource_size(res));
ret = -ENOMEM; if (!mcbsp->io_base)
goto err_ioremap; return -ENOMEM;
}
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma");
if (!res) if (!res)
...@@ -1015,34 +980,25 @@ int __devinit omap_mcbsp_probe(struct platform_device *pdev) ...@@ -1015,34 +980,25 @@ int __devinit omap_mcbsp_probe(struct platform_device *pdev)
res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
if (!res) { if (!res) {
dev_err(&pdev->dev, "%s:mcbsp%d has invalid rx DMA channel\n", dev_err(&pdev->dev, "invalid rx DMA channel\n");
__func__, pdev->id); return -ENODEV;
ret = -ENODEV;
goto err_res;
} }
mcbsp->dma_rx_sync = res->start; mcbsp->dma_rx_sync = res->start;
res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
if (!res) { if (!res) {
dev_err(&pdev->dev, "%s:mcbsp%d has invalid tx DMA channel\n", dev_err(&pdev->dev, "invalid tx DMA channel\n");
__func__, pdev->id); return -ENODEV;
ret = -ENODEV;
goto err_res;
} }
mcbsp->dma_tx_sync = res->start; mcbsp->dma_tx_sync = res->start;
mcbsp->fclk = clk_get(&pdev->dev, "fck"); mcbsp->fclk = clk_get(&pdev->dev, "fck");
if (IS_ERR(mcbsp->fclk)) { if (IS_ERR(mcbsp->fclk)) {
ret = PTR_ERR(mcbsp->fclk); ret = PTR_ERR(mcbsp->fclk);
dev_err(&pdev->dev, "unable to get fck: %d\n", ret); dev_err(mcbsp->dev, "unable to get fck: %d\n", ret);
goto err_res; return ret;
} }
mcbsp->pdata = pdata;
mcbsp->dev = &pdev->dev;
platform_set_drvdata(pdev, mcbsp);
pm_runtime_enable(mcbsp->dev);
mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT;
if (mcbsp->pdata->buffer_size) { if (mcbsp->pdata->buffer_size) {
/* /*
...@@ -1082,41 +1038,17 @@ int __devinit omap_mcbsp_probe(struct platform_device *pdev) ...@@ -1082,41 +1038,17 @@ int __devinit omap_mcbsp_probe(struct platform_device *pdev)
err_st: err_st:
if (mcbsp->pdata->buffer_size) if (mcbsp->pdata->buffer_size)
sysfs_remove_group(&mcbsp->dev->kobj, sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
&additional_attr_group);
err_thres: err_thres:
clk_put(mcbsp->fclk); clk_put(mcbsp->fclk);
err_res:
iounmap(mcbsp->io_base);
err_ioremap:
kfree(mcbsp);
exit:
return ret; return ret;
} }
int __devexit omap_mcbsp_remove(struct platform_device *pdev) void __devexit omap_mcbsp_sysfs_remove(struct omap_mcbsp *mcbsp)
{ {
struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
platform_set_drvdata(pdev, NULL);
if (mcbsp) {
if (mcbsp->pdata && mcbsp->pdata->ops &&
mcbsp->pdata->ops->free)
mcbsp->pdata->ops->free(mcbsp->id);
if (mcbsp->pdata->buffer_size) if (mcbsp->pdata->buffer_size)
sysfs_remove_group(&mcbsp->dev->kobj, sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
&additional_attr_group);
if (mcbsp->st_data) if (mcbsp->st_data)
omap_st_remove(mcbsp); sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group);
clk_put(mcbsp->fclk);
iounmap(mcbsp->io_base);
kfree(mcbsp);
}
return 0;
} }
...@@ -341,7 +341,7 @@ int omap_st_enable(struct omap_mcbsp *mcbsp); ...@@ -341,7 +341,7 @@ int omap_st_enable(struct omap_mcbsp *mcbsp);
int omap_st_disable(struct omap_mcbsp *mcbsp); int omap_st_disable(struct omap_mcbsp *mcbsp);
int omap_st_is_enabled(struct omap_mcbsp *mcbsp); int omap_st_is_enabled(struct omap_mcbsp *mcbsp);
int __devinit omap_mcbsp_probe(struct platform_device *pdev); int __devinit omap_mcbsp_init(struct platform_device *pdev);
int __devexit omap_mcbsp_remove(struct platform_device *pdev); void __devexit omap_mcbsp_sysfs_remove(struct omap_mcbsp *mcbsp);
#endif /* __ASOC_MCBSP_H */ #endif /* __ASOC_MCBSP_H */
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/pm_runtime.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/pcm.h> #include <sound/pcm.h>
#include <sound/pcm_params.h> #include <sound/pcm_params.h>
...@@ -603,7 +604,27 @@ static const struct snd_soc_dai_ops mcbsp_dai_ops = { ...@@ -603,7 +604,27 @@ static const struct snd_soc_dai_ops mcbsp_dai_ops = {
.set_sysclk = omap_mcbsp_dai_set_dai_sysclk, .set_sysclk = omap_mcbsp_dai_set_dai_sysclk,
}; };
static int omap_mcbsp_probe(struct snd_soc_dai *dai)
{
struct omap_mcbsp *mcbsp = snd_soc_dai_get_drvdata(dai);
pm_runtime_enable(mcbsp->dev);
return 0;
}
static int omap_mcbsp_remove(struct snd_soc_dai *dai)
{
struct omap_mcbsp *mcbsp = snd_soc_dai_get_drvdata(dai);
pm_runtime_disable(mcbsp->dev);
return 0;
}
static struct snd_soc_dai_driver omap_mcbsp_dai = { static struct snd_soc_dai_driver omap_mcbsp_dai = {
.probe = omap_mcbsp_probe,
.remove = omap_mcbsp_remove,
.playback = { .playback = {
.channels_min = 1, .channels_min = 1,
.channels_max = 16, .channels_max = 16,
...@@ -756,9 +777,24 @@ EXPORT_SYMBOL_GPL(omap_mcbsp_st_add_controls); ...@@ -756,9 +777,24 @@ EXPORT_SYMBOL_GPL(omap_mcbsp_st_add_controls);
static __devinit int asoc_mcbsp_probe(struct platform_device *pdev) static __devinit int asoc_mcbsp_probe(struct platform_device *pdev)
{ {
struct omap_mcbsp_platform_data *pdata = dev_get_platdata(&pdev->dev);
struct omap_mcbsp *mcbsp;
int ret; int ret;
ret = omap_mcbsp_probe(pdev); if (!pdata) {
dev_err(&pdev->dev, "missing platform data.\n");
return -EINVAL;
}
mcbsp = devm_kzalloc(&pdev->dev, sizeof(struct omap_mcbsp), GFP_KERNEL);
if (!mcbsp)
return -ENOMEM;
mcbsp->id = pdev->id;
mcbsp->pdata = pdata;
mcbsp->dev = &pdev->dev;
platform_set_drvdata(pdev, mcbsp);
ret = omap_mcbsp_init(pdev);
if (!ret) if (!ret)
return snd_soc_register_dai(&pdev->dev, &omap_mcbsp_dai); return snd_soc_register_dai(&pdev->dev, &omap_mcbsp_dai);
...@@ -767,8 +803,19 @@ static __devinit int asoc_mcbsp_probe(struct platform_device *pdev) ...@@ -767,8 +803,19 @@ static __devinit int asoc_mcbsp_probe(struct platform_device *pdev)
static int __devexit asoc_mcbsp_remove(struct platform_device *pdev) static int __devexit asoc_mcbsp_remove(struct platform_device *pdev)
{ {
omap_mcbsp_remove(pdev); struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
snd_soc_unregister_dai(&pdev->dev); snd_soc_unregister_dai(&pdev->dev);
if (mcbsp->pdata->ops && mcbsp->pdata->ops->free)
mcbsp->pdata->ops->free(mcbsp->id);
omap_mcbsp_sysfs_remove(mcbsp);
clk_put(mcbsp->fclk);
platform_set_drvdata(pdev, NULL);
return 0; return 0;
} }
......
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