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

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

Get register address for uchi-rhd from uhci-hcd

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[816175a2]1/*
[c56dbe0]2 * Copyright (c) 2011 Vojtech Horky, Jan Vesely
[816175a2]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 */
[c56dbe0]28/** @addtogroup usb
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
[eb1a2f4]34#include <ddf/driver.h>
[6cbe7dad]35#include <devman.h>
36#include <device/hw_res.h>
[c56dbe0]37#include <usb_iface.h>
[357a302]38#include <usb/ddfiface.h>
[c56dbe0]39
[1256a0a]40#include <errno.h>
[7ce0fe3]41
42#include <usb/debug.h>
[1256a0a]43
44#include "root_hub.h"
45
[7ce0fe3]46#define NAME "uhci-rhd"
[6cbe7dad]47static int hc_get_my_registers(ddf_dev_t *dev,
48 uintptr_t *io_reg_address, size_t *io_reg_size);
[7ce0fe3]49
[eb1a2f4]50static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
[1256a0a]51{
[eb1a2f4]52 assert(fun);
53 assert(fun->driver_data);
[7ce0fe3]54 assert(handle);
55
[eb1a2f4]56 *handle = ((uhci_root_hub_t*)fun->driver_data)->hc_handle;
[816175a2]57
[1256a0a]58 return EOK;
59}
[816175a2]60
[1256a0a]61static usb_iface_t uhci_rh_usb_iface = {
[357a302]62 .get_hc_handle = usb_iface_get_hc_handle,
63 .get_address = usb_iface_get_address_hub_impl
[1256a0a]64};
[245b56b5]65
[eb1a2f4]66static ddf_dev_ops_t uhci_rh_ops = {
[1256a0a]67 .interfaces[USB_DEV_IFACE] = &uhci_rh_usb_iface,
[816175a2]68};
69
[eb1a2f4]70static int uhci_rh_add_device(ddf_dev_t *device)
[1256a0a]71{
72 if (!device)
73 return ENOTSUP;
[816175a2]74
[7ce0fe3]75 usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle);
[eb1a2f4]76
77 //device->ops = &uhci_rh_ops;
78 (void) uhci_rh_ops;
[816175a2]79
[1256a0a]80 uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t));
81 if (!rh) {
[7ce0fe3]82 usb_log_error("Failed to allocate memory for driver instance.\n");
[1256a0a]83 return ENOMEM;
84 }
[7ce0fe3]85
[6cbe7dad]86 uintptr_t io_regs = 0;
87 size_t io_size = 0;
88
89 int ret = hc_get_my_registers(device, &io_regs, &io_size);
90 assert(ret == EOK);
91
92 /* TODO: verify values from hc */
93 usb_log_info("I/O regs at 0x%X (size %zu).\n", io_regs, io_size);
94 ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
[1256a0a]95 if (ret != EOK) {
[7ce0fe3]96 usb_log_error("Failed(%d) to initialize driver instance.\n", ret);
[1256a0a]97 free(rh);
98 return ret;
99 }
[7ce0fe3]100
[1256a0a]101 device->driver_data = rh;
[5944244]102 usb_log_info("Sucessfully initialized driver instance for device:%d.\n",
[7ce0fe3]103 device->handle);
[1256a0a]104 return EOK;
105}
[816175a2]106
[1256a0a]107static driver_ops_t uhci_rh_driver_ops = {
108 .add_device = uhci_rh_add_device,
109};
[816175a2]110
[1256a0a]111static driver_t uhci_rh_driver = {
112 .name = NAME,
113 .driver_ops = &uhci_rh_driver_ops
114};
[6cbe7dad]115/*----------------------------------------------------------------------------*/
[1256a0a]116int main(int argc, char *argv[])
117{
[eb1a2f4]118 usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
119 return ddf_driver_main(&uhci_rh_driver);
[1256a0a]120}
[6cbe7dad]121/*----------------------------------------------------------------------------*/
122int hc_get_my_registers(ddf_dev_t *dev,
123 uintptr_t *io_reg_address, size_t *io_reg_size)
124{
125 assert(dev != NULL);
126
127 int parent_phone = devman_parent_device_connect(dev->handle,
128 IPC_FLAG_BLOCKING);
129 if (parent_phone < 0) {
130 return parent_phone;
131 }
132
133 int rc;
134
135 hw_resource_list_t hw_resources;
136 rc = hw_res_get_resource_list(parent_phone, &hw_resources);
137 if (rc != EOK) {
138 goto leave;
139 }
140
141 uintptr_t io_address = 0;
142 size_t io_size = 0;
143 bool io_found = false;
144
145 size_t i;
146 for (i = 0; i < hw_resources.count; i++) {
147 hw_resource_t *res = &hw_resources.resources[i];
148 switch (res->type) {
149 case IO_RANGE:
150 io_address = (uintptr_t)
151 res->res.io_range.address;
152 io_size = res->res.io_range.size;
153 io_found = true;
154 break;
155 default:
156 break;
157 }
158 }
159
160 if (!io_found) {
161 rc = ENOENT;
162 goto leave;
163 }
164
165 if (io_reg_address != NULL) {
166 *io_reg_address = io_address;
167 }
168 if (io_reg_size != NULL) {
169 *io_reg_size = io_size;
170 }
171 rc = EOK;
172leave:
173 async_hangup(parent_phone);
174
175 return rc;
176}
[c56dbe0]177/**
178 * @}
179 */
Note: See TracBrowser for help on using the repository browser.