source: mainline/uspace/lib/usbhost/include/usb/host/hcd.h@ 9c7ed9c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9c7ed9c was 9c7ed9c, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

libusbhost,hcd: Add generic device_add function.

This will be useful later.
Switch rh initialization to use this function.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2011 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
29/** @addtogroup libusbhost
30 * @{
31 */
32/** @file
33 *
34 */
35
36#ifndef LIBUSBHOST_HOST_HCD_H
37#define LIBUSBHOST_HOST_HCD_H
38
39#include <assert.h>
40#include <adt/list.h>
41#include <usbhc_iface.h>
42
43#include <usb/host/usb_device_manager.h>
44#include <usb/host/usb_endpoint_manager.h>
45#include <usb/host/usb_transfer_batch.h>
46
47typedef struct hcd hcd_t;
48
49typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
50typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *);
51typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *);
52
53/** Generic host controller driver structure. */
54struct hcd {
55 /** Device manager storing handles and addresses. */
56 usb_device_manager_t dev_manager;
57 /** Endpoint manager. */
58 usb_endpoint_manager_t ep_manager;
59 /** Added devices */
60 list_t devices;
61
62 /** Device specific driver data. */
63 void *private_data;
64 /** Transfer scheduling, implement in device driver. */
65 schedule_hook_t schedule;
66 /** Hook called upon registering new endpoint. */
67 ep_add_hook_t ep_add_hook;
68 /** Hook called upon removing of an endpoint. */
69 ep_remove_hook_t ep_remove_hook;
70};
71
72
73/** Initialize hcd_t structure.
74 * Initializes device and endpoint managers. Sets data and hook pointer to NULL.
75 * @param hcd hcd_t structure to initialize, non-null.
76 * @param bandwidth Available bandwidth, passed to endpoint manager.
77 * @param bw_count Bandwidth compute function, passed to endpoint manager.
78 */
79static inline void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
80 bw_count_func_t bw_count)
81{
82 assert(hcd);
83 usb_device_manager_init(&hcd->dev_manager, max_speed);
84 usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);
85 list_initialize(&hcd->devices);
86
87 hcd->private_data = NULL;
88 hcd->schedule = NULL;
89 hcd->ep_add_hook = NULL;
90 hcd->ep_remove_hook = NULL;
91}
92
93static inline void hcd_set_implementation(hcd_t *hcd, void *data,
94 schedule_hook_t schedule, ep_add_hook_t add_hook, ep_remove_hook_t rem_hook)
95{
96 assert(hcd);
97 hcd->private_data = data;
98 hcd->schedule = schedule;
99 hcd->ep_add_hook = add_hook;
100 hcd->ep_remove_hook = rem_hook;
101
102}
103
104/** Check registered endpoints and reset toggle bit if necessary.
105 * @param hcd hcd_t structure, non-null.
106 * @param target Control communication target.
107 * @param setup_data Setup packet of the control communication.
108 */
109static inline void reset_ep_if_need(hcd_t *hcd, usb_target_t target,
110 const char setup_data[8])
111{
112 assert(hcd);
113 usb_endpoint_manager_reset_eps_if_need(
114 &hcd->ep_manager, target, (const uint8_t *)setup_data);
115}
116
117
118int hcd_add_device(hcd_t *instance, ddf_dev_t *parent,
119 usb_address_t address, usb_speed_t speed, const char *name,
120 const match_id_list_t *mids);
121
122int hcd_setup_device(ddf_dev_t *device);
123int hcd_setup_hub(hcd_t *instance, usb_address_t *address, ddf_dev_t *dev);
124
125hcd_t *dev_to_hcd(ddf_dev_t *dev);
126
127/** Data retrieve wrapper.
128 * @param fun ddf function, non-null.
129 * @return pointer cast to hcd_t*.
130 */
131static inline hcd_t *fun_to_hcd(ddf_fun_t *fun)
132{
133 return ddf_fun_data_get(fun);
134}
135
136
137extern usbhc_iface_t hcd_iface;
138
139#endif
140
141/**
142 * @}
143 */
Note: See TracBrowser for help on using the repository browser.