Module Name:    src
Committed By:   thorpej
Date:           Thu Jan  2 19:00:34 UTC 2020

Modified Files:
        src/sys/dev/i2c: r2025.c s390.c x1226.c

Log Message:
Use todr_gettime_ymdhms / todr_settime_ymdhms.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/r2025.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/s390.c
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/i2c/x1226.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/r2025.c
diff -u src/sys/dev/i2c/r2025.c:1.9 src/sys/dev/i2c/r2025.c:1.10
--- src/sys/dev/i2c/r2025.c:1.9	Thu Jan  2 17:03:05 2020
+++ src/sys/dev/i2c/r2025.c	Thu Jan  2 19:00:34 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: r2025.c,v 1.9 2020/01/02 17:03:05 thorpej Exp $ */
+/* $NetBSD: r2025.c,v 1.10 2020/01/02 19:00:34 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Shigeyuki Fukushima.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: r2025.c,v 1.9 2020/01/02 17:03:05 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: r2025.c,v 1.10 2020/01/02 19:00:34 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -63,8 +63,10 @@ static int	r2025rtc_match(device_t, cfda
 CFATTACH_DECL_NEW(r2025rtc, sizeof(struct r2025rtc_softc),
 	r2025rtc_match, r2025rtc_attach, NULL, NULL);
 
-static int	r2025rtc_gettime(struct todr_chip_handle *, struct timeval *);
-static int	r2025rtc_settime(struct todr_chip_handle *, struct timeval *);
+static int	r2025rtc_gettime_ymdhms(struct todr_chip_handle *,
+					struct clock_ymdhms *);
+static int	r2025rtc_settime_ymdhms(struct todr_chip_handle *,
+					struct clock_ymdhms *);
 static int	r2025rtc_reg_write(struct r2025rtc_softc *, int, uint8_t*, int);
 static int	r2025rtc_reg_read(struct r2025rtc_softc *, int, uint8_t*, int);
 
@@ -94,24 +96,25 @@ r2025rtc_attach(device_t parent, device_
 	sc->sc_dev = self;
 	sc->sc_open = 0;
 	sc->sc_todr.cookie = sc;
-	sc->sc_todr.todr_gettime = r2025rtc_gettime;
-	sc->sc_todr.todr_settime = r2025rtc_settime;
+	sc->sc_todr.todr_gettime = NULL;
+	sc->sc_todr.todr_settime = NULL;
+	sc->sc_todr.todr_gettime_ymdhms = r2025rtc_gettime_ymdhms;
+	sc->sc_todr.todr_settime_ymdhms = r2025rtc_settime_ymdhms;
 	sc->sc_todr.todr_setwen = NULL;
 
 	todr_attach(&sc->sc_todr);
 }
 
 static int
-r2025rtc_gettime(struct todr_chip_handle *ch, struct timeval *tv)
+r2025rtc_gettime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt)
 {
 	struct r2025rtc_softc *sc = ch->cookie;
-	struct clock_ymdhms dt;
 	uint8_t rctrl;
 	uint8_t bcd[R2025_CLK_SIZE];
 	int hour;
 	int error;
 
-	memset(&dt, 0, sizeof(dt));
+	memset(dt, 0, sizeof(*dt));
 
 	if ((error = r2025rtc_reg_read(sc, R2025_REG_CTRL1, &rctrl, 1)) != 0) {
 		aprint_error_dev(sc->sc_dev,
@@ -126,47 +129,41 @@ r2025rtc_gettime(struct todr_chip_handle
 		return error;
 	}
 
-	dt.dt_sec = bcdtobin(bcd[R2025_REG_SEC] & R2025_REG_SEC_MASK);
-	dt.dt_min = bcdtobin(bcd[R2025_REG_MIN] & R2025_REG_MIN_MASK);
+	dt->dt_sec = bcdtobin(bcd[R2025_REG_SEC] & R2025_REG_SEC_MASK);
+	dt->dt_min = bcdtobin(bcd[R2025_REG_MIN] & R2025_REG_MIN_MASK);
 	hour = bcdtobin(bcd[R2025_REG_HOUR] & R2025_REG_HOUR_MASK);
 	if (rctrl & R2025_REG_CTRL1_H1224) {
-		dt.dt_hour = hour;
+		dt->dt_hour = hour;
 	} else {
 		if (hour == 12) {
-			dt.dt_hour = 0;
+			dt->dt_hour = 0;
 		} else if (hour == 32) {
-			dt.dt_hour = 12;
+			dt->dt_hour = 12;
 		} else if (hour > 13) {
-			dt.dt_hour = (hour - 8);
+			dt->dt_hour = (hour - 8);
 		} else { /* (hour < 12) */
-			dt.dt_hour = hour;
+			dt->dt_hour = hour;
 		}
 	}
-	dt.dt_wday = bcdtobin(bcd[R2025_REG_WDAY] & R2025_REG_WDAY_MASK);
-	dt.dt_day = bcdtobin(bcd[R2025_REG_DAY] & R2025_REG_DAY_MASK);
-	dt.dt_mon = bcdtobin(bcd[R2025_REG_MON] & R2025_REG_MON_MASK);
-	dt.dt_year = bcdtobin(bcd[R2025_REG_YEAR] & R2025_REG_YEAR_MASK)
+	dt->dt_wday = bcdtobin(bcd[R2025_REG_WDAY] & R2025_REG_WDAY_MASK);
+	dt->dt_day = bcdtobin(bcd[R2025_REG_DAY] & R2025_REG_DAY_MASK);
+	dt->dt_mon = bcdtobin(bcd[R2025_REG_MON] & R2025_REG_MON_MASK);
+	dt->dt_year = bcdtobin(bcd[R2025_REG_YEAR] & R2025_REG_YEAR_MASK)
 		+ ((bcd[R2025_REG_MON] & R2025_REG_MON_Y1920) ? 2000 : 1900);
 
-	tv->tv_sec = clock_ymdhms_to_secs(&dt);
-	tv->tv_usec = 0;
-
 	return 0;
 }
 
 static int
-r2025rtc_settime(struct todr_chip_handle *ch, struct timeval *tv)
+r2025rtc_settime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt)
 {
 	struct r2025rtc_softc *sc = ch->cookie;
-	struct clock_ymdhms dt;
 	uint8_t rctrl;
 	uint8_t bcd[R2025_CLK_SIZE];
 	int error;
 
-	clock_secs_to_ymdhms(tv->tv_sec, &dt);
-
 	/* Y3K problem */
-	if (dt.dt_year >= 3000) {
+	if (dt->dt_year >= 3000) {
 		aprint_error_dev(sc->sc_dev,
 		    "r2025rtc_settime: "
 		    "RTC does not support year 3000 or over.\n");
@@ -181,14 +178,14 @@ r2025rtc_settime(struct todr_chip_handle
 	rctrl |= R2025_REG_CTRL1_H1224;
 
 	/* setup registers 0x00-0x06 (7 byte) */
-	bcd[R2025_REG_SEC] = bintobcd(dt.dt_sec) & R2025_REG_SEC_MASK;
-	bcd[R2025_REG_MIN] = bintobcd(dt.dt_min) & R2025_REG_MIN_MASK;
-	bcd[R2025_REG_HOUR] = bintobcd(dt.dt_hour) & R2025_REG_HOUR_MASK;
-	bcd[R2025_REG_WDAY] = bintobcd(dt.dt_wday) & R2025_REG_WDAY_MASK;
-	bcd[R2025_REG_DAY] = bintobcd(dt.dt_day) & R2025_REG_DAY_MASK;
-	bcd[R2025_REG_MON] = (bintobcd(dt.dt_mon) & R2025_REG_MON_MASK)
-		| ((dt.dt_year >= 2000) ? R2025_REG_MON_Y1920 : 0);
-	bcd[R2025_REG_YEAR] = bintobcd(dt.dt_year % 100) & R2025_REG_YEAR_MASK;
+	bcd[R2025_REG_SEC] = bintobcd(dt->dt_sec) & R2025_REG_SEC_MASK;
+	bcd[R2025_REG_MIN] = bintobcd(dt->dt_min) & R2025_REG_MIN_MASK;
+	bcd[R2025_REG_HOUR] = bintobcd(dt->dt_hour) & R2025_REG_HOUR_MASK;
+	bcd[R2025_REG_WDAY] = bintobcd(dt->dt_wday) & R2025_REG_WDAY_MASK;
+	bcd[R2025_REG_DAY] = bintobcd(dt->dt_day) & R2025_REG_DAY_MASK;
+	bcd[R2025_REG_MON] = (bintobcd(dt->dt_mon) & R2025_REG_MON_MASK)
+		| ((dt->dt_year >= 2000) ? R2025_REG_MON_Y1920 : 0);
+	bcd[R2025_REG_YEAR] = bintobcd(dt->dt_year % 100) & R2025_REG_YEAR_MASK;
 
 	/* Write RTC register */
 	if ((error = r2025rtc_reg_write(sc, R2025_REG_CTRL1, &rctrl, 1)) != 0) {

Index: src/sys/dev/i2c/s390.c
diff -u src/sys/dev/i2c/s390.c:1.5 src/sys/dev/i2c/s390.c:1.6
--- src/sys/dev/i2c/s390.c:1.5	Thu Jan  2 17:26:37 2020
+++ src/sys/dev/i2c/s390.c	Thu Jan  2 19:00:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: s390.c,v 1.5 2020/01/02 17:26:37 thorpej Exp $	*/
+/*	$NetBSD: s390.c,v 1.6 2020/01/02 19:00:34 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2011 Frank Wille.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: s390.c,v 1.5 2020/01/02 17:26:37 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: s390.c,v 1.6 2020/01/02 19:00:34 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -54,10 +54,10 @@ static void s390rtc_attach(device_t, dev
 CFATTACH_DECL_NEW(s390rtc, sizeof(struct s390rtc_softc),
     s390rtc_match, s390rtc_attach, NULL, NULL);
 
-static int s390rtc_gettime(struct todr_chip_handle *, struct timeval *);
-static int s390rtc_settime(struct todr_chip_handle *, struct timeval *);
-static int s390rtc_clock_read(struct s390rtc_softc *, struct clock_ymdhms *);
-static int s390rtc_clock_write(struct s390rtc_softc *, struct clock_ymdhms *);
+static int s390rtc_gettime_ymdhms(struct todr_chip_handle *,
+				  struct clock_ymdhms *);
+static int s390rtc_settime_ymdhms(struct todr_chip_handle *,
+				  struct clock_ymdhms *);
 static int s390rtc_read(struct s390rtc_softc *, int, uint8_t *, size_t);
 static int s390rtc_write(struct s390rtc_softc *, int, uint8_t *, size_t);
 static uint8_t bitreverse(uint8_t);
@@ -111,48 +111,18 @@ s390rtc_attach(device_t parent, device_t
 	}
 
 	sc->sc_todr.cookie = sc;
-	sc->sc_todr.todr_gettime = s390rtc_gettime;
-	sc->sc_todr.todr_settime = s390rtc_settime;
+	sc->sc_todr.todr_gettime = NULL;
+	sc->sc_todr.todr_settime = NULL;
+	sc->sc_todr.todr_gettime_ymdhms = s390rtc_gettime_ymdhms;
+	sc->sc_todr.todr_settime_ymdhms = s390rtc_settime_ymdhms;
 	sc->sc_todr.todr_setwen = NULL;
 	todr_attach(&sc->sc_todr);
 }
 
 static int
-s390rtc_gettime(struct todr_chip_handle *ch, struct timeval *tv)
+s390rtc_gettime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt)
 {
 	struct s390rtc_softc *sc = ch->cookie;
-	struct clock_ymdhms dt;
-	int error;
-
-	memset(&dt, 0, sizeof(dt));
-
-	if ((error = s390rtc_clock_read(sc, &dt)) != 0)
-		return error;
-
-	tv->tv_sec = clock_ymdhms_to_secs(&dt);
-	tv->tv_usec = 0;
-
-	return 0;
-}
-
-static int
-s390rtc_settime(struct todr_chip_handle *ch, struct timeval *tv)
-{
-	struct s390rtc_softc *sc = ch->cookie;
-	struct clock_ymdhms dt;
-	int error;
-
-	clock_secs_to_ymdhms(tv->tv_sec, &dt);
-
-	if ((error = s390rtc_clock_write(sc, &dt)) != 0)
-		return error;
-
-	return 0;
-}
-
-static int
-s390rtc_clock_read(struct s390rtc_softc *sc, struct clock_ymdhms *dt)
-{
 	uint8_t bcd[S390_RT1_NBYTES];
 	int error;
 
@@ -174,8 +144,9 @@ s390rtc_clock_read(struct s390rtc_softc 
 }
 
 static int
-s390rtc_clock_write(struct s390rtc_softc *sc, struct clock_ymdhms *dt)
+s390rtc_settime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt)
 {
+	struct s390rtc_softc *sc = ch->cookie;
 	uint8_t bcd[S390_RT1_NBYTES];
 
 	/*

Index: src/sys/dev/i2c/x1226.c
diff -u src/sys/dev/i2c/x1226.c:1.22 src/sys/dev/i2c/x1226.c:1.23
--- src/sys/dev/i2c/x1226.c:1.22	Thu Jan  2 17:40:27 2020
+++ src/sys/dev/i2c/x1226.c	Thu Jan  2 19:00:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: x1226.c,v 1.22 2020/01/02 17:40:27 thorpej Exp $	*/
+/*	$NetBSD: x1226.c,v 1.23 2020/01/02 19:00:34 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Shigeyuki Fukushima.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x1226.c,v 1.22 2020/01/02 17:40:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x1226.c,v 1.23 2020/01/02 19:00:34 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -89,9 +89,10 @@ const struct cdevsw xrtc_cdevsw = {
 };
 
 static int xrtc_clock_read(struct xrtc_softc *, struct clock_ymdhms *);
-static int xrtc_clock_write(struct xrtc_softc *, struct clock_ymdhms *);
-static int xrtc_gettime(struct todr_chip_handle *, struct timeval *);
-static int xrtc_settime(struct todr_chip_handle *, struct timeval *);
+static int xrtc_gettime_ymdhms(struct todr_chip_handle *,
+			       struct clock_ymdhms *);
+static int xrtc_settime_ymdhms(struct todr_chip_handle *,
+			       struct clock_ymdhms *);
 
 /*
  * xrtc_match()
@@ -125,8 +126,10 @@ xrtc_attach(device_t parent, device_t se
 	sc->sc_dev = self;
 	sc->sc_open = 0;
 	sc->sc_todr.cookie = sc;
-	sc->sc_todr.todr_gettime = xrtc_gettime;
-	sc->sc_todr.todr_settime = xrtc_settime;
+	sc->sc_todr.todr_gettime = NULL;
+	sc->sc_todr.todr_settime = NULL;
+	sc->sc_todr.todr_gettime_ymdhms = xrtc_gettime_ymdhms;
+	sc->sc_todr.todr_settime_ymdhms = xrtc_settime_ymdhms;
 	sc->sc_todr.todr_setwen = NULL;
 
 	todr_attach(&sc->sc_todr);
@@ -247,42 +250,28 @@ xrtc_write(dev_t dev, struct uio *uio, i
 
 
 static int
-xrtc_gettime(struct todr_chip_handle *ch, struct timeval *tv)
+xrtc_gettime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt)
 {
 	struct xrtc_softc *sc = ch->cookie;
-	struct clock_ymdhms dt, check;
+	struct clock_ymdhms check;
 	int retries;
 	int error;
 
-	memset(&dt, 0, sizeof(dt));
+	memset(dt, 0, sizeof(*dt));
 	memset(&check, 0, sizeof(check));
 
 	retries = 5;
 	do {
-		if ((error = xrtc_clock_read(sc, &dt)) == 0)
+		if ((error = xrtc_clock_read(sc, dt)) == 0)
 			error = xrtc_clock_read(sc, &check);
 		if (error)
 			return error;
-	} while (memcmp(&dt, &check, sizeof(check)) != 0 && --retries);
-
-	tv->tv_sec = clock_ymdhms_to_secs(&dt);
-	tv->tv_usec = 0;
+	} while (memcmp(dt, &check, sizeof(check)) != 0 && --retries);
 
 	return (0);
 }
 
 static int
-xrtc_settime(struct todr_chip_handle *ch, struct timeval *tv)
-{
-	struct xrtc_softc *sc = ch->cookie;
-	struct clock_ymdhms dt;
-
-	clock_secs_to_ymdhms(tv->tv_sec, &dt);
-
-	return xrtc_clock_write(sc, &dt);
-}
-
-static int
 xrtc_clock_read(struct xrtc_softc *sc, struct clock_ymdhms *dt)
 {
 	int i = 0;
@@ -348,8 +337,9 @@ xrtc_clock_read(struct xrtc_softc *sc, s
 }
 
 static int
-xrtc_clock_write(struct xrtc_softc *sc, struct clock_ymdhms *dt)
+xrtc_settime_ymdhms(struct todr_chip_handle *ch, struct clock_ymdhms *dt)
 {
+	struct xrtc_softc *sc = ch->cookie;
 	int i = 0, addr;
 	u_int8_t bcd[X1226_REG_RTC_SIZE], cmdbuf[3];
 	int error, error2;

Reply via email to