Skip to content

Commit 7fdaba9

Browse files
committed
Merge tag 'rtc-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "There are two new drivers this cycle. There is also support for a negative offset for RTCs that have been shipped with a date set using an epoch that is before 1970. This unfortunately happens with some products that ship with a vendor kernel and an out of tree driver. Core: - support negative offsets for RTCs that have shipped with an epoch earlier than 1970 New drivers: - NXP S32G2/S32G3 - Sophgo CV1800 Drivers: - loongson: fix missing alarm notifications for ACPI - m41t80: kickstart ocillator upon failure - mt6359: mt6357 support - pcf8563: fix wrong alarm register - sh: cleanups" * tag 'rtc-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (39 commits) rtc: mt6359: Add mt6357 support rtc: test: Test date conversion for dates starting in 1900 rtc: test: Also test time and wday outcome of rtc_time64_to_tm() rtc: test: Emit the seconds-since-1970 value instead of days-since-1970 rtc: Fix offset calculation for .start_secs < 0 rtc: Make rtc_time64_to_tm() support dates before 1970 rtc: pcf8563: fix wrong alarm register rtc: rzn1: support input frequencies other than 32768Hz rtc: rzn1: Disable controller before initialization dt-bindings: rtc: rzn1: add optional second clock rtc: m41t80: reduce verbosity rtc: m41t80: kickstart ocillator upon failure rtc: s32g: add NXP S32G2/S32G3 SoC support dt-bindings: rtc: add schema for NXP S32G2/S32G3 SoCs dt-bindings: at91rm9260-rtt: add microchip,sama7d65-rtt dt-bindings: rtc: at91rm9200: add microchip,sama7d65-rtc rtc: loongson: Add missing alarm notifications for ACPI RTC events rtc: sophgo: add rtc support for Sophgo CV1800 SoC rtc: stm32: drop unused module alias rtc: s3c: drop unused module alias ...
2 parents bfdf35c + 3d8b44b commit 7fdaba9

26 files changed

+946
-329
lines changed

Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ properties:
2323
- microchip,sam9x60-rtc
2424
- microchip,sama7g5-rtc
2525
- items:
26-
- const: microchip,sam9x7-rtc
26+
- enum:
27+
- microchip,sam9x7-rtc
28+
- microchip,sama7d65-rtc
2729
- const: microchip,sam9x60-rtc
2830

2931
reg:

Documentation/devicetree/bindings/rtc/atmel,at91sam9260-rtt.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ properties:
2222
- enum:
2323
- microchip,sam9x60-rtt
2424
- microchip,sam9x7-rtt
25+
- microchip,sama7d65-rtt
2526
- const: atmel,at91sam9260-rtt
2627
- items:
2728
- const: microchip,sama7g5-rtt
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/rtc/nxp,s32g-rtc.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: NXP S32G2/S32G3 Real Time Clock (RTC)
8+
9+
maintainers:
10+
- Bogdan Hamciuc <[email protected]>
11+
- Ciprian Marian Costea <[email protected]>
12+
13+
description:
14+
RTC hardware module present on S32G2/S32G3 SoCs is used as a wakeup source.
15+
It is not kept alive during system reset and it is not battery-powered.
16+
17+
allOf:
18+
- $ref: rtc.yaml#
19+
20+
properties:
21+
compatible:
22+
oneOf:
23+
- enum:
24+
- nxp,s32g2-rtc
25+
- items:
26+
- const: nxp,s32g3-rtc
27+
- const: nxp,s32g2-rtc
28+
29+
reg:
30+
maxItems: 1
31+
32+
interrupts:
33+
maxItems: 1
34+
35+
clocks:
36+
items:
37+
- description: ipg clock drives the access to the RTC iomapped registers
38+
- description: Clock source for the RTC module. Can be selected between
39+
4 different clock sources using an integrated hardware mux.
40+
On S32G2/S32G3 SoCs, 'source0' is the SIRC clock (~32KHz) and it is
41+
available during standby and runtime. 'source1' is reserved and cannot
42+
be used. 'source2' is the FIRC clock and it is only available during
43+
runtime providing a better resolution (~48MHz). 'source3' is an external
44+
RTC clock source which can be additionally added in hardware.
45+
46+
clock-names:
47+
items:
48+
- const: ipg
49+
- enum: [ source0, source1, source2, source3 ]
50+
51+
required:
52+
- compatible
53+
- reg
54+
- interrupts
55+
- clocks
56+
- clock-names
57+
58+
additionalProperties: false
59+
60+
examples:
61+
- |
62+
#include <dt-bindings/interrupt-controller/arm-gic.h>
63+
#include <dt-bindings/interrupt-controller/irq.h>
64+
65+
rtc@40060000 {
66+
compatible = "nxp,s32g3-rtc",
67+
"nxp,s32g2-rtc";
68+
reg = <0x40060000 0x1000>;
69+
interrupts = <GIC_SPI 121 IRQ_TYPE_LEVEL_HIGH>;
70+
clocks = <&clks 54>, <&clks 55>;
71+
clock-names = "ipg", "source0";
72+
};

Documentation/devicetree/bindings/rtc/qcom-pm8xxx-rtc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ properties:
5555
description:
5656
RTC alarm is not owned by the OS
5757

58+
qcom,uefi-rtc-info:
59+
type: boolean
60+
description:
61+
RTC offset is stored as a four-byte GPS time offset in a 12-byte UEFI
62+
variable 882f8c2b-9646-435f-8de5-f208ff80c1bd-RTCInfo
63+
5864
wakeup-source: true
5965

6066
required:

Documentation/devicetree/bindings/rtc/renesas,rzn1-rtc.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ properties:
3333
- const: pps
3434

3535
clocks:
36-
maxItems: 1
36+
minItems: 1
37+
maxItems: 2
3738

3839
clock-names:
39-
const: hclk
40+
minItems: 1
41+
items:
42+
- const: hclk
43+
- const: xtal
4044

4145
power-domains:
4246
maxItems: 1

drivers/rtc/Kconfig

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,18 @@ config RTC_DRV_ASM9260
13881388
This driver can also be built as a module. If so, the module
13891389
will be called rtc-asm9260.
13901390

1391+
config RTC_DRV_CV1800
1392+
tristate "Sophgo CV1800 RTC"
1393+
depends on SOPHGO_CV1800_RTCSYS || COMPILE_TEST
1394+
select MFD_SYSCON
1395+
select REGMAP
1396+
help
1397+
If you say yes here you get support the RTC driver for Sophgo CV1800
1398+
series SoC.
1399+
1400+
This driver can also be built as a module. If so, the module will be
1401+
called rtc-cv1800.
1402+
13911403
config RTC_DRV_DIGICOLOR
13921404
tristate "Conexant Digicolor RTC"
13931405
depends on ARCH_DIGICOLOR || COMPILE_TEST
@@ -2088,12 +2100,23 @@ config RTC_DRV_AMLOGIC_A4
20882100
tristate "Amlogic RTC"
20892101
depends on ARCH_MESON || COMPILE_TEST
20902102
select REGMAP_MMIO
2091-
default y
2103+
default ARCH_MESON
20922104
help
20932105
If you say yes here you get support for the RTC block on the
20942106
Amlogic A113L2(A4) and A113X2(A5) SoCs.
20952107

20962108
This driver can also be built as a module. If so, the module
20972109
will be called "rtc-amlogic-a4".
20982110

2111+
config RTC_DRV_S32G
2112+
tristate "RTC driver for S32G2/S32G3 SoCs"
2113+
depends on ARCH_S32 || COMPILE_TEST
2114+
depends on COMMON_CLK
2115+
help
2116+
Say yes to enable RTC driver for platforms based on the
2117+
S32G2/S32G3 SoC family.
2118+
2119+
This RTC module can be used as a wakeup source.
2120+
Please note that it is not battery-powered.
2121+
20992122
endif # RTC_CLASS

drivers/rtc/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ obj-$(CONFIG_RTC_DRV_CADENCE) += rtc-cadence.o
4444
obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
4545
obj-$(CONFIG_RTC_DRV_CPCAP) += rtc-cpcap.o
4646
obj-$(CONFIG_RTC_DRV_CROS_EC) += rtc-cros-ec.o
47+
obj-$(CONFIG_RTC_DRV_CV1800) += rtc-cv1800.o
4748
obj-$(CONFIG_RTC_DRV_DA9052) += rtc-da9052.o
4849
obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o
4950
obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o
@@ -160,6 +161,7 @@ obj-$(CONFIG_RTC_DRV_RX8111) += rtc-rx8111.o
160161
obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o
161162
obj-$(CONFIG_RTC_DRV_RZN1) += rtc-rzn1.o
162163
obj-$(CONFIG_RTC_DRV_RENESAS_RTCA3) += rtc-renesas-rtca3.o
164+
obj-$(CONFIG_RTC_DRV_S32G) += rtc-s32g.o
163165
obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o
164166
obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o
165167
obj-$(CONFIG_RTC_DRV_S5M) += rtc-s5m.o

drivers/rtc/class.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static void rtc_device_get_offset(struct rtc_device *rtc)
326326
*
327327
* Otherwise the offset seconds should be 0.
328328
*/
329-
if (rtc->start_secs > rtc->range_max ||
329+
if ((rtc->start_secs >= 0 && rtc->start_secs > rtc->range_max) ||
330330
rtc->start_secs + range_secs - 1 < rtc->range_min)
331331
rtc->offset_secs = rtc->start_secs - rtc->range_min;
332332
else if (rtc->start_secs > rtc->range_min)

drivers/rtc/interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc,
205205

206206
mutex_unlock(&rtc->ops_lock);
207207

208-
trace_rtc_read_alarm(rtc_tm_to_time64(&alarm->time), err);
208+
trace_rtc_read_alarm(err?0:rtc_tm_to_time64(&alarm->time), err);
209209
return err;
210210
}
211211

drivers/rtc/lib.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,38 @@ EXPORT_SYMBOL(rtc_year_days);
4646
* rtc_time64_to_tm - converts time64_t to rtc_time.
4747
*
4848
* @time: The number of seconds since 01-01-1970 00:00:00.
49-
* (Must be positive.)
49+
* Works for values since at least 1900
5050
* @tm: Pointer to the struct rtc_time.
5151
*/
5252
void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
5353
{
54-
unsigned int secs;
55-
int days;
54+
int days, secs;
5655

5756
u64 u64tmp;
5857
u32 u32tmp, udays, century, day_of_century, year_of_century, year,
5958
day_of_year, month, day;
6059
bool is_Jan_or_Feb, is_leap_year;
6160

62-
/* time must be positive */
61+
/*
62+
* Get days and seconds while preserving the sign to
63+
* handle negative time values (dates before 1970-01-01)
64+
*/
6365
days = div_s64_rem(time, 86400, &secs);
6466

67+
/*
68+
* We need 0 <= secs < 86400 which isn't given for negative
69+
* values of time. Fixup accordingly.
70+
*/
71+
if (secs < 0) {
72+
days -= 1;
73+
secs += 86400;
74+
}
75+
6576
/* day of the week, 1970-01-01 was a Thursday */
6677
tm->tm_wday = (days + 4) % 7;
78+
/* Ensure tm_wday is always positive */
79+
if (tm->tm_wday < 0)
80+
tm->tm_wday += 7;
6781

6882
/*
6983
* The following algorithm is, basically, Proposition 6.3 of Neri
@@ -93,7 +107,7 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
93107
* thus, is slightly different from [1].
94108
*/
95109

96-
udays = ((u32) days) + 719468;
110+
udays = days + 719468;
97111

98112
u32tmp = 4 * udays + 3;
99113
century = u32tmp / 146097;

drivers/rtc/lib_test.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
/*
77
* Advance a date by one day.
88
*/
9-
static void advance_date(int *year, int *month, int *mday, int *yday)
9+
static void advance_date(int *year, int *month, int *mday, int *yday, int *wday)
1010
{
11+
*wday = (*wday + 1) % 7;
12+
1113
if (*mday != rtc_month_days(*month - 1, *year)) {
1214
++*mday;
1315
++*yday;
@@ -39,35 +41,38 @@ static void rtc_time64_to_tm_test_date_range(struct kunit *test, int years)
3941
*/
4042
time64_t total_secs = ((time64_t)years) / 400 * 146097 * 86400;
4143

42-
int year = 1970;
44+
int year = 1900;
4345
int month = 1;
4446
int mday = 1;
4547
int yday = 1;
48+
int wday = 1; /* Jan 1st 1900 was a Monday */
4649

4750
struct rtc_time result;
4851
time64_t secs;
49-
s64 days;
52+
const time64_t sec_offset = RTC_TIMESTAMP_BEGIN_1900 + ((1 * 60) + 2) * 60 + 3;
5053

5154
for (secs = 0; secs <= total_secs; secs += 86400) {
5255

53-
rtc_time64_to_tm(secs, &result);
54-
55-
days = div_s64(secs, 86400);
56+
rtc_time64_to_tm(secs + sec_offset, &result);
5657

57-
#define FAIL_MSG "%d/%02d/%02d (%2d) : %lld", \
58-
year, month, mday, yday, days
58+
#define FAIL_MSG "%d/%02d/%02d (%2d, %d) : %lld", \
59+
year, month, mday, yday, wday, secs + sec_offset
5960

6061
KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG);
6162
KUNIT_ASSERT_EQ_MSG(test, month - 1, result.tm_mon, FAIL_MSG);
6263
KUNIT_ASSERT_EQ_MSG(test, mday, result.tm_mday, FAIL_MSG);
6364
KUNIT_ASSERT_EQ_MSG(test, yday, result.tm_yday, FAIL_MSG);
65+
KUNIT_ASSERT_EQ_MSG(test, 1, result.tm_hour, FAIL_MSG);
66+
KUNIT_ASSERT_EQ_MSG(test, 2, result.tm_min, FAIL_MSG);
67+
KUNIT_ASSERT_EQ_MSG(test, 3, result.tm_sec, FAIL_MSG);
68+
KUNIT_ASSERT_EQ_MSG(test, wday, result.tm_wday, FAIL_MSG);
6469

65-
advance_date(&year, &month, &mday, &yday);
70+
advance_date(&year, &month, &mday, &yday, &wday);
6671
}
6772
}
6873

6974
/*
70-
* Checks every day in a 160000 years interval starting on 1970-01-01
75+
* Checks every day in a 160000 years interval starting on 1900-01-01
7176
* against the expected result.
7277
*/
7378
static void rtc_time64_to_tm_test_date_range_160000(struct kunit *test)
@@ -76,7 +81,7 @@ static void rtc_time64_to_tm_test_date_range_160000(struct kunit *test)
7681
}
7782

7883
/*
79-
* Checks every day in a 1000 years interval starting on 1970-01-01
84+
* Checks every day in a 1000 years interval starting on 1900-01-01
8085
* against the expected result.
8186
*/
8287
static void rtc_time64_to_tm_test_date_range_1000(struct kunit *test)

drivers/rtc/rtc-at91rm9200.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,4 +654,3 @@ module_platform_driver_probe(at91_rtc_driver, at91_rtc_probe);
654654
MODULE_AUTHOR("Rick Bronson");
655655
MODULE_DESCRIPTION("RTC driver for Atmel AT91RM9200");
656656
MODULE_LICENSE("GPL");
657-
MODULE_ALIAS("platform:at91_rtc");

drivers/rtc/rtc-cpcap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ static struct platform_driver cpcap_rtc_driver = {
320320

321321
module_platform_driver(cpcap_rtc_driver);
322322

323-
MODULE_ALIAS("platform:cpcap-rtc");
324323
MODULE_DESCRIPTION("CPCAP RTC driver");
325324
MODULE_AUTHOR("Sebastian Reichel <[email protected]>");
326325
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)