Changeset 8c877b2 in mainline for uspace/drv/uhci-hcd/main.c


Ignore:
Timestamp:
2011-03-04T13:05:35Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d49728c
Parents:
dff940f8 (diff), 9a422574 (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 with \usb\development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/main.c

    rdff940f8 r8c877b2  
    3434#include <ddf/driver.h>
    3535#include <ddf/interrupt.h>
     36#include <device/hw_res.h>
     37#include <errno.h>
     38#include <str_error.h>
     39
    3640#include <usb_iface.h>
    3741#include <usb/ddfiface.h>
    38 #include <device/hw_res.h>
    39 
    40 #include <errno.h>
    41 
    4242#include <usb/debug.h>
    4343
     
    5050
    5151static int uhci_add_device(ddf_dev_t *device);
    52 
    5352/*----------------------------------------------------------------------------*/
    5453static driver_ops_t uhci_driver_ops = {
     
    7069}
    7170/*----------------------------------------------------------------------------*/
    72 #define CHECK_RET_RETURN(ret, message...) \
     71static int uhci_add_device(ddf_dev_t *device)
     72{
     73        assert(device);
     74        uhci_t *hcd = NULL;
     75#define CHECK_RET_FREE_HC_RETURN(ret, message...) \
    7376if (ret != EOK) { \
    7477        usb_log_error(message); \
     78        if (hcd != NULL) \
     79                free(hcd); \
    7580        return ret; \
    7681}
    7782
    78 static int uhci_add_device(ddf_dev_t *device)
    79 {
    80         assert(device);
    81 
    8283        usb_log_info("uhci_add_device() called\n");
    8384
    84 
    85         uintptr_t io_reg_base;
    86         size_t io_reg_size;
    87         int irq;
     85        uintptr_t io_reg_base = 0;
     86        size_t io_reg_size = 0;
     87        int irq = 0;
    8888
    8989        int ret =
    9090            pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
    91 
    92         CHECK_RET_RETURN(ret,
     91        CHECK_RET_FREE_HC_RETURN(ret,
    9392            "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
    9493        usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    9594            io_reg_base, io_reg_size, irq);
    9695
     96        ret = pci_disable_legacy(device);
     97        CHECK_RET_FREE_HC_RETURN(ret,
     98            "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret));
     99
     100#if 0
    97101        ret = pci_enable_interrupts(device);
    98         CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
     102        if (ret != EOK) {
     103                usb_log_warning(
     104                    "Failed(%d) to enable interrupts, fall back to polling.\n",
     105                    ret);
     106        }
     107#endif
    99108
    100         uhci_t *uhci_hc = malloc(sizeof(uhci_t));
    101         ret = (uhci_hc != NULL) ? EOK : ENOMEM;
    102         CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
     109        hcd = malloc(sizeof(uhci_t));
     110        ret = (hcd != NULL) ? EOK : ENOMEM;
     111        CHECK_RET_FREE_HC_RETURN(ret,
     112            "Failed(%d) to allocate memory for uhci hcd.\n", ret);
    103113
    104         ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size);
    105         if (ret != EOK) {
    106                 usb_log_error("Failed to init uhci-hcd.\n");
    107                 free(uhci_hc);
    108                 return ret;
    109         }
     114        ret = uhci_init(hcd, device, (void*)io_reg_base, io_reg_size);
     115        CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n",
     116            ret);
     117#undef CHECK_RET_FREE_HC_RETURN
    110118
    111119        /*
    112          * We might free uhci_hc, but that does not matter since no one
     120         * We might free hcd, but that does not matter since no one
    113121         * else would access driver_data anyway.
    114122         */
    115         device->driver_data = uhci_hc;
     123        device->driver_data = hcd;
    116124
     125        ddf_fun_t *rh = NULL;
     126#define CHECK_RET_FINI_FREE_RETURN(ret, message...) \
     127if (ret != EOK) { \
     128        usb_log_error(message); \
     129        if (hcd != NULL) {\
     130                uhci_fini(hcd); \
     131                free(hcd); \
     132        } \
     133        if (rh != NULL) \
     134                free(rh); \
     135        return ret; \
     136}
     137
     138        /* It does no harm if we register this on polling */
    117139        ret = register_interrupt_handler(device, irq, irq_handler,
    118             &uhci_hc->interrupt_code);
    119         if (ret != EOK) {
    120                 usb_log_error("Failed to register interrupt handler.\n");
    121                 uhci_fini(uhci_hc);
    122                 free(uhci_hc);
    123                 return ret;
    124         }
     140            &hcd->interrupt_code);
     141        CHECK_RET_FINI_FREE_RETURN(ret,
     142            "Failed(%d) to register interrupt handler.\n", ret);
    125143
    126         ddf_fun_t *rh;
    127144        ret = setup_root_hub(&rh, device);
    128         if (ret != EOK) {
    129                 usb_log_error("Failed to setup uhci root hub.\n");
    130                 uhci_fini(uhci_hc);
    131                 free(uhci_hc);
    132                 return ret;
    133         }
    134         rh->driver_data = uhci_hc->ddf_instance;
     145        CHECK_RET_FINI_FREE_RETURN(ret,
     146            "Failed(%d) to setup UHCI root hub.\n", ret);
     147        rh->driver_data = hcd->ddf_instance;
    135148
    136149        ret = ddf_fun_bind(rh);
    137         if (ret != EOK) {
    138                 usb_log_error("Failed to register root hub.\n");
    139                 uhci_fini(uhci_hc);
    140                 free(uhci_hc);
    141                 free(rh);
    142                 return ret;
    143         }
     150        CHECK_RET_FINI_FREE_RETURN(ret,
     151            "Failed(%d) to register UHCI root hub.\n", ret);
    144152
    145153        return EOK;
     154#undef CHECK_RET_FINI_FREE_RETURN
    146155}
    147156/*----------------------------------------------------------------------------*/
     
    149158{
    150159        sleep(3);
    151         usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
     160        usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
    152161
    153162        return ddf_driver_main(&uhci_driver);
Note: See TracChangeset for help on using the changeset viewer.