source: mainline/uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c@ dd7078c

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

ohci: Add additional checks and a TODO

  • Property mode set to 100644
File size: 3.4 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/** @addtogroup drvusbohci
29 * @{
30 */
31/** @file
32 * @brief OHCI driver
33 */
34#include "endpoint_descriptor.h"
35#include "macros.h"
36
37/** USB direction to OHCI values translation table. */
38static const uint32_t dir[] = {
39 [USB_DIRECTION_IN] = ED_STATUS_D_IN,
40 [USB_DIRECTION_OUT] = ED_STATUS_D_OUT,
41 [USB_DIRECTION_BOTH] = ED_STATUS_D_TD,
42};
43
44/**
45 * Initialize ED.
46 *
47 * @param instance ED structure to initialize.
48 * @param ep Driver endpoint to use.
49 * @param td TD to put in the list.
50 *
51 * If @param ep is NULL, dummy ED is initalized with only skip flag set.
52 */
53void ed_init(ed_t *instance, const endpoint_t *ep, const td_t *td)
54{
55 assert(instance);
56 memset(instance, 0, sizeof(ed_t));
57
58 if (ep == NULL) {
59 /* Mark as dead, used for dummy EDs at the beginning of
60 * endpoint lists. */
61 OHCI_MEM32_WR(instance->status, ED_STATUS_K_FLAG);
62 return;
63 }
64 /* Non-dummy ED must have corresponding EP and TD assigned */
65 assert(td);
66 assert(ep);
67 assert(ep->direction < ARRAY_SIZE(dir));
68
69 /* Status: address, endpoint nr, direction mask and max packet size. */
70 OHCI_MEM32_WR(instance->status,
71 ((ep->address & ED_STATUS_FA_MASK) << ED_STATUS_FA_SHIFT)
72 | ((ep->endpoint & ED_STATUS_EN_MASK) << ED_STATUS_EN_SHIFT)
73 | ((dir[ep->direction] & ED_STATUS_D_MASK) << ED_STATUS_D_SHIFT)
74 | ((ep->max_packet_size & ED_STATUS_MPS_MASK)
75 << ED_STATUS_MPS_SHIFT));
76
77 /* Low speed flag */
78 if (ep->speed == USB_SPEED_LOW)
79 OHCI_MEM32_SET(instance->status, ED_STATUS_S_FLAG);
80
81 /* Isochronous format flag */
82 // TODO: We need iTD instead of TD for iso transfers
83 if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)
84 OHCI_MEM32_SET(instance->status, ED_STATUS_F_FLAG);
85
86 /* Set TD to the list */
87 const uintptr_t pa = addr_to_phys(td);
88 OHCI_MEM32_WR(instance->td_head, pa & ED_TDHEAD_PTR_MASK);
89 OHCI_MEM32_WR(instance->td_tail, pa & ED_TDTAIL_PTR_MASK);
90
91 /* Set toggle bit */
92 if (ep->toggle)
93 OHCI_MEM32_SET(instance->td_head, ED_TDHEAD_TOGGLE_CARRY);
94
95}
96/**
97 * @}
98 */
Note: See TracBrowser for help on using the repository browser.