ASoC: cleanup duplicated code.
Many codec drivers were implementing cookie-cutter copies of the function that adds kcontrols to the codec. This patch moves this code to a common function snd_soc_add_controls() in soc-core.c and updates all drivers using copies of this function to use the new common version. [Edited to raise priority of error log message and document parameters. -- broonie] Signed-off-by: Ian Molton <ian@mnementh.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
@@ -1494,6 +1494,37 @@ struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_soc_cnew);
|
||||
|
||||
/**
|
||||
* snd_soc_add_controls - add an array of controls to a codec.
|
||||
* Convienience function to add a list of controls. Many codecs were
|
||||
* duplicating this code.
|
||||
*
|
||||
* @codec: codec to add controls to
|
||||
* @controls: array of controls to add
|
||||
* @num_controls: number of elements in the array
|
||||
*
|
||||
* Return 0 for success, else error.
|
||||
*/
|
||||
int snd_soc_add_controls(struct snd_soc_codec *codec,
|
||||
const struct snd_kcontrol_new *controls, int num_controls)
|
||||
{
|
||||
struct snd_card *card = codec->card;
|
||||
int err, i;
|
||||
|
||||
for (i = 0; i < num_controls; i++) {
|
||||
const struct snd_kcontrol_new *control = &controls[i];
|
||||
err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL));
|
||||
if (err < 0) {
|
||||
dev_err(codec->dev, "%s: Failed to add %s\n",
|
||||
codec->name, control->name);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_soc_add_controls);
|
||||
|
||||
/**
|
||||
* snd_soc_info_enum_double - enumerated double mixer info callback
|
||||
* @kcontrol: mixer control
|
||||
|
Reference in New Issue
Block a user