Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Support for OLPC XO-1 Real Time Clock (RTC)
0004  *
0005  * Copyright (C) 2011 One Laptop per Child
0006  */
0007 
0008 #include <linux/mc146818rtc.h>
0009 #include <linux/platform_device.h>
0010 #include <linux/rtc.h>
0011 #include <linux/of.h>
0012 
0013 #include <asm/msr.h>
0014 #include <asm/olpc.h>
0015 #include <asm/x86_init.h>
0016 
0017 static void rtc_wake_on(struct device *dev)
0018 {
0019     olpc_xo1_pm_wakeup_set(CS5536_PM_RTC);
0020 }
0021 
0022 static void rtc_wake_off(struct device *dev)
0023 {
0024     olpc_xo1_pm_wakeup_clear(CS5536_PM_RTC);
0025 }
0026 
0027 static struct resource rtc_platform_resource[] = {
0028     [0] = {
0029         .start  = RTC_PORT(0),
0030         .end    = RTC_PORT(1),
0031         .flags  = IORESOURCE_IO,
0032     },
0033     [1] = {
0034         .start  = RTC_IRQ,
0035         .end    = RTC_IRQ,
0036         .flags  = IORESOURCE_IRQ,
0037     }
0038 };
0039 
0040 static struct cmos_rtc_board_info rtc_info = {
0041     .rtc_day_alarm = 0,
0042     .rtc_mon_alarm = 0,
0043     .rtc_century = 0,
0044     .wake_on = rtc_wake_on,
0045     .wake_off = rtc_wake_off,
0046 };
0047 
0048 static struct platform_device xo1_rtc_device = {
0049     .name = "rtc_cmos",
0050     .id = -1,
0051     .num_resources = ARRAY_SIZE(rtc_platform_resource),
0052     .dev.platform_data = &rtc_info,
0053     .resource = rtc_platform_resource,
0054 };
0055 
0056 static int __init xo1_rtc_init(void)
0057 {
0058     int r;
0059     struct device_node *node;
0060 
0061     node = of_find_compatible_node(NULL, NULL, "olpc,xo1-rtc");
0062     if (!node)
0063         return 0;
0064     of_node_put(node);
0065 
0066     pr_info("olpc-xo1-rtc: Initializing OLPC XO-1 RTC\n");
0067     rdmsrl(MSR_RTC_DOMA_OFFSET, rtc_info.rtc_day_alarm);
0068     rdmsrl(MSR_RTC_MONA_OFFSET, rtc_info.rtc_mon_alarm);
0069     rdmsrl(MSR_RTC_CEN_OFFSET, rtc_info.rtc_century);
0070 
0071     r = platform_device_register(&xo1_rtc_device);
0072     if (r)
0073         return r;
0074 
0075     x86_platform.legacy.rtc = 0;
0076 
0077     device_init_wakeup(&xo1_rtc_device.dev, 1);
0078     return 0;
0079 }
0080 arch_initcall(xo1_rtc_init);