[openfirmware] r1020 - dev/mmc/sdhci

svn at openfirmware.info svn at openfirmware.info
Thu Dec 4 10:18:24 CET 2008


Author: wmb
Date: 2008-12-04 10:18:23 +0100 (Thu, 04 Dec 2008)
New Revision: 1020

Modified:
   dev/mmc/sdhci/sdhci.fth
Log:
OLPC - attempt to make SD startup a little more robust by
retrying if the first power-up attempt failed.

Modified: dev/mmc/sdhci/sdhci.fth
===================================================================
--- dev/mmc/sdhci/sdhci.fth	2008-12-04 09:18:18 UTC (rev 1019)
+++ dev/mmc/sdhci/sdhci.fth	2008-12-04 09:18:23 UTC (rev 1020)
@@ -463,8 +463,7 @@
       drop d# 10 ms
    loop                      ( )
 
-   ." SDHCI: Card didn't power up after 1 second" cr
-   abort
+   true
 ;
 
 : set-operating-conditions  ( -- error? )
@@ -560,22 +559,37 @@
    false to writing?
 ;
 
-external
-
-: attach-card  ( -- okay? )
+\ -1 means error, 1 means retry
+: power-up-card  ( -- false | retry? true )
    intstat-on
    card-power-off d# 20 ms
-
    card-power-on  d# 20 ms  \ This delay is just a guess
-
-   card-inserted?  0=  if  card-power-off  false intstat-off  exit  then   
-
+   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
-
    reset-card     \ Cmd 0
+   set-operating-conditions  if  intstat-off  true true exit  then
+   false
+;
 
-   set-operating-conditions  if  false intstat-off  exit  then
+external
 
+: attach-card  ( -- okay? )
+   power-up-card  if         ( retry? )
+      \ The first try at powering up failed.
+      if                     ( )
+         \ 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? )
+            if  ." SD card did not power up" cr  then
+            false exit
+         then
+         \ The second attempt to power up the card worked
+      else
+         \ The card was not detected, so we give up
+         false exit
+      then
+   then
+
    get-all-cids   \ Cmd 2
    mmc?  if
       h# 10000 set-rca   \ Cmd 3 (MMC) - Get relative card address




More information about the openfirmware mailing list