xburst: Update to 3.18
[openwrt/svn-archive/archive.git] / target / linux / xburst / patches-3.18 / 005-RTC-JZ4740-Init-the-regulator-register-on-startup.patch
1 From f05b1ecd7e4fde7e69320a4b7be461636e982991 Mon Sep 17 00:00:00 2001
2 From: Paul Cercueil <paul@crapouillou.net>
3 Date: Thu, 13 Sep 2012 00:09:20 +0200
4 Subject: [PATCH 5/7] RTC: JZ4740: Init the "regulator" register on startup.
5
6 This register controls the accuracy of the RTC. uC/OS-II use
7 the RTC as a 100Hz clock, and writes a completely wrong value
8 on that register, that we have to overwrite if we want a working
9 real-time clock.
10
11 Signed-off-by: Paul Cercueil <paul@crapouillou.net>
12 ---
13 drivers/rtc/rtc-jz4740.c | 17 +++++++++++++++++
14 1 file changed, 17 insertions(+)
15
16 diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
17 index 08f5160..5f027dc 100644
18 --- a/drivers/rtc/rtc-jz4740.c
19 +++ b/drivers/rtc/rtc-jz4740.c
20 @@ -15,6 +15,7 @@
21 */
22
23 #include <linux/io.h>
24 +#include <linux/clk.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 @@ -216,6 +217,7 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
29 struct jz4740_rtc *rtc;
30 uint32_t scratchpad;
31 struct resource *mem;
32 + struct clk *rtc_clk;
33
34 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
35 if (!rtc)
36 @@ -263,6 +265,21 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
37 }
38 }
39
40 + rtc_clk = clk_get(&pdev->dev, "rtc");
41 + if (IS_ERR(rtc_clk)) {
42 + dev_err(&pdev->dev, "Failed to get RTC clock\n");
43 + return PTR_ERR(rtc_clk);
44 + }
45 +
46 + /* TODO: initialize the ADJC bits (25:16) to fine-tune
47 + * the accuracy of the RTC */
48 + ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_REGULATOR,
49 + (clk_get_rate(rtc_clk) - 1) & 0xffff);
50 + clk_put(rtc_clk);
51 +
52 + if (ret)
53 + dev_warn(&pdev->dev, "Could not update RTC regulator register\n");
54 +
55 return 0;
56 }
57
58 --
59 1.7.10.4
60