git: 26a0a4035e51 - main - superio: Add superio_ldn_read and superio_ldn_write

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sat, 01 Jul 2023 17:20:42 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=26a0a4035e517d633b96cbcfe6b75bddec553ec3

commit 26a0a4035e517d633b96cbcfe6b75bddec553ec3
Author:     Stéphane Rochoy <stephane.rochoy@stormshield.eu>
AuthorDate: 2023-07-01 17:19:44 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-07-01 17:19:49 +0000

    superio: Add superio_ldn_read and superio_ldn_write
    
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/719
---
 sys/dev/superio/superio.c | 38 ++++++++++++++++++++++++++------------
 sys/dev/superio/superio.h |  2 ++
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/sys/dev/superio/superio.c b/sys/dev/superio/superio.c
index 6f2e44450681..1e4782277c0e 100644
--- a/sys/dev/superio/superio.c
+++ b/sys/dev/superio/superio.c
@@ -564,7 +564,7 @@ superio_detect(device_t dev, bool claim, struct siosc *sc)
 	    sc->vendor == SUPERIO_VENDOR_FINTEK,
 	    ("Only ITE, Nuvoton and Fintek SuperIO-s are supported"));
 	sc->ldn_reg = 0x07;
-	sc->enable_reg = 0x30;
+	sc->enable_reg = 0x30;	/* FIXME enable_reg not used by nctgpio(4). */
 	sc->current_ldn = 0xff;	/* no device should have this */
 
 	if (superio_table[i].descr != NULL) {
@@ -877,30 +877,44 @@ superio_revid(device_t dev)
 	return (sc->revid);
 }
 
+uint8_t
+superio_ldn_read(device_t dev, uint8_t ldn, uint8_t reg)
+{
+	device_t      sio_dev = device_get_parent(dev);
+	struct siosc *sc      = device_get_softc(sio_dev);
+	uint8_t       v;
+
+	sio_conf_enter(sc);
+	v = sio_ldn_read(sc, ldn, reg);
+	sio_conf_exit(sc);
+	return (v);
+}
+
 uint8_t
 superio_read(device_t dev, uint8_t reg)
 {
-	device_t sio_dev = device_get_parent(dev);
-	struct siosc *sc = device_get_softc(sio_dev);
 	struct superio_devinfo *dinfo = device_get_ivars(dev);
-	uint8_t v;
+
+	return (superio_ldn_read(dev, dinfo->ldn, reg));
+}
+
+void
+superio_ldn_write(device_t dev, uint8_t ldn, uint8_t reg, uint8_t val)
+{
+	device_t      sio_dev = device_get_parent(dev);
+	struct siosc *sc      = device_get_softc(sio_dev);
 
 	sio_conf_enter(sc);
-	v = sio_ldn_read(sc, dinfo->ldn, reg);
+	sio_ldn_write(sc, ldn, reg, val);
 	sio_conf_exit(sc);
-	return (v);
 }
 
 void
 superio_write(device_t dev, uint8_t reg, uint8_t val)
 {
-	device_t sio_dev = device_get_parent(dev);
-	struct siosc *sc = device_get_softc(sio_dev);
 	struct superio_devinfo *dinfo = device_get_ivars(dev);
 
-	sio_conf_enter(sc);
-	sio_ldn_write(sc, dinfo->ldn, reg, val);
-	sio_conf_exit(sc);
+	return (superio_ldn_write(dev, dinfo->ldn, reg, val));
 }
 
 bool
@@ -915,7 +929,7 @@ superio_dev_enabled(device_t dev, uint8_t mask)
 	if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7)
 		return (true);
 
-	v = superio_read(dev, sc->enable_reg);
+	v = superio_read(dev, sc->enable_reg); /* FIXME enable_reg not used by nctgpio(4). */
 	return ((v & mask) != 0);
 }
 
diff --git a/sys/dev/superio/superio.h b/sys/dev/superio/superio.h
index 993f95fc9fbb..997bcb2c6efd 100644
--- a/sys/dev/superio/superio.h
+++ b/sys/dev/superio/superio.h
@@ -50,7 +50,9 @@ superio_vendor_t superio_vendor(device_t dev);
 uint16_t superio_devid(device_t dev);
 uint8_t superio_revid(device_t dev);
 uint8_t superio_read(device_t dev, uint8_t reg);
+uint8_t superio_ldn_read(device_t dev, uint8_t ldn, uint8_t reg);
 void superio_write(device_t dev, uint8_t reg, uint8_t val);
+void superio_ldn_write(device_t dev, uint8_t ldn, uint8_t reg, uint8_t val);
 bool superio_dev_enabled(device_t dev, uint8_t mask);
 void superio_dev_enable(device_t dev, uint8_t mask);
 void superio_dev_disable(device_t dev, uint8_t mask);