| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * arch/sh/boards/dreamcast/rtc.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Copyright (c) 2001, 2002 M. R. Brown <mrbrown@0xd6.org> |
|---|
| 7 | 8 | * Copyright (c) 2002 Paul Mundt <lethal@chaoticdreams.org> |
|---|
| 8 | | - * |
|---|
| 9 | | - * Released under the terms of the GNU GPL v2.0. |
|---|
| 10 | | - * |
|---|
| 11 | 9 | */ |
|---|
| 12 | 10 | |
|---|
| 13 | 11 | #include <linux/time.h> |
|---|
| 14 | | -#include <asm/rtc.h> |
|---|
| 15 | | -#include <asm/io.h> |
|---|
| 12 | +#include <linux/rtc.h> |
|---|
| 13 | +#include <linux/io.h> |
|---|
| 14 | +#include <linux/platform_device.h> |
|---|
| 16 | 15 | |
|---|
| 17 | 16 | /* The AICA RTC has an Epoch of 1/1/1950, so we must subtract 20 years (in |
|---|
| 18 | 17 | seconds) to get the standard Unix Epoch when getting the time, and add |
|---|
| .. | .. |
|---|
| 26 | 25 | |
|---|
| 27 | 26 | /** |
|---|
| 28 | 27 | * aica_rtc_gettimeofday - Get the time from the AICA RTC |
|---|
| 29 | | - * @ts: pointer to resulting timespec |
|---|
| 28 | + * @dev: the RTC device (ignored) |
|---|
| 29 | + * @tm: pointer to resulting RTC time structure |
|---|
| 30 | 30 | * |
|---|
| 31 | 31 | * Grabs the current RTC seconds counter and adjusts it to the Unix Epoch. |
|---|
| 32 | 32 | */ |
|---|
| 33 | | -static void aica_rtc_gettimeofday(struct timespec *ts) |
|---|
| 33 | +static int aica_rtc_gettimeofday(struct device *dev, struct rtc_time *tm) |
|---|
| 34 | 34 | { |
|---|
| 35 | 35 | unsigned long val1, val2; |
|---|
| 36 | + time64_t t; |
|---|
| 36 | 37 | |
|---|
| 37 | 38 | do { |
|---|
| 38 | 39 | val1 = ((__raw_readl(AICA_RTC_SECS_H) & 0xffff) << 16) | |
|---|
| .. | .. |
|---|
| 42 | 43 | (__raw_readl(AICA_RTC_SECS_L) & 0xffff); |
|---|
| 43 | 44 | } while (val1 != val2); |
|---|
| 44 | 45 | |
|---|
| 45 | | - ts->tv_sec = val1 - TWENTY_YEARS; |
|---|
| 46 | + /* normalize to 1970..2106 time range */ |
|---|
| 47 | + t = (u32)(val1 - TWENTY_YEARS); |
|---|
| 46 | 48 | |
|---|
| 47 | | - /* Can't get nanoseconds with just a seconds counter. */ |
|---|
| 48 | | - ts->tv_nsec = 0; |
|---|
| 49 | + rtc_time64_to_tm(t, tm); |
|---|
| 50 | + |
|---|
| 51 | + return 0; |
|---|
| 49 | 52 | } |
|---|
| 50 | 53 | |
|---|
| 51 | 54 | /** |
|---|
| 52 | 55 | * aica_rtc_settimeofday - Set the AICA RTC to the current time |
|---|
| 53 | | - * @secs: contains the time_t to set |
|---|
| 56 | + * @dev: the RTC device (ignored) |
|---|
| 57 | + * @tm: pointer to new RTC time structure |
|---|
| 54 | 58 | * |
|---|
| 55 | 59 | * Adjusts the given @tv to the AICA Epoch and sets the RTC seconds counter. |
|---|
| 56 | 60 | */ |
|---|
| 57 | | -static int aica_rtc_settimeofday(const time_t secs) |
|---|
| 61 | +static int aica_rtc_settimeofday(struct device *dev, struct rtc_time *tm) |
|---|
| 58 | 62 | { |
|---|
| 59 | 63 | unsigned long val1, val2; |
|---|
| 60 | | - unsigned long adj = secs + TWENTY_YEARS; |
|---|
| 64 | + time64_t secs = rtc_tm_to_time64(tm); |
|---|
| 65 | + u32 adj = secs + TWENTY_YEARS; |
|---|
| 61 | 66 | |
|---|
| 62 | 67 | do { |
|---|
| 63 | 68 | __raw_writel((adj & 0xffff0000) >> 16, AICA_RTC_SECS_H); |
|---|
| .. | .. |
|---|
| 73 | 78 | return 0; |
|---|
| 74 | 79 | } |
|---|
| 75 | 80 | |
|---|
| 76 | | -void aica_time_init(void) |
|---|
| 77 | | -{ |
|---|
| 78 | | - rtc_sh_get_time = aica_rtc_gettimeofday; |
|---|
| 79 | | - rtc_sh_set_time = aica_rtc_settimeofday; |
|---|
| 80 | | -} |
|---|
| 81 | +static const struct rtc_class_ops rtc_generic_ops = { |
|---|
| 82 | + .read_time = aica_rtc_gettimeofday, |
|---|
| 83 | + .set_time = aica_rtc_settimeofday, |
|---|
| 84 | +}; |
|---|
| 81 | 85 | |
|---|
| 86 | +static int __init aica_time_init(void) |
|---|
| 87 | +{ |
|---|
| 88 | + struct platform_device *pdev; |
|---|
| 89 | + |
|---|
| 90 | + pdev = platform_device_register_data(NULL, "rtc-generic", -1, |
|---|
| 91 | + &rtc_generic_ops, |
|---|
| 92 | + sizeof(rtc_generic_ops)); |
|---|
| 93 | + |
|---|
| 94 | + return PTR_ERR_OR_ZERO(pdev); |
|---|
| 95 | +} |
|---|
| 96 | +arch_initcall(aica_time_init); |
|---|