Ticket #350: ohci-resume.patch

File ohci-resume.patch, 2.1 KB (added by Jan Vesely, 13 years ago)

Resume device if we are slow during OHCI startup

  • uspace/drv/ohci/hc.c

    === modified file 'uspace/drv/ohci/hc.c'
     
    3434#include <errno.h>
    3535#include <str_error.h>
    3636#include <adt/list.h>
     37#include <time.h>
    3738#include <libarch/ddi.h>
    3839
    3940#include <usb/debug.h>
     
    472473        }
    473474        usb_log_debug2("HC reset complete in %zu us.\n", time);
    474475
     476        struct timeval start, end;
     477        int ret = gettimeofday(&start, NULL);
     478        assert(ret == EOK);
     479
     480        /* hc is now in suspend state */
     481        usb_log_debug2("HC should be in suspend state(%x):%x.\n",
     482            C_HCFS_SUSPEND << C_HCFS_SHIFT, instance->registers->control);
     483
    475484        /* Restore fm_interval */
    476485        instance->registers->fm_interval = fm_interval;
    477         assert((instance->registers->command_status & CS_HCR) == 0);
    478 
    479         /* hc is now in suspend state */
    480         usb_log_debug2("HC should be in suspend state(%x).\n",
    481             instance->registers->control);
    482486
    483487        /* Use HCCA */
    484488        instance->registers->hcca = addr_to_phys(instance->hcca);
     
    514518            instance->registers->periodic_start,
    515519            instance->registers->periodic_start, frame_length);
    516520
    517         instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT);
     521        ret = gettimeofday(&end, NULL);
     522        assert(ret == EOK);
     523
     524        /* The Host Controller is now in the USBSUSPEND state;
     525         * it must not stay in this state more than 2 ms
     526         * or the USBRESUME state will need to be entered for
     527         * the minimum time specified in the USB Specification
     528         * for the assertion of resume on the USB.
     529         * OpenHCI - 5.1.1.4
     530         */
     531        if (tv_sub(&end, &start) > 2000) {
     532                usb_log_info("OHCI setup took too long, force resume.\n");
     533                /* We may use simple &= to change status as RESUME is bit
     534                 * subset of SUSPEND (suspend = 0x3, resume 0x1)*/
     535                instance->registers->control &=
     536                    (C_HCFS_RESUME << C_HCFS_SHIFT);
     537                async_usleep(20000);
     538
     539        }
     540        instance->registers->control =
     541            (instance->registers->control & ~(C_HCFS_MASK << C_HCFS_SHIFT)) |
     542            (C_HCFS_OPERATIONAL << C_HCFS_SHIFT);
    518543        usb_log_info("OHCI HC up and running(%x).\n",
    519544            instance->registers->control);
    520545}