hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rtc/rtc-sh.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * SuperH On-Chip RTC Support
34 *
....@@ -9,10 +10,6 @@
910 *
1011 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
1112 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
12
- *
13
- * This file is subject to the terms and conditions of the GNU General Public
14
- * License. See the file "COPYING" in the main directory of this archive
15
- * for more details.
1613 */
1714 #include <linux/module.h>
1815 #include <linux/mod_devicetable.h>
....@@ -279,6 +276,9 @@
279276 struct sh_rtc *rtc = dev_get_drvdata(dev);
280277 unsigned int sec128, sec2, yr, yr100, cf_bit;
281278
279
+ if (!(readb(rtc->regbase + RCR2) & RCR2_RTCEN))
280
+ return -EINVAL;
281
+
282282 do {
283283 unsigned int tmp;
284284
....@@ -469,7 +469,6 @@
469469 {
470470 struct sh_rtc *rtc;
471471 struct resource *res;
472
- struct rtc_time r;
473472 char clk_name[6];
474473 int clk_id, ret;
475474
....@@ -505,8 +504,7 @@
505504 if (unlikely(!rtc->res))
506505 return -EBUSY;
507506
508
- rtc->regbase = devm_ioremap_nocache(&pdev->dev, rtc->res->start,
509
- rtc->regsize);
507
+ rtc->regbase = devm_ioremap(&pdev->dev, rtc->res->start, rtc->regsize);
510508 if (unlikely(!rtc->regbase))
511509 return -EINVAL;
512510
....@@ -530,6 +528,10 @@
530528 */
531529 rtc->clk = NULL;
532530 }
531
+
532
+ rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
533
+ if (IS_ERR(rtc->rtc_dev))
534
+ return PTR_ERR(rtc->rtc_dev);
533535
534536 clk_enable(rtc->clk);
535537
....@@ -594,20 +596,20 @@
594596 sh_rtc_setaie(&pdev->dev, 0);
595597 sh_rtc_setcie(&pdev->dev, 0);
596598
597
- rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "sh",
598
- &sh_rtc_ops, THIS_MODULE);
599
- if (IS_ERR(rtc->rtc_dev)) {
600
- ret = PTR_ERR(rtc->rtc_dev);
601
- goto err_unmap;
602
- }
603
-
599
+ rtc->rtc_dev->ops = &sh_rtc_ops;
604600 rtc->rtc_dev->max_user_freq = 256;
605601
606
- /* reset rtc to epoch 0 if time is invalid */
607
- if (rtc_read_time(rtc->rtc_dev, &r) < 0) {
608
- rtc_time_to_tm(0, &r);
609
- rtc_set_time(rtc->rtc_dev, &r);
602
+ if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
603
+ rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
604
+ rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
605
+ } else {
606
+ rtc->rtc_dev->range_min = mktime64(1999, 1, 1, 0, 0, 0);
607
+ rtc->rtc_dev->range_max = mktime64(2098, 12, 31, 23, 59, 59);
610608 }
609
+
610
+ ret = rtc_register_device(rtc->rtc_dev);
611
+ if (ret)
612
+ goto err_unmap;
611613
612614 device_init_wakeup(&pdev->dev, 1);
613615 return 0;
....@@ -681,5 +683,5 @@
681683 MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, "
682684 "Jamie Lenehan <lenehan@twibble.org>, "
683685 "Angelo Castello <angelo.castello@st.com>");
684
-MODULE_LICENSE("GPL");
686
+MODULE_LICENSE("GPL v2");
685687 MODULE_ALIAS("platform:" DRV_NAME);