[c7137738] | 1 | /*
|
---|
[d4a829e] | 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 |
|
---|
[b5f813c] | 51 | static int uhci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool);
|
---|
| 52 | static void uhci_driver_fini(hcd_t *);
|
---|
| 53 | static int disable_legacy(ddf_dev_t *);
|
---|
[76fbd9a] | 54 |
|
---|
[b5f813c] | 55 | static const ddf_hc_driver_t uhci_hc_driver = {
|
---|
| 56 | .claim = disable_legacy,
|
---|
| 57 | .hc_speed = USB_SPEED_FULL,
|
---|
| 58 | .irq_code_gen = uhci_hc_gen_irq_code,
|
---|
| 59 | .init = uhci_driver_init,
|
---|
| 60 | .fini = uhci_driver_fini,
|
---|
| 61 | .name = "UHCI",
|
---|
| 62 | .ops = {
|
---|
| 63 | .schedule = uhci_hc_schedule,
|
---|
| 64 | .irq_hook = uhci_hc_interrupt,
|
---|
| 65 | .status_hook = uhci_hc_status,
|
---|
| 66 | },
|
---|
[36a4738] | 67 | };
|
---|
[76fbd9a] | 68 |
|
---|
[1a0fa29c] | 69 | static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
|
---|
| 70 | {
|
---|
| 71 | assert(hcd);
|
---|
[b5f813c] | 72 | assert(hcd_get_driver_data(hcd) == NULL);
|
---|
[1a0fa29c] | 73 |
|
---|
| 74 | hc_t *instance = malloc(sizeof(hc_t));
|
---|
| 75 | if (!instance)
|
---|
| 76 | return ENOMEM;
|
---|
| 77 |
|
---|
[a25d893] | 78 | const int ret = hc_init(instance, res, irq);
|
---|
[55346870] | 79 | if (ret == EOK) {
|
---|
[b5f813c] | 80 | hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops);
|
---|
[55346870] | 81 | } else {
|
---|
| 82 | free(instance);
|
---|
| 83 | }
|
---|
[1a0fa29c] | 84 | return ret;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | static void uhci_driver_fini(hcd_t *hcd)
|
---|
| 88 | {
|
---|
| 89 | assert(hcd);
|
---|
[b5f813c] | 90 | hc_t *hc = hcd_get_driver_data(hcd);
|
---|
| 91 | if (hc)
|
---|
| 92 | hc_fini(hc);
|
---|
[1a0fa29c] | 93 |
|
---|
[b5f813c] | 94 | hcd_set_implementation(hcd, NULL, NULL);
|
---|
| 95 | free(hc);
|
---|
[1a0fa29c] | 96 | }
|
---|
| 97 |
|
---|
[e3a07bba] | 98 | /** Call the PCI driver with a request to clear legacy support register
|
---|
| 99 | *
|
---|
| 100 | * @param[in] device Device asking to disable interrupts
|
---|
| 101 | * @return Error code.
|
---|
| 102 | */
|
---|
| 103 | static int disable_legacy(ddf_dev_t *device)
|
---|
| 104 | {
|
---|
| 105 | assert(device);
|
---|
| 106 |
|
---|
[d15797d] | 107 | async_sess_t *parent_sess = ddf_dev_parent_sess_get(device);
|
---|
| 108 | if (parent_sess == NULL)
|
---|
[e3a07bba] | 109 | return ENOMEM;
|
---|
| 110 |
|
---|
| 111 | /* See UHCI design guide page 45 for these values.
|
---|
| 112 | * Write all WC bits in USB legacy register */
|
---|
[53a309e] | 113 | return pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
|
---|
[e3a07bba] | 114 | }
|
---|
[76fbd9a] | 115 |
|
---|
[17ceb72] | 116 | /** Initialize a new ddf driver instance for uhci hc and hub.
|
---|
[a7e2f0d] | 117 | *
|
---|
| 118 | * @param[in] device DDF instance of the device to initialize.
|
---|
| 119 | * @return Error code.
|
---|
| 120 | */
|
---|
[b5f813c] | 121 | static int uhci_dev_add(ddf_dev_t *device)
|
---|
[86341e2] | 122 | {
|
---|
[0c0f823b] | 123 | usb_log_debug2("uhci_dev_add() called\n");
|
---|
[9351353] | 124 | assert(device);
|
---|
[a799708] | 125 | return hcd_ddf_add_hc(device, &uhci_hc_driver);
|
---|
[c7137738] | 126 | }
|
---|
[ea993d18] | 127 |
|
---|
[b5f813c] | 128 | static const driver_ops_t uhci_driver_ops = {
|
---|
| 129 | .dev_add = uhci_dev_add,
|
---|
| 130 | };
|
---|
| 131 |
|
---|
| 132 | static const driver_t uhci_driver = {
|
---|
| 133 | .name = NAME,
|
---|
| 134 | .driver_ops = &uhci_driver_ops
|
---|
| 135 | };
|
---|
[fbefd0e] | 136 |
|
---|
[76fbd9a] | 137 |
|
---|
[17ceb72] | 138 | /** Initialize global driver structures (NONE).
|
---|
[a7e2f0d] | 139 | *
|
---|
[ea993d18] | 140 | * @param[in] argc Number of arguments in argv vector (ignored).
|
---|
[a7e2f0d] | 141 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
| 142 | * @return Error code.
|
---|
| 143 | *
|
---|
| 144 | * Driver debug level is set here.
|
---|
| 145 | */
|
---|
[c7137738] | 146 | int main(int argc, char *argv[])
|
---|
| 147 | {
|
---|
[fbefd0e] | 148 | printf(NAME ": HelenOS UHCI driver.\n");
|
---|
[920d0fc] | 149 | log_init(NAME);
|
---|
[b74ec299] | 150 | logctl_set_log_level(NAME, LVL_NOTE);
|
---|
[eb1a2f4] | 151 | return ddf_driver_main(&uhci_driver);
|
---|
[c7137738] | 152 | }
|
---|
[c56dbe0] | 153 | /**
|
---|
| 154 | * @}
|
---|
| 155 | */
|
---|