Author: wmb Date: 2009-12-08 09:29:20 +0100 (Tue, 08 Dec 2009) New Revision: 1550
Modified: dev/mmc/sdhci/sdhci.fth dev/mmc/sdhci/selftest.fth Log: Test for write protect switch in SD selftest.
Modified: dev/mmc/sdhci/sdhci.fth =================================================================== --- dev/mmc/sdhci/sdhci.fth 2009-12-08 06:21:21 UTC (rev 1549) +++ dev/mmc/sdhci/sdhci.fth 2009-12-08 08:29:20 UTC (rev 1550) @@ -153,8 +153,11 @@ \ The debouncer takes about 300 ms to stabilize.
: card-inserted? ( -- flag ) - present-state@ h# 40000 and h# 40000 = + present-state@ h# 30000 and h# 30000 = ; +: write-protected? ( -- flag ) + present-state@ h# 80000 and 0= +;
: ?via-quirk ( -- ) \ This is a workaround for an odd problem with the Via Vx855 chip. @@ -314,8 +317,10 @@
." SDHCI: Error: ISR = " swap u. ." ESR = " dup u. decode-esr +\ debug-me + card-clock-off + card-power-off ." Stopping" cr abort - \ debug-me ;
: wait ( mask -- ) @@ -724,10 +729,10 @@ \ -1 means error, 1 means retry : power-up-sdio-card ( -- false | retry? true ) intstat-on - card-power-off d# 20 ms - card-power-on d# 40 ms \ This delay is just a guess (20 was barely too slow for a Via board) + card-power-off d# 50 ms + card-power-on d# 50 ms \ This delay is just a guess (20 was barely too slow for a Via board) card-inserted? 0= if card-power-off intstat-off false true exit then - card-clock-slow d# 10 ms \ This delay is just a guess + card-clock-slow d# 50 ms \ This delay is just a guess reset-card \ Cmd 0 false ; @@ -756,9 +761,15 @@
: attach-card ( -- okay? ) setup-host - power-up-card if ( retry? ) + ['] power-up-card catch if true true then if ( retry? ) \ The first try at powering up failed. if ( ) + ." Trying to reset data lines" cr + card-clock-off + card-power-off + d# 500 ms + setup-host + \ The card was detected, but didn't go to "powered up" state. \ Sometimes that can be fixed by power cycling, so we retry power-up-card if ( retry? ) @@ -798,7 +809,7 @@ intstat-on wait-write-done intstat-off card-clock-off card-power-off - unmap-regs +\ unmap-regs ;
: attach-sdio-card ( -- okay? )
Modified: dev/mmc/sdhci/selftest.fth =================================================================== --- dev/mmc/sdhci/selftest.fth 2009-12-08 06:21:21 UTC (rev 1549) +++ dev/mmc/sdhci/selftest.fth 2009-12-08 08:29:20 UTC (rev 1550) @@ -28,28 +28,85 @@ ibuf obuf /block comp ;
+: write-protected? ( -- ) " write-protected?" $call-parent ; + : (selftest) ( -- error? ) + write-protected? if ." SD card is locked" cr true exit then + sbuf 0 read-block if true exit then 0 h# 5a test-block if true exit then 0 h# a5 test-block if true exit then sbuf 0 write-block \ Restore original content ; +: $= ( $1 $2 -- flag ) + rot tuck <> if ( adr1 adr2 len1 ) + 3drop false exit + then ( adr1 adr2 len1 ) + comp 0= ( flag ) +; +: external? ( -- flag ) + " slot-name" get-my-property if + false + else + decode-string " external" $= + then +; +: .slot-name ( -- ) + " slot-name" get-my-property 0= if + decode-string type space 2drop + then + ." SD slot" +; +: card-present? ( -- ) " card-inserted?" $call-parent ; +: test-abort? ( -- flag ) + key? if key h# 1b = else false then +; +: wait-card? ( -- error? ) + card-present? if false exit then + diagnostic-mode? if + ." Please insert card in " .slot-name ." to continue test." cr + begin + d# 100 ms + test-abort? if ." Aborted" true exit then + card-present? until + ." Card insertion correctly detected." cr + d# 200 ms \ Settling time + false + else + ." No card in " .slot-name cr + true + then +; + +: wait-removal? ( -- error? ) + diagnostic-mode? 0= if false exit then + external? 0= if false exit then + + ." Please remove card from " .slot-name ." to continue test." cr + + begin + d# 100 ms + test-abort? if ." Aborted" true exit then + card-present? 0= until + ." Card removal correctly detected." cr + false +; + external : selftest ( -- error? ) set-unit - " card-inserted?" $call-parent 0= if - ." No card in " - " slot-name" get-my-property 0= if - decode-string type space 2drop - then - ." SD slot" cr - true exit - then - open 0= if ." Open sdmmc failed" cr true exit then + + wait-card? if true exit then + + open 0= if ." Open SD card failed" cr true exit then alloc-test-bufs - ['] (selftest) catch if true then - free-test-bufs - close + ['] (selftest) catch if true then ( error? ) + free-test-bufs ( error? ) + close ( error? ) + + if true exit then ( ) + + wait-removal? ( error? ) ; headers
openfirmware@openfirmware.info