diff options
author | merge <null@invalid> | 2009-01-22 13:55:32 +0000 |
---|---|---|
committer | Andy Green <agreen@octopus.localdomain> | 2009-01-22 13:55:32 +0000 |
commit | aa6f5ffbdba45aa8e19e5048648fc6c7b25376d3 (patch) | |
tree | fbb786d0ac6f8a774fd834e9ce951197e60fbffa /drivers/rtc/rtc-pcf50633.c | |
parent | f2d78193eae5dccd3d588d2c8ea0866efc368332 (diff) |
MERGE-via-pending-tracking-hist-MERGE-via-stable-tracking-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040-1232632141
pending-tracking-hist top was MERGE-via-stable-tracking-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040-1232632141 / fdf777a63bcb59e0dfd78bfe2c6242e01f6d4eb9 ... parent commitmessage:
From: merge <null@invalid>
MERGE-via-stable-tracking-hist-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040
stable-tracking-hist top was MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040 / 90463bfd2d5a3c8b52f6e6d71024a00e052b0ced ... parent commitmessage:
From: merge <null@invalid>
MERGE-via-mokopatches-tracking-hist-fix-stray-endmenu-patch
mokopatches-tracking-hist top was fix-stray-endmenu-patch / 3630e0be570de8057e7f8d2fe501ed353cdf34e6 ... parent commitmessage:
From: Andy Green <andy@openmoko.com>
fix-stray-endmenu.patch
Signed-off-by: Andy Green <andy@openmoko.com>
Diffstat (limited to 'drivers/rtc/rtc-pcf50633.c')
-rw-r--r-- | drivers/rtc/rtc-pcf50633.c | 266 |
1 files changed, 155 insertions, 111 deletions
diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c index e1576d24254..f4dd87e2907 100644 --- a/drivers/rtc/rtc-pcf50633.c +++ b/drivers/rtc/rtc-pcf50633.c @@ -1,4 +1,4 @@ -/* Philips PCF50633 RTC Driver +/* NXP PCF50633 RTC Driver * * (C) 2006-2008 by Openmoko, Inc. * Author: Balaji Rao <balajirrao@openmoko.org> @@ -7,31 +7,41 @@ * Broken down from monstrous PCF50633 driver mainly by * Harald Welte, Andy Green and Werner Almesberger * - * 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 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., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA */ -#include <linux/rtc.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/device.h> #include <linux/platform_device.h> +#include <linux/rtc.h> #include <linux/bcd.h> +#include <linux/err.h> #include <linux/mfd/pcf50633/core.h> -#include <linux/mfd/pcf50633/rtc.h> + +#define PCF50633_REG_RTCSC 0x59 /* Second */ +#define PCF50633_REG_RTCMN 0x5a /* Minute */ +#define PCF50633_REG_RTCHR 0x5b /* Hour */ +#define PCF50633_REG_RTCWD 0x5c /* Weekday */ +#define PCF50633_REG_RTCDT 0x5d /* Day */ +#define PCF50633_REG_RTCMT 0x5e /* Month */ +#define PCF50633_REG_RTCYR 0x5f /* Year */ +#define PCF50633_REG_RTCSCA 0x60 /* Alarm Second */ +#define PCF50633_REG_RTCMNA 0x61 /* Alarm Minute */ +#define PCF50633_REG_RTCHRA 0x62 /* Alarm Hour */ +#define PCF50633_REG_RTCWDA 0x63 /* Alarm Weekday */ +#define PCF50633_REG_RTCDTA 0x64 /* Alarm Day */ +#define PCF50633_REG_RTCMTA 0x65 /* Alarm Month */ +#define PCF50633_REG_RTCYRA 0x66 /* Alarm Year */ enum pcf50633_time_indexes { - PCF50633_TI_SEC = 0, + PCF50633_TI_SEC, PCF50633_TI_MIN, PCF50633_TI_HOUR, PCF50633_TI_WKDAY, @@ -41,11 +51,18 @@ enum pcf50633_time_indexes { PCF50633_TI_EXTENT /* always last */ }; - struct pcf50633_time { u_int8_t time[PCF50633_TI_EXTENT]; }; +struct pcf50633_rtc { + int alarm_enabled; + int second_enabled; + + struct pcf50633 *pcf; + struct rtc_device *rtc_dev; +}; + static void pcf2rtc_time(struct rtc_time *rtc, struct pcf50633_time *pcf) { rtc->tm_sec = bcd2bin(pcf->time[PCF50633_TI_SEC]); @@ -65,54 +82,62 @@ static void rtc2pcf_time(struct pcf50633_time *pcf, struct rtc_time *rtc) pcf->time[PCF50633_TI_WKDAY] = bin2bcd(rtc->tm_wday); pcf->time[PCF50633_TI_DAY] = bin2bcd(rtc->tm_mday); pcf->time[PCF50633_TI_MONTH] = bin2bcd(rtc->tm_mon); - pcf->time[PCF50633_TI_YEAR] = bin2bcd(rtc->tm_year - 100); + pcf->time[PCF50633_TI_YEAR] = bin2bcd(rtc->tm_year % 100); } -static int pcf50633_rtc_ioctl(struct device *dev, unsigned int cmd, - unsigned long arg) +static int +pcf50633_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) { - struct pcf50633 *pcf; + struct pcf50633_rtc *rtc = dev_get_drvdata(dev); + int err; - pcf = dev_get_drvdata(dev); - - switch (cmd) { - case RTC_AIE_OFF: - /* disable the alarm interrupt */ - pcf->rtc.alarm_enabled = 0; - pcf50633_irq_mask(pcf, PCF50633_IRQ_ALARM); - return 0; - case RTC_AIE_ON: - /* enable the alarm interrupt */ - pcf->rtc.alarm_enabled = 1; - pcf50633_irq_unmask(pcf, PCF50633_IRQ_ALARM); - return 0; - case RTC_PIE_OFF: - /* disable periodic interrupt (hz tick) */ - pcf->rtc.second_enabled = 0; - pcf50633_irq_mask(pcf, PCF50633_IRQ_SECOND); - return 0; - case RTC_PIE_ON: - /* ensable periodic interrupt (hz tick) */ - pcf->rtc.second_enabled = 1; - pcf50633_irq_unmask(pcf, PCF50633_IRQ_SECOND); - return 0; - } - return -ENOIOCTLCMD; + if (enabled) + err = pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_ALARM); + else + err = pcf50633_irq_mask(rtc->pcf, PCF50633_IRQ_ALARM); + + if (err < 0) + return err; + + rtc->alarm_enabled = enabled; + + return 0; +} + +static int +pcf50633_rtc_update_irq_enable(struct device *dev, unsigned int enabled) +{ + struct pcf50633_rtc *rtc = dev_get_drvdata(dev); + int err; + + if (enabled) + err = pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_SECOND); + else + err = pcf50633_irq_mask(rtc->pcf, PCF50633_IRQ_SECOND); + + if (err < 0) + return err; + + rtc->second_enabled = enabled; + + return 0; } static int pcf50633_rtc_read_time(struct device *dev, struct rtc_time *tm) { - struct pcf50633 *pcf; + struct pcf50633_rtc *rtc; struct pcf50633_time pcf_tm; int ret; - pcf = dev_get_drvdata(dev); + rtc = dev_get_drvdata(dev); - ret = pcf50633_read_block(pcf, PCF50633_REG_RTCSC, + ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSC, PCF50633_TI_EXTENT, &pcf_tm.time[0]); - if (ret != PCF50633_TI_EXTENT) + if (ret != PCF50633_TI_EXTENT) { dev_err(dev, "Failed to read time\n"); + return -EIO; + } dev_dbg(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n", pcf_tm.time[PCF50633_TI_DAY], @@ -128,22 +153,23 @@ static int pcf50633_rtc_read_time(struct device *dev, struct rtc_time *tm) tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); - return 0; + return rtc_valid_tm(tm); } static int pcf50633_rtc_set_time(struct device *dev, struct rtc_time *tm) { - struct pcf50633 *pcf; + struct pcf50633_rtc *rtc; struct pcf50633_time pcf_tm; - int ret; - int second_masked, alarm_masked; + int second_masked, alarm_masked, ret = 0; - pcf = dev_get_drvdata(dev); + rtc = dev_get_drvdata(dev); dev_dbg(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n", tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); + rtc2pcf_time(&pcf_tm, tm); + dev_dbg(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n", pcf_tm.time[PCF50633_TI_DAY], pcf_tm.time[PCF50633_TI_MONTH], @@ -153,126 +179,145 @@ static int pcf50633_rtc_set_time(struct device *dev, struct rtc_time *tm) pcf_tm.time[PCF50633_TI_SEC]); - second_masked = pcf50633_irq_mask_get(pcf, PCF50633_IRQ_SECOND); - alarm_masked = pcf50633_irq_mask_get(pcf, PCF50633_IRQ_ALARM); + second_masked = pcf50633_irq_mask_get(rtc->pcf, PCF50633_IRQ_SECOND); + alarm_masked = pcf50633_irq_mask_get(rtc->pcf, PCF50633_IRQ_ALARM); if (!second_masked) - pcf50633_irq_mask(pcf, PCF50633_IRQ_SECOND); + pcf50633_irq_mask(rtc->pcf, PCF50633_IRQ_SECOND); if (!alarm_masked) - pcf50633_irq_mask(pcf, PCF50633_IRQ_ALARM); + pcf50633_irq_mask(rtc->pcf, PCF50633_IRQ_ALARM); - ret = pcf50633_write_block(pcf, PCF50633_REG_RTCSC, + /* Returns 0 on success */ + ret = pcf50633_write_block(rtc->pcf, PCF50633_REG_RTCSC, PCF50633_TI_EXTENT, &pcf_tm.time[0]); - if (ret) - dev_err(dev, "Failed to set time %d\n", ret); if (!second_masked) - pcf50633_irq_unmask(pcf, PCF50633_IRQ_SECOND); + pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_SECOND); if (!alarm_masked) - pcf50633_irq_unmask(pcf, PCF50633_IRQ_ALARM); + pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_ALARM); - - return 0; + return ret; } static int pcf50633_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { - struct pcf50633 *pcf; + struct pcf50633_rtc *rtc; struct pcf50633_time pcf_tm; - int ret; + int ret = 0; - pcf = dev_get_drvdata(dev); + rtc = dev_get_drvdata(dev); - alrm->enabled = pcf->rtc.alarm_enabled; + alrm->enabled = rtc->alarm_enabled; - ret = pcf50633_read_block(pcf, PCF50633_REG_RTCSCA, + ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSCA, PCF50633_TI_EXTENT, &pcf_tm.time[0]); - - if (ret != PCF50633_TI_EXTENT) - dev_err(dev, "Failed to read Alarm time :-(\n"); + if (ret != PCF50633_TI_EXTENT) { + dev_err(dev, "Failed to read time\n"); + return -EIO; + } pcf2rtc_time(&alrm->time, &pcf_tm); - return 0; + return rtc_valid_tm(&alrm->time); } static int pcf50633_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) { - struct pcf50633 *pcf; + struct pcf50633_rtc *rtc; struct pcf50633_time pcf_tm; - int ret, alarm_masked; + int alarm_masked, ret = 0; - pcf = dev_get_drvdata(dev); + rtc = dev_get_drvdata(dev); rtc2pcf_time(&pcf_tm, &alrm->time); /* do like mktime does and ignore tm_wday */ pcf_tm.time[PCF50633_TI_WKDAY] = 7; - alarm_masked = pcf50633_irq_mask_get(pcf, PCF50633_IRQ_ALARM); + alarm_masked = pcf50633_irq_mask_get(rtc->pcf, PCF50633_IRQ_ALARM); /* disable alarm interrupt */ if (!alarm_masked) - pcf50633_irq_mask(pcf, PCF50633_IRQ_ALARM); + pcf50633_irq_mask(rtc->pcf, PCF50633_IRQ_ALARM); - ret = pcf50633_write_block(pcf, PCF50633_REG_RTCSCA, - PCF50633_TI_EXTENT, &pcf_tm.time[0]); - if (ret) - dev_err(dev, "Failed to write alarm time %d\n", ret); + /* Returns 0 on success */ + ret = pcf50633_write_block(rtc->pcf, PCF50633_REG_RTCSCA, + PCF50633_TI_EXTENT, &pcf_tm.time[0]); if (!alarm_masked) - pcf50633_irq_unmask(pcf, PCF50633_IRQ_ALARM); + pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_ALARM); - return 0; + return ret; } + static struct rtc_class_ops pcf50633_rtc_ops = { - .ioctl = pcf50633_rtc_ioctl, - .read_time = pcf50633_rtc_read_time, - .set_time = pcf50633_rtc_set_time, - .read_alarm = pcf50633_rtc_read_alarm, - .set_alarm = pcf50633_rtc_set_alarm, + .read_time = pcf50633_rtc_read_time, + .set_time = pcf50633_rtc_set_time, + .read_alarm = pcf50633_rtc_read_alarm, + .set_alarm = pcf50633_rtc_set_alarm, + .alarm_irq_enable = pcf50633_rtc_alarm_irq_enable, + .update_irq_enable = pcf50633_rtc_update_irq_enable, }; -static void pcf50633_rtc_irq(struct pcf50633 *pcf, int irq, void *unused) +static void pcf50633_rtc_irq(int irq, void *data) { + struct pcf50633_rtc *rtc = data; + switch (irq) { case PCF50633_IRQ_ALARM: - rtc_update_irq(pcf->rtc.rtc_dev, 1, RTC_AF | RTC_IRQF); + rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF); break; case PCF50633_IRQ_SECOND: - rtc_update_irq(pcf->rtc.rtc_dev, 1, RTC_PF | RTC_IRQF); + rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF); break; } } -static int pcf50633_rtc_probe(struct platform_device *pdev) +static int __devinit pcf50633_rtc_probe(struct platform_device *pdev) { - struct rtc_device *rtc; - struct pcf50633 *pcf; + struct pcf50633_subdev_pdata *pdata; + struct pcf50633_rtc *rtc; + - rtc = rtc_device_register("pcf50633", &pdev->dev, - &pcf50633_rtc_ops, THIS_MODULE); - if (IS_ERR(rtc)) - return -ENODEV; + rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); + if (!rtc) + return -ENOMEM; - pcf = platform_get_drvdata(pdev); + pdata = pdev->dev.platform_data; + rtc->pcf = pdata->pcf; + platform_set_drvdata(pdev, rtc); + rtc->rtc_dev = rtc_device_register("pcf50633-rtc", &pdev->dev, + &pcf50633_rtc_ops, THIS_MODULE); - /* Set up IRQ handlers */ - pcf->irq_handler[PCF50633_IRQ_ALARM].handler = pcf50633_rtc_irq; - pcf->irq_handler[PCF50633_IRQ_SECOND].handler = pcf50633_rtc_irq; + if (IS_ERR(rtc->rtc_dev)) { + kfree(rtc); + return PTR_ERR(rtc->rtc_dev); + } - pcf->rtc.rtc_dev = rtc; + pcf50633_register_irq(rtc->pcf, PCF50633_IRQ_ALARM, + pcf50633_rtc_irq, rtc); + pcf50633_register_irq(rtc->pcf, PCF50633_IRQ_SECOND, + pcf50633_rtc_irq, rtc); return 0; } -static int pcf50633_rtc_remove(struct platform_device *pdev) +static int __devexit pcf50633_rtc_remove(struct platform_device *pdev) { + struct pcf50633_rtc *rtc; + + rtc = platform_get_drvdata(pdev); + + pcf50633_free_irq(rtc->pcf, PCF50633_IRQ_ALARM); + pcf50633_free_irq(rtc->pcf, PCF50633_IRQ_SECOND); + + rtc_device_unregister(rtc->rtc_dev); + kfree(rtc); + return 0; } - static struct platform_driver pcf50633_rtc_driver = { .driver = { .name = "pcf50633-rtc", @@ -293,8 +338,7 @@ static void __exit pcf50633_rtc_exit(void) } module_exit(pcf50633_rtc_exit); - -MODULE_DESCRIPTION("RTC driver for NXP PCF50633 power management unit"); +MODULE_DESCRIPTION("PCF50633 RTC driver"); MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>"); MODULE_LICENSE("GPL"); |