| 1 | /*
|
|---|
| 2 | * Copyright (c) 2013 Jan Vesely
|
|---|
| 3 | * Copyright (c) 2018 Ondrej Hlavaty
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 | /** @addtogroup drvusbehci
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * @brief EHCI driver
|
|---|
| 34 | */
|
|---|
| 35 | #ifndef DRV_EHCI_EHCI_RH_H
|
|---|
| 36 | #define DRV_EHCI_EHCI_RH_H
|
|---|
| 37 |
|
|---|
| 38 | #include <assert.h>
|
|---|
| 39 | #include <stdint.h>
|
|---|
| 40 |
|
|---|
| 41 | #include <usb/usb.h>
|
|---|
| 42 | #include <usb/classes/hub.h>
|
|---|
| 43 | #include <usb/host/usb_transfer_batch.h>
|
|---|
| 44 | #include <usbvirt/virthub_base.h>
|
|---|
| 45 |
|
|---|
| 46 | #include "ehci_regs.h"
|
|---|
| 47 |
|
|---|
| 48 | enum {
|
|---|
| 49 | EHCI_MAX_PORTS = 15,
|
|---|
| 50 | };
|
|---|
| 51 |
|
|---|
| 52 | typedef struct {
|
|---|
| 53 | /** Virtual hub instance */
|
|---|
| 54 | virthub_base_t base;
|
|---|
| 55 | /** EHCI device registers */
|
|---|
| 56 | ehci_regs_t *registers;
|
|---|
| 57 | /** Number of downstream ports, EHCI limits this to 15 */
|
|---|
| 58 | unsigned port_count;
|
|---|
| 59 | /** USB hub descriptor describing the EHCI root hub */
|
|---|
| 60 | struct {
|
|---|
| 61 | usb_hub_descriptor_header_t header;
|
|---|
| 62 | uint8_t rempow[STATUS_BYTES(EHCI_MAX_PORTS) * 2];
|
|---|
| 63 | } __attribute__((packed)) hub_descriptor;
|
|---|
| 64 | bool reset_flag[EHCI_MAX_PORTS];
|
|---|
| 65 | bool resume_flag[EHCI_MAX_PORTS];
|
|---|
| 66 |
|
|---|
| 67 | /* HC guard */
|
|---|
| 68 | fibril_mutex_t *guard;
|
|---|
| 69 |
|
|---|
| 70 | /*
|
|---|
| 71 | * This is sort of hacky, but better than duplicating functionality.
|
|---|
| 72 | * We cannot simply store a pointer to a transfer in-progress, in order
|
|---|
| 73 | * to allow it to be aborted. We can however store a reference to the
|
|---|
| 74 | * Status Change Endpoint. Note that this is mixing two worlds together
|
|---|
| 75 | * - otherwise, the RH is "a device" and have no clue about HC, apart
|
|---|
| 76 | * from accessing its registers.
|
|---|
| 77 | */
|
|---|
| 78 | endpoint_t *status_change_endpoint;
|
|---|
| 79 |
|
|---|
| 80 | } ehci_rh_t;
|
|---|
| 81 |
|
|---|
| 82 | errno_t ehci_rh_init(ehci_rh_t *instance, ehci_caps_regs_t *caps,
|
|---|
| 83 | ehci_regs_t *regs, fibril_mutex_t *guard, const char *name);
|
|---|
| 84 | errno_t ehci_rh_schedule(ehci_rh_t *instance, usb_transfer_batch_t *batch);
|
|---|
| 85 | errno_t ehci_rh_interrupt(ehci_rh_t *instance);
|
|---|
| 86 |
|
|---|
| 87 | /** Get EHCI rh address.
|
|---|
| 88 | *
|
|---|
| 89 | * @param instance UHCI rh instance.
|
|---|
| 90 | * @return USB address assigned to the hub.
|
|---|
| 91 | * Wrapper for virtual hub address
|
|---|
| 92 | */
|
|---|
| 93 | static inline usb_address_t ehci_rh_get_address(ehci_rh_t *instance)
|
|---|
| 94 | {
|
|---|
| 95 | assert(instance);
|
|---|
| 96 | return virthub_base_get_address(&instance->base);
|
|---|
| 97 | }
|
|---|
| 98 | #endif
|
|---|
| 99 | /**
|
|---|
| 100 | * @}
|
|---|
| 101 | */
|
|---|