xref: /rk3399_rockchip-uboot/include/rockusb.h (revision a6c9ff8691383a19143bc7d99d254cffe997e9a3)
1 /*
2  * Copyright 2017 Rockchip Electronics Co., Ltd
3  * Frank Wang <frank.wang@rock-chips.com>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef __ROCKUSB_H__
9 #define __ROCKUSB_H__
10 
11 #include <common.h>
12 #include <part.h>
13 #include <linux/usb/composite.h>
14 
15 enum rkusb_cmd {
16 	RKUSB_TEST_UNIT_READY	= 0x00,
17 	RKUSB_READ_FLASH_ID	= 0x01,
18 	RKUSB_SET_DEVICE_ID	= 0x02,
19 	RKUSB_TEST_BAD_BLOCK	= 0x03,
20 	RKUSB_READ_10		= 0x04,
21 	RKUSB_WRITE_10		= 0x05,
22 	RKUSB_ERASE_10		= 0x06,
23 	RKUSB_WRITE_SPARE	= 0x07,
24 	RKUSB_READ_SPARE	= 0x08,
25 	RKUSB_ERASE_10_FORCE	= 0x0B,
26 	RKUSB_GET_VERSION	= 0x0C,
27 	RKUSB_LBA_READ_10	= 0x14,
28 	RKUSB_LBA_WRITE_10	= 0x15,
29 	RKUSB_ERASE_SYS_DISK	= 0x16,
30 	RKUSB_SDRAM_READ_10	= 0x17,
31 	RKUSB_SDRAM_WRITE_10	= 0x18,
32 	RKUSB_SDRAM_EXECUTE	= 0x19,
33 	RKUSB_READ_FLASH_INFO	= 0x1A,
34 	RKUSB_GET_CHIP_VER	= 0x1B,
35 	RKUSB_LOW_FORMAT	= 0x1C,
36 	RKUSB_SET_RESET_FLAG	= 0x1E,
37 	RKUSB_SPI_READ_10	= 0x21,
38 	RKUSB_SPI_WRITE_10	= 0x22,
39 	RKUSB_LBA_ERASE		= 0x25,
40 	RKUSB_VS_WRITE		= 0x26,
41 	RKUSB_VS_READ		= 0x27,
42 	RKUSB_SWITCH_STORAGE	= 0x2A,
43 	RKUSB_GET_STORAGE_MEDIA = 0x2B,
44 	RKUSB_READ_OTP_DATA	= 0x2C,
45 	RKUSB_READ_CAPACITY	= 0xAA,
46 	RKUSB_SWITCH_USB3	= 0xBB,
47 	RKUSB_RESET		= 0xFF,
48 };
49 
50 enum rkusb_rc {
51 	RKUSB_RC_ERROR		= -1,
52 	RKUSB_RC_CONTINUE	= 0,
53 	RKUSB_RC_FINISHED	= 1,
54 	RKUSB_RC_UNKNOWN_CMND	= 2,
55 };
56 
57 struct fsg_common;
58 
59 #ifdef CONFIG_CMD_ROCKUSB
60 #define IS_RKUSB_UMS_DNL(name)	(!strncmp((name), "rkusb_ums_dnl", 13))
61 
62 int rkusb_do_check_parity(struct fsg_common *common);
63 void rkusb_force_to_usb2(bool enable);
64 bool rkusb_force_usb2_enabled(void);
65 void rkusb_switch_to_usb3_enable(bool enable);
66 bool rkusb_switch_usb3_enabled(void);
67 bool rkusb_usb3_capable(void);
68 
69 #else
70 #define IS_RKUSB_UMS_DNL(name)	0
71 
72 struct fsg_buffhd;
73 struct fsg_dev;
74 struct fsg_common;
75 struct fsg_config;
76 
77 static struct usb_descriptor_header *rkusb_fs_function[];
78 static struct usb_descriptor_header *rkusb_hs_function[];
79 
80 static inline int rkusb_cmd_process(struct fsg_common *common,
81 				    struct fsg_buffhd *bh, int *reply)
82 {
83 	return -EPERM;
84 }
85 
86 static inline int rkusb_do_check_parity(struct fsg_common *common)
87 {
88 	return -EOPNOTSUPP;
89 }
90 
91 static inline void rkusb_force_to_usb2(bool enable)
92 {
93 }
94 
95 static inline bool rkusb_force_usb2_enabled(void)
96 {
97 	return false;
98 }
99 
100 static inline void rkusb_switch_to_usb3_enable(bool enable)
101 {
102 }
103 
104 static inline bool rkusb_switch_usb3_enabled(void)
105 {
106 	return false;
107 }
108 
109 static inline bool rkusb_usb3_capable(void)
110 {
111 	return false;
112 }
113 #endif
114 
115 #ifdef CONFIG_USB_DWC3_GADGET
116 bool dwc3_gadget_is_connected(void);
117 #endif
118 
119 /* Wait at maximum 60 seconds for cable connection */
120 #define RKUSB_CABLE_READY_TIMEOUT	60
121 #define SECTOR_SIZE			0x200
122 
123 #define RKUSB_READ_LIMIT_ADDR	        (32 * 2048)	/* 32MB */
124 
125 struct rockusb {
126 	struct ums *ums;
127 	int ums_cnt;
128 	bool force_usb2;
129 	bool switch_usb3;
130 };
131 
132 #endif /* __ROCKUSB_H__ */
133