1
2
3
4
5
6
7
8#ifndef USB_EHCI_H
9#define USB_EHCI_H
10
11#include <stdbool.h>
12#include <usb.h>
13#include <generic-phy.h>
14
15
16#define MAX_HC_PORTS 15
17
18
19
20
21struct ehci_hccr {
22 uint32_t cr_capbase;
23#define HC_LENGTH(p) (((p) >> 0) & 0x00ff)
24#define HC_VERSION(p) (((p) >> 16) & 0xffff)
25 uint32_t cr_hcsparams;
26#define HCS_PPC(p) ((p) & (1 << 4))
27#define HCS_INDICATOR(p) ((p) & (1 << 16))
28#define HCS_N_PORTS(p) (((p) >> 0) & 0xf)
29 uint32_t cr_hccparams;
30 uint8_t cr_hcsp_portrt[8];
31} __attribute__ ((packed, aligned(4)));
32
33struct ehci_hcor {
34 uint32_t or_usbcmd;
35#define CMD_PARK (1 << 11)
36#define CMD_PARK_CNT(c) (((c) >> 8) & 3)
37#define CMD_LRESET (1 << 7)
38#define CMD_IAAD (1 << 6)
39#define CMD_ASE (1 << 5)
40#define CMD_PSE (1 << 4)
41#define CMD_RESET (1 << 1)
42#define CMD_RUN (1 << 0)
43 uint32_t or_usbsts;
44#define STS_ASS (1 << 15)
45#define STS_PSS (1 << 14)
46#define STS_HALT (1 << 12)
47 uint32_t or_usbintr;
48#define INTR_UE (1 << 0)
49#define INTR_UEE (1 << 1)
50#define INTR_PCE (1 << 2)
51#define INTR_SEE (1 << 4)
52#define INTR_AAE (1 << 5)
53 uint32_t or_frindex;
54 uint32_t or_ctrldssegment;
55 uint32_t or_periodiclistbase;
56 uint32_t or_asynclistaddr;
57 uint32_t _reserved_0_;
58 uint32_t or_burstsize;
59 uint32_t or_txfilltuning;
60#define TXFIFO_THRESH_MASK (0x3f << 16)
61#define TXFIFO_THRESH(p) ((p & 0x3f) << 16)
62 uint32_t _reserved_1_[6];
63 uint32_t or_configflag;
64#define FLAG_CF (1 << 0)
65 uint32_t or_portsc[MAX_HC_PORTS];
66#define PORTSC_PSPD(x) (((x) >> 26) & 0x3)
67#define PORTSC_PSPD_FS 0x0
68#define PORTSC_PSPD_LS 0x1
69#define PORTSC_PSPD_HS 0x2
70#define PORTSC_FSL_PFSC BIT(24)
71
72 uint32_t or_systune;
73} __attribute__ ((packed, aligned(4)));
74
75#define USBMODE 0x68
76#define USBMODE_SDIS (1 << 3)
77#define USBMODE_BE (1 << 2)
78#define USBMODE_CM_HC (3 << 0)
79#define USBMODE_CM_IDLE (0 << 0)
80
81
82struct usb_linux_interface_descriptor {
83 unsigned char bLength;
84 unsigned char bDescriptorType;
85 unsigned char bInterfaceNumber;
86 unsigned char bAlternateSetting;
87 unsigned char bNumEndpoints;
88 unsigned char bInterfaceClass;
89 unsigned char bInterfaceSubClass;
90 unsigned char bInterfaceProtocol;
91 unsigned char iInterface;
92} __attribute__ ((packed));
93
94
95struct usb_linux_config_descriptor {
96 unsigned char bLength;
97 unsigned char bDescriptorType;
98 unsigned short wTotalLength;
99 unsigned char bNumInterfaces;
100 unsigned char bConfigurationValue;
101 unsigned char iConfiguration;
102 unsigned char bmAttributes;
103 unsigned char MaxPower;
104} __attribute__ ((packed));
105
106#if defined CONFIG_EHCI_DESC_BIG_ENDIAN
107#define ehci_readl(x) be32_to_cpu(__raw_readl(x))
108#define ehci_writel(a, b) __raw_writel(cpu_to_be32(b), a)
109#else
110#define ehci_readl(x) readl(x)
111#define ehci_writel(a, b) writel(b, a)
112#endif
113
114#if defined CONFIG_EHCI_MMIO_BIG_ENDIAN
115#define hc32_to_cpu(x) be32_to_cpu((x))
116#define cpu_to_hc32(x) cpu_to_be32((x))
117#else
118#define hc32_to_cpu(x) le32_to_cpu((x))
119#define cpu_to_hc32(x) cpu_to_le32((x))
120#endif
121
122#define EHCI_PS_WKOC_E (1 << 22)
123#define EHCI_PS_WKDSCNNT_E (1 << 21)
124#define EHCI_PS_WKCNNT_E (1 << 20)
125#define EHCI_PS_PO (1 << 13)
126#define EHCI_PS_PP (1 << 12)
127#define EHCI_PS_LS (3 << 10)
128#define EHCI_PS_PR (1 << 8)
129#define EHCI_PS_SUSP (1 << 7)
130#define EHCI_PS_FPR (1 << 6)
131#define EHCI_PS_OCC (1 << 5)
132#define EHCI_PS_OCA (1 << 4)
133#define EHCI_PS_PEC (1 << 3)
134#define EHCI_PS_PE (1 << 2)
135#define EHCI_PS_CSC (1 << 1)
136#define EHCI_PS_CS (1 << 0)
137#define EHCI_PS_CLEAR (EHCI_PS_OCC | EHCI_PS_PEC | EHCI_PS_CSC)
138
139#define EHCI_PS_IS_LOWSPEED(x) (((x) & EHCI_PS_LS) == (1 << 10))
140
141
142
143
144
145
146
147
148
149
150
151
152struct qTD {
153
154 uint32_t qt_next;
155#define QT_NEXT_TERMINATE 1
156 uint32_t qt_altnext;
157 uint32_t qt_token;
158#define QT_TOKEN_DT(x) (((x) & 0x1) << 31)
159#define QT_TOKEN_GET_DT(x) (((x) >> 31) & 0x1)
160#define QT_TOKEN_TOTALBYTES(x) (((x) & 0x7fff) << 16)
161#define QT_TOKEN_GET_TOTALBYTES(x) (((x) >> 16) & 0x7fff)
162#define QT_TOKEN_IOC(x) (((x) & 0x1) << 15)
163#define QT_TOKEN_CPAGE(x) (((x) & 0x7) << 12)
164#define QT_TOKEN_CERR(x) (((x) & 0x3) << 10)
165#define QT_TOKEN_PID(x) (((x) & 0x3) << 8)
166#define QT_TOKEN_PID_OUT 0x0
167#define QT_TOKEN_PID_IN 0x1
168#define QT_TOKEN_PID_SETUP 0x2
169#define QT_TOKEN_STATUS(x) (((x) & 0xff) << 0)
170#define QT_TOKEN_GET_STATUS(x) (((x) >> 0) & 0xff)
171#define QT_TOKEN_STATUS_ACTIVE 0x80
172#define QT_TOKEN_STATUS_HALTED 0x40
173#define QT_TOKEN_STATUS_DATBUFERR 0x20
174#define QT_TOKEN_STATUS_BABBLEDET 0x10
175#define QT_TOKEN_STATUS_XACTERR 0x08
176#define QT_TOKEN_STATUS_MISSEDUFRAME 0x04
177#define QT_TOKEN_STATUS_SPLITXSTATE 0x02
178#define QT_TOKEN_STATUS_PERR 0x01
179#define QT_BUFFER_CNT 5
180 uint32_t qt_buffer[QT_BUFFER_CNT];
181 uint32_t qt_buffer_hi[QT_BUFFER_CNT];
182
183 uint32_t unused[3];
184};
185
186#define EHCI_PAGE_SIZE 4096
187
188
189struct QH {
190 uint32_t qh_link;
191#define QH_LINK_TERMINATE 1
192#define QH_LINK_TYPE_ITD 0
193#define QH_LINK_TYPE_QH 2
194#define QH_LINK_TYPE_SITD 4
195#define QH_LINK_TYPE_FSTN 6
196 uint32_t qh_endpt1;
197#define QH_ENDPT1_RL(x) (((x) & 0xf) << 28)
198#define QH_ENDPT1_C(x) (((x) & 0x1) << 27)
199#define QH_ENDPT1_MAXPKTLEN(x) (((x) & 0x7ff) << 16)
200#define QH_ENDPT1_H(x) (((x) & 0x1) << 15)
201#define QH_ENDPT1_DTC(x) (((x) & 0x1) << 14)
202#define QH_ENDPT1_DTC_IGNORE_QTD_TD 0x0
203#define QH_ENDPT1_DTC_DT_FROM_QTD 0x1
204#define QH_ENDPT1_EPS(x) (((x) & 0x3) << 12)
205#define QH_ENDPT1_EPS_FS 0x0
206#define QH_ENDPT1_EPS_LS 0x1
207#define QH_ENDPT1_EPS_HS 0x2
208#define QH_ENDPT1_ENDPT(x) (((x) & 0xf) << 8)
209#define QH_ENDPT1_I(x) (((x) & 0x1) << 7)
210#define QH_ENDPT1_DEVADDR(x) (((x) & 0x7f) << 0)
211 uint32_t qh_endpt2;
212#define QH_ENDPT2_MULT(x) (((x) & 0x3) << 30)
213#define QH_ENDPT2_PORTNUM(x) (((x) & 0x7f) << 23)
214#define QH_ENDPT2_HUBADDR(x) (((x) & 0x7f) << 16)
215#define QH_ENDPT2_UFCMASK(x) (((x) & 0xff) << 8)
216#define QH_ENDPT2_UFSMASK(x) (((x) & 0xff) << 0)
217 uint32_t qh_curtd;
218 struct qTD qh_overlay;
219
220
221
222
223 union {
224 uint32_t fill[4];
225 void *buffer;
226 };
227};
228
229
230enum {
231
232 EHCI_TWEAK_NO_INIT_CF = 1 << 0,
233};
234
235struct ehci_ctrl;
236
237struct ehci_ops {
238 void (*set_usb_mode)(struct ehci_ctrl *ctrl);
239 int (*get_port_speed)(struct ehci_ctrl *ctrl, uint32_t reg);
240 void (*powerup_fixup)(struct ehci_ctrl *ctrl, uint32_t *status_reg,
241 uint32_t *reg);
242 uint32_t *(*get_portsc_register)(struct ehci_ctrl *ctrl, int port);
243 int (*init_after_reset)(struct ehci_ctrl *ctrl);
244};
245
246struct ehci_ctrl {
247 enum usb_init_type init;
248 struct ehci_hccr *hccr;
249 struct ehci_hcor *hcor;
250 int rootdev;
251 uint16_t portreset;
252 struct QH qh_list __aligned(USB_DMA_MINALIGN);
253 struct QH periodic_queue __aligned(USB_DMA_MINALIGN);
254 uint32_t *periodic_list;
255 int periodic_schedules;
256 int ntds;
257 bool has_fsl_erratum_a005275;
258 bool async_locked;
259 struct ehci_ops ops;
260 void *priv;
261};
262
263
264
265
266
267
268
269
270
271
272
273
274
275void ehci_set_controller_priv(int index, void *priv,
276 const struct ehci_ops *ops);
277
278
279
280
281
282
283
284void *ehci_get_controller_priv(int index);
285
286
287int ehci_hcd_init(int index, enum usb_init_type init,
288 struct ehci_hccr **hccr, struct ehci_hcor **hcor);
289int ehci_hcd_stop(int index);
290
291int ehci_register(struct udevice *dev, struct ehci_hccr *hccr,
292 struct ehci_hcor *hcor, const struct ehci_ops *ops,
293 uint tweaks, enum usb_init_type init);
294int ehci_deregister(struct udevice *dev);
295extern struct dm_usb_ops ehci_usb_ops;
296
297
298int ehci_setup_phy(struct udevice *dev, struct phy *phy, int index);
299int ehci_shutdown_phy(struct udevice *dev, struct phy *phy);
300
301#include <linux/bitops.h>
302#endif
303