clk: sunxi-ng: Use sigma-delta modulation for audio PLL
Subsystems (2)
cover clk: sunxi-ng: Use sigma-delta modulation for audio PLL
Hi everyone,
This series adds support for fractional-N synthesis using sigma-delta modulation in the audio PLL to get the exact required clock rate. This fixes the speed and pitch change when audio is played back on sunxi platforms, due to the slightly inaccurate audio clock.
I've done this for all platforms I can test at the moment. A83T is left out for now as the the clock unit's design is slightly different. I was unable to work on the A33, as my board is very unstable, plus A33 audio playback seems to be broken at the moment. There might be some issue with the DAPM routes.
Patch 1 fixes an error with the audio PLL's post-divider bit field offset.
Patch 2 adds a check for fractional mode clock rates in the N-M clock's round_rate callback. This is mostly for aesthetics to have both round_rate and set_rate code paths look the same. In practice the N-M factors can also generate the fractional mode clock rates directly.
Patch 3 adds a table based sigma-delta modulation clock type. This is implemented much like the fractional mode clocks, as a helper library to be integrated into the various factor clocks where needed. As there is no explanation on how to calculate the parameters for SDM, the table based approach allows us to copy existing parameters from the vendor kernel.
Patch 4 hooks the SDM clock type helpers into the N-M factors clock type. The audio PLLs on most of our are of this type.
Patches 5 ~ 9 convert the audio PLL to using SDM on various SoCs. The changes are the same, accounting for minor variances between SoCs:
- audio PLL post-divider now forced to 1.
- pll-audio-1x fixed-factor-clock divider now set to 1, matching the hardware setting from above.
- SDM parameter table added.
- SDM parameters added to pll-audio-base clock.
Please have a look.
ChenYu
Chen-Yu Tsai (9):
clk: sunxi-ng: sun5i: Fix bit offset of audio PLL post-divider
clk: sunxi-ng: nm: Check if requested rate is supported by fractional
clock
clk: sunxi-ng: Add sigma-delta modulation support
clk: sunxi-ng: nm: Add support for sigma-delta modulation
clk: sunxi-ng: sun8i: h3: Use sigma-delta modulation for audio PLL
clk: sunxi-ng: sun4i: Use sigma-delta modulation for audio PLL
clk: sunxi-ng: sun5i: Use sigma-delta modulation for audio PLL
clk: sunxi-ng: sun6i: Use sigma-delta modulation for audio PLL
clk: sunxi-ng: sun8i: a23: Use sigma-delta modulation for audio PLL
drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu-sun4i-a10.c | 26 ++++-- drivers/clk/sunxi-ng/ccu-sun5i.c | 27 ++++-- drivers/clk/sunxi-ng/ccu-sun6i-a31.c | 38 ++++++--- drivers/clk/sunxi-ng/ccu-sun8i-a23.c | 38 ++++++--- drivers/clk/sunxi-ng/ccu-sun8i-h3.c | 38 ++++++--- drivers/clk/sunxi-ng/ccu_common.h | 1 + drivers/clk/sunxi-ng/ccu_nm.c | 25 +++++- drivers/clk/sunxi-ng/ccu_nm.h | 25 ++++++ drivers/clk/sunxi-ng/ccu_sdm.c | 158 +++++++++++++++++++++++++++++++++++ drivers/clk/sunxi-ng/ccu_sdm.h | 80 ++++++++++++++++++ 11 files changed, 404 insertions(+), 53 deletions(-) create mode 100644 drivers/clk/sunxi-ng/ccu_sdm.c create mode 100644 drivers/clk/sunxi-ng/ccu_sdm.h
Signature · 1 line
2.14.2
PATCH 1/9 clk: sunxi-ng: sun5i: Fix bit offset of audio PLL post-divider
The post-divider for the audio PLL is in bits [29:26], as specified in the user manual, not [19:16] as currently programmed in the code. The post-divider has a default register value of 2, i.e. a divider of 3. This means the clock rate fed to the audio codec would be off.
This was discovered when porting sigma-delta modulation for the PLL to sun5i, which needs the post-divider to be 1.
Fix the bit offset, so we do actually force the post-divider to a certain value.
--- drivers/clk/sunxi-ng/ccu-sun5i.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/sunxi-ng/ccu-sun5i.c +2 -2
@@ -982,8 +982,8 @@ static void __init sun5i_ccu_init(struct device_node *node,/* Force the PLL-Audio-1x divider to 4 */ val =readl (reg +SUN5I_PLL_AUDIO_REG ); - val &= ~GENMASK (19 ,16 ); -writel (val | (3 <<16 ), reg +SUN5I_PLL_AUDIO_REG ); + val &= ~GENMASK (29 ,26 ); +writel (val | (3 <<26 ), reg +SUN5I_PLL_AUDIO_REG );/* * Use the peripheral PLL as the AHB parent, instead of CPU /
Signature · 1 line
2.14.2
PATCH 2/9 clk: sunxi-ng: nm: Check if requested rate is supported by fractional clock
In reply to Chen-Yu TsaiThe round_rate callback for N-M-factor style clocks does not check if the requested clock rate is supported by the fractional clock mode. While this doesn't affect usage in practice, since the clock rates are also supported through N-M factors, it does not match the set_rate code.
Add a check to the round_rate callback so it matches the set_rate callback.
--- drivers/clk/sunxi-ng/ccu_nm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/clk/sunxi-ng/ccu_nm.c +3 -0
@@ -99,6 +99,9 @@ static long ccu_nm_round_rate(struct clk_hw *hw, unsigned long rate,struct ccu_nm *nm =hw_to_ccu_nm (hw);struct _ccu_nm _nm; +if (ccu_frac_helper_has_rate (&nm->common, &nm->frac, rate)) +return rate; + _nm.min_n = nm->n.min ?:1 ; _nm.max_n = nm->n.max ?:1 << nm->n.width; _nm.min_m =1 ;
Signature · 1 line
2.14.2
PATCH 3/9 clk: sunxi-ng: Add sigma-delta modulation support
In reply to Chen-Yu TsaiSigma-delta modulation is supported for some PLLs. This allows fractional-N multipliers to be used. In reality we don't know how to configure the individual settings for it. However we can copy existing settings from the vendor kernel to support clock rates that cannot be generated from integer factors, but are really desired. The vendor kernel only uses this for the audio PLL clock, and only on the latest chips.
This patch adds a new class of clocks, along with helper functions. It is intended to be merged into N-M-factor style clocks as a feature, much like fractional clocks.
--- drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu_common.h | 1 + drivers/clk/sunxi-ng/ccu_sdm.c | 158 ++++++++++++++++++++++++++++++++++++++ drivers/clk/sunxi-ng/ccu_sdm.h | 80 +++++++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 drivers/clk/sunxi-ng/ccu_sdm.c create mode 100644 drivers/clk/sunxi-ng/ccu_sdm.h
drivers/clk/sunxi-ng/Makefile +1 -0
@@ -10,6 +10,7 @@ lib-$(CONFIG_SUNXI_CCU) += ccu_gate.o lib-$(CONFIG_SUNXI_CCU) += ccu_mux.o lib-$(CONFIG_SUNXI_CCU) += ccu_mult.o lib-$(CONFIG_SUNXI_CCU) += ccu_phase.o +lib-$(CONFIG_SUNXI_CCU) += ccu_sdm.o # Multi-factor clocks lib-$(CONFIG_SUNXI_CCU) += ccu_nk.o
drivers/clk/sunxi-ng/ccu_common.h +1 -0
@@ -24,6 +24,7 @@#define CCU_FEATURE_ALL_PREDIV BIT(4)#define CCU_FEATURE_LOCK_REG BIT(5)#define CCU_FEATURE_MMC_TIMING_SWITCH BIT(6) +#define CCU_FEATURE_SIGMA_DELTA_MOD BIT(7)/* MMC timing mode switch bit */ #define CCU_MMC_NEW_TIMING_MODE BIT(30)
drivers/clk/sunxi-ng/ccu_sdm.c new file +158 -0
158 lines not on this page · raw message
drivers/clk/sunxi-ng/ccu_sdm.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 4/9 clk: sunxi-ng: nm: Add support for sigma-delta modulation
In reply to Chen-Yu TsaiSome of the N-M-style clocks, namely the PLLs, support sigma-delta modulation to do fractional-N frequency synthesis. This is used in the audio PLL to generate the exact frequency the audio blocks need. These frequencies can not be generated with integer N-M factors.
--- drivers/clk/sunxi-ng/ccu_nm.c | 22 +++++++++++++++++++++- drivers/clk/sunxi-ng/ccu_nm.h | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-)
drivers/clk/sunxi-ng/ccu_nm.c +21 -1
@@ -90,6 +90,14 @@ static unsigned long ccu_nm_recalc_rate(struct clk_hw *hw,if (!m) m++; +if (ccu_sdm_helper_is_enabled (&nm->common, &nm->sdm)) { +unsigned long rate = +ccu_sdm_helper_read_rate (&nm->common, &nm->sdm, + m, n); +if (rate) +return rate; + } +return parent_rate * n / m; }
@@ -102,6 +110,9 @@ static long ccu_nm_round_rate(struct clk_hw *hw, unsigned long rate,if (ccu_frac_helper_has_rate (&nm->common, &nm->frac, rate))return rate; +if (ccu_sdm_helper_has_rate (&nm->common, &nm->sdm, rate)) +return rate; + _nm.min_n = nm->n.min ?:1 ; _nm.max_n = nm->n.max ?:1 << nm->n.width; _nm.min_m =1 ;
@@ -143,7 +154,16 @@ static int ccu_nm_set_rate(struct clk_hw *hw, unsigned long rate, _nm.min_m =1 ; _nm.max_m = nm->m.max ?:1 << nm->m.width; -ccu_nm_find_best (parent_rate, rate, &_nm); +if (ccu_sdm_helper_has_rate (&nm->common, &nm->sdm, rate)) { +ccu_sdm_helper_enable (&nm->common, &nm->sdm, rate); + +/* Sigma delta modulation requires specific N and M factors */ +ccu_sdm_helper_get_factors (&nm->common, &nm->sdm, rate, + &_nm.m, &_nm.n); + }else { +ccu_sdm_helper_disable (&nm->common, &nm->sdm); +ccu_nm_find_best (parent_rate, rate, &_nm); + }spin_lock_irqsave (nm->common.lock, flags);
drivers/clk/sunxi-ng/ccu_nm.h +25 -0
@@ -20,6 +20,7 @@#include "ccu_div.h" #include "ccu_frac.h" #include "ccu_mult.h" +#include "ccu_sdm.h" /* * struct ccu_nm - Definition of an N-M clock
@@ -33,10 +34,34 @@ struct ccu_nm {struct ccu_mult_internal n;struct ccu_div_internal m;struct ccu_frac_internal frac; +struct ccu_sdm_internal sdm;struct ccu_common common; }; +#define SUNXI_CCU_NM_WITH_SDM_GATE_LOCK (_struct, _name, _parent, _reg, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _sdm_table, _sdm_en, \ + _sdm_reg, _sdm_reg_en, \ + _gate, _lock, _flags) \ + struct ccu_nm _struct = { \ + .enable = _gate, \ + .lock = _lock, \ + .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \ + .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \ + .sdm = _SUNXI_CCU_SDM(_sdm_table, _sdm_en, \ + _sdm_reg, _sdm_reg_en),\ + .common = { \ + .reg = _reg, \ + .features = CCU_FEATURE_SIGMA_DELTA_MOD, \ + .hw.init = CLK_HW_INIT(_name, \ + _parent, \ + &ccu_nm_ops, \ + _flags), \ + }, \ + } + #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(_struct, _name, _parent, _reg, \ _nshift, _nwidth, \ _mshift, _mwidth, \
Signature · 1 line
2.14.2
PATCH 5/9 clk: sunxi-ng: sun8i: h3: Use sigma-delta modulation for audio PLL
In reply to Chen-Yu TsaiThe audio blocks require specific clock rates. Until now we were using the closest clock rate possible with integer N-M factors. This resulted in audio playback being slightly slower than it should be.
The vendor kernel gets around this (for newer SoCs) by using sigma-delta modulation to generate a fractional-N factor. This patch copies the parameters for the H3.
--- drivers/clk/sunxi-ng/ccu-sun8i-h3.c | 38 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
drivers/clk/sunxi-ng/ccu-sun8i-h3.c +25 -13
@@ -26,6 +26,7 @@#include "ccu_nkmp.h" #include "ccu_nm.h" #include "ccu_phase.h" +#include "ccu_sdm.h" #include "ccu-sun8i-h3.h"
@@ -44,18 +45,29 @@ static SUNXI_CCU_NKMP_WITH_GATE_LOCK(pll_cpux_clk, "pll-cpux",* the base (2x, 4x and 8x), and one variable divider (the one true * pll audio). * -* We don't have any need for the variable divider for now, so we just -* hardcode it to match with the clock names +* With sigma-delta modulation for fractional-N on the audio PLL, +* we have to use specific dividers. This means the variable divider +* can no longer be used, as the audio codec requests the exact clock +* rates we support through this mechanism. So we now hard code the +* variable divider to 1. This means the clock rates will no longer +* match the clock names. */ #define SUN8I_H3_PLL_AUDIO_REG 0x008 -static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", -"osc24M" ,0x008 , -8 ,7 ,/* N */ -0 ,5 ,/* M */ -BIT (31 ),/* gate */ -BIT (28 ),/* lock */ - CLK_SET_RATE_UNGATE); +static struct ccu_sdm_setting pll_audio_sdm_table[] = { + { .rate =22579200 , .pattern =0xc0010d84 , .m =8 , .n =7 }, + { .rate =24576000 , .pattern =0xc000ac02 , .m =14 , .n =14 }, +}; + +static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", +"osc24M" ,0x008 , +8 ,7 ,/* N */ +0 ,5 ,/* M */ + pll_audio_sdm_table,BIT (24 ), +0x284 ,BIT (31 ), +BIT (31 ),/* gate */ +BIT (28 ),/* lock */ + CLK_SET_RATE_UNGATE); static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video", "osc24M", 0x0010,
@@ -707,9 +719,9 @@ static struct ccu_common *sun50i_h5_ccu_clks[] = { &gpu_clk.common, }; -/* We hardcode the divider to 4 for now */ +/* We hardcode the divider to 1 for now */ static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio", - "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT); + "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x", "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
@@ -1129,10 +1141,10 @@ static void __init sunxi_h3_h5_ccu_init(struct device_node *node,return ; } -/* Force the PLL-Audio-1x divider to 4 */ +/* Force the PLL-Audio-1x divider to 1 */ val =readl (reg +SUN8I_H3_PLL_AUDIO_REG ); val &= ~GENMASK (19 ,16 ); -writel (val | (3 <<16 ), reg +SUN8I_H3_PLL_AUDIO_REG ); +writel (val | (0 <<16 ), reg +SUN8I_H3_PLL_AUDIO_REG );sunxi_ccu_probe (node, reg, desc);
Signature · 1 line
2.14.2
PATCH 6/9 clk: sunxi-ng: sun4i: Use sigma-delta modulation for audio PLL
In reply to Chen-Yu TsaiThe audio blocks require specific clock rates. Until now we were using the closest clock rate possible with integer N-M factors. This resulted in audio playback being slightly slower than it should be.
The vendor kernel gets around this (for newer SoCs) by using sigma-delta modulation to generate a fractional-N factor. As the PLL hardware is identical in most chips, we can back port the settings from the newer SoC, in this case the H3, onto the A10 and A20.
--- drivers/clk/sunxi-ng/ccu-sun4i-a10.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/clk/sunxi-ng/ccu-sun4i-a10.c +20 -6
@@ -28,6 +28,7 @@#include "ccu_nkmp.h" #include "ccu_nm.h" #include "ccu_phase.h" +#include "ccu_sdm.h" #include "ccu-sun4i-a10.h"
@@ -51,16 +52,29 @@ static struct ccu_nkmp pll_core_clk = {* the base (2x, 4x and 8x), and one variable divider (the one true * pll audio). * -* We don't have any need for the variable divider for now, so we just -* hardcode it to match with the clock names. +* With sigma-delta modulation for fractional-N on the audio PLL, +* we have to use specific dividers. This means the variable divider +* can no longer be used, as the audio codec requests the exact clock +* rates we support through this mechanism. So we now hard code the +* variable divider to 1. This means the clock rates will no longer +* match the clock names. */ #define SUN4I_PLL_AUDIO_REG 0x008 + +static struct ccu_sdm_setting pll_audio_sdm_table[] = { + { .rate =22579200 , .pattern =0xc0010d84 , .m =8 , .n =7 }, + { .rate =24576000 , .pattern =0xc000ac02 , .m =14 , .n =14 }, +}; +static struct ccu_nm pll_audio_base_clk = { .enable =BIT (31 ), .n =_SUNXI_CCU_MULT_OFFSET (8 ,7 ,0 ), .m =_SUNXI_CCU_DIV_OFFSET (0 ,5 ,0 ), + .sdm =_SUNXI_CCU_SDM (pll_audio_sdm_table,0 , +0x00c ,BIT (31 )), .common = { .reg =0x008 , + .features =CCU_FEATURE_SIGMA_DELTA_MOD , .hw.init = CLK_HW_INIT("pll-audio-base", "hosc", &ccu_nm_ops,
@@ -1021,9 +1035,9 @@ static struct ccu_common *sun4i_sun7i_ccu_clks[] = { &out_b_clk.common }; -/* Post-divider for pll-audio is hardcoded to 4 */ +/* Post-divider for pll-audio is hardcoded to 1 */ static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio", - "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT); + "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x", "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
@@ -1420,10 +1434,10 @@ static void __init sun4i_ccu_init(struct device_node *node,return ; } -/* Force the PLL-Audio-1x divider to 4 */ +/* Force the PLL-Audio-1x divider to 1 */ val =readl (reg +SUN4I_PLL_AUDIO_REG ); val &= ~GENMASK (29 ,26 ); -writel (val | (4 <<26 ), reg +SUN4I_PLL_AUDIO_REG ); +writel (val | (1 <<26 ), reg +SUN4I_PLL_AUDIO_REG );/* * Use the peripheral PLL6 as the AHB parent, instead of CPU /
Signature · 1 line
2.14.2
PATCH 7/9 clk: sunxi-ng: sun5i: Use sigma-delta modulation for audio PLL
In reply to Chen-Yu TsaiThe audio blocks require specific clock rates. Until now we were using the closest clock rate possible with integer N-M factors. This resulted in audio playback being slightly slower than it should be.
The vendor kernel gets around this (for newer SoCs) by using sigma-delta modulation to generate a fractional-N factor. As the PLL hardware is identical in most chips, we can back port the settings from the newer SoC, in this case the H3, onto the sun5i family.
--- drivers/clk/sunxi-ng/ccu-sun5i.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/clk/sunxi-ng/ccu-sun5i.c +19 -6
@@ -26,6 +26,7 @@#include "ccu_nkmp.h" #include "ccu_nm.h" #include "ccu_phase.h" +#include "ccu_sdm.h" #include "ccu-sun5i.h"
@@ -49,11 +50,20 @@ static struct ccu_nkmp pll_core_clk = {* the base (2x, 4x and 8x), and one variable divider (the one true * pll audio). * -* We don't have any need for the variable divider for now, so we just -* hardcode it to match with the clock names +* With sigma-delta modulation for fractional-N on the audio PLL, +* we have to use specific dividers. This means the variable divider +* can no longer be used, as the audio codec requests the exact clock +* rates we support through this mechanism. So we now hard code the +* variable divider to 1. This means the clock rates will no longer +* match the clock names. */ #define SUN5I_PLL_AUDIO_REG 0x008 +static struct ccu_sdm_setting pll_audio_sdm_table[] = { + { .rate =22579200 , .pattern =0xc0010d84 , .m =8 , .n =7 }, + { .rate =24576000 , .pattern =0xc000ac02 , .m =14 , .n =14 }, +}; +static struct ccu_nm pll_audio_base_clk = { .enable =BIT (31 ), .n =_SUNXI_CCU_MULT_OFFSET (8 ,7 ,0 ),
@@ -63,8 +73,11 @@ static struct ccu_nm pll_audio_base_clk = {* offset */ .m = _SUNXI_CCU_DIV_OFFSET(0, 5, 0), + .sdm = _SUNXI_CCU_SDM(pll_audio_sdm_table, 0, + 0x00c, BIT(31)), .common = { .reg = 0x008, + .features = CCU_FEATURE_SIGMA_DELTA_MOD, .hw.init = CLK_HW_INIT("pll-audio-base", "hosc", &ccu_nm_ops,
@@ -597,9 +610,9 @@ static struct ccu_common *sun5i_a10s_ccu_clks[] = { &iep_clk.common, }; -/* We hardcode the divider to 4 for now */ +/* We hardcode the divider to 1 for now */ static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio", - "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT); + "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x", "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
@@ -980,10 +993,10 @@ static void __init sun5i_ccu_init(struct device_node *node,return ; } -/* Force the PLL-Audio-1x divider to 4 */ +/* Force the PLL-Audio-1x divider to 1 */ val =readl (reg +SUN5I_PLL_AUDIO_REG ); val &= ~GENMASK (29 ,26 ); -writel (val | (3 <<26 ), reg +SUN5I_PLL_AUDIO_REG ); +writel (val | (0 <<26 ), reg +SUN5I_PLL_AUDIO_REG );/* * Use the peripheral PLL as the AHB parent, instead of CPU /
Signature · 1 line
2.14.2
PATCH 8/9 clk: sunxi-ng: sun6i: Use sigma-delta modulation for audio PLL
In reply to Chen-Yu TsaiThe audio blocks require specific clock rates. Until now we were using the closest clock rate possible with integer N-M factors. This resulted in audio playback being slightly slower than it should be.
The vendor kernel gets around this (for newer SoCs) by using sigma-delta modulation to generate a fractional-N factor. As the PLL hardware is identical in most chips, we can back port the settings from the newer SoC, in this case the H3, onto the A31.
--- drivers/clk/sunxi-ng/ccu-sun6i-a31.c | 38 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-)
drivers/clk/sunxi-ng/ccu-sun6i-a31.c +25 -13
@@ -31,6 +31,7 @@#include "ccu_nkmp.h" #include "ccu_nm.h" #include "ccu_phase.h" +#include "ccu_sdm.h" #include "ccu-sun6i-a31.h"
@@ -48,18 +49,29 @@ static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_cpu_clk, "pll-cpu",* the base (2x, 4x and 8x), and one variable divider (the one true * pll audio). * -* We don't have any need for the variable divider for now, so we just -* hardcode it to match with the clock names +* With sigma-delta modulation for fractional-N on the audio PLL, +* we have to use specific dividers. This means the variable divider +* can no longer be used, as the audio codec requests the exact clock +* rates we support through this mechanism. So we now hard code the +* variable divider to 1. This means the clock rates will no longer +* match the clock names. */ #define SUN6I_A31_PLL_AUDIO_REG 0x008 -static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", -"osc24M" ,0x008 , -8 ,7 ,/* N */ -0 ,5 ,/* M */ -BIT (31 ),/* gate */ -BIT (28 ),/* lock */ - CLK_SET_RATE_UNGATE); +static struct ccu_sdm_setting pll_audio_sdm_table[] = { + { .rate =22579200 , .pattern =0xc0010d84 , .m =8 , .n =7 }, + { .rate =24576000 , .pattern =0xc000ac02 , .m =14 , .n =14 }, +}; + +static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", +"osc24M" ,0x008 , +8 ,7 ,/* N */ +0 ,5 ,/* M */ + pll_audio_sdm_table,BIT (24 ), +0x284 ,BIT (31 ), +BIT (31 ),/* gate */ +BIT (28 ),/* lock */ + CLK_SET_RATE_UNGATE); static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video0_clk, "pll-video0", "osc24M", 0x010,
@@ -950,9 +962,9 @@ static struct ccu_common *sun6i_a31_ccu_clks[] = { &out_c_clk.common, }; -/* We hardcode the divider to 4 for now */ +/* We hardcode the divider to 1 for now */ static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio", - "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT); + "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x", "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
@@ -1221,10 +1233,10 @@ static void __init sun6i_a31_ccu_setup(struct device_node *node)return ; } -/* Force the PLL-Audio-1x divider to 4 */ +/* Force the PLL-Audio-1x divider to 1 */ val =readl (reg +SUN6I_A31_PLL_AUDIO_REG ); val &= ~GENMASK (19 ,16 ); -writel (val | (3 <<16 ), reg +SUN6I_A31_PLL_AUDIO_REG ); +writel (val | (0 <<16 ), reg +SUN6I_A31_PLL_AUDIO_REG );/* Force PLL-MIPI to MIPI mode */ val =readl (reg +SUN6I_A31_PLL_MIPI_REG );
Signature · 1 line
2.14.2
PATCH 9/9 clk: sunxi-ng: sun8i: a23: Use sigma-delta modulation for audio PLL
In reply to Chen-Yu TsaiThe audio blocks require specific clock rates. Until now we were using the closest clock rate possible with integer N-M factors. This resulted in audio playback being slightly slower than it should be.
The vendor kernel gets around this (for newer SoCs) by using sigma-delta modulation to generate a fractional-N factor. As the PLL hardware is identical in most chips, we can back port the settings from the newer SoC, in this case the H3, onto the A23.
--- drivers/clk/sunxi-ng/ccu-sun8i-a23.c | 38 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-)
drivers/clk/sunxi-ng/ccu-sun8i-a23.c +25 -13
@@ -26,6 +26,7 @@#include "ccu_nkmp.h" #include "ccu_nm.h" #include "ccu_phase.h" +#include "ccu_sdm.h" #include "ccu-sun8i-a23-a33.h"
@@ -52,18 +53,29 @@ static struct ccu_nkmp pll_cpux_clk = {* the base (2x, 4x and 8x), and one variable divider (the one true * pll audio). * -* We don't have any need for the variable divider for now, so we just -* hardcode it to match with the clock names +* With sigma-delta modulation for fractional-N on the audio PLL, +* we have to use specific dividers. This means the variable divider +* can no longer be used, as the audio codec requests the exact clock +* rates we support through this mechanism. So we now hard code the +* variable divider to 1. This means the clock rates will no longer +* match the clock names. */ #define SUN8I_A23_PLL_AUDIO_REG 0x008 -static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", -"osc24M" ,0x008 , -8 ,7 ,/* N */ -0 ,5 ,/* M */ -BIT (31 ),/* gate */ -BIT (28 ),/* lock */ - CLK_SET_RATE_UNGATE); +static struct ccu_sdm_setting pll_audio_sdm_table[] = { + { .rate =22579200 , .pattern =0xc0010d84 , .m =8 , .n =7 }, + { .rate =24576000 , .pattern =0xc000ac02 , .m =14 , .n =14 }, +}; + +static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", +"osc24M" ,0x008 , +8 ,7 ,/* N */ +0 ,5 ,/* M */ + pll_audio_sdm_table,BIT (24 ), +0x284 ,BIT (31 ), +BIT (31 ),/* gate */ +BIT (28 ),/* lock */ + CLK_SET_RATE_UNGATE); static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video", "osc24M", 0x010,
@@ -538,9 +550,9 @@ static struct ccu_common *sun8i_a23_ccu_clks[] = { &ats_clk.common, }; -/* We hardcode the divider to 4 for now */ +/* We hardcode the divider to 1 for now */ static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio", - "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT); + "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x", "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT); static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
@@ -720,10 +732,10 @@ static void __init sun8i_a23_ccu_setup(struct device_node *node)return ; } -/* Force the PLL-Audio-1x divider to 4 */ +/* Force the PLL-Audio-1x divider to 1 */ val =readl (reg +SUN8I_A23_PLL_AUDIO_REG ); val &= ~GENMASK (19 ,16 ); -writel (val | (3 <<16 ), reg +SUN8I_A23_PLL_AUDIO_REG ); +writel (val | (0 <<16 ), reg +SUN8I_A23_PLL_AUDIO_REG );/* Force PLL-MIPI to MIPI mode */ val =readl (reg +SUN8I_A23_PLL_MIPI_REG );
Signature · 1 line
2.14.2
Maxime Ripard
Appliedcover clk: sunxi-ng: Use sigma-delta modulation for audio PLL
In reply to Chen-Yu TsaiQuoted 7 lines · Chen-Yu Tsai
Hi everyone,
This series adds support for fractional-N synthesis using sigma-delta modulation in the audio PLL to get the exact required clock rate. This fixes the speed and pitch change when audio is played back on sunxi platforms, due to the slightly inaccurate audio clock.
Quoted 5 lines
I've done this for all platforms I can test at the moment. A83T is left out for now as the the clock unit's design is slightly different. I was unable to work on the A33, as my board is very unstable, plus A33 audio playback seems to be broken at the moment. There might be some issue with the DAPM routes.
Applied, thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171013/18a35be7/attachment.sig>