Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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
...

+507 -247
+8 -3
Documentation/devicetree/bindings/rtc/amlogic,a4-rtc.yaml
··· 16 16 17 17 properties: 18 18 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 22 27 23 28 reg: 24 29 maxItems: 1
+6 -1
Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.yaml
··· 18 18 19 19 properties: 20 20 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 22 27 23 28 reg: 24 29 maxItems: 1
+49
Documentation/devicetree/bindings/rtc/nxp,lpc3220-rtc.yaml
··· 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 <Frank.Li@nxp.com> 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 +
+32 -1
Documentation/devicetree/bindings/rtc/nxp,pcf85063.yaml
··· 12 12 properties: 13 13 compatible: 14 14 enum: 15 + - microcrystal,rv8063 15 16 - microcrystal,rv8263 16 17 - nxp,pcf85063 17 18 - nxp,pcf85063a ··· 45 44 46 45 wakeup-source: true 47 46 47 + spi-cs-high: true 48 + 49 + spi-3wire: true 50 + 48 51 allOf: 52 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 49 53 - $ref: rtc.yaml# 50 54 - if: 51 55 properties: 52 56 compatible: 53 57 contains: 54 58 enum: 59 + - microcrystal,rv8063 55 60 - microcrystal,rv8263 56 61 then: 57 62 properties: ··· 72 65 properties: 73 66 quartz-load-femtofarads: 74 67 const: 7000 68 + - if: 69 + properties: 70 + compatible: 71 + not: 72 + contains: 73 + enum: 74 + - microcrystal,rv8063 75 + then: 76 + properties: 77 + spi-cs-high: false 78 + spi-3wire: false 75 79 76 80 required: 77 81 - compatible 78 82 - reg 79 83 80 - additionalProperties: false 84 + unevaluatedProperties: false 81 85 82 86 examples: 83 87 - | ··· 108 90 }; 109 91 }; 110 92 }; 93 + 94 + - | 95 + spi { 96 + #address-cells = <1>; 97 + #size-cells = <0>; 98 + 99 + rtc@0 { 100 + compatible = "microcrystal,rv8063"; 101 + reg = <0>; 102 + spi-cs-high; 103 + spi-3wire; 104 + }; 105 + };
-2
Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
··· 63 63 - microcrystal,rv3029 64 64 # Real Time Clock 65 65 - microcrystal,rv8523 66 - # NXP LPC32xx SoC Real-time Clock 67 - - nxp,lpc3220-rtc 68 66 # I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC 69 67 - ricoh,r2025sd 70 68 # I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
+1 -1
Documentation/devicetree/bindings/soc/sophgo/sophgo,cv1800b-rtc.yaml Documentation/devicetree/bindings/rtc/sophgo,cv1800b-rtc.yaml
··· 1 1 # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 2 %YAML 1.2 3 3 --- 4 - $id: http://devicetree.org/schemas/sophgo/sophgo,cv1800b-rtc.yaml# 4 + $id: http://devicetree.org/schemas/rtc/sophgo,cv1800b-rtc.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 7 title: Real Time Clock of the Sophgo CV1800 SoC
+1 -1
MAINTAINERS
··· 6713 6713 F: drivers/input/keyboard/dlink-dir685-touchkeys.c 6714 6714 6715 6715 DALLAS/MAXIM DS1685-FAMILY REAL TIME CLOCK 6716 - M: Joshua Kinard <kumba@gentoo.org> 6716 + M: Joshua Kinard <linux@kumba.dev> 6717 6717 S: Maintained 6718 6718 F: drivers/rtc/rtc-ds1685.c 6719 6719 F: include/linux/rtc/ds1685.h
+12 -9
drivers/rtc/Kconfig
··· 483 483 This driver can also be built as a module. If so, the module 484 484 will be called rtc-pcf8523. 485 485 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 - 495 486 config RTC_DRV_PCF85363 496 487 tristate "NXP PCF85363" 497 488 select REGMAP_I2C ··· 961 970 962 971 This driver can also be built as a module. If so, the module 963 972 will be called rtc-pcf2127. 973 + 974 + config RTC_DRV_PCF85063 975 + tristate "NXP PCF85063" 976 + depends on RTC_I2C_AND_SPI 977 + select REGMAP_I2C if I2C 978 + select REGMAP_SPI if SPI_MASTER 979 + help 980 + If you say yes here you get support for the PCF85063 and RV8063 981 + RTC chips. 982 + 983 + This driver can also be built as a module. If so, the module 984 + will be called rtc-pcf85063. 964 985 965 986 config RTC_DRV_RV3029C2 966 987 tristate "Micro Crystal RV3029/3049"
+1 -1
drivers/rtc/Makefile
··· 15 15 rtc-core-$(CONFIG_RTC_INTF_PROC) += proc.o 16 16 rtc-core-$(CONFIG_RTC_INTF_SYSFS) += sysfs.o 17 17 18 - obj-$(CONFIG_RTC_LIB_KUNIT_TEST) += lib_test.o 18 + obj-$(CONFIG_RTC_LIB_KUNIT_TEST) += test_rtc_lib.o 19 19 20 20 # Keep the list ordered. 21 21
+19 -21
drivers/rtc/lib.c
··· 51 51 */ 52 52 void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) 53 53 { 54 - int days, secs; 54 + int secs; 55 55 56 56 u64 u64tmp; 57 57 u32 u32tmp, udays, century, day_of_century, year_of_century, year, ··· 59 59 bool is_Jan_or_Feb, is_leap_year; 60 60 61 61 /* 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. 64 69 */ 65 - days = div_s64_rem(time, 86400, &secs); 70 + time += (u64)719468 * 86400; 71 + 72 + udays = div_s64_rem(time, 86400, &secs); 66 73 67 74 /* 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) 70 77 */ 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; 81 79 82 80 /* 83 - * The following algorithm is, basically, Proposition 6.3 of Neri 81 + * The following algorithm is, basically, Figure 12 of Neri 84 82 * and Schneider [1]. In a few words: it works on the computational 85 83 * (fictitious) calendar where the year starts in March, month = 2 86 84 * (*), and finishes in February, month = 13. This calendar is ··· 98 100 * (using just arithmetics) it's easy to convert it to the 99 101 * corresponding date in the Gregorian calendar. 100 102 * 101 - * [1] "Euclidean Affine Functions and Applications to Calendar 102 - * Algorithms". https://arxiv.org/abs/2102.06959 103 + * [1] Neri C, Schneider L. Euclidean affine functions and their 104 + * application to calendar algorithms. Softw Pract Exper. 105 + * 2023;53(4):937-970. doi: 10.1002/spe.3172 106 + * https://doi.org/10.1002/spe.3172 103 107 * 104 108 * (*) The numbering of months follows rtc_time more closely and 105 109 * thus, is slightly different from [1]. 106 110 */ 107 - 108 - udays = days + 719468; 109 111 110 112 u32tmp = 4 * udays + 3; 111 113 century = u32tmp / 146097;
drivers/rtc/lib_test.c drivers/rtc/test_rtc_lib.c
+22 -8
drivers/rtc/rtc-ds1307.c
··· 279 279 if (tmp & DS1340_BIT_OSF) 280 280 return -EINVAL; 281 281 break; 282 + case ds_1341: 283 + ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &tmp); 284 + if (ret) 285 + return ret; 286 + if (tmp & DS1337_BIT_OSF) 287 + return -EINVAL; 288 + break; 282 289 case ds_1388: 283 290 ret = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &tmp); 284 291 if (ret) ··· 383 376 case ds_1340: 384 377 regmap_update_bits(ds1307->regmap, DS1340_REG_FLAG, 385 378 DS1340_BIT_OSF, 0); 379 + break; 380 + case ds_1341: 381 + regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS, 382 + DS1337_BIT_OSF, 0); 386 383 break; 387 384 case ds_1388: 388 385 regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG, ··· 1467 1456 return ds3231_clk_sqw_rates[rate_sel]; 1468 1457 } 1469 1458 1470 - static long ds3231_clk_sqw_round_rate(struct clk_hw *hw, unsigned long rate, 1471 - unsigned long *prate) 1459 + static int ds3231_clk_sqw_determine_rate(struct clk_hw *hw, 1460 + struct clk_rate_request *req) 1472 1461 { 1473 1462 int i; 1474 1463 1475 1464 for (i = ARRAY_SIZE(ds3231_clk_sqw_rates) - 1; i >= 0; i--) { 1476 - if (ds3231_clk_sqw_rates[i] <= rate) 1477 - return ds3231_clk_sqw_rates[i]; 1465 + if (ds3231_clk_sqw_rates[i] <= req->rate) { 1466 + req->rate = ds3231_clk_sqw_rates[i]; 1467 + 1468 + return 0; 1469 + } 1478 1470 } 1471 + 1472 + req->rate = ds3231_clk_sqw_rates[ARRAY_SIZE(ds3231_clk_sqw_rates) - 1]; 1479 1473 1480 1474 return 0; 1481 1475 } ··· 1541 1525 .unprepare = ds3231_clk_sqw_unprepare, 1542 1526 .is_prepared = ds3231_clk_sqw_is_prepared, 1543 1527 .recalc_rate = ds3231_clk_sqw_recalc_rate, 1544 - .round_rate = ds3231_clk_sqw_round_rate, 1528 + .determine_rate = ds3231_clk_sqw_determine_rate, 1545 1529 .set_rate = ds3231_clk_sqw_set_rate, 1546 1530 }; 1547 1531 ··· 1829 1813 regmap_write(ds1307->regmap, DS1337_REG_CONTROL, 1830 1814 regs[0]); 1831 1815 1832 - /* oscillator fault? clear flag, and warn */ 1816 + /* oscillator fault? warn */ 1833 1817 if (regs[1] & DS1337_BIT_OSF) { 1834 - regmap_write(ds1307->regmap, DS1337_REG_STATUS, 1835 - regs[1] & ~DS1337_BIT_OSF); 1836 1818 dev_warn(ds1307->dev, "SET TIME!\n"); 1837 1819 } 1838 1820 break;
+2 -2
drivers/rtc/rtc-ds1685.c
··· 3 3 * An rtc driver for the Dallas/Maxim DS1685/DS1687 and related real-time 4 4 * chips. 5 5 * 6 - * Copyright (C) 2011-2014 Joshua Kinard <kumba@gentoo.org>. 6 + * Copyright (C) 2011-2014 Joshua Kinard <linux@kumba.dev>. 7 7 * Copyright (C) 2009 Matthias Fuchs <matthias.fuchs@esd-electronics.com>. 8 8 * 9 9 * References: ··· 1436 1436 /* ----------------------------------------------------------------------- */ 1437 1437 1438 1438 1439 - MODULE_AUTHOR("Joshua Kinard <kumba@gentoo.org>"); 1439 + MODULE_AUTHOR("Joshua Kinard <linux@kumba.dev>"); 1440 1440 MODULE_AUTHOR("Matthias Fuchs <matthias.fuchs@esd-electronics.com>"); 1441 1441 MODULE_DESCRIPTION("Dallas/Maxim DS1685/DS1687-series RTC driver"); 1442 1442 MODULE_LICENSE("GPL");
+10 -5
drivers/rtc/rtc-hym8563.c
··· 285 285 return clkout_rates[ret]; 286 286 } 287 287 288 - static long hym8563_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 289 - unsigned long *prate) 288 + static int hym8563_clkout_determine_rate(struct clk_hw *hw, 289 + struct clk_rate_request *req) 290 290 { 291 291 int i; 292 292 293 293 for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 294 - if (clkout_rates[i] <= rate) 295 - return clkout_rates[i]; 294 + if (clkout_rates[i] <= req->rate) { 295 + req->rate = clkout_rates[i]; 296 + 297 + return 0; 298 + } 299 + 300 + req->rate = clkout_rates[0]; 296 301 297 302 return 0; 298 303 } ··· 368 363 .unprepare = hym8563_clkout_unprepare, 369 364 .is_prepared = hym8563_clkout_is_prepared, 370 365 .recalc_rate = hym8563_clkout_recalc_rate, 371 - .round_rate = hym8563_clkout_round_rate, 366 + .determine_rate = hym8563_clkout_determine_rate, 372 367 .set_rate = hym8563_clkout_set_rate, 373 368 }; 374 369
+13 -12
drivers/rtc/rtc-m41t80.c
··· 72 72 73 73 static const struct i2c_device_id m41t80_id[] = { 74 74 { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT }, 75 - { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, 75 + { "m41t65", M41T80_FEATURE_WD }, 76 76 { "m41t80", M41T80_FEATURE_SQ }, 77 77 { "m41t81", M41T80_FEATURE_HT | M41T80_FEATURE_SQ}, 78 78 { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, ··· 93 93 }, 94 94 { 95 95 .compatible = "st,m41t65", 96 - .data = (void *)(M41T80_FEATURE_HT | M41T80_FEATURE_WD) 96 + .data = (void *)(M41T80_FEATURE_WD) 97 97 }, 98 98 { 99 99 .compatible = "st,m41t80", ··· 484 484 return sqw_to_m41t80_data(hw)->freq; 485 485 } 486 486 487 - static long m41t80_sqw_round_rate(struct clk_hw *hw, unsigned long rate, 488 - unsigned long *prate) 487 + static int m41t80_sqw_determine_rate(struct clk_hw *hw, 488 + struct clk_rate_request *req) 489 489 { 490 - if (rate >= M41T80_SQW_MAX_FREQ) 491 - return M41T80_SQW_MAX_FREQ; 492 - if (rate >= M41T80_SQW_MAX_FREQ / 4) 493 - return M41T80_SQW_MAX_FREQ / 4; 494 - if (!rate) 495 - return 0; 496 - return 1 << ilog2(rate); 490 + if (req->rate >= M41T80_SQW_MAX_FREQ) 491 + req->rate = M41T80_SQW_MAX_FREQ; 492 + else if (req->rate >= M41T80_SQW_MAX_FREQ / 4) 493 + req->rate = M41T80_SQW_MAX_FREQ / 4; 494 + else if (req->rate) 495 + req->rate = 1 << ilog2(req->rate); 496 + 497 + return 0; 497 498 } 498 499 499 500 static int m41t80_sqw_set_rate(struct clk_hw *hw, unsigned long rate, ··· 565 564 .unprepare = m41t80_sqw_unprepare, 566 565 .is_prepared = m41t80_sqw_is_prepared, 567 566 .recalc_rate = m41t80_sqw_recalc_rate, 568 - .round_rate = m41t80_sqw_round_rate, 567 + .determine_rate = m41t80_sqw_determine_rate, 569 568 .set_rate = m41t80_sqw_set_rate, 570 569 }; 571 570
+7 -5
drivers/rtc/rtc-max31335.c
··· 497 497 return max31335_clkout_freq[reg & freq_mask]; 498 498 } 499 499 500 - static long max31335_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 501 - unsigned long *prate) 500 + static int max31335_clkout_determine_rate(struct clk_hw *hw, 501 + struct clk_rate_request *req) 502 502 { 503 503 int index; 504 504 505 - index = find_closest(rate, max31335_clkout_freq, 505 + index = find_closest(req->rate, max31335_clkout_freq, 506 506 ARRAY_SIZE(max31335_clkout_freq)); 507 507 508 - return max31335_clkout_freq[index]; 508 + req->rate = max31335_clkout_freq[index]; 509 + 510 + return 0; 509 511 } 510 512 511 513 static int max31335_clkout_set_rate(struct clk_hw *hw, unsigned long rate, ··· 556 554 557 555 static const struct clk_ops max31335_clkout_ops = { 558 556 .recalc_rate = max31335_clkout_recalc_rate, 559 - .round_rate = max31335_clkout_round_rate, 557 + .determine_rate = max31335_clkout_determine_rate, 560 558 .set_rate = max31335_clkout_set_rate, 561 559 .enable = max31335_clkout_enable, 562 560 .disable = max31335_clkout_disable,
+10 -5
drivers/rtc/rtc-nct3018y.c
··· 367 367 return clkout_rates[flags]; 368 368 } 369 369 370 - static long nct3018y_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 371 - unsigned long *prate) 370 + static int nct3018y_clkout_determine_rate(struct clk_hw *hw, 371 + struct clk_rate_request *req) 372 372 { 373 373 int i; 374 374 375 375 for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 376 - if (clkout_rates[i] <= rate) 377 - return clkout_rates[i]; 376 + if (clkout_rates[i] <= req->rate) { 377 + req->rate = clkout_rates[i]; 378 + 379 + return 0; 380 + } 381 + 382 + req->rate = clkout_rates[0]; 378 383 379 384 return 0; 380 385 } ··· 451 446 .unprepare = nct3018y_clkout_unprepare, 452 447 .is_prepared = nct3018y_clkout_is_prepared, 453 448 .recalc_rate = nct3018y_clkout_recalc_rate, 454 - .round_rate = nct3018y_clkout_round_rate, 449 + .determine_rate = nct3018y_clkout_determine_rate, 455 450 .set_rate = nct3018y_clkout_set_rate, 456 451 }; 457 452
+242 -109
drivers/rtc/rtc-pcf85063.c
··· 17 17 #include <linux/of.h> 18 18 #include <linux/pm_wakeirq.h> 19 19 #include <linux/regmap.h> 20 + #include <linux/spi/spi.h> 20 21 21 22 /* 22 23 * Information for this driver was pulled from the following datasheets. ··· 30 29 * 31 30 * https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8263-C7_App-Manual.pdf 32 31 * RV8263 -- Rev. 1.0 — January 2019 32 + * 33 + * https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8063-C7_App-Manual.pdf 34 + * RV8063 -- Rev. 1.1 - October 2018 33 35 */ 34 36 35 37 #define PCF85063_REG_CTRL1 0x00 /* status */ ··· 405 401 return clkout_rates[buf]; 406 402 } 407 403 408 - static long pcf85063_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 409 - unsigned long *prate) 404 + static int pcf85063_clkout_determine_rate(struct clk_hw *hw, 405 + struct clk_rate_request *req) 410 406 { 411 407 int i; 412 408 413 409 for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 414 - if (clkout_rates[i] <= rate) 415 - return clkout_rates[i]; 410 + if (clkout_rates[i] <= req->rate) { 411 + req->rate = clkout_rates[i]; 412 + 413 + return 0; 414 + } 415 + 416 + req->rate = clkout_rates[0]; 416 417 417 418 return 0; 418 419 } ··· 491 482 .unprepare = pcf85063_clkout_unprepare, 492 483 .is_prepared = pcf85063_clkout_is_prepared, 493 484 .recalc_rate = pcf85063_clkout_recalc_rate, 494 - .round_rate = pcf85063_clkout_round_rate, 485 + .determine_rate = pcf85063_clkout_determine_rate, 495 486 .set_rate = pcf85063_clkout_set_rate, 496 487 }; 497 488 ··· 533 524 } 534 525 #endif 535 526 527 + static int pcf85063_probe(struct device *dev, struct regmap *regmap, int irq, 528 + const struct pcf85063_config *config) 529 + { 530 + struct pcf85063 *pcf85063; 531 + unsigned int tmp; 532 + int err; 533 + struct nvmem_config nvmem_cfg = { 534 + .name = "pcf85063_nvram", 535 + .reg_read = pcf85063_nvmem_read, 536 + .reg_write = pcf85063_nvmem_write, 537 + .type = NVMEM_TYPE_BATTERY_BACKED, 538 + .size = 1, 539 + }; 540 + 541 + dev_dbg(dev, "%s\n", __func__); 542 + 543 + pcf85063 = devm_kzalloc(dev, sizeof(struct pcf85063), 544 + GFP_KERNEL); 545 + if (!pcf85063) 546 + return -ENOMEM; 547 + 548 + pcf85063->regmap = regmap; 549 + 550 + dev_set_drvdata(dev, pcf85063); 551 + 552 + err = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &tmp); 553 + if (err) 554 + return dev_err_probe(dev, err, "RTC chip is not present\n"); 555 + 556 + pcf85063->rtc = devm_rtc_allocate_device(dev); 557 + if (IS_ERR(pcf85063->rtc)) 558 + return PTR_ERR(pcf85063->rtc); 559 + 560 + /* 561 + * If a Power loss is detected, SW reset the device. 562 + * From PCF85063A datasheet: 563 + * There is a low probability that some devices will have corruption 564 + * of the registers after the automatic power-on reset... 565 + */ 566 + if (tmp & PCF85063_REG_SC_OS) { 567 + dev_warn(dev, "POR issue detected, sending a SW reset\n"); 568 + err = regmap_write(pcf85063->regmap, PCF85063_REG_CTRL1, 569 + PCF85063_REG_CTRL1_SWR); 570 + if (err < 0) 571 + dev_warn(dev, "SW reset failed, trying to continue\n"); 572 + } 573 + 574 + err = pcf85063_load_capacitance(pcf85063, dev->of_node, 575 + config->force_cap_7000 ? 7000 : 0); 576 + if (err < 0) 577 + dev_warn(dev, "failed to set xtal load capacitance: %d", 578 + err); 579 + 580 + pcf85063->rtc->ops = &pcf85063_rtc_ops; 581 + pcf85063->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 582 + pcf85063->rtc->range_max = RTC_TIMESTAMP_END_2099; 583 + set_bit(RTC_FEATURE_ALARM_RES_2S, pcf85063->rtc->features); 584 + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf85063->rtc->features); 585 + clear_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features); 586 + 587 + if (config->has_alarms && irq > 0) { 588 + unsigned long irqflags = IRQF_TRIGGER_LOW; 589 + 590 + if (dev_fwnode(dev)) 591 + irqflags = 0; 592 + 593 + err = devm_request_threaded_irq(dev, irq, 594 + NULL, pcf85063_rtc_handle_irq, 595 + irqflags | IRQF_ONESHOT, 596 + "pcf85063", pcf85063); 597 + if (err) { 598 + dev_warn(&pcf85063->rtc->dev, 599 + "unable to request IRQ, alarms disabled\n"); 600 + } else { 601 + set_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features); 602 + device_init_wakeup(dev, true); 603 + err = dev_pm_set_wake_irq(dev, irq); 604 + if (err) 605 + dev_err(&pcf85063->rtc->dev, 606 + "failed to enable irq wake\n"); 607 + } 608 + } 609 + 610 + nvmem_cfg.priv = pcf85063->regmap; 611 + devm_rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg); 612 + 613 + #ifdef CONFIG_COMMON_CLK 614 + /* register clk in common clk framework */ 615 + pcf85063_clkout_register_clk(pcf85063); 616 + #endif 617 + 618 + return devm_rtc_register_device(pcf85063->rtc); 619 + } 620 + 621 + #if IS_ENABLED(CONFIG_I2C) 622 + 536 623 static const struct pcf85063_config config_pcf85063 = { 537 624 .regmap = { 538 625 .reg_bits = 8, ··· 664 559 .force_cap_7000 = 1, 665 560 }; 666 561 667 - static int pcf85063_probe(struct i2c_client *client) 668 - { 669 - struct pcf85063 *pcf85063; 670 - unsigned int tmp; 671 - int err; 672 - const struct pcf85063_config *config; 673 - struct nvmem_config nvmem_cfg = { 674 - .name = "pcf85063_nvram", 675 - .reg_read = pcf85063_nvmem_read, 676 - .reg_write = pcf85063_nvmem_write, 677 - .type = NVMEM_TYPE_BATTERY_BACKED, 678 - .size = 1, 679 - }; 680 - 681 - dev_dbg(&client->dev, "%s\n", __func__); 682 - 683 - pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063), 684 - GFP_KERNEL); 685 - if (!pcf85063) 686 - return -ENOMEM; 687 - 688 - config = i2c_get_match_data(client); 689 - if (!config) 690 - return -ENODEV; 691 - 692 - pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap); 693 - if (IS_ERR(pcf85063->regmap)) 694 - return PTR_ERR(pcf85063->regmap); 695 - 696 - i2c_set_clientdata(client, pcf85063); 697 - 698 - err = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &tmp); 699 - if (err) 700 - return dev_err_probe(&client->dev, err, "RTC chip is not present\n"); 701 - 702 - pcf85063->rtc = devm_rtc_allocate_device(&client->dev); 703 - if (IS_ERR(pcf85063->rtc)) 704 - return PTR_ERR(pcf85063->rtc); 705 - 706 - /* 707 - * If a Power loss is detected, SW reset the device. 708 - * From PCF85063A datasheet: 709 - * There is a low probability that some devices will have corruption 710 - * of the registers after the automatic power-on reset... 711 - */ 712 - if (tmp & PCF85063_REG_SC_OS) { 713 - dev_warn(&client->dev, 714 - "POR issue detected, sending a SW reset\n"); 715 - err = regmap_write(pcf85063->regmap, PCF85063_REG_CTRL1, 716 - PCF85063_REG_CTRL1_SWR); 717 - if (err < 0) 718 - dev_warn(&client->dev, 719 - "SW reset failed, trying to continue\n"); 720 - } 721 - 722 - err = pcf85063_load_capacitance(pcf85063, client->dev.of_node, 723 - config->force_cap_7000 ? 7000 : 0); 724 - if (err < 0) 725 - dev_warn(&client->dev, "failed to set xtal load capacitance: %d", 726 - err); 727 - 728 - pcf85063->rtc->ops = &pcf85063_rtc_ops; 729 - pcf85063->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 730 - pcf85063->rtc->range_max = RTC_TIMESTAMP_END_2099; 731 - set_bit(RTC_FEATURE_ALARM_RES_2S, pcf85063->rtc->features); 732 - clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf85063->rtc->features); 733 - clear_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features); 734 - 735 - if (config->has_alarms && client->irq > 0) { 736 - unsigned long irqflags = IRQF_TRIGGER_LOW; 737 - 738 - if (dev_fwnode(&client->dev)) 739 - irqflags = 0; 740 - 741 - err = devm_request_threaded_irq(&client->dev, client->irq, 742 - NULL, pcf85063_rtc_handle_irq, 743 - irqflags | IRQF_ONESHOT, 744 - "pcf85063", pcf85063); 745 - if (err) { 746 - dev_warn(&pcf85063->rtc->dev, 747 - "unable to request IRQ, alarms disabled\n"); 748 - } else { 749 - set_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features); 750 - device_init_wakeup(&client->dev, true); 751 - err = dev_pm_set_wake_irq(&client->dev, client->irq); 752 - if (err) 753 - dev_err(&pcf85063->rtc->dev, 754 - "failed to enable irq wake\n"); 755 - } 756 - } 757 - 758 - nvmem_cfg.priv = pcf85063->regmap; 759 - devm_rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg); 760 - 761 - #ifdef CONFIG_COMMON_CLK 762 - /* register clk in common clk framework */ 763 - pcf85063_clkout_register_clk(pcf85063); 764 - #endif 765 - 766 - return devm_rtc_register_device(pcf85063->rtc); 767 - } 768 - 769 562 static const struct i2c_device_id pcf85063_ids[] = { 770 563 { "pca85073a", .driver_data = (kernel_ulong_t)&config_pcf85063a }, 771 564 { "pcf85063", .driver_data = (kernel_ulong_t)&config_pcf85063 }, ··· 686 683 MODULE_DEVICE_TABLE(of, pcf85063_of_match); 687 684 #endif 688 685 686 + static int pcf85063_i2c_probe(struct i2c_client *client) 687 + { 688 + const struct pcf85063_config *config; 689 + struct regmap *regmap; 690 + 691 + config = i2c_get_match_data(client); 692 + if (!config) 693 + return -ENODEV; 694 + 695 + regmap = devm_regmap_init_i2c(client, &config->regmap); 696 + if (IS_ERR(regmap)) 697 + return PTR_ERR(regmap); 698 + 699 + return pcf85063_probe(&client->dev, regmap, client->irq, config); 700 + } 701 + 689 702 static struct i2c_driver pcf85063_driver = { 690 703 .driver = { 691 704 .name = "rtc-pcf85063", 692 705 .of_match_table = of_match_ptr(pcf85063_of_match), 693 706 }, 694 - .probe = pcf85063_probe, 707 + .probe = pcf85063_i2c_probe, 695 708 .id_table = pcf85063_ids, 696 709 }; 697 710 698 - module_i2c_driver(pcf85063_driver); 711 + static int pcf85063_register_driver(void) 712 + { 713 + return i2c_add_driver(&pcf85063_driver); 714 + } 715 + 716 + static void pcf85063_unregister_driver(void) 717 + { 718 + i2c_del_driver(&pcf85063_driver); 719 + } 720 + 721 + #else 722 + 723 + static int pcf85063_register_driver(void) 724 + { 725 + return 0; 726 + } 727 + 728 + static void pcf85063_unregister_driver(void) 729 + { 730 + } 731 + 732 + #endif /* IS_ENABLED(CONFIG_I2C) */ 733 + 734 + #if IS_ENABLED(CONFIG_SPI_MASTER) 735 + 736 + static const struct pcf85063_config config_rv8063 = { 737 + .regmap = { 738 + .reg_bits = 8, 739 + .val_bits = 8, 740 + .max_register = 0x11, 741 + .read_flag_mask = BIT(7) | BIT(5), 742 + .write_flag_mask = BIT(5), 743 + }, 744 + .has_alarms = 1, 745 + .force_cap_7000 = 1, 746 + }; 747 + 748 + static const struct spi_device_id rv8063_id[] = { 749 + { "rv8063" }, 750 + {} 751 + }; 752 + MODULE_DEVICE_TABLE(spi, rv8063_id); 753 + 754 + static const struct of_device_id rv8063_of_match[] = { 755 + { .compatible = "microcrystal,rv8063" }, 756 + {} 757 + }; 758 + MODULE_DEVICE_TABLE(of, rv8063_of_match); 759 + 760 + static int rv8063_probe(struct spi_device *spi) 761 + { 762 + const struct pcf85063_config *config = &config_rv8063; 763 + struct regmap *regmap; 764 + 765 + regmap = devm_regmap_init_spi(spi, &config->regmap); 766 + if (IS_ERR(regmap)) 767 + return PTR_ERR(regmap); 768 + 769 + return pcf85063_probe(&spi->dev, regmap, spi->irq, config); 770 + } 771 + 772 + static struct spi_driver rv8063_driver = { 773 + .driver = { 774 + .name = "rv8063", 775 + .of_match_table = rv8063_of_match, 776 + }, 777 + .probe = rv8063_probe, 778 + .id_table = rv8063_id, 779 + }; 780 + 781 + static int __init rv8063_register_driver(void) 782 + { 783 + return spi_register_driver(&rv8063_driver); 784 + } 785 + 786 + static void __exit rv8063_unregister_driver(void) 787 + { 788 + spi_unregister_driver(&rv8063_driver); 789 + } 790 + 791 + #else 792 + 793 + static int __init rv8063_register_driver(void) 794 + { 795 + return 0; 796 + } 797 + 798 + static void __exit rv8063_unregister_driver(void) 799 + { 800 + } 801 + 802 + #endif /* IS_ENABLED(CONFIG_SPI_MASTER) */ 803 + 804 + static int __init pcf85063_init(void) 805 + { 806 + int ret; 807 + 808 + ret = pcf85063_register_driver(); 809 + if (ret) 810 + return ret; 811 + 812 + ret = rv8063_register_driver(); 813 + if (ret) 814 + pcf85063_unregister_driver(); 815 + 816 + return ret; 817 + } 818 + module_init(pcf85063_init); 819 + 820 + static void __exit pcf85063_exit(void) 821 + { 822 + rv8063_unregister_driver(); 823 + pcf85063_unregister_driver(); 824 + } 825 + module_exit(pcf85063_exit); 699 826 700 827 MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>"); 701 828 MODULE_DESCRIPTION("PCF85063 RTC driver");
+10 -5
drivers/rtc/rtc-pcf8563.c
··· 330 330 return clkout_rates[buf]; 331 331 } 332 332 333 - static long pcf8563_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 334 - unsigned long *prate) 333 + static int pcf8563_clkout_determine_rate(struct clk_hw *hw, 334 + struct clk_rate_request *req) 335 335 { 336 336 int i; 337 337 338 338 for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 339 - if (clkout_rates[i] <= rate) 340 - return clkout_rates[i]; 339 + if (clkout_rates[i] <= req->rate) { 340 + req->rate = clkout_rates[i]; 341 + 342 + return 0; 343 + } 344 + 345 + req->rate = clkout_rates[0]; 341 346 342 347 return 0; 343 348 } ··· 418 413 .unprepare = pcf8563_clkout_unprepare, 419 414 .is_prepared = pcf8563_clkout_is_prepared, 420 415 .recalc_rate = pcf8563_clkout_recalc_rate, 421 - .round_rate = pcf8563_clkout_round_rate, 416 + .determine_rate = pcf8563_clkout_determine_rate, 422 417 .set_rate = pcf8563_clkout_set_rate, 423 418 }; 424 419
+10 -5
drivers/rtc/rtc-rv3028.c
··· 731 731 return clkout_rates[clkout]; 732 732 } 733 733 734 - static long rv3028_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 735 - unsigned long *prate) 734 + static int rv3028_clkout_determine_rate(struct clk_hw *hw, 735 + struct clk_rate_request *req) 736 736 { 737 737 int i; 738 738 739 739 for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 740 - if (clkout_rates[i] <= rate) 741 - return clkout_rates[i]; 740 + if (clkout_rates[i] <= req->rate) { 741 + req->rate = clkout_rates[i]; 742 + 743 + return 0; 744 + } 745 + 746 + req->rate = clkout_rates[0]; 742 747 743 748 return 0; 744 749 } ··· 807 802 .unprepare = rv3028_clkout_unprepare, 808 803 .is_prepared = rv3028_clkout_is_prepared, 809 804 .recalc_rate = rv3028_clkout_recalc_rate, 810 - .round_rate = rv3028_clkout_round_rate, 805 + .determine_rate = rv3028_clkout_determine_rate, 811 806 .set_rate = rv3028_clkout_set_rate, 812 807 }; 813 808
+13 -8
drivers/rtc/rtc-rv3032.c
··· 646 646 return clkout_xtal_rates[FIELD_GET(RV3032_CLKOUT2_FD_MSK, clkout)]; 647 647 } 648 648 649 - static long rv3032_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 650 - unsigned long *prate) 649 + static int rv3032_clkout_determine_rate(struct clk_hw *hw, 650 + struct clk_rate_request *req) 651 651 { 652 652 int i, hfd; 653 653 654 - if (rate < RV3032_HFD_STEP) 654 + if (req->rate < RV3032_HFD_STEP) 655 655 for (i = 0; i < ARRAY_SIZE(clkout_xtal_rates); i++) 656 - if (clkout_xtal_rates[i] <= rate) 657 - return clkout_xtal_rates[i]; 656 + if (clkout_xtal_rates[i] <= req->rate) { 657 + req->rate = clkout_xtal_rates[i]; 658 658 659 - hfd = DIV_ROUND_CLOSEST(rate, RV3032_HFD_STEP); 659 + return 0; 660 + } 660 661 661 - return RV3032_HFD_STEP * clamp(hfd, 0, 8192); 662 + hfd = DIV_ROUND_CLOSEST(req->rate, RV3032_HFD_STEP); 663 + 664 + req->rate = RV3032_HFD_STEP * clamp(hfd, 0, 8192); 665 + 666 + return 0; 662 667 } 663 668 664 669 static int rv3032_clkout_set_rate(struct clk_hw *hw, unsigned long rate, ··· 743 738 .unprepare = rv3032_clkout_unprepare, 744 739 .is_prepared = rv3032_clkout_is_prepared, 745 740 .recalc_rate = rv3032_clkout_recalc_rate, 746 - .round_rate = rv3032_clkout_round_rate, 741 + .determine_rate = rv3032_clkout_determine_rate, 747 742 .set_rate = rv3032_clkout_set_rate, 748 743 }; 749 744
+4 -4
drivers/rtc/rtc-s3c.c
··· 549 549 writeb(mask, info->base + S3C2410_INTP); 550 550 } 551 551 552 - static struct s3c_rtc_data const s3c2410_rtc_data = { 552 + static const struct s3c_rtc_data s3c2410_rtc_data = { 553 553 .irq_handler = s3c24xx_rtc_irq, 554 554 .enable = s3c24xx_rtc_enable, 555 555 .disable = s3c24xx_rtc_disable, 556 556 }; 557 557 558 - static struct s3c_rtc_data const s3c2416_rtc_data = { 558 + static const struct s3c_rtc_data s3c2416_rtc_data = { 559 559 .irq_handler = s3c24xx_rtc_irq, 560 560 .enable = s3c24xx_rtc_enable, 561 561 .disable = s3c24xx_rtc_disable, 562 562 }; 563 563 564 - static struct s3c_rtc_data const s3c2443_rtc_data = { 564 + static const struct s3c_rtc_data s3c2443_rtc_data = { 565 565 .irq_handler = s3c24xx_rtc_irq, 566 566 .enable = s3c24xx_rtc_enable, 567 567 .disable = s3c24xx_rtc_disable, 568 568 }; 569 569 570 - static struct s3c_rtc_data const s3c6410_rtc_data = { 570 + static const struct s3c_rtc_data s3c6410_rtc_data = { 571 571 .needs_src_clk = true, 572 572 .irq_handler = s3c6410_rtc_irq, 573 573 .enable = s3c24xx_rtc_enable,
+4 -4
drivers/rtc/rtc-sh.c
··· 455 455 clk_disable(rtc->clk); 456 456 } 457 457 458 - static int __maybe_unused sh_rtc_suspend(struct device *dev) 458 + static int sh_rtc_suspend(struct device *dev) 459 459 { 460 460 struct sh_rtc *rtc = dev_get_drvdata(dev); 461 461 ··· 465 465 return 0; 466 466 } 467 467 468 - static int __maybe_unused sh_rtc_resume(struct device *dev) 468 + static int sh_rtc_resume(struct device *dev) 469 469 { 470 470 struct sh_rtc *rtc = dev_get_drvdata(dev); 471 471 ··· 475 475 return 0; 476 476 } 477 477 478 - static SIMPLE_DEV_PM_OPS(sh_rtc_pm_ops, sh_rtc_suspend, sh_rtc_resume); 478 + static DEFINE_SIMPLE_DEV_PM_OPS(sh_rtc_pm_ops, sh_rtc_suspend, sh_rtc_resume); 479 479 480 480 static const struct of_device_id sh_rtc_of_match[] = { 481 481 { .compatible = "renesas,sh-rtc", }, ··· 492 492 static struct platform_driver sh_rtc_platform_driver __refdata = { 493 493 .driver = { 494 494 .name = DRV_NAME, 495 - .pm = &sh_rtc_pm_ops, 495 + .pm = pm_sleep_ptr(&sh_rtc_pm_ops), 496 496 .of_match_table = sh_rtc_of_match, 497 497 }, 498 498 .remove = __exit_p(sh_rtc_remove),
+30 -34
drivers/rtc/sysfs.c
··· 24 24 static ssize_t 25 25 name_show(struct device *dev, struct device_attribute *attr, char *buf) 26 26 { 27 - return sprintf(buf, "%s %s\n", dev_driver_string(dev->parent), 28 - dev_name(dev->parent)); 27 + return sysfs_emit(buf, "%s %s\n", dev_driver_string(dev->parent), 28 + dev_name(dev->parent)); 29 29 } 30 30 static DEVICE_ATTR_RO(name); 31 31 ··· 39 39 if (retval) 40 40 return retval; 41 41 42 - return sprintf(buf, "%ptRd\n", &tm); 42 + return sysfs_emit(buf, "%ptRd\n", &tm); 43 43 } 44 44 static DEVICE_ATTR_RO(date); 45 45 ··· 53 53 if (retval) 54 54 return retval; 55 55 56 - return sprintf(buf, "%ptRt\n", &tm); 56 + return sysfs_emit(buf, "%ptRt\n", &tm); 57 57 } 58 58 static DEVICE_ATTR_RO(time); 59 59 ··· 64 64 struct rtc_time tm; 65 65 66 66 retval = rtc_read_time(to_rtc_device(dev), &tm); 67 - if (retval == 0) { 68 - time64_t time; 67 + if (retval) 68 + return retval; 69 69 70 - time = rtc_tm_to_time64(&tm); 71 - retval = sprintf(buf, "%lld\n", time); 72 - } 73 - 74 - return retval; 70 + return sysfs_emit(buf, "%lld\n", rtc_tm_to_time64(&tm)); 75 71 } 76 72 static DEVICE_ATTR_RO(since_epoch); 77 73 78 74 static ssize_t 79 75 max_user_freq_show(struct device *dev, struct device_attribute *attr, char *buf) 80 76 { 81 - return sprintf(buf, "%d\n", to_rtc_device(dev)->max_user_freq); 77 + return sysfs_emit(buf, "%d\n", to_rtc_device(dev)->max_user_freq); 82 78 } 83 79 84 80 static ssize_t ··· 114 118 if (rtc_hctosys_ret == 0 && 115 119 strcmp(dev_name(&to_rtc_device(dev)->dev), 116 120 CONFIG_RTC_HCTOSYS_DEVICE) == 0) 117 - return sprintf(buf, "1\n"); 121 + return sysfs_emit(buf, "1\n"); 118 122 #endif 119 - return sprintf(buf, "0\n"); 123 + return sysfs_emit(buf, "0\n"); 120 124 } 121 125 static DEVICE_ATTR_RO(hctosys); 122 126 ··· 124 128 wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf) 125 129 { 126 130 ssize_t retval; 127 - time64_t alarm; 128 131 struct rtc_wkalrm alm; 129 132 130 133 /* Don't show disabled alarms. For uniformity, RTC alarms are ··· 135 140 * alarms after they trigger, to ensure one-shot semantics. 136 141 */ 137 142 retval = rtc_read_alarm(to_rtc_device(dev), &alm); 138 - if (retval == 0 && alm.enabled) { 139 - alarm = rtc_tm_to_time64(&alm.time); 140 - retval = sprintf(buf, "%lld\n", alarm); 141 - } 143 + if (retval) 144 + return retval; 142 145 143 - return retval; 146 + if (alm.enabled) 147 + return sysfs_emit(buf, "%lld\n", rtc_tm_to_time64(&alm.time)); 148 + 149 + return 0; 144 150 } 145 151 146 152 static ssize_t ··· 218 222 long offset; 219 223 220 224 retval = rtc_read_offset(to_rtc_device(dev), &offset); 221 - if (retval == 0) 222 - retval = sprintf(buf, "%ld\n", offset); 225 + if (retval) 226 + return retval; 223 227 224 - return retval; 228 + return sysfs_emit(buf, "%ld\n", offset); 225 229 } 226 230 227 231 static ssize_t ··· 242 246 static ssize_t 243 247 range_show(struct device *dev, struct device_attribute *attr, char *buf) 244 248 { 245 - return sprintf(buf, "[%lld,%llu]\n", to_rtc_device(dev)->range_min, 246 - to_rtc_device(dev)->range_max); 249 + return sysfs_emit(buf, "[%lld,%llu]\n", to_rtc_device(dev)->range_min, 250 + to_rtc_device(dev)->range_max); 247 251 } 248 252 static DEVICE_ATTR_RO(range); 249 253 ··· 298 302 .is_visible = rtc_attr_is_visible, 299 303 .attrs = rtc_attrs, 300 304 }; 301 - 302 - static const struct attribute_group *rtc_attr_groups[] = { 303 - &rtc_attr_group, 304 - NULL 305 - }; 305 + __ATTRIBUTE_GROUPS(rtc_attr); 306 306 307 307 const struct attribute_group **rtc_get_dev_attribute_groups(void) 308 308 { ··· 310 318 size_t old_cnt = 0, add_cnt = 0, new_cnt; 311 319 const struct attribute_group **groups, **old; 312 320 313 - if (!grps) 321 + if (grps) { 322 + for (groups = grps; *groups; groups++) 323 + add_cnt++; 324 + /* No need to modify current groups if nothing new is provided */ 325 + if (add_cnt == 0) 326 + return 0; 327 + } else { 314 328 return -EINVAL; 329 + } 315 330 316 331 groups = rtc->dev.groups; 317 332 if (groups) 318 333 for (; *groups; groups++) 319 334 old_cnt++; 320 - 321 - for (groups = grps; *groups; groups++) 322 - add_cnt++; 323 335 324 336 new_cnt = old_cnt + add_cnt + 1; 325 337 groups = devm_kcalloc(&rtc->dev, new_cnt, sizeof(*groups), GFP_KERNEL);
+1 -1
include/linux/rtc/ds1685.h
··· 8 8 * include larger, battery-backed NV-SRAM, burst-mode access, and an RTC 9 9 * write counter. 10 10 * 11 - * Copyright (C) 2011-2014 Joshua Kinard <kumba@gentoo.org>. 11 + * Copyright (C) 2011-2014 Joshua Kinard <linux@kumba.dev>. 12 12 * Copyright (C) 2009 Matthias Fuchs <matthias.fuchs@esd-electronics.com>. 13 13 * 14 14 * References: