source: mainline/uspace/drv/bus/usb/vhc/hub/hub.h

Last change on this file was 09ab0a9a, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix vertical spacing with new Ccheck revision.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2010 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 drvusbvhc
30 * @{
31 */
32/** @file
33 * @brief Representation of an USB hub.
34 */
35#ifndef VHC_HUB_HUB_H_
36#define VHC_HUB_HUB_H_
37
38#include <fibril_synch.h>
39
40#ifndef HUB_PORT_COUNT
41#define HUB_PORT_COUNT 2
42#endif
43#define BITS2BYTES(bits) (bits ? ((((bits)-1)>>3)+1) : 0)
44
45/** Hub port internal state.
46 * Some states (e.g. port over current) are not covered as they are not
47 * simulated at all.
48 */
49typedef enum {
50 HUB_PORT_STATE_UNKNOWN,
51 HUB_PORT_STATE_NOT_CONFIGURED,
52 HUB_PORT_STATE_POWERED_OFF,
53 HUB_PORT_STATE_DISCONNECTED,
54 HUB_PORT_STATE_DISABLED,
55 HUB_PORT_STATE_RESETTING,
56 HUB_PORT_STATE_ENABLED,
57 HUB_PORT_STATE_SUSPENDED,
58 HUB_PORT_STATE_RESUMING,
59 /* HUB_PORT_STATE_, */
60} hub_port_state_t;
61
62char hub_port_state_to_char(hub_port_state_t);
63
64/** Hub status change mask bits. */
65typedef enum {
66 HUB_STATUS_C_PORT_CONNECTION = (1 << 0),
67 HUB_STATUS_C_PORT_ENABLE = (1 << 1),
68 HUB_STATUS_C_PORT_SUSPEND = (1 << 2),
69 HUB_STATUS_C_PORT_OVER_CURRENT = (1 << 3),
70 HUB_STATUS_C_PORT_RESET = (1 << 4),
71 /* HUB_STATUS_C_ = (1 << ), */
72} hub_status_change_t;
73
74typedef struct hub hub_t;
75
76/** Hub port information. */
77typedef struct {
78 /** Custom pointer to connected device. */
79 void *connected_device;
80 /** Port index (one based). */
81 size_t index;
82 /** Port state. */
83 hub_port_state_t state;
84 /** Status change bitmap. */
85 uint16_t status_change;
86 /** Containing hub. */
87 hub_t *hub;
88} hub_port_t;
89
90/** Hub device type. */
91struct hub {
92 /** Hub ports. */
93 hub_port_t ports[HUB_PORT_COUNT];
94 /** Custom hub data. */
95 void *custom_data;
96 /** Access guard to the whole hub. */
97 fibril_mutex_t guard;
98 /** Last value of status change bitmap. */
99 bool signal_changes;
100};
101
102void hub_init(hub_t *);
103size_t hub_connect_device(hub_t *, void *);
104errno_t hub_disconnect_device(hub_t *, void *);
105size_t hub_find_device(hub_t *, void *);
106void hub_acquire(hub_t *);
107void hub_release(hub_t *);
108void hub_set_port_state(hub_t *, size_t, hub_port_state_t);
109void hub_set_port_state_all(hub_t *, hub_port_state_t);
110hub_port_state_t hub_get_port_state(hub_t *, size_t);
111void hub_clear_port_status_change(hub_t *, size_t, hub_status_change_t);
112uint16_t hub_get_port_status_change(hub_t *, size_t);
113uint32_t hub_get_port_status(hub_t *, size_t);
114uint8_t hub_get_status_change_bitmap(hub_t *);
115
116#endif
117/**
118 * @}
119 */
Note: See TracBrowser for help on using the repository browser.