Changeset 382f3266 in mainline for uspace/drv


Ignore:
Timestamp:
2011-03-18T16:50:37Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
411d9fa, f51594fa
Parents:
054ed84 (diff), 98637224 (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:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/hiddev.c

    r054ed84 r382f3266  
    158158        }
    159159       
     160        hid_dev->report_desc_size = length;
     161       
    160162        usb_log_debug("Done.\n");
    161163       
     
    262264       
    263265        if (rc != EOK) {
    264                 usb_log_warning("Problem with parsing Report descriptor: %s.\n",
    265                     str_error(rc));
    266                 return rc;
    267         }
     266                usb_log_warning("Problem with getting Report descriptor: %s.\n",
     267                    str_error(rc));
     268                return rc;
     269        }
     270       
     271        rc = usb_hid_parse_report_descriptor(hid_dev->parser,
     272            hid_dev->report_desc, hid_dev->report_desc_size);
     273        if (rc != EOK) {
     274                usb_log_warning("Problem parsing Report descriptor: %s.\n",
     275                    str_error(rc));
     276                return rc;
     277        }
     278       
     279        usb_hid_descriptor_print(hid_dev->parser);
    268280       
    269281        return EOK;
     
    289301       
    290302        memset(dev, 0, sizeof(usbhid_dev_t));
     303       
     304        dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof(
     305            usb_hid_report_parser_t)));
     306        if (dev->parser == NULL) {
     307                usb_log_fatal("No memory!\n");
     308                free(dev);
     309                return NULL;
     310        }
    291311       
    292312        dev->initialized = 0;
     
    399419
    400420        /*
     421         * Initialize the report parser.
     422         */
     423        rc = usb_hid_parser_init(hid_dev->parser);
     424        if (rc != EOK) {
     425                usb_log_error("Failed to initialize report parser.\n");
     426                return rc;
     427        }
     428
     429        /*
    401430         * Get descriptors, parse descriptors and save endpoints.
    402431         */
  • uspace/drv/usbhid/hiddev.h

    r054ed84 r382f3266  
    7575        /** Report descriptor. */
    7676        uint8_t *report_desc;
     77
     78        size_t report_desc_size;
     79
    7780        /** HID Report parser. */
    7881        usb_hid_report_parser_t *parser;
  • uspace/drv/usbhid/kbddev.c

    r054ed84 r382f3266  
    5151#include <usb/classes/hidparser.h>
    5252#include <usb/classes/classes.h>
     53#include <usb/classes/hidut.h>
    5354
    5455#include "kbddev.h"
     
    122123        KC_RALT,          /* USB_HID_MOD_RALT */
    123124        0,                /* USB_HID_MOD_RGUI */
     125};
     126
     127typedef enum usbhid_lock_code {
     128        USBHID_LOCK_NUM = 0x53,
     129        USBHID_LOCK_CAPS = 0x39,
     130        USBHID_LOCK_SCROLL = 0x47,
     131        USBHID_LOCK_COUNT = 3
     132} usbhid_lock_code;
     133
     134static const usbhid_lock_code usbhid_lock_codes[USBHID_LOCK_COUNT] = {
     135        USBHID_LOCK_NUM,
     136        USBHID_LOCK_CAPS,
     137        USBHID_LOCK_SCROLL
    124138};
    125139
     
    346360 * @sa usbhid_kbd_push_ev()
    347361 */
    348 static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev,
    349     uint8_t modifiers)
    350 {
    351         /*
    352          * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK
    353          *       both as modifiers and as keys with their own scancodes???
    354          *
    355          * modifiers should be sent as normal keys to usbhid_parse_scancode()!!
    356          * so maybe it would be better if I received it from report parser in
    357          * that way
    358          */
    359        
    360         int i;
    361         for (i = 0; i < USB_HID_MOD_COUNT; ++i) {
    362                 if ((modifiers & usb_hid_modifiers_consts[i]) &&
    363                     !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
    364                         // modifier pressed
    365                         if (usbhid_modifiers_keycodes[i] != 0) {
    366                                 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS,
    367                                     usbhid_modifiers_keycodes[i]);
    368                         }
    369                 } else if (!(modifiers & usb_hid_modifiers_consts[i]) &&
    370                     (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
    371                         // modifier released
    372                         if (usbhid_modifiers_keycodes[i] != 0) {
    373                                 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE,
    374                                     usbhid_modifiers_keycodes[i]);
    375                         }
    376                 }       // no change
    377         }
    378        
    379         kbd_dev->modifiers = modifiers;
     362//static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev,
     363//    const uint8_t *key_codes, size_t count)
     364//{
     365//      /*
     366//       * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK
     367//       *       both as modifiers and as keyUSB_HID_LOCK_COUNTs with their own scancodes???
     368//       *
     369//       * modifiers should be sent as normal keys to usbhid_parse_scancode()!!
     370//       * so maybe it would be better if I received it from report parser in
     371//       * that way
     372//       */
     373       
     374//      int i;
     375//      for (i = 0; i < count; ++i) {
     376//              if ((modifiers & usb_hid_modifiers_consts[i]) &&
     377//                  !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
     378//                      // modifier pressed
     379//                      if (usbhid_modifiers_keycodes[i] != 0) {
     380//                              usbhid_kbd_push_ev(kbd_dev, KEY_PRESS,
     381//                                  usbhid_modifiers_keycodes[i]);
     382//                      }
     383//              } else if (!(modifiers & usb_hid_modifiers_consts[i]) &&
     384//                  (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
     385//                      // modifier released
     386//                      if (usbhid_modifiers_keycodes[i] != 0) {
     387//                              usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE,
     388//                                  usbhid_modifiers_keycodes[i]);
     389//                      }
     390//              }       // no change
     391//      }
     392       
     393//      kbd_dev->modifiers = modifiers;
     394//}
     395
     396/*----------------------------------------------------------------------------*/
     397
     398static inline int usbhid_kbd_is_lock(unsigned int key_code)
     399{
     400        return (key_code == KC_NUM_LOCK
     401            || key_code == KC_SCROLL_LOCK
     402            || key_code == KC_CAPS_LOCK);
    380403}
    381404
     
    404427        /*
    405428         * First of all, check if the kbd have reported phantom state.
     429         *
     430         * TODO: this must be changed as we don't know which keys are modifiers
     431         *       and which are regular keys.
    406432         */
    407433        i = 0;
     
    434460                        // not found, i.e. the key was released
    435461                        key = usbhid_parse_scancode(kbd_dev->keys[j]);
    436                         usbhid_kbd_repeat_stop(kbd_dev, key);
     462                        if (!usbhid_kbd_is_lock(key)) {
     463                                usbhid_kbd_repeat_stop(kbd_dev, key);
     464                        }
    437465                        usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key);
    438466                        usb_log_debug2("Key released: %d\n", key);
     
    458486                            key_codes[i]);
    459487                        usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
    460                         usbhid_kbd_repeat_start(kbd_dev, key);
     488                        if (!usbhid_kbd_is_lock(key)) {
     489                                usbhid_kbd_repeat_start(kbd_dev, key);
     490                        }
    461491                } else {
    462492                        // found, nothing happens
     
    502532
    503533        usb_log_debug("Got keys from parser: %s\n",
    504             usb_debug_str_buffer(key_codes, kbd_dev->key_count, 0));
     534            usb_debug_str_buffer(key_codes, count, 0));
    505535       
    506536        if (count != kbd_dev->key_count) {
     
    510540        }
    511541       
    512         usbhid_kbd_check_modifier_changes(kbd_dev, modifiers);
     542        ///usbhid_kbd_check_modifier_changes(kbd_dev, key_codes, count);
    513543        usbhid_kbd_check_key_changes(kbd_dev, key_codes, count);
    514544}
     
    535565                                    uint8_t *buffer, size_t actual_size)
    536566{
     567        assert(kbd_dev->initialized);
     568        assert(kbd_dev->hid_dev->parser != NULL);
     569       
    537570        usb_hid_report_in_callbacks_t *callbacks =
    538571            (usb_hid_report_in_callbacks_t *)malloc(
     
    541574        callbacks->keyboard = usbhid_kbd_process_keycodes;
    542575
    543         usb_log_debug("Calling usb_hid_boot_keyboard_input_report() with "
     576        usb_log_debug("Calling usb_hid_parse_report() with "
    544577            "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0));
    545578       
    546         int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
    547             callbacks, kbd_dev);
     579//      int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
     580//          callbacks, kbd_dev);
     581        int rc = usb_hid_parse_report(kbd_dev->hid_dev->parser, buffer,
     582            actual_size, callbacks, kbd_dev);
    548583       
    549584        if (rc != EOK) {
     
    614649                free((*kbd_dev)->repeat_mtx);
    615650        }
    616        
     651
    617652        free(*kbd_dev);
    618653        *kbd_dev = NULL;
     
    674709       
    675710        // save the size of the report (boot protocol report by default)
    676         kbd_dev->key_count = BOOTP_REPORT_SIZE;
     711//      kbd_dev->key_count = BOOTP_REPORT_SIZE;
     712       
     713        usb_hid_report_path_t path;
     714        path.usage_page = USB_HIDUT_PAGE_KEYBOARD;
     715        kbd_dev->key_count = usb_hid_report_input_length(
     716            kbd_dev->hid_dev->parser, &path);
     717       
     718        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
     719       
    677720        kbd_dev->keys = (uint8_t *)calloc(
    678721            kbd_dev->key_count, sizeof(uint8_t));
     
    709752        assert(kbd_dev->hid_dev != NULL);
    710753        assert(kbd_dev->hid_dev->initialized);
    711         usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);
     754        //usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);
    712755       
    713756        usbhid_kbd_set_led(kbd_dev);
  • uspace/drv/usbhid/kbddev.h

    r054ed84 r382f3266  
    4242
    4343#include <usb/classes/hid.h>
     44#include <usb/classes/hidparser.h>
    4445#include <ddf/driver.h>
    4546#include <usb/pipes.h>
  • uspace/drv/usbhub/port_status.h

    r054ed84 r382f3266  
    270270}
    271271
     272//low speed device attached
     273static inline bool usb_port_high_speed(usb_port_status_t * status){
     274        return usb_port_get_bit(status,10);
     275}
     276
     277static inline void usb_port_set_high_speed(usb_port_status_t * status,bool high_speed){
     278        usb_port_set_bit(status,10,high_speed);
     279}
     280
     281static inline usb_speed_t usb_port_speed(usb_port_status_t * status){
     282        if(usb_port_low_speed(status))
     283                return USB_SPEED_LOW;
     284        if(usb_port_high_speed(status))
     285                return USB_SPEED_HIGH;
     286        return USB_SPEED_FULL;
     287}
     288
    272289
    273290//connect change
  • uspace/drv/usbhub/usbhub.c

    r054ed84 r382f3266  
    7878                async_usleep(1000 * 1000 );/// \TODO proper number once
    7979        }
    80         dprintf(USB_LOG_LEVEL_ERROR,
    81                                 "something in ctrl loop went wrong, errno %d",errorCode);
     80        usb_log_error("something in ctrl loop went wrong, errno %d",errorCode);
     81
    8282        return 0;
    8383}
     
    104104                        hub->device);
    105105        if(opResult != EOK){
    106                 dprintf(USB_LOG_LEVEL_ERROR,
    107                                 "could not initialize connection to hc, errno %d",opResult);
     106                usb_log_error("could not initialize connection to hc, errno %d",opResult);
    108107                return opResult;
    109108        }
     
    112111                        hub->device);
    113112        if(opResult != EOK){
    114                 dprintf(USB_LOG_LEVEL_ERROR,
    115                                 "could not initialize connection to device, errno %d",opResult);
     113                usb_log_error("could not initialize connection to device, errno %d",
     114                                opResult);
    116115                return opResult;
    117116        }
     
    120119            &hub->device_connection);
    121120        if(opResult != EOK){
    122                 dprintf(USB_LOG_LEVEL_ERROR,
    123                                 "could not initialize connection to device endpoint, errno %d",opResult);
     121                usb_log_error("could not initialize connection to device endpoint, errno %d",
     122                                opResult);
    124123                return opResult;
    125124        }
     
    127126        opResult = usb_endpoint_pipe_probe_default_control(&hub->endpoints.control);
    128127        if (opResult != EOK) {
    129                 dprintf(USB_LOG_LEVEL_ERROR, "failed probing endpoint 0, %d", opResult);
     128                usb_log_error("failed probing endpoint 0, %d", opResult);
    130129                return opResult;
    131130        }
     
    151150            &std_descriptor);
    152151        if(opResult!=EOK){
    153                 dprintf(USB_LOG_LEVEL_ERROR, "could not get device descriptor, %d",opResult);
    154                 return opResult;
    155         }
    156         dprintf(USB_LOG_LEVEL_INFO, "hub has %d configurations",
     152                usb_log_error("could not get device descriptor, %d",opResult);
     153                return opResult;
     154        }
     155        usb_log_info("hub has %d configurations",
    157156                        std_descriptor.configuration_count);
    158157        if(std_descriptor.configuration_count<1){
    159                 dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE");
     158                usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE");
    160159                //shouldn`t I return?
    161160        }
     
    184183                return opResult;
    185184        }
    186         dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",
     185        usb_log_debug("\tused configuration %d",
    187186                        config_descriptor->configuration_number);
    188187
     
    200199            &hub->device_connection);
    201200        if (opResult != EOK) {
    202                 dprintf(USB_LOG_LEVEL_ERROR,
    203                                 "Failed to initialize status change pipe: %s",
     201                usb_log_error("Failed to initialize status change pipe: %s",
    204202                    str_error(opResult));
    205203                return opResult;
    206204        }
    207205        if (!endpoint_mapping[0].present) {
    208                 dprintf(USB_LOG_LEVEL_ERROR,"Not accepting device, " \
     206                usb_log_error("Not accepting device, " \
    209207                    "cannot understand what is happenning");
    210208                return EREFUSED;
     
    235233        result->port_count = -1;
    236234        result->device = device;
     235        result->is_default_address_used = false;
    237236
    238237        //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     
    240239
    241240        // get hub descriptor
    242         dprintf(USB_LOG_LEVEL_DEBUG, "creating serialized descripton");
     241        usb_log_debug("creating serialized descripton");
    243242        void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
    244243        usb_hub_descriptor_t * descriptor;
    245         dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
     244        usb_log_debug("starting control transaction");
    246245        usb_endpoint_pipe_start_session(&result->endpoints.control);
    247246        opResult = usb_request_set_configuration(&result->endpoints.control, 1);
     
    256255
    257256        if (opResult != EOK) {
    258                 dprintf(USB_LOG_LEVEL_ERROR, "failed when receiving hub descriptor, badcode = %d",opResult);
     257                usb_log_error("failed when receiving hub descriptor, badcode = %d",
     258                                opResult);
    259259                free(serialized_descriptor);
    260260                free(result);
    261261                return NULL;
    262262        }
    263         dprintf(USB_LOG_LEVEL_DEBUG2, "deserializing descriptor");
     263        usb_log_debug2("deserializing descriptor");
    264264        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
    265265        if(descriptor==NULL){
    266                 dprintf(USB_LOG_LEVEL_WARNING, "could not deserialize descriptor ");
     266                usb_log_warning("could not deserialize descriptor ");
    267267                free(result);
    268268                return NULL;
    269269        }
    270270
    271         dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
     271        usb_log_info("setting port count to %d",descriptor->ports_count);
    272272        result->port_count = descriptor->ports_count;
    273273        result->attached_devs = (usb_hc_attached_device_t*)
     
    278278                result->attached_devs[i].address=0;
    279279        }
    280         dprintf(USB_LOG_LEVEL_DEBUG2, "freeing data");
     280        usb_log_debug2("freeing data");
    281281        free(serialized_descriptor);
    282282        free(descriptor->devices_removable);
     
    285285        //finish
    286286
    287         dprintf(USB_LOG_LEVEL_INFO, "hub info created");
     287        usb_log_info("hub info created");
    288288
    289289        return result;
     
    296296 */
    297297int usb_add_hub_device(ddf_dev_t *dev) {
    298         dprintf(USB_LOG_LEVEL_INFO, "add_hub_device(handle=%d)", (int) dev->handle);
     298        usb_log_info("add_hub_device(handle=%d)", (int) dev->handle);
    299299
    300300        //dev->ops = &hub_device_ops;
     
    313313        opResult = usb_hub_process_configuration_descriptors(hub_info);
    314314        if(opResult != EOK){
    315                 dprintf(USB_LOG_LEVEL_ERROR,"could not get configuration descriptors, %d",
     315                usb_log_error("could not get configuration descriptors, %d",
    316316                                opResult);
    317317                return opResult;
     
    324324                opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
    325325                                &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
    326                 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
     326                usb_log_info("powering port %d",port);
    327327                if (opResult != EOK) {
    328                         dprintf(USB_LOG_LEVEL_WARNING, "something went wrong when setting hub`s %dth port", port);
     328                        usb_log_warning("something went wrong when setting hub`s %dth port", port);
    329329                }
    330330        }
     
    337337        usb_lst_append(&usb_hub_list, hub_info);
    338338        fibril_mutex_unlock(&usb_hub_list_lock);
    339         dprintf(USB_LOG_LEVEL_DEBUG, "hub info added to list");
    340 
    341         dprintf(USB_LOG_LEVEL_DEBUG, "adding to ddf");
     339        usb_log_debug("hub info added to list");
     340
     341        usb_log_debug("adding to ddf");
    342342        ddf_fun_t *hub_fun = ddf_fun_create(dev, fun_exposed, "hub");
    343343        assert(hub_fun != NULL);
     
    351351        fid_t fid = fibril_create(usb_hub_control_loop, hub_info);
    352352        if (fid == 0) {
    353                 dprintf(USB_LOG_LEVEL_ERROR,
    354                                 ": failed to start monitoring fibril for new hub");
     353                usb_log_error("failed to start monitoring fibril for new hub");
    355354                return ENOMEM;
    356355        }
    357356        fibril_add_ready(fid);
    358357
    359         dprintf(USB_LOG_LEVEL_DEBUG, "hub fibril created");
     358        usb_log_debug("hub fibril created");
    360359        //(void)hub_info;
    361360        //usb_hub_check_hub_changes();
    362361       
    363         dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
     362        usb_log_info("hub dev added");
    364363        //address is lost...
    365         dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
     364        usb_log_debug("\taddress %d, has %d ports ",
    366365                        //hub_info->endpoints.control.,
    367366                        hub_info->port_count);
     
    379378
    380379/**
     380 * release default address used by given hub
     381 *
     382 * Also unsets hub->is_default_address_used. Convenience wrapper function.
     383 * @note hub->connection MUST be open for communication
     384 * @param hub hub representation
     385 * @return error code
     386 */
     387static int usb_hub_release_default_address(usb_hub_info_t * hub){
     388        int opResult = usb_hc_release_default_address(&hub->connection);
     389        if(opResult!=EOK){
     390                usb_log_error("could not release default address, errno %d",opResult);
     391                return opResult;
     392        }
     393        hub->is_default_address_used = false;
     394        return EOK;
     395}
     396
     397/**
    381398 * Reset the port with new device and reserve the default address.
    382399 * @param hc
     
    385402 */
    386403static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
    387                 bool isLowSpeed) {
     404                usb_speed_t speed) {
     405        //if this hub already uses default address, it cannot request it once more
     406        if(hub->is_default_address_used) return;
     407        int opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     408                                port, USB_HUB_FEATURE_C_PORT_CONNECTION);
     409        if(opResult != EOK){
     410                usb_log_warning("could not clear port-change-connection flag");
     411        }
     412
    388413        usb_device_request_setup_packet_t request;
    389         int opResult;
    390         dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
     414        usb_log_info("some connection changed");
    391415        assert(hub->endpoints.control.hc_phone);
    392416        //get default address
    393         usb_speed_t speed = isLowSpeed?USB_SPEED_LOW:USB_SPEED_FULL;
    394417        opResult = usb_hc_reserve_default_address(&hub->connection, speed);
    395418       
    396419        if (opResult != EOK) {
    397                 dprintf(USB_LOG_LEVEL_WARNING,
    398                                 "cannot assign default address, it is probably used %d",opResult);
    399                 return;
    400         }
     420                usb_log_warning("cannot assign default address, it is probably used %d",
     421                                opResult);
     422                return;
     423        }
     424        hub->is_default_address_used = true;
    401425        //reset port
    402426        usb_hub_set_reset_port_request(&request, port);
     
    407431                        );
    408432        if (opResult != EOK) {
    409                 dprintf(USB_LOG_LEVEL_ERROR,
    410                                 "something went wrong when reseting a port %d",opResult);
     433                usb_log_error("something went wrong when reseting a port %d",opResult);
    411434                //usb_hub_release_default_address(hc);
    412                 usb_hc_release_default_address(&hub->connection);
    413         }
     435                usb_hub_release_default_address(hub);
     436        }
     437        return;
    414438}
    415439
     
    424448
    425449        int opResult;
    426         dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
     450        usb_log_info("finalizing add device");
    427451        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    428452            port, USB_HUB_FEATURE_C_PORT_RESET);
    429453
    430454        if (opResult != EOK) {
    431                 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
    432                 usb_hc_release_default_address(&hub->connection);
     455                usb_log_error("failed to clear port reset feature");
     456                usb_hub_release_default_address(hub);
    433457                return;
    434458        }
     
    454478                        );
    455479        if (new_device_address < 0) {
    456                 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
     480                usb_log_error("failed to get free USB address");
    457481                opResult = new_device_address;
    458                 usb_hc_release_default_address(&hub->connection);
    459                 return;
    460         }
    461         dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
     482                usb_hub_release_default_address(hub);
     483                return;
     484        }
     485        usb_log_info("setting new address %d",new_device_address);
    462486        //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    463487        //    new_device_address);
     
    466490        usb_endpoint_pipe_end_session(&new_device_pipe);
    467491        if (opResult != EOK) {
    468                 dprintf(USB_LOG_LEVEL_ERROR,
    469                                 "could not set address for new device %d",opResult);
    470                 usb_hc_release_default_address(&hub->connection);
     492                usb_log_error("could not set address for new device %d",opResult);
     493                usb_hub_release_default_address(hub);
    471494                return;
    472495        }
     
    474497
    475498        //opResult = usb_hub_release_default_address(hc);
    476         opResult = usb_hc_release_default_address(&hub->connection);
     499        opResult = usb_hub_release_default_address(hub);
    477500        if(opResult!=EOK){
    478501                return;
     
    486509
    487510        if (opResult != EOK) {
    488                 dprintf(USB_LOG_LEVEL_ERROR,
    489                                 "could not start driver for new device %d",opResult);
     511                usb_log_error("could not start driver for new device %d",opResult);
    490512                return;
    491513        }
     
    498520                        &hub->attached_devs[port]);
    499521        if (opResult != EOK) {
    500                 dprintf(USB_LOG_LEVEL_ERROR,
    501                                 "could not assign address of device in hcd %d",opResult);
    502                 return;
    503         }
    504         dprintf(USB_LOG_LEVEL_INFO, "new device address %d, handle %zu",
     522                usb_log_error("could not assign address of device in hcd %d",opResult);
     523                return;
     524        }
     525        usb_log_info("new device address %d, handle %zu",
    505526            new_device_address, child_handle);
    506527
     
    515536static void usb_hub_removed_device(
    516537    usb_hub_info_t * hub,uint16_t port) {
    517                
     538
     539        int opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     540                                port, USB_HUB_FEATURE_C_PORT_CONNECTION);
     541        if(opResult != EOK){
     542                usb_log_warning("could not clear port-change-connection flag");
     543        }
    518544        /** \TODO remove device from device manager - not yet implemented in
    519545         * devide manager
     
    533559                 */
    534560        }else{
    535                 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
     561                usb_log_warning("this is strange, disconnected device had no address");
    536562                //device was disconnected before it`s port was reset - return default address
    537                 //usb_drv_release_default_address(hc);
    538                 usb_hc_release_default_address(&hub->connection);
    539         }
    540 }
    541 
    542 
    543 /**
    544  *Process over current condition on port.
     563                usb_hub_release_default_address(hub);
     564        }
     565}
     566
     567
     568/**
     569 * Process over current condition on port.
    545570 *
    546571 * Turn off the power on the port.
     
    555580            port, USB_HUB_FEATURE_PORT_POWER);
    556581        if(opResult!=EOK){
    557                 dprintf(USB_LOG_LEVEL_ERROR, "cannot power off port %d;  %d",
     582                usb_log_error("cannot power off port %d;  %d",
    558583                                port, opResult);
    559584        }
     
    568593static void usb_hub_process_interrupt(usb_hub_info_t * hub,
    569594        uint16_t port) {
    570         dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
     595        usb_log_debug("interrupt at port %d", port);
    571596        //determine type of change
    572597        usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
     
    587612                        );
    588613        if (opResult != EOK) {
    589                 dprintf(USB_LOG_LEVEL_ERROR, "could not get port status");
     614                usb_log_error("could not get port status");
    590615                return;
    591616        }
    592617        if (rcvd_size != sizeof (usb_port_status_t)) {
    593                 dprintf(USB_LOG_LEVEL_ERROR, "received status has incorrect size");
     618                usb_log_error("received status has incorrect size");
    594619                return;
    595620        }
    596621        //something connected/disconnected
    597622        if (usb_port_connect_change(&status)) {
    598                 opResult = usb_hub_clear_port_feature(pipe,
    599                     port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    600                 // TODO: check opResult
    601623                if (usb_port_dev_connected(&status)) {
    602                         dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    603                         usb_hub_init_add_device(hub, port, usb_port_low_speed(&status));
     624                        usb_log_info("some connection changed");
     625                        usb_hub_init_add_device(hub, port, usb_port_speed(&status));
    604626                } else {
    605627                        usb_hub_removed_device(hub, port);
     
    612634                        usb_hub_over_current(hub,port);
    613635                }else{
    614                         dprintf(USB_LOG_LEVEL_INFO,
    615                                 "over current condition was auto-resolved on port %d",port);
     636                        usb_log_info("over current condition was auto-resolved on port %d",
     637                                        port);
    616638                }
    617639        }
    618640        //port reset
    619641        if (usb_port_reset_completed(&status)) {
    620                 dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
     642                usb_log_info("port reset complete");
    621643                if (usb_port_enabled(&status)) {
    622644                        usb_hub_finalize_add_device(hub, port, usb_port_low_speed(&status));
    623645                } else {
    624                         dprintf(USB_LOG_LEVEL_WARNING, "port reset, but port still not enabled");
     646                        usb_log_warning("port reset, but port still not enabled");
    625647                }
    626648        }
     
    631653        usb_port_set_dev_connected(&status, false);
    632654        if (status>>16) {
    633                 dprintf(USB_LOG_LEVEL_INFO, "there was some unsupported change on port %d: %X",port,status);
    634 
    635         }
    636         /// \TODO handle other changes
     655                usb_log_info("there was some unsupported change on port %d: %X",
     656                                port,status);
     657
     658        }
     659        /// \TODO handle other changes - is there any?
    637660}
    638661
     
    647670        opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
    648671        if(opResult != EOK){
    649                 dprintf(USB_LOG_LEVEL_ERROR,
    650                                 "could not initialize communication for hub; %d", opResult);
     672                usb_log_error("could not initialize communication for hub; %d",
     673                                opResult);
    651674                return opResult;
    652675        }
     
    669692        if (opResult != EOK) {
    670693                free(change_bitmap);
    671                 dprintf(USB_LOG_LEVEL_WARNING, "something went wrong while getting status of hub");
     694                usb_log_warning("something went wrong while getting status of hub");
    672695                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    673696                return opResult;
     
    676699        opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
    677700        if(opResult!=EOK){
    678                 dprintf(USB_LOG_LEVEL_ERROR, "could not start control pipe session %d",
    679                                 opResult);
     701                usb_log_error("could not start control pipe session %d", opResult);
    680702                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    681703                return opResult;
     
    683705        opResult = usb_hc_connection_open(&hub_info->connection);
    684706        if(opResult!=EOK){
    685                 dprintf(USB_LOG_LEVEL_ERROR, "could not start host controller session %d",
     707                usb_log_error("could not start host controller session %d",
    686708                                opResult);
    687709                usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
  • uspace/drv/usbhub/usbhub.h

    r054ed84 r382f3266  
    7171        /** hub endpoints */
    7272        usb_hub_endpoints_t endpoints;
     73
     74        bool is_default_address_used;
    7375} usb_hub_info_t;
    7476
Note: See TracChangeset for help on using the changeset viewer.