xref: /plan9/sys/src/cmd/usb/usbd/usbd.h (revision 6083aa4307383671473908ab2d661f80fbf6814b)
1 typedef struct Hub Hub;
2 typedef struct Port Port;
3 typedef struct DHub DHub;
4 typedef struct Devtab Devtab;
5 typedef struct Usbfs Usbfs;
6 
7 enum
8 {
9 	Stack	= 32*1024,
10 
11 	Dhub	= 0x29,		/* hub descriptor type */
12 	Dhublen = 9,		/* hub descriptor length */
13 
14 	/* hub class feature selectors */
15 	Fhublocalpower	= 0,
16 	Fhubovercurrent	= 1,
17 
18 	Fportconnection	= 0,
19 	Fportenable	= 1,
20 	Fportsuspend	= 2,
21 	Fportovercurrent = 3,
22 	Fportreset	= 4,
23 	Fportpower	= 8,
24 	Fportlowspeed	= 9,
25 	Fcportconnection	= 16,
26 	Fcportenable	= 17,
27 	Fcportsuspend	= 18,
28 	Fcportovercurrent= 19,
29 	Fcportreset	= 20,
30 	Fportindicator	= 22,
31 
32 	/* Port status and status change bits
33 	 * Constants at /sys/src/9/pc/usb.h starting with HP-
34 	 * must have the same values or root hubs won't work.
35 	 */
36 	PSpresent	= 0x0001,
37 	PSenable	= 0x0002,
38 	PSsuspend	= 0x0004,
39 	PSovercurrent	= 0x0008,
40 	PSreset		= 0x0010,
41 	PSpower		= 0x0100,
42 	PSslow		= 0x0200,
43 	PShigh		= 0x0400,
44 
45 	PSstatuschg	= 0x10000,	/* PSpresent changed */
46 	PSchange	= 0x20000,	/* PSenable changed */
47 
48 
49 	/* port/device state */
50 	Pdisabled = 0,		/* must be 0 */
51 	Pattached,
52 	Pconfiged,
53 
54 	/* Delays, timeouts (ms) */
55 	Spawndelay	= 100,		/* how often may we re-spawn a driver */
56 	Connectdelay	= 500,		/* how much to wait after a connect */
57 	Resetdelay	= 20,		/* how much to wait after a reset */
58 	Enabledelay	= 20,		/* how much to wait after an enable */
59 	Powerdelay	= 100,		/* after powering up ports */
60 	Pollms		= 250, 		/* port poll interval */
61 	Chgdelay	= 100,		/* waiting for port become stable */
62 	Chgtmout	= 1000,		/* ...but at most this much */
63 
64 	/*
65 	 * device tab for embedded usb drivers.
66 	 */
67 	DCL = 0x01000000,		/* csp identifies just class */
68 	DSC = 0x02000000,		/* csp identifies just subclass */
69 	DPT = 0x04000000,		/* csp identifies just proto */
70 
71 };
72 
73 struct Hub
74 {
75 	uchar	pwrmode;
76 	uchar	compound;
77 	uchar	pwrms;		/* time to wait in ms */
78 	uchar	maxcurrent;	/*    after powering port*/
79 	int	leds;		/* has port indicators? */
80 	int	maxpkt;
81 	uchar	nport;
82 	Port	*port;
83 	int	failed;		/* I/O error while enumerating */
84 	int	isroot;		/* set if root hub */
85 	Dev	*dev;		/* for this hub */
86 	Hub	*next;		/* in list of hubs */
87 };
88 
89 struct Port
90 {
91 	int	state;		/* state of the device */
92 	int	sts;		/* old port status */
93 	uchar	removable;
94 	uchar	pwrctl;
95 	Dev	*dev;		/* attached device (if non-nil) */
96 	Hub	*hub;		/* non-nil if hub attached */
97 	int	devnb;		/* device number */
98 	uvlong	*devmaskp;	/* ptr to dev mask */
99 };
100 
101 
102 /* USB HUB descriptor */
103 struct DHub
104 {
105 	uchar	bLength;
106 	uchar	bDescriptorType;
107 	uchar	bNbrPorts;
108 	uchar	wHubCharacteristics[2];
109 	uchar	bPwrOn2PwrGood;
110 	uchar	bHubContrCurrent;
111 	uchar	DeviceRemovable[1];	/* variable length */
112 };
113 
114 struct Devtab
115 {
116 	char	*name;
117 	int	(*init)(Dev*, int, char**);	/* nil if external */
118 	int	csps[4];
119 	int	vid;
120 	int	did;
121 	char	*args;
122 	uvlong	devmask;
123 	int	noauto;
124 };
125 
126 
127 Hub*	newhub(char *fn, Dev *d);
128 int	startdev(Port *pp);
129 int	getdevnb(uvlong *maskp);
130 void	putdevnb(uvlong *maskp, int nb);
131 void	threadmain(int argc, char **argv);
132 
133 extern Usbfs usbdfsops;
134