drivers/rtc: add Marvell Integrated RTC.
Subsystems (2)
PATCH 1/1 drivers/rtc: add Marvell Integrated RTC.
This driver can be used for kirkwood SoCs by enabling CONFIG_RTC_MVINTEG. Tested on Global Scale Technologies Dreamplug.
---
Changes from v1:
- renamed files to mvrtc.{c,h}
- used proper c-structs for register access
- used existing macros for register access
- removed RFC
arch/arm/include/asm/arch-kirkwood/kirkwood.h | 1 + drivers/rtc/Makefile | 1 + drivers/rtc/mvrtc.c | 157 +++++++++++++++++++++++++ drivers/rtc/mvrtc.h | 79 +++++++++++++ 4 files changed, 238 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/mvrtc.c create mode 100644 drivers/rtc/mvrtc.h
arch/arm/include/asm/arch-kirkwood/kirkwood.h +1 -0
@@ -50,6 +50,7 @@#define KW_MPP_BASE (KW_REGISTER(0x10000))#define KW_GPIO0_BASE (KW_REGISTER(0x10100))#define KW_GPIO1_BASE (KW_REGISTER(0x10140)) +#define KW_RTC_BASE (KW_REGISTER(0x10300))#define KW_NANDF_BASE (KW_REGISTER(0x10418))#define KW_SPI_BASE (KW_REGISTER(0x10600))#define KW_CPU_WIN_BASE (KW_REGISTER(0x20000))
drivers/rtc/Makefile +1 -0
@@ -55,6 +55,7 @@ COBJS-$(CONFIG_MCFRTC) += mcfrtc.o COBJS-$(CONFIG_RTC_MK48T59) += mk48t59.o COBJS-$(CONFIG_RTC_MPC5200) += mpc5xxx.o COBJS-$(CONFIG_RTC_MPC8xx) += mpc8xx.o +COBJS-$(CONFIG_RTC_MVINTEG) += mvrtc.o COBJS-$(CONFIG_RTC_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
drivers/rtc/mvrtc.c new file +157 -0
157 lines not on this page · raw message
drivers/rtc/mvrtc.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v2 1/1 drivers/rtc: add Marvell Integrated RTC.
v2. My apologies.
thx,
Jason.
PATCH 1/1 drivers/rtc: add Marvell Integrated RTC.
In reply to Jason CooperHi Jason,
Quoted 36 lines · Jason Cooper
This driver can be used for kirkwood SoCs by enabling
CONFIG_RTC_MVINTEG. Tested on Global Scale Technologies Dreamplug.Signed-off-by Jason Cooper <[email protected]>---
Changes from v1:
- renamed files to mvrtc.{c,h}
- used proper c-structs for register access
- used existing macros for register access
- removed RFCarch/arm/include/asm/arch-kirkwood/kirkwood.h | 1 + drivers/rtc/Makefile | 1 + drivers/rtc/mvrtc.c | 157 +++++++++++++++++++++++++ drivers/rtc/mvrtc.h | 79 +++++++++++++ 4 files changed, 238 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/mvrtc.c create mode 100644 drivers/rtc/mvrtc.harch/arm/include/asm/arch-kirkwood/kirkwood.h +1
-0@@ -50,6 +50,7 @@#define KW_MPP_BASE (KW_REGISTER(0x10000))#define KW_GPIO0_BASE (KW_REGISTER(0x10100))#define KW_GPIO1_BASE (KW_REGISTER(0x10140)) +#define KW_RTC_BASE (KW_REGISTER(0x10300))#define KW_NANDF_BASE (KW_REGISTER(0x10418))#define KW_SPI_BASE (KW_REGISTER(0x10600))#define KW_CPU_WIN_BASE (KW_REGISTER(0x20000))drivers/rtc/Makefile +0
-0
drivers/rtc/Makefile COBJS-$(CONFIG_MCFRTC) += mcfrtc.o · line 58
Quoted 4 lines
drivers/rtc/Makefile +1
-0@@ -55,6 +55,7 @@ COBJS-$(CONFIG_MCFRTC) += mcfrtc.o COBJS-$(CONFIG_RTC_MK48T59) += mk48t59.o COBJS-$(CONFIG_RTC_MPC5200) += mpc5xxx.o COBJS-$(CONFIG_RTC_MPC8xx) += mpc8xx.o +COBJS-$(CONFIG_RTC_MVINTEG) += mvrtc.o
What about using CONFIG_RTC_MV ?
Quoted 40 lines
drivers/rtc/Makefile +0
-0COBJS-$(CONFIG_RTC_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.odrivers/rtc/mvrtc.c new file +31
-0@@ -0,0 +1,157 @@ +/* +* Copyright (C) 2011 +* Jason Cooper <[email protected]> +* +* 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 +*/ + +/* +* Date & Time support for Marvell Integrated RTC +*/ + +#include <common.h> +#include <command.h> +#include <rtc.h> +#include "mvrtc.h"
drivers/rtc/mvrtc.c line 41
Quoted 10 lines
drivers/rtc/mvrtc.c new file +10
-0+ +/* This RTC does not support century, so we assume 20 */ +#define CENTURY 20 + +int rtc_get (struct rtc_time *t) +{ +u32 time; +u32 date; +u8 tens; +u8 single;
Maybe you could use the function bcd2bin() and then hide the "tens" and "single" split.
drivers/rtc/mvrtc.c line 50
Quoted 9 lines
drivers/rtc/mvrtc.c new file +9
-0+struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* read the time register */ + time =readl (&mvrtc_regs->time); + +/* read the date register */ + date =readl (&mvrtc_regs->date);
For example, you could have something like:
t->tm_sec = bcd2bin(time & 0x7f);t->tm_min = bcd2bin((time >> MVRTC_MIN_SFT) & 0x7f); t->tm_hour = bcd2bin((time >> MVRTC_HOUR_SFT) & 0x3f); /* 24 hour mode */
...
Quoted 5 lines
drivers/rtc/mvrtc.c new file +5
-0+ +/* seconds */ + tens = ((time &MVRTC_10SEC_MSK ) >>MVRTC_10SEC_SFT ); + single = ((time &MVRTC_SEC_MSK ) >>MVRTC_SEC_SFT ); + t->tm_sec =10 * tens + single;
drivers/rtc/mvrtc.c line 65
Quoted 10 lines
drivers/rtc/mvrtc.c new file +10
-0+ +/* minutes */ + tens = ((time &MVRTC_10MIN_MSK ) >>MVRTC_10MIN_SFT ); + single = ((time &MVRTC_MIN_MSK ) >>MVRTC_MIN_SFT ); + t->tm_min =10 * tens + single; + +/* hours */ + tens = ((time &MVRTC_10HOUR_MSK ) >>MVRTC_10HOUR_SFT ); + single = ((time &MVRTC_HOUR_MSK ) >>MVRTC_HOUR_SFT ); + t->tm_hour =10 * tens + single;
If the RTC operates in 12 hour mode, the code above is wrong.
Quoted 30 lines
drivers/rtc/mvrtc.c new file +30
-0+ +/* day */ + t->tm_wday = ((time &MVRTC_DAY_MSK ) >>MVRTC_DAY_SFT ); + t->tm_wday--; + +/* date */ + tens = ((date &MVRTC_10DATE_MSK ) >>MVRTC_10DATE_SFT ); + single = ((date &MVRTC_DATE_MSK ) >>MVRTC_DATE_SFT ); + t->tm_mday =10 * tens + single; + +/* month */ + tens = ((date &MVRTC_10MON_MSK ) >>MVRTC_10MON_SFT ); + single = ((date &MVRTC_MON_MSK ) >>MVRTC_MON_SFT ); + t->tm_mon =10 * tens + single; + +/* year */ + tens = ((date &MVRTC_10YEAR_MSK ) >>MVRTC_10YEAR_SFT ); + single = ((date &MVRTC_YEAR_MSK ) >>MVRTC_YEAR_SFT ); + t->tm_year = (CENTURY *100 ) + (10 * tens) + single; + +/* not supported in this RTC */ + t->tm_yday =0 ; + t->tm_isdst =0 ; + +return 0 ; +} + +int rtc_set (struct rtc_time *t) +{ +u32 time =0 ;
drivers/rtc/mvrtc.c line 105
Quoted 10 lines
drivers/rtc/mvrtc.c new file +10
-0+u32 date =0 ; +u32 tens; +u32 single; +struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* seconds */ + tens = t->tm_sec /10 ; + single = t->tm_sec %10 ;
Again, you could use the function bin2bcd() and then get ride of this "tens" and "single" split.
drivers/rtc/mvrtc.c line 107
Quoted 2 lines
drivers/rtc/mvrtc.c new file +2
-0+ time |= ((tens <<MVRTC_10SEC_SFT ) &MVRTC_10SEC_MSK ) | + ((single <<MVRTC_SEC_SFT ) &MVRTC_SEC_MSK );
For example, here you could have:
time |= bin2bcd(tm->tm_sec) << MVRTC_SEC_SFT;
Quoted 39 lines
drivers/rtc/mvrtc.c new file +39
-0+ +/* minutes */ + tens = t->tm_min /10 ; + single = t->tm_min %10 ; + time |= ((tens <<MVRTC_10MIN_SFT ) &MVRTC_10MIN_MSK ) | + ((single <<MVRTC_MIN_SFT ) &MVRTC_MIN_MSK ); + +/* hours (24) */ + tens = t->tm_hour /10 ; + single = t->tm_hour %10 ; + time |= ((tens <<MVRTC_10HOUR_SFT ) &MVRTC_10HOUR_MSK ) | + ((single <<MVRTC_HOUR_SFT ) &MVRTC_HOUR_MSK ); + +/* day */ + single = t->tm_wday +1 ; + time |= ((single <<MVRTC_DAY_SFT ) &MVRTC_DAY_MSK ); + +/* date */ + tens = t->tm_mday /10 ; + single = t->tm_mday %10 ; + date |= ((tens <<MVRTC_10DATE_SFT ) &MVRTC_10DATE_MSK ) | + ((single <<MVRTC_DATE_SFT ) &MVRTC_DATE_MSK ); + +/* month */ + tens = t->tm_mon /10 ; + single = t->tm_mon %10 ; + date |= ((tens <<MVRTC_10MON_SFT ) &MVRTC_10MON_MSK ) | + ((single <<MVRTC_MON_SFT ) &MVRTC_MON_MSK ); + +/* year */ +if ((t->tm_year /100 ) !=CENTURY ) +printf ("Warning: Only century %d supported.\n" ,CENTURY ); + tens = (t->tm_year %100 ) /10 ; + single = (t->tm_year %100 ) %10 ; + date |= ((tens <<MVRTC_10YEAR_SFT ) &MVRTC_10YEAR_MSK ) | + ((single <<MVRTC_YEAR_SFT ) &MVRTC_YEAR_MSK ); + +/* write the time register */ +writel (time, &mvrtc_regs->time);
drivers/rtc/mvrtc.c line 156
Quoted 10 lines
drivers/rtc/mvrtc.c new file +10
-0+ +/* write the date register */ +writel (date, &mvrtc_regs->date); + +return 0 ; +} + +void rtc_reset (void ) +{ +/* no init routine for this RTC needed */
In the Linux driver, there is also a check to ensure that the RTC is ticking. Maybe it could be useful here too, just to let know the RTC is functional (or not).
Regards,
Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110801/1022dc90/attachment.pgp
PATCH v2 1/1 drivers/rtc: add Marvell Integrated RTC.
Quoted 37 lines · Simon Guinot
Hi Jason,
Quoted 34 lines · Jason Cooper
This driver can be used for kirkwood SoCs by enabling
CONFIG_RTC_MVINTEG. Tested on Global Scale Technologies Dreamplug.Signed-off-by Jason Cooper <[email protected]>---
Changes from v1:
- renamed files to mvrtc.{c,h}
- used proper c-structs for register access
- used existing macros for register access
- removed RFCarch/arm/include/asm/arch-kirkwood/kirkwood.h | 1 + drivers/rtc/Makefile | 1 + drivers/rtc/mvrtc.c | 157 +++++++++++++++++++++++++ drivers/rtc/mvrtc.h | 79 +++++++++++++ 4 files changed, 238 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/mvrtc.c create mode 100644 drivers/rtc/mvrtc.harch/arm/include/asm/arch-kirkwood/kirkwood.h +1
-0@@ -50,6 +50,7 @@#define KW_MPP_BASE (KW_REGISTER(0x10000))#define KW_GPIO0_BASE (KW_REGISTER(0x10100))#define KW_GPIO1_BASE (KW_REGISTER(0x10140)) +#define KW_RTC_BASE (KW_REGISTER(0x10300))#define KW_NANDF_BASE (KW_REGISTER(0x10418))#define KW_SPI_BASE (KW_REGISTER(0x10600))#define KW_CPU_WIN_BASE (KW_REGISTER(0x20000))drivers/rtc/Makefile +0
-1--- a/drivers/rtc/Makefile
Quoted 8 lines
drivers/rtc/Makefile COBJS-$(CONFIG_MCFRTC) += mcfrtc.o · line 58
Quoted 6 lines
+++ b/drivers/rtc/Makefile
drivers/rtc/Makefile +1
-0@@ -55,6 +55,7 @@ COBJS-$(CONFIG_MCFRTC) += mcfrtc.o COBJS-$(CONFIG_RTC_MK48T59) += mk48t59.o COBJS-$(CONFIG_RTC_MPC5200) += mpc5xxx.o COBJS-$(CONFIG_RTC_MPC8xx) += mpc8xx.o +COBJS-$(CONFIG_RTC_MVINTEG) += mvrtc.oWhat about using
CONFIG_RTC_MV?
Sure.
Quoted 66 lines
Quoted 40 lines
drivers/rtc/Makefile +0
-0COBJS-$(CONFIG_RTC_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.odrivers/rtc/mvrtc.c new file +31
-0@@ -0,0 +1,157 @@ +/* +* Copyright (C) 2011 +* Jason Cooper <[email protected]> +* +* 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 +*/ + +/* +* Date & Time support for Marvell Integrated RTC +*/ + +#include <common.h> +#include <command.h> +#include <rtc.h> +#include "mvrtc.h" drivers/rtc/mvrtc.c line 41
Quoted 10 lines
drivers/rtc/mvrtc.c new file +10
-0+ +/* This RTC does not support century, so we assume 20 */ +#define CENTURY 20 + +int rtc_get (struct rtc_time *t) +{ +u32 time; +u32 date; +u8 tens; +u8 single;Maybe you could use the function
bcd2bin()and then hide the "tens" and "single" split.drivers/rtc/mvrtc.c line 50
Quoted 9 lines
drivers/rtc/mvrtc.c new file +9
-0+struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* read the time register */ + time =readl (&mvrtc_regs->time); + +/* read the date register */ + date =readl (&mvrtc_regs->date);For example, you could have something like:
Quoted 4 lines
t->tm_sec=bcd2bin(time & 0x7f);t->tm_min=bcd2bin((time >> MVRTC_MIN_SFT) & 0x7f);t->tm_hour=bcd2bin((time >> MVRTC_HOUR_SFT) & 0x3f); /* 24 hour mode */
...
Awesome, thanks! Will do.
Quoted 9 lines
Quoted 9 lines
drivers/rtc/mvrtc.c new file +9
-0+ +/* seconds */ + tens = ((time &MVRTC_10SEC_MSK ) >>MVRTC_10SEC_SFT ); + single = ((time &MVRTC_SEC_MSK ) >>MVRTC_SEC_SFT ); + t->tm_sec =10 * tens + single; + +/* minutes */ + tens = ((time &MVRTC_10MIN_MSK ) >>MVRTC_10MIN_SFT ); + single = ((time &MVRTC_MIN_MSK ) >>MVRTC_MIN_SFT );
Quoted 8 lines
drivers/rtc/mvrtc.c line 65
Quoted 6 lines
drivers/rtc/mvrtc.c new file +6
-0+ t->tm_min =10 * tens + single; + +/* hours */ + tens = ((time &MVRTC_10HOUR_MSK ) >>MVRTC_10HOUR_SFT ); + single = ((time &MVRTC_HOUR_MSK ) >>MVRTC_HOUR_SFT ); + t->tm_hour =10 * tens + single;If the RTC operates in 12 hour mode, the code above is wrong.
Will double check, I've been testing it in the evening without problems. I'll set it to just before noon to see what it does.
Quoted 96 lines
Quoted 30 lines
drivers/rtc/mvrtc.c new file +30
-0+ +/* day */ + t->tm_wday = ((time &MVRTC_DAY_MSK ) >>MVRTC_DAY_SFT ); + t->tm_wday--; + +/* date */ + tens = ((date &MVRTC_10DATE_MSK ) >>MVRTC_10DATE_SFT ); + single = ((date &MVRTC_DATE_MSK ) >>MVRTC_DATE_SFT ); + t->tm_mday =10 * tens + single; + +/* month */ + tens = ((date &MVRTC_10MON_MSK ) >>MVRTC_10MON_SFT ); + single = ((date &MVRTC_MON_MSK ) >>MVRTC_MON_SFT ); + t->tm_mon =10 * tens + single; + +/* year */ + tens = ((date &MVRTC_10YEAR_MSK ) >>MVRTC_10YEAR_SFT ); + single = ((date &MVRTC_YEAR_MSK ) >>MVRTC_YEAR_SFT ); + t->tm_year = (CENTURY *100 ) + (10 * tens) + single; + +/* not supported in this RTC */ + t->tm_yday =0 ; + t->tm_isdst =0 ; + +return 0 ; +} + +int rtc_set (struct rtc_time *t) +{ +u32 time =0 ;drivers/rtc/mvrtc.c line 105
Quoted 10 lines
drivers/rtc/mvrtc.c new file +10
-0+u32 date =0 ; +u32 tens; +u32 single; +struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* seconds */ + tens = t->tm_sec /10 ; + single = t->tm_sec %10 ;Again, you could use the function
bin2bcd()and then get ride of this "tens" and "single" split.drivers/rtc/mvrtc.c line 107
Quoted 2 lines
drivers/rtc/mvrtc.c new file +2
-0+ time |= ((tens <<MVRTC_10SEC_SFT ) &MVRTC_10SEC_MSK ) | + ((single <<MVRTC_SEC_SFT ) &MVRTC_SEC_MSK );For example, here you could have:
time |=
bin2bcd(tm->tm_sec)<<MVRTC_SEC_SFT;Quoted 45 lines
drivers/rtc/mvrtc.c new file +45
-0+ +/* minutes */ + tens = t->tm_min /10 ; + single = t->tm_min %10 ; + time |= ((tens <<MVRTC_10MIN_SFT ) &MVRTC_10MIN_MSK ) | + ((single <<MVRTC_MIN_SFT ) &MVRTC_MIN_MSK ); + +/* hours (24) */ + tens = t->tm_hour /10 ; + single = t->tm_hour %10 ; + time |= ((tens <<MVRTC_10HOUR_SFT ) &MVRTC_10HOUR_MSK ) | + ((single <<MVRTC_HOUR_SFT ) &MVRTC_HOUR_MSK ); + +/* day */ + single = t->tm_wday +1 ; + time |= ((single <<MVRTC_DAY_SFT ) &MVRTC_DAY_MSK ); + +/* date */ + tens = t->tm_mday /10 ; + single = t->tm_mday %10 ; + date |= ((tens <<MVRTC_10DATE_SFT ) &MVRTC_10DATE_MSK ) | + ((single <<MVRTC_DATE_SFT ) &MVRTC_DATE_MSK ); + +/* month */ + tens = t->tm_mon /10 ; + single = t->tm_mon %10 ; + date |= ((tens <<MVRTC_10MON_SFT ) &MVRTC_10MON_MSK ) | + ((single <<MVRTC_MON_SFT ) &MVRTC_MON_MSK ); + +/* year */ +if ((t->tm_year /100 ) !=CENTURY ) +printf ("Warning: Only century %d supported.\n" ,CENTURY ); + tens = (t->tm_year %100 ) /10 ; + single = (t->tm_year %100 ) %10 ; + date |= ((tens <<MVRTC_10YEAR_SFT ) &MVRTC_10YEAR_MSK ) | + ((single <<MVRTC_YEAR_SFT ) &MVRTC_YEAR_MSK ); + +/* write the time register */ +writel (time, &mvrtc_regs->time); + +/* write the date register */ +writel (date, &mvrtc_regs->date); + +return 0 ; +}
Quoted 8 lines
drivers/rtc/mvrtc.c line 156
Quoted 4 lines
drivers/rtc/mvrtc.c new file +4
-0+ +void rtc_reset (void ) +{ +/* no init routine for this RTC needed */ In the Linux driver, there is also a check to ensure that the RTC is ticking. Maybe it could be useful here too, just to let know the RTC is functional (or not).
Good idea, I'll take a look at the Linux code for that test and implement similar.
Quoted 4 lines
Regards,
Simon
Thanks for the comments and suggestions,
Jason.
PATCH v3 1/1 drivers/rtc: add Marvell Integrated RTC.
In reply to Jason CooperThis driver can be used for kirkwood SoCs by enabling CONFIG_RTC_MV. Tested on Global Scale Technologies Dreamplug.
---
Changes from v1:
- renamed files to mvrtc.{c,h}
- used proper c-structs for register access
- used existing macros for register access
- removed RFC
Changes from v2:
- use bin2bcd() and bcd2bin() to make code easier to read
- changed CONFIG_RTC_MVINTEG -> CONFIG_RTC_MV
- use 24 hour mode, detect if rtc went into 12 hour mode
- add check if ticking to rtc_reset()
arch/arm/include/asm/arch-kirkwood/kirkwood.h | 1 + drivers/rtc/Makefile | 1 + drivers/rtc/mvrtc.c | 124 +++++++++++++++++++++++++ drivers/rtc/mvrtc.h | 65 +++++++++++++ 4 files changed, 191 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/mvrtc.c create mode 100644 drivers/rtc/mvrtc.h
arch/arm/include/asm/arch-kirkwood/kirkwood.h +1 -0
@@ -50,6 +50,7 @@#define KW_MPP_BASE (KW_REGISTER(0x10000))#define KW_GPIO0_BASE (KW_REGISTER(0x10100))#define KW_GPIO1_BASE (KW_REGISTER(0x10140)) +#define KW_RTC_BASE (KW_REGISTER(0x10300))#define KW_NANDF_BASE (KW_REGISTER(0x10418))#define KW_SPI_BASE (KW_REGISTER(0x10600))#define KW_CPU_WIN_BASE (KW_REGISTER(0x20000))
drivers/rtc/Makefile +1 -0
@@ -55,6 +55,7 @@ COBJS-$(CONFIG_MCFRTC) += mcfrtc.o 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_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
drivers/rtc/mvrtc.c new file +124 -0
124 lines not on this page · raw message
drivers/rtc/mvrtc.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v3 1/1 drivers/rtc: add Marvell Integrated RTC.
Quoted 4 lines · Jason Cooper
This driver can be used for kirkwood SoCs by enabling
CONFIG_RTC_MV. Tested on Global Scale Technologies Dreamplug.Signed-off-by Jason Cooper <[email protected]>
Quoted 253 lines
---
Changes from v1:
- renamed files to mvrtc.{c,h}
- used proper c-structs for register access
- used existing macros for register access
- removed RFCChanges from v2:
- usebin2bcd()andbcd2bin()to make code easier to read
- changedCONFIG_RTC_MVINTEG->CONFIG_RTC_MV
- use 24 hour mode, detect if rtc went into 12 hour mode
- add check if ticking tortc_reset()arch/arm/include/asm/arch-kirkwood/kirkwood.h | 1 + drivers/rtc/Makefile | 1 + drivers/rtc/mvrtc.c | 124 +++++++++++++++++++++++++ drivers/rtc/mvrtc.h | 65 +++++++++++++ 4 files changed, 191 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/mvrtc.c create mode 100644 drivers/rtc/mvrtc.harch/arm/include/asm/arch-kirkwood/kirkwood.h +1
-0@@ -50,6 +50,7 @@#define KW_MPP_BASE (KW_REGISTER(0x10000))#define KW_GPIO0_BASE (KW_REGISTER(0x10100))#define KW_GPIO1_BASE (KW_REGISTER(0x10140)) +#define KW_RTC_BASE (KW_REGISTER(0x10300))#define KW_NANDF_BASE (KW_REGISTER(0x10418))#define KW_SPI_BASE (KW_REGISTER(0x10600))#define KW_CPU_WIN_BASE (KW_REGISTER(0x20000))drivers/rtc/Makefile +1
-0@@ -55,6 +55,7 @@ COBJS-$(CONFIG_MCFRTC) += mcfrtc.o 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_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.odrivers/rtc/mvrtc.c new file +124
-0@@ -0,0 +1,124 @@ +/* +* Copyright (C) 2011 +* Jason Cooper <[email protected]> +* +* 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 +*/ + +/* +* Date & Time support for Marvell Integrated RTC +*/ + +#include <common.h> +#include <command.h> +#include <rtc.h> +#include "mvrtc.h" + +/* This RTC does not support century, so we assume 20 */ +#define CENTURY 20 + +int rtc_get (struct rtc_time *t) +{ +u32 time; +u32 date; +struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* read the time register */ + time =readl (&mvrtc_regs->time); + +/* read the date register */ + date =readl (&mvrtc_regs->date); + +/* test for 12 hour clock (can't tell if it's am/pm) */ +if (time &MVRTC_HRFMT_MSK ) { +printf ("Error: RTC in 12 hour mode, can't determine AM/PM.\n" ); +return -1 ; + } + +/* time */ + t->tm_sec =bcd2bin ((time >>MVRTC_SEC_SFT ) &MVRTC_SEC_MSK ); + t->tm_min =bcd2bin ((time >>MVRTC_MIN_SFT ) &MVRTC_MIN_MSK ); + t->tm_hour =bcd2bin ((time >>MVRTC_HOUR_SFT ) &MVRTC_HOUR_MSK ); + t->tm_wday =bcd2bin ((time >>MVRTC_DAY_SFT ) &MVRTC_DAY_MSK ); + t->tm_wday--; + +/* date */ + t->tm_mday =bcd2bin ((date >>MVRTC_DATE_SFT ) &MVRTC_DATE_MSK ); + t->tm_mon =bcd2bin ((date >>MVRTC_MON_SFT ) &MVRTC_MON_MSK ); + t->tm_year =bcd2bin ((date >>MVRTC_YEAR_SFT ) &MVRTC_YEAR_MSK ); + t->tm_year +=CENTURY *100 ; + +/* not supported in this RTC */ + t->tm_yday =0 ; + t->tm_isdst =0 ; + +return 0 ; +} + +int rtc_set (struct rtc_time *t) +{ +u32 time =0 ;/* sets hour format bit to zero, 24hr format. */ +u32 date =0 ; +struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* check that this code isn't 80+ years old ;-) */ +if ((t->tm_year /100 ) !=CENTURY ) +printf ("Warning: Only century %d supported.\n" ,CENTURY ); + +/* time */ + time |= (bin2bcd (t->tm_sec) &MVRTC_SEC_MSK ) <<MVRTC_SEC_SFT ; + time |= (bin2bcd (t->tm_min) &MVRTC_MIN_MSK ) <<MVRTC_MIN_SFT ; + time |= (bin2bcd (t->tm_hour) &MVRTC_HOUR_MSK ) <<MVRTC_HOUR_SFT ; + time |= (bin2bcd (t->tm_wday +1 ) &MVRTC_DAY_MSK ) <<MVRTC_DAY_SFT ; + +/* date */ + date |= (bin2bcd (t->tm_mday) &MVRTC_DATE_MSK ) <<MVRTC_DATE_SFT ; + date |= (bin2bcd (t->tm_mon) &MVRTC_MON_MSK ) <<MVRTC_MON_SFT ; + date |= (bin2bcd (t->tm_year %100 ) &MVRTC_YEAR_MSK ) <<MVRTC_YEAR_SFT ; + +/* write the time register */ +writel (time, &mvrtc_regs->time); + +/* write the date register */ +writel (date, &mvrtc_regs->date); + +return 0 ; +} + +void rtc_reset (void ) +{ +u32 time; +u32 sec; +struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* no init routine for this RTC needed, just check that it's working */ + time =readl (&mvrtc_regs->time); + sec =bcd2bin ((time >>MVRTC_SEC_SFT ) &MVRTC_SEC_MSK ); +udelay (1000000 ); + time =readl (&mvrtc_regs->time); + +if (sec ==bcd2bin ((time >>MVRTC_SEC_SFT ) &MVRTC_SEC_MSK )) +printf ("Error: RTC did not increment.\n" ); +}drivers/rtc/mvrtc.h new file +65
-0@@ -0,0 +1,65 @@ +/* +* Copyright (C) 2011 +* Jason Cooper <[email protected]> +* +* 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 +*/ + +/* +* Date & Time support for Marvell Integrated RTC +*/ + +#ifndef _MVRTC_H_ +#define _MVRTC_H_ + +#include <asm/arch/kirkwood.h> +#include <compiler.h> + +/* RTC registers */ +struct mvrtc_registers { +u32 time; +u32 date; +}; + +/* time register */ +#define MVRTC_SEC_SFT 0 +#define MVRTC_SEC_MSK 0x7f +#define MVRTC_MIN_SFT 8 +#define MVRTC_MIN_MSK 0x7f +#define MVRTC_HOUR_SFT 16 +#define MVRTC_HOUR_MSK 0x3f +#define MVRTC_DAY_SFT 24 +#define MVRTC_DAY_MSK 0x7 + +/* +* Hour format bit +* 1 = 12 hour clock +* 0 = 24 hour clock +*/ +#define MVRTC_HRFMT_MSK 0x00400000 + +/* date register */ +#define MVRTC_DATE_SFT 0 +#define MVRTC_DATE_MSK 0x3f +#define MVRTC_MON_SFT 8 +#define MVRTC_MON_MSK 0x1f +#define MVRTC_YEAR_SFT 16 +#define MVRTC_YEAR_MSK 0xff + +#endif Signature · 6 lines
1.7.0.4 _______________________________________________ U-Boot mailing list U-Boot at lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110802/5eae6d0a/attachment.pgp
PATCH v3 1/1 drivers/rtc: add Marvell Integrated RTC.
In reply to Jason CooperQuoted 258 lines
-----Original Message-----
From: Jason Cooper [mailto:u-boot at lakedaemon.net]
Sent: Monday, August 01, 2011 7:39 PM
To: wd at denx.de; Prafulla Wadaskar
Cc: u-boot at lists.denx.de; clint at debian.org; Prabhanjan Sarnaik; Ashish Karkare; Siddarth Gore; bdale at gag.com; Jason Cooper
Subject: [PATCH v3]drivers/rtc: add Marvell Integrated RTC.This driver can be used for kirkwood SoCs by enabling
CONFIG_RTC_MV. Tested on
Global Scale Technologies Dreamplug.Signed-off-by Jason Cooper <[email protected]>---
Changes from v1:
- renamed files to mvrtc.{c,h}
- used proper c-structs for register access
- used existing macros for register access
- removed RFCChanges from v2:
- usebin2bcd()andbcd2bin()to make code easier to read
- changedCONFIG_RTC_MVINTEG->CONFIG_RTC_MV
- use 24 hour mode, detect if rtc went into 12 hour mode
- add check if ticking tortc_reset()arch/arm/include/asm/arch-kirkwood/kirkwood.h | 1 + drivers/rtc/Makefile | 1 + drivers/rtc/mvrtc.c | 124 +++++++++++++++++++++++++ drivers/rtc/mvrtc.h | 65 +++++++++++++ 4 files changed, 191 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/mvrtc.c create mode 100644 drivers/rtc/mvrtc.harch/arm/include/asm/arch-kirkwood/kirkwood.h +1
-0@@ -50,6 +50,7 @@#define KW_MPP_BASE (KW_REGISTER(0x10000))#define KW_GPIO0_BASE (KW_REGISTER(0x10100))#define KW_GPIO1_BASE (KW_REGISTER(0x10140)) +#define KW_RTC_BASE (KW_REGISTER(0x10300))#define KW_NANDF_BASE (KW_REGISTER(0x10418))#define KW_SPI_BASE (KW_REGISTER(0x10600))#define KW_CPU_WIN_BASE (KW_REGISTER(0x20000))drivers/rtc/Makefile +1
-0@@ -55,6 +55,7 @@ COBJS-$(CONFIG_MCFRTC) += mcfrtc.o 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_PCF8563) += pcf8563.o COBJS-$(CONFIG_RTC_PL031) += pl031.o COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.odrivers/rtc/mvrtc.c new file +91
-0@@ -0,0 +1,124 @@ +/* +* Copyright (C) 2011 +* Jason Cooper <[email protected]> +* +* 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 +*/ + +/* +* Date & Time support for Marvell Integrated RTC +*/ + +#include <common.h> +#include <command.h> +#include <rtc.h> +#include "mvrtc.h" + +/* This RTC does not support century, so we assume 20 */ +#define CENTURY 20 + +int rtc_get (struct rtc_time *t) +{ +u32 time; +u32 date; +struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* read the time register */ + time =readl (&mvrtc_regs->time); + +/* read the date register */ + date =readl (&mvrtc_regs->date); + +/* test for 12 hour clock (can't tell if it's am/pm) */ +if (time &MVRTC_HRFMT_MSK ) { +printf ("Error: RTC in 12 hour mode, can't determine AM/PM.\n" ); +return -1 ; + } + +/* time */ + t->tm_sec =bcd2bin ((time >>MVRTC_SEC_SFT ) &MVRTC_SEC_MSK ); + t->tm_min =bcd2bin ((time >>MVRTC_MIN_SFT ) &MVRTC_MIN_MSK ); + t->tm_hour =bcd2bin ((time >>MVRTC_HOUR_SFT ) &MVRTC_HOUR_MSK ); + t->tm_wday =bcd2bin ((time >>MVRTC_DAY_SFT ) &MVRTC_DAY_MSK ); + t->tm_wday--; + +/* date */ + t->tm_mday =bcd2bin ((date >>MVRTC_DATE_SFT ) &MVRTC_DATE_MSK ); + t->tm_mon =bcd2bin ((date >>MVRTC_MON_SFT ) &MVRTC_MON_MSK ); + t->tm_year =bcd2bin ((date >>MVRTC_YEAR_SFT ) &MVRTC_YEAR_MSK ); + t->tm_year +=CENTURY *100 ; + +/* not supported in this RTC */ + t->tm_yday =0 ; + t->tm_isdst =0 ; + +return 0 ; +} + +int rtc_set (struct rtc_time *t) +{ +u32 time =0 ;/* sets hour format bit to zero, 24hr format. */ +u32 date =0 ; +struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* check that this code isn't 80+ years old ;-) */ +if ((t->tm_year /100 ) !=CENTURY ) +printf ("Warning: Only century %d supported.\n" ,CENTURY ); + +/* time */ + time |= (bin2bcd (t->tm_sec) &MVRTC_SEC_MSK ) <<MVRTC_SEC_SFT ; + time |= (bin2bcd (t->tm_min) &MVRTC_MIN_MSK ) <<MVRTC_MIN_SFT ; + time |= (bin2bcd(t->tm_hour) & MVRTC_HOUR_MSK) <<
MVRTC_HOUR_SFT;drivers/rtc/mvrtc.c new file +4
-0+ time |= (bin2bcd (t->tm_wday +1 ) &MVRTC_DAY_MSK ) <<MVRTC_DAY_SFT ; + +/* date */ + date |= (bin2bcd(t->tm_mday) & MVRTC_DATE_MSK) <<
MVRTC_DATE_SFT;drivers/rtc/mvrtc.c new file +1
-0+ date |= (bin2bcd(t->tm_mon) & MVRTC_MON_MSK) <<
MVRTC_MON_SFT;drivers/rtc/mvrtc.c new file +1
-0+ date |= (bin2bcd(t->tm_year % 100) & MVRTC_YEAR_MSK) <<
MVRTC_YEAR_SFT;drivers/rtc/mvrtc.c new file +19
-0+ +/* write the time register */ +writel (time, &mvrtc_regs->time); + +/* write the date register */ +writel (date, &mvrtc_regs->date); + +return 0 ; +} + +void rtc_reset (void ) +{ +u32 time; +u32 sec; +struct mvrtc_registers *mvrtc_regs; + + mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE ; + +/* no init routine for this RTC needed, just check that it's working */
drivers/rtc/mvrtc.c new file +8
-0+ time =readl (&mvrtc_regs->time); + sec =bcd2bin ((time >>MVRTC_SEC_SFT ) &MVRTC_SEC_MSK ); +udelay (1000000 ); + time =readl (&mvrtc_regs->time); + +if (sec ==bcd2bin ((time >>MVRTC_SEC_SFT ) &MVRTC_SEC_MSK )) +printf ("Error: RTC did not increment.\n" ); +}drivers/rtc/mvrtc.h new file +55
-0@@ -0,0 +1,65 @@ +/* +* Copyright (C) 2011 +* Jason Cooper <[email protected]> +* +* 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 +*/ + +/* +* Date & Time support for Marvell Integrated RTC +*/ + +#ifndef _MVRTC_H_ +#define _MVRTC_H_ + +#include <asm/arch/kirkwood.h> +#include <compiler.h> + +/* RTC registers */ +struct mvrtc_registers { +u32 time; +u32 date; +}; + +/* time register */ +#define MVRTC_SEC_SFT 0 +#define MVRTC_SEC_MSK 0x7f +#define MVRTC_MIN_SFT 8 +#define MVRTC_MIN_MSK 0x7f +#define MVRTC_HOUR_SFT 16 +#define MVRTC_HOUR_MSK 0x3f +#define MVRTC_DAY_SFT 24 +#define MVRTC_DAY_MSK 0x7 + +/* +* Hour format bit +* 1 = 12 hour clock +* 0 = 24 hour clock +*/ +#define MVRTC_HRFMT_MSK 0x00400000
drivers/rtc/mvrtc.h line 65
Quoted 10 lines
drivers/rtc/mvrtc.h new file +10
-0+ +/* date register */ +#define MVRTC_DATE_SFT 0 +#define MVRTC_DATE_MSK 0x3f +#define MVRTC_MON_SFT 8 +#define MVRTC_MON_MSK 0x1f +#define MVRTC_YEAR_SFT 16 +#define MVRTC_YEAR_MSK 0xff + +#endif
Regards..
Prafulla . .
Quoted 2 lines
--
1.7.0.4
PATCH v3 1/1 drivers/rtc: add Marvell Integrated RTC.
In reply to Jason CooperQuoted 28 lines
-----Original Message-----
From: Jason Cooper [mailto:u-boot at lakedaemon.net]
Sent: Monday, August 01, 2011 7:39 PM
To: wd at denx.de; Prafulla Wadaskar
Cc: u-boot at lists.denx.de; clint at debian.org; Prabhanjan Sarnaik; Ashish Karkare; Siddarth Gore; bdale at gag.com; Jason Cooper
Subject: [PATCH v3]drivers/rtc: add Marvell Integrated RTC.This driver can be used for kirkwood SoCs by enabling
CONFIG_RTC_MV. Tested on
Global Scale Technologies Dreamplug.Signed-off-by Jason Cooper <[email protected]>---
Changes from v1:
- renamed files to mvrtc.{c,h}
- used proper c-structs for register access
- used existing macros for register access
- removed RFCChanges from v2:
- usebin2bcd()andbcd2bin()to make code easier to read
- changedCONFIG_RTC_MVINTEG->CONFIG_RTC_MV
- use 24 hour mode, detect if rtc went into 12 hour mode
- add check if ticking tortc_reset()
Quoted 9 lines
arch/arm/include/asm/arch-kirkwood/kirkwood.h | 1 + drivers/rtc/Makefile | 1 + drivers/rtc/mvrtc.c | 124 +++++++++++++++++++++++++ drivers/rtc/mvrtc.h | 65 +++++++++++++ 4 files changed, 191 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/mvrtc.c create mode 100644 drivers/rtc/mvrtc.h
Applied to u-boot-marvell.git master branch
Regards..
Prafulla . .