.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * APM X-Gene SoC Real Time Clock Driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2014, Applied Micro Circuits Corporation |
---|
5 | 6 | * Author: Rameshwar Prasad Sahu <rsahu@apm.com> |
---|
6 | 7 | * 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 | | - * |
---|
21 | 8 | */ |
---|
22 | 9 | |
---|
| 10 | +#include <linux/clk.h> |
---|
| 11 | +#include <linux/delay.h> |
---|
23 | 12 | #include <linux/init.h> |
---|
| 13 | +#include <linux/io.h> |
---|
24 | 14 | #include <linux/module.h> |
---|
25 | 15 | #include <linux/of.h> |
---|
26 | 16 | #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> |
---|
31 | 17 | #include <linux/rtc.h> |
---|
| 18 | +#include <linux/slab.h> |
---|
32 | 19 | |
---|
33 | 20 | /* RTC CSR Registers */ |
---|
34 | 21 | #define RTC_CCVR 0x00 |
---|
.. | .. |
---|
47 | 34 | |
---|
48 | 35 | struct xgene_rtc_dev { |
---|
49 | 36 | struct rtc_device *rtc; |
---|
50 | | - struct device *dev; |
---|
51 | | - unsigned long alarm_time; |
---|
52 | 37 | void __iomem *csr_base; |
---|
53 | 38 | struct clk *clk; |
---|
54 | 39 | unsigned int irq_wake; |
---|
.. | .. |
---|
59 | 44 | { |
---|
60 | 45 | struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); |
---|
61 | 46 | |
---|
62 | | - rtc_time_to_tm(readl(pdata->csr_base + RTC_CCVR), tm); |
---|
| 47 | + rtc_time64_to_tm(readl(pdata->csr_base + RTC_CCVR), tm); |
---|
63 | 48 | return 0; |
---|
64 | 49 | } |
---|
65 | 50 | |
---|
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) |
---|
67 | 52 | { |
---|
68 | 53 | struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); |
---|
69 | 54 | |
---|
.. | .. |
---|
71 | 56 | * NOTE: After the following write, the RTC_CCVR is only reflected |
---|
72 | 57 | * after the update cycle of 1 seconds. |
---|
73 | 58 | */ |
---|
74 | | - writel((u32) secs, pdata->csr_base + RTC_CLR); |
---|
| 59 | + writel((u32)rtc_tm_to_time64(tm), pdata->csr_base + RTC_CLR); |
---|
75 | 60 | readl(pdata->csr_base + RTC_CLR); /* Force a barrier */ |
---|
76 | 61 | |
---|
77 | 62 | return 0; |
---|
.. | .. |
---|
81 | 66 | { |
---|
82 | 67 | struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); |
---|
83 | 68 | |
---|
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); |
---|
85 | 71 | alrm->enabled = readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE; |
---|
86 | 72 | |
---|
87 | 73 | return 0; |
---|
.. | .. |
---|
115 | 101 | static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
---|
116 | 102 | { |
---|
117 | 103 | struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); |
---|
118 | | - unsigned long alarm_time; |
---|
119 | 104 | |
---|
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); |
---|
123 | 106 | |
---|
124 | 107 | xgene_rtc_alarm_irq_enable(dev, alrm->enabled); |
---|
125 | 108 | |
---|
.. | .. |
---|
128 | 111 | |
---|
129 | 112 | static const struct rtc_class_ops xgene_rtc_ops = { |
---|
130 | 113 | .read_time = xgene_rtc_read_time, |
---|
131 | | - .set_mmss = xgene_rtc_set_mmss, |
---|
| 114 | + .set_time = xgene_rtc_set_time, |
---|
132 | 115 | .read_alarm = xgene_rtc_read_alarm, |
---|
133 | 116 | .set_alarm = xgene_rtc_set_alarm, |
---|
134 | 117 | .alarm_irq_enable = xgene_rtc_alarm_irq_enable, |
---|
.. | .. |
---|
136 | 119 | |
---|
137 | 120 | static irqreturn_t xgene_rtc_interrupt(int irq, void *id) |
---|
138 | 121 | { |
---|
139 | | - struct xgene_rtc_dev *pdata = (struct xgene_rtc_dev *) id; |
---|
| 122 | + struct xgene_rtc_dev *pdata = id; |
---|
140 | 123 | |
---|
141 | 124 | /* Check if interrupt asserted */ |
---|
142 | 125 | if (!(readl(pdata->csr_base + RTC_STAT) & RTC_STAT_BIT)) |
---|
.. | .. |
---|
153 | 136 | static int xgene_rtc_probe(struct platform_device *pdev) |
---|
154 | 137 | { |
---|
155 | 138 | struct xgene_rtc_dev *pdata; |
---|
156 | | - struct resource *res; |
---|
157 | 139 | int ret; |
---|
158 | 140 | int irq; |
---|
159 | 141 | |
---|
.. | .. |
---|
161 | 143 | if (!pdata) |
---|
162 | 144 | return -ENOMEM; |
---|
163 | 145 | platform_set_drvdata(pdev, pdata); |
---|
164 | | - pdata->dev = &pdev->dev; |
---|
165 | 146 | |
---|
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); |
---|
168 | 148 | if (IS_ERR(pdata->csr_base)) |
---|
169 | 149 | return PTR_ERR(pdata->csr_base); |
---|
170 | 150 | |
---|
.. | .. |
---|
173 | 153 | return PTR_ERR(pdata->rtc); |
---|
174 | 154 | |
---|
175 | 155 | irq = platform_get_irq(pdev, 0); |
---|
176 | | - if (irq < 0) { |
---|
177 | | - dev_err(&pdev->dev, "No IRQ resource\n"); |
---|
| 156 | + if (irq < 0) |
---|
178 | 157 | return irq; |
---|
179 | | - } |
---|
180 | 158 | ret = devm_request_irq(&pdev->dev, irq, xgene_rtc_interrupt, 0, |
---|
181 | 159 | dev_name(&pdev->dev), pdata); |
---|
182 | 160 | if (ret) { |
---|
.. | .. |
---|
205 | 183 | /* HW does not support update faster than 1 seconds */ |
---|
206 | 184 | pdata->rtc->uie_unsupported = 1; |
---|
207 | 185 | pdata->rtc->ops = &xgene_rtc_ops; |
---|
| 186 | + pdata->rtc->range_max = U32_MAX; |
---|
208 | 187 | |
---|
209 | 188 | ret = rtc_register_device(pdata->rtc); |
---|
210 | 189 | if (ret) { |
---|