1 | /*
|
---|
2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
3 | * Copyright (c) 2011 Vojtech Horky, Jan Vesely
|
---|
4 | * Copyright (c) 2018 Ondrej Hlavaty, Petr Manek
|
---|
5 | * All rights reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * - Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
14 | * notice, this list of conditions and the following disclaimer in the
|
---|
15 | * documentation and/or other materials provided with the distribution.
|
---|
16 | * - The name of the author may not be used to endorse or promote products
|
---|
17 | * derived from this software without specific prior written permission.
|
---|
18 | *
|
---|
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /** @addtogroup drvusbuhci
|
---|
32 | * @{
|
---|
33 | */
|
---|
34 | /** @file
|
---|
35 | * @brief UHCI driver initialization
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <assert.h>
|
---|
39 | #include <ddf/driver.h>
|
---|
40 | #include <errno.h>
|
---|
41 | #include <io/log.h>
|
---|
42 | #include <io/logctl.h>
|
---|
43 | #include <pci_dev_iface.h>
|
---|
44 | #include <stdio.h>
|
---|
45 | #include <str_error.h>
|
---|
46 | #include <usb/debug.h>
|
---|
47 | #include <usb/host/utility.h>
|
---|
48 |
|
---|
49 | #include "hc.h"
|
---|
50 |
|
---|
51 | #define NAME "uhci"
|
---|
52 |
|
---|
53 | static errno_t disable_legacy(hc_device_t *);
|
---|
54 |
|
---|
55 | static const hc_driver_t uhci_driver = {
|
---|
56 | .name = NAME,
|
---|
57 | .hc_device_size = sizeof(hc_t),
|
---|
58 | .claim = disable_legacy,
|
---|
59 | .irq_code_gen = hc_gen_irq_code,
|
---|
60 | .hc_add = hc_add,
|
---|
61 | .start = hc_start,
|
---|
62 | .setup_root_hub = hc_setup_roothub,
|
---|
63 | .hc_gone = hc_gone,
|
---|
64 | .hc_quiesce = hc_quiesce
|
---|
65 | };
|
---|
66 |
|
---|
67 | /** Call the PCI driver with a request to clear legacy support register
|
---|
68 | *
|
---|
69 | * @param[in] device Device asking to disable interrupts
|
---|
70 | * @return Error code.
|
---|
71 | */
|
---|
72 | static errno_t disable_legacy(hc_device_t *hcd)
|
---|
73 | {
|
---|
74 | assert(hcd);
|
---|
75 |
|
---|
76 | async_sess_t *parent_sess = ddf_dev_parent_sess_get(hcd->ddf_dev);
|
---|
77 | if (parent_sess == NULL)
|
---|
78 | return ENOMEM;
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * See UHCI design guide page 45 for these values.
|
---|
82 | * Write all WC bits in USB legacy register
|
---|
83 | */
|
---|
84 | return pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
|
---|
85 | }
|
---|
86 |
|
---|
87 | /** Initialize global driver structures (NONE).
|
---|
88 | *
|
---|
89 | * @param[in] argc Number of arguments in argv vector (ignored).
|
---|
90 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
91 | * @return Error code.
|
---|
92 | *
|
---|
93 | * Driver debug level is set here.
|
---|
94 | */
|
---|
95 | int main(int argc, char *argv[])
|
---|
96 | {
|
---|
97 | printf(NAME ": HelenOS UHCI driver.\n");
|
---|
98 | log_init(NAME);
|
---|
99 | logctl_set_log_level(NAME, LVL_NOTE);
|
---|
100 | return hc_driver_main(&uhci_driver);
|
---|
101 | }
|
---|
102 | /**
|
---|
103 | * @}
|
---|
104 | */
|
---|