Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/i2c - No need to use I2C_F_POLL here.
details: https://anonhg.NetBSD.org/src/rev/e979f909e3ee
branches: trunk
changeset: 847735:e979f909e3ee
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Jan 02 17:17:36 2020 +0000
description:
- No need to use I2C_F_POLL here.
- Correctly propagate errors up the stack.
diffstat:
sys/dev/i2c/rs5c372.c | 71 +++++++++++++++++++++++++-------------------------
sys/dev/i2c/s390.c | 66 +++++++++++++++++++++++++----------------------
2 files changed, 71 insertions(+), 66 deletions(-)
diffs (truncated from 340 to 300 lines):
diff -r ef6cca66c229 -r e979f909e3ee sys/dev/i2c/rs5c372.c
--- a/sys/dev/i2c/rs5c372.c Thu Jan 02 17:09:59 2020 +0000
+++ b/sys/dev/i2c/rs5c372.c Thu Jan 02 17:17:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rs5c372.c,v 1.15 2018/06/16 21:22:13 thorpej Exp $ */
+/* $NetBSD: rs5c372.c,v 1.16 2020/01/02 17:17:36 thorpej Exp $ */
/*-
* Copyright (C) 2005 NONAKA Kimihiro <nonaka%netbsd.org@localhost>
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rs5c372.c,v 1.15 2018/06/16 21:22:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rs5c372.c,v 1.16 2020/01/02 17:17:36 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -55,7 +55,7 @@
CFATTACH_DECL_NEW(rs5c372rtc, sizeof(struct rs5c372rtc_softc),
rs5c372rtc_match, rs5c372rtc_attach, NULL, NULL);
-static void rs5c372rtc_reg_write(struct rs5c372rtc_softc *, int, uint8_t);
+static int rs5c372rtc_reg_write(struct rs5c372rtc_softc *, int, uint8_t);
static int rs5c372rtc_clock_read(struct rs5c372rtc_softc *, struct clock_ymdhms *);
static int rs5c372rtc_clock_write(struct rs5c372rtc_softc *, struct clock_ymdhms *);
static int rs5c372rtc_gettime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
@@ -106,10 +106,7 @@
{
struct rs5c372rtc_softc *sc = ch->cookie;
- if (rs5c372rtc_clock_read(sc, dt) == 0)
- return (-1);
-
- return (0);
+ return rs5c372rtc_clock_read(sc, dt);
}
static int
@@ -117,35 +114,36 @@
{
struct rs5c372rtc_softc *sc = ch->cookie;
- if (rs5c372rtc_clock_write(sc, dt) == 0)
- return (-1);
-
- return (0);
+ return rs5c372rtc_clock_write(sc, dt);
}
-static void
+static int
rs5c372rtc_reg_write(struct rs5c372rtc_softc *sc, int reg, uint8_t val)
{
uint8_t cmdbuf[2];
+ int error;
- if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) {
+ if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) {
aprint_error_dev(sc->sc_dev,
"rs5c372rtc_reg_write: failed to acquire I2C bus\n");
- return;
+ return error;
}
reg &= 0xf;
cmdbuf[0] = (reg << 4);
cmdbuf[1] = val;
- if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address,
- cmdbuf, 1, &cmdbuf[1], 1, I2C_F_POLL)) {
- iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
+ sc->sc_address, cmdbuf, 1, &cmdbuf[1], 1,
+ 0)) != 0) {
+ iic_release_bus(sc->sc_tag, 0);
aprint_error_dev(sc->sc_dev,
"rs5c372rtc_reg_write: failed to write reg%d\n", reg);
- return;
+ return error;
}
- iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ iic_release_bus(sc->sc_tag, 0);
+
+ return 0;
}
static int
@@ -153,23 +151,24 @@
{
uint8_t bcd[RS5C372_NRTC_REGS];
uint8_t cmdbuf[1];
+ int error;
- if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) {
+ if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) {
aprint_error_dev(sc->sc_dev,
"rs5c372rtc_clock_read: failed to acquire I2C bus\n");
- return (0);
+ return (error);
}
cmdbuf[0] = (RS5C372_SECONDS << 4);
- if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address,
- cmdbuf, 1, bcd, RS5C372_NRTC_REGS, I2C_F_POLL)) {
- iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_address,
+ cmdbuf, 1, bcd, RS5C372_NRTC_REGS, 0)) != 0) {
+ iic_release_bus(sc->sc_tag, 0);
aprint_error_dev(sc->sc_dev,
"rs5c372rtc_clock_read: failed to read rtc\n");
- return (0);
+ return (error);
}
- iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ iic_release_bus(sc->sc_tag, 0);
/*
* Convert the RS5C372's register values into something useable
@@ -181,7 +180,7 @@
dt->dt_mon = bcdtobin(bcd[RS5C372_MONTH] & RS5C372_MONTH_MASK);
dt->dt_year = bcdtobin(bcd[RS5C372_YEAR]) + 2000;
- return (1);
+ return (0);
}
static int
@@ -189,6 +188,7 @@
{
uint8_t bcd[RS5C372_NRTC_REGS];
uint8_t cmdbuf[1];
+ int error;
/*
* Convert our time representation into something the RS5C372
@@ -202,22 +202,23 @@
bcd[RS5C372_MONTH] = bintobcd(dt->dt_mon);
bcd[RS5C372_YEAR] = bintobcd(dt->dt_year % 100);
- if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) {
+ if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) {
aprint_error_dev(sc->sc_dev, "rs5c372rtc_clock_write: failed to "
"acquire I2C bus\n");
- return (0);
+ return (error);
}
cmdbuf[0] = (RS5C372_SECONDS << 4);
- if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_address,
- cmdbuf, 1, bcd, RS5C372_NRTC_REGS, I2C_F_POLL)) {
- iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
+ sc->sc_address, cmdbuf, 1, bcd,
+ RS5C372_NRTC_REGS, 0)) != 0) {
+ iic_release_bus(sc->sc_tag, 0);
aprint_error_dev(sc->sc_dev,
"rs5c372rtc_clock_write: failed to write rtc\n");
- return (0);
+ return (error);
}
- iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ iic_release_bus(sc->sc_tag, 0);
- return (1);
+ return (0);
}
diff -r ef6cca66c229 -r e979f909e3ee sys/dev/i2c/s390.c
--- a/sys/dev/i2c/s390.c Thu Jan 02 17:09:59 2020 +0000
+++ b/sys/dev/i2c/s390.c Thu Jan 02 17:17:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: s390.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $ */
+/* $NetBSD: s390.c,v 1.5 2020/01/02 17:26:37 thorpej Exp $ */
/*-
* Copyright (c) 2011 Frank Wille.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: s390.c,v 1.4 2018/06/16 21:22:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: s390.c,v 1.5 2020/01/02 17:26:37 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -93,20 +93,20 @@
sc->sc_dev = self;
/* Reset the chip and turn on 24h mode, after power-off or battery. */
- if (!s390rtc_read(sc, S390_STATUS1, reg, sizeof(reg)))
+ if (s390rtc_read(sc, S390_STATUS1, reg, sizeof(reg)))
return;
if (reg[0] & (S390_ST1_POC | S390_ST1_BLD)) {
reg[0] |= S390_ST1_24H | S390_ST1_RESET;
- if (!s390rtc_write(sc, S390_STATUS1, reg, sizeof(reg)))
+ if (s390rtc_write(sc, S390_STATUS1, reg, sizeof(reg)))
return;
}
/* Disable the test mode, when enabled. */
- if (!s390rtc_read(sc, S390_STATUS2, reg, sizeof(reg)))
+ if (s390rtc_read(sc, S390_STATUS2, reg, sizeof(reg)))
return;
if ((reg[0] & S390_ST2_TEST)) {
reg[0] &= ~S390_ST2_TEST;
- if (!s390rtc_write(sc, S390_STATUS2, reg, sizeof(reg)))
+ if (s390rtc_write(sc, S390_STATUS2, reg, sizeof(reg)))
return;
}
@@ -122,11 +122,12 @@
{
struct s390rtc_softc *sc = ch->cookie;
struct clock_ymdhms dt;
+ int error;
memset(&dt, 0, sizeof(dt));
- if (!s390rtc_clock_read(sc, &dt))
- return -1;
+ if ((error = s390rtc_clock_read(sc, &dt)) != 0)
+ return error;
tv->tv_sec = clock_ymdhms_to_secs(&dt);
tv->tv_usec = 0;
@@ -139,11 +140,12 @@
{
struct s390rtc_softc *sc = ch->cookie;
struct clock_ymdhms dt;
+ int error;
clock_secs_to_ymdhms(tv->tv_sec, &dt);
- if (!s390rtc_clock_write(sc, &dt))
- return -1;
+ if ((error = s390rtc_clock_write(sc, &dt)) != 0)
+ return error;
return 0;
}
@@ -152,9 +154,11 @@
s390rtc_clock_read(struct s390rtc_softc *sc, struct clock_ymdhms *dt)
{
uint8_t bcd[S390_RT1_NBYTES];
+ int error;
- if (!s390rtc_read(sc, S390_REALTIME1, bcd, S390_RT1_NBYTES))
- return 0;
+ if ((error = s390rtc_read(sc, S390_REALTIME1, bcd,
+ S390_RT1_NBYTES)) != 0)
+ return error;
/*
* Convert the register values into something useable.
@@ -166,7 +170,7 @@
dt->dt_mon = bcdtobin(bcd[S390_RT1_MONTH]);
dt->dt_year = bcdtobin(bcd[S390_RT1_YEAR]) + 2000;
- return 1;
+ return 0;
}
static int
@@ -192,56 +196,56 @@
static int
s390rtc_read(struct s390rtc_softc *sc, int reg, uint8_t *buf, size_t len)
{
- int i;
+ int i, error;
- if (iic_acquire_bus(sc->sc_tag, I2C_F_POLL)) {
+ if ((error = iic_acquire_bus(sc->sc_tag, 0)) != 0) {
aprint_error_dev(sc->sc_dev,
"%s: failed to acquire I2C bus\n", __func__);
- return 0;
+ return error;
}
- if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr + reg,
- NULL, 0, buf, len, I2C_F_POLL)) {
- iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
+ sc->sc_addr + reg, NULL, 0, buf, len, 0)) != 0) {
+ iic_release_bus(sc->sc_tag, 0);
aprint_error_dev(sc->sc_dev,
"%s: failed to read reg%d\n", __func__, reg);
- return 0;
+ return error;
}
- iic_release_bus(sc->sc_tag, I2C_F_POLL);
+ iic_release_bus(sc->sc_tag, 0);
/* this chip returns each byte in reverse order */
for (i = 0; i < len; i++)
buf[i] = bitreverse(buf[i]);
- return 1;
Home |
Main Index |
Thread Index |
Old Index