Skip to content

Commit a5e3e2b

Browse files
wensmripard
authored andcommitted
clk: sunxi-ng: sun8i: h3: Use sigma-delta modulation for audio PLL
The 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. Signed-off-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
1 parent 392ba5f commit a5e3e2b

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

drivers/clk/sunxi-ng/ccu-sun8i-h3.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ccu_nkmp.h"
2727
#include "ccu_nm.h"
2828
#include "ccu_phase.h"
29+
#include "ccu_sdm.h"
2930

3031
#include "ccu-sun8i-h3.h"
3132

@@ -44,18 +45,29 @@ static SUNXI_CCU_NKMP_WITH_GATE_LOCK(pll_cpux_clk, "pll-cpux",
4445
* the base (2x, 4x and 8x), and one variable divider (the one true
4546
* pll audio).
4647
*
47-
* We don't have any need for the variable divider for now, so we just
48-
* hardcode it to match with the clock names
48+
* With sigma-delta modulation for fractional-N on the audio PLL,
49+
* we have to use specific dividers. This means the variable divider
50+
* can no longer be used, as the audio codec requests the exact clock
51+
* rates we support through this mechanism. So we now hard code the
52+
* variable divider to 1. This means the clock rates will no longer
53+
* match the clock names.
4954
*/
5055
#define SUN8I_H3_PLL_AUDIO_REG 0x008
5156

52-
static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
53-
"osc24M", 0x008,
54-
8, 7, /* N */
55-
0, 5, /* M */
56-
BIT(31), /* gate */
57-
BIT(28), /* lock */
58-
CLK_SET_RATE_UNGATE);
57+
static struct ccu_sdm_setting pll_audio_sdm_table[] = {
58+
{ .rate = 22579200, .pattern = 0xc0010d84, .m = 8, .n = 7 },
59+
{ .rate = 24576000, .pattern = 0xc000ac02, .m = 14, .n = 14 },
60+
};
61+
62+
static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
63+
"osc24M", 0x008,
64+
8, 7, /* N */
65+
0, 5, /* M */
66+
pll_audio_sdm_table, BIT(24),
67+
0x284, BIT(31),
68+
BIT(31), /* gate */
69+
BIT(28), /* lock */
70+
CLK_SET_RATE_UNGATE);
5971

6072
static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video",
6173
"osc24M", 0x0010,
@@ -707,9 +719,9 @@ static struct ccu_common *sun50i_h5_ccu_clks[] = {
707719
&gpu_clk.common,
708720
};
709721

710-
/* We hardcode the divider to 4 for now */
722+
/* We hardcode the divider to 1 for now */
711723
static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio",
712-
"pll-audio-base", 4, 1, CLK_SET_RATE_PARENT);
724+
"pll-audio-base", 1, 1, CLK_SET_RATE_PARENT);
713725
static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x",
714726
"pll-audio-base", 2, 1, CLK_SET_RATE_PARENT);
715727
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,
11291141
return;
11301142
}
11311143

1132-
/* Force the PLL-Audio-1x divider to 4 */
1144+
/* Force the PLL-Audio-1x divider to 1 */
11331145
val = readl(reg + SUN8I_H3_PLL_AUDIO_REG);
11341146
val &= ~GENMASK(19, 16);
1135-
writel(val | (3 << 16), reg + SUN8I_H3_PLL_AUDIO_REG);
1147+
writel(val | (0 << 16), reg + SUN8I_H3_PLL_AUDIO_REG);
11361148

11371149
sunxi_ccu_probe(node, reg, desc);
11381150

0 commit comments

Comments
 (0)