source: mainline/uspace/drv/bus/usb/ehci/main.c@ c10daa8

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c10daa8 was 366e9b6, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

usbhost: setup of the root hub is now a method of an driver

[oue]hci + vhc still use the previous implementation, renamed to hcd_setup_virtual_root_hub. xhci currently does not do anything, so the virtual hub is not created anymore.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * Copyright (c) 2011 Vojtech Horky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup drvusbehci
31 * @{
32 */
33/** @file
34 * Main routines of EHCI driver.
35 */
36
37#include <ddf/driver.h>
38#include <ddf/interrupt.h>
39#include <device/hw_res.h>
40#include <errno.h>
41#include <str_error.h>
42#include <io/logctl.h>
43
44#include <usb_iface.h>
45#include <usb/debug.h>
46#include <usb/host/ddf_helpers.h>
47
48#include "res.h"
49#include "hc.h"
50
51#define NAME "ehci"
52
53static int ehci_driver_init(hcd_t *, const hw_res_list_parsed_t *);
54static int ehci_driver_claim(hcd_t *, ddf_dev_t *);
55static int ehci_driver_start(hcd_t *, bool);
56static void ehci_driver_fini(hcd_t *);
57
58static const ddf_hc_driver_t ehci_hc_driver = {
59 .hc_speed = USB_SPEED_HIGH,
60 .name = "EHCI-PCI",
61 .init = ehci_driver_init,
62 .irq_code_gen = ehci_hc_gen_irq_code,
63 .claim = ehci_driver_claim,
64 .start = ehci_driver_start,
65 .setup_root_hub = hcd_setup_virtual_root_hub,
66 .fini = ehci_driver_fini,
67 .ops = {
68 .schedule = ehci_hc_schedule,
69 .irq_hook = ehci_hc_interrupt,
70 .status_hook = ehci_hc_status,
71 }
72};
73
74
75static int ehci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res)
76{
77 assert(hcd);
78 assert(hcd_get_driver_data(hcd) == NULL);
79
80 hc_t *instance = malloc(sizeof(hc_t));
81 if (!instance)
82 return ENOMEM;
83
84 const int ret = hc_init(instance, res);
85 if (ret == EOK) {
86 hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops, &instance->bus.base.base);
87 } else {
88 free(instance);
89 }
90 return ret;
91}
92
93static int ehci_driver_claim(hcd_t *hcd, ddf_dev_t *dev)
94{
95 hc_t *instance = hcd_get_driver_data(hcd);
96 assert(instance);
97
98 return disable_legacy(instance, dev);
99}
100
101static int ehci_driver_start(hcd_t *hcd, bool irq) {
102 hc_t *instance = hcd_get_driver_data(hcd);
103 assert(instance);
104
105 return hc_start(instance, irq);
106}
107
108static void ehci_driver_fini(hcd_t *hcd)
109{
110 assert(hcd);
111 hc_t *hc = hcd_get_driver_data(hcd);
112 if (hc)
113 hc_fini(hc);
114
115 free(hc);
116 hcd_set_implementation(hcd, NULL, NULL, NULL);
117}
118
119/** Initializes a new ddf driver instance of EHCI hcd.
120 *
121 * @param[in] device DDF instance of the device to initialize.
122 * @return Error code.
123 */
124static int ehci_dev_add(ddf_dev_t *device)
125{
126 usb_log_debug("ehci_dev_add() called\n");
127 assert(device);
128
129 return hcd_ddf_add_hc(device, &ehci_hc_driver);
130
131}
132
133
134static const driver_ops_t ehci_driver_ops = {
135 .dev_add = ehci_dev_add,
136};
137
138static const driver_t ehci_driver = {
139 .name = NAME,
140 .driver_ops = &ehci_driver_ops
141};
142
143
144/** Initializes global driver structures (NONE).
145 *
146 * @param[in] argc Nmber of arguments in argv vector (ignored).
147 * @param[in] argv Cmdline argument vector (ignored).
148 * @return Error code.
149 *
150 * Driver debug level is set here.
151 */
152int main(int argc, char *argv[])
153{
154 log_init(NAME);
155 logctl_set_log_level(NAME, LVL_NOTE);
156 return ddf_driver_main(&ehci_driver);
157}
158
159/**
160 * @}
161 */
Note: See TracBrowser for help on using the repository browser.