[9351353] | 1 | /*
|
---|
[a9f91cd] | 2 | * Copyright (c) 2011 Jan Vesely
|
---|
[9351353] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[17ceb72] | 29 | /** @addtogroup drvusbuhcihc
|
---|
[9351353] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[17ceb72] | 33 | * @brief UHCI host controller driver structure
|
---|
[9351353] | 34 | */
|
---|
[58563585] | 35 |
|
---|
[23f40280] | 36 | #ifndef DRV_UHCI_HC_H
|
---|
| 37 | #define DRV_UHCI_HC_H
|
---|
[9351353] | 38 |
|
---|
[7de1988c] | 39 | #include <device/hw_res_parsed.h>
|
---|
[9351353] | 40 | #include <fibril.h>
|
---|
[c95c00e] | 41 | #include <macros.h>
|
---|
[8064c2f6] | 42 | #include <stdbool.h>
|
---|
[7ee7e6a] | 43 | #include <ddi.h>
|
---|
[5fe0a697] | 44 | #include <usb/host/hcd.h>
|
---|
[fc0271a5] | 45 | #include <usb/host/usb2_bus.h>
|
---|
[8064c2f6] | 46 | #include <usb/host/usb_transfer_batch.h>
|
---|
[9351353] | 47 |
|
---|
[8064c2f6] | 48 | #include "uhci_rh.h"
|
---|
[9351353] | 49 | #include "transfer_list.h"
|
---|
[8064c2f6] | 50 | #include "hw_struct/link_pointer.h"
|
---|
[9351353] | 51 |
|
---|
[ea993d18] | 52 | /** UHCI I/O registers layout */
|
---|
[9351353] | 53 | typedef struct uhci_regs {
|
---|
[ea993d18] | 54 | /** Command register, controls HC behaviour */
|
---|
[c95c00e] | 55 | ioport16_t usbcmd;
|
---|
[9351353] | 56 | #define UHCI_CMD_MAX_PACKET (1 << 7)
|
---|
| 57 | #define UHCI_CMD_CONFIGURE (1 << 6)
|
---|
| 58 | #define UHCI_CMD_DEBUG (1 << 5)
|
---|
| 59 | #define UHCI_CMD_FORCE_GLOBAL_RESUME (1 << 4)
|
---|
| 60 | #define UHCI_CMD_FORCE_GLOBAL_SUSPEND (1 << 3)
|
---|
| 61 | #define UHCI_CMD_GLOBAL_RESET (1 << 2)
|
---|
| 62 | #define UHCI_CMD_HCRESET (1 << 1)
|
---|
| 63 | #define UHCI_CMD_RUN_STOP (1 << 0)
|
---|
| 64 |
|
---|
[ea993d18] | 65 | /** Status register, 1 means interrupt is asserted (if enabled) */
|
---|
[c95c00e] | 66 | ioport16_t usbsts;
|
---|
[9351353] | 67 | #define UHCI_STATUS_HALTED (1 << 5)
|
---|
| 68 | #define UHCI_STATUS_PROCESS_ERROR (1 << 4)
|
---|
| 69 | #define UHCI_STATUS_SYSTEM_ERROR (1 << 3)
|
---|
| 70 | #define UHCI_STATUS_RESUME (1 << 2)
|
---|
| 71 | #define UHCI_STATUS_ERROR_INTERRUPT (1 << 1)
|
---|
| 72 | #define UHCI_STATUS_INTERRUPT (1 << 0)
|
---|
[302a4b6] | 73 | #define UHCI_STATUS_NM_INTERRUPTS \
|
---|
| 74 | (UHCI_STATUS_PROCESS_ERROR | UHCI_STATUS_SYSTEM_ERROR)
|
---|
[9351353] | 75 |
|
---|
[ea993d18] | 76 | /** Interrupt enabled registers */
|
---|
[c95c00e] | 77 | ioport16_t usbintr;
|
---|
[9351353] | 78 | #define UHCI_INTR_SHORT_PACKET (1 << 3)
|
---|
| 79 | #define UHCI_INTR_COMPLETE (1 << 2)
|
---|
| 80 | #define UHCI_INTR_RESUME (1 << 1)
|
---|
| 81 | #define UHCI_INTR_CRC (1 << 0)
|
---|
| 82 |
|
---|
[ea993d18] | 83 | /** Register stores frame number used in SOF packet */
|
---|
[c95c00e] | 84 | ioport16_t frnum;
|
---|
[ea993d18] | 85 |
|
---|
| 86 | /** Pointer(physical) to the Frame List */
|
---|
[c95c00e] | 87 | ioport32_t flbaseadd;
|
---|
[ea993d18] | 88 |
|
---|
| 89 | /** SOF modification to match external timers */
|
---|
[c95c00e] | 90 | ioport8_t sofmod;
|
---|
| 91 |
|
---|
| 92 | PADD8[3];
|
---|
| 93 | ioport16_t ports[];
|
---|
[dfe4955] | 94 | } uhci_regs_t;
|
---|
[9351353] | 95 |
|
---|
| 96 | #define UHCI_FRAME_LIST_COUNT 1024
|
---|
| 97 | #define UHCI_DEBUGER_TIMEOUT 5000000
|
---|
[fcc525d] | 98 | #define UHCI_ALLOWED_HW_FAIL 5
|
---|
[9351353] | 99 |
|
---|
[02cacce] | 100 | /** Main UHCI driver structure */
|
---|
[c01cd32] | 101 | typedef struct hc {
|
---|
[32fb6bce] | 102 | /* Common hc_device header */
|
---|
| 103 | hc_device_t base;
|
---|
| 104 |
|
---|
[c95c00e] | 105 | uhci_rh_t rh;
|
---|
[d369b3b] | 106 | bus_t bus;
|
---|
| 107 | usb2_bus_helper_t bus_helper;
|
---|
| 108 |
|
---|
[ea993d18] | 109 | /** Addresses of I/O registers */
|
---|
[dfe4955] | 110 | uhci_regs_t *registers;
|
---|
[9351353] | 111 |
|
---|
[ea993d18] | 112 | /** Frame List contains 1024 link pointers */
|
---|
[9351353] | 113 | link_pointer_t *frame_list;
|
---|
| 114 |
|
---|
[ea993d18] | 115 | /** List and queue of interrupt transfers */
|
---|
| 116 | transfer_list_t transfers_interrupt;
|
---|
| 117 | /** List and queue of low speed control transfers */
|
---|
| 118 | transfer_list_t transfers_control_slow;
|
---|
| 119 | /** List and queue of full speed bulk transfers */
|
---|
[9351353] | 120 | transfer_list_t transfers_bulk_full;
|
---|
[ea993d18] | 121 | /** List and queue of full speed control transfers */
|
---|
[9351353] | 122 | transfer_list_t transfers_control_full;
|
---|
| 123 |
|
---|
[ea993d18] | 124 | /** Pointer table to the above lists, helps during scheduling */
|
---|
[9351353] | 125 | transfer_list_t *transfers[2][4];
|
---|
| 126 |
|
---|
[4db49344] | 127 | /**
|
---|
| 128 | * Guard for the pending list. Can be locked under EP guard, but not
|
---|
| 129 | * vice versa.
|
---|
| 130 | */
|
---|
| 131 | fibril_mutex_t guard;
|
---|
| 132 | /** List of endpoints with a transfer scheduled */
|
---|
| 133 | list_t pending_endpoints;
|
---|
| 134 |
|
---|
[ea993d18] | 135 | /** Number of hw failures detected. */
|
---|
| 136 | unsigned hw_failures;
|
---|
[c01cd32] | 137 | } hc_t;
|
---|
[3afb758] | 138 |
|
---|
[c6f82e5] | 139 | typedef struct uhci_endpoint {
|
---|
| 140 | endpoint_t base;
|
---|
| 141 |
|
---|
| 142 | bool toggle;
|
---|
| 143 | } uhci_endpoint_t;
|
---|
| 144 |
|
---|
[32fb6bce] | 145 | static inline hc_t *hcd_to_hc(hc_device_t *hcd)
|
---|
| 146 | {
|
---|
| 147 | assert(hcd);
|
---|
| 148 | return (hc_t *) hcd;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | static inline hc_t *bus_to_hc(bus_t *bus)
|
---|
| 152 | {
|
---|
| 153 | assert(bus);
|
---|
| 154 | return member_to_inst(bus, hc_t, bus);
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[929599a8] | 157 | int hc_unschedule_batch(usb_transfer_batch_t *);
|
---|
| 158 |
|
---|
[32fb6bce] | 159 | extern int hc_add(hc_device_t *, const hw_res_list_parsed_t *);
|
---|
| 160 | extern int hc_gen_irq_code(irq_code_t *, hc_device_t *, const hw_res_list_parsed_t *);
|
---|
| 161 | extern int hc_start(hc_device_t *);
|
---|
[129b821f] | 162 | extern int hc_setup_roothub(hc_device_t *);
|
---|
[32fb6bce] | 163 | extern int hc_gone(hc_device_t *);
|
---|
[9351353] | 164 |
|
---|
| 165 | #endif
|
---|
[7de1988c] | 166 |
|
---|
[9351353] | 167 | /**
|
---|
| 168 | * @}
|
---|
| 169 | */
|
---|