Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1443687iob; Sat, 14 May 2022 09:06:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymB1vXYYS+6VX4vYFIx+Y4VU4AKvj++cARFSw9ewNBA5Owb1yxG6yQBYQUswTITUqDOGm/ X-Received: by 2002:a05:6402:f13:b0:428:a849:d0c1 with SMTP id i19-20020a0564020f1300b00428a849d0c1mr4447475eda.346.1652544371249; Sat, 14 May 2022 09:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652544371; cv=none; d=google.com; s=arc-20160816; b=DYDLw7YZ2lZuHp9SuPbz/xf7bWas1XVCp/v1ls49UthF/0WAitj81RIA/pRwW5DmB2 XEjXQHpEqwf2LXR9Q4P88ZK4SRtOUg1nv/VF2xAv/ARkYZ055bkinftNKiiYNSv5BBGc Iy9YaY4HLPXwZaPsrGsHSJoMwfIitXqHL1ykEUSW+cn6D95qzHSZL67el56SH17KSkoK tLiEe883vu03MK7ZqIVVpOLTgHQlUChHwGzD+9XYiT6fyNaD1ON+qc8M+je+U3p3FmRP rXQbebYjvmyoRaJQKrpowK4QM+Ul8NRPNAkS1pgrXGz/HQMOD/zlPlK/9Qk5eg0Pw5N3 ttLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=oM8SGEEmjqKyTL4PH4BUvpxyMwUaIngixmnGGZ9iZ0A=; b=bTt8kOc6tVN3aukNFFnk9JX2LVH8YxvkYrYvjurnhOSN+evlDcEgJrzp4g3GgcUg9+ S7kZTU8M8qql5aIAoLIjdCUMZPIGZmV/3yO2vz8uleKzPohfKNo8t6nEFTykU0d3cmB8 SzrZK5iUjt2vIMdUPB7pH4wBpsfax7sbVAQLE/cK8keVR0B9R1242DhcVTDynT4b8niY B8fpWpyEf21Rp6tkN1RATbotS6OaM4nGZeDdzuUnaM5UKuwVD1cFeZ8RyTIk1VfvKBUC 31whlJjJ5sfJfbfXvjJ7IUxE8jhxoOKUp6VdYXPGKmetOxSlBxpOFASuIj5Wl4GpNhPo FZtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ob+fPlJe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020aa7d402000000b00425d51eb390si4723667edq.97.2022.05.14.09.05.43; Sat, 14 May 2022 09:06:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ob+fPlJe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232249AbiENM4p (ORCPT + 99 others); Sat, 14 May 2022 08:56:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbiENM4n (ORCPT ); Sat, 14 May 2022 08:56:43 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1ED455AD; Sat, 14 May 2022 05:56:40 -0700 (PDT) Received: (Authenticated sender: alexandre.belloni@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id CE700240005; Sat, 14 May 2022 12:56:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1652532997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oM8SGEEmjqKyTL4PH4BUvpxyMwUaIngixmnGGZ9iZ0A=; b=Ob+fPlJen2ehiRjMLuUBKMlg0bkjx4JCLSqFi4diPnQwLi5D6eIrWMYNHCnw5CfFr9dvQS Ul9BxgQ5sUHl1gKPcBctJ6J2M2K1dzuVZUAo8BrLpmqeplB9VsRScePUkFLu+XbNKJAMNu DixHweOpIFN1Ck6E061REZssX1Sk2vs+0rhHag+HWZwOjTUAGlv0S1+/WWRDLL2URwo/m2 68fBJohtVWRPMGlf8Kuqkke1CyCJ6d/RKY/oK9YBft2tzWG74QSts8k4sS0ARyY1nPn/sA hqmUNYTxwhKl2EBu+AUsdPV8N0gRcu4jh+4Gf5wbV8yhIP5fLYvJm9r2lifu1g== Date: Sat, 14 May 2022 14:56:32 +0200 From: Alexandre Belloni To: Huacai Chen Cc: Arnd Bergmann , Andy Lutomirski , Thomas Gleixner , Peter Zijlstra , Andrew Morton , David Airlie , Jonathan Corbet , Linus Torvalds , linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Xuefeng Li , Yanteng Si , Huacai Chen , Guo Ren , Xuerui Wang , Jiaxun Yang , Stephen Rothwell Subject: Re: [PATCH V10 16/22] LoongArch: Add misc common routines Message-ID: References: <20220514080402.2650181-1-chenhuacai@loongson.cn> <20220514080402.2650181-17-chenhuacai@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220514080402.2650181-17-chenhuacai@loongson.cn> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 14/05/2022 16:03:56+0800, Huacai Chen wrote: > diff --git a/arch/loongarch/kernel/rtc.c b/arch/loongarch/kernel/rtc.c > new file mode 100644 > index 000000000000..d7568385219f > --- /dev/null > +++ b/arch/loongarch/kernel/rtc.c > @@ -0,0 +1,36 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2020-2022 Loongson Technology Corporation Limited > + */ > + > +#include > +#include > +#include > +#include > + > +#define RTC_TOYREAD0 0x2C > +#define RTC_YEAR 0x30 > + > +unsigned long loongson_get_rtc_time(void) > +{ > + unsigned int year, mon, day, hour, min, sec; > + unsigned int value; > + > + value = ls7a_readl(LS7A_RTC_REG_BASE + RTC_TOYREAD0); > + sec = (value >> 4) & 0x3f; > + min = (value >> 10) & 0x3f; > + hour = (value >> 16) & 0x1f; > + day = (value >> 21) & 0x1f; > + mon = (value >> 26) & 0x3f; > + year = ls7a_readl(LS7A_RTC_REG_BASE + RTC_YEAR); > + > + year = 1900 + year; > + > + return mktime64(year, mon, day, hour, min, sec); > +} > + > +void read_persistent_clock64(struct timespec64 *ts) > +{ This should rather be implemented in a proper rtc driver and then have userspace set the system time or use hctosys. > + ts->tv_sec = loongson_get_rtc_time(); > + ts->tv_nsec = 0; > +} > -- > 2.27.0 > -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com