lkml.org 
[lkml]   [2022]   [May]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V10 16/22] LoongArch: Add misc common routines
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 <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <asm/loongson.h>
> +
> +#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

\
 
 \ /
  Last update: 2022-05-14 14:57    [W:0.295 / U:2.316 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site