| 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 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @addtogroup drvusbohci
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file
|
|---|
| 34 | * Main routines of OHCI driver.
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <assert.h>
|
|---|
| 38 | #include <ddf/driver.h>
|
|---|
| 39 | #include <errno.h>
|
|---|
| 40 | #include <io/log.h>
|
|---|
| 41 | #include <str_error.h>
|
|---|
| 42 |
|
|---|
| 43 | #include <usb/debug.h>
|
|---|
| 44 | #include <usb/host/ddf_helpers.h>
|
|---|
| 45 |
|
|---|
| 46 | #include "hc.h"
|
|---|
| 47 | #include "ohci_bus.h"
|
|---|
| 48 |
|
|---|
| 49 | #define NAME "ohci"
|
|---|
| 50 | static int ohci_driver_init(hcd_t *, const hw_res_list_parsed_t *, ddf_dev_t *);
|
|---|
| 51 | static int ohci_driver_start(hcd_t *, bool);
|
|---|
| 52 | static int ohci_driver_claim(hcd_t *, ddf_dev_t *);
|
|---|
| 53 | static void ohci_driver_fini(hcd_t *);
|
|---|
| 54 |
|
|---|
| 55 | static const ddf_hc_driver_t ohci_hc_driver = {
|
|---|
| 56 | .irq_code_gen = ohci_hc_gen_irq_code,
|
|---|
| 57 | .init = ohci_driver_init,
|
|---|
| 58 | .claim = ohci_driver_claim,
|
|---|
| 59 | .start = ohci_driver_start,
|
|---|
| 60 | .setup_root_hub = hcd_setup_virtual_root_hub,
|
|---|
| 61 | .fini = ohci_driver_fini,
|
|---|
| 62 | .name = "OHCI",
|
|---|
| 63 | .ops = {
|
|---|
| 64 | .schedule = ohci_hc_schedule,
|
|---|
| 65 | .irq_hook = ohci_hc_interrupt,
|
|---|
| 66 | .status_hook = ohci_hc_status,
|
|---|
| 67 | },
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, ddf_dev_t *device)
|
|---|
| 72 | {
|
|---|
| 73 | int err;
|
|---|
| 74 |
|
|---|
| 75 | assert(hcd);
|
|---|
| 76 | assert(hcd_get_driver_data(hcd) == NULL);
|
|---|
| 77 |
|
|---|
| 78 | hc_t *instance = malloc(sizeof(hc_t));
|
|---|
| 79 | if (!instance)
|
|---|
| 80 | return ENOMEM;
|
|---|
| 81 |
|
|---|
| 82 | if ((err = hc_init(instance, res)) != EOK)
|
|---|
| 83 | goto err;
|
|---|
| 84 |
|
|---|
| 85 | if ((err = ohci_bus_init(&instance->bus, instance)))
|
|---|
| 86 | goto err;
|
|---|
| 87 |
|
|---|
| 88 | hcd_set_implementation(hcd, instance, &ohci_hc_driver.ops, &instance->bus.base.base);
|
|---|
| 89 |
|
|---|
| 90 | return EOK;
|
|---|
| 91 |
|
|---|
| 92 | err:
|
|---|
| 93 | free(instance);
|
|---|
| 94 | return err;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | static int ohci_driver_claim(hcd_t *hcd, ddf_dev_t *dev)
|
|---|
| 98 | {
|
|---|
| 99 | hc_t *hc = hcd_get_driver_data(hcd);
|
|---|
| 100 | assert(hc);
|
|---|
| 101 |
|
|---|
| 102 | hc_gain_control(hc);
|
|---|
| 103 |
|
|---|
| 104 | return EOK;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | static int ohci_driver_start(hcd_t *hcd, bool interrupts)
|
|---|
| 108 | {
|
|---|
| 109 | hc_t *hc = hcd_get_driver_data(hcd);
|
|---|
| 110 | assert(hc);
|
|---|
| 111 |
|
|---|
| 112 | hc->hw_interrupts = interrupts;
|
|---|
| 113 | hc_start(hc);
|
|---|
| 114 | return EOK;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | static void ohci_driver_fini(hcd_t *hcd)
|
|---|
| 118 | {
|
|---|
| 119 | assert(hcd);
|
|---|
| 120 | hc_t *hc = hcd_get_driver_data(hcd);
|
|---|
| 121 | if (hc)
|
|---|
| 122 | hc_fini(hc);
|
|---|
| 123 |
|
|---|
| 124 | hcd_set_implementation(hcd, NULL, NULL, NULL);
|
|---|
| 125 | free(hc);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /** Initializes a new ddf driver instance of OHCI hcd.
|
|---|
| 129 | *
|
|---|
| 130 | * @param[in] device DDF instance of the device to initialize.
|
|---|
| 131 | * @return Error code.
|
|---|
| 132 | */
|
|---|
| 133 | static int ohci_dev_add(ddf_dev_t *device)
|
|---|
| 134 | {
|
|---|
| 135 | usb_log_debug("ohci_dev_add() called\n");
|
|---|
| 136 | assert(device);
|
|---|
| 137 | return hcd_ddf_add_hc(device, &ohci_hc_driver);
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | static const driver_ops_t ohci_driver_ops = {
|
|---|
| 141 | .dev_add = ohci_dev_add,
|
|---|
| 142 | };
|
|---|
| 143 |
|
|---|
| 144 | static const driver_t ohci_driver = {
|
|---|
| 145 | .name = NAME,
|
|---|
| 146 | .driver_ops = &ohci_driver_ops
|
|---|
| 147 | };
|
|---|
| 148 |
|
|---|
| 149 | /** Initializes global driver structures (NONE).
|
|---|
| 150 | *
|
|---|
| 151 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
|---|
| 152 | * @param[in] argv Cmdline argument vector (ignored).
|
|---|
| 153 | * @return Error code.
|
|---|
| 154 | *
|
|---|
| 155 | * Driver debug level is set here.
|
|---|
| 156 | */
|
|---|
| 157 | int main(int argc, char *argv[])
|
|---|
| 158 | {
|
|---|
| 159 | log_init(NAME);
|
|---|
| 160 | return ddf_driver_main(&ohci_driver);
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | /**
|
|---|
| 164 | * @}
|
|---|
| 165 | */
|
|---|