[e40b9f00] | 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 | {
|
---|
| 59 | CHECK_CONNECTION(connection);
|
---|
| 60 |
|
---|
| 61 | return async_req_1_0(connection->hc_phone,
|
---|
| 62 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 63 | IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /** Tell host controller to release default address.
|
---|
| 67 | *
|
---|
| 68 | * @param connection Opened connection to host controller.
|
---|
| 69 | * @return Error code.
|
---|
| 70 | */
|
---|
| 71 | int usb_hc_release_default_address(usb_hc_connection_t *connection)
|
---|
| 72 | {
|
---|
| 73 | CHECK_CONNECTION(connection);
|
---|
| 74 |
|
---|
| 75 | return async_req_1_0(connection->hc_phone,
|
---|
| 76 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 77 | IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | /** Ask host controller for free address assignment.
|
---|
| 81 | *
|
---|
| 82 | * @param connection Opened connection to host controller.
|
---|
| 83 | * @return Assigned USB address or negative error code.
|
---|
| 84 | */
|
---|
| 85 | usb_address_t usb_hc_request_address(usb_hc_connection_t *connection)
|
---|
| 86 | {
|
---|
| 87 | CHECK_CONNECTION(connection);
|
---|
| 88 |
|
---|
| 89 | sysarg_t address;
|
---|
| 90 | int rc = async_req_1_1(connection->hc_phone,
|
---|
| 91 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 92 | IPC_M_USBHC_REQUEST_ADDRESS, &address);
|
---|
| 93 | if (rc != EOK) {
|
---|
| 94 | return (usb_address_t) rc;
|
---|
| 95 | } else {
|
---|
| 96 | return (usb_address_t) address;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | /** Inform host controller about new device.
|
---|
| 101 | *
|
---|
| 102 | * @param connection Opened connection to host controller.
|
---|
| 103 | * @param attached_device Information about the new device.
|
---|
| 104 | * @return Error code.
|
---|
| 105 | */
|
---|
| 106 | int usb_hc_register_device(usb_hc_connection_t * connection,
|
---|
| 107 | const usb_hc_attached_device_t *attached_device)
|
---|
| 108 | {
|
---|
| 109 | CHECK_CONNECTION(connection);
|
---|
| 110 | if (attached_device == NULL) {
|
---|
| 111 | return EBADMEM;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | return async_req_3_0(connection->hc_phone,
|
---|
| 115 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 116 | IPC_M_USBHC_BIND_ADDRESS,
|
---|
| 117 | attached_device->address, attached_device->handle);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /** Inform host controller about device removal.
|
---|
| 121 | *
|
---|
| 122 | * @param connection Opened connection to host controller.
|
---|
| 123 | * @param address Address of the device that is being removed.
|
---|
| 124 | * @return Error code.
|
---|
| 125 | */
|
---|
| 126 | int usb_hc_unregister_device(usb_hc_connection_t *connection,
|
---|
| 127 | usb_address_t address)
|
---|
| 128 | {
|
---|
| 129 | CHECK_CONNECTION(connection);
|
---|
| 130 |
|
---|
| 131 | return async_req_2_0(connection->hc_phone,
|
---|
| 132 | DEV_IFACE_ID(USBHC_DEV_IFACE),
|
---|
| 133 | IPC_M_USBHC_RELEASE_ADDRESS, address);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | /**
|
---|
| 138 | * @}
|
---|
| 139 | */
|
---|