#!/bin/sh
set -e

CM_PER=0x44E00000
CM_PER_PRUSS_CLKCTRL=$(( $CM_PER + 0xE8 ))

PRM_PER=0x44E00C00
RM_PER_PWRRSTCTRL=$(( $PRM_PER + 0x00 ))
PM_PER_PWRSTST=$(( $PRM_PER + 0x08 ))
PM_PER_PWRSTCTRL=$(( $PRM_PER + 0x0C ))


write32() {
        printf '\tWRITING 0x%08x : 0x%08x\n' $1 $2
        devmem2 $1 w $2 | grep -v mapped | grep -v opened
}

read32() {
        printf '\tREADING 0x%08x\n' $1
        devmem2 $1 w
}

echo
echo "Enabling PRU clock"
write32 ${CM_PER_PRUSS_CLKCTRL} 0x00000002

echo
echo "Enabling PRU power"
write32 ${PM_PER_PWRSTCTRL} 0x660000E3

echo
echo "Taking PRU out of reset"
write32 ${RM_PER_PWRRSTCTRL} 0x00000000

echo
echo "Trying to read REVID"
read32 0x4a326000

echo
echo "Trying to read SYSCFG"
read32 0x4a326004 

