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

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

ehci,ohci,uhci: Switch to generic hc drv initialization function

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