source: mainline/uspace/drv/bus/usb/ehci/ehci_endpoint.c@ 6de4b4a1

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

ehci/ep: Consolidate debug messages

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2014 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 drvusbehci
29 * @{
30 */
31/** @file
32 * @brief EHCI driver
33 */
34
35#include <assert.h>
36#include <stdlib.h>
37#include <usb/debug.h>
38#include <usb/host/utils/malloc32.h>
39
40#include "ehci_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 ehci_ep_toggle_set(void *ehci_ep, int toggle)
49{
50 ehci_endpoint_t *instance = ehci_ep;
51 assert(instance);
52 assert(instance->qh);
53 if (qh_toggle_from_td(instance->qh))
54 usb_log_warning("EP(%p): Setting toggle bit for transfer "
55 "directed EP", instance);
56 qh_toggle_set(instance->qh, toggle);
57}
58
59/** Callback to get value of toggle bit.
60 *
61 * @param[in] hcd_ep hcd endpoint structure
62 * @return Current value of toggle bit.
63 */
64static int ehci_ep_toggle_get(void *ehci_ep)
65{
66 ehci_endpoint_t *instance = ehci_ep;
67 assert(instance);
68 assert(instance->qh);
69 if (qh_toggle_from_td(instance->qh))
70 usb_log_warning("EP(%p): Reading useless toggle bit", instance);
71 return qh_toggle_get(instance->qh);
72}
73
74/** Creates new hcd endpoint representation.
75 *
76 * @param[in] ep USBD endpoint structure
77 * @return Error code.
78 */
79int ehci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
80{
81 assert(ep);
82 ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t));
83 if (ehci_ep == NULL)
84 return ENOMEM;
85
86 ehci_ep->qh = malloc32(sizeof(qh_t));
87 if (ehci_ep->qh == NULL) {
88 free(ehci_ep);
89 return ENOMEM;
90 }
91
92 usb_log_debug2("EP(%p): Creating for %p", ehci_ep, ep);
93 link_initialize(&ehci_ep->link);
94 qh_init(ehci_ep->qh, ep);
95 endpoint_set_hc_data(
96 ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set);
97 hc_enqueue_endpoint(hcd->driver.data, ep);
98 return EOK;
99}
100
101/** Disposes hcd endpoint structure
102 *
103 * @param[in] hcd driver using this instance.
104 * @param[in] ep endpoint structure.
105 */
106void ehci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
107{
108 assert(hcd);
109 assert(ep);
110 ehci_endpoint_t *instance = ehci_endpoint_get(ep);
111 hc_dequeue_endpoint(hcd->driver.data, ep);
112 endpoint_clear_hc_data(ep);
113 usb_log_debug2("EP(%p): Destroying for %p", instance, ep);
114 if (instance) {
115 free32(instance->qh);
116 free(instance);
117 }
118}
119/**
120 * @}
121 */
122
Note: See TracBrowser for help on using the repository browser.