Re: [rtc-linux] [PATCH 3/3] drivers: rtc: Add support for QualcommPMIC8xxx RTC

From: Wan ZongShun
Date: Thu Mar 31 2011 - 12:48:14 EST


Hi Anirudh,

Some advice below:

2011/3/27 Anirudh Ghayal <aghayal@xxxxxxxxxxxxxx>:
> PMIC8xxx is Qualcomm's power management IC. A
> 32-bit RTC is housed inside this PMIC. The RTC driver
> uses SSBI to communicate with the RTC module.
>
> Cc: Alessandro Zummo <a.zummo@xxxxxxxxxxxx>
> Cc: Lars-Peter Clausen <lars@xxxxxxxxxx>
> Signed-off-by: Anirudh Ghayal <aghayal@xxxxxxxxxxxxxx>
> ---
> Âdrivers/rtc/Kconfig      Â|  Â9 +
> Âdrivers/rtc/Makefile      |  Â1 +
> Âdrivers/rtc/rtc-pm8xxx.c    | Â567 ++++++++++++++++++++++++++++++++++++++++
> Âinclude/linux/mfd/pm8xxx/rtc.h | Â 25 ++
> Â4 files changed, 602 insertions(+), 0 deletions(-)
> Âcreate mode 100644 drivers/rtc/rtc-pm8xxx.c
> Âcreate mode 100644 include/linux/mfd/pm8xxx/rtc.h
>
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index e187887..a66672a 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -995,4 +995,13 @@ config RTC_DRV_TEGRA
> Â Â Â Â ÂThis drive can also be built as a module. If so, the module
> Â Â Â Â Âwill be called rtc-tegra.
>
> +config RTC_DRV_PM8XXX
> + Â Â Â tristate "Qualcomm PMIC8XXX RTC"
> + Â Â Â depends on MFD_PM8XXX
> + Â Â Â help
> + Â Â Â Â Say Y here if you want to support the Qualcomm PMIC8XXX RTC.
> +
> + Â Â Â Â To compile this driver as a module, choose M here: the
> + Â Â Â Â module will be called rtc-pm8xxx.
> +
> Âendif # RTC_CLASS
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index ca91c3c..ff40366 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -72,6 +72,7 @@ obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
> Âobj-$(CONFIG_RTC_DRV_PCF8583) Â+= rtc-pcf8583.o
> Âobj-$(CONFIG_RTC_DRV_PCF2123) Â+= rtc-pcf2123.o
> Âobj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o
> +obj-$(CONFIG_RTC_DRV_PM8XXX) Â Â+= rtc-pm8xxx.o
> Âobj-$(CONFIG_RTC_DRV_PL030) Â Â+= rtc-pl030.o
> Âobj-$(CONFIG_RTC_DRV_PL031) Â Â+= rtc-pl031.o
> Âobj-$(CONFIG_RTC_DRV_PS3) Â Â Â+= rtc-ps3.o
> diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c
> new file mode 100644
> index 0000000..ce2dad3
> --- /dev/null
> +++ b/drivers/rtc/rtc-pm8xxx.c
> @@ -0,0 +1,567 @@
> +/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * 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.
> + */
> +
> +#define pr_fmt(fmt) "%s: " fmt, __func__
> +

why add pr_fmt here?

> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/rtc.h>
> +#include <linux/pm.h>
> +#include <linux/slab.h>
> +#include<linux/spinlock.h>
> +
> +#include <linux/mfd/pm8xxx/core.h>
> +#include <linux/mfd/pm8xxx/rtc.h>
> +
> +/* RTC Register offsets from RTC CTRL REG */
> +#define PM8XXX_ALARM_CTRL_OFFSET 0x01
> +#define PM8XXX_RTC_WRITE_OFFSET 0x02
> +#define PM8XXX_RTC_READ_OFFSET 0x06
> +#define PM8XXX_ALARM_RW_OFFSET 0x0A
> +
> +/* RTC_CTRL register bit fields */
> +#define PM8xxx_RTC_ENABLE Â Â ÂBIT(7)
> +#define PM8xxx_RTC_ALARM_ENABLE Â Â Â ÂBIT(1)
> +#define PM8xxx_RTC_ALARM_CLEAR ÂBIT(0)
> +
> +#define NUM_8_BIT_RTC_REGS Â Â 0x4
> +
> +/**
> + * struct pm8xxx_rtc - rtc driver internal structure
> + * @rtc: rtc device for this driver
> + * @rtc_alarm_irq: rtc alarm irq number
> + */
> +struct pm8xxx_rtc {
> + Â Â Â struct rtc_device *rtc;
> + Â Â Â int rtc_alarm_irq;
> + Â Â Â int rtc_base;
> + Â Â Â int rtc_read_base;
> + Â Â Â int rtc_write_base;
> + Â Â Â int alarm_rw_base;
> + Â Â Â u8 Âctrl_reg;
> + Â Â Â struct device *parent;
> + Â Â Â spinlock_t ctrl_reg_lock;
> +};
> +
> +/*
> + * The RTC registers need to be read/written one byte at a time. This is a
> + * hardware limitation.
> + */
> +static int pm8xxx_read_wrapper(struct pm8xxx_rtc *rtc_dd, u8 *rtc_val,
> + Â Â Â Â Â Â Â Â Â Â Â int base, int count)
> +{
> + Â Â Â int i, rc;
> +
> + Â Â Â for (i = 0; i < count; i++) {
> + Â Â Â Â Â Â Â rc = pm8xxx_readb(rtc_dd->parent, base + i, &rtc_val[i]);
> + Â Â Â Â Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â pr_err("PM8xxx read failed\n");

All pr_err are not so good, please try to use dev_err.

> + Â Â Â Â Â Â Â Â Â Â Â return rc;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static int pm8xxx_write_wrapper(struct pm8xxx_rtc *rtc_dd, u8 *rtc_val,
> + Â Â Â Â Â Â Â Â Â Â Â int base, int count)
> +{
> + Â Â Â int i, rc;
> +
> + Â Â Â for (i = 0; i < count; i++) {
> + Â Â Â Â Â Â Â rc = pm8xxx_writeb(rtc_dd->parent, base + i, rtc_val[i]);
> + Â Â Â Â Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â pr_err("PM8xxx write failed\n");
> + Â Â Â Â Â Â Â Â Â Â Â return rc;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +
> +/*
> + * Steps to write the RTC registers.
> + * 1. Disable alarm if enabled.
> + * 2. Write 0x00 to LSB.
> + * 3. Write Byte[1], Byte[2], Byte[3] then Byte[0].
> + * 4. Enable alarm if disabled in step 1.
> + */
> +static int
> +pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> + Â Â Â int rc;
> + Â Â Â unsigned long secs, irq_flags;
> + Â Â Â u8 value[4], reg = 0, alarm_enabled = 0, ctrl_reg;
> + Â Â Â struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
> +
> + Â Â Â rtc_tm_to_time(tm, &secs);
> +
> + Â Â Â value[0] = secs & 0xFF;
> + Â Â Â value[1] = (secs >> 8) & 0xFF;
> + Â Â Â value[2] = (secs >> 16) & 0xFF;
> + Â Â Â value[3] = (secs >> 24) & 0xFF;
> +
> + Â Â Â dev_dbg(dev, "Seconds value to be written to RTC = %lu\n", secs);
> +
> + Â Â Â spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
> + Â Â Â ctrl_reg = rtc_dd->ctrl_reg;
> +
> + Â Â Â if (ctrl_reg & PM8xxx_RTC_ALARM_ENABLE) {
> + Â Â Â Â Â Â Â alarm_enabled = 1;
> + Â Â Â Â Â Â Â ctrl_reg &= ~PM8xxx_RTC_ALARM_ENABLE;
> + Â Â Â Â Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1);
> + Â Â Â Â Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "PM8xxx write failed\n");
> + Â Â Â Â Â Â Â Â Â Â Â goto rtc_rw_fail;
> + Â Â Â Â Â Â Â }
> + Â Â Â } else
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
> +
> + Â Â Â /* Write Byte[1], Byte[2], Byte[3], Byte[0] */
> + Â Â Â /* Write 0 to Byte[0] */
> + Â Â Â reg = 0;
> + Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, &reg, rtc_dd->rtc_write_base, 1);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "PM8xxx write failed\n");
> + Â Â Â Â Â Â Â goto rtc_rw_fail;
> + Â Â Â }
> +
> + Â Â Â /* Write Byte[1], Byte[2], Byte[3] */
> + Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, value + 1,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rtc_dd->rtc_write_base + 1, 3);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "Write to RTC registers failed\n");
> + Â Â Â Â Â Â Â goto rtc_rw_fail;
> + Â Â Â }
> +
> + Â Â Â /* Write Byte[0] */
> + Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, value, rtc_dd->rtc_write_base, 1);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "Write to RTC register failed\n");
> + Â Â Â Â Â Â Â goto rtc_rw_fail;
> + Â Â Â }
> +
> + Â Â Â if (alarm_enabled) {
> + Â Â Â Â Â Â Â ctrl_reg |= PM8xxx_RTC_ALARM_ENABLE;
> + Â Â Â Â Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1);
> + Â Â Â Â Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "PM8xxx write failed\n");
> + Â Â Â Â Â Â Â Â Â Â Â goto rtc_rw_fail;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â rtc_dd->ctrl_reg = ctrl_reg;
> +
> +rtc_rw_fail:
> + Â Â Â if (alarm_enabled)
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
> +
> + Â Â Â return rc;
> +}
> +
> +static int
> +pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> + Â Â Â int rc;
> + Â Â Â u8 value[4], reg;
> + Â Â Â unsigned long secs;
> + Â Â Â struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
> +
> + Â Â Â rc = pm8xxx_read_wrapper(rtc_dd, value, rtc_dd->rtc_read_base,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â NUM_8_BIT_RTC_REGS);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "RTC time read failed\n");
> + Â Â Â Â Â Â Â return rc;
> + Â Â Â }
> +
> + Â Â Â /*
> + Â Â Â Â* Read the LSB again and check if there has been a carry over.
> + Â Â Â Â* If there is, redo the read operation.
> + Â Â Â Â*/
> + Â Â Â rc = pm8xxx_read_wrapper(rtc_dd, &reg, rtc_dd->rtc_read_base, 1);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "PM8xxx read failed\n");
> + Â Â Â Â Â Â Â return rc;
> + Â Â Â }
> +
> + Â Â Â if (unlikely(reg < value[0])) {
> + Â Â Â Â Â Â Â rc = pm8xxx_read_wrapper(rtc_dd, value,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rtc_dd->rtc_read_base, NUM_8_BIT_RTC_REGS);
> + Â Â Â Â Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "RTC time read failed\n");
> + Â Â Â Â Â Â Â Â Â Â Â return rc;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â secs = value[0] | (value[1] << 8) | (value[2] << 16) \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | (value[3] << 24);
> +
> + Â Â Â rtc_time_to_tm(secs, tm);
> +
> + Â Â Â rc = rtc_valid_tm(tm);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "Invalid time read from PM8xxx\n");
> + Â Â Â Â Â Â Â return rc;
> + Â Â Â }
> +
> + Â Â Â dev_dbg(dev, "secs = %lu, h:m:s == %d:%d:%d, d/m/y = %d/%d/%d\n",
> + Â Â Â Â Â Â Â Â Â Â Â secs, tm->tm_hour, tm->tm_min, tm->tm_sec,
> + Â Â Â Â Â Â Â Â Â Â Â tm->tm_mday, tm->tm_mon, tm->tm_year);
> +
> + Â Â Â return 0;
> +}
> +
> +static int
> +pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
> +{
> + Â Â Â int rc;
> + Â Â Â u8 value[4], ctrl_reg;
> + Â Â Â unsigned long secs, secs_rtc, irq_flags;
> + Â Â Â struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
> + Â Â Â struct rtc_time rtc_tm;
> +
> + Â Â Â rtc_tm_to_time(&alarm->time, &secs);
> +
> + Â Â Â /*
> + Â Â Â Â* Read the current RTC time and verify if the alarm time is in the
> + Â Â Â Â* past. If yes, return invalid.
> + Â Â Â Â*/
> + Â Â Â rc = pm8xxx_rtc_read_time(dev, &rtc_tm);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "Unamble to read RTC time\n");
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â }
> +
> + Â Â Â rtc_tm_to_time(&rtc_tm, &secs_rtc);
> + Â Â Â if (secs < secs_rtc) {
> + Â Â Â Â Â Â Â dev_err(dev, "Trying to set alarm in the past\n");
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â }
> +
> + Â Â Â value[0] = secs & 0xFF;
> + Â Â Â value[1] = (secs >> 8) & 0xFF;
> + Â Â Â value[2] = (secs >> 16) & 0xFF;
> + Â Â Â value[3] = (secs >> 24) & 0xFF;
> +
> + Â Â Â spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
> +
> + Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, value, rtc_dd->alarm_rw_base,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â NUM_8_BIT_RTC_REGS);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "Write to RTC ALARM registers failed\n");
> + Â Â Â Â Â Â Â goto rtc_rw_fail;
> + Â Â Â }
> +
> + Â Â Â ctrl_reg = rtc_dd->ctrl_reg;
> + Â Â Â ctrl_reg = (alarm->enabled) ? (ctrl_reg | PM8xxx_RTC_ALARM_ENABLE) :
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (ctrl_reg & ~PM8xxx_RTC_ALARM_ENABLE);
> +
> + Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "PM8xxx write failed\n");
> + Â Â Â Â Â Â Â goto rtc_rw_fail;
> + Â Â Â }
> +
> + Â Â Â rtc_dd->ctrl_reg = ctrl_reg;
> +
> + Â Â Â dev_dbg(dev, "Alarm Set for h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n",
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_hour, alarm->time.tm_min,
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_sec, alarm->time.tm_mday,
> + Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_mon, alarm->time.tm_year);
> +rtc_rw_fail:
> + Â Â Â spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
> + Â Â Â return rc;
> +}
> +
> +static int
> +pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
> +{
> + Â Â Â int rc;
> + Â Â Â u8 value[4];
> + Â Â Â unsigned long secs;
> + Â Â Â struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
> +
> + Â Â Â rc = pm8xxx_read_wrapper(rtc_dd, value, rtc_dd->alarm_rw_base,
> + Â Â Â Â Â Â Â Â Â Â Â NUM_8_BIT_RTC_REGS);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "RTC alarm time read failed\n");
> + Â Â Â Â Â Â Â return rc;
> + Â Â Â }
> +
> + Â Â Â secs = value[0] | (value[1] << 8) | (value[2] << 16) | \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(value[3] << 24);
> +
> + Â Â Â rtc_time_to_tm(secs, &alarm->time);
> +
> + Â Â Â rc = rtc_valid_tm(&alarm->time);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "Invalid time read from PM8xxx\n");
> + Â Â Â Â Â Â Â return rc;
> + Â Â Â }
> +
> + Â Â Â dev_dbg(dev, "Alarm set for - h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n",
> + Â Â Â Â Â Â Â alarm->time.tm_hour, alarm->time.tm_min,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_sec, alarm->time.tm_mday,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â alarm->time.tm_mon, alarm->time.tm_year);
> +
> + Â Â Â return 0;
> +}
> +
> +
> +static int
> +pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
> +{
> + Â Â Â int rc;
> + Â Â Â unsigned long irq_flags;
> + Â Â Â struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
> + Â Â Â u8 ctrl_reg;
> +
> + Â Â Â spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
> + Â Â Â ctrl_reg = rtc_dd->ctrl_reg;
> + Â Â Â ctrl_reg = (enabled) ? (ctrl_reg | PM8xxx_RTC_ALARM_ENABLE) :
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (ctrl_reg & ~PM8xxx_RTC_ALARM_ENABLE);
> +
> + Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(dev, "PM8xxx write failed\n");
> + Â Â Â Â Â Â Â goto rtc_rw_fail;
> + Â Â Â }
> +
> + Â Â Â rtc_dd->ctrl_reg = ctrl_reg;
> +
> +rtc_rw_fail:
> + Â Â Â spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
> + Â Â Â return rc;
> +}
> +
> +static struct rtc_class_ops pm8xxx_rtc_ops = {
> +    .read_time   Â= pm8xxx_rtc_read_time,
> +    .set_alarm   Â= pm8xxx_rtc_set_alarm,
> +    .read_alarm   = pm8xxx_rtc_read_alarm,
> + Â Â Â .alarm_irq_enable = pm8xxx_rtc_alarm_irq_enable,
> +};
> +
> +static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id)
> +{
> + Â Â Â struct pm8xxx_rtc *rtc_dd = dev_id;
> + Â Â Â u8 ctrl_reg;
> + Â Â Â int rc;
> + Â Â Â unsigned long irq_flags;
> +
> + Â Â Â rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF);
> +
> + Â Â Â spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
> +
> + Â Â Â /* Clear the alarm enable bit */
> + Â Â Â ctrl_reg = rtc_dd->ctrl_reg;
> + Â Â Â ctrl_reg &= ~PM8xxx_RTC_ALARM_ENABLE;
> +
> + Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
> + Â Â Â Â Â Â Â pr_err("PM8xxx write failed!\n");
> + Â Â Â Â Â Â Â goto rtc_alarm_handled;
> + Â Â Â }
> +
> + Â Â Â rtc_dd->ctrl_reg = ctrl_reg;
> + Â Â Â spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
> +
> + Â Â Â /* Clear RTC alarm register */
> + Â Â Â rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base +
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PM8XXX_ALARM_CTRL_OFFSET, 1);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â pr_err("PM8xxx write failed!\n");
> + Â Â Â Â Â Â Â goto rtc_alarm_handled;
> + Â Â Â }
> +
> + Â Â Â ctrl_reg &= ~PM8xxx_RTC_ALARM_CLEAR;
> + Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base +
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PM8XXX_ALARM_CTRL_OFFSET, 1);
> + Â Â Â if (rc < 0)
> + Â Â Â Â Â Â Â pr_err("PM8xxx write failed!\n");
> +
> +rtc_alarm_handled:
> + Â Â Â return IRQ_HANDLED;
> +}
> +
> +static int __devinit pm8xxx_rtc_probe(struct platform_device *pdev)
> +{
> + Â Â Â int rc;
> + Â Â Â u8 ctrl_reg;
> + Â Â Â bool rtc_write_enable = false;
> + Â Â Â struct pm8xxx_rtc *rtc_dd;
> + Â Â Â struct resource *rtc_resource;
> + Â Â Â const struct pm8xxx_rtc_platform_data *pdata =
> + Â Â Â Â Â Â Â pdev->dev.platform_data;
> +
> + Â Â Â if (pdata != NULL)
> + Â Â Â Â Â Â Â rtc_write_enable = pdata->rtc_write_enable;
> +
> + Â Â Â rtc_dd = kzalloc(sizeof(*rtc_dd), GFP_KERNEL);
> + Â Â Â if (rtc_dd == NULL) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "Unable to allocate memory!\n");
> + Â Â Â Â Â Â Â return -ENOMEM;
> + Â Â Â }
> +
> + Â Â Â /* Initialise spinlock to protect RTC cntrol register */
> + Â Â Â spin_lock_init(&rtc_dd->ctrl_reg_lock);
> +
> + Â Â Â rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0);
> + Â Â Â if (!rtc_dd->rtc_alarm_irq) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "Alarm IRQ resource absent!\n");
> + Â Â Â Â Â Â Â rc = -ENXIO;
> + Â Â Â Â Â Â Â goto fail_rtc_enable;
> + Â Â Â }
> +

In fact, the 'platform_get_irq' maybe return -ENXIO, so you should use
the 'if (rtc_dd->rtc_alarm_irq < 0)' instead of '!' to judge
the get irq action.

> + Â Â Â rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "pmic_rtc_base");
> + Â Â Â if (rtc_resource)
> + Â Â Â Â Â Â Â rtc_dd->rtc_base = rtc_resource->start;
> + Â Â Â if (!rtc_dd->rtc_base) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "RTC IO resource absent!\n");
> + Â Â Â Â Â Â Â rc = -ENXIO;
> + Â Â Â Â Â Â Â goto fail_rtc_enable;
> + Â Â Â }


rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO,
"pmic_rtc_base");
if !(rtc_resource && rtc_resource->start) {
dev_err(&pdev->dev, "RTC IO resource absent!\n");
rc = -ENXIO;
goto fail_rtc_enable;
}
rtc_dd->rtc_base = rtc_resource->start;

Do you think above code style is better?

> +
> + Â Â Â /* Setup RTC register addresses */
> + Â Â Â rtc_dd->rtc_write_base = rtc_dd->rtc_base + PM8XXX_RTC_WRITE_OFFSET;
> + Â Â Â rtc_dd->rtc_read_base = rtc_dd->rtc_base + PM8XXX_RTC_READ_OFFSET;
> + Â Â Â rtc_dd->alarm_rw_base = rtc_dd->rtc_base + PM8XXX_ALARM_RW_OFFSET;
> +
> + Â Â Â rtc_dd->parent = pdev->dev.parent;
> +
> + Â Â Â /* Check if the RTC is on, else turn it on */
> + Â Â Â rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "PM8xxx read failed!\n");
> + Â Â Â Â Â Â Â goto fail_rtc_enable;
> + Â Â Â }
> +
> + Â Â Â if (!(ctrl_reg & PM8xxx_RTC_ENABLE)) {
> + Â Â Â Â Â Â Â ctrl_reg |= PM8xxx_RTC_ENABLE;
> + Â Â Â Â Â Â Â rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1);
> + Â Â Â Â Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(&pdev->dev, "PM8xxx write failed!\n");
> + Â Â Â Â Â Â Â Â Â Â Â goto fail_rtc_enable;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â rtc_dd->ctrl_reg = ctrl_reg;
> + Â Â Â if (rtc_write_enable == true)
> + Â Â Â Â Â Â Â pm8xxx_rtc_ops.set_time = pm8xxx_rtc_set_time,
> +
> + Â Â Â platform_set_drvdata(pdev, rtc_dd);
> +
> + Â Â Â /* Register the RTC device */
> + Â Â Â rtc_dd->rtc = rtc_device_register("pm8xxx_rtc", &pdev->dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &pm8xxx_rtc_ops, THIS_MODULE);
> + Â Â Â if (IS_ERR(rtc_dd->rtc)) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "%s: RTC registration failed (%ld)\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__, PTR_ERR(rtc_dd->rtc));
> + Â Â Â Â Â Â Â rc = PTR_ERR(rtc_dd->rtc);
> + Â Â Â Â Â Â Â goto fail_rtc_enable;
> + Â Â Â }
> +
> + Â Â Â /* Request the alarm IRQ */
> + Â Â Â rc = request_any_context_irq(rtc_dd->rtc_alarm_irq,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âpm8xxx_alarm_trigger, IRQF_TRIGGER_RISING,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"pm8xxx_rtc_alarm", rtc_dd);
> + Â Â Â if (rc < 0) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "Request IRQ failed (%d)\n", rc);
> + Â Â Â Â Â Â Â goto fail_req_irq;
> + Â Â Â }
> +
> + Â Â Â device_init_wakeup(&pdev->dev, 1);
> +
> + Â Â Â dev_dbg(&pdev->dev, "Probe success !!\n");
> +
> + Â Â Â return 0;
> +
> +fail_req_irq:
> + Â Â Â rtc_device_unregister(rtc_dd->rtc);
> +fail_rtc_enable:
> + Â Â Â platform_set_drvdata(pdev, NULL);
> + Â Â Â kfree(rtc_dd);
> + Â Â Â return rc;
> +}
> +
> +#ifdef CONFIG_PM
> +static int pm8xxx_rtc_resume(struct device *dev)
> +{
> + Â Â Â struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
> +
> + Â Â Â if (device_may_wakeup(dev))
> + Â Â Â Â Â Â Â disable_irq_wake(rtc_dd->rtc_alarm_irq);
> +
> + Â Â Â return 0;
> +}
> +
> +static int pm8xxx_rtc_suspend(struct device *dev)
> +{
> + Â Â Â struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
> +
> + Â Â Â if (device_may_wakeup(dev))
> + Â Â Â Â Â Â Â enable_irq_wake(rtc_dd->rtc_alarm_irq);
> +
> + Â Â Â return 0;
> +}
> +
> +static const struct dev_pm_ops pm8xxx_rtc_pm_ops = {
> + Â Â Â .suspend = pm8xxx_rtc_suspend,
> + Â Â Â .resume = pm8xxx_rtc_resume,
> +};
> +#endif
> +static int __devexit pm8xxx_rtc_remove(struct platform_device *pdev)
> +{
> + Â Â Â struct pm8xxx_rtc *rtc_dd = platform_get_drvdata(pdev);
> +
> + Â Â Â device_init_wakeup(&pdev->dev, 0);
> + Â Â Â free_irq(rtc_dd->rtc_alarm_irq, rtc_dd);
> + Â Â Â rtc_device_unregister(rtc_dd->rtc);
> + Â Â Â platform_set_drvdata(pdev, NULL);
> + Â Â Â kfree(rtc_dd);
> +
> + Â Â Â return 0;
> +}
> +
> +static struct platform_driver pm8xxx_rtc_driver = {
> +    .probe     Â= pm8xxx_rtc_probe,
> +    .remove     = __devexit_p(pm8xxx_rtc_remove),
> + Â Â Â .driver = {
> +        .name  = PM8XXX_RTC_DEV_NAME,
> + Â Â Â Â Â Â Â .owner Â= THIS_MODULE,
> +#ifdef CONFIG_PM
> +        .pm   = &pm8xxx_rtc_pm_ops,
> +#endif
> + Â Â Â },
> +};
> +
> +static int __init pm8xxx_rtc_init(void)
> +{
> + Â Â Â return platform_driver_register(&pm8xxx_rtc_driver);
> +}
> +module_init(pm8xxx_rtc_init);
> +
> +static void __exit pm8xxx_rtc_exit(void)
> +{
> + Â Â Â platform_driver_unregister(&pm8xxx_rtc_driver);
> +}
> +module_exit(pm8xxx_rtc_exit);
> +
> +MODULE_ALIAS("platform:rtc-pm8xxx");
> +MODULE_DESCRIPTION("PMIC8xxx RTC driver");
> +MODULE_LICENSE("GPL v2");
> +MODULE_AUTHOR("Anirudh Ghayal <aghayal@xxxxxxxxxxxxxx>");
> diff --git a/include/linux/mfd/pm8xxx/rtc.h b/include/linux/mfd/pm8xxx/rtc.h
> new file mode 100644
> index 0000000..2528e1d
> --- /dev/null
> +++ b/include/linux/mfd/pm8xxx/rtc.h
> @@ -0,0 +1,25 @@
> +/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * 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.
> + */
> +
> +#ifndef __RTC_PM8XXX_H__
> +#define __RTC_PM8XXX_H__
> +
> +#define PM8XXX_RTC_DEV_NAME Â Â "rtc-pm8xxx"
> +/**
> + * struct pm8058_rtc_pdata - RTC driver platform data
> + * @rtc_write_enable: variable stating RTC write capability
> + */
> +struct pm8xxx_rtc_platform_data {
> + Â Â Â bool rtc_write_enable;
> +};
> +
> +#endif /* __RTC_PM8XXX_H__ */
> --
> 1.7.3.5
>
> --
> 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/