mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/7] hwclock command: use format like the Linux tool does
@ 2015-12-14 11:43 Sascha Hauer
  2015-12-14 11:43 ` [PATCH 2/7] hwclock command: forward return value of rtc_set_time Sascha Hauer
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-12-14 11:43 UTC (permalink / raw)
  To: Barebox List

Print three-letter abbreviations of the days and months.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/hwclock.c |  4 +---
 common/date.c      | 18 ++++++++++++++++++
 include/rtc.h      |  2 ++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/commands/hwclock.c b/commands/hwclock.c
index a1f5293..49569a9 100644
--- a/commands/hwclock.c
+++ b/commands/hwclock.c
@@ -138,9 +138,7 @@ static int do_hwclock(int argc, char *argv[])
 		snprintf(t, 12, "%lu", time);
 		setenv(env_name, t);
 	} else {
-		printf("%02d:%02d:%02d %02d-%02d-%04d\n",
-			tm.tm_hour, tm.tm_min, tm.tm_sec,
-			tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
+		printf("%s\n", time_str(&tm));
 	}
 
 	return 0;
diff --git a/common/date.c b/common/date.c
index 6b6b7ab..33fb9ec 100644
--- a/common/date.c
+++ b/common/date.c
@@ -148,3 +148,21 @@ mktime (unsigned int year, unsigned int mon,
 	  )*60 + min /* now have minutes */
 	)*60 + sec; /* finally seconds */
 }
+
+const char *time_str(struct rtc_time *tm)
+{
+	const char *weekdays[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
+	const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
+				 "Sep", "Okt", "Nov", "Dec" };
+	static char buf[128];
+
+	sprintf(buf, "%s %02d %s %4d %02d:%02d:%02d",
+			weekdays[tm->tm_wday - 1],
+			tm->tm_mday,
+			months[tm->tm_mon],
+			tm->tm_year + 1900,
+			tm->tm_hour,
+			tm->tm_min,
+			tm->tm_sec);
+	return buf;
+}
\ No newline at end of file
diff --git a/include/rtc.h b/include/rtc.h
index e2414fb..600dc46 100644
--- a/include/rtc.h
+++ b/include/rtc.h
@@ -55,4 +55,6 @@ unsigned long mktime (unsigned int, unsigned int, unsigned int,
 
 extern struct rtc_device *rtc_lookup(const char *name);
 
+const char *time_str(struct rtc_time *tm);
+
 #endif	/* _RTC_H_ */
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/7] hwclock command: forward return value of rtc_set_time
  2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
@ 2015-12-14 11:43 ` Sascha Hauer
  2015-12-14 11:43 ` [PATCH 3/7] rtc: Check time for validity before passing it to the rtc driver Sascha Hauer
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-12-14 11:43 UTC (permalink / raw)
  To: Barebox List

rtc_set_time can fail, forward the error to the user.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/hwclock.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/commands/hwclock.c b/commands/hwclock.c
index 49569a9..3f89cce 100644
--- a/commands/hwclock.c
+++ b/commands/hwclock.c
@@ -124,8 +124,7 @@ static int do_hwclock(int argc, char *argv[])
 		return PTR_ERR(r);
 
 	if (set) {
-		rtc_set_time(r, &stm);
-		return 0;
+		return rtc_set_time(r, &stm);
 	}
 
 	rtc_read_time(r, &tm);
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/7] rtc: Check time for validity before passing it to the rtc driver
  2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
  2015-12-14 11:43 ` [PATCH 2/7] hwclock command: forward return value of rtc_set_time Sascha Hauer
@ 2015-12-14 11:43 ` Sascha Hauer
  2015-12-14 11:43 ` [PATCH 4/7] rtc: Fill in weekdays before setting time Sascha Hauer
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-12-14 11:43 UTC (permalink / raw)
  To: Barebox List

So that rtc drivers do not get invalid times.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/rtc/class.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 356707b..e87f5f7 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -46,6 +46,9 @@ EXPORT_SYMBOL(rtc_read_time);
 
 int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
 {
+	if (rtc_valid_tm(tm))
+		return -EINVAL;
+
 	return rtc->ops->set_time(rtc, tm);
 }
 EXPORT_SYMBOL(rtc_set_time);
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/7] rtc: Fill in weekdays before setting time
  2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
  2015-12-14 11:43 ` [PATCH 2/7] hwclock command: forward return value of rtc_set_time Sascha Hauer
  2015-12-14 11:43 ` [PATCH 3/7] rtc: Check time for validity before passing it to the rtc driver Sascha Hauer
@ 2015-12-14 11:43 ` Sascha Hauer
  2015-12-14 11:43 ` [PATCH 5/7] net: Add SNTP support Sascha Hauer
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-12-14 11:43 UTC (permalink / raw)
  To: Barebox List

Some rtcs store the weekday. Make sure it's filled in correctly before
passinf the time to the driver. This is easily done by converting it to
seconds-since-epoch and back to struct rtc_time.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/rtc/class.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index e87f5f7..8b047a6 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -46,10 +46,16 @@ EXPORT_SYMBOL(rtc_read_time);
 
 int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
 {
+	struct rtc_time time;
+	unsigned long secs;
+
 	if (rtc_valid_tm(tm))
 		return -EINVAL;
 
-	return rtc->ops->set_time(rtc, tm);
+	rtc_tm_to_time(tm, &secs);
+	rtc_time_to_tm(secs, &time);
+
+	return rtc->ops->set_time(rtc, &time);
 }
 EXPORT_SYMBOL(rtc_set_time);
 
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/7] net: Add SNTP support
  2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
                   ` (2 preceding siblings ...)
  2015-12-14 11:43 ` [PATCH 4/7] rtc: Fill in weekdays before setting time Sascha Hauer
@ 2015-12-14 11:43 ` Sascha Hauer
  2015-12-14 11:43 ` [PATCH 6/7] hwclock: Allow to set hwclock from sntp Sascha Hauer
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-12-14 11:43 UTC (permalink / raw)
  To: Barebox List

This adds support for retrieving the time via Simple Network Time
Protocol (SNTP). No fancy features are supported, only plainly getting
the current time.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/sntp.h |   8 +++
 net/Kconfig    |   4 ++
 net/Makefile   |   1 +
 net/sntp.c     | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 186 insertions(+)
 create mode 100644 include/sntp.h
 create mode 100644 net/sntp.c

diff --git a/include/sntp.h b/include/sntp.h
new file mode 100644
index 0000000..bfcfcfa
--- /dev/null
+++ b/include/sntp.h
@@ -0,0 +1,8 @@
+#ifndef __SNTP_H
+#define __SNTP_H
+
+#include <types.h>
+
+s64 sntp(const char *server);
+
+#endif /* __SNTP_H */
diff --git a/net/Kconfig b/net/Kconfig
index a890492..f6ef0ce 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -26,4 +26,8 @@ config NET_DHCP
 	bool
 	prompt "dhcp support"
 
+config NET_SNTP
+	bool
+	prompt "sntp support"
+
 endif
diff --git a/net/Makefile b/net/Makefile
index 8d564e7..eb8d439 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_NET)	+= eth.o
 obj-$(CONFIG_NET)	+= net.o
 obj-$(CONFIG_NET_NFS)	+= nfs.o
 obj-$(CONFIG_NET_DHCP)	+= dhcp.o
+obj-$(CONFIG_NET_SNTP)	+= sntp.o
 obj-$(CONFIG_CMD_PING)	+= ping.o
 obj-$(CONFIG_NET_RESOLV)+= dns.o
 obj-$(CONFIG_NET_NETCONSOLE) += netconsole.o
diff --git a/net/sntp.c b/net/sntp.c
new file mode 100644
index 0000000..3b9f244
--- /dev/null
+++ b/net/sntp.c
@@ -0,0 +1,173 @@
+/*
+ * 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; version 2.
+ *
+ * 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.
+ */
+
+#include <common.h>
+#include <asm/byteorder.h>
+#include <asm/unaligned.h>
+#include <asm-generic/div64.h>
+#include <command.h>
+#include <clock.h>
+#include <net.h>
+#include <sntp.h>
+#include <errno.h>
+#include <environment.h>
+#include <linux/err.h>
+
+#define SNTP_PORT       123
+#define TIMEOUT         1
+
+#define VERSION         4	/* version number */
+
+#define M_RSVD          0	/* reserved */
+#define M_SACT          1	/* symmetric active */
+#define M_PASV          2	/* symmetric passive */
+#define M_CLNT          3	/* client */
+#define M_SERV          4	/* server */
+#define M_BCST          5	/* broadcast server */
+#define M_BCLN          6	/* broadcast client */
+
+typedef uint64_t tstamp;	/* NTP timestamp format */
+typedef uint32_t tdist;		/* NTP short format */
+
+struct ntp_packet {
+#if __BYTE_ORDER == __LITTLE_ENDIAN	// reversed
+	unsigned int mode:3;	/* mode */
+	unsigned int version:3;	/* version number */
+	unsigned int leap:2;	/* leap indicator */
+#elif __BYTE_ORDER == __BIG_ENDIAN	// forward
+	unsigned int leap:2;	/* leap indicator */
+	unsigned int version:3;	/* version number */
+	unsigned int mode:3;	/* mode */
+#else
+#error "byte order undefined"
+#endif
+	uint8_t stratum;	/* stratum */
+	uint8_t poll;		/* poll interval */
+	int8_t precision;	/* precision */
+	tdist rootdelay;	/* root delay */
+	tdist rootdisp;		/* root dispersion */
+	uint32_t refid;		/* reference ID */
+	tstamp reftime;		/* reference time */
+	tstamp org;		/* origin timestamp */
+	tstamp rec;		/* receive timestamp */
+	tstamp xmt;		/* transmit timestamp */
+};
+
+static IPaddr_t net_sntp_ip;
+
+#define SNTP_STATE_INIT		0
+#define SNTP_STATE_SUCCESS	1
+
+static int sntp_state;
+
+static struct net_connection *sntp_con;
+
+static s64 curr_timestamp;
+
+static int sntp_send(void)
+{
+	struct ntp_packet *ntp = net_udp_get_payload(sntp_con);
+
+	memset(ntp, 0, sizeof(struct ntp_packet));
+
+	ntp->version = VERSION;
+	ntp->mode = M_CLNT;
+
+	return net_udp_send(sntp_con, sizeof(struct ntp_packet));
+}
+
+static void sntp_handler(void *ctx, char *pkt, unsigned len)
+{
+	IPaddr_t ip_addr;
+	struct iphdr *ip = net_eth_to_iphdr(pkt);
+	struct ntp_packet *ntp =
+	    (struct ntp_packet *)net_eth_to_udp_payload(pkt);
+
+	ip_addr = net_read_ip((void *)&ip->saddr);
+	if (ip_addr != net_sntp_ip)
+		return;
+
+	len = net_eth_to_udplen(pkt);
+	if (len < sizeof(struct ntp_packet))
+		return;
+
+	pr_debug("received SNTP response\n");
+
+	if (ntp->version != VERSION)
+		return;
+
+	if (ntp->mode != M_SERV)
+		return;
+
+	curr_timestamp = (get_unaligned_be64(&ntp->xmt) >> 32) - 2208988800UL;
+
+	sntp_state = SNTP_STATE_SUCCESS;
+}
+
+s64 sntp(const char *server)
+{
+	int ret, repeat = 5;
+	u64 sntp_start;
+
+	if (!server)
+		server = getenv("global.dhcp.ntpserver");
+	if (!server)
+		return -EINVAL;
+
+	net_sntp_ip = resolv(server);
+	if (!net_sntp_ip) {
+		printf("unknown host %s\n", server);
+		return 1;
+	}
+
+	sntp_con = net_udp_new(net_sntp_ip, SNTP_PORT, sntp_handler, NULL);
+	if (IS_ERR(sntp_con)) {
+		ret = PTR_ERR(sntp_con);
+		goto out;
+	}
+
+	sntp_start = get_time_ns();
+	ret = sntp_send();
+	if (ret)
+		goto out_unreg;
+
+	sntp_state = SNTP_STATE_INIT;
+
+	while (sntp_state == SNTP_STATE_INIT) {
+		if (ctrlc()) {
+			ret = -EINTR;
+			break;
+		}
+
+		net_poll();
+
+		if (is_timeout(sntp_start, 1 * SECOND)) {
+			sntp_start = get_time_ns();
+			ret = sntp_send();
+			if (ret)
+				goto out_unreg;
+			repeat--;
+			if (!repeat) {
+				ret = -ETIMEDOUT;
+				goto out_unreg;
+			}
+		}
+	}
+
+	net_unregister(sntp_con);
+
+	return curr_timestamp;
+
+out_unreg:
+	net_unregister(sntp_con);
+out:
+	return ret;
+}
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/7] hwclock: Allow to set hwclock from sntp
  2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
                   ` (3 preceding siblings ...)
  2015-12-14 11:43 ` [PATCH 5/7] net: Add SNTP support Sascha Hauer
@ 2015-12-14 11:43 ` Sascha Hauer
  2015-12-14 11:43 ` [PATCH 7/7] rtc: Add Abracon driver Sascha Hauer
  2015-12-14 11:54 ` [PATCH 1/7] hwclock command: use format like the Linux tool does Fabio Estevam
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-12-14 11:43 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/hwclock.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/commands/hwclock.c b/commands/hwclock.c
index 3f89cce..7633132 100644
--- a/commands/hwclock.c
+++ b/commands/hwclock.c
@@ -4,6 +4,7 @@
 #include <linux/err.h>
 #include <linux/ctype.h>
 #include <rtc.h>
+#include <sntp.h>
 #include <linux/rtc.h>
 #include <string.h>
 #include <environment.h>
@@ -92,8 +93,10 @@ static int do_hwclock(int argc, char *argv[])
 	char *env_name = NULL;
 	int opt;
 	int set = 0;
+	int ntp_to_hw = 0;
+	char *ntpserver = NULL;
 
-	while ((opt = getopt(argc, argv, "f:s:e:")) > 0) {
+	while ((opt = getopt(argc, argv, "f:s:e:n:")) > 0) {
 		int ret;
 
 		switch (opt) {
@@ -116,6 +119,10 @@ static int do_hwclock(int argc, char *argv[])
 		case 'e':
 			env_name = optarg;
 			break;
+		case 'n':
+			ntp_to_hw = 1;
+			ntpserver = optarg;
+			break;
 		}
 	}
 
@@ -127,6 +134,23 @@ static int do_hwclock(int argc, char *argv[])
 		return rtc_set_time(r, &stm);
 	}
 
+	if (ntp_to_hw) {
+		s64 now;
+
+		if (!IS_ENABLED(CONFIG_NET_SNTP)) {
+			printf("SNTP support is disabled\n");
+			return 1;
+		}
+
+		now = sntp(ntpserver);
+		if (now < 0)
+			return now;
+
+		rtc_time_to_tm(now, &stm);
+		printf("%s\n", time_str(&stm));
+		return rtc_set_time(r, &stm);
+	}
+
 	rtc_read_time(r, &tm);
 
 	if (env_name) {
@@ -147,6 +171,7 @@ BAREBOX_CMD_HELP_START(hwclock)
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-f NAME\t\t\t", "RTC device name (default rtc0)")
 BAREBOX_CMD_HELP_OPT ("-e VARNAME\t\t", "store RTC readout into variable VARNAME")
+BAREBOX_CMD_HELP_OPT ("-n NTPSERVER\t", "set RTC from NTP server")
 BAREBOX_CMD_HELP_OPT ("-s ccyymmddHHMM[.SS]\t", "set time")
 BAREBOX_CMD_HELP_END
 
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/7] rtc: Add Abracon driver
  2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
                   ` (4 preceding siblings ...)
  2015-12-14 11:43 ` [PATCH 6/7] hwclock: Allow to set hwclock from sntp Sascha Hauer
@ 2015-12-14 11:43 ` Sascha Hauer
  2015-12-14 11:54 ` [PATCH 1/7] hwclock command: use format like the Linux tool does Fabio Estevam
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-12-14 11:43 UTC (permalink / raw)
  To: Barebox List

This patch adds support for the Abracon ab-rtcmc-32.768khz-eoz9-s3
RTC. The driver can probably support other Abracon RTCs aswell, but this
hasn't been verified.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/rtc/Kconfig       |   3 ++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-abracon.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 drivers/rtc/rtc-abracon.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 191ad97..7d18194 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -33,6 +33,9 @@ config RTC_DRV_DS1307
 	  registers may add features such as NVRAM, a trickle charger for
 	  the RTC/NVRAM backup power, and alarms.
 
+config RTC_DRV_ABRACON
+	tristate "Abracon RTCs"
+
 endif # I2C
 
 config RTC_DRV_JZ4740
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 1cc9bb8..68741c2 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -7,5 +7,6 @@ obj-$(CONFIG_RTC_CLASS)         += class.o
 
 # Keep the list ordered.
 
+obj-$(CONFIG_RTC_DRV_ABRACON)   += rtc-abracon.o
 obj-$(CONFIG_RTC_DRV_DS1307)    += rtc-ds1307.o
 obj-$(CONFIG_RTC_DRV_JZ4740)	+= rtc-jz4740.o
diff --git a/drivers/rtc/rtc-abracon.c b/drivers/rtc/rtc-abracon.c
new file mode 100644
index 0000000..b3af990
--- /dev/null
+++ b/drivers/rtc/rtc-abracon.c
@@ -0,0 +1,126 @@
+/*
+ * 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; version 2.
+ *
+ * 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.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+#include <xfuncs.h>
+#include <errno.h>
+#include <i2c/i2c.h>
+#include <rtc.h>
+#include <linux/rtc.h>
+#include <linux/bcd.h>
+
+struct abracon {
+	struct rtc_device	rtc;
+	struct i2c_client	*client;
+};
+
+static inline struct abracon *to_abracon_priv(struct rtc_device *rtcdev)
+{
+	return container_of(rtcdev, struct abracon, rtc);
+}
+
+static int abracon_get_time(struct rtc_device *rtcdev, struct rtc_time *t)
+{
+	struct abracon *abracon = to_abracon_priv(rtcdev);
+	struct i2c_client *client = abracon->client;
+	u8 cp[7] = {};
+	u8 reg = 8;
+	struct i2c_msg msg[2] = {};
+	int ret;
+
+	msg[0].addr = client->addr;
+	msg[0].buf = &reg;
+	msg[0].len = 1;
+
+	msg[1].addr = client->addr;
+	msg[1].flags = I2C_M_RD;
+	msg[1].buf = cp;
+	msg[1].len = 7;
+
+	ret = i2c_transfer(client->adapter, msg, 2);
+	if (ret != 2)
+		return -EIO;
+
+	t->tm_sec = bcd2bin(cp[0]);
+	t->tm_min = bcd2bin(cp[1]);
+	t->tm_hour = bcd2bin(cp[2]);
+	t->tm_mday = bcd2bin(cp[3]);
+	t->tm_wday = bcd2bin(cp[4]);
+	t->tm_mon = bcd2bin(cp[5]);
+	t->tm_year = bcd2bin(cp[6]) + 100;
+
+	return 0;
+}
+
+static int abracon_set_time(struct rtc_device *rtcdev, struct rtc_time *t)
+{
+	struct abracon *abracon = to_abracon_priv(rtcdev);
+	struct i2c_client *client = abracon->client;
+	u8 cp[8] = {};
+	int ret;
+
+	cp[0] = 8;
+	cp[1] = bin2bcd(t->tm_sec);
+	cp[2] = bin2bcd(t->tm_min);
+	cp[3] = bin2bcd(t->tm_hour);
+	cp[4] = bin2bcd(t->tm_mday);
+	cp[5] = bin2bcd(t->tm_wday);
+	cp[6] = bin2bcd(t->tm_mon);
+	cp[7] = bin2bcd(t->tm_year - 100);
+
+	ret = i2c_master_send(client, cp, 8);
+	if (ret != 8)
+		return -EIO;
+
+	return 0;
+}
+
+static const struct rtc_class_ops ds13xx_rtc_ops = {
+	.read_time	= abracon_get_time,
+	.set_time	= abracon_set_time,
+};
+
+static int abracon_probe(struct device_d *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct abracon *abracon;
+	int ret;
+
+	abracon = xzalloc(sizeof(*abracon));
+
+	abracon->client = client;
+
+	abracon->rtc.ops = &ds13xx_rtc_ops;
+	abracon->rtc.dev = dev;
+
+	ret = rtc_register(&abracon->rtc);
+
+	return ret;
+};
+
+static struct platform_device_id abracon_id[] = {
+	{ "ab-rtcmc-32.768khz-eoz9-s3", 0 },
+	{ }
+};
+
+static struct driver_d abracon_driver = {
+	.name	= "rtc-abracon",
+	.probe		= abracon_probe,
+	.id_table	= abracon_id,
+};
+
+static int __init abracon_init(void)
+{
+	return i2c_driver_register(&abracon_driver);
+}
+device_initcall(abracon_init);
\ No newline at end of file
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/7] hwclock command: use format like the Linux tool does
  2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
                   ` (5 preceding siblings ...)
  2015-12-14 11:43 ` [PATCH 7/7] rtc: Add Abracon driver Sascha Hauer
@ 2015-12-14 11:54 ` Fabio Estevam
  2015-12-14 12:02   ` Sascha Hauer
  6 siblings, 1 reply; 9+ messages in thread
From: Fabio Estevam @ 2015-12-14 11:54 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Mon, Dec 14, 2015 at 9:43 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:

> +const char *time_str(struct rtc_time *tm)
> +{
> +       const char *weekdays[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
> +       const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
> +                                "Sep", "Okt", "Nov", "Dec" };

The 'Okt' one looks like German ;-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/7] hwclock command: use format like the Linux tool does
  2015-12-14 11:54 ` [PATCH 1/7] hwclock command: use format like the Linux tool does Fabio Estevam
@ 2015-12-14 12:02   ` Sascha Hauer
  0 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2015-12-14 12:02 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: Barebox List

On Mon, Dec 14, 2015 at 09:54:40AM -0200, Fabio Estevam wrote:
> On Mon, Dec 14, 2015 at 9:43 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> 
> > +const char *time_str(struct rtc_time *tm)
> > +{
> > +       const char *weekdays[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
> > +       const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
> > +                                "Sep", "Okt", "Nov", "Dec" };
> 
> The 'Okt' one looks like German ;-)

Uh, indeed. I hoped nobody would notice ;-)

Fixed, thanks

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-12-14 12:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-14 11:43 [PATCH 1/7] hwclock command: use format like the Linux tool does Sascha Hauer
2015-12-14 11:43 ` [PATCH 2/7] hwclock command: forward return value of rtc_set_time Sascha Hauer
2015-12-14 11:43 ` [PATCH 3/7] rtc: Check time for validity before passing it to the rtc driver Sascha Hauer
2015-12-14 11:43 ` [PATCH 4/7] rtc: Fill in weekdays before setting time Sascha Hauer
2015-12-14 11:43 ` [PATCH 5/7] net: Add SNTP support Sascha Hauer
2015-12-14 11:43 ` [PATCH 6/7] hwclock: Allow to set hwclock from sntp Sascha Hauer
2015-12-14 11:43 ` [PATCH 7/7] rtc: Add Abracon driver Sascha Hauer
2015-12-14 11:54 ` [PATCH 1/7] hwclock command: use format like the Linux tool does Fabio Estevam
2015-12-14 12:02   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox