Add basic support for RTC on Allwinner H6 SoC
v2 cover Add basic support for RTC on Allwinner H6 SoC
From: Ondrej Jirman <megous-5qf/[email protected]>
I went through the datasheets for H6 and H5, and compared the differences. RTCs are largely similar, but not entirely compatible. Incompatibilities are in details not yet implemented by the rtc driver though.
I also corrected the clock tree in H6 DTSI.
This patchset is necessary for implementing the WiFi/Bluetooth support on boards using H6 SoC.
There was some discussion previously of describing HOSC, DCXO and XO oscillators and clocks as part of RTC in DT, but I decided against it because it's not necessary, becuse information that would be provided as a part of DT can already be determined at runtime from RTC registers, so this woudn't add any value and would only introduce complications to the driver. See: https://patchwork.kernel.org/cover/10898083/
Please take a look.
Thank you and regards,
Ondrej Jirman
Changes in v2:
- bindings converted to yaml
- added reviewed by tags
Ondrej Jirman (3):
dt-bindings: Add compatible for H6 RTC
rtc: sun6i: Add support for H6 RTC
arm64: dts: sun50i-h6: Add support for RTC and fix the clock tree
.../bindings/rtc/allwinner,sun6i-a31-rtc.yaml | 13 ++++++ arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi | 30 +++++++------- drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++- 3 files changed, 67 insertions(+), 16 deletions(-)
Signature · 1 line
2.22.1
PATCH v2 1/3 dt-bindings: Add compatible for H6 RTC
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is similar to the one on H5 SoC, but incompatible in small details. See the driver for description of differences. For example H6 RTC needs to enable the external low speed oscillator. Add new compatible for this RTC.
--- .../bindings/rtc/allwinner,sun6i-a31-rtc.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Documentation/devicetree/bindings/rtc/allwinner,sun6i-a31-rtc.yaml +13 -0
@@ -25,6 +25,7 @@ properties: - items: - const: allwinner,sun50i-a64-rtc - const: allwinner,sun8i-h3-rtc + - const: allwinner,sun50i-h6-rtc reg: maxItems: 1
@@ -92,6 +93,18 @@ allOf: minItems: 3 maxItems: 3 + - if: + properties: + compatible: + contains: + const: allwinner,sun50i-h6-rtc + + then: + properties: + clock-output-names: + minItems: 3 + maxItems: 3 + - if: properties: compatible:
Signature · 1 line
2.22.1
Re: [PATCH v2 1/3] dt-bindings: Add compatible for H6 RTC
Quoted 7 lines · On 20/08/2019 17:19:32+0200, megous-5qf/[email protected]…
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is similar to the one on H5 SoC, but incompatible in small details. See the driver for description of differences. For example H6 RTC needs to enable the external low speed oscillator. Add new compatible for this RTC.
Quoted 5 lines
Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>--- .../bindings/rtc/allwinner,sun6i-a31-rtc.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Applied, thanks.
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v2 2/3 rtc: sun6i: Add support for H6 RTC
In reply to [email protected]From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences mostly in features that are not yet supported by this driver.
Some differences are already stated in the comments in existing code. One other difference is that H6 has extra bit in LOSC_CTRL_REG, called EXT_LOSC_EN to enable/disable external low speed crystal oscillator.
It also has bit EXT_LOSC_STA in LOSC_AUTO_SWT_STA_REG, to check whether external low speed oscillator is working correctly.
This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clock
H6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external oscillator fails. This is enabled by default. Disable it during probe.
--- drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
drivers/rtc/rtc-sun6i.c +38 -2
@@ -32,9 +32,11 @@/* Control register */ #define SUN6I_LOSC_CTRL 0x0000#define SUN6I_LOSC_CTRL_KEY (0x16aa << 16) +#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS BIT(15)#define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9)#define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUN6I_LOSC_CTRL_EXT_LOSC_EN BIT(4)#define SUN6I_LOSC_CTRL_EXT_OSC BIT(0)#define SUN6I_LOSC_CTRL_ACC_MASK GENMASK(9, 7)
@@ -128,6 +130,8 @@ struct sun6i_rtc_clk_data { unsigned int has_prescaler : 1; unsigned int has_out_clk : 1; unsigned int export_iosc : 1; + unsigned int has_losc_en : 1; + unsigned int has_auto_swt : 1; };struct sun6i_rtc_dev {
@@ -190,6 +194,10 @@ static int sun6i_rtc_osc_set_parent(struct clk_hw *hw, u8 index) val &= ~SUN6I_LOSC_CTRL_EXT_OSC ; val |=SUN6I_LOSC_CTRL_KEY ; val |= index ?SUN6I_LOSC_CTRL_EXT_OSC :0 ; +if (rtc->data->has_losc_en) { + val &= ~SUN6I_LOSC_CTRL_EXT_LOSC_EN ; + val |= index ?SUN6I_LOSC_CTRL_EXT_LOSC_EN :0 ; + }writel (val, rtc->base +SUN6I_LOSC_CTRL );spin_unlock_irqrestore (&rtc->lock, flags);
@@ -215,6 +223,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node,const char *iosc_name ="rtc-int-osc" ;const char *clkout_name ="osc32k-out" ;const char *parents[2 ]; +u32 reg; rtc =kzalloc (sizeof (*rtc),GFP_KERNEL );if (!rtc)
@@ -235,9 +244,18 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, goto err; } + reg =SUN6I_LOSC_CTRL_KEY ; +if (rtc->data->has_auto_swt) { +/* Bypass auto-switch to int osc, on ext losc failure */ + reg |=SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL ); + } +/* Switch to the external, more precise, oscillator */ -writel (SUN6I_LOSC_CTRL_KEY |SUN6I_LOSC_CTRL_EXT_OSC , - rtc->base +SUN6I_LOSC_CTRL ); + reg |=SUN6I_LOSC_CTRL_EXT_OSC ; +if (rtc->data->has_losc_en) + reg |=SUN6I_LOSC_CTRL_EXT_LOSC_EN ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL );/* Yes, I know, this is ugly. */ sun6i_rtc = rtc;
@@ -345,6 +363,23 @@ CLK_OF_DECLARE_DRIVER(sun8i_h3_rtc_clk, "allwinner,sun8i-h3-rtc",CLK_OF_DECLARE_DRIVER (sun50i_h5_rtc_clk,"allwinner,sun50i-h5-rtc" , sun8i_h3_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun50i_h6_rtc_data = { + .rc_osc_rate =16000000 , + .fixed_prescaler =32 , + .has_prescaler =1 , + .has_out_clk =1 , + .export_iosc =1 , + .has_losc_en =1 , + .has_auto_swt =1 , +}; + +static void __init sun50i_h6_rtc_clk_init (struct device_node *node) +{ +sun6i_rtc_clk_init (node, &sun50i_h6_rtc_data); +} +CLK_OF_DECLARE_DRIVER (sun50i_h6_rtc_clk,"allwinner,sun50i-h6-rtc" , + sun50i_h6_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = { .rc_osc_rate =32000 , .has_out_clk =1 ,
@@ -675,6 +710,7 @@ static const struct of_device_id sun6i_rtc_dt_ids[] = { { .compatible = "allwinner,sun8i-r40-rtc" }, { .compatible = "allwinner,sun8i-v3-rtc" }, { .compatible = "allwinner,sun50i-h5-rtc" }, + { .compatible = "allwinner,sun50i-h6-rtc" }, { /* sentinel */ }, };MODULE_DEVICE_TABLE (of, sun6i_rtc_dt_ids);
Signature · 1 line
2.22.1
Re: [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Quoted 22 lines · On 20/08/2019 17:19:33+0200, [email protected] wrote:
From: Ondrej Jirman <[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences mostly in features that are not yet supported by this driver.
Some differences are already stated in the comments in existing code. One other difference is that H6 has extra bit in
LOSC_CTRL_REG, calledEXT_LOSC_ENto enable/disable external low speed crystal oscillator.It also has bit
EXT_LOSC_STAinLOSC_AUTO_SWT_STA_REG, to check whether external low speed oscillator is working correctly.This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clockH6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external oscillator fails. This is enabled by default. Disable it during probe.
Quoted 6 lines
Signed-off-by Ondrej Jirman <[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>--- drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
Applied, thanks.
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Jernej Škrabec
maintainerRe: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
In reply to [email protected]Hi!
Dne torek, 20. avgust 2019 ob 17:19:33 CEST je megous-5qf/[email protected] napisal(a):
Quoted 33 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences mostly in features that are not yet supported by this driver.
Some differences are already stated in the comments in existing code. One other difference is that H6 has extra bit in
LOSC_CTRL_REG, calledEXT_LOSC_ENto enable/disable external low speed crystal oscillator.It also has bit
EXT_LOSC_STAinLOSC_AUTO_SWT_STA_REG, to check whether external low speed oscillator is working correctly.This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clockH6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external oscillator fails. This is enabled by default. Disable it during probe.
Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>--- drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)drivers/rtc/rtc-sun6i.c +0
-0
drivers/rtc/rtc-sun6i.c line 35
Quoted 4 lines
drivers/rtc/rtc-sun6i.c +1
-0@@ -32,9 +32,11 @@/* Control register */ #define SUN6I_LOSC_CTRL 0x0000#define SUN6I_LOSC_CTRL_KEY (0x16aa << 16) +#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS BIT(15)
User manual says that above field is bit 14.
Best regards,
Jernej
Quoted 88 lines
drivers/rtc/rtc-sun6i.c +37
-2#define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9)#define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUN6I_LOSC_CTRL_EXT_LOSC_EN BIT(4)#define SUN6I_LOSC_CTRL_EXT_OSC BIT(0)#define SUN6I_LOSC_CTRL_ACC_MASK GENMASK(9, 7)@@ -128,6 +130,8 @@ struct sun6i_rtc_clk_data { unsigned int has_prescaler : 1; unsigned int has_out_clk : 1; unsigned int export_iosc : 1; + unsigned int has_losc_en : 1; + unsigned int has_auto_swt : 1; };struct sun6i_rtc_dev {@@ -190,6 +194,10 @@ static int sun6i_rtc_osc_set_parent(struct clk_hw *hw, u8 index) val &= ~SUN6I_LOSC_CTRL_EXT_OSC; val |=SUN6I_LOSC_CTRL_KEY ; val |= index ?SUN6I_LOSC_CTRL_EXT_OSC :0 ; +if (rtc->data->has_losc_en) { + val &= ~SUN6I_LOSC_CTRL_EXT_LOSC_EN ; + val |= index ?SUN6I_LOSC_CTRL_EXT_LOSC_EN :0 ; + }writel (val, rtc->base +SUN6I_LOSC_CTRL );spin_unlock_irqrestore (&rtc->lock, flags);@@ -215,6 +223,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, const char *iosc_name = "rtc-int-osc";const char *clkout_name ="osc32k-out" ;const char *parents[2 ]; +u32 reg; rtc =kzalloc (sizeof (*rtc),GFP_KERNEL );if (!rtc)@@ -235,9 +244,18 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, goto err; } + reg =SUN6I_LOSC_CTRL_KEY ; +if (rtc->data->has_auto_swt) { +/* Bypass auto-switch to int osc, on ext losc failure */ + reg |=SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL ); + } +/* Switch to the external, more precise, oscillator */ -writel (SUN6I_LOSC_CTRL_KEY |SUN6I_LOSC_CTRL_EXT_OSC , - rtc->base +SUN6I_LOSC_CTRL ); + reg |=SUN6I_LOSC_CTRL_EXT_OSC ; +if (rtc->data->has_losc_en) + reg |=SUN6I_LOSC_CTRL_EXT_LOSC_EN ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL );/* Yes, I know, this is ugly. */ sun6i_rtc = rtc;@@ -345,6 +363,23 @@ CLK_OF_DECLARE_DRIVER(sun8i_h3_rtc_clk,"allwinner,sun8i-h3-rtc" ,CLK_OF_DECLARE_DRIVER (sun50i_h5_rtc_clk,"allwinner,sun50i-h5-rtc" , sun8i_h3_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun50i_h6_rtc_data = { + .rc_osc_rate =16000000 , + .fixed_prescaler =32 , + .has_prescaler =1 , + .has_out_clk =1 , + .export_iosc =1 , + .has_losc_en =1 , + .has_auto_swt =1 , +}; + +static void __init sun50i_h6_rtc_clk_init (struct device_node *node) +{ +sun6i_rtc_clk_init (node, &sun50i_h6_rtc_data); +} +CLK_OF_DECLARE_DRIVER (sun50i_h6_rtc_clk,"allwinner,sun50i-h6-rtc" , + sun50i_h6_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = { .rc_osc_rate =32000 , .has_out_clk =1 ,@@ -675,6 +710,7 @@ static const struct of_device_id sun6i_rtc_dt_ids[] = { { .compatible = "allwinner,sun8i-r40-rtc" }, { .compatible = "allwinner,sun8i-v3-rtc" }, { .compatible = "allwinner,sun50i-h5-rtc" }, + { .compatible = "allwinner,sun50i-h6-rtc" }, { /* sentinel */ }, };MODULE_DEVICE_TABLE (of, sun6i_rtc_dt_ids);
Re: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Hi,
Quoted 31 lines · Jernej Škrabec
Hi!
Dne torek, 20. avgust 2019 ob 17:19:33 CEST je megous-5qf/[email protected] napisal(a):
Quoted 28 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences mostly in features that are not yet supported by this driver.
Some differences are already stated in the comments in existing code. One other difference is that H6 has extra bit in
LOSC_CTRL_REG, calledEXT_LOSC_ENto enable/disable external low speed crystal oscillator.It also has bit
EXT_LOSC_STAinLOSC_AUTO_SWT_STA_REG, to check whether external low speed oscillator is working correctly.This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clockH6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external oscillator fails. This is enabled by default. Disable it during probe.
Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>--- drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
Quoted 11 lines
drivers/rtc/rtc-sun6i.c line 35
Quoted 9 lines
drivers/rtc/rtc-sun6i.c +1
-0@@ -32,9 +32,11 @@/* Control register */ #define SUN6I_LOSC_CTRL 0x0000#define SUN6I_LOSC_CTRL_KEY (0x16aa << 16) +#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS BIT(15)User manual says that above field is bit 14.
See the previous discussion, this is from BSP.
regards,
o.
Quoted 100 lines
Best regards,
JernejQuoted 81 lines
drivers/rtc/rtc-sun6i.c +36
-2#define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9)#define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUN6I_LOSC_CTRL_EXT_LOSC_EN BIT(4)#define SUN6I_LOSC_CTRL_EXT_OSC BIT(0)#define SUN6I_LOSC_CTRL_ACC_MASK GENMASK(9, 7)@@ -128,6 +130,8 @@ struct sun6i_rtc_clk_data { unsigned int has_prescaler : 1; unsigned int has_out_clk : 1; unsigned int export_iosc : 1; + unsigned int has_losc_en : 1; + unsigned int has_auto_swt : 1; };struct sun6i_rtc_dev {@@ -190,6 +194,10 @@ static int sun6i_rtc_osc_set_parent(struct clk_hw *hw, u8 index) val &= ~SUN6I_LOSC_CTRL_EXT_OSC; val |=SUN6I_LOSC_CTRL_KEY ; val |= index ?SUN6I_LOSC_CTRL_EXT_OSC :0 ; +if (rtc->data->has_losc_en) { + val &= ~SUN6I_LOSC_CTRL_EXT_LOSC_EN ; + val |= index ?SUN6I_LOSC_CTRL_EXT_LOSC_EN :0 ; + }writel (val, rtc->base +SUN6I_LOSC_CTRL );spin_unlock_irqrestore (&rtc->lock, flags);@@ -215,6 +223,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, const char *iosc_name = "rtc-int-osc";const char *clkout_name ="osc32k-out" ;const char *parents[2 ]; +u32 reg; rtc =kzalloc (sizeof (*rtc),GFP_KERNEL );if (!rtc)@@ -235,9 +244,18 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, goto err; } + reg =SUN6I_LOSC_CTRL_KEY ; +if (rtc->data->has_auto_swt) { +/* Bypass auto-switch to int osc, on ext losc failure */ + reg |=SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL ); + } +/* Switch to the external, more precise, oscillator */ -writel (SUN6I_LOSC_CTRL_KEY |SUN6I_LOSC_CTRL_EXT_OSC , - rtc->base +SUN6I_LOSC_CTRL ); + reg |=SUN6I_LOSC_CTRL_EXT_OSC ; +if (rtc->data->has_losc_en) + reg |=SUN6I_LOSC_CTRL_EXT_LOSC_EN ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL );/* Yes, I know, this is ugly. */ sun6i_rtc = rtc;@@ -345,6 +363,23 @@ CLK_OF_DECLARE_DRIVER(sun8i_h3_rtc_clk,"allwinner,sun8i-h3-rtc" ,CLK_OF_DECLARE_DRIVER (sun50i_h5_rtc_clk,"allwinner,sun50i-h5-rtc" , sun8i_h3_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun50i_h6_rtc_data = { + .rc_osc_rate =16000000 , + .fixed_prescaler =32 , + .has_prescaler =1 , + .has_out_clk =1 , + .export_iosc =1 , + .has_losc_en =1 , + .has_auto_swt =1 , +}; + +static void __init sun50i_h6_rtc_clk_init (struct device_node *node) +{ +sun6i_rtc_clk_init (node, &sun50i_h6_rtc_data); +} +CLK_OF_DECLARE_DRIVER (sun50i_h6_rtc_clk,"allwinner,sun50i-h6-rtc" , + sun50i_h6_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = { .rc_osc_rate =32000 , .has_out_clk =1 ,drivers/rtc/rtc-sun6i.c static const struct of_device_id sun6i_rtc_dt_ids[] = { · line 716
Quoted 7 lines
drivers/rtc/rtc-sun6i.c +1
-0@@ -675,6 +710,7 @@ static const struct of_device_id sun6i_rtc_dt_ids[] = { { .compatible = "allwinner,sun8i-r40-rtc" }, { .compatible = "allwinner,sun8i-v3-rtc" }, { .compatible = "allwinner,sun50i-h5-rtc" }, + { .compatible = "allwinner,sun50i-h6-rtc" }, { /* sentinel */ }, };MODULE_DEVICE_TABLE (of, sun6i_rtc_dt_ids);_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20190824124654.nqtlkam2gsaqsj77%40core.my.home.
Jernej Škrabec
maintainerRe: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Dne sobota, 24. avgust 2019 ob 14:46:54 CEST je Ondřej Jirman napisal(a):
Quoted 6 lines
Hi,
Quoted 3 lines · Jernej Škrabec
Hi!
Dne torek, 20. avgust 2019 ob 17:19:33 CEST je megous-5qf/[email protected]
napisal(a):
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences mostly in features that are not yet supported by this driver.
Some differences are already stated in the comments in existing code. One other difference is that H6 has extra bit in
LOSC_CTRL_REG, calledEXT_LOSC_ENto enable/disable external low speed crystal oscillator.It also has bit
EXT_LOSC_STAinLOSC_AUTO_SWT_STA_REG, to check whether external low speed oscillator is working correctly.This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clockH6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external oscillator fails. This is enabled by default. Disable it during probe.
Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>---
drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)drivers/rtc/rtc-sun6i.c +0
-0@@ -32,9 +32,11 @@/* Control register */ #define SUN6I_LOSC_CTRL 0x0000#define SUN6I_LOSC_CTRL_KEY (0x16aa << 16)
Quoted 5 lines
Quoted 3 lines
drivers/rtc/rtc-sun6i.c line 35
Quoted 1 line
drivers/rtc/rtc-sun6i.c +1
-0+#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS BIT(15)User manual says that above field is bit 14.
See the previous discussion, this is from BSP.
I have two versions of BSP (don't ask me which) which have this set as bit 14 and changing this to 14 actually solves all my problems with LOSC (no more issues with setting RTC and HDMI-CEC works now - it uses LOSC as parent) on Tanix TX6 box.
Best regards,
Jernej
Quoted 55 lines
regards,
o.Quoted 51 lines
Best regards,
JernejQuoted 48 lines
drivers/rtc/rtc-sun6i.c +1
-0#define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9)#define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUN6I_LOSC_CTRL_EXT_LOSC_EN BIT(4)#define
SUN6I_LOSC_CTRL_EXT_OSCBIT(0)
#defineSUN6I_LOSC_CTRL_ACC_MASKGENMASK(9, 7)drivers/rtc/rtc-sun6i.c +2
-0@@ -128,6 +130,8 @@ struct sun6i_rtc_clk_data { unsigned int has_prescaler : 1; unsigned int has_out_clk : 1; unsigned int export_iosc : 1; + unsigned int has_losc_en : 1; + unsigned int has_auto_swt : 1;};
struct
sun6i_rtc_dev{drivers/rtc/rtc-sun6i.c +4
-0@@ -190,6 +194,10 @@ static int sun6i_rtc_osc_set_parent(struct clk_hw *hw, u8 index) val &= ~SUN6I_LOSC_CTRL_EXT_OSC; val |=SUN6I_LOSC_CTRL_KEY ; val |= index ?SUN6I_LOSC_CTRL_EXT_OSC :0 ; +if (rtc->data->has_losc_en) { + val &= ~SUN6I_LOSC_CTRL_EXT_LOSC_EN ; + val |= index ?SUN6I_LOSC_CTRL_EXT_LOSC_EN :0 ; + }drivers/rtc/rtc-sun6i.c +1
-0writel (val, rtc->base +SUN6I_LOSC_CTRL );spin_unlock_irqrestore (&rtc->lock, flags);@@ -215,6 +223,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, const char *iosc_name = "rtc-int-osc";const char *clkout_name ="osc32k-out" ;const char *parents[2 ]; +u32 reg;drivers/rtc/rtc-sun6i.c +0
-0rtc =kzalloc (sizeof (*rtc),GFP_KERNEL );if (!rtc)
Quoted 8 lines
Quoted 8 lines
drivers/rtc/rtc-sun6i.c static void __init sun6i_rtc_clk_init(struct · line 250
Quoted 8 lines
drivers/rtc/rtc-sun6i.c +3
-0@@ -235,9 +244,18 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, goto err; } + reg =SUN6I_LOSC_CTRL_KEY ; +if (rtc->data->has_auto_swt) { +/* Bypass auto-switch to int osc, on ext losc failure
*/
Quoted 62 lines
Quoted 62 lines
Quoted 53 lines
drivers/rtc/rtc-sun6i.c +8
-2+ reg |=SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL ); + } +/* Switch to the external, more precise, oscillator */ -writel (SUN6I_LOSC_CTRL_KEY |SUN6I_LOSC_CTRL_EXT_OSC , - rtc->base +SUN6I_LOSC_CTRL ); + reg |=SUN6I_LOSC_CTRL_EXT_OSC ; +if (rtc->data->has_losc_en) + reg |=SUN6I_LOSC_CTRL_EXT_LOSC_EN ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL );drivers/rtc/rtc-sun6i.c +17
-0/* Yes, I know, this is ugly. */ sun6i_rtc = rtc;@@ -345,6 +363,23 @@ CLK_OF_DECLARE_DRIVER(sun8i_h3_rtc_clk,"allwinner,sun8i-h3-rtc" ,CLK_OF_DECLARE_DRIVER (sun50i_h5_rtc_clk,"allwinner,sun50i-h5-rtc" , sun8i_h3_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun50i_h6_rtc_data = { + .rc_osc_rate =16000000 , + .fixed_prescaler =32 , + .has_prescaler =1 , + .has_out_clk =1 , + .export_iosc =1 , + .has_losc_en =1 , + .has_auto_swt =1 , +}; + +static void __init sun50i_h6_rtc_clk_init (struct device_node *node) +{ +sun6i_rtc_clk_init (node, &sun50i_h6_rtc_data); +} +CLK_OF_DECLARE_DRIVER (sun50i_h6_rtc_clk,"allwinner,sun50i-h6-rtc" , + sun50i_h6_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = {drivers/rtc/rtc-sun6i.c +1
-0.rc_osc_rate = 32000, .has_out_clk = 1,@@ -675,6 +710,7 @@ static const struct of_device_id sun6i_rtc_dt_ids[] = { { .compatible = "allwinner,sun8i-r40-rtc" }, { .compatible = "allwinner,sun8i-v3-rtc" }, { .compatible = "allwinner,sun50i-h5-rtc" }, + { .compatible = "allwinner,sun50i-h6-rtc" },Quoted 4 lines
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, sun6i_rtc_dt_ids);_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/2544007.NTLiB2pbcT%40jernej-laptop.
Re: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Quoted 51 lines · Jernej Škrabec
Dne sobota, 24. avgust 2019 ob 14:46:54 CEST je Ondřej Jirman napisal(a):
Quoted 6 lines
Hi,
Quoted 3 lines · Jernej Škrabec
Hi!
Dne torek, 20. avgust 2019 ob 17:19:33 CEST je megous-5qf/[email protected]
napisal(a):
Quoted 43 lines
Quoted 42 lines
Quoted 34 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences mostly in features that are not yet supported by this driver.
Some differences are already stated in the comments in existing code. One other difference is that H6 has extra bit in
LOSC_CTRL_REG, calledEXT_LOSC_ENto enable/disable external low speed crystal oscillator.It also has bit
EXT_LOSC_STAinLOSC_AUTO_SWT_STA_REG, to check whether external low speed oscillator is working correctly.This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clockH6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external oscillator fails. This is enabled by default. Disable it during probe.
Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>---
drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)drivers/rtc/rtc-sun6i.c +0
-0drivers/rtc/rtc-sun6i.c line 37
Quoted 6 lines
drivers/rtc/rtc-sun6i.c +1
-0@@ -32,9 +32,11 @@/* Control register */ #define SUN6I_LOSC_CTRL 0x0000#define SUN6I_LOSC_CTRL_KEY (0x16aa << 16) +#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS BIT(15)User manual says that above field is bit 14.
Quoted 6 lines
Quoted 1 line
See the previous discussion, this is from BSP.
I have two versions of BSP (don't ask me which) which have this set as bit 14 and changing this to 14 actually solves all my problems with LOSC (no more issues with setting RTC and HDMI-CEC works now - it uses LOSC as parent) on Tanix TX6 box.
Interesting. Is LOSC fed externally generated clock, or is it setup as a crystal oscillator on your board?
Anyway, see here:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.h?h=h6-4.9-bsp#n649
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n652
It would be nice to know what's really happening.
My output is:
[ 0.832252] sun6i-rtc 7000000.rtc: registered as rtc0 [ 0.832257] sun6i-rtc 7000000.rtc: RTC enabled [ 1.728968] sun6i-rtc 7000000.rtc: setting system clock to 1970-01-01T00:00:07 UTC (7)
I think, you may have just enabled the auto switch feature, and running the clock from low precision RC oscillator with your patch.
The real issue probably is that the mainline driver is missing this:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n650
regards,
o.
Quoted 138 lines
Best regards,
JernejQuoted 55 lines
regards,
o.Quoted 51 lines
Best regards,
JernejQuoted 48 lines
drivers/rtc/rtc-sun6i.c +1
-0#define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9)#define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUN6I_LOSC_CTRL_EXT_LOSC_EN BIT(4)#define
SUN6I_LOSC_CTRL_EXT_OSCBIT(0)
#defineSUN6I_LOSC_CTRL_ACC_MASKGENMASK(9, 7)drivers/rtc/rtc-sun6i.c +2
-0@@ -128,6 +130,8 @@ struct sun6i_rtc_clk_data { unsigned int has_prescaler : 1; unsigned int has_out_clk : 1; unsigned int export_iosc : 1; + unsigned int has_losc_en : 1; + unsigned int has_auto_swt : 1;};
struct
sun6i_rtc_dev{drivers/rtc/rtc-sun6i.c +4
-0@@ -190,6 +194,10 @@ static int sun6i_rtc_osc_set_parent(struct clk_hw *hw, u8 index) val &= ~SUN6I_LOSC_CTRL_EXT_OSC; val |=SUN6I_LOSC_CTRL_KEY ; val |= index ?SUN6I_LOSC_CTRL_EXT_OSC :0 ; +if (rtc->data->has_losc_en) { + val &= ~SUN6I_LOSC_CTRL_EXT_LOSC_EN ; + val |= index ?SUN6I_LOSC_CTRL_EXT_LOSC_EN :0 ; + }drivers/rtc/rtc-sun6i.c +1
-0writel (val, rtc->base +SUN6I_LOSC_CTRL );spin_unlock_irqrestore (&rtc->lock, flags);@@ -215,6 +223,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, const char *iosc_name = "rtc-int-osc";const char *clkout_name ="osc32k-out" ;const char *parents[2 ]; +u32 reg;drivers/rtc/rtc-sun6i.c +0
-0rtc =kzalloc (sizeof (*rtc),GFP_KERNEL );if (!rtc)Quoted 8 lines
Quoted 8 lines
drivers/rtc/rtc-sun6i.c static void __init sun6i_rtc_clk_init(struct · line 250
Quoted 8 lines
drivers/rtc/rtc-sun6i.c +3
-0@@ -235,9 +244,18 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, goto err; } + reg =SUN6I_LOSC_CTRL_KEY ; +if (rtc->data->has_auto_swt) { +/* Bypass auto-switch to int osc, on ext losc failure */
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
drivers/rtc/rtc-sun6i.c +8
-2+ reg |=SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL ); + } +/* Switch to the external, more precise, oscillator */ -writel (SUN6I_LOSC_CTRL_KEY |SUN6I_LOSC_CTRL_EXT_OSC , - rtc->base +SUN6I_LOSC_CTRL ); + reg |=SUN6I_LOSC_CTRL_EXT_OSC ; +if (rtc->data->has_losc_en) + reg |=SUN6I_LOSC_CTRL_EXT_LOSC_EN ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL );drivers/rtc/rtc-sun6i.c +17
-0/* Yes, I know, this is ugly. */ sun6i_rtc = rtc;@@ -345,6 +363,23 @@ CLK_OF_DECLARE_DRIVER(sun8i_h3_rtc_clk,"allwinner,sun8i-h3-rtc" ,CLK_OF_DECLARE_DRIVER (sun50i_h5_rtc_clk,"allwinner,sun50i-h5-rtc" , sun8i_h3_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun50i_h6_rtc_data = { + .rc_osc_rate =16000000 , + .fixed_prescaler =32 , + .has_prescaler =1 , + .has_out_clk =1 , + .export_iosc =1 , + .has_losc_en =1 , + .has_auto_swt =1 , +}; + +static void __init sun50i_h6_rtc_clk_init (struct device_node *node) +{ +sun6i_rtc_clk_init (node, &sun50i_h6_rtc_data); +} +CLK_OF_DECLARE_DRIVER (sun50i_h6_rtc_clk,"allwinner,sun50i-h6-rtc" , + sun50i_h6_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = {drivers/rtc/rtc-sun6i.c +1
-0.rc_osc_rate = 32000, .has_out_clk = 1,@@ -675,6 +710,7 @@ static const struct of_device_id sun6i_rtc_dt_ids[] = { { .compatible = "allwinner,sun8i-r40-rtc" }, { .compatible = "allwinner,sun8i-v3-rtc" }, { .compatible = "allwinner,sun50i-h5-rtc" }, + { .compatible = "allwinner,sun50i-h6-rtc" },{ /* sentinel */ },
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
};
MODULE_DEVICE_TABLE(of, sun6i_rtc_dt_ids);_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20190824130544.kxypq3siv7kffidp%40core.my.home.
Jernej Škrabec
maintainerRe: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Dne sobota, 24. avgust 2019 ob 15:05:44 CEST je Ondřej Jirman napisal(a):
Quoted 50 lines · Jernej Škrabec
Quoted 49 lines
Dne sobota, 24. avgust 2019 ob 14:46:54 CEST je Ondřej Jirman napisal(a):
Quoted 6 lines
Hi,
Quoted 3 lines · Jernej Škrabec
Hi!
Dne torek, 20. avgust 2019 ob 17:19:33 CEST je megous-5qf/[email protected]
napisal(a):
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences
mostly in features that are not yet supported by this driver.Some differences are already stated in the comments in existing code.
One other difference is that H6 has extra bit inLOSC_CTRL_REG, calledEXT_LOSC_ENto enable/disable external low speed crystal oscillator.It also has bit
EXT_LOSC_STAinLOSC_AUTO_SWT_STA_REG, to check whether
external low speed oscillator is working correctly.This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clockH6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external oscillator fails. This is enabled by default. Disable it during probe.
Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>---
drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)drivers/rtc/rtc-sun6i.c +0
-0@@ -32,9 +32,11 @@
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/rtc/rtc-sun6i.c
Quoted 3 lines
drivers/rtc/rtc-sun6i.c +0
-0/* Control register */ #define SUN6I_LOSC_CTRL 0x0000#define SUN6I_LOSC_CTRL_KEY (0x16aa
<< 16)
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
drivers/rtc/rtc-sun6i.c line 35
Quoted 2 lines
drivers/rtc/rtc-sun6i.c +1
-0+#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS BIT(15)User manual says that above field is bit 14.
See the previous discussion, this is from BSP.
Quoted 7 lines
Quoted 4 lines
I have two versions of BSP (don't ask me which) which have this set as bit 14 and changing this to 14 actually solves all my problems with LOSC (no more issues with setting RTC and HDMI-CEC works now - it uses LOSC as parent) on Tanix TX6 box.
Interesting. Is LOSC fed externally generated clock, or is it setup as a crystal oscillator on your board?
I really don't know, but here is DT: http://ix.io/1ThI
Quoted 5 lines
Anyway, see here:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.h?h=h6-4.9-bsp#n649
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n652
Interesting, 4.9 BSP has additional bit definition, which is not documented in manual and 3.10 BSP to which I refer.
I was referring to 3.10 BSP, which uses only bit 14. I thought that you named it differently.
Quoted 9 lines
It would be nice to know what's really happening.
My output is:
[ 0.832252] sun6i-rtc 7000000.rtc: registered as rtc0 [ 0.832257] sun6i-rtc 7000000.rtc: RTC enabled [ 1.728968] sun6i-rtc 7000000.rtc: setting system clock to 1970-01-01T00:00:07 UTC (7)
With change, I get same output.
Quoted 3 lines
I think, you may have just enabled the auto switch feature, and running the clock from low precision RC oscillator with your patch.
True, now I think there is no external crystal, but I'm still not sure how to confirm that.
Quoted 5 lines
The real issue probably is that the mainline driver is missing this:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n650
Not sure what you mean by that. ext vs. int source selection?
Best regards,
Jernej
Quoted 141 lines
regards,
o.Quoted 138 lines
Best regards,
JernejQuoted 56 lines
regards,
o.Quoted 52 lines
Best regards,
JernejQuoted 49 lines
drivers/rtc/rtc-sun6i.c +1
-0#define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9)#define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUN6I_LOSC_CTRL_EXT_LOSC_EN BIT(4)#define
SUN6I_LOSC_CTRL_EXT_OSCBIT(0)
#defineSUN6I_LOSC_CTRL_ACC_MASKGENMASK(9, 7)drivers/rtc/rtc-sun6i.c +2
-0@@ -128,6 +130,8 @@ struct sun6i_rtc_clk_data { unsigned int has_prescaler : 1; unsigned int has_out_clk : 1; unsigned int export_iosc : 1; + unsigned int has_losc_en : 1; + unsigned int has_auto_swt : 1;};
struct
sun6i_rtc_dev{drivers/rtc/rtc-sun6i.c +0
-0@@ -190,6 +194,10 @@ static int sun6i_rtc_osc_set_parent(struct
clk_hw
*hw,
u8 index) val &= ~SUN6I_LOSC_CTRL_EXT_OSC;drivers/rtc/rtc-sun6i.c +5
-0val |=SUN6I_LOSC_CTRL_KEY ; val |= index ?SUN6I_LOSC_CTRL_EXT_OSC :0 ; +if (rtc->data->has_losc_en) { + val &= ~SUN6I_LOSC_CTRL_EXT_LOSC_EN ; + val |= index ?SUN6I_LOSC_CTRL_EXT_LOSC_EN :0 ; + }writel (val, rtc->base +SUN6I_LOSC_CTRL );spin_unlock_irqrestore (&rtc->lock, flags);@@ -215,6 +223,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, const char *iosc_name = "rtc-int-osc";const char *clkout_name ="osc32k-out" ;const char *parents[2 ]; +u32 reg;drivers/rtc/rtc-sun6i.c +0
-0rtc =kzalloc (sizeof (*rtc),GFP_KERNEL );if (!rtc)Quoted 8 lines
Quoted 8 lines
drivers/rtc/rtc-sun6i.c static void __init sun6i_rtc_clk_init(struct · line 250
Quoted 8 lines
drivers/rtc/rtc-sun6i.c +3
-0@@ -235,9 +244,18 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, goto err; } + reg =SUN6I_LOSC_CTRL_KEY ; +if (rtc->data->has_auto_swt) { +/* Bypass auto-switch to int osc, on ext losc failure */
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines
drivers/rtc/rtc-sun6i.c +8
-2+ reg |=SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL ); + } +/* Switch to the external, more precise, oscillator */ -writel (SUN6I_LOSC_CTRL_KEY |SUN6I_LOSC_CTRL_EXT_OSC , - rtc->base +SUN6I_LOSC_CTRL ); + reg |=SUN6I_LOSC_CTRL_EXT_OSC ; +if (rtc->data->has_losc_en) + reg |=SUN6I_LOSC_CTRL_EXT_LOSC_EN ; +writel (reg, rtc->base +SUN6I_LOSC_CTRL );drivers/rtc/rtc-sun6i.c +17
-0/* Yes, I know, this is ugly. */ sun6i_rtc = rtc;@@ -345,6 +363,23 @@ CLK_OF_DECLARE_DRIVER(sun8i_h3_rtc_clk,"allwinner,sun8i-h3-rtc" ,CLK_OF_DECLARE_DRIVER (sun50i_h5_rtc_clk,"allwinner,sun50i-h5-rtc" , sun8i_h3_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun50i_h6_rtc_data = { + .rc_osc_rate =16000000 , + .fixed_prescaler =32 , + .has_prescaler =1 , + .has_out_clk =1 , + .export_iosc =1 , + .has_losc_en =1 , + .has_auto_swt =1 , +}; + +static void __init sun50i_h6_rtc_clk_init (struct device_node *node) +{ +sun6i_rtc_clk_init (node, &sun50i_h6_rtc_data); +} +CLK_OF_DECLARE_DRIVER (sun50i_h6_rtc_clk,"allwinner,sun50i-h6-rtc" , + sun50i_h6_rtc_clk_init); +static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = {drivers/rtc/rtc-sun6i.c +0
-0.rc_osc_rate = 32000, .has_out_clk = 1,@@ -675,6 +710,7 @@ static const struct of_device_idsun6i_rtc_dt_ids[]
= {drivers/rtc/rtc-sun6i.c +1
-0{ .compatible = "allwinner,sun8i-r40-rtc" }, { .compatible = "allwinner,sun8i-v3-rtc" }, { .compatible = "allwinner,sun50i-h5-rtc" }, + { .compatible = "allwinner,sun50i-h6-rtc" }, { /* sentinel */ },Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
};
MODULE_DEVICE_TABLE(of, sun6i_rtc_dt_ids);_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/10880274.nteIY8W56H%40jernej-laptop.
Re: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Quoted 94 lines · Jernej Škrabec
Dne sobota, 24. avgust 2019 ob 15:05:44 CEST je Ondřej Jirman napisal(a):
Quoted 50 lines · Jernej Škrabec
Quoted 49 lines
Dne sobota, 24. avgust 2019 ob 14:46:54 CEST je Ondřej Jirman napisal(a):
Quoted 6 lines
Hi,
Quoted 3 lines · Jernej Škrabec
Hi!
Dne torek, 20. avgust 2019 ob 17:19:33 CEST je megous-5qf/[email protected]
napisal(a):
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences
mostly in features that are not yet supported by this driver.Some differences are already stated in the comments in existing code.
One other difference is that H6 has extra bit inLOSC_CTRL_REG, calledEXT_LOSC_ENto enable/disable external low speed crystal oscillator.It also has bit
EXT_LOSC_STAinLOSC_AUTO_SWT_STA_REG, to check whether
external low speed oscillator is working correctly.This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clockH6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external oscillator fails. This is enabled by default. Disable it during probe.
Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>---
drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)drivers/rtc/rtc-sun6i.c +0
-0@@ -32,9 +32,11 @@Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/rtc/rtc-sun6i.c
Quoted 3 lines
drivers/rtc/rtc-sun6i.c +0
-0/* Control register */ #define SUN6I_LOSC_CTRL 0x0000#define SUN6I_LOSC_CTRL_KEY (0x16aa<< 16)
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
drivers/rtc/rtc-sun6i.c line 35
Quoted 2 lines
drivers/rtc/rtc-sun6i.c +1
-0+#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS BIT(15)User manual says that above field is bit 14.
See the previous discussion, this is from BSP.
Quoted 7 lines
Quoted 4 lines
I have two versions of BSP (don't ask me which) which have this set as bit 14 and changing this to 14 actually solves all my problems with LOSC (no more issues with setting RTC and HDMI-CEC works now - it uses LOSC as parent) on Tanix TX6 box.
Interesting. Is LOSC fed externally generated clock, or is it setup as a crystal oscillator on your board?
I really don't know, but here is DT: http://ix.io/1ThI
Quoted 5 lines
Anyway, see here:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.h?h=h6-4.9-bsp#n649
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n652Interesting, 4.9 BSP has additional bit definition, which is not documented in manual and 3.10 BSP to which I refer.
I was referring to 3.10 BSP, which uses only bit 14. I thought that you named it differently.
Quoted 9 lines
It would be nice to know what's really happening.
My output is:
[ 0.832252] sun6i-rtc 7000000.rtc: registered as rtc0 [ 0.832257] sun6i-rtc 7000000.rtc: RTC enabled [ 1.728968] sun6i-rtc 7000000.rtc: setting system clock to 1970-01-01T00:00:07 UTC (7)
Quoted 8 lines
With change, I get same output.
Quoted 3 lines
I think, you may have just enabled the auto switch feature, and running the clock from low precision RC oscillator with your patch.
True, now I think there is no external crystal, but I'm still not sure how to confirm that.
Visually?
That would explain why it doesn't work for you. The mainline RTC driver disables auto-switch feature, and if your board doesn't have a crystal for LOSC, RTC will not generate a clock for the RTC.
H6's dtsi describes by default a situatiuon with external 32k crystal oscillator. See ext_osc32k node. That's incorrect for your board if it doesn't have the crystal. You need to fix this in the DTS for your board instead of patching the driver.
The driver has parent clock selection logic in case the LOSC crystal is not used.
Your patch enables automatic detection of LOSC failure and RTC changes clock to LOSC automatically, despite what's described in the DTS. That may fix the issue, but is not the correct solution.
Registers on my board look like this (external 32k osc is used) for reference:
LOSC_CTRL_REG[7000000]: 8011
KEY_FIELD ??? (0) LOSC_AUTO_SWT_BYPASS EN (1) LOSC_AUTO_SWT_EN DIS (0) EXT_LOSC_EN EN (1) EXT_LOSC_GSM LOW (0) BATTERY_DIR DISCHARGE (0) LOSC_SRC_SEL EXT32k (1)
LOSC_AUTO_SWT_STA_REG[7000004]: 1
EXT_LOSC_STA OK (0) LOSC_AUTO_SWT_PEND NOEFF (0) LOSC_SRC_SEL_STA EXT32K (1)
regards,
o.
Quoted 15 lines
Quoted 5 lines
The real issue probably is that the mainline driver is missing this:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n650
Not sure what you mean by that. ext vs. int source selection?
Best regards,
JernejQuoted 2 lines
regards,
o.
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20190824133057.rhpj3xuzr3vymdiy%40core.my.home.
Jernej Škrabec
maintainerRe: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Dne sobota, 24. avgust 2019 ob 15:30:57 CEST je Ondřej Jirman napisal(a):
Quoted 4 lines · Jernej Škrabec
Quoted 3 lines
Dne sobota, 24. avgust 2019 ob 15:05:44 CEST je Ondřej Jirman napisal(a):
Quoted 2 lines · Jernej Škrabec
Quoted 1 line
Dne sobota, 24. avgust 2019 ob 14:46:54 CEST je Ondřej Jirman
napisal(a):
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
Quoted 6 lines
Hi,
Quoted 3 lines · Jernej Škrabec
Hi!
Dne torek, 20. avgust 2019 ob 17:19:33 CEST je megous-5qf/[email protected]
napisal(a):
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
RTC on H6 is mostly the same as on H5 and H3. It has slight differences
mostly in features that are not yet supported by this driver.Some differences are already stated in the comments in existing code.
One other difference is that H6 has extra bit inLOSC_CTRL_REG, calledEXT_LOSC_ENto enable/disable external low speed crystal oscillator.It also has bit
EXT_LOSC_STAinLOSC_AUTO_SWT_STA_REG, to check whether
external low speed oscillator is working correctly.This patch adds support for enabling LOSC when necessary:
- during reparenting
- when probing the clockH6 also has capacbility to automatically reparent RTC clock from external crystal oscillator, to internal RC oscillator, if external
oscillator fails. This is enabled by default. Disable it during probe.Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>---
drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/rtc/rtc-sun6i.c line 34
Quoted 8 lines
drivers/rtc/rtc-sun6i.c +0
-0@@ -32,9 +32,11 @@/* Control register */ #define SUN6I_LOSC_CTRL
0x0000
Quoted 55 lines
Quoted 44 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/rtc/rtc-sun6i.c line 35
Quoted 1 line
drivers/rtc/rtc-sun6i.c +0
-0#define SUN6I_LOSC_CTRL_KEY (0x16aa<< 16)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
drivers/rtc/rtc-sun6i.c line 36
Quoted 1 line
drivers/rtc/rtc-sun6i.c +1
-0+#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS BIT(15)User manual says that above field is bit 14.
Quoted 8 lines
Quoted 1 line
See the previous discussion, this is from BSP.
I have two versions of BSP (don't ask me which) which have this set as bit
14 and changing this to 14 actually solves all my problems with LOSC (no
more issues with setting RTC and HDMI-CEC works now - it uses LOSC as parent) on Tanix TX6 box.Quoted 2 lines
Interesting. Is LOSC fed externally generated clock, or is it setup as a crystal oscillator on your board?
I really don't know, but here is DT: http://ix.io/1ThI
Quoted 6 lines
Anyway, see here:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.h?h=h6-4.9-bsp#n
649
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n
652Interesting, 4.9 BSP has additional bit definition, which is not documented in manual and 3.10 BSP to which I refer.
I was referring to 3.10 BSP, which uses only bit 14. I thought that you named it differently.
Quoted 8 lines
It would be nice to know what's really happening.
My output is:
[ 0.832252] sun6i-rtc 7000000.rtc: registered as rtc0 [ 0.832257] sun6i-rtc 7000000.rtc: RTC enabled [ 1.728968] sun6i-rtc 7000000.rtc: setting system clock to 1970-01-01T00:00:07 UTC (7)Quoted 8 lines
With change, I get same output.
Quoted 3 lines
I think, you may have just enabled the auto switch feature, and running the
clock from low precision RC oscillator with your patch.True, now I think there is no external crystal, but I'm still not sure how to confirm that.
Visually?
Quoted 8 lines
That would explain why it doesn't work for you. The mainline RTC driver disables auto-switch feature, and if your board doesn't have a crystal for LOSC, RTC will not generate a clock for the RTC.
H6's dtsi describes by default a situatiuon with external 32k crystal oscillator. See
ext_osc32knode. That's incorrect for your board if it doesn't have the crystal. You need to fix this in the DTS for your board instead of patching the driver.
I see that reparenting is supported, but I'm not sure how to fix that in DT. Any suggestion?
Quoted 20 lines
The driver has parent clock selection logic in case the LOSC crystal is not used.
Your patch enables automatic detection of LOSC failure and RTC changes clock to LOSC automatically, despite what's described in the DTS. That may fix the issue, but is not the correct solution.
Registers on my board look like this (external 32k osc is used) for reference:
LOSC_CTRL_REG[7000000]: 8011
KEY_FIELD ??? (0) LOSC_AUTO_SWT_BYPASS EN (1) LOSC_AUTO_SWT_EN DIS (0) EXT_LOSC_EN EN (1) EXT_LOSC_GSM LOW (0) BATTERY_DIR DISCHARGE (0) LOSC_SRC_SEL EXT32k (1)
Quoted 5 lines
LOSC_AUTO_SWT_STA_REG[7000004]: 1
EXT_LOSC_STA OK (0) LOSC_AUTO_SWT_PEND NOEFF (0) LOSC_SRC_SEL_STA EXT32K (1)
In my case LOSC_CTRL_REG has value 0x4010 and LOSC_AUTO_SWT_STA_REG has value 0x4, so there is issue with external crystal (it's missing) and RTC switched to internal one.
BTW, what's wrong with automatic switching? Why is it disabled?
Best regards,
Jernej
Quoted 18 lines
regards,
o.Quoted 15 lines
Quoted 4 lines
The real issue probably is that the mainline driver is missing this:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n
650Not sure what you mean by that. ext vs. int source selection?
Best regards,
JernejQuoted 3 lines
regards,
o.
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/1690798.2HKiRSsjat%40jernej-laptop.
Re: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Hello Jernej,
Quoted 6 lines · Jernej Škrabec
Quoted 6 lines
Visually?
That would explain why it doesn't work for you. The mainline RTC driver disables auto-switch feature, and if your board doesn't have a crystal for LOSC, RTC will not generate a clock for the RTC.
Quoted 7 lines
Quoted 4 lines
H6's dtsi describes by default a situatiuon with external 32k crystal oscillator. See
ext_osc32knode. That's incorrect for your board if it doesn't have the crystal. You need to fix this in the DTS for your board instead of patching the driver.I see that reparenting is supported, but I'm not sure how to fix that in DT. Any suggestion?
You may try removing the clocks property from rtc node.
Quoted 26 lines
Quoted 20 lines
The driver has parent clock selection logic in case the LOSC crystal is not used.
Your patch enables automatic detection of LOSC failure and RTC changes clock to LOSC automatically, despite what's described in the DTS. That may fix the issue, but is not the correct solution.
Registers on my board look like this (external 32k osc is used) for reference:
LOSC_CTRL_REG[7000000]: 8011
KEY_FIELD ??? (0) LOSC_AUTO_SWT_BYPASS EN (1) LOSC_AUTO_SWT_EN DIS (0) EXT_LOSC_EN EN (1) EXT_LOSC_GSM LOW (0) BATTERY_DIR DISCHARGE (0) LOSC_SRC_SEL EXT32k (1)Quoted 5 lines
LOSC_AUTO_SWT_STA_REG[7000004]: 1
EXT_LOSC_STA OK (0) LOSC_AUTO_SWT_PEND NOEFF (0) LOSC_SRC_SEL_STA EXT32K (1)
Quoted 5 lines
In my case
LOSC_CTRL_REGhas value0x4010andLOSC_AUTO_SWT_STA_REGhas value0x4, so there is issue with external crystal (it's missing) and RTC switched to internal one.BTW, what's wrong with automatic switching? Why is it disabled?
It always was disabled on mainline (bit 14 was set to 0 even before my patch). H6 just probably has another extra undocummented bit, that's needed to disables it properly.
You probably don't want a glitch to switch your RTC from high-precision clock to a low precision one possibly without any indication in the userspace or a kernel log.
Regardless of all this, DTS needs to have a correct description of the HW, which means if RTC module is not connected to the 32.757kHz crystal/clock, clocks property should be empty.
regards,
o.
Quoted 25 lines
Best regards,
JernejQuoted 18 lines
regards,
o.Quoted 15 lines
Quoted 4 lines
The real issue probably is that the mainline driver is missing this:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-bsp#n
650Not sure what you mean by that. ext vs. int source selection?
Best regards,
JernejQuoted 3 lines
regards,
o.
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20190824212746.a5pyilkrrvysjjbd%40core.my.home.
Jernej Škrabec
maintainerRe: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Dne sobota, 24. avgust 2019 ob 23:27:46 CEST je Ondřej Jirman napisal(a):
Quoted 15 lines
Hello Jernej,
Quoted 12 lines · Jernej Škrabec
Quoted 11 lines
Visually?
That would explain why it doesn't work for you. The mainline RTC driver disables auto-switch feature, and if your board doesn't have a crystal for
LOSC, RTC will not generate a clock for the RTC.H6's dtsi describes by default a situatiuon with external 32k crystal oscillator. See
ext_osc32knode. That's incorrect for your board if it doesn't have the crystal. You need to fix this in the DTS for your board instead of patching the driver.
Quoted 4 lines
Quoted 2 lines
I see that reparenting is supported, but I'm not sure how to fix that in DT. Any suggestion?
You may try removing the clocks property from rtc node.
I don't think this would work:
https://elixir.bootlin.com/linux/latest/source/drivers/rtc/rtc-sun6i.c#L246
Quoted 38 lines
Quoted 28 lines
Quoted 22 lines
The driver has parent clock selection logic in case the LOSC crystal is not
used.Your patch enables automatic detection of LOSC failure and RTC changes clock to LOSC automatically, despite what's described in the DTS. That may fix the issue, but is not the correct solution.
Registers on my board look like this (external 32k osc is used) for reference:
LOSC_CTRL_REG[7000000]: 8011
KEY_FIELD ??? (0) LOSC_AUTO_SWT_BYPASS EN (1) LOSC_AUTO_SWT_EN DIS (0) EXT_LOSC_EN EN (1) EXT_LOSC_GSM LOW (0) BATTERY_DIR DISCHARGE (0) LOSC_SRC_SEL EXT32k (1)Quoted 5 lines
LOSC_AUTO_SWT_STA_REG[7000004]: 1
EXT_LOSC_STA OK (0) LOSC_AUTO_SWT_PEND NOEFF (0) LOSC_SRC_SEL_STA EXT32K (1)Quoted 5 lines
In my case
LOSC_CTRL_REGhas value0x4010andLOSC_AUTO_SWT_STA_REGhas value0x4, so there is issue with external crystal (it's missing) and RTC switched to internal one.BTW, what's wrong with automatic switching? Why is it disabled?
It always was disabled on mainline (bit 14 was set to 0 even before my patch). H6 just probably has another extra undocummented bit, that's needed to disables it properly.
Quoted 7 lines
You probably don't want a glitch to switch your RTC from high-precision clock to a low precision one possibly without any indication in the userspace or a kernel log.
Regardless of all this, DTS needs to have a correct description of the HW, which means if RTC module is not connected to the 32.757kHz crystal/clock, clocks property should be empty.
If we are talking about correct HW description, then clock property should actually have possibility that two clocks are defined - one for internal RC (always present) and one external crystal (optional). In such case I could really just omit external clock and be done with it. But I'm not sure if such solution is acceptable at this point.
Best regards,
Jernej
Quoted 27 lines
regards,
o.Quoted 23 lines
Best regards,
JernejQuoted 20 lines
regards,
o.Quoted 16 lines
Quoted 5 lines
The real issue probably is that the mainline driver is missing this:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-b
sp#n
650Not sure what you mean by that. ext vs. int source selection?
Best regards,
JernejQuoted 3 lines
regards,
o.
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/7913281.jYEbquIlsS%40jernej-laptop.
Re: [linux-sunxi] [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Quoted 16 lines · Jernej Škrabec
Dne sobota, 24. avgust 2019 ob 23:27:46 CEST je Ondřej Jirman napisal(a):
Quoted 15 lines
Hello Jernej,
Quoted 12 lines · Jernej Škrabec
Quoted 11 lines
Visually?
That would explain why it doesn't work for you. The mainline RTC driver disables auto-switch feature, and if your board doesn't have a crystal for
LOSC, RTC will not generate a clock for the RTC.H6's dtsi describes by default a situatiuon with external 32k crystal oscillator. See
ext_osc32knode. That's incorrect for your board if it doesn't have the crystal. You need to fix this in the DTS for your board instead of patching the driver.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I see that reparenting is supported, but I'm not sure how to fix that in DT. Any suggestion?
You may try removing the clocks property from rtc node.
I don't think this would work:
https://elixir.bootlin.com/linux/latest/source/drivers/rtc/rtc-sun6i.c#L246
Well, I don't know. There has to be some way to make it work, since the code deals with it here:
https://elixir.bootlin.com/linux/latest/source/drivers/rtc/rtc-sun6i.c#L270
Number of parents for LOSC is calculated from the DT somehow. Maybne something to do with the #clock-cells property?
Sorry I can't be of more help here.
Quoted 42 lines
Quoted 42 lines
Quoted 28 lines
Quoted 22 lines
The driver has parent clock selection logic in case the LOSC crystal is not
used.Your patch enables automatic detection of LOSC failure and RTC changes clock to LOSC automatically, despite what's described in the DTS. That may fix the issue, but is not the correct solution.
Registers on my board look like this (external 32k osc is used) for reference:
LOSC_CTRL_REG[7000000]: 8011
KEY_FIELD ??? (0) LOSC_AUTO_SWT_BYPASS EN (1) LOSC_AUTO_SWT_EN DIS (0) EXT_LOSC_EN EN (1) EXT_LOSC_GSM LOW (0) BATTERY_DIR DISCHARGE (0) LOSC_SRC_SEL EXT32k (1)Quoted 5 lines
LOSC_AUTO_SWT_STA_REG[7000004]: 1
EXT_LOSC_STA OK (0) LOSC_AUTO_SWT_PEND NOEFF (0) LOSC_SRC_SEL_STA EXT32K (1)Quoted 5 lines
In my case
LOSC_CTRL_REGhas value0x4010andLOSC_AUTO_SWT_STA_REGhas value0x4, so there is issue with external crystal (it's missing) and RTC switched to internal one.BTW, what's wrong with automatic switching? Why is it disabled?
It always was disabled on mainline (bit 14 was set to 0 even before my patch). H6 just probably has another extra undocummented bit, that's needed to disables it properly.
You probably don't want a glitch to switch your RTC from high-precision clock to a low precision one possibly without any indication in the userspace or a kernel log.
Quoted 8 lines
Quoted 3 lines
Regardless of all this, DTS needs to have a correct description of the HW, which means if RTC module is not connected to the 32.757kHz crystal/clock, clocks property should be empty.
If we are talking about correct HW description, then clock property should actually have possibility that two clocks are defined - one for internal RC (always present) and one external crystal (optional). In such case I could really just omit external clock and be done with it. But I'm not sure if such
Internal RC is thought to be part of the RTC module, so it's not defined as an input clock to the RTC module.
regards,
Ondrej
Quoted 35 lines
Best regards,
JernejQuoted 27 lines
regards,
o.Quoted 23 lines
Best regards,
JernejQuoted 20 lines
regards,
o.Quoted 16 lines
Quoted 5 lines
The real issue probably is that the mainline driver is missing this:
https://megous.com/git/linux/tree/drivers/rtc/rtc-sunxi.c?h=h6-4.9-b
sp#n
650Not sure what you mean by that. ext vs. int source selection?
Best regards,
JernejQuoted 3 lines
regards,
o.
PATCH v2 3/3 arm64: dts: sun50i-h6: Add support for RTC and fix the clock tree
In reply to [email protected]From: Ondrej Jirman <megous-5qf/[email protected]>
This patch adds RTC node and fixes the clock properties and nodes to reflect the real clock tree.
The device nodes for the internal oscillator and osc32k are removed, as these clocks are now provided by the RTC device. Clock references are fixed accordingly, too.
--- arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-)
arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi +16 -14
@@ -56,14 +56,6 @@ status = "disabled"; }; - iosc: internal-osc-clk { - #clock-cells = <0>; - compatible = "fixed-clock"; - clock-frequency = <16000000>; - clock-accuracy = <300000000>; - clock-output-names = "iosc"; - }; - osc24M: osc24M_clk { #clock-cells = <0>; compatible = "fixed-clock";
@@ -71,11 +63,11 @@ clock-output-names = "osc24M"; }; - osc32k: osc32k_clk { + ext_osc32k: ext_osc32k_clk { #clock-cells = <0>; compatible = "fixed-clock"; clock-frequency = <32768>; - clock-output-names = "osc32k"; + clock-output-names = "ext_osc32k"; }; psci {
@@ -197,7 +189,7 @@ ccu: clock@3001000 { compatible = "allwinner,sun50i-h6-ccu"; reg = <0x03001000 0x1000>; - clocks = <&osc24M>, <&osc32k>, <&iosc>; + clocks = <&osc24M>, <&rtc 0>, <&rtc 2>; clock-names = "hosc", "losc", "iosc"; #clock-cells = <1>; #reset-cells = <1>;
@@ -236,7 +228,7 @@ <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI 54 IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>; - clocks = <&ccu CLK_APB1>, <&osc24M>, <&osc32k>; + clocks = <&ccu CLK_APB1>, <&osc24M>, <&rtc 0>; clock-names = "apb", "hosc", "losc"; gpio-controller; #gpio-cells = <3>;
@@ -710,10 +702,20 @@ }; }; + rtc: rtc@7000000 { + compatible = "allwinner,sun50i-h6-rtc"; + reg = <0x07000000 0x400>; + interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>; + clock-output-names = "osc32k", "osc32k-out", "iosc"; + clocks = <&ext_osc32k>; + #clock-cells = <1>; + }; + r_ccu: clock@7010000 { compatible = "allwinner,sun50i-h6-r-ccu"; reg = <0x07010000 0x400>; - clocks = <&osc24M>, <&osc32k>, <&iosc>, + clocks = <&osc24M>, <&rtc 0>, <&rtc 2>, <&ccu CLK_PLL_PERIPH0>; clock-names = "hosc", "losc", "iosc", "pll-periph"; #clock-cells = <1>;
@@ -741,7 +743,7 @@ reg = <0x07022000 0x400>; interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI 111 IRQ_TYPE_LEVEL_HIGH>; - clocks = <&r_ccu CLK_R_APB1>, <&osc24M>, <&osc32k>; + clocks = <&r_ccu CLK_R_APB1>, <&osc24M>, <&rtc 0>; clock-names = "apb", "hosc", "losc"; gpio-controller; #gpio-cells = <3>;
Signature · 1 line
2.22.1
Re: [PATCH v2 3/3] arm64: dts: sun50i-h6: Add support for RTC and fix the clock tree
Quoted 10 lines · On Tue, Aug 20, 2019 at 05:19:34PM +0200…
From: Ondrej Jirman <megous-5qf/[email protected]>
This patch adds RTC node and fixes the clock properties and nodes to reflect the real clock tree.
The device nodes for the internal oscillator and osc32k are removed, as these clocks are now provided by the RTC device. Clock references are fixed accordingly, too.
Signed-off-by Ondrej Jirman <megous-5qf/[email protected]>
The prefix should be "arm64: dts: allwinner: h6:"
I've fixed it up and applied it.
Maxime
--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Jernej Škrabec
maintainerHi!
Dne torek, 20. avgust 2019 ob 17:19:31 CEST je megous-5qf/[email protected] napisal(a):
Quoted 18 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
I went through the datasheets for H6 and H5, and compared the differences. RTCs are largely similar, but not entirely compatible. Incompatibilities are in details not yet implemented by the rtc driver though.
I also corrected the clock tree in H6 DTSI.
This patchset is necessary for implementing the WiFi/Bluetooth support on boards using H6 SoC.
There was some discussion previously of describing HOSC, DCXO and XO oscillators and clocks as part of RTC in DT, but I decided against it because it's not necessary, becuse information that would be provided as a part of DT can already be determined at runtime from RTC registers, so this woudn't add any value and would only introduce complications to the driver. See: https://patchwork.kernel.org/cover/10898083/
Quoted 5 lines
Please take a look.
Thank you and regards,
Ondrej Jirman
Sorry for a bit late test, but with your patches on Tanix TX6 box I get this in dmesg:
[ 17.431742] sun6i-rtc 7000000.rtc: Failed to set rtc time. [ 20.439742] sun6i-rtc 7000000.rtc: rtc is still busy. [ 21.435744] sun6i-rtc 7000000.rtc: rtc is still busy. [ 24.055741] sun6i-rtc 7000000.rtc: rtc is still busy. [ 24.439752] sun6i-rtc 7000000.rtc: rtc is still busy.
Last line is repeated non-stop.
Any idea what could be wrong?
Best regards,
Jernej
Jernej Škrabec
maintainerDne sobota, 24. avgust 2019 ob 10:04:24 CEST je Jernej Škrabec napisal(a):
Quoted 37 lines
Hi!
Dne torek, 20. avgust 2019 ob 17:19:31 CEST je megous-5qf/[email protected] napisal(a):
Quoted 18 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
I went through the datasheets for H6 and H5, and compared the differences. RTCs are largely similar, but not entirely compatible. Incompatibilities are in details not yet implemented by the rtc driver though.
I also corrected the clock tree in H6 DTSI.
This patchset is necessary for implementing the WiFi/Bluetooth support on boards using H6 SoC.
There was some discussion previously of describing HOSC, DCXO and XO oscillators and clocks as part of RTC in DT, but I decided against it because it's not necessary, becuse information that would be provided as a part of DT can already be determined at runtime from RTC registers, so this woudn't add any value and would only introduce complications to the driver. See: https://patchwork.kernel.org/cover/10898083/
Quoted 6 lines
Please take a look.
Thank you and regards,
Ondrej Jirman
Sorry for a bit late test, but with your patches on Tanix TX6 box I get this in dmesg:
[ 17.431742] sun6i-rtc 7000000.rtc: Failed to set rtc time. [ 20.439742] sun6i-rtc 7000000.rtc: rtc is still busy. [ 21.435744] sun6i-rtc 7000000.rtc: rtc is still busy. [ 24.055741] sun6i-rtc 7000000.rtc: rtc is still busy. [ 24.439752] sun6i-rtc 7000000.rtc: rtc is still busy.
Quoted 3 lines
Last line is repeated non-stop.
Any idea what could be wrong?
Additional info - this is on kernel 5.2.6 with your patches applied.
Best regards,
Jernej
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/5421621.t8Lore9UF7%40jernej-laptop.
Hi,
Quoted 38 lines · Jernej Škrabec
Dne sobota, 24. avgust 2019 ob 10:04:24 CEST je Jernej Škrabec napisal(a):
Quoted 37 lines
Hi!
Dne torek, 20. avgust 2019 ob 17:19:31 CEST je megous-5qf/[email protected] napisal(a):
Quoted 18 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
I went through the datasheets for H6 and H5, and compared the differences. RTCs are largely similar, but not entirely compatible. Incompatibilities are in details not yet implemented by the rtc driver though.
I also corrected the clock tree in H6 DTSI.
This patchset is necessary for implementing the WiFi/Bluetooth support on boards using H6 SoC.
There was some discussion previously of describing HOSC, DCXO and XO oscillators and clocks as part of RTC in DT, but I decided against it because it's not necessary, becuse information that would be provided as a part of DT can already be determined at runtime from RTC registers, so this woudn't add any value and would only introduce complications to the driver. See: https://patchwork.kernel.org/cover/10898083/
Quoted 6 lines
Please take a look.
Thank you and regards,
Ondrej Jirman
Sorry for a bit late test, but with your patches on Tanix TX6 box I get this in dmesg:
[ 17.431742] sun6i-rtc 7000000.rtc: Failed to set rtc time. [ 20.439742] sun6i-rtc 7000000.rtc: rtc is still busy. [ 21.435744] sun6i-rtc 7000000.rtc: rtc is still busy. [ 24.055741] sun6i-rtc 7000000.rtc: rtc is still busy. [ 24.439752] sun6i-rtc 7000000.rtc: rtc is still busy.
Quoted 5 lines
Quoted 3 lines
Last line is repeated non-stop.
Any idea what could be wrong?
Additional info - this is on kernel 5.2.6 with your patches applied.
Do you have schematics, or a FEX file for the board or any other info on how the RTC is set up on that board?
Can you dump the RTC register range?
regards,
o.
Quoted 11 lines
Best regards,
Jernej_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20190824125612.zq5qsay2wv62wykt%40core.my.home.
Jernej Škrabec
maintainerDne sobota, 24. avgust 2019 ob 14:56:12 CEST je Ondřej Jirman napisal(a):
Quoted 7 lines
Hi,
Quoted 4 lines · Jernej Škrabec
Dne sobota, 24. avgust 2019 ob 10:04:24 CEST je Jernej Škrabec napisal(a):
Quoted 3 lines
Hi!
Dne torek, 20. avgust 2019 ob 17:19:31 CEST je megous-5qf/[email protected]
napisal(a):
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 21 lines
From: Ondrej Jirman <megous-5qf/[email protected]>
I went through the datasheets for H6 and H5, and compared the differences.
RTCs are largely similar, but not entirely compatible. Incompatibilities
are in details not yet implemented by the rtc driver though.I also corrected the clock tree in H6 DTSI.
This patchset is necessary for implementing the WiFi/Bluetooth support on boards using H6 SoC.
There was some discussion previously of describing HOSC, DCXO and XO oscillators and clocks as part of RTC in DT, but I decided against it because it's not necessary, becuse information that would be provided as a part of DT can already be determined at runtime from RTC registers,
so this woudn't add any value and would only introduce complications to the driver. See: https://patchwork.kernel.org/cover/10898083/Quoted 6 lines
Please take a look.
Thank you and regards,
Ondrej Jirman
Sorry for a bit late test, but with your patches on Tanix TX6 box I get this in dmesg:
[ 17.431742] sun6i-rtc 7000000.rtc: Failed to set rtc time. [ 20.439742] sun6i-rtc 7000000.rtc: rtc is still busy. [ 21.435744] sun6i-rtc 7000000.rtc: rtc is still busy. [ 24.055741] sun6i-rtc 7000000.rtc: rtc is still busy. [ 24.439752] sun6i-rtc 7000000.rtc: rtc is still busy.Last line is repeated non-stop.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Any idea what could be wrong?
Additional info - this is on kernel 5.2.6 with your patches applied.
Do you have schematics, or a FEX file for the board or any other info on how the RTC is set up on that board?
Can you dump the RTC register range?
I have only Android DT, but as I already said in latest reply to patch 2, changing switch bypass to bit 14 instead of 15 solved all issues.
Best regards,
Jernej
Quoted 15 lines
regards,
o.Quoted 11 lines
Best regards,
Jernej_______________________________________________
linux-arm-kernel mailing list linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/2660592.K6CN9dZ0QN%40jernej-laptop.