Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/uhci.c

    r1ae51ae rb9d910f  
    3333 */
    3434#include <errno.h>
    35 #include <str_error.h>
    3635#include <adt/list.h>
    37 #include <libarch/ddi.h>
    3836
    3937#include <usb/debug.h>
    4038#include <usb/usb.h>
    41 #include <usb/ddfiface.h>
    42 #include <usb_iface.h>
    4339
    4440#include "uhci.h"
    45 #include "iface.h"
    46 
    4741static irq_cmd_t uhci_cmds[] = {
    4842        {
    4943                .cmd = CMD_PIO_READ_16,
    50                 .addr = NULL, /* patched for every instance */
     44                .addr = (void*)0xc022,
    5145                .dstarg = 1
    5246        },
    5347        {
    5448                .cmd = CMD_PIO_WRITE_16,
    55                 .addr = NULL, /* pathed for every instance */
     49                .addr = (void*)0xc022,
    5650                .value = 0x1f
    5751        },
     
    5953                .cmd = CMD_ACCEPT
    6054        }
    61 };
    62 
    63 static int usb_iface_get_address(ddf_fun_t *fun, devman_handle_t handle,
    64     usb_address_t *address)
    65 {
    66         assert(fun);
    67         uhci_t *hc = fun_to_uhci(fun);
    68         assert(hc);
    69 
    70         usb_address_t addr = device_keeper_find(&hc->device_manager,
    71             handle);
    72         if (addr < 0) {
    73                 return addr;
    74         }
    75 
    76         if (address != NULL) {
    77                 *address = addr;
    78         }
    79 
    80         return EOK;
    81 }
    82 /*----------------------------------------------------------------------------*/
    83 static usb_iface_t hc_usb_iface = {
    84         .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
    85         .get_address = usb_iface_get_address
    86 };
    87 /*----------------------------------------------------------------------------*/
    88 static ddf_dev_ops_t uhci_ops = {
    89         .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    90         .interfaces[USBHC_DEV_IFACE] = &uhci_iface,
    9155};
    9256
     
    10771        } else (void) 0
    10872
    109 int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size)
     73int uhci_init(uhci_t *instance, void *regs, size_t reg_size)
    11074{
    11175        assert(reg_size >= sizeof(regs_t));
    112         int ret;
    113 
    114         /*
    115          * Create UHCI function.
    116          */
    117         instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci");
    118         if (instance->ddf_instance == NULL) {
    119                 usb_log_error("Failed to create UHCI device function.\n");
    120                 return ENOMEM;
    121         }
    122         instance->ddf_instance->ops = &uhci_ops;
    123         instance->ddf_instance->driver_data = instance;
    124 
    125         ret = ddf_fun_bind(instance->ddf_instance);
    126         CHECK_RET_RETURN(ret, "Failed to bind UHCI device function: %s.\n",
    127             str_error(ret));
    12876
    12977        /* allow access to hc control registers */
    13078        regs_t *io;
    131         ret = pio_enable(regs, reg_size, (void**)&io);
     79        int ret = pio_enable(regs, reg_size, (void**)&io);
    13280        CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p.\n", io);
    13381        instance->registers = io;
     
    14088
    14189        instance->cleaner = fibril_create(uhci_interrupt_emulator, instance);
    142         fibril_add_ready(instance->cleaner);
     90//      fibril_add_ready(instance->cleaner);
    14391
    14492        instance->debug_checker = fibril_create(uhci_debug_checker, instance);
     
    15098void uhci_init_hw(uhci_t *instance)
    15199{
    152         /* reset everything, who knows what touched it before us */
    153         pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
    154         async_usleep(10000); /* 10ms according to USB spec */
    155         pio_write_16(&instance->registers->usbcmd, 0);
    156 
    157         /* reset hc, all states and counters */
    158         pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET);
    159         while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0)
    160                 { async_usleep(10); }
    161100
    162101        /* set framelist pointer */
     
    211150
    212151        /* init address keeper(libusb) */
    213         device_keeper_init(&instance->device_manager);
    214         usb_log_debug("Initialized device manager.\n");
     152        usb_address_keeping_init(&instance->address_manager, USB11_ADDRESS_MAX);
     153        usb_log_debug("Initialized address manager.\n");
    215154
    216155        return EOK;
     
    263202        assert(instance);
    264203        assert(batch);
    265         const int low_speed = (batch->speed == USB_SPEED_LOW);
     204        const int low_speed = (batch->speed == LOW_SPEED);
    266205        if (!allowed_usb_packet(
    267206            low_speed, batch->transfer_type, batch->max_packet_size)) {
     
    284223{
    285224        assert(instance);
    286 //      if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0)
    287 //              return;
    288 //      usb_log_debug2("UHCI interrupt: %X.\n", status);
    289         transfer_list_remove_finished(&instance->transfers_interrupt);
    290         transfer_list_remove_finished(&instance->transfers_control_slow);
    291         transfer_list_remove_finished(&instance->transfers_control_full);
    292         transfer_list_remove_finished(&instance->transfers_bulk_full);
     225        if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0)
     226                return;
     227        usb_log_debug("UHCI interrupt: %X.\n", status);
     228        transfer_list_check(&instance->transfers_interrupt);
     229        transfer_list_check(&instance->transfers_control_slow);
     230        transfer_list_check(&instance->transfers_control_full);
     231        transfer_list_check(&instance->transfers_bulk_full);
    293232}
    294233/*----------------------------------------------------------------------------*/
     
    299238        assert(instance);
    300239
    301         while (1) {
     240        while(1) {
    302241                uint16_t status = pio_read_16(&instance->registers->usbsts);
    303                 if (status != 0)
    304                         usb_log_debug2("UHCI status: %x.\n", status);
    305                 status |= 1;
    306242                uhci_interrupt(instance, status);
    307                 pio_write_16(&instance->registers->usbsts, 0x1f);
    308                 async_usleep(UHCI_CLEANER_TIMEOUT * 5);
     243                async_usleep(UHCI_CLEANER_TIMEOUT);
    309244        }
    310245        return EOK;
     
    319254                const uint16_t sts = pio_read_16(&instance->registers->usbsts);
    320255                const uint16_t intr = pio_read_16(&instance->registers->usbintr);
    321                 if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) {
    322                         usb_log_debug2("Command: %X Status: %X Intr: %x\n",
    323                             cmd, sts, intr);
    324                 }
    325 
    326                 uintptr_t frame_list =
    327                     pio_read_32(&instance->registers->flbaseadd) & ~0xfff;
     256                usb_log_debug("Command: %X Status: %X Interrupts: %x\n",
     257                    cmd, sts, intr);
     258
     259                uintptr_t frame_list = pio_read_32(&instance->registers->flbaseadd);
    328260                if (frame_list != addr_to_phys(instance->frame_list)) {
    329261                        usb_log_debug("Framelist address: %p vs. %p.\n",
Note: See TracChangeset for help on using the changeset viewer.