[alsa-devel] [PATCH 1/3] ASoC: Use card rather than soc-audio device to card PM functions
The platform device for the card is tied closely to the soc-audio implementation which we're currently trying to remove in favour of allowing cards to have their own devices. Begin removing it by replacing it with the card in the suspend and resume callbacks we give to cards, also taking the opportunity to remove the legacy suspend types which are currently hard coded anyway.
Signed-off-by: Mark Brown broonie@opensource.wolfsonmicro.com --- include/sound/soc.h | 8 ++++---- sound/soc/pxa/raumfeld.c | 4 ++-- sound/soc/pxa/zylonite.c | 5 ++--- sound/soc/soc-core.c | 9 ++++----- 4 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 00c6fba..d1cc1a2 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -655,10 +655,10 @@ struct snd_soc_card {
/* the pre and post PM functions are used to do any PM work before and * after the codec and DAI's do any PM work. */ - int (*suspend_pre)(struct platform_device *pdev, pm_message_t state); - int (*suspend_post)(struct platform_device *pdev, pm_message_t state); - int (*resume_pre)(struct platform_device *pdev); - int (*resume_post)(struct platform_device *pdev); + int (*suspend_pre)(struct snd_soc_card *card); + int (*suspend_post)(struct snd_soc_card *card); + int (*resume_pre)(struct snd_soc_card *card); + int (*resume_post)(struct snd_soc_card *card);
/* callbacks */ int (*set_bias_level)(struct snd_soc_card *, diff --git a/sound/soc/pxa/raumfeld.c b/sound/soc/pxa/raumfeld.c index 0fd60f4..db1dd56 100644 --- a/sound/soc/pxa/raumfeld.c +++ b/sound/soc/pxa/raumfeld.c @@ -151,13 +151,13 @@ static struct snd_soc_ops raumfeld_cs4270_ops = { .hw_params = raumfeld_cs4270_hw_params, };
-static int raumfeld_line_suspend(struct platform_device *pdev, pm_message_t state) +static int raumfeld_line_suspend(struct snd_soc_card *card) { raumfeld_enable_audio(false); return 0; }
-static int raumfeld_line_resume(struct platform_device *pdev) +static int raumfeld_line_resume(struct snd_soc_card *card) { raumfeld_enable_audio(true); return 0; diff --git a/sound/soc/pxa/zylonite.c b/sound/soc/pxa/zylonite.c index b222a7d..7b72901 100644 --- a/sound/soc/pxa/zylonite.c +++ b/sound/soc/pxa/zylonite.c @@ -226,8 +226,7 @@ static int zylonite_remove(struct platform_device *pdev) return 0; }
-static int zylonite_suspend_post(struct platform_device *pdev, - pm_message_t state) +static int zylonite_suspend_post(struct snd_soc_card *card) { if (clk_pout) clk_disable(pout); @@ -235,7 +234,7 @@ static int zylonite_suspend_post(struct platform_device *pdev, return 0; }
-static int zylonite_resume_pre(struct platform_device *pdev) +static int zylonite_resume_pre(struct snd_soc_card *card) { int ret = 0;
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 14861f9..446838e 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1011,7 +1011,7 @@ static int soc_suspend(struct device *dev) }
if (card->suspend_pre) - card->suspend_pre(pdev, PMSG_SUSPEND); + card->suspend_pre(card);
for (i = 0; i < card->num_rtd; i++) { struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; @@ -1078,7 +1078,7 @@ static int soc_suspend(struct device *dev) }
if (card->suspend_post) - card->suspend_post(pdev, PMSG_SUSPEND); + card->suspend_post(card);
return 0; } @@ -1090,7 +1090,6 @@ static void soc_resume_deferred(struct work_struct *work) { struct snd_soc_card *card = container_of(work, struct snd_soc_card, deferred_resume_work); - struct platform_device *pdev = to_platform_device(card->dev); struct snd_soc_codec *codec; int i;
@@ -1104,7 +1103,7 @@ static void soc_resume_deferred(struct work_struct *work) snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
if (card->resume_pre) - card->resume_pre(pdev); + card->resume_pre(card);
/* resume AC97 DAIs */ for (i = 0; i < card->num_rtd; i++) { @@ -1179,7 +1178,7 @@ static void soc_resume_deferred(struct work_struct *work) }
if (card->resume_post) - card->resume_post(pdev); + card->resume_post(card);
dev_dbg(card->dev, "resume work completed\n");
In order to support cards instantiated without using soc-audio remove the use of the platform device in the card probe() and remove() ops.
Signed-off-by: Mark Brown broonie@opensource.wolfsonmicro.com --- include/sound/soc.h | 4 ++-- sound/soc/fsl/mpc8610_hpcd.c | 6 ++---- sound/soc/fsl/p1022_ds.c | 6 ++---- sound/soc/pxa/tosa.c | 4 ++-- sound/soc/pxa/zylonite.c | 4 ++-- sound/soc/soc-core.c | 8 +++----- 6 files changed, 13 insertions(+), 19 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index d1cc1a2..a6a9013 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -650,8 +650,8 @@ struct snd_soc_card {
bool instantiated;
- int (*probe)(struct platform_device *pdev); - int (*remove)(struct platform_device *pdev); + int (*probe)(struct snd_soc_card *card); + int (*remove)(struct snd_soc_card *card);
/* the pre and post PM functions are used to do any PM work before and * after the codec and DAI's do any PM work. */ diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c index 7d7847a..c16c6b2 100644 --- a/sound/soc/fsl/mpc8610_hpcd.c +++ b/sound/soc/fsl/mpc8610_hpcd.c @@ -53,9 +53,8 @@ struct mpc8610_hpcd_data { * * Here we program the DMACR and PMUXCR registers. */ -static int mpc8610_hpcd_machine_probe(struct platform_device *sound_device) +static int mpc8610_hpcd_machine_probe(struct snd_soc_card *card) { - struct snd_soc_card *card = platform_get_drvdata(sound_device); struct mpc8610_hpcd_data *machine_data = container_of(card, struct mpc8610_hpcd_data, card); struct ccsr_guts_86xx __iomem *guts; @@ -138,9 +137,8 @@ static int mpc8610_hpcd_startup(struct snd_pcm_substream *substream) * This function is called to remove the sound device for one SSI. We * de-program the DMACR and PMUXCR register. */ -static int mpc8610_hpcd_machine_remove(struct platform_device *sound_device) +static int mpc8610_hpcd_machine_remove(struct snd_soc_card *card) { - struct snd_soc_card *card = platform_get_drvdata(sound_device); struct mpc8610_hpcd_data *machine_data = container_of(card, struct mpc8610_hpcd_data, card); struct ccsr_guts_86xx __iomem *guts; diff --git a/sound/soc/fsl/p1022_ds.c b/sound/soc/fsl/p1022_ds.c index 026b756..66e0b68 100644 --- a/sound/soc/fsl/p1022_ds.c +++ b/sound/soc/fsl/p1022_ds.c @@ -85,9 +85,8 @@ struct machine_data { * * Here we program the DMACR and PMUXCR registers. */ -static int p1022_ds_machine_probe(struct platform_device *sound_device) +static int p1022_ds_machine_probe(struct snd_soc_card *card) { - struct snd_soc_card *card = platform_get_drvdata(sound_device); struct machine_data *mdata = container_of(card, struct machine_data, card); struct ccsr_guts_85xx __iomem *guts; @@ -160,9 +159,8 @@ static int p1022_ds_startup(struct snd_pcm_substream *substream) * This function is called to remove the sound device for one SSI. We * de-program the DMACR and PMUXCR register. */ -static int p1022_ds_machine_remove(struct platform_device *sound_device) +static int p1022_ds_machine_remove(struct snd_soc_card *card) { - struct snd_soc_card *card = platform_get_drvdata(sound_device); struct machine_data *mdata = container_of(card, struct machine_data, card); struct ccsr_guts_85xx __iomem *guts; diff --git a/sound/soc/pxa/tosa.c b/sound/soc/pxa/tosa.c index f75804e..489139a 100644 --- a/sound/soc/pxa/tosa.c +++ b/sound/soc/pxa/tosa.c @@ -237,7 +237,7 @@ static struct snd_soc_dai_link tosa_dai[] = { }, };
-static int tosa_probe(struct platform_device *dev) +static int tosa_probe(struct snd_soc_card *card) { int ret;
@@ -251,7 +251,7 @@ static int tosa_probe(struct platform_device *dev) return ret; }
-static int tosa_remove(struct platform_device *dev) +static int tosa_remove(struct snd_soc_card *card) { gpio_free(TOSA_GPIO_L_MUTE); return 0; diff --git a/sound/soc/pxa/zylonite.c b/sound/soc/pxa/zylonite.c index 7b72901..c585829 100644 --- a/sound/soc/pxa/zylonite.c +++ b/sound/soc/pxa/zylonite.c @@ -189,7 +189,7 @@ static struct snd_soc_dai_link zylonite_dai[] = { }, };
-static int zylonite_probe(struct platform_device *pdev) +static int zylonite_probe(struct snd_soc_card *card) { int ret;
@@ -216,7 +216,7 @@ static int zylonite_probe(struct platform_device *pdev) return 0; }
-static int zylonite_remove(struct platform_device *pdev) +static int zylonite_remove(struct snd_soc_card *card) { if (clk_pout) { clk_disable(pout); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 446838e..4bc2365 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1717,7 +1717,6 @@ static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
static void snd_soc_instantiate_card(struct snd_soc_card *card) { - struct platform_device *pdev = to_platform_device(card->dev); struct snd_soc_codec *codec; struct snd_soc_codec_conf *codec_conf; enum snd_soc_compress_type compress_type; @@ -1781,7 +1780,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
/* initialise the sound card only once */ if (card->probe) { - ret = card->probe(pdev); + ret = card->probe(card); if (ret < 0) goto card_probe_error; } @@ -1842,7 +1841,7 @@ probe_dai_err:
card_probe_error: if (card->remove) - card->remove(pdev); + card->remove(card);
snd_card_free(card->snd_card);
@@ -1888,7 +1887,6 @@ static int soc_probe(struct platform_device *pdev)
static int soc_cleanup_card_resources(struct snd_soc_card *card) { - struct platform_device *pdev = to_platform_device(card->dev); int i;
/* make sure any delayed work runs */ @@ -1909,7 +1907,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
/* remove the card */ if (card->remove) - card->remove(pdev); + card->remove(card);
kfree(card->rtd); snd_card_free(card->snd_card);
Allow hookup of cards registered directly with the core to the PM operations by exporting the device power management operations to modules, also exporting the default PM operations since it is expected that most cards will end up using exactly the same setup.
Note that the callbacks require that the driver data for the card be the snd_soc_card.
Signed-off-by: Mark Brown broonie@opensource.wolfsonmicro.com --- include/sound/soc.h | 5 +++++ sound/soc/soc-core.c | 34 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index a6a9013..4fd79e0 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -261,6 +261,9 @@ enum snd_soc_compress_type {
int snd_soc_register_card(struct snd_soc_card *card); int snd_soc_unregister_card(struct snd_soc_card *card); +int snd_soc_suspend(struct device *dev); +int snd_soc_resume(struct device *dev); +int snd_soc_poweroff(struct device *dev); int snd_soc_register_platform(struct device *dev, struct snd_soc_platform_driver *platform_drv); void snd_soc_unregister_platform(struct device *dev); @@ -803,4 +806,6 @@ static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card) extern struct dentry *snd_soc_debugfs_root; #endif
+extern const struct dev_pm_ops snd_soc_pm_ops; + #endif diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 4bc2365..5dffc7a4 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -965,12 +965,11 @@ static struct snd_pcm_ops soc_pcm_ops = { .pointer = soc_pcm_pointer, };
-#ifdef CONFIG_PM +#ifdef CONFIG_PM_SLEEP /* powers down audio subsystem for suspend */ -static int soc_suspend(struct device *dev) +int snd_soc_suspend(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct snd_soc_card *card = platform_get_drvdata(pdev); + struct snd_soc_card *card = dev_get_drvdata(dev); struct snd_soc_codec *codec; int i;
@@ -1082,6 +1081,7 @@ static int soc_suspend(struct device *dev)
return 0; } +EXPORT_SYMBOL_GPL(snd_soc_suspend);
/* deferred resume work, so resume can complete before we finished * setting our codec back up, which can be very slow on I2C @@ -1187,10 +1187,9 @@ static void soc_resume_deferred(struct work_struct *work) }
/* powers up audio subsystem after a suspend */ -static int soc_resume(struct device *dev) +int snd_soc_resume(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct snd_soc_card *card = platform_get_drvdata(pdev); + struct snd_soc_card *card = dev_get_drvdata(dev); int i;
/* AC97 devices might have other drivers hanging off them so @@ -1212,9 +1211,10 @@ static int soc_resume(struct device *dev)
return 0; } +EXPORT_SYMBOL_GPL(snd_soc_resume); #else -#define soc_suspend NULL -#define soc_resume NULL +#define snd_soc_suspend NULL +#define snd_soc_resume NULL #endif
static struct snd_soc_dai_ops null_dai_ops = { @@ -1924,10 +1924,9 @@ static int soc_remove(struct platform_device *pdev) return 0; }
-static int soc_poweroff(struct device *dev) +int snd_soc_poweroff(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct snd_soc_card *card = platform_get_drvdata(pdev); + struct snd_soc_card *card = dev_get_drvdata(dev); int i;
if (!card->instantiated) @@ -1944,11 +1943,12 @@ static int soc_poweroff(struct device *dev)
return 0; } +EXPORT_SYMBOL_GPL(snd_soc_poweroff);
-static const struct dev_pm_ops soc_pm_ops = { - .suspend = soc_suspend, - .resume = soc_resume, - .poweroff = soc_poweroff, +const struct dev_pm_ops snd_soc_pm_ops = { + .suspend = snd_soc_suspend, + .resume = snd_soc_resume, + .poweroff = snd_soc_poweroff, };
/* ASoC platform driver */ @@ -1956,7 +1956,7 @@ static struct platform_driver soc_driver = { .driver = { .name = "soc-audio", .owner = THIS_MODULE, - .pm = &soc_pm_ops, + .pm = &snd_soc_pm_ops, }, .probe = soc_probe, .remove = soc_remove,
On Wed, 2011-01-26 at 17:08 +0000, Mark Brown wrote:
The platform device for the card is tied closely to the soc-audio implementation which we're currently trying to remove in favour of allowing cards to have their own devices. Begin removing it by replacing it with the card in the suspend and resume callbacks we give to cards, also taking the opportunity to remove the legacy suspend types which are currently hard coded anyway.
Signed-off-by: Mark Brown broonie@opensource.wolfsonmicro.com
include/sound/soc.h | 8 ++++---- sound/soc/pxa/raumfeld.c | 4 ++-- sound/soc/pxa/zylonite.c | 5 ++--- sound/soc/soc-core.c | 9 ++++----- 4 files changed, 12 insertions(+), 14 deletions(-)
All
Acked-by: Liam Girdwood lrg@slimlogic.co.uk
participants (2)
-
Liam Girdwood
-
Mark Brown