diff options
author | Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | 2013-03-11 21:27:21 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-03-13 07:07:58 -0400 |
commit | 030e79f658de11da43d32e7ad814b5d2d64c8bac (patch) | |
tree | 4f38f2b01aa2dc6da29d3b3fb3ffda556f5cb23a /sound/soc/soc-core.c | |
parent | f6161aa153581da4a3867a2d1a7caf4be19b6ec9 (diff) |
ASoC: add snd_soc_register_component()
Current ASoC has register function for platform/codec/dai/card,
but doesn't have for cpu.
It often produces confusion and fault on ASoC.
As result of ASoC community discussion,
we consider new struct snd_soc_component for CPU/CODEC,
and will switch over to use it.
This patch adds very basic struct snd_soc_component,
and register function for it.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r-- | sound/soc/soc-core.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index b7e84a7cd9ee..9e6118573fef 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
@@ -58,6 +58,7 @@ static DEFINE_MUTEX(client_mutex); | |||
58 | static LIST_HEAD(dai_list); | 58 | static LIST_HEAD(dai_list); |
59 | static LIST_HEAD(platform_list); | 59 | static LIST_HEAD(platform_list); |
60 | static LIST_HEAD(codec_list); | 60 | static LIST_HEAD(codec_list); |
61 | static LIST_HEAD(component_list); | ||
61 | 62 | ||
62 | /* | 63 | /* |
63 | * This is a timeout to do a DAPM powerdown after a stream is closed(). | 64 | * This is a timeout to do a DAPM powerdown after a stream is closed(). |
@@ -4137,6 +4138,82 @@ found: | |||
4137 | } | 4138 | } |
4138 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); | 4139 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); |
4139 | 4140 | ||
4141 | |||
4142 | /** | ||
4143 | * snd_soc_register_component - Register a component with the ASoC core | ||
4144 | * | ||
4145 | */ | ||
4146 | int snd_soc_register_component(struct device *dev, | ||
4147 | const struct snd_soc_component_driver *cmpnt_drv, | ||
4148 | struct snd_soc_dai_driver *dai_drv, | ||
4149 | int num_dai) | ||
4150 | { | ||
4151 | struct snd_soc_component *cmpnt; | ||
4152 | int ret; | ||
4153 | |||
4154 | dev_dbg(dev, "component register %s\n", dev_name(dev)); | ||
4155 | |||
4156 | cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL); | ||
4157 | if (!cmpnt) { | ||
4158 | dev_err(dev, "ASoC: Failed to allocate memory\n"); | ||
4159 | return -ENOMEM; | ||
4160 | } | ||
4161 | |||
4162 | cmpnt->name = fmt_single_name(dev, &cmpnt->id); | ||
4163 | if (!cmpnt->name) { | ||
4164 | dev_err(dev, "ASoC: Failed to simplifying name\n"); | ||
4165 | return -ENOMEM; | ||
4166 | } | ||
4167 | |||
4168 | cmpnt->dev = dev; | ||
4169 | cmpnt->driver = cmpnt_drv; | ||
4170 | cmpnt->num_dai = num_dai; | ||
4171 | |||
4172 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); | ||
4173 | if (ret < 0) { | ||
4174 | dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); | ||
4175 | goto error_component_name; | ||
4176 | } | ||
4177 | |||
4178 | mutex_lock(&client_mutex); | ||
4179 | list_add(&cmpnt->list, &component_list); | ||
4180 | mutex_unlock(&client_mutex); | ||
4181 | |||
4182 | dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name); | ||
4183 | |||
4184 | return ret; | ||
4185 | |||
4186 | error_component_name: | ||
4187 | kfree(cmpnt->name); | ||
4188 | |||
4189 | return ret; | ||
4190 | } | ||
4191 | |||
4192 | /** | ||
4193 | * snd_soc_unregister_component - Unregister a component from the ASoC core | ||
4194 | * | ||
4195 | */ | ||
4196 | void snd_soc_unregister_component(struct device *dev) | ||
4197 | { | ||
4198 | struct snd_soc_component *cmpnt; | ||
4199 | |||
4200 | list_for_each_entry(cmpnt, &component_list, list) { | ||
4201 | if (dev == cmpnt->dev) | ||
4202 | goto found; | ||
4203 | } | ||
4204 | return; | ||
4205 | |||
4206 | found: | ||
4207 | snd_soc_unregister_dais(dev, cmpnt->num_dai); | ||
4208 | |||
4209 | mutex_lock(&client_mutex); | ||
4210 | list_del(&cmpnt->list); | ||
4211 | mutex_unlock(&client_mutex); | ||
4212 | |||
4213 | dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name); | ||
4214 | kfree(cmpnt->name); | ||
4215 | } | ||
4216 | |||
4140 | /* Retrieve a card's name from device tree */ | 4217 | /* Retrieve a card's name from device tree */ |
4141 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, | 4218 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, |
4142 | const char *propname) | 4219 | const char *propname) |