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

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

ohci: Sanitize includes.

Include what you use.

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