Changes in uspace/drv/ohci/hc.c [1387692:53f1c87] in mainline


Ignore:
File:
1 edited

Legend:

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

    r1387692 r53f1c87  
    3939#include <usb/debug.h>
    4040#include <usb/usb.h>
    41 #include <usb/hub.h>
    4241#include <usb/ddfiface.h>
    4342#include <usb/usbdevice.h>
     
    4544#include "hc.h"
    4645
    47 static int dummy_reset(int foo, void *arg)
     46static int interrupt_emulator(hc_t *instance);
     47/*----------------------------------------------------------------------------*/
     48int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
    4849{
    49         hc_t *hc = (hc_t*)arg;
    50         assert(hc);
    51         hc->rh.address = 0;
    52         return EOK;
     50        assert(instance);
     51        assert(hub_fun);
     52
     53        usb_address_t hub_address =
     54            device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL);
     55        instance->rh.address = hub_address;
     56        usb_device_keeper_bind(
     57            &instance->manager, hub_address, hub_fun->handle);
     58
     59        char *match_str = NULL;
     60        int ret = asprintf(&match_str, "usb&mid");
     61        ret = (match_str == NULL) ? ret : EOK;
     62        if (ret < 0) {
     63                usb_log_error("Failed to create root hub match-id string.\n");
     64                return ret;
     65        }
     66
     67        ret = ddf_fun_add_match_id(hub_fun, match_str, 100);
     68        if (ret != EOK) {
     69                usb_log_error("Failed add create root hub match-id.\n");
     70        }
     71        return ret;
    5372}
    5473/*----------------------------------------------------------------------------*/
     
    6786        usb_device_keeper_init(&instance->manager);
    6887
     88        if (!interrupts) {
     89                instance->interrupt_emulator =
     90                    fibril_create((int(*)(void*))interrupt_emulator, instance);
     91                fibril_add_ready(instance->interrupt_emulator);
     92        }
    6993
    7094        rh_init(&instance->rh, dev, instance->registers);
     95
    7196        /* TODO: implement */
    72         return EOK;
    73 }
    74 /*----------------------------------------------------------------------------*/
    75 int hc_register_hub(hc_t *instance)
    76 {
    77         async_usleep(1000000);
    78 #define CHECK_RET_RETURN(ret, msg...) \
    79         if (ret != EOK) { \
    80                 usb_log_error(msg); \
    81                 return ret; \
    82         } else (void)0
    83         assert(instance);
    84         assert(instance->ddf_instance);
    85         assert(instance->ddf_instance->handle);
    86         ddf_dev_t *dev = instance->rh.device;
    87         int ret = EOK;
    88 
    89         usb_hc_connection_t conn;
    90         ret =
    91             usb_hc_connection_initialize(&conn, instance->ddf_instance->handle);
    92         CHECK_RET_RETURN(ret, "Failed to initialize hc connection.\n");
    93 
    94         ret = usb_hc_connection_open(&conn);
    95         CHECK_RET_RETURN(ret, "Failed to open hc connection.\n");
    96 
    97         usb_address_t address;
    98         devman_handle_t handle;
    99         ret = usb_hc_new_device_wrapper(dev, &conn, USB_SPEED_FULL, dummy_reset,
    100             0, instance, &address, &handle, NULL, NULL, NULL);
    101         CHECK_RET_RETURN(ret, "Failed to add rh device.\n");
    102 
    103         ret = usb_hc_connection_close(&conn);
    104         CHECK_RET_RETURN(ret, "Failed to close hc connection.\n");
    10597        return EOK;
    10698}
     
    117109}
    118110/*----------------------------------------------------------------------------*/
    119 void hc_interrupt(hc_t *instance, uint16_t status)
     111void hc_interrupt(hc_t *instance, uint32_t status)
    120112{
    121113        assert(instance);
    122         /* TODO: Check for interrupt cause */
    123         rh_interrupt(&instance->rh);
     114        if (status == 0)
     115                return;
     116        if (status & IS_RHSC)
     117                rh_interrupt(&instance->rh);
     118
     119        /* TODO: Check for further interrupt causes */
    124120        /* TODO: implement */
     121}
     122/*----------------------------------------------------------------------------*/
     123int interrupt_emulator(hc_t *instance)
     124{
     125        assert(instance);
     126        usb_log_info("Started interrupt emulator.\n");
     127        while (1) {
     128                uint32_t status = instance->registers->interrupt_status;
     129                instance->registers->interrupt_status = status;
     130                hc_interrupt(instance, status);
     131                async_usleep(1000);
     132        }
     133        return EOK;
    125134}
    126135/**
Note: See TracChangeset for help on using the changeset viewer.