summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2019-09-07 13:32:37 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2019-09-07 13:32:37 +0000
commitad4c03cf29c0e05d73b3e6723b817e21335d4367 (patch)
tree6cdc4d3c73c8a08727e3e1f17f05226a03fa2540 /sys
parent899512ab5713f678d9d9d477fdf0ff11b185e85c (diff)
Add sfp(4), a driver that allows talking to SFPs connected over
an I2C bus and provides a method to read its pages over the SFP framework. Feedback from dlg@ ok kettenis@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/arm64/conf/GENERIC3
-rw-r--r--sys/arch/arm64/conf/RAMDISK3
-rw-r--r--sys/dev/fdt/files.fdt6
-rw-r--r--sys/dev/fdt/sfp.c109
4 files changed, 118 insertions, 3 deletions
diff --git a/sys/arch/arm64/conf/GENERIC b/sys/arch/arm64/conf/GENERIC
index 49cda0b2612..01154dc6ad9 100644
--- a/sys/arch/arm64/conf/GENERIC
+++ b/sys/arch/arm64/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.123 2019/09/06 09:38:19 patrick Exp $
+# $OpenBSD: GENERIC,v 1.124 2019/09/07 13:32:36 patrick Exp $
#
# GENERIC machine description file
#
@@ -173,6 +173,7 @@ mvrng* at fdt?
mvrtc* at fdt?
mvtemp* at fdt?
mvuart* at fdt?
+sfp* at fdt?
# Rockchip SoCs
rkclock* at fdt? early 1
diff --git a/sys/arch/arm64/conf/RAMDISK b/sys/arch/arm64/conf/RAMDISK
index 49f3b7c99de..5d8fde15ae8 100644
--- a/sys/arch/arm64/conf/RAMDISK
+++ b/sys/arch/arm64/conf/RAMDISK
@@ -1,4 +1,4 @@
-# $OpenBSD: RAMDISK,v 1.101 2019/09/06 09:38:19 patrick Exp $
+# $OpenBSD: RAMDISK,v 1.102 2019/09/07 13:32:36 patrick Exp $
#
# GENERIC machine description file
#
@@ -161,6 +161,7 @@ mvneta* at fdt?
mvrng* at fdt?
mvrtc* at fdt?
mvuart* at fdt?
+sfp* at fdt?
# Rockchip SoCs
rkclock* at fdt? early 1
diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt
index eaa0144f3e5..28390fee6dc 100644
--- a/sys/dev/fdt/files.fdt
+++ b/sys/dev/fdt/files.fdt
@@ -1,4 +1,4 @@
-# $OpenBSD: files.fdt,v 1.91 2019/09/06 08:45:37 patrick Exp $
+# $OpenBSD: files.fdt,v 1.92 2019/09/07 13:32:36 patrick Exp $
#
# Config file and device description for machine-independent FDT code.
# Included by ports that need it.
@@ -353,3 +353,7 @@ file dev/fdt/ssdfb.c ssdfb
device fusbtc
attach fusbtc at i2c
file dev/fdt/fusbtc.c fusbtc
+
+device sfp
+attach sfp at fdt
+file dev/fdt/sfp.c sfp
diff --git a/sys/dev/fdt/sfp.c b/sys/dev/fdt/sfp.c
new file mode 100644
index 00000000000..f0ee6bc8bc4
--- /dev/null
+++ b/sys/dev/fdt/sfp.c
@@ -0,0 +1,109 @@
+/* $OpenBSD: sfp.c,v 1.1 2019/09/07 13:32:36 patrick Exp $ */
+/*
+ * Copyright (c) 2019 Patrick Wildt <patrick@blueri.se>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+
+#include <net/if.h>
+
+#include <machine/bus.h>
+#include <machine/fdt.h>
+
+#include <dev/i2c/i2cvar.h>
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_gpio.h>
+#include <dev/ofw/ofw_misc.h>
+
+struct sfp_softc {
+ struct device sc_dev;
+ i2c_tag_t sc_tag;
+ int sc_node;
+
+ struct sfp_device sc_sd;
+};
+
+int sfp_match(struct device *, void *, void *);
+void sfp_attach(struct device *, struct device *, void *);
+int sfp_detach(struct device *, int);
+
+int sfp_i2c_get_sffpage(void *, struct if_sffpage *);
+
+struct cfattach sfp_ca = {
+ sizeof(struct sfp_softc), sfp_match, sfp_attach, sfp_detach,
+};
+
+struct cfdriver sfp_cd = {
+ NULL, "sfp", DV_DULL
+};
+
+int
+sfp_match(struct device *parent, void *match, void *aux)
+{
+ struct fdt_attach_args *faa = aux;
+
+ return (OF_is_compatible(faa->fa_node, "sff,sfp") ||
+ OF_is_compatible(faa->fa_node, "sff,sfp+"));
+}
+
+void
+sfp_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct sfp_softc *sc = (struct sfp_softc *)self;
+ struct fdt_attach_args *faa = aux;
+
+ sc->sc_node = faa->fa_node;
+ sc->sc_tag = i2c_byphandle(OF_getpropint(sc->sc_node,
+ "i2c-bus", 0));
+
+ if (sc->sc_tag == NULL) {
+ printf(": can't get i2c bus\n");
+ return;
+ }
+
+ printf("\n");
+
+ sc->sc_sd.sd_node = faa->fa_node;
+ sc->sc_sd.sd_cookie = sc;
+ sc->sc_sd.sd_get_sffpage = sfp_i2c_get_sffpage;
+ sfp_register(&sc->sc_sd);
+}
+
+int
+sfp_detach(struct device *self, int flags)
+{
+ return 0;
+}
+
+int
+sfp_i2c_get_sffpage(void *cookie, struct if_sffpage *sff)
+{
+ struct sfp_softc *sc = cookie;
+ uint8_t reg = sff->sff_page;
+
+ iic_acquire_bus(sc->sc_tag, 0);
+ if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
+ sff->sff_addr >> 1, &reg, sizeof(reg),
+ sff->sff_data, sizeof(sff->sff_data), 0)) {
+ printf("%s: cannot read register 0x%x\n",
+ sc->sc_dev.dv_xname, reg);
+ }
+ iic_release_bus(sc->sc_tag, 0);
+
+ return 0;
+}