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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1558d85 was 7de1988c, checked in by Jakub Jermar <jakub@…>, 12 years ago

Adapt drivers using parsed HW resources to use the new interface.

  • 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/** @addtogroup drvusbehci
30 * @{
31 */
32/** @file
33 * Main routines of EHCI driver.
34 */
35
36#include <ddf/driver.h>
37#include <ddf/interrupt.h>
38#include <device/hw_res.h>
39#include <errno.h>
40#include <stdbool.h>
41#include <str_error.h>
42
43#include <usb_iface.h>
44#include <usb/ddfiface.h>
45#include <usb/debug.h>
46#include <usb/host/hcd.h>
47
48#include "res.h"
49
50#define NAME "ehci"
51
52static int ehci_dev_add(ddf_dev_t *device);
53
54static driver_ops_t ehci_driver_ops = {
55 .dev_add = ehci_dev_add,
56};
57
58static driver_t ehci_driver = {
59 .name = NAME,
60 .driver_ops = &ehci_driver_ops
61};
62static ddf_dev_ops_t hc_ops = {
63 .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
64};
65
66
67/** Initializes a new ddf driver instance of EHCI hcd.
68 *
69 * @param[in] device DDF instance of the device to initialize.
70 * @return Error code.
71 */
72static int ehci_dev_add(ddf_dev_t *device)
73{
74 ddf_fun_t *hc_fun = NULL;
75 bool fun_bound = false;
76
77 assert(device);
78
79 addr_range_t reg_range;
80 int irq = 0;
81
82 int rc = get_my_registers(device, &reg_range, &irq);
83 if (rc != EOK) {
84 usb_log_error("Failed to get memory addresses for %" PRIun
85 ": %s.\n", ddf_dev_get_handle(device), str_error(rc));
86 goto error;
87 }
88
89 usb_log_info("Memory mapped regs at %p (size %zu), IRQ %d.\n",
90 RNGABSPTR(reg_range), RNGSZ(reg_range), irq);
91
92 rc = disable_legacy(device, &reg_range);
93 if (rc != EOK) {
94 usb_log_error("Failed to disable legacy USB: %s.\n",
95 str_error(rc));
96 goto error;
97 }
98
99 hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
100 if (hc_fun == NULL) {
101 usb_log_error("Failed to create EHCI function.\n");
102 rc = ENOMEM;
103 goto error;
104 }
105
106 hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t));
107 if (ehci_hc == NULL) {
108 usb_log_error("Failed to alloc generic HC driver.\n");
109 rc = ENOMEM;
110 goto error;
111 }
112
113 /* High Speed, no bandwidth */
114 hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
115 ddf_fun_set_ops(hc_fun, &hc_ops);
116
117 rc = ddf_fun_bind(hc_fun);
118 if (rc != EOK) {
119 usb_log_error("Failed to bind EHCI function: %s.\n",
120 str_error(rc));
121 goto error;
122 }
123
124 fun_bound = true;
125
126 rc = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
127 if (rc != EOK) {
128 usb_log_error("Failed to add EHCI to HC class: %s.\n",
129 str_error(rc));
130 goto error;
131 }
132
133 usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
134 ddf_dev_get_name(device), ddf_dev_get_handle(device));
135
136 return EOK;
137error:
138 if (fun_bound)
139 ddf_fun_unbind(hc_fun);
140 if (hc_fun != NULL)
141 ddf_fun_destroy(hc_fun);
142 return rc;
143}
144
145/** Initializes global driver structures (NONE).
146 *
147 * @param[in] argc Nmber of arguments in argv vector (ignored).
148 * @param[in] argv Cmdline argument vector (ignored).
149 * @return Error code.
150 *
151 * Driver debug level is set here.
152 */
153int main(int argc, char *argv[])
154{
155 log_init(NAME);
156 return ddf_driver_main(&ehci_driver);
157}
158/**
159 * @}
160 */
Note: See TracBrowser for help on using the repository browser.