Skip to content

Commit 515bbbd

Browse files
committed
Revert "Revert "usb: rockchip: add the rockusb gadget""
This reverts commit 7a4b754.
1 parent 6baca5b commit 515bbbd

File tree

5 files changed

+833
-1
lines changed

5 files changed

+833
-1
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* (C) Copyright 2017
3+
*
4+
* Eddie Cai <[email protected]>
5+
*
6+
* SPDX-License-Identifier: GPL-2.0+
7+
*/
8+
9+
#ifndef _F_ROCKUSB_H_
10+
#define _F_ROCKUSB_H_
11+
#include <blk.h>
12+
13+
#define ROCKUSB_VERSION "0.1"
14+
15+
#define ROCKUSB_INTERFACE_CLASS 0xff
16+
#define ROCKUSB_INTERFACE_SUB_CLASS 0x06
17+
#define ROCKUSB_INTERFACE_PROTOCOL 0x05
18+
19+
#define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_2_0 (0x0200)
20+
#define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_1_1 (0x0040)
21+
#define TX_ENDPOINT_MAXIMUM_PACKET_SIZE (0x0040)
22+
23+
#define EP_BUFFER_SIZE 4096
24+
/*
25+
* EP_BUFFER_SIZE must always be an integral multiple of maxpacket size
26+
* (64 or 512 or 1024), else we break on certain controllers like DWC3
27+
* that expect bulk OUT requests to be divisible by maxpacket size.
28+
*/
29+
30+
#define CONFIG_ROCKUSB_BUF_ADDR CONFIG_SYS_LOAD_ADDR
31+
#define CONFIG_ROCKUSB_BUF_SIZE 0x08000000
32+
33+
#define RKUSB_STATUS_IDLE 0
34+
#define RKUSB_STATUS_CMD 1
35+
#define RKUSB_STATUS_RXDATA 2
36+
#define RKUSB_STATUS_TXDATA 3
37+
#define RKUSB_STATUS_CSW 4
38+
#define RKUSB_STATUS_RXDATA_PREPARE 5
39+
#define RKUSB_STATUS_TXDATA_PREPARE 6
40+
41+
enum rkusb_command {
42+
K_FW_TEST_UNIT_READY = 0x00,
43+
K_FW_READ_FLASH_ID = 0x01,
44+
K_FW_SET_DEVICE_ID = 0x02,
45+
K_FW_TEST_BAD_BLOCK = 0x03,
46+
K_FW_READ_10 = 0x04,
47+
K_FW_WRITE_10 = 0x05,
48+
K_FW_ERASE_10 = 0x06,
49+
K_FW_WRITE_SPARE = 0x07,
50+
K_FW_READ_SPARE = 0x08,
51+
52+
K_FW_ERASE_10_FORCE = 0x0b,
53+
K_FW_GET_VERSION = 0x0c,
54+
55+
K_FW_LBA_READ_10 = 0x14,
56+
K_FW_LBA_WRITE_10 = 0x15,
57+
K_FW_ERASE_SYS_DISK = 0x16,
58+
K_FW_SDRAM_READ_10 = 0x17,
59+
K_FW_SDRAM_WRITE_10 = 0x18,
60+
K_FW_SDRAM_EXECUTE = 0x19,
61+
K_FW_READ_FLASH_INFO = 0x1A,
62+
K_FW_GET_CHIP_VER = 0x1B,
63+
K_FW_LOW_FORMAT = 0x1C,
64+
K_FW_SET_RESET_FLAG = 0x1E,
65+
K_FW_SPI_READ_10 = 0x21,
66+
K_FW_SPI_WRITE_10 = 0x22,
67+
68+
K_FW_SESSION = 0X30,
69+
K_FW_RESET = 0xff,
70+
};
71+
72+
#define CBW_DIRECTION_OUT 0x00
73+
#define CBW_DIRECTION_IN 0x80
74+
75+
struct cmd_dispatch_info {
76+
enum rkusb_command cmd;
77+
/* call back function to handle rockusb command */
78+
void (*cb)(struct usb_ep *ep, struct usb_request *req);
79+
};
80+
81+
/* Bulk-only data structures */
82+
83+
/* Command Block Wrapper */
84+
struct fsg_bulk_cb_wrap {
85+
__le32 signature; /* Contains 'USBC' */
86+
u32 tag; /* Unique per command id */
87+
__le32 data_transfer_length; /* Size of the data */
88+
u8 flags; /* Direction in bit 7 */
89+
u8 lun; /* lun (normally 0) */
90+
u8 length; /* Of the CDB, <= MAX_COMMAND_SIZE */
91+
u8 CDB[16]; /* Command Data Block */
92+
};
93+
94+
#define USB_BULK_CB_WRAP_LEN 31
95+
#define USB_BULK_CB_SIG 0x43425355 /* Spells out USBC */
96+
#define USB_BULK_IN_FLAG 0x80
97+
98+
/* Command status Wrapper */
99+
struct bulk_cs_wrap {
100+
__le32 signature; /* Should = 'USBS' */
101+
u32 tag; /* Same as original command */
102+
__le32 residue; /* Amount not transferred */
103+
u8 status; /* See below */
104+
};
105+
106+
#define USB_BULK_CS_WRAP_LEN 13
107+
#define USB_BULK_CS_SIG 0x53425355 /* Spells out 'USBS' */
108+
#define USB_STATUS_PASS 0
109+
#define USB_STATUS_FAIL 1
110+
#define USB_STATUS_PHASE_ERROR 2
111+
112+
#define CSW_GOOD 0x00
113+
#define CSW_FAIL 0x01
114+
115+
struct f_rockusb {
116+
struct usb_function usb_function;
117+
struct usb_ep *in_ep, *out_ep;
118+
struct usb_request *in_req, *out_req;
119+
char *rockusb_dev_type;
120+
unsigned int rockusb_dev_index;
121+
unsigned int download_tag;
122+
unsigned int download_lba;
123+
unsigned int download_size;
124+
unsigned int download_bytes;
125+
struct blk_desc *download_desc;
126+
int reboot_flag;
127+
};
128+
129+
/* init rockusb device, tell rockusb which device you want to read/write*/
130+
void rockusb_dev_init(char *dev_type, int dev_index);
131+
#endif /* _F_ROCKUSB_H_ */
132+

drivers/usb/dwc3/gadget.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
11231123
dwc3_stop_active_transfer(dwc, dep->number, true);
11241124
goto out1;
11251125
}
1126-
dev_err(dwc->dev, "request %p was not queued to %s\n",
1126+
dev_vdbg(dwc->dev, "request %p was not queued to %s\n",
11271127
request, ep->name);
11281128
ret = -EINVAL;
11291129
goto out0;

drivers/usb/gadget/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ config G_DNL_VENDOR_NUM
119119
config G_DNL_PRODUCT_NUM
120120
hex "Product ID of USB device"
121121

122+
config USB_FUNCTION_ROCKUSB
123+
bool "Enable USB rockusb gadget"
124+
help
125+
Rockusb protocol is widely used by Rockchip SoC based devices. It can
126+
read/write info, image to/from devices. This enables the USB part of
127+
the rockusb gadget.for more detail about Rockusb protocol, please see
128+
doc/README.rockusb
129+
122130
config USBNET_DEVADDR
123131
string "USB Gadget Ethernet device mac address"
124132
default "de:ad:be:ef:00:01"

drivers/usb/gadget/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o
2929
obj-$(CONFIG_USB_FUNCTION_DFU) += f_dfu.o
3030
obj-$(CONFIG_USB_FUNCTION_MASS_STORAGE) += f_mass_storage.o
3131
obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o
32+
obj-$(CONFIG_USB_FUNCTION_ROCKUSB) += f_rockusb.o
3233
obj-$(CONFIG_USB_FUNCTION_SDP) += f_sdp.o
3334
endif
3435
endif

0 commit comments

Comments
 (0)