Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: ohci.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)ohci.fth 1.1 07/01/22 | |
43 | purpose: Driver for OHCI USB Controller | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | \ See license at end of file | |
46 | ||
47 | hex | |
48 | headers | |
49 | ||
50 | defer end-extra ' noop to end-extra | |
51 | ||
52 | \ Configuration space registers | |
53 | my-address my-space encode-phys | |
54 | 0 encode-int encode+ 0 encode-int encode+ | |
55 | \ OHCI operational registers | |
56 | 0 0 my-space 0200.0010 + encode-phys encode+ | |
57 | 0 encode-int encode+ 1000 encode-int encode+ | |
58 | ||
59 | " reg" property | |
60 | ||
61 | 1 constant potpgt \ PowerONToPowerGoodTime | |
62 | ||
63 | true value first-open? | |
64 | 0 value open-count | |
65 | 0 value ohci-reg | |
66 | ||
67 | : map-regs ( -- ) | |
68 | 4 my-w@ 6 or 4 my-w! | |
69 | 0 0 my-space h# 0200.0010 + 1000 map-in to ohci-reg | |
70 | ; | |
71 | ||
72 | : unmap-regs ( -- ) | |
73 | ohci-reg 1000 map-out 0 to ohci-reg | |
74 | ; | |
75 | ||
76 | : ohci-reg@ ( idx -- data ) ohci-reg + rl@ ; | |
77 | : ohci-reg! ( data idx -- ) ohci-reg + rl! ; | |
78 | ||
79 | : hc-cntl@ ( -- data ) 4 ohci-reg@ ; | |
80 | : hc-cntl! ( data -- ) 4 ohci-reg! ; | |
81 | : hc-stat@ ( -- data ) 8 ohci-reg@ ; | |
82 | : hc-cmd! ( data -- ) 8 ohci-reg! ; | |
83 | : hc-intr@ ( -- data ) c ohci-reg@ ; | |
84 | : hc-intr! ( data -- ) c ohci-reg! ; | |
85 | : hc-hcca@ ( -- data ) 18 ohci-reg@ ; | |
86 | : hc-hcca! ( data -- ) 18 ohci-reg! ; | |
87 | ||
88 | : hc-rh-desA@ ( -- data ) 48 ohci-reg@ ; | |
89 | : hc-rh-desA! ( data -- ) 48 ohci-reg! ; | |
90 | : hc-rh-desB@ ( -- data ) 4c ohci-reg@ ; | |
91 | : hc-rh-desB! ( data -- ) 4c ohci-reg! ; | |
92 | : hc-rh-stat@ ( -- data ) 50 ohci-reg@ ; | |
93 | : hc-rh-stat! ( data -- ) 50 ohci-reg! ; | |
94 | ||
95 | : hc-rh-psta@ ( port -- data ) 4 * 54 + ohci-reg@ ; | |
96 | : hc-rh-psta! ( data port -- ) 4 * 54 + ohci-reg! ; | |
97 | ||
98 | : hc-cntl-clr ( bit-mask -- ) hc-cntl@ swap invert and hc-cntl! ; | |
99 | : hc-cntl-set ( bit-mask -- ) hc-cntl@ swap or hc-cntl! ; | |
100 | ||
101 | : reset-usb ( -- ) | |
102 | 1 hc-rh-stat! \ power-off root hub | |
103 | 1 hc-cmd! \ reset usb host controller | |
104 | 10 ms | |
105 | ; | |
106 | ||
107 | : init-ohci-regs ( -- ) | |
108 | hcca-phys hc-hcca! \ physical address of hcca | |
109 | ||
110 | 81 hc-cntl! \ USB operational, 2:1 ControlBulkServiceRatio | |
111 | d# 10 ms | |
112 | ||
113 | a668.2edf 34 \ HcFmInterval | |
114 | ||
115 | \ Sometimes the HcFmInterval register will not hold it's value | |
116 | \ after the first write. This was seen primarily on the ULI 1575 | |
117 | \ controller, but also reported on the 1535+. | |
118 | \ Loop on the write to ensure it has completed. | |
119 | d# 10 0 do | |
120 | 2dup ohci-reg! | |
121 | 2dup ohci-reg@ = if | |
122 | leave | |
123 | then | |
124 | d# 10 ms | |
125 | loop | |
126 | ohci-reg@ <> if | |
127 | cmn-error[ " Unable to write to HcFmInterval Register" ]cmn-end | |
128 | then | |
129 | ||
130 | 2580 40 ohci-reg! \ HcPeriodicStart | |
131 | ; | |
132 | ||
133 | : (process-hc-status) ( -- ) | |
134 | hc-intr@ dup hc-intr! | |
135 | h# 10 and if " Unrecoverable error" USB_ERR_HCHALTED set-usb-error then | |
136 | ; | |
137 | ' (process-hc-status) to process-hc-status | |
138 | ||
139 | : wait-for-frame ( -- ) begin hc-intr@ 4 and until ; | |
140 | : next-frame ( -- ) 4 hc-intr! wait-for-frame ; | |
141 | ||
142 | external | |
143 | \ Kick the USB controller into operation mode. | |
144 | : start-usb ( -- ) c0 hc-cntl-clr 80 hc-cntl-set ; | |
145 | : suspend-usb ( -- ) c0 hc-cntl-set ; | |
146 | ||
147 | : open ( -- flag ) | |
148 | parse-my-args | |
149 | open-count 0= if | |
150 | map-regs | |
151 | first-open? if | |
152 | false to first-open? | |
153 | reset-usb | |
154 | init-struct | |
155 | init-ohci-regs | |
156 | then | |
157 | alloc-dma-buf | |
158 | then | |
159 | open-count 1+ to open-count | |
160 | true | |
161 | ; | |
162 | ||
163 | : close ( -- ) | |
164 | open-count 1- to open-count | |
165 | end-extra | |
166 | open-count 0= if free-dma-buf unmap-regs then | |
167 | ; | |
168 | ||
169 | headers | |
170 | ||
171 | \ LICENSE_BEGIN | |
172 | \ Copyright (c) 2006 FirmWorks | |
173 | \ | |
174 | \ Permission is hereby granted, free of charge, to any person obtaining | |
175 | \ a copy of this software and associated documentation files (the | |
176 | \ "Software"), to deal in the Software without restriction, including | |
177 | \ without limitation the rights to use, copy, modify, merge, publish, | |
178 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
179 | \ permit persons to whom the Software is furnished to do so, subject to | |
180 | \ the following conditions: | |
181 | \ | |
182 | \ The above copyright notice and this permission notice shall be | |
183 | \ included in all copies or substantial portions of the Software. | |
184 | \ | |
185 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
186 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
187 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
188 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
189 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
190 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
191 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
192 | \ | |
193 | \ LICENSE_END |