Skip to contentSkip to conversation

Add a simple rtc framework

PATCH Applied Antony Pavlov 2 participants 11 messages Jul 29, 2014 – Jul 31, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover Add a simple rtc framework

Changes since RFC v3:

* rebase over latest 'next';
* hwclock: add additional checks;
* add jz4740 driver; make appropriate changes
for jz4755 and Ritmix RZX50 support;
* fix copyright information.

Changes since RFC v2:

* rtc/Kconfig: fix formatting, dependencies and help sections;
* hwclock: read time into environment variable.

Changes since RFC v1:

* rebase over latest 'next';
* fix copy'n'paste side effects;
* add hwclock set time function;
* make hwclock options more close to util-linux hwclock;
* rtc-ds1307: add ds1338 chip support (used in versatile);
* use qemu-versatile for testing.

Antony Pavlov (9):
lib: import 'bcd' from linux-3.15
Add a simple rtc framework
rtc: import ds1307 driver from linux-3.15
commands: add hwclock
ARM: versatilepb_defconfig: enable RTC support
rtc-lib: import rtc_time_to_tm() from linux-3.15
rtc: add jz4740 driver
MIPS: dts: jz4755.dtsi: add jz4740-rtc
MIPS: ritmix-rzx50_defconfig: enable RTC support

 arch/arm/configs/versatilepb_defconfig   |   2 +
 arch/mips/configs/ritmix-rzx50_defconfig |   3 +
 arch/mips/dts/jz4755.dtsi                |   5 +
 commands/Kconfig                         |   8 +
 commands/Makefile                        |   1 +
 commands/hwclock.c                       | 161 ++++++++++++++
 drivers/Kconfig                          |   1 +
 drivers/Makefile                         |   1 +
 drivers/rtc/Kconfig                      |  44 ++++
 drivers/rtc/Makefile                     |  11 +
 drivers/rtc/class.c                      |  70 +++++++
 drivers/rtc/rtc-ds1307.c                 | 347 +++++++++++++++++++++++++++++++
 drivers/rtc/rtc-jz4740.c                 | 165 +++++++++++++++
 drivers/rtc/rtc-lib.c                    | 113 ++++++++++
 include/linux/bcd.h                      |  22 ++
 include/linux/rtc.h                      |  47 +++++
 include/rtc.h                            |   2 +
 lib/Makefile                             |   1 +
 lib/bcd.c                                |  14 ++
 19 files changed, 1018 insertions(+)
 create mode 100644 commands/hwclock.c
 create mode 100644 drivers/rtc/Kconfig
 create mode 100644 drivers/rtc/Makefile
 create mode 100644 drivers/rtc/class.c
 create mode 100644 drivers/rtc/rtc-ds1307.c
 create mode 100644 drivers/rtc/rtc-jz4740.c
 create mode 100644 drivers/rtc/rtc-lib.c
 create mode 100644 include/linux/bcd.h
 create mode 100644 include/linux/rtc.h
 create mode 100644 lib/bcd.c
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v4 1/9 lib: import 'bcd' from linux-3.15

---
 include/linux/bcd.h | 22 ++++++++++++++++++++++
 lib/Makefile        |  1 +
 lib/bcd.c           | 14 ++++++++++++++
 3 files changed, 37 insertions(+)
include/linux/bcd.h new file +22 -0
new file mode 100644
index 0000000..18fff11
@@ -0,0 +1,22 @@
+#ifndef _BCD_H
+#define _BCD_H
+
+#include <linux/compiler.h>
+
+#define bcd2bin(x)					\
+		(__builtin_constant_p((u8 )(x)) ?	\
+		const_bcd2bin(x) :			\
+		_bcd2bin(x))
+
+#define bin2bcd(x)					\
+		(__builtin_constant_p((u8 )(x)) ?	\
+		const_bin2bcd(x) :			\
+		_bin2bcd(x))
+
+#define const_bcd2bin(x)	(((x) & 0x0f) + ((x) >> 4) * 10)
+#define const_bin2bcd(x)	((((x) / 10) << 4) + (x) % 10)
+
+unsigned _bcd2bin(unsigned char val) __attribute_const__;
+unsigned char _bin2bcd(unsigned val) __attribute_const__;
+
+#endif /* _BCD_H */
lib/Makefile +1 -0
index 60274c3..977977f 100644
@@ -1,3 +1,4 @@
+obj-y			+= bcd.o
 obj-$(CONFIG_BOOTSTRAP)	+= bootstrap/
 obj-y			+= ctype.o
 obj-y			+= rbtree.o
lib/bcd.c new file +14 -0
new file mode 100644
index 0000000..b072d50
@@ -0,0 +1,14 @@
+#include <linux/bcd.h>
+#include <module.h>
+
+unsigned _bcd2bin(unsigned char val)
+{
+	return (val & 0x0f) + (val >> 4) * 10;
+}
+EXPORT_SYMBOL(_bcd2bin);
+
+unsigned char _bin2bcd(unsigned val)
+{
+	return ((val / 10) << 4) + val % 10;
+}
+EXPORT_SYMBOL(_bin2bcd);
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v4 2/9 Add a simple rtc framework

In reply to Antony Pavlov

This patch adds a simple rtc framework
for reading and setting board's RTC time.

---
 drivers/Kconfig       |  1 +
 drivers/Makefile      |  1 +
 drivers/rtc/Kconfig   | 15 +++++++++++
 drivers/rtc/Makefile  |  6 +++++
 drivers/rtc/class.c   | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/rtc/rtc-lib.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/rtc.h   | 46 +++++++++++++++++++++++++++++++++
 include/rtc.h         |  2 ++
 8 files changed, 209 insertions(+)
drivers/Kconfig +1 -0
index 12a9d8c..d38032c 100644
@@ -28,5 +28,6 @@ source "drivers/bus/Kconfig"
 source "drivers/regulator/Kconfig"
 source "drivers/reset/Kconfig"
 source "drivers/pci/Kconfig"
+source "drivers/rtc/Kconfig"
 
 endmenu
drivers/Makefile +1 -0
index 1990e86..4591f9a 100644
@@ -27,3 +27,4 @@ obj-y += bus/
 obj-$(CONFIG_REGULATOR) += regulator/
 obj-$(CONFIG_RESET_CONTROLLER) += reset/
 obj-$(CONFIG_PCI) += pci/
+obj-y += rtc/
drivers/rtc/Kconfig new file +15 -0
new file mode 100644
index 0000000..5401503
@@ -0,0 +1,15 @@
+#
+# RTC class/drivers configuration
+#
+
+config RTC_LIB
+	bool
+
+menuconfig RTC_CLASS
+	bool "Real Time Clock"
+	default n
+	select RTC_LIB
+	help
+	  Generic RTC class support. If you say yes here, you will
+	  be allowed to plug one or more RTCs to your system. You will
+	  probably want to enable one or more of the interfaces below.
drivers/rtc/Makefile new file +6 -0
new file mode 100644
index 0000000..7d1b5bc
@@ -0,0 +1,6 @@
+#
+# Makefile for RTC class/drivers.
+#
+
+obj-$(CONFIG_RTC_LIB)           += rtc-lib.o
+obj-$(CONFIG_RTC_CLASS)         += class.o
drivers/rtc/class.c new file +70 -0

70 lines not on this page · raw message

drivers/rtc/rtc-lib.c new file +68 -0

68 lines not on this page · raw message

include/linux/rtc.h new file +46 -0

46 lines not on this page · raw message

include/rtc.h +2 -0
index c2d8bce..e2414fb 100644
@@ -53,4 +53,6 @@ void to_tm (int, struct rtc_time *);
 unsigned long mktime (unsigned int, unsigned int, unsigned int,
 		      unsigned int, unsigned int, unsigned int);
 
+extern struct rtc_device *rtc_lookup(const char *name);
+
 #endif	/* _RTC_H_ */
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v4 3/9 rtc: import ds1307 driver from linux-3.15

In reply to Antony Pavlov

Current ds1307 rtc driver supports only ds1307 and ds1338 chips; it has no nvram support at the moment.

---
 drivers/rtc/Kconfig      |  22 +++
 drivers/rtc/Makefile     |   4 +
 drivers/rtc/rtc-ds1307.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+)
drivers/rtc/Kconfig +22 -0
index 5401503..c2b3764 100644
@@ -13,3 +13,25 @@ menuconfig RTC_CLASS
 	  Generic RTC class support. If you say yes here, you will
 	  be allowed to plug one or more RTCs to your system. You will
 	  probably want to enable one or more of the interfaces below.
+
+if RTC_CLASS
+
+comment "I2C RTC drivers"
+	depends on I2C
+
+if I2C
+
+config RTC_DRV_DS1307
+	tristate "Dallas/Maxim DS1307/38"
+	help
+	  If you say yes here you get support for various compatible RTC
+	  chips (often with battery backup) connected with I2C. This driver
+	  should handle DS1307, DS1338 and probably other chips.
+
+	  The first seven registers on these chips hold an RTC, and other
+	  registers may add features such as NVRAM, a trickle charger for
+	  the RTC/NVRAM backup power, and alarms.
+
+endif # I2C
+
+endif # RTC_CLASS
drivers/rtc/Makefile +4 -0
index 7d1b5bc..2c5a50e 100644
@@ -4,3 +4,7 @@
 
 obj-$(CONFIG_RTC_LIB)           += rtc-lib.o
 obj-$(CONFIG_RTC_CLASS)         += class.o
+
+# Keep the list ordered.
+
+obj-$(CONFIG_RTC_DRV_DS1307)    += rtc-ds1307.o
drivers/rtc/rtc-ds1307.c new file +347 -0

347 lines not on this page · raw message

Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v4 4/9 commands: add hwclock

In reply to Antony Pavlov

The hwclock command allows to query or set the hardware clock (RTC).

Barebox' 'hwclock' command uses busybox' 'date' compatible time format ccyymmddHHMM[.SS]:

  # /bin/busybox date -s 201407292005.41 ; /bin/date
  Tue Jul 29 20:05:41 MSK 2014
  Tue Jul 29 20:05:41 MSK 2014
---
 commands/Kconfig   |   8 +++
 commands/Makefile  |   1 +
 commands/hwclock.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
commands/Kconfig +8 -0
index 506b3d0..df8d60f 100644
@@ -1691,6 +1691,14 @@ config CMD_GPIO
 
 	  Usage: gpio_set_value GPIO VALUE
 
+config CMD_HWCLOCK
+	bool
+	depends on RTC_CLASS
+	prompt "hwclock command"
+	default y
+	help
+	  The hwclock command allows to query or set the hardware clock (RTC).
+
 config CMD_I2C
 	bool
 	depends on I2C
commands/Makefile +1 -0
index f3caceb..9151c96 100644
@@ -101,3 +101,4 @@ obj-$(CONFIG_CMD_2048)		+= 2048.o
 obj-$(CONFIG_CMD_REGULATOR)	+= regulator.o
 obj-$(CONFIG_CMD_LSPCI)		+= lspci.o
 obj-$(CONFIG_CMD_USBGADGET)	+= usbgadget.o
+obj-$(CONFIG_CMD_HWCLOCK)	+= hwclock.o
commands/hwclock.c new file +161 -0

161 lines not on this page · raw message

Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH v4 5/9 ARM: versatilepb_defconfig: enable RTC support

In reply to Antony Pavlov

Use this qemu cmdline to test hwclock

  $ qemu-system-arm -M versatilepb -nographic \
      -monitor null -kernel barebox -serial stdio
---
 arch/arm/configs/versatilepb_defconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/configs/versatilepb_defconfig +2 -0
index 58dfb8b..a447f93 100644
@@ -51,6 +51,8 @@ CONFIG_DRIVER_NET_SMC91111=y
 CONFIG_I2C=y
 CONFIG_I2C_VERSATILE=y
 CONFIG_GPIO_PL061=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_DS1307=y
 CONFIG_FS_CRAMFS=y
 CONFIG_FS_TFTP=y
 CONFIG_SHA1=y
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH v4 6/9 rtc-lib: import rtc_time_to_tm() from linux-3.15

In reply to Antony Pavlov
---
 drivers/rtc/rtc-lib.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/rtc.h   |  1 +
 2 files changed, 46 insertions(+)
drivers/rtc/rtc-lib.c +45 -0
index 0d6acde..1b23458 100644
@@ -39,6 +39,51 @@ int rtc_month_days(unsigned int month, unsigned int year)
 EXPORT_SYMBOL(rtc_month_days);
 
 /*
+ * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
+ */
+void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
+{
+	unsigned int month, year;
+	int days;
+
+	days = time / 86400;
+	time -= (unsigned int) days * 86400;
+
+	/* day of the week, 1970-01-01 was a Thursday */
+	tm->tm_wday = (days + 4) % 7;
+
+	year = 1970 + days / 365;
+	days -= (year - 1970) * 365
+		+ LEAPS_THRU_END_OF(year - 1)
+		- LEAPS_THRU_END_OF(1970 - 1);
+	if (days < 0) {
+		year -= 1;
+		days += 365 + is_leap_year(year);
+	}
+	tm->tm_year = year - 1900;
+	tm->tm_yday = days + 1;
+
+	for (month = 0; month < 11; month++) {
+		int newdays;
+
+		newdays = days - rtc_month_days(month, year);
+		if (newdays < 0)
+			break;
+		days = newdays;
+	}
+	tm->tm_mon = month;
+	tm->tm_mday = days + 1;
+
+	tm->tm_hour = time / 3600;
+	time -= tm->tm_hour * 3600;
+	tm->tm_min = time / 60;
+	tm->tm_sec = time - tm->tm_min * 60;
+
+	tm->tm_isdst = 0;
+}
+EXPORT_SYMBOL(rtc_time_to_tm);
+
+/*
  * Does the rtc_time represent a valid date/time?
  */
 int rtc_valid_tm(struct rtc_time *tm)
include/linux/rtc.h +1 -0
index 2e034f6..2dacb14 100644
@@ -17,6 +17,7 @@
 extern int rtc_month_days(unsigned int month, unsigned int year);
 extern int rtc_valid_tm(struct rtc_time *tm);
 extern int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time);
+extern void rtc_time_to_tm(unsigned long time, struct rtc_time *tm);
 
 struct rtc_class_ops;
 
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH v4 7/9 rtc: add jz4740 driver

In reply to Antony Pavlov

Add support for the RTC unit on Ingenic JZ4740, JZ475x and JZ477x SoCs.

---
 drivers/rtc/Kconfig      |   7 ++
 drivers/rtc/Makefile     |   1 +
 drivers/rtc/rtc-jz4740.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 173 insertions(+)
drivers/rtc/Kconfig +7 -0
index c2b3764..957fee7 100644
@@ -34,4 +34,11 @@ config RTC_DRV_DS1307
 
 endif # I2C
 
+config RTC_DRV_JZ4740
+	tristate "Ingenic JZ4740 RTC"
+	depends on MACH_MIPS_XBURST
+	help
+	  If you say yes here you get support for the Ingenic JZ4740 SoC RTC
+	  controller.
+
 endif # RTC_CLASS
drivers/rtc/Makefile +1 -0
index 2c5a50e..1cc9bb8 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_RTC_CLASS)         += class.o
 # Keep the list ordered.
 
 obj-$(CONFIG_RTC_DRV_DS1307)    += rtc-ds1307.o
+obj-$(CONFIG_RTC_DRV_JZ4740)	+= rtc-jz4740.o
drivers/rtc/rtc-jz4740.c new file +165 -0

165 lines not on this page · raw message

Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH v4 8/9 MIPS: dts: jz4755.dtsi: add jz4740-rtc

In reply to Antony Pavlov
---
 arch/mips/dts/jz4755.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/mips/dts/jz4755.dtsi +5 -0
index 0e655b6..ed64f9a 100644
@@ -8,6 +8,11 @@
 		#size-cells = <1>;
 		ranges;
 
+		rtc: rtc@10003000 {
+			compatible = "ingenic,jz4740-rtc";
+			reg = <0xb0003000 0x38>;
+		};
+
 		serial0: serial@b0030000 {
 			compatible = "ingenic,jz4740-uart";
 			reg = <0xb0030000 0x20>;
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH v4 9/9 MIPS: ritmix-rzx50_defconfig: enable RTC support

In reply to Antony Pavlov

Also enable CONFIG_LONGHELP.

---
 arch/mips/configs/ritmix-rzx50_defconfig | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/configs/ritmix-rzx50_defconfig +3 -0
index e6f10fb..3a2cf54 100644
@@ -10,6 +10,7 @@ CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 # CONFIG_DEFAULT_ENVIRONMENT is not set
 CONFIG_DEBUG_LL=y
+CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_BOOTM_SHOW_TYPE=y
@@ -36,6 +37,8 @@ CONFIG_CMD_OFTREE=y
 CONFIG_OFDEVICE=y
 # CONFIG_SPI is not set
 CONFIG_GPIO_JZ4740=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_JZ4740=y
 CONFIG_SHA1=y
 CONFIG_SHA224=y
 CONFIG_SHA256=y
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#10 lore raw
In reply to Antony Pavlov
Quoted 23 lines · Antony Pavlov

Changes since RFC v3:

* rebase over latest 'next';
* hwclock: add additional checks;
* add jz4740 driver; make appropriate changes
for jz4755 and Ritmix RZX50 support;
* fix copyright information.

Changes since RFC v2:

* rtc/Kconfig: fix formatting, dependencies and help sections;
* hwclock: read time into environment variable.

Changes since RFC v1:

* rebase over latest 'next';
* fix copy'n'paste side effects;
* add hwclock set time function;
* make hwclock options more close to util-linux hwclock;
* rtc-ds1307: add ds1338 chip support (used in versatile);
* use qemu-versatile for testing.

Quoted 10 lines

Antony Pavlov (9):
lib: import 'bcd' from linux-3.15
Add a simple rtc framework
rtc: import ds1307 driver from linux-3.15
commands: add hwclock
ARM: versatilepb_defconfig: enable RTC support
rtc-lib: import rtc_time_to_tm() from linux-3.15
rtc: add jz4740 driver
MIPS: dts: jz4755.dtsi: add jz4740-rtc
MIPS: ritmix-rzx50_defconfig: enable RTC support

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox