| 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 |
|
|---|
| 35 | #include <assert.h>
|
|---|
| 36 | #include <mem.h>
|
|---|
| 37 |
|
|---|
| 38 | #include <usb/usb.h>
|
|---|
| 39 |
|
|---|
| 40 | #include "../utils/malloc32.h"
|
|---|
| 41 | #include "completion_codes.h"
|
|---|
| 42 | #include "mem_access.h"
|
|---|
| 43 | #include "transfer_descriptor.h"
|
|---|
| 44 |
|
|---|
| 45 | /** USB direction to OHCI TD values translation table */
|
|---|
| 46 | static const uint32_t dir[] = {
|
|---|
| 47 | [USB_DIRECTION_IN] = TD_STATUS_DP_IN,
|
|---|
| 48 | [USB_DIRECTION_OUT] = TD_STATUS_DP_OUT,
|
|---|
| 49 | [USB_DIRECTION_BOTH] = TD_STATUS_DP_SETUP,
|
|---|
| 50 | };
|
|---|
| 51 |
|
|---|
| 52 | /**
|
|---|
| 53 | * Initialize OHCI TD.
|
|---|
| 54 | * @param instance TD structure to initialize.
|
|---|
| 55 | * @param next Next TD in ED list.
|
|---|
| 56 | * @param direction Used to determine PID, BOTH means setup PID.
|
|---|
| 57 | * @param buffer Pointer to the first byte of transferred data.
|
|---|
| 58 | * @param size Size of the buffer.
|
|---|
| 59 | * @param toggle Toggle bit value, use 0/1 to set explicitly,
|
|---|
| 60 | * any other value means that ED toggle will be used.
|
|---|
| 61 | */
|
|---|
| 62 | void td_init(td_t *instance, const td_t *next,
|
|---|
| 63 | usb_direction_t direction, const void *buffer, size_t size, int toggle)
|
|---|
| 64 | {
|
|---|
| 65 | assert(instance);
|
|---|
| 66 | memset(instance, 0, sizeof(td_t));
|
|---|
| 67 | /* Set PID and Error code */
|
|---|
| 68 | OHCI_MEM32_WR(instance->status,
|
|---|
| 69 | ((dir[direction] & TD_STATUS_DP_MASK) << TD_STATUS_DP_SHIFT)
|
|---|
| 70 | | ((CC_NOACCESS2 & TD_STATUS_CC_MASK) << TD_STATUS_CC_SHIFT));
|
|---|
| 71 |
|
|---|
| 72 | if (toggle == 0 || toggle == 1) {
|
|---|
| 73 | /* Set explicit toggle bit */
|
|---|
| 74 | OHCI_MEM32_SET(instance->status, TD_STATUS_T_USE_TD_FLAG);
|
|---|
| 75 | OHCI_MEM32_SET(instance->status, toggle ? TD_STATUS_T_FLAG : 0);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | /* Alow less data on input. */
|
|---|
| 79 | if (dir == USB_DIRECTION_IN) {
|
|---|
| 80 | OHCI_MEM32_SET(instance->status, TD_STATUS_ROUND_FLAG);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | if (buffer != NULL) {
|
|---|
| 84 | assert(size != 0);
|
|---|
| 85 | OHCI_MEM32_WR(instance->cbp, addr_to_phys(buffer));
|
|---|
| 86 | OHCI_MEM32_WR(instance->be, addr_to_phys(buffer + size - 1));
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | OHCI_MEM32_WR(instance->next, addr_to_phys(next) & TD_NEXT_PTR_MASK);
|
|---|
| 90 |
|
|---|
| 91 | }
|
|---|
| 92 | /**
|
|---|
| 93 | * @}
|
|---|
| 94 | */
|
|---|
| 95 |
|
|---|