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 |
|
---|
36 | #include <assert.h>
|
---|
37 | #include <usb/usb.h>
|
---|
38 | #include <mem.h>
|
---|
39 | #include <macros.h>
|
---|
40 | #include <usb/host/bus.h>
|
---|
41 |
|
---|
42 | #include "mem_access.h"
|
---|
43 | #include "queue_head.h"
|
---|
44 |
|
---|
45 | static const uint32_t speed[] = {
|
---|
46 | [USB_SPEED_LOW] = QH_EP_CHAR_EPS_LS,
|
---|
47 | [USB_SPEED_FULL] = QH_EP_CHAR_EPS_FS,
|
---|
48 | [USB_SPEED_HIGH] = QH_EP_CHAR_EPS_HS,
|
---|
49 | };
|
---|
50 |
|
---|
51 | void qh_init(qh_t *instance, const endpoint_t *ep)
|
---|
52 | {
|
---|
53 | assert(instance);
|
---|
54 | memset(instance, 0, sizeof(*instance));
|
---|
55 |
|
---|
56 | EHCI_MEM32_WR(instance->horizontal, LINK_POINTER_TERM);
|
---|
57 | #if 0
|
---|
58 | EHCI_MEM32_WR(instance->current, LINK_POINTER_TERM);
|
---|
59 | #endif
|
---|
60 | EHCI_MEM32_WR(instance->next, LINK_POINTER_TERM);
|
---|
61 | EHCI_MEM32_WR(instance->alternate, LINK_POINTER_TERM);
|
---|
62 | if (ep == NULL) {
|
---|
63 | /*
|
---|
64 | * Mark as halted and list head,
|
---|
65 | * used by endpoint lists as dummy
|
---|
66 | */
|
---|
67 | EHCI_MEM32_WR(instance->ep_char, QH_EP_CHAR_H_FLAG);
|
---|
68 | EHCI_MEM32_WR(instance->status, QH_STATUS_HALTED_FLAG);
|
---|
69 | return;
|
---|
70 | }
|
---|
71 | assert(ep->device->speed < ARRAY_SIZE(speed));
|
---|
72 | EHCI_MEM32_WR(instance->ep_char,
|
---|
73 | QH_EP_CHAR_ADDR_SET(ep->device->address) |
|
---|
74 | QH_EP_CHAR_EP_SET(ep->endpoint) |
|
---|
75 | speed[ep->device->speed] |
|
---|
76 | QH_EP_CHAR_MAX_LENGTH_SET(ep->max_packet_size));
|
---|
77 | if (ep->transfer_type == USB_TRANSFER_CONTROL) {
|
---|
78 | if (ep->device->speed != USB_SPEED_HIGH)
|
---|
79 | EHCI_MEM32_SET(instance->ep_char, QH_EP_CHAR_C_FLAG);
|
---|
80 | /*
|
---|
81 | * Let BULK and INT use queue head managed toggle,
|
---|
82 | * CONTROL needs special toggle handling anyway
|
---|
83 | */
|
---|
84 | EHCI_MEM32_SET(instance->ep_char, QH_EP_CHAR_DTC_FLAG);
|
---|
85 | }
|
---|
86 | uint32_t ep_cap = QH_EP_CAP_C_MASK_SET(3 << 2) |
|
---|
87 | QH_EP_CAP_MULTI_SET(ep->packets_per_uframe);
|
---|
88 | if (usb_speed_is_11(ep->device->speed)) {
|
---|
89 | assert(ep->device->tt.dev != NULL);
|
---|
90 | ep_cap |=
|
---|
91 | QH_EP_CAP_TT_PORT_SET(ep->device->tt.port) |
|
---|
92 | QH_EP_CAP_TT_ADDR_SET(ep->device->tt.dev->address);
|
---|
93 | }
|
---|
94 | if (ep->transfer_type == USB_TRANSFER_INTERRUPT) {
|
---|
95 | ep_cap |= QH_EP_CAP_S_MASK_SET(3);
|
---|
96 | }
|
---|
97 |
|
---|
98 | // TODO Figure out how to correctly use CMASK and SMASK for LS/FS
|
---|
99 | // INT transfers. Current values are just guesses
|
---|
100 | EHCI_MEM32_WR(instance->ep_cap, ep_cap);
|
---|
101 |
|
---|
102 | /*
|
---|
103 | * The rest of the fields are transfer working area, it should be ok to
|
---|
104 | * leave it NULL
|
---|
105 | */
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * @}
|
---|
110 | */
|
---|