usb-core: adding generic dev-hci.fs

* Generic forth device file for [OEX]HCI controller.
* Routines to setup hcd structure

Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Signed-off-by: Avik Sil <aviksil@linux.vnet.ibm.com>
[ implmented generic hc-suspend for [oe]hci ]
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Acked-by: Thomas Huth <thuth@linux.vnet.ibm.com>
This commit is contained in:
Nikunj A Dadhania 2013-07-24 14:26:32 +05:30
parent c4ddc59f67
commit 7ef8498799
5 changed files with 171 additions and 11 deletions

View File

@ -45,7 +45,8 @@ FPPINCLUDES = -I. -I$(SLOFCMNDIR)/fs -I$(SLOFCMNDIR)
USB_FFS_FILES = \ USB_FFS_FILES = \
$(SLOFCMNDIR)/fs/devices/pci-class_02.fs \ $(SLOFCMNDIR)/fs/devices/pci-class_02.fs \
$(SLOFCMNDIR)/fs/devices/pci-class_0c.fs $(SLOFCMNDIR)/fs/devices/pci-class_0c.fs \
$(SLOFCMNDIR)/fs/usb/dev-hci.fs
VIO_FFS_FILES = \ VIO_FFS_FILES = \
$(SLOFBRDDIR)/pci-device_1af4_1000.fs \ $(SLOFBRDDIR)/pci-device_1af4_1000.fs \

View File

@ -124,6 +124,10 @@ d# 512000000 VALUE tb-frequency \ default value - needed for "ms" to work
3f0 cp 3f0 cp
#include "usb.fs"
400 cp
#include "tree.fs" #include "tree.fs"
800 cp 800 cp

31
board-qemu/slof/usb.fs Normal file
View File

@ -0,0 +1,31 @@
\ *****************************************************************************
\ * Copyright (c) 2006, 2012, 2013 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
\ *
\ * [OEX]HCI functions
\ *
\ ****************************************************************************
STRUCT
/n FIELD hcd>base
/n FIELD hcd>type
/n FIELD hcd>num
CONSTANT /hci-dev
: usb-setup-hcidev ( num hci-dev -- )
>r
s" 10 config-l@ translate-my-address 3 not AND" evaluate
( io-base ) r@ hcd>base !
s" 08 config-l@ 8 rshift 0000000F0 AND 4 rshift " evaluate
( usb-type ) r@ hcd>type !
( usb-num ) r@ hcd>num !
r> drop
;

100
slof/fs/usb/dev-hci.fs Normal file
View File

@ -0,0 +1,100 @@
\ *****************************************************************************
\ * Copyright (c) 2006, 2012, 2013 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
\ *
\ * [OEX]HCI functions
\ *
\ ****************************************************************************
\ ( num $name type )
VALUE usb_type \ USB type
\ Open Firmware Properties
2dup device-name
s" usb" device-type
rot
VALUE usb_num \ controller number
usb_num $cathex strdup \ create alias name
2dup find-alias 0= IF
get-node node>path set-alias
ELSE 3drop THEN
/hci-dev BUFFER: hcidev
usb_num hcidev usb-setup-hcidev
false VALUE dev-hci-debug?
: get-base-address ( -- baseaddr )
hcidev hcd>base @
;
get-base-address CONSTANT baseaddrs
1 encode-int s" #address-cells" property
0 encode-int s" #size-cells" property
\ converts physical address to text unit string
: encode-unit ( port -- unit-str unit-len ) 1 hex-encode-unit ;
\ Converts text unit string to phyical address
: decode-unit ( addr len -- port ) 1 hex-decode-unit ;
: get-hci-dev ( -- hcidev )
hcidev
;
0 VALUE open-count
: USB-HCI-INIT drop 1 ;
: USB-HCI-EXIT drop 1 ;
: open ( -- true | false )
dev-hci-debug? IF ." DEV-HCI: Opening (count is " open-count . ." )" cr THEN
open-count 0= IF
hcidev USB-HCI-INIT 0= IF
." HCI Device setup failed " pwd cr
false EXIT
THEN
THEN
open-count 1 + to open-count
true
;
: close
dev-hci-debug? IF ." DEV-HCI: Closing (count is " open-count . ." )" cr THEN
open-count 0> IF
open-count 1 - dup to open-count
0= IF
hcidev USB-HCI-EXIT drop
THEN
THEN
;
\ set HCI into suspend mode
\ this disables all activities to shared RAM
\ called when linux starts (quiesce)
: hc-suspend ( -- )
hcidev hcd>type @ dup 1 = IF
00C3 baseaddrs 4 + rl!-le \ Suspend OHCI controller
THEN
2 = IF
baseaddrs dup c@ + rl@-le FFFFFFFE and
baseaddrs dup c@ + rl!-le \ Stop EHCI controller
ELSE
drop
THEN
;
\ create a new entry to suspend HCI
' hc-suspend add-quiesce-xt

View File

@ -10,11 +10,9 @@
\ * IBM Corporation - initial implementation \ * IBM Corporation - initial implementation
\ ****************************************************************************/ \ ****************************************************************************/
\ register device alias \ Load dev hci
: do-alias-setting ( num name-str name-len ) : load-dev-hci ( num name-str name-len )
rot $cathex strdup \ create alias name s" dev-hci.fs" INCLUDED
get-node node>path \ get path string
set-alias \ and set the alias
; ;
0 VALUE ohci-alias-num 0 VALUE ohci-alias-num
@ -24,24 +22,50 @@
\ create a new ohci device alias for the current node \ create a new ohci device alias for the current node
: set-ohci-alias ( -- ) : set-ohci-alias ( -- )
ohci-alias-num dup 1+ TO ohci-alias-num ( num ) ohci-alias-num dup 1+ TO ohci-alias-num ( num )
s" ohci" do-alias-setting s" ohci" 1 load-dev-hci
; ;
\ create a new ehci device alias for the current node \ create a new ehci device alias for the current node
: set-ehci-alias ( -- ) : set-ehci-alias ( -- )
ehci-alias-num dup 1+ TO ehci-alias-num ( num ) ehci-alias-num dup 1+ TO ehci-alias-num ( num )
s" ehci" do-alias-setting s" ehci" 2 load-dev-hci
; ;
\ create a new xhci device alias for the current node \ create a new xhci device alias for the current node
: set-xhci-alias ( -- ) : set-xhci-alias ( -- )
xhci-alias-num dup 1+ TO xhci-alias-num ( num ) xhci-alias-num dup 1+ TO xhci-alias-num ( num )
s" xhci" do-alias-setting s" xhci" 3 load-dev-hci
;
: usb-enumerate ( hcidev -- )
drop
; ;
: usb-scan ( -- ) : usb-scan ( -- )
." Scanning USB " cr ." Scanning USB " cr
ohci-alias-num 1 >= IF ohci-alias-num 1 >= IF
USB-OHCI-REGISTER USB-OHCI-REGISTER
then THEN
;
ohci-alias-num 0 ?DO
" ohci" i $cathex find-device
" get-hci-dev" get-node find-method
IF
execute usb-enumerate
ELSE
." get-base-address method not found for ohci" i . cr
THEN
LOOP
ehci-alias-num 0 ?DO
" ehci" i $cathex find-device
" get-hci-dev" get-node find-method
IF
execute usb-enumerate
ELSE
." get-base-address method not found for ehci" i . cr
THEN
LOOP
0 set-node \ FIXME Setting it back
;