Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011, Marvell Semiconductor Inc. |
| 3 | * Lei Wen <leiwen@marvell.com> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | |
| 9 | #ifndef __MV_UDC_H__ |
| 10 | #define __MV_UDC_H__ |
| 11 | |
| 12 | #include <asm/byteorder.h> |
| 13 | #include <asm/errno.h> |
| 14 | #include <linux/usb/ch9.h> |
| 15 | #include <linux/usb/gadget.h> |
| 16 | |
Marek Vasut | be7ed25 | 2013-07-10 03:16:32 +0200 | [diff] [blame] | 17 | #include "../../drivers/usb/host/ehci.h" |
| 18 | |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 19 | #define NUM_ENDPOINTS 6 |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 20 | |
| 21 | /* Endpoint parameters */ |
| 22 | #define MAX_ENDPOINTS 4 |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 23 | |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 24 | #define EP_MAX_PACKET_SIZE 0x200 |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 25 | #define EP0_MAX_PACKET_SIZE 64 |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 26 | |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 27 | struct mv_udc { |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 28 | #define MICRO_8FRAME 0x8 |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 29 | #define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16) |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 30 | #define USBCMD_FS2 (1 << 15) |
| 31 | #define USBCMD_RST (1 << 1) |
| 32 | #define USBCMD_RUN (1) |
| 33 | u32 usbcmd; /* 0x140 */ |
| 34 | #define STS_SLI (1 << 8) |
| 35 | #define STS_URI (1 << 6) |
| 36 | #define STS_PCI (1 << 2) |
| 37 | #define STS_UEI (1 << 1) |
| 38 | #define STS_UI (1 << 0) |
| 39 | u32 usbsts; /* 0x144 */ |
| 40 | u32 pad1[3]; |
| 41 | u32 devaddr; /* 0x154 */ |
| 42 | u32 epinitaddr; /* 0x158 */ |
| 43 | u32 pad2[10]; |
| 44 | #define PTS_ENABLE 2 |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 45 | #define PTS(x) (((x) & 0x3) << 30) |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 46 | #define PFSC (1 << 24) |
| 47 | u32 portsc; /* 0x184 */ |
| 48 | u32 pad3[8]; |
| 49 | #define USBMODE_DEVICE 2 |
| 50 | u32 usbmode; /* 0x1a8 */ |
| 51 | u32 epstat; /* 0x1ac */ |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 52 | #define EPT_TX(x) (1 << (((x) & 0xffff) + 16)) |
| 53 | #define EPT_RX(x) (1 << ((x) & 0xffff)) |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 54 | u32 epprime; /* 0x1b0 */ |
| 55 | u32 epflush; /* 0x1b4 */ |
| 56 | u32 pad4; |
| 57 | u32 epcomp; /* 0x1bc */ |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 58 | #define CTRL_TXE (1 << 23) |
| 59 | #define CTRL_TXR (1 << 22) |
| 60 | #define CTRL_RXE (1 << 7) |
| 61 | #define CTRL_RXR (1 << 6) |
| 62 | #define CTRL_TXT_BULK (2 << 18) |
| 63 | #define CTRL_RXT_BULK (2 << 2) |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 64 | u32 epctrl[16]; /* 0x1c0 */ |
| 65 | }; |
| 66 | |
Marek Vasut | 532d846 | 2013-07-10 03:16:29 +0200 | [diff] [blame] | 67 | struct mv_ep { |
| 68 | struct usb_ep ep; |
Marek Vasut | 532d846 | 2013-07-10 03:16:29 +0200 | [diff] [blame] | 69 | struct list_head queue; |
| 70 | const struct usb_endpoint_descriptor *desc; |
Marek Vasut | 6dd30af | 2013-07-10 03:16:43 +0200 | [diff] [blame] | 71 | |
| 72 | struct usb_request req; |
| 73 | uint8_t *b_buf; |
| 74 | uint32_t b_len; |
| 75 | uint8_t b_fast[64] __aligned(ARCH_DMA_MINALIGN); |
Marek Vasut | 532d846 | 2013-07-10 03:16:29 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 78 | struct mv_drv { |
| 79 | struct usb_gadget gadget; |
Marek Vasut | 532d846 | 2013-07-10 03:16:29 +0200 | [diff] [blame] | 80 | struct usb_gadget_driver *driver; |
Marek Vasut | be7ed25 | 2013-07-10 03:16:32 +0200 | [diff] [blame] | 81 | struct ehci_ctrl *ctrl; |
Marek Vasut | ab52df1 | 2013-07-10 03:16:36 +0200 | [diff] [blame] | 82 | struct ept_queue_head *epts; |
| 83 | struct ept_queue_item *items[2 * NUM_ENDPOINTS]; |
Marek Vasut | 8a095a6 | 2013-07-10 03:16:40 +0200 | [diff] [blame] | 84 | uint8_t *items_mem; |
Marek Vasut | 2ea4b44 | 2013-07-10 03:16:30 +0200 | [diff] [blame] | 85 | struct mv_ep ep[NUM_ENDPOINTS]; |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct ept_queue_head { |
| 89 | unsigned config; |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 90 | unsigned current; /* read-only */ |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 91 | |
| 92 | unsigned next; |
| 93 | unsigned info; |
| 94 | unsigned page0; |
| 95 | unsigned page1; |
| 96 | unsigned page2; |
| 97 | unsigned page3; |
| 98 | unsigned page4; |
| 99 | unsigned reserved_0; |
| 100 | |
| 101 | unsigned char setup_data[8]; |
| 102 | |
| 103 | unsigned reserved_1; |
| 104 | unsigned reserved_2; |
| 105 | unsigned reserved_3; |
| 106 | unsigned reserved_4; |
| 107 | }; |
| 108 | |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 109 | #define CONFIG_MAX_PKT(n) ((n) << 16) |
| 110 | #define CONFIG_ZLT (1 << 29) /* stop on zero-len xfer */ |
| 111 | #define CONFIG_IOS (1 << 15) /* IRQ on setup */ |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 112 | |
| 113 | struct ept_queue_item { |
| 114 | unsigned next; |
| 115 | unsigned info; |
| 116 | unsigned page0; |
| 117 | unsigned page1; |
| 118 | unsigned page2; |
| 119 | unsigned page3; |
| 120 | unsigned page4; |
| 121 | unsigned reserved; |
| 122 | }; |
| 123 | |
| 124 | #define TERMINATE 1 |
Marek Vasut | 6368c91 | 2013-07-10 03:16:28 +0200 | [diff] [blame] | 125 | #define INFO_BYTES(n) ((n) << 16) |
| 126 | #define INFO_IOC (1 << 15) |
| 127 | #define INFO_ACTIVE (1 << 7) |
| 128 | #define INFO_HALTED (1 << 6) |
| 129 | #define INFO_BUFFER_ERROR (1 << 5) |
| 130 | #define INFO_TX_ERROR (1 << 3) |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 131 | |
Lei Wen | 26cc512 | 2011-10-05 08:11:40 -0700 | [diff] [blame] | 132 | #endif /* __MV_UDC_H__ */ |