xref: /openbmc/u-boot/drivers/usb/gadget/dwc2_udc_otg_priv.h (revision 401c2540445aad08816382c0dc208d2516d90d89)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
2f4d9bd06SMarek Vasut /*
3e179ceddSMarek Vasut  * Designware DWC2 on-chip full/high speed USB device controllers
4f4d9bd06SMarek Vasut  * Copyright (C) 2005 for Samsung Electronics
5f4d9bd06SMarek Vasut  */
6f4d9bd06SMarek Vasut 
7f4d9bd06SMarek Vasut #ifndef __DWC2_UDC_OTG_PRIV__
8f4d9bd06SMarek Vasut #define __DWC2_UDC_OTG_PRIV__
9f4d9bd06SMarek Vasut 
101221ce45SMasahiro Yamada #include <linux/errno.h>
11f4d9bd06SMarek Vasut #include <linux/sizes.h>
12f4d9bd06SMarek Vasut #include <linux/usb/ch9.h>
13f4d9bd06SMarek Vasut #include <linux/usb/gadget.h>
14f4d9bd06SMarek Vasut #include <linux/list.h>
155d5716eeSMarek Vasut #include <usb/dwc2_udc.h>
16f4d9bd06SMarek Vasut 
17f4d9bd06SMarek Vasut /*-------------------------------------------------------------------------*/
18f4d9bd06SMarek Vasut /* DMA bounce buffer size, 16K is enough even for mass storage */
19f4d9bd06SMarek Vasut #define DMA_BUFFER_SIZE	(16*SZ_1K)
20f4d9bd06SMarek Vasut 
21f4d9bd06SMarek Vasut #define EP0_FIFO_SIZE		64
22f4d9bd06SMarek Vasut #define EP_FIFO_SIZE		512
23f4d9bd06SMarek Vasut #define EP_FIFO_SIZE2		1024
24f4d9bd06SMarek Vasut /* ep0-control, ep1in-bulk, ep2out-bulk, ep3in-int */
25507e677bSMarek Vasut #define DWC2_MAX_ENDPOINTS	4
26507e677bSMarek Vasut #define DWC2_MAX_HW_ENDPOINTS	16
27f4d9bd06SMarek Vasut 
28f4d9bd06SMarek Vasut #define WAIT_FOR_SETUP          0
29f4d9bd06SMarek Vasut #define DATA_STATE_XMIT         1
30f4d9bd06SMarek Vasut #define DATA_STATE_NEED_ZLP     2
31f4d9bd06SMarek Vasut #define WAIT_FOR_OUT_STATUS     3
32f4d9bd06SMarek Vasut #define DATA_STATE_RECV         4
33f4d9bd06SMarek Vasut #define WAIT_FOR_COMPLETE	5
34f4d9bd06SMarek Vasut #define WAIT_FOR_OUT_COMPLETE	6
35f4d9bd06SMarek Vasut #define WAIT_FOR_IN_COMPLETE	7
36f4d9bd06SMarek Vasut #define WAIT_FOR_NULL_COMPLETE	8
37f4d9bd06SMarek Vasut 
38f4d9bd06SMarek Vasut #define TEST_J_SEL		0x1
39f4d9bd06SMarek Vasut #define TEST_K_SEL		0x2
40f4d9bd06SMarek Vasut #define TEST_SE0_NAK_SEL	0x3
41f4d9bd06SMarek Vasut #define TEST_PACKET_SEL		0x4
42f4d9bd06SMarek Vasut #define TEST_FORCE_ENABLE_SEL	0x5
43f4d9bd06SMarek Vasut 
44f4d9bd06SMarek Vasut /* ************************************************************************* */
45f4d9bd06SMarek Vasut /* IO
46f4d9bd06SMarek Vasut  */
47f4d9bd06SMarek Vasut 
48f4d9bd06SMarek Vasut enum ep_type {
49f4d9bd06SMarek Vasut 	ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt
50f4d9bd06SMarek Vasut };
51f4d9bd06SMarek Vasut 
52f4d9bd06SMarek Vasut struct dwc2_ep {
53f4d9bd06SMarek Vasut 	struct usb_ep ep;
54f4d9bd06SMarek Vasut 	struct dwc2_udc *dev;
55f4d9bd06SMarek Vasut 
56f4d9bd06SMarek Vasut 	const struct usb_endpoint_descriptor *desc;
57f4d9bd06SMarek Vasut 	struct list_head queue;
58f4d9bd06SMarek Vasut 	unsigned long pio_irqs;
59f4d9bd06SMarek Vasut 	int len;
60f4d9bd06SMarek Vasut 	void *dma_buf;
61f4d9bd06SMarek Vasut 
62f4d9bd06SMarek Vasut 	u8 stopped;
63f4d9bd06SMarek Vasut 	u8 bEndpointAddress;
64f4d9bd06SMarek Vasut 	u8 bmAttributes;
65f4d9bd06SMarek Vasut 
66f4d9bd06SMarek Vasut 	enum ep_type ep_type;
67f4d9bd06SMarek Vasut 	int fifo_num;
68f4d9bd06SMarek Vasut };
69f4d9bd06SMarek Vasut 
70f4d9bd06SMarek Vasut struct dwc2_request {
71f4d9bd06SMarek Vasut 	struct usb_request req;
72f4d9bd06SMarek Vasut 	struct list_head queue;
73f4d9bd06SMarek Vasut };
74f4d9bd06SMarek Vasut 
75f4d9bd06SMarek Vasut struct dwc2_udc {
76f4d9bd06SMarek Vasut 	struct usb_gadget gadget;
77f4d9bd06SMarek Vasut 	struct usb_gadget_driver *driver;
78f4d9bd06SMarek Vasut 
79c0982871SMarek Vasut 	struct dwc2_plat_otg_data *pdata;
80f4d9bd06SMarek Vasut 
81f4d9bd06SMarek Vasut 	int ep0state;
82507e677bSMarek Vasut 	struct dwc2_ep ep[DWC2_MAX_ENDPOINTS];
83f4d9bd06SMarek Vasut 
84f4d9bd06SMarek Vasut 	unsigned char usb_address;
85f4d9bd06SMarek Vasut 
86f4d9bd06SMarek Vasut 	unsigned req_pending:1, req_std:1;
87f4d9bd06SMarek Vasut };
88f4d9bd06SMarek Vasut 
89f4d9bd06SMarek Vasut #define ep_is_in(EP) (((EP)->bEndpointAddress&USB_DIR_IN) == USB_DIR_IN)
90f4d9bd06SMarek Vasut #define ep_index(EP) ((EP)->bEndpointAddress&0xF)
91f4d9bd06SMarek Vasut #define ep_maxpacket(EP) ((EP)->ep.maxpacket)
92f4d9bd06SMarek Vasut 
93f4d9bd06SMarek Vasut void otg_phy_init(struct dwc2_udc *dev);
94f4d9bd06SMarek Vasut void otg_phy_off(struct dwc2_udc *dev);
95f4d9bd06SMarek Vasut 
96f4d9bd06SMarek Vasut #endif	/* __DWC2_UDC_OTG_PRIV__ */
97