hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rtc/rtc-xgene.c
....@@ -1,34 +1,21 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * APM X-Gene SoC Real Time Clock Driver
34 *
45 * Copyright (c) 2014, Applied Micro Circuits Corporation
56 * Author: Rameshwar Prasad Sahu <rsahu@apm.com>
67 * Loc Ho <lho@apm.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify it
9
- * under the terms of the GNU General Public License as published by the
10
- * Free Software Foundation; either version 2 of the License, or (at your
11
- * option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
- *
218 */
229
10
+#include <linux/clk.h>
11
+#include <linux/delay.h>
2312 #include <linux/init.h>
13
+#include <linux/io.h>
2414 #include <linux/module.h>
2515 #include <linux/of.h>
2616 #include <linux/platform_device.h>
27
-#include <linux/io.h>
28
-#include <linux/slab.h>
29
-#include <linux/clk.h>
30
-#include <linux/delay.h>
3117 #include <linux/rtc.h>
18
+#include <linux/slab.h>
3219
3320 /* RTC CSR Registers */
3421 #define RTC_CCVR 0x00
....@@ -47,8 +34,6 @@
4734
4835 struct xgene_rtc_dev {
4936 struct rtc_device *rtc;
50
- struct device *dev;
51
- unsigned long alarm_time;
5237 void __iomem *csr_base;
5338 struct clk *clk;
5439 unsigned int irq_wake;
....@@ -59,11 +44,11 @@
5944 {
6045 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
6146
62
- rtc_time_to_tm(readl(pdata->csr_base + RTC_CCVR), tm);
47
+ rtc_time64_to_tm(readl(pdata->csr_base + RTC_CCVR), tm);
6348 return 0;
6449 }
6550
66
-static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs)
51
+static int xgene_rtc_set_time(struct device *dev, struct rtc_time *tm)
6752 {
6853 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
6954
....@@ -71,7 +56,7 @@
7156 * NOTE: After the following write, the RTC_CCVR is only reflected
7257 * after the update cycle of 1 seconds.
7358 */
74
- writel((u32) secs, pdata->csr_base + RTC_CLR);
59
+ writel((u32)rtc_tm_to_time64(tm), pdata->csr_base + RTC_CLR);
7560 readl(pdata->csr_base + RTC_CLR); /* Force a barrier */
7661
7762 return 0;
....@@ -81,7 +66,8 @@
8166 {
8267 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
8368
84
- rtc_time_to_tm(pdata->alarm_time, &alrm->time);
69
+ /* If possible, CMR should be read here */
70
+ rtc_time64_to_tm(0, &alrm->time);
8571 alrm->enabled = readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE;
8672
8773 return 0;
....@@ -115,11 +101,8 @@
115101 static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
116102 {
117103 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
118
- unsigned long alarm_time;
119104
120
- rtc_tm_to_time(&alrm->time, &alarm_time);
121
- pdata->alarm_time = alarm_time;
122
- writel((u32) pdata->alarm_time, pdata->csr_base + RTC_CMR);
105
+ writel((u32)rtc_tm_to_time64(&alrm->time), pdata->csr_base + RTC_CMR);
123106
124107 xgene_rtc_alarm_irq_enable(dev, alrm->enabled);
125108
....@@ -128,7 +111,7 @@
128111
129112 static const struct rtc_class_ops xgene_rtc_ops = {
130113 .read_time = xgene_rtc_read_time,
131
- .set_mmss = xgene_rtc_set_mmss,
114
+ .set_time = xgene_rtc_set_time,
132115 .read_alarm = xgene_rtc_read_alarm,
133116 .set_alarm = xgene_rtc_set_alarm,
134117 .alarm_irq_enable = xgene_rtc_alarm_irq_enable,
....@@ -136,7 +119,7 @@
136119
137120 static irqreturn_t xgene_rtc_interrupt(int irq, void *id)
138121 {
139
- struct xgene_rtc_dev *pdata = (struct xgene_rtc_dev *) id;
122
+ struct xgene_rtc_dev *pdata = id;
140123
141124 /* Check if interrupt asserted */
142125 if (!(readl(pdata->csr_base + RTC_STAT) & RTC_STAT_BIT))
....@@ -153,7 +136,6 @@
153136 static int xgene_rtc_probe(struct platform_device *pdev)
154137 {
155138 struct xgene_rtc_dev *pdata;
156
- struct resource *res;
157139 int ret;
158140 int irq;
159141
....@@ -161,10 +143,8 @@
161143 if (!pdata)
162144 return -ENOMEM;
163145 platform_set_drvdata(pdev, pdata);
164
- pdata->dev = &pdev->dev;
165146
166
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
167
- pdata->csr_base = devm_ioremap_resource(&pdev->dev, res);
147
+ pdata->csr_base = devm_platform_ioremap_resource(pdev, 0);
168148 if (IS_ERR(pdata->csr_base))
169149 return PTR_ERR(pdata->csr_base);
170150
....@@ -173,10 +153,8 @@
173153 return PTR_ERR(pdata->rtc);
174154
175155 irq = platform_get_irq(pdev, 0);
176
- if (irq < 0) {
177
- dev_err(&pdev->dev, "No IRQ resource\n");
156
+ if (irq < 0)
178157 return irq;
179
- }
180158 ret = devm_request_irq(&pdev->dev, irq, xgene_rtc_interrupt, 0,
181159 dev_name(&pdev->dev), pdata);
182160 if (ret) {
....@@ -205,6 +183,7 @@
205183 /* HW does not support update faster than 1 seconds */
206184 pdata->rtc->uie_unsupported = 1;
207185 pdata->rtc->ops = &xgene_rtc_ops;
186
+ pdata->rtc->range_max = U32_MAX;
208187
209188 ret = rtc_register_device(pdata->rtc);
210189 if (ret) {