005-RTC-JZ4740-Init-the-regulator-register-on-startup.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. This register controls the accuracy of the RTC. uC/OS-II use
  6. the RTC as a 100Hz clock, and writes a completely wrong value
  7. on that register, that we have to overwrite if we want a working
  8. real-time clock.
  9. Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  10. ---
  11. drivers/rtc/rtc-jz4740.c | 17 +++++++++++++++++
  12. 1 file changed, 17 insertions(+)
  13. --- a/drivers/rtc/rtc-jz4740.c
  14. +++ b/drivers/rtc/rtc-jz4740.c
  15. @@ -15,6 +15,7 @@
  16. */
  17. #include <linux/io.h>
  18. +#include <linux/clk.h>
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. @@ -216,6 +217,7 @@ static int jz4740_rtc_probe(struct platf
  23. struct jz4740_rtc *rtc;
  24. uint32_t scratchpad;
  25. struct resource *mem;
  26. + struct clk *rtc_clk;
  27. rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
  28. if (!rtc)
  29. @@ -263,6 +265,21 @@ static int jz4740_rtc_probe(struct platf
  30. }
  31. }
  32. + rtc_clk = clk_get(&pdev->dev, "rtc");
  33. + if (IS_ERR(rtc_clk)) {
  34. + dev_err(&pdev->dev, "Failed to get RTC clock\n");
  35. + return PTR_ERR(rtc_clk);
  36. + }
  37. +
  38. + /* TODO: initialize the ADJC bits (25:16) to fine-tune
  39. + * the accuracy of the RTC */
  40. + ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_REGULATOR,
  41. + (clk_get_rate(rtc_clk) - 1) & 0xffff);
  42. + clk_put(rtc_clk);
  43. +
  44. + if (ret)
  45. + dev_warn(&pdev->dev, "Could not update RTC regulator register\n");
  46. +
  47. return 0;
  48. }