RTC: LPC32xx: Introduce RTC driver for the LPC32xx (v2)
Subsystems (2)
This patch set adds support for the LPC32xx built-in RTC. This is a persistent RTC with alarm on it's own power domain and a dedicated oscillator. UIE emulation is used for *_UIE_* ioctls.
v2 includes updates from the initial review of the RTC driver.
The patch can be pulled from:
git://git.lpclinux.com/linux-2.6-lpc rtc-lpc32xx_v2
PATCH 1/1 rtc: rtc-lpc32xx: Introduce RTC driver for the LPC32XX SoC (v2)
From: Kevin Wells <[email protected]>
This patch contains the RTC driver for the built-in RTC in the LPC32XX SoC. This patch includes updates from the initial review comments.
Changes since v1:
Fixed spaces/tabbing in lpc32xx entry in Kconfig/Makefile Remove improper enable for rtc->alarm_enabled Removed typecast on rtc structure in irq handler Switch to resource managed (devm_) variants of kzalloc
and other functions in probe. Updated remove based on these changes.
Disabled alarm on probe instead of keeping current register
settings. No changes for suspend.
Allowed driver to continue operation without wakeup or
alarm irq if the rtc irq request failed.
Relocated module_init and _exit macros to just after it's
associated function
Passed a NULL pointer to .driver.pm in platform driver
structure instead of a list of NULL functions.
Added MODULE_ALIAS
--- drivers/rtc/Kconfig | 9 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-lpc32xx.c | 392 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 402 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/rtc-lpc32xx.c
drivers/rtc/Kconfig +9 -0
@@ -916,4 +916,13 @@ config RTC_DRV_JZ4740 This driver can also be buillt as a module. If so, the module will be called rtc-jz4740. +config RTC_DRV_LPC32XX + depends on ARCH_LPC32XX + tristate "NXP LPC32XX RTC" + help + This enables support for the NXP RTC in the LPC32XX + + This driver can also be buillt as a module. If so, the module + will be called rtc-lpc32xx. + endif # RTC_CLASS
drivers/rtc/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o +obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o obj-$(CONFIG_RTC_DRV_M48T35) += rtc-m48t35.o
drivers/rtc/rtc-lpc32xx.c new file +392 -0
392 lines not on this page · raw message
Signature · 1 line
1.7.1.1
Re: [rtc-linux] [PATCH] rtc: rtc-lpc32xx: Introduce RTC driver for the LPC32XX SoC (v2)
2010/8/12 <[email protected]>:
Quoted 23 lines
From: Kevin Wells <[email protected]>
This patch contains the RTC driver for the built-in RTC in the LPC32XX SoC. This patch includes updates from the initial review comments.
Changes since v1:
? ? ? ?Fixed spaces/tabbing in lpc32xx entry in Kconfig/Makefile ? ? ? ?Remove improper enable forrtc->alarm_enabled
? ? ? ?Removed typecast on rtc structure in irq handler ? ? ? ?Switch to resource managed (devm_) variants of kzalloc ? ? ? ? ? ? ? ?and other functions in probe. Updated remove ? ? ? ? ? ? ? ?based on these changes.
? ? ? ?Disabled alarm on probe instead of keeping current register ? ? ? ? ? ? ? ?settings. No changes for suspend.
? ? ? ?Allowed driver to continue operation without wakeup or ? ? ? ? ? ? ? ?alarm irq if the rtc irq request failed. ? ? ? ?Relocatedmodule_initand_exitmacros to just after it's ? ? ? ? ? ? ? ?associated function
? ? ? ?Passed a NULL pointer to .driver.pm in platform driver ? ? ? ? ? ? ? ?structure instead of a list of NULL functions. ? ? ? ?AddedMODULE_ALIAS
Quoted 2 lines
Signed-off-by Kevin Wells <[email protected]>Signed-off-by Durgesh Pattamatta <[email protected]>
Now, it looks good to me.
Quoted 443 lines
---
?drivers/rtc/Kconfig ? ? ? | ? ?9 + ?drivers/rtc/Makefile ? ? ?| ? ?1 + ?drivers/rtc/rtc-lpc32xx.c | ?392 +++++++++++++++++++++++++++++++++++++++++++++?3 files changed, 402 insertions(+), 0 deletions(-) ?create mode 100644
drivers/rtc/rtc-lpc32xx.cdrivers/rtc/Kconfig +0
-0@@ -916,4 +916,13 @@ config RTC_DRV_JZ4740? ? ? ? ?This driver can also be buillt as a module. If so, the module ? ? ? ? ?will be called rtc-jz4740.
drivers/rtc/Kconfig +9
-0+config RTC_DRV_LPC32XX + ? ? ? depends on ARCH_LPC32XX + ? ? ? tristate "NXP LPC32XX RTC" + ? ? ? help + ? ? ? ? This enables support for the NXP RTC in the LPC32XX + + ? ? ? ? This driver can also be buillt as a module. If so, the module + ? ? ? ? will be called rtc-lpc32xx. +?endif #
RTC_CLASSdrivers/rtc/Makefile +0
-0@@ -48,6 +48,7 @@ obj-$(CONFIG_RTC_DRV_FM3130) ?+= rtc-fm3130.o?obj-$(CONFIG_RTC_DRV_GENERIC) ?+= rtc-generic.o
?obj-$(CONFIG_RTC_DRV_ISL1208) ?+= rtc-isl1208.o
?obj-$(CONFIG_RTC_DRV_JZ4740) ? += rtc-jz4740.o
+obj-$(CONFIG_RTC_DRV_LPC32XX) ?+= rtc-lpc32xx.o
?obj-$(CONFIG_RTC_DRV_M41T80) ? += rtc-m41t80.o
?obj-$(CONFIG_RTC_DRV_M41T94) ? += rtc-m41t94.o
?obj-$(CONFIG_RTC_DRV_M48T35) ? += rtc-m48t35.odrivers/rtc/rtc-lpc32xx.c new file +392
-1@@ -0,0 +1,392 @@ +/* +* Copyright (C) 2010 NXP Semiconductors +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* ?You should have received a copy of the GNU General Public License along +* ?with this program; if not, write to the Free Software Foundation, Inc., +* ?675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/platform_device.h> +#include <linux/spinlock.h> +#include <linux/rtc.h> +#include <linux/slab.h> +#include <linux/io.h> + +/* +* Clock and Power control register offsets +*/ +#define RTC_UCOUNT ? ? ? ? ? ? 0x00 +#define RTC_DCOUNT ? ? ? ? ? ? 0x04 +#define RTC_MATCH0 ? ? ? ? ? ? 0x08 +#define RTC_MATCH1 ? ? ? ? ? ? 0x0C +#define RTC_CTRL ? ? ? ? ? ? ? 0x10 +#define RTC_INTSTAT ? ? ? ? ? ?0x14 +#define RTC_KEY ? ? ? ? ? ? ? ? ? ? ? ?0x18 +#define RTC_SRAM ? ? ? ? ? ? ? 0x80 + +#define RTC_MATCH0_EN ? ? ? ? ?(1 << 0) +#define RTC_MATCH1_EN ? ? ? ? ?(1 << 1) +#define RTC_ONSW_MATCH0_EN ? ? (1 << 2) +#define RTC_ONSW_MATCH1_EN ? ? (1 << 3) +#define RTC_SW_RESET ? ? ? ? ? (1 << 4) +#define RTC_CNTR_DIS ? ? ? ? ? (1 << 6) +#define RTC_ONSW_FORCE_HIGH ? ?(1 << 7) + +#define RTC_MATCH0_INT_STS ? ? (1 << 0) +#define RTC_MATCH1_INT_STS ? ? (1 << 1) +#define RTC_ONSW_INT_STS ? ? ? (1 << 2) + +#define RTC_KEY_ONSW_LOADVAL ? 0xB5C13F27 + +#define RTC_NAME "rtc-lpc32xx" + +#define rtc_readl (dev, reg) \ + ? ? ? __raw_readl((dev)->rtc_base + (reg)) +#define rtc_writel (dev, reg, val) \ + ? ? ? __raw_writel((val), (dev)->rtc_base + (reg)) + +struct lpc32xx_rtc { + ? ? ? void __iomem *rtc_base; + ? ? ? int irq; + ? ? ? int alarm_enabled; + ? ? ? struct rtc_device *rtc; + ? ? ? spinlock_t lock; +}; + +static int lpc32xx_rtc_read_time (struct device *dev,struct rtc_time *time) +{ + ? ? ? unsigned long elapsed_sec; + ? ? ? struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); + + ? ? ? elapsed_sec = rtc_readl(rtc, RTC_UCOUNT); + ? ? ? rtc_time_to_tm(elapsed_sec, time); + + ? ? ? return rtc_valid_tm(time); +} + +static int lpc32xx_rtc_set_mmss (struct device *dev,unsigned long secs) +{ + ? ? ? struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); + ? ? ? u32 tmp; + + ? ? ? spin_lock_irq(&rtc->lock); + + ? ? ? /* RTC must be disabled during count update */ + ? ? ? tmp = rtc_readl(rtc, RTC_CTRL); + ? ? ? rtc_writel(rtc, RTC_CTRL, tmp | RTC_CNTR_DIS); + ? ? ? rtc_writel(rtc, RTC_UCOUNT, secs); + ? ? ? rtc_writel(rtc, RTC_DCOUNT, 0xFFFFFFFF - secs); + ? ? ? rtc_writel(rtc, RTC_CTRL, tmp &= ~RTC_CNTR_DIS); + + ? ? ? spin_unlock_irq(&rtc->lock); + + ? ? ? return 0; +} + +static int lpc32xx_rtc_read_alarm (struct device *dev, + ? ? ? struct rtc_wkalrm *wkalrm) +{ + ? ? ? struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); + + ? ? ? rtc_time_to_tm(rtc_readl(rtc, RTC_MATCH0), &wkalrm->time); + ? ? ? wkalrm->enabled = rtc->alarm_enabled; + + ? ? ? return rtc_valid_tm(&wkalrm->time); +} + +static int lpc32xx_rtc_set_alarm (struct device *dev, + ? ? ? struct rtc_wkalrm *wkalrm) +{ + ? ? ? struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); + ? ? ? unsigned long alarmsecs; + ? ? ? u32 tmp; + ? ? ? int ret; + + ? ? ? ret = rtc_tm_to_time(&wkalrm->time, &alarmsecs); + ? ? ? if (ret < 0) { + ? ? ? ? ? ? ? dev_err(dev, "Failed to convert time: %d\n", ret); + ? ? ? ? ? ? ? return ret; + ? ? ? } + + ? ? ? spin_lock_irq(&rtc->lock); + + ? ? ? /* Disable alarm during update */ + ? ? ? tmp = rtc_readl(rtc, RTC_CTRL); + ? ? ? rtc_writel(rtc, RTC_CTRL, tmp & ~RTC_MATCH0_EN); + + ? ? ? rtc->alarm_enabled = wkalrm->enabled; + ? ? ? if (wkalrm->enabled) { + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_MATCH0, alarmsecs); + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_INTSTAT, RTC_MATCH0_INT_STS); + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_CTRL, tmp | RTC_MATCH0_EN); + ? ? ? } + + ? ? ? spin_unlock_irq(&rtc->lock); + + ? ? ? return 0; +} + +static int lpc32xx_rtc_alarm_irq_enable (struct device *dev, + ? ? ? unsigned int enabled) +{ + ? ? ? struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); + ? ? ? u32 tmp; + + ? ? ? spin_lock_irq(&rtc->lock); + ? ? ? rtc->alarm_enabled = (int) enabled; + ? ? ? tmp = rtc_readl(rtc, RTC_CTRL); + + ? ? ? if (enabled) + ? ? ? ? ? ? ? tmp |= RTC_MATCH0_EN; + ? ? ? else + ? ? ? ? ? ? ? tmp &= ~RTC_MATCH0_EN; + + ? ? ? rtc_writel(rtc, RTC_CTRL, tmp); + ? ? ? spin_unlock_irq(&rtc->lock); + + ? ? ? return 0; +} + +static irqreturn_t lpc32xx_rtc_alarm_interrupt (int irq,void *dev) +{ + ? ? ? struct lpc32xx_rtc *rtc = dev; + + ? ? ? spin_lock(&rtc->lock); + + ? ? ? /* Disable alarm interrupt */ + ? ? ? rtc_writel(rtc, RTC_CTRL, + ? ? ? ? ? ? ? rtc_readl(rtc, RTC_CTRL) & ~RTC_MATCH0_EN); + ? ? ? rtc->alarm_enabled = 0; + + ? ? ? /* + ? ? ? ?* Write a large value to the match value so the RTC won't + ? ? ? ?* keep firing the match status + ? ? ? ?*/ + ? ? ? rtc_writel(rtc, RTC_MATCH0, 0xFFFFFFFF); + ? ? ? rtc_writel(rtc, RTC_INTSTAT, RTC_MATCH0_INT_STS); + + ? ? ? spin_unlock(&rtc->lock); + + ? ? ? rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF); + + ? ? ? return IRQ_HANDLED; +} + +static const struct rtc_class_ops lpc32xx_rtc_ops = { + ? ? ? .read_time ? ? ? ? ? ? ?= lpc32xx_rtc_read_time, + ? ? ? .set_mmss ? ? ? ? ? ? ? = lpc32xx_rtc_set_mmss, + ? ? ? .read_alarm ? ? ? ? ? ? = lpc32xx_rtc_read_alarm, + ? ? ? .set_alarm ? ? ? ? ? ? ?= lpc32xx_rtc_set_alarm, + ? ? ? .alarm_irq_enable ? ? ? = lpc32xx_rtc_alarm_irq_enable, +}; + +static int __devinit lpc32xx_rtc_probe (struct platform_device *pdev) +{ + ? ? ? struct resource *res; + ? ? ? struct lpc32xx_rtc *rtc; + ? ? ? resource_size_t size; + ? ? ? int rtcirq; + ? ? ? u32 tmp; + + ? ? ? res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + ? ? ? if (!res) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "Can't get memory resource\n"); + ? ? ? ? ? ? ? return -ENOENT; + ? ? ? } + + ? ? ? rtcirq = platform_get_irq(pdev, 0); + ? ? ? if (rtcirq < 0 || rtcirq >= NR_IRQS) { + ? ? ? ? ? ? ? dev_warn(&pdev->dev, "Can't get interrupt resource\n"); + ? ? ? ? ? ? ? rtcirq = -1; + ? ? ? } + + ? ? ? rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + ? ? ? if (unlikely(!rtc)) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "Can't allocate memory\n"); + ? ? ? ? ? ? ? return -ENOMEM; + ? ? ? } + ? ? ? rtc->irq = rtcirq; + + ? ? ? size = resource_size(res); + + ? ? ? if (!devm_request_mem_region(&pdev->dev, res->start, size, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?pdev->name)) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "RTC registers are not free\n"); + ? ? ? ? ? ? ? return -EBUSY; + ? ? ? } + + ? ? ? rtc->rtc_base = devm_ioremap(&pdev->dev, res->start, size); + ? ? ? if (!rtc->rtc_base) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "Can't map memory\n"); + ? ? ? ? ? ? ? return -ENOMEM; + ? ? ? } + + ? ? ? spin_lock_init(&rtc->lock); + + ? ? ? /* + ? ? ? ?* The RTC is on a seperate power domain and can keep it's state + ? ? ? ?* across a chip power cycle. If the RTC has never been previously + ? ? ? ?* setup, then set it up now for the first time. + ? ? ? ?*/ + ? ? ? tmp = rtc_readl(rtc, RTC_CTRL); + ? ? ? if (rtc_readl(rtc, RTC_KEY) == RTC_KEY_ONSW_LOADVAL) { + ? ? ? ? ? ? ? tmp &= ~(RTC_SW_RESET | RTC_CNTR_DIS | RTC_MATCH0_EN | + ? ? ? ? ? ? ? ? ? ? ? RTC_MATCH1_EN | RTC_ONSW_MATCH0_EN | + ? ? ? ? ? ? ? ? ? ? ? RTC_ONSW_MATCH1_EN | RTC_ONSW_FORCE_HIGH); + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_CTRL, tmp); + + ? ? ? ? ? ? ? /* Clear latched interrupt states */ + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_MATCH0, 0xFFFFFFFF); + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_INTSTAT, RTC_MATCH0_INT_STS | + ? ? ? ? ? ? ? ? ? ? ? RTC_MATCH1_INT_STS | RTC_ONSW_INT_STS); + + ? ? ? ? ? ? ? /* Write key value to RTC so it won't reload on reset */ + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_KEY, RTC_KEY_ONSW_LOADVAL); + ? ? ? } else + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_CTRL, tmp & ~RTC_ONSW_MATCH0_EN); + + ? ? ? platform_set_drvdata(pdev, rtc); + + ? ? ? rtc->rtc = rtc_device_register(RTC_NAME, &pdev->dev, &lpc32xx_rtc_ops, + ? ? ? ? ? ? ? THIS_MODULE); + ? ? ? if (IS_ERR(rtc->rtc)) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "Can't get RTC\n"); + ? ? ? ? ? ? ? return PTR_ERR(rtc->rtc); + ? ? ? } + + ? ? ? /* + ? ? ? ?* IRQ is enabled after device registration in case alarm IRQ + ? ? ? ?* is pending upon suspend exit. + ? ? ? ?*/ + ? ? ? if (rtc->irq >= 0) { + ? ? ? ? ? ? ? if (devm_request_irq(&pdev->dev, rtc->irq, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?lpc32xx_rtc_alarm_interrupt, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?IRQF_DISABLED, pdev->name, rtc) < 0) { + ? ? ? ? ? ? ? ? ? ? ? dev_warn(&pdev->dev, "Can't request interrupt.\n"); + ? ? ? ? ? ? ? ? ? ? ? rtc->irq = -1; + ? ? ? ? ? ? ? } else + ? ? ? ? ? ? ? ? ? ? ? device_init_wakeup(&pdev->dev, 1); + ? ? ? } + + ? ? ? return 0; +} + +static int __devexit lpc32xx_rtc_remove(struct platform_device *pdev) +{ + ? ? ? struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); + + ? ? ? if (rtc->irq >= 0) + ? ? ? ? ? ? ? device_init_wakeup(&pdev->dev, 0); + + ? ? ? rtc_device_unregister(rtc->rtc); + + ? ? ? return 0; +} + +#ifdef CONFIG_PM +static int lpc32xx_rtc_suspend (struct device *dev) +{ + ? ? ? struct platform_device *pdev = to_platform_device(dev); + ? ? ? struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); + + ? ? ? if (rtc->irq >= 0) { + ? ? ? ? ? ? ? if (device_may_wakeup(&pdev->dev)) + ? ? ? ? ? ? ? ? ? ? ? enable_irq_wake(rtc->irq); + ? ? ? ? ? ? ? else + ? ? ? ? ? ? ? ? ? ? ? disable_irq_wake(rtc->irq); + ? ? ? } + + ? ? ? return 0; +} + +static int lpc32xx_rtc_resume (struct device *dev) +{ + ? ? ? struct platform_device *pdev = to_platform_device(dev); + ? ? ? struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); + + ? ? ? if (rtc->irq >= 0 && device_may_wakeup(&pdev->dev)) + ? ? ? ? ? ? ? disable_irq_wake(rtc->irq); + + ? ? ? return 0; +} + +/* Unconditionally disable the alarm */ +static int lpc32xx_rtc_freeze (struct device *dev) +{ + ? ? ? struct platform_device *pdev = to_platform_device(dev); + ? ? ? struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); + + ? ? ? spin_lock_irq(&rtc->lock); + + ? ? ? rtc_writel(rtc, RTC_CTRL, + ? ? ? ? ? ? ? rtc_readl(rtc, RTC_CTRL) & ~RTC_MATCH0_EN); + + ? ? ? spin_unlock_irq(&rtc->lock); + + ? ? ? return 0; +} + +static int lpc32xx_rtc_thaw (struct device *dev) +{ + ? ? ? struct platform_device *pdev = to_platform_device(dev); + ? ? ? struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); + + ? ? ? if (rtc->alarm_enabled) { + ? ? ? ? ? ? ? spin_lock_irq(&rtc->lock); + + ? ? ? ? ? ? ? rtc_writel(rtc, RTC_CTRL, + ? ? ? ? ? ? ? ? ? ? ? rtc_readl(rtc, RTC_CTRL) | RTC_MATCH0_EN); + + ? ? ? ? ? ? ? spin_unlock_irq(&rtc->lock); + ? ? ? } + + ? ? ? return 0; +} + +static const struct dev_pm_ops lpc32xx_rtc_pm_ops = { + ? ? ? .suspend = lpc32xx_rtc_suspend, + ? ? ? .resume = lpc32xx_rtc_resume, + ? ? ? .freeze = lpc32xx_rtc_freeze, + ? ? ? .thaw = lpc32xx_rtc_thaw, + ? ? ? .restore = lpc32xx_rtc_resume +}; + +#define LPC32XX_RTC_PM_OPS (&lpc32xx_rtc_pm_ops) +#else +#define LPC32XX_RTC_PM_OPS NULL +#endif + +static struct platform_driver lpc32xx_rtc_driver = { + ? ? ? .probe ? ? ? ? ?= lpc32xx_rtc_probe, + ? ? ? .remove ? ? ? ? = __devexit_p(lpc32xx_rtc_remove), + ? ? ? .driver = { + ? ? ? ? ? ? ? .name ? = RTC_NAME, + ? ? ? ? ? ? ? .owner ?= THIS_MODULE, + ? ? ? ? ? ? ? .pm ? ? = LPC32XX_RTC_PM_OPS + ? ? ? }, +}; + +static int __init lpc32xx_rtc_init (void ) +{ + ? ? ? return platform_driver_register(&lpc32xx_rtc_driver); +} +module_init (lpc32xx_rtc_init); + +static void __exit lpc32xx_rtc_exit(void) +{ + ? ? ? platform_driver_unregister(&lpc32xx_rtc_driver); +} +module_exit (lpc32xx_rtc_exit); + +MODULE_AUTHOR ("Kevin Wells <[email protected]" ); +MODULE_DESCRIPTION ("RTC driver for the LPC32xx SoC" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:rtc-lpc32xx" ); --1.7.1.1
--
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
Signature · 10 lines
*linux-arm-kernel mailing list mail addr:linux-arm-kernel at lists.infradead.org you can subscribe by: http://lists.infradead.org/mailman/listinfo/linux-arm-kernel * linux-arm-NUC900 mailing list mail addr:NUC900 at googlegroups.com main web: https://groups.google.com/group/NUC900 you can subscribe it by sending me mail: mcuos.com at gmail.com
Re: [rtc-linux] [PATCH] rtc: rtc-lpc32xx: Introduce RTC driver for the LPC32XX SoC (v2)
In reply to [email protected]Hi Kevin,
Quoted 91 lines · On Wed, Aug 11, 2010 at 04:06:20PM -0700, wellsk40 at gmail.com wrote:
From: Kevin Wells <[email protected]>
This patch contains the RTC driver for the built-in RTC in the LPC32XX SoC. This patch includes updates from the initial review comments.
Changes since v1:
Fixed spaces/tabbing in lpc32xx entry in Kconfig/Makefile Remove improper enable forrtc->alarm_enabledRemoved typecast on rtc structure in irq handler Switch to resource managed (devm_) variants of kzalloc
and other functions in probe. Updated remove based on these changes.
Disabled alarm on probe instead of keeping current register
settings. No changes for suspend.
Allowed driver to continue operation without wakeup or
alarm irq if the rtc irq request failed.
Relocatedmodule_initand_exitmacros to just after it's
associated function
Passed a NULL pointer to .driver.pm in platform driver
structure instead of a list of NULL functions.
AddedMODULE_ALIASSigned-off-by Kevin Wells <[email protected]>Signed-off-by Durgesh Pattamatta <[email protected]>--- drivers/rtc/Kconfig | 9 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-lpc32xx.c | 392 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 402 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/rtc-lpc32xx.cdrivers/rtc/Kconfig +9
-0@@ -916,4 +916,13 @@ config RTC_DRV_JZ4740 This driver can also be buillt as a module. If so, the module will be called rtc-jz4740. +config RTC_DRV_LPC32XX + depends on ARCH_LPC32XX + tristate "NXP LPC32XX RTC" + help + This enables support for the NXP RTC in the LPC32XX + + This driver can also be buillt as a module. If so, the module + will be called rtc-lpc32xx. + endif # RTC_CLASSdrivers/rtc/Makefile +1
-0@@ -48,6 +48,7 @@ obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o +obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o obj-$(CONFIG_RTC_DRV_M48T35) += rtc-m48t35.odrivers/rtc/rtc-lpc32xx.c new file +23
-0@@ -0,0 +1,392 @@ +/* +* Copyright (C) 2010 NXP Semiconductors +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/platform_device.h> +#include <linux/spinlock.h> +#include <linux/rtc.h> +#include <linux/slab.h> +#include <linux/io.h> + +/*
drivers/rtc/rtc-lpc32xx.c line 33
Quoted 10 lines
drivers/rtc/rtc-lpc32xx.c new file +10
-0+* Clock and Power control register offsets +*/ +#define RTC_UCOUNT 0x00 +#define RTC_DCOUNT 0x04 +#define RTC_MATCH0 0x08 +#define RTC_MATCH1 0x0C +#define RTC_CTRL 0x10 +#define RTC_INTSTAT 0x14 +#define RTC_KEY 0x18 +#define RTC_SRAM 0x80
How about LPC32XX_-prefixes here?
drivers/rtc/rtc-lpc32xx.c line 41
Quoted 8 lines
drivers/rtc/rtc-lpc32xx.c new file +8
-0+ +#define RTC_MATCH0_EN (1 << 0) +#define RTC_MATCH1_EN (1 << 1) +#define RTC_ONSW_MATCH0_EN (1 << 2) +#define RTC_ONSW_MATCH1_EN (1 << 3) +#define RTC_SW_RESET (1 << 4) +#define RTC_CNTR_DIS (1 << 6) +#define RTC_ONSW_FORCE_HIGH (1 << 7)
How about LPC32XX_RTC_CTRL_*?
drivers/rtc/rtc-lpc32xx.c line 45
Quoted 4 lines
drivers/rtc/rtc-lpc32xx.c new file +4
-0+ +#define RTC_MATCH0_INT_STS (1 << 0) +#define RTC_MATCH1_INT_STS (1 << 1) +#define RTC_ONSW_INT_STS (1 << 2)
LPC32XX_RTC_INTSTAT_*?
drivers/rtc/rtc-lpc32xx.c line 47
Quoted 2 lines
drivers/rtc/rtc-lpc32xx.c new file +2
-0+ +#define RTC_KEY_ONSW_LOADVAL 0xB5C13F27
LPC32XX_*?
Quoted 58 lines
drivers/rtc/rtc-lpc32xx.c new file +58
-0+ +#define RTC_NAME "rtc-lpc32xx" + +#define rtc_readl (dev, reg) \ + __raw_readl((dev)->rtc_base + (reg)) +#define rtc_writel (dev, reg, val) \ + __raw_writel((val), (dev)->rtc_base + (reg)) + +struct lpc32xx_rtc { +void __iomem *rtc_base; +int irq; +int alarm_enabled; +struct rtc_device *rtc; +spinlock_t lock; +}; + +static int lpc32xx_rtc_read_time (struct device *dev,struct rtc_time *time) +{ +unsigned long elapsed_sec; +struct lpc32xx_rtc *rtc =dev_get_drvdata (dev); + + elapsed_sec =rtc_readl (rtc,RTC_UCOUNT ); +rtc_time_to_tm (elapsed_sec, time); + +return rtc_valid_tm (time); +} + +static int lpc32xx_rtc_set_mmss (struct device *dev,unsigned long secs) +{ +struct lpc32xx_rtc *rtc =dev_get_drvdata (dev); +u32 tmp; + +spin_lock_irq (&rtc->lock); + +/* RTC must be disabled during count update */ + tmp =rtc_readl (rtc,RTC_CTRL ); +rtc_writel (rtc,RTC_CTRL , tmp |RTC_CNTR_DIS ); +rtc_writel (rtc,RTC_UCOUNT , secs); +rtc_writel (rtc,RTC_DCOUNT ,0xFFFFFFFF - secs); +rtc_writel (rtc,RTC_CTRL , tmp &= ~RTC_CNTR_DIS ); + +spin_unlock_irq (&rtc->lock); + +return 0 ; +} + +static int lpc32xx_rtc_read_alarm (struct device *dev, +struct rtc_wkalrm *wkalrm) +{ +struct lpc32xx_rtc *rtc =dev_get_drvdata (dev); + +rtc_time_to_tm (rtc_readl (rtc,RTC_MATCH0 ), &wkalrm->time); + wkalrm->enabled = rtc->alarm_enabled; + +return rtc_valid_tm (&wkalrm->time); +} + +static int lpc32xx_rtc_set_alarm(struct device *dev,
drivers/rtc/rtc-lpc32xx.c line 115
Quoted 10 lines
drivers/rtc/rtc-lpc32xx.c new file +10
-0+ struct rtc_wkalrm *wkalrm) +{ +struct lpc32xx_rtc *rtc =dev_get_drvdata (dev); +unsigned long alarmsecs; +u32 tmp; +int ret; + + ret =rtc_tm_to_time (&wkalrm->time, &alarmsecs); +if (ret <0 ) { +dev_err (dev,"Failed to convert time: %d\n" , ret);
Minor: Error or warning?
Quoted 19 lines
drivers/rtc/rtc-lpc32xx.c new file +19
-0+return ret; + } + +spin_lock_irq (&rtc->lock); + +/* Disable alarm during update */ + tmp =rtc_readl (rtc,RTC_CTRL ); +rtc_writel (rtc,RTC_CTRL , tmp & ~RTC_MATCH0_EN ); + + rtc->alarm_enabled = wkalrm->enabled; +if (wkalrm->enabled) { +rtc_writel (rtc,RTC_MATCH0 , alarmsecs); +rtc_writel (rtc,RTC_INTSTAT ,RTC_MATCH0_INT_STS ); +rtc_writel (rtc,RTC_CTRL , tmp |RTC_MATCH0_EN ); + } + +spin_unlock_irq (&rtc->lock); + +return 0 ;
drivers/rtc/rtc-lpc32xx.c line 144
Quoted 10 lines
drivers/rtc/rtc-lpc32xx.c new file +10
-0+} + +static int lpc32xx_rtc_alarm_irq_enable (struct device *dev, +unsigned int enabled) +{ +struct lpc32xx_rtc *rtc =dev_get_drvdata (dev); +u32 tmp; + +spin_lock_irq (&rtc->lock); + rtc->alarm_enabled = (int ) enabled;
Make alarm_enabled also unsigned and save this cast? Shoud also be better for the conversion to wkalarm->enabled which is also unsigned.
Quoted 100 lines
drivers/rtc/rtc-lpc32xx.c new file +100
-0+ tmp =rtc_readl (rtc,RTC_CTRL ); + +if (enabled) + tmp |=RTC_MATCH0_EN ; +else + tmp &= ~RTC_MATCH0_EN ; + +rtc_writel (rtc,RTC_CTRL , tmp); +spin_unlock_irq (&rtc->lock); + +return 0 ; +} + +static irqreturn_t lpc32xx_rtc_alarm_interrupt (int irq,void *dev) +{ +struct lpc32xx_rtc *rtc = dev; + +spin_lock (&rtc->lock); + +/* Disable alarm interrupt */ +rtc_writel (rtc,RTC_CTRL , +rtc_readl (rtc,RTC_CTRL ) & ~RTC_MATCH0_EN ); + rtc->alarm_enabled =0 ; + +/* +* Write a large value to the match value so the RTC won't +* keep firing the match status +*/ +rtc_writel (rtc,RTC_MATCH0 ,0xFFFFFFFF ); +rtc_writel (rtc,RTC_INTSTAT ,RTC_MATCH0_INT_STS ); + +spin_unlock (&rtc->lock); + +rtc_update_irq (rtc->rtc,1 ,RTC_IRQF |RTC_AF ); + +return IRQ_HANDLED ; +} + +static const struct rtc_class_ops lpc32xx_rtc_ops = { + .read_time = lpc32xx_rtc_read_time, + .set_mmss = lpc32xx_rtc_set_mmss, + .read_alarm = lpc32xx_rtc_read_alarm, + .set_alarm = lpc32xx_rtc_set_alarm, + .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable, +}; + +static int __devinit lpc32xx_rtc_probe (struct platform_device *pdev) +{ +struct resource *res; +struct lpc32xx_rtc *rtc; +resource_size_t size; +int rtcirq; +u32 tmp; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"Can't get memory resource\n" ); +return -ENOENT ; + } + + rtcirq =platform_get_irq (pdev,0 ); +if (rtcirq <0 || rtcirq >=NR_IRQS ) { +dev_warn (&pdev->dev,"Can't get interrupt resource\n" ); + rtcirq =-1 ; + } + + rtc =devm_kzalloc (&pdev->dev,sizeof (*rtc),GFP_KERNEL ); +if (unlikely (!rtc)) { +dev_err (&pdev->dev,"Can't allocate memory\n" ); +return -ENOMEM ; + } + rtc->irq = rtcirq; + + size =resource_size (res); + +if (!devm_request_mem_region (&pdev->dev, res->start, size, + pdev->name)) { +dev_err (&pdev->dev,"RTC registers are not free\n" ); +return -EBUSY ; + } + + rtc->rtc_base =devm_ioremap (&pdev->dev, res->start, size); +if (!rtc->rtc_base) { +dev_err (&pdev->dev,"Can't map memory\n" ); +return -ENOMEM ; + } + +spin_lock_init (&rtc->lock); + +/* +* The RTC is on a seperate power domain and can keep it's state +* across a chip power cycle. If the RTC has never been previously +* setup, then set it up now for the first time. +*/ + tmp =rtc_readl (rtc,RTC_CTRL ); +if (rtc_readl (rtc,RTC_KEY ) ==RTC_KEY_ONSW_LOADVAL ) { + tmp &= ~(RTC_SW_RESET |RTC_CNTR_DIS |RTC_MATCH0_EN | +RTC_MATCH1_EN |RTC_ONSW_MATCH0_EN | +RTC_ONSW_MATCH1_EN |RTC_ONSW_FORCE_HIGH ); +rtc_writel (rtc,RTC_CTRL , tmp);
drivers/rtc/rtc-lpc32xx.c line 254
Quoted 10 lines
drivers/rtc/rtc-lpc32xx.c new file +10
-0+ +/* Clear latched interrupt states */ +rtc_writel (rtc,RTC_MATCH0 ,0xFFFFFFFF ); +rtc_writel (rtc,RTC_INTSTAT ,RTC_MATCH0_INT_STS | +RTC_MATCH1_INT_STS |RTC_ONSW_INT_STS ); + +/* Write key value to RTC so it won't reload on reset */ +rtc_writel (rtc,RTC_KEY ,RTC_KEY_ONSW_LOADVAL ); + }else +rtc_writel (rtc,RTC_CTRL , tmp & ~RTC_ONSW_MATCH0_EN );
CodingStyle suggests using braces for else, because the if-block also has them.
drivers/rtc/rtc-lpc32xx.c line 256
Quoted 2 lines
drivers/rtc/rtc-lpc32xx.c new file +2
-0+ +platform_set_drvdata (pdev, rtc);
That one should be cleared on error/remove?
Quoted 10 lines
drivers/rtc/rtc-lpc32xx.c new file +10
-0+ + rtc->rtc =rtc_device_register (RTC_NAME , &pdev->dev, &lpc32xx_rtc_ops, +THIS_MODULE ); +if (IS_ERR (rtc->rtc)) { +dev_err (&pdev->dev,"Can't get RTC\n" ); +return PTR_ERR (rtc->rtc); + } + +/* +* IRQ is enabled after device registration in case alarm IRQ
drivers/rtc/rtc-lpc32xx.c line 276
Quoted 10 lines
drivers/rtc/rtc-lpc32xx.c new file +10
-0+* is pending upon suspend exit. +*/ +if (rtc->irq >=0 ) { +if (devm_request_irq (&pdev->dev, rtc->irq, + lpc32xx_rtc_alarm_interrupt, +IRQF_DISABLED , pdev->name, rtc) <0 ) { +dev_warn (&pdev->dev,"Can't request interrupt.\n" ); + rtc->irq =-1 ; + }else +device_init_wakeup (&pdev->dev,1 );
else-braces.
Quoted 124 lines
drivers/rtc/rtc-lpc32xx.c new file +116
-0+ } + +return 0 ; +} + +static int __devexit lpc32xx_rtc_remove(struct platform_device *pdev) +{ +struct lpc32xx_rtc *rtc =platform_get_drvdata (pdev); + +if (rtc->irq >=0 ) +device_init_wakeup (&pdev->dev,0 ); + +rtc_device_unregister (rtc->rtc); + +return 0 ; +} + +#ifdef CONFIG_PM +static int lpc32xx_rtc_suspend (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct lpc32xx_rtc *rtc =platform_get_drvdata (pdev); + +if (rtc->irq >=0 ) { +if (device_may_wakeup (&pdev->dev)) +enable_irq_wake (rtc->irq); +else +disable_irq_wake (rtc->irq); + } + +return 0 ; +} + +static int lpc32xx_rtc_resume (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct lpc32xx_rtc *rtc =platform_get_drvdata (pdev); + +if (rtc->irq >=0 &&device_may_wakeup (&pdev->dev)) +disable_irq_wake (rtc->irq); + +return 0 ; +} + +/* Unconditionally disable the alarm */ +static int lpc32xx_rtc_freeze (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct lpc32xx_rtc *rtc =platform_get_drvdata (pdev); + +spin_lock_irq (&rtc->lock); + +rtc_writel (rtc,RTC_CTRL , +rtc_readl (rtc,RTC_CTRL ) & ~RTC_MATCH0_EN ); + +spin_unlock_irq (&rtc->lock); + +return 0 ; +} + +static int lpc32xx_rtc_thaw (struct device *dev) +{ +struct platform_device *pdev =to_platform_device (dev); +struct lpc32xx_rtc *rtc =platform_get_drvdata (pdev); + +if (rtc->alarm_enabled) { +spin_lock_irq (&rtc->lock); + +rtc_writel (rtc,RTC_CTRL , +rtc_readl (rtc,RTC_CTRL ) |RTC_MATCH0_EN ); + +spin_unlock_irq (&rtc->lock); + } + +return 0 ; +} + +static const struct dev_pm_ops lpc32xx_rtc_pm_ops = { + .suspend = lpc32xx_rtc_suspend, + .resume = lpc32xx_rtc_resume, + .freeze = lpc32xx_rtc_freeze, + .thaw = lpc32xx_rtc_thaw, + .restore = lpc32xx_rtc_resume +}; + +#define LPC32XX_RTC_PM_OPS (&lpc32xx_rtc_pm_ops) +#else +#define LPC32XX_RTC_PM_OPS NULL +#endif + +static struct platform_driver lpc32xx_rtc_driver = { + .probe = lpc32xx_rtc_probe, + .remove =__devexit_p (lpc32xx_rtc_remove), + .driver = { + .name =RTC_NAME , + .owner =THIS_MODULE , + .pm =LPC32XX_RTC_PM_OPS + }, +}; + +static int __init lpc32xx_rtc_init (void ) +{ +return platform_driver_register (&lpc32xx_rtc_driver); +} +module_init (lpc32xx_rtc_init); + +static void __exit lpc32xx_rtc_exit(void) +{ +platform_driver_unregister (&lpc32xx_rtc_driver); +} +module_exit (lpc32xx_rtc_exit); + +MODULE_AUTHOR ("Kevin Wells <[email protected]" ); +MODULE_DESCRIPTION ("RTC driver for the LPC32xx SoC" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:rtc-lpc32xx" );Signature · 7 lines
1.7.1.1 -- You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver.
Signature · 9 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ | -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100812/1d24a9dd/attachment.sig>
RE: [rtc-linux] [PATCH] rtc: rtc-lpc32xx: Introduce RTC driver for the LPC32XX SoC (v2)
Quoted 5 lines
Quoted 5 lines
drivers/rtc/rtc-lpc32xx.c new file +5
-0+ +/* +* Clock and Power control register offsets */ +#define RTC_UCOUNT 0x00 +#define RTC_DCOUNT 0x04
Quoted 9 lines
drivers/rtc/rtc-lpc32xx.c line 33
Quoted 6 lines
drivers/rtc/rtc-lpc32xx.c new file +6
-0+#define RTC_MATCH0 0x08 +#define RTC_MATCH1 0x0C +#define RTC_CTRL 0x10 +#define RTC_INTSTAT 0x14 +#define RTC_KEY 0x18 +#define RTC_SRAM 0x80How about LPC32XX_-prefixes here?
Hi Wolfram,
This and all following items are updated in v3
thanks,
Kevin