RTC: update APM X-Gene RTC driver by adding the pre-scaler support
[email protected]
maintainercover RTC: update APM X-Gene RTC driver by adding the pre-scaler support
From: Wei Fu <[email protected]>
This patch add Counter Prescaler support in APM X-Gene RTC driver by getting prescaler (Optional) property value from dtb.
This hardware support can only be found in DW_apb_rtc after v2.06a.
And adds the optional property "prescaler" in bindings for APM X-Gene RTC. Because the clock source on some platform to RTC is NOT 1HZ, so we need to prescale the clock to make the input clock become 1HZ, like (32K/prescaler) = 1HZ on the XuanTie TH1520 AP sub-system RTC.
This patch also add "snps,dw-apb-rtc" into the "compatible".
Since XuanTie TH1520 is using the same RTC, so this patch enables APM X-Gene RTC driver for XuanTie TH1520, and add a device node in the XuanTie TH1520 Soc dts: th1520.dtsi.
Wei Fu (5):
drivers/rtc/rtc-xgene: Add prescaler support in APM X-Gene RTC driver
dt-bindings: rtc: Add optional property "prescaler" in APM X-Gene RTC
Document
drivers/rtc/rtc-xgene: Add "snps,dw-apb-rtc" into the "compatible"
Kconfig: Enable APM X-Gene RTC for XuanTie TH1520
riscv: dts: thead: Add XuanTie TH1520 RTC device node
.../devicetree/bindings/rtc/xgene-rtc.txt | 16 ++++++++++ arch/riscv/boot/dts/thead/th1520.dtsi | 11 +++++++ drivers/rtc/Kconfig | 12 ++++++- drivers/rtc/rtc-xgene.c | 32 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-)
Signature · 1 line
2.44.0
[email protected]
maintainerPATCH 1/5 drivers/rtc/rtc-xgene: Add prescaler support in APM X-Gene RTC driver
From: Wei Fu <[email protected]>
This patch add Counter Prescaler support in APM X-Gene RTC driver by getting prescaler (Optional) property value from dtb.
--- drivers/rtc/Kconfig | 10 ++++++++++ drivers/rtc/rtc-xgene.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
drivers/rtc/Kconfig +10 -0
@@ -1888,6 +1888,16 @@ config RTC_DRV_XGENE This driver can also be built as a module, if so, the module will be called "rtc-xgene". +config RTC_DRV_XGENE_PRESCALER + bool "Pre-scaler Counter support for APM X-Gene RTC driver" + depends on RTC_DRV_XGENE + depends on ARCH_THEAD + default y + help + Say Y here if your Soc has Pre-scaler Counter support on rtc-xgene. + + This hardware support can only be found in DW_apb_rtc after v2.06a. + config RTC_DRV_PIC32 tristate "Microchip PIC32 RTC" depends on MACH_PIC32
drivers/rtc/rtc-xgene.c +31 -0
@@ -26,11 +26,13 @@#define RTC_CCR_MASK BIT(1)#define RTC_CCR_EN BIT(2)#define RTC_CCR_WEN BIT(3) +#define RTC_CCR_PSCLR_EN BIT(4)#define RTC_STAT 0x10#define RTC_STAT_BIT BIT(0)#define RTC_RSTAT 0x14#define RTC_EOI 0x18#define RTC_VER 0x1C +#define RTC_CPSR 0x20struct xgene_rtc_dev {struct rtc_device *rtc;
@@ -40,6 +42,33 @@ struct xgene_rtc_dev {unsigned int irq_enabled; }; +static void xgene_rtc_set_prescaler (struct device *dev) +{ +#ifdef CONFIG_RTC_DRV_XGENE_PRESCALER +u32 ccr; +u32 prescaler; +struct xgene_rtc_dev *pdata =dev_get_drvdata (dev); + +if (device_property_read_u32 (dev,"prescaler" , &prescaler)) { +dev_warn (dev,"Missing the pre-scaler config for RTC.\n" ); +dev_warn (dev,"The current pre-scaler config is 0x%x.\n" , +readl (pdata->csr_base +RTC_CPSR )); +return ; + } + +/* The clock source on some platform to RTC is NOT 1HZ, +* so we need to prescale the clock to make the input clock become 1HZ, +* like (clock_source/prescaler) = 1HZ +*/ +writel (prescaler, pdata->csr_base +RTC_CPSR ); + +/* enable RTC Prescaler feature in CCR register */ + ccr =readl (pdata->csr_base +RTC_CCR ); + ccr |=RTC_CCR_PSCLR_EN ; +writel (ccr, pdata->csr_base +RTC_CCR ); +#endif /* CONFIG_RTC_DRV_XGENE_PRESCALER */ +} +static int xgene_rtc_read_time (struct device *dev,struct rtc_time *tm) {struct xgene_rtc_dev *pdata =dev_get_drvdata (dev);
@@ -174,6 +203,8 @@ static int xgene_rtc_probe(struct platform_device *pdev)/* Turn on the clock and the crystal */ writel (RTC_CCR_EN , pdata->csr_base +RTC_CCR ); +xgene_rtc_set_prescaler (&pdev->dev); + ret =device_init_wakeup (&pdev->dev,1 );if (ret) {clk_disable_unprepare (pdata->clk);
Signature · 1 line
2.44.0
Alexandre Belloni
maintainerRe: [PATCH 1/5] drivers/rtc/rtc-xgene: Add prescaler support in APM X-Gene RTC driver
Quoted 19 lines · On 12/04/2024 16:01:43+0800, [email protected] wrote:
From: Wei Fu <[email protected]>
This patch add Counter Prescaler support in APM X-Gene RTC driver by getting prescaler (Optional) property value from dtb.
Signed-off-by Wei Fu <[email protected]>--- drivers/rtc/Kconfig | 10 ++++++++++ drivers/rtc/rtc-xgene.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)drivers/rtc/Kconfig +0
-0@@ -1888,6 +1888,16 @@ config RTC_DRV_XGENE This driver can also be built as a module, if so, the module will be called "rtc-xgene".
drivers/rtc/Kconfig config RTC_DRV_XGENE · line 1900
Quoted 10 lines
drivers/rtc/Kconfig +10
-0+config RTC_DRV_XGENE_PRESCALER + bool "Pre-scaler Counter support for APM X-Gene RTC driver" + depends on RTC_DRV_XGENE + depends on ARCH_THEAD + default y + help + Say Y here if your Soc has Pre-scaler Counter support on rtc-xgene. + + This hardware support can only be found in DW_apb_rtc after v2.06a. +
I don't feel like this needs a config option, rather you should have a proper compatible string that will tell the driver whether the feature is available.
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
[email protected]
maintainerPATCH 2/5 dt-bindings: rtc: Add optional property "prescaler" in APM X-Gene RTC Document
In reply to [email protected]From: Wei Fu <[email protected]>
Add optional property "prescaler" for APM X-Gene RTC.
The clock source on some platform to RTC is NOT 1HZ,
so we need to prescale the clock to make the input clock become 1HZ, like (32K/prescaler) = 1HZ on the XuanTie TH1520 AP sub-system RTC.
--- .../devicetree/bindings/rtc/xgene-rtc.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Documentation/devicetree/bindings/rtc/xgene-rtc.txt +16 -0
@@ -10,6 +10,9 @@ Required properties: - #clock-cells: Should be 1. - clocks: Reference to the clock entry. +Optional properties: +- prescaler: Reference to the Value of Counter Prescaler. + Example: rtcclk: rtcclk {
@@ -26,3 +29,16 @@ rtc: rtc@10510000 { #clock-cells = <1>; clocks = <&rtcclk 0>; }; + +Example XuanTie TH1520 RTC node with Counter Prescaler(prescaler): + +rtc: rtc@fffff40000 { + compatible = "snps,dw-apb-rtc"; + reg = <0xff 0xfff40000 0x0 0x1000>; + interrupts = <74 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&osc_32k>; + clock-names = "osc_32k"; + wakeup-source; + prescaler = <0x8000>; + status = "okay"; +};
Signature · 1 line
2.44.0
Alexandre Belloni
maintainerRe: [PATCH 2/5] dt-bindings: rtc: Add optional property "prescaler" in APM X-Gene RTC Document
Quoted 17 lines · On 12/04/2024 16:01:44+0800, [email protected] wrote:
From: Wei Fu <[email protected]>
Add optional property "prescaler" for APM X-Gene RTC.
The clock source on some platform to RTC is NOT 1HZ,
so we need to prescale the clock to make the input clock become 1HZ, like (32K/prescaler) = 1HZ on the XuanTie TH1520 AP sub-system RTC.Signed-off-by Wei Fu <[email protected]>--- .../devicetree/bindings/rtc/xgene-rtc.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)Documentation/devicetree/bindings/rtc/xgene-rtc.txt +0
-0
Documentation/devicetree/bindings/rtc/xgene-rtc.txt Required properties: · line 14
Quoted 5 lines
Documentation/devicetree/bindings/rtc/xgene-rtc.txt +2
-0@@ -10,6 +10,9 @@ Required properties: - #clock-cells: Should be 1. - clocks: Reference to the clock entry. +Optional properties: +- prescaler: Reference to the Value of Counter Prescaler.
What about getting the input clock rate and calculate the needed prescaler instead of having it in the device tree?
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
[email protected]
maintainerPATCH 3/5 drivers/rtc/rtc-xgene: Add "snps,dw-apb-rtc" into the "compatible"
In reply to [email protected]From: Wei Fu <[email protected]>
This patch add "snps,dw-apb-rtc" into the "compatible".
--- drivers/rtc/rtc-xgene.c | 1 + 1 file changed, 1 insertion(+)
drivers/rtc/rtc-xgene.c +1 -0
@@ -287,6 +287,7 @@ static SIMPLE_DEV_PM_OPS(xgene_rtc_pm_ops, xgene_rtc_suspend, xgene_rtc_resume);#ifdef CONFIG_OF static const struct of_device_id xgene_rtc_of_match[] = { {.compatible ="apm,xgene-rtc" }, + {.compatible ="snps,dw-apb-rtc" }, { } };MODULE_DEVICE_TABLE (of, xgene_rtc_of_match);
Signature · 1 line
2.44.0
Re: [PATCH 3/5] drivers/rtc/rtc-xgene: Add "snps,dw-apb-rtc" into the "compatible"
Quoted 3 lines · On 12/04/2024 10:01, [email protected] wrote:
From: Wei Fu <[email protected]>
This patch add "snps,dw-apb-rtc" into the "compatible".
Please do not use "This commit/patch/change", but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v5.17.1/source/Documentation/process/submitting-patches.rst#L95
This we see from the patch. Say what hardware are you adding?
Please run scripts/checkpatch.pl and fix reported warnings. Then please run scripts/checkpatch.pl --strict and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.
Best regards,
Krzysztof
Re: [PATCH 3/5] drivers/rtc/rtc-xgene: Add "snps,dw-apb-rtc" into the "compatible"
Quoted 11 lines · Krzysztof Kozlowski
Quoted 3 lines · On 12/04/2024 10:01, [email protected] wrote:
From: Wei Fu <[email protected]>
This patch add "snps,dw-apb-rtc" into the "compatible".
Please do not use "This commit/patch/change", but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v5.17.1/source/Documentation/process/submitting-patches.rst#L95This we see from the patch. Say what hardware are you adding?
The compatible, unless I misread the patchset, isn't actually documented either, only the new property is.
Quoted 11 lines
Please run
scripts/checkpatch.pland fix reported warnings. Then please runscripts/checkpatch.pl --strictand (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.Best regards,
Krzysztof
[email protected]
maintainerPATCH 4/5 Kconfig: Enable APM X-Gene RTC for XuanTie TH1520
In reply to [email protected]From: Wei Fu <[email protected]>
This patch enables APM X-Gene RTC for XuanTie TH1520.
--- drivers/rtc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/Kconfig +1 -1
@@ -1880,7 +1880,7 @@ config RTC_DRV_MT7622 config RTC_DRV_XGENE tristate "APM X-Gene RTC" depends on HAS_IOMEM - depends on ARCH_XGENE || COMPILE_TEST + depends on ARCH_XGENE || ARCH_THEAD || COMPILE_TEST help If you say yes here you get support for the APM X-Gene SoC real time clock.
Signature · 1 line
2.44.0
Re: [PATCH 4/5] Kconfig: Enable APM X-Gene RTC for XuanTie TH1520
Quoted 14 lines · On Fri, Apr 12, 2024 at 04:01:46PM +0800, [email protected] wrote:
From: Wei Fu <[email protected]>
This patch enables APM X-Gene RTC for XuanTie TH1520.
Signed-off-by Wei Fu <[email protected]>--- drivers/rtc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/rtc/Kconfig +0
-0
drivers/rtc/Kconfig config RTC_DRV_MT7622 · line 1886
Quoted 8 lines
drivers/rtc/Kconfig +1
-1@@ -1880,7 +1880,7 @@ config RTC_DRV_MT7622 config RTC_DRV_XGENE tristate "APM X-Gene RTC" depends on HAS_IOMEM - depends on ARCH_XGENE || COMPILE_TEST + depends on ARCH_XGENE || ARCH_THEAD || COMPILE_TEST help If you say yes here you get support for the APM X-Gene SoC real time clock.
If I was configuring my system by reading menuconfig, I would have absolutely no idea that this driver supports platforms other than the X-Gene one. I think the Kconfig stuff for this likely needs an update to convey that it's no longer just one SoC family that's supported here.
[email protected]
maintainerPATCH 5/5 riscv: dts: thead: Add XuanTie TH1520 RTC device node
In reply to [email protected]From: Wei Fu <[email protected]>
Add nodes for the XuanTie TH1520 RTC device node on the XuanTie TH1520 Soc.
--- arch/riscv/boot/dts/thead/th1520.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/riscv/boot/dts/thead/th1520.dtsi +11 -0
@@ -463,6 +463,17 @@ timer7: timer@ffffc3303c { status = "disabled"; }; + rtc: rtc@fffff40000 { + compatible = "snps,dw-apb-rtc"; + reg = <0xff 0xfff40000 0x0 0x1000>; + interrupts = <74 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&osc_32k>; + clock-names = "osc_32k"; + wakeup-source; + prescaler = <0x8000>; + status = "okay"; + }; + gpio@fffff41000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xfff41000 0x0 0x1000>;
Signature · 1 line
2.44.0
Alexandre Belloni
maintainerRe: [PATCH 5/5] riscv: dts: thead: Add XuanTie TH1520 RTC device node
Quoted 14 lines · On 12/04/2024 16:01:47+0800, [email protected] wrote:
From: Wei Fu <[email protected]>
Add nodes for the XuanTie TH1520 RTC device node on the XuanTie TH1520 Soc.
Signed-off-by Wei Fu <[email protected]>--- arch/riscv/boot/dts/thead/th1520.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/riscv/boot/dts/thead/th1520.dtsi +0
-0
arch/riscv/boot/dts/thead/th1520.dtsi timer7: timer@ffffc3303c { · line 472
Quoted 10 lines
arch/riscv/boot/dts/thead/th1520.dtsi +7
-0@@ -463,6 +463,17 @@ timer7: timer@ffffc3303c { status = "disabled"; }; + rtc: rtc@fffff40000 { + compatible = "snps,dw-apb-rtc"; + reg = <0xff 0xfff40000 0x0 0x1000>; + interrupts = <74 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&osc_32k>; + clock-names = "osc_32k"; + wakeup-source;
The wakeup-source and interrupts properties are mutually exclusive.
Quoted 10 lines
arch/riscv/boot/dts/thead/th1520.dtsi +4
-0+ prescaler = <0x8000>; + status = "okay"; + }; + gpio@fffff41000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xfff41000 0x0 0x1000>;Signature · 1 line
2.44.0
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH 5/5] riscv: dts: thead: Add XuanTie TH1520 RTC device node
In reply to [email protected]Quoted 14 lines · On 12/04/2024 10:01, [email protected] wrote:
From: Wei Fu <[email protected]>
Add nodes for the XuanTie TH1520 RTC device node on the XuanTie TH1520 Soc.
Signed-off-by Wei Fu <[email protected]>--- arch/riscv/boot/dts/thead/th1520.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/riscv/boot/dts/thead/th1520.dtsi +0
-0
arch/riscv/boot/dts/thead/th1520.dtsi timer7: timer@ffffc3303c { · line 467
Quoted 5 lines
arch/riscv/boot/dts/thead/th1520.dtsi +2
-0@@ -463,6 +463,17 @@ timer7: timer@ffffc3303c { status = "disabled"; }; + rtc: rtc@fffff40000 { + compatible = "snps,dw-apb-rtc";
Please run scripts/checkpatch.pl and fix reported warnings. Then please run scripts/checkpatch.pl --strict and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.
arch/riscv/boot/dts/thead/th1520.dtsi timer7: timer@ffffc3303c { · line 473
Quoted 6 lines
arch/riscv/boot/dts/thead/th1520.dtsi +6
-0+ reg = <0xff 0xfff40000 0x0 0x1000>; + interrupts = <74 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&osc_32k>; + clock-names = "osc_32k"; + wakeup-source; + prescaler = <0x8000>;
What is 0x8000? Why is it in hex if this divides the clock? Clock is in Hz and we all operate on decimal units.
arch/riscv/boot/dts/thead/th1520.dtsi timer7: timer@ffffc3303c { · line 474
Quoted 1 line
arch/riscv/boot/dts/thead/th1520.dtsi +1
-0+ status = "okay";
Drop, please don't upstream directly downstream code.
arch/riscv/boot/dts/thead/th1520.dtsi timer7: timer@ffffc3303c { · line 479
Quoted 5 lines
arch/riscv/boot/dts/thead/th1520.dtsi +2
-0+ }; + gpio@fffff41000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xfff41000 0x0 0x1000>;
Best regards,
Krzysztof