source: mainline/uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c

Last change on this file was 09ab0a9a, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix vertical spacing with new Ccheck revision.

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