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


Ignore:
File:
1 edited

Legend:

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

    r53f1c87 rc2be0e5  
    4545
    4646static int interrupt_emulator(hc_t *instance);
     47static void hc_gain_control(hc_t *instance);
     48static void hc_init_hw(hc_t *instance);
    4749/*----------------------------------------------------------------------------*/
    4850int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
     
    5860
    5961        char *match_str = NULL;
    60         int ret = asprintf(&match_str, "usb&mid");
     62        int ret = asprintf(&match_str, "usb&class=hub");
    6163        ret = (match_str == NULL) ? ret : EOK;
    6264        if (ret < 0) {
     
    7779        assert(instance);
    7880        int ret = EOK;
     81#define CHECK_RET_RETURN(ret, message...) \
     82if (ret != EOK) { \
     83        usb_log_error(message); \
     84        return ret; \
     85} else (void)0
    7986
    8087        ret = pio_enable((void*)regs, reg_size, (void**)&instance->registers);
    81         if (ret != EOK) {
    82                 usb_log_error("Failed to gain access to device registers.\n");
    83                 return ret;
    84         }
     88        CHECK_RET_RETURN(ret,
     89            "Failed(%d) to gain access to device registers: %s.\n",
     90            ret, str_error(ret));
     91
    8592        instance->ddf_instance = fun;
    8693        usb_device_keeper_init(&instance->manager);
     94        ret = bandwidth_init(&instance->bandwidth, BANDWIDTH_AVAILABLE_USB11,
     95            bandwidth_count_usb11);
     96        CHECK_RET_RETURN(ret, "Failed to initialize bandwidth allocator: %s.\n",
     97            ret, str_error(ret));
    8798
    8899        if (!interrupts) {
     
    92103        }
    93104
     105        hc_gain_control(instance);
     106
    94107        rh_init(&instance->rh, dev, instance->registers);
     108
     109        hc_init_hw(instance);
    95110
    96111        /* TODO: implement */
     
    117132                rh_interrupt(&instance->rh);
    118133
     134        usb_log_info("OHCI interrupt: %x.\n", status);
     135
    119136        /* TODO: Check for further interrupt causes */
    120137        /* TODO: implement */
     
    126143        usb_log_info("Started interrupt emulator.\n");
    127144        while (1) {
    128                 uint32_t status = instance->registers->interrupt_status;
     145                const uint32_t status = instance->registers->interrupt_status;
    129146                instance->registers->interrupt_status = status;
    130147                hc_interrupt(instance, status);
     
    133150        return EOK;
    134151}
     152/*----------------------------------------------------------------------------*/
     153void hc_gain_control(hc_t *instance)
     154{
     155        assert(instance);
     156        /* Interrupt routing enabled => smm driver is active */
     157        if (instance->registers->control & C_IR) {
     158                usb_log_info("Found SMM driver requesting ownership change.\n");
     159                instance->registers->command_status |= CS_OCR;
     160                while (instance->registers->control & C_IR) {
     161                        async_usleep(1000);
     162                }
     163                usb_log_info("Ownership taken from SMM driver.\n");
     164                return;
     165        }
     166
     167        const unsigned hc_status =
     168            (instance->registers->control >> C_HCFS_SHIFT) & C_HCFS_MASK;
     169        /* Interrupt routing disabled && status != USB_RESET => BIOS active */
     170        if (hc_status != C_HCFS_RESET) {
     171                usb_log_info("Found BIOS driver.\n");
     172                if (hc_status == C_HCFS_OPERATIONAL) {
     173                        usb_log_info("HC operational(BIOS).\n");
     174                        return;
     175                }
     176                /* HC is suspended assert resume for 20ms */
     177                instance->registers->control &= (C_HCFS_RESUME << C_HCFS_SHIFT);
     178                async_usleep(20000);
     179                return;
     180        }
     181
     182        /* HC is in reset (hw startup) => no other driver
     183         * maintain reset for at least the time specified in USB spec (50 ms)*/
     184        async_usleep(50000);
     185}
     186/*----------------------------------------------------------------------------*/
     187void hc_init_hw(hc_t *instance)
     188{
     189        assert(instance);
     190        const uint32_t fm_interval = instance->registers->fm_interval;
     191        instance->registers->command_status = CS_HCR;
     192        async_usleep(10);
     193        instance->registers->fm_interval = fm_interval;
     194        assert((instance->registers->command_status & CS_HCR) == 0);
     195        /* hc is now in suspend state */
     196        /* TODO: init HCCA block */
     197        /* TODO: init queues */
     198        /* TODO: enable queues */
     199        /* TODO: enable interrupts */
     200        /* TODO: set periodic start to 90% */
     201
     202        instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT);
     203        usb_log_info("OHCI HC up and running.\n");
     204}
    135205/**
    136206 * @}
Note: See TracChangeset for help on using the changeset viewer.