On Fri, 7 Oct 2011 10:34:58 +0800
dave jones <s.dave.jo...@gmail.com> wrote:

>> Hi,
>> 
>> Does FreeBSD have gpio bitbang api for MII? If not, any driver in
>> tree using gpio-bitbang mii that I can refer to? Thanks.
>> It seems like OpenBSD, NetBSD and Linux have added support to gpio
>> bitbang mii, and it's useful for porting embedded devices.
>> 
>> Best regards,
>> Dave.

Hi Dave,

you can try my script for now :) (Attached as text)
then we will do something with that problem.
I'm not sure that script works fine, because i was use it for detect is
attached device MDIO controlled or I2C.

BTW, which device use MDIO attached to GPIO?
And this is PHY or switch, if second take a look on
http://zrouter.org/hg/FreeBSD/head/file/03dd18c85162/head/sys/dev/switch

######################### bitbanged MDIO
#!/bin/sh

mdc="x"
mdio="x"
lmdc="x"
lmdio="x"

phy=$1
reg=$2

DATA=7
CLOCK=6

out=0;

append()
{
    local c=$1
    local d=$2

    if [ ${c} = "X" ]; then c=${lmdc}; fi
    if [ ${d} = "X" ]; then d=${lmdio}; fi
    mdc="${mdc}${c}"
    mdio="${mdio}${d}"
    lmdc="${c}"
    lmdio="${d}"

}

alias gp='gpioctl -q -f /dev/gpioc0'
alias d0='gp ${DATA} 0 > /dev/null; append X _'
alias d1='gp ${DATA} 1 > /dev/null; append X T'
alias c0='gp ${CLOCK} 0 > /dev/null; append _ X'
alias c1='gp ${CLOCK} 1 > /dev/null; append T X'
alias dIN='gp -c ${DATA} IN > /dev/null; append X "<"'
alias dOUT='gp -c ${DATA} OUT > /dev/null; append X ">"'
alias cIN='gp -c ${CLOCK} IN > /dev/null; append ">" X'
alias cOUT='gp -c ${CLOCK} OUT > /dev/null; append ">" X'
alias dget='gp -g ${DATA}'

#SMI send 1
SMI_1()
{
        d1;
        c1;
        c0;
}

#SMI send 0
SMI_0()
{
        d0;
        c1;
        c0;
}
 
ReadMSIO()
{
        local phyad=$1;
        local regad=$2;
        i=0
        while true; do
                SMI_1;
                i=$(( ${i} + 1))
                if [ ${i} -gt 31 ]; then
                        break
                fi
        done

        # 01 # send start
        SMI_0;
        SMI_1;
        # 10 # opcode
        SMI_1;
        SMI_0;

        i=0x10
        while true; do
                if [ $(( ${phyad} & ${i} )) = 0 ]; then
                        SMI_0;
                else
                        SMI_1;
                fi

                i=$(( ${i} >> 1 ))
                if [ ${i} = 0 ]; then
                        break
                fi
        done

        i=0x10
        while true; do
                if [ $(( ${regad} & ${i} )) = 0 ]; then
                        SMI_0;
                else
                        SMI_1;
                fi

                i=$(( ${i} >> 1 ))
                if [ ${i} = 0 ]; then
                        break
                fi
        done

        # #10 # send turn around
        SMI_1;
        SMI_0;

        i=15
        out=0
        dIN;
        while true; do
                c1;
                dinput=`gp -q -g ${DATA}`;
                append X ${dinput}
                append X '<'
                c0;
                out=$(( ${out} | (${dinput} << ${i}) ))

                if [ ${i} = 0 ]; then
                        break
                fi
                i=$(( ${i} - 1 ))
        done
        dOUT;
}

dump()
{
    echo
    echo
    echo " mdc pin${CLOCK} ${mdc}"
    echo "mdio pin${DATA} ${mdio}"
    echo
    echo
    echo
    echo
}

cOUT;
c0;
dOUT;
d0;

out=0
ReadMDIO ${phy} ${reg}
printf "P=0x%02x R=0x%02x: 0x%04x\n" ${phy} ${reg} ${out}
dIN;
cIN;

dump

######################### END bitbanged MDIO



>> _______________________________________________
>> freebsd-net@freebsd.org mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-net
>> To unsubscribe, send any mail to
>> "freebsd-net-unsubscr...@freebsd.org"

WBW
-- 
Alexandr Rybalko <r...@dlink.ua> 
aka Alex RAY <r...@ddteam.net>
_______________________________________________
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"

Reply via email to