[U-Boot] [PATCH] rtc: add support of mx27 rtc

This driver has been tested on board armadeus apf27.
Signed-off-by: Philippe Reynes tremyfr@yahoo.fr --- arch/arm/include/asm/arch-mx27/imx-regs.h | 3 + arch/arm/include/asm/arch-mx27/regs-rtc.h | 40 ++++++++++++++ drivers/rtc/Makefile | 1 + drivers/rtc/mx27rtc.c | 83 +++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 0 deletions(-) create mode 100644 arch/arm/include/asm/arch-mx27/regs-rtc.h create mode 100644 drivers/rtc/mx27rtc.c
diff --git a/arch/arm/include/asm/arch-mx27/imx-regs.h b/arch/arm/include/asm/arch-mx27/imx-regs.h index ced5b2a..f7cf85b 100644 --- a/arch/arm/include/asm/arch-mx27/imx-regs.h +++ b/arch/arm/include/asm/arch-mx27/imx-regs.h @@ -24,6 +24,8 @@ #ifndef _IMX_REGS_H #define _IMX_REGS_H
+#include <asm/arch/regs-rtc.h> + #ifndef __ASSEMBLY__
extern void imx_gpio_mode (int gpio_mode); @@ -224,6 +226,7 @@ struct fuse_bank0_regs { #define IMX_TIM1_BASE (0x03000 + IMX_IO_BASE) #define IMX_TIM2_BASE (0x04000 + IMX_IO_BASE) #define IMX_TIM3_BASE (0x05000 + IMX_IO_BASE) +#define IMX_RTC_BASE (0x07000 + IMX_IO_BASE) #define UART1_BASE (0x0a000 + IMX_IO_BASE) #define UART2_BASE (0x0b000 + IMX_IO_BASE) #define UART3_BASE (0x0c000 + IMX_IO_BASE) diff --git a/arch/arm/include/asm/arch-mx27/regs-rtc.h b/arch/arm/include/asm/arch-mx27/regs-rtc.h new file mode 100644 index 0000000..4f92d0f --- /dev/null +++ b/arch/arm/include/asm/arch-mx27/regs-rtc.h @@ -0,0 +1,40 @@ +/* + * Freescale i.MX27 RTC Register Definitions + * + * Copyright (C) 2012 Philippe Reynes tremyfr@yahoo.fr + * + * 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 + * + */ + +#ifndef __MX27_REGS_RTC_H__ +#define __MX27_REGS_RTC_H__ + +#ifndef __ASSEMBLY__ +struct rtc_regs { + u32 hourmin; + u32 seconds; + u32 alrm_hm; + u32 alrm_sec; + u32 rtcctl; + u32 rtcisr; + u32 rtcienr; + u32 stpwch; + u32 dayr; + u32 dayalarm; +}; +#endif /* __ASSEMBLY__*/ + +#endif /* __MX28_REGS_RTC_H__ */ diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index faf4fcd..640f148 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -57,6 +57,7 @@ COBJS-$(CONFIG_RTC_MK48T59) += mk48t59.o COBJS-$(CONFIG_RTC_MPC5200) += mpc5xxx.o COBJS-$(CONFIG_RTC_MPC8xx) += mpc8xx.o COBJS-$(CONFIG_RTC_MV) += mvrtc.o +COBJS-$(CONFIG_RTC_MX27) += mx27rtc.o COBJS-$(CONFIG_RTC_MXS) += mxsrtc.o COBJS-$(CONFIG_RTC_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o diff --git a/drivers/rtc/mx27rtc.c b/drivers/rtc/mx27rtc.c new file mode 100644 index 0000000..7628dec --- /dev/null +++ b/drivers/rtc/mx27rtc.c @@ -0,0 +1,83 @@ +/* + * Freescale i.MX27 RTC Driver + * + * Copyright (C) 2012 Philippe Reynes tremyfr@yahoo.fr + * + * 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> +#include <rtc.h> +#include <asm/io.h> +#include <asm/arch/imx-regs.h> + +#define HOUR_SHIFT 8 +#define HOUR_MASK 0x1f +#define MIN_SHIFT 0 +#define MIN_MASK 0x3f + +int rtc_get(struct rtc_time *time) +{ + struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE; + uint32_t day, hour, min, sec; + + day = readl(&rtc_regs->dayr); + hour = readl(&rtc_regs->hourmin); + sec = readl(&rtc_regs->seconds); + + min = (hour >> MIN_SHIFT) & MIN_MASK; + hour = (hour >> HOUR_SHIFT) & HOUR_MASK; + + sec += min * 60 + hour * 3600 + day * 24 * 3600; + + to_tm(sec, time); + + return 0; +} + +int rtc_set(struct rtc_time *time) +{ + struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE; + uint32_t day, hour, min, sec; + + sec = mktime(time->tm_year, time->tm_mon, time->tm_mday, + time->tm_hour, time->tm_min, time->tm_sec); + + day = sec / (24 * 3600); + sec = sec % (24 * 3600); + hour = sec / 3600; + sec = sec % 3600; + min = sec / 60; + sec = sec % 60; + + hour = (hour & HOUR_MASK) << HOUR_SHIFT; + hour |= (min & MIN_MASK) << MIN_SHIFT; + + writel(day, &rtc_regs->dayr); + writel(hour, &rtc_regs->hourmin); + writel(sec, &rtc_regs->seconds); + + return 0; +} + +void rtc_reset(void) +{ + struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE; + + writel(0, &rtc_regs->dayr); + writel(0, &rtc_regs->hourmin); + writel(0, &rtc_regs->seconds); +}

Am 08/08/2012 19:04, schrieb Philippe Reynes:
This driver has been tested on board armadeus apf27.
Signed-off-by: Philippe Reynes tremyfr@yahoo.fr
Hi Philippe,
arch/arm/include/asm/arch-mx27/imx-regs.h | 3 + arch/arm/include/asm/arch-mx27/regs-rtc.h | 40 ++++++++++++++ drivers/rtc/Makefile | 1 + drivers/rtc/mx27rtc.c | 83 +++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 0 deletions(-) create mode 100644 arch/arm/include/asm/arch-mx27/regs-rtc.h create mode 100644 drivers/rtc/mx27rtc.c
diff --git a/arch/arm/include/asm/arch-mx27/imx-regs.h b/arch/arm/include/asm/arch-mx27/imx-regs.h index ced5b2a..f7cf85b 100644 --- a/arch/arm/include/asm/arch-mx27/imx-regs.h +++ b/arch/arm/include/asm/arch-mx27/imx-regs.h @@ -24,6 +24,8 @@ #ifndef _IMX_REGS_H #define _IMX_REGS_H
+#include <asm/arch/regs-rtc.h>
#ifndef __ASSEMBLY__
extern void imx_gpio_mode (int gpio_mode); @@ -224,6 +226,7 @@ struct fuse_bank0_regs { #define IMX_TIM1_BASE (0x03000 + IMX_IO_BASE) #define IMX_TIM2_BASE (0x04000 + IMX_IO_BASE) #define IMX_TIM3_BASE (0x05000 + IMX_IO_BASE) +#define IMX_RTC_BASE (0x07000 + IMX_IO_BASE) #define UART1_BASE (0x0a000 + IMX_IO_BASE) #define UART2_BASE (0x0b000 + IMX_IO_BASE) #define UART3_BASE (0x0c000 + IMX_IO_BASE) diff --git a/arch/arm/include/asm/arch-mx27/regs-rtc.h b/arch/arm/include/asm/arch-mx27/regs-rtc.h new file mode 100644 index 0000000..4f92d0f --- /dev/null +++ b/arch/arm/include/asm/arch-mx27/regs-rtc.h @@ -0,0 +1,40 @@ +/*
- Freescale i.MX27 RTC Register Definitions
- Copyright (C) 2012 Philippe Reynes tremyfr@yahoo.fr
- 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
- */
+#ifndef __MX27_REGS_RTC_H__ +#define __MX27_REGS_RTC_H__
+#ifndef __ASSEMBLY__ +struct rtc_regs {
- u32 hourmin;
- u32 seconds;
- u32 alrm_hm;
- u32 alrm_sec;
- u32 rtcctl;
- u32 rtcisr;
- u32 rtcienr;
- u32 stpwch;
- u32 dayr;
- u32 dayalarm;
+}; +#endif /* __ASSEMBLY__*/
+#endif /* __MX28_REGS_RTC_H__ */ diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index faf4fcd..640f148 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -57,6 +57,7 @@ COBJS-$(CONFIG_RTC_MK48T59) += mk48t59.o COBJS-$(CONFIG_RTC_MPC5200) += mpc5xxx.o COBJS-$(CONFIG_RTC_MPC8xx) += mpc8xx.o COBJS-$(CONFIG_RTC_MV) += mvrtc.o +COBJS-$(CONFIG_RTC_MX27) += mx27rtc.o COBJS-$(CONFIG_RTC_MXS) += mxsrtc.o COBJS-$(CONFIG_RTC_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o diff --git a/drivers/rtc/mx27rtc.c b/drivers/rtc/mx27rtc.c new file mode 100644 index 0000000..7628dec --- /dev/null +++ b/drivers/rtc/mx27rtc.c @@ -0,0 +1,83 @@ +/*
- Freescale i.MX27 RTC Driver
- Copyright (C) 2012 Philippe Reynes tremyfr@yahoo.fr
- 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> +#include <rtc.h> +#include <asm/io.h> +#include <asm/arch/imx-regs.h>
+#define HOUR_SHIFT 8 +#define HOUR_MASK 0x1f +#define MIN_SHIFT 0 +#define MIN_MASK 0x3f
+int rtc_get(struct rtc_time *time) +{
- struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
- uint32_t day, hour, min, sec;
- day = readl(&rtc_regs->dayr);
- hour = readl(&rtc_regs->hourmin);
- sec = readl(&rtc_regs->seconds);
- min = (hour >> MIN_SHIFT) & MIN_MASK;
- hour = (hour >> HOUR_SHIFT) & HOUR_MASK;
- sec += min * 60 + hour * 3600 + day * 24 * 3600;
- to_tm(sec, time);
- return 0;
+}
+int rtc_set(struct rtc_time *time) +{
- struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
- uint32_t day, hour, min, sec;
- sec = mktime(time->tm_year, time->tm_mon, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec);
- day = sec / (24 * 3600);
- sec = sec % (24 * 3600);
- hour = sec / 3600;
- sec = sec % 3600;
- min = sec / 60;
- sec = sec % 60;
- hour = (hour & HOUR_MASK) << HOUR_SHIFT;
- hour |= (min & MIN_MASK) << MIN_SHIFT;
- writel(day, &rtc_regs->dayr);
- writel(hour, &rtc_regs->hourmin);
- writel(sec, &rtc_regs->seconds);
- return 0;
+}
+void rtc_reset(void) +{
- struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
- writel(0, &rtc_regs->dayr);
- writel(0, &rtc_regs->hourmin);
- writel(0, &rtc_regs->seconds);
+}
It looks good.
Acked-by: Stefano Babic sbabic@denx.de
Best regards. Stefano Babic

On 08/08/2012 19:04, Philippe Reynes wrote:
This driver has been tested on board armadeus apf27.
Signed-off-by: Philippe Reynes tremyfr@yahoo.fr
arch/arm/include/asm/arch-mx27/imx-regs.h | 3 + arch/arm/include/asm/arch-mx27/regs-rtc.h | 40 ++++++++++++++ drivers/rtc/Makefile | 1 + drivers/rtc/mx27rtc.c | 83 +++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 0 deletions(-) create mode 100644 arch/arm/include/asm/arch-mx27/regs-rtc.h create mode 100644 drivers/rtc/mx27rtc.c
diff --git a/arch/arm/include/asm/arch-mx27/imx-regs.h b/arch/arm/include/asm/arch-mx27/imx-regs.h index ced5b2a..f7cf85b 100644 --- a/arch/arm/include/asm/arch-mx27/imx-regs.h +++ b/arch/arm/include/asm/arch-mx27/imx-regs.h @@ -24,6 +24,8 @@ #ifndef _IMX_REGS_H #define _IMX_REGS_H
+#include <asm/arch/regs-rtc.h>
#ifndef __ASSEMBLY__
extern void imx_gpio_mode (int gpio_mode); @@ -224,6 +226,7 @@ struct fuse_bank0_regs { #define IMX_TIM1_BASE (0x03000 + IMX_IO_BASE) #define IMX_TIM2_BASE (0x04000 + IMX_IO_BASE) #define IMX_TIM3_BASE (0x05000 + IMX_IO_BASE) +#define IMX_RTC_BASE (0x07000 + IMX_IO_BASE) #define UART1_BASE (0x0a000 + IMX_IO_BASE) #define UART2_BASE (0x0b000 + IMX_IO_BASE) #define UART3_BASE (0x0c000 + IMX_IO_BASE) diff --git a/arch/arm/include/asm/arch-mx27/regs-rtc.h b/arch/arm/include/asm/arch-mx27/regs-rtc.h new file mode 100644 index 0000000..4f92d0f --- /dev/null +++ b/arch/arm/include/asm/arch-mx27/regs-rtc.h @@ -0,0 +1,40 @@ +/*
- Freescale i.MX27 RTC Register Definitions
- Copyright (C) 2012 Philippe Reynes tremyfr@yahoo.fr
- 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
- */
+#ifndef __MX27_REGS_RTC_H__ +#define __MX27_REGS_RTC_H__
+#ifndef __ASSEMBLY__ +struct rtc_regs {
- u32 hourmin;
- u32 seconds;
- u32 alrm_hm;
- u32 alrm_sec;
- u32 rtcctl;
- u32 rtcisr;
- u32 rtcienr;
- u32 stpwch;
- u32 dayr;
- u32 dayalarm;
+}; +#endif /* __ASSEMBLY__*/
+#endif /* __MX28_REGS_RTC_H__ */ diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index faf4fcd..640f148 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -57,6 +57,7 @@ COBJS-$(CONFIG_RTC_MK48T59) += mk48t59.o COBJS-$(CONFIG_RTC_MPC5200) += mpc5xxx.o COBJS-$(CONFIG_RTC_MPC8xx) += mpc8xx.o COBJS-$(CONFIG_RTC_MV) += mvrtc.o +COBJS-$(CONFIG_RTC_MX27) += mx27rtc.o COBJS-$(CONFIG_RTC_MXS) += mxsrtc.o COBJS-$(CONFIG_RTC_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o diff --git a/drivers/rtc/mx27rtc.c b/drivers/rtc/mx27rtc.c new file mode 100644 index 0000000..7628dec --- /dev/null +++ b/drivers/rtc/mx27rtc.c @@ -0,0 +1,83 @@ +/*
- Freescale i.MX27 RTC Driver
- Copyright (C) 2012 Philippe Reynes tremyfr@yahoo.fr
- 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> +#include <rtc.h> +#include <asm/io.h> +#include <asm/arch/imx-regs.h>
+#define HOUR_SHIFT 8 +#define HOUR_MASK 0x1f +#define MIN_SHIFT 0 +#define MIN_MASK 0x3f
+int rtc_get(struct rtc_time *time) +{
- struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
- uint32_t day, hour, min, sec;
- day = readl(&rtc_regs->dayr);
- hour = readl(&rtc_regs->hourmin);
- sec = readl(&rtc_regs->seconds);
- min = (hour >> MIN_SHIFT) & MIN_MASK;
- hour = (hour >> HOUR_SHIFT) & HOUR_MASK;
- sec += min * 60 + hour * 3600 + day * 24 * 3600;
- to_tm(sec, time);
- return 0;
+}
+int rtc_set(struct rtc_time *time) +{
- struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
- uint32_t day, hour, min, sec;
- sec = mktime(time->tm_year, time->tm_mon, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec);
- day = sec / (24 * 3600);
- sec = sec % (24 * 3600);
- hour = sec / 3600;
- sec = sec % 3600;
- min = sec / 60;
- sec = sec % 60;
- hour = (hour & HOUR_MASK) << HOUR_SHIFT;
- hour |= (min & MIN_MASK) << MIN_SHIFT;
- writel(day, &rtc_regs->dayr);
- writel(hour, &rtc_regs->hourmin);
- writel(sec, &rtc_regs->seconds);
- return 0;
+}
+void rtc_reset(void) +{
- struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
- writel(0, &rtc_regs->dayr);
- writel(0, &rtc_regs->hourmin);
- writel(0, &rtc_regs->seconds);
+}
Applied to u-boot-imx, thanks.
Best regards, Stefano Babic
participants (3)
-
Philippe Reynes
-
Stefano Babic
-
stefano babic