ASoC: adau: Factor out shared PLL configuration code
Subsystems (3)
Lars-Peter Clausen
maintainerPATCH 1/1 ASoC: adau: Factor out shared PLL configuration code
Multiple devices from the ADAU family share the same PLL structure and configuration register layout. Introduce a new helper module that can be used to calculated the PLL configuration registers based on a specified input frequency and the desired output frequency of the PLL.
The ADAU1761/ADAU1781 and ADAU1373 drivers are updated to make use of this new helper module. But future drivers for additional devices from the ADAU family are also expected to make use of it.
In anticipation of sharing more infrastructure code between different devices from the ADAU family the new module is called adau-utils.
--- sound/soc/codecs/Kconfig | 5 ++++ sound/soc/codecs/Makefile | 2 ++ sound/soc/codecs/adau-utils.c | 61 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/adau-utils.h | 7 +++++ sound/soc/codecs/adau1373.c | 38 +++++++-------------------- sound/soc/codecs/adau17x1.c | 38 +++------------------------ 6 files changed, 89 insertions(+), 62 deletions(-) create mode 100644 sound/soc/codecs/adau-utils.c create mode 100644 sound/soc/codecs/adau-utils.h
sound/soc/codecs/Kconfig +5 -0
@@ -272,8 +272,12 @@ config SND_SOC_AD1980 config SND_SOC_AD73311 tristate +config SND_SOC_ADAU_UTILS + tristate + config SND_SOC_ADAU1373 tristate + select SND_SOC_ADAU_UTILS config SND_SOC_ADAU1701 tristate "Analog Devices ADAU1701 CODEC"
@@ -283,6 +287,7 @@ config SND_SOC_ADAU1701 config SND_SOC_ADAU17X1 tristate select SND_SOC_SIGMADSP_REGMAP + select SND_SOC_ADAU_UTILS config SND_SOC_ADAU1761 tristate
sound/soc/codecs/Makefile +2 -0
@@ -7,6 +7,7 @@ snd-soc-ad193x-spi-objs := ad193x-spi.o snd-soc-ad193x-i2c-objs := ad193x-i2c.o snd-soc-ad1980-objs := ad1980.o snd-soc-ad73311-objs := ad73311.o +snd-soc-adau-utils-objs := adau-utils.o snd-soc-adau1373-objs := adau1373.o snd-soc-adau1701-objs := adau1701.o snd-soc-adau17x1-objs := adau17x1.o
@@ -223,6 +224,7 @@ obj-$(CONFIG_SND_SOC_AD193X_SPI) += snd-soc-ad193x-spi.o obj-$(CONFIG_SND_SOC_AD193X_I2C) += snd-soc-ad193x-i2c.o obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o +obj-$(CONFIG_SND_SOC_ADAU_UTILS) += snd-soc-adau-utils.o obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o obj-$(CONFIG_SND_SOC_ADAU17X1) += snd-soc-adau17x1.o
sound/soc/codecs/adau-utils.c new file +61 -0
61 lines not on this page · raw message
sound/soc/codecs/adau-utils.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef SOUND_SOC_CODECS_ADAU_PLL_H +#define SOUND_SOC_CODECS_ADAU_PLL_H + +int adau_calc_pll_cfg (unsigned int freq_in,unsigned int freq_out, +uint8_t regs[5 ]); + +#endif
sound/soc/codecs/adau1373.c +10 -28
@@ -23,6 +23,7 @@#include <sound/adau1373.h> #include "adau1373.h" +#include "adau-utils.h" struct adau1373_dai {unsigned int clk_src;
@@ -1254,7 +1255,8 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id, {struct adau1373 *adau1373 =snd_soc_codec_get_drvdata (codec);unsigned int dpll_div =0 ; -unsigned int x, r, n, m, i, j, mode; +uint8_t pll_regs[5 ]; +int ret;switch (pll_id) {case ADAU1373_PLL1 :
@@ -1295,27 +1297,8 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id, dpll_div++; } -if (freq_out % freq_in !=0 ) { -/* fout = fin * (r + (n/m)) / x */ - x =DIV_ROUND_UP (freq_in,13500000 ); - freq_in /= x; - r = freq_out / freq_in; - i = freq_out % freq_in; - j =gcd (i, freq_in); - n = i / j; - m = freq_in / j; - x--; - mode =1 ; - }else { -/* fout = fin / r */ - r = freq_out / freq_in; - n =0 ; - m =0 ; - x =0 ; - mode =0 ; - } - -if (r <2 || r >8 || x >3 || m >0xffff || n >0xffff ) + ret =adau_calc_pll_cfg (freq_in, freq_out, pll_regs); +if (ret)return -EINVAL ;if (dpll_div) {
@@ -1330,12 +1313,11 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id,regmap_write (adau1373->regmap,ADAU1373_DPLL_CTRL (pll_id), (source <<4 ) | dpll_div); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL1 (pll_id), (m >>8 ) &0xff ); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL2 (pll_id), m &0xff ); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL3 (pll_id), (n >>8 ) &0xff ); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL4 (pll_id), n &0xff ); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL5 (pll_id), - (r <<3 ) | (x <<1 ) | mode); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL1 (pll_id), pll_regs[0 ]); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL2 (pll_id), pll_regs[1 ]); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL3 (pll_id), pll_regs[2 ]); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL4 (pll_id), pll_regs[3 ]); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL5 (pll_id), pll_regs[4 ]);/* Set sysclk to pll_rate / 4 */ regmap_update_bits (adau1373->regmap,ADAU1373_CLK_SRC_DIV (pll_id),0x3f ,0x09 );
sound/soc/codecs/adau17x1.c +4 -34
@@ -23,6 +23,7 @@#include "sigmadsp.h" #include "adau17x1.h" +#include "adau-utils.h" static const char *const adau17x1_capture_mixer_boost_text[] = {"Normal operation" ,"Boost Level 1" ,"Boost Level 2" ,"Boost Level 3" ,
@@ -391,45 +392,14 @@ static int adau17x1_set_dai_pll(struct snd_soc_dai *dai, int pll_id, {struct snd_soc_codec *codec = dai->codec;struct adau *adau =snd_soc_codec_get_drvdata (codec); -unsigned int r, n, m, i, j; -unsigned int div;int ret;if (freq_in <8000000 || freq_in >27000000 )return -EINVAL ; -if (!freq_out) { - r =0 ; - n =0 ; - m =0 ; - div =0 ; - }else { -if (freq_out % freq_in !=0 ) { - div =DIV_ROUND_UP (freq_in,13500000 ); - freq_in /= div; - r = freq_out / freq_in; - i = freq_out % freq_in; - j =gcd (i, freq_in); - n = i / j; - m = freq_in / j; - div--; - }else { - r = freq_out / freq_in; - n =0 ; - m =0 ; - div =0 ; - } -if (n >0xffff || m >0xffff || div >3 || r >8 || r <2 ) -return -EINVAL ; - } - - adau->pll_regs[0 ] = m >>8 ; - adau->pll_regs[1 ] = m &0xff ; - adau->pll_regs[2 ] = n >>8 ; - adau->pll_regs[3 ] = n &0xff ; - adau->pll_regs[4 ] = (r <<3 ) | (div <<1 ); -if (m !=0 ) - adau->pll_regs[4 ] |=1 ;/* Fractional mode */ + ret =adau_calc_pll_cfg (freq_in, freq_out, adau->pll_regs); +if (ret <0 ) +return ret;/* The PLL register is 6 bytes long and can only be written at once. */ ret = regmap_raw_write(adau->regmap, ADAU17X1_PLL_CONTROL,
Signature · 1 line
2.1.4
Mark Brown
maintainerQuoted 4 lines · Lars-Peter Clausen
Multiple devices from the ADAU family share the same PLL structure and configuration register layout. Introduce a new helper module that can be used to calculated the PLL configuration registers based on a specified input frequency and the desired output frequency of the PLL.
Sounds like we may be heading towards an MFD with a clock driver here?
Lars-Peter Clausen
maintainerQuoted 7 lines · Mark Brown
Quoted 4 lines · Lars-Peter Clausen
Multiple devices from the ADAU family share the same PLL structure and configuration register layout. Introduce a new helper module that can be used to calculated the PLL configuration registers based on a specified input frequency and the desired output frequency of the PLL.
Sounds like we may be heading towards an MFD with a clock driver here?
Not at the moment, the PLL outputs are only used internally so it makes no sense to expose it through the CCF at the moment. The questions on IRC were more about how to replace the input clock configuration, which is currently done through the set_sysclk callbacks, with the CCF.
Mark Brown
maintainerQuoted 7 lines · Lars-Peter Clausen
Quoted 5 lines · Mark Brown
Quoted 4 lines · Lars-Peter Clausen
Multiple devices from the ADAU family share the same PLL structure and configuration register layout. Introduce a new helper module that can be used to calculated the PLL configuration registers based on a specified input frequency and the desired output frequency of the PLL.
Quoted 6 lines
Quoted 1 line
Sounds like we may be heading towards an MFD with a clock driver here?
Not at the moment, the PLL outputs are only used internally so it makes no sense to expose it through the CCF at the moment. The questions on IRC were more about how to replace the input clock configuration, which is currently done through the
set_sysclkcallbacks, with the CCF.
This was independant of the IRC discussion - it's just the pattern that you're describing here.
Mark Brown
maintainerApplied "ASoC: adau: Factor out shared PLL configuration code" to the asoc tree
In reply to Lars-Peter ClausenThe patch
ASoC: adau: Factor out shared PLL configuration code
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
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
0eadaa9ce2aacdcc3cf050d98c25aacabadc557fMon Sep 17 00:00:00 2001
From: Lars-Peter Clausen <[email protected]>
Date: Thu, 9 Jun 2016 19:39:06 +0200
Subject: [PATCH] ASoC: adau: Factor out shared PLL configuration code
Multiple devices from the ADAU family share the same PLL structure and configuration register layout. Introduce a new helper module that can be used to calculated the PLL configuration registers based on a specified input frequency and the desired output frequency of the PLL.
The ADAU1761/ADAU1781 and ADAU1373 drivers are updated to make use of this new helper module. But future drivers for additional devices from the ADAU family are also expected to make use of it.
In anticipation of sharing more infrastructure code between different devices from the ADAU family the new module is called adau-utils.
--- sound/soc/codecs/Kconfig | 5 ++++ sound/soc/codecs/Makefile | 2 ++ sound/soc/codecs/adau-utils.c | 61 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/adau-utils.h | 7 +++++ sound/soc/codecs/adau1373.c | 38 +++++++-------------------- sound/soc/codecs/adau17x1.c | 38 +++------------------------ 6 files changed, 89 insertions(+), 62 deletions(-) create mode 100644 sound/soc/codecs/adau-utils.c create mode 100644 sound/soc/codecs/adau-utils.h
sound/soc/codecs/Kconfig +5 -0
@@ -269,8 +269,12 @@ config SND_SOC_AD1980 config SND_SOC_AD73311 tristate +config SND_SOC_ADAU_UTILS + tristate + config SND_SOC_ADAU1373 tristate + select SND_SOC_ADAU_UTILS config SND_SOC_ADAU1701 tristate "Analog Devices ADAU1701 CODEC"
@@ -280,6 +284,7 @@ config SND_SOC_ADAU1701 config SND_SOC_ADAU17X1 tristate select SND_SOC_SIGMADSP_REGMAP + select SND_SOC_ADAU_UTILS config SND_SOC_ADAU1761 tristate
sound/soc/codecs/Makefile +2 -0
@@ -7,6 +7,7 @@ snd-soc-ad193x-spi-objs := ad193x-spi.o snd-soc-ad193x-i2c-objs := ad193x-i2c.o snd-soc-ad1980-objs := ad1980.o snd-soc-ad73311-objs := ad73311.o +snd-soc-adau-utils-objs := adau-utils.o snd-soc-adau1373-objs := adau1373.o snd-soc-adau1701-objs := adau1701.o snd-soc-adau17x1-objs := adau17x1.o
@@ -220,6 +221,7 @@ obj-$(CONFIG_SND_SOC_AD193X_SPI) += snd-soc-ad193x-spi.o obj-$(CONFIG_SND_SOC_AD193X_I2C) += snd-soc-ad193x-i2c.o obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o +obj-$(CONFIG_SND_SOC_ADAU_UTILS) += snd-soc-adau-utils.o obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o obj-$(CONFIG_SND_SOC_ADAU17X1) += snd-soc-adau17x1.o
sound/soc/codecs/adau-utils.c new file +61 -0
61 lines not on this page · raw message
sound/soc/codecs/adau-utils.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef SOUND_SOC_CODECS_ADAU_PLL_H +#define SOUND_SOC_CODECS_ADAU_PLL_H + +int adau_calc_pll_cfg (unsigned int freq_in,unsigned int freq_out, +uint8_t regs[5 ]); + +#endif
sound/soc/codecs/adau1373.c +10 -28
@@ -23,6 +23,7 @@#include <sound/adau1373.h> #include "adau1373.h" +#include "adau-utils.h" struct adau1373_dai {unsigned int clk_src;
@@ -1254,7 +1255,8 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id, {struct adau1373 *adau1373 =snd_soc_codec_get_drvdata (codec);unsigned int dpll_div =0 ; -unsigned int x, r, n, m, i, j, mode; +uint8_t pll_regs[5 ]; +int ret;switch (pll_id) {case ADAU1373_PLL1 :
@@ -1295,27 +1297,8 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id, dpll_div++; } -if (freq_out % freq_in !=0 ) { -/* fout = fin * (r + (n/m)) / x */ - x =DIV_ROUND_UP (freq_in,13500000 ); - freq_in /= x; - r = freq_out / freq_in; - i = freq_out % freq_in; - j =gcd (i, freq_in); - n = i / j; - m = freq_in / j; - x--; - mode =1 ; - }else { -/* fout = fin / r */ - r = freq_out / freq_in; - n =0 ; - m =0 ; - x =0 ; - mode =0 ; - } - -if (r <2 || r >8 || x >3 || m >0xffff || n >0xffff ) + ret =adau_calc_pll_cfg (freq_in, freq_out, pll_regs); +if (ret)return -EINVAL ;if (dpll_div) {
@@ -1330,12 +1313,11 @@ static int adau1373_set_pll(struct snd_soc_codec *codec, int pll_id,regmap_write (adau1373->regmap,ADAU1373_DPLL_CTRL (pll_id), (source <<4 ) | dpll_div); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL1 (pll_id), (m >>8 ) &0xff ); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL2 (pll_id), m &0xff ); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL3 (pll_id), (n >>8 ) &0xff ); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL4 (pll_id), n &0xff ); -regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL5 (pll_id), - (r <<3 ) | (x <<1 ) | mode); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL1 (pll_id), pll_regs[0 ]); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL2 (pll_id), pll_regs[1 ]); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL3 (pll_id), pll_regs[2 ]); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL4 (pll_id), pll_regs[3 ]); +regmap_write (adau1373->regmap,ADAU1373_PLL_CTRL5 (pll_id), pll_regs[4 ]);/* Set sysclk to pll_rate / 4 */ regmap_update_bits (adau1373->regmap,ADAU1373_CLK_SRC_DIV (pll_id),0x3f ,0x09 );
sound/soc/codecs/adau17x1.c +4 -34
@@ -23,6 +23,7 @@#include "sigmadsp.h" #include "adau17x1.h" +#include "adau-utils.h" static const char *const adau17x1_capture_mixer_boost_text[] = {"Normal operation" ,"Boost Level 1" ,"Boost Level 2" ,"Boost Level 3" ,
@@ -391,45 +392,14 @@ static int adau17x1_set_dai_pll(struct snd_soc_dai *dai, int pll_id, {struct snd_soc_codec *codec = dai->codec;struct adau *adau =snd_soc_codec_get_drvdata (codec); -unsigned int r, n, m, i, j; -unsigned int div;int ret;if (freq_in <8000000 || freq_in >27000000 )return -EINVAL ; -if (!freq_out) { - r =0 ; - n =0 ; - m =0 ; - div =0 ; - }else { -if (freq_out % freq_in !=0 ) { - div =DIV_ROUND_UP (freq_in,13500000 ); - freq_in /= div; - r = freq_out / freq_in; - i = freq_out % freq_in; - j =gcd (i, freq_in); - n = i / j; - m = freq_in / j; - div--; - }else { - r = freq_out / freq_in; - n =0 ; - m =0 ; - div =0 ; - } -if (n >0xffff || m >0xffff || div >3 || r >8 || r <2 ) -return -EINVAL ; - } - - adau->pll_regs[0 ] = m >>8 ; - adau->pll_regs[1 ] = m &0xff ; - adau->pll_regs[2 ] = n >>8 ; - adau->pll_regs[3 ] = n &0xff ; - adau->pll_regs[4 ] = (r <<3 ) | (div <<1 ); -if (m !=0 ) - adau->pll_regs[4 ] |=1 ;/* Fractional mode */ + ret =adau_calc_pll_cfg (freq_in, freq_out, adau->pll_regs); +if (ret <0 ) +return ret;/* The PLL register is 6 bytes long and can only be written at once. */ ret = regmap_raw_write(adau->regmap, ADAU17X1_PLL_CONTROL,
Signature · 1 line
2.8.1