some routines for removing a device on demand. thist do not work properly origin/master
authorBernhard Urban <lewurm@gmx.net>
Sat, 26 Sep 2009 09:15:00 +0000 (11:15 +0200)
committerBernhard Urban <lewurm@gmx.net>
Sat, 26 Sep 2009 09:15:00 +0000 (11:15 +0200)
(TODO!)

main.c
usb/core/core.c
usb/core/core.h
usb/drivers/class/hid.c
usb/drivers/class/hid.h
usb/host/ohci.c
usb/lib/list.c

diff --git a/main.c b/main.c
index 530d9e827ca2be63858d8526bf2e36dc7da1d148..67d6d88c26a3224b997f44b943af21462bb2cac0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -128,6 +128,7 @@ int main(void)
        /* load HID keyboard driver */
        usb_hidkb_init();
 
        /* load HID keyboard driver */
        usb_hidkb_init();
 
+wait_kb:
        /* wait for usb keyboard plugged in */
        if(!usb_hidkb_inuse()) {
                print_str("plug in an usb keyboard", 23);
        /* wait for usb keyboard plugged in */
        if(!usb_hidkb_inuse()) {
                print_str("plug in an usb keyboard", 23);
@@ -149,7 +150,7 @@ int main(void)
        u16 old_x, old_y;
        struct kbrep *k, *old=NULL;
 
        u16 old_x, old_y;
        struct kbrep *k, *old=NULL;
 
-       while(1) {
+       while(usb_hidkb_inuse()) {
                memset(str, '\0', 7);
                k = usb_hidkb_getChars();
                j=0;
                memset(str, '\0', 7);
                k = usb_hidkb_getChars();
                j=0;
@@ -219,6 +220,8 @@ int main(void)
                }
        }
 
                }
        }
 
+       goto wait_kb;
+
 #if 0
        printf("===============================\n");
 
 #if 0
        printf("===============================\n");
 
index 0b38e77d6c34ec6136a360041ba6d087ceee49f7..97acc56a57be1e7a66d1b0fbded801c2396e6540 100644 (file)
@@ -120,8 +120,8 @@ struct usb_device *usb_add_device(u8 lowspeed, u32 reg)
        if(ret < 0) {
                return (void*) -1;
        }
        if(ret < 0) {
                return (void*) -1;
        }
-
-#define WTF
+//
+//#define WTF
 #ifdef WTF
        volatile u8 wzf = 11;
        if(0 == wzf) {
 #ifdef WTF
        volatile u8 wzf = 11;
        if(0 == wzf) {
@@ -232,12 +232,27 @@ void lsusb(struct usb_device *dev)
  * Find currently detached device and remove
  * data structures
  */
  * 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;
 }
 
        return 1;
 }
 
index ce9cecf4ba8f51c7d8ba00657e53af53f1b7cf5d..98ab7ea3641581a53f191cd7088123f4ee6d4e6e 100644 (file)
@@ -145,6 +145,7 @@ struct usb_driver {
        char* name;
        void (*probe)(void);
        void (*check)(void);
        char* name;
        void (*probe)(void);
        void (*check)(void);
+       void (*remove)(void);
        void *data;
        struct usb_driver *next;
 };
        void *data;
        struct usb_driver *next;
 };
index b79bcd3f85c77db2e25aeef73f13cd4e04483672..933b592073e938dedb1d09c47207563bf762b38d 100644 (file)
@@ -21,6 +21,7 @@ struct usb_driver hidkb = {
        .name     = "hidkb",
        .probe  = usb_hidkb_probe,
        .check  = usb_hidkb_check,
        .name     = "hidkb",
        .probe  = usb_hidkb_probe,
        .check  = usb_hidkb_check,
+       .remove = usb_hidkb_remove,
        .data     = NULL
 };
 
        .data     = NULL
 };
 
@@ -90,6 +91,10 @@ u8 usb_hidkb_inuse()
        return hidkb.data ? 1 : 0;
 }
 
        return hidkb.data ? 1 : 0;
 }
 
+void usb_hidkb_remove() {
+       hidkb.data = NULL;
+}
+
 struct kbrep *usb_hidkb_getChars() {
        struct usb_device *dev = (struct usb_device*) hidkb.data;
        struct kbrep *ret = (struct kbrep*) malloc(sizeof(struct kbrep));
 struct kbrep *usb_hidkb_getChars() {
        struct usb_device *dev = (struct usb_device*) hidkb.data;
        struct kbrep *ret = (struct kbrep*) malloc(sizeof(struct kbrep));
index e8218ad9778298a6f248c7d8758e1bc8a6329707..04a278662cf88ec71e2cd341fa9804ae9e92a724 100644 (file)
@@ -36,6 +36,7 @@ u8 usb_hidkb_inuse();
 struct kbrep *usb_hidkb_getChars();
 unsigned char usb_hidkb_get_char_from_keycode(u8 keycode, int shifted);
 void usb_hidkb_set_idle(struct usb_device *dev, u8 duration);
 struct kbrep *usb_hidkb_getChars();
 unsigned char usb_hidkb_get_char_from_keycode(u8 keycode, int shifted);
 void usb_hidkb_set_idle(struct usb_device *dev, u8 duration);
+void usb_hidkb_remove();
 
 #endif /* __HID_H */
 
 
 #endif /* __HID_H */
 
index f243bcad9f56c7f6040eccc5c599cbb3fc4b4424..64b77deda2634fe669f85bd3fef6713b8f372a7a 100644 (file)
@@ -34,7 +34,7 @@ Copyright (C) 2009     Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
 static struct general_td *allocate_general_td();
 static void dbg_op_state(u32 reg);
 static void configure_ports(u8 from_init, u32 reg);
 static struct general_td *allocate_general_td();
 static void dbg_op_state(u32 reg);
 static void configure_ports(u8 from_init, u32 reg);
-static void setup_port(u32 ohci, u32 reg, u8 from_init);
+static struct usb_device *setup_port(u32 ohci, u32 reg, u8 pport, u8 from_init);
 static void set_target_hcca(u32 reg);
 
 static struct ohci_hcca hcca_oh0;
 static void set_target_hcca(u32 reg);
 
 static struct ohci_hcca hcca_oh0;
@@ -498,6 +498,7 @@ void hcdi_init(u32 reg)
        dbg_op_state(reg);
 }
 
        dbg_op_state(reg);
 }
 
+static struct usb_device *connected[2] = {NULL, NULL};
 static void configure_ports(u8 from_init, u32 reg)
 {
 #ifdef _DU_OHCI_RH
 static void configure_ports(u8 from_init, u32 reg)
 {
 #ifdef _DU_OHCI_RH
@@ -509,14 +510,31 @@ static void configure_ports(u8 from_init, u32 reg)
        printf("OHCI_HC_RH_PORT_STATUS_2:\t0x%08X\n", read32(reg+OHCI_HC_RH_PORT_STATUS_2));
 #endif
 
        printf("OHCI_HC_RH_PORT_STATUS_2:\t0x%08X\n", read32(reg+OHCI_HC_RH_PORT_STATUS_2));
 #endif
 
-       setup_port(reg, reg+OHCI_HC_RH_PORT_STATUS_1, from_init);
-       setup_port(reg, reg+OHCI_HC_RH_PORT_STATUS_2, from_init);
+       struct usb_device *dtmp;
+       if(!(dtmp = setup_port(reg, reg+OHCI_HC_RH_PORT_STATUS_1, 0, from_init))) {
+               if(connected[0]) {
+                       usb_remove_device(connected[0]);
+                       connected[0] = NULL;
+               }
+       } else {
+               connected[0] = dtmp;
+       }
+
+       if(!(dtmp = setup_port(reg, reg+OHCI_HC_RH_PORT_STATUS_2, 1, from_init))) {
+               if(connected[1]) {
+                       usb_remove_device(connected[1]);
+                       connected[1] = NULL;
+               }
+       } else {
+               connected[1] = dtmp;
+       }
+
 #ifdef _DU_OHCI_RH
        printf("configure_ports done\n");
 #endif
 }
 
 #ifdef _DU_OHCI_RH
        printf("configure_ports done\n");
 #endif
 }
 
-static void setup_port(u32 ohci, u32 reg, u8 from_init)
+static struct usb_device *setup_port(u32 ohci, u32 reg, u8 pport, u8 from_init)
 {
        u32 port = read32(reg);
        if((port & RH_PS_CCS) && ((port & RH_PS_CSC) || from_init)) {
 {
        u32 port = read32(reg);
        if((port & RH_PS_CCS) && ((port & RH_PS_CSC) || from_init)) {
@@ -530,7 +548,7 @@ static void setup_port(u32 ohci, u32 reg, u8 from_init)
 #ifdef _DU_OHCI_RH
                        printf("fu\n");
 #endif
 #ifdef _DU_OHCI_RH
                        printf("fu\n");
 #endif
-                       return;
+                       return NULL;
                }
 
                write32(reg, RH_PS_PRS);
                }
 
                write32(reg, RH_PS_PRS);
@@ -542,8 +560,12 @@ static void setup_port(u32 ohci, u32 reg, u8 from_init)
 #endif
 
                /* returns usb_device struct */
 #endif
 
                /* returns usb_device struct */
-               (void) usb_add_device((read32(reg) & RH_PS_LSDA) >> 8, ohci);
+               return usb_add_device((read32(reg) & RH_PS_LSDA) >> 8, ohci);
+       }
+       if(port & RH_PS_CCS) {
+               return connected[pport];
        }
        }
+       return NULL;
 }
 
 void hcdi_irq(u32 reg)
 }
 
 void hcdi_irq(u32 reg)
index 39c94392da4eb7ff0da7530baf56e4b14f8d06cb..9ea2090c5a0254eb6b430198380ff14d47cabcfb 100644 (file)
@@ -34,6 +34,8 @@
 //#include <stdlib.h>
 #include "list.h"
 #include "../../malloc.h"
 //#include <stdlib.h>
 #include "list.h"
 #include "../../malloc.h"
+#include "../../string.h"
+#include "../../bootmii_ppc.h"
 
 struct list* list_create()
 {
 
 struct list* list_create()
 {
@@ -53,7 +55,7 @@ u8 list_add_tail(struct list *l, struct element *e)
        }
 
        /* find last element */
        }
 
        /* find last element */
-       struct element * iterator = l->head;
+       struct element *iterator = l->head;
 
        while(iterator->next!=NULL) {
                iterator = iterator->next;
 
        while(iterator->next!=NULL) {
                iterator = iterator->next;
@@ -65,9 +67,36 @@ u8 list_add_tail(struct list *l, struct element *e)
 
 
 
 
 
 
-// FIXME: untested and unused!! 
+// FIXME: untested
 u8 list_delete_element(struct list *l, struct element *e)
 {
 u8 list_delete_element(struct list *l, struct element *e)
 {
+       struct element *iterator = l->head;
+       struct element *delete = NULL;
+
+       if(!l->head) {
+               return 0;
+       } else {
+               if(l->head->data && !(memcmp(l->head->data, e->data, sizeof(struct element)))) {
+                       delete = l->head;
+                       l->head = NULL;
+               }
+       }
+
+       while(iterator->next!=NULL) {
+               if(iterator->next->data && !(memcmp(iterator->next->data, e->data, sizeof(struct element)))) {
+                       delete = iterator->next;
+                       iterator->next = iterator->next->next;
+                       break;
+               }
+
+               iterator = iterator->next;
+       } 
+
+       if(delete) {
+               free(delete->data);
+               free(delete);
+       }
+       
        return 1;
 }
 
        return 1;
 }