[56fb3732] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
---|
[56bdd9a4] | 3 | * Copyright (c) 2011 Jan Vesely
|
---|
[e0a5d4c] | 4 | * Copyright (c) 2018 Michal Staruch, Ondrej Hlavaty
|
---|
[56fb3732] | 5 | * All rights reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * - Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | * documentation and/or other materials provided with the distribution.
|
---|
| 16 | * - The name of the author may not be used to endorse or promote products
|
---|
| 17 | * derived from this software without specific prior written permission.
|
---|
| 18 | *
|
---|
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | /** @addtogroup libdrv
|
---|
| 32 | * @{
|
---|
| 33 | */
|
---|
| 34 | /** @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <async.h>
|
---|
[90c340fb] | 38 | #include <assert.h>
|
---|
[9be30cdf] | 39 | #include <macros.h>
|
---|
[56fb3732] | 40 | #include <errno.h>
|
---|
[e938fa6] | 41 | #include <devman.h>
|
---|
[56fb3732] | 42 |
|
---|
| 43 | #include "usb_iface.h"
|
---|
[eb1a2f4] | 44 | #include "ddf/driver.h"
|
---|
[56fb3732] | 45 |
|
---|
[56bdd9a4] | 46 |
|
---|
[94fbf78] | 47 | usb_dev_session_t *usb_dev_connect(devman_handle_t handle)
|
---|
[56bdd9a4] | 48 | {
|
---|
[b4b534ac] | 49 | return devman_device_connect(handle, IPC_FLAG_BLOCKING);
|
---|
[94fbf78] | 50 | }
|
---|
[56bdd9a4] | 51 |
|
---|
[94fbf78] | 52 | usb_dev_session_t *usb_dev_connect_to_self(ddf_dev_t *dev)
|
---|
[e938fa6] | 53 | {
|
---|
[ae3a941] | 54 | return devman_parent_device_connect(ddf_dev_get_handle(dev),
|
---|
| 55 | IPC_FLAG_BLOCKING);
|
---|
[e938fa6] | 56 | }
|
---|
| 57 |
|
---|
[71384bd3] | 58 | void usb_dev_disconnect(usb_dev_session_t *sess)
|
---|
[e938fa6] | 59 | {
|
---|
| 60 | if (sess)
|
---|
| 61 | async_hangup(sess);
|
---|
[56bdd9a4] | 62 | }
|
---|
[a76b01b4] | 63 |
|
---|
[56bdd9a4] | 64 | typedef enum {
|
---|
[c280d7e] | 65 | IPC_M_USB_GET_MY_DESCRIPTION,
|
---|
[56bdd9a4] | 66 | } usb_iface_funcs_t;
|
---|
| 67 |
|
---|
| 68 | /** Tell interface number given device can use.
|
---|
| 69 | * @param[in] exch IPC communication exchange
|
---|
| 70 | * @param[in] handle Id of the device
|
---|
| 71 | * @param[out] usb_iface Assigned USB interface
|
---|
| 72 | * @return Error code.
|
---|
| 73 | */
|
---|
[5a6cc679] | 74 | errno_t usb_get_my_description(async_exch_t *exch, usb_device_desc_t *desc)
|
---|
[56bdd9a4] | 75 | {
|
---|
| 76 | if (!exch)
|
---|
[8afeb04] | 77 | return EBADMEM;
|
---|
[a76b01b4] | 78 |
|
---|
[c280d7e] | 79 | usb_device_desc_t tmp_desc;
|
---|
| 80 |
|
---|
[5a6cc679] | 81 | const errno_t ret = async_req_1_5(exch, DEV_IFACE_ID(USB_DEV_IFACE),
|
---|
[c280d7e] | 82 | IPC_M_USB_GET_MY_DESCRIPTION,
|
---|
| 83 | (sysarg_t *) &tmp_desc.address,
|
---|
[2aaba7e] | 84 | (sysarg_t *) &tmp_desc.depth,
|
---|
[c280d7e] | 85 | (sysarg_t *) &tmp_desc.speed,
|
---|
| 86 | &tmp_desc.handle,
|
---|
| 87 | (sysarg_t *) &tmp_desc.iface);
|
---|
| 88 | if (ret == EOK && desc)
|
---|
| 89 | *desc = tmp_desc;
|
---|
[9d15d1b] | 90 | return ret;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[ae3a941] | 93 | static void remote_usb_get_my_description(ddf_fun_t *, void *,
|
---|
| 94 | ipc_callid_t, ipc_call_t *);
|
---|
[56fb3732] | 95 |
|
---|
| 96 | /** Remote USB interface operations. */
|
---|
[9be30cdf] | 97 | static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
|
---|
[c280d7e] | 98 | [IPC_M_USB_GET_MY_DESCRIPTION] = remote_usb_get_my_description,
|
---|
[56fb3732] | 99 | };
|
---|
| 100 |
|
---|
| 101 | /** Remote USB interface structure.
|
---|
| 102 | */
|
---|
[7f80313] | 103 | const remote_iface_t remote_usb_iface = {
|
---|
[9be30cdf] | 104 | .method_count = ARRAY_SIZE(remote_usb_iface_ops),
|
---|
[e938fa6] | 105 | .methods = remote_usb_iface_ops,
|
---|
[56fb3732] | 106 | };
|
---|
| 107 |
|
---|
[c280d7e] | 108 | void remote_usb_get_my_description(ddf_fun_t *fun, void *iface,
|
---|
[357a302] | 109 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 110 | {
|
---|
[56bdd9a4] | 111 | const usb_iface_t *usb_iface = (usb_iface_t *) iface;
|
---|
[357a302] | 112 |
|
---|
[c280d7e] | 113 | if (usb_iface->get_my_description == NULL) {
|
---|
[357a302] | 114 | async_answer_0(callid, ENOTSUP);
|
---|
| 115 | return;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[c280d7e] | 118 | usb_device_desc_t desc;
|
---|
[5a6cc679] | 119 | const errno_t ret = usb_iface->get_my_description(fun, &desc);
|
---|
[56bdd9a4] | 120 | if (ret != EOK) {
|
---|
| 121 | async_answer_0(callid, ret);
|
---|
[357a302] | 122 | } else {
|
---|
[2aaba7e] | 123 | async_answer_5(callid, EOK,
|
---|
[c280d7e] | 124 | (sysarg_t) desc.address,
|
---|
[2aaba7e] | 125 | (sysarg_t) desc.depth,
|
---|
[c280d7e] | 126 | (sysarg_t) desc.speed,
|
---|
| 127 | desc.handle,
|
---|
| 128 | desc.iface);
|
---|
[357a302] | 129 | }
|
---|
| 130 | }
|
---|
[a76b01b4] | 131 |
|
---|
[56fb3732] | 132 | /**
|
---|
| 133 | * @}
|
---|
| 134 | */
|
---|