Commit dab5aec6 authored by Chris Brandt's avatar Chris Brandt Committed by Alexandre Belloni

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: default avatarChris Brandt <chris.brandt@renesas.com>
Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent 65e9e65c
...@@ -1303,10 +1303,10 @@ config RTC_DRV_SA1100 ...@@ -1303,10 +1303,10 @@ config RTC_DRV_SA1100
config RTC_DRV_SH config RTC_DRV_SH
tristate "SuperH On-Chip RTC" tristate "SuperH On-Chip RTC"
depends on SUPERH && HAVE_CLK depends on SUPERH || ARCH_RENESAS
help help
Say Y here to enable support for the on-chip RTC found in Say Y here to enable support for the on-chip RTC found in
most SuperH processors. most SuperH processors. This RTC is also found in RZ/A SoCs.
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called rtc-sh. module will be called rtc-sh.
......
...@@ -27,7 +27,15 @@ ...@@ -27,7 +27,15 @@
#include <linux/log2.h> #include <linux/log2.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/slab.h> #include <linux/slab.h>
#ifdef CONFIG_SUPERH
#include <asm/rtc.h> #include <asm/rtc.h>
#else
/* Default values for RZ/A RTC */
#define rtc_reg_size sizeof(u16)
#define RTC_BIT_INVERTED 0 /* no chip bugs */
#define RTC_CAP_4_DIGIT_YEAR (1 << 0)
#define RTC_DEF_CAPABILITIES RTC_CAP_4_DIGIT_YEAR
#endif
#define DRV_NAME "sh-rtc" #define DRV_NAME "sh-rtc"
...@@ -570,6 +578,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -570,6 +578,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
rtc->alarm_irq = platform_get_irq(pdev, 2); rtc->alarm_irq = platform_get_irq(pdev, 2);
res = platform_get_resource(pdev, IORESOURCE_IO, 0); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (!res)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (unlikely(res == NULL)) { if (unlikely(res == NULL)) {
dev_err(&pdev->dev, "No IO resource\n"); dev_err(&pdev->dev, "No IO resource\n");
return -ENOENT; return -ENOENT;
...@@ -587,12 +597,15 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -587,12 +597,15 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
if (unlikely(!rtc->regbase)) if (unlikely(!rtc->regbase))
return -EINVAL; return -EINVAL;
if (!pdev->dev.of_node) {
clk_id = pdev->id; clk_id = pdev->id;
/* With a single device, the clock id is still "rtc0" */ /* With a single device, the clock id is still "rtc0" */
if (clk_id < 0) if (clk_id < 0)
clk_id = 0; clk_id = 0;
snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id); snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id);
} else
snprintf(clk_name, sizeof(clk_name), "fck");
rtc->clk = devm_clk_get(&pdev->dev, clk_name); rtc->clk = devm_clk_get(&pdev->dev, clk_name);
if (IS_ERR(rtc->clk)) { if (IS_ERR(rtc->clk)) {
...@@ -608,6 +621,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -608,6 +621,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
clk_enable(rtc->clk); clk_enable(rtc->clk);
rtc->capabilities = RTC_DEF_CAPABILITIES; rtc->capabilities = RTC_DEF_CAPABILITIES;
#ifdef CONFIG_SUPERH
if (dev_get_platdata(&pdev->dev)) { if (dev_get_platdata(&pdev->dev)) {
struct sh_rtc_platform_info *pinfo = struct sh_rtc_platform_info *pinfo =
dev_get_platdata(&pdev->dev); dev_get_platdata(&pdev->dev);
...@@ -618,6 +633,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -618,6 +633,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
*/ */
rtc->capabilities |= pinfo->capabilities; rtc->capabilities |= pinfo->capabilities;
} }
#endif
if (rtc->carry_irq <= 0) { if (rtc->carry_irq <= 0) {
/* register shared periodic/carry/alarm irq */ /* register shared periodic/carry/alarm irq */
...@@ -738,10 +754,17 @@ static int sh_rtc_resume(struct device *dev) ...@@ -738,10 +754,17 @@ static int sh_rtc_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(sh_rtc_pm_ops, sh_rtc_suspend, sh_rtc_resume); static SIMPLE_DEV_PM_OPS(sh_rtc_pm_ops, sh_rtc_suspend, sh_rtc_resume);
static const struct of_device_id sh_rtc_of_match[] = {
{ .compatible = "renesas,sh-rtc", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, sh_rtc_of_match);
static struct platform_driver sh_rtc_platform_driver = { static struct platform_driver sh_rtc_platform_driver = {
.driver = { .driver = {
.name = DRV_NAME, .name = DRV_NAME,
.pm = &sh_rtc_pm_ops, .pm = &sh_rtc_pm_ops,
.of_match_table = sh_rtc_of_match,
}, },
.remove = __exit_p(sh_rtc_remove), .remove = __exit_p(sh_rtc_remove),
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment