From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/7] S3C24XX: Add RTC driver
Date: Wed, 12 Sep 2012 23:03:35 +0200 [thread overview]
Message-ID: <201209122303.35665.marex@denx.de> (raw)
In-Reply-To: <1347448523-19565-5-git-send-email-jose.goncalves@inov.pt>
Dear Jos? Miguel Gon?alves,
> RTC driver for the S3C24XX SoCs.
>
> Signed-off-by: Jos? Miguel Gon?alves <jose.goncalves@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.goncalves@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
next prev parent reply other threads:[~2012-09-12 21:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-12 11:15 [U-Boot] [PATCH 0/7] Add support to MINI2416 board José Miguel Gonçalves
2012-09-12 11:15 ` [U-Boot] [PATCH 1/7] ARM: fix relocation on ARM926EJS José Miguel Gonçalves
2012-09-12 11:15 ` [U-Boot] [PATCH 2/7] S3C24XX: Add core support for Samsung's S3C24XX SoCs José Miguel Gonçalves
2012-09-12 11:15 ` [U-Boot] [PATCH 3/7] S3C24XX: Add serial driver José Miguel Gonçalves
2012-09-12 21:01 ` Marek Vasut
2012-09-13 0:54 ` José Miguel Gonçalves
2012-09-13 9:17 ` Marek Vasut
2012-09-13 9:30 ` José Miguel Gonçalves
2012-09-12 11:15 ` [U-Boot] [PATCH 4/7] S3C24XX: Add RTC driver José Miguel Gonçalves
2012-09-12 21:03 ` Marek Vasut [this message]
2012-09-12 23:28 ` José Miguel Gonçalves
2012-09-12 11:15 ` [U-Boot] [PATCH 5/7] S3C24XX: Add NAND Flash driver José Miguel Gonçalves
2012-09-12 21:11 ` Marek Vasut
2012-09-12 23:16 ` José Miguel Gonçalves
2012-09-12 23:20 ` Scott Wood
2012-09-13 0:18 ` José Miguel Gonçalves
2012-09-13 0:24 ` Marek Vasut
2012-09-13 0:40 ` José Miguel Gonçalves
2012-09-13 0:44 ` Marek Vasut
2012-09-12 23:45 ` Marek Vasut
2012-09-12 23:55 ` José Miguel Gonçalves
2012-09-12 11:15 ` [U-Boot] [PATCH 6/7] Add u-boot-ubl.bin target to the Makefile José Miguel Gonçalves
2012-09-12 11:15 ` [U-Boot] [PATCH 7/7] S3C24XX: Add support to MINI2416 board José Miguel Gonçalves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201209122303.35665.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.