build/patch/kernel/mvebu-current/421-rtc-initialize.patch
Igor Pečovnik 150ac0c2af
Remove K<4, change branches, new features (#1586)
AR-1 - Adding support category for distributions
AR-4 - Remove Allwinner legacy
AR-5 - Drop Udoo family and move Udoo board into newly created imx6 family
AR-9 - Rename sunxi-next to sunxi-legacy
AR-10 - Rename sunxi-dev to sunxi-current
AR-11 - Adding Radxa Rockpi S support
AR-13 - Rename rockchip64-default to rockchip64-legacy
AR-14 - Add rockchip64-current as mainline source
AR-15 - Drop Rockchip 4.19.y NEXT, current become 5.3.y
AR-16 - Rename RK3399 default to legacy
AR-17 - Rename Odroid XU4 next and default to legacy 4.14.y, add DEV 5.4.y
AR-18 - Add Odroid N2 current mainline
AR-19 - Move Odroid C1 to meson family
AR-20 - Rename mvebu64-default to mvebu64-legacy
AR-21 - Rename mvebu-default to mvebu-legacy
AR-22 - Rename mvebu-next to mvebu-current
AR-23 - Drop meson64 default and next, current becomes former DEV 5.3.y
AR-24 - Drop cubox family and move Cubox/Hummingboard boards under imx6
AR-26 - Adjust motd
AR-27 - Enabling distribution release status
AR-28 - Added new GCC compilers
AR-29 - Implementing Ubuntu Eoan
AR-30 - Add desktop packages per board or family
AR-31 - Remove (Ubuntu/Debian) distribution name from image filename
AR-32 - Move arch configs from configuration.sh to separate arm64 and armhf config files
AR-33 - Revision numbers for beta builds changed to day_in_the_year
AR-34 - Patches support linked patches
AR-35 - Break meson64 family into gxbb and gxl
AR-36 - Add Nanopineo2 Black
AR-38 - Upgrade option from old branches to new one via armbian-config
AR-41 - Show full timezone info
AR-43 - Merge Odroid N2 to meson64
AR-44 - Enable FORCE_BOOTSCRIPT_UPDATE for all builds
2019-11-19 23:25:39 +01:00

75 lines
2.3 KiB
Diff

Some boards like the Turris Omnia have an RTC chip that does not get
initialized. Initializing the RTC at the driver level helps get rid of
bootloader hacks that write special register values.
--- a/drivers/rtc/rtc-armada38x.c
+++ b/drivers/rtc/rtc-armada38x.c
@@ -30,7 +30,10 @@
#define RTC_IRQ_FREQ_1HZ BIT(2)
#define RTC_CCR 0x18
#define RTC_CCR_MODE BIT(15)
+#define RTC_CCR_NORMAL_PPB 0x2000
#define RTC_CONF_TEST 0x1C
+#define RTC_TEST_CONF 0x1c
+#define RTC_TEST_CONF_MASK 0xff
#define RTC_NOMINAL_TIMING BIT(13)
#define RTC_TIME 0xC
@@ -91,6 +94,7 @@ struct armada38x_rtc_data {
void (*clear_isr)(struct armada38x_rtc *rtc);
void (*unmask_interrupt)(struct armada38x_rtc *rtc);
u32 alarm;
+ void (*init_rtc)(struct armada38x_rtc *rtc);
};
/*
@@ -202,6 +206,23 @@ static void armada38x_unmask_interrupt(s
writel(val | SOC_RTC_ALARM1_MASK, rtc->regs_soc + SOC_RTC_INTERRUPT);
}
+static void armada38x_rtc_init(struct armada38x_rtc *rtc)
+{
+ u32 reg;
+
+ /* Test RTC test configuration register bits [7:0] */
+ reg = readl(rtc->regs + RTC_TEST_CONF);
+ /* If bits [7:0] are non-zero, assume RTC was uninitialized */
+ if (reg & RTC_TEST_CONF_MASK) {
+ rtc_delayed_write(0, rtc, RTC_TEST_CONF);
+ rtc_delayed_write(0, rtc, RTC_TIME);
+ rtc_delayed_write((RTC_STATUS_ALARM1 | RTC_STATUS_ALARM2),
+ rtc, RTC_STATUS);
+ rtc_delayed_write(RTC_CCR_NORMAL_PPB, rtc, RTC_CCR);
+ }
+ return;
+}
+
static void armada8k_clear_isr(struct armada38x_rtc *rtc)
{
writel(RTC_8K_ALARM2, rtc->regs_soc + RTC_8K_ISR);
@@ -464,6 +485,7 @@ static const struct armada38x_rtc_data a
.clear_isr = armada38x_clear_isr,
.unmask_interrupt = armada38x_unmask_interrupt,
.alarm = ALARM1,
+ .init_rtc = armada38x_rtc_init,
};
static const struct armada38x_rtc_data armada8k_data = {
@@ -558,6 +580,17 @@ static __init int armada38x_rtc_probe(st
dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
return ret;
}
+
+ /*
+ * Try to detect if RTC is in uninitialized state.
+ * It is not definitive to know if the RTC is in an uninialized state or not,
+ * but the following call will read some bits in the RTC unit and guess if
+ * if it's in that state, and accordingly set it to sane default values.
+ */
+ if (rtc->data->init_rtc) {
+ rtc->data->init_rtc(rtc);
+ }
+
return 0;
}