ALSA:AT91SAM9G20: Add support(DAI) for wolfson8731
Subsystems (3)
Hi,
So here is a patch to add support for the wolfson 8731 on the at91sam9g20 evaluation board. Any comments will be welcomed!!
Regards,
Sedji
sound/soc/at91/Kconfig | 19 +- sound/soc/at91/Makefile | 6 + sound/soc/at91/at91-ssc.h | 1 + sound/soc/at91/atmel_ssc_dai.c | 715 ++++++++++++++++++++++++++++++++++ sound/soc/at91/sam9g20_wm8731.c | 290 ++++++++++++++ sound/soc/codecs/Kconfig | 2 +- 6 files changed, 1031 insertions(+), 2 deletions(-)
sound/soc/at91/Kconfig +18 -1
@@ -7,7 +7,15 @@ config SND_AT91_SOC to select the audio interfaces to support below. config SND_AT91_SOC_SSC - tristate + tristate "at91 soc ssc" + +config SND_ATMEL_SOC_SSC + tristate "ATMEL SoC ssc dai" + depends on ATMEL_SSC + help + Say Y or M if you want to add support for codecs the + ATMEL SSC interface(interface between at91sam9g20 and + WM8731 for instance). config SND_AT91_SOC_ETI_B1_WM8731 tristate "SoC Audio support for WM8731-based Endrelia ETI-B1 boards"
@@ -18,6 +26,15 @@ config SND_AT91_SOC_ETI_B1_WM8731 Say Y if you want to add support for SoC audio on WM8731-based Endrelia Technologies Inc ETI-B1 or ETI-C1 boards. +config SND_AT91_SOC_SAM9G20_WM8731 + tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board" + depends on ATMEL_SSC && ARCH_AT91SAM9G20 && SND_AT91_SOC + select SND_ATMEL_SOC_SSC + select SND_SOC_WM8731 + help + Say Y if you want to add support for SoC audio on WM8731-based + AT91sam9g20 evaluation board. + config SND_AT91_SOC_ETI_SLAVE bool "Run codec in slave Mode on Endrelia boards" depends on SND_AT91_SOC_ETI_B1_WM8731
sound/soc/at91/Makefile +6 -0
@@ -1,11 +1,17 @@ # AT91 Platform Support snd-soc-at91-objs := at91-pcm.o snd-soc-at91-ssc-objs := at91-ssc.o +snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o + obj-$(CONFIG_SND_AT91_SOC) += snd-soc-at91.o obj-$(CONFIG_SND_AT91_SOC_SSC) += snd-soc-at91-ssc.o +obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o + # AT91 Machine Support snd-soc-eti-b1-wm8731-objs := eti_b1_wm8731.o +snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o obj-$(CONFIG_SND_AT91_SOC_ETI_B1_WM8731) += snd-soc-eti-b1-wm8731.o +obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o
sound/soc/at91/at91-ssc.h +1 -0
@@ -22,6 +22,7 @@#define AT91SSC_RCMR_PERIOD 2/* BCLK divider for receive FS */ extern struct snd_soc_dai at91_ssc_dai[]; +extern struct snd_soc_dai atmel_ssc_dai[];#endif /* _AT91_SSC_H */
sound/soc/at91/atmel_ssc_dai.c new file +715 -0
715 lines not on this page · raw message
sound/soc/at91/sam9g20_wm8731.c new file +290 -0
290 lines not on this page · raw message
sound/soc/codecs/Kconfig +1 -1
@@ -12,7 +12,7 @@ config SND_SOC_WM8510 tristate config SND_SOC_WM8731 - tristate + tristate "WM8731" config SND_SOC_WM8750 tristate
Quoted 2 lines · Sedji Gaouaou
So here is a patch to add support for the wolfson 8731 on the at91sam9g20 evaluation board. Any comments will be welcomed!!
Thanks! Overall in terms of code quality this patch looks very good - see below for some comments but they're all very minor.
The only major issue I see with the patch is a documentation one: it's not clear to me reading the code how the atmel_ssc DAI driver relates to the existing at91_ssc driver. It may be that this is something that's obvious to someone familiar with the at91 hardware but just looking at the code it's not clear to me what the difference is between the two and when each should be used.
Looking at the code they appear to be similar to the point where they should be the same driver but it's entirely possible that I'm missing something here. I've CCed in Frank Mandarino who did the existing AT91 support. If they should be separate drivers then some comments should be added in the driver and the Kconfig help text explaning the situation.
Please include a changelog entry and a Signed-off-by - see Documentation/SubmittingPatches for details of how things should be formatted. It's also helpful to check your patches with scripts/checkpatch.pl which will pick up things like that and also coding style issues (there's a small number of them in your patch).
sound/soc/at91/Kconfig config SND_AT91_SOC · line 10
Quoted 8 lines
sound/soc/at91/Kconfig +1
-1@@ -7,7 +7,15 @@ config SND_AT91_SOC to select the audio interfaces to support below. config SND_AT91_SOC_SSC - tristate + tristate "at91 soc ssc"
If this is intended to be user visible (rather than selected by the machine drivers) it'd be nice to provide some help text for it - it's not terribly clear at the minute.
sound/soc/at91/Kconfig config SND_AT91_SOC · line 18
Quoted 7 lines
sound/soc/at91/Kconfig +7
-0+config SND_ATMEL_SOC_SSC + tristate "ATMEL SoC ssc dai" + depends on ATMEL_SSC + help + Say Y or M if you want to add support for codecs the + ATMEL SSC interface(interface between at91sam9g20 and + WM8731 for instance).
Just a non-native English thing but how about:
Say Y or M to enable support for codecs attached to the ATMEL SSC interface. You will also need to select the individual machine drivers to support below.
sound/soc/at91/Kconfig config SND_AT91_SOC · line 19
Quoted 2 lines
sound/soc/at91/Kconfig +2
-0+snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o +
Very minor but please don't add these extra blank lines.
Quoted 15 lines
sound/soc/at91/atmel_ssc_dai.c new file +9
-0@@ -0,0 +1,715 @@ +/* +* atmel_ssc_dai.c -- ALSA SoC ATMEL SSC Audio Layer Platform driver +* +* Copyright (C) 2005 SAN People +* Copyright (C) 2008 Atmel +* +* Author: Sedji Gaouaou <[email protected]> +* ATMEL CORP. +*
sound/soc/at91/atmel_ssc_dai.c line 55
Quoted 10 lines
sound/soc/at91/atmel_ssc_dai.c new file +9
-0+* Based on at91-ssc.c by +* Frank Mandarino <[email protected]> +* Based on pxa2xx Platform drivers by +* Liam Girdwood <[email protected]> +#if 0 +#define DBG(x...) printk(KERN_DEBUG "atmel_ssc_dai:" x) +#else +#define DBG(x...) +#endif
Please use the standard pr_dbg() (or, if possible, dev_dbg()) for this. Quite a lot of the existing drivers do this but they're gradually being converted away and it'd be good to avoid adding any more.
Quoted 11 lines
sound/soc/at91/atmel_ssc_dai.c new file +11
-0+/* +* Record SSC clock dividers for use in hw_params(). +*/ +static int atmel_ssc_set_dai_clkdiv (struct snd_soc_dai *cpu_dai, +int div_id,int div) +{ +struct atmel_ssc_info *ssc_p = &ssc_info[cpu_dai->id]; + +switch (div_id) { +case AT91SSC_CMR_DIV : +/*
sound/soc/at91/atmel_ssc_dai.c line 313
Quoted 10 lines
sound/soc/at91/atmel_ssc_dai.c new file +10
-0+* The same master clock divider is used for both +* transmit and receive, so if a value has already +* been set, it must match this value. +*/ +if (ssc_p->cmr_div ==0 ) + ssc_p->cmr_div = div; +else +if (div != ssc_p->cmr_div) +return -EBUSY ; +break ;
What happens if the user wants to change the master clock divider at runtime - for example, when changing sample rates?
sound/soc/at91/atmel_ssc_dai.c line 465
Quoted 3 lines
sound/soc/at91/atmel_ssc_dai.c new file +3
-0+ start_event = channels ==1 + ?4 + :7 ;
This would be much clearer if it were expanded into multiple statements.
sound/soc/at91/atmel_ssc_dai.c line 618
Quoted 7 lines
sound/soc/at91/atmel_ssc_dai.c new file +7
-0+#ifdef CONFIG_PM +#define atmel_ssc_suspend NULL +#define atmel_ssc_resume NULL +#else +#define atmel_ssc_suspend NULL +#define atmel_ssc_resume NULL +#endif
These may as well be removed - if someone implements suspend/resume support they can add them then then.
sound/soc/at91/atmel_ssc_dai.c
Quoted 5 lines
sound/soc/at91/atmel_ssc_dai.c new file +5
-0+#if 0 +#define DBG(x...) printk(KERN_INFO "at91sam9g20ek_wm8731: " x) +#else +#define DBG(x...) +#endif
Again, please replace with the standard pr_dbg() macro.
sound/soc/at91/atmel_ssc_dai.c
Quoted 3 lines
sound/soc/at91/atmel_ssc_dai.c new file +3
-0+static struct wm8731_setup_data at91sam9g20ek_wm8731_setup = { + .i2c_address =0x1b , +};
Is the codec on I2C bus zero? If not then the i2c_bus field should also be initialised here. This was added as part of the recent patches converting the codec drivers to the new I2C registration interface - see the topic/asoc branch of Takashi's tree:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git
for the latest code queued for merge in 2.6.28.
sound/soc/codecs/Kconfig config SND_SOC_WM8510 · line 15
Quoted 10 lines
sound/soc/codecs/Kconfig +1
-1@@ -12,7 +12,7 @@ config SND_SOC_WM8510 tristate config SND_SOC_WM8731 - tristate + tristate "WM8731"
This shouldn't be a user-visible config option - codec drivers are only useful in conjunction with a machine driver describing how they are connected to the system so there's no need to expose the configuration to users (there is an all codecs config option which can be used for test builds).
Quoted 7 lines · Mark Brown
The only major issue I see with the patch is a documentation one: it's not clear to me reading the code how the
atmel_sscDAI driver relates to the existingat91_sscdriver. It may be that this is something that's obvious to someone familiar with the at91 hardware but just looking at the code it's not clear to me what the difference is between the two and when each should be used.
Quoted 6 lines
Looking at the code they appear to be similar to the point where they should be the same driver but it's entirely possible that I'm missing something here. I've CCed in Frank Mandarino who did the existing AT91 support. If they should be separate drivers then some comments should be added in the driver and the
Kconfighelp text explaning the situation.
I agree that the drivers should be combined. Unfortunately, at this time I am unable to contribute to this effort.
Quoted 16 lines
Quoted 16 lines
sound/soc/at91/atmel_ssc_dai.c new file +16
-0+/* +* Record SSC clock dividers for use in hw_params(). +*/ +static int atmel_ssc_set_dai_clkdiv (struct snd_soc_dai *cpu_dai, +int div_id,int div) +{ +struct atmel_ssc_info *ssc_p = &ssc_info[cpu_dai->id]; + +switch (div_id) { +case AT91SSC_CMR_DIV : +/* +* The same master clock divider is used for both +* transmit and receive, so if a value has already +* been set, it must match this value. +*/ +if (ssc_p->cmr_div ==0 )
Quoted 8 lines
sound/soc/at91/atmel_ssc_dai.c line 313
Quoted 5 lines
sound/soc/at91/atmel_ssc_dai.c new file +5
-0+ ssc_p->cmr_div = div; + else + if (div != ssc_p->cmr_div) + return -EBUSY; +break ;What happens if the user wants to change the master clock divider at runtime - for example, when changing sample rates?
This is code from at91-ssc.c. I really didn't consider the case of changing the sample rate on an open substream. This logic could be updated to allow the new divider value if there is only one substream open.
Quoted 6 lines
sound/soc/at91/atmel_ssc_dai.c line 465
Quoted 4 lines
sound/soc/at91/atmel_ssc_dai.c new file +3
-0+ start_event = channels ==1 + ?4 + :7 ;This would be much clearer if it were expanded into multiple statements.
This was a little clearer in at91-ssc.c:
start_event = channels == 1
? AT91_SSC_START_FALLING_RF
: AT91_SSC_START_EDGE_RF;Perhaps these constant definitions are no longer available it the latest kernel. Are there updated definitions to use instead of magic numbers?
Also, I'm fine with using multiple statements if that helps readability.
Quoted 11 lines
sound/soc/at91/atmel_ssc_dai.c line 618
Quoted 8 lines
sound/soc/at91/atmel_ssc_dai.c new file +7
-0+#ifdef CONFIG_PM +#define atmel_ssc_suspend NULL +#define atmel_ssc_resume NULL +#else +#define atmel_ssc_suspend NULL +#define atmel_ssc_resume NULL +#endif These may as well be removed - if someone implements suspend/resume support they can add them then then.
Is there a reason that suspend/resume was removed? It is really important for embedded systems.
Regards,
../fam
Signature · 3 lines
Frank Mandarino fmandarino(a)endrelia.com Endrelia Technologies Inc. Toronto, Ontario, Canada
Quoted 20 lines · Frank Mandarino
Quoted 9 lines · Mark Brown
Quoted 9 lines
sound/soc/at91/atmel_ssc_dai.c new file +9
-0+ +switch (div_id) { +case AT91SSC_CMR_DIV : +/* +* The same master clock divider is used for both +* transmit and receive, so if a value has already +* been set, it must match this value. +*/ +if (ssc_p->cmr_div ==0 )Quoted 8 lines
sound/soc/at91/atmel_ssc_dai.c line 313
Quoted 5 lines
sound/soc/at91/atmel_ssc_dai.c new file +5
-0+ ssc_p->cmr_div = div; + else + if (div != ssc_p->cmr_div) + return -EBUSY; +break ;What happens if the user wants to change the master clock divider at runtime - for example, when changing sample rates?
Quoted 3 lines
This is code from
at91-ssc.c. I really didn't consider the case of changing the sample rate on an open substream. This logic could be updated to allow the new divider value if there is only one substream open.
Ah, right - on further inspection I see that cmr_div is reset when the stream is shut down. That's fine since it means that the clocks can be reconfigured when reopening the device which is the case I was worried about.
Changing the dividers on an active stream is unlikely to work well so it's perfectly reasonable to not support it.
Quoted 8 lines
Quoted 5 lines
sound/soc/at91/atmel_ssc_dai.c line 465
Quoted 3 lines
sound/soc/at91/atmel_ssc_dai.c new file +3
-0+ start_event = channels ==1 + ?4 + :7 ;This would be much clearer if it were expanded into multiple statements.
This was a little clearer in
at91-ssc.c:
Quoted 8 lines
start_event = channels == 1 ? AT91_SSC_START_FALLING_RF : AT91_SSC_START_EDGE_RF;Perhaps these constant definitions are no longer available it the latest kernel. Are there updated definitions to use instead of magic numbers?
Also, I'm fine with using multiple statements if that helps readability.
I wasn't so worried about the magic numbers as the combination of assignment and an equality test without even any brackets. I can see what's going on but it's certainly not the most transparent way of writing it.
Quoted 5 lines
Quoted 2 lines
These may as well be removed - if someone implements suspend/resume support they can add them then then.
Is there a reason that suspend/resume was removed? It is really important for embedded systems.
Yeah, I did wonder, though there are plenty of embedded systems that aren't particular power sensitive for one reason or another.
Hi Frank,
Quoted 16 lines · Frank Mandarino
Quoted 7 lines · Mark Brown
The only major issue I see with the patch is a documentation one: it's not clear to me reading the code how the
atmel_sscDAI driver relates to the existingat91_sscdriver. It may be that this is something that's obvious to someone familiar with the at91 hardware but just looking at the code it's not clear to me what the difference is between the two and when each should be used.Quoted 6 lines
Looking at the code they appear to be similar to the point where they should be the same driver but it's entirely possible that I'm missing something here. I've CCed in Frank Mandarino who did the existing AT91 support. If they should be separate drivers then some comments should be added in the driver and the
Kconfighelp text explaning the situation.
Quoted 3 lines
I agree that the drivers should be combined. Unfortunately, at this time I am unable to contribute to this effort.
I agree with you as well. I wanted to use the drivers/misc/atmel-ssc in the dai because it is a common arch between atmel ARM and AVR core. I will have a look at the at91-ssc code and at the eti_b1_wm8731.c file to see what changes should be done.
Quoted 6 lines
Quoted 5 lines
sound/soc/at91/atmel_ssc_dai.c line 465
Quoted 4 lines
sound/soc/at91/atmel_ssc_dai.c new file +3
-0+ start_event = channels ==1 + ?4 + :7 ;This would be much clearer if it were expanded into multiple statements.
Quoted 8 lines
This was a little clearer in
at91-ssc.c:start_event = channels == 1 ? AT91_SSC_START_FALLING_RF : AT91_SSC_START_EDGE_RF;Perhaps these constant definitions are no longer available it the latest kernel. Are there updated definitions to use instead of magic numbers?
My mistake, I will use your constant def.
Quoted 11 lines
Quoted 10 lines
sound/soc/at91/atmel_ssc_dai.c line 618
Quoted 8 lines
sound/soc/at91/atmel_ssc_dai.c new file +7
-0+#ifdef CONFIG_PM +#define atmel_ssc_suspend NULL +#define atmel_ssc_resume NULL +#else +#define atmel_ssc_suspend NULL +#define atmel_ssc_resume NULL +#endif These may as well be removed - if someone implements suspend/resume support they can add them then then.
Quoted 2 lines
Is there a reason that suspend/resume was removed? It is really important for embedded systems.
I removed resume/suspend because I didn't have the time to write it... I wanted to add it in a next patch, but maybe I shoul do it now.
Mark, concerning your other comments I am working on it. I will send another patch as soon as it is finished.
Regards,
Sedji
Quoted 4 lines · Sedji Gaouaou
I agree with you as well. I wanted to use the
drivers/misc/atmel-sscin the dai because it is a common arch between atmel ARM and AVR core. I will have a look at the at91-ssc code and at theeti_b1_wm8731.cfile to see what changes should be done.
If your intention is to produce a combined driver which works for both AVR32 and AT91 (which would be excellent!) then it'd probably best to create a new directory called atmel or something. The existing at91 and avr32 code could then either be merged into that directory or changed to reference it with any processor-specific glue that's needed.
Also CCing Geoffrey Wossum who did the AVR32 code (based on the AT91 work Frank did).
Quoted 2 lines
I removed resume/suspend because I didn't have the time to write it... I wanted to add it in a next patch, but maybe I shoul do it now.
Either was is OK.
Quoted 6 lines · Mark Brown
If your intention is to produce a combined driver which works for both AVR32 and AT91 (which would be excellent!) then it'd probably best to create a new directory called atmel or something. The existing at91 and avr32 code could then either be merged into that directory or changed to reference it with any processor-specific glue that's needed.
I am not plannig to produce a common audio driver. I just wanted to use a common ssc driver. Anyway I will look at how can I change at91-ssc and if it is doable.
Cheers,
Sedji
Quoted 9 lines · Sedji Gaouaou
Mark Brown a ?crit :
Quoted 3 lines
create a new directory called atmel or something. The existing at91 and avr32 code could then either be merged into that directory or changed to reference it with any processor-specific glue that's needed.
I am not plannig to produce a common audio driver. I just wanted to use a common ssc driver. Anyway I will look at how can I change at91-ssc and if it is doable.
That sounds like the case I'm talking about with common code in an atmel directory and other, processor-specific, stuff in the at91 and avr32 directories - the idea was that if it was common code then it shouldn't be in a processor-specific directory.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: Does LKML accept non-ASOC audio driver?
Quoted 1 line · Cliff Cai
We(blackfin arch) have several audio codec drivers which are written in alsa style,actually they are hard to transfer to asoc.
What are the problems with this - is it a case of the hardware not fitting the model well or are there other difficulties with the ASoC framework?
Quoted 2 lines
I also saw that there are several arch-based directories in
sound/, e.g.sound/arm, does this mean non-asoc driver is also accepted currently?
Yes, ASoC only needs to be used in situations where it makes sense to do so. If the hardware doesn't have separate codec and DMA controllers, for example, then it wouldn't make much sense to try to shoehorn it into ASoC.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: Does LKML accept non-ASOC audio driver?
Quoted 2 lines · Cliff Cai
Yes,the hardware doesn't have seperate codec control,
we use the same bus as for DMA transmission to configure the codec( e.g.AD73311)
That shouldn't be an issue, AC97 does the same thing but...
Quoted 1 line
and after configuring it,the codec will enter data mode,and is not configurable any more.
...this might be more of an issue. That said, is the SPORT on the DSP likely to be used with smarter codecs (it looks like it's already used by your existing ASoC drivers but perhaps differently?)? If it is then it's probably worth fitting it in to ASoC in order to avoid having two distinct drivers for it. It should be possible for the machine driver to do the codec setup when it probes and then just have a dumb DAI for the codec with no operations (actually, it's worth adding that dumb codec driver anyway - it's not like dumb ADCs and DACs are uncommon).
If there's not much code to reuse then a simpler driver for the SPORT outside of ASoC with just a platform data hook for doing the codec initialisation would probably be the best bet. Could you point me at the existing drivers?
Actually, looking at the datasheet for the AD73311 it is actually possible to reconfigure the codec at run time at the expense of one data bit.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: Does LKML accept non-ASOC audio driver?
Quoted 6 lines · Cliff Cai
Quoted 3 lines
outside of ASoC with just a platform data hook for doing the codec initialisation would probably be the best bet. Could you point me at the existing drivers?
One thing I should let you know ,the initialisation code will highly depend on the low-level SPORT operation code in blackfin arch.
That's absolutely fine - the machine driver is entirely specific to the hardware it's connecting so things like this are not a problem. It already explicitly references the codec and machine drivers anyway.
Quoted 6 lines
Quoted 3 lines
Actually, looking at the datasheet for the AD73311 it is actually possible to reconfigure the codec at run time at the expense of one data bit.
You are right,but it's not a good way in real use,since we need to format every PCM sample in that mode.
Yeah, without trusting the application data to leave the bit clear it'd need some glue in hardware to force the MSB low when not doing control operations.