New ASoC Drivers for ADI AD1938 codec
Subsystems (3)
PATCH 1/1 New ASoC Drivers for ADI AD1938 codec
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)
--- include/sound/soc-dai.h | 1 + sound/soc/blackfin/Kconfig | 46 +++- sound/soc/blackfin/Makefile | 6 + sound/soc/blackfin/bf5xx-ad1938.c | 178 ++++++++++++ sound/soc/blackfin/bf5xx-tdm-pcm.c | 330 ++++++++++++++++++++++ sound/soc/blackfin/bf5xx-tdm-pcm.h | 21 ++ sound/soc/blackfin/bf5xx-tdm.c | 295 +++++++++++++++++++ sound/soc/blackfin/bf5xx-tdm.h | 14 + sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/ad1938.c | 548 ++++++++++++++++++++++++++++++++++++ sound/soc/codecs/ad1938.h | 68 +++++ 12 files changed, 1512 insertions(+), 1 deletions(-) create mode 100644 sound/soc/blackfin/bf5xx-ad1938.c create mode 100644 sound/soc/blackfin/bf5xx-tdm-pcm.c create mode 100644 sound/soc/blackfin/bf5xx-tdm-pcm.h create mode 100644 sound/soc/blackfin/bf5xx-tdm.c create mode 100644 sound/soc/blackfin/bf5xx-tdm.h create mode 100644 sound/soc/codecs/ad1938.c create mode 100644 sound/soc/codecs/ad1938.h
include/sound/soc-dai.h +1 -0
@@ -30,6 +30,7 @@ struct snd_pcm_substream;#define SND_SOC_DAIFMT_DSP_A 3/* L data msb after FRM LRC */ #define SND_SOC_DAIFMT_DSP_B 4/* L data msb during FRM LRC */ #define SND_SOC_DAIFMT_AC97 5/* AC97 */ +#define SND_SOC_DAIFMT_SPORT_TDM 6/* SPORT TDM for ADI parts */ /* left and right justified also known as MSB and LSB respectively */ #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
sound/soc/blackfin/Kconfig +45 -1
66 lines not on this page · raw message
sound/soc/blackfin/Makefile +6 -0
@@ -1,21 +1,27 @@ # Blackfin Platform Support snd-bf5xx-ac97-objs := bf5xx-ac97-pcm.o snd-bf5xx-i2s-objs := bf5xx-i2s-pcm.o +snd-bf5xx-tdm-objs := bf5xx-tdm-pcm.o snd-soc-bf5xx-sport-objs := bf5xx-sport.o snd-soc-bf5xx-ac97-objs := bf5xx-ac97.o snd-soc-bf5xx-i2s-objs := bf5xx-i2s.o +snd-soc-bf5xx-tdm-objs := bf5xx-tdm.o obj-$(CONFIG_SND_BF5XX_AC97) += snd-bf5xx-ac97.o obj-$(CONFIG_SND_BF5XX_I2S) += snd-bf5xx-i2s.o +obj-$(CONFIG_SND_BF5XX_TDM) += snd-bf5xx-tdm.o obj-$(CONFIG_SND_BF5XX_SOC_SPORT) += snd-soc-bf5xx-sport.o obj-$(CONFIG_SND_BF5XX_SOC_AC97) += snd-soc-bf5xx-ac97.o obj-$(CONFIG_SND_BF5XX_SOC_I2S) += snd-soc-bf5xx-i2s.o +obj-$(CONFIG_SND_BF5XX_SOC_TDM) += snd-soc-bf5xx-tdm.o # Blackfin Machine Support snd-ad1980-objs := bf5xx-ad1980.o snd-ssm2602-objs := bf5xx-ssm2602.o snd-ad73311-objs := bf5xx-ad73311.o +snd-ad1938-objs := bf5xx-ad1938.o obj-$(CONFIG_SND_BF5XX_SOC_AD1980) += snd-ad1980.o obj-$(CONFIG_SND_BF5XX_SOC_SSM2602) += snd-ssm2602.o obj-$(CONFIG_SND_BF5XX_SOC_AD73311) += snd-ad73311.o +obj-$(CONFIG_SND_BF5XX_SOC_AD1938) += snd-ad1938.o
sound/soc/blackfin/bf5xx-ad1938.c new file +178 -0
178 lines not on this page · raw message
sound/soc/blackfin/bf5xx-tdm-pcm.c new file +330 -0
330 lines not on this page · raw message
sound/soc/blackfin/bf5xx-tdm-pcm.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* linux/sound/arm/bf5xx-tdm-pcm.h -- ALSA PCM interface for the Blackfin +* +* Copyright 2009 Analog Device Inc. +* +* 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 _BF5XX_TDM_PCM_H +#define _BF5XX_TDM_PCM_H + +struct bf5xx_pcm_dma_params { +char *name;/* stream identifier */ +}; + +/* platform data */ +extern struct snd_soc_platform bf5xx_tdm_soc_platform; + +#endif
sound/soc/blackfin/bf5xx-tdm.c new file +295 -0
295 lines not on this page · raw message
sound/soc/blackfin/bf5xx-tdm.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* linux/sound/arm/bf5xx-i2s.h +* +* 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 _BF5XX_TDM_H +#define _BF5XX_TDM_H + +extern struct snd_soc_dai bf5xx_tdm_dai; + +#endif
sound/soc/codecs/Kconfig +4 -0
@@ -12,6 +12,7 @@ config SND_SOC_ALL_CODECS tristate "Build all ASoC CODEC drivers" select SND_SOC_L3 select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS + select SND_SOC_AD1938 if SPI_MASTER select SND_SOC_AD1939 if I2C select SND_SOC_AD1980 if SND_SOC_AC97_BUS select SND_SOC_AD73311 if I2C
@@ -70,6 +71,9 @@ config SND_SOC_ALL_CODECS config SND_SOC_AC97_CODEC tristate +config SND_SOC_AD1938 + tristate + config SND_SOC_AD1939 tristate
sound/soc/codecs/Makefile +2 -0
@@ -1,4 +1,5 @@ snd-soc-ac97-objs := ac97.o +snd-soc-ad1938-objs := ad1938.o snd-soc-ad1939-objs := ad1939.o snd-soc-ad1980-objs := ad1980.o snd-soc-ak4535-objs := ak4535.o
@@ -49,6 +50,7 @@ snd-soc-wm9712-objs := wm9712.o snd-soc-wm9713-objs := wm9713.o obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o +obj-$(CONFIG_SND_SOC_AD1938) += snd-soc-ad1938.o obj-$(CONFIG_SND_SOC_AD1939) += snd-soc-ad1939.o obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
sound/soc/codecs/ad1938.c new file +548 -0
548 lines not on this page · raw message
sound/soc/codecs/ad1938.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
1.5.6.3
Quoted 17 lines · Barry Song
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)Signed-off-by Barry Song <[email protected]>--- include/sound/soc-dai.h | 1 + sound/soc/blackfin/Kconfig | 46 +++- sound/soc/blackfin/Makefile | 6 + sound/soc/blackfin/bf5xx-ad1938.c | 178 ++++++++++++ sound/soc/blackfin/bf5xx-tdm-pcm.c | 330 ++++++++++++++++++++++ sound/soc/blackfin/bf5xx-tdm-pcm.h | 21 ++ sound/soc/blackfin/bf5xx-tdm.c | 295 +++++++++++++++++++ sound/soc/blackfin/bf5xx-tdm.h | 14 + sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/ad1938.c | 548 ++++++++++++++++++++++++++++++++++++ sound/soc/codecs/ad1938.h | 68 +++++
Quoted 9 lines
12 files changed, 1512 insertions(+), 1 deletions(-) create mode 100644 sound/soc/blackfin/bf5xx-ad1938.c create mode 100644 sound/soc/blackfin/bf5xx-tdm-pcm.c create mode 100644 sound/soc/blackfin/bf5xx-tdm-pcm.h create mode 100644 sound/soc/blackfin/bf5xx-tdm.c create mode 100644 sound/soc/blackfin/bf5xx-tdm.h create mode 100644 sound/soc/codecs/ad1938.c create mode 100644 sound/soc/codecs/ad1938.h
Could you break this patch into smaller chunks. This should make it easier to review and apply.
Thanks
Liam
Quoted 28 lines · Liam Girdwood
Quoted 17 lines · Barry Song
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)Signed-off-by Barry Song <[email protected]>--- include/sound/soc-dai.h | 1 + sound/soc/blackfin/Kconfig | 46 +++- sound/soc/blackfin/Makefile | 6 + sound/soc/blackfin/bf5xx-ad1938.c | 178 ++++++++++++ sound/soc/blackfin/bf5xx-tdm-pcm.c | 330 ++++++++++++++++++++++ sound/soc/blackfin/bf5xx-tdm-pcm.h | 21 ++ sound/soc/blackfin/bf5xx-tdm.c | 295 +++++++++++++++++++ sound/soc/blackfin/bf5xx-tdm.h | 14 + sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/ad1938.c | 548 ++++++++++++++++++++++++++++++++++++ sound/soc/codecs/ad1938.h | 68 +++++Quoted 9 lines
12 files changed, 1512 insertions(+), 1 deletions(-) create mode 100644 sound/soc/blackfin/bf5xx-ad1938.c create mode 100644 sound/soc/blackfin/bf5xx-tdm-pcm.c create mode 100644 sound/soc/blackfin/bf5xx-tdm-pcm.h create mode 100644 sound/soc/blackfin/bf5xx-tdm.c create mode 100644 sound/soc/blackfin/bf5xx-tdm.h create mode 100644 sound/soc/codecs/ad1938.c create mode 100644 sound/soc/codecs/ad1938.h
Quoted 2 lines
Could you break this patch into smaller chunks. This should make it easier to review and apply.
and also add a description for each patch in your series.
Thanks
Liam
Quoted 3 lines · Barry Song
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)
As Liam said you really need to submit this as a patch series rather than as a single big patch - as your commit log here indicates you've got several different things going on here.
include/sound/soc-dai.h struct snd_pcm_substream; · line 33
Quoted 6 lines
+++
b/include/sound/soc-dai.hinclude/sound/soc-dai.h +1
-0@@ -30,6 +30,7 @@ struct snd_pcm_substream;#define SND_SOC_DAIFMT_DSP_A 3/* L data msb after FRM LRC */ #define SND_SOC_DAIFMT_DSP_B 4/* L data msb during FRM LRC */ #define SND_SOC_DAIFMT_AC97 5/* AC97 */ +#define SND_SOC_DAIFMT_SPORT_TDM 6/* SPORT TDM for ADI parts */
If you're going to add a new DAI format that really needs more explanation than this explaining what the DAI format is. It'd be very surprising to see hardware needing a new format.
Looking at the datasheet for the ad1938 it appears that the actual format here is just normal I2S with TDM. This does not need a new DAI format or new CPU DAI, you just need to add suport for TDM to the Blackfin I2S driver. The format is fairly standard and implemented by a number of other devices.
See set_tdm_slot() for setting up the higher channel counts - there's some ongoing revisions to that API so you'll want to also ensure that the code is set up so that it can cope with specification of the sample width for each slot in set_tdm_slot().
Given this I've only looked at the CODEC driver below.
sound/soc/codecs/ad1938.c line 13
Quoted 9 lines
sound/soc/codecs/ad1938.c new file +3
-0+* +* Revision history +* 4 June 2009 Initial version.
Don't include this, git provides code history for us.
sound/soc/codecs/ad1938.c line 32
Quoted 4 lines
sound/soc/codecs/ad1938.c new file +4
-0+struct snd_soc_device *ad1938_socdev; + +/* dac de-emphasis enum control */ +static const char *ad1938_deemp[] = {"flat" ,"48kHz" ,"44.1kHz" ,"32kHz" };
For consistency with other drivers "flat" should be "None".
sound/soc/codecs/ad1938.c line 42
Quoted 5 lines
sound/soc/codecs/ad1938.c new file +5
-0+/* AD1938 volume/mute/de-emphasis etc. controls */ +static const struct snd_kcontrol_new ad1938_snd_controls[] = { +/* DAC volume control */ +SOC_SINGLE ("DAC L1 Volume" ,AD1938_DAC_L1_VOL ,0 ,0xFF ,1 ), +SOC_SINGLE ("DAC R1 Volume" ,AD1938_DAC_R1_VOL ,0 ,0xFF ,1 ),
These (and the other stereo pairs below) should be SOC_DOUBLE_R(). This allows ALSA to represent them as stereo controls to applications rather than as two separate controls. You should also provide TLV information so actually SOC_DOUBLE_R_TLV() if possible.
sound/soc/codecs/ad1938.c line 52
Quoted 3 lines
sound/soc/codecs/ad1938.c new file +3
-0+/* DAC mute control */ +SOC_SINGLE ("DAC L1 Switch" ,AD1938_DAC_CHNL_MUTE ,0 ,1 ,1 ), + SOC_SINGLE("DAC R1 Switch", AD1938_DAC_CHNL_MUTE, 1, 1, 1),
These should be stereo controls too - SOC_DOUBLE() since they're in the same register.
sound/soc/codecs/ad1938.c line 62
Quoted 3 lines
sound/soc/codecs/ad1938.c new file +3
-0+/* ADC mute control */ +SOC_SINGLE ("ADC L1 Switch" ,AD1938_ADC_CTRL0 ,ADC0_MUTE ,1 ,1 ), + SOC_SINGLE("ADC R1 Switch", AD1938_ADC_CTRL0, ADC1_MUTE, 1, 1),
These too.
sound/soc/codecs/ad1938.c line 70
Quoted 2 lines
sound/soc/codecs/ad1938.c new file +2
-0+/* DAC de-emphasis */ + SOC_ENUM("Playback Deemphasis", ad1938_enum[0]),
Don't put your enums in an array, use named variables for them. This makes drivers easier to maintian when you get a lot of enums.
sound/soc/codecs/ad1938.c line 80
Quoted 7 lines
sound/soc/codecs/ad1938.c new file +7
-0+static int ad1938_add_controls (struct snd_soc_codec *codec) +{ +int err, i; + +for (i =0 ; i <ARRAY_SIZE (ad1938_snd_controls); i++) { + err =snd_ctl_add (codec->card, +snd_soc_cnew (&ad1938_snd_controls[i], codec,NULL ));
Use snd_soc_add_controls() here - you can replace the entire function with a call to that.
sound/soc/codecs/ad1938.c line 99
Quoted 11 lines
sound/soc/codecs/ad1938.c new file +11
-0+/* dac/adc/pll poweron/off functions */ +static int ad1938_dac_powerctrl (struct snd_soc_codec *codec,int cmd) +{ +int reg; + + reg = codec->read (codec,AD1938_DAC_CTRL0 ); +if (cmd) + reg &= ~DAC_POWERDOWN ; +else + reg |=DAC_POWERDOWN ; + codec->write (codec,AD1938_DAC_CTRL0 , reg);
This should be handled by DAPM - either have a single DAC widget representing all the channels (since you don't appear to have independant control anyway) or have a bunch of dummy DAC widgets and a supply widget representing the actual power control. The same thing applies to the ADCs.
sound/soc/codecs/ad1938.c line 148
Quoted 12 lines
sound/soc/codecs/ad1938.c new file +12
-0+static int ad1938_set_pll (struct snd_soc_dai *codec_dai, +int pll_id,unsigned int freq_in,unsigned int freq_out) +{ +struct snd_soc_codec *codec = codec_dai->codec; + +if (freq_out) +ad1938_pll_powerctrl (codec,1 ); +else { +/* playing while recording, framework will poweroff-poweron pll redundantly */ +if ((!codec_dai->capture.active) && (!codec_dai->playback.active)) +ad1938_pll_powerctrl (codec,0 ); + }
Hrm. This appears to completely ignore the frequencies supplied for the PLL and just provide power control. I suspect that you can just handle the PLL as a SND_SOC_DAPM_SUPPLY(), there seems to be no need to expose the set_pll() operation and make machine drivers call it given that there isn't any frequency configuration going on.
sound/soc/codecs/ad1938.c line 163
Quoted 11 lines
sound/soc/codecs/ad1938.c new file +11
-0+static int ad1938_mute (struct snd_soc_dai *dai,int mute) +{ +struct snd_soc_codec *codec = dai->codec; + +if (!mute) + codec->write (codec,AD1938_DAC_CHNL_MUTE ,0 ); +else + codec->write (codec,AD1938_DAC_CHNL_MUTE ,0xff ); + +return 0 ; +}
This isn't going to play well with the explicit mute controls you've got above - it's writing to the same register bits without any coordination. One or the other set of controls ought to be removed.
sound/soc/codecs/ad1938.c line 174
Quoted 10 lines
sound/soc/codecs/ad1938.c new file +10
-0+static int ad1938_tdm_set (struct snd_soc_codec *codec) +{ + codec->write (codec,AD1938_DAC_CTRL0 , (codec->read (codec,AD1938_DAC_CTRL0 ) & + (~DAC_SERFMT_MASK )) |DAC_SERFMT_TDM ); + codec->write (codec,AD1938_DAC_CTRL1 ,0x84 );/* invert bclk, 256bclk/frame, latch in mid */ + codec->write (codec,AD1938_ADC_CTRL1 ,0x43 );/* sata delay=1, adc aux mode */ + codec->write (codec,AD1938_ADC_CTRL2 ,0x6F );/* left high, driver on rising edge */ + +return 0 ; +}
If you use set_tdm_slot() then the BCLK/frame ratio will be set by that.
Inversion of BCLK (and any other clocks) should be handled by the set_dai_fmt() operation based on the machine driver request rather than done unconditionally.
sound/soc/codecs/ad1938.c line 243
Quoted 5 lines
sound/soc/codecs/ad1938.c new file +5
-0+/* bit size */ +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : + word_len =3 ; +break ;
Once you implement set_tdm_slot() you should allow the word length to be configured there if it's called or otherwise keep this code here - see Daniel Ribeiro's patche "change set_tdm_slot api to allow slot_width override" posted to the ALSA list this week.
sound/soc/codecs/ad1938.c line 359
Quoted 12 lines
sound/soc/codecs/ad1938.c new file +12
-0+static int __devinit ad1938_spi_probe (struct spi_device *spi) +{ + spi->dev.power.power_state =PMSG_ON ; + ad1938_socdev->card->codec->control_data = spi; + +return 0 ; +} + +static int __devexit ad1938_spi_remove(struct spi_device *spi) +{ +return 0 ; +}
Your device probing should all be restructured so that the SPI device for the CODEC is registered as any other SPI device rather than being set up as part of probing the ASoC device. See the wm8731 driver for an example of doing this for a SPI device.
This will require that the arch code for any systems with the ad1938 do the setup of the device.
sound/soc/codecs/ad1938.c line 398
Quoted 7 lines
sound/soc/codecs/ad1938.c new file +7
-0+ .name = "AD1938", + .playback = { + .stream_name = "Playback", + .channels_min = 2, + .channels_max = 8, + .rates = SNDRV_PCM_RATE_48000, + .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, },
Please keep your lines to under 80 columns.
sound/soc/codecs/ad1938.c
Quoted 8 lines
sound/soc/codecs/ad1938.c new file +8
-0+#define AD1938_PLL_CLK_CTRL0 0 +#define PLL_POWERDOWN 0x01 +#define AD1938_PLL_CLK_CTRL1 1 +#define AD1938_DAC_CTRL0 2 +#define DAC_POWERDOWN 0x01 +#define DAC_SERFMT_MASK 0xC0 +#define DAC_SERFMT_STEREO (0 << 6) +#define DAC_SERFMT_TDM (1 << 6)
These defines need namespacing if they're going to appear in the headers
- everything should have the AD1938_ prefix.
Quoted 8 lines · Mark Brown
Quoted 3 lines · Barry Song
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)As Liam said you really need to submit this as a patch series rather than as a single big patch - as your commit log here indicates you've got several different things going on here.
blah, i had this queued locally with a "todo:split". wanted to wait for Barry to finish developing the driver first though.
at any rate, i hate to sound like a broken record wrt my alsa ignorance, but i'm thinking the logical split would be like Barry numbered it -- one patch for sound/codec/, one patch for the TDM transport, and one patch for hooking up the AD1938 to TDM.
Quoted 18 lines
sound/soc/codecs/ad1938.c line 359
Quoted 12 lines
sound/soc/codecs/ad1938.c new file +12
-0+static int __devinit ad1938_spi_probe (struct spi_device *spi) +{ + spi->dev.power.power_state = PMSG_ON; + ad1938_socdev->card->codec->control_data = spi; + + return 0; +} + +static int __devexit ad1938_spi_remove(struct spi_device *spi) +{ + return 0; +}Your device probing should all be restructured so that the SPI device for the CODEC is registered as any other SPI device rather than being set up as part of probing the ASoC device. See the wm8731 driver for an example of doing this for a SPI device.
Quoted 2 lines
This will require that the arch code for any systems with the ad1938 do the setup of the device.
so should sound/soc/blackfin/bf5xx-ad1938.c even exist in the first place ? -mike
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 10 lines · Mike Frysinger
Quoted 8 lines · Mark Brown
Quoted 3 lines · Barry Song
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)As Liam said you really need to submit this as a patch series rather than as a single big patch - as your commit log here indicates you've got several different things going on here.
Quoted 7 lines
blah, i had this queued locally with a "todo:split". wanted to wait for Barry to finish developing the driver first though.
at any rate, i hate to sound like a broken record wrt my alsa ignorance, but i'm thinking the logical split would be like Barry numbered it -- one patch for
sound/codec/, one patch for the TDM transport, and one patch for hooking up the AD1938 to TDM.
Yes, though if the new DAI format had been required it would be worth considering a separate patch for it.
Quoted 19 lines
Quoted 19 lines
sound/soc/codecs/ad1938.c line 359
Quoted 13 lines
sound/soc/codecs/ad1938.c new file +12
-0+static int __devinit ad1938_spi_probe (struct spi_device *spi) +{ + spi->dev.power.power_state =PMSG_ON ; + ad1938_socdev->card->codec->control_data = spi; + +return 0 ; +} + +static int __devexit ad1938_spi_remove(struct spi_device *spi) +{ +return 0 ; +}Your device probing should all be restructured so that the SPI device for the CODEC is registered as any other SPI device rather than being set up as part of probing the ASoC device. See the wm8731 driver for an example of doing this for a SPI device.
Quoted 5 lines
Quoted 2 lines
This will require that the arch code for any systems with the ad1938 do the setup of the device.
so should
sound/soc/blackfin/bf5xx-ad1938.ceven exist in the first place ?
Yes. It is needed in order to specify how things are hooked up on a given board.
Quoted 14 lines · Mark Brown
Quoted 13 lines · Mike Frysinger
Quoted 8 lines · Mark Brown
Quoted 3 lines · Barry Song
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)As Liam said you really need to submit this as a patch series rather than as a single big patch - as your commit log here indicates you've got several different things going on here.
blah, i had this queued locally with a "todo:split". wanted to wait for Barry to finish developing the driver first though.
Quoted 7 lines
Quoted 4 lines
at any rate, i hate to sound like a broken record wrt my alsa ignorance, but i'm thinking the logical split would be like Barry numbered it -- one patch for
sound/codec/, one patch for the TDM transport, and one patch for hooking up the AD1938 to TDM.Yes, though if the new DAI format had been required it would be worth considering a separate patch for it.
OK, Barry can handle this, otherwise i'll split it up in my git and send him the repo info
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
sound/soc/codecs/ad1938.c line 359
Quoted 12 lines
sound/soc/codecs/ad1938.c new file +12
-0+static int __devinit ad1938_spi_probe (struct spi_device *spi) +{ + spi->dev.power.power_state = PMSG_ON; + ad1938_socdev->card->codec->control_data = spi; + + return 0; +} + +static int __devexit ad1938_spi_remove(struct spi_device *spi) +{ + return 0; +}Your device probing should all be restructured so that the SPI device for the CODEC is registered as any other SPI device rather than being set up as part of probing the ASoC device. See the wm8731 driver for an example of doing this for a SPI device.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
This will require that the arch code for any systems with the ad1938 do the setup of the device.
so should
sound/soc/blackfin/bf5xx-ad1938.ceven exist in the first place ?Yes. It is needed in order to specify how things are hooked up on a given board.
to look at the wm8731 then, these are good examples of how it's done ? sound/soc/atmel/sam9g20_wm8731.csound/soc/pxa/corgi.c
-mike
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 8 lines · Mike Frysinger
Quoted 7 lines · Mark Brown
Quoted 7 lines
Quoted 6 lines
Quoted 7 lines
Quoted 3 lines
Yes. It is needed in order to specify how things are hooked up on a given
board.to look at the wm8731 then, these are good examples of how it's done ?
sound/soc/atmel/sam9g20_wm8731.csound/soc/pxa/corgi.c
Anything should be OK - possibly one of the existing Blackfin drivers. I mentioned wm8731 due to the SPI but by the time it gets to the machine driver that's hidden so it's not urgently relevant.
On Fri 19 Jun 2009 07:13, Mark Brown pondered:
Quoted 10 lines · Mike Frysinger
Quoted 6 lines · Mark Brown
Quoted 2 lines
This will require that the arch code for any systems with the ad1938 do the setup of the device.
so should
sound/soc/blackfin/bf5xx-ad1938.ceven exist in the first place ?Yes. It is needed in order to specify how things are hooked up on a given board.
This has always kind of bugged me about ASOC - (or maybe it is just my ignorance about the architecture decisions that were made).
Any reason why platform/board specific things are in sound/soc/arch rather than arch/xxxx/boards - like the majority of drivers?
?
Quoted 5 lines · Robin Getz
Any reason why platform/board specific things are in
sound/soc/archratherQuoted 2 lines
Quoted 1 line
than
arch/xxxx/boards- like the majority of drivers?
Partly because the APIs are sufficiently fluid to make the cross tree merge issues unmanageable, partly because non trivial boards really do need an entire driver for the board. I'd also say that at the minute I'm catching enough errors on review of machine drivers to make it worthwhile.
Quoted 1 line
Hi Mark,
***For the new DAI format
According to I2S spec, it doesn't definite a I2S with TDM as a standard I2S.
http://www.nxp.com/acrobat_download/various/I2SBUS.pdf
It looks like you are admitting this kind of timing into I2S DAI too:
http://i3.6.cn/cvbnm/8f/3d/08/268a4560e0daa1b41d69b82419da06e1.jpg
I think I can follow it too.
Due to my test boards, at present, the AD1938 is working in and supporting TDM timing like the diagram:
http://i3.6.cn/cvbnm/2f/e2/f2/03ae2b51c4e90749972e70bf887f926f.jpg
It looks like DSP mode with TDM, so can I path related codes into SND_SOC_DAIFMT_DSP switch?
***For volume controls based on stereo pairs
Even though DAC1-DAC8 are named as DACL1,DACR1, DACL2,DACR2..., but the DACLx and DACRx are not always in a pair, in fact, they are independent. As a codec supporting 8 channels, it can be configed into 2, 2.1, 4.1, 5.1, 6.1, 7.1, how to handle the pairs?
Thanks
Barry
2009/6/19 Mark Brown <[email protected]>
Quoted 227 lines · Barry Song
Quoted 3 lines
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)As Liam said you really need to submit this as a patch series rather than as a single big patch - as your commit log here indicates you've got several different things going on here.
include/sound/soc-dai.h struct snd_pcm_substream; · line 33
Quoted 6 lines
+++
b/include/sound/soc-dai.hinclude/sound/soc-dai.h +1
-0@@ -30,6 +30,7 @@ struct snd_pcm_substream;#define SND_SOC_DAIFMT_DSP_A 3/* L data msb after FRM LRC */ #define SND_SOC_DAIFMT_DSP_B 4/* L data msb during FRM LRC */ #define SND_SOC_DAIFMT_AC97 5/* AC97 */ +#define SND_SOC_DAIFMT_SPORT_TDM 6/* SPORT TDM for ADI parts */ If you're going to add a new DAI format that really needs more explanation than this explaining what the DAI format is. It'd be very surprising to see hardware needing a new format.
Looking at the datasheet for the ad1938 it appears that the actual format here is just normal I2S with TDM. This does not need a new DAI format or new CPU DAI, you just need to add suport for TDM to the Blackfin I2S driver. The format is fairly standard and implemented by a number of other devices.
See
set_tdm_slot()for setting up the higher channel counts - there's some ongoing revisions to that API so you'll want to also ensure that the code is set up so that it can cope with specification of the sample width for each slot inset_tdm_slot().Given this I've only looked at the CODEC driver below.
sound/soc/codecs/ad1938.c line 13
Quoted 9 lines
sound/soc/codecs/ad1938.c new file +3
-0+* +* Revision history +* 4 June 2009 Initial version. Don't include this, git provides code history for us.
sound/soc/codecs/ad1938.c
Quoted 4 lines
sound/soc/codecs/ad1938.c new file +4
-0+struct snd_soc_device *ad1938_socdev; + +/* dac de-emphasis enum control */ +static const char *ad1938_deemp[] = {"flat" ,"48kHz" ,"44.1kHz" ,"32kHz"};
For consistency with other drivers "flat" should be "None".
sound/soc/codecs/ad1938.c line 42
Quoted 5 lines
sound/soc/codecs/ad1938.c new file +5
-0+/* AD1938 volume/mute/de-emphasis etc. controls */ +static const struct snd_kcontrol_new ad1938_snd_controls[] = { +/* DAC volume control */ +SOC_SINGLE ("DAC L1 Volume" ,AD1938_DAC_L1_VOL ,0 ,0xFF ,1 ), +SOC_SINGLE ("DAC R1 Volume" ,AD1938_DAC_R1_VOL ,0 ,0xFF ,1 ),These (and the other stereo pairs below) should be
SOC_DOUBLE_R(). This allows ALSA to represent them as stereo controls to applications rather than as two separate controls. You should also provide TLV information so actuallySOC_DOUBLE_R_TLV()if possible.sound/soc/codecs/ad1938.c line 52
Quoted 3 lines
sound/soc/codecs/ad1938.c new file +3
-0+/* DAC mute control */ +SOC_SINGLE ("DAC L1 Switch" ,AD1938_DAC_CHNL_MUTE ,0 ,1 ,1 ), + SOC_SINGLE("DAC R1 Switch", AD1938_DAC_CHNL_MUTE, 1, 1, 1),These should be stereo controls too -
SOC_DOUBLE()since they're in the same register.sound/soc/codecs/ad1938.c line 62
Quoted 3 lines
sound/soc/codecs/ad1938.c new file +3
-0+/* ADC mute control */ +SOC_SINGLE ("ADC L1 Switch" ,AD1938_ADC_CTRL0 ,ADC0_MUTE ,1 ,1 ), + SOC_SINGLE("ADC R1 Switch", AD1938_ADC_CTRL0, ADC1_MUTE, 1, 1),These too.
sound/soc/codecs/ad1938.c line 70
Quoted 2 lines
sound/soc/codecs/ad1938.c new file +2
-0+/* DAC de-emphasis */ + SOC_ENUM("Playback Deemphasis", ad1938_enum[0]),Don't put your enums in an array, use named variables for them. This makes drivers easier to maintian when you get a lot of enums.
sound/soc/codecs/ad1938.c
Quoted 7 lines
sound/soc/codecs/ad1938.c new file +7
-0+static int ad1938_add_controls (struct snd_soc_codec *codec) +{ +int err, i; + +for (i =0 ; i <ARRAY_SIZE (ad1938_snd_controls); i++) { + err = snd_ctl_add(codec->card, + snd_soc_cnew(&ad1938_snd_controls[i],codec, NULL));
Use
snd_soc_add_controls()here - you can replace the entire function with a call to that.sound/soc/codecs/ad1938.c line 99
Quoted 11 lines
sound/soc/codecs/ad1938.c new file +11
-0+/* dac/adc/pll poweron/off functions */ +static int ad1938_dac_powerctrl (struct snd_soc_codec *codec,int cmd) +{ +int reg; + + reg = codec->read (codec,AD1938_DAC_CTRL0 ); +if (cmd) + reg &= ~DAC_POWERDOWN ; +else + reg |=DAC_POWERDOWN ; + codec->write (codec,AD1938_DAC_CTRL0 , reg);This should be handled by DAPM - either have a single DAC widget representing all the channels (since you don't appear to have independant control anyway) or have a bunch of dummy DAC widgets and a supply widget representing the actual power control. The same thing applies to the ADCs.
sound/soc/codecs/ad1938.c
Quoted 9 lines
sound/soc/codecs/ad1938.c new file +9
-0+static int ad1938_set_pll (struct snd_soc_dai *codec_dai, +int pll_id,unsigned int freq_in,unsigned int freq_out) +{ +struct snd_soc_codec *codec = codec_dai->codec; + +if (freq_out) +ad1938_pll_powerctrl (codec,1 ); +else { +/* playing while recording, framework will poweroff-poweron pll redundantly */
Quoted 1 line
+ if ((!codec_dai->capture.active) &&
(!codec_dai->playback.active))
sound/soc/codecs/ad1938.c
Quoted 2 lines
sound/soc/codecs/ad1938.c new file +2
-0+ad1938_pll_powerctrl (codec,0 ); + }Hrm. This appears to completely ignore the frequencies supplied for the PLL and just provide power control. I suspect that you can just handle the PLL as a
SND_SOC_DAPM_SUPPLY(), there seems to be no need to expose theset_pll()operation and make machine drivers call it given that there isn't any frequency configuration going on.sound/soc/codecs/ad1938.c line 163
Quoted 11 lines
sound/soc/codecs/ad1938.c new file +11
-0+static int ad1938_mute (struct snd_soc_dai *dai,int mute) +{ +struct snd_soc_codec *codec = dai->codec; + +if (!mute) + codec->write (codec,AD1938_DAC_CHNL_MUTE ,0 ); +else + codec->write (codec,AD1938_DAC_CHNL_MUTE ,0xff ); + +return 0 ; +}This isn't going to play well with the explicit mute controls you've got above - it's writing to the same register bits without any coordination. One or the other set of controls ought to be removed.
sound/soc/codecs/ad1938.c
Quoted 3 lines
sound/soc/codecs/ad1938.c new file +3
-0+static int ad1938_tdm_set (struct snd_soc_codec *codec) +{ + codec->write(codec, AD1938_DAC_CTRL0, (codec->read(codec,
AD1938_DAC_CTRL0) &sound/soc/codecs/ad1938.c
Quoted 2 lines
sound/soc/codecs/ad1938.c new file +2
-0+ (~DAC_SERFMT_MASK)) | DAC_SERFMT_TDM); + codec->write (codec,AD1938_DAC_CTRL1 ,0x84 );/* invert bclk, 256bclk/frame, latch in mid */
Quoted 1 line
+
codec->write(codec, AD1938_ADC_CTRL1, 0x43); /* sata delay=1, adcaux mode */
Quoted 1 line
+
codec->write(codec, AD1938_ADC_CTRL2, 0x6F); /* left high, driveron rising edge */
sound/soc/codecs/ad1938.c
Quoted 3 lines
sound/soc/codecs/ad1938.c new file +3
-0+ +return 0 ; +}If you use
set_tdm_slot()then the BCLK/frame ratio will be set by that.Inversion of BCLK (and any other clocks) should be handled by the
set_dai_fmt()operation based on the machine driver request rather than done unconditionally.sound/soc/codecs/ad1938.c line 243
Quoted 5 lines
sound/soc/codecs/ad1938.c new file +5
-0+/* bit size */ +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : + word_len =3 ; +break ;Once you implement
set_tdm_slot()you should allow the word length to be configured there if it's called or otherwise keep this code here - see Daniel Ribeiro's patche "changeset_tdm_slotapi to allowslot_widthoverride" posted to the ALSA list this week.sound/soc/codecs/ad1938.c line 359
Quoted 12 lines
sound/soc/codecs/ad1938.c new file +12
-0+static int __devinit ad1938_spi_probe (struct spi_device *spi) +{ + spi->dev.power.power_state =PMSG_ON ; + ad1938_socdev->card->codec->control_data = spi; + +return 0 ; +} + +static int __devexit ad1938_spi_remove(struct spi_device *spi) +{ +return 0 ; +}Your device probing should all be restructured so that the SPI device for the CODEC is registered as any other SPI device rather than being set up as part of probing the ASoC device. See the wm8731 driver for an example of doing this for a SPI device.
This will require that the arch code for any systems with the ad1938 do the setup of the device.
sound/soc/codecs/ad1938.c
Quoted 7 lines
sound/soc/codecs/ad1938.c new file +7
-0+ .name = "AD1938", + .playback = { + .stream_name = "Playback", + .channels_min = 2, + .channels_max = 8, + .rates = SNDRV_PCM_RATE_48000, + .formats = SNDRV_PCM_FMTBIT_S32_LE |
SNDRV_PCM_FMTBIT_S16_LE|SNDRV_PCM_FMTBIT_S20_3LE|SNDRV_PCM_FMTBIT_S24_LE, },Please keep your lines to under 80 columns.
sound/soc/codecs/ad1938.c
Quoted 8 lines
sound/soc/codecs/ad1938.c new file +8
-0+#define AD1938_PLL_CLK_CTRL0 0 +#define PLL_POWERDOWN 0x01 +#define AD1938_PLL_CLK_CTRL1 1 +#define AD1938_DAC_CTRL0 2 +#define DAC_POWERDOWN 0x01 +#define DAC_SERFMT_MASK 0xC0 +#define DAC_SERFMT_STEREO (0 << 6) +#define DAC_SERFMT_TDM (1 << 6)These defines need namespacing if they're going to appear in the headers
- everything should have theAD1938_prefix.
Signature · 6 lines
宋宝华 [email protected] http://21cnbao.blog.51cto.com _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
On Mon, Jun 22, 2009 at 11:08:27AM +0800, 宋宝华 wrote:
[Please reply in-line, interspersing your new text into the message you're replying to - it makes the discussion much easier to follow.]
Quoted 4 lines
Hi Mark,
***For the new DAI format
According to I2S spec, it doesn't definite a I2S with TDM as a standard I2S.
http://www.nxp.com/acrobat_download/various/I2SBUS.pdf
It's a de facto standard - several other vendors implement TDM in exactly the same fashion. If you think about it this is a natural way to handle TDM in I2S.
Quoted 3 lines
It looks like you are admitting this kind of timing into I2S DAI too:
http://i3.6.cn/cvbnm/8f/3d/08/268a4560e0daa1b41d69b82419da06e1.jpg
I think I can follow it too.
The timing you're showing there is essentially a DSP mode with the left and right channels alternating rather than an I2S style where the polarity of the LRCLK signal indicates if the data transmitted at the same time is for the left or right channel. I'd need to think about it in slightly more detail but probably it is actually a DSP mode - with the DSP modes only one edge of the frame sync is used so the other edge can be anywhere else within the frame.
Quoted 5 lines
Due to my test boards, at present, the AD1938 is working in and supporting TDM timing like the diagram:
http://i3.6.cn/cvbnm/2f/e2/f2/03ae2b51c4e90749972e70bf887f926f.jpg
It looks like DSP mode with TDM, so can I path related codes intoSND_SOC_DAIFMT_DSPswitch?
Yes, that's DSP mode.
Quoted 5 lines
***For volume controls based on stereo pairs
Even though DAC1-DAC8 are named as DACL1,DACR1, DACL2,DACR2..., but the DACLx and DACRx are not always in a pair, in fact, they are independent. As a codec supporting 8 channels, it can be configed into 2, 2.1, 4.1, 5.1, 6.1, 7.1, how to handle the pairs?
That's fairly standard and not really a practical problem. Since applications can address each channel of a stereo control independantly they don't loose any control from grouping the channels together. Having the stereo controls just makes it a bit easier when they are used that way.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
2009/6/22 Mark Brown <[email protected]>
Quoted 27 lines · 宋宝华
[Please reply in-line, interspersing your new text into the message you're replying to - it makes the discussion much easier to follow.]
Quoted 3 lines
Hi Mark,
***For the new DAI format
According to I2S spec, it doesn't definite a I2S with TDM as a standardI2S.
It's a de facto standard - several other vendors implement TDM in exactly the same fashion. If you think about it this is a natural way to handle TDM in I2S.
Quoted 3 lines
It looks like you are admitting this kind of timing into I2S DAI too:
http://i3.6.cn/cvbnm/8f/3d/08/268a4560e0daa1b41d69b82419da06e1.jpg
I think I can follow it too.The timing you're showing there is essentially a DSP mode with the left and right channels alternating rather than an I2S style where the polarity of the LRCLK signal indicates if the data transmitted at the same time is for the left or right channel. I'd need to think about it in slightly more detail but probably it is actually a DSP mode - with the DSP modes only one edge of the frame sync is used so the other edge can be anywhere else within the frame.
Quoted 8 lines
Quoted 1 line
Due to my test boards, at present, the AD1938 is working in and
supporting
Quoted 4 lines
TDM timing like the diagram:
http://i3.6.cn/cvbnm/2f/e2/f2/03ae2b51c4e90749972e70bf887f926f.jpg
It looks like DSP mode with TDM, so can I path related codes intoSND_SOC_DAIFMT_DSPswitch?Yes, that's DSP mode.
Based on the "de facto ", I think I will merge TDM related codes into blackfin I2S DAI directly.
Quoted 6 lines
Quoted 5 lines
***For volume controls based on stereo pairs
Even though DAC1-DAC8 are named as DACL1,DACR1, DACL2,DACR2..., but the DACLx and DACRx are not always in a pair, in fact, they are independent.As
Quoted 9 lines
Quoted 2 lines
a codec supporting 8 channels, it can be configed into 2, 2.1, 4.1, 5.1, 6.1, 7.1, how to handle the pairs?
That's fairly standard and not really a practical problem. Since applications can address each channel of a stereo control independantly they don't loose any control from grouping the channels together. Having the stereo controls just makes it a bit easier when they are used that way.
So, does it mean I need to support both single and pair since we don't know how users will use it? If I only create 4 pairs, how could users control channels not in any pair?
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 3 lines · 宋宝华
So, does it mean I need to support both single and pair since we don't know how users will use it? If I only create 4 pairs, how could users control channels not in any pair?
You only need to do stereo, like I said users can still control the individual channels. Creating stereo controls only adds new ways of controlling things, it doesn't remove any capabilities.
Quoted 1 line
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
2009/6/19 Mark Brown <[email protected]>:
Quoted 102 lines · Barry Song
Quoted 3 lines
1. add AD1938 codec driver (codec)
2. add blackfin SPORT-TDM DAI and PCM driver (platform)
3. add bf5xx board with AD1938 driver (machine)As Liam said you really need to submit this as a patch series rather than as a single big patch - as your commit log here indicates you've got several different things going on here.
include/sound/soc-dai.h struct snd_pcm_substream; · line 33
Quoted 6 lines
+++
b/include/sound/soc-dai.hinclude/sound/soc-dai.h +1
-0@@ -30,6 +30,7 @@ struct snd_pcm_substream; #define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM LRC */ #define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM LRC */ #define SND_SOC_DAIFMT_AC97 5 /* AC97 */ +#define SND_SOC_DAIFMT_SPORT_TDM 6/* SPORT TDM for ADI parts */ If you're going to add a new DAI format that really needs more explanation than this explaining what the DAI format is. It'd be very surprising to see hardware needing a new format.
Looking at the datasheet for the ad1938 it appears that the actual format here is just normal I2S with TDM. This does not need a new DAI format or new CPU DAI, you just need to add suport for TDM to the Blackfin I2S driver. The format is fairly standard and implemented by a number of other devices.
See
set_tdm_slot()for setting up the higher channel counts - there's some ongoing revisions to that API so you'll want to also ensure that the code is set up so that it can cope with specification of the sample width for each slot inset_tdm_slot().Given this I've only looked at the CODEC driver below.
sound/soc/codecs/ad1938.c line 13
Quoted 9 lines
sound/soc/codecs/ad1938.c new file +3
-0+* +* Revision history +* 4 June 2009 Initial version. Don't include this, git provides code history for us.
sound/soc/codecs/ad1938.c line 32
Quoted 4 lines
sound/soc/codecs/ad1938.c new file +4
-0+struct snd_soc_device *ad1938_socdev; + +/* dac de-emphasis enum control */ +static const char *ad1938_deemp[] = {"flat" ,"48kHz" ,"44.1kHz" ,"32kHz" };For consistency with other drivers "flat" should be "None".
sound/soc/codecs/ad1938.c line 42
Quoted 5 lines
sound/soc/codecs/ad1938.c new file +5
-0+/* AD1938 volume/mute/de-emphasis etc. controls */ +static const struct snd_kcontrol_new ad1938_snd_controls[] = { + /* DAC volume control */ + SOC_SINGLE("DAC L1 Volume", AD1938_DAC_L1_VOL, 0, 0xFF, 1), + SOC_SINGLE("DAC R1 Volume", AD1938_DAC_R1_VOL, 0, 0xFF, 1),These (and the other stereo pairs below) should be
SOC_DOUBLE_R(). This allows ALSA to represent them as stereo controls to applications rather than as two separate controls. You should also provide TLV information so actuallySOC_DOUBLE_R_TLV()if possible.Quoted 3 lines
+ /* DAC mute control */
+SOC_SINGLE("DAC L1 Switch", AD1938_DAC_CHNL_MUTE, 0, 1, 1),
+SOC_SINGLE("DAC R1 Switch", AD1938_DAC_CHNL_MUTE, 1, 1, 1),These should be stereo controls too -
SOC_DOUBLE()since they're in the same register.Quoted 3 lines
+ /* ADC mute control */
+SOC_SINGLE("ADC L1 Switch", AD1938_ADC_CTRL0, ADC0_MUTE, 1, 1),
+SOC_SINGLE("ADC R1 Switch", AD1938_ADC_CTRL0, ADC1_MUTE, 1, 1),These too.
Quoted 2 lines
+ /* DAC de-emphasis */
+SOC_ENUM("Playback Deemphasis", ad1938_enum[0]),Don't put your enums in an array, use named variables for them. This makes drivers easier to maintian when you get a lot of enums.
sound/soc/codecs/ad1938.c line 80
Quoted 7 lines
sound/soc/codecs/ad1938.c new file +7
-0+static int ad1938_add_controls (struct snd_soc_codec *codec) +{ + int err, i; + + for (i = 0; i < ARRAY_SIZE(ad1938_snd_controls); i++) { + err = snd_ctl_add(codec->card, + snd_soc_cnew(&ad1938_snd_controls[i], codec, NULL));Use
snd_soc_add_controls()here - you can replace the entire function with a call to that.Quoted 9 lines
sound/soc/codecs/ad1938.c new file +9
-0+/* dac/adc/pll poweron/off functions */ +static int ad1938_dac_powerctrl (struct snd_soc_codec *codec,int cmd) +{ + int reg; + + reg = codec->read(codec, AD1938_DAC_CTRL0); + if (cmd) + reg &= ~DAC_POWERDOWN; + else
Quoted 8 lines
Quoted 2 lines
+ reg |=
DAC_POWERDOWN;
+codec->write(codec, AD1938_DAC_CTRL0, reg);This should be handled by DAPM - either have a single DAC widget representing all the channels (since you don't appear to have independant control anyway) or have a bunch of dummy DAC widgets and a supply widget representing the actual power control. The same thing applies to the ADCs.
I want to use ADC/DAC widgets.
static const struct snd_soc_dapm_widget ad1938_dapm_widgets[] = {
SND_SOC_DAPM_DAC("DAC", "HiFi Playback", AD1938_DAC_CTRL0, 0, 1),
SND_SOC_DAPM_ADC("ADC", "HiFi Capture", AD1938_ADC_CTRL0, 0, 1),
};But for this AD1938 codec, DAC's work depends on ADC is powered on in hardware. I think there is no any mechanism to handle this kind of strange depending now. So is there a generic way to handle this?
Quoted 107 lines
sound/soc/codecs/ad1938.c line 148
Quoted 13 lines
sound/soc/codecs/ad1938.c new file +12
-0+static int ad1938_set_pll (struct snd_soc_dai *codec_dai, + int pll_id, unsigned int freq_in, unsigned int freq_out) +{ + struct snd_soc_codec *codec = codec_dai->codec; + + if (freq_out) + ad1938_pll_powerctrl(codec, 1); + else { + /* playing while recording, framework will poweroff-poweron pll redundantly */ + if ((!codec_dai->capture.active) && (!codec_dai->playback.active)) + ad1938_pll_powerctrl(codec, 0); + }Hrm. This appears to completely ignore the frequencies supplied for the PLL and just provide power control. I suspect that you can just handle the PLL as a
SND_SOC_DAPM_SUPPLY(), there seems to be no need to expose theset_pll()operation and make machine drivers call it given that there isn't any frequency configuration going on.sound/soc/codecs/ad1938.c line 163
Quoted 11 lines
sound/soc/codecs/ad1938.c new file +11
-0+static int ad1938_mute (struct snd_soc_dai *dai,int mute) +{ + struct snd_soc_codec *codec = dai->codec; + + if (!mute) + codec->write(codec, AD1938_DAC_CHNL_MUTE, 0); + else + codec->write(codec, AD1938_DAC_CHNL_MUTE, 0xff); + + return 0; +}This isn't going to play well with the explicit mute controls you've got above - it's writing to the same register bits without any coordination. One or the other set of controls ought to be removed.
sound/soc/codecs/ad1938.c line 174
Quoted 10 lines
sound/soc/codecs/ad1938.c new file +10
-0+static int ad1938_tdm_set (struct snd_soc_codec *codec) +{ + codec->write(codec, AD1938_DAC_CTRL0, (codec->read(codec, AD1938_DAC_CTRL0) & + (~DAC_SERFMT_MASK)) | DAC_SERFMT_TDM); + codec->write(codec, AD1938_DAC_CTRL1, 0x84); /* invert bclk, 256bclk/frame, latch in mid */ + codec->write(codec, AD1938_ADC_CTRL1, 0x43); /* sata delay=1, adc aux mode */ + codec->write(codec, AD1938_ADC_CTRL2, 0x6F); /* left high, driver on rising edge */ + + return 0; +}If you use
set_tdm_slot()then the BCLK/frame ratio will be set by that.Inversion of BCLK (and any other clocks) should be handled by the
set_dai_fmt()operation based on the machine driver request rather than done unconditionally.Quoted 5 lines
+ /* bit size */
+ switch (params_format(params)) {
+ caseSNDRV_PCM_FORMAT_S16_LE:
+word_len= 3;
+ break;Once you implement
set_tdm_slot()you should allow the word length to be configured there if it's called or otherwise keep this code here - see Daniel Ribeiro's patche "changeset_tdm_slotapi to allowslot_widthoverride" posted to the ALSA list this week.sound/soc/codecs/ad1938.c line 359
Quoted 12 lines
sound/soc/codecs/ad1938.c new file +12
-0+static int __devinit ad1938_spi_probe (struct spi_device *spi) +{ + spi->dev.power.power_state = PMSG_ON; + ad1938_socdev->card->codec->control_data = spi; + + return 0; +} + +static int __devexit ad1938_spi_remove(struct spi_device *spi) +{ + return 0; +}Your device probing should all be restructured so that the SPI device for the CODEC is registered as any other SPI device rather than being set up as part of probing the ASoC device. See the wm8731 driver for an example of doing this for a SPI device.
This will require that the arch code for any systems with the ad1938 do the setup of the device.
Quoted 7 lines
+ .name = "AD1938",
+ .playback = {
+ .stream_name = "Playback",
+ .channels_min = 2,
+ .channels_max = 8,
+ .rates =SNDRV_PCM_RATE_48000,
+ .formats =SNDRV_PCM_FMTBIT_S32_LE|SNDRV_PCM_FMTBIT_S16_LE|SNDRV_PCM_FMTBIT_S20_3LE|SNDRV_PCM_FMTBIT_S24_LE, },Please keep your lines to under 80 columns.
sound/soc/codecs/ad1938.c
Quoted 8 lines
sound/soc/codecs/ad1938.c new file +8
-0+#define AD1938_PLL_CLK_CTRL0 0 +#define PLL_POWERDOWN 0x01 +#define AD1938_PLL_CLK_CTRL1 1 +#define AD1938_DAC_CTRL0 2 +#define DAC_POWERDOWN 0x01 +#define DAC_SERFMT_MASK 0xC0 +#define DAC_SERFMT_STEREO (0 << 6) +#define DAC_SERFMT_TDM (1 << 6)These defines need namespacing if they're going to appear in the headers
- everything should have theAD1938_prefix.
Signature · 2 lines
宋宝华 [email protected] http://21cnbao.blog.51cto.com
Quoted 8 lines · 宋宝华
I want to use ADC/DAC widgets.
static const struct snd_soc_dapm_widget ad1938_dapm_widgets[] = { SND_SOC_DAPM_DAC("DAC", "HiFi Playback", AD1938_DAC_CTRL0, 0, 1), SND_SOC_DAPM_ADC("ADC", "HiFi Capture", AD1938_ADC_CTRL0, 0, 1), };But for this AD1938 codec, DAC's work depends on ADC is powered on in hardware. I think there is no any mechanism to handle this kind of strange depending now. So is there a generic way to handle this?
Make the ADC power a SND_SOC_DAPM_SUPPLY() supplying both the DAC and the ADC, with the ADC widget marged as having no power management.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel