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 | /** @addtogroup drvusbohci
|
---|
29 | * @{
|
---|
30 | */
|
---|
31 | /** @file
|
---|
32 | * @brief OHCI driver
|
---|
33 | */
|
---|
34 | #include "utils/malloc32.h"
|
---|
35 | #include "ohci_endpoint.h"
|
---|
36 | #include "hc.h"
|
---|
37 |
|
---|
38 | /** Callback to set toggle on ED.
|
---|
39 | *
|
---|
40 | * @param[in] hcd_ep hcd endpoint structure
|
---|
41 | * @param[in] toggle new value of toggle bit
|
---|
42 | */
|
---|
43 | static void ohci_ep_toggle_set(void *ohci_ep, int toggle)
|
---|
44 | {
|
---|
45 | ohci_endpoint_t *instance = ohci_ep;
|
---|
46 | assert(instance);
|
---|
47 | assert(instance->ed);
|
---|
48 | ed_toggle_set(instance->ed, toggle);
|
---|
49 | }
|
---|
50 | /*----------------------------------------------------------------------------*/
|
---|
51 | /** Callback to get value of toggle bit.
|
---|
52 | *
|
---|
53 | * @param[in] hcd_ep hcd endpoint structure
|
---|
54 | * @return Current value of toggle bit.
|
---|
55 | */
|
---|
56 | static int ohci_ep_toggle_get(void *ohci_ep)
|
---|
57 | {
|
---|
58 | ohci_endpoint_t *instance = ohci_ep;
|
---|
59 | assert(instance);
|
---|
60 | assert(instance->ed);
|
---|
61 | return ed_toggle_get(instance->ed);
|
---|
62 | }
|
---|
63 | /*----------------------------------------------------------------------------*/
|
---|
64 | /** Disposes hcd endpoint structure
|
---|
65 | *
|
---|
66 | * @param[in] hcd_ep endpoint structure
|
---|
67 | */
|
---|
68 | static void ohci_endpoint_fini(endpoint_t *ep)
|
---|
69 | {
|
---|
70 | ohci_endpoint_t *instance = ep->hc_data.data;
|
---|
71 | hc_dequeue_endpoint(instance->hcd->private_data, ep);
|
---|
72 | if (instance) {
|
---|
73 | free32(instance->ed);
|
---|
74 | free32(instance->td);
|
---|
75 | free(instance);
|
---|
76 | }
|
---|
77 | }
|
---|
78 | /*----------------------------------------------------------------------------*/
|
---|
79 | /** Creates new hcd endpoint representation.
|
---|
80 | *
|
---|
81 | * @param[in] ep USBD endpoint structure
|
---|
82 | * @return pointer to a new hcd endpoint structure, NULL on failure.
|
---|
83 | */
|
---|
84 | int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
|
---|
85 | {
|
---|
86 | assert(ep);
|
---|
87 | ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
|
---|
88 | if (ohci_ep == NULL)
|
---|
89 | return ENOMEM;
|
---|
90 |
|
---|
91 | ohci_ep->ed = malloc32(sizeof(ed_t));
|
---|
92 | if (ohci_ep->ed == NULL) {
|
---|
93 | free(ohci_ep);
|
---|
94 | return ENOMEM;
|
---|
95 | }
|
---|
96 |
|
---|
97 | ohci_ep->td = malloc32(sizeof(td_t));
|
---|
98 | if (ohci_ep->td == NULL) {
|
---|
99 | free32(ohci_ep->ed);
|
---|
100 | free(ohci_ep);
|
---|
101 | return ENOMEM;
|
---|
102 | }
|
---|
103 |
|
---|
104 | ed_init(ohci_ep->ed, ep);
|
---|
105 | ed_set_td(ohci_ep->ed, ohci_ep->td);
|
---|
106 | endpoint_set_hc_data(
|
---|
107 | ep, ohci_ep, ohci_endpoint_fini, ohci_ep_toggle_get, ohci_ep_toggle_set);
|
---|
108 | ohci_ep->hcd = hcd;
|
---|
109 | hc_enqueue_endpoint(hcd->private_data, ep);
|
---|
110 | return EOK;
|
---|
111 | }
|
---|
112 | /**
|
---|
113 | * @}
|
---|
114 | */
|
---|