[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 | */
|
---|
[d930980] | 35 |
|
---|
[40a5d40] | 36 | #include <ddf/driver.h>
|
---|
| 37 | #include <ddf/interrupt.h>
|
---|
| 38 | #include <device/hw_res.h>
|
---|
| 39 | #include <errno.h>
|
---|
[d930980] | 40 | #include <stdbool.h>
|
---|
[40a5d40] | 41 | #include <str_error.h>
|
---|
| 42 |
|
---|
| 43 | #include <usb_iface.h>
|
---|
| 44 | #include <usb/ddfiface.h>
|
---|
| 45 | #include <usb/debug.h>
|
---|
[f9776ae5] | 46 | #include <usb/host/hcd.h>
|
---|
[40a5d40] | 47 |
|
---|
[dcffe95] | 48 | #include "res.h"
|
---|
[f9776ae5] | 49 |
|
---|
| 50 | #define NAME "ehci"
|
---|
[40a5d40] | 51 |
|
---|
[0c0f823b] | 52 | static int ehci_dev_add(ddf_dev_t *device);
|
---|
[76fbd9a] | 53 |
|
---|
[40a5d40] | 54 | static driver_ops_t ehci_driver_ops = {
|
---|
[0c0f823b] | 55 | .dev_add = ehci_dev_add,
|
---|
[40a5d40] | 56 | };
|
---|
[76fbd9a] | 57 |
|
---|
[40a5d40] | 58 | static driver_t ehci_driver = {
|
---|
| 59 | .name = NAME,
|
---|
| 60 | .driver_ops = &ehci_driver_ops
|
---|
| 61 | };
|
---|
[f51594fa] | 62 | static ddf_dev_ops_t hc_ops = {
|
---|
[f9776ae5] | 63 | .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
|
---|
[f51594fa] | 64 | };
|
---|
| 65 |
|
---|
[76fbd9a] | 66 |
|
---|
[13927cf] | 67 | /** Initializes a new ddf driver instance of EHCI hcd.
|
---|
| 68 | *
|
---|
| 69 | * @param[in] device DDF instance of the device to initialize.
|
---|
| 70 | * @return Error code.
|
---|
| 71 | */
|
---|
[0c0f823b] | 72 | static int ehci_dev_add(ddf_dev_t *device)
|
---|
[40a5d40] | 73 | {
|
---|
[d930980] | 74 | ddf_fun_t *hc_fun = NULL;
|
---|
| 75 | bool fun_bound = false;
|
---|
| 76 |
|
---|
[40a5d40] | 77 | assert(device);
|
---|
| 78 |
|
---|
[7de1988c] | 79 | addr_range_t reg_range;
|
---|
[40a5d40] | 80 | int irq = 0;
|
---|
| 81 |
|
---|
[7de1988c] | 82 | int rc = get_my_registers(device, ®_range, &irq);
|
---|
[d930980] | 83 | if (rc != EOK) {
|
---|
| 84 | usb_log_error("Failed to get memory addresses for %" PRIun
|
---|
| 85 | ": %s.\n", ddf_dev_get_handle(device), str_error(rc));
|
---|
| 86 | goto error;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[7de1988c] | 89 | usb_log_info("Memory mapped regs at %p (size %zu), IRQ %d.\n",
|
---|
| 90 | RNGABSPTR(reg_range), RNGSZ(reg_range), irq);
|
---|
[40a5d40] | 91 |
|
---|
[7de1988c] | 92 | rc = disable_legacy(device, ®_range);
|
---|
[d930980] | 93 | if (rc != EOK) {
|
---|
| 94 | usb_log_error("Failed to disable legacy USB: %s.\n",
|
---|
| 95 | str_error(rc));
|
---|
| 96 | goto error;
|
---|
| 97 | }
|
---|
[40a5d40] | 98 |
|
---|
[d930980] | 99 | hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
|
---|
[f51594fa] | 100 | if (hc_fun == NULL) {
|
---|
| 101 | usb_log_error("Failed to create EHCI function.\n");
|
---|
[d930980] | 102 | rc = ENOMEM;
|
---|
| 103 | goto error;
|
---|
[f51594fa] | 104 | }
|
---|
[d930980] | 105 |
|
---|
[f9776ae5] | 106 | hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t));
|
---|
| 107 | if (ehci_hc == NULL) {
|
---|
| 108 | usb_log_error("Failed to alloc generic HC driver.\n");
|
---|
[d930980] | 109 | rc = ENOMEM;
|
---|
| 110 | goto error;
|
---|
[f9776ae5] | 111 | }
|
---|
[d930980] | 112 |
|
---|
[f9776ae5] | 113 | /* High Speed, no bandwidth */
|
---|
| 114 | hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
|
---|
[56fd7cf] | 115 | ddf_fun_set_ops(hc_fun, &hc_ops);
|
---|
[f51594fa] | 116 |
|
---|
[d930980] | 117 | rc = ddf_fun_bind(hc_fun);
|
---|
| 118 | if (rc != EOK) {
|
---|
| 119 | usb_log_error("Failed to bind EHCI function: %s.\n",
|
---|
| 120 | str_error(rc));
|
---|
| 121 | goto error;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | fun_bound = true;
|
---|
| 125 |
|
---|
| 126 | rc = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
|
---|
| 127 | if (rc != EOK) {
|
---|
| 128 | usb_log_error("Failed to add EHCI to HC class: %s.\n",
|
---|
| 129 | str_error(rc));
|
---|
| 130 | goto error;
|
---|
| 131 | }
|
---|
[f51594fa] | 132 |
|
---|
[4125b7d] | 133 | usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
|
---|
[56fd7cf] | 134 | ddf_dev_get_name(device), ddf_dev_get_handle(device));
|
---|
[81608b5b] | 135 |
|
---|
[40a5d40] | 136 | return EOK;
|
---|
[d930980] | 137 | error:
|
---|
| 138 | if (fun_bound)
|
---|
| 139 | ddf_fun_unbind(hc_fun);
|
---|
| 140 | if (hc_fun != NULL)
|
---|
| 141 | ddf_fun_destroy(hc_fun);
|
---|
| 142 | return rc;
|
---|
[40a5d40] | 143 | }
|
---|
[76fbd9a] | 144 |
|
---|
[13927cf] | 145 | /** Initializes global driver structures (NONE).
|
---|
| 146 | *
|
---|
| 147 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
---|
| 148 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
| 149 | * @return Error code.
|
---|
[0d3167e] | 150 | *
|
---|
| 151 | * Driver debug level is set here.
|
---|
[13927cf] | 152 | */
|
---|
[40a5d40] | 153 | int main(int argc, char *argv[])
|
---|
| 154 | {
|
---|
[920d0fc] | 155 | log_init(NAME);
|
---|
[40a5d40] | 156 | return ddf_driver_main(&ehci_driver);
|
---|
| 157 | }
|
---|
| 158 | /**
|
---|
| 159 | * @}
|
---|
| 160 | */
|
---|