source: mainline/uspace/drv/bus/usb/uhcirh/root_hub.c@ 208b5f5

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 208b5f5 was 7de1988c, checked in by Jakub Jermar <jakub@…>, 12 years ago

Adapt drivers using parsed HW resources to use the new interface.

  • Property mode set to 100644
File size: 2.9 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 drvusbuhcirh
29 * @{
30 */
31/** @file
32 * @brief UHCI root hub driver
33 */
34#include <errno.h>
35#include <str_error.h>
36#include <ddi.h>
37#include <usb/debug.h>
38#include <device/hw_res_parsed.h>
39
40#include "root_hub.h"
41
42/** Initialize UHCI root hub instance.
43 *
44 * @param[in] instance Driver memory structure to use.
45 * @param[in] io_regs Range of I/O registers.
46 * @param[in] rh Pointer to DDF instance of the root hub driver.
47 * @return Error code.
48 */
49int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *io_regs,
50 ddf_dev_t *rh)
51{
52 port_status_t *regs;
53
54 assert(instance);
55 assert(rh);
56
57 /* Allow access to root hub port registers */
58 assert(sizeof(*regs) * UHCI_ROOT_HUB_PORT_COUNT <= io_regs->size);
59
60 int ret = pio_enable_range(io_regs, (void **) &regs);
61 if (ret < 0) {
62 usb_log_error(
63 "Failed(%d) to gain access to port registers at %p: %s.\n",
64 ret, RNGABSPTR(*io_regs), str_error(ret));
65 return ret;
66 }
67
68 /* Initialize root hub ports */
69 unsigned i = 0;
70 for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
71 ret = uhci_port_init(
72 &instance->ports[i], &regs[i], i, ROOT_HUB_WAIT_USEC, rh);
73 if (ret != EOK) {
74 unsigned j = 0;
75 for (;j < i; ++j)
76 uhci_port_fini(&instance->ports[j]);
77 return ret;
78 }
79 }
80
81 return EOK;
82}
83
84/** Cleanup UHCI root hub instance.
85 *
86 * @param[in] instance Root hub structure to use.
87 */
88void uhci_root_hub_fini(uhci_root_hub_t* instance)
89{
90 assert(instance);
91 unsigned i = 0;
92 for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
93 uhci_port_fini(&instance->ports[i]);
94 }
95}
96
97/**
98 * @}
99 */
Note: See TracBrowser for help on using the repository browser.