Author: quozl Date: Tue Nov 1 06:32:03 2011 New Revision: 2660 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2660
Log: OLPC XO-1.75 - use fast mode (400 kHz i2c) to communicate with new accelerometer.
Modified: cpu/arm/mmp2/twsi.fth cpu/arm/olpc/1.75/accelerometer.fth
Modified: cpu/arm/mmp2/twsi.fth ============================================================================== --- cpu/arm/mmp2/twsi.fth Tue Nov 1 06:29:32 2011 (r2659) +++ cpu/arm/mmp2/twsi.fth Tue Nov 1 06:32:03 2011 (r2660) @@ -58,13 +58,13 @@
h# 1000 constant BBU_TWSI_TimeOut \ TWSI bus timeout loop counter value
-bbu_ICR_IUE bbu_ICR_SCLE or constant iue+scle +bbu_ICR_IUE bbu_ICR_SCLE or value cr-set \ bits to maintain as set : init-twsi-channel ( channel# -- ) set-twsi-channel 7 clock-reg io! 3 clock-reg io! \ Set then clear reset bit 1 us - iue+scle bbu_ICR_UR or cr! \ Reset the unit - iue+scle cr! \ Release the reset + cr-set bbu_ICR_UR or cr! \ Reset the unit + cr-set cr! \ Release the reset 0 sar! \ Set host slave address 0 cr! \ Disable interrupts ; @@ -73,7 +73,7 @@ ;
: twsi-run ( extra-flags -- ) - iue+scle or bbu_ICR_TB or cr! ( ) + cr-set or bbu_ICR_TB or cr! ( )
h# 1000 0 do cr@ bbu_ICR_TB and 0= if unloop exit then @@ -94,7 +94,7 @@ bbu_ICR_START twsi-putbyte ( ) sr@ bbu_ISR_BED and if ( ) bbu_ISR_BED sr! ( ) - iue+scle bbu_ICR_MA or cr! ( ) + cr-set bbu_ICR_MA or cr! ( ) true abort" TWSI bus error" then ( ) ; @@ -111,7 +111,7 @@ \ If no result data requested, quit now r@ 0= if ( r: #data-bytes ) r> drop ( ) - iue+scle bbu_ICR_STOP or cr! ( ) + cr-set bbu_ICR_STOP or cr! ( ) exit then ( r: #data-bytes ) then ( r: #data-bytes ) @@ -177,10 +177,19 @@ twsi-out ;
-d# 12,600,000 constant numerator -: set-bus-speed ( hz -- ) \ Useful range is currently 25,000 .. 100,000 - child-address set-twsi-target - numerator swap / h# 1ff min h# 7e max lcr! +: set-bus-standard cr-set h# fffe7fff and to cr-set ; +: set-bus-fast cr-set h# fffe7fff and h# 8000 or to cr-set ; +: set-bus-speed ( hz -- ) \ Useful range is 25,000 .. 100,000, or 400,000 + child-address set-twsi-target + dup 1- d# 100,000 < if + set-bus-standard + d# 12,600,000 swap / h# 1ff min h# 7e max + lcr@ h# ffff.ff00 and or lcr! + else + set-bus-fast + lcr@ h# ffff.00ff and h# 0000.1d00 or lcr! + then + ; : decode-unit ( adr len -- low high ) parse-2int ; : encode-unit ( low high -- adr len ) >r <# u#s drop [char] , hold r> u#s u#> ;
Modified: cpu/arm/olpc/1.75/accelerometer.fth ============================================================================== --- cpu/arm/olpc/1.75/accelerometer.fth Tue Nov 1 06:29:32 2011 (r2659) +++ cpu/arm/olpc/1.75/accelerometer.fth Tue Nov 1 06:32:03 2011 (r2660) @@ -13,7 +13,6 @@ : ctl4! ( b -- ) h# 23 acc-reg! ; : accelerometer-on ( -- ) h# 47 ctl1! ; : accelerometer-off ( -- ) h# 07 ctl1! ; - : wext ( b -- n ) dup h# 8000 and if h# ffff0000 or then ; : acceleration@ ( -- x y z ) h# 28 acc-reg@ h# 29 acc-reg@ bwjoin wext 5 >>a @@ -49,7 +48,7 @@ : open ( -- flag ) my-unit " set-address" $call-parent bus-speed " set-bus-speed" $call-parent - ['] accelerometer-on catch 0= + ['] accelerometer-on catch 0= ; : close ( -- ) accelerometer-off @@ -122,7 +121,7 @@ average-acceleration@ t- ( dx dy dz ) h# 08 ctl4! ( x y z ) \ High res, Normal mode error? if accelerometer-off true exit then - + accelerometer-off false ; @@ -141,22 +140,22 @@ ['] accelerometer-on catch if \ The attempt to talk at the old address failed, so we assume the new chip \ Support for new LIS3DHTR chip - d# 100,000 to bus-speed - d# 50 to min-x d# 50 to min-y d# 50 to min-z - d# 150 to max-x d# 150 to max-y d# 450 to max-z + d# 400,000 to bus-speed + d# 50 to min-x d# 50 to min-y d# 50 to min-z + d# 150 to max-x d# 150 to max-y d# 450 to max-z h# 32 6 encode-phys " reg" property ['] lis3dhtr-selftest to lis-selftest else accelerometer-off \ Something responded to the old address, so we assume it's the old chip \ Support for old LIS33DE chip - d# 25,000 to bus-speed - d# 20 to min-x d# 20 to min-y d# 20 to min-z - d# 400 to max-x d# 400 to max-y d# 400 to max-z + d# 25,000 to bus-speed + d# 20 to min-x d# 20 to min-y d# 20 to min-z + d# 400 to max-x d# 400 to max-y d# 400 to max-z h# 3a 6 encode-phys " reg" property ['] lis33de-selftest to lis-selftest then -; +;
end-package
openfirmware@openfirmware.info