ASoC: dpcm: Add Dynamic PCM core operations.
PATCH 1/5 ASoC: dpcm: Add Dynamic PCM core operations.
The Dynamic PCM core allows digital audio data to be dynamically routed between different ALSA PCMs and DAI links on SoC CPUs with on chip DSP devices. e.g. audio data could be played on pcm:0,0 and routed to any (or all) SoC DAI links.
Dynamic PCM introduces the concept of Front End (FE) PCMs and Back End (BE) PCMs. The FE PCMs are normal ALSA PCM devices except that they can dynamically route digital audio data to any supported BE PCM. A BE PCM has no ALSA device, but represents a DAI link and it's substream and audio HW parameters.
e.g. pcm:0,0 routing digital data to 2 external codecs.
FE pcm:0,0 ----> BE (McBSP.0) ----> CODEC 0
+--> BE (McPDM.0) ----> CODEC 1
e.g. pcm:0,0 and pcm:0,1 routing digital data to 1 external codec.
FE pcm:0,0 ---
+--> BE (McBSP.0) ----> CODEC
FE pcm:0,1 ---
The digital audio routing is controlled by the usual ALSA method of mixer kcontrols. Dynamic PCM uses a DAPM graph to work out the routing based upon the mixer settings and configures the BE PCMs based on routing and the FE HW params.
DPCM is designed so that most ASoC component drivers will need no modification at all. It's intended that existing CODEC, DAI and platform drivers can be used in DPCM based audio devices without any changes. However, there will be some cases where minor changes are required (e.g. for very tightly coupled HW) and there are helpers to support this too.
Somethimes the HW params of a FE and BE do not match or are incompatible, so in these cases the machine driver can reconfigure any hw_params and make any DSP perform sample rate / format conversion.
This patch adds the core DPCM code and contains :-
o The FE and BE PCM operations.
o FE and BE DAI link support.
o FE and BE PCM creation.
o BE support API.
o BE and FE link management.
--- include/sound/soc-dpcm.h | 132 +++++ include/sound/soc.h | 17 + sound/soc/soc-core.c | 5 + sound/soc/soc-pcm.c | 1246 ++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 1370 insertions(+), 30 deletions(-) create mode 100644 include/sound/soc-dpcm.h
include/sound/soc-dpcm.h new file +132 -0
@@ -0,0 +1,132 @@ +/* +* linux/sound/soc-dpcm.h -- ALSA SoC Dynamic PCM Support +* +* Author: Liam Girdwood <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __LINUX_SND_SOC_DPCM_H +#define __LINUX_SND_SOC_DPCM_H + +#include <linux/list.h> +#include <sound/pcm.h> + +struct snd_soc_pcm_runtime ; + +/* +* Types of runtime_update to perform. e.g. originated from FE PCM ops +* or audio route changes triggered by muxes/mixers. +*/ +enum snd_soc_dpcm_update { +SND_SOC_DPCM_UPDATE_NO =0 , +SND_SOC_DPCM_UPDATE_BE , +SND_SOC_DPCM_UPDATE_FE , +}; + +/* +* Dynamic PCM Frontend -> Backend link management states. +*/ +enum snd_soc_dpcm_link_state { +SND_SOC_DPCM_LINK_STATE_NEW =0 ,/* newly created link */ +SND_SOC_DPCM_LINK_STATE_FREE ,/* link to be dismantled */ +}; + +/* +* Dynamic PCM Frontend -> Backend link PCM states. +*/ +enum snd_soc_dpcm_state { +SND_SOC_DPCM_STATE_NEW =0 , +SND_SOC_DPCM_STATE_OPEN , +SND_SOC_DPCM_STATE_HW_PARAMS , +SND_SOC_DPCM_STATE_PREPARE , +SND_SOC_DPCM_STATE_START , +SND_SOC_DPCM_STATE_STOP , +SND_SOC_DPCM_STATE_PAUSED , +SND_SOC_DPCM_STATE_SUSPEND , +SND_SOC_DPCM_STATE_HW_FREE , +SND_SOC_DPCM_STATE_CLOSE , +}; + +/* +* Dynamic PCM trigger ordering. Triggering flexibility is required as some +* DSPs require triggering before/after their CPU platform and DAIs. +* +* i.e. some clients may want to manually order this call in their PCM +* trigger() whilst others will just use the regular core ordering. +*/ +enum snd_soc_dpcm_trigger { +SND_SOC_DPCM_TRIGGER_PRE =0 , +SND_SOC_DPCM_TRIGGER_POST , +}; + +/* +* Dynamic PCM link +* This links together a FE and BE DAI at runtime and stores the link +* state information and the hw_params configuration. +*/ +struct snd_soc_dpcm { +/* FE and BE DAIs*/ +struct snd_soc_pcm_runtime *be; +struct snd_soc_pcm_runtime *fe; + +/* link state */ +enum snd_soc_dpcm_link_state state; + +/* list of BE and FE for this DPCM link */ +struct list_head list_be; +struct list_head list_fe; + +/* hw params for this link - may be different for each link */ +struct snd_pcm_hw_params hw_params; +}; + +/* +* Dynamic PCM runtime data. +*/ +struct snd_soc_dpcm_runtime { +struct list_head be_clients; +struct list_head fe_clients; + +int users; +struct snd_pcm_runtime *runtime; +struct snd_pcm_hw_params hw_params; + +/* state and update */ +enum snd_soc_dpcm_update runtime_update; +enum snd_soc_dpcm_state state; +}; + +/* can this BE stop and free */ +int snd_soc_dpcm_can_be_free_stop (struct snd_soc_pcm_runtime *fe, +struct snd_soc_pcm_runtime *be,int stream); + +/* can this BE perform a hw_params() */ +int snd_soc_dpcm_can_be_params (struct snd_soc_pcm_runtime *fe, +struct snd_soc_pcm_runtime *be,int stream); + +/* is the current PCM operation for this FE ? */ +int snd_soc_dpcm_fe_can_update (struct snd_soc_pcm_runtime *fe,int stream); + +/* is the current PCM operation for this BE ? */ +int snd_soc_dpcm_be_can_update (struct snd_soc_pcm_runtime *fe, +struct snd_soc_pcm_runtime *be,int stream); + +/* get the substream for this BE */ +struct snd_pcm_substream * +snd_soc_dpcm_get_substream (struct snd_soc_pcm_runtime *be,int stream); + +/* get the BE runtime state */ +enum snd_soc_dpcm_state +snd_soc_dpcm_be_get_state (struct snd_soc_pcm_runtime *be,int stream); + +/* set the BE runtime state */ +void snd_soc_dpcm_be_set_state (struct snd_soc_pcm_runtime *be,int stream, +enum snd_soc_dpcm_state state); + +/* internal use only */ +int soc_dpcm_be_digital_mute (struct snd_soc_pcm_runtime *fe,int mute); + +#endif
include/sound/soc.h +17 -0
@@ -274,6 +274,7 @@ struct snd_soc_jack_zone;struct snd_soc_jack_pin ;struct snd_soc_cache_ops ;#include <sound/soc-dapm.h> +#include <sound/soc-dpcm.h> #ifdef CONFIG_GPIOLIB struct snd_soc_jack_gpio ;
@@ -760,23 +761,36 @@ struct snd_soc_dai_link {const char *cpu_dai_name;const struct device_node *cpu_dai_of_node;const char *codec_dai_name; +int be_id;/* optional ID for machine driver BE identification */ const struct snd_soc_pcm_stream *params;unsigned int dai_fmt;/* format to set on init */ +enum snd_soc_dpcm_trigger trigger[2 ];/* trigger type for DPCM */ +/* Keep DAI active over suspend */ unsigned int ignore_suspend:1;/* Symmetry requirements */ unsigned int symmetric_rates:1; +/* Do not create a PCM for this DAI link (Backend link) */ + unsigned int no_pcm:1; + +/* This DAI link can route to other DAI links at runtime (Frontend)*/ + unsigned int dynamic:1; +/* pmdown_time is ignored at stop */ unsigned int ignore_pmdown_time:1;/* codec/machine specific init - e.g. add machine controls */ int (*init)(struct snd_soc_pcm_runtime *rtd); +/* optional hw_params re-writing for BE and FE sync */ +int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd, +struct snd_pcm_hw_params *params); +/* machine stream operations */ struct snd_soc_ops *ops; };
@@ -908,6 +922,9 @@ struct snd_soc_pcm_runtime { unsigned int dev_registered:1; +/* Dynamic PCM BE runtime data */ +struct snd_soc_dpcm_runtime dpcm[2 ]; +long pmdown_time;/* runtime devices */
sound/soc/soc-core.c +5 -0
@@ -39,6 +39,7 @@#include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> +#include <sound/soc-dpcm.h> #include <sound/initval.h> #define CREATE_TRACE_POINTS
@@ -1161,6 +1162,10 @@ static int soc_post_component_init(struct snd_soc_card *card, rtd->dev->init_name = name;dev_set_drvdata (rtd->dev, rtd);mutex_init (&rtd->pcm_mutex); +INIT_LIST_HEAD (&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK ].be_clients); +INIT_LIST_HEAD (&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE ].be_clients); +INIT_LIST_HEAD (&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK ].fe_clients); +INIT_LIST_HEAD (&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE ].fe_clients); ret =device_add (rtd->dev);if (ret <0 ) { dev_err(card->dev,
sound/soc/soc-pcm.c +1216 -30
1,309 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 2/5 ASoC: dpcm: Add debugFS support for DPCM
Add debugFS files for DPCM link management information.
--- include/sound/soc-dpcm.h | 4 + include/sound/soc.h | 4 + sound/soc/soc-core.c | 11 +++ sound/soc/soc-pcm.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+), 0 deletions(-)
include/sound/soc-dpcm.h +4 -0
@@ -81,6 +81,9 @@ struct snd_soc_dpcm {/* hw params for this link - may be different for each link */ struct snd_pcm_hw_params hw_params; +#ifdef CONFIG_DEBUG_FS +struct dentry *debugfs_state; +#endif };/*
@@ -128,5 +131,6 @@ void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, int stream,/* internal use only */ int soc_dpcm_be_digital_mute (struct snd_soc_pcm_runtime *fe,int mute); +int soc_dpcm_debugfs_add (struct snd_soc_pcm_runtime *rtd);#endif
include/sound/soc.h +4 -0
@@ -935,6 +935,10 @@ struct snd_soc_pcm_runtime {struct snd_soc_dai *cpu_dai;struct delayed_work delayed_work; +#ifdef CONFIG_DEBUG_FS +struct dentry *debugfs_dpcm_root; +struct dentry *debugfs_dpcm_state; +#endif };/* mixer control */
sound/soc/soc-core.c +11 -0
@@ -1187,6 +1187,17 @@ static int soc_post_component_init(struct snd_soc_card *card,dev_err (codec->dev,"asoc: failed to add codec sysfs files: %d\n" , ret); +#ifdef CONFIG_DEBUG_FS +/* add DPCM sysfs entries */ +if (!dai_link->dynamic) + goto out; + + ret =soc_dpcm_debugfs_add (rtd); +if (ret <0 ) +dev_err (rtd->dev,"asoc: failed to add dpcm sysfs entries: %d\n" , ret); + +out: +#endif return 0 ; }
sound/soc/soc-pcm.c +152 -0
173 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [PATCH 2/5] ASoC: dpcm: Add debugFS support for DPCM
On Wed, Apr 25, 2012 at 12:12:50PM +0100, Liam Girdwood wrote:
I've queued this to apply this but a few nits I noticed:
sound/soc/soc-pcm.c static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe, · line 697
Quoted 4 lines
sound/soc/soc-pcm.c +4
-0+#ifdef CONFIG_DEBUG_FS + dpcm->debugfs_state =debugfs_create_u32 (be->dai_link->name,0644 , + fe->debugfs_dpcm_root, &dpcm->state); +#endif
I have to say that this being writable seems rather scary... any great need for that?
sound/soc/soc-pcm.c int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe, · line 1935
Quoted 5 lines
sound/soc/soc-pcm.c +5
-0+static int dpcm_state_open_file (struct inode *inode,struct file *file) +{ + file->private_data = inode->i_private; +return 0 ; +}
This is simple_open() - could just remove this and use simple_open() in the ops.
sound/soc/soc-pcm.c int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe, · line 2018
Quoted 9 lines
sound/soc/soc-pcm.c +9
-0+if (fe->cpu_dai->driver->capture.channels_min) + offset +=dpcm_show_state (fe,SNDRV_PCM_STREAM_CAPTURE , + buf + offset, out_count - offset); + + ret =simple_read_from_buffer (user_buf, count, ppos, buf, offset); + +kfree (buf); + +return ret;
Suspect there's some spaces being used for indentation here...
Re: [PATCH 2/5] ASoC: dpcm: Add debugFS support for DPCM
Quoted 11 lines · Mark Brown
On Wed, Apr 25, 2012 at 12:12:50PM +0100, Liam Girdwood wrote:
I've queued this to apply this but a few nits I noticed:
sound/soc/soc-pcm.c static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe, · line 697
Quoted 4 lines
sound/soc/soc-pcm.c +4
-0+#ifdef CONFIG_DEBUG_FS + dpcm->debugfs_state =debugfs_create_u32 (be->dai_link->name,0644 , + fe->debugfs_dpcm_root, &dpcm->state); +#endif I have to say that this being writable seems rather scary... any great need for that?
Ah, no - will fix this and the other two incrementally.
Regards
Liam
PATCH 3/5 ASoC: dpcm: Add runtime dynamic route update
In reply to Liam GirdwoodThis patch allows DPCM to dynamically alter the FE to BE PCM links at runtime based on mixer setting updates. DAPM is looked up after every mixer update and we perform a DPCM runtime update if the mixer has a change of value.
This patchs adds/changes the following :-
o Adds DPCM runtime update core.
o Changes soc_dapm_mixer_update_power() and soc_dapm_mux_update_power() to return if a change has occured rather than 0. No other users check atm.
--- include/sound/soc-dpcm.h | 1 + sound/soc/soc-dapm.c | 8 ++- sound/soc/soc-pcm.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+), 2 deletions(-)
include/sound/soc-dpcm.h +1 -0
@@ -132,5 +132,6 @@ void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, int stream,/* internal use only */ int soc_dpcm_be_digital_mute (struct snd_soc_pcm_runtime *fe,int mute);int soc_dpcm_debugfs_add (struct snd_soc_pcm_runtime *rtd); +int soc_dpcm_runtime_update (struct snd_soc_dapm_widget *);#endif
sound/soc/soc-dapm.c +6 -2
@@ -1744,7 +1744,7 @@ static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,dapm_power_widgets (widget->dapm,SND_SOC_DAPM_STREAM_NOP ); } -return 0 ; +return found; } int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
@@ -1756,6 +1756,8 @@ int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,mutex_lock_nested (&card->dapm_mutex,SND_SOC_DAPM_CLASS_RUNTIME ); ret =soc_dapm_mux_update_power (widget, kcontrol, mux, e);mutex_unlock (&card->dapm_mutex); +if (ret >0 ) +soc_dpcm_runtime_update (widget);return ret; }EXPORT_SYMBOL_GPL (snd_soc_dapm_mux_update_power);
@@ -1788,7 +1790,7 @@ static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,dapm_power_widgets (widget->dapm,SND_SOC_DAPM_STREAM_NOP ); } -return 0 ; +return found; } int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
@@ -1800,6 +1802,8 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,mutex_lock_nested (&card->dapm_mutex,SND_SOC_DAPM_CLASS_RUNTIME ); ret =soc_dapm_mixer_update_power (widget, kcontrol, connect);mutex_unlock (&card->dapm_mutex); +if (ret >0 ) +soc_dpcm_runtime_update (widget);return ret; }EXPORT_SYMBOL_GPL (snd_soc_dapm_mixer_update_power);
sound/soc/soc-pcm.c +221 -0
228 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 4/5 ASoC: dpcm: Add bespoke trigger()
In reply to Liam GirdwoodSome on SoC DSP HW is very tightly coupled with DMA and DAI drivers. It's necessary to allow some flexability wrt to PCM operations here so that we can define a bespoke DPCM trigger() PCM operation for such HW.
A bespoke DPCM trigger() allows exact ordering and timing of component triggering by allowing a component driver to manage the final enable and disable configurations without adding extra complexity to other component drivers. e.g. The McPDM DAI and ABE are tightly coupled on OMAP4 so we have a bespoke trigger to manage the trigger to improve performance and reduce complexity when triggering new McPDM BEs.
--- include/sound/soc-dai.h | 2 + include/sound/soc-dpcm.h | 1 + include/sound/soc.h | 4 ++ sound/soc/soc-pcm.c | 99 +++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 96 insertions(+), 10 deletions(-)
include/sound/soc-dai.h +2 -0
@@ -173,6 +173,8 @@ struct snd_soc_dai_ops { struct snd_soc_dai *);int (*trigger)(struct snd_pcm_substream *,int ,struct snd_soc_dai *); +int (*bespoke_trigger)(struct snd_pcm_substream *,int , +struct snd_soc_dai *);/* * For hardware based FIFO caused delay reporting. * Optional.
include/sound/soc-dpcm.h +1 -0
@@ -60,6 +60,7 @@ enum snd_soc_dpcm_state {enum snd_soc_dpcm_trigger {SND_SOC_DPCM_TRIGGER_PRE =0 ,SND_SOC_DPCM_TRIGGER_POST , +SND_SOC_DPCM_TRIGGER_BESPOKE , };/*
include/sound/soc.h +4 -0
@@ -359,6 +359,9 @@ int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);int snd_soc_set_runtime_hwparams (struct snd_pcm_substream *substream,const struct snd_pcm_hardware *hw); +int snd_soc_platform_trigger (struct snd_pcm_substream *substream, +int cmd,struct snd_soc_platform *platform); +/* Jack reporting */ int snd_soc_jack_new (struct snd_soc_codec *codec,const char *id,int type,struct snd_soc_jack *jack);
@@ -726,6 +729,7 @@ struct snd_soc_platform_driver {/* platform IO - used for platform DAPM */ unsigned int (*read)(struct snd_soc_platform *,unsigned int );int (*write)(struct snd_soc_platform *,unsigned int ,unsigned int ); +int (*bespoke_trigger)(struct snd_pcm_substream *,int ); };struct snd_soc_platform {
sound/soc/soc-pcm.c +89 -10
142 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 5/5 ASoC: dpcm: Add API for DAI link substream and runtime lookup
In reply to Liam GirdwoodSome component drivers will need to be able to look up their DAI link substream and RTD data. Provide a mechanism for this.
--- include/sound/soc.h | 5 +++++ sound/soc/soc-core.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-)
include/sound/soc.h +5 -0
@@ -349,6 +349,11 @@ int snd_soc_platform_write(struct snd_soc_platform *platform, unsigned int reg, unsigned int val);int soc_new_pcm (struct snd_soc_pcm_runtime *rtd,int num); +struct snd_pcm_substream *snd_soc_get_dai_substream (struct snd_soc_card *card, +const char *dai_link,int stream); +struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime (struct snd_soc_card *card, +const char *dai_link); +/* Utility functions to get clock rates from various things */ int snd_soc_calc_frame_size (int sample_size,int channels,int tdm_slots);int snd_soc_params_to_frame_size (struct snd_pcm_hw_params *params);
sound/soc/soc-core.c +29 -0
@@ -465,6 +465,35 @@ static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) }#endif +struct snd_pcm_substream *snd_soc_get_dai_substream (struct snd_soc_card *card, +const char *dai_link,int stream) +{ +int i; + +for (i =0 ; i < card->num_links; i++) { +if (card->rtd[i].dai_link->no_pcm && + !strcmp (card->rtd[i].dai_link->name, dai_link)) +return card->rtd[i].pcm->streams[stream].substream; + } +dev_dbg (card->dev,"failed to find dai link %s\n" , dai_link); +return NULL ; +} +EXPORT_SYMBOL_GPL (snd_soc_get_dai_substream); + +struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime (struct snd_soc_card *card, +const char *dai_link) +{ +int i; + +for (i =0 ; i < card->num_links; i++) { +if (!strcmp (card->rtd[i].dai_link->name, dai_link)) +return &card->rtd[i]; + } +dev_dbg (card->dev,"failed to find rtd %s\n" , dai_link); +return NULL ; +} +EXPORT_SYMBOL_GPL (snd_soc_get_pcm_runtime); +#ifdef CONFIG_SND_SOC_AC97_BUS /* unregister ac97 codec */ static int soc_ac97_dev_unregister (struct snd_soc_codec *codec)
Signature · 1 line
1.7.5.4
Quoted 4 lines · Liam Girdwood
The Dynamic PCM core allows digital audio data to be dynamically routed between different ALSA PCMs and DAI links on SoC CPUs with on chip DSP devices. e.g. audio data could be played on pcm:0,0 and routed to any (or all) SoC DAI links.
I've applied all these now - after recovering from the shock of seeing them! :)
I think we need to have a look at/think about the no_pcm flag, partly just in relation to the CODEC<->CODEC code as that's also figuring out that there's no PCM but it does it just by checking that there's no DMA driver specified. But I'm not sure what the best thing to do is here without seeing a machine driver or two.
Quoted 9 lines · Mark Brown
Quoted 4 lines · Liam Girdwood
The Dynamic PCM core allows digital audio data to be dynamically routed between different ALSA PCMs and DAI links on SoC CPUs with on chip DSP devices. e.g. audio data could be played on pcm:0,0 and routed to any (or all) SoC DAI links.
I've applied all these now - after recovering from the shock of seeing them! :)
Ah yes, it did take along time ! I'm doing less support now so any other new stuff should be faster now :)
Quoted 5 lines
I think we need to have a look at/think about the
no_pcmflag, partly just in relation to the CODEC<->CODEC code as that's also figuring out that there's no PCM but it does it just by checking that there's no DMA driver specified. But I'm not sure what the best thing to do is here without seeing a machine driver or two.
Ok, yes - lets look at that. We should have machine updates ready to upstream soon with ABE.
Liam