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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d776329b was 58563585, checked in by Martin Decky <martin@…>, 9 years ago

code review and cstyle cleanup (no change in functionality)

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