Commit 13919056 authored by Mark Brown's avatar Mark Brown

Merge series "ASoC: soc-component: collect component functions" from Kuninori...

Merge series "ASoC: soc-component: collect component functions" from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>:

Hi Mark

We have soc-component.c now, but still many component related
functions are implemented many place.
This patch-set collect these into soc-component.c.

v1 -> v2
	- remove soc-compress.c exchange
	  (But I have plan to repost it)
	- fixup loop break issue on some functions
	- direct return on some functions

Link: https://lore.kernel.org/r/87a71nzhy2.wl-kuninori.morimoto.gx@renesas.com

Kuninori Morimoto (12):
  ASoC: soc-component: add soc_component_pin() and share code
  ASoC: soc-component: move snd_soc_component_xxx_regmap() to soc-component
  ASoC: soc-component: move snd_soc_component_initialize() to soc-component.c
  ASoC: soc-component: add soc_component_err()
  ASoC: soc-component: add snd_soc_pcm_component_prepare()
  ASoC: soc-component: add snd_soc_pcm_component_hw_params()
  ASoC: soc-component: add snd_soc_pcm_component_hw_free()
  ASoC: soc-component: add snd_soc_pcm_component_trigger()
  ASoC: soc-component: add snd_soc_component_init()
  ASoC: soc-component: merge soc-io.c into soc-component.c
  ASoC: soc-component: merge soc_pcm_trigger_start/stop()
  ASoC: soc-component: tidyup Copyright

 include/sound/soc-component.h |  29 +-
 sound/soc/Makefile            |   2 +-
 sound/soc/soc-component.c     | 666 ++++++++++++++++++++++++----------
 sound/soc/soc-core.c          | 102 +-----
 sound/soc/soc-io.c            | 202 -----------
 sound/soc/soc-pcm.c           | 114 ++----
 6 files changed, 531 insertions(+), 584 deletions(-)
 delete mode 100644 sound/soc/soc-io.c

--
2.17.1
parents b7a742cf 45108214
......@@ -2,7 +2,8 @@
*
* soc-component.h
*
* Copyright (c) 2019 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
* Copyright (C) 2019 Renesas Electronics Corp.
* Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
*/
#ifndef __SOC_COMPONENT_H
#define __SOC_COMPONENT_H
......@@ -324,6 +325,13 @@ static inline int snd_soc_component_cache_sync(
return regcache_sync(component->regmap);
}
int snd_soc_component_initialize(struct snd_soc_component *component,
const struct snd_soc_component_driver *driver,
struct device *dev, const char *name);
void snd_soc_component_set_aux(struct snd_soc_component *component,
struct snd_soc_aux_dev *aux);
int snd_soc_component_init(struct snd_soc_component *component);
/* component IO */
int snd_soc_component_read(struct snd_soc_component *component,
unsigned int reg, unsigned int *val);
......@@ -359,6 +367,7 @@ int snd_soc_component_stream_event(struct snd_soc_component *component,
int snd_soc_component_set_bias_level(struct snd_soc_component *component,
enum snd_soc_bias_level level);
void snd_soc_component_setup_regmap(struct snd_soc_component *component);
#ifdef CONFIG_REGMAP
void snd_soc_component_init_regmap(struct snd_soc_component *component,
struct regmap *regmap);
......@@ -421,16 +430,6 @@ int snd_soc_component_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int snd_soc_component_close(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int snd_soc_component_prepare(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int snd_soc_component_hw_params(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params);
int snd_soc_component_hw_free(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int snd_soc_component_trigger(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
int cmd);
void snd_soc_component_suspend(struct snd_soc_component *component);
void snd_soc_component_resume(struct snd_soc_component *component);
int snd_soc_component_is_suspended(struct snd_soc_component *component);
......@@ -455,5 +454,13 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
struct vm_area_struct *vma);
int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_component **last);
void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
struct snd_soc_component *last);
int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
int cmd);
#endif /* __SOC_COMPONENT_H */
# SPDX-License-Identifier: GPL-2.0
snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-utils.o soc-dai.o soc-component.o
snd-soc-core-objs += soc-pcm.o soc-io.o soc-devres.o soc-ops.o soc-link.o soc-card.o
snd-soc-core-objs += soc-pcm.o soc-devres.o soc-ops.o soc-link.o soc-card.o
snd-soc-core-$(CONFIG_SND_SOC_COMPRESS) += soc-compress.o
ifneq ($(CONFIG_SND_SOC_TOPOLOGY),)
......
This diff is collapsed.
......@@ -1208,15 +1208,14 @@ static int soc_probe_component(struct snd_soc_card *card,
component->name);
probed = 1;
/* machine specific init */
if (component->init) {
ret = component->init(component);
if (ret < 0) {
dev_err(component->dev,
"Failed to do machine specific init %d\n", ret);
/*
* machine specific init
* see
* snd_soc_component_set_aux()
*/
ret = snd_soc_component_init(component);
if (ret < 0)
goto err_probe;
}
}
ret = snd_soc_add_component_controls(component,
component->driver->controls,
......@@ -1330,7 +1329,8 @@ static void soc_unbind_aux_dev(struct snd_soc_card *card)
struct snd_soc_component *component, *_component;
for_each_card_auxs_safe(card, component, _component) {
component->init = NULL;
/* for snd_soc_component_init() */
snd_soc_component_set_aux(component, NULL);
list_del(&component->card_aux_list);
}
}
......@@ -1347,7 +1347,8 @@ static int soc_bind_aux_dev(struct snd_soc_card *card)
if (!component)
return -EPROBE_DEFER;
component->init = aux->init;
/* for snd_soc_component_init() */
snd_soc_component_set_aux(component, aux);
/* see for_each_card_auxs */
list_add(&component->card_aux_list, &card->aux_comp_list);
}
......@@ -2378,76 +2379,6 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
return ret;
}
static int snd_soc_component_initialize(struct snd_soc_component *component,
const struct snd_soc_component_driver *driver, struct device *dev)
{
INIT_LIST_HEAD(&component->dai_list);
INIT_LIST_HEAD(&component->dobj_list);
INIT_LIST_HEAD(&component->card_list);
mutex_init(&component->io_mutex);
component->name = fmt_single_name(dev, &component->id);
if (!component->name) {
dev_err(dev, "ASoC: Failed to allocate name\n");
return -ENOMEM;
}
component->dev = dev;
component->driver = driver;
return 0;
}
static void snd_soc_component_setup_regmap(struct snd_soc_component *component)
{
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;
}
#ifdef CONFIG_REGMAP
/**
* snd_soc_component_init_regmap() - Initialize regmap instance for the
* component
* @component: The component for which to initialize the regmap instance
* @regmap: The regmap instance that should be used by the component
*
* This function allows deferred assignment of the regmap instance that is
* associated with the component. Only use this if the regmap instance is not
* yet ready when the component is registered. The function must also be called
* before the first IO attempt of the component.
*/
void snd_soc_component_init_regmap(struct snd_soc_component *component,
struct regmap *regmap)
{
component->regmap = regmap;
snd_soc_component_setup_regmap(component);
}
EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
/**
* snd_soc_component_exit_regmap() - De-initialize regmap instance for the
* component
* @component: The component for which to de-initialize the regmap instance
*
* Calls regmap_exit() on the regmap instance associated to the component and
* removes the regmap instance from the component.
*
* This function should only be used if snd_soc_component_init_regmap() was used
* to initialize the regmap instance.
*/
void snd_soc_component_exit_regmap(struct snd_soc_component *component)
{
regmap_exit(component->regmap);
component->regmap = NULL;
}
EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
#endif
#define ENDIANNESS_MAP(name) \
(SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE)
static u64 endianness_format_map[] = {
......@@ -2510,12 +2441,19 @@ int snd_soc_add_component(struct device *dev,
struct snd_soc_dai_driver *dai_drv,
int num_dai)
{
const char *name = fmt_single_name(dev, &component->id);
int ret;
int i;
if (!name) {
dev_err(dev, "ASoC: Failed to allocate name\n");
return -ENOMEM;
}
mutex_lock(&client_mutex);
ret = snd_soc_component_initialize(component, component_driver, dev);
ret = snd_soc_component_initialize(component, component_driver,
dev, name);
if (ret)
goto err_free;
......
// SPDX-License-Identifier: GPL-2.0+
//
// soc-io.c -- ASoC register I/O helpers
//
// Copyright 2009-2011 Wolfson Microelectronics PLC.
//
// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
#include <linux/i2c.h>
#include <linux/spi/spi.h>
#include <linux/regmap.h>
#include <linux/export.h>
#include <sound/soc.h>
/**
* snd_soc_component_read() - Read register value
* @component: Component to read from
* @reg: Register to read
* @val: Pointer to where the read value is stored
*
* Return: 0 on success, a negative error code otherwise.
*/
int snd_soc_component_read(struct snd_soc_component *component,
unsigned int reg, unsigned int *val)
{
int ret;
if (component->regmap)
ret = regmap_read(component->regmap, reg, val);
else if (component->driver->read) {
*val = component->driver->read(component, reg);
ret = 0;
}
else
ret = -EIO;
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_component_read);
unsigned int snd_soc_component_read32(struct snd_soc_component *component,
unsigned int reg)
{
unsigned int val;
int ret;
ret = snd_soc_component_read(component, reg, &val);
if (ret < 0)
return -1;
return val;
}
EXPORT_SYMBOL_GPL(snd_soc_component_read32);
/**
* snd_soc_component_write() - Write register value
* @component: Component to write to
* @reg: Register to write
* @val: Value to write to the register
*
* Return: 0 on success, a negative error code otherwise.
*/
int snd_soc_component_write(struct snd_soc_component *component,
unsigned int reg, unsigned int val)
{
if (component->regmap)
return regmap_write(component->regmap, reg, val);
else if (component->driver->write)
return component->driver->write(component, reg, val);
else
return -EIO;
}
EXPORT_SYMBOL_GPL(snd_soc_component_write);
static int snd_soc_component_update_bits_legacy(
struct snd_soc_component *component, unsigned int reg,
unsigned int mask, unsigned int val, bool *change)
{
unsigned int old, new;
int ret;
mutex_lock(&component->io_mutex);
ret = snd_soc_component_read(component, reg, &old);
if (ret < 0)
goto out_unlock;
new = (old & ~mask) | (val & mask);
*change = old != new;
if (*change)
ret = snd_soc_component_write(component, reg, new);
out_unlock:
mutex_unlock(&component->io_mutex);
return ret;
}
/**
* snd_soc_component_update_bits() - Perform read/modify/write cycle
* @component: Component to update
* @reg: Register to update
* @mask: Mask that specifies which bits to update
* @val: New value for the bits specified by mask
*
* Return: 1 if the operation was successful and the value of the register
* changed, 0 if the operation was successful, but the value did not change.
* Returns a negative error code otherwise.
*/
int snd_soc_component_update_bits(struct snd_soc_component *component,
unsigned int reg, unsigned int mask, unsigned int val)
{
bool change;
int ret;
if (component->regmap)
ret = regmap_update_bits_check(component->regmap, reg, mask,
val, &change);
else
ret = snd_soc_component_update_bits_legacy(component, reg,
mask, val, &change);
if (ret < 0)
return ret;
return change;
}
EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
/**
* snd_soc_component_update_bits_async() - Perform asynchronous
* read/modify/write cycle
* @component: Component to update
* @reg: Register to update
* @mask: Mask that specifies which bits to update
* @val: New value for the bits specified by mask
*
* This function is similar to snd_soc_component_update_bits(), but the update
* operation is scheduled asynchronously. This means it may not be completed
* when the function returns. To make sure that all scheduled updates have been
* completed snd_soc_component_async_complete() must be called.
*
* Return: 1 if the operation was successful and the value of the register
* changed, 0 if the operation was successful, but the value did not change.
* Returns a negative error code otherwise.
*/
int snd_soc_component_update_bits_async(struct snd_soc_component *component,
unsigned int reg, unsigned int mask, unsigned int val)
{
bool change;
int ret;
if (component->regmap)
ret = regmap_update_bits_check_async(component->regmap, reg,
mask, val, &change);
else
ret = snd_soc_component_update_bits_legacy(component, reg,
mask, val, &change);
if (ret < 0)
return ret;
return change;
}
EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
/**
* snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
* @component: Component for which to wait
*
* This function blocks until all asynchronous I/O which has previously been
* scheduled using snd_soc_component_update_bits_async() has completed.
*/
void snd_soc_component_async_complete(struct snd_soc_component *component)
{
if (component->regmap)
regmap_async_complete(component->regmap);
}
EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
/**
* snd_soc_component_test_bits - Test register for change
* @component: component
* @reg: Register to test
* @mask: Mask that specifies which bits to test
* @value: Value to test against
*
* Tests a register with a new value and checks if the new value is
* different from the old value.
*
* Return: 1 for change, otherwise 0.
*/
int snd_soc_component_test_bits(struct snd_soc_component *component,
unsigned int reg, unsigned int mask, unsigned int value)
{
unsigned int old, new;
int ret;
ret = snd_soc_component_read(component, reg, &old);
if (ret < 0)
return ret;
new = (old & ~mask) | value;
return old != new;
}
EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);
......@@ -850,7 +850,6 @@ static void codec2codec_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
static int soc_pcm_prepare(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_component *component;
struct snd_soc_dai *dai;
int i, ret = 0;
......@@ -860,14 +859,9 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
if (ret < 0)
goto out;
for_each_rtd_components(rtd, i, component) {
ret = snd_soc_component_prepare(component, substream);
if (ret < 0) {
dev_err(component->dev,
"ASoC: platform prepare error: %d\n", ret);
ret = snd_soc_pcm_component_prepare(substream);
if (ret < 0)
goto out;
}
}
ret = snd_soc_pcm_dai_prepare(substream);
if (ret < 0) {
......@@ -904,25 +898,6 @@ static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params,
interval->max = channels;
}
static int soc_pcm_components_hw_free(struct snd_pcm_substream *substream,
struct snd_soc_component *last)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_component *component;
int i, r, ret = 0;
for_each_rtd_components(rtd, i, component) {
if (component == last)
break;
r = snd_soc_component_hw_free(component, substream);
if (r < 0)
ret = r; /* use last ret */
}
return ret;
}
/*
* Called by ALSA when the hardware params are set by application. This
* function can also be called multiple times and can allocate buffers
......@@ -1015,23 +990,16 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
snd_soc_dapm_update_dai(substream, params, cpu_dai);
}
for_each_rtd_components(rtd, i, component) {
ret = snd_soc_component_hw_params(component, substream, params);
if (ret < 0) {
dev_err(component->dev,
"ASoC: %s hw params failed: %d\n",
component->name, ret);
ret = snd_soc_pcm_component_hw_params(substream, params, &component);
if (ret < 0)
goto component_err;
}
}
component = NULL;
out:
mutex_unlock(&rtd->card->pcm_mutex);
return ret;
component_err:
soc_pcm_components_hw_free(substream, component);
snd_soc_pcm_component_hw_free(substream, component);
i = rtd->num_cpus;
......@@ -1090,7 +1058,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
snd_soc_link_hw_free(substream);
/* free any component resources */
soc_pcm_components_hw_free(substream, NULL);
snd_soc_pcm_component_hw_free(substream, NULL);
/* now free hw params for the DAIs */
for_each_rtd_dais(rtd, i, dai) {
......@@ -1104,65 +1072,37 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
return 0;
}
static int soc_pcm_trigger_start(struct snd_pcm_substream *substream, int cmd)
static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_component *component;
int i, ret;
int ret = -EINVAL;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
ret = snd_soc_link_trigger(substream, cmd);
if (ret < 0)
return ret;
break;
for_each_rtd_components(rtd, i, component) {
ret = snd_soc_component_trigger(component, substream, cmd);
ret = snd_soc_pcm_component_trigger(substream, cmd);
if (ret < 0)
return ret;
}
return snd_soc_pcm_dai_trigger(substream, cmd);
}
static int soc_pcm_trigger_stop(struct snd_pcm_substream *substream, int cmd)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_component *component;
int i, ret;
break;
ret = snd_soc_pcm_dai_trigger(substream, cmd);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
ret = snd_soc_pcm_dai_trigger(substream, cmd);
if (ret < 0)
return ret;
break;
for_each_rtd_components(rtd, i, component) {
ret = snd_soc_component_trigger(component, substream, cmd);
ret = snd_soc_pcm_component_trigger(substream, cmd);
if (ret < 0)
return ret;
}
break;
ret = snd_soc_link_trigger(substream, cmd);
if (ret < 0)
return ret;
return 0;
}
static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
{
int ret;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
ret = soc_pcm_trigger_start(substream, cmd);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
ret = soc_pcm_trigger_stop(substream, cmd);
break;
default:
return -EINVAL;
}
return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment