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

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

libushost: promote endpoint data dtor to destruction hook

ohci: use new usb c driver architecture

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