Re: [rtc-linux] [PATCH 1/1] rtc: Add real-time clock driver for Tegra.

From: Wan ZongShun
Date: Wed Oct 13 2010 - 23:36:51 EST


Hi Andrew Chew ,

I have a quick look for your patch, Few comments below:

2010/10/14 <achew@xxxxxxxxxx>:
> From: Andrew Chew <achew@xxxxxxxxxx>
>
> This is a platform driver that supports the built-in real-time clock on
> Tegra SOCs.
>
> Signed-off-by: Andrew Chew <achew@xxxxxxxxxx>
> ---
> Âdrivers/rtc/Kconfig   |  10 +
> Âdrivers/rtc/Makefile  Â|  Â1 +
> Âdrivers/rtc/rtc-tegra.c | Â520 +++++++++++++++++++++++++++++++++++++++++++++++
> Â3 files changed, 531 insertions(+), 0 deletions(-)
> Âcreate mode 100644 drivers/rtc/rtc-tegra.c
>
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 2432541..ca0da79 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -963,4 +963,14 @@ 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_TEGRA
> + Â Â Â tristate "NVIDIA Tegra Internal RTC driver"
> + Â Â Â depends on RTC_CLASS && ARCH_TEGRA
> + Â Â Â help
> + Â Â Â Â If you say yes here you get support for the
> + Â Â Â Â Tegra 200 series internal RTC module.
> +
> + Â Â Â Â This drive can also be built as a module. If so, the module
> + Â Â Â Â will be called rtc-tegra.
> +
> Âendif # RTC_CLASS
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 4ff4b88..a7f3617 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -91,6 +91,7 @@ obj-$(CONFIG_RTC_DRV_STARFIRE) Â Â Â Â+= rtc-starfire.o
> Âobj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
> Âobj-$(CONFIG_RTC_DRV_STMP) Â Â += rtc-stmp3xxx.o
> Âobj-$(CONFIG_RTC_DRV_SUN4V) Â Â+= rtc-sun4v.o
> +obj-$(CONFIG_RTC_DRV_TEGRA) Â Â+= rtc-tegra.o
> Âobj-$(CONFIG_RTC_DRV_TEST) Â Â += rtc-test.o
> Âobj-$(CONFIG_RTC_DRV_TWL4030) Â+= rtc-twl.o
> Âobj-$(CONFIG_RTC_DRV_TX4939) Â += rtc-tx4939.o
> diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c
> new file mode 100644
> index 0000000..79054d1
> --- /dev/null
> +++ b/drivers/rtc/rtc-tegra.c
> @@ -0,0 +1,520 @@
> +/*
> + * An RTC driver for the NVIDIA Tegra 200 series internal RTC.
> + *
> + * Copyright (c) 2010, NVIDIA Corporation.
> + * Copyright (c) 2010 Jon Mayo <jmayo@xxxxxxxxxx>
> + *
> + * 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.
> + *
> + * This program is distributed in the hope that it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. ÂSee the GNU General Public License for
> + * more details.
> + *
> + * 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.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA Â02110-1301, USA.
> + */
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/irq.h>
> +#include <linux/io.h>
> +#include <linux/delay.h>
> +#include <linux/rtc.h>
> +#include <linux/platform_device.h>
> +
> +/* how many attempts to wait in tegra_rtc_wait_while_busy(). */
> +#define RTC_TEGRA_RETRIES 15
> +
> +/* STATUS: This bit is set when a write is initiated on the APB side. It is
> + * cleared once the write completes in RTC 32KHz clock domain which could be
> + * several thousands of APB clocks. This must be IDLE before a write is
> + * initiated. Note that this bit is only for writes.
> + * 0 = IDLE
> + * 1 = BUSY
> + */
> +#define RTC_TEGRA_REG_BUSY Â Â Â Â Â Â Â Â Â Â 0x004
> +#define RTC_TEGRA_REG_SECONDS Â Â Â Â Â Â Â Â Â0x008
> +#define RTC_TEGRA_REG_SHADOW_SECONDS Â Â Â Â Â 0x00c
> +#define RTC_TEGRA_REG_MILLI_SECONDS Â Â Â Â Â Â0x010
> +#define RTC_TEGRA_REG_SECONDS_ALARM0 Â Â Â Â Â 0x014
> +#define RTC_TEGRA_REG_SECONDS_ALARM1 Â Â Â Â Â 0x018
> +#define RTC_TEGRA_REG_MILLI_SECONDS_ALARM0 Â Â 0x01c
> +#define RTC_TEGRA_REG_INTR_MASK Â Â Â Â Â Â Â Â Â Â Â Â0x028
> +/* a write to this register performs a clear. reg=reg&(~x) */
> +#define RTC_TEGRA_REG_INTR_STATUS Â Â Â Â Â Â Â0x02c
> +
> +/* bits in INTR_MASK */
> +#define RTC_TEGRA_INTR_MASK_MSEC_CDN_ALARM Â Â (1<<4)
> +#define RTC_TEGRA_INTR_MASK_SEC_CDN_ALARM Â Â Â(1<<3)
> +#define RTC_TEGRA_INTR_MASK_MSEC_ALARM Â Â Â Â (1<<2)
> +#define RTC_TEGRA_INTR_MASK_SEC_ALARM1 Â Â Â Â (1<<1)
> +#define RTC_TEGRA_INTR_MASK_SEC_ALARM0 Â Â Â Â (1<<0)
> +
> +/* bits in INTR_STATUS */
> +#define RTC_TEGRA_INTR_STATUS_MSEC_CDN_ALARM Â (1<<4)
> +#define RTC_TEGRA_INTR_STATUS_SEC_CDN_ALARM Â Â(1<<3)
> +#define RTC_TEGRA_INTR_STATUS_MSEC_ALARM Â Â Â (1<<2)
> +#define RTC_TEGRA_INTR_STATUS_SEC_ALARM1 Â Â Â (1<<1)
> +#define RTC_TEGRA_INTR_STATUS_SEC_ALARM0 Â Â Â (1<<0)
> +
> +struct tegra_rtc_info {
> + Â Â Â struct platform_device Â*pdev;
> +    struct rtc_device    *rtc_dev;
> +    void __iomem      Â*rtc_base; /* NULL if not initialized. */
> +    int           tegra_rtc_irq; /* alarm and periodic irq */
> +    spinlock_t       Âtegra_rtc_lock;
> +};
> +
> +/* check is hardware is accessing APB. */
> +static inline u32 tegra_rtc_check_busy(struct tegra_rtc_info *info)
> +{
> + Â Â Â return readl(info->rtc_base + RTC_TEGRA_REG_BUSY);
> +}
> +
> +/* wait for hardware to be ready for writing.
> + * do not call this inside the spin lock because it sleeps.
> + */
> +static int tegra_rtc_wait_while_busy(struct device *dev)
> +{
> + Â Â Â struct tegra_rtc_info *info = dev_get_drvdata(dev);
> +
> + Â Â Â /* TODO: wait for busy then not busy to catch a leading edge. */
> + Â Â Â int retries = RTC_TEGRA_RETRIES;
> +
> + Â Â Â while (tegra_rtc_check_busy(info)) {
> + Â Â Â Â Â Â Â if (!retries--) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "write failed:retry count exceeded.\n");
> + Â Â Â Â Â Â Â Â Â Â Â return -ETIMEDOUT;
> + Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â msleep(1);
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +/* waits for the RTC to not be busy accessing APB, then write a single value. */
> +static int tegra_rtc_write_not_busy(struct device *dev, unsigned ofs, u32 value)
> +{
> + Â Â Â struct tegra_rtc_info *info = dev_get_drvdata(dev);
> + Â Â Â unsigned long sl_irq_flags;
> + Â Â Â int ret;
> +
> + Â Â Â spin_lock_irqsave(&info->tegra_rtc_lock, sl_irq_flags);
> +
> + Â Â Â if (tegra_rtc_check_busy(info)) {
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
> + Â Â Â Â Â Â Â ret = tegra_rtc_wait_while_busy(dev);
> + Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â return ret;
> + Â Â Â Â Â Â Â spin_lock_irqsave(&info->tegra_rtc_lock, sl_irq_flags);
> + Â Â Â }
> +
> + Â Â Â writel(value, info->rtc_base + ofs);
> +
> + Â Â Â spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
> +
> + Â Â Â return 0;
> +}
> +
> +
> +static int tegra_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> + Â Â Â struct tegra_rtc_info *info = dev_get_drvdata(dev);
> + Â Â Â unsigned long sec, msec;
> + Â Â Â unsigned long sl_irq_flags;
> +
> + Â Â Â spin_lock_irqsave(&info->tegra_rtc_lock, sl_irq_flags);
> +
> + Â Â Â msec = readl(info->rtc_base + RTC_TEGRA_REG_MILLI_SECONDS);
> + Â Â Â sec = readl(info->rtc_base + RTC_TEGRA_REG_SHADOW_SECONDS);
> +
> + Â Â Â spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
> +
> + Â Â Â rtc_time_to_tm(sec, tm);
> +
> + Â Â Â dev_vdbg(dev, "time read as %lu. %d/%d/%d %d:%02u:%02u\n",
> + Â Â Â Â Â Â Â sec,
> + Â Â Â Â Â Â Â tm->tm_mon + 1,
> + Â Â Â Â Â Â Â tm->tm_mday,
> + Â Â Â Â Â Â Â tm->tm_year + 1900,
> + Â Â Â Â Â Â Â tm->tm_hour,
> + Â Â Â Â Â Â Â tm->tm_min,
> + Â Â Â Â Â Â Â tm->tm_sec
> + Â Â Â );
> +
> + Â Â Â return 0;
> +}
> +
> +static int tegra_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> + Â Â Â struct tegra_rtc_info *info = dev_get_drvdata(dev);
> + Â Â Â unsigned long sec;
> + Â Â Â int ret;
> +
> + Â Â Â /* convert tm to seconds. */
> + Â Â Â ret = rtc_valid_tm(tm);
> + Â Â Â if (ret < 0)
> + Â Â Â Â Â Â Â return ret;
> +
> + Â Â Â rtc_tm_to_time(tm, &sec);
> +
> + Â Â Â dev_vdbg(dev, "time set to %lu. %d/%d/%d %d:%02u:%02u\n",
> + Â Â Â Â Â Â Â sec,
> + Â Â Â Â Â Â Â tm->tm_mon+1,
> + Â Â Â Â Â Â Â tm->tm_mday,
> + Â Â Â Â Â Â Â tm->tm_year+1900,
> + Â Â Â Â Â Â Â tm->tm_hour,
> + Â Â Â Â Â Â Â tm->tm_min,
> + Â Â Â Â Â Â Â tm->tm_sec
> + Â Â Â );
> +
> + Â Â Â /* seconds only written if wait succeeded. */
> + Â Â Â ret = tegra_rtc_write_not_busy(dev, RTC_TEGRA_REG_SECONDS, sec);
> +
> + Â Â Â dev_vdbg(dev, "time read back as %d\n",
> + Â Â Â Â Â Â Â readl(info->rtc_base + RTC_TEGRA_REG_SECONDS));
> +
> + Â Â Â return ret;
> +}
> +
> +static int tegra_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
> +{
> + Â Â Â struct tegra_rtc_info *info = dev_get_drvdata(dev);
> + Â Â Â unsigned long sec;
> + Â Â Â unsigned long sl_irq_flags;
> + Â Â Â unsigned tmp;
> +
> + Â Â Â spin_lock_irqsave(&info->tegra_rtc_lock, sl_irq_flags);
> +
> + Â Â Â sec = readl(info->rtc_base + RTC_TEGRA_REG_SECONDS_ALARM0);
> +
> + Â Â Â spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
> +
> + Â Â Â if (sec == 0) {
> + Â Â Â Â Â Â Â /* alarm is disabled. */
> + Â Â Â Â Â Â Â alarm->enabled = 0;
> + Â Â Â Â Â Â Â alarm->time.tm_mon = -1;
> + Â Â Â Â Â Â Â alarm->time.tm_mday = -1;
> + Â Â Â Â Â Â Â alarm->time.tm_year = -1;
> + Â Â Â Â Â Â Â alarm->time.tm_hour = -1;
> + Â Â Â Â Â Â Â alarm->time.tm_min = -1;
> + Â Â Â Â Â Â Â alarm->time.tm_sec = -1;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â /* alarm is enabled. */
> + Â Â Â Â Â Â Â alarm->enabled = 1;
> + Â Â Â Â Â Â Â rtc_time_to_tm(sec, &alarm->time);
> + Â Â Â }
> +
> + Â Â Â tmp = readl(info->rtc_base + RTC_TEGRA_REG_INTR_STATUS);
> + Â Â Â alarm->pending = (tmp & RTC_TEGRA_INTR_STATUS_SEC_ALARM0) != 0;
> +
> + Â Â Â return 0;
> +}
> +
> +static int tegra_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
> +{
> + Â Â Â struct tegra_rtc_info *info = dev_get_drvdata(dev);
> + Â Â Â unsigned status;
> + Â Â Â unsigned long sl_irq_flags;
> + Â Â Â int ret;
> +
> + Â Â Â spin_lock_irqsave(&info->tegra_rtc_lock, sl_irq_flags);
> +
> + Â Â Â if (tegra_rtc_check_busy(info)) { /* wait for the busy bit to clear. */
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
> + Â Â Â Â Â Â Â ret = tegra_rtc_wait_while_busy(dev);
> + Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â return ret;
> + Â Â Â Â Â Â Â spin_lock_irqsave(&info->tegra_rtc_lock, sl_irq_flags);
> + Â Â Â }
> +
> + Â Â Â /* read the original value, and OR in the flag. */
> + Â Â Â status = readl(info->rtc_base + RTC_TEGRA_REG_INTR_MASK);
> + Â Â Â if (enabled)
> + Â Â Â Â Â Â Â status |= RTC_TEGRA_INTR_MASK_SEC_ALARM0; /* set it */
> + Â Â Â else
> + Â Â Â Â Â Â Â status &= ~RTC_TEGRA_INTR_MASK_SEC_ALARM0; /* clear it */
> +
> + Â Â Â writel(status, info->rtc_base + RTC_TEGRA_REG_INTR_MASK);
> +
> + Â Â Â spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
> +
> + Â Â Â return 0;
> +}
> +
> +static int tegra_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
> +{
> + Â Â Â struct tegra_rtc_info *info = dev_get_drvdata(dev);
> + Â Â Â int ret;
> + Â Â Â unsigned long sec;
> +
> + Â Â Â if (alarm->enabled)
> + Â Â Â Â Â Â Â rtc_tm_to_time(&alarm->time, &sec);
> + Â Â Â else
> + Â Â Â Â Â Â Â sec = 0;
> +
> + Â Â Â ret = tegra_rtc_write_not_busy(dev, RTC_TEGRA_REG_SECONDS_ALARM0, sec);
> + Â Â Â dev_vdbg(dev, "alarm read back as %d\n",
> + Â Â Â Â Â Â Â readl(info->rtc_base + RTC_TEGRA_REG_SECONDS_ALARM0));
> +
> + Â Â Â /* if successfully written and alarm is enabled ... */
> + Â Â Â if ((ret == 0) && sec) {
> + Â Â Â Â Â Â Â tegra_rtc_alarm_irq_enable(dev, 1);
> +
> + Â Â Â Â Â Â Â dev_vdbg(dev, "alarm set as %lu. %d/%d/%d %d:%02u:%02u\n",
> + Â Â Â Â Â Â Â Â Â Â Â sec,
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_mon+1,
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_mday,
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_year+1900,
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_hour,
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_min,
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_sec);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â /* disable alarm if 0 or write error. */
> + Â Â Â Â Â Â Â dev_vdbg(dev, "alarm disabled\n");
> + Â Â Â Â Â Â Â tegra_rtc_alarm_irq_enable(dev, 0);
> + Â Â Â }
> +
> + Â Â Â return ret;
> +}
> +
> +static int tegra_rtc_ioctl(
> + Â Â Â struct device *dev, unsigned int cmd, unsigned long arg)
> +{
> + Â Â Â /* use default ioctl handlers for:
> + Â Â Â Â* RTC_RD_TIME, RTC_SET_TIME, RTC_ALM_SET, RTC_ALM_READ, RTC_WKALM_SET,
> + Â Â Â Â* RTC_WKALM_RD, RTC_IRQP_SET, RTC_IRQP_READ, RTC_PIE_ON, RTC_PIE_OFF
> + Â Â Â Â*/
> + Â Â Â return -ENOIOCTLCMD;
> +}

The function is redundant here.

> +
> +/* additional proc lines. */
> +static int tegra_rtc_proc(struct device *dev, struct seq_file *seq)
> +{
> + Â Â Â if (!dev || !dev->driver)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â return seq_printf(seq, "name\t\t: %s\n", dev_name(dev));
> +}
> +
> +static irqreturn_t tegra_rtc_irq_handler(int irq, void *data)
> +{
> + Â Â Â struct device *dev = data;
> + Â Â Â struct tegra_rtc_info *info = dev_get_drvdata(dev);
> + Â Â Â unsigned long events = 0;
> + Â Â Â unsigned status;
> + Â Â Â unsigned long sl_irq_flags;
> +
> + Â Â Â status = readl(info->rtc_base + RTC_TEGRA_REG_INTR_STATUS);
> + Â Â Â if (status) {
> + Â Â Â Â Â Â Â /* clear the interrupt masks and status on any irq. */
> + Â Â Â Â Â Â Â spin_lock_irqsave(&info->tegra_rtc_lock, sl_irq_flags);
> + Â Â Â Â Â Â Â writel(0, info->rtc_base + RTC_TEGRA_REG_INTR_MASK);
> + Â Â Â Â Â Â Â writel(0xffffffff, info->rtc_base + RTC_TEGRA_REG_INTR_STATUS);
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
> + Â Â Â }
> +
> + Â Â Â /* check if Alarm */
> + Â Â Â if ((status & RTC_TEGRA_INTR_STATUS_SEC_ALARM0))
> + Â Â Â Â Â Â Â events |= RTC_IRQF | RTC_AF;
> +
> + Â Â Â /* check if Periodic */
> + Â Â Â if ((status & RTC_TEGRA_INTR_STATUS_SEC_CDN_ALARM))
> + Â Â Â Â Â Â Â events |= RTC_IRQF | RTC_PF;
> +
> + Â Â Â rtc_update_irq(info->rtc_dev, 1, events);
> +
> + Â Â Â return IRQ_HANDLED;
> +}
> +
> +static struct rtc_class_ops tegra_rtc_ops = {
> +    .ioctl     Â= tegra_rtc_ioctl,

There is no need to put it here.

> +    .read_time   Â= tegra_rtc_read_time,
> +    .set_time    = tegra_rtc_set_time,
> +    .read_alarm   = tegra_rtc_read_alarm,
> +    .set_alarm   Â= tegra_rtc_set_alarm,
> +    .proc      = tegra_rtc_proc,
> + Â Â Â .alarm_irq_enable = tegra_rtc_alarm_irq_enable,
> +};
> +
> +static int __init tegra_rtc_probe(struct platform_device *pdev)

__devinit ?

> +{
> + Â Â Â struct tegra_rtc_info *info;
> + Â Â Â struct resource *res;
> + Â Â Â int ret;
> +
> + Â Â Â info = kzalloc(sizeof(struct tegra_rtc_info), GFP_KERNEL);
> + Â Â Â if (!info)
> + Â Â Â Â Â Â Â return -ENOMEM;
> +
> + Â Â Â res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + Â Â Â if (!res) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "Unable to allocate resources for device.\n");
> + Â Â Â Â Â Â Â ret = -EBUSY;
> + Â Â Â Â Â Â Â goto err_free_info;
> + Â Â Â }
> +
> + Â Â Â info->tegra_rtc_irq = platform_get_irq(pdev, 0);
> + Â Â Â if (info->tegra_rtc_irq <= 0) {
> + Â Â Â Â Â Â Â ret = -EBUSY;
> + Â Â Â Â Â Â Â goto err_free_info;
> + Â Â Â }
> +
> + Â Â Â info->rtc_base = ioremap(res->start, res->end - res->start + 1);
> + Â Â Â if (!info->rtc_base) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "Unable to grab IOs for device.\n");
> + Â Â Â Â Â Â Â ret = -EBUSY;
> + Â Â Â Â Â Â Â goto err_free_info;
> + Â Â Â }
> +
> + Â Â Â /* set context info. */
> + Â Â Â info->pdev = pdev;
> + Â Â Â info->tegra_rtc_lock = __SPIN_LOCK_UNLOCKED(info->tegra_rtc_lock);
> +
> + Â Â Â platform_set_drvdata(pdev, info);
> +
> + Â Â Â /* clear out the hardware. */
> + Â Â Â tegra_rtc_write_not_busy(&pdev->dev, RTC_TEGRA_REG_SECONDS_ALARM0, 0);
> + Â Â Â tegra_rtc_write_not_busy(&pdev->dev, RTC_TEGRA_REG_INTR_STATUS,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0xffffffff);
> + Â Â Â tegra_rtc_write_not_busy(&pdev->dev, RTC_TEGRA_REG_INTR_MASK, 0);
> +
> + Â Â Â device_init_wakeup(&pdev->dev, 1);
> +
> + Â Â Â info->rtc_dev = rtc_device_register(
> + Â Â Â Â Â Â Â pdev->name, &pdev->dev, &tegra_rtc_ops, THIS_MODULE);
> + Â Â Â if (IS_ERR(info->rtc_dev)) {
> + Â Â Â Â Â Â Â ret = PTR_ERR(info->rtc_dev);
> + Â Â Â Â Â Â Â info->rtc_dev = NULL;
> + Â Â Â Â Â Â Â dev_err(&pdev->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "Unable to register device (err=%d).\n",
> + Â Â Â Â Â Â Â Â Â Â Â ret);
> + Â Â Â Â Â Â Â goto err_iounmap;
> + Â Â Â }
> +
> + Â Â Â ret = request_irq(info->tegra_rtc_irq, tegra_rtc_irq_handler,
> + Â Â Â Â Â Â Â IRQF_TRIGGER_HIGH, "rtc alarm", &pdev->dev);
> + Â Â Â if (ret) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "Unable to request interrupt for device (err=%d).\n",
> + Â Â Â Â Â Â Â Â Â Â Â ret);
> + Â Â Â Â Â Â Â goto err_dev_unreg;
> + Â Â Â }
> +
> + Â Â Â dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n");
> +
> + Â Â Â return 0;
> +
> +err_dev_unreg:
> + Â Â Â rtc_device_unregister(info->rtc_dev);
> +err_iounmap:
> + Â Â Â iounmap(info->rtc_base);
> +err_free_info:
> + Â Â Â kfree(info);
> +
> + Â Â Â return ret;
> +}
> +
> +static int __devexit tegra_rtc_remove(struct platform_device *pdev)
> +{
> + Â Â Â struct tegra_rtc_info *info = platform_get_drvdata(pdev);
> +
> + Â Â Â free_irq(info->tegra_rtc_irq, &pdev->dev);
> + Â Â Â rtc_device_unregister(info->rtc_dev);
> + Â Â Â iounmap(info->rtc_base);
> + Â Â Â kfree(info);
> +
> + Â Â Â platform_set_drvdata(pdev, NULL);
> +
> + Â Â Â return 0;
> +}
> +
> +#ifdef CONFIG_PM
> +static int tegra_rtc_suspend(struct platform_device *pdev, pm_message_t state)
> +{
> + Â Â Â struct device *dev = &pdev->dev;
> + Â Â Â struct tegra_rtc_info *info = platform_get_drvdata(pdev);
> +
> + Â Â Â /* only use ALARM0 as a wake source. */
> + Â Â Â writel(0xffffffff, info->rtc_base + RTC_TEGRA_REG_INTR_STATUS);
> + Â Â Â writel(RTC_TEGRA_INTR_STATUS_SEC_ALARM0,
> + Â Â Â Â Â Â Â info->rtc_base + RTC_TEGRA_REG_INTR_MASK);
> +
> + Â Â Â dev_vdbg(dev, "alarm sec = %d\n",
> + Â Â Â Â Â Â Â readl(info->rtc_base + RTC_TEGRA_REG_SECONDS_ALARM0));
> +
> + Â Â Â dev_vdbg(dev, "Suspend (device_may_wakeup=%d) irq:%d\n",
> + Â Â Â Â Â Â Â device_may_wakeup(dev), info->tegra_rtc_irq);
> +
> + Â Â Â /* leave the alarms on as a wake source. */
> + Â Â Â if (device_may_wakeup(dev))
> + Â Â Â Â Â Â Â enable_irq_wake(info->tegra_rtc_irq);
> +
> + Â Â Â return 0;
> +}
> +
> +static int tegra_rtc_resume(struct platform_device *pdev)
> +{
> + Â Â Â struct device *dev = &pdev->dev;
> + Â Â Â struct tegra_rtc_info *info = platform_get_drvdata(pdev);
> + Â Â Â unsigned int intr_status;
> +
> + Â Â Â /* clear */
> + Â Â Â intr_status = readl(info->rtc_base + RTC_TEGRA_REG_INTR_STATUS);
> + Â Â Â if (intr_status & RTC_TEGRA_INTR_STATUS_SEC_ALARM0) {
> + Â Â Â Â Â Â Â tegra_rtc_write_not_busy(dev, RTC_TEGRA_REG_INTR_MASK, 0);
> + Â Â Â Â Â Â Â tegra_rtc_write_not_busy(dev, RTC_TEGRA_REG_INTR_STATUS,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0xffffffff);
> + Â Â Â }
> +
> + Â Â Â dev_vdbg(dev, "Resume (device_may_wakeup=%d)\n",
> + Â Â Â Â Â Â Â device_may_wakeup(dev));
> + Â Â Â /* alarms were left on as a wake source, turn them off. */
> + Â Â Â if (device_may_wakeup(dev))
> + Â Â Â Â Â Â Â disable_irq_wake(info->tegra_rtc_irq);
> +
> + Â Â Â return 0;
> +}
> +#endif
> +
> +static void tegra_rtc_shutdown(struct platform_device *pdev)
> +{
> + Â Â Â dev_vdbg(&pdev->dev, "disabling interrupts.\n");
> + Â Â Â tegra_rtc_alarm_irq_enable(&pdev->dev, 0);
> +}
> +
> +MODULE_ALIAS("platform:tegra_rtc");
> +static struct platform_driver tegra_rtc_driver = {
> +    .remove     = __devexit_p(tegra_rtc_remove),
> +    .shutdown    = tegra_rtc_shutdown,
> +    .driver     = {
> +        .name  = "tegra_rtc",
> + Â Â Â Â Â Â Â .owner Â= THIS_MODULE,
> + Â Â Â },
> +#ifdef CONFIG_PM
> +    .suspend    Â= tegra_rtc_suspend,
> +    .resume     = tegra_rtc_resume,
> +#endif
> +};
> +
> +static int __init tegra_rtc_init(void)
> +{
> + Â Â Â return platform_driver_probe(&tegra_rtc_driver, tegra_rtc_probe);
> +}
> +module_init(tegra_rtc_init);
> +
> +static void __exit tegra_rtc_exit(void)
> +{
> + Â Â Â platform_driver_unregister(&tegra_rtc_driver);
> +}
> +module_exit(tegra_rtc_exit);
> +
> +MODULE_DESCRIPTION("driver for Tegra internal RTC");
> +MODULE_LICENSE("GPL");
> --
> 1.7.0.4
>
> --
> 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.



--
*linux-arm-kernel mailing list
mail addr:linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
you can subscribe by:
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

* linux-arm-NUC900 mailing list
mail addr:NUC900@xxxxxxxxxxxxxxxx
main web: https://groups.google.com/group/NUC900
you can subscribe it by sending me mail:
mcuos.com@xxxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/