| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Vojtech Horky, Jan Vesely
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 | /** @addtogroup drvusbuhci
|
|---|
| 29 | * @{
|
|---|
| 30 | */
|
|---|
| 31 | /** @file
|
|---|
| 32 | * @brief UHCI driver initialization
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #include <assert.h>
|
|---|
| 36 | #include <ddf/driver.h>
|
|---|
| 37 | #include <devman.h>
|
|---|
| 38 | #include <errno.h>
|
|---|
| 39 | #include <io/log.h>
|
|---|
| 40 | #include <pci_dev_iface.h>
|
|---|
| 41 | #include <stdio.h>
|
|---|
| 42 | #include <str_error.h>
|
|---|
| 43 | #include <usb/debug.h>
|
|---|
| 44 | #include <usb/host/ddf_helpers.h>
|
|---|
| 45 |
|
|---|
| 46 | #include "hc.h"
|
|---|
| 47 |
|
|---|
| 48 | #define NAME "uhci"
|
|---|
| 49 |
|
|---|
| 50 | static int uhci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
|
|---|
| 51 | static void uhci_driver_fini(hcd_t *);
|
|---|
| 52 | static int disable_legacy(ddf_dev_t *);
|
|---|
| 53 |
|
|---|
| 54 | static const ddf_hc_driver_t uhci_hc_driver = {
|
|---|
| 55 | .claim = disable_legacy,
|
|---|
| 56 | .hc_speed = USB_SPEED_FULL,
|
|---|
| 57 | .irq_code_gen = uhci_hc_gen_irq_code,
|
|---|
| 58 | .init = uhci_driver_init,
|
|---|
| 59 | .fini = uhci_driver_fini,
|
|---|
| 60 | .name = "UHCI",
|
|---|
| 61 | .ops = {
|
|---|
| 62 | .schedule = uhci_hc_schedule,
|
|---|
| 63 | .irq_hook = uhci_hc_interrupt,
|
|---|
| 64 | .status_hook = uhci_hc_status,
|
|---|
| 65 | },
|
|---|
| 66 | };
|
|---|
| 67 |
|
|---|
| 68 | static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
|
|---|
| 69 | {
|
|---|
| 70 | assert(hcd);
|
|---|
| 71 | assert(hcd_get_driver_data(hcd) == NULL);
|
|---|
| 72 |
|
|---|
| 73 | hc_t *instance = malloc(sizeof(hc_t));
|
|---|
| 74 | if (!instance)
|
|---|
| 75 | return ENOMEM;
|
|---|
| 76 |
|
|---|
| 77 | const int ret = hc_init(instance, res, irq);
|
|---|
| 78 | if (ret == EOK) {
|
|---|
| 79 | hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops);
|
|---|
| 80 | } else {
|
|---|
| 81 | free(instance);
|
|---|
| 82 | }
|
|---|
| 83 | return ret;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | static void uhci_driver_fini(hcd_t *hcd)
|
|---|
| 87 | {
|
|---|
| 88 | assert(hcd);
|
|---|
| 89 | hc_t *hc = hcd_get_driver_data(hcd);
|
|---|
| 90 | if (hc)
|
|---|
| 91 | hc_fini(hc);
|
|---|
| 92 |
|
|---|
| 93 | hcd_set_implementation(hcd, NULL, NULL);
|
|---|
| 94 | free(hc);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | /** Call the PCI driver with a request to clear legacy support register
|
|---|
| 98 | *
|
|---|
| 99 | * @param[in] device Device asking to disable interrupts
|
|---|
| 100 | * @return Error code.
|
|---|
| 101 | */
|
|---|
| 102 | static int disable_legacy(ddf_dev_t *device)
|
|---|
| 103 | {
|
|---|
| 104 | assert(device);
|
|---|
| 105 |
|
|---|
| 106 | async_sess_t *parent_sess = devman_parent_device_connect(
|
|---|
| 107 | EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
|
|---|
| 108 | if (!parent_sess)
|
|---|
| 109 | return ENOMEM;
|
|---|
| 110 |
|
|---|
| 111 | /* See UHCI design guide page 45 for these values.
|
|---|
| 112 | * Write all WC bits in USB legacy register */
|
|---|
| 113 | const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
|
|---|
| 114 |
|
|---|
| 115 | async_hangup(parent_sess);
|
|---|
| 116 | return rc;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | /** Initialize a new ddf driver instance for uhci hc and hub.
|
|---|
| 120 | *
|
|---|
| 121 | * @param[in] device DDF instance of the device to initialize.
|
|---|
| 122 | * @return Error code.
|
|---|
| 123 | */
|
|---|
| 124 | static int uhci_dev_add(ddf_dev_t *device)
|
|---|
| 125 | {
|
|---|
| 126 | usb_log_debug2("uhci_dev_add() called\n");
|
|---|
| 127 | assert(device);
|
|---|
| 128 | return hcd_ddf_add_hc(device, &uhci_hc_driver);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | static const driver_ops_t uhci_driver_ops = {
|
|---|
| 132 | .dev_add = uhci_dev_add,
|
|---|
| 133 | };
|
|---|
| 134 |
|
|---|
| 135 | static const driver_t uhci_driver = {
|
|---|
| 136 | .name = NAME,
|
|---|
| 137 | .driver_ops = &uhci_driver_ops
|
|---|
| 138 | };
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 | /** Initialize global driver structures (NONE).
|
|---|
| 142 | *
|
|---|
| 143 | * @param[in] argc Number of arguments in argv vector (ignored).
|
|---|
| 144 | * @param[in] argv Cmdline argument vector (ignored).
|
|---|
| 145 | * @return Error code.
|
|---|
| 146 | *
|
|---|
| 147 | * Driver debug level is set here.
|
|---|
| 148 | */
|
|---|
| 149 | int main(int argc, char *argv[])
|
|---|
| 150 | {
|
|---|
| 151 | printf(NAME ": HelenOS UHCI driver.\n");
|
|---|
| 152 | log_init(NAME);
|
|---|
| 153 |
|
|---|
| 154 | return ddf_driver_main(&uhci_driver);
|
|---|
| 155 | }
|
|---|
| 156 | /**
|
|---|
| 157 | * @}
|
|---|
| 158 | */
|
|---|