[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 | */
|
---|
| 34 | #include "utils/malloc32.h"
|
---|
[e20eaed] | 35 | #include "ohci_endpoint.h"
|
---|
[620c710] | 36 | #include "hc.h"
|
---|
[2759c52] | 37 |
|
---|
[02cacce] | 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 | */
|
---|
[e20eaed] | 43 | static void ohci_ep_toggle_set(void *ohci_ep, int toggle)
|
---|
[545764b] | 44 | {
|
---|
[e20eaed] | 45 | ohci_endpoint_t *instance = ohci_ep;
|
---|
[545764b] | 46 | assert(instance);
|
---|
| 47 | assert(instance->ed);
|
---|
| 48 | ed_toggle_set(instance->ed, toggle);
|
---|
| 49 | }
|
---|
[02cacce] | 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 | */
|
---|
[e20eaed] | 56 | static int ohci_ep_toggle_get(void *ohci_ep)
|
---|
[545764b] | 57 | {
|
---|
[e20eaed] | 58 | ohci_endpoint_t *instance = ohci_ep;
|
---|
[545764b] | 59 | assert(instance);
|
---|
| 60 | assert(instance->ed);
|
---|
| 61 | return ed_toggle_get(instance->ed);
|
---|
| 62 | }
|
---|
[02cacce] | 63 | /*----------------------------------------------------------------------------*/
|
---|
[b02308e] | 64 | /** Disposes hcd endpoint structure
|
---|
| 65 | *
|
---|
| 66 | * @param[in] hcd_ep endpoint structure
|
---|
| 67 | */
|
---|
[620c710] | 68 | static void ohci_endpoint_fini(endpoint_t *ep)
|
---|
[b02308e] | 69 | {
|
---|
[620c710] | 70 | ohci_endpoint_t *instance = ep->hc_data.data;
|
---|
| 71 | hc_dequeue_endpoint(instance->hcd->private_data, ep);
|
---|
| 72 | if (instance) {
|
---|
[b02308e] | 73 | free32(instance->ed);
|
---|
| 74 | free32(instance->td);
|
---|
| 75 | free(instance);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | /*----------------------------------------------------------------------------*/
|
---|
[02cacce] | 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 | */
|
---|
[620c710] | 84 | int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep)
|
---|
[2759c52] | 85 | {
|
---|
| 86 | assert(ep);
|
---|
[e20eaed] | 87 | ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
|
---|
| 88 | if (ohci_ep == NULL)
|
---|
[b02308e] | 89 | return ENOMEM;
|
---|
[2759c52] | 90 |
|
---|
[e20eaed] | 91 | ohci_ep->ed = malloc32(sizeof(ed_t));
|
---|
| 92 | if (ohci_ep->ed == NULL) {
|
---|
| 93 | free(ohci_ep);
|
---|
[b02308e] | 94 | return ENOMEM;
|
---|
[2759c52] | 95 | }
|
---|
| 96 |
|
---|
[e20eaed] | 97 | ohci_ep->td = malloc32(sizeof(td_t));
|
---|
| 98 | if (ohci_ep->td == NULL) {
|
---|
| 99 | free32(ohci_ep->ed);
|
---|
| 100 | free(ohci_ep);
|
---|
[b02308e] | 101 | return ENOMEM;
|
---|
[2759c52] | 102 | }
|
---|
| 103 |
|
---|
[e20eaed] | 104 | ed_init(ohci_ep->ed, ep);
|
---|
| 105 | ed_set_td(ohci_ep->ed, ohci_ep->td);
|
---|
[32e093e] | 106 | endpoint_set_hc_data(
|
---|
[620c710] | 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);
|
---|
[b02308e] | 110 | return EOK;
|
---|
[2759c52] | 111 | }
|
---|
| 112 | /**
|
---|
| 113 | * @}
|
---|
| 114 | */
|
---|