hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/rtc/rtc-davinci.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * DaVinci Power Management and Real Time Clock Driver for TI platforms
34 *
45 * Copyright (C) 2009 Texas Instruments, Inc
56 *
67 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your 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, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
218 */
229 #include <linux/kernel.h>
2310 #include <linux/init.h>
....@@ -240,7 +227,7 @@
240227 return ret;
241228 }
242229
243
-static int convertfromdays(u16 days, struct rtc_time *tm)
230
+static void convertfromdays(u16 days, struct rtc_time *tm)
244231 {
245232 int tmp_days, year, mon;
246233
....@@ -263,24 +250,17 @@
263250 break;
264251 }
265252 }
266
- return 0;
267253 }
268254
269
-static int convert2days(u16 *days, struct rtc_time *tm)
255
+static void convert2days(u16 *days, struct rtc_time *tm)
270256 {
271257 int i;
272258 *days = 0;
273
-
274
- /* epoch == 1900 */
275
- if (tm->tm_year < 100 || tm->tm_year > 199)
276
- return -EINVAL;
277259
278260 for (i = 2000; i < 1900 + tm->tm_year; i++)
279261 *days += rtc_year_days(1, 12, i);
280262
281263 *days += rtc_year_days(tm->tm_mday, tm->tm_mon, 1900 + tm->tm_year);
282
-
283
- return 0;
284264 }
285265
286266 static int davinci_rtc_read_time(struct device *dev, struct rtc_time *tm)
....@@ -313,8 +293,7 @@
313293 days <<= 8;
314294 days |= day0;
315295
316
- if (convertfromdays(days, tm) < 0)
317
- return -EINVAL;
296
+ convertfromdays(days, tm);
318297
319298 return 0;
320299 }
....@@ -326,8 +305,7 @@
326305 u8 rtc_cctrl;
327306 unsigned long flags;
328307
329
- if (convert2days(&days, tm) < 0)
330
- return -EINVAL;
308
+ convert2days(&days, tm);
331309
332310 spin_lock_irqsave(&davinci_rtc_lock, flags);
333311
....@@ -409,8 +387,7 @@
409387 days <<= 8;
410388 days |= day0;
411389
412
- if (convertfromdays(days, &alm->time) < 0)
413
- return -EINVAL;
390
+ convertfromdays(days, &alm->time);
414391
415392 alm->pending = !!(rtcss_read(davinci_rtc,
416393 PRTCSS_RTC_CCTRL) &
....@@ -426,29 +403,7 @@
426403 unsigned long flags;
427404 u16 days;
428405
429
- if (alm->time.tm_mday <= 0 && alm->time.tm_mon < 0
430
- && alm->time.tm_year < 0) {
431
- struct rtc_time tm;
432
- unsigned long now, then;
433
-
434
- davinci_rtc_read_time(dev, &tm);
435
- rtc_tm_to_time(&tm, &now);
436
-
437
- alm->time.tm_mday = tm.tm_mday;
438
- alm->time.tm_mon = tm.tm_mon;
439
- alm->time.tm_year = tm.tm_year;
440
- rtc_tm_to_time(&alm->time, &then);
441
-
442
- if (then < now) {
443
- rtc_time_to_tm(now + 24 * 60 * 60, &tm);
444
- alm->time.tm_mday = tm.tm_mday;
445
- alm->time.tm_mon = tm.tm_mon;
446
- alm->time.tm_year = tm.tm_year;
447
- }
448
- }
449
-
450
- if (convert2days(&days, &alm->time) < 0)
451
- return -EINVAL;
406
+ convert2days(&days, &alm->time);
452407
453408 spin_lock_irqsave(&davinci_rtc_lock, flags);
454409
....@@ -482,7 +437,6 @@
482437 {
483438 struct device *dev = &pdev->dev;
484439 struct davinci_rtc *davinci_rtc;
485
- struct resource *res;
486440 int ret = 0;
487441
488442 davinci_rtc = devm_kzalloc(&pdev->dev, sizeof(struct davinci_rtc), GFP_KERNEL);
....@@ -490,25 +444,22 @@
490444 return -ENOMEM;
491445
492446 davinci_rtc->irq = platform_get_irq(pdev, 0);
493
- if (davinci_rtc->irq < 0) {
494
- dev_err(dev, "no RTC irq\n");
447
+ if (davinci_rtc->irq < 0)
495448 return davinci_rtc->irq;
496
- }
497449
498
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
499
- davinci_rtc->base = devm_ioremap_resource(dev, res);
450
+ davinci_rtc->base = devm_platform_ioremap_resource(pdev, 0);
500451 if (IS_ERR(davinci_rtc->base))
501452 return PTR_ERR(davinci_rtc->base);
502453
503454 platform_set_drvdata(pdev, davinci_rtc);
504455
505
- davinci_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
506
- &davinci_rtc_ops, THIS_MODULE);
507
- if (IS_ERR(davinci_rtc->rtc)) {
508
- dev_err(dev, "unable to register RTC device, err %d\n",
509
- ret);
456
+ davinci_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
457
+ if (IS_ERR(davinci_rtc->rtc))
510458 return PTR_ERR(davinci_rtc->rtc);
511
- }
459
+
460
+ davinci_rtc->rtc->ops = &davinci_rtc_ops;
461
+ davinci_rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
462
+ davinci_rtc->rtc->range_max = RTC_TIMESTAMP_BEGIN_2000 + (1 << 16) * 86400ULL - 1;
512463
513464 rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG);
514465 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
....@@ -533,7 +484,7 @@
533484
534485 device_init_wakeup(&pdev->dev, 0);
535486
536
- return 0;
487
+ return rtc_register_device(davinci_rtc->rtc);
537488 }
538489
539490 static int __exit davinci_rtc_remove(struct platform_device *pdev)