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

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

ohci: initialize endpoint link.

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[2759c52]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 */
[0d4b110]34
35#include <assert.h>
36#include <stdlib.h>
37
[2759c52]38#include "utils/malloc32.h"
[e20eaed]39#include "ohci_endpoint.h"
[620c710]40#include "hc.h"
[2759c52]41
[02cacce]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 */
[e20eaed]47static void ohci_ep_toggle_set(void *ohci_ep, int toggle)
[545764b]48{
[e20eaed]49 ohci_endpoint_t *instance = ohci_ep;
[545764b]50 assert(instance);
51 assert(instance->ed);
52 ed_toggle_set(instance->ed, toggle);
53}
[76fbd9a]54
[02cacce]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 */
[e20eaed]60static int ohci_ep_toggle_get(void *ohci_ep)
[545764b]61{
[e20eaed]62 ohci_endpoint_t *instance = ohci_ep;
[545764b]63 assert(instance);
64 assert(instance->ed);
65 return ed_toggle_get(instance->ed);
66}
[76fbd9a]67
[02cacce]68/** Creates new hcd endpoint representation.
69 *
70 * @param[in] ep USBD endpoint structure
[57e06ef]71 * @return Error code.
[02cacce]72 */
[620c710]73int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
[2759c52]74{
75 assert(ep);
[e20eaed]76 ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
77 if (ohci_ep == NULL)
[b02308e]78 return ENOMEM;
[2759c52]79
[e20eaed]80 ohci_ep->ed = malloc32(sizeof(ed_t));
81 if (ohci_ep->ed == NULL) {
82 free(ohci_ep);
[b02308e]83 return ENOMEM;
[2759c52]84 }
85
[e20eaed]86 ohci_ep->td = malloc32(sizeof(td_t));
87 if (ohci_ep->td == NULL) {
88 free32(ohci_ep->ed);
89 free(ohci_ep);
[b02308e]90 return ENOMEM;
[2759c52]91 }
92
[a2e8c44]93 link_initialize(&ohci_ep->link);
[9515f674]94 ed_init(ohci_ep->ed, ep, ohci_ep->td);
[32e093e]95 endpoint_set_hc_data(
[48ae3ef]96 ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set);
[9348862]97 hc_enqueue_endpoint(hcd->driver.data, ep);
[b02308e]98 return EOK;
[2759c52]99}
[76fbd9a]100
[48ae3ef]101/** Disposes hcd endpoint structure
102 *
[57e06ef]103 * @param[in] hcd driver using this instance.
104 * @param[in] ep endpoint structure.
[48ae3ef]105 */
106void ohci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
107{
108 assert(hcd);
109 assert(ep);
110 ohci_endpoint_t *instance = ohci_endpoint_get(ep);
[9348862]111 hc_dequeue_endpoint(hcd->driver.data, ep);
[48ae3ef]112 if (instance) {
113 free32(instance->ed);
114 free32(instance->td);
115 free(instance);
116 }
117 endpoint_clear_hc_data(ep);
118}
[2759c52]119/**
120 * @}
121 */
Note: See TracBrowser for help on using the repository browser.