summaryrefslogtreecommitdiff
path: root/drivers/rtc
diff options
context:
space:
mode:
authorPaul Cercueil <paul@crapouillou.net>2020-05-06 00:13:33 +0200
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2020-05-11 16:34:59 +0200
commitfe0557f4dbd8cab3fd3a410212157d1a4b67de8b (patch)
treed7d6fd1960b42400d35f74670913b87c5c54d3b6 /drivers/rtc
parent796be8b59dec3efe840a251e2ecc0734408c5ff3 (diff)
rtc: ingenic: Set wakeup params in probe
We can write the wakeup timing parameters as soon as the driver probes, there's no need to wait the very last moment. Signed-off-by: Paul Cercueil <paul@crapouillou.net> Link: https://lore.kernel.org/r/20200505221336.222313-4-paul@crapouillou.net Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-jz4740.c95
1 files changed, 44 insertions, 51 deletions
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 129c68cebb92..8927fd0fb086 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -60,9 +60,6 @@ struct jz4740_rtc {
int irq;
spinlock_t lock;
-
- unsigned int min_wakeup_pin_assert_time;
- unsigned int reset_pin_assert_time;
};
static struct device *dev_for_power_off;
@@ -259,38 +256,6 @@ static void jz4740_rtc_poweroff(struct device *dev)
static void jz4740_rtc_power_off(void)
{
- struct jz4740_rtc *rtc = dev_get_drvdata(dev_for_power_off);
- unsigned long rtc_rate;
- unsigned long wakeup_filter_ticks;
- unsigned long reset_counter_ticks;
-
- rtc_rate = clk_get_rate(rtc->clk);
-
- /*
- * Set minimum wakeup pin assertion time: 100 ms.
- * Range is 0 to 2 sec if RTC is clocked at 32 kHz.
- */
- wakeup_filter_ticks =
- (rtc->min_wakeup_pin_assert_time * rtc_rate) / 1000;
- if (wakeup_filter_ticks < JZ_RTC_WAKEUP_FILTER_MASK)
- wakeup_filter_ticks &= JZ_RTC_WAKEUP_FILTER_MASK;
- else
- wakeup_filter_ticks = JZ_RTC_WAKEUP_FILTER_MASK;
- jz4740_rtc_reg_write(rtc,
- JZ_REG_RTC_WAKEUP_FILTER, wakeup_filter_ticks);
-
- /*
- * Set reset pin low-level assertion time after wakeup: 60 ms.
- * Range is 0 to 125 ms if RTC is clocked at 32 kHz.
- */
- reset_counter_ticks = (rtc->reset_pin_assert_time * rtc_rate) / 1000;
- if (reset_counter_ticks < JZ_RTC_RESET_COUNTER_MASK)
- reset_counter_ticks &= JZ_RTC_RESET_COUNTER_MASK;
- else
- reset_counter_ticks = JZ_RTC_RESET_COUNTER_MASK;
- jz4740_rtc_reg_write(rtc,
- JZ_REG_RTC_RESET_COUNTER, reset_counter_ticks);
-
jz4740_rtc_poweroff(dev_for_power_off);
kernel_halt();
}
@@ -308,12 +273,49 @@ static const struct of_device_id jz4740_rtc_of_match[] = {
};
MODULE_DEVICE_TABLE(of, jz4740_rtc_of_match);
+static void jz4740_rtc_set_wakeup_params(struct jz4740_rtc *rtc,
+ struct device_node *np,
+ unsigned long rate)
+{
+ unsigned long wakeup_ticks, reset_ticks;
+ unsigned int min_wakeup_pin_assert_time = 60; /* Default: 60ms */
+ unsigned int reset_pin_assert_time = 100; /* Default: 100ms */
+
+ of_property_read_u32(np, "ingenic,reset-pin-assert-time-ms",
+ &reset_pin_assert_time);
+ of_property_read_u32(np, "ingenic,min-wakeup-pin-assert-time-ms",
+ &min_wakeup_pin_assert_time);
+
+ /*
+ * Set minimum wakeup pin assertion time: 100 ms.
+ * Range is 0 to 2 sec if RTC is clocked at 32 kHz.
+ */
+ wakeup_ticks = (min_wakeup_pin_assert_time * rate) / 1000;
+ if (wakeup_ticks < JZ_RTC_WAKEUP_FILTER_MASK)
+ wakeup_ticks &= JZ_RTC_WAKEUP_FILTER_MASK;
+ else
+ wakeup_ticks = JZ_RTC_WAKEUP_FILTER_MASK;
+ jz4740_rtc_reg_write(rtc, JZ_REG_RTC_WAKEUP_FILTER, wakeup_ticks);
+
+ /*
+ * Set reset pin low-level assertion time after wakeup: 60 ms.
+ * Range is 0 to 125 ms if RTC is clocked at 32 kHz.
+ */
+ reset_ticks = (reset_pin_assert_time * rate) / 1000;
+ if (reset_ticks < JZ_RTC_RESET_COUNTER_MASK)
+ reset_ticks &= JZ_RTC_RESET_COUNTER_MASK;
+ else
+ reset_ticks = JZ_RTC_RESET_COUNTER_MASK;
+ jz4740_rtc_reg_write(rtc, JZ_REG_RTC_RESET_COUNTER, reset_ticks);
+}
+
static int jz4740_rtc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
int ret;
struct jz4740_rtc *rtc;
+ unsigned long rate;
rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
if (!rtc)
@@ -369,6 +371,9 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
rtc->rtc->ops = &jz4740_rtc_ops;
rtc->rtc->range_max = U32_MAX;
+ rate = clk_get_rate(rtc->clk);
+ jz4740_rtc_set_wakeup_params(rtc, np, rate);
+
ret = rtc_register_device(rtc->rtc);
if (ret)
return ret;
@@ -381,24 +386,12 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
}
if (of_device_is_system_power_controller(np)) {
- if (!pm_power_off) {
- /* Default: 60ms */
- rtc->reset_pin_assert_time = 60;
- of_property_read_u32(np,
- "ingenic,reset-pin-assert-time-ms",
- &rtc->reset_pin_assert_time);
-
- /* Default: 100ms */
- rtc->min_wakeup_pin_assert_time = 100;
- of_property_read_u32(np,
- "ingenic,min-wakeup-pin-assert-time-ms",
- &rtc->min_wakeup_pin_assert_time);
-
- dev_for_power_off = dev;
+ dev_for_power_off = dev;
+
+ if (!pm_power_off)
pm_power_off = jz4740_rtc_power_off;
- } else {
+ else
dev_warn(dev, "Poweroff handler already present!\n");
- }
}
return 0;