source: mainline/uspace/drv/uhci-rhd/main.c@ cd1e6b62

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cd1e6b62 was fbefd0e, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

USB drivers less verbose on info level

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky, 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 initialization routines
33 */
34#include <ddf/driver.h>
35#include <devman.h>
36#include <device/hw_res.h>
37#include <errno.h>
38#include <str_error.h>
39#include <usb_iface.h>
40#include <usb/ddfiface.h>
41#include <usb/debug.h>
42
43#include "root_hub.h"
44
45#define NAME "uhci-rhd"
46static int hc_get_my_registers(ddf_dev_t *dev,
47 uintptr_t *io_reg_address, size_t *io_reg_size);
48#if 0
49/*----------------------------------------------------------------------------*/
50static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
51{
52 assert(fun);
53 assert(fun->driver_data);
54 assert(handle);
55
56 *handle = ((uhci_root_hub_t*)fun->driver_data)->hc_handle;
57
58 return EOK;
59}
60/*----------------------------------------------------------------------------*/
61static usb_iface_t uhci_rh_usb_iface = {
62 .get_hc_handle = usb_iface_get_hc_handle,
63 .get_address = usb_iface_get_address_hub_impl
64};
65/*----------------------------------------------------------------------------*/
66static ddf_dev_ops_t uhci_rh_ops = {
67 .interfaces[USB_DEV_IFACE] = &uhci_rh_usb_iface,
68};
69#endif
70/*----------------------------------------------------------------------------*/
71/** Initialize a new ddf driver instance of UHCI root hub.
72 *
73 * @param[in] device DDF instance of the device to initialize.
74 * @return Error code.
75 */
76static int uhci_rh_add_device(ddf_dev_t *device)
77{
78 if (!device)
79 return ENOTSUP;
80
81 usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle);
82
83 //device->ops = &uhci_rh_ops;
84 uintptr_t io_regs = 0;
85 size_t io_size = 0;
86
87 int ret = hc_get_my_registers(device, &io_regs, &io_size);
88 if (ret != EOK) {
89 usb_log_error("Failed to get registers from parent HC: %s.\n",
90 str_error(ret));
91 }
92 usb_log_debug("I/O regs at %#X (size %zu).\n", io_regs, io_size);
93
94 uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t));
95 if (!rh) {
96 usb_log_error("Failed to allocate driver instance.\n");
97 return ENOMEM;
98 }
99
100 ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
101 if (ret != EOK) {
102 usb_log_error("Failed to initialize driver instance: %s.\n",
103 str_error(ret));
104 free(rh);
105 return ret;
106 }
107
108 device->driver_data = rh;
109 usb_log_info("Controlling root hub `%s' (%llu).\n",
110 device->name, device->handle);
111 return EOK;
112}
113/*----------------------------------------------------------------------------*/
114static driver_ops_t uhci_rh_driver_ops = {
115 .add_device = uhci_rh_add_device,
116};
117/*----------------------------------------------------------------------------*/
118static driver_t uhci_rh_driver = {
119 .name = NAME,
120 .driver_ops = &uhci_rh_driver_ops
121};
122/*----------------------------------------------------------------------------*/
123/** Initialize global driver structures (NONE).
124 *
125 * @param[in] argc Nmber of arguments in argv vector (ignored).
126 * @param[in] argv Cmdline argument vector (ignored).
127 * @return Error code.
128 *
129 * Driver debug level is set here.
130 */
131int main(int argc, char *argv[])
132{
133 printf(NAME ": HelenOS UHCI root hub driver.\n");
134
135 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
136
137 return ddf_driver_main(&uhci_rh_driver);
138}
139/*----------------------------------------------------------------------------*/
140/** Get address of I/O registers.
141 *
142 * @param[in] dev Device asking for the addresses.
143 * @param[out] io_reg_address Base address of the memory range.
144 * @param[out] io_reg_size Size of the memory range.
145 * @return Error code.
146 */
147int hc_get_my_registers(
148 ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)
149{
150 assert(dev != NULL);
151
152 int parent_phone = devman_parent_device_connect(dev->handle,
153 IPC_FLAG_BLOCKING);
154 if (parent_phone < 0) {
155 return parent_phone;
156 }
157
158 int rc;
159
160 hw_resource_list_t hw_resources;
161 rc = hw_res_get_resource_list(parent_phone, &hw_resources);
162 if (rc != EOK) {
163 goto leave;
164 }
165
166 uintptr_t io_address = 0;
167 size_t io_size = 0;
168 bool io_found = false;
169
170 size_t i;
171 for (i = 0; i < hw_resources.count; i++) {
172 hw_resource_t *res = &hw_resources.resources[i];
173 switch (res->type)
174 {
175 case IO_RANGE:
176 io_address = (uintptr_t) res->res.io_range.address;
177 io_size = res->res.io_range.size;
178 io_found = true;
179
180 default:
181 break;
182 }
183 }
184
185 if (!io_found) {
186 rc = ENOENT;
187 goto leave;
188 }
189
190 if (io_reg_address != NULL) {
191 *io_reg_address = io_address;
192 }
193 if (io_reg_size != NULL) {
194 *io_reg_size = io_size;
195 }
196 rc = EOK;
197
198leave:
199 async_hangup(parent_phone);
200 return rc;
201}
202/**
203 * @}
204 */
Note: See TracBrowser for help on using the repository browser.