Skip to content

Commit d2eedaa

Browse files
committed
Merge tag 'rtc-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "Support for a new RTC in an existing driver and all the drivers exposing clocks using the common clock framework have been converted to determine_rate(). Summary: Subsystem: - Convert drivers exposing a clock from round_rate() to determine_rate() Drivers: - ds1307: oscillator stop flag handling for ds1341 - pcf85063: add support for RV8063" * tag 'rtc-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (34 commits) rtc: ds1685: Update Joshua Kinard's email address. rtc: rv3032: convert from round_rate() to determine_rate() rtc: rv3028: convert from round_rate() to determine_rate() rtc: pcf8563: convert from round_rate() to determine_rate() rtc: pcf85063: convert from round_rate() to determine_rate() rtc: nct3018y: convert from round_rate() to determine_rate() rtc: max31335: convert from round_rate() to determine_rate() rtc: m41t80: convert from round_rate() to determine_rate() rtc: hym8563: convert from round_rate() to determine_rate() rtc: ds1307: convert from round_rate() to determine_rate() rtc: rv3028: fix incorrect maximum clock rate handling rtc: pcf8563: fix incorrect maximum clock rate handling rtc: pcf85063: fix incorrect maximum clock rate handling rtc: nct3018y: fix incorrect maximum clock rate handling rtc: hym8563: fix incorrect maximum clock rate handling rtc: ds1307: fix incorrect maximum clock rate handling rtc: pcf85063: scope pcf85063_config structures rtc: Optimize calculations in rtc_time64_to_tm() dt-bindings: rtc: amlogic,a4-rtc: Add compatible string for C3 rtc: ds1307: handle oscillator stop flag (OSF) for ds1341 ...
2 parents 806381e + bb5b0b4 commit d2eedaa

25 files changed

+465
-205
lines changed

Documentation/devicetree/bindings/rtc/amlogic,a4-rtc.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ allOf:
1616

1717
properties:
1818
compatible:
19-
enum:
20-
- amlogic,a4-rtc
21-
- amlogic,a5-rtc
19+
oneOf:
20+
- enum:
21+
- amlogic,a4-rtc
22+
- amlogic,a5-rtc
23+
- items:
24+
- enum:
25+
- amlogic,c3-rtc
26+
- const: amlogic,a5-rtc
2227

2328
reg:
2429
maxItems: 1

Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ allOf:
1818

1919
properties:
2020
compatible:
21-
const: nxp,lpc1788-rtc
21+
oneOf:
22+
- items:
23+
- enum:
24+
- nxp,lpc1850-rtc
25+
- const: nxp,lpc1788-rtc
26+
- const: nxp,lpc1788-rtc
2227

2328
reg:
2429
maxItems: 1
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/rtc/nxp,lpc3220-rtc.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: NXP LPC32xx SoC Real-time Clock
8+
9+
maintainers:
10+
- Frank Li <[email protected]>
11+
12+
properties:
13+
compatible:
14+
enum:
15+
- nxp,lpc3220-rtc
16+
17+
reg:
18+
maxItems: 1
19+
20+
clocks:
21+
maxItems: 1
22+
23+
interrupts:
24+
maxItems: 1
25+
26+
start-year: true
27+
28+
required:
29+
- compatible
30+
- reg
31+
32+
allOf:
33+
- $ref: rtc.yaml#
34+
35+
unevaluatedProperties: false
36+
37+
examples:
38+
- |
39+
#include <dt-bindings/interrupt-controller/irq.h>
40+
#include <dt-bindings/clock/lpc32xx-clock.h>
41+
42+
rtc@40024000 {
43+
compatible = "nxp,lpc3220-rtc";
44+
reg = <0x40024000 0x1000>;
45+
interrupt-parent = <&sic1>;
46+
interrupts = <20 IRQ_TYPE_LEVEL_HIGH>;
47+
clocks = <&clk LPC32XX_CLK_RTC>;
48+
};
49+

Documentation/devicetree/bindings/rtc/nxp,pcf85063.yaml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ maintainers:
1212
properties:
1313
compatible:
1414
enum:
15+
- microcrystal,rv8063
1516
- microcrystal,rv8263
1617
- nxp,pcf85063
1718
- nxp,pcf85063a
@@ -44,13 +45,19 @@ properties:
4445

4546
wakeup-source: true
4647

48+
spi-cs-high: true
49+
50+
spi-3wire: true
51+
4752
allOf:
53+
- $ref: /schemas/spi/spi-peripheral-props.yaml#
4854
- $ref: rtc.yaml#
4955
- if:
5056
properties:
5157
compatible:
5258
contains:
5359
enum:
60+
- microcrystal,rv8063
5461
- microcrystal,rv8263
5562
then:
5663
properties:
@@ -65,12 +72,23 @@ allOf:
6572
properties:
6673
quartz-load-femtofarads:
6774
const: 7000
75+
- if:
76+
properties:
77+
compatible:
78+
not:
79+
contains:
80+
enum:
81+
- microcrystal,rv8063
82+
then:
83+
properties:
84+
spi-cs-high: false
85+
spi-3wire: false
6886

6987
required:
7088
- compatible
7189
- reg
7290

73-
additionalProperties: false
91+
unevaluatedProperties: false
7492

7593
examples:
7694
- |
@@ -90,3 +108,16 @@ examples:
90108
};
91109
};
92110
};
111+
112+
- |
113+
spi {
114+
#address-cells = <1>;
115+
#size-cells = <0>;
116+
117+
rtc@0 {
118+
compatible = "microcrystal,rv8063";
119+
reg = <0>;
120+
spi-cs-high;
121+
spi-3wire;
122+
};
123+
};

Documentation/devicetree/bindings/soc/sophgo/sophgo,cv1800b-rtc.yaml renamed to Documentation/devicetree/bindings/rtc/sophgo,cv1800b-rtc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
22
%YAML 1.2
33
---
4-
$id: http://devicetree.org/schemas/sophgo/sophgo,cv1800b-rtc.yaml#
4+
$id: http://devicetree.org/schemas/rtc/sophgo,cv1800b-rtc.yaml#
55
$schema: http://devicetree.org/meta-schemas/core.yaml#
66

77
title: Real Time Clock of the Sophgo CV1800 SoC

Documentation/devicetree/bindings/rtc/trivial-rtc.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ properties:
6363
- microcrystal,rv3029
6464
# Real Time Clock
6565
- microcrystal,rv8523
66-
# NXP LPC32xx SoC Real-time Clock
67-
- nxp,lpc3220-rtc
6866
# I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
6967
- ricoh,r2025sd
7068
# I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6713,7 +6713,7 @@ S: Supported
67136713
F: drivers/input/keyboard/dlink-dir685-touchkeys.c
67146714

67156715
DALLAS/MAXIM DS1685-FAMILY REAL TIME CLOCK
6716-
M: Joshua Kinard <[email protected]>
6716+
M: Joshua Kinard <[email protected]>
67176717
S: Maintained
67186718
F: drivers/rtc/rtc-ds1685.c
67196719
F: include/linux/rtc/ds1685.h

drivers/rtc/Kconfig

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,6 @@ config RTC_DRV_PCF8523
483483
This driver can also be built as a module. If so, the module
484484
will be called rtc-pcf8523.
485485

486-
config RTC_DRV_PCF85063
487-
tristate "NXP PCF85063"
488-
select REGMAP_I2C
489-
help
490-
If you say yes here you get support for the PCF85063 RTC chip
491-
492-
This driver can also be built as a module. If so, the module
493-
will be called rtc-pcf85063.
494-
495486
config RTC_DRV_PCF85363
496487
tristate "NXP PCF85363"
497488
select REGMAP_I2C
@@ -971,6 +962,18 @@ config RTC_DRV_PCF2127
971962
This driver can also be built as a module. If so, the module
972963
will be called rtc-pcf2127.
973964

965+
config RTC_DRV_PCF85063
966+
tristate "NXP PCF85063"
967+
depends on RTC_I2C_AND_SPI
968+
select REGMAP_I2C if I2C
969+
select REGMAP_SPI if SPI_MASTER
970+
help
971+
If you say yes here you get support for the PCF85063 and RV8063
972+
RTC chips.
973+
974+
This driver can also be built as a module. If so, the module
975+
will be called rtc-pcf85063.
976+
974977
config RTC_DRV_RV3029C2
975978
tristate "Micro Crystal RV3029/3049"
976979
depends on RTC_I2C_AND_SPI

drivers/rtc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rtc-core-$(CONFIG_RTC_INTF_DEV) += dev.o
1515
rtc-core-$(CONFIG_RTC_INTF_PROC) += proc.o
1616
rtc-core-$(CONFIG_RTC_INTF_SYSFS) += sysfs.o
1717

18-
obj-$(CONFIG_RTC_LIB_KUNIT_TEST) += lib_test.o
18+
obj-$(CONFIG_RTC_LIB_KUNIT_TEST) += test_rtc_lib.o
1919

2020
# Keep the list ordered.
2121

drivers/rtc/lib.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,34 @@ EXPORT_SYMBOL(rtc_year_days);
5151
*/
5252
void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
5353
{
54-
int days, secs;
54+
int secs;
5555

5656
u64 u64tmp;
5757
u32 u32tmp, udays, century, day_of_century, year_of_century, year,
5858
day_of_year, month, day;
5959
bool is_Jan_or_Feb, is_leap_year;
6060

6161
/*
62-
* Get days and seconds while preserving the sign to
63-
* handle negative time values (dates before 1970-01-01)
62+
* The time represented by `time` is given in seconds since 1970-01-01
63+
* (UTC). As the division done below might misbehave for negative
64+
* values, we convert it to seconds since 0000-03-01 and then assume it
65+
* will be non-negative.
66+
* Below we do 4 * udays + 3 which should fit into a 32 bit unsigned
67+
* variable. So the latest date this algorithm works for is 1073741823
68+
* days after 0000-03-01 which is in the year 2939805.
6469
*/
65-
days = div_s64_rem(time, 86400, &secs);
70+
time += (u64)719468 * 86400;
71+
72+
udays = div_s64_rem(time, 86400, &secs);
6673

6774
/*
68-
* We need 0 <= secs < 86400 which isn't given for negative
69-
* values of time. Fixup accordingly.
75+
* day of the week, 0000-03-01 was a Wednesday (in the proleptic
76+
* Gregorian calendar)
7077
*/
71-
if (secs < 0) {
72-
days -= 1;
73-
secs += 86400;
74-
}
75-
76-
/* day of the week, 1970-01-01 was a Thursday */
77-
tm->tm_wday = (days + 4) % 7;
78-
/* Ensure tm_wday is always positive */
79-
if (tm->tm_wday < 0)
80-
tm->tm_wday += 7;
78+
tm->tm_wday = (udays + 3) % 7;
8179

8280
/*
83-
* The following algorithm is, basically, Proposition 6.3 of Neri
81+
* The following algorithm is, basically, Figure 12 of Neri
8482
* and Schneider [1]. In a few words: it works on the computational
8583
* (fictitious) calendar where the year starts in March, month = 2
8684
* (*), and finishes in February, month = 13. This calendar is
@@ -100,15 +98,15 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
10098
* (using just arithmetics) it's easy to convert it to the
10199
* corresponding date in the Gregorian calendar.
102100
*
103-
* [1] "Euclidean Affine Functions and Applications to Calendar
104-
* Algorithms". https://arxiv.org/abs/2102.06959
101+
* [1] Neri C, Schneider L. Euclidean affine functions and their
102+
* application to calendar algorithms. Softw Pract Exper.
103+
* 2023;53(4):937-970. doi: 10.1002/spe.3172
104+
* https://doi.org/10.1002/spe.3172
105105
*
106106
* (*) The numbering of months follows rtc_time more closely and
107107
* thus, is slightly different from [1].
108108
*/
109109

110-
udays = days + 719468;
111-
112110
u32tmp = 4 * udays + 3;
113111
century = u32tmp / 146097;
114112
day_of_century = u32tmp % 146097 / 4;

0 commit comments

Comments
 (0)