diff options
author | venu byravarasu <vbyravarasu@nvidia.com> | 2011-04-18 14:49:22 +0530 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2011-04-26 15:55:52 -0700 |
commit | e421d8e8771e4c6698761a5408bf7fe68a6efc8f (patch) | |
tree | 29e6c764a53222c634d4f50dae39f7f209194978 /drivers/rtc/rtc-tps6591x.c | |
parent | eee725de1119955fa792c8542b63a0d619745744 (diff) |
rtc: tps6591x: setting default date & time
Following changes are done:
1. Set default date, if platform data is incorrect.
2. Added an offset to adjust the RTC time to show
the correct date in the time stamp.
Original-Change-Id: I69d9632a3db4a64b61f68bf84098fd00cb95bed7
Reviewed-on: http://git-master/r/27761
Tested-by: Venu Byravarasu <vbyravarasu@nvidia.com>
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
Change-Id: I875005353c75567821f0497a4ee47dc087d8e322
Diffstat (limited to 'drivers/rtc/rtc-tps6591x.c')
-rwxr-xr-x | drivers/rtc/rtc-tps6591x.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/drivers/rtc/rtc-tps6591x.c b/drivers/rtc/rtc-tps6591x.c index 8b69f61055f1..abfb7c20af7d 100755 --- a/drivers/rtc/rtc-tps6591x.c +++ b/drivers/rtc/rtc-tps6591x.c @@ -43,6 +43,18 @@ #define RTC_RESET_VALUE 0x80 #define ALARM_INT_STATUS 0x40 +/* +Linux RTC driver refers 1900 as base year in many calculations. +(e.g. refer drivers/rtc/rtc-lib.c) +*/ +#define OS_REF_YEAR 1900 + +/* + PMU RTC have only 2 nibbles to store year information, so using an offset + of 100 to set the base year as 2000 for our driver. +*/ +#define RTC_YEAR_OFFSET 100 + struct tps6591x_rtc { unsigned long epoch_start; int irq; @@ -90,13 +102,13 @@ static int tps6591x_write_regs(struct device *dev, int reg, int len, static int tps6591x_rtc_valid_tm(struct rtc_time *tm) { - if (tm->tm_year > 99 - || ((unsigned)tm->tm_mon) >= 12 + if (tm->tm_year >= (RTC_YEAR_OFFSET + 99) + || tm->tm_mon >= 12 || tm->tm_mday < 1 - || tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900) - || ((unsigned)tm->tm_hour) >= 24 - || ((unsigned)tm->tm_min) >= 60 - || ((unsigned)tm->tm_sec) >= 60) + || tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + OS_REF_YEAR) + || tm->tm_hour >= 24 + || tm->tm_min >= 60 + || tm->tm_sec >= 60) return -EINVAL; return 0; } @@ -127,8 +139,8 @@ static void convert_decimal_to_bcd(u8 *buf, u8 len) static void print_time(struct device *dev, struct rtc_time *tm) { - dev_info(dev, "RTC Time : %d-%d-%d %d:%d:%d\n", - tm->tm_mday, tm->tm_mon, tm->tm_year, + dev_info(dev, "RTC Time : %d/%d/%d %d:%d:%d\n", + (tm->tm_mon + 1), tm->tm_mday, (tm->tm_year + OS_REF_YEAR), tm->tm_hour, tm->tm_min , tm->tm_sec); } @@ -284,10 +296,8 @@ static int tps6591x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) } if (alrm->enabled && !rtc->irq_en) { - enable_irq(rtc->irq); rtc->irq_en = true; } else if (!alrm->enabled && rtc->irq_en) { - disable_irq(rtc->irq); rtc->irq_en = false; } @@ -438,9 +448,6 @@ static int __devinit tps6591x_rtc_probe(struct platform_device *pdev) return -EBUSY; } - if (reg & RTC_RESET_VALUE) - dev_info(&pdev->dev, "\n %s RTC reset occured\n", __func__); - reg = ENABLE_ALARM_INT; tps6591x_write_regs(&pdev->dev, RTC_INT, 1, ®); if (err) { @@ -448,6 +455,14 @@ static int __devinit tps6591x_rtc_probe(struct platform_device *pdev) return -EBUSY; } + if (pdata->time.tm_year < 2000 || pdata->time.tm_year > 2100) { + memset(&pdata->time, 0, sizeof(pdata->time)); + pdata->time.tm_year = RTC_YEAR_OFFSET; + pdata->time.tm_mday = 1; + } else + pdata->time.tm_year -= OS_REF_YEAR; + tps6591x_rtc_set_time(&pdev->dev, &pdata->time); + dev_set_drvdata(&pdev->dev, rtc); if (pdata && (pdata->irq >= 0)) { rtc->irq = pdata->irq; |