X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Frtc%2Fftrtc010.c;h=7d0cfb3ba8c7320f6102ec533a5dde4e2aded88e;hb=2693047acdcdae20b066715d0da4937814347935;hp=c3c0bc2f591e7491483c9511d3fde017070d9264;hpb=7c32dc5bed053348003da5ba3635d4c61c420e66;p=u-boot diff --git a/drivers/rtc/ftrtc010.c b/drivers/rtc/ftrtc010.c index c3c0bc2f59..7d0cfb3ba8 100644 --- a/drivers/rtc/ftrtc010.c +++ b/drivers/rtc/ftrtc010.c @@ -4,19 +4,7 @@ * (C) Copyright 2009 Faraday Technology * Po-Yu Chuang * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -34,6 +22,13 @@ struct ftrtc010 { unsigned int alarm_hour; /* 0x18 */ unsigned int record; /* 0x1c */ unsigned int cr; /* 0x20 */ + unsigned int wsec; /* 0x24 */ + unsigned int wmin; /* 0x28 */ + unsigned int whour; /* 0x2c */ + unsigned int wday; /* 0x30 */ + unsigned int intr; /* 0x34 */ + unsigned int div; /* 0x38 */ + unsigned int rev; /* 0x3c */ }; /* @@ -47,15 +42,15 @@ struct ftrtc010 { static struct ftrtc010 *rtc = (struct ftrtc010 *)CONFIG_FTRTC010_BASE; -static void ftrtc010_enable (void) +static void ftrtc010_enable(void) { - writel (FTRTC010_CR_ENABLE, &rtc->cr); + writel(FTRTC010_CR_ENABLE, &rtc->cr); } /* * return current time in seconds */ -static unsigned long ftrtc010_time (void) +static unsigned long ftrtc010_time(void) { unsigned long day; unsigned long hour; @@ -64,11 +59,11 @@ static unsigned long ftrtc010_time (void) unsigned long second2; do { - second = readl (&rtc->sec); - day = readl (&rtc->day); - hour = readl (&rtc->hour); - minute = readl (&rtc->min); - second2 = readl (&rtc->sec); + second = readl(&rtc->sec); + day = readl(&rtc->day); + hour = readl(&rtc->hour); + minute = readl(&rtc->min); + second2 = readl(&rtc->sec); } while (second != second2); return day * 24 * 60 * 60 + hour * 60 * 60 + minute * 60 + second; @@ -78,16 +73,20 @@ static unsigned long ftrtc010_time (void) * Get the current time from the RTC */ -int rtc_get (struct rtc_time *tmp) +int rtc_get(struct rtc_time *tmp) { unsigned long now; - debug ("%s(): record register: %x\n", - __func__, readl (&rtc->record)); + debug("%s(): record register: %x\n", + __func__, readl(&rtc->record)); - now = ftrtc010_time () + readl (&rtc->record); +#ifdef CONFIG_FTRTC010_PCLK + now = (ftrtc010_time() + readl(&rtc->record)) / RTC_DIV_COUNT; +#else /* CONFIG_FTRTC010_EXTCLK */ + now = ftrtc010_time() + readl(&rtc->record); +#endif - to_tm (now, tmp); + rtc_to_tm(now, tmp); return 0; } @@ -95,30 +94,29 @@ int rtc_get (struct rtc_time *tmp) /* * Set the RTC */ -int rtc_set (struct rtc_time *tmp) +int rtc_set(struct rtc_time *tmp) { unsigned long new; unsigned long now; - debug ("%s(): DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", - __func__, - tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + debug("%s(): DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", + __func__, + tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, + tmp->tm_hour, tmp->tm_min, tmp->tm_sec); - new = mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_hour, - tmp->tm_min, tmp->tm_sec); + new = rtc_mktime(tmp); - now = ftrtc010_time (); + now = ftrtc010_time(); - debug ("%s(): write %lx to record register\n", __func__, new - now); + debug("%s(): write %lx to record register\n", __func__, new - now); - writel (new - now, &rtc->record); + writel(new - now, &rtc->record); return 0; } -void rtc_reset (void) +void rtc_reset(void) { - debug ("%s()\n", __func__); - ftrtc010_enable (); + debug("%s()\n", __func__); + ftrtc010_enable(); }