ASoC: codecs: ad193x: Group register initialization at probe
Subsystems (3)
PATCH 1/2 ASoC: codecs: ad193x: Group register initialization at probe
Create a structure with the register initialization values at probe and use it to initialize all the registers at once.
---
The order of the initialization is changed, but it doesn't seem to matter.
There is one checkpatch warning, let me know if you want to remove it:
WARNING: line over 80 characters
#32: FILE: sound/soc/codecs/ad193x.c:425:
+ { 0, 0x99 }, /* PLL_CLK_CTRL0: pll input: mclki/xi 12.288Mhz */
sound/soc/codecs/ad193x.c | 52 +++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 19 deletions(-)
sound/soc/codecs/ad193x.c +33 -19
@@ -413,6 +413,38 @@ static struct snd_soc_dai_driver ad193x_no_adc_dai = { .ops = &ad193x_dai_ops, }; +struct ad193x_reg_default { +unsigned int reg; +unsigned int val; +}; + +/* codec register values to set after reset */ +static void ad193x_reg_default_init (struct ad193x_priv *ad193x) +{ +const struct ad193x_reg_default reg_init[] = { + {0 ,0x99 },/* PLL_CLK_CTRL0: pll input: mclki/xi 12.288Mhz */ + {1 ,0x04 },/* PLL_CLK_CTRL1: no on-chip Vref */ + {2 ,0x40 },/* DAC_CTRL0: TDM mode */ + {4 ,0x1A },/* DAC_CTRL2: 48kHz de-emphasis, unmute dac */ + {5 ,0x00 },/* DAC_CHNL_MUTE: unmute DAC channels */ + }; +const struct ad193x_reg_default reg_adc_init[] = { + {14 ,0x03 },/* ADC_CTRL0: high-pass filter enable */ + {15 ,0x43 },/* ADC_CTRL1: sata delay=1, adc aux mode */ + }; +int i; + +for (i =0 ; i <ARRAY_SIZE (reg_init); i++) +regmap_write (ad193x->regmap, reg_init[i].reg, reg_init[i].val); + +if (ad193x_has_adc (ad193x)) { +for (i =0 ; i <ARRAY_SIZE (reg_adc_init); i++) { +regmap_write (ad193x->regmap, reg_adc_init[i].reg, + reg_adc_init[i].val); + } + } +} +static int ad193x_component_probe (struct snd_soc_component *component) {struct ad193x_priv *ad193x =snd_soc_component_get_drvdata (component);
@@ -420,25 +452,7 @@ static int ad193x_component_probe(struct snd_soc_component *component)int num, ret;/* default setting for ad193x */ - -/* unmute dac channels */ -regmap_write (ad193x->regmap,AD193X_DAC_CHNL_MUTE ,0x0 ); -/* de-emphasis: 48kHz, powedown dac */ -regmap_write (ad193x->regmap,AD193X_DAC_CTRL2 ,0x1A ); -/* dac in tdm mode */ -regmap_write (ad193x->regmap,AD193X_DAC_CTRL0 ,0x40 ); - -/* adc only */ -if (ad193x_has_adc (ad193x)) { -/* high-pass filter enable */ -regmap_write (ad193x->regmap,AD193X_ADC_CTRL0 ,0x3 ); -/* sata delay=1, adc aux mode */ -regmap_write (ad193x->regmap,AD193X_ADC_CTRL1 ,0x43 ); - } - -/* pll input: mclki/xi */ -regmap_write (ad193x->regmap,AD193X_PLL_CLK_CTRL0 ,0x99 );/* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */ -regmap_write (ad193x->regmap,AD193X_PLL_CLK_CTRL1 ,0x04 ); +ad193x_reg_default_init (ad193x);/* adc only */ if (ad193x_has_adc (ad193x)) {
Signature · 1 line
2.20.1
PATCH 2/2 ASoC: codecs: ad193x: Reset used registers at probe
Since the ad193x codecs have no software reset, we have to reinitialize the registers after a hardware reset to assure no previous values are kept.
--- sound/soc/codecs/ad193x.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
sound/soc/codecs/ad193x.c +10 -0
@@ -425,12 +425,22 @@ static void ad193x_reg_default_init(struct ad193x_priv *ad193x) { 0, 0x99 }, /* PLL_CLK_CTRL0: pll input: mclki/xi 12.288Mhz */ { 1, 0x04 }, /* PLL_CLK_CTRL1: no on-chip Vref */ { 2, 0x40 }, /* DAC_CTRL0: TDM mode */ + { 3, 0x00 }, /* DAC_CTRL1: reset */ { 4, 0x1A }, /* DAC_CTRL2: 48kHz de-emphasis, unmute dac */ { 5, 0x00 }, /* DAC_CHNL_MUTE: unmute DAC channels */ + { 6, 0x00 }, /* DAC_L1_VOL: no attenuation */ + { 7, 0x00 }, /* DAC_R1_VOL: no attenuation */ + { 8, 0x00 }, /* DAC_L2_VOL: no attenuation */ + { 9, 0x00 }, /* DAC_R2_VOL: no attenuation */ + { 10, 0x00 }, /* DAC_L3_VOL: no attenuation */ + { 11, 0x00 }, /* DAC_R3_VOL: no attenuation */ + { 12, 0x00 }, /* DAC_L4_VOL: no attenuation */ + { 13, 0x00 }, /* DAC_R4_VOL: no attenuation */ };const struct ad193x_reg_default reg_adc_init[] = { {14 ,0x03 },/* ADC_CTRL0: high-pass filter enable */ {15 ,0x43 },/* ADC_CTRL1: sata delay=1, adc aux mode */ + {16 ,0x00 },/* ADC_CTRL2: reset */ };int i;
Signature · 1 line
2.20.1
Mark Brown
maintainerApplied "ASoC: codecs: ad193x: Reset used registers at probe" to the asoc tree
The patch
ASoC: codecs: ad193x: Reset used registers at probe
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.3
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
8af6b2291e054773e2e58b2e5dbc06e981d14296Mon Sep 17 00:00:00 2001
From: Codrin Ciubotariu <[email protected]>
Date: Thu, 27 Jun 2019 15:02:08 +0300
Subject: [PATCH] ASoC: codecs: ad193x: Reset used registers at probe
Since the ad193x codecs have no software reset, we have to reinitialize the registers after a hardware reset to assure no previous values are kept.
--- sound/soc/codecs/ad193x.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
sound/soc/codecs/ad193x.c +10 -0
@@ -427,12 +427,22 @@ static void ad193x_reg_default_init(struct ad193x_priv *ad193x) { 0, 0x99 }, /* PLL_CLK_CTRL0: pll input: mclki/xi 12.288Mhz */ { 1, 0x04 }, /* PLL_CLK_CTRL1: no on-chip Vref */ { 2, 0x40 }, /* DAC_CTRL0: TDM mode */ + { 3, 0x00 }, /* DAC_CTRL1: reset */ { 4, 0x1A }, /* DAC_CTRL2: 48kHz de-emphasis, unmute dac */ { 5, 0x00 }, /* DAC_CHNL_MUTE: unmute DAC channels */ + { 6, 0x00 }, /* DAC_L1_VOL: no attenuation */ + { 7, 0x00 }, /* DAC_R1_VOL: no attenuation */ + { 8, 0x00 }, /* DAC_L2_VOL: no attenuation */ + { 9, 0x00 }, /* DAC_R2_VOL: no attenuation */ + { 10, 0x00 }, /* DAC_L3_VOL: no attenuation */ + { 11, 0x00 }, /* DAC_R3_VOL: no attenuation */ + { 12, 0x00 }, /* DAC_L4_VOL: no attenuation */ + { 13, 0x00 }, /* DAC_R4_VOL: no attenuation */ };const struct ad193x_reg_default reg_adc_init[] = { {14 ,0x03 },/* ADC_CTRL0: high-pass filter enable */ {15 ,0x43 },/* ADC_CTRL1: sata delay=1, adc aux mode */ + {16 ,0x00 },/* ADC_CTRL2: reset */ };int i;
Signature · 1 line
2.20.1
Mark Brown
maintainerApplied "ASoC: codecs: ad193x: Group register initialization at probe" to the asoc tree
In reply to Codrin CiubotariuThe patch
ASoC: codecs: ad193x: Group register initialization at probe
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.3
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
bc0a5f43d7d6ba5258a65cf00fa692845f128d3cMon Sep 17 00:00:00 2001
From: Codrin Ciubotariu <[email protected]>
Date: Thu, 27 Jun 2019 15:02:07 +0300
Subject: [PATCH] ASoC: codecs: ad193x: Group register initialization at probe
Create a structure with the register initialization values at probe and use it to initialize all the registers at once.
--- sound/soc/codecs/ad193x.c | 52 +++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 19 deletions(-)
sound/soc/codecs/ad193x.c +33 -19
@@ -415,6 +415,38 @@ static struct snd_soc_dai_driver ad193x_no_adc_dai = { .ops = &ad193x_dai_ops, }; +struct ad193x_reg_default { +unsigned int reg; +unsigned int val; +}; + +/* codec register values to set after reset */ +static void ad193x_reg_default_init (struct ad193x_priv *ad193x) +{ +const struct ad193x_reg_default reg_init[] = { + {0 ,0x99 },/* PLL_CLK_CTRL0: pll input: mclki/xi 12.288Mhz */ + {1 ,0x04 },/* PLL_CLK_CTRL1: no on-chip Vref */ + {2 ,0x40 },/* DAC_CTRL0: TDM mode */ + {4 ,0x1A },/* DAC_CTRL2: 48kHz de-emphasis, unmute dac */ + {5 ,0x00 },/* DAC_CHNL_MUTE: unmute DAC channels */ + }; +const struct ad193x_reg_default reg_adc_init[] = { + {14 ,0x03 },/* ADC_CTRL0: high-pass filter enable */ + {15 ,0x43 },/* ADC_CTRL1: sata delay=1, adc aux mode */ + }; +int i; + +for (i =0 ; i <ARRAY_SIZE (reg_init); i++) +regmap_write (ad193x->regmap, reg_init[i].reg, reg_init[i].val); + +if (ad193x_has_adc (ad193x)) { +for (i =0 ; i <ARRAY_SIZE (reg_adc_init); i++) { +regmap_write (ad193x->regmap, reg_adc_init[i].reg, + reg_adc_init[i].val); + } + } +} +static int ad193x_component_probe (struct snd_soc_component *component) {struct ad193x_priv *ad193x =snd_soc_component_get_drvdata (component);
@@ -422,25 +454,7 @@ static int ad193x_component_probe(struct snd_soc_component *component)int num, ret;/* default setting for ad193x */ - -/* unmute dac channels */ -regmap_write (ad193x->regmap,AD193X_DAC_CHNL_MUTE ,0x0 ); -/* de-emphasis: 48kHz, powedown dac */ -regmap_write (ad193x->regmap,AD193X_DAC_CTRL2 ,0x1A ); -/* dac in tdm mode */ -regmap_write (ad193x->regmap,AD193X_DAC_CTRL0 ,0x40 ); - -/* adc only */ -if (ad193x_has_adc (ad193x)) { -/* high-pass filter enable */ -regmap_write (ad193x->regmap,AD193X_ADC_CTRL0 ,0x3 ); -/* sata delay=1, adc aux mode */ -regmap_write (ad193x->regmap,AD193X_ADC_CTRL1 ,0x43 ); - } - -/* pll input: mclki/xi */ -regmap_write (ad193x->regmap,AD193X_PLL_CLK_CTRL0 ,0x99 );/* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */ -regmap_write (ad193x->regmap,AD193X_PLL_CLK_CTRL1 ,0x04 ); +ad193x_reg_default_init (ad193x);/* adc only */ if (ad193x_has_adc (ad193x)) {
Signature · 1 line
2.20.1
sound/soc/codecs/ad193x.c static struct snd_soc_dai_driver ad193x_no_adc_dai = { · line 419
Quoted 4 lines · Codrin Ciubotariu
sound/soc/codecs/ad193x.c +4
-0+struct ad193x_reg_default { +unsigned int reg; +unsigned int val; +};
You probably don't need to define this. There is a struct reg_sequence in regmap.h.
Quoted 16 lines
sound/soc/codecs/ad193x.c +16
-0+ +/* codec register values to set after reset */ +static void ad193x_reg_default_init (struct ad193x_priv *ad193x) +{ +const struct ad193x_reg_default reg_init[] = { + {0 ,0x99 },/* PLL_CLK_CTRL0: pll input: mclki/xi 12.288Mhz */ + {1 ,0x04 },/* PLL_CLK_CTRL1: no on-chip Vref */ + {2 ,0x40 },/* DAC_CTRL0: TDM mode */ + {4 ,0x1A },/* DAC_CTRL2: 48kHz de-emphasis, unmute dac */ + {5 ,0x00 },/* DAC_CHNL_MUTE: unmute DAC channels */ + }; +const struct ad193x_reg_default reg_adc_init[] = { + {14 ,0x03 },/* ADC_CTRL0: high-pass filter enable */ + {15 ,0x43 },/* ADC_CTRL1: sata delay=1, adc aux mode */ + }; +int i;
sound/soc/codecs/ad193x.c static struct snd_soc_dai_driver ad193x_no_adc_dai = { · line 445
Quoted 10 lines
sound/soc/codecs/ad193x.c +10
-0+ +for (i =0 ; i <ARRAY_SIZE (reg_init); i++) +regmap_write (ad193x->regmap, reg_init[i].reg, reg_init[i].val); + +if (ad193x_has_adc (ad193x)) { +for (i =0 ; i <ARRAY_SIZE (reg_adc_init); i++) { +regmap_write (ad193x->regmap, reg_adc_init[i].reg, + reg_adc_init[i].val); + } + }
And you could use regmap_multi_reg_write( ) to substitute the two for-loops.
See https://mailman.alsa-project.org/pipermail/alsa-devel/2019-June/151090.html
as an example. It also has some reg initializations in component probe( ).
Quoted 37 lines · Tzung-Bi Shih
sound/soc/codecs/ad193x.c static struct snd_soc_dai_driver ad193x_no_adc_dai = { · line 419
Quoted 4 lines · Codrin Ciubotariu
sound/soc/codecs/ad193x.c +4
-0+struct ad193x_reg_default { +unsigned int reg; +unsigned int val; +};You probably don't need to define this. There is a struct
reg_sequenceinregmap.h.Quoted 16 lines
sound/soc/codecs/ad193x.c +16
-0+ +/* codec register values to set after reset */ +static void ad193x_reg_default_init (struct ad193x_priv *ad193x) +{ +const struct ad193x_reg_default reg_init[] = { + {0 ,0x99 },/* PLL_CLK_CTRL0: pll input: mclki/xi 12.288Mhz */ + {1 ,0x04 },/* PLL_CLK_CTRL1: no on-chip Vref */ + {2 ,0x40 },/* DAC_CTRL0: TDM mode */ + {4 ,0x1A },/* DAC_CTRL2: 48kHz de-emphasis, unmute dac */ + {5 ,0x00 },/* DAC_CHNL_MUTE: unmute DAC channels */ + }; +const struct ad193x_reg_default reg_adc_init[] = { + {14 ,0x03 },/* ADC_CTRL0: high-pass filter enable */ + {15 ,0x43 },/* ADC_CTRL1: sata delay=1, adc aux mode */ + }; +int i;sound/soc/codecs/ad193x.c static struct snd_soc_dai_driver ad193x_no_adc_dai = { · line 445
Quoted 10 lines
sound/soc/codecs/ad193x.c +10
-0+ +for (i =0 ; i <ARRAY_SIZE (reg_init); i++) +regmap_write (ad193x->regmap, reg_init[i].reg, reg_init[i].val); + +if (ad193x_has_adc (ad193x)) { +for (i =0 ; i <ARRAY_SIZE (reg_adc_init); i++) { +regmap_write (ad193x->regmap, reg_adc_init[i].reg, + reg_adc_init[i].val); + } + }And you could use
regmap_multi_reg_write( )to substitute the two for-loops.
Quoted 4 lines
See https://mailman.alsa-project.org/pipermail/alsa-devel/2019-June/151090.html
as an example. It also has some reg initializations in componentprobe( ).
Your solution is certainly more elegant. I will make a patch and switch to regmap_multi_reg_write().
Thank you for your review.
Best regards,
Codrin