blob: c71516cf6daa01f56c6bbea77e7bbf221fd603a6 [file] [log] [blame]
Lei Wen26cc5122011-10-05 08:11:40 -07001/*
2 * Copyright 2011, Marvell Semiconductor Inc.
3 * Lei Wen <leiwen@marvell.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Lei Wen26cc5122011-10-05 08:11:40 -07006 */
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 Vasutbe7ed252013-07-10 03:16:32 +020017#include "../../drivers/usb/host/ehci.h"
18
Marek Vasut6368c912013-07-10 03:16:28 +020019#define NUM_ENDPOINTS 6
Lei Wen26cc5122011-10-05 08:11:40 -070020
21/* Endpoint parameters */
22#define MAX_ENDPOINTS 4
Marek Vasut6368c912013-07-10 03:16:28 +020023
Lei Wen26cc5122011-10-05 08:11:40 -070024#define EP_MAX_PACKET_SIZE 0x200
Lei Wen26cc5122011-10-05 08:11:40 -070025#define EP0_MAX_PACKET_SIZE 64
Lei Wen26cc5122011-10-05 08:11:40 -070026
Lei Wen26cc5122011-10-05 08:11:40 -070027struct mv_udc {
Lei Wen26cc5122011-10-05 08:11:40 -070028#define MICRO_8FRAME 0x8
Marek Vasut6368c912013-07-10 03:16:28 +020029#define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16)
Lei Wen26cc5122011-10-05 08:11:40 -070030#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 Vasut6368c912013-07-10 03:16:28 +020045#define PTS(x) (((x) & 0x3) << 30)
Lei Wen26cc5122011-10-05 08:11:40 -070046#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 Vasut6368c912013-07-10 03:16:28 +020052#define EPT_TX(x) (1 << (((x) & 0xffff) + 16))
53#define EPT_RX(x) (1 << ((x) & 0xffff))
Lei Wen26cc5122011-10-05 08:11:40 -070054 u32 epprime; /* 0x1b0 */
55 u32 epflush; /* 0x1b4 */
56 u32 pad4;
57 u32 epcomp; /* 0x1bc */
Marek Vasut6368c912013-07-10 03:16:28 +020058#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 Wen26cc5122011-10-05 08:11:40 -070064 u32 epctrl[16]; /* 0x1c0 */
65};
66
Marek Vasut532d8462013-07-10 03:16:29 +020067struct mv_ep {
68 struct usb_ep ep;
Marek Vasut532d8462013-07-10 03:16:29 +020069 struct list_head queue;
70 const struct usb_endpoint_descriptor *desc;
Marek Vasut6dd30af2013-07-10 03:16:43 +020071
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 Vasut532d8462013-07-10 03:16:29 +020076};
77
Lei Wen26cc5122011-10-05 08:11:40 -070078struct mv_drv {
79 struct usb_gadget gadget;
Marek Vasut532d8462013-07-10 03:16:29 +020080 struct usb_gadget_driver *driver;
Marek Vasutbe7ed252013-07-10 03:16:32 +020081 struct ehci_ctrl *ctrl;
Marek Vasutab52df12013-07-10 03:16:36 +020082 struct ept_queue_head *epts;
83 struct ept_queue_item *items[2 * NUM_ENDPOINTS];
Marek Vasut8a095a62013-07-10 03:16:40 +020084 uint8_t *items_mem;
Marek Vasut2ea4b442013-07-10 03:16:30 +020085 struct mv_ep ep[NUM_ENDPOINTS];
Lei Wen26cc5122011-10-05 08:11:40 -070086};
87
88struct ept_queue_head {
89 unsigned config;
Marek Vasut6368c912013-07-10 03:16:28 +020090 unsigned current; /* read-only */
Lei Wen26cc5122011-10-05 08:11:40 -070091
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 Vasut6368c912013-07-10 03:16:28 +0200109#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 Wen26cc5122011-10-05 08:11:40 -0700112
113struct 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 Vasut6368c912013-07-10 03:16:28 +0200125#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 Wen26cc5122011-10-05 08:11:40 -0700131
Lei Wen26cc5122011-10-05 08:11:40 -0700132#endif /* __MV_UDC_H__ */