source: mainline/uspace/drv/uhci-hcd/root_hub.c@ 6143ce3

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

Doxygen and other comments

  • Property mode set to 100644
File size: 5.3 KB
RevLine 
[c56dbe0]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 usb
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
[1256a0a]34#include <assert.h>
35#include <errno.h>
[4abc304]36#include <str_error.h>
[1256a0a]37#include <stdio.h>
[6cbe7dad]38#include <ops/hw_res.h>
39
[1256a0a]40#include <usb_iface.h>
[afcd86e]41#include <usb/debug.h>
42
[1256a0a]43#include "root_hub.h"
[eb1a2f4]44#include "uhci.h"
45
[6cbe7dad]46/*----------------------------------------------------------------------------*/
[a7e2f0d]47/** Gets handle of the respective hc (parent device).
48 *
49 * @param[in] root_hub_fun Root hub function seeking hc handle.
50 * @param[out] handle Place to write the handle.
51 * @return Error code.
52 */
53static int usb_iface_get_hc_handle_rh_impl(
54 ddf_fun_t *root_hub_fun, devman_handle_t *handle)
[eb1a2f4]55{
[a7e2f0d]56 /* TODO: Can't this use parent pointer? */
[eb1a2f4]57 ddf_fun_t *hc_fun = root_hub_fun->driver_data;
58 assert(hc_fun != NULL);
59
60 *handle = hc_fun->handle;
61
62 return EOK;
63}
[6cbe7dad]64/*----------------------------------------------------------------------------*/
[a7e2f0d]65/** Gets USB address of the calling device.
66 *
67 * @param[in] fun Root hub function.
68 * @param[in] handle Handle of the device seeking address.
69 * @param[out] address Place to store found address.
70 * @return Error code.
71 */
72static int usb_iface_get_address_rh_impl(
73 ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
[eb1a2f4]74{
[a7e2f0d]75 /* TODO: What does this do? Is it neccessary? Can't it use implemented
76 * hc function?*/
[eb1a2f4]77 assert(fun);
78 ddf_fun_t *hc_fun = fun->driver_data;
79 assert(hc_fun);
80 uhci_t *hc = fun_to_uhci(hc_fun);
81 assert(hc);
82
[a7e2f0d]83 usb_address_t addr = device_keeper_find(&hc->device_manager, handle);
[eb1a2f4]84 if (addr < 0) {
85 return addr;
86 }
87
88 if (address != NULL) {
89 *address = addr;
90 }
91
92 return EOK;
93}
[6cbe7dad]94/*----------------------------------------------------------------------------*/
[eb1a2f4]95usb_iface_t usb_iface_root_hub_fun_impl = {
96 .get_hc_handle = usb_iface_get_hc_handle_rh_impl,
97 .get_address = usb_iface_get_address_rh_impl
98};
[6cbe7dad]99/*----------------------------------------------------------------------------*/
[a7e2f0d]100/** Gets root hub hw resources.
101 *
102 * @param[in] fun Root hub function.
103 * @return Pointer to the resource list used by the root hub.
104 */
[6cbe7dad]105static hw_resource_list_t *get_resource_list(ddf_fun_t *dev)
106{
107 assert(dev);
108 ddf_fun_t *hc_ddf_instance = dev->driver_data;
109 assert(hc_ddf_instance);
110 uhci_t *hc = hc_ddf_instance->driver_data;
111 assert(hc);
[eb1a2f4]112
[a7e2f0d]113 /* TODO: fix memory leak */
[6cbe7dad]114 hw_resource_list_t *resource_list = malloc(sizeof(hw_resource_list_t));
115 assert(resource_list);
116 resource_list->count = 1;
117 resource_list->resources = malloc(sizeof(hw_resource_t));
118 assert(resource_list->resources);
119 resource_list->resources[0].type = IO_RANGE;
120 resource_list->resources[0].res.io_range.address =
121 ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide
122 resource_list->resources[0].res.io_range.size = 4;
123 resource_list->resources[0].res.io_range.endianness = LITTLE_ENDIAN;
124
125 return resource_list;
126}
127/*----------------------------------------------------------------------------*/
128static hw_res_ops_t hw_res_iface = {
129 .get_resource_list = get_resource_list,
130 .enable_interrupt = NULL
131};
132/*----------------------------------------------------------------------------*/
[eb1a2f4]133static ddf_dev_ops_t root_hub_ops = {
[6cbe7dad]134 .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl,
135 .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
[eb1a2f4]136};
[1256a0a]137/*----------------------------------------------------------------------------*/
[eb1a2f4]138int setup_root_hub(ddf_fun_t **fun, ddf_dev_t *hc)
[1256a0a]139{
[eb1a2f4]140 assert(fun);
[4abc304]141 assert(hc);
[eb1a2f4]142 int ret;
143
144 ddf_fun_t *hub = ddf_fun_create(hc, fun_inner, "root-hub");
[1256a0a]145 if (!hub) {
[afcd86e]146 usb_log_error("Failed to create root hub device structure.\n");
[1256a0a]147 return ENOMEM;
148 }
149
150 char *match_str;
151 ret = asprintf(&match_str, "usb&uhci&root-hub");
152 if (ret < 0) {
[afcd86e]153 usb_log_error("Failed to create root hub match string.\n");
[eb1a2f4]154 ddf_fun_destroy(hub);
[1256a0a]155 return ENOMEM;
156 }
157
[eb1a2f4]158 ret = ddf_fun_add_match_id(hub, match_str, 100);
159 if (ret != EOK) {
[4abc304]160 usb_log_error("Failed(%d) to add root hub match id: %s\n",
161 ret, str_error(ret));
[eb1a2f4]162 ddf_fun_destroy(hub);
[4abc304]163 return ret;
[1256a0a]164 }
165
[eb1a2f4]166 hub->ops = &root_hub_ops;
[1256a0a]167
[eb1a2f4]168 *fun = hub;
[1256a0a]169 return EOK;
170}
[c56dbe0]171/**
172 * @}
173 */
Note: See TracBrowser for help on using the repository browser.