Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp539822lqp; Wed, 22 May 2024 11:39:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUDf7pOgplM1+/RZBdI6GcokBawtITI+jI7UCjsuTBlXaxP1M49vlZwtNW76TjO24rxOdQW1wmPhTM4tQt5At5ZEasqOZIDj+TVSMjQg== X-Google-Smtp-Source: AGHT+IHr0SQQvdFSyflFiEMNOdKtQm9MTSSGw0XjTAbO7VxxsSZUjFNQ0NmjHiSMdnJGlaoVkVrc X-Received: by 2002:a17:902:d50b:b0:1f3:633:976e with SMTP id d9443c01a7336-1f31c9f013amr32534205ad.54.1716403145769; Wed, 22 May 2024 11:39:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716403145; cv=pass; d=google.com; s=arc-20160816; b=hlx4ql3oVm1qi1xnQIwm6q41zS7BhYZ8Qq/yRbIP3RBbzpUY1uLND//FBILv6DaVgv mRjWFs2AF/KsZQZYWcAfx7iYzf9n4fqq3bMR/G0VyWn4hLSm5TP3HSR8quJNWB5mLY2n Q8nhS4+aoeE21171Yr/D+E83BV6m22AhNnyHbwLdsN7I2gJJvvGEHA/qxnlTNPpAkq8r dS3tgnvnL/ZM99aH6sG+ESx+jRg45i+tM522kdGWPUkBP9hHo7FVLf9AYgJEo2ADJqWB cW8U7R8IhCvmkQD5DoFLTX32T1Bw3a4JZhE62gTkf/YIQAAIPia0pQ0ZNCnUfkBpvJrz tYtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=ReNPXlg0AV0mVSZRWWY2veX3fjYL6DTCe/7Y+df6KMo=; fh=mf4dgaXlorQkKES/hme0xl+pLrEO3zcnvqPpFhj0XIw=; b=LVEdEw4WzW5AOusW5Wi+KclyCVBl4WqrkppDOXNEShdmNCX0TjZHTB8k4I800L8dDW tEin7jBKSM47tcAzZgDSuw6jTgxHzFoZgERvuBSDISNuwiva83dsezJPv1BW5GdGRsLv jFth3ZQw167oz+iRT/x2N4K3vXijP4SCzQ02pe1Ozo2JY9Yv7Hntu11vwHuO2Dm2ixT1 H/CoT3pK08hrJP2MT6SiUGzhQ2XlVw6uybpSPiy/W2U6NWoKsaOrssXtwQUKZs2mJeL1 LaYnazwlaobex1+Xa/ASVjU+L0mti6m3Sz0K+1r5gdyLFyD1LJInFiEGhbvnGMYitK7e VHIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=t-online.de); spf=pass (google.com: domain of linux-kernel+bounces-186619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186619-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f3080a8f7asi47510215ad.236.2024.05.22.11.39.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 11:39:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=t-online.de); spf=pass (google.com: domain of linux-kernel+bounces-186619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186619-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 47BF4B2106B for ; Wed, 22 May 2024 18:39:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE643145FF8; Wed, 22 May 2024 18:38:52 +0000 (UTC) Received: from mailout04.t-online.de (mailout04.t-online.de [194.25.134.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 071BA145B1D; Wed, 22 May 2024 18:38:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.25.134.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716403132; cv=none; b=K8eeR1VN55t1m0EWNwFvJBjATVqmFFt2Tm6mmgcdqMjIrfnXDN23Q1c6Lh8vux8ZiwtfyXArCt5gH4KjixQlHU1tItZWUCHidEnFGfhgSxr6V19/7an+PTH40HHjgMwx2bomPvlKI2WzJs0Zoy+5TKbSx7aQC4ZcmF04ILfE9uY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716403132; c=relaxed/simple; bh=GgTdux9gYeqRKqacAiPHtF3+mAjRSMmb0GCGIwvLtfY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=taMaHdibzxWze1h9LOADiNIWm7Oz1ph/ffAcOr/D57E5Rl0GncZusbyJ0xaLY3qPauaaOj9WJ9DIjo3dMEdtwuA/agTHbEw2kAk6twLrCtpawr1imDb+lLa4aT6NVJP3KuZB3Or7gu68ETo3IWdo29aLCYCj2HQWYFlxf1MqV1U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=t-online.de; spf=pass smtp.mailfrom=t-online.de; arc=none smtp.client-ip=194.25.134.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=t-online.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=t-online.de Received: from fwd85.aul.t-online.de (fwd85.aul.t-online.de [10.223.144.111]) by mailout04.t-online.de (Postfix) with SMTP id 8226B84B3; Wed, 22 May 2024 20:29:13 +0200 (CEST) Received: from dino2.dhome ([77.47.123.226]) by fwd85.t-online.de with (TLSv1.3:TLS_AES_256_GCM_SHA384 encrypted) esmtp id 1s9qi6-0rGXNR0; Wed, 22 May 2024 20:29:10 +0200 From: Alois Fertl To: a.zummo@towertech.it Cc: alexandre.belloni@bootlin.com, wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-rtc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, andre.przywara@arm.com, Alois Fertl Subject: [PATCH v4 1/1] drivers/rtc: rtc-sun6i: AutoCal Internal OSC Date: Wed, 22 May 2024 20:28:26 +0200 Message-Id: <20240522182826.6824-1-a.fertl@t-online.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TOI-EXPURGATEID: 150726::1716402550-F28FED0F-6FFADA25/0/0 CLEAN NORMAL X-TOI-MSGID: 45263082-cff6-49c7-a496-925ce572f1eb I have a M98-8K PLUS Magcubic TV-Box based on the Allwinner H618 SOC. On board is a Sp6330 wifi/bt module that requires a 32kHz clock to operate correctly. Without this change the clock from the SOC is ~29kHz and BT module does not start up. The patch enables the Internal OSC Clock Auto Calibration of the H616/H618 which than provides the necessary 32kHz and the BT module initializes successfully. Add a flag and set it for H6. Also the code is developed on the H618 board it only modifies the H6 as there is no support for H616/H618 in the current code. Signed-off-by: Alois Fertl --- v1->v2 - add flag and activate for H6 AND H616 v2->v3 - correct findings from review v3->v4 - adjust to mainline tree I have also tried to test this using the new driver in sunxi-ng manually injecting the reverted patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=60d9f050da63b The code in drivers/clk/sunxi-ng/ccu-sun6i-rtc.c is being called and it initializes the relevant registers to the same values as the old driver, but the change ends up with a system that often hangs during booting and only ocasionally reaches the login state (one out of 10). The main difference I see adhoc is that the old drivers init is done using CLK_OF_DECLARE_DRIVER so initialization is done very early. The new driver does the initialisation via probe which is quite some time later. Can't tell if this is the cause for the problems. --- drivers/rtc/rtc-sun6i.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c index 8e0c66906..57aa52d3b 100644 --- a/drivers/rtc/rtc-sun6i.c +++ b/drivers/rtc/rtc-sun6i.c @@ -42,6 +42,11 @@ #define SUN6I_LOSC_CLK_PRESCAL 0x0008 +#define SUN6I_LOSC_CLK_AUTO_CAL 0x000c +#define SUN6I_LOSC_CLK_AUTO_CAL_16MS BIT(2) +#define SUN6I_LOSC_CLK_AUTO_CAL_ENABLE BIT(1) +#define SUN6I_LOSC_CLK_AUTO_CAL_SEL_CAL BIT(0) + /* RTC */ #define SUN6I_RTC_YMD 0x0010 #define SUN6I_RTC_HMS 0x0014 @@ -126,7 +131,6 @@ * registers (R40, H6) * - SYS power domain controls (R40) * - DCXO controls (H6) - * - RC oscillator calibration (H6) * * These functions are not covered by this driver. */ @@ -137,6 +141,7 @@ struct sun6i_rtc_clk_data { unsigned int has_out_clk : 1; unsigned int has_losc_en : 1; unsigned int has_auto_swt : 1; + unsigned int has_auto_cal : 1; }; #define RTC_LINEAR_DAY BIT(0) @@ -267,6 +272,14 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, } writel(reg, rtc->base + SUN6I_LOSC_CTRL); + if (rtc->data->has_auto_cal) { + /* Enable internal OSC clock auto calibration */ + reg = SUN6I_LOSC_CLK_AUTO_CAL_16MS | + SUN6I_LOSC_CLK_AUTO_CAL_ENABLE | + SUN6I_LOSC_CLK_AUTO_CAL_SEL_CAL; + writel(reg, rtc->base + SUN6I_LOSC_CLK_AUTO_CAL); + } + /* Yes, I know, this is ugly. */ sun6i_rtc = rtc; @@ -374,6 +387,7 @@ static const struct sun6i_rtc_clk_data sun50i_h6_rtc_data = { .has_out_clk = 1, .has_losc_en = 1, .has_auto_swt = 1, + .has_auto_cal = 1, }; static void __init sun50i_h6_rtc_clk_init(struct device_node *node) -- 2.39.2