Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp921058imu; Wed, 28 Nov 2018 01:32:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/WsyiivEBnwCRbMRIpqjcu3aljf/AId6g4UL/QF9MsHZ6q6eaSz0NoylIv+bztYBm5UtoxH X-Received: by 2002:a63:f710:: with SMTP id x16mr32663585pgh.322.1543397557371; Wed, 28 Nov 2018 01:32:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543397557; cv=none; d=google.com; s=arc-20160816; b=XXDbsNGyJjPak+8i29YUBgAKbV3Q6n3mYFdNGH8O4adxeoFm80Ckgi5wITYfPbG2vw 124/uTP5aZXV2vmDVGbIdXCHDp5BDCPsAVz9SkKUG2WHQd+WwNiXeZpzvPW+6gv5ERp/ HFjimdHtH3C4bUVWwPJpcefbvuMMBc06BJFGd3i0g7kP7uW7GzgOoIjxVq/Cm0C7dyST xlevDCiFRb2T4KxGr8++DNjVVcfI657XSqMyjl01GPttU85z8V1mFx+V0PXP4ysC4TJN RQ6L5be8c0G3sH1XNehE/Pk+XZ7HQRxmX4fO/am/X9WgTP8gHSv6GXgUtJv808a921KD FmGw== 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=5kDANuZ0zoLZm9hnBYi1J7Xr22dJrMy0o0i+/kz5flU=; b=p6nqBFjLCJZbhB1WR6DMSYZIVmEvjp7Nj8MSoZVpLUGHP7I2zMlmUKMiqRvI8TVgWE oqw6f+mn6TPFm48M+NgFEyQSKmWu0pUXeQRwr/nupBxBRcaDCgrvChkcVbH3xOBTU8vy 82RcEWOucEXc8x1TFZt+f5d3qGSAJe5YqP+Uucw28kULiPsKhJ/RkEtZOcUKYqh9zW6X 0U9+487mqL9u4CEW1qk4+W5LRlXUtcIpxE/Bc063L58i2JbdAhB5DJwLLoeLHckyjRsc kEw4LOks+edx5S1kYtPWyAUFM/6Xm9HmN4Qai4hHqaJ46L+/rKckDUiYSAbNmHghbi4l EQBw== 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 o11si6843772pll.160.2018.11.28.01.32.22; Wed, 28 Nov 2018 01:32:37 -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 S1728285AbeK1Ubg (ORCPT + 99 others); Wed, 28 Nov 2018 15:31:36 -0500 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:49300 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728182AbeK1Ubg (ORCPT ); Wed, 28 Nov 2018 15:31:36 -0500 Received: by wens.csie.org (Postfix, from userid 1000) id 7B39A6035A; Wed, 28 Nov 2018 17:30:28 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , Alexandre Belloni , Alessandro Zummo , Michael Turquette , Stephen Boyd , Rob Herring , Mark Rutland Cc: Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, linux-rtc@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com Subject: [PATCH 09/15] clk: sunxi-ng: r40: Force LOSC parent to RTC LOSC output Date: Wed, 28 Nov 2018 17:30:07 +0800 Message-Id: <20181128093013.24442-11-wens@csie.org> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181128093013.24442-1-wens@csie.org> References: <20181128093013.24442-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 On the R40, in addition to a mux between the RTC's own RC oscillator and an external 32768 Hz crystal, which are muxed inside the RTC module, the CCU also has its own RC oscillator, which runs at around 2 MHz, and can be muxed with the LOSC output from the RTC. This muxed output is called "SYS 32K" in the module clock diagram, but otherwise referred to as the LOSC throughout the CCU documentation. The RC oscillator is not very accurate, even though it has an undocumented calibration function. We really want a precise clock at 32768 Hz, instead of something at around 32 KHz. This patch forces the SYS 32K clock to use the RTC output as its parent, and doesn't bother registering the internal oscillator nor a clock mux. Signed-off-by: Chen-Yu Tsai --- drivers/clk/sunxi-ng/ccu-sun8i-r40.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-r40.c b/drivers/clk/sunxi-ng/ccu-sun8i-r40.c index 582ebd41d20d..a22d11aa38ba 100644 --- a/drivers/clk/sunxi-ng/ccu-sun8i-r40.c +++ b/drivers/clk/sunxi-ng/ccu-sun8i-r40.c @@ -1284,6 +1284,9 @@ static struct regmap_config sun8i_r40_ccu_regmap_config = { .writeable_reg = sun8i_r40_ccu_regmap_accessible_reg, }; +#define SUN8I_R40_SYS_32K_CLK_REG 0x310 +#define SUN8I_R40_SYS_32K_CLK_KEY (0x16AA << 16) + static int sun8i_r40_ccu_probe(struct platform_device *pdev) { struct resource *res; @@ -1312,6 +1315,14 @@ static int sun8i_r40_ccu_probe(struct platform_device *pdev) val &= ~GENMASK(25, 20); writel(val, reg + SUN8I_R40_USB_CLK_REG); + /* + * Force SYS 32k (otherwise known as LOSC throughout the CCU) + * clock parent to LOSC output from RTC module instead of the + * CCU's internal RC oscillator divided output. + */ + writel(SUN8I_R40_SYS_32K_CLK_KEY | BIT(8), + reg + SUN8I_R40_SYS_32K_CLK_REG); + regmap = devm_regmap_init_mmio(&pdev->dev, reg, &sun8i_r40_ccu_regmap_config); if (IS_ERR(regmap)) -- 2.20.0.rc1