|
|
1.1 root 1: \ *****************************************************************************
2: \ * Copyright (c) 2004, 2008 IBM Corporation
3: \ * All rights reserved.
4: \ * This program and the accompanying materials
5: \ * are made available under the terms of the BSD License
6: \ * which accompanies this distribution, and is available at
7: \ * http://www.opensource.org/licenses/bsd-license.php
8: \ *
9: \ * Contributors:
10: \ * IBM Corporation - initial implementation
11: \ ****************************************************************************/
12:
13:
14: \ create the device tree for hub
15:
16: : (hub-create) ( -- )
17: mps port-number new-device-address port-number
18: ( mps port-number usb-address port-number )
19: new-device set-space ( mps port-number usb-address )
20: encode-int s" USB-ADDRESS" property ( mps port-number )
21: s" Address Set" usb-debug-print
22: encode-int s" reg" property ( mps )
23: s" Port Number Set" usb-debug-print
24: encode-int s" MPS-DCP" property
25: s" MPS Set" usb-debug-print
26: s" usb-hub.fs" INCLUDED
27: s" Driver Included" usb-debug-print
28: finish-device
29: ;
30:
31:
32: \ encode properties for scsi or atapi device
33:
34: : (atapi-scsi-property-set) ( -- )
35: dd-buffer @ e + c@ ( Manuf )
36: dd-buffer @ f + c@ ( Manuf Prod )
37: dd-buffer @ 10 + c@ ( Manuf Prod Serial-Num )
38: cd-buffer @ 16 + w@-le ( Manuf Prod Serial-Num ep-mps )
39: cd-buffer @ 14 + c@ ( Manuf Prod Serial-Num ep-mps ep-addr )
40: cd-buffer @ 1d + w@-le ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps )
41: cd-buffer @ 1b + c@ ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr )
42: mps port-number new-device-address port-number
43: ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr
44: mps port-num usb-addr port-num )
45: new-device set-space
46: ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr
47: mps port-num usb-addr )
48: encode-int s" USB-ADDRESS" property
49: ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr
50: mps port-num )
51: encode-int s" reg" property
52: ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr
53: mps )
54: encode-int s" MPS-DCP" property
55: ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr )
56: 2 0 DO
57: dup 80 and IF
58: 7f and encode-int
59: s" BULK-IN-EP-ADDR" property
60: encode-int s" MPS-BULKIN" property
61: ELSE
62: encode-int s" BULK-OUT-EP-ADDR" property
63: encode-int s" MPS-BULKOUT" property
64: THEN
65: LOOP ( Manuf Prod Serial-Num )
66: encode-int s" iSerialNumber" property ( Manuf Prod )
67: encode-int s" iProduct" property ( Manuf )
68: encode-int s" iManufacturer" property
69: ;
70:
71:
72: \ To classify device as hub/atapi/scsi/HID device
73:
74: : (device-classify)
75: ( -- Interface-protocol Interface-subclass Interface-class TRUE|FALSE )
76: cd-buffer @ BULK-CONFIG-DESCRIPTOR-LEN erase
77: cd-buffer @ BULK-CONFIG-DESCRIPTOR-LEN mps new-device-address
78: ( buffer descp-len mps usb-address )
79: control-std-get-configuration-descriptor
80: IF
81: cd-buffer @ 1+ c@ ( Descriptor-type )
82: 2 = IF
83: cd-buffer @ 10 + c@ ( protocol )
84: cd-buffer @ f + c@ ( protocol subclass )
85: cd-buffer @ e + c@ ( protocol subclass class )
86: TRUE
87: ELSE
88: s" Not a valid configuration descriptor!!" usb-debug-print
89: FALSE
90: THEN
91: ELSE
92: s" Unable to read configuration descriptor!!" usb-debug-print
93: FALSE
94: THEN
95: ;
96:
97:
98: \ create device tree for Atapi SFF-8020 device
99:
100: : (atapi-8020-create) ( -- )
101: (atapi-scsi-property-set)
102: s" usb-storage.fs" INCLUDED
103: finish-device
104: ;
105:
106: \ create device tree for Atapi SFF-8070 device
107:
108: : (atapi-8070-create) ( -- )
109: (atapi-scsi-property-set)
110: s" usb-storage.fs" INCLUDED
111: \ s" storage" device-name
112: finish-device
113: ;
114:
115:
116: \ create device tree for SCSI device
117:
118: : (scsi-create) ( -- )
119: s" SCSI-CREATE " usb-debug-print
120:
121: \ ***********************************************************************
122: \ a problem was encountered on Media-Tray (REV-0):
123: \ The CDROM is connected to USB via an ATA/USB-Bridge (U38: CYPRESS CY7C68300)
124: \ The C-Revision of this chip has an malfunction which results in a
125: \ hanging IORD Signal at the ATA-Interface and so prevents from reading.
126: \ The B-Revision doesn't have this problem (populated on Media-Tray REV-5)
127: \ Two additional Mass-Storage-Resets are necessary to reset the ATA-Interface.
128: \ (see CYPRESS Application Notes to CY7C68300)
129: \ (see USB-Spec: 'Bulk-Only-Transport')
130: \ ***********************************************************************
131: \ a mounted ISO image (via USB) doesn't accept this bulk-reset-command!
132: \ ***********************************************************************
133:
134: dd-buffer @ 8 + w@-le 4b4 = \ VendorID = CYPRESS ?
135: IF
136: dd-buffer @ a + w@-le 6830 = \ Device = CY7C68300 ?
137: IF
138: \ here a Cypress ATA/USB Bridge is detected
139: d# 20 ms
140: mps new-device-address 0 0 0 ( MPS fun-addr dir data-buff data-len )
141: control-bulk-reset ( TRUE|FALSE )
142: d# 100 ms
143: mps new-device-address 0 0 0 ( TRUE|FALSE MPS fun-addr dir data-buff data-len )
144: control-bulk-reset ( TRUE|FALSE TRUE|FALSE )
145: and invert
146: IF
147: ." ** BULK-RESET failed **" cr
148: THEN
149: d# 20 ms
150: THEN
151: THEN
152:
153: 0 ch-buffer ! \ preset a clean response
154: mps new-device-address 0 ch-buffer 1 control-std-get-maxlun ( TRUE|FALSE )
155: IF
156: \ s" GET-MAX-LUN IS WORKING :" usb-debug-print
157: \ ch-buffer 5 dump cr \ dump the responsed message
158: ELSE
159: s" ERROR in GET-MAX-LUN " usb-debug-print
160: 0 ch-buffer ! \ clear invalid numbers
161: cd-buffer @ 5 + c@ to temp1
162: temp1 new-device-address control-std-set-configuration drop
163: THEN
164: \ FIXME: an IBM external HDD reported a number of 127 LUNs which could
165: \ not be set up. We need to understand how to set up the device
166: \ to report the correct number of LUNs.
167: \ The USB Massbulk Standard 1.0 defines a maximum of 15 mult. LUNs.
168: \ Workaround: Devices that might report a higher number are treated
169: \ as having exactly one LUN. Without this workaround the
170: \ USB scan hangs during the setup of non-available LUNs.
171: \
172: \ Concerns: "FUJITSU MHV2040AT" (VendorID: 0x984 / DeviceID: 0x70)
173: \
174: \ MR: This Device reports an invalid MaxLUN number within the first
175: \ three seconds after power-on or USB-Reset. The following loop repeats
176: \ the MaxLUN request up to 8 times until a valid ( <15 ) value is responded.
177: \ This can last up to four seconds as there is a delay of 500ms in every loop
178:
179: 0 ( counter )
180: begin
181: dup 8 < ( counter flag ) \ max 8 * 500 ms
182: ch-buffer c@ f > ( counter flag flag ) \ is MuxLUN above limit ?
183: AND ( counter flag )
184: while
185: d# 500 ms \ this device is not yet ready
186: 0 ch-buffer ! \ preset a clean response
187: mps new-device-address 0 ch-buffer 1 control-std-get-maxlun ( TRUE|FALSE )
188: not
189: IF
190: s" ** ERROR in GET-MAX-LUN ** " usb-debug-print
191: drop 10 \ replace counter to force loop end
192: THEN
193: 1+ ( counter+1 )
194: repeat
195: drop
196:
197: \ here is still the workaround to handle invalid MaxLUNs as '0'
198: \
199: ch-buffer c@ dup 0= swap f > or IF
200: s" + LUN: " ch-buffer c@ usb-debug-print-val
201: (atapi-scsi-property-set)
202: s" usb-storage.fs" INCLUDED
203: finish-device
204:
205: ELSE
206: s" - LUN: " ch-buffer c@ usb-debug-print-val
207: (atapi-scsi-property-set)
208: s" usb-storage-wrapper.fs" INCLUDED
209: finish-device
210:
211: THEN
212: ;
213:
214:
215: \ Classify USB storage device by sub-class code
216:
217: : (classify-storage) ( interface-protocol interface-subclass -- )
218: s" USB: Mass Storage Device Found!" usb-debug-print
219: swap 50 <> IF
220: s" USB storage: Protocol is not 50." usb-debug-print
221: drop EXIT
222: THEN
223: ( interface-subclass )
224: CASE
225: 02 OF (atapi-8020-create) s" ATAPI Interface " usb-debug-print ENDOF
226: 05 OF (atapi-8070-create) s" ATAPI Interface " usb-debug-print ENDOF
227: 06 OF (scsi-create) s" SCSI Interface " usb-debug-print ENDOF
228: dup OF s" USB storage: Unsupported sub-class code." usb-debug-print ENDOF
229: ENDCASE
230: ;
231:
232:
233: \ create keyboard device tree
234:
235: : (keyboard-create) ( -- )
236: cd-buffer @ 1f + c@ ( ep-mps )
237: cd-buffer @ 1d + c@ ( ep-mps ep-addr )
238: mps port-number new-device-address port-number
239: ( ep-mps ep-addr mps port-num usb-addr port-num )
240: new-device set-space ( ep-mps ep-addr mps port-num usb-addr )
241: encode-int s" USB-ADDRESS" property ( ep-mps ep-addr mps port-num )
242: encode-int s" reg" property ( ep-mps ep-addr mps )
243: encode-int s" MPS-DCP" property ( ep-mps ep-addr )
244: 7f and encode-int s" INT-IN-EP-ADDR" property
245: encode-int s" MPS-INTIN" property
246: new-device-address \ device-speed
247: s" usb-keyboard.fs" INCLUDED
248: finish-device
249: ;
250:
251: : (mouse-create) ( -- )
252: mps port-number new-device-address port-number
253: ( mps port-num usb-addr port-num )
254: new-device set-space ( mps port-num usb-addr )
255: encode-int s" USB-ADDRESS" property ( mps port-num )
256: encode-int s" reg" property ( mps )
257: encode-int s" MPS-DCP" property
258: s" usb-mouse.fs" INCLUDED
259: finish-device
260: ;
261:
262:
263: \ Classify by interface class code
264:
265: : (classify-by-interface) ( -- )
266: (device-classify) IF
267: ( Interface-protocol Interface-subclass Interface-class )
268: CASE
269: 08 OF
270: ( Interface-protocol Interface-subclass )
271: (classify-storage)
272: ENDOF
273: 03 OF
274: ( Interface-protocol Interface-subclass )
275: s" USB: HID Found!" usb-debug-print
276: 01 =
277: IF
278: case
279: 01 of
280: s" USB keyboard!" usb-debug-print
281: (keyboard-create)
282: endof
283: 02 of
284: s" USB mouse!" usb-debug-print
285: (mouse-create)
286: endof
287: dup of
288: s" USB: unsupported HID!" usb-debug-print
289: endof
290: endcase
291: ELSE
292: s" USB: unsupported HID!" usb-debug-print
293: THEN
294: ENDOF
295: dup OF
296: ( Interface-protocol Interface-subclass )
297: s" USB: unsupported interface type." usb-debug-print
298: 2drop
299: ENDOF
300: ENDCASE
301: THEN
302: ;
303:
304:
305: \ create usb device tree depending upon classification of the device
306: \ after encoding apt properties
307:
308: : create-usb-device-tree ( -- )
309: dd-buffer @ DEVICE-DESCRIPTOR-DEVCLASS-OFFSET + c@ ( Device-class )
310: CASE
311: HUB-DEVICE-CLASS OF s" USB: HUB found" usb-debug-print
312: (hub-create)
313: ENDOF
314: NO-CLASS OF
315: \ In this case, the INTERFACE descriptor
316: \ tells you whats what -- Refer USB spec.
317: (classify-by-interface)
318: ENDOF
319: DUP OF
320: s" USB: Unknown device found." usb-debug-print
321: ENDOF
322: ENDCASE
323: uDOC-present 0f and to uDOC-present \ remove uDOC processing flag
324: ;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.