Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/i2c Use todr_gettime_ymdhms / todr_settime_ymdhms.
details: https://anonhg.NetBSD.org/src/rev/4d32e3471089
branches: trunk
changeset: 466815:4d32e3471089
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Jan 02 19:00:34 2020 +0000
description:
Use todr_gettime_ymdhms / todr_settime_ymdhms.
diffstat:
sys/dev/i2c/r2025.c | 69 +++++++++++++++++++++++++---------------------------
sys/dev/i2c/s390.c | 55 +++++++++--------------------------------
sys/dev/i2c/x1226.c | 44 +++++++++++++--------------------
3 files changed, 63 insertions(+), 105 deletions(-)
diffs (truncated from 348 to 300 lines):
diff -r eb072c3fb0eb -r 4d32e3471089 sys/dev/i2c/r2025.c
--- a/sys/dev/i2c/r2025.c Thu Jan 02 18:57:58 2020 +0000
+++ b/sys/dev/i2c/r2025.c Thu Jan 02 19:00:34 2020 +0000
@@ -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 @@
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 @@
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 @@
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 @@
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) {
diff -r eb072c3fb0eb -r 4d32e3471089 sys/dev/i2c/s390.c
--- a/sys/dev/i2c/s390.c Thu Jan 02 18:57:58 2020 +0000
+++ b/sys/dev/i2c/s390.c Thu Jan 02 19:00:34 2020 +0000
@@ -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 @@
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 @@
}
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 @@
}
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];
/*
diff -r eb072c3fb0eb -r 4d32e3471089 sys/dev/i2c/x1226.c
--- a/sys/dev/i2c/x1226.c Thu Jan 02 18:57:58 2020 +0000
+++ b/sys/dev/i2c/x1226.c Thu Jan 02 19:00:34 2020 +0000
@@ -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 @@
};
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 @@
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 @@
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;
Home |
Main Index |
Thread Index |
Old Index