ASoC: Extend DAPM to handle cross-device paths
Subsystems (4)
v2 cover ASoC: Extend DAPM to handle cross-device paths
Hi
Here's updated version of previous RFC_ii/iv set:
http://mailman.alsa-project.org/pipermail/alsa-devel/2010-October/033196.html
Patches 1-2 have no remarkable changes, just modified on top of recent changes.
Patch 3 is simpler as it turns out that the dapm_seq_run_coalesced doesn't need any changes because it's enough to call it with a right DAPM context. One fix is in beginning of dapm_power_widgets that d->dev_power is zeroed only for those codecs that have widgets in order to avoid unnecessary widgetless codec bias shutdowns.
Minor changes are dapm.sys_power renaming to dev_power and long lines are cut.
Signature · 1 line
Jarkko
PATCH v2 1/3 ASoC: Move DAPM paths from DAPM context to snd_soc_card
Decoupling DAPM paths from DAPM context is a first prerequisite when extending ASoC core to cross-device paths. This patch is almost a nullop and does not allow to construct cross-device setup but the path clean-up part in dapm_free_widgets is prepared to remove cross-device paths between a device being removed and others.
--- include/sound/soc-dapm.h | 1 - include/sound/soc.h | 2 + sound/soc/codecs/tlv320aic3x.c | 2 +- sound/soc/soc-core.c | 2 +- sound/soc/soc-dapm.c | 41 ++++++++++++++++++++++++++------------- 5 files changed, 31 insertions(+), 17 deletions(-)
include/sound/soc-dapm.h +0 -1
@@ -470,7 +470,6 @@ struct snd_soc_dapm_widget {/* DAPM context */ struct snd_soc_dapm_context {struct list_head widgets; -struct list_head paths;enum snd_soc_bias_level bias_level;enum snd_soc_bias_level suspend_bias_level;struct delayed_work delayed_work;
include/sound/soc.h +2 -0
@@ -618,6 +618,8 @@ struct snd_soc_card {struct list_head platform_dev_list;struct list_head dai_dev_list; +struct list_head paths; +#ifdef CONFIG_DEBUG_FS struct dentry *debugfs_card_root;struct dentry *debugfs_pop_time;
sound/soc/codecs/tlv320aic3x.c +1 -1
@@ -183,7 +183,7 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,if (snd_soc_test_bits (widget->codec, reg, val_mask, val)) {/* find dapm widget path assoc with kcontrol */ -list_for_each_entry (path, &widget->dapm->paths, list) { +list_for_each_entry (path, &widget->dapm->card->paths, list) {if (path->kcontrol != kcontrol)continue ;
sound/soc/soc-core.c +1 -1
@@ -1696,6 +1696,7 @@ static int soc_probe(struct platform_device *pdev)INIT_LIST_HEAD (&card->dai_dev_list);INIT_LIST_HEAD (&card->codec_dev_list);INIT_LIST_HEAD (&card->platform_dev_list); +INIT_LIST_HEAD (&card->paths);soc_init_card_debugfs (card);
@@ -3275,7 +3276,6 @@ int snd_soc_register_codec(struct device *dev, }INIT_LIST_HEAD (&codec->dapm.widgets); -INIT_LIST_HEAD (&codec->dapm.paths); codec->dapm.bias_level =SND_SOC_BIAS_OFF ; codec->dapm.dev = dev; codec->dapm.codec = codec;
sound/soc/soc-dapm.c +27 -14
97 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH v2 2/3 ASoC: Move widgets from DAPM context to snd_soc_card
In reply to Jarkko NikulaDecoupling widgets from DAPM context is required when extending the ASoC core to cross-device paths. Even the list of widgets are now kept in struct snd_soc_card, the widget listing in sysfs and debugs remain sorted per device.
This patch makes possible to build cross-device paths but does not extend yet the DAPM to handle codec bias and widget power changes of an another device.
Cross-device paths are registered by listing the widgets from device A in a map for device B. An example below shows a path that connects MONO out of A into Line In of B:
static const struct snd_soc_dapm_route mapA[] = {
{"MONO", NULL, "DAC"},
};static const struct snd_soc_dapm_route mapB[] = {
{"Line In", NULL, "MONO"},
};--- include/sound/soc-dapm.h | 2 +- include/sound/soc.h | 1 + sound/soc/codecs/wm8960.c | 4 ++- sound/soc/soc-core.c | 2 +- sound/soc/soc-dapm.c | 69 ++++++++++++++++++++++++++++++++------------- 5 files changed, 55 insertions(+), 23 deletions(-)
include/sound/soc-dapm.h +1 -1
@@ -469,7 +469,7 @@ struct snd_soc_dapm_widget {/* DAPM context */ struct snd_soc_dapm_context { -struct list_head widgets; +int n_widgets;/* number of widgets in this context */ enum snd_soc_bias_level bias_level;enum snd_soc_bias_level suspend_bias_level;struct delayed_work delayed_work;
include/sound/soc.h +1 -0
@@ -618,6 +618,7 @@ struct snd_soc_card {struct list_head platform_dev_list;struct list_head dai_dev_list; +struct list_head widgets;struct list_head paths;#ifdef CONFIG_DEBUG_FS
sound/soc/codecs/wm8960.c +3 -1
@@ -418,7 +418,9 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)* list each time to find the desired power state do so now * and save the result. */ -list_for_each_entry (w, &codec->dapm.widgets, list) { +list_for_each_entry (w, &codec->card->widgets, list) { +if (w->dapm != &codec->dapm) +continue ;if (strcmp (w->name,"LOUT1 PGA" ) ==0 ) wm8960->lout1 = w;if (strcmp (w->name,"ROUT1 PGA" ) ==0 )
sound/soc/soc-core.c +1 -1
@@ -1696,6 +1696,7 @@ static int soc_probe(struct platform_device *pdev)INIT_LIST_HEAD (&card->dai_dev_list);INIT_LIST_HEAD (&card->codec_dev_list);INIT_LIST_HEAD (&card->platform_dev_list); +INIT_LIST_HEAD (&card->widgets);INIT_LIST_HEAD (&card->paths);soc_init_card_debugfs (card);
@@ -3275,7 +3276,6 @@ int snd_soc_register_codec(struct device *dev,return -ENOMEM ; } -INIT_LIST_HEAD (&codec->dapm.widgets); codec->dapm.bias_level =SND_SOC_BIAS_OFF ; codec->dapm.dev = dev; codec->dapm.codec = codec;
sound/soc/soc-dapm.c +49 -20
170 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Re: [PATCHv2 2/3] ASoC: Move widgets from DAPM context to snd_soc_card
Quoted 11 lines · Jarkko Nikula
Cross-device paths are registered by listing the widgets from device A in a map for device B. An example below shows a path that connects MONO out of A into Line In of B:
static const struct snd_soc_dapm_route mapA[] = { {"MONO", NULL, "DAC"}, };static const struct snd_soc_dapm_route mapB[] = { {"Line In", NULL, "MONO"}, };
This is going to fall over if we have widgets in two devices with the same name (and especially if we have two devices of the same kind in the system). Adding source device names to the paths would probably cover it with the same format but it should be considered and noted here.
include/sound/soc-dapm.h struct snd_soc_dapm_widget { · line 472
Quoted 3 lines
struct
snd_soc_dapm_context{include/sound/soc-dapm.h +1
-1-struct list_head widgets; +int n_widgets;/* number of widgets in this context */
I'm not sure why we need to count the number of widgets here;
include/sound/soc.h struct snd_soc_card { · line 623
Quoted 10 lines
index 835087d..77be6b3 100644
include/sound/soc.h +1
-0@@ -618,6 +618,7 @@ struct snd_soc_card {struct list_head platform_dev_list;struct list_head dai_dev_list; +struct list_head widgets;struct list_head paths;
If we keep moving stuff into the card it's questionable what the context is buying us...
Re: [PATCHv2 2/3] ASoC: Move widgets from DAPM context to snd_soc_card
Quoted 10 lines · On Fri, 12 Nov 2010 13:18:41 +0000 Mark Brown…
Quoted 7 lines · Jarkko Nikula
Cross-device paths are registered by listing the widgets from device A in a map for device B. An example below shows a path that connects MONO out of A into Line In of B:
static const struct snd_soc_dapm_route mapA[] = { {"MONO", NULL, "DAC"}, };
Quoted 9 lines
Quoted 3 lines
static const struct snd_soc_dapm_route mapB[] = { {"Line In", NULL, "MONO"}, };This is going to fall over if we have widgets in two devices with the same name (and especially if we have two devices of the same kind in the system). Adding source device names to the paths would probably cover it with the same format but it should be considered and noted here.
That's the reason why the code favors a widget from current DAPM context in snd_soc_dapm_add_route so that no current machine would (hopefully) break because of this patch.
Of course any new code implementing cross-device paths between codecs with conflicting widget names would need the name prefixing stuff also.
Quoted 6 lines
include/sound/soc-dapm.h struct snd_soc_dapm_widget { · line 472
Quoted 3 lines
struct
snd_soc_dapm_context{include/sound/soc-dapm.h +1
-1-struct list_head widgets; +int n_widgets;/* number of widgets in this context */ I'm not sure why we need to count the number of widgets here;
True, this should go the next patch actually.
Quoted 7 lines
Quoted 7 lines
index 835087d..77be6b3 100644
include/sound/soc.h +0
-0@@ -618,6 +618,7 @@ struct snd_soc_card {struct list_head platform_dev_list;struct list_head dai_dev_list;
Quoted 6 lines
include/sound/soc.h struct snd_soc_card { · line 623
Quoted 3 lines
include/sound/soc.h +1
-0+struct list_head widgets;struct list_head paths;If we keep moving stuff into the card it's questionable what the context is buying us...
DAPM context represent the parent device (codecs currently and other devices in someday) and its state so I don't see we'll be removing it in near future even now the widgets and paths are moved to card.
Signature · 1 line
Jarkko
Re: [PATCHv2 2/3] ASoC: Move widgets from DAPM context to snd_soc_card
Quoted 11 lines · On Fri, 12 Nov 2010 15:57:56 +0200 Jarkko Nikula <[email protected]> wrote:
Quoted 6 lines · On Fri, 12 Nov 2010 13:18:41 +0000 Mark Brown…
include/sound/soc-dapm.h struct snd_soc_dapm_widget { · line 472
Quoted 3 lines
struct
snd_soc_dapm_context{include/sound/soc-dapm.h +1
-1-struct list_head widgets; +int n_widgets;/* number of widgets in this context */ I'm not sure why we need to count the number of widgets here;
True, this should go the next patch actually.
Not true, it is actually need here. We cannot detect widgetless codecs by testing list_empty(&card->widgets) after moving widgets from dapm to card so we must keep count of widgets for each DAPM context (device).
- if (list_empty(&dapm->widgets)) {
+ if (!dapm->n_widgets) {
Signature · 1 line
Jarkko
Re: [PATCHv2 2/3] ASoC: Move widgets from DAPM context to snd_soc_card
In reply to Jarkko NikulaQuoted 8 lines · Jarkko Nikula
Quoted 2 lines · Mark Brown
If we keep moving stuff into the card it's questionable what the context is buying us...
DAPM context represent the parent device (codecs currently and other devices in someday) and its state so I don't see we'll be removing it in near future even now the widgets and paths are moved to card.
Yeah, but as we keep reducing the amount of per-device state we hold that could eventually go down to zero - we keep on looking at things and deciding they're better managed over the whole card.
PATCH v2 3/3 ASoC: Extend DAPM to handle power changes on cross-device paths
In reply to Jarkko NikulaPower change event like stream start/stop or kcontrol change in a cross-device path originates from one device but codec bias and widget power changes must be populated to another devices on that path as well.
This patch modifies the dapm_power_widgets so that all the widgets on a sound card are checked for a power change, not just those that are specific to originating device. Also bias management is extended to check all the devices. Only exception in bias management are widgetless codecs whose bias state is changed only if power change is originating from that context.
DAPM context test is added to dapm_seq_run to take care of if power sequence extends to an another device which requires separate register writes.
--- include/sound/soc-dapm.h | 5 ++ include/sound/soc.h | 1 + sound/soc/soc-core.c | 2 + sound/soc/soc-dapm.c | 107 ++++++++++++++++++++++++++------------------- 4 files changed, 70 insertions(+), 45 deletions(-)
include/sound/soc-dapm.h +5 -0
@@ -478,6 +478,11 @@ struct snd_soc_dapm_context {struct device *dev;/* from parent - for debug */ struct snd_soc_codec *codec;/* parent codec */ struct snd_soc_card *card;/* parent card */ + +/* used during DAPM updates */ +int dev_power; +struct list_head list; +#ifdef CONFIG_DEBUG_FS struct dentry *debugfs_dapm;#endif
include/sound/soc.h +1 -0
@@ -620,6 +620,7 @@ struct snd_soc_card {struct list_head widgets;struct list_head paths; +struct list_head dapm_list;#ifdef CONFIG_DEBUG_FS struct dentry *debugfs_card_root;
sound/soc/soc-core.c +2 -0
@@ -1454,6 +1454,7 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)/* mark codec as probed and add to card codec list */ codec->probed =1 ;list_add (&codec->card_list, &card->codec_dev_list); +list_add (&codec->dapm.list, &card->dapm_list); }/* probe the platform */
@@ -1698,6 +1699,7 @@ static int soc_probe(struct platform_device *pdev)INIT_LIST_HEAD (&card->platform_dev_list);INIT_LIST_HEAD (&card->widgets);INIT_LIST_HEAD (&card->paths); +INIT_LIST_HEAD (&card->dapm_list);soc_init_card_debugfs (card);
sound/soc/soc-dapm.c +62 -45
189 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Re: [PATCHv2 3/3] ASoC: Extend DAPM to handle power changes on cross-device paths
Quoted 4 lines · Jarkko Nikula
sound/soc/soc-dapm.c +0
-0list_for_each_entry_safe (w, n, list, power_list) { ret =0 ;/* Do we need to apply any queued changes? */
sound/soc/soc-dapm.c static void dapm_seq_run(struct snd_soc_dapm_context *dapm, · line 858
Quoted 10 lines
sound/soc/soc-dapm.c +3
-2-if (sort[w->id] != cur_sort || w->reg != cur_reg) { +if (sort[w->id] != cur_sort || w->reg != cur_reg || + w->dapm != cur_dapm) {if (!list_empty (&pending)) -dapm_seq_run_coalesced (dapm, &pending); +dapm_seq_run_coalesced (cur_dapm, &pending);INIT_LIST_HEAD (&pending); cur_sort =-1 ; cur_reg =SND_SOC_NOPM ;
We need a corresponding change in dapm_seq_compare() to ensure that the widgets for a given card are grouped together. I'll send out some patches to do that shortly since I just noticed there's an oversight there anyway.
Quoted 1 line · Jarkko Nikula
One fix is in beginning of
dapm_power_widgetsthatd->dev_poweris zeroed only
Fix relative to the previous version, this is?
Quoted 2 lines
for those codecs that have widgets in order to avoid unnecessary widgetless codec bias shutdowns.
Hrm, I think we should probably consider just requring all devices to have at least stub DAPM support. It's probably simpler than having to special case them, we should be able to add a utility function which adds default stubs to minimise the code impact.
Quoted 7 lines · Mark Brown
Quoted 2 lines
for those codecs that have widgets in order to avoid unnecessary widgetless codec bias shutdowns.
Hrm, I think we should probably consider just requring all devices to have at least stub DAPM support. It's probably simpler than having to special case them, we should be able to add a utility function which adds default stubs to minimise the code impact.
...and on further reflection this is actually broken for simultaneous playback and record in mainline so we probably want to do a fix there anyway.
Quoted 5 lines · On Fri, 12 Nov 2010 13:54:12 +0000 Mark Brown…
Quoted 2 lines · Mark Brown
Quoted 2 lines
for those codecs that have widgets in order to avoid unnecessary widgetless codec bias shutdowns.
Quoted 8 lines
Quoted 4 lines
Hrm, I think we should probably consider just requring all devices to have at least stub DAPM support. It's probably simpler than having to special case them, we should be able to add a utility function which adds default stubs to minimise the code impact.
...and on further reflection this is actually broken for simultaneous playback and record in mainline so we probably want to do a fix there anyway.
Are you thinking to have a fix before this set or let it to float if the issue has been there already some time? I'm thinking do we have any other widgetless codecs than some dummy bluetooth etc. codec stubs.
Signature · 1 line
Jarkko
Quoted 9 lines · Jarkko Nikula
Quoted 3 lines · Mark Brown
...and on further reflection this is actually broken for simultaneous playback and record in mainline so we probably want to do a fix there anyway.
Are you thinking to have a fix before this set or let it to float if the issue has been there already some time? I'm thinking do we have any other widgetless codecs than some dummy bluetooth etc. codec stubs.
One or the other. The bluetooth/baseband stubs are something else again
- they're DAIs with no associated device - but I'll need to think about how bad this really is and if insisting on DAPM really is the best way forward. I'd suggest just dropping the special casing of this from your series unless you feel inspired to change stuff for 2.6.37 (in which case do the change separately, obviously) as you're not making anything worse.
Quoted 6 lines · On Fri, 12 Nov 2010 13:51:44 +0000 Mark Brown…
Quoted 1 line · Jarkko Nikula
One fix is in beginning of
dapm_power_widgetsthatd->dev_poweris zeroed onlyFix relative to the previous version, this is?
Yep, I noticed that previous version had the bug that widgetless codec bias would shutdown if any other device initiates power change.
Signature · 1 line
Jarkko