[openfirmware] [commit] r2036 - cpu/arm/olpc/1.75 dev/olpc/kb3700
repository service
svn at openfirmware.info
Wed Nov 24 21:33:21 CET 2010
Author: wmb
Date: Wed Nov 24 21:33:20 2010
New Revision: 2036
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2036
Log:
OLPC XO-1.75 - implemented a bunch of EC commands.
Added:
dev/olpc/kb3700/eccmds.fth
Modified:
cpu/arm/olpc/1.75/devices.fth
cpu/arm/olpc/1.75/ecflash.fth
dev/olpc/kb3700/spicmd.fth
Modified: cpu/arm/olpc/1.75/devices.fth
==============================================================================
--- cpu/arm/olpc/1.75/devices.fth Wed Nov 24 21:29:04 2010 (r2035)
+++ cpu/arm/olpc/1.75/devices.fth Wed Nov 24 21:33:20 2010 (r2036)
@@ -228,6 +228,7 @@
devalias keyboard /ec-spi/keyboard
+fload ${BP}/dev/olpc/kb3700/eccmds.fth
fload ${BP}/cpu/arm/olpc/1.75/ecflash.fth
0 0 " d4208000" " /" begin-package \ USB Host Controller
Modified: cpu/arm/olpc/1.75/ecflash.fth
==============================================================================
--- cpu/arm/olpc/1.75/ecflash.fth Wed Nov 24 21:29:04 2010 (r2035)
+++ cpu/arm/olpc/1.75/ecflash.fth Wed Nov 24 21:33:20 2010 (r2036)
@@ -1,20 +1,6 @@
\ See license at end of file
purpose: Reflash the EC code
-0 value ec-ih
-: open-ec ( -- )
- ec-ih 0= if
- " /eccmd" open-dev to ec-ih
- then
- ec-ih 0= abort" Can't open eccmd node"
-;
-: close-ec ( -- )
- ec-ih if
- ec-ih close-dev
- 0 to ec-ih
- then
-;
-
h# 10000 value /ec-flash
char 3 value expected-ec-version
@@ -45,24 +31,20 @@
;
: flash-ec ( "filename" -- )
get-ec-file
- open-ec
- " enter-updater" ec-ih $call-method
- ." Erasing ..." " erase-flash" ec-ih $call-method cr
- ." Writing ..." load-base /ec-flash 0 " write-flash" ec-ih $call-method cr
+ " enter-updater" $call-ec
+ ." Erasing ..." " erase-flash" $call-ec cr
+ ." Writing ..." load-base /ec-flash 0 " write-flash" $call-ec cr
." Verifying ..."
- load-base /ec-flash + /ec-flash 0 " read-flash" ec-ih $call-method
+ load-base /ec-flash + /ec-flash 0 " read-flash" $call-ec
load-base load-base /ec-flash + /ec-flash comp
abort" Miscompare!"
cr
- " reboot-ec" ec-ih $call-method
- close-ec
+ reset-ec
;
: read-ec-flash ( -- )
- open-ec
- " enter-updater" ec-ih $call-method
- flash-buf /ec-flash 0 " read-flash" ec-ih $call-method
-\ " reboot-ec" ec-ih $call-method
- close-ec
+ " enter-updater" $call-ec
+ flash-buf /ec-flash 0 " read-flash" $call-ec
+\ " reboot-ec" $call-ec
;
: save-ec-flash ( "name" -- )
safe-parse-word $new-file
Added: dev/olpc/kb3700/eccmds.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/olpc/kb3700/eccmds.fth Wed Nov 24 21:33:20 2010 (r2036)
@@ -0,0 +1,116 @@
+\ See license at end of file
+purpose: EC Commands for XO-1.75 and later
+
+0 value ec-ih
+: $call-ec ( ... adr len -- ... ) ec-ih $call-method ;
+: do-ec-cmd ( [ args ] #args #results cmd-code -- [ results ] )
+ " ec-command" $call-ec abort" EC command failed"
+;
+stand-init: EC
+ " /ec-spi" open-dev to ec-ih
+;
+
+: too-many-retries ( -- ) true abort" Too many EC command retries" ;
+d# 10 constant #ec-retries
+
+: ec-cmd ( cmd -- ) 0 0 rot do-ec-cmd ;
+: ec-cmd-b@ ( cmd -- w ) 0 1 rot do-ec-cmd bwjoin ;
+: ec-cmd-w@ ( cmd -- w ) 0 2 rot do-ec-cmd bwjoin ;
+: ec-cmd-l@ ( cmd -- l ) 0 4 rot do-ec-cmd bljoin ;
+: ec-cmd-b! ( b cmd -- ) 1 0 rot do-ec-cmd ;
+: ec-cmd-w! ( w cmd -- ) >r wbsplit 2 0 r> do-ec-cmd ;
+: ec-cmd-l! ( l cmd -- ) >r lbsplit 4 0 r> do-ec-cmd ;
+
+: ec-api-ver@ ( -- b ) h# 08 ec-cmd-b@ ;
+: bat-voltage@ ( -- w ) h# 10 ec-cmd-w@ ;
+: bat-current@ ( -- w ) h# 11 ec-cmd-w@ ;
+: bat-acr@ ( -- w ) h# 12 ec-cmd-w@ ;
+: bat-temp@ ( -- w ) h# 13 ec-cmd-w@ ;
+: ambient-temp@ ( -- w ) h# 14 ec-cmd-w@ ;
+: bat-status@ ( -- b ) h# 15 ec-cmd-b@ ;
+: bat-soc@ ( -- b ) h# 16 ec-cmd-b@ ;
+
+: (bat-gauge-id@) ( -- sn0 .. sn7 ) 0 8 h# 17 do-ec-cmd ;
+: bat-gauge-id@ ( -- sn0 .. sn7 )
+ #ec-retries 0 do
+ ['] (bat-gauge-id@) catch 0= if unloop exit then
+ loop
+ too-many-retries
+;
+: (bat-gauge@) ( -- b ) h# 31 1 1 h# 18 do-ec-cmd ; \ 31 is the EEPROM address
+: bat-gauge@ ( -- b )
+ #ec-retries 0 do
+ ['] (bat-gauge@) catch 0= if unloop exit then
+ loop
+ too-many-retries
+;
+
+: (bat-type@) ( -- b ) h# 5f 1 1 h# 18 do-ec-cmd ; \ 5f is the EEPROM address
+: bat-type@ ( -- b )
+ #ec-retries 0 do
+ ['] (bat-type@) catch 0= if unloop exit then
+ loop
+ too-many-retries
+;
+
+: board-id ( -- n ) h# 19 ec-cmd-w@ ;
+: reset-ec ( -- ) h# 28 ec-cmd ;
+
+: autowack-on ( -- ) 1 33 ec-cmd-b! ;
+: autowack-off ( -- ) 0 33 ec-cmd-b! ;
+
+: ec-echo ( ... n -- ... ) dup h# 52 do-ec-cmd ;
+
+[ifdef] notdef
+#define CMD_READ_BATT_ERR_CODE 0x1f
+#define CMD_READ_BATTERY_TYPE 0x2c
+#define CMD_SET_EC_WAKEUP_TIMER 0x36
+#define CMD_READ_EXT_SCI_MASK 0x37
+#define CMD_WRITE_EXT_SCI_MASK 0x38
+#define CMD_CLEAR_EC_WAKEUP_TIMER 0x39
+#define CMD_ENABLE_RUNIN_DISCHARGE 0x3B
+#define CMD_DISABLE_RUNIN_DISCHARGE 0x3C
+#define CMD_READ_MPPT_ACTIVE 0x3d
+#define CMD_READ_MPPT_LIMIT 0x3e
+#define CMD_SET_MPPT_LIMIT 0x3f
+#define CMD_DISABLE_MPPT 0x40
+#define CMD_ENABLE_MPPT 0x41
+#define CMD_READ_VIN 0x42
+#define CMD_EXT_SCI_QUERY 0x43
+#define CMD_READ_LOCATION 0x44
+#define CMD_WRITE_LOCATION 0x45
+#define CMD_KEYBOARD_CMD 0x46
+#define CMD_TOUCHPAD_CMD 0x47
+#define RSP_KEYBOARD_DATA 0x48
+#define RSP_TOUCHPAD_DATA 0x49
+#define CMD_GET_FW_VER 0x4a
+#define CMD_POWER_CYCLE 0x4b
+#define CMD_POWER_OFF 0x4c
+#define CMD_RESET_EC_SOFT 0x4d
+#define CMD_READ_GUAGE_U16 0x4e
+#define CMD_ENABLE_MOUSE 0x4f
+[then]
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2010 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
Modified: dev/olpc/kb3700/spicmd.fth
==============================================================================
--- dev/olpc/kb3700/spicmd.fth Wed Nov 24 21:29:04 2010 (r2035)
+++ dev/olpc/kb3700/spicmd.fth Wed Nov 24 21:33:20 2010 (r2036)
@@ -280,7 +280,6 @@
0 instance value port#
: set-port ( port# -- ) to port# ;
-\ : put-data ( byte -- ) port# 2 0 d# 99 ec-command ; \ XXX
: get-data? ( -- false | data true )
port# deque? ( false | data true )
poll
@@ -292,7 +291,6 @@
loop
true \ abort" Timeout waiting for data from device"
;
-\ : put-get-data ( cmd -- data | -1 ) put-data get-data ;
\ Wait until the device stops sending data
: clear-out-buf ( -- ) begin d# 120 ms get-data? while drop repeat ;
@@ -331,16 +329,6 @@
>r >r >r 0 0 0 r> r> r> data-command
;
-new-device
-" " " 2" set-args
-" eccmd" name
-my-space " reg" integer-property
-: open ( -- flag )
- my-unit " set-port" $call-parent
- true
-;
-: close ( -- )
-;
8 buffer: ec-cmdbuf
d# 16 buffer: ec-respbuf
: expected-response-length ( -- n ) ec-cmdbuf 1+ c@ h# f and ;
@@ -357,11 +345,12 @@
dup 5 > abort" Too many EC command arguments"
ec-cmdbuf 3 + swap bounds ?do i c! loop ( )
;
-: timed-get-data ( -- b )
+: timed-get-results ( -- b )
get-msecs d# 20 + begin ( limit )
- " get-data?" $call-parent if ( limit data )
- nip exit
+ 2 deque? if ( limit b )
+ nip exit ( -- b )
then ( limit )
+ poll ( limit )
dup get-msecs - 0< ( limit )
until ( limit )
drop
@@ -370,7 +359,7 @@
: get-results ( -- [ results ] )
ec-respbuf #results bounds ?do
- timed-get-data i c!
+ timed-get-results i c!
loop
#results 0 ?do \ XXX maybe this loop should go backwards?
@@ -380,19 +369,28 @@
: ec-command ( [ args ] #args #results cmd-code -- [ results ] error? )
0 set-cmdbuf
- ec-cmdbuf 8 false " no-data-command" $call-parent
+ ec-cmdbuf 8 false no-data-command
get-results
false
;
+: put-data ( byte -- )
+ 1 0
+ port# case
+ 3 of h# 46 endof
+ 4 of h# 47 endof
+ ( default ) 3drop exit
+ endcase ( byte #args #results cmd )
+ ec-command drop
+;
+: put-get-data ( cmd -- data | -1 ) put-data get-data ;
+
: enter-updater ( -- )
0 0 h# 50 1 set-cmdbuf
- ec-respbuf 1 true ec-cmdbuf 8 true " data-command" $call-parent
+ ec-respbuf 1 true ec-cmdbuf 8 true data-command
;
-: reboot-ec ( -- ) 0 0 h# 28 ec-command drop ;
-
create pgm-cmd h# 51 c, h# 84 c, d# 16 c, h# 02 c, h# 00 c, 0 c, 0 c, 0 c,
create read-cmd h# 51 c, h# 04 c, d# 16 c, h# 03 c, h# 00 c, 0 c, 0 c, 0 c,
create rdstat-cmd h# 51 c, h# 01 c, d# 01 c, h# 05 c, h# 80 c, 0 c, 0 c, 0 c,
@@ -405,9 +403,8 @@
lbsplit drop ( low mid hi r: template )
r@ 4 + c! r@ 5 + c! r> 6 + c!
;
-: flash-command ( datadr datlen in? template -- )
- 8 true " data-command" $call-parent
-;
+: flash-command ( datadr datlen in? template -- ) data-command ;
+
: write-flash-chunk ( adr len offset -- ) \ len limited to 16 bytes for now
over pgm-cmd set-offset&len ( adr len )
false pgm-cmd flash-command ( )
@@ -459,8 +456,6 @@
drop ( )
;
-finish-device
-
new-device
" " " 3" set-args
fload ${BP}/dev/pckbd.fth
More information about the openfirmware
mailing list