| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
|---|
| 3 | * Copyright (c) 2011 Jan Vesely
|
|---|
| 4 | * Copyright (c) 2017 Ondra Hlavaty
|
|---|
| 5 | * All rights reserved.
|
|---|
| 6 | *
|
|---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 8 | * modification, are permitted provided that the following conditions
|
|---|
| 9 | * are met:
|
|---|
| 10 | *
|
|---|
| 11 | * - Redistributions of source code must retain the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 13 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 15 | * documentation and/or other materials provided with the distribution.
|
|---|
| 16 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 17 | * derived from this software without specific prior written permission.
|
|---|
| 18 | *
|
|---|
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 | /** @addtogroup drvusbhub
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 | /** @file
|
|---|
| 35 | * Hub port state machine.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #ifndef DRV_USBHUB_PORT_H
|
|---|
| 39 | #define DRV_USBHUB_PORT_H
|
|---|
| 40 |
|
|---|
| 41 | #include <usb/dev/driver.h>
|
|---|
| 42 | #include <usb/classes/hub.h>
|
|---|
| 43 |
|
|---|
| 44 | typedef struct usb_hub_dev usb_hub_dev_t;
|
|---|
| 45 |
|
|---|
| 46 | typedef enum {
|
|---|
| 47 | PORT_DISABLED, /* No device connected. */
|
|---|
| 48 | PORT_CONNECTED, /* A device connected, not yet initialized. */
|
|---|
| 49 | PORT_IN_RESET, /* An initial port reset in progress. */
|
|---|
| 50 | PORT_ENABLED, /* Port reset complete, port enabled. Device announced to the HC. */
|
|---|
| 51 | PORT_ERROR, /* An error occured. There is still a fibril that needs to know it. */
|
|---|
| 52 | } port_state_t;
|
|---|
| 53 |
|
|---|
| 54 | /** Information about single port on a hub. */
|
|---|
| 55 | typedef struct {
|
|---|
| 56 | /* Parenting hub */
|
|---|
| 57 | usb_hub_dev_t *hub;
|
|---|
| 58 | /** Guarding all fields */
|
|---|
| 59 | fibril_mutex_t guard;
|
|---|
| 60 | /** Current state of the port */
|
|---|
| 61 | port_state_t state;
|
|---|
| 62 | /** A speed of the device connected (if any). Valid unless state == PORT_DISABLED. */
|
|---|
| 63 | usb_speed_t speed;
|
|---|
| 64 | /** Port number as reported in descriptors. */
|
|---|
| 65 | unsigned int port_number;
|
|---|
| 66 | /** CV for waiting to port reset completion. */
|
|---|
| 67 | fibril_condvar_t state_cv;
|
|---|
| 68 | } usb_hub_port_t;
|
|---|
| 69 |
|
|---|
| 70 | void usb_hub_port_init(usb_hub_port_t *, usb_hub_dev_t *, unsigned int);
|
|---|
| 71 | void usb_hub_port_fini(usb_hub_port_t *);
|
|---|
| 72 |
|
|---|
| 73 | void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_dev_t *hub);
|
|---|
| 74 |
|
|---|
| 75 | #endif
|
|---|
| 76 |
|
|---|
| 77 | /**
|
|---|
| 78 | * @}
|
|---|
| 79 | */
|
|---|