[openfirmware] [commit] r2062 - cpu/arm/olpc/1.75 dev/olpc/kb3700

repository service svn at openfirmware.info
Fri Dec 3 07:35:59 CET 2010


Author: wmb
Date: Fri Dec  3 07:35:59 2010
New Revision: 2062
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2062

Log:
XO-1.75 - added battery status reporting.

Added:
   dev/olpc/kb3700/batstat.fth
   dev/olpc/kb3700/eccmdcom.fth
Modified:
   cpu/arm/olpc/1.75/devices.fth
   dev/olpc/kb3700/eccmds.fth
   dev/olpc/kb3700/ecio.fth

Modified: cpu/arm/olpc/1.75/devices.fth
==============================================================================
--- cpu/arm/olpc/1.75/devices.fth	Fri Dec  3 02:40:28 2010	(r2061)
+++ cpu/arm/olpc/1.75/devices.fth	Fri Dec  3 07:35:59 2010	(r2062)
@@ -101,7 +101,6 @@
 
 : ignore-power-button ;  \ XXX implement me
 : ssp-spi-reprogrammed ;
-: ?enough-power  ( -- )  ;
 
 fload ${BP}/cpu/arm/mmp2/sspspi.fth        \ Synchronous Serial Port SPI interface
 
@@ -130,9 +129,9 @@
 fload ${BP}/cpu/x86/pc/olpc/mfgdata.fth      \ Manufacturing data
 fload ${BP}/cpu/x86/pc/olpc/mfgtree.fth      \ Manufacturing data in device tree
 
-[ifdef] notyet
-fload ${BP}/dev/olpc/kb3700/battery.fth      \ Battery status reports
-[then]
+fload ${BP}/dev/olpc/kb3700/eccmds.fth
+fload ${BP}/dev/olpc/kb3700/batstat.fth      \ Battery status reports
+fload ${BP}/cpu/arm/olpc/1.75/boardrev.fth   \ Board revision decoding
 
 false constant tethered?                     \ We only support reprogramming our own FLASH
 
@@ -141,6 +140,8 @@
 : ofw-fw-filename$  " disk:\boot\olpc.rom"  ;
 ' ofw-fw-filename$ to fw-filename$
 
+fload ${BP}/cpu/arm/olpc/1.75/ecflash.fth
+
 0 0  " d420b000"  " /" begin-package
    " display" name
    fload ${BP}/cpu/arm/olpc/1.75/lcdcfg.fth
@@ -228,10 +229,6 @@
 
 devalias keyboard /ec-spi/keyboard
 
-fload ${BP}/dev/olpc/kb3700/eccmds.fth
-fload ${BP}/cpu/arm/olpc/1.75/ecflash.fth
-fload ${BP}/cpu/arm/olpc/1.75/boardrev.fth   \ Board revision decoding
-
 0 0  " d4208000"  " /" begin-package  \ USB Host Controller
    h# 200 constant /regs
    my-address my-space /regs reg

Added: dev/olpc/kb3700/batstat.fth
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dev/olpc/kb3700/batstat.fth	Fri Dec  3 07:35:59 2010	(r2062)
@@ -0,0 +1,253 @@
+: wextend  ( w -- n )  dup h# 8000 and  if  h# ffff.0000 or  then  ;
+\ Base unit for temperature is 1/256 degrees C
+: >degrees-c 7 rshift 1+ 2/  ;  \ Round to nearest degree 
+: uvolt@ bat-voltage@ d# 9760 d# 32 */ ;
+: cur@ bat-current@ wextend  d# 15625 d# 120 */ ;
+: pcb-temp ambient-temp@ >degrees-c  ;
+: bat-temp bat-temp@ >degrees-c  ;
+: soc     bat-soc@  ;
+
+string-array bat-causes
+( 00) ," "
+( 01) ," Bus Stuck at Zero"
+( 02) ," Pack info"
+( 03) ," NiMH Temp"
+( 04) ," NiMH Over Voltage"
+( 05) ," NiMH Over Current"
+( 06) ," NiMH No voltage change during use"
+( 07) ," "
+( 08) ," NiMH Pre-charge fail"
+( 09) ," No Battery ID"
+( 0a) ," LiFe Over Voltage"
+( 0b) ," LiFe Over Temp"
+( 0c) ," LiFe No voltage change during use"
+( 0d) ," "
+( 0e) ," "
+( 0f) ," "
+( 10) ," ACR error"
+( 11) ," NIMH 0xFF count"
+( 12) ," FF count"
+( 13) ," Voltage Invalid"
+( 14) ," Bank 0 Invalid"
+( 15) ," Bank 1 Invalid"
+( 16) ," Bank 2 Invalid"
+end-string-array
+
+: .bat-cause  ( -- )
+   bat-cause@ bat-causes count type cr
+;
+
+: .bat-error .bat-cause ;
+
+string-array bat-states
+  ," no-battery        "
+  ," charging-idle     "
+  ," charging-normal   "
+  ," charging-equalize "
+  ," charging-learning "
+  ," charging-temp-wait"
+  ," charging-full     "
+  ," discharge         "
+  ," abnormal: "
+  ," trickle           "
+end-string-array
+
+: .bat-type  ( -- )
+   bat-type@  dup 4 rshift  case   ( type )
+      0  of  ." "      endof
+      1  of  ." GPB "  endof
+      2  of  ." BYD "  endof
+      ." UnknownVendor "
+   endcase                         ( type )
+
+   h# 0f and  case                 ( )
+      0  of  ." "           endof
+      1  of  ." NiMH  "     endof
+      2  of  ." LiFePO4  "  endof
+      ." UnknownType  "
+   endcase
+;
+
+: .milli  ( -- )
+   push-decimal
+   dup abs  d# 10,000 /  <# u# u# [char] . hold u#s swap sign u#> type
+   pop-base
+;
+
+: .mppt-active?
+   mppt-active@ h# d and
+   if ." MPPT" then
+;
+
+\needs 2.d : 2.d  ( n -- )  push-decimal <# u# u#s u#>  type  pop-base  ;
+: .%  ( n -- )  2.d ." %" ;
+: .bat  ( -- )
+   bat-status@  ( stat )
+   ." AC:"  dup h# 10 and  if  ." on  "  else  ." off "  then  ( stat )
+
+\ PCB temp was nver really valid and was removed in Gen 1.5
+\   ." PCB: "  pcb-temp 2.d ." C "
+
+   dup h# 81 and  if
+      ." Battery: "
+      .bat-type
+      soc .%   ."  "
+      uvolt@  .milli  ." V "
+      cur@  .milli  ." A "
+      bat-temp 2.d ." C "
+      dup 2 and  if  ." full "  then
+      dup 4 and  if  ." low "  then
+      dup 8 and  if  ." error "  then
+      dup h# 20 and  if  ." charging "  then
+      dup h# 40 and  if  ." discharging "  then
+      dup h# 80 and  if  ." trickle  "  then
+   else
+      ." No battery "
+   then
+   drop
+   .mppt-active?
+;
+
+: ?enough-power  ( )
+   bat-status@                                    ( stat )
+   dup  h# 10 and  0=  abort" No external power"  ( stat )
+   dup  1 and  0=  abort" No battery"             ( stat )
+   4 and  abort" Battery low"  
+;
+: watch-battery  ( -- )
+   begin  (cr .bat kill-line  d# 1000 ms  key?  until
+   key drop
+   bat-status@ 8 and if cr .bat-error then
+;
+
+[ifndef] >sd.ddd
+: >sd.ddd  ( n -- formatted )
+   base @ >r  decimal
+   dup abs <# u# u# u# [char] . hold u# u#s swap sign u#>
+   r> base !
+;
+[then]
+
+: mppt-pct 255 * 100 / mppt-limit! ;
+
+: .mppt 
+   mppt-limit@            ( pwr_limit )
+   vin@                   ( pwr_limit VA2 )
+    ." Vsa: " d# 14927 * d# 158 / >sd.ddd type ."  PWM: " . 
+;
+
+: watch-mppt ( -- )
+   begin  (cr .mppt kill-line  d# 500 ms  key?  until
+   key drop
+;
+
+
+dev /
+new-device
+" battery" device-name
+0 0 reg  \ Needed so test-all will run the selftest
+
+\ Test that the battery is inserted and not broken.
+: test-battery  ( -- error? )
+   bat-status@ h# 01 and  0= if
+      ." Insert battery to continue.. "
+      begin  d# 100 ms  bat-status@ h# 01 and  until
+      cr
+   then
+   ." Testing battery status.. "
+   bat-status@ h# 04 and  if
+      ." error: battery broken" cr
+      true
+   else
+      ." ok: " cr .bat cr
+      false
+   then
+;
+
+: wait-no-ac  ( -- error? )
+   ." Disconnect AC power to continue.. "
+   begin
+      bat-status@ h# 10 and   ( ac-connected? )
+   while
+      d# 100 ms
+
+      key?  if
+         key  h# 1b =  if
+            ." ERROR: AC still connected" cr
+            true  exit
+         then
+      then
+   repeat
+   cr
+   false
+;
+
+\ Test that we can run without AC power.
+: test-discharging  ( -- error? )
+   bat-status@ h# 10 and  0<> if
+      wait-no-ac  if  true exit  then
+   then
+   ." Test running from battery.. "
+   d# 2000 ms
+   bat-status@ h# 40 and  if
+      ." ok: battery discharging" cr
+      false
+   else
+      ." ERROR: battery not discharging" cr
+      true
+   then
+;
+
+: wait-ac  ( -- error? )
+   ." Connect AC power to continue.. "
+   begin
+      bat-status@ h# 10 and  0=  ( ac-disconnected? )
+   while
+      d# 100 ms
+      
+      key?  if
+         key  h# 1b =  if
+            ." ERROR: AC not connected" cr
+            true  exit
+         then
+      then
+   repeat
+   cr
+   false
+;
+
+: test-charging  ( -- error? )
+   bat-status@ h# 10 and  0= if
+      wait-ac  if  true exit  then
+   then
+   ." Test running from AC.. "
+   d# 4000 ms
+   bat-status@ h# 40 and  0= if
+      ." ok: battery is not discharging" cr
+      false
+   else
+      ." ERROR: battery is discharging" cr
+      true
+   then
+;
+
+: interactive-test  ( -- error? )
+   test-battery      if  true exit  then
+   " test-station" $find  if  execute  else  2drop 0  then  ( station# )
+   1 <>   if                                 \ Skip this test in SMT
+      test-discharging  if  true exit  then
+   then
+   test-charging     if  true exit  then
+   false
+;
+
+: selftest  ( -- error? )
+   diagnostic-mode?  if
+      interactive-test
+   else
+      .bat false
+   then
+;
+
+finish-device
+device-end

Added: dev/olpc/kb3700/eccmdcom.fth
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dev/olpc/kb3700/eccmdcom.fth	Fri Dec  3 07:35:59 2010	(r2062)
@@ -0,0 +1,49 @@
+\ See license at end of file
+purpose: EC commands that are the same for all XO versions
+
+: 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@  ;
+
+: ec-abnormal@   ( -- b )  h# 1f ec-cmd-b@  ;
+
+: reset-ec       ( -- )    h# 28 ec-cmd  ;
+
+: autowack-on    ( -- )  1 h# 33 ec-cmd-b!  ;
+: autowack-off   ( -- )  0 h# 33 ec-cmd-b!  ;
+
+: mppt-active@   ( -- b )  h# 3d ec-cmd-b@  ;
+: mppt-limit@    ( -- b )  h# 3e ec-cmd-b!  ;
+: mppt-limit!    ( b -- )  h# 3f ec-cmd-b!  ;
+: mppt-off       ( -- )    h# 40 ec-cmd  ;
+: mppt-on        ( -- )    h# 41 ec-cmd  ;
+: vin@           ( -- b )  h# 42 ec-cmd-b@  ;
+
+\ 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/eccmds.fth
==============================================================================
--- dev/olpc/kb3700/eccmds.fth	Fri Dec  3 02:40:28 2010	(r2061)
+++ dev/olpc/kb3700/eccmds.fth	Fri Dec  3 07:35:59 2010	(r2062)
@@ -24,14 +24,11 @@
 : 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@  ;
+fload ${BP}/dev/olpc/kb3700/eccmdcom.fth  \ Common commands 
+
+\ Commands that are different for XO-1.75
+: board-id@      ( -- n )  h# 19 ec-cmd-w@  ;
+: bat-cause@     ( -- b )  h# 1f ec-cmd-b@  ;
 
 : (bat-gauge-id@)  ( -- sn0 .. sn7 )  0 8 h# 17 do-ec-cmd  ;
 : bat-gauge-id@  ( -- sn0 .. sn7 )
@@ -41,13 +38,11 @@
    too-many-retries
 ;
 
+: bat-type@  ( -- b )  h# 2c ec-cmd-b@  ;
 
-: board-id@  ( -- n )  h# 19 ec-cmd-w@  ;
-: reset-ec  ( -- )  h# 28 ec-cmd  ;
+: ec-wackup  ( ms -- )  lbsplit 4 0 h# 36 do-ec-cmd  ;
 
-: bat-type@  ( -- b )  h# 2c ec-cmd-b@  ;
-: autowack-on      ( -- )         1 33 ec-cmd-b! ;
-: autowack-off     ( -- )         0 33 ec-cmd-b! ;
+: bat-gauge@  ( -- w )  h# 4e ec-cmd-w@  ;
 
 : cscount-max  ( adr maxlen -- adr len )
    dup 0  ?do        ( adr maxlen )
@@ -61,8 +56,6 @@
    d# 16 cscount-max
 ;
 
-: bat-gauge@  ( -- w )  h# 4e ec-cmd-w@  ;
-
 : ec-echo  ( ... n -- ... )  dup h# 52 do-ec-cmd  ;
 
 : ec-date$  ( -- adr len )
@@ -74,29 +67,17 @@
    d# 16 cscount-max
 ;
 
-
-: mppt-active@  ( -- b )  h# 3d ec-cmd-b@  ;
-
-: bat-cause@  ( -- b )  h# 1f ec-cmd-b@  ;
-
-[ifdef] notdef
-#define CMD_SET_EC_WAKEUP_TIMER          0x36
+[ifdef] notdef  \ These commands are awaiting documentation on their interfaces
 #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_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 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

Modified: dev/olpc/kb3700/ecio.fth
==============================================================================
--- dev/olpc/kb3700/ecio.fth	Fri Dec  3 02:40:28 2010	(r2061)
+++ dev/olpc/kb3700/ecio.fth	Fri Dec  3 07:35:59 2010	(r2062)
@@ -170,13 +170,12 @@
    too-many-retries
 ;
 
-: 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@  ;
+fload ${BP}/dev/olpc/kb3700/eccmdcom.fth
+
+\ Commands that are specific to XO-1 and XO-1.5
+: write-protect-fw ( -- )  3 ec-cmd  ;
+: sci-queue@       ( -- b )  h# 84 ec-cmd-b@  ;
+
 : (bat-gauge-id@)  ( -- sn0 .. sn7 )  h# 17 ec-cmd-out  8 0  do ec-rb  loop  ;
 : bat-gauge-id@  ( -- sn0 .. sn7 )
    #ec-retries  0  do
@@ -184,22 +183,6 @@
    loop
    too-many-retries
 ;
-: (bat-gauge@)   ( -- b )  h# 18 ec-cmd-out  h# 31 ec-wb  ec-rb  ;  \ 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# 18 ec-cmd-out  h# 5f ec-wb  ec-rb  ;  \ 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@      ( -- b )  h# 19 ec-cmd-b@  ;
 : sci-source@    ( -- b )  h# 1a ec-cmd-b@  ;
 : sci-mask!      ( b -- )  h# 1b ec-cmd-b!  ;
@@ -214,10 +197,6 @@
    too-many-retries
 ;
 
-: ec-wackup   ( ms -- ) lbsplit h# 36 ec-cmd-out ec-wb ec-wb ec-wb ec-wb ;
-
-: ec-abnormal@   ( -- b )  h# 1f ec-cmd-b@  ;
-
 : bat-init-nimh-gp     ( -- )  h# 20 ec-cmd  ;
 : bat-init-lifepo4-byd ( -- )  h# 21 ec-cmd  ;
 : bat-init-lifepo4-gp  ( -- )  h# 22 ec-cmd  ;
@@ -229,23 +208,34 @@
 : dcon-power-off   ( -- )  0 h# 26 ec-cmd-b!  ;
 : dcon-power-on    ( -- )  1 h# 26 ec-cmd-b!  ;
 : reset-ec-warm    ( -- )  h# 27 ec-cmd  ;
-: reset-ec         ( -- )  h# 28 ec-cmd  ;
-: write-protect-fw ( -- )  3 ec-cmd  ;
 : ebook-mode?      ( -- b )  h# 2a ec-cmd-b@  ;
 : wlan-freeze      ( -- )  h# 35 ec-cmd  ;
-: sci-queue@       ( -- b )  h# 84 ec-cmd-b@  ;
-: ec-api-ver@      ( -- b )  h# 08 ec-cmd-b@  ;
-: sci-inhibit      ( -- )  h# 32 ec-cmd  ;
-: sci-uninhibit    ( -- )  h# 34 ec-cmd  ;
+: ec-wackup   ( ms -- ) lbsplit h# 36 ec-cmd-out ec-wb ec-wb ec-wb ec-wb ;
+
 
-: mppt-active@  ( -- b )  h# 3d ec-cmd-b@  ;
+: (bat-gauge@)   ( -- b )  h# 18 ec-cmd-out  h# 31 ec-wb  ec-rb  ;  \ 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# 18 ec-cmd-out  h# 5f ec-wb  ec-rb  ;  \ 5f is the EEPROM address
+: bat-type@  ( -- b )
+   #ec-retries  0  do
+      ['] (bat-type@) catch  0=  if  unloop exit  then
+   loop
+   too-many-retries
+;
 
-: autowack-on      ( -- )         1 33 ec-cmd-b! ;
-: autowack-off     ( -- )         0 33 ec-cmd-b! ;
 : autowack-delay   ( delay -- )   wbsplit f650 ec! f651 ec! ;
 
 : ec-indexed-io-off  ( -- )  h# fe95 ec@  h# 40 invert and  h# fe95 ec!  ;
 
+: sci-inhibit      ( -- )  h# 32 ec-cmd  ;
+: sci-uninhibit    ( -- )  h# 34 ec-cmd  ;
+
 0 [if]
 \ EC mailbox access words
 



More information about the openfirmware mailing list