diff options
Diffstat (limited to 'arch/powerpc/platforms/powernv/opal-rtc.c')
-rw-r--r-- | arch/powerpc/platforms/powernv/opal-rtc.c | 65 |
1 files changed, 19 insertions, 46 deletions
diff --git a/arch/powerpc/platforms/powernv/opal-rtc.c b/arch/powerpc/platforms/powernv/opal-rtc.c index 499707ddaa9c..37dbee15769f 100644 --- a/arch/powerpc/platforms/powernv/opal-rtc.c +++ b/arch/powerpc/platforms/powernv/opal-rtc.c | |||
@@ -15,6 +15,8 @@ | |||
15 | #include <linux/bcd.h> | 15 | #include <linux/bcd.h> |
16 | #include <linux/rtc.h> | 16 | #include <linux/rtc.h> |
17 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/of_platform.h> | ||
18 | 20 | ||
19 | #include <asm/opal.h> | 21 | #include <asm/opal.h> |
20 | #include <asm/firmware.h> | 22 | #include <asm/firmware.h> |
@@ -43,7 +45,7 @@ unsigned long __init opal_get_boot_time(void) | |||
43 | long rc = OPAL_BUSY; | 45 | long rc = OPAL_BUSY; |
44 | 46 | ||
45 | if (!opal_check_token(OPAL_RTC_READ)) | 47 | if (!opal_check_token(OPAL_RTC_READ)) |
46 | goto out; | 48 | return 0; |
47 | 49 | ||
48 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { | 50 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
49 | rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms); | 51 | rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms); |
@@ -53,62 +55,33 @@ unsigned long __init opal_get_boot_time(void) | |||
53 | mdelay(10); | 55 | mdelay(10); |
54 | } | 56 | } |
55 | if (rc != OPAL_SUCCESS) | 57 | if (rc != OPAL_SUCCESS) |
56 | goto out; | 58 | return 0; |
57 | 59 | ||
58 | y_m_d = be32_to_cpu(__y_m_d); | 60 | y_m_d = be32_to_cpu(__y_m_d); |
59 | h_m_s_ms = be64_to_cpu(__h_m_s_ms); | 61 | h_m_s_ms = be64_to_cpu(__h_m_s_ms); |
60 | opal_to_tm(y_m_d, h_m_s_ms, &tm); | 62 | opal_to_tm(y_m_d, h_m_s_ms, &tm); |
61 | return mktime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, | 63 | return mktime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, |
62 | tm.tm_hour, tm.tm_min, tm.tm_sec); | 64 | tm.tm_hour, tm.tm_min, tm.tm_sec); |
63 | out: | ||
64 | ppc_md.get_rtc_time = NULL; | ||
65 | ppc_md.set_rtc_time = NULL; | ||
66 | return 0; | ||
67 | } | 65 | } |
68 | 66 | ||
69 | void opal_get_rtc_time(struct rtc_time *tm) | 67 | static __init int opal_time_init(void) |
70 | { | 68 | { |
71 | long rc = OPAL_BUSY; | 69 | struct platform_device *pdev; |
72 | u32 y_m_d; | 70 | struct device_node *rtc; |
73 | u64 h_m_s_ms; | ||
74 | __be32 __y_m_d; | ||
75 | __be64 __h_m_s_ms; | ||
76 | 71 | ||
77 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { | 72 | rtc = of_find_node_by_path("/ibm,opal/rtc"); |
78 | rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms); | 73 | if (rtc) { |
79 | if (rc == OPAL_BUSY_EVENT) | 74 | pdev = of_platform_device_create(rtc, "opal-rtc", NULL); |
80 | opal_poll_events(NULL); | 75 | of_node_put(rtc); |
76 | } else { | ||
77 | if (opal_check_token(OPAL_RTC_READ) || | ||
78 | opal_check_token(OPAL_READ_TPO)) | ||
79 | pdev = platform_device_register_simple("opal-rtc", -1, | ||
80 | NULL, 0); | ||
81 | else | 81 | else |
82 | mdelay(10); | 82 | return -ENODEV; |
83 | } | 83 | } |
84 | if (rc != OPAL_SUCCESS) | ||
85 | return; | ||
86 | y_m_d = be32_to_cpu(__y_m_d); | ||
87 | h_m_s_ms = be64_to_cpu(__h_m_s_ms); | ||
88 | opal_to_tm(y_m_d, h_m_s_ms, tm); | ||
89 | } | ||
90 | |||
91 | int opal_set_rtc_time(struct rtc_time *tm) | ||
92 | { | ||
93 | long rc = OPAL_BUSY; | ||
94 | u32 y_m_d = 0; | ||
95 | u64 h_m_s_ms = 0; | ||
96 | |||
97 | y_m_d |= ((u32)bin2bcd((tm->tm_year + 1900) / 100)) << 24; | ||
98 | y_m_d |= ((u32)bin2bcd((tm->tm_year + 1900) % 100)) << 16; | ||
99 | y_m_d |= ((u32)bin2bcd((tm->tm_mon + 1))) << 8; | ||
100 | y_m_d |= ((u32)bin2bcd(tm->tm_mday)); | ||
101 | |||
102 | h_m_s_ms |= ((u64)bin2bcd(tm->tm_hour)) << 56; | ||
103 | h_m_s_ms |= ((u64)bin2bcd(tm->tm_min)) << 48; | ||
104 | h_m_s_ms |= ((u64)bin2bcd(tm->tm_sec)) << 40; | ||
105 | 84 | ||
106 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { | 85 | return PTR_ERR_OR_ZERO(pdev); |
107 | rc = opal_rtc_write(y_m_d, h_m_s_ms); | ||
108 | if (rc == OPAL_BUSY_EVENT) | ||
109 | opal_poll_events(NULL); | ||
110 | else | ||
111 | mdelay(10); | ||
112 | } | ||
113 | return rc == OPAL_SUCCESS ? 0 : -EIO; | ||
114 | } | 86 | } |
87 | machine_subsys_initcall(powernv, opal_time_init); | ||