hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/rtc/rtc-88pm860x.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Real Time Clock driver for Marvell 88PM860x PMIC
34 *
45 * Copyright (c) 2010 Marvell International Ltd.
56 * 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.
107 */
118
129 #include <linux/kernel.h>
....@@ -31,7 +28,6 @@
3128
3229 int irq;
3330 int vrtc;
34
- int (*sync)(unsigned int ticks);
3531 };
3632
3733 #define REG_VRTC_MEAS1 0x7D
....@@ -79,33 +75,6 @@
7975 return 0;
8076 }
8177
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
-
10978 static int pm860x_rtc_read_time(struct device *dev, struct rtc_time *tm)
11079 {
11180 struct pm860x_rtc_info *info = dev_get_drvdata(dev);
....@@ -126,7 +95,7 @@
12695 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
12796 base, data, ticks);
12897
129
- rtc_time_to_tm(ticks, tm);
98
+ rtc_time64_to_tm(ticks, tm);
13099
131100 return 0;
132101 }
....@@ -137,13 +106,7 @@
137106 unsigned char buf[4];
138107 unsigned long ticks, base, data;
139108
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);
147110
148111 /* load 32-bit read-only counter */
149112 pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf);
....@@ -158,8 +121,6 @@
158121 pm860x_page_reg_write(info->i2c, REG2_DATA, (base >> 8) & 0xFF);
159122 pm860x_page_reg_write(info->i2c, REG3_DATA, base & 0xFF);
160123
161
- if (info->sync)
162
- info->sync(ticks);
163124 return 0;
164125 }
165126
....@@ -183,7 +144,7 @@
183144 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
184145 base, data, ticks);
185146
186
- rtc_time_to_tm(ticks, &alrm->time);
147
+ rtc_time64_to_tm(ticks, &alrm->time);
187148 ret = pm860x_reg_read(info->i2c, PM8607_RTC1);
188149 alrm->enabled = (ret & ALARM_EN) ? 1 : 0;
189150 alrm->pending = (ret & (ALARM | ALARM_WAKEUP)) ? 1 : 0;
....@@ -193,7 +154,6 @@
193154 static int pm860x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
194155 {
195156 struct pm860x_rtc_info *info = dev_get_drvdata(dev);
196
- struct rtc_time now_tm, alarm_tm;
197157 unsigned long ticks, base, data;
198158 unsigned char buf[8];
199159 int mask;
....@@ -206,18 +166,7 @@
206166 base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) |
207167 (buf[5] << 8) | buf[7];
208168
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);
221170 data = ticks - base;
222171
223172 buf[0] = data & 0xff;
....@@ -312,29 +261,22 @@
312261 return 0;
313262 }
314263 #else
315
-#define pm860x_rtc_dt_init(x, y) (-1)
264
+#define pm860x_rtc_dt_init(x, y) do { } while (0)
316265 #endif
317266
318267 static int pm860x_rtc_probe(struct platform_device *pdev)
319268 {
320269 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
321
- struct pm860x_rtc_pdata *pdata = NULL;
322270 struct pm860x_rtc_info *info;
323
- struct rtc_time tm;
324
- unsigned long ticks = 0;
325271 int ret;
326
-
327
- pdata = dev_get_platdata(&pdev->dev);
328272
329273 info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info),
330274 GFP_KERNEL);
331275 if (!info)
332276 return -ENOMEM;
333277 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)
336279 return info->irq;
337
- }
338280
339281 info->chip = chip;
340282 info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
....@@ -360,33 +302,10 @@
360302 pm860x_page_reg_write(info->i2c, REG2_ADDR, REG2_DATA);
361303 pm860x_page_reg_write(info->i2c, REG3_ADDR, REG3_DATA);
362304
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);
388306
389307 info->rtc_dev->ops = &pm860x_rtc_ops;
308
+ info->rtc_dev->range_max = U32_MAX;
390309
391310 ret = rtc_register_device(info->rtc_dev);
392311 if (ret)
....@@ -400,12 +319,6 @@
400319
401320 #ifdef VRTC_CALIBRATION
402321 /* <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
- }
409322 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, MEAS2_VRTC);
410323
411324 /* calibrate VRTC */