1 | /*
|
---|
2 | * Copyright (c) 2014 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 <stdlib.h>
|
---|
37 | #include <usb/debug.h>
|
---|
38 | #include <usb/host/utils/malloc32.h>
|
---|
39 |
|
---|
40 | #include "ehci_endpoint.h"
|
---|
41 | #include "hc.h"
|
---|
42 |
|
---|
43 | /** Callback to set toggle on ED.
|
---|
44 | *
|
---|
45 | * @param[in] hcd_ep hcd endpoint structure
|
---|
46 | * @param[in] toggle new value of toggle bit
|
---|
47 | */
|
---|
48 | static void ehci_ep_toggle_set(void *ehci_ep, int toggle)
|
---|
49 | {
|
---|
50 | ehci_endpoint_t *instance = ehci_ep;
|
---|
51 | assert(instance);
|
---|
52 | assert(instance->qh);
|
---|
53 | if (qh_toggle_from_td(instance->qh))
|
---|
54 | usb_log_warning("EP(%p): Setting toggle bit for transfer "
|
---|
55 | "directed EP", instance);
|
---|
56 | qh_toggle_set(instance->qh, toggle);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /** Callback to get value of toggle bit.
|
---|
60 | *
|
---|
61 | * @param[in] hcd_ep hcd endpoint structure
|
---|
62 | * @return Current value of toggle bit.
|
---|
63 | */
|
---|
64 | static int ehci_ep_toggle_get(void *ehci_ep)
|
---|
65 | {
|
---|
66 | ehci_endpoint_t *instance = ehci_ep;
|
---|
67 | assert(instance);
|
---|
68 | assert(instance->qh);
|
---|
69 | if (qh_toggle_from_td(instance->qh))
|
---|
70 | usb_log_warning("EP(%p): Reading useless toggle bit", instance);
|
---|
71 | return qh_toggle_get(instance->qh);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /** Creates new hcd endpoint representation.
|
---|
75 | *
|
---|
76 | * @param[in] ep USBD endpoint structure
|
---|
77 | * @return Error code.
|
---|
78 | */
|
---|
79 | int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
|
---|
80 | {
|
---|
81 | assert(ep);
|
---|
82 | hc_t *hc = hcd_get_driver_data(hcd);
|
---|
83 |
|
---|
84 | ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t));
|
---|
85 | if (ehci_ep == NULL)
|
---|
86 | return ENOMEM;
|
---|
87 |
|
---|
88 | ehci_ep->qh = malloc32(sizeof(qh_t));
|
---|
89 | if (ehci_ep->qh == NULL) {
|
---|
90 | free(ehci_ep);
|
---|
91 | return ENOMEM;
|
---|
92 | }
|
---|
93 |
|
---|
94 | usb_log_debug2("EP(%p): Creating for %p", ehci_ep, ep);
|
---|
95 | link_initialize(&ehci_ep->link);
|
---|
96 | qh_init(ehci_ep->qh, ep);
|
---|
97 | endpoint_set_hc_data(
|
---|
98 | ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set);
|
---|
99 | hc_enqueue_endpoint(hc, ep);
|
---|
100 | return EOK;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /** Disposes hcd endpoint structure
|
---|
104 | *
|
---|
105 | * @param[in] hcd driver using this instance.
|
---|
106 | * @param[in] ep endpoint structure.
|
---|
107 | */
|
---|
108 | void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
|
---|
109 | {
|
---|
110 | assert(hcd);
|
---|
111 | assert(ep);
|
---|
112 | hc_t *hc = hcd_get_driver_data(hcd);
|
---|
113 |
|
---|
114 | ehci_endpoint_t *instance = ehci_endpoint_get(ep);
|
---|
115 | hc_dequeue_endpoint(hc, ep);
|
---|
116 | endpoint_clear_hc_data(ep);
|
---|
117 | usb_log_debug2("EP(%p): Destroying for %p", instance, ep);
|
---|
118 | if (instance) {
|
---|
119 | free32(instance->qh);
|
---|
120 | free(instance);
|
---|
121 | }
|
---|
122 | }
|
---|
123 | /**
|
---|
124 | * @}
|
---|
125 | */
|
---|
126 |
|
---|