ASoC: add RT5670 CODEC driver
Subsystems (3)
PATCH 1/1 ASoC: add RT5670 CODEC driver
From: Bard Liao <[email protected]>
This patch adds a minimum support of Realtek ALC5670 codec.
---
Currently, only playback with headphone or line out and capture with digital mic are tested. We will add other patches for other functions.
--- include/sound/rt5670.h | 27 + sound/soc/codecs/Kconfig | 6 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/rt5670-dsp.h | 54 + sound/soc/codecs/rt5670.c | 2720 +++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/rt5670.h | 2000 ++++++++++++++++++++++++++++++ 6 files changed, 4809 insertions(+) create mode 100644 include/sound/rt5670.h create mode 100644 sound/soc/codecs/rt5670-dsp.h create mode 100644 sound/soc/codecs/rt5670.c create mode 100644 sound/soc/codecs/rt5670.h
include/sound/rt5670.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* linux/sound/rt5670.h -- Platform data for RT5670 +* +* Copyright 2014 Realtek Microelectronics +* +* 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 __LINUX_SND_RT5670_H +#define __LINUX_SND_RT5670_H + +struct rt5670_platform_data { +int jd_mode; +bool in2_diff; + +bool dmic_en; +unsigned int dmic1_data_pin; +/* 0 = GPIO6; 1 = IN2P; 3 = GPIO7*/ +unsigned int dmic2_data_pin; +/* 0 = GPIO8; 1 = IN3N; */ +unsigned int dmic3_data_pin; +/* 0 = GPIO9; 1 = GPIO10; 2 = GPIO5*/ +}; + +#endif
sound/soc/codecs/Kconfig +6 -0
@@ -78,6 +78,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_RT5640 if I2C select SND_SOC_RT5645 if I2C select SND_SOC_RT5651 if I2C + select SND_SOC_RT5670 if I2C select SND_SOC_RT5677 if I2C select SND_SOC_SGTL5000 if I2C select SND_SOC_SI476X if MFD_SI476X_CORE
@@ -445,9 +446,11 @@ config SND_SOC_RL6231 default y if SND_SOC_RT5640=y default y if SND_SOC_RT5645=y default y if SND_SOC_RT5651=y + default y if SND_SOC_RT5670=y default m if SND_SOC_RT5640=m default m if SND_SOC_RT5645=m default m if SND_SOC_RT5651=m + default m if SND_SOC_RT5670=m config SND_SOC_RT5631 tristate
@@ -461,6 +464,9 @@ config SND_SOC_RT5645 config SND_SOC_RT5651 tristate +config SND_SOC_RT5670 + tristate + config SND_SOC_RT5677 tristate
sound/soc/codecs/Makefile +2 -0
@@ -72,6 +72,7 @@ snd-soc-rt5631-objs := rt5631.o snd-soc-rt5640-objs := rt5640.o snd-soc-rt5645-objs := rt5645.o snd-soc-rt5651-objs := rt5651.o +snd-soc-rt5670-objs := rt5670.o snd-soc-rt5677-objs := rt5677.o snd-soc-sgtl5000-objs := sgtl5000.o snd-soc-alc5623-objs := alc5623.o
@@ -237,6 +238,7 @@ obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o obj-$(CONFIG_SND_SOC_RT5651) += snd-soc-rt5651.o +obj-$(CONFIG_SND_SOC_RT5670) += snd-soc-rt5670.o obj-$(CONFIG_SND_SOC_RT5677) += snd-soc-rt5677.o obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o
sound/soc/codecs/rt5670-dsp.h new file +54 -0
54 lines not on this page · raw message
sound/soc/codecs/rt5670.c new file +2720 -0
2,720 lines not on this page · raw message
sound/soc/codecs/rt5670.h new file +2000 -0
158 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.1.1.439.g50a6b54
Part of the diff is not shown here. View the raw message.
Mark Brown
maintainerQuoted 1 line · On Fri, Jun 06, 2014 at 12:15:38PM +0800, [email protected] wrote:
This patch adds a minimum support of Realtek ALC5670 codec.
This looks good overall, there are a few issues I've identified below but they're relatively small.
sound/soc/codecs/rt5670.c line 458
Quoted 5 lines
sound/soc/codecs/rt5670.c new file +5
-0+/* IN1/IN2 Control */ +SOC_SINGLE_TLV ("IN1 Boost" ,RT5670_CJ_CTRL1 , +RT5670_BST_SFT1 ,8 ,0 , bst_tlv), +SOC_SINGLE_TLV ("IN2 Boost" ,RT5670_IN2 , + RT5670_BST_SFT1, 8, 0, bst_tlv),
Boost Volume.
sound/soc/codecs/rt5670.c line 481
Quoted 7 lines
sound/soc/codecs/rt5670.c new file +7
-0+/* ADC Boost Volume Control */ +SOC_DOUBLE_TLV ("STO1 ADC Boost Gain" ,RT5670_ADC_BST_VOL1 , +RT5670_STO1_ADC_L_BST_SFT ,RT5670_STO1_ADC_R_BST_SFT , +3 ,0 , adc_bst_tlv), +SOC_DOUBLE_TLV ("STO2 ADC Boost Gain" ,RT5670_ADC_BST_VOL1 , +RT5670_STO2_ADC_L_BST_SFT ,RT5670_STO2_ADC_R_BST_SFT , + 3, 0, adc_bst_tlv),
s/Gain/Volume/
sound/soc/codecs/rt5670.c line 596
Quoted 7 lines
sound/soc/codecs/rt5670.c new file +7
-0+static int check_dac_monor_asrc_source (struct snd_soc_dapm_widget *source, +struct snd_soc_dapm_widget *sink) +{ +struct snd_soc_codec *codec = source->codec; + +return is_using_asrc (codec,RT5670_ASRC_2 ,4 ); +}
I have to say I'm not convinced all these wrapper functions are really adding much - just making is_using_asrc() take a widget and passing the arguments directly seems as simple.
Quoted 9 lines
sound/soc/codecs/rt5670.c new file +9
-0+/* ASRC */ +SND_SOC_DAPM_SUPPLY_S ("I2S1 ASRC" ,1 ,RT5670_ASRC_1 , +11 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("I2S2 ASRC" ,1 ,RT5670_ASRC_1 , +12 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("DAC STO ASRC" ,1 ,RT5670_ASRC_1 , +10 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("DAC MONO L ASRC" ,1 ,RT5670_ASRC_1 , + 9, 0, NULL, 0),
sound/soc/codecs/rt5670.c line 1346
Quoted 10 lines
sound/soc/codecs/rt5670.c new file +10
-0+SND_SOC_DAPM_SUPPLY_S ("DAC MONO R ASRC" ,1 ,RT5670_ASRC_1 , +8 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("ADC STO1 ASRC" ,1 ,RT5670_ASRC_1 , +3 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("ADC STO2 ASRC" ,1 ,RT5670_ASRC_1 , +2 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("ADC MONO L ASRC" ,1 ,RT5670_ASRC_1 , +1 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("ADC MONO R ASRC" ,1 ,RT5670_ASRC_1 , + 0, 0, NULL, 0),
These are all _S but they seem not to have different sequence numbers - do they really need to be _S.
sound/soc/codecs/rt5670.c line 1351
Quoted 4 lines
sound/soc/codecs/rt5670.c new file +4
-0+/* Input Side */ +/* micbias */ +SND_SOC_DAPM_MICBIAS ("MICBIAS1" ,RT5670_PWR_ANLG2 , + RT5670_PWR_MB1_BIT, 0),
Modern drivers should use supply widgets for MICBIAS.
Quoted 7 lines
sound/soc/codecs/rt5670.c new file +7
-0+static const struct snd_soc_dapm_route rt5670_dapm_routes[] = { + {"adc stereo1 filter" ,NULL ,"ADC STO1 ASRC" , + check_adc_sto1_asrc_source }, + {"adc stereo2 filter" ,NULL ,"ADC STO2 ASRC" , + check_adc_sto2_asrc_source }, + {"adc mono left filter" ,NULL ,"ADC MONO L ASRC" , + check_adc_monol_asrc_source },
sound/soc/codecs/rt5670.c line 1692
Quoted 10 lines
sound/soc/codecs/rt5670.c new file +10
-0+ {"adc mono right filter" ,NULL ,"ADC MONO R ASRC" , + check_adc_monor_asrc_source }, + { "dac mono left filter", NULL, "DAC MONO L ASRC", + check_dac_monol_asrc_source }, + { "dac mono right filter", NULL, "DAC MONO R ASRC", + check_dac_monor_asrc_source }, + { "dac stereo1 filter", NULL, "DAC STO ASRC", + check_dac_sto_asrc_source }, + + {"I2S1", NULL, "I2S1 ASRC"},
Coding style here is a bit inconsistent, and normally widget names are capitalised.
sound/soc/codecs/rt5670.c line 2184
Quoted 7 lines
sound/soc/codecs/rt5670.c new file +7
-0+switch (dai->id) { +case RT5670_AIF1 : +snd_soc_update_bits (codec,RT5670_I2S1_SDP , +RT5670_I2S_MS_MASK |RT5670_I2S_BP_MASK | +RT5670_I2S_DF_MASK , reg_val); +break ; +case RT5670_AIF2 :
Extra space.
Quoted 4 lines
sound/soc/codecs/rt5670.c new file +4
-0+switch (slots) { +case 4 : + val |= (1 <<12 ); +break ;
sound/soc/codecs/rt5670.c line 2325
Quoted 10 lines
sound/soc/codecs/rt5670.c new file +10
-0+case 6 : + val |= (2 <<12 ); +break ; +case 8 : + val |= (3 <<12 ); +break ; +case 2 : +default : +break ; + }
This seems wrong - the code will map all unknown slot counts to stereo which probably won't do what was expected.
Quoted 4 lines
sound/soc/codecs/rt5670.c new file +4
-0+switch (slot_width) { +case 20 : + val |= (1 <<10 ); +break ;
sound/soc/codecs/rt5670.c line 2340
Quoted 10 lines
sound/soc/codecs/rt5670.c new file +10
-0+case 24 : + val |= (2 <<10 ); +break ; +case 32 : + val |= (3 <<10 ); +break ; +case 16 : +default : +break ; + }
Similarly here for 16 bits.
sound/soc/codecs/rt5670.c line 2400
Quoted 11 lines
sound/soc/codecs/rt5670.c new file +11
-0+static int rt5670_probe (struct snd_soc_codec *codec) +{ +struct rt5670_priv *rt5670 =snd_soc_codec_get_drvdata (codec); + + rt5670->codec = codec; + +snd_soc_update_bits (codec,RT5670_GEN_CTRL3 ,0x4 ,0x4 ); +rt5670_set_bias_level (codec,SND_SOC_BIAS_OFF ); + +return 0 ; +}
I would expect this setup to be done in the bus level probe() rather than at ASoC level.
Quoted 10 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Friday, June 27, 2014 11:32 PM
To: Bard Liao
Cc: [email protected]; [email protected]; [email protected]; Flove; Oder Chiou
Subject: Re: [PATCH] ASoC: add RT5670 CODEC driverQuoted 1 line
+static int check_dac_monor_asrc_source(struct
snd_soc_dapm_widget*source,
Quoted 8 lines
sound/soc/codecs/rt5670.c
Quoted 4 lines
sound/soc/codecs/rt5670.c new file +4
-0+ struct snd_soc_dapm_widget *sink) { +struct snd_soc_codec *codec = source->codec; + +return is_using_asrc (codec,RT5670_ASRC_2 ,4 ); }I have to say I'm not convinced all these wrapper functions are really adding much - just making
is_using_asrc()take a widget and passing the arguments directly seems as simple.
Do you mean use is_using_asrc() as the checking function for all of those widgets, and use different arguments for different widgets?
Quoted 20 lines
sound/soc/codecs/rt5670.c
Quoted 9 lines
sound/soc/codecs/rt5670.c new file +8
-0+/* ASRC */ +SND_SOC_DAPM_SUPPLY_S ("I2S1 ASRC" ,1 ,RT5670_ASRC_1 , +11 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("I2S2 ASRC" ,1 ,RT5670_ASRC_1 , +12 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("DAC STO ASRC" ,1 ,RT5670_ASRC_1 , +10 ,0 ,NULL ,0 ), + SND_SOC_DAPM_SUPPLY_S("DAC MONO L ASRC", 1,
RT5670_ASRC_1,Review
Quoted 2 lines
(quoted diff) +2
-0+ 9, 0, NULL, 0), + SND_SOC_DAPM_SUPPLY_S("DAC MONO R ASRC", 1,
RT5670_ASRC_1,sound/soc/codecs/rt5670.c
Quoted 6 lines
sound/soc/codecs/rt5670.c new file +6
-0+ 8, 0, NULL, 0), +SND_SOC_DAPM_SUPPLY_S ("ADC STO1 ASRC" ,1 ,RT5670_ASRC_1 , +3 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY_S ("ADC STO2 ASRC" ,1 ,RT5670_ASRC_1 , +2 ,0 ,NULL ,0 ), + SND_SOC_DAPM_SUPPLY_S("ADC MONO L ASRC", 1,
RT5670_ASRC_1,
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ 1, 0, NULL, 0), + SND_SOC_DAPM_SUPPLY_S("ADC MONO R ASRC", 1,
RT5670_ASRC_1,sound/soc/codecs/rt5670.c line 1346
Quoted 1 line
sound/soc/codecs/rt5670.c new file +1
-0+ 0, 0, NULL, 0),These are all _S but they seem not to have different sequence numbers - do they really need to be _S.
Yes, all of them should be powered up after filter powers. But it doesn't matter which ASRC power is power up first. That's why we set the same sequence for each ASRC widget.
Quoted 1 line
------Please consider the environment before printing this e-mail.
Mark Brown
maintainerQuoted 11 lines · Bard Liao
Quoted 10 lines
Quoted 1 line
+static int check_dac_monor_asrc_source(struct
snd_soc_dapm_widget*source,
sound/soc/codecs/rt5670.c
Quoted 4 lines
sound/soc/codecs/rt5670.c new file +4
-0+ struct snd_soc_dapm_widget *sink) { +struct snd_soc_codec *codec = source->codec; + +return is_using_asrc (codec,RT5670_ASRC_2 ,4 ); }I have to say I'm not convinced all these wrapper functions are really adding much - just making
is_using_asrc()take a widget and passing the arguments directly seems as simple.
Quoted 2 lines
Do you mean use
is_using_asrc()as the checking function for all of those widgets, and use different arguments for different widgets?
Yes, it seems like that's all the functions do which isn't adding much.