aboutsummaryrefslogtreecommitdiff
path: root/slof/fs/usb/usb-static.fs
blob: 0067549541e9f20ff9a68515653e3bc1cee784ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
\ *****************************************************************************
\ * Copyright (c) 2004, 2007 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
\ ****************************************************************************/

\ Set usb-debug flag to TRUE for debugging output:
0 VALUE usb-debug-flag
0 VALUE usb-test-flag

\ Print a debug message when usb-debug-flag is set
: usb-debug-print  ( str len -- )
   usb-debug-flag  IF type cr ELSE 2drop THEN
;

\ Print a debug message with corresponding value when usb-debug-flag is set
: usb-debug-print-val  ( str len val -- )
   usb-debug-flag  IF -ROT type . cr ELSE drop 2drop THEN
;


0 VALUE ohci-alias-num

\ create a new ohci device alias for the current node:
: set-ohci-alias  ( -- )
   ohci-alias-num dup 1+ TO ohci-alias-num    ( num )
   s" ohci" rot $cathex strdup   \ create alias name
   get-node node>path            \ get path string
   set-alias                     \ and set the alias
;

0 VALUE cdrom-alias-num

\ create a new ohci device alias for the current node:
: set-cdrom-alias  ( --  )
   cdrom-alias-num dup 1+ TO cdrom-alias-num    ( num )
   s" cdrom" rot $cathex strdup   \ create alias name
   get-node node>path            \ get path string
   set-alias                     \ and set the alias
;

: usb-create-alias-name ( num -- str len )
    >r s" ohciX" 2dup + 1-           ( str len last-char-ptr  R: num )
    r> [char] 0 + swap c!            ( str len  R: )
;
    
\ Scan all USB host controllers for attached devices:
: usb-scan
   \ Scan all OHCI chips:
   ." Scan USB... " cr 
   0 >r                             \ Counter for alias
   BEGIN
      r@ usb-create-alias-name
      find-alias ?dup               ( false | str len len  R: num )
   WHILE
      usb-debug-flag IF
         ." * Scanning hub " 2dup type ." ..." cr
      THEN
      open-dev ?dup IF              ( ihandle  R: num )
         dup to my-self
         dup ihandle>phandle dup set-node
          child ?dup IF
              delete-node s" Deleting node" usb-debug-print
          THEN
         >r s" enumerate" r@ $call-method   \ Scan host controller
         r> close-dev  0 set-node 0 to my-self
      THEN                          ( R: num )
      r> 1+ >r                      ( R: num+1 )
   REPEAT   r> drop
   0 TO ohci-alias-num
   0 TO cdrom-alias-num
   s" cdrom0" find-alias            ( false | dev-path len )
   dup IF
       s" cdrom" 2swap              ( alias-name len' dev-path len )
       set-alias                    ( -- )
   ELSE 
       drop                         ( -- )
   THEN
;