Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178372488
D60060.1796607720.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
D60060.1796607720.diff
View Options
Index: sys/dev/iicbus/mux/iicmux.h
===================================================================
--- sys/dev/iicbus/mux/iicmux.h
+++ sys/dev/iicbus/mux/iicmux.h
@@ -55,6 +55,12 @@
#ifdef FDT
phandle_t childnodes[IICMUX_MAX_BUSES]; /* Child bus fdt nodes. */
#endif
+ /*
+ * Child bus ACPI handles (ACPI_HANDLE is void *). Kept unconditional
+ * so every mux chip driver sees the same struct iicmux_softc layout
+ * without needing opt_acpi.h or ACPICA headers.
+ */
+ void *childhandles[IICMUX_MAX_BUSES];
};
DECLARE_CLASS(iicmux_driver);
@@ -64,10 +70,10 @@
*
* The iicmux_attach() function initializes the core driver's portion of the
* softc, and creates child iicbus instances for any children it can identify
- * using hints and FDT data. If a chip driver does its own device_add_child()
- * calls to add other downstream buses that participate in the mux switching, it
- * must call iicmux_add_child() to inform the core driver of the downstream
- * busidx<->device_t relationship.
+ * using hints, FDT, or ACPI data. If a chip driver does its own
+ * device_add_child() calls to add other downstream buses that participate in
+ * the mux switching, it must call iicmux_add_child() to inform the core driver
+ * of the downstream busidx<->device_t relationship.
*/
int iicmux_add_child(device_t dev, device_t child, int busidx);
int iicmux_attach(device_t dev, device_t busdev, int numbuses);
Index: sys/dev/iicbus/mux/iicmux.c
===================================================================
--- sys/dev/iicbus/mux/iicmux.c
+++ sys/dev/iicbus/mux/iicmux.c
@@ -26,6 +26,7 @@
*/
#include <sys/cdefs.h>
+#include "opt_acpi.h"
#include "opt_platform.h"
#include <sys/param.h>
@@ -40,6 +41,11 @@
#include <dev/ofw/openfirm.h>
#endif
+#ifdef DEV_ACPI
+#include <contrib/dev/acpica/include/acpi.h>
+#include <dev/acpica/acpivar.h>
+#endif
+
#include <dev/iicbus/iiconf.h>
#include "iicbus_if.h"
#include "iicmux_if.h"
@@ -139,7 +145,34 @@
if (sc->childdevs[i] == child)
return (sc->childnodes[i]);
}
- return (0); /* null handle */
+ return (-1); /* no node */
+}
+#endif
+
+#ifdef DEV_ACPI
+static int
+iicmux_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
+{
+ struct iicmux_softc *sc = device_get_softc(dev);
+ int i;
+
+ /*
+ * Answer ACPI_IVAR_HANDLE for our child buses so that acpi_iicbus(4)
+ * attaches to each channel's own namespace scope. Answering with a
+ * NULL handle (e.g. on the generic fallback path) is distinct from
+ * declining: it tells acpi_iicbus(4) this channel has no ACPI scope
+ * of its own rather than falling back to the mux's handle.
+ */
+ if (which == ACPI_IVAR_HANDLE) {
+ for (i = 0; i <= sc->maxbus; ++i) {
+ if (sc->childdevs[i] != child)
+ continue;
+ *result = (uintptr_t)sc->childhandles[i];
+ return (0);
+ }
+ return (ENOENT);
+ }
+ return (bus_generic_read_ivar(dev, child, which, result));
}
#endif
@@ -248,54 +281,125 @@
/*
* Find our FDT node. Child nodes within our node will become our
- * iicbus children.
+ * iicbus children. On a kernel built with both FDT and ACPI (or on
+ * a hinted device), ofw_bus_get_node() answers -1 when there is no
+ * OFW node; skip the FDT walk in that case.
*/
- if((node = ofw_bus_get_node(sc->dev)) == 0) {
- device_printf(sc->dev, "cannot find FDT node\n");
- return (ENOENT);
- }
+ node = ofw_bus_get_node(sc->dev);
+ if (node > 0) {
+ /*
+ * First we have to see if there is a child node named
+ * "i2c-mux". If it exists, all children of that node are
+ * buses, else all children of the device node are buses.
+ */
+ if ((parent = ofw_bus_find_child(node, "i2c-mux")) == 0)
+ parent = node;
+
+ /*
+ * Attach the children represented in the device tree.
+ */
+ for (child = OF_child(parent); child != 0;
+ child = OF_peer(child)) {
+ if (OF_getencprop(child, "reg", &idx,
+ sizeof(idx)) == -1) {
+ device_printf(sc->dev,
+ "child bus missing required 'reg' "
+ "property\n");
+ continue;
+ }
+ if (idx >= sc->numbuses) {
+ device_printf(sc->dev,
+ "child bus 'reg' property %d exceeds the "
+ "number of buses supported by the device "
+ "(%d)\n", idx, sc->numbuses);
+ continue;
+ }
+ sc->childdevs[idx] = device_add_child(sc->dev,
+ "iicbus", DEVICE_UNIT_ANY);
+ sc->childnodes[idx] = child;
+ if (sc->maxbus < (int)idx)
+ sc->maxbus = idx;
+ }
- /*
- * First we have to see if there is a child node named "i2c-mux". If it
- * exists, all children of that node are buses, else all children of the
- * device node are buses.
- */
- if ((parent = ofw_bus_find_child(node, "i2c-mux")) == 0)
- parent = node;
+ /* If we configured anything using FDT data, we're done. */
+ if (sc->maxbus >= 0)
+ return (0);
+ }
+#endif /* FDT */
- /*
- * Attach the children represented in the device tree.
- */
- for (child = OF_child(parent); child != 0; child = OF_peer(child)) {
- if (OF_getencprop(child, "reg", &idx, sizeof(idx)) == -1) {
- device_printf(sc->dev,
- "child bus missing required 'reg' property\n");
- continue;
- }
- if (idx >= sc->numbuses) {
- device_printf(sc->dev,
- "child bus 'reg' property %d exceeds the number "
- "of buses supported by the device (%d)\n",
- idx, sc->numbuses);
- continue;
+#ifdef DEV_ACPI
+ {
+ ACPI_HANDLE handle, achild;
+ UINT32 adr, sta;
+
+ /*
+ * Mirror the FDT path for an ACPI-described mux: each
+ * downstream channel firmware describes is an immediate child
+ * Device node whose _ADR gives the channel index. Create an
+ * iicbus child only for described, present channels; if none
+ * are described, fall through to the generic path below.
+ */
+ handle = acpi_get_handle(sc->dev);
+ if (handle != NULL) {
+ achild = NULL;
+ while (ACPI_SUCCESS(AcpiGetNextObject(ACPI_TYPE_DEVICE,
+ handle, achild, &achild))) {
+ if (ACPI_SUCCESS(acpi_GetInteger(achild,
+ "_STA", &sta)) &&
+ !ACPI_DEVICE_PRESENT(sta))
+ continue;
+ if (ACPI_FAILURE(acpi_GetInteger(achild,
+ "_ADR", &adr))) {
+ device_printf(sc->dev,
+ "child bus %s missing required "
+ "'_ADR' property\n",
+ acpi_name(achild));
+ continue;
+ }
+ if (adr >= (UINT32)sc->numbuses) {
+ device_printf(sc->dev,
+ "child bus %s '_ADR' %u exceeds "
+ "the number of buses supported by "
+ "the device (%d)\n",
+ acpi_name(achild), adr,
+ sc->numbuses);
+ continue;
+ }
+ if (sc->childdevs[adr] != NULL) {
+ device_printf(sc->dev,
+ "child bus %s duplicates '_ADR' "
+ "%u\n", acpi_name(achild), adr);
+ continue;
+ }
+ sc->childdevs[adr] = device_add_child(sc->dev,
+ "iicbus", DEVICE_UNIT_ANY);
+ if (sc->childdevs[adr] == NULL)
+ continue;
+#ifdef FDT
+ sc->childnodes[adr] = -1;
+#endif
+ sc->childhandles[adr] = achild;
+ if (sc->maxbus < (int)adr)
+ sc->maxbus = (int)adr;
+ }
+
+ /* If we configured anything using ACPI data, we're done. */
+ if (sc->maxbus >= 0)
+ return (0);
}
- sc->childdevs[idx] = device_add_child(sc->dev, "iicbus", DEVICE_UNIT_ANY);
- sc->childnodes[idx] = child;
- if (sc->maxbus < (int)idx)
- sc->maxbus = idx;
}
-
- /* If we configured anything using FDT data, we're done. */
- if (sc->maxbus >= 0)
- return (0);
-#endif /* FDT */
+#endif /* DEV_ACPI */
/*
- * If we make it to here, we didn't add any children based on FDT data.
- * Add an iicbus child for every downstream bus supported by the mux.
+ * If we make it to here, we didn't add any children based on firmware
+ * data. Add an iicbus child for every downstream bus supported by
+ * the mux.
*/
for (i = 0; i < sc->numbuses; ++i) {
sc->childdevs[i] = device_add_child(sc->dev, "iicbus", DEVICE_UNIT_ANY);
+#ifdef FDT
+ sc->childnodes[i] = -1; /* not described by a device tree */
+#endif
sc->maxbus = i;
}
@@ -365,6 +469,11 @@
DEVMETHOD(ofw_bus_get_node, iicmux_get_node),
#endif
+#ifdef DEV_ACPI
+ /* bus_if methods */
+ DEVMETHOD(bus_read_ivar, iicmux_read_ivar),
+#endif
+
DEVMETHOD_END
};
@@ -392,4 +501,7 @@
DECLARE_MODULE(iicmux, iicmux_mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
MODULE_VERSION(iicmux, 1);
+#ifdef DEV_ACPI
+MODULE_DEPEND(iicmux, acpi, 1, 1, 1);
+#endif
MODULE_DEPEND(iicmux, iicbus, 1, 1, 1);
Index: sys/modules/i2c/mux/iicmux/Makefile
===================================================================
--- sys/modules/i2c/mux/iicmux/Makefile
+++ sys/modules/i2c/mux/iicmux/Makefile
@@ -8,8 +8,11 @@
device_if.h \
iicbus_if.h \
iicmux_if.h \
+ opt_acpi.h \
opt_platform.h \
+SRCS.DEV_ACPI= acpi_if.h
+
.if !empty(OPT_FDT)
SRCS+= ofw_bus_if.h
.endif
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 7, 1:42 AM (9 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42248446
Default Alt Text
D60060.1796607720.diff (8 KB)
Attached To
Mode
D60060: iicmux: enumerate ACPI child channels symmetrically with FDT
Attached
Detach File
Event Timeline