[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 | */
|
---|
| 29 | /** @addtogroup drvusbohci
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * Main routines of OHCI driver.
|
---|
| 34 | */
|
---|
[0d4b110] | 35 |
|
---|
| 36 | #include <assert.h>
|
---|
[41b96b4] | 37 | #include <ddf/driver.h>
|
---|
| 38 | #include <errno.h>
|
---|
[0d4b110] | 39 | #include <io/log.h>
|
---|
[41b96b4] | 40 | #include <str_error.h>
|
---|
| 41 |
|
---|
| 42 | #include <usb/debug.h>
|
---|
[da06e92] | 43 | #include <usb/host/ddf_helpers.h>
|
---|
[41b96b4] | 44 |
|
---|
[da06e92] | 45 | #include "hc.h"
|
---|
[41b96b4] | 46 |
|
---|
[53f1c87] | 47 | #define NAME "ohci"
|
---|
[da06e92] | 48 |
|
---|
| 49 | static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
|
---|
| 50 | {
|
---|
| 51 | assert(hcd);
|
---|
| 52 | assert(hcd->driver.data == NULL);
|
---|
| 53 |
|
---|
| 54 | hc_t *instance = malloc(sizeof(hc_t));
|
---|
| 55 | if (!instance)
|
---|
| 56 | return ENOMEM;
|
---|
| 57 |
|
---|
| 58 | const int ret = hc_init(instance, res, irq);
|
---|
| 59 | if (ret == EOK)
|
---|
[fccf289] | 60 | hcd_set_implementation(hcd, instance, ohci_hc_schedule,
|
---|
| 61 | ohci_endpoint_init, ohci_endpoint_fini, ohci_hc_interrupt,
|
---|
| 62 | ohci_hc_status);
|
---|
[da06e92] | 63 | return ret;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | static void ohci_driver_fini(hcd_t *hcd)
|
---|
| 67 | {
|
---|
| 68 | assert(hcd);
|
---|
| 69 | if (hcd->driver.data)
|
---|
| 70 | hc_fini(hcd->driver.data);
|
---|
| 71 |
|
---|
| 72 | free(hcd->driver.data);
|
---|
[e26a9d95] | 73 | hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
|
---|
[da06e92] | 74 | }
|
---|
[8627377] | 75 |
|
---|
[41b96b4] | 76 | /** Initializes a new ddf driver instance of OHCI hcd.
|
---|
| 77 | *
|
---|
| 78 | * @param[in] device DDF instance of the device to initialize.
|
---|
| 79 | * @return Error code.
|
---|
| 80 | */
|
---|
[0c0f823b] | 81 | static int ohci_dev_add(ddf_dev_t *device)
|
---|
[41b96b4] | 82 | {
|
---|
[0c0f823b] | 83 | usb_log_debug("ohci_dev_add() called\n");
|
---|
[41b96b4] | 84 | assert(device);
|
---|
| 85 |
|
---|
[da06e92] | 86 | const int ret = ddf_hcd_device_setup_all(device, USB_SPEED_FULL,
|
---|
| 87 | BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11,
|
---|
[fccf289] | 88 | ddf_hcd_gen_irq_handler, ohci_hc_gen_irq_code,
|
---|
[da06e92] | 89 | ohci_driver_init, ohci_driver_fini);
|
---|
[e7bc999] | 90 | if (ret != EOK) {
|
---|
[53f1c87] | 91 | usb_log_error("Failed to initialize OHCI driver: %s.\n",
|
---|
[05ead5c] | 92 | str_error(ret));
|
---|
[41b96b4] | 93 | }
|
---|
[da06e92] | 94 | usb_log_info("Controlling new OHCI device '%s'.\n",
|
---|
| 95 | ddf_dev_get_name(device));
|
---|
[41b96b4] | 96 |
|
---|
[da06e92] | 97 | return ret;
|
---|
[41b96b4] | 98 | }
|
---|
[76fbd9a] | 99 |
|
---|
[2ef8023] | 100 | static const driver_ops_t ohci_driver_ops = {
|
---|
[0c0f823b] | 101 | .dev_add = ohci_dev_add,
|
---|
[dc5f2fb] | 102 | };
|
---|
[76fbd9a] | 103 |
|
---|
[2ef8023] | 104 | static const driver_t ohci_driver = {
|
---|
[dc5f2fb] | 105 | .name = NAME,
|
---|
| 106 | .driver_ops = &ohci_driver_ops
|
---|
| 107 | };
|
---|
[76fbd9a] | 108 |
|
---|
[41b96b4] | 109 | /** Initializes global driver structures (NONE).
|
---|
| 110 | *
|
---|
| 111 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
---|
| 112 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
| 113 | * @return Error code.
|
---|
| 114 | *
|
---|
| 115 | * Driver debug level is set here.
|
---|
| 116 | */
|
---|
| 117 | int main(int argc, char *argv[])
|
---|
| 118 | {
|
---|
[920d0fc] | 119 | log_init(NAME);
|
---|
[41b96b4] | 120 | return ddf_driver_main(&ohci_driver);
|
---|
| 121 | }
|
---|
| 122 | /**
|
---|
| 123 | * @}
|
---|
| 124 | */
|
---|