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

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

libusbhost: Add status hook.

Implement in UHCI, OHCI

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