summaryrefslogtreecommitdiff
path: root/bsp/phytium/libraries/standalone/drivers/usb/fusb_generic_hub.h
blob: da3bd6cc2d862081866d473b7ec6505f9e77b0fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright : (C) 2022 Phytium Information Technology, Inc.
 * All Rights Reserved.
 *
 * This program is OPEN SOURCE software: you can redistribute it and/or modify it
 * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
 * either version 1.0 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the Phytium Public License for more details.
 *
 *
 * FilePath: fusb_generic_hub.h
 * Date: 2022-02-11 13:33:11
 * LastEditTime: 2022-02-18 09:20:23
 * Description:  This files is for definition of generic hub function
 *
 * Modify History:
 *  Ver   Who        Date         Changes
 * ----- ------     --------    --------------------------------------
 * 1.0   Zhugengyu  2022/2/7    init commit
 */

#ifndef  DRIVERS_FUSB_GENERIC_HUB_H
#define  DRIVERS_FUSB_GENERIC_HUB_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "fusb_private.h"

typedef struct
{
    /* negative results denote an error */

    /* returns 1 if the hub's status changed since the last call (optional) */
    FUsbTransCode(*hub_status_changed)(FUsbDev *);
    /* returns 1 if the port's status changed since the last call */
    FUsbTransCode(*port_status_changed)(FUsbDev *, int port);
    /* returns 1 if something is connected to the port */
    FUsbTransCode(*port_connected)(FUsbDev *, int port);
    /* returns 1 if port is currently resetting */
    FUsbTransCode(*port_in_reset)(FUsbDev *, int port);
    /* returns 1 if the port is enabled */
    FUsbTransCode(*port_enabled)(FUsbDev *, int port);
    /* returns speed if port is enabled, negative value if not */
    FUsbSpeed(*port_speed)(FUsbDev *, int port);

    /* enables (powers up) a port (optional) */
    FUsbTransCode(*enable_port)(FUsbDev *, int port);
    /* disables (powers down) a port (optional) */
    FUsbTransCode(*disable_port)(FUsbDev *, int port);
    /* starts a port reset (required if reset_port is set to a generic one from below) */
    FUsbTransCode(*start_port_reset)(FUsbDev *, int port);

    /* performs a port reset (optional, generic implementations below) */
    FUsbTransCode(*reset_port)(FUsbDev *, int port);
} FUsbGenericHubOps;

typedef struct
{
    int num_ports;
    /* port numbers are always 1 based,
       so we waste one int for convenience */
    int *ports; /* allocated to sizeof(*ports)*(num_ports+1) */
#define FUSB_NO_DEV_ADDR -1

    const FUsbGenericHubOps *ops;

    void *data;
} FUsbGenericHub;

void FUsbGenericHubDestory(FUsbDev *);
int FUsbGenericHubWaitForPort(FUsbDev *const dev, const int port,
                              const int wait_for,
                              int (*const port_op)(FUsbDev *, int),
                              int timeout_steps, const int step_us);
int  FUsbGenericHubResetPort(FUsbDev *, int port);
int  FUsbGenericHubScanPort(FUsbDev *, int port);
/* the provided generic_hub_ops struct has to be static */
int FUsbGenericHubInit(FUsbDev *, int num_ports, const FUsbGenericHubOps *);

#define FUSB_GEN_HUB_GET(FUsbDev) ((FUsbGenericHub *)(FUsbDev)->data)

#ifdef __cplusplus
}
#endif


#endif