Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: sh: add support for rza series

This same RTC is used in RZ/A series MPUs, therefore with some slight
changes, this driver can be reused. Additionally, since ARM architectures
require Device Tree configurations, device tree support has been added.

Signed-off-by: Chris Brandt <chris.brandt@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

authored by

Chris Brandt and committed by
Alexandre Belloni
dab5aec6 65e9e65c

+30 -7
+2 -2
drivers/rtc/Kconfig
··· 1303 1303 1304 1304 config RTC_DRV_SH 1305 1305 tristate "SuperH On-Chip RTC" 1306 - depends on SUPERH && HAVE_CLK 1306 + depends on SUPERH || ARCH_RENESAS 1307 1307 help 1308 1308 Say Y here to enable support for the on-chip RTC found in 1309 - most SuperH processors. 1309 + most SuperH processors. This RTC is also found in RZ/A SoCs. 1310 1310 1311 1311 To compile this driver as a module, choose M here: the 1312 1312 module will be called rtc-sh.
+28 -5
drivers/rtc/rtc-sh.c
··· 27 27 #include <linux/log2.h> 28 28 #include <linux/clk.h> 29 29 #include <linux/slab.h> 30 + #ifdef CONFIG_SUPERH 30 31 #include <asm/rtc.h> 32 + #else 33 + /* Default values for RZ/A RTC */ 34 + #define rtc_reg_size sizeof(u16) 35 + #define RTC_BIT_INVERTED 0 /* no chip bugs */ 36 + #define RTC_CAP_4_DIGIT_YEAR (1 << 0) 37 + #define RTC_DEF_CAPABILITIES RTC_CAP_4_DIGIT_YEAR 38 + #endif 31 39 32 40 #define DRV_NAME "sh-rtc" 33 41 ··· 578 570 rtc->alarm_irq = platform_get_irq(pdev, 2); 579 571 580 572 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 573 + if (!res) 574 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 581 575 if (unlikely(res == NULL)) { 582 576 dev_err(&pdev->dev, "No IO resource\n"); 583 577 return -ENOENT; ··· 597 587 if (unlikely(!rtc->regbase)) 598 588 return -EINVAL; 599 589 600 - clk_id = pdev->id; 601 - /* With a single device, the clock id is still "rtc0" */ 602 - if (clk_id < 0) 603 - clk_id = 0; 590 + if (!pdev->dev.of_node) { 591 + clk_id = pdev->id; 592 + /* With a single device, the clock id is still "rtc0" */ 593 + if (clk_id < 0) 594 + clk_id = 0; 604 595 605 - snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id); 596 + snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id); 597 + } else 598 + snprintf(clk_name, sizeof(clk_name), "fck"); 606 599 607 600 rtc->clk = devm_clk_get(&pdev->dev, clk_name); 608 601 if (IS_ERR(rtc->clk)) { ··· 621 608 clk_enable(rtc->clk); 622 609 623 610 rtc->capabilities = RTC_DEF_CAPABILITIES; 611 + 612 + #ifdef CONFIG_SUPERH 624 613 if (dev_get_platdata(&pdev->dev)) { 625 614 struct sh_rtc_platform_info *pinfo = 626 615 dev_get_platdata(&pdev->dev); ··· 633 618 */ 634 619 rtc->capabilities |= pinfo->capabilities; 635 620 } 621 + #endif 636 622 637 623 if (rtc->carry_irq <= 0) { 638 624 /* register shared periodic/carry/alarm irq */ ··· 754 738 755 739 static SIMPLE_DEV_PM_OPS(sh_rtc_pm_ops, sh_rtc_suspend, sh_rtc_resume); 756 740 741 + static const struct of_device_id sh_rtc_of_match[] = { 742 + { .compatible = "renesas,sh-rtc", }, 743 + { /* sentinel */ } 744 + }; 745 + MODULE_DEVICE_TABLE(of, sh_rtc_of_match); 746 + 757 747 static struct platform_driver sh_rtc_platform_driver = { 758 748 .driver = { 759 749 .name = DRV_NAME, 760 750 .pm = &sh_rtc_pm_ops, 751 + .of_match_table = sh_rtc_of_match, 761 752 }, 762 753 .remove = __exit_p(sh_rtc_remove), 763 754 };