aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-08-19 09:51:28 -0400
committerMark Brown <broonie@linaro.org>2014-08-19 11:59:47 -0400
commit886f5692253de1a9509f5cb708432b2157afb57c (patch)
tree59478de5d89b9f6b99e7cb9772ee2c3ee53fd09d
parent14621c7e5e72200ec021a7580121130ce7f2ff22 (diff)
ASoC: Automatically initialize regmap for all components
So far regmap is only automatically initialized for CODECs. Now that we have the infrastructure in place to let components have DAPM widgets and controls that want to use the generic regmap based IO also make sure to automatically initialize regmap for all components. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--include/sound/soc.h3
-rw-r--r--sound/soc/soc-core.c35
-rw-r--r--sound/soc/soc-io.c28
3 files changed, 17 insertions, 49 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 3a0031e1f9b4..8ebee30311e3 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1289,9 +1289,6 @@ void snd_soc_component_async_complete(struct snd_soc_component *component);
1289int snd_soc_component_test_bits(struct snd_soc_component *component, 1289int snd_soc_component_test_bits(struct snd_soc_component *component,
1290 unsigned int reg, unsigned int mask, unsigned int value); 1290 unsigned int reg, unsigned int mask, unsigned int value);
1291 1291
1292int snd_soc_component_init_io(struct snd_soc_component *component,
1293 struct regmap *regmap);
1294
1295/* device driver data */ 1292/* device driver data */
1296 1293
1297static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card, 1294static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 140f43f91635..96f286643ca1 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -4032,8 +4032,23 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
4032 return 0; 4032 return 0;
4033} 4033}
4034 4034
4035static void snd_soc_component_init_regmap(struct snd_soc_component *component)
4036{
4037 if (!component->regmap)
4038 component->regmap = dev_get_regmap(component->dev, NULL);
4039 if (component->regmap) {
4040 int val_bytes = regmap_get_val_bytes(component->regmap);
4041 /* Errors are legitimate for non-integer byte multiples */
4042 if (val_bytes > 0)
4043 component->val_bytes = val_bytes;
4044 }
4045}
4046
4035static void snd_soc_component_add_unlocked(struct snd_soc_component *component) 4047static void snd_soc_component_add_unlocked(struct snd_soc_component *component)
4036{ 4048{
4049 if (!component->write && !component->read)
4050 snd_soc_component_init_regmap(component);
4051
4037 list_add(&component->list, &component_list); 4052 list_add(&component->list, &component_list);
4038} 4053}
4039 4054
@@ -4371,7 +4386,6 @@ int snd_soc_register_codec(struct device *dev,
4371{ 4386{
4372 struct snd_soc_codec *codec; 4387 struct snd_soc_codec *codec;
4373 struct snd_soc_dai *dai; 4388 struct snd_soc_dai *dai;
4374 struct regmap *regmap;
4375 int ret, i; 4389 int ret, i;
4376 4390
4377 dev_dbg(dev, "codec register %s\n", dev_name(dev)); 4391 dev_dbg(dev, "codec register %s\n", dev_name(dev));
@@ -4425,23 +4439,8 @@ int snd_soc_register_codec(struct device *dev,
4425 codec->component.debugfs_prefix = "codec"; 4439 codec->component.debugfs_prefix = "codec";
4426#endif 4440#endif
4427 4441
4428 if (!codec->component.write) { 4442 if (codec_drv->get_regmap)
4429 if (codec_drv->get_regmap) 4443 codec->component.regmap = codec_drv->get_regmap(dev);
4430 regmap = codec_drv->get_regmap(dev);
4431 else
4432 regmap = dev_get_regmap(dev, NULL);
4433
4434 if (regmap) {
4435 ret = snd_soc_component_init_io(&codec->component,
4436 regmap);
4437 if (ret) {
4438 dev_err(codec->dev,
4439 "Failed to set cache I/O:%d\n",
4440 ret);
4441 goto err_cleanup;
4442 }
4443 }
4444 }
4445 4444
4446 for (i = 0; i < num_dai; i++) { 4445 for (i = 0; i < num_dai; i++) {
4447 fixup_codec_formats(&dai_drv[i].playback); 4446 fixup_codec_formats(&dai_drv[i].playback);
diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
index 7767fbd73eb7..9b3939049cef 100644
--- a/sound/soc/soc-io.c
+++ b/sound/soc/soc-io.c
@@ -271,31 +271,3 @@ int snd_soc_platform_write(struct snd_soc_platform *platform,
271 return snd_soc_component_write(&platform->component, reg, val); 271 return snd_soc_component_write(&platform->component, reg, val);
272} 272}
273EXPORT_SYMBOL_GPL(snd_soc_platform_write); 273EXPORT_SYMBOL_GPL(snd_soc_platform_write);
274
275/**
276 * snd_soc_component_init_io() - Initialize regmap IO
277 *
278 * @component: component to initialize
279 * @regmap: regmap instance to use for IO operations
280 *
281 * Return: 0 on success, a negative error code otherwise
282 */
283int snd_soc_component_init_io(struct snd_soc_component *component,
284 struct regmap *regmap)
285{
286 int ret;
287
288 if (!regmap)
289 return -EINVAL;
290
291 ret = regmap_get_val_bytes(regmap);
292 /* Errors are legitimate for non-integer byte
293 * multiples */
294 if (ret > 0)
295 component->val_bytes = ret;
296
297 component->regmap = regmap;
298
299 return 0;
300}
301EXPORT_SYMBOL_GPL(snd_soc_component_init_io);