diff --git a/gpio_fixup.py b/gpio_fixup.py new file mode 100644 index 0000000..c0ff3d8 --- /dev/null +++ b/gpio_fixup.py @@ -0,0 +1,65 @@ +#!/usr/bin/python3 + +# a program to correct the GPIO settings to match the values in the i96 bus spec +# +# Pat Beirne 2021 +# +# this script applies only to the OrangePi-i96, booting from u-boot 2012.04.442 + +from mmap import mmap +import os, sys, time, struct + +# assert the i96 GPIO pins into GPIO mode +PORTC_GPIO_MASK = 0 # no pins need changing +PORTA_GPIO_MASK = 0x7e508000 # rda gpioA 15,20,22,25-30 (i96 gpio group) +PORTB_GPIO_MASK = 0 # no pins need changing +PORTD_GPIO_MASK = 0xc # rda gpioD 2,3 (i96 gpioi group) +PORTB_GPIO_MASK_NO_CTSRTS = 0x300 # assert B 8,9 to reuse uart2_cts,rts + +# clear the i96 GPIO pins to special function mode +PORTC_SF_MASK = 0xfffffe3f # clear bits C c6,7,8 (i96 uarts) +PORTA_SF_MASK = 0xffff91a0 # clear bits A 0-4,6,9-11,13,14 (i96 i2c, spi, i2s) +PORTB_SF_MASK = 0xfffffc3f # clear bits B 6-9 (i96 i2c, uart) +PORTD_SF_MASK = 0xFFFFFFFF # nothing to change + +PORTC_IOMUX = 0x11a09008 +PORTA_IOMUX = 0x11a0900c +PORTB_IOMUX = 0x11a09010 +PORTD_IOMUX = 0x11a09014 + +PAGE_MASK = ~0xFFF +PAGE_OFFSET = 0xFFF + +# we must read and write 4 bytes at a time, little-endian +def get_word(mapfile, address): + address &= PAGE_OFFSET + return struct.unpack("