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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bd41b192 was 615abda, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

ehci: plug legacy disabling code

Remove CHECK_RET macro

  • Property mode set to 100644
File size: 3.7 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#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
41#include <usb_iface.h>
42#include <usb/debug.h>
43#include <usb/host/ddf_helpers.h>
44
45#include "res.h"
46#include "hc.h"
47
48#define NAME "ehci"
49
50static int ehci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
51{
52 assert(hcd);
53 assert(hcd->driver.data == NULL);
54
55 hc_t *instance = malloc(sizeof(hc_t));
56 if (!instance)
57 return ENOMEM;
58
59 const int ret = hc_init(instance, res, irq);
60 if (ret == EOK)
61 hcd_set_implementation(hcd, instance, ehci_hc_schedule,
62 NULL, NULL, ehci_hc_interrupt, ehci_hc_status);
63 return ret;
64}
65
66static void ehci_driver_fini(hcd_t *hcd)
67{
68 assert(hcd);
69 if (hcd->driver.data)
70 hc_fini(hcd->driver.data);
71
72 free(hcd->driver.data);
73 hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
74}
75
76static int ehci_dev_add(ddf_dev_t *device);
77
78static const driver_ops_t ehci_driver_ops = {
79 .dev_add = ehci_dev_add,
80};
81
82static const driver_t ehci_driver = {
83 .name = NAME,
84 .driver_ops = &ehci_driver_ops
85};
86
87
88/** Initializes a new ddf driver instance of EHCI hcd.
89 *
90 * @param[in] device DDF instance of the device to initialize.
91 * @return Error code.
92 */
93static int ehci_dev_add(ddf_dev_t *device)
94{
95 usb_log_debug("ehci_dev_add() called\n");
96 assert(device);
97
98 int ret = disable_legacy(device);
99 if (ret != EOK) {
100 usb_log_error("Failed to disable EHCI legacy support: %s\n",
101 str_error(ret));
102 return ret;
103 }
104
105 ret = ddf_hcd_device_setup_all(device, USB_SPEED_HIGH,
106 BANDWIDTH_AVAILABLE_USB20, bandwidth_count_usb11,
107 ddf_hcd_gen_irq_handler, ehci_hc_gen_irq_code,
108 ehci_driver_init, ehci_driver_fini);
109 if (ret != EOK) {
110 usb_log_error("Failed to initialize EHCI driver: %s.\n",
111 str_error(ret));
112 return ret;
113 }
114 usb_log_info("Controlling new EHCI device '%s'.\n",
115 ddf_dev_get_name(device));
116
117 return EOK;
118}
119
120/** Initializes global driver structures (NONE).
121 *
122 * @param[in] argc Nmber of arguments in argv vector (ignored).
123 * @param[in] argv Cmdline argument vector (ignored).
124 * @return Error code.
125 *
126 * Driver debug level is set here.
127 */
128int main(int argc, char *argv[])
129{
130 log_init(NAME);
131 return ddf_driver_main(&ehci_driver);
132}
133/**
134 * @}
135 */
Note: See TracBrowser for help on using the repository browser.