ASoC: au1x: convert to platform drivers.
Convert psc-ac97,i2s to platform drivers similar to the davinci ones.
Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
diff --git a/sound/soc/au1x/psc-ac97.c b/sound/soc/au1x/psc-ac97.c
index 2a06a9c..340311d 100644
--- a/sound/soc/au1x/psc-ac97.c
+++ b/sound/soc/au1x/psc-ac97.c
@@ -317,109 +317,12 @@
static int au1xpsc_ac97_probe(struct platform_device *pdev,
struct snd_soc_dai *dai)
{
- int ret;
- struct resource *r;
- unsigned long sel;
-
- if (au1xpsc_ac97_workdata)
- return -EBUSY;
-
- au1xpsc_ac97_workdata =
- kzalloc(sizeof(struct au1xpsc_audio_data), GFP_KERNEL);
- if (!au1xpsc_ac97_workdata)
- return -ENOMEM;
-
- mutex_init(&au1xpsc_ac97_workdata->lock);
-
- r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!r) {
- ret = -ENODEV;
- goto out0;
- }
-
- ret = -EBUSY;
- au1xpsc_ac97_workdata->ioarea =
- request_mem_region(r->start, r->end - r->start + 1,
- "au1xpsc_ac97");
- if (!au1xpsc_ac97_workdata->ioarea)
- goto out0;
-
- au1xpsc_ac97_workdata->mmio = ioremap(r->start, 0xffff);
- if (!au1xpsc_ac97_workdata->mmio)
- goto out1;
-
- /* configuration: max dma trigger threshold, enable ac97 */
- au1xpsc_ac97_workdata->cfg = PSC_AC97CFG_RT_FIFO8 |
- PSC_AC97CFG_TT_FIFO8 |
- PSC_AC97CFG_DE_ENABLE;
-
- /* preserve PSC clock source set up by platform (dev.platform_data
- * is already occupied by soc layer)
- */
- sel = au_readl(PSC_SEL(au1xpsc_ac97_workdata)) & PSC_SEL_CLK_MASK;
- au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata));
- au_sync();
- au_writel(0, PSC_SEL(au1xpsc_ac97_workdata));
- au_sync();
- au_writel(PSC_SEL_PS_AC97MODE | sel, PSC_SEL(au1xpsc_ac97_workdata));
- au_sync();
- /* next up: cold reset. Dont check for PSC-ready now since
- * there may not be any codec clock yet.
- */
-
- return 0;
-
-out1:
- release_resource(au1xpsc_ac97_workdata->ioarea);
- kfree(au1xpsc_ac97_workdata->ioarea);
-out0:
- kfree(au1xpsc_ac97_workdata);
- au1xpsc_ac97_workdata = NULL;
- return ret;
+ return au1xpsc_ac97_workdata ? 0 : -ENODEV;
}
static void au1xpsc_ac97_remove(struct platform_device *pdev,
struct snd_soc_dai *dai)
{
- /* disable PSC completely */
- au_writel(0, AC97_CFG(au1xpsc_ac97_workdata));
- au_sync();
- au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata));
- au_sync();
-
- iounmap(au1xpsc_ac97_workdata->mmio);
- release_resource(au1xpsc_ac97_workdata->ioarea);
- kfree(au1xpsc_ac97_workdata->ioarea);
- kfree(au1xpsc_ac97_workdata);
- au1xpsc_ac97_workdata = NULL;
-}
-
-static int au1xpsc_ac97_suspend(struct snd_soc_dai *dai)
-{
- /* save interesting registers and disable PSC */
- au1xpsc_ac97_workdata->pm[0] =
- au_readl(PSC_SEL(au1xpsc_ac97_workdata));
-
- au_writel(0, AC97_CFG(au1xpsc_ac97_workdata));
- au_sync();
- au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata));
- au_sync();
-
- return 0;
-}
-
-static int au1xpsc_ac97_resume(struct snd_soc_dai *dai)
-{
- /* restore PSC clock config */
- au_writel(au1xpsc_ac97_workdata->pm[0] | PSC_SEL_PS_AC97MODE,
- PSC_SEL(au1xpsc_ac97_workdata));
- au_sync();
-
- /* after this point the ac97 core will cold-reset the codec.
- * During cold-reset the PSC is reinitialized and the last
- * configuration set up in hw_params() is restored.
- */
- return 0;
}
static struct snd_soc_dai_ops au1xpsc_ac97_dai_ops = {
@@ -432,8 +335,6 @@
.ac97_control = 1,
.probe = au1xpsc_ac97_probe,
.remove = au1xpsc_ac97_remove,
- .suspend = au1xpsc_ac97_suspend,
- .resume = au1xpsc_ac97_resume,
.playback = {
.rates = AC97_RATES,
.formats = AC97_FMTS,
@@ -450,20 +351,165 @@
};
EXPORT_SYMBOL_GPL(au1xpsc_ac97_dai);
-static int __init au1xpsc_ac97_init(void)
+static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev)
+{
+ int ret;
+ struct resource *r;
+ unsigned long sel;
+ struct au1xpsc_audio_data *wd;
+
+ if (au1xpsc_ac97_workdata)
+ return -EBUSY;
+
+ wd = kzalloc(sizeof(struct au1xpsc_audio_data), GFP_KERNEL);
+ if (!wd)
+ return -ENOMEM;
+
+ mutex_init(&wd->lock);
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!r) {
+ ret = -ENODEV;
+ goto out0;
+ }
+
+ ret = -EBUSY;
+ wd->ioarea = request_mem_region(r->start, r->end - r->start + 1,
+ "au1xpsc_ac97");
+ if (!wd->ioarea)
+ goto out0;
+
+ wd->mmio = ioremap(r->start, 0xffff);
+ if (!wd->mmio)
+ goto out1;
+
+ /* configuration: max dma trigger threshold, enable ac97 */
+ wd->cfg = PSC_AC97CFG_RT_FIFO8 | PSC_AC97CFG_TT_FIFO8 |
+ PSC_AC97CFG_DE_ENABLE;
+
+ /* preserve PSC clock source set up by platform */
+ sel = au_readl(PSC_SEL(wd)) & PSC_SEL_CLK_MASK;
+ au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
+ au_sync();
+ au_writel(0, PSC_SEL(wd));
+ au_sync();
+ au_writel(PSC_SEL_PS_AC97MODE | sel, PSC_SEL(wd));
+ au_sync();
+
+ ret = snd_soc_register_dai(&au1xpsc_ac97_dai);
+ if (ret)
+ goto out1;
+
+ wd->dmapd = au1xpsc_pcm_add(pdev);
+ if (wd->dmapd) {
+ platform_set_drvdata(pdev, wd);
+ au1xpsc_ac97_workdata = wd; /* MDEV */
+ return 0;
+ }
+
+ snd_soc_unregister_dai(&au1xpsc_ac97_dai);
+out1:
+ release_resource(wd->ioarea);
+ kfree(wd->ioarea);
+out0:
+ kfree(wd);
+ return ret;
+}
+
+static int __devexit au1xpsc_ac97_drvremove(struct platform_device *pdev)
+{
+ struct au1xpsc_audio_data *wd = platform_get_drvdata(pdev);
+
+ if (wd->dmapd)
+ au1xpsc_pcm_destroy(wd->dmapd);
+
+ snd_soc_unregister_dai(&au1xpsc_ac97_dai);
+
+ /* disable PSC completely */
+ au_writel(0, AC97_CFG(wd));
+ au_sync();
+ au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
+ au_sync();
+
+ iounmap(wd->mmio);
+ release_resource(wd->ioarea);
+ kfree(wd->ioarea);
+ kfree(wd);
+
+ au1xpsc_ac97_workdata = NULL; /* MDEV */
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int au1xpsc_ac97_drvsuspend(struct device *dev)
+{
+ struct au1xpsc_audio_data *wd = dev_get_drvdata(dev);
+
+ /* save interesting registers and disable PSC */
+ wd->pm[0] = au_readl(PSC_SEL(wd));
+
+ au_writel(0, AC97_CFG(wd));
+ au_sync();
+ au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
+ au_sync();
+
+ return 0;
+}
+
+static int au1xpsc_ac97_drvresume(struct device *dev)
+{
+ struct au1xpsc_audio_data *wd = dev_get_drvdata(dev);
+
+ /* restore PSC clock config */
+ au_writel(wd->pm[0] | PSC_SEL_PS_AC97MODE, PSC_SEL(wd));
+ au_sync();
+
+ /* after this point the ac97 core will cold-reset the codec.
+ * During cold-reset the PSC is reinitialized and the last
+ * configuration set up in hw_params() is restored.
+ */
+ return 0;
+}
+
+static struct dev_pm_ops au1xpscac97_pmops = {
+ .suspend = au1xpsc_ac97_drvsuspend,
+ .resume = au1xpsc_ac97_drvresume,
+};
+
+#define AU1XPSCAC97_PMOPS &au1xpscac97_pmops
+
+#else
+
+#define AU1XPSCAC97_PMOPS NULL
+
+#endif
+
+static struct platform_driver au1xpsc_ac97_driver = {
+ .driver = {
+ .name = "au1xpsc_ac97",
+ .owner = THIS_MODULE,
+ .pm = AU1XPSCAC97_PMOPS,
+ },
+ .probe = au1xpsc_ac97_drvprobe,
+ .remove = __devexit_p(au1xpsc_ac97_drvremove),
+};
+
+static int __init au1xpsc_ac97_load(void)
{
au1xpsc_ac97_workdata = NULL;
- return snd_soc_register_dai(&au1xpsc_ac97_dai);
+ return platform_driver_register(&au1xpsc_ac97_driver);
}
-static void __exit au1xpsc_ac97_exit(void)
+static void __exit au1xpsc_ac97_unload(void)
{
- snd_soc_unregister_dai(&au1xpsc_ac97_dai);
+ platform_driver_unregister(&au1xpsc_ac97_driver);
}
-module_init(au1xpsc_ac97_init);
-module_exit(au1xpsc_ac97_exit);
+module_init(au1xpsc_ac97_load);
+module_exit(au1xpsc_ac97_unload);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Au12x0/Au1550 PSC AC97 ALSA ASoC audio driver");
-MODULE_AUTHOR("Manuel Lauss <manuel.lauss@gmail.com>");
+MODULE_AUTHOR("Manuel Lauss");
+