forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/arch/sh/boards/mach-sh03/rtc.c
....@@ -13,8 +13,9 @@
1313 #include <linux/bcd.h>
1414 #include <linux/rtc.h>
1515 #include <linux/spinlock.h>
16
-#include <asm/io.h>
17
-#include <asm/rtc.h>
16
+#include <linux/io.h>
17
+#include <linux/rtc.h>
18
+#include <linux/platform_device.h>
1819
1920 #define RTC_BASE 0xb0000000
2021 #define RTC_SEC1 (RTC_BASE + 0)
....@@ -38,7 +39,7 @@
3839
3940 static DEFINE_SPINLOCK(sh03_rtc_lock);
4041
41
-unsigned long get_cmos_time(void)
42
+static int sh03_rtc_gettimeofday(struct device *dev, struct rtc_time *tm)
4243 {
4344 unsigned int year, mon, day, hour, min, sec;
4445
....@@ -75,17 +76,18 @@
7576 }
7677
7778 spin_unlock(&sh03_rtc_lock);
78
- return mktime(year, mon, day, hour, min, sec);
79
+
80
+ tm->tm_sec = sec;
81
+ tm->tm_min = min;
82
+ tm->tm_hour = hour;
83
+ tm->tm_mday = day;
84
+ tm->tm_mon = mon;
85
+ tm->tm_year = year - 1900;
86
+
87
+ return 0;
7988 }
8089
81
-void sh03_rtc_gettimeofday(struct timespec *tv)
82
-{
83
-
84
- tv->tv_sec = get_cmos_time();
85
- tv->tv_nsec = 0;
86
-}
87
-
88
-static int set_rtc_mmss(unsigned long nowtime)
90
+static int set_rtc_mmss(struct rtc_time *tm)
8991 {
9092 int retval = 0;
9193 int real_seconds, real_minutes, cmos_minutes;
....@@ -97,8 +99,8 @@
9799 if (!(__raw_readb(RTC_CTL) & RTC_BUSY))
98100 break;
99101 cmos_minutes = (__raw_readb(RTC_MIN1) & 0xf) + (__raw_readb(RTC_MIN10) & 0xf) * 10;
100
- real_seconds = nowtime % 60;
101
- real_minutes = nowtime / 60;
102
+ real_seconds = tm->tm_sec;
103
+ real_minutes = tm->tm_min;
102104 if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
103105 real_minutes += 30; /* correct for half hour time zone */
104106 real_minutes %= 60;
....@@ -112,22 +114,31 @@
112114 printk_once(KERN_NOTICE
113115 "set_rtc_mmss: can't update from %d to %d\n",
114116 cmos_minutes, real_minutes);
115
- retval = -1;
117
+ retval = -EINVAL;
116118 }
117119 spin_unlock(&sh03_rtc_lock);
118120
119121 return retval;
120122 }
121123
122
-int sh03_rtc_settimeofday(const time_t secs)
124
+int sh03_rtc_settimeofday(struct device *dev, struct rtc_time *tm)
123125 {
124
- unsigned long nowtime = secs;
125
-
126
- return set_rtc_mmss(nowtime);
126
+ return set_rtc_mmss(tm);
127127 }
128128
129
-void sh03_time_init(void)
129
+static const struct rtc_class_ops rtc_generic_ops = {
130
+ .read_time = sh03_rtc_gettimeofday,
131
+ .set_time = sh03_rtc_settimeofday,
132
+};
133
+
134
+static int __init sh03_time_init(void)
130135 {
131
- rtc_sh_get_time = sh03_rtc_gettimeofday;
132
- rtc_sh_set_time = sh03_rtc_settimeofday;
136
+ struct platform_device *pdev;
137
+
138
+ pdev = platform_device_register_data(NULL, "rtc-generic", -1,
139
+ &rtc_generic_ops,
140
+ sizeof(rtc_generic_ops));
141
+
142
+ return PTR_ERR_OR_ZERO(pdev);
133143 }
144
+arch_initcall(sh03_time_init);