Author: wmb
Date: Tue Nov 30 21:50:14 2010
New Revision: 2052
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2052
Log:
OLPC XO-1.75 - Omnibus checkin:
a) Fix memory available size problem that prevented Linux from booting on Q4A06
b) New touchpad diagnostic that omits all the old ALPS complexity, and works well
c) Support EC version commands
Added:
dev/olpc/touchpad/syntpad.fth
Modified:
cpu/arm/linux.fth
cpu/arm/olpc/1.75/devices.fth
cpu/arm/olpc/1.75/fw.bth
cpu/x86/adpcm.fth
cpu/x86/pc/olpc/sound.fth
dev/olpc/kb3700/eccmds.fth
dev/olpc/kb3700/spicmd.fth
Modified: cpu/arm/linux.fth
==============================================================================
--- cpu/arm/linux.fth Fri Nov 26 00:05:18 2010 (r2051)
+++ cpu/arm/linux.fth Tue Nov 30 21:50:14 2010 (r2052)
@@ -1,7 +1,8 @@
\ See license at end of file
purpose: ARM Linux zImage program loading
-defer linux-hook ' noop to linux-hook
+defer linux-hook ' noop to linux-hook
+defer linux-pre-hook ' noop to linux-pre-hook
0 value ramdisk-adr
0 value /ramdisk
@@ -170,7 +171,8 @@
init-program
linux-loaded? if
['] linux-place-ramdisk to place-ramdisk
- memory-limit to linux-memtop \ load-ramdisk may change this
+ linux-pre-hook
+ memory-limit 1meg round-down to linux-memtop \ load-ramdisk may change this
['] load-ramdisk guarded
linux-fixup
then
Modified: cpu/arm/olpc/1.75/devices.fth
==============================================================================
--- cpu/arm/olpc/1.75/devices.fth Fri Nov 26 00:05:18 2010 (r2051)
+++ cpu/arm/olpc/1.75/devices.fth Tue Nov 30 21:50:14 2010 (r2052)
@@ -290,10 +290,9 @@
" SN" find-tag if 1- else " Unknown" then " serial-number" string-property
[ifdef] notyet
ec-api-ver@ " ec-version" integer-property
-
- XXX Get EC name with an EC command
- " ec-name" string-property
[then]
+
+ ec-name$ " ec-name" string-property
dend
" /openprom" find-device
Modified: cpu/arm/olpc/1.75/fw.bth
==============================================================================
--- cpu/arm/olpc/1.75/fw.bth Fri Nov 26 00:05:18 2010 (r2051)
+++ cpu/arm/olpc/1.75/fw.bth Tue Nov 30 21:50:14 2010 (r2052)
@@ -150,7 +150,7 @@
0 value final-test? \ !!!
fload ${BP}/cpu/x86/pc/olpc/disptest.fth
fload ${BP}/dev/olpc/keyboard/selftest.fth \ Keyboard diagnostic
-fload ${BP}/dev/olpc/touchpad/touchpad.fth \ Touchpad diagnostic
+fload ${BP}/dev/olpc/touchpad/syntpad.fth \ Touchpad diagnostic
fload ${BP}/cpu/x86/pc/olpc/gridmap.fth \ Gridded display tools
fload ${BP}/cpu/x86/pc/olpc/via/copynand.fth
@@ -187,6 +187,12 @@
fload ${BP}/cpu/x86/pc/olpc/sound.fth
fload ${BP}/cpu/x86/pc/olpc/security.fth
+: pre-setup-for-linux ( -- )
+ [ ' linux-pre-hook behavior compile, ] \ Chain to old behavior
+ sound-end
+;
+' pre-setup-for-linux to linux-pre-hook
+
[ifdef] notyet
create use-thinmac
fload ${BP}/cpu/x86/bootascall.fth
@@ -381,6 +387,9 @@
\ " wifi media lab 802.11" eval
\ " flash http:\\18.85.46.172\new.rom" eval
;
+: newec
+ " flash-ec http:\\10.20.0.14\ecimage.bin" eval
+;
: urom " flash! u:\new.rom" eval ;
: erom " flash! ext:\new.rom" eval ;
: no-usb-delay " dev /usb false to delay? dend" evaluate ;
Modified: cpu/x86/adpcm.fth
==============================================================================
--- cpu/x86/adpcm.fth Fri Nov 26 00:05:18 2010 (r2051)
+++ cpu/x86/adpcm.fth Tue Nov 30 21:50:14 2010 (r2052)
@@ -323,11 +323,15 @@
false ( error? )
;
-: (play-wav) ( adr -- error? )
+: free-wav ( -- )
pcm-base if
pcm-base /pcm-output " dma-free" $call-audio
0 to pcm-base
then
+;
+
+: (play-wav) ( adr -- error? )
+ free-wav
parse-wav-ok? not if ." Not a .wav file" cr true exit then
audio-ih 0= if
Modified: cpu/x86/pc/olpc/sound.fth
==============================================================================
--- cpu/x86/pc/olpc/sound.fth Fri Nov 26 00:05:18 2010 (r2051)
+++ cpu/x86/pc/olpc/sound.fth Tue Nov 30 21:50:14 2010 (r2052)
@@ -39,9 +39,11 @@
;
: sound-end ( -- )
" wait-sound" ['] $call-audio catch if 2drop then
+ free-wav
;
: stop-sound ( -- )
" stop-sound" ['] $call-audio catch if 2drop then
+ free-wav
;
\ LICENSE_BEGIN
Modified: dev/olpc/kb3700/eccmds.fth
==============================================================================
--- dev/olpc/kb3700/eccmds.fth Fri Nov 26 00:05:18 2010 (r2051)
+++ dev/olpc/kb3700/eccmds.fth Tue Nov 30 21:50:14 2010 (r2052)
@@ -4,7 +4,10 @@
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"
+ " ec-command" $call-ec
+;
+: do-ec-cmd-buf ( [ args ] #args #results cmd-code -- buf-adr )
+ " ec-command-buf" $call-ec
;
stand-init: EC
" /ec-spi" open-dev to ec-ih
@@ -46,6 +49,18 @@
: autowack-on ( -- ) 1 33 ec-cmd-b! ;
: autowack-off ( -- ) 0 33 ec-cmd-b! ;
+: cscount-max ( adr maxlen -- adr len )
+ dup 0 ?do ( adr maxlen )
+ over i + c@ 0= if
+ drop i unloop exit
+ then
+ loop
+;
+: ec-name$ ( -- adr len )
+ 0 d# 16 h# 4a do-ec-cmd-buf ( adr )
+ d# 16 cscount-max
+;
+
: bat-gauge@ ( -- w ) h# 4e ec-cmd-w@ ;
: ec-echo ( ... n -- ... ) dup h# 52 do-ec-cmd ;
Modified: dev/olpc/kb3700/spicmd.fth
==============================================================================
--- dev/olpc/kb3700/spicmd.fth Fri Nov 26 00:05:18 2010 (r2051)
+++ dev/olpc/kb3700/spicmd.fth Tue Nov 30 21:50:14 2010 (r2052)
@@ -50,24 +50,49 @@
\ 5 Event
\ 6 EC Debug
-5 constant #ports
-#ports /n* buffer: port-data
-: init-queue ( -- ) port-data #ports /n* bounds ?do -1 i ! /n +loop ;
-: enque ( data channel# -- )
- 2- ( data queue# )
- dup #ports >= if 2drop exit then
- port-data swap na+ ! ( data adr )
-;
-: deque? ( channel# -- false | data true )
- 2- ( queue# )
- port-data swap na+ ( adr )
- dup @ ( adr data )
- dup -1 = if ( adr data )
- 2drop false ( false )
- else ( adr data )
- -1 rot ! ( data )
- true ( data true )
+6 constant #ports
+#ports 2- constant #queues
+
+d# 16 constant /q
+
+0 value queue#
+#queues /n* buffer: heads : head ( -- adr ) heads queue# na+ ;
+#queues /n* buffer: tails : tail ( -- adr ) tails queue# na+ ;
+
+#queues /q * buffer: qs : q ( adr -- ) qs queue# /q * + ;
+
+/q 1- value q-end
+
+: init-queues ( -- )
+ #queues 0 do
+ i to queue#
+ 0 head ! 0 tail ! /q 1- to q-end
+ loop
+;
+: inc-q-ptr ( pointer-addr -- )
+ dup @ q-end >= if 0 swap ! else /c swap +! then
+;
+
+: select-queue ( channel# -- error? )
+ 2- to queue#
+ queue# #queues >=
+;
+
+: enque ( new-entry channel# -- )
+ select-queue if drop exit then ( new-entry )
+ tail @ head @ 2dup > if - q-end else 1- then ( new-entry tail head )
+ <> if q tail @ ca+ c! tail inc-q-ptr else drop then
+;
+
+: deque? ( channel# -- false | entry true )
+ select-queue if false exit then
+ lock[
+ head @ tail @ <> if
+ q head @ ca+ c@ head inc-q-ptr true
+ else
+ false
then
+ ]unlock
;
h# d4037000 value ssp-base \ Default to SSP3
@@ -258,7 +283,7 @@
init-gpios
init-ssp-in-slave-mode
rxflush
- init-queue
+ init-queues
clr-cmd
prime-fifo
clr-ack \ Tell EC that it is okay to send
@@ -357,23 +382,22 @@
true abort" EC command result timeout"
;
-: get-results ( -- [ results ] )
- ec-respbuf #results bounds ?do
- timed-get-results i c!
- loop
+: ec-command-buf ( [ args ] #args #results cmd-code -- result-buf-adr )
+ 0 set-cmdbuf ( )
- #results 0 ?do \ XXX maybe this loop should go backwards?
- ec-respbuf i + c@
- loop
-;
-: ec-command ( [ args ] #args #results cmd-code -- [ results ] error? )
- 0 set-cmdbuf
+ ec-cmdbuf 8 false no-data-command ( )
- ec-cmdbuf 8 false no-data-command
+ ec-respbuf #results bounds ?do ( )
+ timed-get-results i c! ( )
+ loop ( )
- get-results
- false
+ ec-respbuf ( result-buf-adr )
;
+: ec-command ( [ args ] #args #results cmd-code -- [ results ] )
+ ec-command-buf ( result-buf-adr )
+ #results bounds ?do i c@ loop ( [ results ] )
+;
+
: put-data ( byte -- )
1 0
port# case
@@ -381,7 +405,7 @@
4 of h# 47 endof
( default ) 3drop exit
endcase ( byte #args #results cmd )
- ec-command drop
+ ec-command
;
: put-get-data ( cmd -- data | -1 ) put-data get-data ;
Added: dev/olpc/touchpad/syntpad.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/olpc/touchpad/syntpad.fth Tue Nov 30 21:50:14 2010 (r2052)
@@ -0,0 +1,304 @@
+\ See license at end of file
+\ Add this code to the existing mouse driver
+dev /mouse
+
+variable 'get-data 'get-data off
+variable 'get-data? 'get-data? off
+
+: setup ( -- )
+ 'get-data @ 0= if
+ " get-data" my-parent ihandle>phandle find-method if
+ 'get-data !
+ then
+ then
+ 'get-data? @ 0= if
+ " get-data?" my-parent ihandle>phandle find-method if
+ 'get-data? !
+ then
+ then
+;
+
+
+h# f800 constant red
+h# 07e0 constant green
+h# 001f constant blue
+h# ffe0 constant yellow
+h# f81f constant magenta
+h# 07ff constant cyan
+h# ffff constant white
+h# 0000 constant black
+
+variable pixcolor
+
+h# 4 value y-offset
+0 value screen-w
+0 value screen-h
+0 value /line
+2 value /pixel
+
+
+\ This program depends on the following routines from the
+\ existing Open Firmware mouse driver:
+
+\ open initializes the port and resets the device
+\ cmd sends a command byte and waits for the ack
+\ read1 reads 1 response byte
+\ read2 reads 2 response bytes
+\ mouse1:1 command e6
+\ mouse2:1 command e7
+\ stream-on command f4
+\ stream-off command f5
+\ mouse-status command e9 and reads 3 response bytes
+\ set-resolution command e8 then sends another command byte
+\ get-data? reads a data byte if one is available
+\ get-data waits for and reads a data byte
+
+
+variable ptr
+0 value show-raw?
+
+\ Runs the special Device ID command and checks for the ALPS return code
+\ Ref: 5.2.10 (1) of Hybrid-GP2B-T-1.pdf
+
+\ The Synaptics touchpad version is 64.02.30
+
+: touchpad-id ( -- n )
+ mouse2:1 mouse2:1 mouse2:1 mouse-status ( 30 02 64 )
+ 0 bljoin
+;
+
+\ Put the device into advanced mode and enable it
+: start ( -- )
+ setup
+ stream-mode
+;
+
+\ The normal mouse driver uses remote mode, but this device
+\ doesn't support remote mode, so patch the mouse driver
+\ "open" routine to substitute "noop" for "remote-mode".
+
+patch start remote-mode open
+
+\ The following code receives and decodes touchpad packets in the
+\ various special formats
+
+: show-packets ( adr len -- )
+ push-hex
+ bounds ?do
+ i 6 bounds ?do i c@ 3 u.r loop cr
+ 6 +loop
+ pop-base
+;
+: last-10 ( -- )
+ ptr @ load-base - d# 60 > if
+ ptr @ d# 60 - d# 60
+ else
+ load-base ptr @ over -
+ then
+ show-packets
+;
+
+variable mouse-x
+variable mouse-y
+
+: mouse-xy ( -- x y ) mouse-x @ mouse-y @ ;
+
+: clipx ( delta -- x ) mouse-x @ + 0 max screen-w 1- min dup mouse-x ! ;
+: clipy ( delta -- y ) mouse-y @ + 0 max screen-h 1- min dup mouse-y ! ;
+
+: rel>abs ( dy dy buttons -- x y buttons )
+ >r ( dx dy )
+ swap clipx swap negate clipy ( x y )
+ r> ( buttons )
+;
+
+\ Try to receive a GS-format packet. If one arrives within
+\ 20 milliseconds, return true and the decoded information.
+\ Otherwise return false.
+: pad? ( -- false | x y buttons true )
+ stream-poll? if ( dx dy buttons )
+ rel>abs true
+ else
+ false
+ then
+;
+
+\ Switch the device to glide format and display
+\ the data that it sends. Stop when a key is typed.
+: show-pad ( -- )
+ start
+ begin
+ pad? if . . . cr then
+ key? until
+;
+
+: button ( color x -- )
+ screen-h d# 50 - d# 200 d# 30 fill-rectangle-noff
+;
+d# 300 d# 300 2constant target-wh
+: left-target ( -- x y w h ) 0 0 target-wh ;
+: right-target ( -- x y w h ) screen-w screen-h target-wh xy- target-wh ;
+false value left-hit?
+false value right-hit?
+: inside? ( mouse-x,y x y w h -- flag )
+ >r >r ( mouse-x mouse-y x y r: h w )
+ xy- ( dx dy )
+ swap r> u< ( dy x-inside? )
+ swap r> u< ( x-inside? y-inside? )
+ and ( flag )
+;
+
+: draw-left-target ( -- ) green left-target fill-rectangle-noff ;
+: draw-right-target ( -- ) red right-target fill-rectangle-noff ;
+: ?hit-target ( but -- but )
+ dup 1 and if \ Left ( but )
+ mouse-xy left-target inside? if ( but )
+ yellow left-target fill-rectangle-noff ( but )
+ true to left-hit? ( but )
+ exit
+ then ( but )
+ then ( but )
+ dup 4 and if \ Right ( but )
+ mouse-xy right-target inside? if ( but )
+ yellow right-target fill-rectangle-noff ( but )
+ true to right-hit? ( but )
+ exit
+ then ( but )
+ then ( but )
+;
+
+: track-init ( -- )
+ " dimensions" $call-screen to screen-h to screen-w
+ screen-w 2/ mouse-x ! screen-h 2/ mouse-y !
+ screen-ih package( bytes/line )package to /line
+ load-base ptr !
+;
+
+: dot ( x y -- )
+ swap screen-w 3 - min swap y-offset + screen-h 3 - min ( x' y' )
+ pixcolor @ -rot 3 3 ( color x y w h )
+ fill-rectangle-noff ( )
+;
+
+: background ( -- )
+ black 0 0 screen-w screen-h fill-rectangle-noff
+ final-test? if
+ false to left-hit?
+ false to right-hit?
+ draw-left-target
+ draw-right-target
+ else
+ 0 d# 27 at-xy ." Touchpad test. Both buttons clears screen. Type a key to exit" cr
+ then
+ mouse-xy dot
+;
+
+: track ( x y buttons -- )
+ cyan pixcolor ! ( x y but )
+
+ dup 5 and 5 = if background load-base ptr ! then
+
+ final-test? if ( x y but )
+ ?hit-target ( x y but )
+ else ( x y but )
+ dup 1 and if green else black then d# 100 button
+ dup 4 and if red else black then d# 350 button ( x y but )
+ then ( x y but )
+ drop ( x y )
+
+ dot
+;
+
+: handle-key ( -- exit? )
+ key upc case
+ [char] P of
+ cursor-on
+ cr last-10
+ key drop
+ background
+ false
+ endof
+
+ [char] S of suspend stream-on false endof
+
+ ( key ) true swap
+ endcase
+;
+
+false value selftest-failed? \ Success/failure flag for final test mode
+: exit-test? ( -- flag )
+ final-test? if ( )
+ \ If the targets have been hit, we exit with successa
+ left-hit? right-hit? and if ( )
+ false to selftest-failed? ( )
+ true ( flag )
+ exit
+ then ( )
+
+ \ Otherwise we give the tester a chance to bail out by typing a key,
+ \ thus indicating failure
+ key? 0= if false exit then ( )
+ key drop ( )
+ true to selftest-failed? ( )
+ true ( flag )
+ exit
+ then ( )
+
+ \ If not final test mode, we only exit via a key - no targets
+ key? if handle-key else false then ( exit ? )
+;
+: selftest ( -- error? )
+ open 0= if ." PS/2 Mouse (trackpad) open failed" true exit then
+
+ \ Being able to open the touchpad is good enough in SMT mode
+ smt-test? if close false exit then
+
+ final-test? 0= if
+ ." Touchpad test will start in 4 seconds" cr
+ d# 4000 ms
+ then
+
+ cursor-off track-init start
+
+ \ Consume already-queued keys to prevent premature exit
+ begin key? while key drop repeat
+
+ background
+ begin
+ ['] pad? catch ?dup if .error close true exit then
+ if track then
+ exit-test? until
+
+ close
+ cursor-on
+ page
+ final-test? if selftest-failed? else false then
+;
+
+\ We are finished adding code to the mouse driver.
+\ Go back to the main forth context
+device-end
+
+\ 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