Changeset 2c617b0 in mainline


Ignore:
Timestamp:
2011-04-02T18:39:07Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c2be0e5
Parents:
4d946647
Message:

Basic OHCI initialization

Location:
uspace/drv/ohci
Files:
3 edited

Legend:

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

    r4d946647 r2c617b0  
    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)
     
    9294        }
    9395
     96        hc_gain_control(instance);
     97
    9498        rh_init(&instance->rh, dev, instance->registers);
     99
     100        hc_init_hw(instance);
    95101
    96102        /* TODO: implement */
     
    117123                rh_interrupt(&instance->rh);
    118124
     125        usb_log_info("OHCI interrupt: %x.\n", status);
     126
    119127        /* TODO: Check for further interrupt causes */
    120128        /* TODO: implement */
     
    126134        usb_log_info("Started interrupt emulator.\n");
    127135        while (1) {
    128                 uint32_t status = instance->registers->interrupt_status;
     136                const uint32_t status = instance->registers->interrupt_status;
    129137                instance->registers->interrupt_status = status;
    130138                hc_interrupt(instance, status);
     
    133141        return EOK;
    134142}
     143/*----------------------------------------------------------------------------*/
     144void hc_gain_control(hc_t *instance)
     145{
     146        assert(instance);
     147        /* Interrupt routing enabled => smm driver is active */
     148        if (instance->registers->control & C_IR) {
     149                usb_log_info("Found SMM driver requesting ownership change.\n");
     150                instance->registers->command_status |= CS_OCR;
     151                while (instance->registers->control & C_IR) {
     152                        async_usleep(1000);
     153                }
     154                usb_log_info("Ownership taken from SMM driver.\n");
     155                return;
     156        }
     157
     158        const unsigned hc_status =
     159            (instance->registers->control >> C_HCFS_SHIFT) & C_HCFS_MASK;
     160        /* Interrupt routing disabled && status != USB_RESET => BIOS active */
     161        if (hc_status != C_HCFS_RESET) {
     162                usb_log_info("Found BIOS driver.\n");
     163                if (hc_status == C_HCFS_OPERATIONAL) {
     164                        usb_log_info("HC operational(BIOS).\n");
     165                        return;
     166                }
     167                /* HC is suspended assert resume for 20ms */
     168                instance->registers->control &= (C_HCFS_RESUME << C_HCFS_SHIFT);
     169                async_usleep(20000);
     170                return;
     171        }
     172
     173        /* HC is in reset (hw startup) => no other driver
     174         * maintain reset for at least the time specified in USB spec (50 ms)*/
     175        async_usleep(50000);
     176}
     177/*----------------------------------------------------------------------------*/
     178void hc_init_hw(hc_t *instance)
     179{
     180        assert(instance);
     181        const uint32_t fm_interval = instance->registers->fm_interval;
     182        instance->registers->command_status = CS_HCR;
     183        async_usleep(10);
     184        instance->registers->fm_interval = fm_interval;
     185        assert((instance->registers->command_status & CS_HCR) == 0);
     186        /* hc is now in suspend state */
     187
     188        instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT);
     189        usb_log_info("OHCI HC up and running.\n");
     190}
    135191/**
    136192 * @}
  • uspace/drv/ohci/ohci_regs.h

    r4d946647 r2c617b0  
    3939typedef struct ohci_regs
    4040{
    41         volatile uint32_t revision;
     41        const volatile uint32_t revision;
    4242        volatile uint32_t control;
     43#define C_CSBR_MASK (0x3)
     44#define C_CSBR_SHIFT (0)
     45#define C_PLE (1 << 2)
     46#define C_IE (1 << 3)
     47#define C_CLE (1 << 4)
     48#define C_BLE (1 << 5)
     49
     50#define C_HCFS_MASK (0x3)
     51#define C_HCFS_SHIFT (6)
     52#define C_HCFS_RESET (0x0)
     53#define C_HCFS_OPERATIONAL (0x1)
     54#define C_HCFS_RESUME (0x2)
     55#define C_HCFS_SUSPEND (0x3)
     56
     57#define C_IR (1 << 8)
     58#define C_RWC (1 << 9)
     59#define C_RWE (1 << 10)
     60
    4361        volatile uint32_t command_status;
     62#define CS_HCR (1 << 0)
     63#define CS_CLF (1 << 1)
     64#define CS_BLF (1 << 2)
     65#define CS_OCR (1 << 3)
     66#define CS_SOC_MASK (0x3)
     67#define CS_SOC_SHIFT (16)
     68
    4469        volatile uint32_t interrupt_status;
    4570#define IS_SO (1 << 0)
     
    5176#define IS_RHSC (1 << 6)
    5277#define IS_OC (1 << 30)
     78
    5379        volatile uint32_t interupt_enable;
    5480#define IE_SO   (1 << 0)
  • uspace/drv/ohci/root_hub.c

    r4d946647 r2c617b0  
    252252
    253253
    254         usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
     254        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
    255255
    256256        //start generic usb hub driver
Note: See TracChangeset for help on using the changeset viewer.