blob: 221e626391784eeaa28343b8d390afcad46b1066 [file] [log] [blame]
Lei Wena91ee2a2011-10-05 08:11:40 -07001/*
2 * Copyright 2011, Marvell Semiconductor Inc.
3 * Lei Wen <leiwen@marvell.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
19 */
20
21
22#ifndef __MV_UDC_H__
23#define __MV_UDC_H__
24
25#include <asm/byteorder.h>
26#include <asm/errno.h>
27#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h>
29
30/* Endpoint 0 states */
31#define EP0_IDLE 0
32#define EP0_IN_DATA 1
33#define EP0_OUT_DATA 2
34#define EP0_XFER_COMPLETE 3
35
36
37/* Endpoint parameters */
38#define MAX_ENDPOINTS 4
39#define EP_MAX_PACKET_SIZE 0x200
40
41#define EP0_MAX_PACKET_SIZE 64
42#define UDC_OUT_ENDPOINT 0x02
43#define UDC_OUT_PACKET_SIZE EP_MAX_PACKET_SIZE
44#define UDC_IN_ENDPOINT 0x01
45#define UDC_IN_PACKET_SIZE EP_MAX_PACKET_SIZE
46#define UDC_INT_ENDPOINT 0x05
47#define UDC_INT_PACKET_SIZE EP_MAX_PACKET_SIZE
48#define UDC_BULK_PACKET_SIZE EP_MAX_PACKET_SIZE
49
50#define NUM_ENDPOINTS 6
51#define REQ_COUNT 12
52struct mv_ep {
53 struct usb_ep ep;
54 struct usb_request req;
55 struct list_head queue;
56 const struct usb_endpoint_descriptor *desc;
57};
58
59struct mv_udc {
60 u32 pad0[80];
61#define MICRO_8FRAME 0x8
62#define USBCMD_ITC(x) (((x > 0xff) ? 0xff : x) << 16)
63#define USBCMD_FS2 (1 << 15)
64#define USBCMD_RST (1 << 1)
65#define USBCMD_RUN (1)
66 u32 usbcmd; /* 0x140 */
67#define STS_SLI (1 << 8)
68#define STS_URI (1 << 6)
69#define STS_PCI (1 << 2)
70#define STS_UEI (1 << 1)
71#define STS_UI (1 << 0)
72 u32 usbsts; /* 0x144 */
73 u32 pad1[3];
74 u32 devaddr; /* 0x154 */
75 u32 epinitaddr; /* 0x158 */
76 u32 pad2[10];
77#define PTS_ENABLE 2
78#define PTS(x) ((x & 0x3) << 30)
79#define PFSC (1 << 24)
80 u32 portsc; /* 0x184 */
81 u32 pad3[8];
82#define USBMODE_DEVICE 2
83 u32 usbmode; /* 0x1a8 */
84 u32 epstat; /* 0x1ac */
85#define EPT_TX(x) (1 << ((x & 0xffff) + 16))
86#define EPT_RX(x) (1 << (x & 0xffff))
87 u32 epprime; /* 0x1b0 */
88 u32 epflush; /* 0x1b4 */
89 u32 pad4;
90 u32 epcomp; /* 0x1bc */
91#define CTRL_TXE (1 << 23)
92#define CTRL_TXR (1 << 22)
93#define CTRL_RXE (1 << 7)
94#define CTRL_RXR (1 << 6)
95#define CTRL_TXT_BULK (2 << 18)
96#define CTRL_RXT_BULK (2 << 2)
97 u32 epctrl[16]; /* 0x1c0 */
98};
99
100struct mv_drv {
101 struct usb_gadget gadget;
102 struct usb_gadget_driver *driver;
103 struct mv_udc *udc;
104};
105
106struct ept_queue_head {
107 unsigned config;
108 unsigned current; /* read-only */
109
110 unsigned next;
111 unsigned info;
112 unsigned page0;
113 unsigned page1;
114 unsigned page2;
115 unsigned page3;
116 unsigned page4;
117 unsigned reserved_0;
118
119 unsigned char setup_data[8];
120
121 unsigned reserved_1;
122 unsigned reserved_2;
123 unsigned reserved_3;
124 unsigned reserved_4;
125};
126
127#define CONFIG_MAX_PKT(n) ((n) << 16)
128#define CONFIG_ZLT (1 << 29) /* stop on zero-len xfer */
129#define CONFIG_IOS (1 << 15) /* IRQ on setup */
130
131struct ept_queue_item {
132 unsigned next;
133 unsigned info;
134 unsigned page0;
135 unsigned page1;
136 unsigned page2;
137 unsigned page3;
138 unsigned page4;
139 unsigned reserved;
140};
141
142#define TERMINATE 1
143#define INFO_BYTES(n) ((n) << 16)
144#define INFO_IOC (1 << 15)
145#define INFO_ACTIVE (1 << 7)
146#define INFO_HALTED (1 << 6)
147#define INFO_BUFFER_ERROR (1 << 5)
148#define INFO_TX_ERROR (1 << 3)
149
Lucas Stacha3231282012-09-26 00:14:34 +0200150extern int usb_lowlevel_init(int index, void **controller);
Lei Wena91ee2a2011-10-05 08:11:40 -0700151#endif /* __MV_UDC_H__ */