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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7265558 was 5203e256, checked in by Martin Decky <martin@…>, 14 years ago

keep the drivers source tree tidy by using logical subdirectories

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[b8507a1]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
[bd8c753d]29/** @addtogroup drvusbvhc
[b8507a1]30 * @{
31 */
32/** @file
[70e5ad5]33 * @brief Representation of an USB hub.
[b8507a1]34 */
[774afaae]35#ifndef VHC_HUB_HUB_H_
36#define VHC_HUB_HUB_H_
[b8507a1]37
[1e32a63]38#include <fibril_synch.h>
[b8507a1]39
[95622c4]40#ifndef HUB_PORT_COUNT
[774afaae]41#define HUB_PORT_COUNT 2
[95622c4]42#endif
[774afaae]43#define BITS2BYTES(bits) (bits ? ((((bits)-1)>>3)+1) : 0)
[b8507a1]44
[355f7c2]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 */
[b8507a1]49typedef enum {
[774afaae]50 HUB_PORT_STATE_UNKNOWN,
[b8507a1]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
[774afaae]62char hub_port_state_to_char(hub_port_state_t);
[355f7c2]63
64/** Hub status change mask bits. */
[6c741e1d]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
[6cb58e6]74typedef struct hub hub_t;
75
[355f7c2]76/** Hub port information. */
[b8507a1]77typedef struct {
[70e5ad5]78 /** Custom pointer to connected device. */
[774afaae]79 void *connected_device;
[70e5ad5]80 /** Port index (one based). */
[774afaae]81 size_t index;
[70e5ad5]82 /** Port state. */
[b8507a1]83 hub_port_state_t state;
[70e5ad5]84 /** Status change bitmap. */
[6c741e1d]85 uint16_t status_change;
[6cb58e6]86 /** Containing hub. */
87 hub_t *hub;
[b8507a1]88} hub_port_t;
89
[355f7c2]90/** Hub device type. */
[6cb58e6]91struct hub {
[70e5ad5]92 /** Hub ports. */
[b8507a1]93 hub_port_t ports[HUB_PORT_COUNT];
[70e5ad5]94 /** Custom hub data. */
[774afaae]95 void *custom_data;
[70e5ad5]96 /** Access guard to the whole hub. */
[774afaae]97 fibril_mutex_t guard;
[6cb58e6]98 /** Last value of status change bitmap. */
99 bool signal_changes;
100};
[b8507a1]101
[774afaae]102void hub_init(hub_t *);
103size_t hub_connect_device(hub_t *, void *);
[68a68705]104int hub_disconnect_device(hub_t *, void *);
[774afaae]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 *);
[6c741e1d]115
116
[b8507a1]117#endif
118/**
119 * @}
120 */
Note: See TracBrowser for help on using the repository browser.