.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Real Time Clock driver for Marvell 88PM860x PMIC |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2010 Marvell International Ltd. |
---|
5 | 6 | * Author: Haojian Zhuang <haojian.zhuang@marvell.com> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License version 2 as |
---|
9 | | - * published by the Free Software Foundation. |
---|
10 | 7 | */ |
---|
11 | 8 | |
---|
12 | 9 | #include <linux/kernel.h> |
---|
.. | .. |
---|
31 | 28 | |
---|
32 | 29 | int irq; |
---|
33 | 30 | int vrtc; |
---|
34 | | - int (*sync)(unsigned int ticks); |
---|
35 | 31 | }; |
---|
36 | 32 | |
---|
37 | 33 | #define REG_VRTC_MEAS1 0x7D |
---|
.. | .. |
---|
79 | 75 | return 0; |
---|
80 | 76 | } |
---|
81 | 77 | |
---|
82 | | -/* |
---|
83 | | - * Calculate the next alarm time given the requested alarm time mask |
---|
84 | | - * and the current time. |
---|
85 | | - */ |
---|
86 | | -static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, |
---|
87 | | - struct rtc_time *alrm) |
---|
88 | | -{ |
---|
89 | | - unsigned long next_time; |
---|
90 | | - unsigned long now_time; |
---|
91 | | - |
---|
92 | | - next->tm_year = now->tm_year; |
---|
93 | | - next->tm_mon = now->tm_mon; |
---|
94 | | - next->tm_mday = now->tm_mday; |
---|
95 | | - next->tm_hour = alrm->tm_hour; |
---|
96 | | - next->tm_min = alrm->tm_min; |
---|
97 | | - next->tm_sec = alrm->tm_sec; |
---|
98 | | - |
---|
99 | | - rtc_tm_to_time(now, &now_time); |
---|
100 | | - rtc_tm_to_time(next, &next_time); |
---|
101 | | - |
---|
102 | | - if (next_time < now_time) { |
---|
103 | | - /* Advance one day */ |
---|
104 | | - next_time += 60 * 60 * 24; |
---|
105 | | - rtc_time_to_tm(next_time, next); |
---|
106 | | - } |
---|
107 | | -} |
---|
108 | | - |
---|
109 | 78 | static int pm860x_rtc_read_time(struct device *dev, struct rtc_time *tm) |
---|
110 | 79 | { |
---|
111 | 80 | struct pm860x_rtc_info *info = dev_get_drvdata(dev); |
---|
.. | .. |
---|
126 | 95 | dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", |
---|
127 | 96 | base, data, ticks); |
---|
128 | 97 | |
---|
129 | | - rtc_time_to_tm(ticks, tm); |
---|
| 98 | + rtc_time64_to_tm(ticks, tm); |
---|
130 | 99 | |
---|
131 | 100 | return 0; |
---|
132 | 101 | } |
---|
.. | .. |
---|
137 | 106 | unsigned char buf[4]; |
---|
138 | 107 | unsigned long ticks, base, data; |
---|
139 | 108 | |
---|
140 | | - if (tm->tm_year > 206) { |
---|
141 | | - dev_dbg(info->dev, "Set time %d out of range. " |
---|
142 | | - "Please set time between 1970 to 2106.\n", |
---|
143 | | - 1900 + tm->tm_year); |
---|
144 | | - return -EINVAL; |
---|
145 | | - } |
---|
146 | | - rtc_tm_to_time(tm, &ticks); |
---|
| 109 | + ticks = rtc_tm_to_time64(tm); |
---|
147 | 110 | |
---|
148 | 111 | /* load 32-bit read-only counter */ |
---|
149 | 112 | pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); |
---|
.. | .. |
---|
158 | 121 | pm860x_page_reg_write(info->i2c, REG2_DATA, (base >> 8) & 0xFF); |
---|
159 | 122 | pm860x_page_reg_write(info->i2c, REG3_DATA, base & 0xFF); |
---|
160 | 123 | |
---|
161 | | - if (info->sync) |
---|
162 | | - info->sync(ticks); |
---|
163 | 124 | return 0; |
---|
164 | 125 | } |
---|
165 | 126 | |
---|
.. | .. |
---|
183 | 144 | dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", |
---|
184 | 145 | base, data, ticks); |
---|
185 | 146 | |
---|
186 | | - rtc_time_to_tm(ticks, &alrm->time); |
---|
| 147 | + rtc_time64_to_tm(ticks, &alrm->time); |
---|
187 | 148 | ret = pm860x_reg_read(info->i2c, PM8607_RTC1); |
---|
188 | 149 | alrm->enabled = (ret & ALARM_EN) ? 1 : 0; |
---|
189 | 150 | alrm->pending = (ret & (ALARM | ALARM_WAKEUP)) ? 1 : 0; |
---|
.. | .. |
---|
193 | 154 | static int pm860x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
---|
194 | 155 | { |
---|
195 | 156 | struct pm860x_rtc_info *info = dev_get_drvdata(dev); |
---|
196 | | - struct rtc_time now_tm, alarm_tm; |
---|
197 | 157 | unsigned long ticks, base, data; |
---|
198 | 158 | unsigned char buf[8]; |
---|
199 | 159 | int mask; |
---|
.. | .. |
---|
206 | 166 | base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) | |
---|
207 | 167 | (buf[5] << 8) | buf[7]; |
---|
208 | 168 | |
---|
209 | | - /* load 32-bit read-only counter */ |
---|
210 | | - pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); |
---|
211 | | - data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | |
---|
212 | | - (buf[1] << 8) | buf[0]; |
---|
213 | | - ticks = base + data; |
---|
214 | | - dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", |
---|
215 | | - base, data, ticks); |
---|
216 | | - |
---|
217 | | - rtc_time_to_tm(ticks, &now_tm); |
---|
218 | | - rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time); |
---|
219 | | - /* get new ticks for alarm in 24 hours */ |
---|
220 | | - rtc_tm_to_time(&alarm_tm, &ticks); |
---|
| 169 | + ticks = rtc_tm_to_time64(&alrm->time); |
---|
221 | 170 | data = ticks - base; |
---|
222 | 171 | |
---|
223 | 172 | buf[0] = data & 0xff; |
---|
.. | .. |
---|
312 | 261 | return 0; |
---|
313 | 262 | } |
---|
314 | 263 | #else |
---|
315 | | -#define pm860x_rtc_dt_init(x, y) (-1) |
---|
| 264 | +#define pm860x_rtc_dt_init(x, y) do { } while (0) |
---|
316 | 265 | #endif |
---|
317 | 266 | |
---|
318 | 267 | static int pm860x_rtc_probe(struct platform_device *pdev) |
---|
319 | 268 | { |
---|
320 | 269 | struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); |
---|
321 | | - struct pm860x_rtc_pdata *pdata = NULL; |
---|
322 | 270 | struct pm860x_rtc_info *info; |
---|
323 | | - struct rtc_time tm; |
---|
324 | | - unsigned long ticks = 0; |
---|
325 | 271 | int ret; |
---|
326 | | - |
---|
327 | | - pdata = dev_get_platdata(&pdev->dev); |
---|
328 | 272 | |
---|
329 | 273 | info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info), |
---|
330 | 274 | GFP_KERNEL); |
---|
331 | 275 | if (!info) |
---|
332 | 276 | return -ENOMEM; |
---|
333 | 277 | info->irq = platform_get_irq(pdev, 0); |
---|
334 | | - if (info->irq < 0) { |
---|
335 | | - dev_err(&pdev->dev, "No IRQ resource!\n"); |
---|
| 278 | + if (info->irq < 0) |
---|
336 | 279 | return info->irq; |
---|
337 | | - } |
---|
338 | 280 | |
---|
339 | 281 | info->chip = chip; |
---|
340 | 282 | info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; |
---|
.. | .. |
---|
360 | 302 | pm860x_page_reg_write(info->i2c, REG2_ADDR, REG2_DATA); |
---|
361 | 303 | pm860x_page_reg_write(info->i2c, REG3_ADDR, REG3_DATA); |
---|
362 | 304 | |
---|
363 | | - ret = pm860x_rtc_read_time(&pdev->dev, &tm); |
---|
364 | | - if (ret < 0) { |
---|
365 | | - dev_err(&pdev->dev, "Failed to read initial time.\n"); |
---|
366 | | - return ret; |
---|
367 | | - } |
---|
368 | | - if ((tm.tm_year < 70) || (tm.tm_year > 138)) { |
---|
369 | | - tm.tm_year = 70; |
---|
370 | | - tm.tm_mon = 0; |
---|
371 | | - tm.tm_mday = 1; |
---|
372 | | - tm.tm_hour = 0; |
---|
373 | | - tm.tm_min = 0; |
---|
374 | | - tm.tm_sec = 0; |
---|
375 | | - ret = pm860x_rtc_set_time(&pdev->dev, &tm); |
---|
376 | | - if (ret < 0) { |
---|
377 | | - dev_err(&pdev->dev, "Failed to set initial time.\n"); |
---|
378 | | - return ret; |
---|
379 | | - } |
---|
380 | | - } |
---|
381 | | - rtc_tm_to_time(&tm, &ticks); |
---|
382 | | - if (pm860x_rtc_dt_init(pdev, info)) { |
---|
383 | | - if (pdata && pdata->sync) { |
---|
384 | | - pdata->sync(ticks); |
---|
385 | | - info->sync = pdata->sync; |
---|
386 | | - } |
---|
387 | | - } |
---|
| 305 | + pm860x_rtc_dt_init(pdev, info); |
---|
388 | 306 | |
---|
389 | 307 | info->rtc_dev->ops = &pm860x_rtc_ops; |
---|
| 308 | + info->rtc_dev->range_max = U32_MAX; |
---|
390 | 309 | |
---|
391 | 310 | ret = rtc_register_device(info->rtc_dev); |
---|
392 | 311 | if (ret) |
---|
.. | .. |
---|
400 | 319 | |
---|
401 | 320 | #ifdef VRTC_CALIBRATION |
---|
402 | 321 | /* <00> -- 2.7V, <01> -- 2.9V, <10> -- 3.1V, <11> -- 3.3V */ |
---|
403 | | - if (pm860x_rtc_dt_init(pdev, info)) { |
---|
404 | | - if (pdata && pdata->vrtc) |
---|
405 | | - info->vrtc = pdata->vrtc & 0x3; |
---|
406 | | - else |
---|
407 | | - info->vrtc = 1; |
---|
408 | | - } |
---|
409 | 322 | pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, MEAS2_VRTC); |
---|
410 | 323 | |
---|
411 | 324 | /* calibrate VRTC */ |
---|