[41b96b4] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
---|
| 3 | * Copyright (c) 2011 Vojtech Horky
|
---|
| 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 |
|
---|
[41b96b4] | 30 | /** @addtogroup drvusbohci
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | * Main routines of OHCI driver.
|
---|
| 35 | */
|
---|
[0d4b110] | 36 |
|
---|
| 37 | #include <assert.h>
|
---|
[41b96b4] | 38 | #include <ddf/driver.h>
|
---|
| 39 | #include <errno.h>
|
---|
[0d4b110] | 40 | #include <io/log.h>
|
---|
[41b96b4] | 41 | #include <str_error.h>
|
---|
| 42 |
|
---|
| 43 | #include <usb/debug.h>
|
---|
[da06e92] | 44 | #include <usb/host/ddf_helpers.h>
|
---|
[41b96b4] | 45 |
|
---|
[da06e92] | 46 | #include "hc.h"
|
---|
[41b96b4] | 47 |
|
---|
[53f1c87] | 48 | #define NAME "ohci"
|
---|
[b5f813c] | 49 | static int ohci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
|
---|
| 50 | static void ohci_driver_fini(hcd_t *);
|
---|
| 51 |
|
---|
| 52 | static const ddf_hc_driver_t ohci_hc_driver = {
|
---|
| 53 | .hc_speed = USB_SPEED_FULL,
|
---|
| 54 | .irq_code_gen = ohci_hc_gen_irq_code,
|
---|
| 55 | .init = ohci_driver_init,
|
---|
| 56 | .fini = ohci_driver_fini,
|
---|
| 57 | .name = "OHCI",
|
---|
| 58 | .ops = {
|
---|
| 59 | .schedule = ohci_hc_schedule,
|
---|
| 60 | .ep_add_hook = ohci_endpoint_init,
|
---|
| 61 | .ep_remove_hook = ohci_endpoint_fini,
|
---|
| 62 | .irq_hook = ohci_hc_interrupt,
|
---|
| 63 | .status_hook = ohci_hc_status,
|
---|
| 64 | },
|
---|
| 65 | };
|
---|
| 66 |
|
---|
[da06e92] | 67 |
|
---|
| 68 | static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
|
---|
| 69 | {
|
---|
| 70 | assert(hcd);
|
---|
[b5f813c] | 71 | assert(hcd_get_driver_data(hcd) == NULL);
|
---|
[da06e92] | 72 |
|
---|
| 73 | hc_t *instance = malloc(sizeof(hc_t));
|
---|
| 74 | if (!instance)
|
---|
| 75 | return ENOMEM;
|
---|
| 76 |
|
---|
[a25d893] | 77 | const int ret = hc_init(instance, res, irq);
|
---|
[55346870] | 78 | if (ret == EOK) {
|
---|
[b5f813c] | 79 | hcd_set_implementation(hcd, instance, &ohci_hc_driver.ops);
|
---|
[55346870] | 80 | } else {
|
---|
| 81 | free(instance);
|
---|
| 82 | }
|
---|
[da06e92] | 83 | return ret;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | static void ohci_driver_fini(hcd_t *hcd)
|
---|
| 87 | {
|
---|
| 88 | assert(hcd);
|
---|
[b5f813c] | 89 | hc_t *hc = hcd_get_driver_data(hcd);
|
---|
| 90 | if (hc)
|
---|
| 91 | hc_fini(hc);
|
---|
[da06e92] | 92 |
|
---|
[b5f813c] | 93 | hcd_set_implementation(hcd, NULL, NULL);
|
---|
| 94 | free(hc);
|
---|
[da06e92] | 95 | }
|
---|
[8627377] | 96 |
|
---|
[41b96b4] | 97 | /** Initializes a new ddf driver instance of OHCI hcd.
|
---|
| 98 | *
|
---|
| 99 | * @param[in] device DDF instance of the device to initialize.
|
---|
| 100 | * @return Error code.
|
---|
| 101 | */
|
---|
[0c0f823b] | 102 | static int ohci_dev_add(ddf_dev_t *device)
|
---|
[41b96b4] | 103 | {
|
---|
[0c0f823b] | 104 | usb_log_debug("ohci_dev_add() called\n");
|
---|
[41b96b4] | 105 | assert(device);
|
---|
[a799708] | 106 | return hcd_ddf_add_hc(device, &ohci_hc_driver);
|
---|
[41b96b4] | 107 | }
|
---|
[76fbd9a] | 108 |
|
---|
[2ef8023] | 109 | static const driver_ops_t ohci_driver_ops = {
|
---|
[0c0f823b] | 110 | .dev_add = ohci_dev_add,
|
---|
[dc5f2fb] | 111 | };
|
---|
[76fbd9a] | 112 |
|
---|
[2ef8023] | 113 | static const driver_t ohci_driver = {
|
---|
[dc5f2fb] | 114 | .name = NAME,
|
---|
| 115 | .driver_ops = &ohci_driver_ops
|
---|
| 116 | };
|
---|
[76fbd9a] | 117 |
|
---|
[41b96b4] | 118 | /** Initializes global driver structures (NONE).
|
---|
| 119 | *
|
---|
| 120 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
---|
| 121 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
| 122 | * @return Error code.
|
---|
| 123 | *
|
---|
| 124 | * Driver debug level is set here.
|
---|
| 125 | */
|
---|
| 126 | int main(int argc, char *argv[])
|
---|
| 127 | {
|
---|
[920d0fc] | 128 | log_init(NAME);
|
---|
[41b96b4] | 129 | return ddf_driver_main(&ohci_driver);
|
---|
| 130 | }
|
---|
[58563585] | 131 |
|
---|
[41b96b4] | 132 | /**
|
---|
| 133 | * @}
|
---|
| 134 | */
|
---|