| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
|---|
| 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 libusb
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * Functions needed by hub drivers.
|
|---|
| 34 | */
|
|---|
| 35 | #include <usb/hub.h>
|
|---|
| 36 | #include <usbhc_iface.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 |
|
|---|
| 39 | /** Check that HC connection is alright.
|
|---|
| 40 | *
|
|---|
| 41 | * @param conn Connection to be checked.
|
|---|
| 42 | */
|
|---|
| 43 | #define CHECK_CONNECTION(conn) \
|
|---|
| 44 | do { \
|
|---|
| 45 | assert((conn)); \
|
|---|
| 46 | if (!usb_hc_connection_is_opened((conn))) { \
|
|---|
| 47 | return ENOENT; \
|
|---|
| 48 | } \
|
|---|
| 49 | } while (false)
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | /** Tell host controller to reserve default address.
|
|---|
| 53 | *
|
|---|
| 54 | * @param connection Opened connection to host controller.
|
|---|
| 55 | * @return Error code.
|
|---|
| 56 | */
|
|---|
| 57 | int usb_hc_reserve_default_address(usb_hc_connection_t *connection,
|
|---|
| 58 | bool full_speed)
|
|---|
| 59 | {
|
|---|
| 60 | CHECK_CONNECTION(connection);
|
|---|
| 61 |
|
|---|
| 62 | return async_req_2_0(connection->hc_phone,
|
|---|
| 63 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
|---|
| 64 | IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS, full_speed);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | /** Tell host controller to release default address.
|
|---|
| 68 | *
|
|---|
| 69 | * @param connection Opened connection to host controller.
|
|---|
| 70 | * @return Error code.
|
|---|
| 71 | */
|
|---|
| 72 | int usb_hc_release_default_address(usb_hc_connection_t *connection)
|
|---|
| 73 | {
|
|---|
| 74 | CHECK_CONNECTION(connection);
|
|---|
| 75 |
|
|---|
| 76 | return async_req_1_0(connection->hc_phone,
|
|---|
| 77 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
|---|
| 78 | IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /** Ask host controller for free address assignment.
|
|---|
| 82 | *
|
|---|
| 83 | * @param connection Opened connection to host controller.
|
|---|
| 84 | * @return Assigned USB address or negative error code.
|
|---|
| 85 | */
|
|---|
| 86 | usb_address_t usb_hc_request_address(usb_hc_connection_t *connection,
|
|---|
| 87 | bool full_speed)
|
|---|
| 88 | {
|
|---|
| 89 | CHECK_CONNECTION(connection);
|
|---|
| 90 |
|
|---|
| 91 | sysarg_t address;
|
|---|
| 92 | int rc = async_req_2_1(connection->hc_phone,
|
|---|
| 93 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
|---|
| 94 | IPC_M_USBHC_REQUEST_ADDRESS, full_speed,
|
|---|
| 95 | &address);
|
|---|
| 96 | if (rc != EOK) {
|
|---|
| 97 | return (usb_address_t) rc;
|
|---|
| 98 | } else {
|
|---|
| 99 | return (usb_address_t) address;
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | /** Inform host controller about new device.
|
|---|
| 104 | *
|
|---|
| 105 | * @param connection Opened connection to host controller.
|
|---|
| 106 | * @param attached_device Information about the new device.
|
|---|
| 107 | * @return Error code.
|
|---|
| 108 | */
|
|---|
| 109 | int usb_hc_register_device(usb_hc_connection_t * connection,
|
|---|
| 110 | const usb_hc_attached_device_t *attached_device)
|
|---|
| 111 | {
|
|---|
| 112 | CHECK_CONNECTION(connection);
|
|---|
| 113 | if (attached_device == NULL) {
|
|---|
| 114 | return EBADMEM;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | return async_req_3_0(connection->hc_phone,
|
|---|
| 118 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
|---|
| 119 | IPC_M_USBHC_BIND_ADDRESS,
|
|---|
| 120 | attached_device->address, attached_device->handle);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | /** Inform host controller about device removal.
|
|---|
| 124 | *
|
|---|
| 125 | * @param connection Opened connection to host controller.
|
|---|
| 126 | * @param address Address of the device that is being removed.
|
|---|
| 127 | * @return Error code.
|
|---|
| 128 | */
|
|---|
| 129 | int usb_hc_unregister_device(usb_hc_connection_t *connection,
|
|---|
| 130 | usb_address_t address)
|
|---|
| 131 | {
|
|---|
| 132 | CHECK_CONNECTION(connection);
|
|---|
| 133 |
|
|---|
| 134 | return async_req_2_0(connection->hc_phone,
|
|---|
| 135 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
|---|
| 136 | IPC_M_USBHC_RELEASE_ADDRESS, address);
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | /**
|
|---|
| 141 | * @}
|
|---|
| 142 | */
|
|---|