source: mainline/uspace/drv/uhci-hcd/iface.c@ 063ead6f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 063ead6f was 357a302, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

USB interfaces reorganization

The most important change is that getting USB address of a device
is an operation of generic USB interface, not USB-HC interface.
That is needed for proper functionality of a MID driver.

Also added sample implementation of USB interface operations as is
needed by most drivers (sample does not mean unfunctional or partially
implemented here).
They are stored in libusb/ddfiface.h

Updated UHCI, UHCI-RH, hub, VHC drivers to use these sample
implementations.

Updated libusb device recognition routines to route get_address requests
through USB interface.

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky, 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/** @addtogroup usb
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
34#include <driver.h>
35#include <remote_usbhc.h>
36
37#include <usb/debug.h>
38
39#include <errno.h>
40
41#include "iface.h"
42#include "uhci.h"
43
44/*----------------------------------------------------------------------------*/
45static int reserve_default_address(device_t *dev, usb_speed_t speed)
46{
47 assert(dev);
48 uhci_t *hc = dev_to_uhci(dev);
49 assert(hc);
50 usb_address_keeping_reserve_default(&hc->address_manager);
51 return EOK;
52}
53/*----------------------------------------------------------------------------*/
54static int release_default_address(device_t *dev)
55{
56 assert(dev);
57 uhci_t *hc = dev_to_uhci(dev);
58 assert(hc);
59 usb_address_keeping_release_default(&hc->address_manager);
60 return EOK;
61}
62/*----------------------------------------------------------------------------*/
63static int request_address(device_t *dev, usb_speed_t speed,
64 usb_address_t *address)
65{
66 assert(dev);
67 uhci_t *hc = dev_to_uhci(dev);
68 assert(hc);
69 *address = usb_address_keeping_request(&hc->address_manager);
70 if (*address <= 0)
71 return *address;
72 return EOK;
73}
74/*----------------------------------------------------------------------------*/
75static int bind_address(
76 device_t *dev, usb_address_t address, devman_handle_t handle)
77{
78 assert(dev);
79 uhci_t *hc = dev_to_uhci(dev);
80 assert(hc);
81 usb_address_keeping_devman_bind(&hc->address_manager, address, handle);
82 return EOK;
83}
84/*----------------------------------------------------------------------------*/
85static int release_address(device_t *dev, usb_address_t address)
86{
87 assert(dev);
88 uhci_t *hc = dev_to_uhci(dev);
89 assert(hc);
90 usb_address_keeping_release_default(&hc->address_manager);
91 return EOK;
92}
93/*----------------------------------------------------------------------------*/
94static int interrupt_out(device_t *dev, usb_target_t target,
95 size_t max_packet_size,
96 void *data, size_t size,
97 usbhc_iface_transfer_out_callback_t callback, void *arg)
98{
99 dev_speed_t speed = FULL_SPEED;
100
101 batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
102 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
103 if (!batch)
104 return ENOMEM;
105 batch_interrupt_out(batch);
106 return EOK;
107}
108/*----------------------------------------------------------------------------*/
109static int interrupt_in(device_t *dev, usb_target_t target,
110 size_t max_packet_size,
111 void *data, size_t size,
112 usbhc_iface_transfer_in_callback_t callback, void *arg)
113{
114 dev_speed_t speed = FULL_SPEED;
115
116 batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
117 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
118 if (!batch)
119 return ENOMEM;
120 batch_interrupt_in(batch);
121 return EOK;
122}
123/*----------------------------------------------------------------------------*/
124static int control_write(device_t *dev, usb_target_t target,
125 size_t max_packet_size,
126 void *setup_data, size_t setup_size, void *data, size_t size,
127 usbhc_iface_transfer_out_callback_t callback, void *arg)
128{
129 dev_speed_t speed = FULL_SPEED;
130
131 batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
132 max_packet_size, speed, data, size, setup_data, setup_size,
133 NULL, callback, arg);
134 if (!batch)
135 return ENOMEM;
136 batch_control_write(batch);
137 return EOK;
138}
139/*----------------------------------------------------------------------------*/
140static int control_read(device_t *dev, usb_target_t target,
141 size_t max_packet_size,
142 void *setup_data, size_t setup_size, void *data, size_t size,
143 usbhc_iface_transfer_in_callback_t callback, void *arg)
144{
145 dev_speed_t speed = FULL_SPEED;
146
147 batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
148 max_packet_size, speed, data, size, setup_data, setup_size, callback,
149 NULL, arg);
150 if (!batch)
151 return ENOMEM;
152 batch_control_read(batch);
153 return EOK;
154}
155
156
157/*----------------------------------------------------------------------------*/
158usbhc_iface_t uhci_iface = {
159 .reserve_default_address = reserve_default_address,
160 .release_default_address = release_default_address,
161 .request_address = request_address,
162 .bind_address = bind_address,
163 .release_address = release_address,
164
165 .interrupt_out = interrupt_out,
166 .interrupt_in = interrupt_in,
167
168 .control_read = control_read,
169 .control_write = control_write,
170};
171/**
172 * @}
173 */
Note: See TracBrowser for help on using the repository browser.