summaryrefslogtreecommitdiff
path: root/bsp/allwinner/libraries/sunxi-hal/hal/source/usb/include/usb_host_hub.h
blob: 9c4802a4937191f46484e2fe6b5fb73f14c70dc0 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#ifndef __USB_HOST_HUB_H__
#define __USB_HOST_HUB_H__
/*
 * Hub protocol and driver data structures.
 *
 * Some of these are known to the "virtual root hub" code
 * in host controller drivers.
 */


#include <hal_osal.h>
#include "usb_host_common.h"

/*
 * Hub request types
 */

#define USB_RT_HUB  (USB_TYPE_CLASS | USB_RECIP_DEVICE)
#define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)

/*
 * Hub class requests
 * See USB 2.0 spec Table 11-16
 */
#define HUB_CLEAR_TT_BUFFER             8
#define HUB_RESET_TT                    9
#define HUB_GET_TT_STATE                10
#define HUB_STOP_TT                     11

/*
 * Hub Class feature numbers
 * See USB 2.0 spec Table 11-17
 */
#define C_HUB_LOCAL_POWER               0
#define C_HUB_OVER_CURRENT              1

/*
 * Port feature numbers
 * See USB 2.0 spec Table 11-17
 */
#define USB_PORT_FEAT_CONNECTION        0
#define USB_PORT_FEAT_ENABLE            1
#define USB_PORT_FEAT_SUSPEND           2
#define USB_PORT_FEAT_OVER_CURRENT      3
#define USB_PORT_FEAT_RESET             4
#define USB_PORT_FEAT_POWER             8
#define USB_PORT_FEAT_LOWSPEED          9
#define USB_PORT_FEAT_HIGHSPEED         10
#define USB_PORT_FEAT_C_CONNECTION      16
#define USB_PORT_FEAT_C_ENABLE          17
#define USB_PORT_FEAT_C_SUSPEND         18
#define USB_PORT_FEAT_C_OVER_CURRENT    19
#define USB_PORT_FEAT_C_RESET           20
#define USB_PORT_FEAT_TEST              21
#define USB_PORT_FEAT_INDICATOR         22

/*
 * wPortStatus bit field
 * See USB 2.0 spec Table 11-21
 */
#define USB_PORT_STAT_CONNECTION        0x0001  //当前的连接状态
#define USB_PORT_STAT_ENABLE            0x0002
#define USB_PORT_STAT_SUSPEND           0x0004
#define USB_PORT_STAT_OVERCURRENT       0x0008
#define USB_PORT_STAT_RESET             0x0010

/* bits 5 to 7 are reserved */
#define USB_PORT_STAT_POWER             0x0100
#define USB_PORT_STAT_LOW_SPEED         0x0200
#define USB_PORT_STAT_HIGH_SPEED        0x0400
#define USB_PORT_STAT_TEST              0x0800
#define USB_PORT_STAT_INDICATOR         0x1000

/* bits 13 to 15 are reserved */

/*
 * wPortChange bit field
 * See USB 2.0 spec Table 11-22
 * Bits 0 to 4 shown, bits 5 to 15 are reserved
 */
#define USB_PORT_STAT_C_CONNECTION      0x0001  //连接状态变化
#define USB_PORT_STAT_C_ENABLE          0x0002
#define USB_PORT_STAT_C_SUSPEND         0x0004
#define USB_PORT_STAT_C_OVERCURRENT     0x0008
#define USB_PORT_STAT_C_RESET           0x0010

/*
 * wHubCharacteristics (masks)
 * See USB 2.0 spec Table 11-13, offset 3
 */
#define HUB_CHAR_LPSM                   0x0003 /* D1 .. D0 */
#define HUB_CHAR_COMPOUND               0x0004 /* D2       */
#define HUB_CHAR_OCPM                   0x0018 /* D4 .. D3 */
#define HUB_CHAR_TTTT                   0x0060 /* D6 .. D5 */
#define HUB_CHAR_PORTIND                0x0080 /* D7       */



/*
 * Hub Status & Hub Change bit masks
 * See USB 2.0 spec Table 11-19 and Table 11-20
 * Bits 0 and 1 for wHubStatus and wHubChange
 * Bits 2 to 15 are reserved for both
 */
#define HUB_STATUS_LOCAL_POWER          0x0001
#define HUB_STATUS_OVERCURRENT          0x0002

#define HUB_CHANGE_LOCAL_POWER          0x0001
#define HUB_CHANGE_OVERCURRENT          0x0002


/*
 * Hub descriptor
 * See USB 2.0 spec Table 11-13
 */

#define USB_DT_HUB                      (USB_TYPE_CLASS | 0x09)
#define USB_DT_HUB_NONVAR_SIZE          7


/*
 * Hub Status and Hub Change results
 * See USB 2.0 spec Table 11-19 and Table 11-20
 */
struct __attribute__((packed)) usb_port_status
{
    __u16 wPortStatus;
    __u16 wPortChange;
} ;


struct __attribute__((packed)) usb_hub_status
{
    __u16 wHubStatus;
    __u16 wHubChange;
};


struct __attribute__((packed)) usb_hub_descriptor
{
    __u8  bDescLength;
    __u8  bDescriptorType;
    __u8  bNbrPorts;
    __u16 wHubCharacteristics;
    __u8  bPwrOn2PwrGood;
    __u8  bHubContrCurrent;

    /* add 1 bit for hub status change; round to bytes */
    __u8  DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
    __u8  PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
} ;


/* port indicator status selectors, tables 11-7 and 11-25 */
#define HUB_LED_AUTO            0
#define HUB_LED_AMBER           1
#define HUB_LED_GREEN           2
#define HUB_LED_OFF             3

enum hub_led_mode
{
    INDICATOR_AUTO = 0,
    INDICATOR_CYCLE,
    /* software blinks for attention:  software, hardware, reserved */
    INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,
    INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,
    INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
};

struct usb_host_virt_dev;

/*
 * As of USB 2.0, full/low speed devices are segregated into trees.
 * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
 * The other type grows from high speed hubs when they connect to
 * full/low speed devices using "Transaction Translators" (TTs).
 *
 * TTs should only be known to the hub driver, and high speed bus
 * drivers (only EHCI for now).  They affect periodic scheduling and
 * sometimes control/bulk error recovery.
 */
struct usb_tt
{
    struct usb_host_virt_dev    *hub;   /* upstream highspeed hub */
    int multi;                          /* true means one TT per port */

    /* for control/bulk error recovery (CLEAR_TT_BUFFER) */
    __u32 lock;
    struct list_head clear_list;        /* of usb_tt_clear */
    //struct work_struct kevent;
};

struct usb_tt_clear
{
    struct list_head clear_list;
    unsigned tt;
    u16 devinfo;
};

/// extern void usb_hub_tt_clear_buffer (struct usb_host_virt_dev *dev, int pipe);
#define STATUS_URB_BUFF_LEN         8
struct usb_hub
{
    //struct device     *intfdev;   /* the "interface" device */
    struct usb_host_virt_dev *hdev;
    struct urb *urb;                //就是用来查询status的urb//for interrupt polling pipe

    /* buffer for urb ... with extra space in case of babble */
    //char (*buffer)[8];        //是status urb和 hub交互status的中介
    char status_urb_ubff[STATUS_URB_BUFF_LEN];
    u32 buffer_dma;                 /* DMA address for buffer */

    union
    {
        struct usb_hub_status   hub;
        struct usb_port_status  port;
    } *status;                      /* buffer for status reports    */

    int error;                      /* last reported error          */
    int nerrors;                    /* track consecutive errors     */

    //  struct list_head    event_list; /* hubs w/data or errs ready    */
    u32 event_bits[1];              /* status change bitmask        */
    u32 change_bits[1];             /* ports with logical connect status change */
    u32 busy_bits[1];               /* ports being reset            */

    struct usb_hub_descriptor *descriptor;  /* class descriptor         */
    struct usb_tt tt;                       /* Transaction Translator   */

    u8 power_budget;                        /* in 2mA units; or zero    */

    unsigned quiescing: 1;
    unsigned activating: 1;
    unsigned resume_root_hub: 1;

    unsigned has_indicators: 1;
    enum hub_led_mode indicator[USB_MAXCHILDREN];
    //struct work_struct    leds;

    //USB_OS_KERNEL_EVENT *HubStatusSemi;     /* hub status thread的睡眠和唤醒 */
    //USB_OS_KERNEL_EVENT *notify_complete;   /* 同步thread创建/删除           */
    hal_sem_t   HubStatusSemi;     /* hub status thread的睡眠和唤醒 */
    hal_sem_t   notify_complete;   /* 同步thread创建/删除           */

    rt_thread_t thread;
    __u32 HubStatusThrdId;                  /* hub线程ID                     */
    __u8 HubRemove;                         /* flag. Hub是否拔出             */
    __u32 hub_req_busy;                     /* 正在发送urb请求               */
};


#endif