Changeset b4b534ac in mainline for uspace/drv/bus/usb/ehci/main.c


Ignore:
Timestamp:
2016-07-22T08:24:47Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (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 lp:~jan.vesely/helenos/usb

File:
1 edited

Legend:

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

    r5b18137 rb4b534ac  
    3333 * Main routines of EHCI driver.
    3434 */
    35 
    3635#include <ddf/driver.h>
    3736#include <ddf/interrupt.h>
    3837#include <device/hw_res.h>
    3938#include <errno.h>
    40 #include <stdbool.h>
    4139#include <str_error.h>
     40#include <io/logctl.h>
    4241
    4342#include <usb_iface.h>
    44 #include <usb/ddfiface.h>
    4543#include <usb/debug.h>
    46 #include <usb/host/hcd.h>
     44#include <usb/host/ddf_helpers.h>
    4745
    4846#include "res.h"
     47#include "hc.h"
     48#include "ehci_endpoint.h"
    4949
    5050#define NAME "ehci"
    5151
    52 static int ehci_dev_add(ddf_dev_t *device);
     52static int ehci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
     53static void ehci_driver_fini(hcd_t *);
    5354
    54 static driver_ops_t ehci_driver_ops = {
    55         .dev_add = ehci_dev_add,
     55static const ddf_hc_driver_t ehci_hc_driver = {
     56        .claim = disable_legacy,
     57        .hc_speed = USB_SPEED_HIGH,
     58        .irq_code_gen = ehci_hc_gen_irq_code,
     59        .init = ehci_driver_init,
     60        .fini = ehci_driver_fini,
     61        .name = "EHCI-PCI",
     62        .ops = {
     63                .schedule       = ehci_hc_schedule,
     64                .ep_add_hook    = ehci_endpoint_init,
     65                .ep_remove_hook = ehci_endpoint_fini,
     66                .irq_hook       = ehci_hc_interrupt,
     67                .status_hook    = ehci_hc_status,
     68        }
    5669};
    5770
    58 static driver_t ehci_driver = {
    59         .name = NAME,
    60         .driver_ops = &ehci_driver_ops
    61 };
    62 static ddf_dev_ops_t hc_ops = {
    63         .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
    64 };
    6571
     72static int ehci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
     73{
     74        assert(hcd);
     75        assert(hcd_get_driver_data(hcd) == NULL);
     76
     77        hc_t *instance = malloc(sizeof(hc_t));
     78        if (!instance)
     79                return ENOMEM;
     80
     81        const int ret = hc_init(instance, res, irq);
     82        if (ret == EOK) {
     83                hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops);
     84        } else {
     85                free(instance);
     86        }
     87        return ret;
     88}
     89
     90static void ehci_driver_fini(hcd_t *hcd)
     91{
     92        assert(hcd);
     93        hc_t *hc = hcd_get_driver_data(hcd);
     94        if (hc)
     95                hc_fini(hc);
     96
     97        free(hc);
     98        hcd_set_implementation(hcd, NULL, NULL);
     99}
    66100
    67101/** Initializes a new ddf driver instance of EHCI hcd.
     
    72106static int ehci_dev_add(ddf_dev_t *device)
    73107{
    74         ddf_fun_t *hc_fun = NULL;
    75         bool fun_bound = false;
    76 
     108        usb_log_debug("ehci_dev_add() called\n");
    77109        assert(device);
    78110
    79         addr_range_t reg_range;
    80         int irq = 0;
     111        return hcd_ddf_add_hc(device, &ehci_hc_driver);
    81112
    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         }
     113}
    88114
    89         usb_log_info("Memory mapped regs at %p (size %zu), IRQ %d.\n",
    90             RNGABSPTR(reg_range), RNGSZ(reg_range), irq);
    91115
    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         }
     116static const driver_ops_t ehci_driver_ops = {
     117        .dev_add = ehci_dev_add,
     118};
    98119
    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         }
     120static const driver_t ehci_driver = {
     121        .name = NAME,
     122        .driver_ops = &ehci_driver_ops
     123};
    105124
    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         }
    112 
    113         /* High Speed, no bandwidth */
    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         }
    132 
    133         usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
    134             ddf_dev_get_name(device), ddf_dev_get_handle(device));
    135 
    136         return EOK;
    137 error:
    138         if (fun_bound)
    139                 ddf_fun_unbind(hc_fun);
    140         if (hc_fun != NULL)
    141                 ddf_fun_destroy(hc_fun);
    142         return rc;
    143 }
    144125
    145126/** Initializes global driver structures (NONE).
     
    154135{
    155136        log_init(NAME);
     137        logctl_set_log_level(NAME, LVL_NOTE);
    156138        return ddf_driver_main(&ehci_driver);
    157139}
Note: See TracChangeset for help on using the changeset viewer.