Ignore:
File:
1 edited

Legend:

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

    rb375bb8 r8e1eb4d0  
    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 
    4036#include <usb_iface.h>
    4137#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
    5253/*----------------------------------------------------------------------------*/
    5354static driver_ops_t uhci_driver_ops = {
     
    6970}
    7071/*----------------------------------------------------------------------------*/
     72#define CHECK_RET_RETURN(ret, message...) \
     73if (ret != EOK) { \
     74        usb_log_error(message); \
     75        return ret; \
     76}
     77
    7178static int uhci_add_device(ddf_dev_t *device)
    7279{
    7380        assert(device);
    74         uhci_t *hcd = NULL;
    75 #define CHECK_RET_FREE_HC_RETURN(ret, message...) \
    76 if (ret != EOK) { \
    77         usb_log_error(message); \
    78         if (hcd != NULL) \
    79                 free(hcd); \
    80         return ret; \
    81 }
    8281
    8382        usb_log_info("uhci_add_device() called\n");
     
    8988        int ret =
    9089            pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
    91         CHECK_RET_FREE_HC_RETURN(ret,
     90
     91        CHECK_RET_RETURN(ret,
    9292            "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
    9393        usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    9494            io_reg_base, io_reg_size, irq);
    9595
    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));
     96//      ret = pci_enable_interrupts(device);
     97//      CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
    9998
    100 #if 0
    101         ret = pci_enable_interrupts(device);
     99        uhci_t *uhci_hc = malloc(sizeof(uhci_t));
     100        ret = (uhci_hc != NULL) ? EOK : ENOMEM;
     101        CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
     102
     103        ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size);
    102104        if (ret != EOK) {
    103                 usb_log_warning(
    104                     "Failed(%d) to enable interrupts, fall back to polling.\n",
    105                     ret);
     105                usb_log_error("Failed to init uhci-hcd.\n");
     106                free(uhci_hc);
     107                return ret;
    106108        }
    107 #endif
    108 
    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);
    113 
    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
    118109
    119110        /*
    120          * We might free hcd, but that does not matter since no one
     111         * We might free uhci_hc, but that does not matter since no one
    121112         * else would access driver_data anyway.
    122113         */
    123         device->driver_data = hcd;
     114        device->driver_data = uhci_hc;
     115        ret = register_interrupt_handler(device, irq, irq_handler,
     116            &uhci_hc->interrupt_code);
     117        if (ret != EOK) {
     118                usb_log_error("Failed to register interrupt handler.\n");
     119                uhci_fini(uhci_hc);
     120                free(uhci_hc);
     121                return ret;
     122        }
    124123
    125         ddf_fun_t *rh = NULL;
    126 #define CHECK_RET_FINI_FREE_RETURN(ret, message...) \
    127 if (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 */
    139         ret = register_interrupt_handler(device, irq, irq_handler,
    140             &hcd->interrupt_code);
    141         CHECK_RET_FINI_FREE_RETURN(ret,
    142             "Failed(%d) to register interrupt handler.\n", ret);
    143 
     124        ddf_fun_t *rh;
    144125        ret = setup_root_hub(&rh, device);
    145         CHECK_RET_FINI_FREE_RETURN(ret,
    146             "Failed(%d) to setup UHCI root hub.\n", ret);
    147         rh->driver_data = hcd->ddf_instance;
     126        if (ret != EOK) {
     127                usb_log_error("Failed to setup uhci root hub.\n");
     128                uhci_fini(uhci_hc);
     129                free(uhci_hc);
     130                return ret;
     131        }
     132        rh->driver_data = uhci_hc->ddf_instance;
    148133
    149134        ret = ddf_fun_bind(rh);
    150         CHECK_RET_FINI_FREE_RETURN(ret,
    151             "Failed(%d) to register UHCI root hub.\n", ret);
     135        if (ret != EOK) {
     136                usb_log_error("Failed to register root hub.\n");
     137                uhci_fini(uhci_hc);
     138                free(uhci_hc);
     139                free(rh);
     140                return ret;
     141        }
    152142
    153143        return EOK;
    154 #undef CHECK_RET_FINI_FREE_RETURN
    155144}
    156145/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.