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