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

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

usbhost: refactoring

This commit moves interrupt, status and schedule to bus
operations. Then the purpose of hcd_t is better defined, and split into
hc_driver_t and hc_device_t. hc_driver_t is used to wrap driver
implementation by the library (similar to how usb_driver_t is used to
wrap usb device drivers). hc_device_t is used as a parent for hc_t
inside drivers, and is allocated inside the DDF device node.

To support these changes, some local identifiers were renamed, some
functions were moved and/or renamed and their arguments changed. The
most notable one being hcd_send_batch → bus_device_send_batch.

  • Property mode set to 100644
File size: 4.9 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(device_t *dev, const usb_endpoint_desc_t *desc)
75{
76 assert(dev);
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, dev, desc);
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(endpoint_t *ep)
118{
119 bus_t *bus_base = endpoint_get_bus(ep);
120 ohci_bus_t *bus = (ohci_bus_t *) bus_base;
121 ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep);
122
123 const int err = usb2_bus_ops.endpoint_register(ep);
124 if (err)
125 return err;
126
127 ed_init(ohci_ep->ed, ep, ohci_ep->td);
128 hc_enqueue_endpoint(bus->hc, ep);
129
130 return EOK;
131}
132
133static int ohci_unregister_ep(endpoint_t *ep)
134{
135 ohci_bus_t *bus = (ohci_bus_t *) endpoint_get_bus(ep);
136 assert(ep);
137
138 const int err = usb2_bus_ops.endpoint_unregister(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_create_batch(endpoint_t *ep)
147{
148 ohci_transfer_batch_t *batch = ohci_transfer_batch_create(ep);
149 return &batch->base;
150}
151
152static void ohci_destroy_batch(usb_transfer_batch_t *batch)
153{
154 ohci_transfer_batch_destroy(ohci_transfer_batch_get(batch));
155}
156
157static const bus_ops_t ohci_bus_ops = {
158 .parent = &usb2_bus_ops,
159
160 .interrupt = ohci_hc_interrupt,
161 .status = ohci_hc_status,
162
163 .endpoint_destroy = ohci_endpoint_destroy,
164 .endpoint_create = ohci_endpoint_create,
165 .endpoint_register = ohci_register_ep,
166 .endpoint_unregister = ohci_unregister_ep,
167 .endpoint_count_bw = bandwidth_count_usb11,
168 .endpoint_set_toggle = ohci_ep_toggle_set,
169 .endpoint_get_toggle = ohci_ep_toggle_get,
170 .batch_create = ohci_create_batch,
171 .batch_destroy = ohci_destroy_batch,
172 .batch_schedule = ohci_hc_schedule,
173};
174
175
176int ohci_bus_init(ohci_bus_t *bus, hc_t *hc)
177{
178 assert(hc);
179 assert(bus);
180
181 usb2_bus_t *usb2_bus = (usb2_bus_t *) bus;
182 bus_t *bus_base = (bus_t *) bus;
183
184 usb2_bus_init(usb2_bus, BANDWIDTH_AVAILABLE_USB11);
185 bus_base->ops = &ohci_bus_ops;
186
187 bus->hc = hc;
188
189 return EOK;
190}
191
192/**
193 * @}
194 */
Note: See TracBrowser for help on using the repository browser.