Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/main.c

    re991937 r7de1988c  
    3333 * Main routines of EHCI driver.
    3434 */
     35
    3536#include <ddf/driver.h>
    3637#include <ddf/interrupt.h>
    3738#include <device/hw_res.h>
    3839#include <errno.h>
     40#include <stdbool.h>
    3941#include <str_error.h>
    4042
    4143#include <usb_iface.h>
     44#include <usb/ddfiface.h>
    4245#include <usb/debug.h>
    43 #include <usb/host/ddf_helpers.h>
     46#include <usb/host/hcd.h>
    4447
    4548#include "res.h"
     
    5760        .driver_ops = &ehci_driver_ops
    5861};
     62static ddf_dev_ops_t hc_ops = {
     63        .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
     64};
    5965
    6066
     
    6672static int ehci_dev_add(ddf_dev_t *device)
    6773{
     74        ddf_fun_t *hc_fun = NULL;
     75        bool fun_bound = false;
     76
    6877        assert(device);
    69 #define CHECK_RET_RETURN(ret, message...) \
    70 if (ret != EOK) { \
    71         usb_log_error(message); \
    72         return ret; \
    73 }
    7478
    75         uintptr_t reg_base = 0;
    76         size_t reg_size = 0;
     79        addr_range_t reg_range;
    7780        int irq = 0;
    7881
    79         int ret = get_my_registers(device, &reg_base, &reg_size, &irq);
    80         CHECK_RET_RETURN(ret,
    81             "Failed to get memory addresses for %" PRIun ": %s.\n",
    82             ddf_dev_get_handle(device), str_error(ret));
    83         usb_log_info("Memory mapped regs at 0x%" PRIxn " (size %zu), IRQ %d.\n",
    84             reg_base, reg_size, irq);
     82        int rc = get_my_registers(device, &reg_range, &irq);
     83        if (rc != EOK) {
     84                usb_log_error("Failed to get memory addresses for %" PRIun
     85                    ": %s.\n", ddf_dev_get_handle(device), str_error(rc));
     86                goto error;
     87        }
    8588
    86         ret = disable_legacy(device, reg_base, reg_size);
    87         CHECK_RET_RETURN(ret,
    88             "Failed to disable legacy USB: %s.\n", str_error(ret));
     89        usb_log_info("Memory mapped regs at %p (size %zu), IRQ %d.\n",
     90            RNGABSPTR(reg_range), RNGSZ(reg_range), irq);
     91
     92        rc = disable_legacy(device, &reg_range);
     93        if (rc != EOK) {
     94                usb_log_error("Failed to disable legacy USB: %s.\n",
     95                    str_error(rc));
     96                goto error;
     97        }
     98
     99        hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
     100        if (hc_fun == NULL) {
     101                usb_log_error("Failed to create EHCI function.\n");
     102                rc = ENOMEM;
     103                goto error;
     104        }
     105
     106        hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t));
     107        if (ehci_hc == NULL) {
     108                usb_log_error("Failed to alloc generic HC driver.\n");
     109                rc = ENOMEM;
     110                goto error;
     111        }
    89112
    90113        /* High Speed, no bandwidth */
    91         ret = hcd_ddf_setup_hc(device, USB_SPEED_HIGH, 0, NULL);       
    92         CHECK_RET_RETURN(ret,
    93             "Failed to init generci hcd driver: %s\n", str_error(ret));
     114        hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
     115        ddf_fun_set_ops(hc_fun,  &hc_ops);
     116
     117        rc = ddf_fun_bind(hc_fun);
     118        if (rc != EOK) {
     119                usb_log_error("Failed to bind EHCI function: %s.\n",
     120                    str_error(rc));
     121                goto error;
     122        }
     123
     124        fun_bound = true;
     125
     126        rc = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
     127        if (rc != EOK) {
     128                usb_log_error("Failed to add EHCI to HC class: %s.\n",
     129                    str_error(rc));
     130                goto error;
     131        }
    94132
    95133        usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
     
    97135
    98136        return EOK;
    99 #undef CHECK_RET_RETURN
     137error:
     138        if (fun_bound)
     139                ddf_fun_unbind(hc_fun);
     140        if (hc_fun != NULL)
     141                ddf_fun_destroy(hc_fun);
     142        return rc;
    100143}
    101144
Note: See TracChangeset for help on using the changeset viewer.