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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 56fd7cf was 56fd7cf, checked in by Jiri Svoboda <jiri@…>, 13 years ago

Make ddf_dev_t and ddf_fun_t opaque. This further tighthens the DDF interface.

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[40a5d40]1/*
[0969e45e]2 * Copyright (c) 2011 Jan Vesely
3 * Copyright (c) 2011 Vojtech Horky
[40a5d40]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 */
[f123909]29/** @addtogroup drvusbehci
[40a5d40]30 * @{
31 */
32/** @file
[0969e45e]33 * Main routines of EHCI driver.
[40a5d40]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/ddfiface.h>
43#include <usb/debug.h>
[f9776ae5]44#include <usb/host/hcd.h>
[40a5d40]45
[dcffe95]46#include "res.h"
[f9776ae5]47
48#define NAME "ehci"
[40a5d40]49
[0c0f823b]50static int ehci_dev_add(ddf_dev_t *device);
[76fbd9a]51
[40a5d40]52static driver_ops_t ehci_driver_ops = {
[0c0f823b]53 .dev_add = ehci_dev_add,
[40a5d40]54};
[76fbd9a]55
[40a5d40]56static driver_t ehci_driver = {
57 .name = NAME,
58 .driver_ops = &ehci_driver_ops
59};
[f51594fa]60static ddf_dev_ops_t hc_ops = {
[f9776ae5]61 .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
[f51594fa]62};
63
[76fbd9a]64
[13927cf]65/** Initializes a new ddf driver instance of EHCI hcd.
66 *
67 * @param[in] device DDF instance of the device to initialize.
68 * @return Error code.
69 */
[0c0f823b]70static int ehci_dev_add(ddf_dev_t *device)
[40a5d40]71{
72 assert(device);
73#define CHECK_RET_RETURN(ret, message...) \
74if (ret != EOK) { \
75 usb_log_error(message); \
76 return ret; \
77}
78
[c060090]79 uintptr_t reg_base = 0;
80 size_t reg_size = 0;
[40a5d40]81 int irq = 0;
82
[dcffe95]83 int ret = get_my_registers(device, &reg_base, &reg_size, &irq);
[40a5d40]84 CHECK_RET_RETURN(ret,
[4125b7d]85 "Failed to get memory addresses for %" PRIun ": %s.\n",
[56fd7cf]86 ddf_dev_get_handle(device), str_error(ret));
[4125b7d]87 usb_log_info("Memory mapped regs at 0x%" PRIxn " (size %zu), IRQ %d.\n",
[c060090]88 reg_base, reg_size, irq);
[40a5d40]89
[dcffe95]90 ret = disable_legacy(device, reg_base, reg_size);
[40a5d40]91 CHECK_RET_RETURN(ret,
[109d55c]92 "Failed to disable legacy USB: %s.\n", str_error(ret));
[40a5d40]93
[8d6c1f1]94 ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
[f51594fa]95 if (hc_fun == NULL) {
96 usb_log_error("Failed to create EHCI function.\n");
97 return ENOMEM;
98 }
[f9776ae5]99 hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t));
100 if (ehci_hc == NULL) {
101 usb_log_error("Failed to alloc generic HC driver.\n");
102 return ENOMEM;
103 }
104 /* High Speed, no bandwidth */
105 hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
[56fd7cf]106 ddf_fun_set_ops(hc_fun, &hc_ops);
[f51594fa]107
[2c49b81b]108 ret = ddf_fun_bind(hc_fun);
[f51594fa]109 CHECK_RET_RETURN(ret,
110 "Failed to bind EHCI function: %s.\n",
111 str_error(ret));
[1dc4a5e]112 ret = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
[2c49b81b]113 CHECK_RET_RETURN(ret,
114 "Failed to add EHCI to HC class: %s.\n",
115 str_error(ret));
[f51594fa]116
[4125b7d]117 usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
[56fd7cf]118 ddf_dev_get_name(device), ddf_dev_get_handle(device));
[81608b5b]119
[40a5d40]120 return EOK;
121#undef CHECK_RET_RETURN
122}
[76fbd9a]123
[13927cf]124/** Initializes global driver structures (NONE).
125 *
126 * @param[in] argc Nmber of arguments in argv vector (ignored).
127 * @param[in] argv Cmdline argument vector (ignored).
128 * @return Error code.
[0d3167e]129 *
130 * Driver debug level is set here.
[13927cf]131 */
[40a5d40]132int main(int argc, char *argv[])
133{
[215b001]134 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
[40a5d40]135 return ddf_driver_main(&ehci_driver);
136}
137/**
138 * @}
139 */
Note: See TracBrowser for help on using the repository browser.