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

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

libusbhost bus: endpoint→device is now managed by bus implementation

That allows xhci to better isolate responsibilities.

  • Property mode set to 100644
File size: 4.7 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 "ohci_batch.h"
43#include "hc.h"
44
45/** Callback to set toggle on ED.
46 *
47 * @param[in] hcd_ep hcd endpoint structure
48 * @param[in] toggle new value of toggle bit
49 */
50static void ohci_ep_toggle_set(endpoint_t *ep, bool toggle)
51{
52 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
53 assert(instance);
54 assert(instance->ed);
55 ep->toggle = toggle;
56 ed_toggle_set(instance->ed, 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 */
64static bool ohci_ep_toggle_get(endpoint_t *ep)
65{
66 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
67 assert(instance);
68 assert(instance->ed);
69 return ed_toggle_get(instance->ed);
70}
71
72/** Creates new hcd endpoint representation.
73 */
74static endpoint_t *ohci_endpoint_create(bus_t *bus)
75{
76 assert(bus);
77
78 ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
79 if (ohci_ep == NULL)
80 return NULL;
81
82 endpoint_init(&ohci_ep->base, bus);
83
84 ohci_ep->ed = malloc32(sizeof(ed_t));
85 if (ohci_ep->ed == NULL) {
86 free(ohci_ep);
87 return NULL;
88 }
89
90 ohci_ep->td = malloc32(sizeof(td_t));
91 if (ohci_ep->td == NULL) {
92 free32(ohci_ep->ed);
93 free(ohci_ep);
94 return NULL;
95 }
96
97 link_initialize(&ohci_ep->link);
98 return &ohci_ep->base;
99}
100
101/** Disposes hcd endpoint structure
102 *
103 * @param[in] hcd driver using this instance.
104 * @param[in] ep endpoint structure.
105 */
106static void ohci_endpoint_destroy(endpoint_t *ep)
107{
108 assert(ep);
109 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
110
111 free32(instance->ed);
112 free32(instance->td);
113 free(instance);
114}
115
116
117static int ohci_register_ep(bus_t *bus_base, device_t *dev, endpoint_t *ep, const usb_endpoint_desc_t *desc)
118{
119 ohci_bus_t *bus = (ohci_bus_t *) bus_base;
120 ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
121
122 const int err = bus->parent_ops.register_endpoint(bus_base, dev, ep, desc);
123 if (err)
124 return err;
125
126 ed_init(ohci_ep->ed, ep, ohci_ep->td);
127 hc_enqueue_endpoint(bus->hc, ep);
128
129 return EOK;
130}
131
132static int ohci_unregister_ep(bus_t *bus_base, endpoint_t *ep)
133{
134 ohci_bus_t *bus = (ohci_bus_t *) bus_base;
135 assert(bus);
136 assert(ep);
137
138 const int err = bus->parent_ops.unregister_endpoint(bus_base, ep);
139 if (err)
140 return err;
141
142 hc_dequeue_endpoint(bus->hc, ep);
143 return EOK;
144}
145
146static usb_transfer_batch_t *ohci_bus_create_batch(bus_t *bus, endpoint_t *ep)
147{
148 ohci_transfer_batch_t *batch = ohci_transfer_batch_create(ep);
149 return &batch->base;
150}
151
152static void ohci_bus_destroy_batch(usb_transfer_batch_t *batch)
153{
154 ohci_transfer_batch_destroy(ohci_transfer_batch_get(batch));
155}
156
157int ohci_bus_init(ohci_bus_t *bus, hc_t *hc)
158{
159 assert(hc);
160 assert(bus);
161
162 usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
163
164 bus_ops_t *ops = &bus->base.base.ops;
165 bus->parent_ops = *ops;
166 ops->create_endpoint = ohci_endpoint_create;
167 ops->destroy_endpoint = ohci_endpoint_destroy;
168 ops->endpoint_set_toggle = ohci_ep_toggle_set;
169 ops->endpoint_get_toggle = ohci_ep_toggle_get;
170
171 ops->register_endpoint = ohci_register_ep;
172 ops->unregister_endpoint = ohci_unregister_ep;
173
174 ops->create_batch = ohci_bus_create_batch;
175 ops->destroy_batch = ohci_bus_destroy_batch;
176
177 bus->hc = hc;
178
179 return EOK;
180}
181
182/**
183 * @}
184 */
Note: See TracBrowser for help on using the repository browser.