ede6bdc7de0a4f7b43944c196a65763cb01106d8
[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 /**
50  * Main datastructure of the usbstack, which have to be instanced
51  * in the main application.
52  */
53
54 typedef struct usb_device_t usb_device;
55 struct usb_device_t {
56         u8 address;
57         u8 fullspeed;
58
59         /* device descriptor */
60         u8 bLength;
61         u8 bDescriptorType;
62         u16 bcdUSB;
63         u8 bDeviceClass;
64         u8 bDeviceSubClass;
65         u8 bDeviceProtocoll;
66         u8 bMaxPacketSize0;
67         u16 idVendor;
68         u16 idProduct;
69         u16 bcdDevice;
70         u8 iManufacturer;
71         u8 iProduct;
72         u8 iSerialNumber;
73         u8 bNumConfigurations;
74
75         u8 epSize[16];
76         u8 epTogl[16];
77
78         usb_device *next;
79 };
80
81
82 typedef struct usb_endpoint_t usb_endpoint;
83 struct usb_endpoint_t {
84         u8 type;
85         u8 size;
86         u8 togl;
87         usb_endpoint *next;
88 };
89
90
91
92
93 typedef struct usb_transfer_descriptor_ep_t usb_transfer_descriptor_ep;
94 struct usb_transfer_descriptor_ep_t {
95         usb_transfer_descriptor_ep *next;
96         u8 device_address;
97         u8 endpoint;
98         struct usb_transfer_descriptor_t *start;
99 };
100
101 /**
102  * USB Driver data structure
103  */
104 typedef struct usb_driver_t usb_driver;
105 struct usb_driver_t {
106         char* name;
107         void (*probe)(void);
108         void (*check)(void);
109         void * data;
110         usb_driver *next;
111 };
112
113
114 /**
115  * I/O Request Block
116  */
117
118 typedef struct usb_irp_t usb_irp;
119 struct usb_irp_t {
120         usb_device * dev;
121         u8 endpoint;                            /* ep -> bit 7 is for direction 1=from  dev to host */
122         u8 epsize;
123         u8 type;                                /* control, interrupt, bulk or isochron */
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 typedef struct usb_transfer_descriptor_t usb_transfer_descriptor;
137 struct usb_transfer_descriptor_t {
138         u8 devaddress;
139         u8 endpoint;
140         
141         // TODO: zusammenfassen!
142         u8 pid;
143         u8 iso;
144         u8 togl;        
145         
146         u8 *buffer;
147         u16 actlen;
148         
149         u8 state;
150         usb_transfer_descriptor *next;
151         u8 maxp;
152 };
153
154 //typedef struct usb_core_t usb_core;
155 struct usb_core_t {
156         u8 nextaddress;
157         void (*stdout)(char * arg); 
158         // driver list
159         list * drivers;
160         list * devices;
161 } core;
162
163 void usb_init();
164 void usb_periodic();
165 u8 usb_next_address();
166
167
168 usb_device * usb_add_device();
169 u8 usb_remove_device(usb_device *dev);
170 u8 usb_register_driver(usb_driver *driver);
171 void usb_probe_driver();
172
173
174
175 usb_irp * usb_get_irp();
176 u8 usb_remove_irp(usb_irp *irp);
177 u16 usb_submit_irp(usb_irp *irp);
178
179
180 usb_transfer_descriptor * usb_create_transfer_descriptor(usb_irp *irp);
181
182
183 #define USB_IRP_WAITING         1
184
185
186 #define USB_TRANSFER_DESCR_NONE 1
187 #define USB_TRANSFER_DESCR_SEND 2
188
189 #endif  //_CORE_H_