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