license stuff
[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         ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
36         plugmii core
37
38 Copyright (C) 2009     Bernhard Urban <lewurm@gmx.net>
39 Copyright (C) 2009     Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
40
41 # This code is licensed to you under the terms of the GNU GPL, version 2;
42 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
43 */
44
45 #ifndef _CORE_H_
46 #define _CORE_H_
47
48 #include "../../types.h"
49 #include "../lib/list.h"
50
51
52 #include "../../bootmii_ppc.h"
53 inline static void wait_ms(int ms)
54 {
55         while(ms--)
56                 udelay(1000);
57 }
58
59 struct usb_device {
60         u8 address;
61         u8 fullspeed;
62         u32 ohci;
63
64         /* device descriptor */
65         u8 bLength;
66         u8 bDescriptorType;
67         u16 bcdUSB;
68         u8 bDeviceClass;
69         u8 bDeviceSubClass;
70         u8 bDeviceProtocoll;
71         u8 bMaxPacketSize0;
72         u16 idVendor;
73         u16 idProduct;
74         u16 bcdDevice;
75         u8 iManufacturer;
76         u8 iProduct;
77         u8 iSerialNumber;
78         u8 bNumConfigurations;
79
80         u8 epSize[16];
81         u8 epTogl[16];
82
83         struct usb_conf *conf;
84         struct usb_device *next;
85 };
86
87 struct usb_conf {
88         u8 bLength;
89         u8 bDescriptorType;
90         u16 wTotalLength;
91         u8 bNumInterfaces;
92         u8 bConfigurationValue;
93         u8 iConfiguration;
94         u8 bmAttributes;
95         u8 bMaxPower;
96
97         struct usb_conf *next;
98         struct usb_intf *intf;
99 };
100
101 struct usb_intf {
102         u8 bLength;
103         u8 bDescriptorType;
104         u8 bInterfaceNumber;
105         u8 bAlternateSetting;
106         u8 bNumEndpoints;
107         u8 bInterfaceClass;
108         u8 bInterfaceSubClass;
109         u8 bInterfaceProtocol;
110         u8 iInterface;
111
112         struct usb_intf *next;
113         struct usb_endp *endp;
114 };
115
116 struct usb_endp {
117         u8 bLength;
118         u8 bDescriptorType;
119         u8 bEndpointAddress;
120         u8 bmAttributes;
121         u16 wMaxPacketSize;
122         u8 bInterval;
123
124         struct usb_endp *next;
125 };
126
127 struct usb_endpoint {
128         u8 type;
129         u8 size;
130         u8 togl;
131         struct usb_endpoint *next;
132 };
133
134 struct usb_transfer_descriptor_ep {
135         struct usb_transfer_descriptor_ep *next;
136         u8 device_address;
137         u8 endpoint;
138         struct usb_transfer_descriptor *start;
139 };
140
141 /**
142  * USB Driver data structure
143  */
144 struct usb_driver {
145         char* name;
146         void (*probe)(void);
147         void (*check)(void);
148         void *data;
149         struct usb_driver *next;
150 };
151
152
153 /**
154  * I/O Request Block
155  */
156
157 struct usb_irp {
158         struct usb_device *dev;
159         /* ep -> bit 7 is for direction 1=from  dev to host */
160         u8 endpoint;
161         u8 epsize;
162         /* control, interrupt, bulk or isochron */
163         u8 type;
164
165         u8 *buffer;
166         u16 len;
167
168         //list * td_list;
169         u16 timeout;
170 };
171
172
173 /**
174  * usb transfer descriptor
175  */
176 struct usb_transfer_descriptor {
177         u8 devaddress;
178         u8 endpoint;
179         u8 fullspeed;
180         u8 type;
181         
182         // TODO: zusammenfassen!
183         u8 pid;
184         u8 iso;
185         u8 togl;        
186         
187         u8 *buffer;
188         u16 actlen;
189         
190         u8 state;
191         struct usb_transfer_descriptor *next;
192         u8 maxp;
193 };
194
195 struct usb_core {
196         u8 nextaddress;
197         void (*stdout)(char * arg); 
198         // driver list
199         struct list *drivers;
200         struct list *devices;
201 } core;
202
203 void usb_init(u32 reg);
204 void usb_periodic();
205 u8 usb_next_address();
206
207
208 struct usb_device *usb_add_device(u8 lowspeed, u32 reg);
209 u8 usb_remove_device(struct usb_device *dev);
210 u8 usb_register_driver(struct usb_driver *driver);
211 void usb_probe_driver();
212
213 void lsusb(struct usb_device *dev);
214
215 struct usb_irp *usb_get_irp();
216 u8 usb_remove_irp(struct usb_irp *irp);
217 u16 usb_submit_irp(struct usb_irp *irp);
218
219
220 struct usb_transfer_descriptor *usb_create_transfer_descriptor(struct usb_irp *irp);
221
222
223 #define USB_IRP_WAITING         1
224
225
226 #define USB_TRANSFER_DESCR_NONE 1
227 #define USB_TRANSFER_DESCR_SEND 2
228
229 #endif  //_CORE_H_