Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp182311pxb; Mon, 16 Aug 2021 03:06:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwczGzPYWGhsgqQF8wQrVlzJXFJh/VlVM0ZyMtGHr7RWeU6NUIenwGokEP1fIHvt+WVM7yA X-Received: by 2002:a92:bf0c:: with SMTP id z12mr11251899ilh.19.1629108363476; Mon, 16 Aug 2021 03:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629108363; cv=none; d=google.com; s=arc-20160816; b=JZHJuNj3U2ygkgHiYwGbp5uMCwGCG7WQRTFUjUgI/cDpoNA8D8nX9Gv+tq6ateMMx0 tePDRB/mnA5yMF2JAvnFSxrAajvpol3LBQTRv/lOPYG4ItNDAwiewOpCg7S4MgpzfDhd TKJtgTR8F3EJwN9zpVYrwUly4devy7SdDyoed0aqJm4DfsUC9LZU0Y5OvG2Alnvn6pfq JmSPvcNYm5Tgv4pn2EfZvEn3DW7LrHc2HlSkckNpZmfazxtY5OhA/6KUXlflnRnjDg4z R+wSVAObZ+Vp9VQd/8IuBK5Y3CE2k2t3wOZ2QS2YJVZ397GNwfBoy7q2PwNbTjfBIkc5 0zFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from; bh=kPD1sXwCUJDWiwvjwpTNK3az1Yc1UwR6RZ/PmvIb3kw=; b=AJbF6sS/olEK8DSv7eHeiUHSJDSSRStJl0a2DXQHhPr6oY0TwCfIJjdmh1FOVZnmeW pIh6FHhFqd0ZtdLCyVHz0C+FuKznIQFsKdHzhpx586nkRdetyJkhTk98IZwV1O6iBOu6 Nl+TwmEXOkPvDAQm+8wIFEh7L8/i1mBuxMl0fV7p6/RcW0E3PI7ERlI2xplIIqVUOZNU vmw7XMUiLQ5n6kceCQ8k5d9bHzoEG2wyP8wouysJVcHh4Q6le3Ak/NF8mrClrw+PIvlC fVE1gvofx8k3lGKqfJ5cRTBcEgJ1RoQchwz4iDytpDL7LVWVTLgRDn2PWcxysfRJKdYK f0Qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r17si13264547iov.104.2021.08.16.03.05.52; Mon, 16 Aug 2021 03:06:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233390AbhHPKFY (ORCPT + 99 others); Mon, 16 Aug 2021 06:05:24 -0400 Received: from ZXSHCAS2.zhaoxin.com ([203.148.12.82]:7372 "EHLO ZXSHCAS2.zhaoxin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbhHPKEu (ORCPT ); Mon, 16 Aug 2021 06:04:50 -0400 Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHCAS2.zhaoxin.com (10.28.252.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Mon, 16 Aug 2021 18:04:16 +0800 Received: from [10.32.56.37] (10.32.56.37) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Mon, 16 Aug 2021 18:04:15 +0800 From: Tony W Wang-oc Subject: Re: [PATCH] rtc: Fix set RTC time delay 500ms on some Zhaoxin SOCs To: Alexandre Belloni CC: , , , , , , , , References: <1629121638-3246-1-git-send-email-TonyWWang-oc@zhaoxin.com> Message-ID: Date: Mon, 16 Aug 2021 18:03:13 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.32.56.37] X-ClientProxiedBy: ZXSHCAS2.zhaoxin.com (10.28.252.162) To zxbjmbx1.zhaoxin.com (10.29.252.163) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/08/2021 16:24, Alexandre Belloni wrote: > Hello, > > On 16/08/2021 21:47:18+0800, Tony W Wang-oc wrote: >> When the RTC divider is changed from reset to an operating time base, >> the first update cycle should be 500ms later. But on some Zhaoxin SOCs, >> this first update cycle is one second later. >> >> So set RTC time on these Zhaoxin SOCs will causing 500ms delay. >> > > Can you explain what is the relationship between writing the divider and > the 500ms delay? >> Isn't the issue that you are using systohc and set_offset_nsec is set to > NSEC_PER_SEC / 2 ? > No. When using #hwclock -s to set RTC time and set_offset_nsec is NSEC_PER_SEC / 2, the function mc146818_set_time() requires the first update cycle after RTC divider be changed from reset to an operating mode is 500ms as the MC146818A spec specified. But on some Zhaoxin SOCs, the first update cycle of RTC is one second later after RTC divider be changed from reset to an operating mode. So the first update cycle after RTC divider be changed from reset to an operation mode on These SOCs will causing 500ms delay with current mc146818_set_time() implementation. Sincerely TonyWWang-oc >> Skip setup RTC divider on these SOCs in mc146818_set_time to fix it. >> >> Signed-off-by: Tony W Wang-oc >> --- >> drivers/rtc/rtc-mc146818-lib.c | 18 ++++++++++++++++++ >> 1 file changed, 18 insertions(+) >> >> diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c >> index dcfaf09..322f94b 100644 >> --- a/drivers/rtc/rtc-mc146818-lib.c >> +++ b/drivers/rtc/rtc-mc146818-lib.c >> @@ -190,8 +190,18 @@ int mc146818_set_time(struct rtc_time *time) >> spin_lock_irqsave(&rtc_lock, flags); >> save_control = CMOS_READ(RTC_CONTROL); >> CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL); >> + >> +#ifdef CONFIG_X86 >> + if (!((boot_cpu_data.x86_vendor == X86_VENDOR_CENTAUR || >> + boot_cpu_data.x86_vendor == X86_VENDOR_ZHAOXIN) && >> + (boot_cpu_data.x86 <= 7 && boot_cpu_data.x86_model <= 59))) { >> + save_freq_select = CMOS_READ(RTC_FREQ_SELECT); >> + CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT); >> + } >> +#else >> save_freq_select = CMOS_READ(RTC_FREQ_SELECT); >> CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT); >> +#endif >> >> #ifdef CONFIG_MACH_DECSTATION >> CMOS_WRITE(real_yrs, RTC_DEC_YEAR); >> @@ -209,7 +219,15 @@ int mc146818_set_time(struct rtc_time *time) >> #endif >> >> CMOS_WRITE(save_control, RTC_CONTROL); >> + >> +#ifdef CONFIG_X86 >> + if (!((boot_cpu_data.x86_vendor == X86_VENDOR_CENTAUR || >> + boot_cpu_data.x86_vendor == X86_VENDOR_ZHAOXIN) && >> + (boot_cpu_data.x86 <= 7 && boot_cpu_data.x86_model <= 59))) >> + CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); >> +#else >> CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); >> +#endif >> >> spin_unlock_irqrestore(&rtc_lock, flags); >> >> -- >> 2.7.4 >> >