source: mainline/uspace/drv/bus/usb/ohci/ohci_bus.c@ e6b9182

lfn serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e6b9182 was e6b9182, checked in by Ondřej Hlavatý <aearsis@…>, 9 years ago

WIP usbhost refactoring: ohci completed

Along with that we noticed hcd_t in bus_t is superfluous and it complicates initialization (and breaks isolation), so we removed it. Also, type of the toggle has changed to bool in the functions.

  • Property mode set to 100644
File size: 4.2 KB
Line 
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 <stdlib.h>
38#include <usb/host/utils/malloc32.h>
39#include <usb/host/bandwidth.h>
40
41#include "ohci_bus.h"
42#include "hc.h"
43
44/** Callback to set toggle on ED.
45 *
46 * @param[in] hcd_ep hcd endpoint structure
47 * @param[in] toggle new value of toggle bit
48 */
49static void ohci_ep_toggle_set(endpoint_t *ep, bool toggle)
50{
51 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
52 assert(instance);
53 assert(instance->ed);
54 ep->toggle = toggle;
55 ed_toggle_set(instance->ed, toggle);
56}
57
58/** Callback to get value of toggle bit.
59 *
60 * @param[in] hcd_ep hcd endpoint structure
61 * @return Current value of toggle bit.
62 */
63static bool ohci_ep_toggle_get(endpoint_t *ep)
64{
65 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
66 assert(instance);
67 assert(instance->ed);
68 return ed_toggle_get(instance->ed);
69}
70
71/** Creates new hcd endpoint representation.
72 */
73static endpoint_t *ohci_endpoint_create(bus_t *bus)
74{
75 assert(bus);
76
77 ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
78 if (ohci_ep == NULL)
79 return NULL;
80
81 ohci_ep->ed = malloc32(sizeof(ed_t));
82 if (ohci_ep->ed == NULL) {
83 free(ohci_ep);
84 return NULL;
85 }
86
87 ohci_ep->td = malloc32(sizeof(td_t));
88 if (ohci_ep->td == NULL) {
89 free32(ohci_ep->ed);
90 free(ohci_ep);
91 return NULL;
92 }
93
94 link_initialize(&ohci_ep->link);
95 return EOK;
96}
97
98/** Disposes hcd endpoint structure
99 *
100 * @param[in] hcd driver using this instance.
101 * @param[in] ep endpoint structure.
102 */
103static void ohci_endpoint_destroy(endpoint_t *ep)
104{
105 assert(ep);
106 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
107
108 free32(instance->ed);
109 free32(instance->td);
110 free(instance);
111}
112
113
114static int ohci_register_ep(bus_t *bus_base, endpoint_t *ep)
115{
116 ohci_bus_t *bus = (ohci_bus_t *) bus_base;
117 ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
118
119 const int err = bus->parent_ops.register_endpoint(bus_base, ep);
120 if (err)
121 return err;
122
123 ed_init(ohci_ep->ed, ep, ohci_ep->td);
124 hc_enqueue_endpoint(bus->hc, ep);
125
126 return EOK;
127}
128
129static int ohci_release_ep(bus_t *bus_base, endpoint_t *ep)
130{
131 ohci_bus_t *bus = (ohci_bus_t *) bus_base;
132 assert(bus);
133 assert(ep);
134
135 const int err = bus->parent_ops.release_endpoint(bus_base, ep);
136 if (err)
137 return err;
138
139 hc_dequeue_endpoint(bus->hc, ep);
140 return EOK;
141
142}
143
144int ohci_bus_init(ohci_bus_t *bus, hc_t *hc)
145{
146 assert(hc);
147 assert(bus);
148
149 usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
150
151 bus_ops_t *ops = &bus->base.base.ops;
152 bus->parent_ops = *ops;
153 ops->create_endpoint = ohci_endpoint_create;
154 ops->destroy_endpoint = ohci_endpoint_destroy;
155 ops->endpoint_set_toggle = ohci_ep_toggle_set;
156 ops->endpoint_get_toggle = ohci_ep_toggle_get;
157
158 ops->register_endpoint = ohci_register_ep;
159 ops->release_endpoint = ohci_release_ep;
160
161 return EOK;
162}
163
164/**
165 * @}
166 */
Note: See TracBrowser for help on using the repository browser.