| 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 | */
|
|---|
| 43 | static 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 | */
|
|---|
| 56 | static 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 | /** Creates new hcd endpoint representation.
|
|---|
| 65 | *
|
|---|
| 66 | * @param[in] ep USBD endpoint structure
|
|---|
| 67 | * @return Error code.
|
|---|
| 68 | */
|
|---|
| 69 | int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
|
|---|
| 70 | {
|
|---|
| 71 | assert(ep);
|
|---|
| 72 | ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
|
|---|
| 73 | if (ohci_ep == NULL)
|
|---|
| 74 | return ENOMEM;
|
|---|
| 75 |
|
|---|
| 76 | ohci_ep->ed = malloc32(sizeof(ed_t));
|
|---|
| 77 | if (ohci_ep->ed == NULL) {
|
|---|
| 78 | free(ohci_ep);
|
|---|
| 79 | return ENOMEM;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | ohci_ep->td = malloc32(sizeof(td_t));
|
|---|
| 83 | if (ohci_ep->td == NULL) {
|
|---|
| 84 | free32(ohci_ep->ed);
|
|---|
| 85 | free(ohci_ep);
|
|---|
| 86 | return ENOMEM;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | ed_init(ohci_ep->ed, ep, ohci_ep->td);
|
|---|
| 90 | endpoint_set_hc_data(
|
|---|
| 91 | ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set);
|
|---|
| 92 | hc_enqueue_endpoint(hcd->private_data, ep);
|
|---|
| 93 | return EOK;
|
|---|
| 94 | }
|
|---|
| 95 | /*----------------------------------------------------------------------------*/
|
|---|
| 96 | /** Disposes hcd endpoint structure
|
|---|
| 97 | *
|
|---|
| 98 | * @param[in] hcd driver using this instance.
|
|---|
| 99 | * @param[in] ep endpoint structure.
|
|---|
| 100 | */
|
|---|
| 101 | void ohci_endpoint_fini(hcd_t *hcd, endpoint_t *ep)
|
|---|
| 102 | {
|
|---|
| 103 | assert(hcd);
|
|---|
| 104 | assert(ep);
|
|---|
| 105 | ohci_endpoint_t *instance = ohci_endpoint_get(ep);
|
|---|
| 106 | hc_dequeue_endpoint(hcd->private_data, ep);
|
|---|
| 107 | if (instance) {
|
|---|
| 108 | free32(instance->ed);
|
|---|
| 109 | free32(instance->td);
|
|---|
| 110 | free(instance);
|
|---|
| 111 | }
|
|---|
| 112 | endpoint_clear_hc_data(ep);
|
|---|
| 113 | }
|
|---|
| 114 | /**
|
|---|
| 115 | * @}
|
|---|
| 116 | */
|
|---|