Skip to content

Commit

Permalink
ASoC: Automatically initialize regmap for all components
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Lars-Peter Clausen authored and Mark Brown committed Aug 19, 2014
1 parent 14621c7 commit 886f569
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 49 deletions.
3 changes: 0 additions & 3 deletions include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1289,9 +1289,6 @@ void snd_soc_component_async_complete(struct snd_soc_component *component);
int snd_soc_component_test_bits(struct snd_soc_component *component,
unsigned int reg, unsigned int mask, unsigned int value);

int snd_soc_component_init_io(struct snd_soc_component *component,
struct regmap *regmap);

/* device driver data */

static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
Expand Down
35 changes: 17 additions & 18 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -4032,8 +4032,23 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
return 0;
}

static void snd_soc_component_init_regmap(struct snd_soc_component *component)
{
if (!component->regmap)
component->regmap = dev_get_regmap(component->dev, NULL);
if (component->regmap) {
int val_bytes = regmap_get_val_bytes(component->regmap);
/* Errors are legitimate for non-integer byte multiples */
if (val_bytes > 0)
component->val_bytes = val_bytes;
}
}

static void snd_soc_component_add_unlocked(struct snd_soc_component *component)
{
if (!component->write && !component->read)
snd_soc_component_init_regmap(component);

list_add(&component->list, &component_list);
}

Expand Down Expand Up @@ -4371,7 +4386,6 @@ int snd_soc_register_codec(struct device *dev,
{
struct snd_soc_codec *codec;
struct snd_soc_dai *dai;
struct regmap *regmap;
int ret, i;

dev_dbg(dev, "codec register %s\n", dev_name(dev));
Expand Down Expand Up @@ -4425,23 +4439,8 @@ int snd_soc_register_codec(struct device *dev,
codec->component.debugfs_prefix = "codec";
#endif

if (!codec->component.write) {
if (codec_drv->get_regmap)
regmap = codec_drv->get_regmap(dev);
else
regmap = dev_get_regmap(dev, NULL);

if (regmap) {
ret = snd_soc_component_init_io(&codec->component,
regmap);
if (ret) {
dev_err(codec->dev,
"Failed to set cache I/O:%d\n",
ret);
goto err_cleanup;
}
}
}
if (codec_drv->get_regmap)
codec->component.regmap = codec_drv->get_regmap(dev);

for (i = 0; i < num_dai; i++) {
fixup_codec_formats(&dai_drv[i].playback);
Expand Down
28 changes: 0 additions & 28 deletions sound/soc/soc-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,31 +271,3 @@ int snd_soc_platform_write(struct snd_soc_platform *platform,
return snd_soc_component_write(&platform->component, reg, val);
}
EXPORT_SYMBOL_GPL(snd_soc_platform_write);

/**
* snd_soc_component_init_io() - Initialize regmap IO
*
* @component: component to initialize
* @regmap: regmap instance to use for IO operations
*
* Return: 0 on success, a negative error code otherwise
*/
int snd_soc_component_init_io(struct snd_soc_component *component,
struct regmap *regmap)
{
int ret;

if (!regmap)
return -EINVAL;

ret = regmap_get_val_bytes(regmap);
/* Errors are legitimate for non-integer byte
* multiples */
if (ret > 0)
component->val_bytes = ret;

component->regmap = regmap;

return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_component_init_io);

0 comments on commit 886f569

Please sign in to comment.