Changeset 3419


Ignore:
Timestamp:
Nov 8, 2012, 7:42:50 AM (3 years ago)
Author:
wmb
Message:

OLPC SPI FLASH driver - converted nested case statements to tables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dev/olpc/spiflash/spiflash.fth

    r3417 r3419  
    3043040 value jedec-id#
    3053050 0 2value spi-id$
     306
     307: (.spi-id)  ( -- )
     308   push-hex
     309   spi-id# 2 .r [char] . emit jedec-id# 6 .r
     310   pop-base
     311;
     312
     313create jedec-spi-table
     314   \ JEDEC-ID    /flash          Name
     315
     316   \ XO-4
     317   h# 1540c8 ,  h# 20.0000 ,  ," GD25Q16B"    \ GigaDevice 3V3
     318   h# 1560c8 ,  h# 20.0000 ,  ," GD25LQ16"    \ GigaDevice 1V8
     319   h# 1540ef ,  h# 20.0000 ,  ," W25Q16"      \ Winbond 3V3
     320   h# 1520c2 ,  h# 20.0000 ,  ," MX25L1606E"  \ Macronix 3V3 also MX25L1605D which is EOL (CS# rise time problem)
     321   h# 1524c2 ,  h# 20.0000 ,  ," MX25L1633E"  \ Macronix 3V3 (this is the preferred Macronyx part)
     322   h# 1525c2 ,  h# 20.0000 ,  ," MX25L1635E"  \ Macronix 1V8 (CS# rise time problem)
     323   h# 3525c2 ,  h# 20.0000 ,  ," MX25U1635E"  \ Macronix 1V8
     324
     325   \ XO-1.75 and XO-3 and XO-4 A2
     326   h# 3425c2 ,  h# 10.0000 ,  ," MX25U8035"   \ Macronix 3V3
     327
     328   \ XO-1 and XO-1.5
     329   h# 1430ef ,  h# 10.0000 ,  ," WX25X80"     \ Winbond  (AB-ID is 13)
     330   h# 130201 ,  h# 10.0000 ,  ," S25FL008A"   \ Spansion (AB-ID is 13)
     331   h# 8e25bf ,  h# 10.0000 ,  ," SST25VF080B" \ SST      (AB-ID is bf)
     332   \ ST M25P80 does not support the JEDEC ID command (AB-ID is 13)
     333
     334   0 ,   \ End of list
     335
     336\ I don't think this table will ever be used, because the only part
     337\ that was actually shipped on XO-1 and XO-1.5 was Winbond WX25X80
     338create ab-spi-table
     339   \   AB-ID     /flash          Name
     340   h#     13 ,  h# 10.0000 ,  ," Spansion, Winbond, or ST"
     341   h#     bf ,  h# 10.0000 ,  ," SST"
     342
     343\ An infrequent HW error on XO-1 B1 used to falsely report 14 instead of 13
     344\  h#     14 ,  h# 10.0000 ,  ," Unknown"
     345
     346   0 ,   \ End of list
     347
     348create unknown-spi-flash
     349   \ /flash      Name
     350   10.0000 ,  ," Unknown"
     351
     352: search-spi-table  ( value table-adr -- true | entry-adr false )
     353   begin  dup @  while       ( value adr )
     354      2dup @ =  if           ( value adr )
     355         nip  na1+           ( entry-adr )
     356         false exit          ( entry-adr false )
     357      then                   ( value adr )
     358      2 na+ +str             ( value adr' )
     359   repeat                    ( value adr )
     360   2drop true                ( true )
     361;
     362
    306363: spi-identify  ( -- )
    307364   ab-id to spi-id#
    308365   jedec-id to jedec-id#
    309    " Unknown" to spi-id$
    310    spi-id# case
    311       h# 13  of
    312          ['] common-write  1mb-flash
    313          " Spansion, Winbond, or ST" to spi-id$
    314       endof
    315       h# 14  of
    316          ['] common-write  1mb-flash
    317          jedec-id# h# 1520c2 =  if  2mb-flash  " MX25L1605D"   to spi-id$  then
    318          jedec-id# h# 1540c8 =  if  2mb-flash  " GD25Q16B"     to spi-id$  then
    319          jedec-id# h# 1540ef =  if  2mb-flash  " W25Q16"       to spi-id$  then
    320       endof
    321       h# 24  of
    322          ['] common-write  2mb-flash
    323          jedec-id# h# 1524c2 =  if  2mb-flash  " MX25L1633E"   to spi-id$  then
    324       endof
    325       h# 25  of
    326          ['] common-write  1mb-flash
    327          jedec-id# h# 1525c2 =  if  2mb-flash  " MX25L1635E"   to spi-id$  then
    328       endof
    329       h# 34  of
    330          ['] common-write  1mb-flash
    331          " Macronyx" to spi-id$
    332          jedec-id# h# 3425c2 =  if  1mb-flash  " MX25E8035"    to spi-id$  then
    333       endof
    334       h# 35  of
    335          ['] common-write  2mb-flash
    336          jedec-id# h# 3525c2 =  if  2mb-flash  " MX25U1635E"    to spi-id$  then
    337       endof
    338       \ the SST part with its unique auto-increment address writing scheme
    339       h# bf  of
    340          ['] sst-write     1mb-flash
    341          " SST" to spi-id$
    342       endof
    343       ( default )  ." Bad SPI FLASH ID " dup . cr  ['] null-write swap
    344    endcase                                      ( writer )
    345    to write-spi-flash
     366
     367   ['] common-write to write-spi-flash  \ The usual case
     368
     369   \ Special case for an uncommon part
     370   spi-id# h# bf =  if  ['] sst-write to write-spi-flash  then
     371
     372   jedec-id#  jedec-spi-table  search-spi-table  if   ( )
     373      \ If we don't find it in the JEDEC ID table, fall back to the AB ID table
     374
     375      ab-id  ab-spi-table  search-spi-table  if       ( )
     376         \ If we still don't find it, complain and disable writes
     377
     378         ." Unsupported SPI FLASH ID " (.spi-id) cr
     379         ['] null-write to write-spi-flash
     380         
     381         unknown-spi-flash     ( entry-adr )
     382      then                     ( entry-adr )
     383   then                        ( entry-adr )
     384   dup @ to /flash             ( entry-adr' )
     385   na1+ count  to spi-id$      ( )
     386   
    346387   spi-unprotect
    347388;
     
    351392: .spi-id  ( -- )
    352393   ." SPI FLASH is type "
    353    spi-id# 2 .r [char] . emit jedec-id# 6 .r
     394   (.spi-id)
    354395   ." , " spi-id$ type
    355396   ." , " /flash h# 100000 / .d ." MB."
Note: See TracChangeset for help on using the changeset viewer.