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

Merge tag 'rtc-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux

Pull RTC updates from Alexandre Belloni:
"More conversions of DT bindings to yaml. There is one new driver, for
the DFRobot SD2405AL and support for important features of the stm32
RTC. Summary:

New driver:
- DFRobot SD2405AL

Drivers:
- stm32: add alarm A out and LSCO support
- sun6i: disable automatic clock input switching
- m48t59: set range"

* tag 'rtc-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux:
rtc: rc5t619: use proper module tables
rtc: m48t59: set range
dt-bindings: rtc: microcrystal,rv3028: add #clock-cells property
rtc: m48t59: Remove division condition with direct comparison
rtc: at91sam9: fix OF node leak in probe() error path
rtc: sun6i: disable automatic clock input switching
dt-bindings: rtc: Drop non-trivial duplicate compatibles
dt-bindings: vendor-prefixes: Add DFRobot.
dt-bindings: rtc: Add support for SD2405AL.
rtc: Add driver for SD2405AL
rtc: s35390a: Drop vendorless compatible string from match table
rtc: twl: convert comma to semicolon
dt-bindings: rtc: sprd,sc2731-rtc: convert to YAML
rtc: stm32: add alarm A out feature
rtc: stm32: add Low Speed Clock Output (LSCO) support
rtc: stm32: add pinctrl and pinmux interfaces
dt-bindings: rtc: stm32: describe pinmux nodes

+633 -39
+3
Documentation/devicetree/bindings/rtc/microcrystal,rv3028.yaml
··· 22 22 interrupts: 23 23 maxItems: 1 24 24 25 + "#clock-cells": 26 + const: 0 27 + 25 28 trickle-resistor-ohms: 26 29 enum: 27 30 - 3000
+49
Documentation/devicetree/bindings/rtc/sprd,sc2731-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/sprd,sc2731-rtc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Spreadtrum SC2731 Real Time Clock 8 + 9 + maintainers: 10 + - Orson Zhai <orsonzhai@gmail.com> 11 + - Baolin Wang <baolin.wang7@gmail.com> 12 + - Chunyan Zhang <zhang.lyra@gmail.com> 13 + 14 + properties: 15 + compatible: 16 + const: sprd,sc2731-rtc 17 + 18 + reg: 19 + maxItems: 1 20 + 21 + interrupts: 22 + maxItems: 1 23 + 24 + required: 25 + - compatible 26 + - reg 27 + - interrupts 28 + 29 + allOf: 30 + - $ref: rtc.yaml# 31 + 32 + unevaluatedProperties: false 33 + 34 + examples: 35 + - | 36 + #include <dt-bindings/interrupt-controller/irq.h> 37 + 38 + pmic { 39 + #address-cells = <1>; 40 + #size-cells = <0>; 41 + 42 + rtc@280 { 43 + compatible = "sprd,sc2731-rtc"; 44 + reg = <0x280>; 45 + interrupt-parent = <&sc2731_pmic>; 46 + interrupts = <2 IRQ_TYPE_LEVEL_HIGH>; 47 + }; 48 + }; 49 + ...
-26
Documentation/devicetree/bindings/rtc/sprd,sc27xx-rtc.txt
··· 1 - Spreadtrum SC27xx Real Time Clock 2 - 3 - Required properties: 4 - - compatible: should be "sprd,sc2731-rtc". 5 - - reg: address offset of rtc register. 6 - - interrupts: rtc alarm interrupt. 7 - 8 - Example: 9 - 10 - sc2731_pmic: pmic@0 { 11 - compatible = "sprd,sc2731"; 12 - reg = <0>; 13 - spi-max-frequency = <26000000>; 14 - interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>; 15 - interrupt-controller; 16 - #interrupt-cells = <2>; 17 - #address-cells = <1>; 18 - #size-cells = <0>; 19 - 20 - rtc@280 { 21 - compatible = "sprd,sc2731-rtc"; 22 - reg = <0x280>; 23 - interrupt-parent = <&sc2731_pmic>; 24 - interrupts = <2 IRQ_TYPE_LEVEL_HIGH>; 25 - }; 26 - };
+28
Documentation/devicetree/bindings/rtc/st,stm32-rtc.yaml
··· 53 53 override default rtc_ck parent clock phandle of the new parent clock of rtc_ck 54 54 maxItems: 1 55 55 56 + patternProperties: 57 + "^rtc-[a-z]+-[0-9]+$": 58 + type: object 59 + $ref: /schemas/pinctrl/pinmux-node.yaml 60 + description: | 61 + Configuration of STM32 RTC pins description. STM32 RTC is able to output 62 + some signals on specific pins: 63 + - LSCO (Low Speed Clock Output) that allow to output LSE clock on a pin. 64 + - Alarm out that allow to send a pulse on a pin when alarm A of the RTC 65 + expires. 66 + additionalProperties: false 67 + properties: 68 + function: 69 + enum: 70 + - lsco 71 + - alarm-a 72 + pins: 73 + enum: 74 + - out1 75 + - out2 76 + - out2_rmp 77 + 56 78 allOf: 57 79 - if: 58 80 properties: ··· 90 68 91 69 clock-names: false 92 70 71 + patternProperties: 72 + "^rtc-[a-z]+-[0-9]+$": false 73 + 93 74 required: 94 75 - st,syscfg 95 76 ··· 107 82 clocks: 108 83 minItems: 2 109 84 maxItems: 2 85 + 86 + patternProperties: 87 + "^rtc-[a-z]+-[0-9]+$": false 110 88 111 89 required: 112 90 - clock-names
+2 -7
Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
··· 38 38 - dallas,ds1672 39 39 # Extremely Accurate I²C RTC with Integrated Crystal and SRAM 40 40 - dallas,ds3232 41 + # SD2405AL Real-Time Clock 42 + - dfrobot,sd2405al 41 43 # EM Microelectronic EM3027 RTC 42 44 - emmicro,em3027 43 45 # I2C-BUS INTERFACE REAL TIME CLOCK MODULE 44 46 - epson,rx8010 45 47 # I2C-BUS INTERFACE REAL TIME CLOCK MODULE 46 - - epson,rx8025 47 48 - epson,rx8035 48 49 # I2C-BUS INTERFACE REAL TIME CLOCK MODULE with Battery Backed RAM 49 50 - epson,rx8111 ··· 53 52 - epson,rx8581 54 53 # Android Goldfish Real-time Clock 55 54 - google,goldfish-rtc 56 - # Intersil ISL1208 Low Power RTC with Battery Backed SRAM 57 - - isil,isl1208 58 - # Intersil ISL1218 Low Power RTC with Battery Backed SRAM 59 - - isil,isl1218 60 55 # Mvebu Real-time Clock 61 56 - marvell,orion-rtc 62 57 # Maxim DS1742/DS1743 Real-time Clock ··· 65 68 - microcrystal,rv8523 66 69 # NXP LPC32xx SoC Real-time Clock 67 70 - nxp,lpc3220-rtc 68 - # Real-time Clock Module 69 - - pericom,pt7c4338 70 71 # I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC 71 72 - ricoh,r2025sd 72 73 # I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
+2
Documentation/devicetree/bindings/vendor-prefixes.yaml
··· 368 368 description: Devantech, Ltd. 369 369 "^dfi,.*": 370 370 description: DFI Inc. 371 + "^dfrobot,.*": 372 + description: DFRobot Corporation 371 373 "^dh,.*": 372 374 description: DH electronics GmbH 373 375 "^difrnce,.*":
+6
MAINTAINERS
··· 6557 6557 F: include/uapi/linux/devlink.h 6558 6558 F: net/devlink/ 6559 6559 6560 + DFROBOT SD2405AL RTC DRIVER 6561 + M: Tóth János <gomba007@gmail.com> 6562 + L: linux-rtc@vger.kernel.org 6563 + S: Maintained 6564 + F: drivers/rtc/rtc-sd2405al.c 6565 + 6560 6566 DH ELECTRONICS IMX6 DHCOM/DHCOR BOARD SUPPORT 6561 6567 M: Christoph Niedermaier <cniedermaier@dh-electronics.com> 6562 6568 L: kernel@dh-electronics.com
+16
drivers/rtc/Kconfig
··· 743 743 This driver can also be built as a module. If so, the module 744 744 will be called rtc-s5m. 745 745 746 + config RTC_DRV_SD2405AL 747 + tristate "DFRobot SD2405AL" 748 + select REGMAP_I2C 749 + help 750 + If you say yes here you will get support for the 751 + DFRobot SD2405AL I2C RTC Module. 752 + 753 + This driver can also be built as a module. If so, the module 754 + will be called rtc-sd2405al. 755 + 746 756 config RTC_DRV_SD3078 747 757 tristate "ZXW Shenzhen whwave SD3078" 748 758 select REGMAP_I2C ··· 1944 1934 tristate "STM32 RTC" 1945 1935 select REGMAP_MMIO 1946 1936 depends on ARCH_STM32 || COMPILE_TEST 1937 + depends on OF 1938 + depends on PINCTRL 1939 + select PINMUX 1940 + select PINCONF 1941 + select GENERIC_PINCONF 1942 + depends on COMMON_CLK 1947 1943 help 1948 1944 If you say yes here you get support for the STM32 On-Chip 1949 1945 Real Time Clock.
+1
drivers/rtc/Makefile
··· 163 163 obj-$(CONFIG_RTC_DRV_S5M) += rtc-s5m.o 164 164 obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o 165 165 obj-$(CONFIG_RTC_DRV_SC27XX) += rtc-sc27xx.o 166 + obj-$(CONFIG_RTC_DRV_SD2405AL) += rtc-sd2405al.o 166 167 obj-$(CONFIG_RTC_DRV_SD3078) += rtc-sd3078.o 167 168 obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o 168 169 obj-$(CONFIG_RTC_DRV_SNVS) += rtc-snvs.o
+1
drivers/rtc/rtc-at91sam9.c
··· 368 368 return ret; 369 369 370 370 rtc->gpbr = syscon_node_to_regmap(args.np); 371 + of_node_put(args.np); 371 372 rtc->gpbr_offset = args.args[0]; 372 373 if (IS_ERR(rtc->gpbr)) { 373 374 dev_err(&pdev->dev, "failed to retrieve gpbr regmap, aborting.\n");
+3 -1
drivers/rtc/rtc-m48t59.c
··· 132 132 M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); 133 133 M48T59_WRITE(bin2bcd(year % 100), M48T59_YEAR); 134 134 135 - if (pdata->type == M48T59RTC_TYPE_M48T59 && (year / 100)) 135 + if (pdata->type == M48T59RTC_TYPE_M48T59 && (year >= 100)) 136 136 val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); 137 137 val |= (bin2bcd(tm->tm_wday) & 0x07); 138 138 M48T59_WRITE(val, M48T59_WDAY); ··· 458 458 platform_set_drvdata(pdev, m48t59); 459 459 460 460 m48t59->rtc->ops = &m48t59_rtc_ops; 461 + m48t59->rtc->range_min = RTC_TIMESTAMP_BEGIN_1900; 462 + m48t59->rtc->range_max = RTC_TIMESTAMP_END_2099; 461 463 462 464 nvmem_cfg.size = pdata->offset; 463 465 ret = devm_rtc_nvmem_register(m48t59->rtc, &nvmem_cfg);
+11 -2
drivers/rtc/rtc-rc5t619.c
··· 429 429 return devm_rtc_register_device(rtc->rtc); 430 430 } 431 431 432 + static const struct platform_device_id rc5t619_rtc_id[] = { 433 + { 434 + .name = "rc5t619-rtc", 435 + }, { 436 + /* sentinel */ 437 + } 438 + }; 439 + MODULE_DEVICE_TABLE(platform, rc5t619_rtc_id); 440 + 432 441 static struct platform_driver rc5t619_rtc_driver = { 433 442 .driver = { 434 443 .name = "rc5t619-rtc", 435 444 }, 436 445 .probe = rc5t619_rtc_probe, 446 + .id_table = rc5t619_rtc_id, 437 447 }; 438 - 439 448 module_platform_driver(rc5t619_rtc_driver); 440 - MODULE_ALIAS("platform:rc5t619-rtc"); 449 + 441 450 MODULE_DESCRIPTION("RICOH RC5T619 RTC driver"); 442 451 MODULE_LICENSE("GPL");
-1
drivers/rtc/rtc-s35390a.c
··· 56 56 MODULE_DEVICE_TABLE(i2c, s35390a_id); 57 57 58 58 static const __maybe_unused struct of_device_id s35390a_of_match[] = { 59 - { .compatible = "s35390a" }, 60 59 { .compatible = "sii,s35390a" }, 61 60 { } 62 61 };
+227
drivers/rtc/rtc-sd2405al.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * RTC driver for the SD2405AL Real-Time Clock 4 + * 5 + * Datasheet: 6 + * https://image.dfrobot.com/image/data/TOY0021/SD2405AL%20datasheet%20(Angelo%20v0.1).pdf 7 + * 8 + * Copyright (C) 2024 Tóth János <gomba007@gmail.com> 9 + */ 10 + 11 + #include <linux/bcd.h> 12 + #include <linux/i2c.h> 13 + #include <linux/regmap.h> 14 + #include <linux/rtc.h> 15 + 16 + /* Real time clock registers */ 17 + #define SD2405AL_REG_T_SEC 0x00 18 + #define SD2405AL_REG_T_MIN 0x01 19 + #define SD2405AL_REG_T_HOUR 0x02 20 + # define SD2405AL_BIT_12H_PM BIT(5) 21 + # define SD2405AL_BIT_24H BIT(7) 22 + #define SD2405AL_REG_T_WEEK 0x03 23 + #define SD2405AL_REG_T_DAY 0x04 24 + #define SD2405AL_REG_T_MON 0x05 25 + #define SD2405AL_REG_T_YEAR 0x06 26 + 27 + #define SD2405AL_NUM_T_REGS (SD2405AL_REG_T_YEAR - SD2405AL_REG_T_SEC + 1) 28 + 29 + /* Control registers */ 30 + #define SD2405AL_REG_CTR1 0x0F 31 + # define SD2405AL_BIT_WRTC2 BIT(2) 32 + # define SD2405AL_BIT_WRTC3 BIT(7) 33 + #define SD2405AL_REG_CTR2 0x10 34 + # define SD2405AL_BIT_WRTC1 BIT(7) 35 + #define SD2405AL_REG_CTR3 0x11 36 + #define SD2405AL_REG_TTF 0x12 37 + #define SD2405AL_REG_CNTDWN 0x13 38 + 39 + /* General RAM */ 40 + #define SD2405AL_REG_M_START 0x14 41 + #define SD2405AL_REG_M_END 0x1F 42 + 43 + struct sd2405al { 44 + struct device *dev; 45 + struct rtc_device *rtc; 46 + struct regmap *regmap; 47 + }; 48 + 49 + static int sd2405al_enable_reg_write(struct sd2405al *sd2405al) 50 + { 51 + int ret; 52 + 53 + /* order of writes is important */ 54 + ret = regmap_update_bits(sd2405al->regmap, SD2405AL_REG_CTR2, 55 + SD2405AL_BIT_WRTC1, SD2405AL_BIT_WRTC1); 56 + if (ret < 0) 57 + return ret; 58 + 59 + ret = regmap_update_bits(sd2405al->regmap, SD2405AL_REG_CTR1, 60 + SD2405AL_BIT_WRTC2 | SD2405AL_BIT_WRTC3, 61 + SD2405AL_BIT_WRTC2 | SD2405AL_BIT_WRTC3); 62 + if (ret < 0) 63 + return ret; 64 + 65 + return 0; 66 + } 67 + 68 + static int sd2405al_disable_reg_write(struct sd2405al *sd2405al) 69 + { 70 + int ret; 71 + 72 + /* order of writes is important */ 73 + ret = regmap_update_bits(sd2405al->regmap, SD2405AL_REG_CTR1, 74 + SD2405AL_BIT_WRTC2 | SD2405AL_BIT_WRTC3, 0x00); 75 + if (ret < 0) 76 + return ret; 77 + 78 + ret = regmap_update_bits(sd2405al->regmap, SD2405AL_REG_CTR2, 79 + SD2405AL_BIT_WRTC1, 0x00); 80 + if (ret < 0) 81 + return ret; 82 + 83 + return 0; 84 + } 85 + 86 + static int sd2405al_read_time(struct device *dev, struct rtc_time *time) 87 + { 88 + u8 data[SD2405AL_NUM_T_REGS] = { 0 }; 89 + struct sd2405al *sd2405al = dev_get_drvdata(dev); 90 + int ret; 91 + 92 + ret = regmap_bulk_read(sd2405al->regmap, SD2405AL_REG_T_SEC, data, 93 + SD2405AL_NUM_T_REGS); 94 + if (ret < 0) 95 + return ret; 96 + 97 + time->tm_sec = bcd2bin(data[SD2405AL_REG_T_SEC] & 0x7F); 98 + time->tm_min = bcd2bin(data[SD2405AL_REG_T_MIN] & 0x7F); 99 + 100 + if (data[SD2405AL_REG_T_HOUR] & SD2405AL_BIT_24H) 101 + time->tm_hour = bcd2bin(data[SD2405AL_REG_T_HOUR] & 0x3F); 102 + else 103 + if (data[SD2405AL_REG_T_HOUR] & SD2405AL_BIT_12H_PM) 104 + time->tm_hour = bcd2bin(data[SD2405AL_REG_T_HOUR] 105 + & 0x1F) + 12; 106 + else /* 12 hour mode, AM */ 107 + time->tm_hour = bcd2bin(data[SD2405AL_REG_T_HOUR] 108 + & 0x1F); 109 + 110 + time->tm_wday = bcd2bin(data[SD2405AL_REG_T_WEEK] & 0x07); 111 + time->tm_mday = bcd2bin(data[SD2405AL_REG_T_DAY] & 0x3F); 112 + time->tm_mon = bcd2bin(data[SD2405AL_REG_T_MON] & 0x1F) - 1; 113 + time->tm_year = bcd2bin(data[SD2405AL_REG_T_YEAR]) + 100; 114 + 115 + dev_dbg(sd2405al->dev, "read time: %ptR (%d)\n", time, time->tm_wday); 116 + 117 + return 0; 118 + } 119 + 120 + static int sd2405al_set_time(struct device *dev, struct rtc_time *time) 121 + { 122 + u8 data[SD2405AL_NUM_T_REGS]; 123 + struct sd2405al *sd2405al = dev_get_drvdata(dev); 124 + int ret; 125 + 126 + data[SD2405AL_REG_T_SEC] = bin2bcd(time->tm_sec); 127 + data[SD2405AL_REG_T_MIN] = bin2bcd(time->tm_min); 128 + data[SD2405AL_REG_T_HOUR] = bin2bcd(time->tm_hour) | SD2405AL_BIT_24H; 129 + data[SD2405AL_REG_T_DAY] = bin2bcd(time->tm_mday); 130 + data[SD2405AL_REG_T_WEEK] = bin2bcd(time->tm_wday); 131 + data[SD2405AL_REG_T_MON] = bin2bcd(time->tm_mon) + 1; 132 + data[SD2405AL_REG_T_YEAR] = bin2bcd(time->tm_year - 100); 133 + 134 + ret = sd2405al_enable_reg_write(sd2405al); 135 + if (ret < 0) 136 + return ret; 137 + 138 + ret = regmap_bulk_write(sd2405al->regmap, SD2405AL_REG_T_SEC, data, 139 + SD2405AL_NUM_T_REGS); 140 + if (ret < 0) 141 + return ret; 142 + 143 + ret = regmap_write(sd2405al->regmap, SD2405AL_REG_TTF, 0x00); 144 + if (ret < 0) 145 + return ret; 146 + 147 + ret = sd2405al_disable_reg_write(sd2405al); 148 + if (ret < 0) 149 + return ret; 150 + 151 + dev_dbg(sd2405al->dev, "set time: %ptR (%d)\n", time, time->tm_wday); 152 + 153 + return 0; 154 + } 155 + 156 + static const struct rtc_class_ops sd2405al_rtc_ops = { 157 + .read_time = sd2405al_read_time, 158 + .set_time = sd2405al_set_time, 159 + }; 160 + 161 + static const struct regmap_config sd2405al_regmap_conf = { 162 + .reg_bits = 8, 163 + .val_bits = 8, 164 + .max_register = SD2405AL_REG_M_END, 165 + }; 166 + 167 + static int sd2405al_probe(struct i2c_client *client) 168 + { 169 + struct sd2405al *sd2405al; 170 + int ret; 171 + 172 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 173 + return -ENODEV; 174 + 175 + sd2405al = devm_kzalloc(&client->dev, sizeof(*sd2405al), GFP_KERNEL); 176 + if (!sd2405al) 177 + return -ENOMEM; 178 + 179 + sd2405al->dev = &client->dev; 180 + 181 + sd2405al->regmap = devm_regmap_init_i2c(client, &sd2405al_regmap_conf); 182 + if (IS_ERR(sd2405al->regmap)) 183 + return PTR_ERR(sd2405al->regmap); 184 + 185 + sd2405al->rtc = devm_rtc_allocate_device(&client->dev); 186 + if (IS_ERR(sd2405al->rtc)) 187 + return PTR_ERR(sd2405al->rtc); 188 + 189 + sd2405al->rtc->ops = &sd2405al_rtc_ops; 190 + sd2405al->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 191 + sd2405al->rtc->range_max = RTC_TIMESTAMP_END_2099; 192 + 193 + dev_set_drvdata(&client->dev, sd2405al); 194 + 195 + ret = devm_rtc_register_device(sd2405al->rtc); 196 + if (ret < 0) 197 + return ret; 198 + 199 + return 0; 200 + } 201 + 202 + static const struct i2c_device_id sd2405al_id[] = { 203 + { "sd2405al" }, 204 + { /* sentinel */ } 205 + }; 206 + MODULE_DEVICE_TABLE(i2c, sd2405al_id); 207 + 208 + static const __maybe_unused struct of_device_id sd2405al_of_match[] = { 209 + { .compatible = "dfrobot,sd2405al" }, 210 + { /* sentinel */ } 211 + }; 212 + MODULE_DEVICE_TABLE(of, sd2405al_of_match); 213 + 214 + static struct i2c_driver sd2405al_driver = { 215 + .driver = { 216 + .name = "sd2405al", 217 + .of_match_table = of_match_ptr(sd2405al_of_match), 218 + }, 219 + .probe = sd2405al_probe, 220 + .id_table = sd2405al_id, 221 + }; 222 + 223 + module_i2c_driver(sd2405al_driver); 224 + 225 + MODULE_AUTHOR("Tóth János <gomba007@gmail.com>"); 226 + MODULE_LICENSE("GPL"); 227 + MODULE_DESCRIPTION("SD2405AL RTC driver");
+281
drivers/rtc/rtc-stm32.c
··· 7 7 #include <linux/bcd.h> 8 8 #include <linux/bitfield.h> 9 9 #include <linux/clk.h> 10 + #include <linux/clk-provider.h> 10 11 #include <linux/errno.h> 11 12 #include <linux/iopoll.h> 12 13 #include <linux/ioport.h> 13 14 #include <linux/mfd/syscon.h> 14 15 #include <linux/module.h> 15 16 #include <linux/of.h> 17 + #include <linux/pinctrl/pinctrl.h> 18 + #include <linux/pinctrl/pinconf-generic.h> 19 + #include <linux/pinctrl/pinmux.h> 16 20 #include <linux/platform_device.h> 17 21 #include <linux/pm_wakeirq.h> 18 22 #include <linux/regmap.h> ··· 46 42 #define STM32_RTC_CR_FMT BIT(6) 47 43 #define STM32_RTC_CR_ALRAE BIT(8) 48 44 #define STM32_RTC_CR_ALRAIE BIT(12) 45 + #define STM32_RTC_CR_OSEL GENMASK(22, 21) 46 + #define STM32_RTC_CR_OSEL_ALARM_A FIELD_PREP(STM32_RTC_CR_OSEL, 0x01) 47 + #define STM32_RTC_CR_COE BIT(23) 48 + #define STM32_RTC_CR_TAMPOE BIT(26) 49 + #define STM32_RTC_CR_TAMPALRM_TYPE BIT(30) 50 + #define STM32_RTC_CR_OUT2EN BIT(31) 49 51 50 52 /* STM32_RTC_ISR/STM32_RTC_ICSR bit fields */ 51 53 #define STM32_RTC_ISR_ALRAWF BIT(0) ··· 88 78 /* STM32_RTC_SR/_SCR bit fields */ 89 79 #define STM32_RTC_SR_ALRA BIT(0) 90 80 81 + /* STM32_RTC_CFGR bit fields */ 82 + #define STM32_RTC_CFGR_OUT2_RMP BIT(0) 83 + #define STM32_RTC_CFGR_LSCOEN GENMASK(2, 1) 84 + #define STM32_RTC_CFGR_LSCOEN_OUT1 1 85 + #define STM32_RTC_CFGR_LSCOEN_OUT2_RMP 2 86 + 91 87 /* STM32_RTC_VERR bit fields */ 92 88 #define STM32_RTC_VERR_MINREV_SHIFT 0 93 89 #define STM32_RTC_VERR_MINREV GENMASK(3, 0) ··· 123 107 /* STM32 RTC driver time helpers */ 124 108 #define SEC_PER_DAY (24 * 60 * 60) 125 109 110 + /* STM32 RTC pinctrl helpers */ 111 + #define STM32_RTC_PINMUX(_name, _action, ...) { \ 112 + .name = (_name), \ 113 + .action = (_action), \ 114 + .groups = ((const char *[]){ __VA_ARGS__ }), \ 115 + .num_groups = ARRAY_SIZE(((const char *[]){ __VA_ARGS__ })), \ 116 + } 117 + 126 118 struct stm32_rtc; 127 119 128 120 struct stm32_rtc_registers { ··· 143 119 u16 wpr; 144 120 u16 sr; 145 121 u16 scr; 122 + u16 cfgr; 146 123 u16 verr; 147 124 }; 148 125 ··· 159 134 bool need_dbp; 160 135 bool need_accuracy; 161 136 bool rif_protected; 137 + bool has_lsco; 138 + bool has_alarm_out; 162 139 }; 163 140 164 141 struct stm32_rtc { ··· 173 146 struct clk *rtc_ck; 174 147 const struct stm32_rtc_data *data; 175 148 int irq_alarm; 149 + struct clk *clk_lsco; 176 150 }; 177 151 178 152 struct stm32_rtc_rif_resource { ··· 198 170 199 171 writel_relaxed(RTC_WPR_WRONG_KEY, rtc->base + regs->wpr); 200 172 } 173 + 174 + enum stm32_rtc_pin_name { 175 + NONE, 176 + OUT1, 177 + OUT2, 178 + OUT2_RMP 179 + }; 180 + 181 + static const struct pinctrl_pin_desc stm32_rtc_pinctrl_pins[] = { 182 + PINCTRL_PIN(OUT1, "out1"), 183 + PINCTRL_PIN(OUT2, "out2"), 184 + PINCTRL_PIN(OUT2_RMP, "out2_rmp"), 185 + }; 186 + 187 + static int stm32_rtc_pinctrl_get_groups_count(struct pinctrl_dev *pctldev) 188 + { 189 + return ARRAY_SIZE(stm32_rtc_pinctrl_pins); 190 + } 191 + 192 + static const char *stm32_rtc_pinctrl_get_group_name(struct pinctrl_dev *pctldev, 193 + unsigned int selector) 194 + { 195 + return stm32_rtc_pinctrl_pins[selector].name; 196 + } 197 + 198 + static int stm32_rtc_pinctrl_get_group_pins(struct pinctrl_dev *pctldev, 199 + unsigned int selector, 200 + const unsigned int **pins, 201 + unsigned int *num_pins) 202 + { 203 + *pins = &stm32_rtc_pinctrl_pins[selector].number; 204 + *num_pins = 1; 205 + return 0; 206 + } 207 + 208 + static const struct pinctrl_ops stm32_rtc_pinctrl_ops = { 209 + .dt_node_to_map = pinconf_generic_dt_node_to_map_all, 210 + .dt_free_map = pinconf_generic_dt_free_map, 211 + .get_groups_count = stm32_rtc_pinctrl_get_groups_count, 212 + .get_group_name = stm32_rtc_pinctrl_get_group_name, 213 + .get_group_pins = stm32_rtc_pinctrl_get_group_pins, 214 + }; 215 + 216 + struct stm32_rtc_pinmux_func { 217 + const char *name; 218 + const char * const *groups; 219 + const unsigned int num_groups; 220 + int (*action)(struct pinctrl_dev *pctl_dev, unsigned int pin); 221 + }; 222 + 223 + static int stm32_rtc_pinmux_action_alarm(struct pinctrl_dev *pctldev, unsigned int pin) 224 + { 225 + struct stm32_rtc *rtc = pinctrl_dev_get_drvdata(pctldev); 226 + struct stm32_rtc_registers regs = rtc->data->regs; 227 + unsigned int cr = readl_relaxed(rtc->base + regs.cr); 228 + unsigned int cfgr = readl_relaxed(rtc->base + regs.cfgr); 229 + 230 + if (!rtc->data->has_alarm_out) 231 + return -EPERM; 232 + 233 + cr &= ~STM32_RTC_CR_OSEL; 234 + cr |= STM32_RTC_CR_OSEL_ALARM_A; 235 + cr &= ~STM32_RTC_CR_TAMPOE; 236 + cr &= ~STM32_RTC_CR_COE; 237 + cr &= ~STM32_RTC_CR_TAMPALRM_TYPE; 238 + 239 + switch (pin) { 240 + case OUT1: 241 + cr &= ~STM32_RTC_CR_OUT2EN; 242 + cfgr &= ~STM32_RTC_CFGR_OUT2_RMP; 243 + break; 244 + case OUT2: 245 + cr |= STM32_RTC_CR_OUT2EN; 246 + cfgr &= ~STM32_RTC_CFGR_OUT2_RMP; 247 + break; 248 + case OUT2_RMP: 249 + cr |= STM32_RTC_CR_OUT2EN; 250 + cfgr |= STM32_RTC_CFGR_OUT2_RMP; 251 + break; 252 + default: 253 + return -EINVAL; 254 + } 255 + 256 + stm32_rtc_wpr_unlock(rtc); 257 + writel_relaxed(cr, rtc->base + regs.cr); 258 + writel_relaxed(cfgr, rtc->base + regs.cfgr); 259 + stm32_rtc_wpr_lock(rtc); 260 + 261 + return 0; 262 + } 263 + 264 + static int stm32_rtc_pinmux_lsco_available(struct pinctrl_dev *pctldev, unsigned int pin) 265 + { 266 + struct stm32_rtc *rtc = pinctrl_dev_get_drvdata(pctldev); 267 + struct stm32_rtc_registers regs = rtc->data->regs; 268 + unsigned int cr = readl_relaxed(rtc->base + regs.cr); 269 + unsigned int cfgr = readl_relaxed(rtc->base + regs.cfgr); 270 + unsigned int calib = STM32_RTC_CR_COE; 271 + unsigned int tampalrm = STM32_RTC_CR_TAMPOE | STM32_RTC_CR_OSEL; 272 + 273 + switch (pin) { 274 + case OUT1: 275 + if ((!(cr & STM32_RTC_CR_OUT2EN) && 276 + ((cr & calib) || cr & tampalrm)) || 277 + ((cr & calib) && (cr & tampalrm))) 278 + return -EBUSY; 279 + break; 280 + case OUT2_RMP: 281 + if ((cr & STM32_RTC_CR_OUT2EN) && 282 + (cfgr & STM32_RTC_CFGR_OUT2_RMP) && 283 + ((cr & calib) || (cr & tampalrm))) 284 + return -EBUSY; 285 + break; 286 + default: 287 + return -EINVAL; 288 + } 289 + 290 + if (clk_get_rate(rtc->rtc_ck) != 32768) 291 + return -ERANGE; 292 + 293 + return 0; 294 + } 295 + 296 + static int stm32_rtc_pinmux_action_lsco(struct pinctrl_dev *pctldev, unsigned int pin) 297 + { 298 + struct stm32_rtc *rtc = pinctrl_dev_get_drvdata(pctldev); 299 + struct stm32_rtc_registers regs = rtc->data->regs; 300 + struct device *dev = rtc->rtc_dev->dev.parent; 301 + u8 lscoen; 302 + int ret; 303 + 304 + if (!rtc->data->has_lsco) 305 + return -EPERM; 306 + 307 + ret = stm32_rtc_pinmux_lsco_available(pctldev, pin); 308 + if (ret) 309 + return ret; 310 + 311 + lscoen = (pin == OUT1) ? STM32_RTC_CFGR_LSCOEN_OUT1 : STM32_RTC_CFGR_LSCOEN_OUT2_RMP; 312 + 313 + rtc->clk_lsco = clk_register_gate(dev, "rtc_lsco", __clk_get_name(rtc->rtc_ck), 314 + CLK_IGNORE_UNUSED | CLK_IS_CRITICAL, 315 + rtc->base + regs.cfgr, lscoen, 0, NULL); 316 + if (IS_ERR(rtc->clk_lsco)) 317 + return PTR_ERR(rtc->clk_lsco); 318 + 319 + of_clk_add_provider(dev->of_node, of_clk_src_simple_get, rtc->clk_lsco); 320 + 321 + return 0; 322 + } 323 + 324 + static const struct stm32_rtc_pinmux_func stm32_rtc_pinmux_functions[] = { 325 + STM32_RTC_PINMUX("lsco", &stm32_rtc_pinmux_action_lsco, "out1", "out2_rmp"), 326 + STM32_RTC_PINMUX("alarm-a", &stm32_rtc_pinmux_action_alarm, "out1", "out2", "out2_rmp"), 327 + }; 328 + 329 + static int stm32_rtc_pinmux_get_functions_count(struct pinctrl_dev *pctldev) 330 + { 331 + return ARRAY_SIZE(stm32_rtc_pinmux_functions); 332 + } 333 + 334 + static const char *stm32_rtc_pinmux_get_fname(struct pinctrl_dev *pctldev, unsigned int selector) 335 + { 336 + return stm32_rtc_pinmux_functions[selector].name; 337 + } 338 + 339 + static int stm32_rtc_pinmux_get_groups(struct pinctrl_dev *pctldev, unsigned int selector, 340 + const char * const **groups, unsigned int * const num_groups) 341 + { 342 + *groups = stm32_rtc_pinmux_functions[selector].groups; 343 + *num_groups = stm32_rtc_pinmux_functions[selector].num_groups; 344 + return 0; 345 + } 346 + 347 + static int stm32_rtc_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned int selector, 348 + unsigned int group) 349 + { 350 + struct stm32_rtc_pinmux_func selected_func = stm32_rtc_pinmux_functions[selector]; 351 + struct pinctrl_pin_desc pin = stm32_rtc_pinctrl_pins[group]; 352 + 353 + /* Call action */ 354 + if (selected_func.action) 355 + return selected_func.action(pctldev, pin.number); 356 + 357 + return -EINVAL; 358 + } 359 + 360 + static const struct pinmux_ops stm32_rtc_pinmux_ops = { 361 + .get_functions_count = stm32_rtc_pinmux_get_functions_count, 362 + .get_function_name = stm32_rtc_pinmux_get_fname, 363 + .get_function_groups = stm32_rtc_pinmux_get_groups, 364 + .set_mux = stm32_rtc_pinmux_set_mux, 365 + .strict = true, 366 + }; 367 + 368 + static struct pinctrl_desc stm32_rtc_pdesc = { 369 + .name = DRIVER_NAME, 370 + .pins = stm32_rtc_pinctrl_pins, 371 + .npins = ARRAY_SIZE(stm32_rtc_pinctrl_pins), 372 + .owner = THIS_MODULE, 373 + .pctlops = &stm32_rtc_pinctrl_ops, 374 + .pmxops = &stm32_rtc_pinmux_ops, 375 + }; 201 376 202 377 static int stm32_rtc_enter_init_mode(struct stm32_rtc *rtc) 203 378 { ··· 807 576 .need_dbp = true, 808 577 .need_accuracy = false, 809 578 .rif_protected = false, 579 + .has_lsco = false, 580 + .has_alarm_out = false, 810 581 .regs = { 811 582 .tr = 0x00, 812 583 .dr = 0x04, ··· 819 586 .wpr = 0x24, 820 587 .sr = 0x0C, /* set to ISR offset to ease alarm management */ 821 588 .scr = UNDEF_REG, 589 + .cfgr = UNDEF_REG, 822 590 .verr = UNDEF_REG, 823 591 }, 824 592 .events = { ··· 833 599 .need_dbp = true, 834 600 .need_accuracy = false, 835 601 .rif_protected = false, 602 + .has_lsco = false, 603 + .has_alarm_out = false, 836 604 .regs = { 837 605 .tr = 0x00, 838 606 .dr = 0x04, ··· 845 609 .wpr = 0x24, 846 610 .sr = 0x0C, /* set to ISR offset to ease alarm management */ 847 611 .scr = UNDEF_REG, 612 + .cfgr = UNDEF_REG, 848 613 .verr = UNDEF_REG, 849 614 }, 850 615 .events = { ··· 868 631 .need_dbp = false, 869 632 .need_accuracy = true, 870 633 .rif_protected = false, 634 + .has_lsco = true, 635 + .has_alarm_out = true, 871 636 .regs = { 872 637 .tr = 0x00, 873 638 .dr = 0x04, ··· 880 641 .wpr = 0x24, 881 642 .sr = 0x50, 882 643 .scr = 0x5C, 644 + .cfgr = 0x60, 883 645 .verr = 0x3F4, 884 646 }, 885 647 .events = { ··· 894 654 .need_dbp = false, 895 655 .need_accuracy = true, 896 656 .rif_protected = true, 657 + .has_lsco = true, 658 + .has_alarm_out = true, 897 659 .regs = { 898 660 .tr = 0x00, 899 661 .dr = 0x04, ··· 906 664 .wpr = 0x24, 907 665 .sr = 0x50, 908 666 .scr = 0x5C, 667 + .cfgr = 0x60, 909 668 .verr = 0x3F4, 910 669 }, 911 670 .events = { ··· 923 680 {} 924 681 }; 925 682 MODULE_DEVICE_TABLE(of, stm32_rtc_of_match); 683 + 684 + static void stm32_rtc_clean_outs(struct stm32_rtc *rtc) 685 + { 686 + struct stm32_rtc_registers regs = rtc->data->regs; 687 + unsigned int cr = readl_relaxed(rtc->base + regs.cr); 688 + 689 + cr &= ~STM32_RTC_CR_OSEL; 690 + cr &= ~STM32_RTC_CR_TAMPOE; 691 + cr &= ~STM32_RTC_CR_COE; 692 + cr &= ~STM32_RTC_CR_TAMPALRM_TYPE; 693 + cr &= ~STM32_RTC_CR_OUT2EN; 694 + 695 + stm32_rtc_wpr_unlock(rtc); 696 + writel_relaxed(cr, rtc->base + regs.cr); 697 + stm32_rtc_wpr_lock(rtc); 698 + 699 + if (regs.cfgr != UNDEF_REG) { 700 + unsigned int cfgr = readl_relaxed(rtc->base + regs.cfgr); 701 + 702 + cfgr &= ~STM32_RTC_CFGR_LSCOEN; 703 + cfgr &= ~STM32_RTC_CFGR_OUT2_RMP; 704 + writel_relaxed(cfgr, rtc->base + regs.cfgr); 705 + } 706 + } 926 707 927 708 static int stm32_rtc_check_rif(struct stm32_rtc *stm32_rtc, 928 709 struct stm32_rtc_rif_resource res) ··· 1058 791 { 1059 792 struct stm32_rtc *rtc; 1060 793 const struct stm32_rtc_registers *regs; 794 + struct pinctrl_dev *pctl; 1061 795 int ret; 1062 796 1063 797 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); ··· 1180 912 goto err; 1181 913 } 1182 914 915 + stm32_rtc_clean_outs(rtc); 916 + 917 + ret = devm_pinctrl_register_and_init(&pdev->dev, &stm32_rtc_pdesc, rtc, &pctl); 918 + if (ret) 919 + return dev_err_probe(&pdev->dev, ret, "pinctrl register failed"); 920 + 921 + ret = pinctrl_enable(pctl); 922 + if (ret) 923 + return dev_err_probe(&pdev->dev, ret, "pinctrl enable failed"); 924 + 1183 925 /* 1184 926 * If INITS flag is reset (calendar year field set to 0x00), calendar 1185 927 * must be initialized ··· 1227 949 struct stm32_rtc *rtc = platform_get_drvdata(pdev); 1228 950 const struct stm32_rtc_registers *regs = &rtc->data->regs; 1229 951 unsigned int cr; 952 + 953 + if (!IS_ERR_OR_NULL(rtc->clk_lsco)) 954 + clk_unregister_gate(rtc->clk_lsco); 1230 955 1231 956 /* Disable interrupts */ 1232 957 stm32_rtc_wpr_unlock(rtc);
+1
drivers/rtc/rtc-sun6i.c
··· 402 402 static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = { 403 403 .rc_osc_rate = 32000, 404 404 .has_out_clk = 1, 405 + .has_auto_swt = 1, 405 406 }; 406 407 407 408 static void __init sun8i_v3_rtc_clk_init(struct device_node *node)
+2 -2
drivers/rtc/rtc-twl.c
··· 591 591 memset(&nvmem_cfg, 0, sizeof(nvmem_cfg)); 592 592 nvmem_cfg.name = "twl-secured-"; 593 593 nvmem_cfg.type = NVMEM_TYPE_BATTERY_BACKED; 594 - nvmem_cfg.reg_read = twl_nvram_read, 595 - nvmem_cfg.reg_write = twl_nvram_write, 594 + nvmem_cfg.reg_read = twl_nvram_read; 595 + nvmem_cfg.reg_write = twl_nvram_write; 596 596 nvmem_cfg.word_size = 1; 597 597 nvmem_cfg.stride = 1; 598 598 if (twl_class_is_4030()) {