Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/hc.c

    r171e668 rcffa14e6  
    4141#include <usb/debug.h>
    4242#include <usb/usb.h>
     43#include <usb/ddfiface.h>
    4344
    4445#include "hc.h"
     
    8788static int hc_init_memory(hc_t *instance);
    8889static int interrupt_emulator(hc_t *instance);
     90static int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
    8991
    9092/** Get number of PIO ranges used in IRQ code.
     
    135137}
    136138
     139/** Announce OHCI root hub to the DDF
     140 *
     141 * @param[in] instance OHCI driver intance
     142 * @param[in] hub_fun DDF fuction representing OHCI root hub
     143 * @return Error code
     144 */
     145int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
     146{
     147        assert(instance);
     148        assert(hub_fun);
     149
     150        /* Try to get address 1 for root hub. */
     151        instance->rh.address = 1;
     152        int ret = usb_device_manager_request_address(
     153            &instance->generic.dev_manager, &instance->rh.address, false,
     154            USB_SPEED_FULL);
     155        if (ret != EOK) {
     156                usb_log_error("Failed to get OHCI root hub address: %s\n",
     157                    str_error(ret));
     158                return ret;
     159        }
     160
     161#define CHECK_RET_UNREG_RETURN(ret, message...) \
     162if (ret != EOK) { \
     163        usb_log_error(message); \
     164        usb_endpoint_manager_remove_ep( \
     165            &instance->generic.ep_manager, instance->rh.address, 0, \
     166            USB_DIRECTION_BOTH, NULL, NULL); \
     167        usb_device_manager_release_address( \
     168            &instance->generic.dev_manager, instance->rh.address); \
     169        return ret; \
     170} else (void)0
     171
     172        ret = usb_endpoint_manager_add_ep(
     173            &instance->generic.ep_manager, instance->rh.address, 0,
     174            USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64,
     175            0, NULL, NULL);
     176        CHECK_RET_UNREG_RETURN(ret,
     177            "Failed to register root hub control endpoint: %s.\n",
     178            str_error(ret));
     179
     180        ret = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
     181        CHECK_RET_UNREG_RETURN(ret,
     182            "Failed to add root hub match-id: %s.\n", str_error(ret));
     183
     184        ret = ddf_fun_bind(hub_fun);
     185        CHECK_RET_UNREG_RETURN(ret,
     186            "Failed to bind root hub function: %s.\n", str_error(ret));
     187
     188        ret = usb_device_manager_bind_address(&instance->generic.dev_manager,
     189            instance->rh.address, ddf_fun_get_handle(hub_fun));
     190        if (ret != EOK)
     191                usb_log_warning("Failed to bind root hub address: %s.\n",
     192                    str_error(ret));
     193
     194        return EOK;
     195#undef CHECK_RET_RELEASE
     196}
     197
    137198/** Initialize OHCI hc driver structure
    138199 *
     
    160221        list_initialize(&instance->pending_batches);
    161222
     223        hcd_init(&instance->generic, USB_SPEED_FULL,
     224            BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
     225        instance->generic.private_data = instance;
     226        instance->generic.schedule = hc_schedule;
     227        instance->generic.ep_add_hook = ohci_endpoint_init;
     228        instance->generic.ep_remove_hook = ohci_endpoint_fini;
     229
    162230        ret = hc_init_memory(instance);
    163231        CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures: %s.\n",
     
    175243        }
    176244
    177         ohci_rh_init(&instance->rh, instance->registers, "ohci rh");
     245        rh_init(&instance->rh, instance->registers);
    178246        hc_start(instance);
    179247
     
    262330
    263331        /* Check for root hub communication */
    264         if (batch->ep->address == ohci_rh_get_address(&instance->rh)) {
     332        if (batch->ep->address == instance->rh.address) {
    265333                usb_log_debug("OHCI root hub request.\n");
    266                 return ohci_rh_schedule(&instance->rh, batch);
     334                rh_request(&instance->rh, batch);
     335                return EOK;
    267336        }
    268337        ohci_transfer_batch_t *ohci_batch = ohci_transfer_batch_get(batch);
     
    303372        usb_log_debug2("OHCI(%p) interrupt: %x.\n", instance, status);
    304373        if (status & I_RHSC)
    305                 ohci_rh_interrupt(&instance->rh);
     374                rh_interrupt(&instance->rh);
    306375
    307376        if (status & I_WDH) {
     
    533602        assert(instance);
    534603
    535         bzero(&instance->rh, sizeof(instance->rh));
     604        memset(&instance->rh, 0, sizeof(instance->rh));
    536605        /* Init queues */
    537606        const int ret = hc_init_transfer_lists(instance);
Note: See TracChangeset for help on using the changeset viewer.