Skip to content

Commit

Permalink
ASoC: Add card registration API
Browse files Browse the repository at this point in the history
ASoC v2 allows cards, codecs and platforms to instantiate separately,
with the overall ASoC device only being instantiated once all the
required components have registered. As part of backporting Liam's work
introduce an initial version of the card registration functions. At
present these do nothing active and are internal only, they will be
exposed to machine drivers after further backporting.  Adding this now
allows the datastructures used for dynamic card instantiation to be
built up gradually.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Mark Brown committed Dec 9, 2008
1 parent ca4513f commit c5af3a2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ struct snd_soc_dai_link {
/* SoC card */
struct snd_soc_card {
char *name;
struct device *dev;

struct list_head list;

int instantiated;

int (*probe)(struct platform_device *pdev);
int (*remove)(struct platform_device *pdev);
Expand Down
62 changes: 62 additions & 0 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
static struct dentry *debugfs_root;
#endif

static DEFINE_MUTEX(client_mutex);
static LIST_HEAD(card_list);

static int snd_soc_register_card(struct snd_soc_card *card);
static int snd_soc_unregister_card(struct snd_soc_card *card);

/*
* This is a timeout to do a DAPM powerdown after a stream is closed().
* It can be used to eliminate pops between different playback streams, e.g.
Expand Down Expand Up @@ -784,6 +790,14 @@ static int soc_probe(struct platform_device *pdev)
/* Bodge while we push things out of socdev */
card->socdev = socdev;

/* Bodge while we unpick instantiation */
card->dev = &pdev->dev;
ret = snd_soc_register_card(card);
if (ret != 0) {
dev_err(&pdev->dev, "Failed to register card\n");
return ret;
}

if (card->probe) {
ret = card->probe(pdev);
if (ret < 0)
Expand Down Expand Up @@ -863,6 +877,8 @@ static int soc_remove(struct platform_device *pdev)
if (card->remove)
card->remove(pdev);

snd_soc_unregister_card(card);

return 0;
}

Expand Down Expand Up @@ -1957,6 +1973,52 @@ int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
}
EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);

/**
* snd_soc_register_card - Register a card with the ASoC core
*
* @param card Card to register
*
* Note that currently this is an internal only function: it will be
* exposed to machine drivers after further backporting of ASoC v2
* registration APIs.
*/
static int snd_soc_register_card(struct snd_soc_card *card)
{
if (!card->name || !card->dev)
return -EINVAL;

INIT_LIST_HEAD(&card->list);
card->instantiated = 0;

mutex_lock(&client_mutex);
list_add(&card->list, &card_list);
mutex_unlock(&client_mutex);

dev_dbg(card->dev, "Registered card '%s'\n", card->name);

return 0;
}

/**
* snd_soc_unregister_card - Unregister a card with the ASoC core
*
* @param card Card to unregister
*
* Note that currently this is an internal only function: it will be
* exposed to machine drivers after further backporting of ASoC v2
* registration APIs.
*/
static int snd_soc_unregister_card(struct snd_soc_card *card)
{
mutex_lock(&client_mutex);
list_del(&card->list);
mutex_unlock(&client_mutex);

dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);

return 0;
}

static int __devinit snd_soc_init(void)
{
#ifdef CONFIG_DEBUG_FS
Expand Down

0 comments on commit c5af3a2

Please sign in to comment.