Skip to content

Commit

Permalink
ASoC: Add support for allocating AC'97 device before registering it
Browse files Browse the repository at this point in the history
In some cases it is necessary to before additional operations after the
device has been initialized and before the device is registered. This can
for example be resetting the device.

This patch introduces a new function snd_soc_alloc_ac97_codec() which is
similar to snd_soc_new_ac97_codec() except that it does not register the
device. Any users of snd_soc_alloc_ac97_codec() are responsible for calling
device_add() manually.

Fixes: 6794f70 ("ASoC: ac97: Drop delayed device registration")
Reported-by: Manuel Lauss <manuel.lauss@gmail.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Tested-by: Manuel Lauss <manuel.lauss@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
  • Loading branch information
Lars-Peter Clausen authored and Mark Brown committed Jan 26, 2015
1 parent 97bf6af commit 47e0394
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned int reg,
unsigned int mask, unsigned int value);

#ifdef CONFIG_SND_SOC_AC97_BUS
struct snd_ac97 *snd_soc_alloc_ac97_codec(struct snd_soc_codec *codec);
struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec);
void snd_soc_free_ac97_codec(struct snd_ac97 *ac97);

Expand Down
36 changes: 30 additions & 6 deletions sound/soc/soc-ac97.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ static void soc_ac97_device_release(struct device *dev)
}

/**
* snd_soc_new_ac97_codec - initailise AC97 device
* @codec: audio codec
* snd_soc_alloc_ac97_codec() - Allocate new a AC'97 device
* @codec: The CODEC for which to create the AC'97 device
*
* Initialises AC97 codec resources for use by ad-hoc devices only.
* Allocated a new snd_ac97 device and intializes it, but does not yet register
* it. The caller is responsible to either call device_add(&ac97->dev) to
* register the device, or to call put_device(&ac97->dev) to free the device.
*
* Returns: A snd_ac97 device or a PTR_ERR in case of an error.
*/
struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
struct snd_ac97 *snd_soc_alloc_ac97_codec(struct snd_soc_codec *codec)
{
struct snd_ac97 *ac97;
int ret;

ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
if (ac97 == NULL)
Expand All @@ -73,7 +76,28 @@ struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
codec->component.card->snd_card->number, 0,
codec->component.name);

ret = device_register(&ac97->dev);
device_initialize(&ac97->dev);

return ac97;
}
EXPORT_SYMBOL(snd_soc_alloc_ac97_codec);

/**
* snd_soc_new_ac97_codec - initailise AC97 device
* @codec: audio codec
*
* Initialises AC97 codec resources for use by ad-hoc devices only.
*/
struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
{
struct snd_ac97 *ac97;
int ret;

ac97 = snd_soc_alloc_ac97_codec(codec);
if (IS_ERR(ac97))
return ac97;

ret = device_add(&ac97->dev);
if (ret) {
put_device(&ac97->dev);
return ERR_PTR(ret);
Expand Down

0 comments on commit 47e0394

Please sign in to comment.