Dear José Miguel Gonçalves, > RTC driver for the S3C24XX SoCs. > > Signed-off-by: José Miguel Gonçalves <jose.goncal...@inov.pt> > --- > drivers/rtc/Makefile | 1 + > drivers/rtc/s3c24xx_rtc.c | 166 > +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 > insertions(+) > create mode 100644 drivers/rtc/s3c24xx_rtc.c > > diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile > index 8316e8f..bd8b1eb 100644 > --- a/drivers/rtc/Makefile > +++ b/drivers/rtc/Makefile > @@ -69,6 +69,7 @@ COBJS-$(CONFIG_RTC_RTC4543) += rtc4543.o > COBJS-$(CONFIG_RTC_RV3029) += rv3029.o > COBJS-$(CONFIG_RTC_RX8025) += rx8025.o > COBJS-$(CONFIG_RTC_S3C24X0) += s3c24x0_rtc.o > +COBJS-$(CONFIG_RTC_S3C24XX) += s3c24xx_rtc.o > COBJS-$(CONFIG_RTC_S3C44B0) += s3c44b0_rtc.o > COBJS-$(CONFIG_RTC_X1205) += x1205.o > > diff --git a/drivers/rtc/s3c24xx_rtc.c b/drivers/rtc/s3c24xx_rtc.c > new file mode 100644 > index 0000000..3844e44 > --- /dev/null > +++ b/drivers/rtc/s3c24xx_rtc.c > @@ -0,0 +1,166 @@ > +/* > + * (C) Copyright 2012 INOV - INESC Inovacao > + * Jose Goncalves <jose.goncal...@inov.pt> > + * > + * Based on drivers/rtc/s3c24x0_rtc.c > + * > + * See file CREDITS for list of people who contributed to this > + * project. > + * > + * 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 <common.h> > + > +#if defined(CONFIG_CMD_DATE) > + > +#include <rtc.h> > +#include <asm/io.h> > +#include <asm/arch/s3c24xx_cpu.h> > + > +static inline void rtc_access_enable(void) > +{ > + s3c24xx_rtc *const rtc = s3c24xx_get_base_rtc(); > + uchar rtccon; > + > + rtccon = readb(&rtc->rtccon); > + rtccon |= 0x01; > + writeb(rtccon, &rtc->rtccon); > +} > + > +static inline void rtc_access_disable(void) > +{ > + s3c24xx_rtc *const rtc = s3c24xx_get_base_rtc(); > + uchar rtccon; > + > + rtccon = readb(&rtc->rtccon); > + rtccon &= ~0x01;
Magic numbers, fix globally in the patchset > + writeb(rtccon, &rtc->rtccon); > +} > + > +/* > ------------------------------------------------------------------------- > */ + > +int rtc_get(struct rtc_time *tmp) > +{ > + s3c24xx_rtc *const rtc = s3c24xx_get_base_rtc(); > + uchar sec, min, hour, mday, wday, mon, year; > + int have_retried = 0; > + > + rtc_access_enable(); > + > + /* Read RTC registers */ > +retry_get_time: > + min = readb(&rtc->bcdmin); > + hour = readb(&rtc->bcdhour); > + mday = readb(&rtc->bcddate); > + wday = readb(&rtc->bcdday); > + mon = readb(&rtc->bcdmon); > + year = readb(&rtc->bcdyear); > + sec = readb(&rtc->bcdsec); > + > + /* The only way to work out whether the RTC was mid-update > + * when we read it is to check the seconds counter. > + * If it's zero, then we re-try the entire read. > + */ Wrong multiline comment style ... use ./tools/checkpatch.pl before resending > + if (rtc->bcdsec == 0 && !have_retried) { I'm sure you can avoid the goto here ...besides, this rtc->bcdsec doesn't make much sense > + have_retried = 1; > + goto retry_get_time; > + } > + > + rtc_access_disable(); > + > + debug("Get RTC year: %02x mon/cent: %02x mday: %02x wday: %02x " > + "hr: %02x min: %02x sec: %02x\n", > + year, mon, mday, wday, hour, min, sec); > + > + tmp->tm_sec = bcd2bin(sec & 0x7F); > + tmp->tm_min = bcd2bin(min & 0x7F); > + tmp->tm_hour = bcd2bin(hour & 0x3F); > + tmp->tm_mday = bcd2bin(mday & 0x3F); > + tmp->tm_wday = bcd2bin(wday & 0x07); > + tmp->tm_mon = bcd2bin(mon & 0x1F); > + tmp->tm_year = bcd2bin(year); > + if (tmp->tm_year < 70) > + tmp->tm_year += 2000; > + else > + tmp->tm_year += 1900; > + tmp->tm_yday = 0; > + tmp->tm_isdst = 0; > + > + debug("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", > + tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, > + tmp->tm_hour, tmp->tm_min, tmp->tm_sec); > + > + return 0; > +} > + > +int rtc_set(struct rtc_time *tmp) > +{ > + s3c24xx_rtc *const rtc = s3c24xx_get_base_rtc(); > + uchar sec, min, hour, mday, wday, mon, year; > + > + debug("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", > + tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, > + tmp->tm_hour, tmp->tm_min, tmp->tm_sec); > + > + if (tmp->tm_year < 1970 || tmp->tm_year > 2069) { > + puts("ERROR: year should be between 1970 and 2069!\n"); > + return -1; > + } > + > + year = bin2bcd(tmp->tm_year % 100); > + mon = bin2bcd(tmp->tm_mon); > + wday = bin2bcd(tmp->tm_wday); > + mday = bin2bcd(tmp->tm_mday); > + hour = bin2bcd(tmp->tm_hour); > + min = bin2bcd(tmp->tm_min); > + sec = bin2bcd(tmp->tm_sec); > + > + debug("Set RTC year: %02x mon/cent: %02x mday: %02x wday: %02x " > + "hr: %02x min: %02x sec: %02x\n", > + year, mon, mday, wday, hour, min, sec); > + > + rtc_access_enable(); > + > + /* Write RTC registers */ > + writeb(sec, &rtc->bcdsec); > + writeb(min, &rtc->bcdmin); > + writeb(hour, &rtc->bcdhour); > + writeb(mday, &rtc->bcddate); > + writeb(wday, &rtc->bcdday); > + writeb(mon, &rtc->bcdmon); > + writeb(year, &rtc->bcdyear); > + > + rtc_access_disable(); > + > + return 0; > +} > + > +void rtc_reset(void) > +{ > + s3c24xx_rtc *const rtc = s3c24xx_get_base_rtc(); > + uchar rtccon; > + > + rtccon = readb(&rtc->rtccon); > + rtccon &= ~0x06; > + rtccon |= 0x08; > + writeb(rtccon, &rtc->rtccon); > + rtccon = readb(&rtc->rtccon); > + rtccon &= ~0x08; > + writeb(rtccon, &rtc->rtccon); > +} > + > +#endif _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot