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.
This commit is contained in:
parent
a3dd8a80d2
commit
b10a2eb875
3 changed files with 98 additions and 0 deletions
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@
|
|||
|
||||
#include <dev/gpio/gpiobusvar.h>
|
||||
#include <dev/gpio/gpiobus_internal.h>
|
||||
#ifdef FDT
|
||||
#include <dev/ofw/ofw_bus.h>
|
||||
#include <dev/ofw/ofw_bus_subr.h>
|
||||
#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: <pin flags>.
|
||||
* "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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue