From b10a2eb875ce4fe60da01108b0827ef546faee15 Mon Sep 17 00:00:00 2001 From: Tomaz Zaman Date: Wed, 4 Mar 2026 22:04:29 +0100 Subject: [PATCH] gpio: add FDT gpio-hog processing for boot-time pin configuration Process gpio-hog child nodes during gpiobus attach to configure pins at boot. Used on Mono Gateway for WiFi module enable (2R-enable), 3R-disable, and UART mux routing. --- .../src/arm64/freescale/mono-gateway-dk.dts | 29 ++++++++ sys/dev/gpio/gpiobus.c | 68 +++++++++++++++++++ sys/dev/gpio/ofw_gpiobus.c | 1 + 3 files changed, 98 insertions(+) diff --git a/sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts b/sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts index fd39c8c2101..a7f2e87291c 100644 --- a/sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts +++ b/sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts @@ -442,6 +442,35 @@ reg = <0 0xc3000000 0 0x800000>; /* 8MB at 0xC3000000 */ }; +/* + * Board mux/enable GPIOs — configure for 2R (dual-radio / Jody W337). + * 2R-enable: power/mux enable for the PCIe WiFi card + * 3R-enable: disabled (3R = 3-radio card, no PCIe) + * uart-mux: route shared UART to 2R card + */ +&gpio2 { + 2r-enable { + gpio-hog; + gpios = <6 GPIO_ACTIVE_LOW>; + output-high; + line-name = "2r-enable"; + }; + + 3r-enable { + gpio-hog; + gpios = <2 GPIO_ACTIVE_LOW>; + output-low; + line-name = "3r-enable"; + }; + + uart-mux { + gpio-hog; + gpios = <26 GPIO_ACTIVE_HIGH>; + output-high; + line-name = "uart-mux"; + }; +}; + /* PCIe3: Jody W337 WiFi module (NXP 88W9098) */ &pcie3 { status = "okay"; diff --git a/sys/dev/gpio/gpiobus.c b/sys/dev/gpio/gpiobus.c index 0fca02c41ca..b48155f23b6 100644 --- a/sys/dev/gpio/gpiobus.c +++ b/sys/dev/gpio/gpiobus.c @@ -40,6 +40,10 @@ #include #include +#ifdef FDT +#include +#include +#endif #include "gpiobus_if.h" @@ -311,6 +315,53 @@ gpiobus_print_pins(struct gpiobus_ivar *devi, struct sbuf *sb) sbuf_printf(sb, "%d", range_start); } +#ifdef FDT +/* + * Process a gpio-hog child node of a GPIO controller. + * Sets the pin direction and value as specified in the DT. + * The "gpios" property is controller-relative: . + * "output-high"/"output-low" are logical levels; GPIO_ACTIVE_LOW + * inverts the physical pin state. + */ +static void +gpiobus_process_hog(device_t dev, phandle_t child) +{ + char name[64]; + uint32_t gpiocells[2]; + uint32_t pin; + int active_low, val; + + if (OF_getencprop(child, "gpios", gpiocells, sizeof(gpiocells)) != + sizeof(gpiocells)) + return; + + pin = gpiocells[0]; + active_low = (gpiocells[1] & 1); /* bit 0 = GPIO_ACTIVE_LOW */ + + name[0] = '\0'; + OF_getprop(child, "line-name", name, sizeof(name)); + name[sizeof(name) - 1] = '\0'; + + if (OF_hasprop(child, "output-high")) { + val = active_low ? 0 : 1; + GPIO_PIN_SETFLAGS(dev, pin, GPIO_PIN_OUTPUT); + GPIO_PIN_SET(dev, pin, val); + device_printf(dev, "gpio-hog: pin %d (%s) " + "output-high (phys=%d)\n", pin, name, val); + } else if (OF_hasprop(child, "output-low")) { + val = active_low ? 1 : 0; + GPIO_PIN_SETFLAGS(dev, pin, GPIO_PIN_OUTPUT); + GPIO_PIN_SET(dev, pin, val); + device_printf(dev, "gpio-hog: pin %d (%s) " + "output-low (phys=%d)\n", pin, name, val); + } else if (OF_hasprop(child, "input")) { + GPIO_PIN_SETFLAGS(dev, pin, GPIO_PIN_INPUT); + device_printf(dev, "gpio-hog: pin %d (%s) input\n", + pin, name); + } +} +#endif + device_t gpiobus_add_bus(device_t dev) { @@ -321,6 +372,23 @@ gpiobus_add_bus(device_t dev) return (NULL); #ifdef FDT ofw_gpiobus_register_provider(dev); + /* + * Process gpio-hog children before bus_generic_attach() so + * that muxes, power enables, and other board signals are + * configured before downstream devices (PCIe, UART) probe. + */ + { + phandle_t node, child; + + node = ofw_bus_get_node(dev); + if (node > 0) { + for (child = OF_child(node); child != 0; + child = OF_peer(child)) { + if (OF_hasprop(child, "gpio-hog")) + gpiobus_process_hog(dev, child); + } + } + } #endif return (busdev); } diff --git a/sys/dev/gpio/ofw_gpiobus.c b/sys/dev/gpio/ofw_gpiobus.c index da1bfbc268b..80e15a16598 100644 --- a/sys/dev/gpio/ofw_gpiobus.c +++ b/sys/dev/gpio/ofw_gpiobus.c @@ -433,6 +433,7 @@ ofw_gpiobus_attach(device_t dev) bus_enumerate_hinted_children(dev); /* * Attach the children represented in the device tree. + * gpio-hog nodes are already processed by gpiobus_attach_bus(). */ for (child = OF_child(ofw_bus_get_node(dev)); child != 0; child = OF_peer(child)) {