forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/drivers/rtc/rtc-wm831x.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Real Time Clock driver for Wolfson Microelectronics WM831x
34 *
45 * Copyright (C) 2009 Wolfson Microelectronics PLC.
56 *
67 * Author: Mark Brown <broonie@opensource.wolfsonmicro.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.
128 *
139 */
1410
....@@ -155,7 +151,7 @@
155151 if (memcmp(time1, time2, sizeof(time1)) == 0) {
156152 u32 time = (time1[0] << 16) | time1[1];
157153
158
- rtc_time_to_tm(time, tm);
154
+ rtc_time64_to_tm(time, tm);
159155 return 0;
160156 }
161157
....@@ -169,14 +165,16 @@
169165 /*
170166 * Set current time and date in RTC
171167 */
172
-static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time)
168
+static int wm831x_rtc_settime(struct device *dev, struct rtc_time *tm)
173169 {
174170 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
175171 struct wm831x *wm831x = wm831x_rtc->wm831x;
176172 struct rtc_time new_tm;
177
- unsigned long new_time;
173
+ unsigned long time, new_time;
178174 int ret;
179175 int count = 0;
176
+
177
+ time = rtc_tm_to_time64(tm);
180178
181179 ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_1,
182180 (time >> 16) & 0xffff);
....@@ -215,11 +213,7 @@
215213 if (ret < 0)
216214 return ret;
217215
218
- ret = rtc_tm_to_time(&new_tm, &new_time);
219
- if (ret < 0) {
220
- dev_err(dev, "Failed to convert time: %d\n", ret);
221
- return ret;
222
- }
216
+ new_time = rtc_tm_to_time64(&new_tm);
223217
224218 /* Allow a second of change in case of tick */
225219 if (new_time - time > 1) {
....@@ -249,7 +243,7 @@
249243
250244 time = (data[0] << 16) | data[1];
251245
252
- rtc_time_to_tm(time, &alrm->time);
246
+ rtc_time64_to_tm(time, &alrm->time);
253247
254248 ret = wm831x_reg_read(wm831x_rtc->wm831x, WM831X_RTC_CONTROL);
255249 if (ret < 0) {
....@@ -288,11 +282,7 @@
288282 int ret;
289283 unsigned long time;
290284
291
- ret = rtc_tm_to_time(&alrm->time, &time);
292
- if (ret < 0) {
293
- dev_err(dev, "Failed to convert time: %d\n", ret);
294
- return ret;
295
- }
285
+ time = rtc_tm_to_time64(&alrm->time);
296286
297287 ret = wm831x_rtc_stop_alarm(wm831x_rtc);
298288 if (ret < 0) {
....@@ -346,7 +336,7 @@
346336
347337 static const struct rtc_class_ops wm831x_rtc_ops = {
348338 .read_time = wm831x_rtc_readtime,
349
- .set_mmss = wm831x_rtc_set_mmss,
339
+ .set_time = wm831x_rtc_settime,
350340 .read_alarm = wm831x_rtc_readalarm,
351341 .set_alarm = wm831x_rtc_setalarm,
352342 .alarm_irq_enable = wm831x_rtc_alarm_irq_enable,
....@@ -356,11 +346,10 @@
356346 /* Turn off the alarm if it should not be a wake source. */
357347 static int wm831x_rtc_suspend(struct device *dev)
358348 {
359
- struct platform_device *pdev = to_platform_device(dev);
360
- struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
349
+ struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
361350 int ret, enable;
362351
363
- if (wm831x_rtc->alarm_enabled && device_may_wakeup(&pdev->dev))
352
+ if (wm831x_rtc->alarm_enabled && device_may_wakeup(dev))
364353 enable = WM831X_RTC_ALM_ENA;
365354 else
366355 enable = 0;
....@@ -368,7 +357,7 @@
368357 ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL,
369358 WM831X_RTC_ALM_ENA, enable);
370359 if (ret != 0)
371
- dev_err(&pdev->dev, "Failed to update RTC alarm: %d\n", ret);
360
+ dev_err(dev, "Failed to update RTC alarm: %d\n", ret);
372361
373362 return 0;
374363 }
....@@ -378,15 +367,13 @@
378367 */
379368 static int wm831x_rtc_resume(struct device *dev)
380369 {
381
- struct platform_device *pdev = to_platform_device(dev);
382
- struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
370
+ struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
383371 int ret;
384372
385373 if (wm831x_rtc->alarm_enabled) {
386374 ret = wm831x_rtc_start_alarm(wm831x_rtc);
387375 if (ret != 0)
388
- dev_err(&pdev->dev,
389
- "Failed to restart RTC alarm: %d\n", ret);
376
+ dev_err(dev, "Failed to restart RTC alarm: %d\n", ret);
390377 }
391378
392379 return 0;
....@@ -395,14 +382,13 @@
395382 /* Unconditionally disable the alarm */
396383 static int wm831x_rtc_freeze(struct device *dev)
397384 {
398
- struct platform_device *pdev = to_platform_device(dev);
399
- struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
385
+ struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
400386 int ret;
401387
402388 ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL,
403389 WM831X_RTC_ALM_ENA, 0);
404390 if (ret != 0)
405
- dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n", ret);
391
+ dev_err(dev, "Failed to stop RTC alarm: %d\n", ret);
406392
407393 return 0;
408394 }
....@@ -429,23 +415,28 @@
429415 ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL);
430416 if (ret < 0) {
431417 dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret);
432
- goto err;
418
+ return ret;
433419 }
434420 if (ret & WM831X_RTC_ALM_ENA)
435421 wm831x_rtc->alarm_enabled = 1;
436422
437423 device_init_wakeup(&pdev->dev, 1);
438424
439
- wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x",
440
- &wm831x_rtc_ops, THIS_MODULE);
441
- if (IS_ERR(wm831x_rtc->rtc)) {
442
- ret = PTR_ERR(wm831x_rtc->rtc);
443
- goto err;
444
- }
425
+ wm831x_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
426
+ if (IS_ERR(wm831x_rtc->rtc))
427
+ return PTR_ERR(wm831x_rtc->rtc);
428
+
429
+ wm831x_rtc->rtc->ops = &wm831x_rtc_ops;
430
+ wm831x_rtc->rtc->range_max = U32_MAX;
431
+
432
+ ret = rtc_register_device(wm831x_rtc->rtc);
433
+ if (ret)
434
+ return ret;
445435
446436 ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL,
447437 wm831x_alm_irq,
448
- IRQF_TRIGGER_RISING, "RTC alarm",
438
+ IRQF_TRIGGER_RISING | IRQF_ONESHOT,
439
+ "RTC alarm",
449440 wm831x_rtc);
450441 if (ret != 0) {
451442 dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
....@@ -455,9 +446,6 @@
455446 wm831x_rtc_add_randomness(wm831x);
456447
457448 return 0;
458
-
459
-err:
460
- return ret;
461449 }
462450
463451 static const struct dev_pm_ops wm831x_rtc_pm_ops = {