lin
2025-01-10 2e0fe69425adee0529756dc3381ac1838197f3ac
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
/*
 * (C) Copyright 2007-2013
 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
 * Jerry Wang <wangflord@allwinnertech.com>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 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
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */
#ifndef  __USB_BASE_H__
#define  __USB_BASE_H__
 
#include <common.h>
#include <malloc.h>
#include <asm/arch/usb.h>
#include <usbdevice.h>
#include <usb_defs.h>
#include "usb_module.h"
#include "usb_status.h"
#include <spare_head.h>
 
 
//#define SUNXI_USB_DEBUG
#undef SUNXI_USB_DEBUG
 
#ifdef SUNXI_USB_DEBUG
#   define sunxi_usb_dbg(fmt,args...)    printf(fmt ,##args)
#else
#   define sunxi_usb_dbg(fmt,args...)
#endif
 
 
//-----------------------------------------------------------------------------
//   数据结构
//-----------------------------------------------------------------------------
#if defined(SUNXI_USB_30)
typedef struct sunxi_udc
{
   u32 address;        /* device address, that host distribute */
   int speed;            /* flag. is high speed?                 */
 
   int ep0_control_step;
   int eps_bulk_step;
 
   struct usb_device_request *standard_reg;
}
sunxi_udc_t;
 
#else
//-----------------------------------------------------------------------------
//   usb3.0控制器 数据结构
//-----------------------------------------------------------------------------
typedef struct sunxi_udc
{
    __hdle usbc_hd;
 
   u32 address;        /* device address, that host distribute */
   int speed;            /* flag. is high speed?                 */
 
   u32 bulk_ep_max;    /* bulk ep max packet size                 */
   u32 fifo_size;        /* fifo size                             */
   u32 bulk_in_addr;
   u32 bulk_out_addr;
   u32 dma_send_channal;
   u32 dma_recv_channal;
   struct usb_device_request standard_reg;
}
sunxi_udc_t;
#endif
 
#define CBWCDBLENGTH    16
#ifndef CBWSIGNATURE
#define CBWSIGNATURE    (0x43425355)
#endif
 
#ifndef CSWSIGNATURE
#define CSWSIGNATURE    (0x53425355)
#endif
 
/* Command Block Wrapper */
struct umass_bbb_cbw_t
{
   __u32        dCBWSignature;
   __u32        dCBWTag;
   __u32        dCBWDataTransferLength;
   __u8        bCBWFlags;
   __u8        bCBWLUN;
   __u8        bCDBLength;
   __u8        CBWCDB[CBWCDBLENGTH];
}__attribute__ ((packed));
 
 
/* Command Status Wrapper */
struct umass_bbb_csw_t
{
   __u32        dCSWSignature;
   __u32        dCSWTag;
   __u32        dCSWDataResidue;
   __u8        bCSWStatus;
}__attribute__ ((packed));
 
 
#define  SUNXI_USB_RX_BUFFER_COUNT             (1)
 
 
 
typedef struct sunxi_ubuf_s
{
   uchar *rx_base_buffer;
   uchar *rx_req_buffer;            //bulk传输的请求阶段buffer
   uint   rx_req_length;            //bulk传输的请求阶段数据长度
 
   uint   rx_ready_for_data;        //表示数据接收已经完成标志
 
   uint   request_size;            //需要发送的数据长度
}
sunxi_ubuf_t;
 
 
extern  void sunxi_udc_ep_reset(void);
 
extern  int sunxi_udc_start_recv_by_dma(void* mem_buf, uint length);
 
extern  void sunxi_udc_send_setup(uint bLength, void *buffer);
extern  int  sunxi_udc_send_data(void *buffer, unsigned int buffer_size);
 
 
extern  int sunxi_udc_set_address(uchar address);
extern  int sunxi_udc_set_configuration(int config_param);
 
extern    int sunxi_udc_get_ep_max(void);
extern  int sunxi_udc_get_ep_in_type(void);
extern  int sunxi_udc_get_ep_out_type(void);
 
#endif