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:
Ian Molton
2009-01-09 00:23:21 +00:00
committed by Mark Brown
parent a6ba2b2dab
commit 3e8e1952e3
23 changed files with 89 additions and 360 deletions

View File

@@ -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