[alsa-devel] [PATCH 0/3] ASoC AC97 generic glue patches
Hi,
While I was porting ep93xx-ac97 driver to multicomponent ASoC, I encountered few issues with the generic AC97 glue driver (which we are using with Sim.One). This series tries to fix those.
Regards, MW
Mika Westerberg (3): ASoC: ac97: don't call snd_soc_new_ac97_codec at probe ASoC: don't register AC97 devices twice ASoC: ac97: add MODULE_ALIAS for the platform driver
include/sound/soc.h | 1 + sound/soc/codecs/ac97.c | 7 +------ sound/soc/soc-core.c | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-)
It is not needed since snd_ac97_mixer() will create a new ac97 object for us. Removing the call also fixes a memory leak since codec->ac97 is set to NULL at the beginning of snd_ac97_mixer().
Signed-off-by: Mika Westerberg mika.westerberg@iki.fi --- sound/soc/codecs/ac97.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c index 2c824a5..f5139ae 100644 --- a/sound/soc/codecs/ac97.c +++ b/sound/soc/codecs/ac97.c @@ -79,12 +79,6 @@ static int ac97_soc_probe(struct snd_soc_codec *codec) struct snd_ac97_template ac97_template; int ret;
- ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); - if (ret < 0) { - printk(KERN_ERR "ASoC: failed to init generic ac97 glue\n"); - return ret; - } - /* add codec as bus device for standard ac97 */ ret = snd_ac97_bus(codec->card->snd_card, 0, &soc_ac97_ops, NULL, &ac97_bus); if (ret < 0)
With generic AC97 ASoC glue driver (codec/ac97.c), we get following warning when the device is registered (slightly stripped the backtrace):
kobject (c5a863e8): tried to init an initialized object, something is seriously wrong. [<c00254fc>] (unwind_backtrace+0x0/0xec) [<c014fad0>] (kobject_init+0x38/0x70) [<c0171e94>] (device_initialize+0x20/0x70) [<c017267c>] (device_register+0xc/0x18) [<bf20db70>] (snd_soc_instantiate_cards+0x924/0xacc [snd_soc_core]) [<bf20e0d0>] (snd_soc_register_platform+0x16c/0x198 [snd_soc_core]) [<c0175304>] (platform_drv_probe+0x18/0x1c) [<c0174454>] (driver_probe_device+0xb0/0x16c) [<c017456c>] (__driver_attach+0x5c/0x7c) [<c0173cec>] (bus_for_each_dev+0x48/0x78) [<c0173600>] (bus_add_driver+0x98/0x214) [<c0174834>] (driver_register+0xa4/0x130) [<c001f410>] (do_one_initcall+0xd0/0x1a4) [<c0062ddc>] (sys_init_module+0x12b0/0x1454)
This happens because the generic AC97 glue driver creates its codec->ac97 via calling snd_ac97_mixer(). snd_ac97_mixer() provides own version of snd_device.register which handles the device registration when snd_card_register() is called.
To avoid registering the AC97 device twice, we add a new flag to the snd_soc_codec: ac97_created which tells whether the AC97 device was created by SoC subsystem.
Signed-off-by: Mika Westerberg mika.westerberg@iki.fi --- I'm not sure whether this is the best solution to the issue. Maybe we could just check codec->ac97->dev.bus and refuse to register the device again?
include/sound/soc.h | 1 + sound/soc/soc-core.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 4fb079e..5c3bce8 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -442,6 +442,7 @@ struct snd_soc_codec { unsigned int suspended:1; /* Codec is in suspend PM state */ unsigned int probed:1; /* Codec has been probed */ unsigned int ac97_registered:1; /* Codec has been AC97 registered */ + unsigned int ac97_created:1; /* Codec has been created by SoC */ unsigned int sysfs_registered:1; /* codec has been sysfs registered */
/* codec IO */ diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 8751efd..7d22b5d 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1497,6 +1497,16 @@ static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) * for the generic AC97 subsystem. */ if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) { + /* + * It is possible that the AC97 device is already registered to + * the device subsystem. This happens when the device is created + * via snd_ac97_mixer(). Currently only SoC codec that does so + * is the generic AC97 glue but others migh emerge. + * + * In those cases we don't try to register the device again. + */ + if (!rtd->codec->ac97_created) + return 0;
ret = soc_ac97_dev_register(rtd->codec); if (ret < 0) { @@ -1812,6 +1822,13 @@ int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
codec->ac97->bus->ops = ops; codec->ac97->num = num; + + /* + * Mark the AC97 device to be created by us. This way we ensure that the + * device will be registered with the device subsystem later on. + */ + codec->ac97_created = 1; + mutex_unlock(&codec->mutex); return 0; } @@ -1832,6 +1849,7 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) kfree(codec->ac97->bus); kfree(codec->ac97); codec->ac97 = NULL; + codec->ac97_created = 0; mutex_unlock(&codec->mutex); } EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
So that modprobe can load the driver automatically when the platform device appears.
Signed-off-by: Mika Westerberg mika.westerberg@iki.fi --- sound/soc/codecs/ac97.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c index f5139ae..3c08793 100644 --- a/sound/soc/codecs/ac97.c +++ b/sound/soc/codecs/ac97.c @@ -162,3 +162,4 @@ module_exit(ac97_exit); MODULE_DESCRIPTION("Soc Generic AC97 driver"); MODULE_AUTHOR("Liam Girdwood"); MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:ac97-codec");
On Wed, 2010-10-13 at 11:30 +0300, Mika Westerberg wrote:
Hi,
While I was porting ep93xx-ac97 driver to multicomponent ASoC, I encountered few issues with the generic AC97 glue driver (which we are using with Sim.One). This series tries to fix those.
Regards, MW
Mika Westerberg (3): ASoC: ac97: don't call snd_soc_new_ac97_codec at probe ASoC: don't register AC97 devices twice ASoC: ac97: add MODULE_ALIAS for the platform driver
include/sound/soc.h | 1 + sound/soc/codecs/ac97.c | 7 +------ sound/soc/soc-core.c | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-)
All
Acked-by: Liam Girdwood lrg@slimlogic.co.uk
On Wed, Oct 13, 2010 at 11:30:30AM +0300, Mika Westerberg wrote:
Hi,
While I was porting ep93xx-ac97 driver to multicomponent ASoC, I encountered few issues with the generic AC97 glue driver (which we are using with Sim.One). This series tries to fix those.
All applied, thanks. I've been trying to get some AC'97 hardware working for a while to fix this :/
participants (3)
-
Liam Girdwood
-
Mark Brown
-
Mika Westerberg