added lsusb and some more config stuff. except of some (simple) setter
[ppcskel.git] / usb / core / core.h
1 /*
2  * Copyright (c) 2007, Benedikt Sauter <sauter@ixbat.de>
3  * All rights reserved.
4  *
5  * Short descripton of file:
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without 
9  * modification, are permitted provided that the following conditions 
10  * are met:
11  *
12  *       * Redistributions of source code must retain the above copyright 
13  *               notice, this list of conditions and the following disclaimer.
14  *       * Redistributions in binary form must reproduce the above 
15  *               copyright notice, this list of conditions and the following 
16  *               disclaimer in the documentation and/or other materials provided 
17  *               with the distribution.
18  *       * Neither the name of the FH Augsburg nor the names of its 
19  *               contributors may be used to endorse or promote products derived 
20  *               from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #ifndef _CORE_H_
36 #define _CORE_H_
37
38 #include "../../types.h"
39 #include "../lib/list.h"
40
41
42 #include "../../bootmii_ppc.h"
43 inline static void wait_ms(int ms)
44 {
45         while(ms--)
46                 udelay(1000);
47 }
48
49 struct usb_device {
50         u8 address;
51         u8 fullspeed;
52
53         /* device descriptor */
54         u8 bLength;
55         u8 bDescriptorType;
56         u16 bcdUSB;
57         u8 bDeviceClass;
58         u8 bDeviceSubClass;
59         u8 bDeviceProtocoll;
60         u8 bMaxPacketSize0;
61         u16 idVendor;
62         u16 idProduct;
63         u16 bcdDevice;
64         u8 iManufacturer;
65         u8 iProduct;
66         u8 iSerialNumber;
67         u8 bNumConfigurations;
68
69         u8 epSize[16];
70         u8 epTogl[16];
71
72         struct usb_conf *conf;
73         struct usb_device *next;
74 };
75
76 struct usb_conf {
77         u8 bLength;
78         u8 bDescriptorType;
79         u16 wTotalLength;
80         u8 bNumInterfaces;
81         u8 bConfigurationValue;
82         u8 iConfiguration;
83         u8 bmAttributes;
84         u8 bMaxPower;
85
86         struct usb_conf *next;
87         struct usb_intf *intf;
88 };
89
90 struct usb_intf {
91         u8 bLength;
92         u8 bDescriptorType;
93         u8 bInterfaceNumber;
94         u8 bAlternateSetting;
95         u8 bNumEndpoints;
96         u8 bInterfaceClass;
97         u8 bInterfaceSubClass;
98         u8 bInterfaceProtocol;
99         u8 iInterface;
100
101         struct usb_intf *next;
102         struct usb_endp *endp;
103 };
104
105 struct usb_endp {
106         u8 bLength;
107         u8 bDescriptorType;
108         u8 bEndpointAddress;
109         u8 bmAttributes;
110         u16 wMaxPacketSize;
111         u8 bInterval;
112
113         struct usb_endp *next;
114 };
115
116 struct usb_endpoint {
117         u8 type;
118         u8 size;
119         u8 togl;
120         struct usb_endpoint *next;
121 };
122
123 struct usb_transfer_descriptor_ep {
124         struct usb_transfer_descriptor_ep *next;
125         u8 device_address;
126         u8 endpoint;
127         struct usb_transfer_descriptor *start;
128 };
129
130 /**
131  * USB Driver data structure
132  */
133 struct usb_driver {
134         char* name;
135         void (*probe)(void);
136         void (*check)(void);
137         void * data;
138         struct usb_driver *next;
139 };
140
141
142 /**
143  * I/O Request Block
144  */
145
146 struct usb_irp {
147         struct usb_device *dev;
148         /* ep -> bit 7 is for direction 1=from  dev to host */
149         u8 endpoint;
150         u8 epsize;
151         /* control, interrupt, bulk or isochron */
152         u8 type;
153
154         u8 *buffer;
155         u16 len;
156
157         //list * td_list;
158         u16 timeout;
159 };
160
161
162 /**
163  * usb transfer descriptor
164  */
165 struct usb_transfer_descriptor {
166         u8 devaddress;
167         u8 endpoint;
168         
169         // TODO: zusammenfassen!
170         u8 pid;
171         u8 iso;
172         u8 togl;        
173         
174         u8 *buffer;
175         u16 actlen;
176         
177         u8 state;
178         struct usb_transfer_descriptor *next;
179         u8 maxp;
180 };
181
182 struct usb_core {
183         u8 nextaddress;
184         void (*stdout)(char * arg); 
185         // driver list
186         struct list *drivers;
187         struct list *devices;
188 } core;
189
190 void usb_init();
191 void usb_periodic();
192 u8 usb_next_address();
193
194
195 struct usb_device *usb_add_device();
196 u8 usb_remove_device(struct usb_device *dev);
197 u8 usb_register_driver(struct usb_driver *driver);
198 void usb_probe_driver();
199
200 void lsusb(struct usb_device *dev);
201
202 struct usb_irp *usb_get_irp();
203 u8 usb_remove_irp(struct usb_irp *irp);
204 u16 usb_submit_irp(struct usb_irp *irp);
205
206
207 struct usb_transfer_descriptor *usb_create_transfer_descriptor(struct usb_irp *irp);
208
209
210 #define USB_IRP_WAITING         1
211
212
213 #define USB_TRANSFER_DESCR_NONE 1
214 #define USB_TRANSFER_DESCR_SEND 2
215
216 #endif  //_CORE_H_