some routines for removing a device on demand. thist do not work properly
[ppcskel.git] / usb / core / core.c
index 5535bb351a22025957ff242dd84c9d7596d289fe..97acc56a57be1e7a66d1b0fbded801c2396e6540 100644 (file)
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+/*
+       ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
+       plugmii core
+
+Copyright (C) 2009     Bernhard Urban <lewurm@gmx.net>
+Copyright (C) 2009     Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
+
+# This code is licensed to you under the terms of the GNU GPL, version 2;
+# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+*/
 
-//#include <stdlib.h>
 #include "core.h"
 #include "../host/host.h"
 #include "usb.h"
@@ -111,16 +120,26 @@ struct usb_device *usb_add_device(u8 lowspeed, u32 reg)
        if(ret < 0) {
                return (void*) -1;
        }
-
-#define WTF
+//
+//#define WTF
 #ifdef WTF
-       printf("lololol PADDING WTF :O lolololololo \n");
-       printf("lololololool PADDING WTF :O lolololololo \n");
-       printf("lolololool PADDING WTF :O lololoololo \n");
-       printf("lololololool PADDING WTF :O lolololololo \n");
-       printf("lolololool PADDING WTF :O lolololololo \n");
-       printf("lololololool PADDING WTF :O lolololololo \n");
-       printf("lollllool PADDING WTF :O lolololololo \n");
+       volatile u8 wzf = 11;
+       if(0 == wzf) {
+               printf("WTF WTF WTF WTF padding??? WTFWTF WTF\n");
+               printf("WTF WTF WTF WTF padding??? WTF WTF WTF\n");
+               printf("WTF TF WTF WTF padding??? WTF WTF WTF\n");
+               printf("WTF WTF TF WTF padding??? WTF WTWTF\n");
+               printf("TF WTF WTF WTF padding??? WTF WTF WTF\n");
+               printf("WTF WTF WTF WT padding??? WTF WF WTF\n");
+               printf("WTF WTF WTF WTF padding??? WTF WTF WTF\n");
+               printf("WTF WTF WTF WTF padding??? WT WTF WTF\n");
+               printf("WTF WTF WTF WTF pdding??? WTF WTF WTF\n");
+               printf("WTF WTF WTF WTF paddin??? WTF WTF WTF\n");
+               printf("WTF WTF WTF WTF padding??? WTF WTF WTF\n");
+               printf("WTF WTF WTF WTF padding?? WT WTF WTF\n");
+               printf("WTF WTF WTF WTF padding??? WTF WTF WTF\n");
+               printf("WTF WTF WTF WTF padding??? WTFWTF WTF\n");
+       }
 #endif
        u8 address = usb_next_address();
        ret = usb_set_address(dev, address);
@@ -133,78 +152,14 @@ struct usb_device *usb_add_device(u8 lowspeed, u32 reg)
                return (void*) -1;
 
        /* print device info */
-       //lsusb(dev);
-
-       //HID only!
-#define GET_PROTOCOL 0x03
-#define SET_PROTOCOL 0x0b
-#define GETit 0xa1
-#define SETit 0x21
-
-
-       u8 buf[255];
-#if 1
-       /* select configuration */
-       wait_ms(500);
-       ret = usb_set_configuration(dev, 1);
-       printf("=============\nusb_set_configuration(ret: %d): %d\n", ret, dev->conf->bConfigurationValue);
-       wait_ms(500);
-#if 0
-       wait_ms(500);
-       printf("=============\nusb_get_configuration: %d (should be 1 here)\n", usb_get_configuration(dev));
-#endif
-#endif
-
-#if 1
-       memset(buf, 0, 0xff);
-       usb_control_msg(dev, (1<<5)|1, SET_CONFIGURATION, 0x200, 0x0, 0x0, buf, 0);
-       printf("wtf request\n");
-       hexdump((void*)buf, 0x8);
-#endif
-
-
-#if 0
-       /* set protocol */
-       /* see p48 in HID spec */
-       memset(buf, 0, 8);
-       usb_control_msg(dev, SETit, SET_PROTOCOL, 0 /*boot protocol*/, 0 /*interface number*/, 0 /*length*/, buf, 0);
-       printf("=============\nhid_set_protocol %d\n", 0);
-       hexdump((void*)buf, 8);
-#endif
-#if 0
-       memset(buf, 0, 8);
-       usb_control_msg(dev, GETit, GET_PROTOCOL, 0, 0, 4, buf, 0);
-       printf("=============\nusb_get_protocol: %d\n", buf[0]);
-       hexdump((void*)buf, 8);
-#endif
-
-#if 1
-       /* I just don't know why on some devices 
-        * {s,g}et_{configuration,interface} won't work.
-        * may the setter works and getter are poorly implemented?
-        * however, I try here some interrupt inputs, assuming 
-        * the setters are fine*/
-
-       memset(buf, 0, 8);
-       s8 epnum = dev->conf->intf->endp->bEndpointAddress & 0xf;
-       printf("epnum: 0x%04X\n", epnum);
-       u8 muh = 10;
-       while(muh--) {
-               (void) usb_interrupt_read(dev, epnum, buf, 8, 0);
-               printf("============\nusb_interrupt_read:\n");
-               hexdump((void*)buf, 8);
-               udelay(2000000);
-       }
-#endif
+       lsusb(dev);
 
-#if 0
        /* add device to device list */
-       element *tmp = (element *) malloc(sizeof(element));
+       struct element *tmp = (struct element *) malloc(sizeof(struct element));
        tmp->data = (void *) dev;
        list_add_tail(core.devices, tmp);
 
        usb_probe_driver();
-#endif
 
        return dev;
 }
@@ -277,19 +232,34 @@ void lsusb(struct usb_device *dev)
  * Find currently detached device and remove
  * data structures
  */
-u8 usb_remove_device(struct usb_device * dev)
+u8 usb_remove_device(struct usb_device *dev)
 {
-       // FIXME!!!! dieser quatsch ist nur temporaer
-       free(core.devices->head);
-       free(core.devices);
-       core.devices = list_create();
+       /* trigger driver for this device */
+       struct usb_driver *drv;
+       struct element *iterator = core.drivers->head;
+       while (iterator != NULL) {
+               drv = (struct usb_driver *) iterator->data;
+               if(drv->data && !memcmp(drv->data, dev, sizeof(struct usb_device))) {
+                       drv->remove();
+                       break;
+               }
+               iterator = iterator->next;
+       }
+
+       /* remove from device list */
+       struct element *tmp = (struct element *) malloc(sizeof(struct element));
+       tmp->data = (void *) dev;
+       list_delete_element(core.devices, tmp);
+
+       printf("REMOVED\n");
+
        return 1;
 }
 
 /**
  * Register new driver at usb stack.
  */
-u8 usb_register_driver(struct usb_driver * dev)
+u8 usb_register_driver(struct usb_driver *dev)
 {
        /* add driver to driver list */
        struct element *tmp = (struct element *) malloc(sizeof(struct element));
@@ -297,7 +267,6 @@ u8 usb_register_driver(struct usb_driver * dev)
        tmp->next = NULL;
        list_add_tail(core.drivers, tmp);
 
-
        /** 
         * first check to find a suitable device 
         * (root hub drivers need this call here)