source: mainline/uspace/drv/bus/usb/ohci/ohci_endpoint.c@ 4e732f1a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4e732f1a was 0d4b110, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

ohci: Sanitize includes.

Include what you use.

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