#!/bin/sh
#
# Lantiq PHY MDIO register swiss army knife utility.
#

LANTIQ=/sys/devices/amba.0/e000b000.ps7-ethernet/net/eth0/e000b000:01

[ $# -lt 1 ] && {
    echo "`basename $0`"
    echo ""
    echo "Usage: `basename $0` addr <val>"
    echo "       addr: MDIO register address"
    echo "       val:  MDIO register value"
    echo
    echo "If optional parameter <val> is present, write operation si performed,"
    echo "otherwise, read operation is performed."
    echo 
    exit 255
}


# Set register address
echo $1 > ${LANTIQ}/mdio_addr
ret=$?
[ $ret -ne 0 ] && {
    echo "Invalid MDIO register address."
    exit $ret
}


# Write register value
[ $# -gt 1 ] && {
    echo $2 > ${LANTIQ}/mdio_val
    ret=$?
    [ $ret -ne 0 ] && {
        echo "Invalid MDIO register value."
        exit $ret
    }
    exit 0
} 


# read register value
cat ${LANTIQ}/mdio_val


exit 0
