Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dump Palmetto GPIO hog devicetree nodes
#!/usr/bin/python3
import sys
from collections import namedtuple
GpioRegsetConfig = namedtuple("GpioRegsetConfig", "banks value direction")
banks = ( "ABCD", "EFGH" )
broken = (
GpioRegsetConfig(banks[0], 0x130F8CE3, 0x01706074),
GpioRegsetConfig(banks[1], 0x9F48F7FF, 0x00004002)
)
working = (
GpioRegsetConfig(banks[0], 0x130F8CE3, 0x0370E677),
GpioRegsetConfig(banks[1], 0x0370E677, 0xC738F202)
)
GpioConfig = namedtuple("GpioConfig", "bank index direction state active")
def gpio_dt(name, config):
fmt = "pin_gpio_{} {{\n\tgpio-hog;\n\tgpios = <ASPEED_GPIO({}, {}) {}>;\n\t{};\n\tline-name = \"{}\";\n}};"
if "output" == config.direction:
state = "{}-{}".format(config.direction, config.state)
else:
state = config.direction
return fmt.format(
name.lower(),
config.bank,
config.index,
"GPIO_ACTIVE_HIGH",
state,
name)
def tell_gpios(config, change):
for i, bank in enumerate(config.banks):
for j in range(0, 8):
bi = i * 8 + j;
if ((1 << bi) & change) > 0:
gpio = "{}{}".format(bank, j)
if (bi & config.direction) > 0:
sd = "output"
value = "high" if (bi & config.value) > 0 else "low"
else:
sd = "input"
value = None
dtconfig = GpioConfig(bank, j, sd, value, "GPIO_ACTIVE_HIGH")
print(gpio_dt(gpio, dtconfig))
print()
def main():
for b, w in zip(broken, working):
cd = b.direction ^ w.direction
tell_gpios(w, cd)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment