Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1958449imu; Fri, 23 Nov 2018 02:42:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/U4Jl3VrcxLfT2EPT/VRkZXcqE15Bk2hrE7wDdMUKMh/o4zGX/osKrqhbDDM9kjOZz8+PQ7 X-Received: by 2002:a63:c942:: with SMTP id y2mr13424664pgg.331.1542969779490; Fri, 23 Nov 2018 02:42:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542969779; cv=none; d=google.com; s=arc-20160816; b=m+4fnhn4fvw7OK+pbWnGMhQwGSoch/IpuDq8XzooqN4FVUGujq5VNgXC5fo8WHSAaX hITNCtE6z6Q1iaqXLhXmS+d+qtzZTDZVGg/rOEI/VXa9Cf+bd/3XvV5SJvO+dKgQJJYA +JBWFFlaTNzx2a/eWLb1vS6iWkDeYJevGV4R2GfXnvIjIqL8rTNcs5h+YrQ3CmZMefGx umIUYGV4H9YKm/MXyPjonjwVO6IxsfqTnD2Xy95KXRo+5DXuq4KxQ79wBou9wWob250q SiP3nQ/tI8fBfen1KzAEqyh7Egf1fnL/OdTBu7HzUvNZ0OsgQs4CsmIrewFtTKgKQzCq cMzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/L7RfMekYnxXXBfZ4RCYWIFfBAlc07eRoHJJVTatEYU=; b=x9iHbLNhqPvMoUx4Z1x9weCD+N9bBErnphRzov4QYpLl0bYf+T/STvis6/xb5PNZYQ Q9jKA++jpIMoTcDlUe+2xW9QWCrTNEnr9V0WQOs0kedqskMMTJ+wrNgvdjCDjLkMhOQU 8ZFWKt4iEUbmeeV6oY200DeWoqTIct5pVRQEcvz9wHXOciVklWVylaBVTHjNudNoD6mP GTZxfGBPJbRTvjpO2CKuT9BiuCzsEzLUOYcg5RPij0KdPNkP96P5uAAUGxUnDMCx2Ah8 VqwJMnLsQ+C2QecXXaebf8JpZttb+pt6iMYha2xXcZAMVK6kx9r8m+BA2QG3t6yawTUO EgSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8si35488830plr.343.2018.11.23.02.42.44; Fri, 23 Nov 2018 02:42:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394285AbeKVVCk (ORCPT + 99 others); Thu, 22 Nov 2018 16:02:40 -0500 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:48376 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394193AbeKVVCj (ORCPT ); Thu, 22 Nov 2018 16:02:39 -0500 Received: by wens.csie.org (Postfix, from userid 1000) id 5AD975FCB2; Thu, 22 Nov 2018 18:23:46 +0800 (CST) From: Chen-Yu Tsai To: Mark Brown , Liam Girdwood , Rob Herring , Mark Rutland , Maxime Ripard Cc: Chen-Yu Tsai , devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Vasily Khoruzhick Subject: [PATCH v9 5/8] clk: sunxi-ng: sun50i: a64: Use sigma-delta modulation for audio PLL Date: Thu, 22 Nov 2018 18:23:22 +0800 Message-Id: <20181122102325.29495-6-wens@csie.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122102325.29495-1-wens@csie.org> References: <20181122102325.29495-1-wens@csie.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 some SoCs) by using sigma-delta modulation to generate a fractional-N factor. As the PLL hardware is identical in most chips, we can port the settings for H3 onto the A64. Signed-off-by: Chen-Yu Tsai --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 37 +++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c index 1f45b20ad752..181b599dc163 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -51,18 +51,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 SUN50I_A64_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_MIN_MAX(pll_video0_clk, "pll-video0", "osc24M", 0x010, @@ -594,9 +605,9 @@ static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu", /* Fixed Factor clocks */ static CLK_FIXED_FACTOR(osc12M_clk, "osc12M", "osc24M", 2, 1, 0); -/* 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", @@ -916,10 +927,10 @@ static int sun50i_a64_ccu_probe(struct platform_device *pdev) if (IS_ERR(reg)) return PTR_ERR(reg); - /* Force the PLL-Audio-1x divider to 4 */ + /* Force the PLL-Audio-1x divider to 1 */ val = readl(reg + SUN50I_A64_PLL_AUDIO_REG); val &= ~GENMASK(19, 16); - writel(val | (3 << 16), reg + SUN50I_A64_PLL_AUDIO_REG); + writel(val | (0 << 16), reg + SUN50I_A64_PLL_AUDIO_REG); writel(0x515, reg + SUN50I_A64_PLL_MIPI_REG); -- 2.19.1