From owner-freebsd-net@FreeBSD.ORG Fri Oct 7 08:19:09 2011 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E4BDB106566B for ; Fri, 7 Oct 2011 08:19:08 +0000 (UTC) (envelope-from ray@dlink.ua) Received: from dlink.ua (smtp.dlink.ua [193.138.187.146]) by mx1.freebsd.org (Postfix) with ESMTP id 6F7438FC08 for ; Fri, 7 Oct 2011 08:19:08 +0000 (UTC) Received: from [192.168.99.1] (helo=terran.dlink.ua) by dlink.ua with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1RC5Kj-0005O0-Jl; Fri, 07 Oct 2011 10:59:05 +0300 Date: Fri, 7 Oct 2011 11:00:28 +0300 From: Aleksandr Rybalko To: dave jones Message-Id: <20111007110028.bae63f84.ray@dlink.ua> In-Reply-To: References: Organization: D-Link X-Mailer: Sylpheed 2.7.1 (GTK+ 2.20.1; i386-portbld-freebsd8.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-net@freebsd.org Subject: Re: Question about GPIO bitbang MII X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 08:19:09 -0000 On Fri, 7 Oct 2011 10:34:58 +0800 dave jones 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-unsubscribe@freebsd.org" WBW -- Alexandr Rybalko aka Alex RAY