core.h

00001 /*
00002  * Copyright (c) 2007, Benedikt Sauter <sauter@ixbat.de>
00003  * All rights reserved.
00004  *
00005  * Short descripton of file:
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met:
00011  *
00012  *       * Redistributions of source code must retain the above copyright 
00013  *               notice, this list of conditions and the following disclaimer.
00014  *       * Redistributions in binary form must reproduce the above 
00015  *               copyright notice, this list of conditions and the following 
00016  *               disclaimer in the documentation and/or other materials provided 
00017  *               with the distribution.
00018  *       * Neither the name of the FH Augsburg nor the names of its 
00019  *               contributors may be used to endorse or promote products derived 
00020  *               from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00025  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00026  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 /*
00035         ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
00036         plugmii core
00037 
00038 Copyright (C) 2009     Bernhard Urban <lewurm@gmx.net>
00039 Copyright (C) 2009     Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
00040 
00041 # This code is licensed to you under the terms of the GNU GPL, version 2;
00042 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
00043 */
00044 
00045 #ifndef _CORE_H_
00046 #define _CORE_H_
00047 
00048 #include <types.h>
00049 #include <hextwelve/lib/list.h>
00050 #include <broadway.h>
00051 
00052 inline static void wait_ms(int ms)
00053 {
00054         while(ms--)
00055                 udelay(1000);
00056 }
00057 
00058 typedef struct usb_device {
00059         u8 address;
00060         u8 fullspeed;
00061         u32 ohci;
00062 
00063         /* device descriptor */
00064         u8 bLength;
00065         u8 bDescriptorType;
00066         u16 bcdUSB;
00067         u8 bDeviceClass;
00068         u8 bDeviceSubClass;
00069         u8 bDeviceProtocoll;
00070         u8 bMaxPacketSize0;
00071         u16 idVendor;
00072         u16 idProduct;
00073         u16 bcdDevice;
00074         u8 iManufacturer;
00075         u8 iProduct;
00076         u8 iSerialNumber;
00077         u8 bNumConfigurations;
00078 
00079         u8 epSize[16];
00080         u8 epTogl[16];
00081 
00082         struct usb_conf *conf;
00083         struct usb_device *next;
00084 } usb_device;
00085 
00086 typedef struct usb_conf {
00087         u8 bLength;
00088         u8 bDescriptorType;
00089         u16 wTotalLength;
00090         u8 bNumInterfaces;
00091         u8 bConfigurationValue;
00092         u8 iConfiguration;
00093         u8 bmAttributes;
00094         u8 bMaxPower;
00095 
00096         struct usb_conf *next;
00097         struct usb_intf *intf;
00098 } usb_conf;
00099 
00100 typedef struct usb_intf {
00101         u8 bLength;
00102         u8 bDescriptorType;
00103         u8 bInterfaceNumber;
00104         u8 bAlternateSetting;
00105         u8 bNumEndpoints;
00106         u8 bInterfaceClass;
00107         u8 bInterfaceSubClass;
00108         u8 bInterfaceProtocol;
00109         u8 iInterface;
00110 
00111         struct usb_intf *next;
00112         struct usb_endp *endp;
00113 } usb_intf;
00114 
00115 typedef struct usb_endp {
00116         u8 bLength;
00117         u8 bDescriptorType;
00118         u8 bEndpointAddress;
00119         u8 bmAttributes;
00120         u16 wMaxPacketSize;
00121         u8 bInterval;
00122 
00123         struct usb_endp *next;
00124 } usb_endp;
00125 
00126 typedef struct usb_endpoint {
00127         u8 type;
00128         u8 size;
00129         u8 togl;
00130         struct usb_endpoint *next;
00131 } usb_endpoint;
00132 
00133 typedef struct usb_transfer_descriptor_ep {
00134         struct usb_transfer_descriptor_ep *next;
00135         u8 device_address;
00136         u8 endpoint;
00137         struct usb_transfer_descriptor *start;
00138 } usb_transfer_descriptor_ep;
00139 
00143 typedef struct usb_driver {
00144         char* name;
00145         void (*probe)(void);
00146         void (*check)(void);
00147         void (*remove)(void);
00148         void *data;
00149         struct usb_driver *next;
00150 } usb_driver;
00151 
00152 
00157 typedef struct usb_irp {
00158         struct usb_device *dev;
00159         /* ep -> bit 7 is for direction 1=from  dev to host */
00160         u8 endpoint;
00161         u8 epsize;
00162         /* control, interrupt, bulk or isochron */
00163         u8 type;
00164 
00165         u8 *buffer;
00166         u16 len;
00167 
00168         //list * td_list;
00169         u16 timeout;
00170 } usb_irp;
00171 
00172 
00176 typedef struct usb_transfer_descriptor {
00177         u8 devaddress;
00178         u8 endpoint;
00179         u8 fullspeed;
00180         u8 type;
00181         
00182         // TODO: zusammenfassen!
00183         u8 pid;
00184         u8 iso;
00185         u8 togl;        
00186         
00187         u8 *buffer;
00188         u16 actlen;
00189         
00190         u8 state;
00191         struct usb_transfer_descriptor *next;
00192         u8 maxp;
00193 } usb_transfer_descriptor;
00194 
00195 struct usb_core {
00196         u8 nextaddress;
00197         void (*stdout)(char * arg); 
00198         // driver list
00199         struct list *drivers;
00200         struct list *devices;
00201 } core;
00202 
00203 void usb_init(u32 reg);
00204 void usb_periodic();
00205 u8 usb_next_address();
00206 
00207 
00208 struct usb_device *usb_add_device(u8 lowspeed, u32 reg);
00209 u8 usb_remove_device(struct usb_device *dev);
00210 u8 usb_register_driver(struct usb_driver *driver);
00211 void usb_probe_driver();
00212 
00213 void lsusb(struct usb_device *dev);
00214 
00215 struct usb_irp *usb_get_irp();
00216 u8 usb_remove_irp(struct usb_irp *irp);
00217 u16 usb_submit_irp(struct usb_irp *irp);
00218 
00219 
00220 struct usb_transfer_descriptor *usb_create_transfer_descriptor(struct usb_irp *irp);
00221 
00222 
00223 #define USB_IRP_WAITING         1
00224 
00225 
00226 #define USB_TRANSFER_DESCR_NONE 1
00227 #define USB_TRANSFER_DESCR_SEND 2
00228 
00229 #endif  //_CORE_H_
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated by  doxygen 1.6.3