Changeset 578a2547 in mainline


Ignore:
Timestamp:
2011-04-07T12:01:05Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3eaa5a5
Parents:
9f9b31ad
Message:

Hub driver uses standard wrapper for new devices

To allow usage of the standard function, the port reset signalling
must be done through condition variable.

Location:
uspace/drv/usbhub
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/Makefile

    r9f9b31ad r578a2547  
    3434SOURCES = \
    3535        main.c \
     36        ports.c \
    3637        utils.c \
    3738        usbhub.c \
  • uspace/drv/usbhub/usbhub.c

    r9f9b31ad r578a2547  
    5454
    5555
    56 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
    57                 usb_speed_t speed);
     56//static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
     57//              usb_speed_t speed);
    5858
    5959static int usb_hub_trigger_connecting_non_removable_devices(
    6060                usb_hub_info_t * hub, usb_hub_descriptor_t * descriptor);
    6161
     62#if 0
    6263/**
    6364 * control loop running in hub`s fibril
     
    8182        return 0;
    8283}
     84#endif
    8385
    8486
     
    152154        usb_log_debug("setting port count to %d\n",descriptor->ports_count);
    153155        hub_info->port_count = descriptor->ports_count;
    154         hub_info->attached_devs = (usb_hc_attached_device_t*)
    155             malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t));
    156         int i;
    157         for(i=0;i<hub_info->port_count+1;++i){
    158                 hub_info->attached_devs[i].handle=0;
    159                 hub_info->attached_devs[i].address=0;
     156        hub_info->ports = malloc(sizeof(usb_hub_port_t) * (hub_info->port_count+1));
     157        size_t port;
     158        for (port = 0; port < hub_info->port_count + 1; port++) {
     159                usb_hub_port_init(&hub_info->ports[port]);
    160160        }
    161161        //handle non-removable devices
     
    259259        assert(rc == EOK);
    260260
    261         //create fibril for the hub control loop
    262         fid_t fid = fibril_create(usb_hub_control_loop, hub_info);
    263         if (fid == 0) {
    264                 usb_log_error("failed to start monitoring fibril for new hub.\n");
    265                 return ENOMEM;
    266         }
    267         fibril_add_ready(fid);
    268         usb_log_debug("Hub fibril created.\n");
     261        /*
     262         * The processing will require opened control pipe and connection
     263         * to the host controller.
     264         * It is waste of resources but let's hope there will be less
     265         * hubs than the phone limit.
     266         * FIXME: with some proper locking over pipes and session
     267         * auto destruction, this could work better.
     268         */
     269        rc = usb_pipe_start_session(&usb_dev->ctrl_pipe);
     270        if (rc != EOK) {
     271                usb_log_error("Failed to start session on control pipe: %s.\n",
     272                    str_error(rc));
     273                goto leave;
     274        }
     275        rc = usb_hc_connection_open(&hub_info->connection);
     276        if (rc != EOK) {
     277                usb_pipe_end_session(&usb_dev->ctrl_pipe);
     278                usb_log_error("Failed to open connection to HC: %s.\n",
     279                    str_error(rc));
     280                goto leave;
     281        }
     282
     283        rc = usb_device_auto_poll(hub_info->usb_device, 0,
     284            hub_port_changes_callback, ((hub_info->port_count+1) / 8) + 1,
     285            NULL, hub_info);
     286        if (rc != EOK) {
     287                usb_log_error("Failed to create polling fibril: %s.\n",
     288                    str_error(rc));
     289                free(hub_info);
     290                return rc;
     291        }
    269292
    270293        usb_log_info("Controlling hub `%s' (%d ports).\n",
    271294            hub_info->usb_device->ddf_dev->name, hub_info->port_count);
    272295        return EOK;
     296
     297leave:
     298        free(hub_info);
     299
     300        return rc;
    273301}
    274302
     
    399427}
    400428
     429#if 0
    401430/**
    402431 * Reset the port with new device and reserve the default address.
     
    440469        return;
    441470}
    442 
     471#endif
     472
     473#if 0
    443474/**
    444475 * Finalize adding new device after port reset
     
    529560            new_device_address, child_handle);
    530561}
     562#endif
    531563
    532564/**
     
    539571 * @param port port number, starting from 1
    540572 */
    541 static void usb_hub_removed_device(
     573void usb_hub_removed_device(
    542574    usb_hub_info_t * hub,uint16_t port) {
    543575
     
    552584       
    553585        //close address
    554         if(hub->attached_devs[port].address!=0){
     586        if(hub->ports[port].attached_device.address >= 0){
    555587                /*uncomment this code to use it when DDF allows device removal
    556588                opResult = usb_hc_unregister_device(
     
    579611 * @param port port number, starting from 1
    580612 */
    581 static void usb_hub_over_current( usb_hub_info_t * hub,
     613void usb_hub_over_current( usb_hub_info_t * hub,
    582614                uint16_t port){
    583615        int opResult;
     
    590622}
    591623
     624#if 0
    592625/**
    593626 * Process interrupts on given hub port
     
    737770        return EOK;
    738771}
    739 
     772#endif
    740773
    741774
  • uspace/drv/usbhub/usbhub.h

    r9f9b31ad r578a2547  
    4747#include <usb/devdrv.h>
    4848
     49#include "ports.h"
     50
     51
    4952
    5053/** Information about attached hub. */
    5154typedef struct {
    5255        /** Number of ports. */
    53         int port_count;
     56        size_t port_count;
    5457
    55         /** attached device handles, for each port one */
    56         usb_hc_attached_device_t * attached_devs;
     58        /** Ports. */
     59        usb_hub_port_t *ports;
    5760       
    5861        /** connection to hcd */
     
    100103int usb_hub_check_hub_changes(usb_hub_info_t * hub_info_param);
    101104
     105void usb_hub_removed_device(usb_hub_info_t *, uint16_t);
     106void usb_hub_over_current(usb_hub_info_t *, uint16_t);
    102107
    103108int usb_hub_add_device(usb_device_t * usb_dev);
Note: See TracChangeset for help on using the changeset viewer.