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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8d2dd7f2 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
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 */
[58563585]28
[2759c52]29/** @addtogroup drvusbohci
30 * @{
31 */
32/** @file
33 * @brief OHCI driver
34 */
[0d4b110]35
36#include <assert.h>
37#include <stdlib.h>
[2dbfe44]38#include <usb/host/utils/malloc32.h>
[0d4b110]39
[e20eaed]40#include "ohci_endpoint.h"
[620c710]41#include "hc.h"
[2759c52]42
[02cacce]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 */
[e20eaed]48static void ohci_ep_toggle_set(void *ohci_ep, int toggle)
[545764b]49{
[e20eaed]50 ohci_endpoint_t *instance = ohci_ep;
[545764b]51 assert(instance);
52 assert(instance->ed);
53 ed_toggle_set(instance->ed, toggle);
54}
[76fbd9a]55
[02cacce]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 */
[e20eaed]61static int ohci_ep_toggle_get(void *ohci_ep)
[545764b]62{
[e20eaed]63 ohci_endpoint_t *instance = ohci_ep;
[545764b]64 assert(instance);
65 assert(instance->ed);
66 return ed_toggle_get(instance->ed);
67}
[76fbd9a]68
[02cacce]69/** Creates new hcd endpoint representation.
70 *
71 * @param[in] ep USBD endpoint structure
[57e06ef]72 * @return Error code.
[02cacce]73 */
[620c710]74int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
[2759c52]75{
76 assert(ep);
[e20eaed]77 ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
78 if (ohci_ep == NULL)
[b02308e]79 return ENOMEM;
[2759c52]80
[e20eaed]81 ohci_ep->ed = malloc32(sizeof(ed_t));
82 if (ohci_ep->ed == NULL) {
83 free(ohci_ep);
[b02308e]84 return ENOMEM;
[2759c52]85 }
86
[e20eaed]87 ohci_ep->td = malloc32(sizeof(td_t));
88 if (ohci_ep->td == NULL) {
89 free32(ohci_ep->ed);
90 free(ohci_ep);
[b02308e]91 return ENOMEM;
[2759c52]92 }
93
[a2e8c44]94 link_initialize(&ohci_ep->link);
[9515f674]95 ed_init(ohci_ep->ed, ep, ohci_ep->td);
[32e093e]96 endpoint_set_hc_data(
[48ae3ef]97 ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set);
[b5f813c]98 hc_enqueue_endpoint(hcd_get_driver_data(hcd), ep);
[b02308e]99 return EOK;
[2759c52]100}
[76fbd9a]101
[48ae3ef]102/** Disposes hcd endpoint structure
103 *
[57e06ef]104 * @param[in] hcd driver using this instance.
105 * @param[in] ep endpoint structure.
[48ae3ef]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);
[b5f813c]112 hc_dequeue_endpoint(hcd_get_driver_data(hcd), ep);
113 endpoint_clear_hc_data(ep);
[48ae3ef]114 if (instance) {
115 free32(instance->ed);
116 free32(instance->td);
117 free(instance);
118 }
119}
[58563585]120
[2759c52]121/**
122 * @}
123 */
Note: See TracBrowser for help on using the repository browser.