1 | /*
|
---|
2 | * Copyright (c) 2011 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 |
|
---|
29 | /** @addtogroup drvusbohci
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief OHCI driver
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <assert.h>
|
---|
37 | #include <macros.h>
|
---|
38 | #include <mem.h>
|
---|
39 |
|
---|
40 | #include <usb/usb.h>
|
---|
41 | #include <usb/host/utils/malloc32.h>
|
---|
42 | #include <usb/host/endpoint.h>
|
---|
43 | #include <usb/host/bus.h>
|
---|
44 |
|
---|
45 | #include "mem_access.h"
|
---|
46 |
|
---|
47 | #include "endpoint_descriptor.h"
|
---|
48 |
|
---|
49 | /** USB direction to OHCI values translation table. */
|
---|
50 | static const uint32_t dir[] = {
|
---|
51 | [USB_DIRECTION_IN] = ED_STATUS_D_IN,
|
---|
52 | [USB_DIRECTION_OUT] = ED_STATUS_D_OUT,
|
---|
53 | [USB_DIRECTION_BOTH] = ED_STATUS_D_TD,
|
---|
54 | };
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Initialize ED.
|
---|
58 | *
|
---|
59 | * @param instance ED structure to initialize.
|
---|
60 | * @param ep Driver endpoint to use.
|
---|
61 | * @param td TD to put in the list.
|
---|
62 | *
|
---|
63 | * If @param ep is NULL, dummy ED is initialized with only skip flag set.
|
---|
64 | */
|
---|
65 | void ed_init(ed_t *instance, const endpoint_t *ep, const td_t *td)
|
---|
66 | {
|
---|
67 | assert(instance);
|
---|
68 | memset(instance, 0, sizeof(*instance));
|
---|
69 |
|
---|
70 | if (ep == NULL) {
|
---|
71 | /*
|
---|
72 | * Mark as dead, used for dummy EDs at the beginning of
|
---|
73 | * endpoint lists.
|
---|
74 | */
|
---|
75 | OHCI_MEM32_WR(instance->status, ED_STATUS_K_FLAG);
|
---|
76 | return;
|
---|
77 | }
|
---|
78 | /* Non-dummy ED must have corresponding EP and TD assigned */
|
---|
79 | assert(td);
|
---|
80 | assert(ep);
|
---|
81 | assert(ep->direction < ARRAY_SIZE(dir));
|
---|
82 |
|
---|
83 | /* Status: address, endpoint nr, direction mask and max packet size. */
|
---|
84 | OHCI_MEM32_WR(instance->status,
|
---|
85 | ((ep->device->address & ED_STATUS_FA_MASK) << ED_STATUS_FA_SHIFT) |
|
---|
86 | ((ep->endpoint & ED_STATUS_EN_MASK) << ED_STATUS_EN_SHIFT) |
|
---|
87 | ((dir[ep->direction] & ED_STATUS_D_MASK) << ED_STATUS_D_SHIFT) |
|
---|
88 | ((ep->max_packet_size & ED_STATUS_MPS_MASK) << ED_STATUS_MPS_SHIFT));
|
---|
89 |
|
---|
90 | /* Low speed flag */
|
---|
91 | if (ep->device->speed == USB_SPEED_LOW)
|
---|
92 | OHCI_MEM32_SET(instance->status, ED_STATUS_S_FLAG);
|
---|
93 |
|
---|
94 | /* Isochronous format flag */
|
---|
95 | // TODO: We need iTD instead of TD for iso transfers
|
---|
96 | if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)
|
---|
97 | OHCI_MEM32_SET(instance->status, ED_STATUS_F_FLAG);
|
---|
98 |
|
---|
99 | /* Set TD to the list */
|
---|
100 | const uintptr_t pa = addr_to_phys(td);
|
---|
101 | OHCI_MEM32_WR(instance->td_head, pa & ED_TDHEAD_PTR_MASK);
|
---|
102 | OHCI_MEM32_WR(instance->td_tail, pa & ED_TDTAIL_PTR_MASK);
|
---|
103 | }
|
---|
104 | /**
|
---|
105 | * @}
|
---|
106 | */
|
---|