| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 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 |
|
|---|
| 29 | /** @addtogroup libusbhost
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | *
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <errno.h>
|
|---|
| 37 | #include <str_error.h>
|
|---|
| 38 | #include <usb/debug.h>
|
|---|
| 39 |
|
|---|
| 40 | #include <usb/host/hcd.h>
|
|---|
| 41 |
|
|---|
| 42 | /** Announce root hub to the DDF
|
|---|
| 43 | *
|
|---|
| 44 | * @param[in] instance OHCI driver instance
|
|---|
| 45 | * @param[in] hub_fun DDF function representing OHCI root hub
|
|---|
| 46 | * @return Error code
|
|---|
| 47 | */
|
|---|
| 48 | int hcd_register_hub(hcd_t *instance, usb_address_t *address, ddf_fun_t *hub_fun)
|
|---|
| 49 | {
|
|---|
| 50 | assert(instance);
|
|---|
| 51 | assert(address);
|
|---|
| 52 | assert(hub_fun);
|
|---|
| 53 |
|
|---|
| 54 | int ret = usb_device_manager_request_address(
|
|---|
| 55 | &instance->dev_manager, address, false,
|
|---|
| 56 | USB_SPEED_FULL);
|
|---|
| 57 | if (ret != EOK) {
|
|---|
| 58 | usb_log_error("Failed to get root hub address: %s\n",
|
|---|
| 59 | str_error(ret));
|
|---|
| 60 | return ret;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | #define CHECK_RET_UNREG_RETURN(ret, message...) \
|
|---|
| 64 | if (ret != EOK) { \
|
|---|
| 65 | usb_log_error(message); \
|
|---|
| 66 | usb_endpoint_manager_remove_ep( \
|
|---|
| 67 | &instance->ep_manager, *address, 0, \
|
|---|
| 68 | USB_DIRECTION_BOTH, NULL, NULL); \
|
|---|
| 69 | usb_device_manager_release_address( \
|
|---|
| 70 | &instance->dev_manager, *address); \
|
|---|
| 71 | return ret; \
|
|---|
| 72 | } else (void)0
|
|---|
| 73 |
|
|---|
| 74 | ret = usb_endpoint_manager_add_ep(
|
|---|
| 75 | &instance->ep_manager, *address, 0,
|
|---|
| 76 | USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64,
|
|---|
| 77 | 0, NULL, NULL);
|
|---|
| 78 | CHECK_RET_UNREG_RETURN(ret,
|
|---|
| 79 | "Failed to register root hub control endpoint: %s.\n",
|
|---|
| 80 | str_error(ret));
|
|---|
| 81 |
|
|---|
| 82 | ret = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
|
|---|
| 83 | CHECK_RET_UNREG_RETURN(ret,
|
|---|
| 84 | "Failed to add root hub match-id: %s.\n", str_error(ret));
|
|---|
| 85 |
|
|---|
| 86 | ret = ddf_fun_bind(hub_fun);
|
|---|
| 87 | CHECK_RET_UNREG_RETURN(ret,
|
|---|
| 88 | "Failed to bind root hub function: %s.\n", str_error(ret));
|
|---|
| 89 |
|
|---|
| 90 | ret = usb_device_manager_bind_address(&instance->dev_manager,
|
|---|
| 91 | *address, ddf_fun_get_handle(hub_fun));
|
|---|
| 92 | if (ret != EOK)
|
|---|
| 93 | usb_log_warning("Failed to bind root hub address: %s.\n",
|
|---|
| 94 | str_error(ret));
|
|---|
| 95 |
|
|---|
| 96 | return EOK;
|
|---|
| 97 | #undef CHECK_RET_UNREG_RETURN
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | /**
|
|---|
| 101 | * @}
|
|---|
| 102 | */
|
|---|