Changeset 72af8da in mainline for uspace/drv/uhci-hcd/main.c


Ignore:
Timestamp:
2011-03-16T18:50:17Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42a3a57
Parents:
3e7b7cd (diff), fcf07e6 (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 from usb/development

File:
1 edited

Legend:

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

    r3e7b7cd r72af8da  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver initialization
    3333 */
    3434#include <ddf/driver.h>
    35 #include <ddf/interrupt.h>
    36 #include <device/hw_res.h>
    3735#include <errno.h>
    3836#include <str_error.h>
    3937
    40 #include <usb_iface.h>
    4138#include <usb/ddfiface.h>
    4239#include <usb/debug.h>
    4340
    4441#include "iface.h"
    45 #include "pci.h"
    46 #include "root_hub.h"
    4742#include "uhci.h"
    4843
     
    6055};
    6156/*----------------------------------------------------------------------------*/
    62 static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
     57/** Initialize a new ddf driver instance for uhci hc and hub.
     58 *
     59 * @param[in] device DDF instance of the device to initialize.
     60 * @return Error code.
     61 */
     62int uhci_add_device(ddf_dev_t *device)
    6363{
    64         assert(dev);
    65         uhci_t *hc = dev_to_uhci(dev);
    66         uint16_t status = IPC_GET_ARG1(*call);
    67         assert(hc);
    68         uhci_interrupt(hc, status);
     64        usb_log_info("uhci_add_device() called\n");
     65        assert(device);
     66        uhci_t *uhci = malloc(sizeof(uhci_t));
     67        if (uhci == NULL) {
     68                usb_log_error("Failed to allocate UHCI driver.\n");
     69                return ENOMEM;
     70        }
     71
     72        int ret = uhci_init(uhci, device);
     73        if (ret != EOK) {
     74                usb_log_error("Failed to initialzie UHCI driver.\n");
     75                return ret;
     76        }
     77        device->driver_data = uhci;
     78        return EOK;
    6979}
    7080/*----------------------------------------------------------------------------*/
    71 static 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...) \
    76 if (ret != EOK) { \
    77         usb_log_error(message); \
    78         if (hcd != NULL) \
    79                 free(hcd); \
    80         return ret; \
    81 }
    82 
    83         usb_log_info("uhci_add_device() called\n");
    84 
    85         uintptr_t io_reg_base = 0;
    86         size_t io_reg_size = 0;
    87         int irq = 0;
    88 
    89         int ret =
    90             pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
    91         CHECK_RET_FREE_HC_RETURN(ret,
    92             "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
    93         usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    94             io_reg_base, io_reg_size, irq);
    95 
    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
    101         ret = pci_enable_interrupts(device);
    102         if (ret != EOK) {
    103                 usb_log_warning(
    104                     "Failed(%d) to enable interrupts, fall back to polling.\n",
    105                     ret);
    106         }
    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
    118 
    119         /*
    120          * We might free hcd, but that does not matter since no one
    121          * else would access driver_data anyway.
    122          */
    123         device->driver_data = hcd;
    124 
    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 
    144         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;
    148 
    149         ret = ddf_fun_bind(rh);
    150         CHECK_RET_FINI_FREE_RETURN(ret,
    151             "Failed(%d) to register UHCI root hub.\n", ret);
    152 
    153         return EOK;
    154 #undef CHECK_RET_FINI_FREE_RETURN
    155 }
    156 /*----------------------------------------------------------------------------*/
     81/** Initialize global driver structures (NONE).
     82 *
     83 * @param[in] argc Nmber of arguments in argv vector (ignored).
     84 * @param[in] argv Cmdline argument vector (ignored).
     85 * @return Error code.
     86 *
     87 * Driver debug level is set here.
     88 */
    15789int main(int argc, char *argv[])
    15890{
    159         sleep(3);
     91        sleep(3); /* TODO: remove in final version */
    16092        usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
    16193
Note: See TracChangeset for help on using the changeset viewer.