f541306ad5204dee855b429d25b9c4be0f5c9397
[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
87 struct usb_intf {
88         u8 bLength;
89         u8 bDescriptorType;
90         u8 bInterfaceNumber;
91         u8 bAlternateSetting;
92         u8 bNumEndpoints;
93         u8 bInterfaceClass;
94         u8 bInterfaceSubClass;
95         u8 bInterfaceProtocol;
96         u8 iInterface;
97
98         struct usb_intf *next;
99 };
100
101 struct usb_endp {
102         u8 bLength;
103         u8 bDescriptorType;
104         u8 bEndpointAddress;
105         u8 bmAttributes;
106         u16 wMaxPacketSize;
107         u8 bInterval;
108
109         struct usb_endp *next;
110 };
111
112 struct usb_endpoint {
113         u8 type;
114         u8 size;
115         u8 togl;
116         struct usb_endpoint *next;
117 };
118
119 struct usb_transfer_descriptor_ep {
120         struct usb_transfer_descriptor_ep *next;
121         u8 device_address;
122         u8 endpoint;
123         struct usb_transfer_descriptor *start;
124 };
125
126 /**
127  * USB Driver data structure
128  */
129 struct usb_driver {
130         char* name;
131         void (*probe)(void);
132         void (*check)(void);
133         void * data;
134         struct usb_driver *next;
135 };
136
137
138 /**
139  * I/O Request Block
140  */
141
142 struct usb_irp {
143         struct usb_device *dev;
144         /* ep -> bit 7 is for direction 1=from  dev to host */
145         u8 endpoint;
146         u8 epsize;
147         /* control, interrupt, bulk or isochron */
148         u8 type;
149
150         u8 *buffer;
151         u16 len;
152
153         //list * td_list;
154         u16 timeout;
155 };
156
157
158 /**
159  * usb transfer descriptor
160  */
161 struct usb_transfer_descriptor {
162         u8 devaddress;
163         u8 endpoint;
164         
165         // TODO: zusammenfassen!
166         u8 pid;
167         u8 iso;
168         u8 togl;        
169         
170         u8 *buffer;
171         u16 actlen;
172         
173         u8 state;
174         struct usb_transfer_descriptor *next;
175         u8 maxp;
176 };
177
178 struct usb_core {
179         u8 nextaddress;
180         void (*stdout)(char * arg); 
181         // driver list
182         struct list *drivers;
183         struct list *devices;
184 } core;
185
186 void usb_init();
187 void usb_periodic();
188 u8 usb_next_address();
189
190
191 struct usb_device *usb_add_device();
192 u8 usb_remove_device(struct usb_device *dev);
193 u8 usb_register_driver(struct usb_driver *driver);
194 void usb_probe_driver();
195
196
197
198 struct usb_irp *usb_get_irp();
199 u8 usb_remove_irp(struct usb_irp *irp);
200 u16 usb_submit_irp(struct usb_irp *irp);
201
202
203 struct usb_transfer_descriptor *usb_create_transfer_descriptor(struct usb_irp *irp);
204
205
206 #define USB_IRP_WAITING         1
207
208
209 #define USB_TRANSFER_DESCR_NONE 1
210 #define USB_TRANSFER_DESCR_SEND 2
211
212 #endif  //_CORE_H_