some routines for removing a device on demand. thist do not work properly
[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 (*remove)(void);
149         void *data;
150         struct usb_driver *next;
151 };
152
153
154 /**
155  * I/O Request Block
156  */
157
158 struct usb_irp {
159         struct usb_device *dev;
160         /* ep -> bit 7 is for direction 1=from  dev to host */
161         u8 endpoint;
162         u8 epsize;
163         /* control, interrupt, bulk or isochron */
164         u8 type;
165
166         u8 *buffer;
167         u16 len;
168
169         //list * td_list;
170         u16 timeout;
171 };
172
173
174 /**
175  * usb transfer descriptor
176  */
177 struct usb_transfer_descriptor {
178         u8 devaddress;
179         u8 endpoint;
180         u8 fullspeed;
181         u8 type;
182         
183         // TODO: zusammenfassen!
184         u8 pid;
185         u8 iso;
186         u8 togl;        
187         
188         u8 *buffer;
189         u16 actlen;
190         
191         u8 state;
192         struct usb_transfer_descriptor *next;
193         u8 maxp;
194 };
195
196 struct usb_core {
197         u8 nextaddress;
198         void (*stdout)(char * arg); 
199         // driver list
200         struct list *drivers;
201         struct list *devices;
202 } core;
203
204 void usb_init(u32 reg);
205 void usb_periodic();
206 u8 usb_next_address();
207
208
209 struct usb_device *usb_add_device(u8 lowspeed, u32 reg);
210 u8 usb_remove_device(struct usb_device *dev);
211 u8 usb_register_driver(struct usb_driver *driver);
212 void usb_probe_driver();
213
214 void lsusb(struct usb_device *dev);
215
216 struct usb_irp *usb_get_irp();
217 u8 usb_remove_irp(struct usb_irp *irp);
218 u16 usb_submit_irp(struct usb_irp *irp);
219
220
221 struct usb_transfer_descriptor *usb_create_transfer_descriptor(struct usb_irp *irp);
222
223
224 #define USB_IRP_WAITING         1
225
226
227 #define USB_TRANSFER_DESCR_NONE 1
228 #define USB_TRANSFER_DESCR_SEND 2
229
230 #endif  //_CORE_H_