Changeset 26e7d6d in mainline for uspace/drv/bus/usb/uhci/uhci.c


Ignore:
Timestamp:
2011-09-19T16:31:00Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a347a11
Parents:
3842a955 (diff), 086290d (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 mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/uhci.c

    r3842a955 r26e7d6d  
    4141
    4242#include "uhci.h"
    43 #include "iface.h"
    4443#include "pci.h"
    4544
     
    6463{
    6564        assert(dev);
    66         assert(dev->driver_data);
    6765        return dev->driver_data;
    6866}
     
    7876        assert(dev);
    7977        uhci_t *uhci = dev_to_uhci(dev);
    80         hc_t *hc = &uhci->hc;
     78        if (!uhci) {
     79                usb_log_error("Interrupt on not yet initialized device.\n");
     80                return;
     81        }
    8182        const uint16_t status = IPC_GET_ARG1(*call);
    82         assert(hc);
    83         hc_interrupt(hc, status);
     83        hc_interrupt(&uhci->hc, status);
    8484}
    8585/*----------------------------------------------------------------------------*/
    8686/** Operations supported by the HC driver */
    8787static ddf_dev_ops_t hc_ops = {
    88         .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
     88        .interfaces[USBHC_DEV_IFACE] = &hcd_iface, /* see iface.h/c */
    8989};
    9090/*----------------------------------------------------------------------------*/
     
    9999{
    100100        assert(fun);
    101         usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc.manager;
    102         usb_address_t addr = usb_device_keeper_find(manager, handle);
     101        usb_device_manager_t *manager =
     102            &dev_to_uhci(fun->dev)->hc.generic.dev_manager;
     103        const usb_address_t addr = usb_device_manager_find(manager, handle);
    103104
    104105        if (addr < 0) {
     
    191192                ddf_fun_destroy(instance->rh_fun); \
    192193        } \
    193         free(instance); \
     194        device->driver_data = NULL; \
    194195        usb_log_error(message); \
    195196        return ret; \
     
    201202        CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI HC function.\n");
    202203        instance->hc_fun->ops = &hc_ops;
    203         instance->hc_fun->driver_data = &instance->hc;
     204        instance->hc_fun->driver_data = &instance->hc.generic;
    204205
    205206        instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci_rh");
     
    222223        ret = pci_disable_legacy(device);
    223224        CHECK_RET_DEST_FREE_RETURN(ret,
    224             "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
     225            "Failed to disable legacy USB: %s.\n", str_error(ret));
     226
     227        const size_t cmd_count = hc_irq_cmd_count();
     228        irq_cmd_t irq_cmds[cmd_count];
     229        ret =
     230            hc_get_irq_commands(irq_cmds, sizeof(irq_cmds), reg_base, reg_size);
     231        CHECK_RET_DEST_FREE_RETURN(ret,
     232            "Failed to generate IRQ commands: %s.\n", str_error(ret));
     233
     234        irq_code_t irq_code = { .cmdcount = cmd_count, .cmds = irq_cmds };
     235
     236        /* Register handler to avoid interrupt lockup */
     237        ret = register_interrupt_handler(device, irq, irq_handler, &irq_code);
     238        CHECK_RET_DEST_FREE_RETURN(ret,
     239            "Failed to register interrupt handler: %s.\n", str_error(ret));
    225240
    226241        bool interrupts = false;
    227 #ifdef CONFIG_USBHC_NO_INTERRUPTS
    228         usb_log_warning("Interrupts disabled in OS config, " \
    229             "falling back to polling.\n");
    230 #else
    231242        ret = pci_enable_interrupts(device);
    232243        if (ret != EOK) {
    233                 usb_log_warning("Failed to enable interrupts: %s.\n",
    234                     str_error(ret));
    235                 usb_log_info("HW interrupts not available, " \
    236                     "falling back to polling.\n");
     244                usb_log_warning("Failed to enable interrupts: %s."
     245                    " Falling back to polling.\n", str_error(ret));
    237246        } else {
    238247                usb_log_debug("Hw interrupts enabled.\n");
    239248                interrupts = true;
    240249        }
    241 #endif
    242 
    243250
    244251        ret = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts);
    245252        CHECK_RET_DEST_FREE_RETURN(ret,
    246             "Failed(%d) to init uhci_hcd: %s.\n", ret, str_error(ret));
     253            "Failed to init uhci_hcd: %s.\n", str_error(ret));
     254
     255        device->driver_data = instance;
    247256
    248257#define CHECK_RET_FINI_RETURN(ret, message...) \
     
    253262} else (void)0
    254263
    255         /* It does no harm if we register this on polling */
    256         ret = register_interrupt_handler(device, irq, irq_handler,
    257             &instance->hc.interrupt_code);
    258         CHECK_RET_FINI_RETURN(ret,
    259             "Failed(%d) to register interrupt handler: %s.\n",
    260             ret, str_error(ret));
    261 
    262264        ret = ddf_fun_bind(instance->hc_fun);
    263         CHECK_RET_FINI_RETURN(ret,
    264             "Failed(%d) to bind UHCI device function: %s.\n",
    265             ret, str_error(ret));
    266 
    267         ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME);
     265        CHECK_RET_FINI_RETURN(ret, "Failed to bind UHCI device function: %s.\n",
     266            str_error(ret));
     267
     268        ret = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
    268269        CHECK_RET_FINI_RETURN(ret,
    269270            "Failed to add UHCI to HC class: %s.\n", str_error(ret));
     
    272273            (uintptr_t)instance->hc.registers + 0x10, 4);
    273274        CHECK_RET_FINI_RETURN(ret,
    274             "Failed(%d) to setup UHCI root hub: %s.\n", ret, str_error(ret));
     275            "Failed to setup UHCI root hub: %s.\n", str_error(ret));
    275276
    276277        ret = ddf_fun_bind(instance->rh_fun);
    277278        CHECK_RET_FINI_RETURN(ret,
    278             "Failed(%d) to register UHCI root hub: %s.\n", ret, str_error(ret));
    279 
    280         device->driver_data = instance;
     279            "Failed to register UHCI root hub: %s.\n", str_error(ret));
     280
    281281        return EOK;
    282282#undef CHECK_RET_FINI_RETURN
Note: See TracChangeset for help on using the changeset viewer.