ASoC: AK4671: add ak4671 codec driver
PATCH v2 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
---
Change log:
v2: - use soc-cache
- remove unused pll_on variable
- add event handler for DAC and ADC
- remove unnecessary comments and PM functions
- modify error handling in ak4671_register function
sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/ak4671.c | 845 +++++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/ak4671.h | 156 +++++++++ 4 files changed, 1007 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 +845 -0
845 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 10 lines · Joonyoung Shim
sound/soc/codecs/ak4671.c new file +10
-0+static int ak4671_pll_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) +{ +struct snd_soc_codec *codec = w->codec; +u8 reg; + +switch (event) { +case SND_SOC_DAPM_PRE_PMU : + reg =snd_soc_read (codec,AK4671_PLL_MODE_SELECT1 ); + reg |=AK4671_PMPLL ;
sound/soc/codecs/ak4671.c line 210
Quoted 10 lines
sound/soc/codecs/ak4671.c new file +10
-0+snd_soc_write (codec,AK4671_PLL_MODE_SELECT1 , reg); +/* pll lock time: max 40ms */ +mdelay (40 ); +break ; +case SND_SOC_DAPM_POST_PMD : + reg =snd_soc_read (codec,AK4671_PLL_MODE_SELECT1 ); + reg &= ~AK4671_PMPLL ; +snd_soc_write (codec,AK4671_PLL_MODE_SELECT1 , reg); +break ; + }
I think you need some reference counting or a supply widget here since this event is there for all the DACs and ADCs:
Quoted 5 lines
sound/soc/codecs/ak4671.c new file +5
-0+/* DAC */ +SND_SOC_DAPM_DAC_E ("DAC Left" ,"Left HiFi Playback" , +AK4671_AD_DA_POWER_MANAGEMENT ,6 ,0 , ak4671_pll_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD ), + SND_SOC_DAPM_DAC_E("DAC Right", "Right HiFi Playback",
sound/soc/codecs/ak4671.c line 322
Quoted 10 lines
sound/soc/codecs/ak4671.c new file +10
-0+ AK4671_AD_DA_POWER_MANAGEMENT, 7, 0, ak4671_pll_event, + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + +/* ADC */ +SND_SOC_DAPM_ADC_E ("ADC Left" ,"Left HiFi Capture" , +AK4671_AD_DA_POWER_MANAGEMENT ,4 ,0 , ak4671_pll_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD ), +SND_SOC_DAPM_ADC_E ("ADC Right" ,"Right HiFi Capture" , +AK4671_AD_DA_POWER_MANAGEMENT ,5 ,0 , ak4671_pll_event, + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
This shouldn't be a problem if they all go on or off at once (except for the extra latency from waiting for the PLL to go on) but unless I'm missing something if capture and playback are stopped independantly I'd expect that the PLL will get shut down when the first one happens, causing problems for the still active stream.
Quoted 39 lines · Mark Brown
Quoted 10 lines · Joonyoung Shim
sound/soc/codecs/ak4671.c new file +10
-0+static int ak4671_pll_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) +{ +struct snd_soc_codec *codec = w->codec; +u8 reg; + +switch (event) { +case SND_SOC_DAPM_PRE_PMU : + reg =snd_soc_read (codec,AK4671_PLL_MODE_SELECT1 ); + reg |=AK4671_PMPLL ;sound/soc/codecs/ak4671.c line 210
Quoted 10 lines
sound/soc/codecs/ak4671.c new file +10
-0+snd_soc_write (codec,AK4671_PLL_MODE_SELECT1 , reg); +/* pll lock time: max 40ms */ +mdelay (40 ); +break ; +case SND_SOC_DAPM_POST_PMD : + reg =snd_soc_read (codec,AK4671_PLL_MODE_SELECT1 ); + reg &= ~AK4671_PMPLL ; +snd_soc_write (codec,AK4671_PLL_MODE_SELECT1 , reg); +break ; + }I think you need some reference counting or a supply widget here since this event is there for all the DACs and ADCs:
Quoted 13 lines
sound/soc/codecs/ak4671.c new file +13
-0+/* DAC */ +SND_SOC_DAPM_DAC_E ("DAC Left" ,"Left HiFi Playback" , +AK4671_AD_DA_POWER_MANAGEMENT ,6 ,0 , ak4671_pll_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD ), +SND_SOC_DAPM_DAC_E ("DAC Right" ,"Right HiFi Playback" , +AK4671_AD_DA_POWER_MANAGEMENT ,7 ,0 , ak4671_pll_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD ), + +/* ADC */ +SND_SOC_DAPM_ADC_E ("ADC Left" ,"Left HiFi Capture" , +AK4671_AD_DA_POWER_MANAGEMENT ,4 ,0 , ak4671_pll_event, +SND_SOC_DAPM_PRE_PMU |SND_SOC_DAPM_POST_PMD ), + SND_SOC_DAPM_ADC_E("ADC Right", "Right HiFi Capture",
Quoted 9 lines
sound/soc/codecs/ak4671.c line 322
Quoted 2 lines
sound/soc/codecs/ak4671.c new file +2
-0+AK4671_AD_DA_POWER_MANAGEMENT ,5 ,0 , ak4671_pll_event, + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),This shouldn't be a problem if they all go on or off at once (except for the extra latency from waiting for the PLL to go on) but unless I'm missing something if capture and playback are stopped independantly I'd expect that the PLL will get shut down when the first one happens, causing problems for the still active stream.
OK. I was not far-sighted enough to think of that. I will do additional try to handle it.
Thanks.