1 | /*
|
---|
2 | * Copyright (c) 2013 Jan Vesely
|
---|
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 | /** @addtogroup drvusbehci
|
---|
29 | * @{
|
---|
30 | */
|
---|
31 | /** @file
|
---|
32 | * @brief EHCI driver
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include <assert.h>
|
---|
36 | #include <usb/usb.h>
|
---|
37 | #include <mem.h>
|
---|
38 | #include <macros.h>
|
---|
39 |
|
---|
40 | #include "mem_access.h"
|
---|
41 |
|
---|
42 | #include "queue_head.h"
|
---|
43 |
|
---|
44 | const uint32_t speed[] = {
|
---|
45 | [USB_SPEED_LOW] = QH_EP_CHAR_EPS_LS,
|
---|
46 | [USB_SPEED_FULL] = QH_EP_CHAR_EPS_FS,
|
---|
47 | [USB_SPEED_HIGH] = QH_EP_CHAR_EPS_HS,
|
---|
48 | };
|
---|
49 |
|
---|
50 | void qh_init(qh_t *instance, const endpoint_t *ep)
|
---|
51 | {
|
---|
52 | assert(instance);
|
---|
53 | memset(instance, 0, sizeof(*instance));
|
---|
54 |
|
---|
55 | EHCI_MEM32_WR(instance->horizontal, LINK_POINTER_TERM);
|
---|
56 | EHCI_MEM32_WR(instance->current, LINK_POINTER_TERM);
|
---|
57 | EHCI_MEM32_WR(instance->next, LINK_POINTER_TERM);
|
---|
58 | EHCI_MEM32_WR(instance->alternate, LINK_POINTER_TERM);
|
---|
59 | if (ep == NULL) {
|
---|
60 | /* Mark as halted and list head, used by endpoint lists
|
---|
61 | * as dummy */
|
---|
62 | EHCI_MEM32_WR(instance->ep_char, QH_EP_CHAR_H_FLAG);
|
---|
63 | EHCI_MEM32_WR(instance->status, QH_STATUS_HALTED_FLAG);
|
---|
64 | return;
|
---|
65 | }
|
---|
66 | assert(ep->speed < ARRAY_SIZE(speed));
|
---|
67 | EHCI_MEM32_WR(instance->ep_char,
|
---|
68 | QH_EP_CHAR_ADDR_SET(ep->address) |
|
---|
69 | QH_EP_CHAR_EP_SET(ep->endpoint) |
|
---|
70 | speed[ep->speed] |
|
---|
71 | QH_EP_CHAR_MAX_LENGTH_SET(ep->max_packet_size)
|
---|
72 | );
|
---|
73 | if (ep->transfer_type == USB_TRANSFER_CONTROL) {
|
---|
74 | if (ep->speed != USB_SPEED_HIGH)
|
---|
75 | EHCI_MEM32_SET(instance->ep_char, QH_EP_CHAR_C_FLAG);
|
---|
76 | /* Let BULK and INT use queue head managed toggle,
|
---|
77 | * CONTROL needs special toggle handling anyway */
|
---|
78 | EHCI_MEM32_SET(instance->ep_char, QH_EP_CHAR_DTC_FLAG);
|
---|
79 | }
|
---|
80 |
|
---|
81 | // TODO Figure out how to correctly use CMASK and SMASK for LS/FS
|
---|
82 | // INT transfers. Current values are just guesses
|
---|
83 | /* Setting TT stuff on HS endpoints is OK, the fields are ignored,
|
---|
84 | * and so is setting multi on async (should be 1 anyway)*/
|
---|
85 | EHCI_MEM32_WR(instance->ep_cap,
|
---|
86 | QH_EP_CAP_MULTI_SET(ep->packets) |
|
---|
87 | QH_EP_CAP_TT_PORT_SET(ep->tt.port) |
|
---|
88 | QH_EP_CAP_TT_ADDR_SET(ep->tt.address) |
|
---|
89 | QH_EP_CAP_C_MASK_SET(3 << 2) |
|
---|
90 | QH_EP_CAP_S_MASK_SET(3)
|
---|
91 | );
|
---|
92 | /* The rest of the fields are transfer working area, it should be ok to
|
---|
93 | * leave it NULL */
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * @}
|
---|
98 | */
|
---|