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 | /** @addtogroup drvusbehci
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * Main routines of EHCI driver.
|
---|
34 | */
|
---|
35 | #include <ddf/driver.h>
|
---|
36 | #include <ddf/interrupt.h>
|
---|
37 | #include <device/hw_res.h>
|
---|
38 | #include <errno.h>
|
---|
39 | #include <str_error.h>
|
---|
40 | #include <io/logctl.h>
|
---|
41 |
|
---|
42 | #include <usb_iface.h>
|
---|
43 | #include <usb/debug.h>
|
---|
44 | #include <usb/host/ddf_helpers.h>
|
---|
45 |
|
---|
46 | #include "res.h"
|
---|
47 | #include "hc.h"
|
---|
48 | #include "ehci_endpoint.h"
|
---|
49 |
|
---|
50 | #define NAME "ehci"
|
---|
51 |
|
---|
52 | static int ehci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
|
---|
53 | static void ehci_driver_fini(hcd_t *);
|
---|
54 |
|
---|
55 | static const ddf_hc_driver_t ehci_hc_driver = {
|
---|
56 | .claim = disable_legacy,
|
---|
57 | .hc_speed = USB_SPEED_HIGH,
|
---|
58 | .irq_code_gen = ehci_hc_gen_irq_code,
|
---|
59 | .init = ehci_driver_init,
|
---|
60 | .fini = ehci_driver_fini,
|
---|
61 | .name = "EHCI-PCI",
|
---|
62 | .ops = {
|
---|
63 | .schedule = ehci_hc_schedule,
|
---|
64 | .ep_add_hook = ehci_endpoint_init,
|
---|
65 | .ep_remove_hook = ehci_endpoint_fini,
|
---|
66 | .irq_hook = ehci_hc_interrupt,
|
---|
67 | .status_hook = ehci_hc_status,
|
---|
68 | }
|
---|
69 | };
|
---|
70 |
|
---|
71 |
|
---|
72 | static int ehci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
|
---|
73 | {
|
---|
74 | assert(hcd);
|
---|
75 | assert(hcd_get_driver_data(hcd) == NULL);
|
---|
76 |
|
---|
77 | hc_t *instance = malloc(sizeof(hc_t));
|
---|
78 | if (!instance)
|
---|
79 | return ENOMEM;
|
---|
80 |
|
---|
81 | const int ret = hc_init(instance, res, irq);
|
---|
82 | if (ret == EOK) {
|
---|
83 | hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops);
|
---|
84 | } else {
|
---|
85 | free(instance);
|
---|
86 | }
|
---|
87 | return ret;
|
---|
88 | }
|
---|
89 |
|
---|
90 | static void ehci_driver_fini(hcd_t *hcd)
|
---|
91 | {
|
---|
92 | assert(hcd);
|
---|
93 | hc_t *hc = hcd_get_driver_data(hcd);
|
---|
94 | if (hc)
|
---|
95 | hc_fini(hc);
|
---|
96 |
|
---|
97 | free(hc);
|
---|
98 | hcd_set_implementation(hcd, NULL, NULL);
|
---|
99 | }
|
---|
100 |
|
---|
101 | /** Initializes a new ddf driver instance of EHCI hcd.
|
---|
102 | *
|
---|
103 | * @param[in] device DDF instance of the device to initialize.
|
---|
104 | * @return Error code.
|
---|
105 | */
|
---|
106 | static int ehci_dev_add(ddf_dev_t *device)
|
---|
107 | {
|
---|
108 | usb_log_debug("ehci_dev_add() called\n");
|
---|
109 | assert(device);
|
---|
110 |
|
---|
111 | return hcd_ddf_add_hc(device, &ehci_hc_driver);
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | static const driver_ops_t ehci_driver_ops = {
|
---|
117 | .dev_add = ehci_dev_add,
|
---|
118 | };
|
---|
119 |
|
---|
120 | static const driver_t ehci_driver = {
|
---|
121 | .name = NAME,
|
---|
122 | .driver_ops = &ehci_driver_ops
|
---|
123 | };
|
---|
124 |
|
---|
125 |
|
---|
126 | /** Initializes global driver structures (NONE).
|
---|
127 | *
|
---|
128 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
---|
129 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
130 | * @return Error code.
|
---|
131 | *
|
---|
132 | * Driver debug level is set here.
|
---|
133 | */
|
---|
134 | int main(int argc, char *argv[])
|
---|
135 | {
|
---|
136 | log_init(NAME);
|
---|
137 | logctl_set_log_level(NAME, LVL_NOTE);
|
---|
138 | return ddf_driver_main(&ehci_driver);
|
---|
139 | }
|
---|
140 | /**
|
---|
141 | * @}
|
---|
142 | */
|
---|