[816175a2] | 1 | /*
|
---|
[4125b7d] | 2 | * Copyright (c) 2011 Jan Vesely
|
---|
[816175a2] | 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 | */
|
---|
[79ae36dd] | 28 |
|
---|
[f123909] | 29 | /** @addtogroup drvusbuhcirh
|
---|
[c56dbe0] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[f123909] | 33 | * @brief UHCI root hub initialization routines
|
---|
[c56dbe0] | 34 | */
|
---|
[79ae36dd] | 35 |
|
---|
[eb1a2f4] | 36 | #include <ddf/driver.h>
|
---|
[6cbe7dad] | 37 | #include <devman.h>
|
---|
[89e061d] | 38 | #include <device/hw_res_parsed.h>
|
---|
[275bf456] | 39 | #include <errno.h>
|
---|
[fbefd0e] | 40 | #include <str_error.h>
|
---|
[563ead9] | 41 |
|
---|
[c56dbe0] | 42 | #include <usb_iface.h>
|
---|
[357a302] | 43 | #include <usb/ddfiface.h>
|
---|
[275bf456] | 44 | #include <usb/debug.h>
|
---|
[c56dbe0] | 45 |
|
---|
[1256a0a] | 46 | #include "root_hub.h"
|
---|
| 47 |
|
---|
[497b6f31] | 48 | #define NAME "uhcirh"
|
---|
[f9c03b5] | 49 |
|
---|
[7de1988c] | 50 | static int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs);
|
---|
[79ae36dd] | 51 |
|
---|
[0c0f823b] | 52 | static int uhci_rh_dev_add(ddf_dev_t *device);
|
---|
[79ae36dd] | 53 |
|
---|
[f9c03b5] | 54 | static driver_ops_t uhci_rh_driver_ops = {
|
---|
[0c0f823b] | 55 | .dev_add = uhci_rh_dev_add,
|
---|
[1256a0a] | 56 | };
|
---|
[79ae36dd] | 57 |
|
---|
[f9c03b5] | 58 | static driver_t uhci_rh_driver = {
|
---|
| 59 | .name = NAME,
|
---|
| 60 | .driver_ops = &uhci_rh_driver_ops
|
---|
[816175a2] | 61 | };
|
---|
[79ae36dd] | 62 |
|
---|
[f9c03b5] | 63 | /** Initialize global driver structures (NONE).
|
---|
| 64 | *
|
---|
| 65 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
---|
| 66 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
| 67 | * @return Error code.
|
---|
| 68 | *
|
---|
| 69 | * Driver debug level is set here.
|
---|
| 70 | */
|
---|
| 71 | int main(int argc, char *argv[])
|
---|
| 72 | {
|
---|
| 73 | printf(NAME ": HelenOS UHCI root hub driver.\n");
|
---|
[920d0fc] | 74 | log_init(NAME);
|
---|
[f9c03b5] | 75 | return ddf_driver_main(&uhci_rh_driver);
|
---|
| 76 | }
|
---|
[79ae36dd] | 77 |
|
---|
[f123909] | 78 | /** Initialize a new ddf driver instance of UHCI root hub.
|
---|
[275bf456] | 79 | *
|
---|
| 80 | * @param[in] device DDF instance of the device to initialize.
|
---|
| 81 | * @return Error code.
|
---|
| 82 | */
|
---|
[0c0f823b] | 83 | static int uhci_rh_dev_add(ddf_dev_t *device)
|
---|
[1256a0a] | 84 | {
|
---|
| 85 | if (!device)
|
---|
[f9c03b5] | 86 | return EINVAL;
|
---|
[816175a2] | 87 |
|
---|
[0c0f823b] | 88 | usb_log_debug2("uhci_rh_dev_add(handle=%" PRIun ")\n",
|
---|
[56fd7cf] | 89 | ddf_dev_get_handle(device));
|
---|
[eb1a2f4] | 90 |
|
---|
[7de1988c] | 91 | addr_range_t regs;
|
---|
[f9c03b5] | 92 | uhci_root_hub_t *rh = NULL;
|
---|
[c53007f] | 93 | int rc;
|
---|
[f9c03b5] | 94 |
|
---|
[7de1988c] | 95 | rc = hc_get_my_registers(device, ®s);
|
---|
[c53007f] | 96 | if (rc != EOK) {
|
---|
| 97 | usb_log_error( "Failed to get registers from HC: %s.\n",
|
---|
| 98 | str_error(rc));
|
---|
| 99 | return rc;
|
---|
| 100 | }
|
---|
[f9c03b5] | 101 |
|
---|
[4125b7d] | 102 | usb_log_debug("I/O regs at %p (size %zuB).\n",
|
---|
[7de1988c] | 103 | RNGABSPTR(regs), RNGSZ(regs));
|
---|
[f9c03b5] | 104 |
|
---|
[56fd7cf] | 105 | rh = ddf_dev_data_alloc(device, sizeof(uhci_root_hub_t));
|
---|
[c53007f] | 106 | if (rh == NULL) {
|
---|
| 107 | usb_log_error("Failed to allocate rh driver instance.\n");
|
---|
| 108 | return ENOMEM;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[7de1988c] | 111 | rc = uhci_root_hub_init(rh, ®s, device);
|
---|
[c53007f] | 112 | if (rc != EOK) {
|
---|
| 113 | usb_log_error("Failed(%d) to initialize rh driver instance: "
|
---|
| 114 | "%s.\n", rc, str_error(rc));
|
---|
| 115 | return rc;
|
---|
| 116 | }
|
---|
[7ce0fe3] | 117 |
|
---|
[4125b7d] | 118 | usb_log_info("Controlling root hub '%s' (%" PRIun ").\n",
|
---|
[56fd7cf] | 119 | ddf_dev_get_name(device), ddf_dev_get_handle(device));
|
---|
[c53007f] | 120 |
|
---|
[1256a0a] | 121 | return EOK;
|
---|
| 122 | }
|
---|
[79ae36dd] | 123 |
|
---|
[275bf456] | 124 | /** Get address of I/O registers.
|
---|
| 125 | *
|
---|
| 126 | * @param[in] dev Device asking for the addresses.
|
---|
[7de1988c] | 127 | * @param[out] io_regs_p Pointer to the device's register range.
|
---|
[275bf456] | 128 | * @return Error code.
|
---|
| 129 | */
|
---|
[7de1988c] | 130 | int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p)
|
---|
[6cbe7dad] | 131 | {
|
---|
[79ae36dd] | 132 | async_sess_t *parent_sess =
|
---|
[56fd7cf] | 133 | devman_parent_device_connect(EXCHANGE_SERIALIZE,
|
---|
| 134 | ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
|
---|
[79ae36dd] | 135 | if (!parent_sess)
|
---|
| 136 | return ENOMEM;
|
---|
[89e061d] | 137 |
|
---|
| 138 | hw_res_list_parsed_t hw_res;
|
---|
| 139 | hw_res_list_parsed_init(&hw_res);
|
---|
[5b89d43b] | 140 | const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
|
---|
[89e061d] | 141 | async_hangup(parent_sess);
|
---|
[f9c03b5] | 142 | if (ret != EOK) {
|
---|
| 143 | return ret;
|
---|
[6cbe7dad] | 144 | }
|
---|
[89e061d] | 145 |
|
---|
| 146 | if (hw_res.io_ranges.count != 1) {
|
---|
| 147 | hw_res_list_parsed_clean(&hw_res);
|
---|
| 148 | return EINVAL;
|
---|
[6cbe7dad] | 149 | }
|
---|
[89e061d] | 150 |
|
---|
[7de1988c] | 151 | if (io_regs_p != NULL)
|
---|
| 152 | *io_regs_p = hw_res.io_ranges.ranges[0];
|
---|
[89e061d] | 153 |
|
---|
| 154 | hw_res_list_parsed_clean(&hw_res);
|
---|
[f9c03b5] | 155 | return EOK;
|
---|
[6cbe7dad] | 156 | }
|
---|
[79ae36dd] | 157 |
|
---|
[c56dbe0] | 158 | /**
|
---|
| 159 | * @}
|
---|
| 160 | */
|
---|