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

Changeset 03171de in mainline


Ignore:
Timestamp:
2010-11-24T14:27:33Z (11 years ago)
Author:
smekideki@…>
Branches:
lfn, master
Children:
2e15ac40, bbe7848
Parents:
8cd1aa5e
Message:

basic hub driver structures

Location:
uspace/lib/usb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/classes/hub.h

    r8cd1aa5e r03171de  
    3636#define LIBUSB_HUB_H_
    3737
    38 /** Hub class request. */
    39 typedef enum {
    40         USB_HUB_REQUEST_GET_STATUS = 0,
    41         USB_HUB_REQUEST_CLEAR_FEATURE = 1,
    42         USB_HUB_REQUEST_GET_STATE = 2,
    43         USB_HUB_REQUEST_SET_FEATURE = 3,
    44         USB_HUB_REQUEST_GET_DESCRIPTOR = 6,
    45         USB_HUB_REQUEST_SET_DESCRIPTOR = 7,
    46         /* USB_HUB_REQUEST_ = , */
    47 } usb_hub_class_request_t;
     38#include <sys/types.h>
     39
    4840
    4941/** Hub class feature selector.
     
    6961} usb_hub_class_feature_t;
    7062
     63
     64/**
     65 *      @brief usb hub descriptor
     66 *
     67 *      For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2
     68 */
     69typedef struct hub_descriptor_type{
     70    /** Number of bytes in this descriptor, including this byte */
     71    //uint8_t bDescLength;
     72
     73    /** Descriptor Type, value: 29H for hub descriptor */
     74    //uint8_t bDescriptorType;
     75
     76    /** Number of downstream ports that this hub supports */
     77    uint8_t ports_count;
     78
     79    /**
     80            D1...D0: Logical Power Switching Mode
     81            00: Ganged power switching (all ports’ power at
     82            once)
     83            01: Individual port power switching
     84            1X: Reserved. Used only on 1.0 compliant hubs
     85            that implement no power switching.
     86            D2: Identifies a Compound Device
     87            0: Hub is not part of a compound device
     88            1: Hub is part of a compound device
     89            D4...D3: Over-current Protection Mode
     90            00: Global Over-current Protection. The hub
     91            reports over-current as a summation of all
     92            ports’ current draw, without a breakdown of
     93            individual port over-current status.
     94            01: Individual Port Over-current Protection. The
     95            hub reports over-current on a per-port basis.
     96            Each port has an over-current indicator.
     97            1X: No Over-current Protection. This option is
     98            allowed only for bus-powered hubs that do not
     99            implement over-current protection.
     100            D15...D5:
     101            Reserved
     102     */
     103    uint16_t hub_characteristics;
     104
     105    /**
     106            Time (in 2ms intervals) from the time the power-on
     107            sequence begins on a port until power is good on that
     108            port. The USB System Software uses this value to
     109            determine how long to wait before accessing a
     110            powered-on port.
     111     */
     112    uint8_t pwr_on_2_good_time;
     113
     114    /**
     115            Maximum current requirements of the Hub Controller
     116            electronics in mA.
     117     */
     118    uint8_t current_requirement;
     119
     120    /**
     121            Indicates if a port has a removable device attached.
     122            This field is reported on byte-granularity. Within a
     123            byte, if no port exists for a given location, the field
     124            representing the port characteristics returns 0.
     125            Bit value definition:
     126            0B - Device is removable
     127            1B - Device is non-removable
     128            This is a bitmap corresponding to the individual ports
     129            on the hub:
     130            Bit 0: Reserved for future use
     131            Bit 1: Port 1
     132            Bit 2: Port 2
     133            ....
     134            Bit n: Port n (implementation-dependent, up to a
     135            maximum of 255 ports).
     136     */
     137    uint8_t * devices_removable;
     138
     139    /**
     140            This field exists for reasons of compatibility with
     141            software written for 1.0 compliant devices. All bits in
     142            this field should be set to 1B. This field has one bit for
     143            each port on the hub with additional pad bits, if
     144            necessary, to make the number of bits in the field an
     145            integer multiple of 8.
     146     */
     147    //uint8_t * port_pwr_ctrl_mask;
     148} usb_hub_descriptor_t;
     149
     150/**
     151 *      Maximum size of usb hub descriptor in bytes
     152 */
     153extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE;
     154
     155/**
     156 *      hub descriptor type
     157 */
     158extern uint8_t USB_HUB_DESCRIPTOR_TYPE;
     159
     160/**
     161 * @brief create uint8_t array with serialized descriptor
     162 *
     163 * @param descriptor
     164 */
     165void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor);
     166
     167/**
     168 * @brief create deserialized desriptor structure out of serialized descriptor
     169 *
     170 * The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur.
     171 *
     172 * @param sdescriptor serialized descriptor
     173 */
     174usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
     175
     176/**     @brief usb hub specific request types.
     177 *
     178 *      For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2
     179 */
     180typedef enum {
     181    /** This request resets a value reported in the hub status. */
     182    USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE = 0x20,
     183    /** This request resets a value reported in the port status. */
     184    USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE = 0x23,
     185    /** This is an optional per-port diagnostic request that returns the bus state value, as sampled at the last EOF2 point. */
     186    USB_HUB_REQ_TYPE_GET_STATE = 0xA3,
     187    /** This request returns the hub descriptor. */
     188    USB_HUB_REQ_TYPE_GET_DESCRIPTOR = 0xA0,
     189    /** This request returns the current hub status and the states that have changed since the previous acknowledgment. */
     190    USB_HUB_REQ_TYPE_GET_HUB_STATUS = 0xA0,
     191    /** This request returns the current port status and the current value of the port status change bits. */
     192    USB_HUB_REQ_TYPE_GET_PORT_STATUS = 0xA3,
     193    /** This request overwrites the hub descriptor. */
     194    USB_HUB_REQ_TYPE_SET_DESCRIPTOR = 0x20,
     195    /** This request sets a value reported in the hub status. */
     196    USB_HUB_REQ_TYPE_SET_HUB_FEATURE = 0x20,
     197    /** This request sets a value reported in the port status. */
     198    USB_HUB_REQ_TYPE_SET_PORT_FEATURE = 0x23
     199} usb_hub_bm_request_type_t;
     200
     201/** @brief hub class request codes*/
     202typedef enum {
     203    /**  */
     204    USB_HUB_REQUEST_GET_STATUS = 0,
     205    /** */
     206    USB_HUB_REQUEST_CLEAR_FEATURE = 1,
     207    /** */
     208    USB_HUB_REQUEST_GET_STATE = 2,
     209    /** */
     210    USB_HUB_REQUEST_SET_FEATURE = 3,
     211    /** */
     212    USB_HUB_REQUEST_GET_DESCRIPTOR = 6,
     213    /** */
     214    USB_HUB_REQUEST_SET_DESCRIPTOR = 7
     215} usb_hub_request_t;
     216
     217
     218
     219
     220
    71221#endif
    72222/**
  • uspace/lib/usb/src/hcdhubd.c

    r8cd1aa5e r03171de  
    3939#include <bool.h>
    4040#include <errno.h>
     41#include <usb/classes/hub.h>
    4142
    4243#define USB_HUB_DEVICE_NAME "usbhub"
     
    5758};
    5859
     60size_t USB_HUB_MAX_DESCRIPTOR_SIZE = 71;
     61
     62uint8_t USB_HUB_DESCRIPTOR_TYPE = 0x29;
     63
     64//*********************************************
     65//
     66//  various utils
     67//
     68//*********************************************
     69
     70
     71void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor){
     72        //base size
     73        size_t size = 7;
     74        //variable size according to port count
     75        size_t var_size = descriptor->ports_count / 8 + ((descriptor->ports_count % 8>0)?1:0);
     76        size += 2 * var_size;
     77        uint8_t * result = (uint8_t*) malloc(size);
     78        //size
     79        result[0]=size;
     80        //descriptor type
     81        result[1]=USB_HUB_DESCRIPTOR_TYPE;
     82        result[2]=descriptor->ports_count;
     83        /// @fixme handling of endianness??
     84        result[3]=descriptor->hub_characteristics / 256;
     85        result[4]=descriptor->hub_characteristics % 256;
     86        result[5]=descriptor->pwr_on_2_good_time;
     87        result[6]=descriptor->current_requirement;
     88
     89        size_t i;
     90        for(i=0;i<var_size;++i){
     91                result[7+i]=descriptor->devices_removable[i];
     92        }
     93        for(i=0;i<var_size;++i){
     94                result[7+var_size+i]=255;
     95        }
     96        return result;
     97}
     98
     99usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * serialized_descriptor){
     100        uint8_t * sdescriptor = (uint8_t*)serialized_descriptor;
     101        if(sdescriptor[1]!=USB_HUB_DESCRIPTOR_TYPE) return NULL;
     102        usb_hub_descriptor_t * result = (usb_hub_descriptor_t*) malloc(sizeof(usb_hub_descriptor_t));
     103        //uint8_t size = sdescriptor[0];
     104        result->ports_count = sdescriptor[2];
     105        /// @fixme handling of endianness??
     106        result->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3];
     107        result->pwr_on_2_good_time=sdescriptor[5];
     108        result->current_requirement=sdescriptor[6];
     109        size_t var_size = result->ports_count / 8 + ((result->ports_count % 8>0)?1:0);
     110        result->devices_removable = (uint8_t*)malloc(var_size);
     111
     112        size_t i;
     113        for(i=0;i<var_size;++i){
     114                result->devices_removable[i] = sdescriptor[7+i];
     115        }
     116        return result;
     117}
     118
     119
     120//*********************************************
     121//
     122//  hub driver code
     123//
     124//*********************************************
     125
     126
     127
    59128static void set_hub_address(usb_hc_device_t *hc, usb_address_t address);
    60129
     
    62131 *
    63132 * @param dev New device.
    64  * @return Error code.
     133 * @return Error code.hub added, hurrah!\n"
    65134 */
    66135static int add_device(device_t *dev)
     
    109178                 * connected devices.
    110179                 */
     180                //insert hub into list
     181                //find owner hcd
     182                device_t * my_hcd = dev;
     183                while(my_hcd->parent)
     184                    my_hcd = my_hcd->parent;
     185                //dev->
     186                printf("%s: owner hcd found: %s\n",hc_driver->name, my_hcd->name);
     187
    111188
    112189                return ENOTSUP;
Note: See TracChangeset for help on using the changeset viewer.