From 063adc7502890a0b115da4af4e15cc2622b348de Mon Sep 17 00:00:00 2001 From: Paul Mundt Date: Thu, 16 Apr 2009 14:12:22 +0900 Subject: rtc: rtc-sh: clock framework support. This adds clock framework support to the rtc-sh driver. With this in place, platforms can default to leaving the clock disabled rather than placing it in the always enabled state. Signed-off-by: Paul Mundt --- drivers/rtc/Kconfig | 2 +- drivers/rtc/rtc-sh.c | 67 ++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index ffe34a12f446..4e9851fc1746 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -573,7 +573,7 @@ config RTC_DRV_SA1100 config RTC_DRV_SH tristate "SuperH On-Chip RTC" - depends on RTC_CLASS && SUPERH + depends on RTC_CLASS && SUPERH && HAVE_CLK help Say Y here to enable support for the on-chip RTC found in most SuperH processors. diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c index 9b1ff12bf947..d7310adb7152 100644 --- a/drivers/rtc/rtc-sh.c +++ b/drivers/rtc/rtc-sh.c @@ -1,7 +1,7 @@ /* * SuperH On-Chip RTC Support * - * Copyright (C) 2006, 2007, 2008 Paul Mundt + * Copyright (C) 2006 - 2009 Paul Mundt * Copyright (C) 2006 Jamie Lenehan * Copyright (C) 2008 Angelo Castello * @@ -25,10 +25,11 @@ #include #include #include +#include #include #define DRV_NAME "sh-rtc" -#define DRV_VERSION "0.2.1" +#define DRV_VERSION "0.2.2" #define RTC_REG(r) ((r) * rtc_reg_size) @@ -87,16 +88,17 @@ #define RCR2_START 0x01 /* Start bit */ struct sh_rtc { - void __iomem *regbase; - unsigned long regsize; - struct resource *res; - int alarm_irq; - int periodic_irq; - int carry_irq; - struct rtc_device *rtc_dev; - spinlock_t lock; - unsigned long capabilities; /* See asm-sh/rtc.h for cap bits */ - unsigned short periodic_freq; + void __iomem *regbase; + unsigned long regsize; + struct resource *res; + int alarm_irq; + int periodic_irq; + int carry_irq; + struct clk *clk; + struct rtc_device *rtc_dev; + spinlock_t lock; + unsigned long capabilities; /* See asm/rtc.h for cap bits */ + unsigned short periodic_freq; }; static int __sh_rtc_interrupt(struct sh_rtc *rtc) @@ -294,10 +296,10 @@ static inline void sh_rtc_setaie(struct device *dev, unsigned int enable) tmp = readb(rtc->regbase + RCR1); - if (!enable) - tmp &= ~RCR1_AIE; - else + if (enable) tmp |= RCR1_AIE; + else + tmp &= ~RCR1_AIE; writeb(tmp, rtc->regbase + RCR1); @@ -618,6 +620,7 @@ static int sh_rtc_irq_set_freq(struct device *dev, int freq) { if (!is_power_of_2(freq)) return -EINVAL; + return sh_rtc_ioctl(dev, RTC_IRQP_SET, freq); } @@ -637,7 +640,8 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev) struct sh_rtc *rtc; struct resource *res; struct rtc_time r; - int ret; + char clk_name[6]; + int clk_id, ret; rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL); if (unlikely(!rtc)) @@ -652,6 +656,7 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev) dev_err(&pdev->dev, "No IRQ resource\n"); goto err_badres; } + rtc->periodic_irq = ret; rtc->carry_irq = platform_get_irq(pdev, 1); rtc->alarm_irq = platform_get_irq(pdev, 2); @@ -663,7 +668,7 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev) goto err_badres; } - rtc->regsize = res->end - res->start + 1; + rtc->regsize = resource_size(res); rtc->res = request_mem_region(res->start, rtc->regsize, pdev->name); if (unlikely(!rtc->res)) { @@ -677,6 +682,26 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev) goto err_badmap; } + clk_id = pdev->id; + /* With a single device, the clock id is still "rtc0" */ + if (clk_id < 0) + clk_id = 0; + + snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id); + + rtc->clk = clk_get(&pdev->dev, clk_name); + if (IS_ERR(rtc->clk)) { + /* + * No error handling for rtc->clk intentionally, not all + * platforms will have a unique clock for the RTC, and + * the clk API can handle the struct clk pointer being + * NULL. + */ + rtc->clk = NULL; + } + + clk_enable(rtc->clk); + rtc->rtc_dev = rtc_device_register("sh", &pdev->dev, &sh_rtc_ops, THIS_MODULE); if (IS_ERR(rtc->rtc_dev)) { @@ -759,6 +784,8 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev) return 0; err_unmap: + clk_disable(rtc->clk); + clk_put(rtc->clk); iounmap(rtc->regbase); err_badmap: release_resource(rtc->res); @@ -780,6 +807,7 @@ static int __devexit sh_rtc_remove(struct platform_device *pdev) sh_rtc_setcie(&pdev->dev, 0); free_irq(rtc->periodic_irq, rtc); + if (rtc->carry_irq > 0) { free_irq(rtc->carry_irq, rtc); free_irq(rtc->alarm_irq, rtc); @@ -789,6 +817,9 @@ static int __devexit sh_rtc_remove(struct platform_device *pdev) iounmap(rtc->regbase); + clk_disable(rtc->clk); + clk_put(rtc->clk); + platform_set_drvdata(pdev, NULL); kfree(rtc); @@ -802,11 +833,11 @@ static void sh_rtc_set_irq_wake(struct device *dev, int enabled) struct sh_rtc *rtc = platform_get_drvdata(pdev); set_irq_wake(rtc->periodic_irq, enabled); + if (rtc->carry_irq > 0) { set_irq_wake(rtc->carry_irq, enabled); set_irq_wake(rtc->alarm_irq, enabled); } - } static int sh_rtc_suspend(struct device *dev) -- cgit v1.2.3-59-g8ed1b From 6bf853aeb1d840222aebe532ad5afc861f4d0fbb Mon Sep 17 00:00:00 2001 From: Paul Mundt Date: Thu, 16 Apr 2009 14:15:38 +0900 Subject: sh: sh7722: Don't default enable the RTC clock. rtc-sh takes care of this now, so no need to have this always enabled. Signed-off-by: Paul Mundt --- arch/sh/kernel/cpu/sh4a/setup-sh7722.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7722.c b/arch/sh/kernel/cpu/sh4a/setup-sh7722.c index 0e5d204bc792..406747f07dc0 100644 --- a/arch/sh/kernel/cpu/sh4a/setup-sh7722.c +++ b/arch/sh/kernel/cpu/sh4a/setup-sh7722.c @@ -256,7 +256,6 @@ static int __init sh7722_devices_setup(void) { clk_always_enable("uram0"); /* URAM */ clk_always_enable("xymem0"); /* XYMEM */ - clk_always_enable("rtc0"); /* RTC */ clk_always_enable("veu0"); /* VEU */ clk_always_enable("vpu0"); /* VPU */ clk_always_enable("jpu0"); /* JPU */ -- cgit v1.2.3-59-g8ed1b From b8c193f88ebd8705b3e916532539031cd9fc0b4c Mon Sep 17 00:00:00 2001 From: Paul Mundt Date: Thu, 16 Apr 2009 14:16:33 +0900 Subject: sh: sh7723: Don't default enable the RTC clock. rtc-sh takes care of this now, so no need to have this always enabled. Signed-off-by: Paul Mundt --- arch/sh/kernel/cpu/sh4a/setup-sh7723.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7723.c b/arch/sh/kernel/cpu/sh4a/setup-sh7723.c index 5338dacbcfba..a800466b938c 100644 --- a/arch/sh/kernel/cpu/sh4a/setup-sh7723.c +++ b/arch/sh/kernel/cpu/sh4a/setup-sh7723.c @@ -267,7 +267,6 @@ static struct platform_device *sh7723_devices[] __initdata = { static int __init sh7723_devices_setup(void) { clk_always_enable("meram0"); /* MERAM */ - clk_always_enable("rtc0"); /* RTC */ clk_always_enable("veu1"); /* VEU2H1 */ clk_always_enable("veu0"); /* VEU2H0 */ clk_always_enable("vpu0"); /* VPU */ -- cgit v1.2.3-59-g8ed1b From 8c31813f31cd4403b46802866949a95a6e8fa584 Mon Sep 17 00:00:00 2001 From: Toshinobu Sugioka Date: Tue, 21 Apr 2009 07:34:53 +0900 Subject: sh: Fix mmap2 for handling differing PAGE_SIZEs. mmap2 uses a fixed page shift of 12, regardless of the PAGE_SIZE setting. Fix up the mmap2 code to add some sanity checks on the mapping, and to update pgoff accordingly. Error handling bits based on 4280e3126f641898f0ed1a931645373d3489e2a6 ("frv: fix mmap2 error handling"). Signed-off-by: Toshinobu Sugioka Signed-off-by: Paul Mundt --- arch/sh/kernel/sys_sh.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/sh/kernel/sys_sh.c b/arch/sh/kernel/sys_sh.c index 58dfc02c7af1..e3a7e36639ef 100644 --- a/arch/sh/kernel/sys_sh.c +++ b/arch/sh/kernel/sys_sh.c @@ -63,6 +63,15 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long pgoff) { + /* + * The shift for mmap2 is constant, regardless of PAGE_SIZE + * setting. + */ + if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1)) + return -EINVAL; + + pgoff >>= PAGE_SHIFT - 12; + return do_mmap2(addr, len, prot, flags, fd, pgoff); } -- cgit v1.2.3-59-g8ed1b