aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorLiam Girdwood <lrg@ti.com>2012-02-03 12:43:09 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-02-04 07:40:11 -0500
commit022658beab5581ecc1d325d60857f2fc464da22f (patch)
treec7617e257cf492990c369197d5e144ac15225fd4 /sound/soc/soc-core.c
parent83344027cacf1944fe180907fa98ee4116ef33ea (diff)
ASoC: core: Add support for DAI and machine kcontrols.
Currently ASoC can only add kcontrols using codec and platform component device handles. It's also desirable to add kcontrols for DAIs (i.e. McBSP) and for SoC card machine drivers too. This allows the kcontrol to have a direct handle to the parent ASoC component DAI/SoC Card/Platform/Codec device and hence easily get it's private data. This change makes snd_soc_add_controls() static and wraps it in the folowing calls (card and dai are new) :- snd_soc_add_card_controls() snd_soc_add_codec_controls() snd_soc_add_dai_controls() snd_soc_add_platform_controls() This patch also does a lot of small mechanical changes in individual codec drivers to replace snd_soc_add_controls() with snd_soc_add_codec_controls(). It also updates the McBSP DAI driver to use snd_soc_add_dai_controls(). Finally, it updates the existing machine drivers that register controls to either :- 1) Use snd_soc_add_card_controls() where no direct codec control is required. 2) Use snd_soc_add_codec_controls() where there is direct codec control. In the case of 1) above we also update the machine drivers to get the correct component data pointers from the kcontrol (rather than getting the machine pointer via the codec pointer). Signed-off-by: Liam Girdwood <lrg@ti.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c108
1 files changed, 70 insertions, 38 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 091d5f37ae64..a3a47cdaac8f 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -996,7 +996,7 @@ static int soc_probe_codec(struct snd_soc_card *card,
996 } 996 }
997 997
998 if (driver->controls) 998 if (driver->controls)
999 snd_soc_add_controls(codec, driver->controls, 999 snd_soc_add_codec_controls(codec, driver->controls,
1000 driver->num_controls); 1000 driver->num_controls);
1001 if (driver->dapm_routes) 1001 if (driver->dapm_routes)
1002 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes, 1002 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
@@ -1457,13 +1457,8 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
1457 } 1457 }
1458 } 1458 }
1459 1459
1460 /* We should have a non-codec control add function but we don't */
1461 if (card->controls) 1460 if (card->controls)
1462 snd_soc_add_controls(list_first_entry(&card->codec_dev_list, 1461 snd_soc_add_card_controls(card, card->controls, card->num_controls);
1463 struct snd_soc_codec,
1464 card_list),
1465 card->controls,
1466 card->num_controls);
1467 1462
1468 if (card->dapm_routes) 1463 if (card->dapm_routes)
1469 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, 1464 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
@@ -2015,9 +2010,28 @@ struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
2015} 2010}
2016EXPORT_SYMBOL_GPL(snd_soc_cnew); 2011EXPORT_SYMBOL_GPL(snd_soc_cnew);
2017 2012
2013static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2014 const struct snd_kcontrol_new *controls, int num_controls,
2015 const char *prefix, void *data)
2016{
2017 int err, i;
2018
2019 for (i = 0; i < num_controls; i++) {
2020 const struct snd_kcontrol_new *control = &controls[i];
2021 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2022 control->name, prefix));
2023 if (err < 0) {
2024 dev_err(dev, "Failed to add %s: %d\n", control->name, err);
2025 return err;
2026 }
2027 }
2028
2029 return 0;
2030}
2031
2018/** 2032/**
2019 * snd_soc_add_controls - add an array of controls to a codec. 2033 * snd_soc_add_codec_controls - add an array of controls to a codec.
2020 * Convienience function to add a list of controls. Many codecs were 2034 * Convenience function to add a list of controls. Many codecs were
2021 * duplicating this code. 2035 * duplicating this code.
2022 * 2036 *
2023 * @codec: codec to add controls to 2037 * @codec: codec to add controls to
@@ -2026,31 +2040,19 @@ EXPORT_SYMBOL_GPL(snd_soc_cnew);
2026 * 2040 *
2027 * Return 0 for success, else error. 2041 * Return 0 for success, else error.
2028 */ 2042 */
2029int snd_soc_add_controls(struct snd_soc_codec *codec, 2043int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
2030 const struct snd_kcontrol_new *controls, int num_controls) 2044 const struct snd_kcontrol_new *controls, int num_controls)
2031{ 2045{
2032 struct snd_card *card = codec->card->snd_card; 2046 struct snd_card *card = codec->card->snd_card;
2033 int err, i;
2034 2047
2035 for (i = 0; i < num_controls; i++) { 2048 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2036 const struct snd_kcontrol_new *control = &controls[i]; 2049 codec->name_prefix, codec);
2037 err = snd_ctl_add(card, snd_soc_cnew(control, codec,
2038 control->name,
2039 codec->name_prefix));
2040 if (err < 0) {
2041 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
2042 codec->name, control->name, err);
2043 return err;
2044 }
2045 }
2046
2047 return 0;
2048} 2050}
2049EXPORT_SYMBOL_GPL(snd_soc_add_controls); 2051EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
2050 2052
2051/** 2053/**
2052 * snd_soc_add_platform_controls - add an array of controls to a platform. 2054 * snd_soc_add_platform_controls - add an array of controls to a platform.
2053 * Convienience function to add a list of controls. 2055 * Convenience function to add a list of controls.
2054 * 2056 *
2055 * @platform: platform to add controls to 2057 * @platform: platform to add controls to
2056 * @controls: array of controls to add 2058 * @controls: array of controls to add
@@ -2062,23 +2064,53 @@ int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2062 const struct snd_kcontrol_new *controls, int num_controls) 2064 const struct snd_kcontrol_new *controls, int num_controls)
2063{ 2065{
2064 struct snd_card *card = platform->card->snd_card; 2066 struct snd_card *card = platform->card->snd_card;
2065 int err, i;
2066 2067
2067 for (i = 0; i < num_controls; i++) { 2068 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2068 const struct snd_kcontrol_new *control = &controls[i]; 2069 NULL, platform);
2069 err = snd_ctl_add(card, snd_soc_cnew(control, platform,
2070 control->name, NULL));
2071 if (err < 0) {
2072 dev_err(platform->dev, "Failed to add %s %d\n",control->name, err);
2073 return err;
2074 }
2075 }
2076
2077 return 0;
2078} 2070}
2079EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); 2071EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2080 2072
2081/** 2073/**
2074 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2075 * Convenience function to add a list of controls.
2076 *
2077 * @soc_card: SoC card to add controls to
2078 * @controls: array of controls to add
2079 * @num_controls: number of elements in the array
2080 *
2081 * Return 0 for success, else error.
2082 */
2083int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2084 const struct snd_kcontrol_new *controls, int num_controls)
2085{
2086 struct snd_card *card = soc_card->snd_card;
2087
2088 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2089 NULL, soc_card);
2090}
2091EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2092
2093/**
2094 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2095 * Convienience function to add a list of controls.
2096 *
2097 * @dai: DAI to add controls to
2098 * @controls: array of controls to add
2099 * @num_controls: number of elements in the array
2100 *
2101 * Return 0 for success, else error.
2102 */
2103int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2104 const struct snd_kcontrol_new *controls, int num_controls)
2105{
2106 struct snd_card *card = dai->card->snd_card;
2107
2108 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2109 NULL, dai);
2110}
2111EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2112
2113/**
2082 * snd_soc_info_enum_double - enumerated double mixer info callback 2114 * snd_soc_info_enum_double - enumerated double mixer info callback
2083 * @kcontrol: mixer control 2115 * @kcontrol: mixer control
2084 * @uinfo: control element information 2116 * @uinfo: control element information