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 | */
|
---|
34 | #include <assert.h>
|
---|
35 | #include <errno.h>
|
---|
36 | #include <stdio.h>
|
---|
37 |
|
---|
38 | #include <usb_iface.h>
|
---|
39 |
|
---|
40 | #include <usb/debug.h>
|
---|
41 |
|
---|
42 | #include "root_hub.h"
|
---|
43 | /*----------------------------------------------------------------------------*/
|
---|
44 | static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
|
---|
45 | {
|
---|
46 | assert(dev);
|
---|
47 | assert(dev->parent != NULL);
|
---|
48 |
|
---|
49 | device_t *parent = dev->parent;
|
---|
50 |
|
---|
51 | if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
|
---|
52 | usb_iface_t *usb_iface
|
---|
53 | = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
|
---|
54 | assert(usb_iface != NULL);
|
---|
55 | if (usb_iface->get_hc_handle) {
|
---|
56 | int rc = usb_iface->get_hc_handle(parent, handle);
|
---|
57 | return rc;
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | return ENOTSUP;
|
---|
62 | }
|
---|
63 | /*----------------------------------------------------------------------------*/
|
---|
64 | static usb_iface_t usb_iface = {
|
---|
65 | .get_hc_handle = usb_iface_get_hc_handle
|
---|
66 | };
|
---|
67 |
|
---|
68 | static device_ops_t rh_ops = {
|
---|
69 | .interfaces[USB_DEV_IFACE] = &usb_iface
|
---|
70 | };
|
---|
71 |
|
---|
72 | int setup_root_hub(device_t **device, device_t *hc)
|
---|
73 | {
|
---|
74 | assert(device);
|
---|
75 | device_t *hub = create_device();
|
---|
76 | if (!hub) {
|
---|
77 | usb_log_error("Failed to create root hub device structure.\n");
|
---|
78 | return ENOMEM;
|
---|
79 | }
|
---|
80 | char *name;
|
---|
81 | int ret = asprintf(&name, "UHCI Root Hub");
|
---|
82 | if (ret < 0) {
|
---|
83 | usb_log_error("Failed to create root hub name.\n");
|
---|
84 | free(hub);
|
---|
85 | return ENOMEM;
|
---|
86 | }
|
---|
87 |
|
---|
88 | char *match_str;
|
---|
89 | ret = asprintf(&match_str, "usb&uhci&root-hub");
|
---|
90 | if (ret < 0) {
|
---|
91 | usb_log_error("Failed to create root hub match string.\n");
|
---|
92 | free(hub);
|
---|
93 | free(name);
|
---|
94 | return ENOMEM;
|
---|
95 | }
|
---|
96 |
|
---|
97 | match_id_t *match_id = create_match_id();
|
---|
98 | if (!match_id) {
|
---|
99 | usb_log_error("Failed to create root hub match id.\n");
|
---|
100 | free(hub);
|
---|
101 | free(match_str);
|
---|
102 | return ENOMEM;
|
---|
103 | }
|
---|
104 | match_id->id = match_str;
|
---|
105 | match_id->score = 90;
|
---|
106 |
|
---|
107 | add_match_id(&hub->match_ids, match_id);
|
---|
108 | hub->name = name;
|
---|
109 | hub->parent = hc;
|
---|
110 | hub->ops = &rh_ops;
|
---|
111 |
|
---|
112 | *device = hub;
|
---|
113 | return EOK;
|
---|
114 | }
|
---|
115 | /**
|
---|
116 | * @}
|
---|
117 | */
|
---|