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