source: mainline/uspace/drv/bus/usb/ohci/ohci_endpoint.c@ 25a179e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 25a179e was 58563585, checked in by Martin Decky <martin@…>, 9 years ago

code review and cstyle cleanup (no change in functionality)

  • Property mode set to 100644
File size: 3.4 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
40#include "ohci_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 */
48static void ohci_ep_toggle_set(void *ohci_ep, int toggle)
49{
50 ohci_endpoint_t *instance = ohci_ep;
51 assert(instance);
52 assert(instance->ed);
53 ed_toggle_set(instance->ed, toggle);
54}
55
56/** Callback to get value of toggle bit.
57 *
58 * @param[in] hcd_ep hcd endpoint structure
59 * @return Current value of toggle bit.
60 */
61static int ohci_ep_toggle_get(void *ohci_ep)
62{
63 ohci_endpoint_t *instance = ohci_ep;
64 assert(instance);
65 assert(instance->ed);
66 return ed_toggle_get(instance->ed);
67}
68
69/** Creates new hcd endpoint representation.
70 *
71 * @param[in] ep USBD endpoint structure
72 * @return Error code.
73 */
74int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
75{
76 assert(ep);
77 ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
78 if (ohci_ep == NULL)
79 return ENOMEM;
80
81 ohci_ep->ed = malloc32(sizeof(ed_t));
82 if (ohci_ep->ed == NULL) {
83 free(ohci_ep);
84 return ENOMEM;
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 ENOMEM;
92 }
93
94 link_initialize(&ohci_ep->link);
95 ed_init(ohci_ep->ed, ep, ohci_ep->td);
96 endpoint_set_hc_data(
97 ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set);
98 hc_enqueue_endpoint(hcd_get_driver_data(hcd), ep);
99 return EOK;
100}
101
102/** Disposes hcd endpoint structure
103 *
104 * @param[in] hcd driver using this instance.
105 * @param[in] ep endpoint structure.
106 */
107void ohci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
108{
109 assert(hcd);
110 assert(ep);
111 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
112 hc_dequeue_endpoint(hcd_get_driver_data(hcd), ep);
113 endpoint_clear_hc_data(ep);
114 if (instance) {
115 free32(instance->ed);
116 free32(instance->td);
117 free(instance);
118 }
119}
120
121/**
122 * @}
123 */
Note: See TracBrowser for help on using the repository browser.