source: mainline/uspace/drv/bus/usb/uhci/root_hub.c@ 0ef03d7

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

uhci: Use helper routines provided by libusbhost

  • Property mode set to 100644
File size: 4.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 drvusbuhci
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
34#include <assert.h>
35#include <errno.h>
36#include <str_error.h>
37#include <stdio.h>
38#include <ops/hw_res.h>
39
40#include <usb_iface.h>
41#include <usb/debug.h>
42
43#include "root_hub.h"
44/** DDF support structure for uhci_rhd driver, provides I/O resources */
45typedef struct {
46 /** List of resources available to the root hub. */
47 hw_resource_list_t resource_list;
48 /** The only resource in the RH resource list */
49 hw_resource_t io_regs;
50
51 devman_handle_t hc_handle;
52} rh_t;
53
54/** Gets handle of the respective hc.
55 *
56 * @param[in] fun DDF function of uhci device.
57 * @param[out] handle Host cotnroller handle.
58 * @return Error code.
59 */
60static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
61{
62 assert(fun);
63 rh_t *rh = ddf_fun_data_get(fun);
64
65 if (handle != NULL)
66 *handle = rh->hc_handle;
67 return EOK;
68}
69
70/** USB interface implementation used by RH */
71static usb_iface_t usb_iface = {
72 .get_hc_handle = usb_iface_get_hc_handle,
73};
74
75/** Get root hub hw resources (I/O registers).
76 *
77 * @param[in] fun Root hub function.
78 * @return Pointer to the resource list used by the root hub.
79 */
80static hw_resource_list_t *get_resource_list(ddf_fun_t *fun)
81{
82 assert(fun);
83 rh_t *rh = ddf_fun_data_get(fun);
84 assert(rh);
85 return &rh->resource_list;
86}
87
88/** Interface to provide the root hub driver with hw info */
89static hw_res_ops_t hw_res_iface = {
90 .get_resource_list = get_resource_list,
91 .enable_interrupt = NULL,
92};
93
94/** RH function support for uhci_rhd */
95static ddf_dev_ops_t rh_ops = {
96 .interfaces[USB_DEV_IFACE] = &usb_iface,
97 .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
98};
99/** Root hub initialization
100 * @param[in] instance RH structure to initialize
101 * @param[in] fun DDF function representing UHCI root hub
102 * @param[in] reg_addr Address of root hub status and control registers.
103 * @param[in] reg_size Size of accessible address space.
104 * @return Error code.
105 */
106int rh_init(ddf_dev_t *device, uintptr_t reg_addr, size_t reg_size,
107 devman_handle_t handle)
108{
109 assert(device);
110
111 ddf_fun_t *fun = ddf_fun_create(device, fun_inner, "uhci_rh");
112 if (!fun) {
113 usb_log_error("Failed to create UHCI RH function.\n");
114 return ENOMEM;
115 }
116 ddf_fun_set_ops(fun, &rh_ops);
117
118 rh_t *instance = ddf_fun_data_alloc(fun, sizeof(rh_t));
119
120 /* Initialize resource structure */
121 instance->resource_list.count = 1;
122 instance->resource_list.resources = &instance->io_regs;
123
124 instance->io_regs.type = IO_RANGE;
125 instance->io_regs.res.io_range.address = reg_addr;
126 instance->io_regs.res.io_range.size = reg_size;
127 instance->io_regs.res.io_range.endianness = LITTLE_ENDIAN;
128
129 instance->hc_handle = handle;
130
131 int ret = ddf_fun_add_match_id(fun, "usb&uhci&root-hub", 100);
132 if (ret != EOK) {
133 usb_log_error("Failed to add root hub match id: %s\n",
134 str_error(ret));
135 ddf_fun_destroy(fun);
136 }
137
138 ret = ddf_fun_bind(fun);
139 if (ret != EOK) {
140 usb_log_error("Failed to bind root function: %s\n",
141 str_error(ret));
142 ddf_fun_destroy(fun);
143 }
144
145 usb_log_fatal("RH ready, hc handle: %"PRIun"\n", handle);
146 return ret;
147}
148/**
149 * @}
150 */
Note: See TracBrowser for help on using the repository browser.