ASoC: Move card list initialization to snd_soc_register_card
Subsystems (3)
PATCH 1/7 ASoC: Move card list initialization to snd_soc_register_card
All ASoC cards need snd_soc_initialize_card_lists called. Previously, it was only called for cards backed by a "soc-audio" platform device, via soc_probe(). However, it's also needed for cards backed by other platform devices, and registered directly via snd_soc_register_card().
--- sound/soc/soc-core.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
sound/soc/soc-core.c +2 -1
@@ -1881,7 +1881,6 @@ static int soc_probe(struct platform_device *pdev)/* Bodge while we unpick instantiation */ card->dev = &pdev->dev; -snd_soc_initialize_card_lists (card); ret =snd_soc_register_card (card);if (ret !=0 ) {
@@ -3122,6 +3121,8 @@ int snd_soc_register_card(struct snd_soc_card *card)if (!card->name || !card->dev)return -EINVAL ; +snd_soc_initialize_card_lists (card); +soc_init_card_debugfs (card); card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
Signature · 1 line
1.7.1
PATCH 2/7 ASoC: Tegra: Harmony: Don't use soc-audio platform device
Previously, snd-soc-tegra-harmony internally instantiated a platform device object whenever the module was loaded. Instead, switch to a more typical model where arch/arm/mach-tegra defines a platform device, and snd-soc-tegra-harmony acts as a driver for such a platform device.
Define a new struct tegra_harmony to store driver data in the future.
--- sound/soc/tegra/harmony.c | 94 +++++++++++++++++++++++++++++++------------- 1 files changed, 66 insertions(+), 28 deletions(-)
sound/soc/tegra/harmony.c +66 -28
@@ -2,7 +2,7 @@* harmony.c - Harmony machine ASoC driver * * Author: Stephen Warren <[email protected]> -* Copyright (C) 2010 - NVIDIA, Inc. +* Copyright (C) 2010-2011 - NVIDIA, Inc. * * Based on code copyright/by: *
@@ -29,7 +29,11 @@*/ #include <asm/mach-types.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h>
@@ -40,9 +44,11 @@#include "tegra_pcm.h" #include "tegra_asoc_utils.h" -#define PREFIX "ASoC Harmony: " +#define DRV_NAME "tegra-snd-harmony" +#define PREFIX DRV_NAME ": " -static struct platform_device *harmony_snd_device; +struct tegra_harmony { +};static int harmony_asoc_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params)
@@ -154,56 +160,88 @@ static struct snd_soc_card snd_soc_harmony = { .num_links = 1, }; -static int __init harmony_soc_modinit (void ) +static __devinit int tegra_snd_harmony_probe (struct platform_device *pdev) { +struct snd_soc_card *card = &snd_soc_harmony; +struct tegra_harmony *harmony;int ret;if (!machine_is_harmony ()) { -pr_err (PREFIX "Not running on Tegra Harmony!\n" ); +dev_err (&pdev->dev,"Not running on Tegra Harmony!\n" );return -ENODEV ; } - ret =tegra_asoc_utils_init (); -if (ret) { -return ret; + harmony =kzalloc (sizeof (struct tegra_harmony ),GFP_KERNEL ); +if (!harmony) { +dev_err (&pdev->dev,"Can't allocate tegra_harmony\n" ); +return -ENOMEM ; } -/* -* Create and register platform device -*/ - harmony_snd_device =platform_device_alloc ("soc-audio" ,-1 ); -if (harmony_snd_device ==NULL ) { -pr_err (PREFIX "platform_device_alloc failed\n" ); - ret = -ENOMEM ; - goto err_clock_utils; - } + ret =tegra_asoc_utils_init (); +if (ret) + goto err_free_harmony; -platform_set_drvdata (harmony_snd_device, &snd_soc_harmony); + card->dev = &pdev->dev; +platform_set_drvdata (pdev, card); +snd_soc_card_set_drvdata (card, harmony); - ret =platform_device_add (harmony_snd_device); + ret =snd_soc_register_card (card);if (ret) { -pr_err (PREFIX "platform_device_add failed (%d)\n" , +dev_err (&pdev->dev,"snd_soc_register_card failed (%d)\n" , ret); - goto err_device_put; + goto err_clear_drvdata; }return 0 ; -err_device_put: -platform_device_put (harmony_snd_device); -err_clock_utils: +err_clear_drvdata: +snd_soc_card_set_drvdata (card,NULL ); +platform_set_drvdata (pdev,NULL ); + card->dev =NULL ;tegra_asoc_utils_fini (); +err_free_harmony: +kfree (harmony);return ret; } -module_init (harmony_soc_modinit); -static void __exit harmony_soc_modexit(void) +static int __devexit tegra_snd_harmony_remove(struct platform_device *pdev) { -platform_device_unregister (harmony_snd_device); +struct snd_soc_card *card =platform_get_drvdata (pdev); +struct tegra_harmony *harmony =snd_soc_card_get_drvdata (card); + +snd_soc_unregister_card (card); + +snd_soc_card_set_drvdata (card,NULL ); +platform_set_drvdata (pdev,NULL ); + card->dev =NULL ;tegra_asoc_utils_fini (); + +kfree (harmony); + +return 0 ; +} + +static struct platform_driver tegra_snd_harmony_driver = { + .driver = { + .name =DRV_NAME , + .owner =THIS_MODULE , + }, + .probe = tegra_snd_harmony_probe, + .remove =__devexit_p (tegra_snd_harmony_remove), +}; + +static int __init snd_tegra_harmony_init (void ) +{ +return platform_driver_register (&tegra_snd_harmony_driver); +} +module_init (snd_tegra_harmony_init); + +static void __exit snd_tegra_harmony_exit(void) +{ +platform_driver_unregister (&tegra_snd_harmony_driver); } -module_exit (harmony_soc_modexit); +module_exit (snd_tegra_harmony_exit);MODULE_AUTHOR ("Stephen Warren <[email protected]>" );MODULE_DESCRIPTION ("Harmony machine ASoC driver" );
Signature · 1 line
1.7.1
PATCH 3/7 ASoC: Tegra: Harmony: Support the internal speaker
In reply to Stephen WarrenAdd DAPM widget definitions for the internal speaker paths. Currently, this path is always enabled while playback is active.
Add code to control the speaker amplifier GPIO.
The GPIO is requested during _init, since that's the first time it is guaranteed that the WM8903 module is loaded, probed, and hence has exported its GPIO chip.
--- sound/soc/tegra/harmony.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-)
sound/soc/tegra/harmony.c +51 -0
@@ -33,6 +33,9 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/slab.h> +#include <linux/gpio.h> + +#include <mach/harmony_audio.h> #include <sound/core.h> #include <sound/pcm.h>
@@ -48,6 +51,8 @@#define PREFIX DRV_NAME ": "struct tegra_harmony { +struct harmony_audio_platform_data *pdata; +int gpio_spkr_en_requested; }; static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,
@@ -113,7 +118,22 @@ static struct snd_soc_ops harmony_asoc_ops = { .hw_params = harmony_asoc_hw_params, }; +static int harmony_event_int_spk (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *k,int event) +{ +struct snd_soc_codec *codec = w->codec; +struct snd_soc_card *card = codec->card; +struct tegra_harmony *harmony =snd_soc_card_get_drvdata (card); +struct harmony_audio_platform_data *pdata = harmony->pdata; + +gpio_set_value_cansleep (pdata->gpio_spkr_en, + !!SND_SOC_DAPM_EVENT_ON (event)); + +return 0 ; +} +static const struct snd_soc_dapm_widget harmony_dapm_widgets[] = { +SND_SOC_DAPM_SPK ("Int Spk" , harmony_event_int_spk),SND_SOC_DAPM_HP ("Headphone Jack" ,NULL ),SND_SOC_DAPM_MIC ("Mic Jack" ,NULL ), };
@@ -121,6 +141,10 @@ static const struct snd_soc_dapm_widget harmony_dapm_widgets[] = {static const struct snd_soc_dapm_route harmony_audio_map[] = { {"Headphone Jack" ,NULL ,"HPOUTR" }, {"Headphone Jack" ,NULL ,"HPOUTL" }, + {"Int Spk" ,NULL ,"ROP" }, + {"Int Spk" ,NULL ,"RON" }, + {"Int Spk" ,NULL ,"LOP" }, + {"Int Spk" ,NULL ,"LON" }, {"Mic Bias" ,NULL ,"Mic Jack" }, {"IN1L" ,NULL ,"Mic Bias" }, };
@@ -129,6 +153,19 @@ static int harmony_asoc_init(struct snd_soc_pcm_runtime *rtd) {struct snd_soc_codec *codec = rtd->codec;struct snd_soc_dapm_context *dapm = &codec->dapm; +struct snd_soc_card *card = codec->card; +struct tegra_harmony *harmony =snd_soc_card_get_drvdata (card); +struct harmony_audio_platform_data *pdata = harmony->pdata; +int ret; + + ret =gpio_request (pdata->gpio_spkr_en,"spkr_en" ); +if (ret) { +dev_err (card->dev,"cannot get spkr_en gpio\n" ); +return ret; + } + harmony->gpio_spkr_en_requested =1 ; + +gpio_direction_output (pdata->gpio_spkr_en,0 );snd_soc_dapm_new_controls (dapm, harmony_dapm_widgets,ARRAY_SIZE (harmony_dapm_widgets));
@@ -137,6 +174,7 @@ static int harmony_asoc_init(struct snd_soc_pcm_runtime *rtd) ARRAY_SIZE(harmony_audio_map));snd_soc_dapm_enable_pin (dapm,"Headphone Jack" ); +snd_soc_dapm_enable_pin (dapm,"Int Spk" );snd_soc_dapm_enable_pin (dapm,"Mic Jack" );snd_soc_dapm_sync (dapm);
@@ -164,6 +202,7 @@ static __devinit int tegra_snd_harmony_probe(struct platform_device *pdev) {struct snd_soc_card *card = &snd_soc_harmony;struct tegra_harmony *harmony; +struct harmony_audio_platform_data *pdata;int ret;if (!machine_is_harmony ()) {
@@ -171,12 +210,20 @@ static __devinit int tegra_snd_harmony_probe(struct platform_device *pdev)return -ENODEV ; } + pdata = pdev->dev.platform_data; +if (!pdata) { +dev_err (&pdev->dev,"no platform data supplied\n" ); +return -EINVAL ; + } + harmony =kzalloc (sizeof (struct tegra_harmony ),GFP_KERNEL );if (!harmony) {dev_err (&pdev->dev,"Can't allocate tegra_harmony\n" );return -ENOMEM ; } + harmony->pdata = pdata; + ret =tegra_asoc_utils_init ();if (ret) goto err_free_harmony;
@@ -208,6 +255,7 @@ static int __devexit tegra_snd_harmony_remove(struct platform_device *pdev) {struct snd_soc_card *card =platform_get_drvdata (pdev);struct tegra_harmony *harmony =snd_soc_card_get_drvdata (card); +struct harmony_audio_platform_data *pdata = harmony->pdata;snd_soc_unregister_card (card);
@@ -217,6 +265,9 @@ static int __devexit tegra_snd_harmony_remove(struct platform_device *pdev)tegra_asoc_utils_fini (); +if (harmony->gpio_spkr_en_requested) +gpio_free (pdata->gpio_spkr_en); +kfree (harmony);return 0 ;
Signature · 1 line
1.7.1
Re: [PATCH 3/7] ASoC: Tegra: Harmony: Support the internal speaker
sound/soc/tegra/harmony.c static struct snd_soc_ops harmony_asoc_ops = { · line 130
Quoted 2 lines · Stephen Warren
sound/soc/tegra/harmony.c +2
-0+gpio_set_value_cansleep (pdata->gpio_spkr_en, + !!SND_SOC_DAPM_EVENT_ON (event));
GPIOs should accept C logical values - if you need the !! there's a bug in the GPIO driver.
PATCH 4/7 ASoC: Tegra: Harmony: Fix indentation issue.
In reply to Stephen WarrenIndent with TABs not spaces.
--- sound/soc/tegra/harmony.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
sound/soc/tegra/harmony.c +6 -5
@@ -104,11 +104,12 @@ static int harmony_asoc_hw_params(struct snd_pcm_substream *substream, }if (mclk_change) { - err =snd_soc_dai_set_sysclk (codec_dai,0 , mclk,SND_SOC_CLOCK_IN ); -if (err <0 ) { -pr_err (PREFIX "codec_dai clock not set\n" ); -return err; - } + err =snd_soc_dai_set_sysclk (codec_dai,0 , mclk, +SND_SOC_CLOCK_IN ); +if (err <0 ) { +pr_err (PREFIX "codec_dai clock not set\n" ); +return err; + } }return 0 ;
Signature · 1 line
1.7.1
PATCH 5/7 ASoC: Tegra: Harmony: Use dev_err not pr_err
In reply to Stephen Warren--- sound/soc/tegra/harmony.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
sound/soc/tegra/harmony.c +6 -5
@@ -48,7 +48,6 @@#include "tegra_asoc_utils.h" #define DRV_NAME "tegra-snd-harmony" -#define PREFIX DRV_NAME ": "struct tegra_harmony {struct harmony_audio_platform_data *pdata;
@@ -61,6 +60,8 @@ static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,struct snd_soc_pcm_runtime *rtd = substream->private_data;struct snd_soc_dai *codec_dai = rtd->codec_dai;struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +struct snd_soc_codec *codec = rtd->codec; +struct snd_soc_card *card = codec->card;int srate, mclk, mclk_change;int err;
@@ -81,7 +82,7 @@ static int harmony_asoc_hw_params(struct snd_pcm_substream *substream, err =tegra_asoc_utils_set_rate (srate, mclk, &mclk_change);if (err <0 ) { -pr_err (PREFIX "Can't configure clocks\n" ); +dev_err (card->dev,"Can't configure clocks\n" );return err; }
@@ -90,7 +91,7 @@ static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);if (err <0 ) { -pr_err (PREFIX "codec_dai fmt not set\n" ); +dev_err (card->dev,"codec_dai fmt not set\n" );return err; }
@@ -99,7 +100,7 @@ static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);if (err <0 ) { -pr_err (PREFIX "cpu_dai fmt not set\n" ); +dev_err (card->dev,"cpu_dai fmt not set\n" );return err; }
@@ -107,7 +108,7 @@ static int harmony_asoc_hw_params(struct snd_pcm_substream *substream, err =snd_soc_dai_set_sysclk (codec_dai,0 , mclk,SND_SOC_CLOCK_IN );if (err <0 ) { -pr_err (PREFIX "codec_dai clock not set\n" ); +dev_err (card->dev,"codec_dai clock not set\n" );return err; } }
Signature · 1 line
1.7.1
PATCH 6/7 ASoC: Tegra: utils: Don't use global variables
In reply to Stephen WarrenInstead, have the machine driver provide storage for the utility data somehow.
For Harmony in particular, store this within struct tegra_harmony, itself referenced by snd_soc_card's drvdata.
--- sound/soc/tegra/harmony.c | 11 +++-- sound/soc/tegra/tegra_asoc_utils.c | 91 +++++++++++++++++------------------ sound/soc/tegra/tegra_asoc_utils.h | 20 +++++++- 3 files changed, 68 insertions(+), 54 deletions(-)
sound/soc/tegra/harmony.c +7 -4
@@ -50,6 +50,7 @@#define DRV_NAME "tegra-snd-harmony"struct tegra_harmony { +struct tegra_asoc_utils_data util_data;struct harmony_audio_platform_data *pdata;int gpio_spkr_en_requested; };
@@ -62,6 +63,7 @@ static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,struct snd_soc_dai *cpu_dai = rtd->cpu_dai;struct snd_soc_codec *codec = rtd->codec;struct snd_soc_card *card = codec->card; +struct tegra_harmony *harmony =snd_soc_card_get_drvdata (card);int srate, mclk, mclk_change;int err;
@@ -80,7 +82,8 @@ static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,while (mclk <6000000 ) mclk *=2 ; - err =tegra_asoc_utils_set_rate (srate, mclk, &mclk_change); + err =tegra_asoc_utils_set_rate (&harmony->util_data, srate, mclk, + &mclk_change);if (err <0 ) {dev_err (card->dev,"Can't configure clocks\n" );return err;
@@ -226,7 +229,7 @@ static __devinit int tegra_snd_harmony_probe(struct platform_device *pdev) harmony->pdata = pdata; - ret =tegra_asoc_utils_init (); + ret =tegra_asoc_utils_init (&harmony->util_data, &pdev->dev);if (ret) goto err_free_harmony;
@@ -247,7 +250,7 @@ err_clear_drvdata:snd_soc_card_set_drvdata (card,NULL );platform_set_drvdata (pdev,NULL ); card->dev =NULL ; -tegra_asoc_utils_fini (); +tegra_asoc_utils_fini (&harmony->util_data); err_free_harmony:kfree (harmony);return ret;
@@ -265,7 +268,7 @@ static int __devexit tegra_snd_harmony_remove(struct platform_device *pdev)platform_set_drvdata (pdev,NULL ); card->dev =NULL ; -tegra_asoc_utils_fini (); +tegra_asoc_utils_fini (&harmony->util_data);if (harmony->gpio_spkr_en_requested)gpio_free (pdata->gpio_spkr_en);
sound/soc/tegra/tegra_asoc_utils.c +44 -47
159 lines not on this page · raw message
sound/soc/tegra/tegra_asoc_utils.h +17 -3
@@ -23,9 +23,23 @@#ifndef __TEGRA_ASOC_UTILS_H__#define __TEGRA_ASOC_UTILS_H_ -int tegra_asoc_utils_set_rate (int srate,int mclk_rate,int *mclk_change); -int tegra_asoc_utils_init (void ); -void tegra_asoc_utils_fini (void ); +struct clk ; +struct device ; + +struct tegra_asoc_utils_data { +struct device *dev; +struct clk *clk_pll_a; +struct clk *clk_pll_a_out0; +struct clk *clk_cdev1; +int set_baseclock; +int set_mclk; +}; + +int tegra_asoc_utils_set_rate (struct tegra_asoc_utils_data *data,int srate, +int mclk,int *mclk_change); +int tegra_asoc_utils_init (struct tegra_asoc_utils_data *data, +struct device *dev); +void tegra_asoc_utils_fini (struct tegra_asoc_utils_data *data);#endif
Signature · 1 line
1.7.1
PATCH 7/7 ASoC: Tegra: I2S: Use dev_err not pr_err
In reply to Stephen Warren--- sound/soc/tegra/tegra_i2s.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
sound/soc/tegra/tegra_i2s.c +1 -1
@@ -386,7 +386,7 @@ static __devinit int tegra_i2s_platform_probe(struct platform_device *pdev)snprintf (clk_name,sizeof (clk_name),DRV_NAME ".%d" , pdev->id); i2s->clk_i2s =clk_get_sys (clk_name,NULL );if (IS_ERR (i2s->clk_i2s)) { -pr_err ("Can't retrieve i2s clock\n" ); +dev_err (&pdev->dev,"Can't retrieve i2s clock\n" ); ret =PTR_ERR (i2s->clk_i2s); goto err_free; }
Signature · 1 line
1.7.1
Quoted 6 lines · Stephen Warren
All ASoC cards need
snd_soc_initialize_card_listscalled. Previously, it was only called for cards backed by a "soc-audio" platform device, viasoc_probe(). However, it's also needed for cards backed by other platform devices, and registered directly viasnd_soc_register_card().Signed-off-by Stephen Warren <[email protected]>
All
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Quoted 4 lines · Stephen Warren
All ASoC cards need
snd_soc_initialize_card_listscalled. Previously, it was only called for cards backed by a "soc-audio" platform device, viasoc_probe(). However, it's also needed for cards backed by other platform devices, and registered directly viasnd_soc_register_card().
All applied, thanks.