| [c7137738] | 1 | /*
|
|---|
| [c56dbe0] | 2 | * Copyright (c) 2011 Vojtech Horky, Jan Vesely
|
|---|
| [c7137738] | 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 | */
|
|---|
| [58563585] | 28 |
|
|---|
| [e3a07bba] | 29 | /** @addtogroup drvusbuhci
|
|---|
| [c56dbe0] | 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| [17ceb72] | 33 | * @brief UHCI driver initialization
|
|---|
| [c56dbe0] | 34 | */
|
|---|
| [8064c2f6] | 35 |
|
|---|
| 36 | #include <assert.h>
|
|---|
| [eb1a2f4] | 37 | #include <ddf/driver.h>
|
|---|
| [c56dbe0] | 38 | #include <errno.h>
|
|---|
| [8064c2f6] | 39 | #include <io/log.h>
|
|---|
| [b74ec299] | 40 | #include <io/logctl.h>
|
|---|
| [e3a07bba] | 41 | #include <pci_dev_iface.h>
|
|---|
| [8064c2f6] | 42 | #include <stdio.h>
|
|---|
| [ab414a6] | 43 | #include <str_error.h>
|
|---|
| [afcd86e] | 44 | #include <usb/debug.h>
|
|---|
| [1a0fa29c] | 45 | #include <usb/host/ddf_helpers.h>
|
|---|
| [afcd86e] | 46 |
|
|---|
| [1a0fa29c] | 47 | #include "hc.h"
|
|---|
| [c7137738] | 48 |
|
|---|
| [497b6f31] | 49 | #define NAME "uhci"
|
|---|
| [afcd86e] | 50 |
|
|---|
| [0f6b50f] | 51 | static int uhci_driver_init(hcd_t *, const hw_res_list_parsed_t *, ddf_dev_t *);
|
|---|
| [e4d7363] | 52 | static int uhci_driver_start(hcd_t *, bool);
|
|---|
| [b5f813c] | 53 | static void uhci_driver_fini(hcd_t *);
|
|---|
| [e4d7363] | 54 | static int disable_legacy(hcd_t *, ddf_dev_t *);
|
|---|
| [76fbd9a] | 55 |
|
|---|
| [b5f813c] | 56 | static const ddf_hc_driver_t uhci_hc_driver = {
|
|---|
| 57 | .claim = disable_legacy,
|
|---|
| 58 | .irq_code_gen = uhci_hc_gen_irq_code,
|
|---|
| 59 | .init = uhci_driver_init,
|
|---|
| [e4d7363] | 60 | .start = uhci_driver_start,
|
|---|
| [366e9b6] | 61 | .setup_root_hub = hcd_setup_virtual_root_hub,
|
|---|
| [b5f813c] | 62 | .fini = uhci_driver_fini,
|
|---|
| 63 | .name = "UHCI",
|
|---|
| 64 | .ops = {
|
|---|
| 65 | .schedule = uhci_hc_schedule,
|
|---|
| 66 | .irq_hook = uhci_hc_interrupt,
|
|---|
| 67 | .status_hook = uhci_hc_status,
|
|---|
| 68 | },
|
|---|
| [36a4738] | 69 | };
|
|---|
| [76fbd9a] | 70 |
|
|---|
| [0f6b50f] | 71 | static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, ddf_dev_t *device)
|
|---|
| [1a0fa29c] | 72 | {
|
|---|
| [fc0271a5] | 73 | int err;
|
|---|
| 74 |
|
|---|
| [1a0fa29c] | 75 | assert(hcd);
|
|---|
| [b5f813c] | 76 | assert(hcd_get_driver_data(hcd) == NULL);
|
|---|
| [1a0fa29c] | 77 |
|
|---|
| 78 | hc_t *instance = malloc(sizeof(hc_t));
|
|---|
| 79 | if (!instance)
|
|---|
| 80 | return ENOMEM;
|
|---|
| 81 |
|
|---|
| [6832245] | 82 | if ((err = hc_init(instance, hcd, res)) != EOK)
|
|---|
| [fc0271a5] | 83 | goto err;
|
|---|
| 84 |
|
|---|
| 85 | hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops, &instance->bus.base);
|
|---|
| 86 |
|
|---|
| 87 | return EOK;
|
|---|
| 88 |
|
|---|
| 89 | err:
|
|---|
| 90 | free(instance);
|
|---|
| 91 | return err;
|
|---|
| [1a0fa29c] | 92 | }
|
|---|
| 93 |
|
|---|
| [e4d7363] | 94 | static int uhci_driver_start(hcd_t *hcd, bool interrupts)
|
|---|
| 95 | {
|
|---|
| 96 | assert(hcd);
|
|---|
| 97 | hc_t *hc = hcd_get_driver_data(hcd);
|
|---|
| 98 |
|
|---|
| 99 | hc->hw_interrupts = interrupts;
|
|---|
| 100 | hc_start(hc);
|
|---|
| 101 | return EOK;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| [1a0fa29c] | 104 | static void uhci_driver_fini(hcd_t *hcd)
|
|---|
| 105 | {
|
|---|
| 106 | assert(hcd);
|
|---|
| [b5f813c] | 107 | hc_t *hc = hcd_get_driver_data(hcd);
|
|---|
| 108 | if (hc)
|
|---|
| 109 | hc_fini(hc);
|
|---|
| [1a0fa29c] | 110 |
|
|---|
| [fc0271a5] | 111 | hcd_set_implementation(hcd, NULL, NULL, NULL);
|
|---|
| [b5f813c] | 112 | free(hc);
|
|---|
| [1a0fa29c] | 113 | }
|
|---|
| 114 |
|
|---|
| [e3a07bba] | 115 | /** Call the PCI driver with a request to clear legacy support register
|
|---|
| 116 | *
|
|---|
| 117 | * @param[in] device Device asking to disable interrupts
|
|---|
| 118 | * @return Error code.
|
|---|
| 119 | */
|
|---|
| [e4d7363] | 120 | static int disable_legacy(hcd_t *hcd, ddf_dev_t *device)
|
|---|
| [e3a07bba] | 121 | {
|
|---|
| 122 | assert(device);
|
|---|
| 123 |
|
|---|
| [d15797d] | 124 | async_sess_t *parent_sess = ddf_dev_parent_sess_get(device);
|
|---|
| 125 | if (parent_sess == NULL)
|
|---|
| [e3a07bba] | 126 | return ENOMEM;
|
|---|
| 127 |
|
|---|
| 128 | /* See UHCI design guide page 45 for these values.
|
|---|
| 129 | * Write all WC bits in USB legacy register */
|
|---|
| [53a309e] | 130 | return pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
|
|---|
| [e3a07bba] | 131 | }
|
|---|
| [76fbd9a] | 132 |
|
|---|
| [17ceb72] | 133 | /** Initialize a new ddf driver instance for uhci hc and hub.
|
|---|
| [a7e2f0d] | 134 | *
|
|---|
| 135 | * @param[in] device DDF instance of the device to initialize.
|
|---|
| 136 | * @return Error code.
|
|---|
| 137 | */
|
|---|
| [b5f813c] | 138 | static int uhci_dev_add(ddf_dev_t *device)
|
|---|
| [86341e2] | 139 | {
|
|---|
| [0c0f823b] | 140 | usb_log_debug2("uhci_dev_add() called\n");
|
|---|
| [9351353] | 141 | assert(device);
|
|---|
| [a799708] | 142 | return hcd_ddf_add_hc(device, &uhci_hc_driver);
|
|---|
| [c7137738] | 143 | }
|
|---|
| [ea993d18] | 144 |
|
|---|
| [c910ecf] | 145 | static int uhci_fun_online(ddf_fun_t *fun)
|
|---|
| 146 | {
|
|---|
| 147 | return hcd_ddf_device_online(fun);
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | static int uhci_fun_offline(ddf_fun_t *fun)
|
|---|
| 151 | {
|
|---|
| 152 | return hcd_ddf_device_offline(fun);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| [b5f813c] | 155 | static const driver_ops_t uhci_driver_ops = {
|
|---|
| 156 | .dev_add = uhci_dev_add,
|
|---|
| [c910ecf] | 157 | .fun_online = uhci_fun_online,
|
|---|
| 158 | .fun_offline = uhci_fun_offline
|
|---|
| [b5f813c] | 159 | };
|
|---|
| 160 |
|
|---|
| 161 | static const driver_t uhci_driver = {
|
|---|
| 162 | .name = NAME,
|
|---|
| 163 | .driver_ops = &uhci_driver_ops
|
|---|
| 164 | };
|
|---|
| [fbefd0e] | 165 |
|
|---|
| [76fbd9a] | 166 |
|
|---|
| [17ceb72] | 167 | /** Initialize global driver structures (NONE).
|
|---|
| [a7e2f0d] | 168 | *
|
|---|
| [ea993d18] | 169 | * @param[in] argc Number of arguments in argv vector (ignored).
|
|---|
| [a7e2f0d] | 170 | * @param[in] argv Cmdline argument vector (ignored).
|
|---|
| 171 | * @return Error code.
|
|---|
| 172 | *
|
|---|
| 173 | * Driver debug level is set here.
|
|---|
| 174 | */
|
|---|
| [c7137738] | 175 | int main(int argc, char *argv[])
|
|---|
| 176 | {
|
|---|
| [fbefd0e] | 177 | printf(NAME ": HelenOS UHCI driver.\n");
|
|---|
| [920d0fc] | 178 | log_init(NAME);
|
|---|
| [58ac3ec] | 179 | logctl_set_log_level(NAME, LVL_DEBUG2);
|
|---|
| [eb1a2f4] | 180 | return ddf_driver_main(&uhci_driver);
|
|---|
| [c7137738] | 181 | }
|
|---|
| [c56dbe0] | 182 | /**
|
|---|
| 183 | * @}
|
|---|
| 184 | */
|
|---|