ASoC: AK4671: add ak4671 codec driver
PATCH 1/1 ASoC: AK4671: add ak4671 codec driver
The AK4671 is a stereo CODEC with a built-in Microphone-Amplifier, Receiver-Amplifier and Headphone-Amplifier.
The datasheet for the ak4671 can find at the following url:
http://www.asahi-kasei.co.jp/akm/en/product/ak4671/ak4671_f01e.pdf
--- sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/ak4671.c | 898 +++++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/ak4671.h | 156 ++++++++ 4 files changed, 1060 insertions(+), 0 deletions(-) create mode 100644 sound/soc/codecs/ak4671.c create mode 100644 sound/soc/codecs/ak4671.h
sound/soc/codecs/Kconfig +4 -0
@@ -19,6 +19,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_AK4104 if SPI_MASTER select SND_SOC_AK4535 if I2C select SND_SOC_AK4642 if I2C + select SND_SOC_AK4671 if I2C select SND_SOC_CS4270 if I2C select SND_SOC_MAX9877 if I2C select SND_SOC_PCM3008
@@ -96,6 +97,9 @@ config SND_SOC_AK4535 config SND_SOC_AK4642 tristate +config SND_SOC_AK4671 + tristate + # Cirrus Logic CS4270 Codec config SND_SOC_CS4270 tristate
sound/soc/codecs/Makefile +2 -0
@@ -6,6 +6,7 @@ snd-soc-ad73311-objs := ad73311.o snd-soc-ak4104-objs := ak4104.o snd-soc-ak4535-objs := ak4535.o snd-soc-ak4642-objs := ak4642.o +snd-soc-ak4671-objs := ak4671.o snd-soc-cs4270-objs := cs4270.o snd-soc-cx20442-objs := cx20442.o snd-soc-l3-objs := l3.o
@@ -56,6 +57,7 @@ obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o obj-$(CONFIG_SND_SOC_AK4642) += snd-soc-ak4642.o +obj-$(CONFIG_SND_SOC_AK4671) += snd-soc-ak4671.o obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
sound/soc/codecs/ak4671.c new file +898 -0
898 lines not on this page · raw message
sound/soc/codecs/ak4671.h new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Quoted 7 lines · Joonyoung Shim
The AK4671 is a stereo CODEC with a built-in Microphone-Amplifier, Receiver-Amplifier and Headphone-Amplifier.
The datasheet for the ak4671 can find at the following url:
http://www.asahi-kasei.co.jp/akm/en/product/ak4671/ak4671_f01e.pdfSigned-off-by Joonyoung Shim <[email protected]>
This looks very good, everything below is relatively minor.
Quoted 9 lines
sound/soc/codecs/ak4671.c new file +9
-0+/* write to the ak4671 register space */ +static int ak4671_write (struct snd_soc_codec *codec,unsigned int reg, +unsigned int value) +{ +u8 data[2 ]; + +/* data is +* D15..D8 AK4671 register offset +* D7...D0 register data
sound/soc/codecs/ak4671.c line 172
Quoted 10 lines
sound/soc/codecs/ak4671.c new file +10
-0+*/ + data[0 ] = reg &0xff ; + data[1 ] = value &0xff ; + +ak4671_write_reg_cache (codec, reg, value); +if (codec->hw_write (codec->control_data, data,2 ) ==2 ) +return 0 ; +else +return -EIO ; +}
It would be nice (but not essential) to move over to soc-cache if possible - see the current for-2.6.32 code.
sound/soc/codecs/ak4671.c line 207
Quoted 8 lines
sound/soc/codecs/ak4671.c new file +8
-0+static const struct snd_kcontrol_new ak4671_snd_controls[] = { +/* Common playback gain controls */ +SOC_SINGLE_TLV ("Stereo Line Output1 Playback Volume" , +AK4671_OUTPUT_VOLUME_CONTROL ,0 ,0x6 ,0 , out1_tlv), +SOC_SINGLE_TLV ("Headphone Output2 Playback Volume" , +AK4671_OUTPUT_VOLUME_CONTROL ,4 ,0xd ,0 , out2_tlv), +SOC_SINGLE_TLV ("Stereo Line Output3 Playback Volume" , +AK4671_LOUT3_POWER_MANAGERMENT ,6 ,0x3 ,0 , out3_tlv),
Could drop the "Stereo" from the control names - it'll probably read better in applications.
sound/soc/codecs/ak4671.c line 602
Quoted 12 lines
sound/soc/codecs/ak4671.c new file +12
-0+switch (fmt &SND_SOC_DAIFMT_MASTER_MASK ) { +case SND_SOC_DAIFMT_CBM_CFM : + ak4671->pll_on =1 ; + mode |=AK4671_M_S ; +break ; +case SND_SOC_DAIFMT_CBM_CFS : + ak4671->pll_on =1 ; + mode &= ~(AK4671_M_S ); +break ; +default : +return -EINVAL ; + }
Looks like pll_on is always set? If that's true then there's not much gain from keeping track of it.
Quoted 9 lines
sound/soc/codecs/ak4671.c new file +9
-0+/* event handlers */ +static int ak4671_set_bias_level (struct snd_soc_codec *codec, +enum snd_soc_bias_level level) +{ +struct ak4671_priv *ak4671 = codec->private_data; +u8 reg; + +switch (level) { +case SND_SOC_BIAS_ON :
sound/soc/codecs/ak4671.c line 648
Quoted 10 lines
sound/soc/codecs/ak4671.c new file +10
-0+case SND_SOC_BIAS_PREPARE : +case SND_SOC_BIAS_STANDBY : +if (ak4671->pll_on) { + reg =ak4671_read_reg_cache (codec, +AK4671_PLL_MODE_SELECT1 ); + reg |=AK4671_PMPLL ; +ak4671_write (codec,AK4671_PLL_MODE_SELECT1 , reg); +/* pll lock time: max 40ms */ +mdelay (40 ); + }
I suspect this will run into trouble with bypass paths (which do appear to exist if I read the DAPM routes correctly). If a bypass path is active then the CODEC will be brought up to full bias out of sync with any configuration of pll_on by the DAI format configuration.
I've not looked at the datasheet but I think what you need here is to make the PLL a SND_SOC_DAPM_SUPPLY for the DACs and ADCs, then use an event on that to turn on and off the PLL. DAPM will then keep the PLL powered so long as one of the DACs or ADCs is in use.
sound/soc/codecs/ak4671.c line 682
Quoted 6 lines
sound/soc/codecs/ak4671.c new file +6
-0+static struct snd_soc_dai_ops ak4671_dai_ops = { + .hw_params = ak4671_hw_params, + .set_sysclk = ak4671_set_dai_sysclk, + .set_fmt = ak4671_set_dai_fmt, + +/* TODO */
Could just remove the comment here.
Quoted 8 lines
sound/soc/codecs/ak4671.c new file +8
-0+#ifdef CONFIG_PM +static int ak4671_suspend (struct platform_device *pdev,pm_message_t state) +{ +/* TODO */ + +return 0 ; +} +
sound/soc/codecs/ak4671.c line 772
Quoted 10 lines
sound/soc/codecs/ak4671.c new file +10
-0+static int ak4671_resume (struct platform_device *pdev) +{ +/* TODO */ + +return 0 ; +} +#else +#define ak4671_suspend NULL +#define ak4671_resume NULL +#endif
May as well just remove these completely if they're not implemented.
Quoted 25 lines · Mark Brown
Quoted 7 lines · Joonyoung Shim
The AK4671 is a stereo CODEC with a built-in Microphone-Amplifier, Receiver-Amplifier and Headphone-Amplifier.
The datasheet for the ak4671 can find at the following url:
http://www.asahi-kasei.co.jp/akm/en/product/ak4671/ak4671_f01e.pdfSigned-off-by Joonyoung Shim <[email protected]>This looks very good, everything below is relatively minor.
Quoted 14 lines
sound/soc/codecs/ak4671.c new file +14
-0+/* write to the ak4671 register space */ +static int ak4671_write (struct snd_soc_codec *codec,unsigned int reg, +unsigned int value) +{ +u8 data[2 ]; + +/* data is +* D15..D8 AK4671 register offset +* D7...D0 register data +*/ + data[0 ] = reg &0xff ; + data[1 ] = value &0xff ; + +ak4671_write_reg_cache (codec, reg, value);
Quoted 9 lines
sound/soc/codecs/ak4671.c line 172
Quoted 5 lines
sound/soc/codecs/ak4671.c new file +5
-0+if (codec->hw_write (codec->control_data, data,2 ) ==2 ) +return 0 ; +else +return -EIO ; +}It would be nice (but not essential) to move over to soc-cache if possible - see the current for-2.6.32 code.
I saw the soc-cache code. Ok, i will move to soc-cache, test it.
Quoted 12 lines
sound/soc/codecs/ak4671.c line 207
Quoted 8 lines
sound/soc/codecs/ak4671.c new file +8
-0+static const struct snd_kcontrol_new ak4671_snd_controls[] = { +/* Common playback gain controls */ +SOC_SINGLE_TLV ("Stereo Line Output1 Playback Volume" , +AK4671_OUTPUT_VOLUME_CONTROL ,0 ,0x6 ,0 , out1_tlv), +SOC_SINGLE_TLV ("Headphone Output2 Playback Volume" , +AK4671_OUTPUT_VOLUME_CONTROL ,4 ,0xd ,0 , out2_tlv), +SOC_SINGLE_TLV ("Stereo Line Output3 Playback Volume" , +AK4671_LOUT3_POWER_MANAGERMENT ,6 ,0x3 ,0 , out3_tlv),Could drop the "Stereo" from the control names - it'll probably read better in applications.
Ok.
Quoted 13 lines
sound/soc/codecs/ak4671.c line 602
Quoted 12 lines
sound/soc/codecs/ak4671.c new file +12
-0+switch (fmt &SND_SOC_DAIFMT_MASTER_MASK ) { +case SND_SOC_DAIFMT_CBM_CFM : + ak4671->pll_on =1 ; + mode |=AK4671_M_S ; +break ; +case SND_SOC_DAIFMT_CBM_CFS : + ak4671->pll_on =1 ; + mode &= ~(AK4671_M_S ); +break ; +default : +return -EINVAL ; + }
Quoted 3 lines
Looks like
pll_onis always set? If that's true then there's not much gain from keeping track of it.
The ak4671 supports four mode.
1. PLL Master Mode
2. PLL Slave Mode
3. EXT Slave Mode
4. EXT Master Mode
The 1 and 2 mode need pll_on set but the 3 and 4 mode don't need pll_on set, but i didn't implemented EXT mode yet.
Ok, I will remove the pll_on keeping until implementing the EXT mode.
Quoted 16 lines
Quoted 16 lines
sound/soc/codecs/ak4671.c new file +16
-0+/* event handlers */ +static int ak4671_set_bias_level (struct snd_soc_codec *codec, +enum snd_soc_bias_level level) +{ +struct ak4671_priv *ak4671 = codec->private_data; +u8 reg; + +switch (level) { +case SND_SOC_BIAS_ON : +case SND_SOC_BIAS_PREPARE : +case SND_SOC_BIAS_STANDBY : +if (ak4671->pll_on) { + reg =ak4671_read_reg_cache (codec, +AK4671_PLL_MODE_SELECT1 ); + reg |=AK4671_PMPLL ; +ak4671_write (codec,AK4671_PLL_MODE_SELECT1 , reg);
Quoted 9 lines
sound/soc/codecs/ak4671.c line 648
Quoted 3 lines
sound/soc/codecs/ak4671.c new file +3
-0+/* pll lock time: max 40ms */ +mdelay (40 ); + }I suspect this will run into trouble with bypass paths (which do appear to exist if I read the DAPM routes correctly). If a bypass path is active then the CODEC will be brought up to full bias out of sync with any configuration of
pll_onby the DAI format configuration.
A bypass path should operate regardless pll_on.
Quoted 5 lines
I've not looked at the datasheet but I think what you need here is to make the PLL a
SND_SOC_DAPM_SUPPLYfor the DACs and ADCs, then use an event on that to turn on and off the PLL. DAPM will then keep the PLL powered so long as one of the DACs or ADCs is in use.
I'll check about this.
Quoted 9 lines
sound/soc/codecs/ak4671.c line 682
Quoted 6 lines
sound/soc/codecs/ak4671.c new file +6
-0+static struct snd_soc_dai_ops ak4671_dai_ops = { + .hw_params = ak4671_hw_params, + .set_sysclk = ak4671_set_dai_sysclk, + .set_fmt = ak4671_set_dai_fmt, + +/* TODO */ Could just remove the comment here.
This is my fault. I will remove the comment.
Quoted 12 lines
Quoted 12 lines
sound/soc/codecs/ak4671.c new file +12
-0+#ifdef CONFIG_PM +static int ak4671_suspend (struct platform_device *pdev,pm_message_t state) +{ +/* TODO */ + +return 0 ; +} + +static int ak4671_resume (struct platform_device *pdev) +{ +/* TODO */ +
Quoted 9 lines
sound/soc/codecs/ak4671.c line 772
Quoted 6 lines
sound/soc/codecs/ak4671.c new file +6
-0+ return 0; +} +#else +#define ak4671_suspend NULL +#define ak4671_resume NULL +#endif May as well just remove these completely if they're not implemented.
I will remove it.
Thanks.
Quoted 11 lines · Joonyoung Shim
Quoted 7 lines · Mark Brown
Review
Quoted 2 lines
(quoted diff) +2
-0+ case SND_SOC_BIAS_STANDBY: + if (ak4671->pll_on) {I suspect this will run into trouble with bypass paths (which do appear to exist if I read the DAPM routes correctly). If a bypass path is active then the CODEC will be brought up to full bias out of sync with any configuration of
pll_onby the DAI format configuration.A bypass path should operate regardless
pll_on.
Yes, I'd expect the bypass path itself to be fine. What I'm concerned about is that because with newer ASoC versions the bypass path will cause the CODEC to change bias levels independantly of playback and record starting the PLL will be configured when the bypass path is enabled rather than when record/playback is started. This may cause things to get out of sync.
2009/9/4 Mark Brown <[email protected]>:
Quoted 11 lines · Joonyoung Shim
Quoted 9 lines · Mark Brown
Quoted 8 lines
Quoted 3 lines
+ case
SND_SOC_BIAS_STANDBY:
+ if (ak4671->pll_on) {I suspect this will run into trouble with bypass paths (which do appear to exist if I read the DAPM routes correctly). If a bypass path is active then the CODEC will be brought up to full bias out of sync with any configuration of
pll_onby the DAI format configuration.
Quoted 9 lines
Quoted 1 line
A bypass path should operate regardless
pll_on.Yes, I'd expect the bypass path itself to be fine. What I'm concerned about is that because with newer ASoC versions the bypass path will cause the CODEC to change bias levels independantly of playback and record starting the PLL will be configured when the bypass path is enabled rather than when record/playback is started. This may cause things to get out of sync.
Right, so i will use SND_SOC_DAPM_DAC_E and SND_SOC_DAPM_ADC_E. This event handler desides the setting of PLL, then PLL can be configured regardless the bypass path.
_______________________________________________
Quoted 4 lines
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 3 lines · Joonyoung Shim
Right, so i will use
SND_SOC_DAPM_DAC_EandSND_SOC_DAPM_ADC_E. This event handler desides the setting of PLL, then PLL can be configured regardless the bypass path.
That sounds good - a supply might be even easier (since the core will then reference count all the DACs and ADCs) but either is fine.