ASoC: omap-mcpdm: New McPDM driver
v3 cover ASoC: omap-mcpdm: New McPDM driver
Hello,
Changes since v2 [1]:
- Code for the DAPM_SUPPLY widget attach has been moved to core (Request from Mark, if I understood correctly).
- Makes it reusable in other drivers
- Additional code still needed in DAI (event handler, selection of the dai), and machine drivers (DAPM routing)
- Should work even if we have multiple instances of the DAI (coment from Lars-Peter Clausen)
[1]
http://mailman.alsa-project.org/pipermail/alsa-devel/2011-August/042923.html
Regards,
Peter
---
Misael Lopez Cruz (1):
ASoC: omap-mcpdm: Replace legacy driver
Peter Ujfalusi (2):
ASoC: DAPM: Add private data pointer for DAPM widget
ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
include/sound/soc-dapm.h | 18 + sound/soc/omap/Makefile | 2 +- sound/soc/omap/mcpdm.c | 474 ------------------------- sound/soc/omap/mcpdm.h | 152 -------- sound/soc/omap/omap-mcpdm.c | 813 ++++++++++++++++++++++++++++--------------- sound/soc/omap/omap-mcpdm.h | 97 +++++ sound/soc/omap/sdp4430.c | 14 +- sound/soc/soc-dapm.c | 27 ++ 8 files changed, 690 insertions(+), 907 deletions(-) delete mode 100644 sound/soc/omap/mcpdm.c delete mode 100644 sound/soc/omap/mcpdm.h rewrite sound/soc/omap/omap-mcpdm.c (46%) create mode 100644 sound/soc/omap/omap-mcpdm.h
Signature · 1 line
1.7.6.1
PATCH v3 1/3 ASoC: DAPM: Add private data pointer for DAPM widget
Support for using custom private data assigned
per DAPM widget.
--- include/sound/soc-dapm.h | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
include/sound/soc-dapm.h +13 -0
@@ -474,6 +474,7 @@ struct snd_soc_dapm_widget { unsigned char force:1; /* force state */ unsigned char ignore_suspend:1; /* kept enabled over suspend */int subseq;/* sort within widget type */ +void *private_data;/* for widget specific data */ int (*power_check)(struct snd_soc_dapm_widget *w);
@@ -535,4 +536,16 @@ struct snd_soc_dapm_widget_list { struct snd_soc_dapm_widget *widgets[0]; }; +/* Accessors for snd_soc_dapm_widget->private_data */ +static inline void *snd_soc_dapm_widget_get_pdata (struct snd_soc_dapm_widget *w) +{ +return w->private_data; +} + +static inline void snd_soc_dapm_widget_set_pdata (struct snd_soc_dapm_widget *w, +void *data) +{ + w->private_data = data; +} +#endif
Signature · 1 line
1.7.6.1
PATCH v3 2/3 ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
In reply to Peter UjfalusiThere are cpu dais, which require special ordering during stream stop (OMAP4's McPDM interface for example) in a system level. OMAP4 McPDM required to be stopped after the attached codec's (twl6040) DAC/ADC has been stopped.
This requironment can be solved with a use of DAPM_SUPPLY widget attached to the codec's ADC/DAC from machine driver.
Provide generic enough API from core which can be used from other drivers, if needed.
The snd_soc_dapm_attach_dai_supply function can be used to attach the DAPM_SUPPLY widget to the specified dapm_context. The resulting widget's private_data will be initialized with the dai's drvdata.
--- include/sound/soc-dapm.h | 5 +++++ sound/soc/soc-dapm.c | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-)
include/sound/soc-dapm.h +5 -0
@@ -381,6 +381,11 @@ int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,int snd_soc_dapm_ignore_suspend (struct snd_soc_dapm_context *dapm,const char *pin); +int snd_soc_dapm_attach_dai_supply (struct snd_soc_dapm_context *dapm, +struct snd_soc_dai *dai,char *wname, +int (*wevent)(struct snd_soc_dapm_widget *,struct snd_kcontrol *,int ), +unsigned short wflags); +/* dapm widget types */ enum snd_soc_dapm_type { snd_soc_dapm_input =0 ,/* input pin */
sound/soc/soc-dapm.c +27 -0
@@ -2776,6 +2776,33 @@ void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) }EXPORT_SYMBOL_GPL (snd_soc_dapm_free); +/** +* snd_soc_dapm_attach_dai_supply - attach supply widget on behalf of a dai +* @dapm: DAPM context +* @dai: DAI, which requesting the widget +* @wname: name of the DAPM_SUPPLY widget +* @wevent: event handler callback +* @wflags: DAPM event flags +* +* Creates DAPM_SUPPLY widget on behalf of a dai. The new widget's private_data +* will inherit the dai's driver data pointer, which is going to be available +* in the event handler. +*/ +int snd_soc_dapm_attach_dai_supply (struct snd_soc_dapm_context *dapm, +struct snd_soc_dai *dai,char *wname, +int (*wevent)(struct snd_soc_dapm_widget *,struct snd_kcontrol *,int ), +unsigned short wflags) +{ +void *pdata =snd_soc_dai_get_drvdata (dai); +struct snd_soc_dapm_widget dai_widget = +SND_SOC_DAPM_SUPPLY (wname,SND_SOC_NOPM ,0 ,0 , wevent, wflags); + +snd_soc_dapm_widget_set_pdata (&dai_widget, pdata); + +return snd_soc_dapm_new_control (dapm, &dai_widget); +} +EXPORT_SYMBOL_GPL (snd_soc_dapm_attach_dai_supply); +static void soc_dapm_shutdown_codec (struct snd_soc_dapm_context *dapm) {struct snd_soc_dapm_widget *w;
Signature · 1 line
1.7.6.1
Re: [PATCH v3 2/3] ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
Quoted 7 lines · Peter Ujfalusi
There are cpu dais, which require special ordering during stream stop (OMAP4's McPDM interface for example) in a system level. OMAP4 McPDM required to be stopped after the attached codec's (twl6040) DAC/ADC has been stopped.
This requironment can be solved with a use of
DAPM_SUPPLYwidget attached to the codec's ADC/DAC from machine driver.
This wasn't really what I meant - what I meant was that we ought to be able to change the ordering of DAPM with regard to the stream shutdown without having to have anything more than flags in the devices that can or need to do it (I'd expect more the CODECs more than the CPUs).
Re: [PATCH v3 2/3] ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
Quoted 4 lines · On Friday 26 August 2011 21:05:02 Mark Brown wrote:
This wasn't really what I meant - what I meant was that we ought to be able to change the ordering of DAPM with regard to the stream shutdown without having to have anything more than flags in the devices that can or need to do it (I'd expect more the CODECs more than the CPUs).
I see, but this is not what I'm trying to achieve here.
Even, if we could re-order the stream shutdown (for DAIs mostly) and DAPM sequence it won't work for me:
I need to make sure that the cpu_dai (McPDM) is shut down _after the DAC/ADC, and _before_ the codec is powered down - which would stop the McPDM clocks - which in turn used by McPDM as functional clock.
So if we would somehow execute the DAPM first followed by the stream shutdown, I can be in a situation, when McPDM is not accessible (missing clocks).
If we really want to reorder the stream shutdown and DAPM, we need to quite a bit of change, since we need to be able to 'delay' the shutdown operations for DAIs/platforms at least. But. Since the stream has been already closed, we can not refer to it anymore in case of pmdown_time > 0 (playback only issue).
One way would be to have special DAPM widget for DAI/platform event, and hook that up somewhere at some point that it will do what it is intended to be doing.
Or some callback function for DAIs/platforms, which would be called from the dapm_power_widgets function.
These would work, mostly, but I'm not convinced, that it would work for me, so I anyway need to do something similar as in this series.
--
Péter
Re: [PATCH v3 2/3] ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
Quoted 6 lines · Péter Ujfalusi
Quoted 4 lines · On Friday 26 August 2011 21:05:02 Mark Brown wrote:
This wasn't really what I meant - what I meant was that we ought to be able to change the ordering of DAPM with regard to the stream shutdown without having to have anything more than flags in the devices that can or need to do it (I'd expect more the CODECs more than the CPUs).
Quoted 6 lines
I see, but this is not what I'm trying to achieve here.
Even, if we could re-order the stream shutdown (for DAIs mostly) and DAPM sequence it won't work for me:
I need to make sure that thecpu_dai(McPDM) is shut down_afterthe DAC/ADC, and _before_ the codec is powered down - which would stop the McPDM clocks - which in turn used by McPDM as functional clock.
That's not what you said before... I did post the sequence I was suggesting and you seemed fine with it. Please try to be clear about what you're trying to do here - previously you'd just said that you needed to make sure the CODEC was powered down prior to the CPU being stopped but now you're adding additional stuff here.
Could you please clarify what exactly the system looks like here and what you need to do? I'm struggling to understand how you've got PDM output links providing clocks back into the CPU - usually a PDM output is two wires going in one direction. I also don't entirely understand why your current approach will be robust, though it should be an improvement on the original change to just put a delay in the shutdown. You can't rely on pmdown_time happening at all as it's user configurable and only happens for some cases even when it's there.
Quoted 4 lines
If we really want to reorder the stream shutdown and DAPM, we need to quite a bit of change, since we need to be able to 'delay' the shutdown operations for DAIs/platforms at least. But. Since the stream has been already closed, we can not refer to it anymore in case of
pmdown_time> 0 (playback only issue).
Part of what I'm suggesting is that we may as well not bother with the pmdown_time timeout if we need to shut the DAI down while we're shutting the CODEC down anyway, the whole thing may as well get shut down at once which will be a little more power efficient.
Quoted 2 lines
These would work, mostly, but I'm not convinced, that it would work for me, so I anyway need to do something similar as in this series.
Like I say I'm not convinced I understand what you need to do yet. It would be easier if we could merge the updated McPDM driver and worry about this separately; I don't understand why you can't just inline the event into the regular teardown (it will be noisy but it should at least run).
Re: [PATCH v3 2/3] ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
Quoted 5 lines · On Monday 29 August 2011 11:16:04 Mark Brown wrote:
That's not what you said before... I did post the sequence I was suggesting and you seemed fine with it. Please try to be clear about what you're trying to do here - previously you'd just said that you needed to make sure the CODEC was powered down prior to the CPU being stopped but now you're adding additional stuff here.
Hrm, yes i did agreed with your sequence until I started to look at the other implications. However at least I was consistent in the commit messages about the sequence requirements (OMAP4 McPDM should be stopped after the codec's DAC/ADC).
Quoted 4 lines
Could you please clarify what exactly the system looks like here and what you need to do? I'm struggling to understand how you've got PDM output links providing clocks back into the CPU - usually a PDM output is two wires going in one direction.
McPDM uses 5 wires.
clks is coming from the codec, and this signal is used within OMAP4 McPDM as functional clock (we have frame sync, ul data, dl data, and clock loopback wires). Chapter 23.6.2.2 of OMAP4430_ES2.x_PUBLIC_TRM_vW.pdf
The sequence I'm looking for is:
1. pcm_trigger: stop DMA
2. DAPM sequence starts
3. DAC is turned off on the codec side
4. OMAP4 McPDM can be stopped - stop it
5. DAPM finishes up
6. codec can be turned off
Quoted 5 lines
I also don't entirely understand
why your current approach will be robust, though it should be an improvement on the original change to just put a delay in the shutdown. You can't rely onpmdown_timehappening at all as it's user configurable and only happens for some cases even when it's there.
I'm not relaying on the pmdown_time but I'm relying on DAPM to handle the power down of the cpu_dai. The pmdown_time does not matter anymore. I do not remember saying that it is robust, but I might meant that this approach needs small amount of code, and it is handled by a well tested/proven piece of code (DAPM).
Quoted 5 lines
Like I say I'm not convinced I understand what you need to do yet. It would be easier if we could merge the updated McPDM driver and worry about this separately; I don't understand why you can't just inline the event into the regular teardown (it will be noisy but it should at least run).
OK, let's take this part out for now.
I'll send a single patch for replacing the legacy driver with the new one, but without the pop avoiding delay magic.
--
Péter
Re: [PATCH v3 2/3] ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
Quoted 11 lines · P?ter Ujfalusi
Quoted 5 lines · On Monday 29 August 2011 11:16:04 Mark Brown wrote:
That's not what you said before... I did post the sequence I was suggesting and you seemed fine with it. Please try to be clear about what you're trying to do here - previously you'd just said that you needed to make sure the CODEC was powered down prior to the CPU being stopped but now you're adding additional stuff here.
Hrm, yes i did agreed with your sequence until I started to look at the other implications. However at least I was consistent in the commit messages about the sequence requirements (OMAP4 McPDM should be stopped after the codec's DAC/ADC).
Right, but there was an important additional bit.
Quoted 5 lines
Quoted 4 lines
Could you please clarify what exactly the system looks like here and what you need to do? I'm struggling to understand how you've got PDM output links providing clocks back into the CPU - usually a PDM output is two wires going in one direction.
Quoted 7 lines
The sequence I'm looking for is:
1.pcm_trigger: stop DMA
2. DAPM sequence starts
3. DAC is turned off on the codec side
4. OMAP4 McPDM can be stopped - stop it
5. DAPM finishes up
6. codec can be turned off
Actually I think this is fine with my suggestion so long as you make the CODEC SYSCLK visible to DAPM and have the machine driver turn it off at some later point in the shutdown process (eg, in shutdown()). That way the data paths will still be torn down by DAPM immediately but SYSCLK will still be generated.
Re: [PATCH v3 2/3] ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
Quoted 8 lines · On Saturday 03 September 2011 07:31:19 Mark Brown wrote:
Quoted 7 lines
The sequence I'm looking for is:
1.pcm_trigger: stop DMA
2. DAPM sequence starts
3. DAC is turned off on the codec side
4. OMAP4 McPDM can be stopped - stop it
5. DAPM finishes up
6. codec can be turned off
Quoted 5 lines
Actually I think this is fine with my suggestion so long as you make the CODEC SYSCLK visible to DAPM and have the machine driver turn it off at some later point in the shutdown process (eg, in
shutdown()). That way the data paths will still be torn down by DAPM immediately but SYSCLK will still be generated.
I need to think about this.
Not sure how it will affect our system, if we do not have pmdown_time in the future, when we add full ABE support.
As a side note: I have found an issue with my earlier proposal (DAPM_SUPPLY attached to the codec's DAC/ADC): I can end up turning off the host side McPDM during audio activity (by muting the outputs/inputs runtime). It has the side effect of not recovering :o (also DMA stops, since the dai is stopped)
I'll get back to you on this soon (probably with a patch).
--
Péter
Re: [PATCH v3 2/3] ASoC: soc-dapm: API to attach DAPM_SUPPLY to be used for dai
Quoted 11 lines · Péter Ujfalusi
Quoted 5 lines · On Saturday 03 September 2011 07:31:19 Mark Brown wrote:
Actually I think this is fine with my suggestion so long as you make the CODEC SYSCLK visible to DAPM and have the machine driver turn it off at some later point in the shutdown process (eg, in
shutdown()). That way the data paths will still be torn down by DAPM immediately but SYSCLK will still be generated.I need to think about this.
Not sure how it will affect our system, if we do not havepmdown_timein the future, when we add full ABE support.
pmdown_time is irrelevant here, it only inserts a delay in the sequence so if it's not there the delay just goes to zero and the sequence of events is the same but quicker.
PATCH v3 3/3 ASoC: omap-mcpdm: Replace legacy driver
In reply to Peter UjfalusiFrom: Misael Lopez Cruz <[email protected]>
Reasons for the replacement:
The current driver for McPDM was developed to support the legacy mode only. In preparation for the ABE support the current driver stack need the be replaced.
The new driver is much simpler, easier to extend, and it also fixes some of the issues with the old stack.
Main changes:
- single file for omap-mcpdm (mcpdm.c/h removed)
- Define names for registers, bits cleaned up, prefixed
- Full-duplex audio operation (arecord | aplay) has been fixed
- Less code
McPDM need to be turned off _after_ the codec's DAC/ADC has been powered down. This can be achieved by attaching DAPM_SUPPLY widget to the current dapm_context using the snd_soc_dapm_attach_dai_supply call.
The machine driver connects the "OMAP McPDM Interface" to the codec's DAC/ADC, so after audio activity we can be sure that the host side McPDM is turned off at the correct time (this takes place in the DAPM_SUPPLY's event handler).
--- sound/soc/omap/Makefile | 2 +- sound/soc/omap/mcpdm.c | 474 ------------------------- sound/soc/omap/mcpdm.h | 152 -------- sound/soc/omap/omap-mcpdm.c | 813 ++++++++++++++++++++++++++++--------------- sound/soc/omap/omap-mcpdm.h | 97 +++++ sound/soc/omap/sdp4430.c | 14 +- 6 files changed, 645 insertions(+), 907 deletions(-) delete mode 100644 sound/soc/omap/mcpdm.c delete mode 100644 sound/soc/omap/mcpdm.h rewrite sound/soc/omap/omap-mcpdm.c (46%) create mode 100644 sound/soc/omap/omap-mcpdm.h
sound/soc/omap/Makefile +1 -1
@@ -1,7 +1,7 @@ # OMAP Platform Support snd-soc-omap-objs := omap-pcm.o snd-soc-omap-mcbsp-objs := omap-mcbsp.o -snd-soc-omap-mcpdm-objs := omap-mcpdm.o mcpdm.o +snd-soc-omap-mcpdm-objs := omap-mcpdm.o snd-soc-omap-hdmi-objs := omap-hdmi.o obj-$(CONFIG_SND_OMAP_SOC) += snd-soc-omap.o
sound/soc/omap/mcpdm.c deleted +0 -474
474 lines not on this page · raw message
sound/soc/omap/mcpdm.h deleted +0 -152
152 lines not on this page · raw message
sound/soc/omap/omap-mcpdm.c +534 -279
813 lines not on this page · raw message
sound/soc/omap/omap-mcpdm.h new file +97 -0
97 lines not on this page · raw message
sound/soc/omap/sdp4430.c +13 -1
@@ -32,7 +32,7 @@#include <plat/hardware.h> #include <plat/mux.h> -#include "mcpdm.h" +#include "omap-mcpdm.h" #include "omap-pcm.h" #include "../codecs/twl6040.h"
@@ -115,6 +115,14 @@ static const struct snd_soc_dapm_route audio_map[] = {/* Aux/FM Stereo In: AFML, AFMR */ {"AFML", NULL, "FM Stereo In"}, {"AFMR", NULL, "FM Stereo In"}, + +/* OMAP4 McPDM interface */ + {"ADC Left", NULL, "OMAP McPDM Interface"}, + {"ADC Right", NULL, "OMAP McPDM Interface"}, + {"HSDAC Left", NULL, "OMAP McPDM Interface"}, + {"HSDAC Right", NULL, "OMAP McPDM Interface"}, + {"HFDAC Left", NULL, "OMAP McPDM Interface"}, + {"HFDAC Right", NULL, "OMAP McPDM Interface"}, };static int sdp4430_twl6040_init (struct snd_soc_pcm_runtime *rtd)
@@ -129,6 +137,10 @@ static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)if (ret)return ret; + ret =omap_mcpdm_add_dapm_widget (rtd); +if (ret) +return ret; +/* Set up SDP4430 specific audio path audio_map */ snd_soc_dapm_add_routes (dapm, audio_map,ARRAY_SIZE (audio_map));
Signature · 1 line
1.7.6.1