diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2020-09-29 13:59:23 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2020-09-29 13:59:23 +0000 |
commit | 3e304545f328dbfcb67df5f376eb13de8f7d229e (patch) | |
tree | 73c72b6ab1e1e804cf43610233a904f9d31f791e | |
parent | f1c05d6687a29b2e43319255eff41d287246f81e (diff) |
Add support for the PCA9546 I2C switch to pcamux(4). In comparison to
PCA9548, this variant supports only 4 instead of 8 channels.
ok kettenis@
-rw-r--r-- | share/man/man4/iic.4 | 6 | ||||
-rw-r--r-- | share/man/man4/pcamux.4 | 8 | ||||
-rw-r--r-- | sys/dev/i2c/pca9548.c | 19 |
3 files changed, 21 insertions, 12 deletions
diff --git a/share/man/man4/iic.4 b/share/man/man4/iic.4 index bc98894f559..b5c3f81db2b 100644 --- a/share/man/man4/iic.4 +++ b/share/man/man4/iic.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: iic.4,v 1.112 2020/06/18 20:39:28 jmc Exp $ +.\" $OpenBSD: iic.4,v 1.113 2020/09/29 13:59:22 patrick Exp $ .\" .\" Copyright (c) 2004, 2006 Alexander Yurchenko <grange@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 18 2020 $ +.Dd $Mdocdate: September 29 2020 $ .Dt IIC 4 .Os .Sh NAME @@ -220,7 +220,7 @@ Philips PCA955[4567] GPIO controller .It Xr pcaled 4 Philips PCA9532/9552 GPIO LED dimmer .It Xr pcamux 4 -Philips PCA9548 I2C switch +Philips PCA954[68] I2C switch .It Xr pcfadc 4 Philips PCF8591 temperature sensor .It Xr pcfrtc 4 diff --git a/share/man/man4/pcamux.4 b/share/man/man4/pcamux.4 index 2ff2b1fc511..82eda7cc9f2 100644 --- a/share/man/man4/pcamux.4 +++ b/share/man/man4/pcamux.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pcamux.4,v 1.2 2020/06/18 20:39:28 jmc Exp $ +.\" $OpenBSD: pcamux.4,v 1.3 2020/09/29 13:59:22 patrick Exp $ .\" .\" Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org> .\" @@ -14,19 +14,19 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 18 2020 $ +.Dd $Mdocdate: September 29 2020 $ .Dt PCAMUX 4 .Os .Sh NAME .Nm pcamux -.Nd Philips PCA9548 I2C switch +.Nd Philips PCA954[68] I2C switch .Sh SYNOPSIS .Cd "pcamux* at iic?" .Cd "iic* at pcamux?" .Sh DESCRIPTION The .Nm -driver provides support for the Philips PCA9548 I2C switch, +driver provides support for the Philips PCA954[68] I2C switch, which is used with the .Xr iic 4 framework. diff --git a/sys/dev/i2c/pca9548.c b/sys/dev/i2c/pca9548.c index 1fe6328f5c2..f4320a9f985 100644 --- a/sys/dev/i2c/pca9548.c +++ b/sys/dev/i2c/pca9548.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pca9548.c,v 1.2 2020/09/29 13:50:54 patrick Exp $ */ +/* $OpenBSD: pca9548.c,v 1.3 2020/09/29 13:59:22 patrick Exp $ */ /* * Copyright (c) 2020 Mark Kettenis @@ -28,7 +28,9 @@ #include <dev/ofw/openfirm.h> #include <dev/ofw/ofw_misc.h> +#define PCA9546_NUM_CHANNELS 4 #define PCA9548_NUM_CHANNELS 8 +#define PCAMUX_MAX_CHANNELS 8 struct pcamux_bus { struct pcamux_softc *pb_sc; @@ -45,7 +47,8 @@ struct pcamux_softc { int sc_node; int sc_channel; - struct pcamux_bus sc_bus[PCA9548_NUM_CHANNELS]; + int sc_nchannel; + struct pcamux_bus sc_bus[PCAMUX_MAX_CHANNELS]; struct rwlock sc_lock; }; @@ -71,7 +74,8 @@ pcamux_match(struct device *parent, void *match, void *aux) { struct i2c_attach_args *ia = aux; - if (strcmp(ia->ia_name, "nxp,pca9548") == 0) + if (strcmp(ia->ia_name, "nxp,pca9546") == 0 || + strcmp(ia->ia_name, "nxp,pca9548") == 0) return (1); return (0); } @@ -90,6 +94,11 @@ pcamux_attach(struct device *parent, struct device *self, void *aux) sc->sc_channel = -1; /* unknown */ rw_init(&sc->sc_lock, sc->sc_dev.dv_xname); + if (strcmp(ia->ia_name, "nxp,pca9546") == 0) + sc->sc_nchannel = 4; + else if (strcmp(ia->ia_name, "nxp,pca9548") == 0) + sc->sc_nchannel = 8; + printf("\n"); for (node = OF_child(node); node; node = OF_peer(node)) { @@ -98,7 +107,7 @@ pcamux_attach(struct device *parent, struct device *self, void *aux) uint32_t channel; channel = OF_getpropint(node, "reg", -1); - if (channel >= PCA9548_NUM_CHANNELS) + if (channel >= sc->sc_nchannel) continue; pb = &sc->sc_bus[channel]; @@ -131,7 +140,7 @@ pcamux_set_channel(struct pcamux_softc *sc, int channel, int flags) uint8_t data; int error; - if (channel < -1 || channel >= PCA9548_NUM_CHANNELS) + if (channel < -1 || channel >= sc->sc_nchannel) return ENXIO; if (sc->sc_channel == channel) |