ASoC: ac97: Drop delayed device registration
We have all the information and dependencies we need to initialize and register the device available in snd_soc_new_ac97_codec(). So there is no need to delay the device registration until after the card itself as been registered. This makes the code significantly simpler and also makes it possible to use the AC'97 device in the CODECs probe function. The later will be required to be able to convert the AC'97 CODEC drivers to regmap. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Родитель
ca005f324e
Коммит
6794f709b7
|
@ -507,15 +507,7 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
|
||||||
struct platform_device *pdev);
|
struct platform_device *pdev);
|
||||||
|
|
||||||
extern struct snd_ac97_bus_ops *soc_ac97_ops;
|
extern struct snd_ac97_bus_ops *soc_ac97_ops;
|
||||||
|
|
||||||
int snd_soc_ac97_register_dai_links(struct snd_soc_card *card);
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline int snd_soc_ac97_register_dai_links(struct snd_soc_card *card)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
|
static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
|
||||||
struct platform_device *pdev)
|
struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
@ -808,8 +800,6 @@ struct snd_soc_codec {
|
||||||
struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
|
struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
|
||||||
unsigned int cache_bypass:1; /* Suppress access to the cache */
|
unsigned int cache_bypass:1; /* Suppress access to the cache */
|
||||||
unsigned int suspended:1; /* Codec is in suspend PM state */
|
unsigned int suspended:1; /* Codec is in suspend PM state */
|
||||||
unsigned int ac97_registered:1; /* Codec has been AC97 registered */
|
|
||||||
unsigned int ac97_created:1; /* Codec has been created by SoC */
|
|
||||||
unsigned int cache_init:1; /* codec cache has been initialized */
|
unsigned int cache_init:1; /* codec cache has been initialized */
|
||||||
u32 cache_sync; /* Cache needs to be synced to hardware */
|
u32 cache_sync; /* Cache needs to be synced to hardware */
|
||||||
|
|
||||||
|
|
|
@ -42,80 +42,6 @@ static struct snd_ac97_bus soc_ac97_bus = {
|
||||||
.ops = NULL, /* Gets initialized in snd_soc_set_ac97_ops() */
|
.ops = NULL, /* Gets initialized in snd_soc_set_ac97_ops() */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* register ac97 codec to bus */
|
|
||||||
static int soc_register_ac97_codec(struct snd_soc_codec *codec,
|
|
||||||
struct snd_soc_dai *codec_dai)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Only instantiate AC97 if not already done by the adaptor
|
|
||||||
* for the generic AC97 subsystem.
|
|
||||||
*/
|
|
||||||
if (!codec_dai->driver->ac97_control || codec->ac97_registered)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 (!codec->ac97_created)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
codec->ac97->dev.bus = &ac97_bus_type;
|
|
||||||
codec->ac97->dev.parent = codec->component.card->dev;
|
|
||||||
|
|
||||||
dev_set_name(&codec->ac97->dev, "%d-%d:%s",
|
|
||||||
codec->component.card->snd_card->number, 0,
|
|
||||||
codec->component.name);
|
|
||||||
ret = device_add(&codec->ac97->dev);
|
|
||||||
if (ret < 0) {
|
|
||||||
dev_err(codec->dev, "ASoC: AC97 device register failed: %d\n",
|
|
||||||
ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
codec->ac97_registered = 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
|
|
||||||
{
|
|
||||||
if (!codec->ac97_registered)
|
|
||||||
return;
|
|
||||||
device_del(&codec->ac97->dev);
|
|
||||||
codec->ac97_registered = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
|
|
||||||
{
|
|
||||||
int i, ret;
|
|
||||||
|
|
||||||
for (i = 0; i < rtd->num_codecs; i++) {
|
|
||||||
struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
|
|
||||||
|
|
||||||
ret = soc_register_ac97_codec(codec_dai->codec, codec_dai);
|
|
||||||
if (ret) {
|
|
||||||
while (--i >= 0)
|
|
||||||
soc_unregister_ac97_codec(codec_dai->codec);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < rtd->num_codecs; i++)
|
|
||||||
soc_unregister_ac97_codec(rtd->codec_dais[i]->codec);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void soc_ac97_device_release(struct device *dev)
|
static void soc_ac97_device_release(struct device *dev)
|
||||||
{
|
{
|
||||||
kfree(to_ac97_t(dev));
|
kfree(to_ac97_t(dev));
|
||||||
|
@ -129,22 +55,28 @@ static void soc_ac97_device_release(struct device *dev)
|
||||||
*/
|
*/
|
||||||
int snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
|
int snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
|
codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
|
||||||
if (codec->ac97 == NULL)
|
if (codec->ac97 == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
codec->ac97->bus = &soc_ac97_bus;
|
codec->ac97->bus = &soc_ac97_bus;
|
||||||
codec->ac97->num = 0;
|
codec->ac97->num = 0;
|
||||||
|
|
||||||
|
codec->ac97->dev.bus = &ac97_bus_type;
|
||||||
|
codec->ac97->dev.parent = codec->component.card->dev;
|
||||||
codec->ac97->dev.release = soc_ac97_device_release;
|
codec->ac97->dev.release = soc_ac97_device_release;
|
||||||
|
|
||||||
/*
|
dev_set_name(&codec->ac97->dev, "%d-%d:%s",
|
||||||
* Mark the AC97 device to be created by us. This way we ensure that the
|
codec->component.card->snd_card->number, 0,
|
||||||
* device will be registered with the device subsystem later on.
|
codec->component.name);
|
||||||
*/
|
|
||||||
codec->ac97_created = 1;
|
|
||||||
device_initialize(&codec->ac97->dev);
|
|
||||||
|
|
||||||
return 0;
|
ret = device_register(&codec->ac97->dev);
|
||||||
|
if (ret)
|
||||||
|
put_device(&codec->ac97->dev);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
|
EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
|
||||||
|
|
||||||
|
@ -156,11 +88,10 @@ EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
|
||||||
*/
|
*/
|
||||||
void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
|
void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
|
||||||
{
|
{
|
||||||
soc_unregister_ac97_codec(codec);
|
device_del(&codec->ac97->dev);
|
||||||
codec->ac97->bus = NULL;
|
codec->ac97->bus = NULL;
|
||||||
put_device(&codec->ac97->dev);
|
put_device(&codec->ac97->dev);
|
||||||
codec->ac97 = NULL;
|
codec->ac97 = NULL;
|
||||||
codec->ac97_created = 0;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
|
EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
|
||||||
|
|
||||||
|
@ -321,24 +252,3 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset);
|
EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset);
|
||||||
|
|
||||||
int snd_soc_ac97_register_dai_links(struct snd_soc_card *card)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* register any AC97 codecs */
|
|
||||||
for (i = 0; i < card->num_rtd; i++) {
|
|
||||||
ret = soc_register_ac97_dai_link(&card->rtd[i]);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
err:
|
|
||||||
dev_err(card->dev,
|
|
||||||
"ASoC: failed to register AC97: %d\n", ret);
|
|
||||||
while (--i >= 0)
|
|
||||||
soc_unregister_ac97_dai_link(&card->rtd[i]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1671,10 +1671,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
|
||||||
goto probe_aux_dev_err;
|
goto probe_aux_dev_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = snd_soc_ac97_register_dai_links(card);
|
|
||||||
if (ret < 0)
|
|
||||||
goto probe_aux_dev_err;
|
|
||||||
|
|
||||||
card->instantiated = 1;
|
card->instantiated = 1;
|
||||||
snd_soc_dapm_sync(&card->dapm);
|
snd_soc_dapm_sync(&card->dapm);
|
||||||
mutex_unlock(&card->mutex);
|
mutex_unlock(&card->mutex);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче