[alsa-devel] [PATCH 0/4] ASoC: add Component level set_xxx
Hi Mark, Lars-Peter
These add Component level set_xxx feature which are supported on Codec side.
After this, we can replace - snd_soc_codec_set_xxx(...); + snd_soc_component_set_xxx(...);
Kuninori Morimoto (4): ASoC: add Component level set_sysclk ASoC: add Component level set_pll ASoC: add Component level set_jack ASoC: add Component level set_bias_level
include/sound/soc.h | 26 ++++++++++++ sound/soc/soc-core.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++----- sound/soc/soc-jack.c | 22 ++++++++++ 3 files changed, 151 insertions(+), 10 deletions(-)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
In current ALSA SoC, Codec only has set_sysclk feature. Codec will be merged into Component in next generation ALSA SoC, thus current Codec specific feature need to be merged into it. This is glue patch for it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc.h | 11 +++++++++++ sound/soc/soc-core.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index f8fa9d0..8fb5c66 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -792,6 +792,10 @@ struct snd_soc_component_driver { int (*pcm_new)(struct snd_soc_pcm_runtime *); void (*pcm_free)(struct snd_pcm *);
+ /* component wide operations */ + int (*set_sysclk)(struct snd_soc_component *component, + int clk_id, int source, unsigned int freq, int dir); + /* DT */ int (*of_xlate_dai_name)(struct snd_soc_component *component, struct of_phandle_args *args, @@ -871,6 +875,9 @@ struct snd_soc_component { int (*suspend)(struct snd_soc_component *); int (*resume)(struct snd_soc_component *);
+ int (*set_sysclk)(struct snd_soc_component *component, + int clk_id, int source, unsigned int freq, int dir); + /* machine specific init */ int (*init)(struct snd_soc_component *component);
@@ -1417,6 +1424,10 @@ int snd_soc_component_update_bits_async(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);
+/* component wide operations */ +int snd_soc_component_set_sysclk(struct snd_soc_component *component, + int clk_id, int source, unsigned int freq, int dir); + #ifdef CONFIG_REGMAP
void snd_soc_component_init_regmap(struct snd_soc_component *component, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ddf5076..3891ba4 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2589,11 +2589,9 @@ int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, { if (dai->driver && dai->driver->ops->set_sysclk) return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); - else if (dai->codec && dai->codec->driver->set_sysclk) - return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, - freq, dir); - else - return -ENOTSUPP; + + return snd_soc_component_set_sysclk(dai->component, clk_id, 0, + freq, dir); } EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
@@ -2619,6 +2617,32 @@ int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
/** + * snd_soc_component_set_sysclk - configure COMPONENT system or master clock. + * @component: COMPONENT + * @clk_id: DAI specific clock ID + * @source: Source for the clock + * @freq: new clock frequency in Hz + * @dir: new clock direction - input/output. + * + * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. + */ +int snd_soc_component_set_sysclk(struct snd_soc_component *component, int clk_id, + int source, unsigned int freq, int dir) +{ + /* will be removed */ + if (component->set_sysclk) + return component->set_sysclk(component, clk_id, source, + freq, dir); + + if (component->driver->set_sysclk) + return component->driver->set_sysclk(component, clk_id, source, + freq, dir); + + return -ENOTSUPP; +} +EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk); + +/** * snd_soc_dai_set_clkdiv - configure DAI clock dividers. * @dai: DAI * @div_id: DAI specific clock divider ID @@ -3173,6 +3197,7 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, component->remove = component->driver->remove; component->suspend = component->driver->suspend; component->resume = component->driver->resume; + component->set_sysclk = component->driver->set_sysclk;
dapm = &component->dapm; dapm->dev = dev; @@ -3475,6 +3500,14 @@ static int snd_soc_codec_drv_read(struct snd_soc_component *component, return 0; }
+static int snd_soc_codec_set_sysclk_(struct snd_soc_component *component, + int clk_id, int source, unsigned int freq, int dir) +{ + struct snd_soc_codec *codec = snd_soc_component_to_codec(component); + + return snd_soc_codec_set_sysclk(codec, clk_id, source, freq, dir); +} + static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level) { @@ -3526,6 +3559,8 @@ int snd_soc_register_codec(struct device *dev, codec->component.write = snd_soc_codec_drv_write; if (codec_drv->read) codec->component.read = snd_soc_codec_drv_read; + if (codec_drv->set_sysclk) + codec->component.set_sysclk = snd_soc_codec_set_sysclk_; codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
dapm = snd_soc_codec_get_dapm(codec);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
In current ALSA SoC, Codec only has set_pll feature. Codec will be merged into Component in next generation ALSA SoC, thus current Codec specific feature need to be merged into it. This is glue patch for it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc.h | 7 +++++++ sound/soc/soc-core.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 8fb5c66..9333f65 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -795,6 +795,8 @@ struct snd_soc_component_driver { /* component wide operations */ int (*set_sysclk)(struct snd_soc_component *component, int clk_id, int source, unsigned int freq, int dir); + int (*set_pll)(struct snd_soc_component *component, int pll_id, + int source, unsigned int freq_in, unsigned int freq_out);
/* DT */ int (*of_xlate_dai_name)(struct snd_soc_component *component, @@ -877,6 +879,8 @@ struct snd_soc_component {
int (*set_sysclk)(struct snd_soc_component *component, int clk_id, int source, unsigned int freq, int dir); + int (*set_pll)(struct snd_soc_component *component, int pll_id, + int source, unsigned int freq_in, unsigned int freq_out);
/* machine specific init */ int (*init)(struct snd_soc_component *component); @@ -1427,6 +1431,9 @@ int snd_soc_component_test_bits(struct snd_soc_component *component, /* component wide operations */ int snd_soc_component_set_sysclk(struct snd_soc_component *component, int clk_id, int source, unsigned int freq, int dir); +int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, + int source, unsigned int freq_in, + unsigned int freq_out);
#ifdef CONFIG_REGMAP
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 3891ba4..ece380a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2678,11 +2678,9 @@ int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, if (dai->driver && dai->driver->ops->set_pll) return dai->driver->ops->set_pll(dai, pll_id, source, freq_in, freq_out); - else if (dai->codec && dai->codec->driver->set_pll) - return dai->codec->driver->set_pll(dai->codec, pll_id, source, - freq_in, freq_out); - else - return -EINVAL; + + return snd_soc_component_set_pll(dai->component, pll_id, source, + freq_in, freq_out); } EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
@@ -2707,6 +2705,33 @@ int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, } EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
+/* + * snd_soc_component_set_pll - configure component PLL. + * @component: COMPONENT + * @pll_id: DAI specific PLL ID + * @source: DAI specific source for the PLL + * @freq_in: PLL input clock frequency in Hz + * @freq_out: requested PLL output clock frequency in Hz + * + * Configures and enables PLL to generate output clock based on input clock. + */ +int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, + int source, unsigned int freq_in, + unsigned int freq_out) +{ + /* will be removed */ + if (component->set_pll) + return component->set_pll(component, pll_id, source, + freq_in, freq_out); + + if (component->driver->set_pll) + return component->driver->set_pll(component, pll_id, source, + freq_in, freq_out); + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(snd_soc_component_set_pll); + /** * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio. * @dai: DAI @@ -3198,6 +3223,7 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, component->suspend = component->driver->suspend; component->resume = component->driver->resume; component->set_sysclk = component->driver->set_sysclk; + component->set_pll = component->driver->set_pll;
dapm = &component->dapm; dapm->dev = dev; @@ -3508,6 +3534,15 @@ static int snd_soc_codec_set_sysclk_(struct snd_soc_component *component, return snd_soc_codec_set_sysclk(codec, clk_id, source, freq, dir); }
+static int snd_soc_codec_set_pll_(struct snd_soc_component *component, + int pll_id, int source, unsigned int freq_in, + unsigned int freq_out) +{ + struct snd_soc_codec *codec = snd_soc_component_to_codec(component); + + return snd_soc_codec_set_pll(codec, pll_id, source, freq_in, freq_out); +} + static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level) { @@ -3561,6 +3596,8 @@ int snd_soc_register_codec(struct device *dev, codec->component.read = snd_soc_codec_drv_read; if (codec_drv->set_sysclk) codec->component.set_sysclk = snd_soc_codec_set_sysclk_; + if (codec_drv->set_pll) + codec->component.set_pll = snd_soc_codec_set_pll_; codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
dapm = snd_soc_codec_get_dapm(codec);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
In current ALSA SoC, Codec only has set_jack feature. Codec will be merged into Component in next generation ALSA SoC, thus current Codec specific feature need to be merged into it. This is glue patch for it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc.h | 4 ++++ sound/soc/soc-core.c | 11 +++++++++++ sound/soc/soc-jack.c | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 9333f65..e817830 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -797,6 +797,8 @@ struct snd_soc_component_driver { int clk_id, int source, unsigned int freq, int dir); int (*set_pll)(struct snd_soc_component *component, int pll_id, int source, unsigned int freq_in, unsigned int freq_out); + int (*set_jack)(struct snd_soc_component *component, + struct snd_soc_jack *jack, void *data);
/* DT */ int (*of_xlate_dai_name)(struct snd_soc_component *component, @@ -881,6 +883,8 @@ struct snd_soc_component { int clk_id, int source, unsigned int freq, int dir); int (*set_pll)(struct snd_soc_component *component, int pll_id, int source, unsigned int freq_in, unsigned int freq_out); + int (*set_jack)(struct snd_soc_component *component, + struct snd_soc_jack *jack, void *data);
/* machine specific init */ int (*init)(struct snd_soc_component *component); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ece380a..c2ef155 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3224,6 +3224,7 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, component->resume = component->driver->resume; component->set_sysclk = component->driver->set_sysclk; component->set_pll = component->driver->set_pll; + component->set_jack = component->driver->set_jack;
dapm = &component->dapm; dapm->dev = dev; @@ -3543,6 +3544,14 @@ static int snd_soc_codec_set_pll_(struct snd_soc_component *component, return snd_soc_codec_set_pll(codec, pll_id, source, freq_in, freq_out); }
+static int snd_soc_codec_set_jack_(struct snd_soc_component *component, + struct snd_soc_jack *jack, void *data) +{ + struct snd_soc_codec *codec = snd_soc_component_to_codec(component); + + return snd_soc_codec_set_jack(codec, jack, data); +} + static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level) { @@ -3598,6 +3607,8 @@ int snd_soc_register_codec(struct device *dev, codec->component.set_sysclk = snd_soc_codec_set_sysclk_; if (codec_drv->set_pll) codec->component.set_pll = snd_soc_codec_set_pll_; + if (codec_drv->set_jack) + codec->component.set_jack = snd_soc_codec_set_jack_; codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
dapm = snd_soc_codec_get_dapm(codec); diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index 42ca9f1..84835a4 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -41,6 +41,28 @@ int snd_soc_codec_set_jack(struct snd_soc_codec *codec, EXPORT_SYMBOL_GPL(snd_soc_codec_set_jack);
/** + * snd_soc_component_set_jack - configure component jack. + * @component: COMPONENTs + * @jack: structure to use for the jack + * @data: can be used if codec driver need extra data for configuring jack + * + * Configures and enables jack detection function. + */ +int snd_soc_component_set_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack, void *data) +{ + /* will be removed */ + if (component->set_jack) + return component->set_jack(component, jack, data); + + if (component->driver->set_jack) + return component->driver->set_jack(component, jack, data); + + return -ENOTSUPP; +} +EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); + +/** * snd_soc_card_jack_new - Create a new jack * @card: ASoC card * @id: an identifying string for this jack
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
In current ALSA SoC, Codec only has set_bias_level feature. Codec will be merged into Component in next generation ALSA SoC, thus current Codec specific feature need to be merged into it. This is glue patch for it.
Codec side bias related code has .idle_bias_off / .suspend_bias_off too. These are used on dapm_idle_bias_off(), and it will return true if .idle_bias_off was true, then, .suspend_bias_off is not used. Now, Component site is using .idle_bias_off = true now. This patch doesn't convert .idle_bias_off / .suspend_bias_off for Component side, let's use current .idle_bias_off, as-is.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc.h | 4 ++++ sound/soc/soc-core.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
diff --git a/include/sound/soc.h b/include/sound/soc.h index e817830..bb62a29 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -799,6 +799,8 @@ struct snd_soc_component_driver { int source, unsigned int freq_in, unsigned int freq_out); int (*set_jack)(struct snd_soc_component *component, struct snd_soc_jack *jack, void *data); + int (*set_bias_level)(struct snd_soc_component *component, + enum snd_soc_bias_level level);
/* DT */ int (*of_xlate_dai_name)(struct snd_soc_component *component, @@ -885,6 +887,8 @@ struct snd_soc_component { int source, unsigned int freq_in, unsigned int freq_out); int (*set_jack)(struct snd_soc_component *component, struct snd_soc_jack *jack, void *data); + int (*set_bias_level)(struct snd_soc_component *component, + enum snd_soc_bias_level level);
/* machine specific init */ int (*init)(struct snd_soc_component *component); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c2ef155..65999df 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3205,6 +3205,14 @@ static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm, return component->driver->stream_event(component, event); }
+static int snd_soc_component_set_bias_level(struct snd_soc_dapm_context *dapm, + enum snd_soc_bias_level level) +{ + struct snd_soc_component *component = dapm->component; + + return component->driver->set_bias_level(component, level); +} + static int snd_soc_component_initialize(struct snd_soc_component *component, const struct snd_soc_component_driver *driver, struct device *dev) { @@ -3235,6 +3243,8 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, dapm->seq_notifier = snd_soc_component_seq_notifier; if (driver->stream_event) dapm->stream_event = snd_soc_component_stream_event; + if (driver->set_bias_level) + dapm->set_bias_level = snd_soc_component_set_bias_level;
component->controls = driver->controls; component->num_controls = driver->num_controls;
Hi
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
In current ALSA SoC, Codec only has set_bias_level feature. Codec will be merged into Component in next generation ALSA SoC, thus current Codec specific feature need to be merged into it. This is glue patch for it.
Codec side bias related code has .idle_bias_off / .suspend_bias_off too. These are used on dapm_idle_bias_off(), and it will return true if .idle_bias_off was true, then, .suspend_bias_off is not used. Now, Component site is using .idle_bias_off = true now. This patch doesn't convert .idle_bias_off / .suspend_bias_off for Component side, let's use current .idle_bias_off, as-is.
Oops... new component want to have .idle_bias_off / .suspend_bias_off ?
Best regards --- Kuninori Morimoto
Hi Mark
On Thu, Aug 24, 2017 at 05:31:36AM +0000, Kuninori Morimoto wrote:
Oops... new component want to have .idle_bias_off / .suspend_bias_off ?
Yes, they're different and both useful.
OK, my concern is these "default". Non-codec case, .idle_bias_off = true is default, In codec case, .idle_bias_off = codec_drv->idle_bias_off (= 0) is default. we can add .idle_bias_off = true on all non-codec driver, but it needs big-patch. but is it OK ?
Best regards --- Kuninori Morimoto
Hi Mark
Oops... new component want to have .idle_bias_off / .suspend_bias_off ?
Yes, they're different and both useful.
OK, my concern is these "default". Non-codec case, .idle_bias_off = true is default, In codec case, .idle_bias_off = codec_drv->idle_bias_off (= 0) is default. we can add .idle_bias_off = true on all non-codec driver, but it needs big-patch. but is it OK ?
In the future, it will be "Component" base framework, so, I want to think "Component" base. Now, codec and internal component are using .idle_bias_off for dapm and its default is...
On Component dapm->idle_bias_off = true; On Codec dapm->idle_bias_off = codec_drv->idle_bias_off; dapm->suspend_bias_off = codec_drv->suspend_bias_off;
Thus, default (= no settings) will be
Component idle_bias_off : true; Codec idle_bias_off : false;
Can I add idel_bias_on instead of idel_bias_off ? ~~ ~~~ It can keep compatibility, and reduce cost. only codec driver needs change and anyway it needs change (= when it replace codec to component).
Component driver dapm->idle_bias_off = !driver->idle_bias_on;
Component user no change Codec user which has .idle_bias_off = true - .idle_bias_off = true, Codec user which doesn't has .idle_bias_off = true + .idle_bias_on = true,
Best regards --- Kuninori Morimoto
participants (2)
-
Kuninori Morimoto
-
Mark Brown