.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * SuperH On-Chip RTC Support |
---|
3 | 4 | * |
---|
.. | .. |
---|
9 | 10 | * |
---|
10 | 11 | * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org> |
---|
11 | 12 | * 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. |
---|
16 | 13 | */ |
---|
17 | 14 | #include <linux/module.h> |
---|
18 | 15 | #include <linux/mod_devicetable.h> |
---|
.. | .. |
---|
279 | 276 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
---|
280 | 277 | unsigned int sec128, sec2, yr, yr100, cf_bit; |
---|
281 | 278 | |
---|
| 279 | + if (!(readb(rtc->regbase + RCR2) & RCR2_RTCEN)) |
---|
| 280 | + return -EINVAL; |
---|
| 281 | + |
---|
282 | 282 | do { |
---|
283 | 283 | unsigned int tmp; |
---|
284 | 284 | |
---|
.. | .. |
---|
469 | 469 | { |
---|
470 | 470 | struct sh_rtc *rtc; |
---|
471 | 471 | struct resource *res; |
---|
472 | | - struct rtc_time r; |
---|
473 | 472 | char clk_name[6]; |
---|
474 | 473 | int clk_id, ret; |
---|
475 | 474 | |
---|
.. | .. |
---|
505 | 504 | if (unlikely(!rtc->res)) |
---|
506 | 505 | return -EBUSY; |
---|
507 | 506 | |
---|
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); |
---|
510 | 508 | if (unlikely(!rtc->regbase)) |
---|
511 | 509 | return -EINVAL; |
---|
512 | 510 | |
---|
.. | .. |
---|
530 | 528 | */ |
---|
531 | 529 | rtc->clk = NULL; |
---|
532 | 530 | } |
---|
| 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); |
---|
533 | 535 | |
---|
534 | 536 | clk_enable(rtc->clk); |
---|
535 | 537 | |
---|
.. | .. |
---|
594 | 596 | sh_rtc_setaie(&pdev->dev, 0); |
---|
595 | 597 | sh_rtc_setcie(&pdev->dev, 0); |
---|
596 | 598 | |
---|
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; |
---|
604 | 600 | rtc->rtc_dev->max_user_freq = 256; |
---|
605 | 601 | |
---|
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); |
---|
610 | 608 | } |
---|
| 609 | + |
---|
| 610 | + ret = rtc_register_device(rtc->rtc_dev); |
---|
| 611 | + if (ret) |
---|
| 612 | + goto err_unmap; |
---|
611 | 613 | |
---|
612 | 614 | device_init_wakeup(&pdev->dev, 1); |
---|
613 | 615 | return 0; |
---|
.. | .. |
---|
681 | 683 | MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, " |
---|
682 | 684 | "Jamie Lenehan <lenehan@twibble.org>, " |
---|
683 | 685 | "Angelo Castello <angelo.castello@st.com>"); |
---|
684 | | -MODULE_LICENSE("GPL"); |
---|
| 686 | +MODULE_LICENSE("GPL v2"); |
---|
685 | 687 | MODULE_ALIAS("platform:" DRV_NAME); |
---|