Changeset ff8ed06 in mainline for uspace/drv


Ignore:
Timestamp:
2011-01-15T10:33:29Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
13101d06
Parents:
c9d5577 (diff), fbddf94 (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 development/ changes

Location:
uspace/drv
Files:
4 added
6 edited

Legend:

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

    rc9d5577 rff8ed06  
    5252        while(true){
    5353                usb_hub_check_hub_changes();
    54                 async_usleep(1000 * 1000);
     54                async_usleep(1000 * 1000 );/// \TODO proper number once
    5555        }
    5656        return 0;
  • uspace/drv/usbhub/usbhub.c

    rc9d5577 rff8ed06  
    4646#include "usbhub_private.h"
    4747#include "port_status.h"
     48#include "usb/usb.h"
    4849
    4950static usb_iface_t hub_usb_iface = {
     
    8586
    8687        // get hub descriptor
    87         usb_target_t target;
    88         target.address = addr;
    89         target.endpoint = 0;
    90         usb_device_request_setup_packet_t request;
    91         //printf("[usb_hub] creating descriptor request\n");
    92         usb_hub_set_descriptor_request(&request);
    9388
    9489        //printf("[usb_hub] creating serialized descriptor\n");
     
    9893        int opResult;
    9994        //printf("[usb_hub] starting control transaction\n");
    100         opResult = usb_drv_sync_control_read(
    101                         hc, target, &request, serialized_descriptor,
     95       
     96        opResult = usb_drv_req_get_descriptor(hc, addr,
     97                        USB_REQUEST_TYPE_CLASS,
     98                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    10299                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
     100
    103101        if (opResult != EOK) {
    104102                dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult);
     
    155153        int port;
    156154        int opResult;
    157         usb_device_request_setup_packet_t request;
    158155        usb_target_t target;
    159156        target.address = hub_info->usb_device->address;
     
    173170        if(std_descriptor.configuration_count<1){
    174171                dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE");
     172                //shouldn`t I return?
    175173        }
    176174        /// \TODO check other configurations
     
    184182        }
    185183        //set configuration
    186         request.request_type = 0;
    187         request.request = USB_DEVREQ_SET_CONFIGURATION;
    188         request.index=0;
    189         request.length=0;
    190         request.value_high=0;
    191         request.value_low = config_descriptor.configuration_number;
    192         opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
     184        opResult = usb_drv_req_set_configuration(hc, target.address,
     185    config_descriptor.configuration_number);
     186
    193187        if (opResult != EOK) {
    194188                dprintf(1,"[usb_hub]something went wrong when setting hub`s configuration, %d", opResult);
    195189        }
    196190
     191        usb_device_request_setup_packet_t request;
    197192        for (port = 1; port < hub_info->port_count+1; ++port) {
    198193                usb_hub_set_power_port_request(&request, port);
     
    229224
    230225
    231 
    232226//*********************************************
    233227//
     
    237231
    238232/**
    239  * convenience function for releasing default address and writing debug info
    240  * (these few lines are used too often to be written again and again)
     233 * Convenience function for releasing default address and writing debug info
     234 * (these few lines are used too often to be written again and again).
    241235 * @param hc
    242236 * @return
     
    253247
    254248/**
    255  * reset the port with new device and reserve the default address
     249 * Reset the port with new device and reserve the default address.
    256250 * @param hc
    257251 * @param port
     
    282276
    283277/**
    284  * finalize adding new device after port reset
     278 * Finalize adding new device after port reset
    285279 * @param hc
    286280 * @param port
     
    345339
    346340/**
    347  * unregister device address in hc
     341 * Unregister device address in hc
    348342 * @param hc
    349343 * @param port
     
    355349        int opResult;
    356350       
    357         /// \TODO remove device
     351        /** \TODO remove device from device manager - not yet implemented in
     352         * devide manager
     353         */
    358354
    359355        hub->attached_devs[port].devman_handle=0;
     
    376372
    377373/**
    378  * process interrupts on given hub port
     374 * Process interrupts on given hub port
    379375 * @param hc
    380376 * @param port
     
    434430        usb_port_set_reset_completed(&status, false);
    435431        usb_port_set_dev_connected(&status, false);
    436         if (status) {
    437                 dprintf(1,"[usb_hub]there was some unsupported change on port %d",port);
     432        if (status>>16) {
     433                dprintf(1,"[usb_hub]there was some unsupported change on port %d: %X",port,status);
     434
    438435        }
    439436        /// \TODO handle other changes
     
    442439}
    443440
    444 /* Check changes on all known hubs.
     441/**
     442 * Check changes on all known hubs.
    445443 */
    446444void usb_hub_check_hub_changes(void) {
     
    462460                target.address = hub_info->usb_device->address;
    463461                target.endpoint = 1;/// \TODO get from endpoint descriptor
    464                 dprintf(1,"[usb_hub] checking changes for hub at addr %d",
    465                     target.address);
     462                /*dprintf(1,"[usb_hub] checking changes for hub at addr %d",
     463                    target.address);*/
    466464
    467465                size_t port_count = hub_info->port_count;
  • uspace/drv/usbhub/usbhub_private.h

    rc9d5577 rff8ed06  
    3131 */
    3232/** @file
    33  * @brief Hub driver.
     33 * @brief Hub driver private definitions
    3434 */
    3535
     
    6868
    6969/**
    70  * create hub structure instance
     70 * Create hub structure instance
    7171 *
    7272 * Set the address and port count information most importantly.
     
    7878usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
    7979
    80 /** list of hubs maanged by this driver */
     80/** List of hubs maanged by this driver */
    8181extern usb_general_list_t usb_hub_list;
    8282
    83 /** lock for hub list*/
     83/** Lock for hub list*/
    8484extern futex_t usb_hub_list_lock;
    8585
    8686
    8787/**
    88  * perform complete control read transaction
     88 * Perform complete control read transaction
    8989 *
    90  * manages all three steps of transaction: setup, read and finalize
     90 * Manages all three steps of transaction: setup, read and finalize
    9191 * @param phone
    9292 * @param target
    93  * @param request request for data
    94  * @param rcvd_buffer received data
     93 * @param request Request packet
     94 * @param rcvd_buffer Received data
    9595 * @param rcvd_size
    96  * @param actual_size actual size of received data
     96 * @param actual_size Actual size of received data
    9797 * @return error code
    9898 */
     
    104104
    105105/**
    106  * perform complete control write transaction
     106 * Perform complete control write transaction
    107107 *
    108  * manages all three steps of transaction: setup, write and finalize
     108 * Manages all three steps of transaction: setup, write and finalize
    109109 * @param phone
    110110 * @param target
    111  * @param request request to send data
     111 * @param request Request packet to send data
    112112 * @param sent_buffer
    113113 * @param sent_size
     
    121121
    122122/**
    123  * set the device request to be a get hub descriptor request.
     123 * Set the device request to be a get hub descriptor request.
    124124 * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
    125125 * @param request
     
    137137}
    138138
     139/**
     140 * Clear feature on hub port.
     141 *
     142 * @param hc Host controller telephone
     143 * @param address Hub address
     144 * @param port_index Port
     145 * @param feature Feature selector
     146 * @return Operation result
     147 */
    139148static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
    140149    int port_index,
  • uspace/drv/usbkbd/Makefile

    rc9d5577 rff8ed06  
    3333
    3434SOURCES = \
    35         main.c
     35        main.c \
     36        descparser.c \
     37        descdump.c
    3638
    3739include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/usbkbd/main.c

    rc9d5577 rff8ed06  
    3838#include <usb/devreq.h>
    3939#include <usb/descriptor.h>
     40#include "descparser.h"
     41#include "descdump.h"
    4042
    4143#define BUFFER_SIZE 32
     
    8890 * Callbacks for parser
    8991 */
    90 static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count,
    91                                     void *arg)
    92 {
    93 
     92static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count,
     93                                    uint8_t modifiers, void *arg)
     94{
     95        printf("Got keys: ");
     96        unsigned i;
     97        for (i = 0; i < count; ++i) {
     98                printf("%d ", key_codes[i]);
     99        }
     100        printf("\n");
    94101}
    95102
     
    97104 * Kbd functions
    98105 */
    99 static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev,
    100                                     const uint8_t *data, size_t size)
    101 {
    102 //      const uint8_t *pos = data;
    103        
    104 //      // get the configuration descriptor (should be first)
    105 //      if (*pos != sizeof(usb_standard_configuration_descriptor_t)
    106 //          || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) {
    107 //              fprintf(stderr, "Wrong format of configuration descriptor");
    108 //              return EINVAL;
    109 //      }
    110        
    111 //      usb_standard_configuration_descriptor_t config_descriptor;
    112 //      memcpy(&config_descriptor, pos,
    113 //          sizeof(usb_standard_configuration_descriptor_t));
    114 //      pos += sizeof(usb_standard_configuration_descriptor_t);
    115        
    116 //      // parse other descriptors
    117 //      while (pos - data < size) {
    118 //              //uint8_t desc_size = *pos;
    119 //              uint8_t desc_type = *(pos + 1);
    120 //              switch (desc_type) {
    121 //              case USB_DESCTYPE_INTERFACE:
    122 //                      break;
    123 //              case USB_DESCTYPE_ENDPOINT:
    124 //                      break;
    125 //              case USB_DESCTYPE_HID:
    126 //                      break;
    127 //              case USB_DESCTYPE_HID_REPORT:
    128 //                      break;
    129 //              case USB_DESCTYPE_HID_PHYSICAL:
    130 //                      break;
    131 //              }
    132 //      }
    133        
     106static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev)
     107{
     108        // iterate over all configurations and interfaces
     109        // TODO: more configurations!!
     110        unsigned i;
     111        for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
     112                // TODO: endianness
     113                uint16_t length =
     114                    kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
     115                size_t actual_size = 0;
     116
     117                // allocate space for the report descriptor
     118                kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
     119               
     120                // get the descriptor from the device
     121                int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
     122                    kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
     123                    0, i, kbd_dev->conf->interfaces[i].report_desc, length,
     124                    &actual_size);
     125
     126                if (rc != EOK) {
     127                        return rc;
     128                }
     129
     130                assert(actual_size == length);
     131
     132                //dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT,
     133                //    kbd_dev->conf->interfaces[i].report_desc, length);
     134        }
     135
    134136        return EOK;
    135137}
    136138
    137 static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    138 {
    139         // get the first configuration descriptor (TODO: or some other??)
     139static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
     140{
     141        // get the first configuration descriptor (TODO: parse also other!)
    140142        usb_standard_configuration_descriptor_t config_desc;
    141143       
     
    166168        }
    167169       
    168         rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred);
     170        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
     171            sizeof(usb_hid_configuration_t));
     172        if (kbd_dev->conf == NULL) {
     173                free(descriptors);
     174                return ENOMEM;
     175        }
     176       
     177        rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    169178        free(descriptors);
    170        
    171         return rc;
     179        if (rc != EOK) {
     180                printf("Problem with parsing standard descriptors.\n");
     181                return rc;
     182        }
     183
     184        // get and report descriptors
     185        rc = usbkbd_get_report_descriptor(kbd_dev);
     186        if (rc != EOK) {
     187                printf("Problem with parsing HID REPORT descriptor.\n");
     188                return rc;
     189        }
     190       
     191        //usbkbd_print_config(kbd_dev->conf);
     192
     193        /*
     194         * TODO:
     195         * 1) select one configuration (lets say the first)
     196         * 2) how many interfaces?? how to select one??
     197     *    ("The default setting for an interface is always alternate setting zero.")
     198         * 3) find endpoint which is IN and INTERRUPT (parse), save its number
     199     *    as the endpoint for polling
     200         */
     201       
     202        return EOK;
    172203}
    173204
    174205static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    175206{
    176         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(
    177                         sizeof(usb_hid_dev_kbd_t));
     207        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
     208            sizeof(usb_hid_dev_kbd_t));
    178209
    179210        if (kbd_dev == NULL) {
     
    186217        // get phone to my HC and save it as my parent's phone
    187218        // TODO: maybe not a good idea if DDF will use parent_phone
    188         kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    189 
    190         kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
    191             dev);
     219        int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
     220        if (rc < 0) {
     221                printf("Problem setting phone to HC.\n");
     222                free(kbd_dev);
     223                return NULL;
     224        }
     225
     226        rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
     227        if (rc < 0) {
     228                printf("Problem getting address of the device.\n");
     229                free(kbd_dev);
     230                return NULL;
     231        }
    192232
    193233        // doesn't matter now that we have no address
     
    208248         */
    209249
    210         // TODO: get descriptors
    211         usbkbd_get_descriptors(kbd_dev);
    212         // TODO: parse descriptors and save endpoints
     250        // TODO: get descriptors, parse descriptors and save endpoints
     251        usbkbd_process_descriptors(kbd_dev);
    213252
    214253        return kbd_dev;
     
    218257                                        uint8_t *buffer, size_t actual_size)
    219258{
    220         /*
    221          * here, the parser will be called, probably with some callbacks
    222          * now only take last 6 bytes and process, i.e. send to kbd
    223          */
    224 
    225259        usb_hid_report_in_callbacks_t *callbacks =
    226260            (usb_hid_report_in_callbacks_t *)malloc(
     
    228262        callbacks->keyboard = usbkbd_process_keycodes;
    229263
    230         usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    231             NULL);
     264        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
     265        //    NULL);
     266        printf("Calling usb_hid_boot_keyboard_input_report()...\n)");
     267        usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL);
    232268}
    233269
    234270static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    235271{
     272        return;
     273       
    236274        int rc;
    237275        usb_handle_t handle;
  • uspace/drv/vhc/hcd.c

    rc9d5577 rff8ed06  
    116116        sleep(5);
    117117
    118         usb_dprintf_enable(NAME, 0);
     118        usb_dprintf_enable(NAME, -1);
    119119
    120120        printf(NAME ": virtual USB host controller driver.\n");
Note: See TracChangeset for help on using the changeset viewer.