diff options
author | Dimitris Papastamos <dp@opensource.wolfsonmicro.com> | 2010-12-02 11:11:06 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-12-03 11:37:32 -0500 |
commit | fdf0f54dab8e401fd9bdd441c3fc4fa5c8837646 (patch) | |
tree | a1d33d33931964c21765042e0ba53591b9c7b7a2 | |
parent | 3335ddca9367675f4ee0bd50cc70402c4919a10d (diff) |
ASoC: soc-core: Allow machine drivers to override compress_type
This patch allows machine drivers to override the compression type
provided by the codec driver.
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r-- | include/sound/soc.h | 1 | ||||
-rw-r--r-- | sound/soc/soc-core.c | 74 |
2 files changed, 64 insertions, 11 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h index 017986159d5e..7d53cc453637 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h | |||
@@ -472,6 +472,7 @@ struct snd_soc_codec { | |||
472 | unsigned int ac97_registered:1; /* Codec has been AC97 registered */ | 472 | unsigned int ac97_registered:1; /* Codec has been AC97 registered */ |
473 | unsigned int ac97_created:1; /* Codec has been created by SoC */ | 473 | unsigned int ac97_created:1; /* Codec has been created by SoC */ |
474 | unsigned int sysfs_registered:1; /* codec has been sysfs registered */ | 474 | unsigned int sysfs_registered:1; /* codec has been sysfs registered */ |
475 | unsigned int cache_init:1; /* codec cache has been initialized */ | ||
475 | 476 | ||
476 | /* codec IO */ | 477 | /* codec IO */ |
477 | void *control_data; /* codec control (i2c/3wire) data */ | 478 | void *control_data; /* codec control (i2c/3wire) data */ |
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index a95d111a6531..e9aa9ce59c06 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
@@ -1730,9 +1730,36 @@ static void soc_remove_aux_dev(struct snd_soc_card *card, int num) | |||
1730 | } | 1730 | } |
1731 | } | 1731 | } |
1732 | 1732 | ||
1733 | static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, | ||
1734 | enum snd_soc_compress_type compress_type) | ||
1735 | { | ||
1736 | int ret; | ||
1737 | |||
1738 | if (codec->cache_init) | ||
1739 | return 0; | ||
1740 | |||
1741 | /* override the compress_type if necessary */ | ||
1742 | if (compress_type && codec->compress_type != compress_type) | ||
1743 | codec->compress_type = compress_type; | ||
1744 | dev_dbg(codec->dev, "Cache compress_type for %s is %d\n", | ||
1745 | codec->name, codec->compress_type); | ||
1746 | ret = snd_soc_cache_init(codec); | ||
1747 | if (ret < 0) { | ||
1748 | dev_err(codec->dev, "Failed to set cache compression type: %d\n", | ||
1749 | ret); | ||
1750 | return ret; | ||
1751 | } | ||
1752 | codec->cache_init = 1; | ||
1753 | return 0; | ||
1754 | } | ||
1755 | |||
1756 | |||
1733 | static void snd_soc_instantiate_card(struct snd_soc_card *card) | 1757 | static void snd_soc_instantiate_card(struct snd_soc_card *card) |
1734 | { | 1758 | { |
1735 | struct platform_device *pdev = to_platform_device(card->dev); | 1759 | struct platform_device *pdev = to_platform_device(card->dev); |
1760 | struct snd_soc_codec *codec; | ||
1761 | struct snd_soc_codec_conf *codec_conf; | ||
1762 | enum snd_soc_compress_type compress_type; | ||
1736 | int ret, i; | 1763 | int ret, i; |
1737 | 1764 | ||
1738 | mutex_lock(&card->mutex); | 1765 | mutex_lock(&card->mutex); |
@@ -1752,6 +1779,39 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card) | |||
1752 | return; | 1779 | return; |
1753 | } | 1780 | } |
1754 | 1781 | ||
1782 | /* initialize the register cache for each available codec */ | ||
1783 | list_for_each_entry(codec, &codec_list, list) { | ||
1784 | if (codec->cache_init) | ||
1785 | continue; | ||
1786 | /* check to see if we need to override the compress_type */ | ||
1787 | for (i = 0; i < card->num_configs; ++i) { | ||
1788 | codec_conf = &card->codec_conf[i]; | ||
1789 | if (!strcmp(codec->name, codec_conf->dev_name)) { | ||
1790 | compress_type = codec_conf->compress_type; | ||
1791 | if (compress_type && compress_type | ||
1792 | != codec->compress_type) | ||
1793 | break; | ||
1794 | } | ||
1795 | } | ||
1796 | if (i == card->num_configs) { | ||
1797 | /* no need to override the compress_type so | ||
1798 | * go ahead and do the standard thing */ | ||
1799 | ret = snd_soc_init_codec_cache(codec, 0); | ||
1800 | if (ret < 0) { | ||
1801 | mutex_unlock(&card->mutex); | ||
1802 | return; | ||
1803 | } | ||
1804 | continue; | ||
1805 | } | ||
1806 | /* override the compress_type with the one supplied in | ||
1807 | * the machine driver */ | ||
1808 | ret = snd_soc_init_codec_cache(codec, compress_type); | ||
1809 | if (ret < 0) { | ||
1810 | mutex_unlock(&card->mutex); | ||
1811 | return; | ||
1812 | } | ||
1813 | } | ||
1814 | |||
1755 | /* card bind complete so register a sound card */ | 1815 | /* card bind complete so register a sound card */ |
1756 | ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, | 1816 | ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
1757 | card->owner, 0, &card->snd_card); | 1817 | card->owner, 0, &card->snd_card); |
@@ -3481,13 +3541,7 @@ int snd_soc_register_codec(struct device *dev, | |||
3481 | reg_size, GFP_KERNEL); | 3541 | reg_size, GFP_KERNEL); |
3482 | if (!codec->reg_def_copy) { | 3542 | if (!codec->reg_def_copy) { |
3483 | ret = -ENOMEM; | 3543 | ret = -ENOMEM; |
3484 | goto error_cache; | 3544 | goto fail; |
3485 | } | ||
3486 | ret = snd_soc_cache_init(codec); | ||
3487 | if (ret < 0) { | ||
3488 | dev_err(codec->dev, "Failed to set cache compression type: %d\n", | ||
3489 | ret); | ||
3490 | goto error_cache; | ||
3491 | } | 3545 | } |
3492 | } | 3546 | } |
3493 | 3547 | ||
@@ -3500,7 +3554,7 @@ int snd_soc_register_codec(struct device *dev, | |||
3500 | if (num_dai) { | 3554 | if (num_dai) { |
3501 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); | 3555 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); |
3502 | if (ret < 0) | 3556 | if (ret < 0) |
3503 | goto error_dais; | 3557 | goto fail; |
3504 | } | 3558 | } |
3505 | 3559 | ||
3506 | mutex_lock(&client_mutex); | 3560 | mutex_lock(&client_mutex); |
@@ -3511,9 +3565,7 @@ int snd_soc_register_codec(struct device *dev, | |||
3511 | pr_debug("Registered codec '%s'\n", codec->name); | 3565 | pr_debug("Registered codec '%s'\n", codec->name); |
3512 | return 0; | 3566 | return 0; |
3513 | 3567 | ||
3514 | error_dais: | 3568 | fail: |
3515 | snd_soc_cache_exit(codec); | ||
3516 | error_cache: | ||
3517 | kfree(codec->reg_def_copy); | 3569 | kfree(codec->reg_def_copy); |
3518 | codec->reg_def_copy = NULL; | 3570 | codec->reg_def_copy = NULL; |
3519 | kfree(codec->name); | 3571 | kfree(codec->name); |