Add the device name on prefix for component controls.
Signed-off-by: Kiseok Jo kiseok.jo@irondevice.com Reported-by: kernel test robot lkp@intel.com --- sound/soc/codecs/sma1303.c | 79 ++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 33 deletions(-)
diff --git a/sound/soc/codecs/sma1303.c b/sound/soc/codecs/sma1303.c index 3a60927e20aa..1991c8d21ba3 100644 --- a/sound/soc/codecs/sma1303.c +++ b/sound/soc/codecs/sma1303.c @@ -29,6 +29,7 @@ #include "sma1303.h"
#define CHECK_PERIOD_TIME 1 /* sec per HZ */ +#define MAX_CONTROL_NAME 48
#define PLL_MATCH(_input_clk_name, _output_clk_name, _input_clk,\ _post_n, _n, _vco, _p_cp)\ @@ -88,6 +89,8 @@ struct sma1303_priv { long check_fault_status; };
+static struct snd_kcontrol_new *sma1303_controls; + static struct sma1303_pll_match sma1303_pll_matches[] = { PLL_MATCH("1.411MHz", "24.595MHz", 1411200, 0x07, 0xF4, 0x8B, 0x03), PLL_MATCH("1.536MHz", "24.576MHz", 1536000, 0x07, 0xE0, 0x8B, 0x03), @@ -825,6 +828,47 @@ static const struct snd_soc_dapm_route sma1303_audio_map[] = { {"AIF OUT", NULL, "AMP Enable"}, };
+static int sma1303_add_component_controls(struct snd_soc_component *component) +{ + struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); + unsigned char **name; + int index, ret = 0, size, apply = 0; + + sma1303_controls = devm_kzalloc(sma1303->dev, + sizeof(sma1303_snd_controls), GFP_KERNEL); + name = devm_kzalloc(sma1303->dev, + ARRAY_SIZE(sma1303_snd_controls), GFP_KERNEL); + + for (index = 0; index < ARRAY_SIZE(sma1303_snd_controls); index++) { + sma1303_controls[index] = sma1303_snd_controls[index]; + name[index] = devm_kzalloc(sma1303->dev, + MAX_CONTROL_NAME, GFP_KERNEL); + size = strlen(sma1303_snd_controls[index].name) + + strlen(sma1303->dev->driver->name); + if (!name[index] || size > MAX_CONTROL_NAME) { + sma1303_controls[index].name = + sma1303_snd_controls[index].name; + } else { + scnprintf(name[index], MAX_CONTROL_NAME, "%s %s", + sma1303->dev->driver->name, + sma1303_snd_controls[index].name); + sma1303_controls[index].name = name[index]; + apply++; + } + } + + ret = snd_soc_add_component_controls(component, + sma1303_controls, ARRAY_SIZE(sma1303_snd_controls)); + + dev_info(sma1303->dev, + "%s : prefix="%s", total_num=%d, apply_num=%d\n", + __func__, sma1303->dev->driver->name, + (int)ARRAY_SIZE(sma1303_snd_controls), apply); + + return ret; + +} + static int sma1303_setup_pll(struct snd_soc_component *component, unsigned int bclk) { @@ -1443,39 +1487,10 @@ static int sma1303_probe(struct snd_soc_component *component) struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); - char *dapm_widget_str = NULL; - int prefix_len = 0, str_max = 30, ret = 0, i = 0; + int ret = 0, i = 0; unsigned int status, otp_stat;
- if (component->name_prefix != NULL) { - dev_info(component->dev, "%s : component name prefix - %s\n", - __func__, component->name_prefix); - - prefix_len = strlen(component->name_prefix); - dapm_widget_str = kzalloc(prefix_len + str_max, GFP_KERNEL); - - if (!dapm_widget_str) { - kfree(dapm_widget_str); - return -ENOMEM; - } - - strcpy(dapm_widget_str, component->name_prefix); - strcat(dapm_widget_str, " Playback"); - - snd_soc_dapm_ignore_suspend(dapm, dapm_widget_str); - - memset(dapm_widget_str + prefix_len, 0, str_max); - - strcpy(dapm_widget_str, component->name_prefix); - strcat(dapm_widget_str, " SPK"); - - snd_soc_dapm_ignore_suspend(dapm, dapm_widget_str); - - kfree(dapm_widget_str); - } else { - snd_soc_dapm_ignore_suspend(dapm, "Playback"); - snd_soc_dapm_ignore_suspend(dapm, "SPK"); - } + ret += sma1303_add_component_controls(component);
snd_soc_dapm_sync(dapm);
@@ -1534,8 +1549,6 @@ static void sma1303_remove(struct snd_soc_component *component) static const struct snd_soc_component_driver sma1303_component = { .probe = sma1303_probe, .remove = sma1303_remove, - .controls = sma1303_snd_controls, - .num_controls = ARRAY_SIZE(sma1303_snd_controls), .dapm_widgets = sma1303_dapm_widgets, .num_dapm_widgets = ARRAY_SIZE(sma1303_dapm_widgets), .dapm_routes = sma1303_audio_map,