usbquery.c
2.8 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "os_bb.h"
#include "osint.h"
#include "host.h"
#include "device.h"
/*
* osBbUsbDevQuery
*
* Description:
* Find out what devices are present on one of the USB controllers, if
* it is acting as a USB host. If the controller is configured as a
* device, this call returns the device info and attachment state.
*
* Returns:
* Number of devices found (0 if none)
*/
s32
osBbUsbDevQuery(s32 which, OSBbUsbInfo *ip, s32 nip)
{
#ifdef USB_HOST
HOST_GLOBAL_STRUCT *hgp;
#endif
if (which < 0 || which >= OS_USB_MAX_CONTROLLERS) {
PRINTF("osBbUsbDevQuery called with bad arg %d\n", which);
return(-1);
}
if (nip == 0)
return(0);
if (_usb_ctlr_state[which].ucs_mode == UCS_MODE_IDLE) {
return(0);
}
/*
* If this controller is a device (USB0 with mini-B connector inserted),
* return the info about what device it implements and whether it has
* a host connected or not.
*/
if (_usb_ctlr_state[which].ucs_mode == UCS_MODE_DEVICE) {
bzero((void *)ip, nip * sizeof (*ip));
dev_global_struct.funcs->query(ip);
return(1);
}
#ifdef USB_HOST
if (_usb_ctlr_state[which].ucs_mode != UCS_MODE_HOST) {
PRINTF("osBbUsbDevQuery called for ctlr %d with invalid mode %d\n",
which, _usb_ctlr_state[which].ucs_mode);
return(0);
}
hgp = &host_global_struct[which];
if (hgp->DEVICE_ATTACHED == 0)
return(0);
/*
* If there is an attached device, wait for enumeration
* to complete.
* XXX how long to wait?
*/
while (hgp->ENUMERATION_DONE == 0) {
/* USB devices can disappear arbitrarily */
if (hgp->DEVICE_ATTACHED == 0)
return(0);
osYieldThread();
}
/*
* A device is there. Check whether to do the Chapter 9
* negotiation.
*/
if (hgp->driver == NULL)
__usb_host_chapter9_negotiation(which);
bzero((void *)ip, nip * sizeof (*ip));
/*
* The current model is that hubs are not supported,
* so there is really never more than one device.
* More sophisticated devices may present several
* different interfaces, though. XXX deal with that later.
*/
ip->ua_type = OS_USB_TYPE_HOST;
ip->ua_state = OS_USB_STATE_ATTACHED;
ip->ua_class = hgp->RX_DESC_DEVICE.BDEVICECLASS;
ip->ua_subclass = hgp->RX_DESC_DEVICE.BDEVICESUBCLASS;
ip->ua_protocol = hgp->RX_DESC_DEVICE.BDEVICEPROTOCOL;
ip->ua_vendor = swab16(hgp->RX_DESC_DEVICE.IDVENDOR);
ip->ua_product = swab16(hgp->RX_DESC_DEVICE.IDPRODUCT);
ip->ua_cfg = 0; /* XXX */
ip->ua_ep = 1; /* XXX */
ip->ua_speed = OS_USB_FULL_SPEED; /* XXX */
ip->ua_mode = OS_USB_MODE_RW; /* XXX */
ip->ua_blksize = hgp->RX_DESC_DEVICE.BMAXPACKETSIZE;
ip->ua_mfr_str = hgp->MFG_STR;
ip->ua_prod_str = hgp->PROD_STR;
if (hgp->driver) {
ip->ua_driver_name = hgp->driver->name;
ip->ua_support = TRUE;
} else {
ip->ua_driver_name = "(No driver found)";
ip->ua_support = FALSE;
}
return(1);
#else
return(0);
#endif /* !USB_HOST */
}