Author: wmb Date: 2010-01-09 09:12:32 +0100 (Sat, 09 Jan 2010) New Revision: 1656
Modified: cpu/x86/build/builder.dic cpu/x86/pc/olpc/via/suspend.fth cpu/x86/pc/olpc/via/usb.fth dev/usb2/device/keyboard/kbd.fth dev/usb2/hcd/dev-info.fth dev/usb2/hcd/device.fth dev/usb2/hcd/uhci/probe.fth ofw/fcode/sysprims.fth Log: OLPC trac 9969 - more USB suspend/resume progress. USB 1.1 keyboards now work across suspend/resume, both directly-connected ones and ones behind hubs. The only missing piece is making it work with OHCI, which will have to wait.
Modified: cpu/x86/build/builder.dic =================================================================== (Binary files differ)
Modified: cpu/x86/pc/olpc/via/suspend.fth =================================================================== --- cpu/x86/pc/olpc/via/suspend.fth 2010-01-09 00:35:42 UTC (rev 1655) +++ cpu/x86/pc/olpc/via/suspend.fth 2010-01-09 08:12:32 UTC (rev 1656) @@ -45,13 +45,17 @@ s3 again ; -: s3-suspend +: s3-no-usb ( -- ) audio-ih if audio-ih close-dev 0 to audio-ih then " video-save" screen-ih $call-method \ Freeze display s3 " video-restore" screen-ih $call-method \ Unfreeze display -\ " /usb@f,5" open-dev ?dup if " do-resume" 2 pick $call-method close-dev then ; +: s3-suspend + suspend-usb + s3-no-usb + resume-usb +; alias s s3-suspend
\ LICENSE_BEGIN
Modified: cpu/x86/pc/olpc/via/usb.fth =================================================================== --- cpu/x86/pc/olpc/via/usb.fth 2010-01-09 00:35:42 UTC (rev 1655) +++ cpu/x86/pc/olpc/via/usb.fth 2010-01-09 08:12:32 UTC (rev 1656) @@ -61,19 +61,42 @@ ; alias p2 probe-usb
-: ?usb-keyboard ( -- ) +0 value usb-keyboard-ih + +: attach-usb-keyboard ( -- ) " usb-keyboard" expand-alias if ( devspec$ ) drop " /usb" comp 0= if ( ) - " usb-keyboard" open-dev add-input + " usb-keyboard" open-dev to usb-keyboard-ih + usb-keyboard-ih add-input exit then else ( devspec$ ) 2drop then +; + +: detach-usb-keyboard ( -- ) + usb-keyboard-ih if + usb-keyboard-ih remove-input + usb-keyboard-ih close-dev + 0 to usb-keyboard-ih + then +; + +: ?usb-keyboard ( -- ) + attach-usb-keyboard " /usb/serial" open-dev ?dup if add-input then ; +: suspend-usb ( -- ) + detach-usb-keyboard +; +: resume-usb ( -- ) + d# 300 ms \ USB misses devices if you probe too soon + silent-probe-usb + attach-usb-keyboard +;
\ Unlink every node whose phys.hi component matches port : port-match? ( port -- flag )
Modified: dev/usb2/device/keyboard/kbd.fth =================================================================== --- dev/usb2/device/keyboard/kbd.fth 2010-01-09 00:35:42 UTC (rev 1655) +++ dev/usb2/device/keyboard/kbd.fth 2010-01-09 08:12:32 UTC (rev 1656) @@ -325,6 +325,18 @@ true ;
+\ kbd-buf and led-buf must have been allocated +: setup-hardware ( -- ) + device set-target + configuration set-config if ." Failed to set USB keyboard configuration" cr then + set-boot-protocol if ." Failed to set USB keyboard boot protocol" cr then + \ Some USB keyboards don't implement set-idle properly, and it's not critical, + \ so we suppress the message to avoid confusing the user + idle-rate set-idle drop \ if ." Failed to set USB keyboard idle" cr then + 0 set-leds +; + + external
: install-abort ( -- ) true to check-abort? ; \ Check for break @@ -346,10 +358,11 @@ dup 0= if drop -2 then ( #read | -2 ) ;
+ : open ( -- flag ) kbd-refcount @ if 1 +refcnt true exit then - device set-target init-kbd-buf + setup-hardware noop \ Add noop so I can patch it before open normal-op? if unlock @@ -375,17 +388,8 @@
: init ( -- ) init - init-kbd-buf null-entry /qe erase key-state /key-state erase - device set-target - configuration set-config if ." Failed to set USB keyboard configuration" cr then - set-boot-protocol if ." Failed to set USB keyboard boot protocol" cr then - \ Some USB keyboards don't implement set-idle properly, and it's not critical, - \ so we suppress the message to avoid confusing the user - idle-rate set-idle drop \ if ." Failed to set USB keyboard idle" cr then - 0 set-leds - free-kbd-buf ;
headers
Modified: dev/usb2/hcd/dev-info.fth =================================================================== --- dev/usb2/hcd/dev-info.fth 2010-01-09 00:35:42 UTC (rev 1655) +++ dev/usb2/hcd/dev-info.fth 2010-01-09 08:12:32 UTC (rev 1656) @@ -22,7 +22,7 @@ 1 field >di-speed \ Device speed 1 field >di-hub \ Hub address (EHCI only) 1 field >di-port \ Port number (EHCI only) - 1 field >di-reset \ rest flag - 0 initially or after a resume, then 1 + 1 field >di-reset \ reset flag - 0 initially or after a resume, then 1 /di-ep-struct #max-endpoint * field >di-ep \ Endpoint structure constant /di-entry
Modified: dev/usb2/hcd/device.fth =================================================================== --- dev/usb2/hcd/device.fth 2010-01-09 00:35:42 UTC (rev 1655) +++ dev/usb2/hcd/device.fth 2010-01-09 08:12:32 UTC (rev 1656) @@ -158,7 +158,7 @@ ;
: make-ctrl-pipe-property ( pipe size interval -- ) - drop 2dup register-pipe ( pipe size ) + drop ( pipe size ) over h# f and rot h# 80 and if ( size pipe ) " control-in-pipe" int-property " control-in-size" @@ -168,7 +168,7 @@ then int-property ; : make-iso-pipe-property ( pipe size interval -- ) - drop 2dup register-pipe ( pipe size ) + drop ( pipe size ) over h# 0f and rot h# 80 and if ( size pipe ) " iso-in-pipe" int-property " iso-in-size" @@ -178,7 +178,7 @@ then int-property ; : make-bulk-pipe-property ( pipe size interval -- ) - drop 2dup register-pipe ( pipe size ) + drop ( pipe size ) over h# f and rot h# 80 and if ( size pipe ) " bulk-in-pipe" int-property " bulk-in-size" @@ -188,7 +188,6 @@ then int-property ; : make-intr-pipe-property ( pipe size interval -- ) - -rot 2dup register-pipe rot ( pipe size interval ) rot dup h# f and swap h# 80 and if ( size interval pipe ) " intr-in-pipe" int-property " intr-in-interval" int-property @@ -204,6 +203,7 @@ swap ENDPOINT find-desc swap 0 ?do ( adr' ) dup 2 + c@ ( adr pipe ) over 4 + le-w@ ( adr pipe size ) + 2dup register-pipe ( adr pipe size ) 2 pick 6 + c@ ( adr pipe size interval ) 3 pick 3 + c@ 3 and case ( adr pipe size interval type ) 0 of make-ctrl-pipe-property endof @@ -238,28 +238,48 @@ 0 0 2swap str-property ;
+\ Sets the di-maxpayload fields in the dev-info endpoint descriptor array +: reregister-pipes ( dev intf -- ) + cfg-desc-buf swap find-intf-desc ( dev adr ) + dup c@ over + swap 4 + c@ ( dev adr' #endpoints ) + swap ENDPOINT find-desc ( dev #endpoints adr' ) + swap 0 ?do ( dev adr' ) + dup 4 + le-w@ ( dev adr size ) + over 2 + c@ h# f and ( dev adr size pipe ) + 3 pick di-maxpayload! ( dev adr ) + dup c@ + ( dev adr' ) + loop 2drop ( ) +; + : be-l! ( n adr -- ) >r lbsplit r@ c! r@ 1+ c! r@ 2+ c! r> 3 + c! ;
: reuse-node ( dev intf port phandle -- ) - nip nip ( dev phandle ) -[ifdef] notdef - \ This is the kosher way to do it ... - push-package ( dev ) - 2drop ( dev ) - encode-int ( adr len ) - " assigned-address" property ( ) - pop-package ( ) -[else] ( dev phandle ) - \ But this way doesn't leak memory - " assigned-address" rot get-package-property if ( dev ) - drop ( ) - else ( dev adr len ) - drop be-l! ( ) - then ( ) -[then] + >r drop ( dev intf r: phandle ) + + 2dup reregister-pipes ( dev intf r: phandle ) + drop ( dev r: phandle ) + + \ Change the assigned-address property without leaking memory + " assigned-address" r@ get-package-property if ( dev r: phandle ) + drop ( r: phandle ) + else ( dev adr len r: phandle ) + drop be-l! ( r: phandle ) + then ( r: phandle ) + + " probe-hub" r@ find-method if ( xt r: phandle ) + r@ push-package ( xt r: phandle ) + " " new-instance ( xt r: phandle ) + set-default-unit ( xt r: phandle ) + execute ( r: phandle ) + destroy-instance ( r: phandle ) + pop-package ( r: phandle ) + then ( r: phandle ) + + r> drop ; + : reuse-old-node? ( dev intf port -- reused? ) my-self ihandle>phandle child ( dev intf port phandle ) begin ?dup while ( dev intf port phandle )
Modified: dev/usb2/hcd/uhci/probe.fth =================================================================== --- dev/usb2/hcd/uhci/probe.fth 2010-01-09 00:35:42 UTC (rev 1655) +++ dev/usb2/hcd/uhci/probe.fth 2010-01-09 08:12:32 UTC (rev 1656) @@ -53,6 +53,14 @@ pop-package ;
+: do-resume ( -- ) + init-struct + start-usb +; + +\ This is a sneaky way to determine if the hardware has been turned off without the software's knowledge +: suspended? ( -- flag ) flbaseadd@ 0= framelist-phys 0<> and ; + : open ( -- flag ) parse-my-args open-count 0= if @@ -61,10 +69,12 @@ false to first-open? ?disable-smis reset-usb - init-struct init-lists - start-usb + do-resume then + + suspended? if do-resume then + alloc-dma-buf
probe-root-hub
Modified: ofw/fcode/sysprims.fth =================================================================== --- ofw/fcode/sysprims.fth 2010-01-09 00:35:42 UTC (rev 1655) +++ ofw/fcode/sysprims.fth 2010-01-09 08:12:32 UTC (rev 1656) @@ -370,4 +370,8 @@ \ --- parsing argument strings v2 040 2 byte-code: left-parse-string ( adr len char -- adrR lenR adrL lenL )
+\ --- New FirmWorks stuff v3 041 2 byte-code: debug-me +v3 042 2 byte-code: new-instance ( args-adr args-len -- ) +v3 043 2 byte-code: destroy-instance ( -- ) +v3 044 2 byte-code: set-default-unit ( -- )
openfirmware@openfirmware.info