Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1843012lqt; Sun, 21 Apr 2024 11:45:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX0+1cDrwxmzrvxAALZx88Fhqe1KkJr7uiVJq1iEUmf5NvFK7/AKACJSDF3LyuPLAoBH6pfL0izpnj7VlcxFVRlGAol8DQuucyJFckOcA== X-Google-Smtp-Source: AGHT+IFfaac3UH2BhZyQeL2HZdXgrlNYMN9UmJkOuU0lcsewvBP9ZFsJ/7XPocqdNbeOqoQ6ZJJu X-Received: by 2002:aa7:88d1:0:b0:6ec:fa34:34b6 with SMTP id k17-20020aa788d1000000b006ecfa3434b6mr12321231pff.13.1713725150122; Sun, 21 Apr 2024 11:45:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713725150; cv=pass; d=google.com; s=arc-20160816; b=cIxECCmV+8BBD9VTK/19cqXk2EmPOs4nRF1M1libVM7Ov0DO4FKsdAtIGbmtMrWtfM XI8G4rMswVdPQElJvXYU/2HiozJtoln99OqAbrQ8y0BWnsRurgpDyW+ZzCGdECzKp/hc 4e3OYdyEbWaDSvc5kyiu45TsPeBOgt2XzsDJSliDNYWt4YBPAAZiHwFzrb2JNXkhc7Df E/9Qv7xEeDwW02tSV/5bx/4e+Pbe3F3fq7vhJDpAthfiQRy4CicBhcUGq+eqDdvFs0MA N/naeq56BRBN/kSGVbzfi64Mo+AaoGQ/uQGlZ4ZdR/mj0YzkbdwVph6TkChFYWzpL4Yg JVeg== 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=wFwolfLW9j4DqzztylWjVHm2V6glYEG6K0Ux0tapKRk=; fh=F1u+LRrJcGXtfxvvyung0wlGLBaqWqWHls+tanvgVYQ=; b=Srcc28eEa+f1RPt6j3c0kRCeWAwBL7NQgrROJgk2eqgdgVIh7gvZTUz4iLWC/yWgkI MZcyF2C/Spb4xRmOrQxuwcGfMXqM9vn9x0KK0UNo3NTi5RS8HEjfToFR/KR34Lci4r8i A7J4mG74H3VhzR0n/3p0Pa0ITVA7HJ+utDTPR4dMoOxIVsF2yArr/YGAaecx1H31GvlH 0tyMtQ8FjyQZrnTc/06suRFQIe6GD7nXk1Q3+hPNnQaeUwSW/lx4rBrrQ8HL6zwfK2Aa firKk+RzLrMqByCeunqXlPYfOfWe353Ufb8IDA2CoLnUkaeXlE1IADZbdAg/6oM6wU/m 0TNw==; 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-152586-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152586-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 ll11-20020a056a00728b00b006e6f9ce6388si6410811pfb.195.2024.04.21.11.45.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 11:45:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152586-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-152586-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152586-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 F08F2B20C9F for ; Sun, 21 Apr 2024 18:45:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 194423D548; Sun, 21 Apr 2024 18:45:39 +0000 (UTC) Received: from mailout02.t-online.de (mailout02.t-online.de [194.25.134.17]) (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 DC29AD29B; Sun, 21 Apr 2024 18:45:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.25.134.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713725138; cv=none; b=RiJMA3bjSqLiC4mN0ddJ12jlm4I7BgZp3AknS8i200w14k6P4iRiVP4p1/w3ALiVSr1q7rteTNYk7/F3b8cnRFDnpDzCpZg4lE0a5T6881o/5W+pdWPhGLbsdbmQAmahf3gXHlwJLh5xHclTePGt2kzXhMR8DeMdsYwrUbIytiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713725138; c=relaxed/simple; bh=uwuQxXfc3+VpnllN8xxeGxr+2TTZclCSi/3gmfaTrms=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=d8N4lA/pJsJiVHWrq1ljYqhwINMeBu/67dUi8tkwCqJfnOui6UldiJKiN4woqONMd4ij8VL6sBF8H0p9MaB1FVOacTtTPS9DbEyJ/vIjf0qCMuDYGq5jlyA7culOy0Tk0KS/9w+19zII0Kg8TbMB+8GHUljXXDY+S5yRGfpOSFU= 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.17 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 fwd82.aul.t-online.de (fwd82.aul.t-online.de [10.223.144.108]) by mailout02.t-online.de (Postfix) with SMTP id E10DB2BE50; Sun, 21 Apr 2024 20:37:21 +0200 (CEST) Received: from dino2.dhome ([77.47.123.226]) by fwd82.t-online.de with (TLSv1.3:TLS_AES_256_GCM_SHA384 encrypted) esmtp id 1ryc41-3gruld0; Sun, 21 Apr 2024 20:37:21 +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, a.fertl@t-online.de Subject: [PATCH v2 1/1] drivers/rtc: rtc-sun6i: AutoCal Internal OSC Clock Date: Sun, 21 Apr 2024 20:36:33 +0200 Message-Id: <20240421183633.117326-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::1713724641-697A1D74-E65BC247/0/0 CLEAN NORMAL X-TOI-MSGID: 9465a6aa-8077-4264-8533-ee6f1a1eb176 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 AND H616. The H618 is the same as H616 regarding rtc. v1->v2 - add flag and activate for H6 AND H616 Signed-off-by: Alois Fertl --- 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 e0b85a0d5645..5d0c917b2099 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_EANABLE 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. */ @@ -138,6 +142,7 @@ struct sun6i_rtc_clk_data { unsigned int has_losc_en : 1; unsigned int has_auto_swt : 1; unsigned int no_ext_losc : 1; + unsigned int has_auto_cal : 1; }; #define RTC_LINEAR_DAY BIT(0) @@ -268,6 +273,13 @@ 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_EANABLE | + 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; @@ -380,6 +392,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) @@ -395,6 +408,7 @@ static const struct sun6i_rtc_clk_data sun50i_h616_rtc_data = { .has_prescaler = 1, .has_out_clk = 1, .no_ext_losc = 1, + .has_auto_cal = 1, }; static void __init sun50i_h616_rtc_clk_init(struct device_node *node) -- 2.39.2