xref: /openbmc/u-boot/drivers/usb/gadget/f_dfu.h (revision 3ebd892f)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * f_dfu.h -- Device Firmware Update gadget
4  *
5  * Copyright (C) 2011-2012 Samsung Electronics
6  * author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
7  */
8 
9 #ifndef __F_DFU_H_
10 #define __F_DFU_H_
11 
12 #include <linux/compiler.h>
13 #include <linux/usb/composite.h>
14 
15 #define DFU_CONFIG_VAL			1
16 #define DFU_DT_FUNC			0x21
17 
18 #define DFU_BIT_WILL_DETACH		(0x1 << 3)
19 #define DFU_BIT_MANIFESTATION_TOLERANT	(0x1 << 2)
20 #define DFU_BIT_CAN_UPLOAD		(0x1 << 1)
21 #define DFU_BIT_CAN_DNLOAD		0x1
22 
23 /* big enough to hold our biggest descriptor */
24 #define DFU_USB_BUFSIZ			4096
25 
26 #define USB_REQ_DFU_DETACH		0x00
27 #define USB_REQ_DFU_DNLOAD		0x01
28 #define USB_REQ_DFU_UPLOAD		0x02
29 #define USB_REQ_DFU_GETSTATUS		0x03
30 #define USB_REQ_DFU_CLRSTATUS		0x04
31 #define USB_REQ_DFU_GETSTATE		0x05
32 #define USB_REQ_DFU_ABORT		0x06
33 
34 #define DFU_STATUS_OK			0x00
35 #define DFU_STATUS_errTARGET		0x01
36 #define DFU_STATUS_errFILE		0x02
37 #define DFU_STATUS_errWRITE		0x03
38 #define DFU_STATUS_errERASE		0x04
39 #define DFU_STATUS_errCHECK_ERASED	0x05
40 #define DFU_STATUS_errPROG		0x06
41 #define DFU_STATUS_errVERIFY		0x07
42 #define DFU_STATUS_errADDRESS		0x08
43 #define DFU_STATUS_errNOTDONE		0x09
44 #define DFU_STATUS_errFIRMWARE		0x0a
45 #define DFU_STATUS_errVENDOR		0x0b
46 #define DFU_STATUS_errUSBR		0x0c
47 #define DFU_STATUS_errPOR		0x0d
48 #define DFU_STATUS_errUNKNOWN		0x0e
49 #define DFU_STATUS_errSTALLEDPKT	0x0f
50 
51 #define RET_STALL			-1
52 #define RET_ZLP				0
53 
54 enum dfu_state {
55 	DFU_STATE_appIDLE		= 0,
56 	DFU_STATE_appDETACH		= 1,
57 	DFU_STATE_dfuIDLE		= 2,
58 	DFU_STATE_dfuDNLOAD_SYNC	= 3,
59 	DFU_STATE_dfuDNBUSY		= 4,
60 	DFU_STATE_dfuDNLOAD_IDLE	= 5,
61 	DFU_STATE_dfuMANIFEST_SYNC	= 6,
62 	DFU_STATE_dfuMANIFEST		= 7,
63 	DFU_STATE_dfuMANIFEST_WAIT_RST	= 8,
64 	DFU_STATE_dfuUPLOAD_IDLE	= 9,
65 	DFU_STATE_dfuERROR		= 10,
66 };
67 
68 struct dfu_status {
69 	__u8				bStatus;
70 	__u8				bwPollTimeout[3];
71 	__u8				bState;
72 	__u8				iString;
73 } __packed;
74 
75 struct dfu_function_descriptor {
76 	__u8				bLength;
77 	__u8				bDescriptorType;
78 	__u8				bmAttributes;
79 	__le16				wDetachTimeOut;
80 	__le16				wTransferSize;
81 	__le16				bcdDFUVersion;
82 } __packed;
83 
84 #define DFU_POLL_TIMEOUT_MASK           (0xFFFFFFUL)
85 #endif /* __F_DFU_H_ */
86