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

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

ohci,uhci,ehci: Use library provided 'get_registers' function

  • Property mode set to 100644
File size: 3.6 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
47#define NAME "ehci"
48
49static int ehci_dev_add(ddf_dev_t *device);
50
51static driver_ops_t ehci_driver_ops = {
52 .dev_add = ehci_dev_add,
53};
54
55static driver_t ehci_driver = {
56 .name = NAME,
57 .driver_ops = &ehci_driver_ops
58};
59
60
61/** Initializes a new ddf driver instance of EHCI hcd.
62 *
63 * @param[in] device DDF instance of the device to initialize.
64 * @return Error code.
65 */
66static int ehci_dev_add(ddf_dev_t *device)
67{
68 assert(device);
69 hw_res_list_parsed_t hw_res;
70 int ret = hcd_ddf_get_registers(device, &hw_res);
71 if (ret != EOK ||
72 hw_res.irqs.count != 1 || hw_res.mem_ranges.count != 1) {
73 usb_log_error("Failed to get register memory addresses "
74 "for %" PRIun ": %s.\n", ddf_dev_get_handle(device),
75 str_error(ret));
76 return ret;
77 }
78 addr_range_t regs = hw_res.mem_ranges.ranges[0];
79 const int irq = hw_res.irqs.irqs[0];
80 hw_res_list_parsed_clean(&hw_res);
81
82 usb_log_info("Memory mapped regs at %p (size %zu), IRQ %d.\n",
83 RNGABSPTR(regs), RNGSZ(regs), irq);
84
85 ret = disable_legacy(device, &regs);
86 if (ret != EOK) {
87 usb_log_error("Failed to disable legacy USB: %s.\n",
88 str_error(ret));
89 return ret;
90 }
91
92 /* High Speed, no bandwidth */
93 ret = hcd_ddf_setup_hc(device, USB_SPEED_HIGH, 0, NULL);
94 if (ret != EOK) {
95 usb_log_error("Failed to init generci hcd driver: %s\n",
96 str_error(ret));
97 return ret;
98 }
99
100 usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
101 ddf_dev_get_name(device), ddf_dev_get_handle(device));
102
103 return EOK;
104}
105
106/** Initializes global driver structures (NONE).
107 *
108 * @param[in] argc Nmber of arguments in argv vector (ignored).
109 * @param[in] argv Cmdline argument vector (ignored).
110 * @return Error code.
111 *
112 * Driver debug level is set here.
113 */
114int main(int argc, char *argv[])
115{
116 log_init(NAME);
117 return ddf_driver_main(&ehci_driver);
118}
119/**
120 * @}
121 */
Note: See TracBrowser for help on using the repository browser.