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