ramips: add support for Tenda 3G150B
[openwrt.git] / target / linux / xburst / patches-3.10 / 007-RTC-JZ4740-Init-the-regulator-register-on-startup.patch
1 From aff616f4a33bd3a9ab1506fdbe97fcfe285cb7b0 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 07/16] 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 Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
13 ---
14  drivers/rtc/rtc-jz4740.c |   17 +++++++++++++++++
15  1 file changed, 17 insertions(+)
16
17 --- a/drivers/rtc/rtc-jz4740.c
18 +++ b/drivers/rtc/rtc-jz4740.c
19 @@ -14,6 +14,7 @@
20   *
21   */
22  
23 +#include <linux/clk.h>
24  #include <linux/kernel.h>
25  #include <linux/module.h>
26  #include <linux/platform_device.h>
27 @@ -215,6 +216,7 @@ static int jz4740_rtc_probe(struct platf
28         int ret;
29         struct jz4740_rtc *rtc;
30         uint32_t scratchpad;
31 +       struct clk *rtc_clk;
32  
33         rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
34         if (!rtc)
35 @@ -280,6 +282,21 @@ static int jz4740_rtc_probe(struct platf
36                 }
37         }
38  
39 +       rtc_clk = clk_get(&pdev->dev, "rtc");
40 +       if (IS_ERR(rtc_clk)) {
41 +               dev_err(&pdev->dev, "Failed to get RTC clock\n");
42 +               goto err_free_irq;
43 +       }
44 +
45 +       /* TODO: initialize the ADJC bits (25:16) to fine-tune
46 +        * the accuracy of the RTC */
47 +       ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_REGULATOR,
48 +                               (clk_get_rate(rtc_clk) - 1) & 0xffff);
49 +       clk_put(rtc_clk);
50 +
51 +       if (ret)
52 +               dev_warn(&pdev->dev, "Could not update RTC regulator register\n");
53 +
54         return 0;
55  
56  err_free_irq: