Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 3b9f1fd in mainline


Ignore:
Timestamp:
2010-12-12T14:50:18Z (11 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master
Children:
403bb26, 8e8289d, c9113d2
Parents:
1f3158c (diff), 16ecc28 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge from smekideki

Location:
uspace/drv/usbhub
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/main.c

    r1f3158c r3b9f1fd  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 #include <usb/usbdrv.h>
     28
    2929#include <driver.h>
    3030#include <errno.h>
     31#include <async.h>
     32
     33#include <usb/usbdrv.h>
    3134#include "usbhub.h"
    3235#include "usbhub_private.h"
     
    4447};
    4548
     49int usb_hub_control_loop(void * noparam){
     50        while(true){
     51                usb_hub_check_hub_changes();
     52                async_usleep(10000);
     53        }
     54        return 0;
     55}
     56
     57
    4658int main(int argc, char *argv[])
    4759{
    4860        usb_lst_init(&usb_hub_list);
     61        fid_t fid = fibril_create(usb_hub_control_loop, NULL);
     62        if (fid == 0) {
     63                printf("%s: failed to start fibril for HUB devices\n", NAME);
     64                return ENOMEM;
     65        }
     66        fibril_add_ready(fid);
     67
    4968        return driver_main(&hub_driver);
    5069}
  • uspace/drv/usbhub/usbhub.h

    r1f3158c r3b9f1fd  
    4646        /** Number of ports. */
    4747        int port_count;
    48         /** General device info. */
    49         usb_hcd_attached_device_info_t * device;
     48        /** General usb device info. */
     49        usb_hcd_attached_device_info_t * usb_device;
     50        /** General device info*/
     51        device_t * device;
     52
    5053} usb_hub_info_t;
    5154
    52 int usb_add_hub_device(device_t *);
     55/**
     56 * function running the hub-controlling loop.
     57 * @param noparam fundtion does not need any parameters
     58 */
     59int usb_hub_control_loop(void * noparam);
     60
     61/** Callback when new hub device is detected.
     62 *
     63 * @param dev New device.
     64 * @return Error code.
     65 */
     66int usb_add_hub_device(device_t *dev);
     67
     68/**
     69 * check changes on all registered hubs
     70 */
     71void usb_hub_check_hub_changes(void);
     72
     73
     74//int usb_add_hub_device(device_t *);
     75
     76
    5377
    5478#endif
  • uspace/drv/usbhub/utils.c

    r1f3158c r3b9f1fd  
    3434 */
    3535#include <driver.h>
    36 #include <usb/devreq.h>
     36#include <bool.h>
     37#include <errno.h>
     38
    3739#include <usbhc_iface.h>
    3840#include <usb/usbdrv.h>
    3941#include <usb/descriptor.h>
    40 #include <driver.h>
    41 #include <bool.h>
    42 #include <errno.h>
     42#include <usb/devreq.h>
    4343#include <usb/classes/hub.h>
     44
    4445#include "usbhub.h"
    4546#include "usbhub_private.h"
    4647#include "port_status.h"
    47 #include <usb/devreq.h>
    48 
    49 static void check_hub_changes(void);
     48
    5049
    5150size_t USB_HUB_MAX_DESCRIPTOR_SIZE = 71;
     
    302301        //result->device = device;
    303302        result->port_count = -1;
     303        /// \TODO is this correct? is the device stored?
     304        result->device = device;
    304305
    305306
     
    316317        }*/
    317318
    318         result->device = usb_new(usb_hcd_attached_device_info_t);
    319         result->device->address = addr;
     319        result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     320        result->usb_device->address = addr;
    320321
    321322        // get hub descriptor
     
    362363}
    363364
    364 /** Callback when new hub device is detected.
    365  *
    366  * @param dev New device.
    367  * @return Error code.
    368  */
    369365int usb_add_hub_device(device_t *dev) {
    370366        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
     
    387383        usb_device_request_setup_packet_t request;
    388384        usb_target_t target;
    389         target.address = hub_info->device->address;
     385        target.address = hub_info->usb_device->address;
    390386        target.endpoint = 0;
    391387        for (port = 0; port < hub_info->port_count; ++port) {
     
    404400        printf("[usb_hub] hub info added to list\n");
    405401        //(void)hub_info;
    406         check_hub_changes();
     402        usb_hub_check_hub_changes();
    407403
    408404        /// \TODO start the check loop, if not already started...
     
    412408
    413409        printf("[usb_hub] hub dev added\n");
     410        printf("\taddress %d, has %d ports \n",
     411                        hub_info->usb_device->address,
     412                        hub_info->port_count);
    414413
    415414        return EOK;
     
    429428 * @param target
    430429 */
    431 
    432430static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
    433431        usb_device_request_setup_packet_t request;
     
    459457 * @param target
    460458 */
    461 static void usb_hub_finalize_add_device(
     459static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    462460                int hc, uint16_t port, usb_target_t target) {
    463461
     
    479477                return;
    480478        }
     479
     480
    481481        usb_drv_release_default_address(hc);
    482482
    483 
    484         /// \TODO driver work
    485         //add_child_device.....
     483        devman_handle_t child_handle;
     484        opResult = usb_drv_register_child_in_devman(hc, hub->device,
     485        new_device_address, &child_handle);
     486        if (opResult != EOK) {
     487                printf("[usb_hub] could not start driver for new device \n");
     488                return;
     489        }
     490        usb_drv_bind_address(hc, new_device_address, child_handle);
     491       
    486492}
    487493
     
    519525 * @param target
    520526 */
    521 static void usb_hub_process_interrupt(int hc, uint16_t port, usb_target_t target) {
     527static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
    522528        printf("[usb_hub] interrupt at port %d\n", port);
    523529        //determine type of change
     
    554560                printf("[usb_hub] finalizing add device\n");
    555561                if (usb_port_enabled(&status)) {
    556                         usb_hub_finalize_add_device(hc, port, target);
     562                        usb_hub_finalize_add_device(hub, hc, port, target);
    557563                } else {
    558564                        printf("[usb_hub] ERROR: port reset, but port still not enabled\n");
     
    585591/** Check changes on all known hubs.
    586592 */
    587 static void check_hub_changes(void) {
     593void usb_hub_check_hub_changes(void) {
    588594        /*
    589595         * Iterate through all hubs.
     
    594600                        lst_item = lst_item->next) {
    595601                printf("[usb_hub] checking hub changes\n");
     602                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
    596603                /*
    597604                 * Check status change pipe of this hub.
    598605                 */
    599606
    600                 usb_target_t target = {
    601                         .address = 5,
    602                         .endpoint = 1
    603                 };
    604                 /// \TODO uncomment once it works correctly
    605                 //target.address = usb_create_hub_info(lst_item)->device->address;
    606 
    607                 size_t port_count = 7;
     607                usb_target_t target;
     608                target.address = hub_info->usb_device->address;
     609                target.endpoint = 1;
     610
     611                size_t port_count = hub_info->port_count;
    608612
    609613                /*
    610614                 * Connect to respective HC.
    611615                 */
    612                 /// \FIXME this is incorrect code: here
    613                 /// must be used particular device instead of NULL
    614                 //which one?
    615                 int hc = usb_drv_hc_connect(NULL, 0);
     616                int hc = usb_drv_hc_connect(hub_info->device, 0);
    616617                if (hc < 0) {
    617618                        continue;
     
    642643                        bool interrupt = (((uint8_t*) change_bitmap)[port / 8] >> (port % 8)) % 2;
    643644                        if (interrupt) {
    644                                 usb_hub_process_interrupt(hc, port, target);
     645                                usb_hub_process_interrupt(hub_info, hc, port, target);
    645646                        }
    646647                }
Note: See TracChangeset for help on using the changeset viewer.