olpc-xo1-rtc.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Support for OLPC XO-1 Real Time Clock (RTC)
  4. *
  5. * Copyright (C) 2011 One Laptop per Child
  6. */
  7. #include <linux/mc146818rtc.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/rtc.h>
  10. #include <linux/of.h>
  11. #include <asm/msr.h>
  12. #include <asm/olpc.h>
  13. #include <asm/x86_init.h>
  14. static void rtc_wake_on(struct device *dev)
  15. {
  16. olpc_xo1_pm_wakeup_set(CS5536_PM_RTC);
  17. }
  18. static void rtc_wake_off(struct device *dev)
  19. {
  20. olpc_xo1_pm_wakeup_clear(CS5536_PM_RTC);
  21. }
  22. static struct resource rtc_platform_resource[] = {
  23. [0] = {
  24. .start = RTC_PORT(0),
  25. .end = RTC_PORT(1),
  26. .flags = IORESOURCE_IO,
  27. },
  28. [1] = {
  29. .start = RTC_IRQ,
  30. .end = RTC_IRQ,
  31. .flags = IORESOURCE_IRQ,
  32. }
  33. };
  34. static struct cmos_rtc_board_info rtc_info = {
  35. .rtc_day_alarm = 0,
  36. .rtc_mon_alarm = 0,
  37. .rtc_century = 0,
  38. .wake_on = rtc_wake_on,
  39. .wake_off = rtc_wake_off,
  40. };
  41. static struct platform_device xo1_rtc_device = {
  42. .name = "rtc_cmos",
  43. .id = -1,
  44. .num_resources = ARRAY_SIZE(rtc_platform_resource),
  45. .dev.platform_data = &rtc_info,
  46. .resource = rtc_platform_resource,
  47. };
  48. static int __init xo1_rtc_init(void)
  49. {
  50. int r;
  51. struct device_node *node;
  52. node = of_find_compatible_node(NULL, NULL, "olpc,xo1-rtc");
  53. if (!node)
  54. return 0;
  55. of_node_put(node);
  56. pr_info("olpc-xo1-rtc: Initializing OLPC XO-1 RTC\n");
  57. rdmsrl(MSR_RTC_DOMA_OFFSET, rtc_info.rtc_day_alarm);
  58. rdmsrl(MSR_RTC_MONA_OFFSET, rtc_info.rtc_mon_alarm);
  59. rdmsrl(MSR_RTC_CEN_OFFSET, rtc_info.rtc_century);
  60. r = platform_device_register(&xo1_rtc_device);
  61. if (r)
  62. return r;
  63. x86_platform.legacy.rtc = 0;
  64. device_init_wakeup(&xo1_rtc_device.dev, 1);
  65. return 0;
  66. }
  67. arch_initcall(xo1_rtc_init);