blob: 2ab830df5155a51c33828fe2a28e83eebba04ebc [file] [log] [blame]
Michael Trimarchi241f7512008-11-28 13:20:46 +01001/*-
2 * Copyright (c) 2007-2008, Juniper Networks, Inc.
Remy Böhmer33e87482008-12-13 22:51:58 +01003 * Copyright (c) 2008, Michael Trimarchi <trimarchimichael@yahoo.it>
Michael Trimarchi241f7512008-11-28 13:20:46 +01004 * All rights reserved.
5 *
Simon Glass1b2e3652015-07-06 16:47:42 -06006 * SPDX-License-Identifier: GPL-2.0
Michael Trimarchi241f7512008-11-28 13:20:46 +01007 */
8
9#ifndef USB_EHCI_H
10#define USB_EHCI_H
11
Marek Vasutfd349a12013-07-10 03:16:31 +020012#include <usb.h>
13
Remy Böhmer33e87482008-12-13 22:51:58 +010014#if !defined(CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS)
15#define CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS 2
16#endif
17
Michael Trimarchi241f7512008-11-28 13:20:46 +010018/*
19 * Register Space.
20 */
21struct ehci_hccr {
michael0a326102008-12-10 17:55:19 +010022 uint32_t cr_capbase;
23#define HC_LENGTH(p) (((p) >> 0) & 0x00ff)
24#define HC_VERSION(p) (((p) >> 16) & 0xffff)
Michael Trimarchi241f7512008-11-28 13:20:46 +010025 uint32_t cr_hcsparams;
Remy Böhmer33e87482008-12-13 22:51:58 +010026#define HCS_PPC(p) ((p) & (1 << 4))
27#define HCS_INDICATOR(p) ((p) & (1 << 16)) /* Port indicators */
michael0bf2a032008-12-11 13:43:55 +010028#define HCS_N_PORTS(p) (((p) >> 0) & 0xf)
Michael Trimarchi241f7512008-11-28 13:20:46 +010029 uint32_t cr_hccparams;
30 uint8_t cr_hcsp_portrt[8];
Jason Kridner8c2465c2011-04-20 08:54:16 -050031} __attribute__ ((packed, aligned(4)));
Michael Trimarchi241f7512008-11-28 13:20:46 +010032
33struct ehci_hcor {
34 uint32_t or_usbcmd;
michael0bf2a032008-12-11 13:43:55 +010035#define CMD_PARK (1 << 11) /* enable "park" */
36#define CMD_PARK_CNT(c) (((c) >> 8) & 3) /* how many transfers to park */
michael0bf2a032008-12-11 13:43:55 +010037#define CMD_LRESET (1 << 7) /* partial reset */
Masahiro Yamadac6f9d822014-11-05 23:11:10 +090038#define CMD_IAAD (1 << 6) /* "doorbell" interrupt */
39#define CMD_ASE (1 << 5) /* async schedule enable */
michael0bf2a032008-12-11 13:43:55 +010040#define CMD_PSE (1 << 4) /* periodic schedule enable */
41#define CMD_RESET (1 << 1) /* reset HC not bus */
42#define CMD_RUN (1 << 0) /* start/stop HC */
Michael Trimarchi241f7512008-11-28 13:20:46 +010043 uint32_t or_usbsts;
Benoît Thébaudeau458fb1e2012-08-10 18:22:11 +020044#define STS_ASS (1 << 15)
Patrick Georgie55fdac2013-03-06 14:08:31 +000045#define STS_PSS (1 << 14)
michael0bf2a032008-12-11 13:43:55 +010046#define STS_HALT (1 << 12)
Michael Trimarchi241f7512008-11-28 13:20:46 +010047 uint32_t or_usbintr;
Damien Dusha7c3be662010-10-14 15:27:06 +020048#define INTR_UE (1 << 0) /* USB interrupt enable */
49#define INTR_UEE (1 << 1) /* USB error interrupt enable */
50#define INTR_PCE (1 << 2) /* Port change detect enable */
51#define INTR_SEE (1 << 4) /* system error enable */
52#define INTR_AAE (1 << 5) /* Interrupt on async adavance enable */
Michael Trimarchi241f7512008-11-28 13:20:46 +010053 uint32_t or_frindex;
54 uint32_t or_ctrldssegment;
55 uint32_t or_periodiclistbase;
56 uint32_t or_asynclistaddr;
Simon Glass5978cdb2012-02-27 10:52:47 +000057 uint32_t _reserved_0_;
58 uint32_t or_burstsize;
59 uint32_t or_txfilltuning;
Benoît Thébaudeau458fb1e2012-08-10 18:22:11 +020060#define TXFIFO_THRESH_MASK (0x3f << 16)
Simon Glass5978cdb2012-02-27 10:52:47 +000061#define TXFIFO_THRESH(p) ((p & 0x3f) << 16)
62 uint32_t _reserved_1_[6];
Michael Trimarchi241f7512008-11-28 13:20:46 +010063 uint32_t or_configflag;
michael0bf2a032008-12-11 13:43:55 +010064#define FLAG_CF (1 << 0) /* true: we'll support "high speed" */
Remy Böhmer33e87482008-12-13 22:51:58 +010065 uint32_t or_portsc[CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS];
Benoît Thébaudeau458fb1e2012-08-10 18:22:11 +020066#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
Michael Trimarchi241f7512008-11-28 13:20:46 +010070 uint32_t or_systune;
Jason Kridner8c2465c2011-04-20 08:54:16 -050071} __attribute__ ((packed, aligned(4)));
Michael Trimarchi241f7512008-11-28 13:20:46 +010072
michael0bf2a032008-12-11 13:43:55 +010073#define USBMODE 0x68 /* USB Device mode */
74#define USBMODE_SDIS (1 << 3) /* Stream disable */
75#define USBMODE_BE (1 << 2) /* BE/LE endiannes select */
76#define USBMODE_CM_HC (3 << 0) /* host controller mode */
77#define USBMODE_CM_IDLE (0 << 0) /* idle state */
78
michael0a326102008-12-10 17:55:19 +010079/* Interface descriptor */
80struct usb_linux_interface_descriptor {
81 unsigned char bLength;
82 unsigned char bDescriptorType;
83 unsigned char bInterfaceNumber;
84 unsigned char bAlternateSetting;
85 unsigned char bNumEndpoints;
86 unsigned char bInterfaceClass;
87 unsigned char bInterfaceSubClass;
88 unsigned char bInterfaceProtocol;
89 unsigned char iInterface;
90} __attribute__ ((packed));
91
92/* Configuration descriptor information.. */
93struct usb_linux_config_descriptor {
94 unsigned char bLength;
95 unsigned char bDescriptorType;
96 unsigned short wTotalLength;
97 unsigned char bNumInterfaces;
98 unsigned char bConfigurationValue;
99 unsigned char iConfiguration;
100 unsigned char bmAttributes;
101 unsigned char MaxPower;
102} __attribute__ ((packed));
103
104#if defined CONFIG_EHCI_DESC_BIG_ENDIAN
Alexey Brodkinbb1cd632017-06-05 22:31:51 +0300105#define ehci_readl(x) cpu_to_be32(readl(x))
106#define ehci_writel(a, b) writel(cpu_to_be32(b), a)
michael0a326102008-12-10 17:55:19 +0100107#else
Alexey Brodkinbb1cd632017-06-05 22:31:51 +0300108#define ehci_readl(x) cpu_to_le32(readl(x))
109#define ehci_writel(a, b) writel(cpu_to_le32(b), a)
michael0a326102008-12-10 17:55:19 +0100110#endif
111
112#if defined CONFIG_EHCI_MMIO_BIG_ENDIAN
113#define hc32_to_cpu(x) be32_to_cpu((x))
114#define cpu_to_hc32(x) cpu_to_be32((x))
115#else
116#define hc32_to_cpu(x) le32_to_cpu((x))
117#define cpu_to_hc32(x) cpu_to_le32((x))
118#endif
119
Remy Böhmer33e87482008-12-13 22:51:58 +0100120#define EHCI_PS_WKOC_E (1 << 22) /* RW wake on over current */
121#define EHCI_PS_WKDSCNNT_E (1 << 21) /* RW wake on disconnect */
122#define EHCI_PS_WKCNNT_E (1 << 20) /* RW wake on connect */
123#define EHCI_PS_PO (1 << 13) /* RW port owner */
124#define EHCI_PS_PP (1 << 12) /* RW,RO port power */
125#define EHCI_PS_LS (3 << 10) /* RO line status */
126#define EHCI_PS_PR (1 << 8) /* RW port reset */
127#define EHCI_PS_SUSP (1 << 7) /* RW suspend */
128#define EHCI_PS_FPR (1 << 6) /* RW force port resume */
129#define EHCI_PS_OCC (1 << 5) /* RWC over current change */
130#define EHCI_PS_OCA (1 << 4) /* RO over current active */
131#define EHCI_PS_PEC (1 << 3) /* RWC port enable change */
132#define EHCI_PS_PE (1 << 2) /* RW port enable */
133#define EHCI_PS_CSC (1 << 1) /* RWC connect status change */
134#define EHCI_PS_CS (1 << 0) /* RO connect status */
Michael Trimarchi241f7512008-11-28 13:20:46 +0100135#define EHCI_PS_CLEAR (EHCI_PS_OCC | EHCI_PS_PEC | EHCI_PS_CSC)
136
Remy Böhmer33e87482008-12-13 22:51:58 +0100137#define EHCI_PS_IS_LOWSPEED(x) (((x) & EHCI_PS_LS) == (1 << 10))
Michael Trimarchi241f7512008-11-28 13:20:46 +0100138
139/*
140 * Schedule Interface Space.
141 *
142 * IMPORTANT: Software must ensure that no interface data structure
143 * reachable by the EHCI host controller spans a 4K page boundary!
144 *
145 * Periodic transfers (i.e. isochronous and interrupt transfers) are
146 * not supported.
147 */
148
149/* Queue Element Transfer Descriptor (qTD). */
150struct qTD {
Wolfgang Denkebb829f2010-10-19 16:13:15 +0200151 /* this part defined by EHCI spec */
Benoît Thébaudeaue68f48a2012-07-19 22:16:38 +0200152 uint32_t qt_next; /* see EHCI 3.5.1 */
Michael Trimarchi241f7512008-11-28 13:20:46 +0100153#define QT_NEXT_TERMINATE 1
Benoît Thébaudeaue68f48a2012-07-19 22:16:38 +0200154 uint32_t qt_altnext; /* see EHCI 3.5.2 */
155 uint32_t qt_token; /* see EHCI 3.5.3 */
Benoît Thébaudeau458fb1e2012-08-10 18:22:11 +0200156#define QT_TOKEN_DT(x) (((x) & 0x1) << 31) /* Data Toggle */
157#define QT_TOKEN_GET_DT(x) (((x) >> 31) & 0x1)
158#define QT_TOKEN_TOTALBYTES(x) (((x) & 0x7fff) << 16) /* Total Bytes to Transfer */
159#define QT_TOKEN_GET_TOTALBYTES(x) (((x) >> 16) & 0x7fff)
160#define QT_TOKEN_IOC(x) (((x) & 0x1) << 15) /* Interrupt On Complete */
161#define QT_TOKEN_CPAGE(x) (((x) & 0x7) << 12) /* Current Page */
162#define QT_TOKEN_CERR(x) (((x) & 0x3) << 10) /* Error Counter */
163#define QT_TOKEN_PID(x) (((x) & 0x3) << 8) /* PID Code */
164#define QT_TOKEN_PID_OUT 0x0
165#define QT_TOKEN_PID_IN 0x1
166#define QT_TOKEN_PID_SETUP 0x2
167#define QT_TOKEN_STATUS(x) (((x) & 0xff) << 0) /* Status */
168#define QT_TOKEN_GET_STATUS(x) (((x) >> 0) & 0xff)
169#define QT_TOKEN_STATUS_ACTIVE 0x80
170#define QT_TOKEN_STATUS_HALTED 0x40
171#define QT_TOKEN_STATUS_DATBUFERR 0x20
172#define QT_TOKEN_STATUS_BABBLEDET 0x10
173#define QT_TOKEN_STATUS_XACTERR 0x08
174#define QT_TOKEN_STATUS_MISSEDUFRAME 0x04
175#define QT_TOKEN_STATUS_SPLITXSTATE 0x02
176#define QT_TOKEN_STATUS_PERR 0x01
Benoît Thébaudeaue68f48a2012-07-19 22:16:38 +0200177#define QT_BUFFER_CNT 5
178 uint32_t qt_buffer[QT_BUFFER_CNT]; /* see EHCI 3.5.4 */
179 uint32_t qt_buffer_hi[QT_BUFFER_CNT]; /* Appendix B */
Wolfgang Denkebb829f2010-10-19 16:13:15 +0200180 /* pad struct for 32 byte alignment */
181 uint32_t unused[3];
Wolfgang Denkcd6cbd92010-10-20 21:08:17 +0200182};
Michael Trimarchi241f7512008-11-28 13:20:46 +0100183
Benoît Thébaudeau458fb1e2012-08-10 18:22:11 +0200184#define EHCI_PAGE_SIZE 4096
185
Michael Trimarchi241f7512008-11-28 13:20:46 +0100186/* Queue Head (QH). */
187struct QH {
188 uint32_t qh_link;
189#define QH_LINK_TERMINATE 1
190#define QH_LINK_TYPE_ITD 0
191#define QH_LINK_TYPE_QH 2
192#define QH_LINK_TYPE_SITD 4
193#define QH_LINK_TYPE_FSTN 6
194 uint32_t qh_endpt1;
Benoît Thébaudeau458fb1e2012-08-10 18:22:11 +0200195#define QH_ENDPT1_RL(x) (((x) & 0xf) << 28) /* NAK Count Reload */
196#define QH_ENDPT1_C(x) (((x) & 0x1) << 27) /* Control Endpoint Flag */
197#define QH_ENDPT1_MAXPKTLEN(x) (((x) & 0x7ff) << 16) /* Maximum Packet Length */
198#define QH_ENDPT1_H(x) (((x) & 0x1) << 15) /* Head of Reclamation List Flag */
199#define QH_ENDPT1_DTC(x) (((x) & 0x1) << 14) /* Data Toggle Control */
200#define QH_ENDPT1_DTC_IGNORE_QTD_TD 0x0
201#define QH_ENDPT1_DTC_DT_FROM_QTD 0x1
202#define QH_ENDPT1_EPS(x) (((x) & 0x3) << 12) /* Endpoint Speed */
203#define QH_ENDPT1_EPS_FS 0x0
204#define QH_ENDPT1_EPS_LS 0x1
205#define QH_ENDPT1_EPS_HS 0x2
206#define QH_ENDPT1_ENDPT(x) (((x) & 0xf) << 8) /* Endpoint Number */
207#define QH_ENDPT1_I(x) (((x) & 0x1) << 7) /* Inactivate on Next Transaction */
208#define QH_ENDPT1_DEVADDR(x) (((x) & 0x7f) << 0) /* Device Address */
Michael Trimarchi241f7512008-11-28 13:20:46 +0100209 uint32_t qh_endpt2;
Benoît Thébaudeau458fb1e2012-08-10 18:22:11 +0200210#define QH_ENDPT2_MULT(x) (((x) & 0x3) << 30) /* High-Bandwidth Pipe Multiplier */
211#define QH_ENDPT2_PORTNUM(x) (((x) & 0x7f) << 23) /* Port Number */
212#define QH_ENDPT2_HUBADDR(x) (((x) & 0x7f) << 16) /* Hub Address */
213#define QH_ENDPT2_UFCMASK(x) (((x) & 0xff) << 8) /* Split Completion Mask */
214#define QH_ENDPT2_UFSMASK(x) (((x) & 0xff) << 0) /* Interrupt Schedule Mask */
Michael Trimarchi241f7512008-11-28 13:20:46 +0100215 uint32_t qh_curtd;
216 struct qTD qh_overlay;
Stefan Roese25983c12009-01-21 17:12:19 +0100217 /*
218 * Add dummy fill value to make the size of this struct
219 * aligned to 32 bytes
220 */
Patrick Georgie55fdac2013-03-06 14:08:31 +0000221 union {
Vincent Palatin28e1d9c2013-03-06 14:08:32 +0000222 uint32_t fill[4];
Patrick Georgie55fdac2013-03-06 14:08:31 +0000223 void *buffer;
224 };
Michael Trimarchi241f7512008-11-28 13:20:46 +0100225};
226
Simon Glassccc40fd2015-03-25 12:22:26 -0600227/* Tweak flags for EHCI, used to control operation */
228enum {
229 /* don't use or_configflag in init */
230 EHCI_TWEAK_NO_INIT_CF = 1 << 0,
231};
232
Simon Glassdc9f3ed2015-03-25 12:22:27 -0600233struct ehci_ctrl;
234
235struct ehci_ops {
236 void (*set_usb_mode)(struct ehci_ctrl *ctrl);
237 int (*get_port_speed)(struct ehci_ctrl *ctrl, uint32_t reg);
238 void (*powerup_fixup)(struct ehci_ctrl *ctrl, uint32_t *status_reg,
239 uint32_t *reg);
240 uint32_t *(*get_portsc_register)(struct ehci_ctrl *ctrl, int port);
Mateusz Kulikowskiaab5a5a2016-03-31 23:12:17 +0200241 int (*init_after_reset)(struct ehci_ctrl *ctrl);
Simon Glassdc9f3ed2015-03-25 12:22:27 -0600242};
243
Marek Vasutfd349a12013-07-10 03:16:31 +0200244struct ehci_ctrl {
Stephen Warren71eced32015-08-20 17:38:05 -0600245 enum usb_init_type init;
Marek Vasutfd349a12013-07-10 03:16:31 +0200246 struct ehci_hccr *hccr; /* R/O registers, not need for volatile */
247 struct ehci_hcor *hcor;
248 int rootdev;
249 uint16_t portreset;
250 struct QH qh_list __aligned(USB_DMA_MINALIGN);
251 struct QH periodic_queue __aligned(USB_DMA_MINALIGN);
252 uint32_t *periodic_list;
Hans de Goede8f5f4f72014-09-20 16:51:25 +0200253 int periodic_schedules;
Marek Vasutfd349a12013-07-10 03:16:31 +0200254 int ntds;
Simon Glassdc9f3ed2015-03-25 12:22:27 -0600255 struct ehci_ops ops;
Simon Glass0851caa2015-03-25 12:22:19 -0600256 void *priv; /* client's private data */
Marek Vasutfd349a12013-07-10 03:16:31 +0200257};
258
Simon Glass0851caa2015-03-25 12:22:19 -0600259/**
Simon Glassdc9f3ed2015-03-25 12:22:27 -0600260 * ehci_set_controller_info() - Set up private data for the controller
Simon Glass0851caa2015-03-25 12:22:19 -0600261 *
262 * This function can be called in ehci_hcd_init() to tell the EHCI layer
263 * about the controller's private data pointer. Then in the above functions
Simon Glassdc9f3ed2015-03-25 12:22:27 -0600264 * this can be accessed given the struct ehci_ctrl pointer. Also special
265 * EHCI operation methods can be provided if required
Simon Glass0851caa2015-03-25 12:22:19 -0600266 *
267 * @index: Controller number to set
268 * @priv: Controller pointer
Simon Glassdc9f3ed2015-03-25 12:22:27 -0600269 * @ops: Controller operations, or NULL to use default
Simon Glass0851caa2015-03-25 12:22:19 -0600270 */
Simon Glassdc9f3ed2015-03-25 12:22:27 -0600271void ehci_set_controller_priv(int index, void *priv,
272 const struct ehci_ops *ops);
Simon Glass0851caa2015-03-25 12:22:19 -0600273
274/**
275 * ehci_get_controller_priv() - Get controller private data
276 *
277 * @index Controller number to get
278 * @return controller pointer for this index
279 */
280void *ehci_get_controller_priv(int index);
281
Remy Böhmer33e87482008-12-13 22:51:58 +0100282/* Low level init functions */
Troy Kisky7d6bbb92013-10-10 15:27:57 -0700283int ehci_hcd_init(int index, enum usb_init_type init,
284 struct ehci_hccr **hccr, struct ehci_hcor **hcor);
Lucas Stach3494a4c2012-09-26 00:14:35 +0200285int ehci_hcd_stop(int index);
Remy Böhmer33e87482008-12-13 22:51:58 +0100286
Simon Glassa194b252015-03-25 12:22:29 -0600287int ehci_register(struct udevice *dev, struct ehci_hccr *hccr,
288 struct ehci_hcor *hcor, const struct ehci_ops *ops,
289 uint tweaks, enum usb_init_type init);
290int ehci_deregister(struct udevice *dev);
291extern struct dm_usb_ops ehci_usb_ops;
292
Michael Trimarchi241f7512008-11-28 13:20:46 +0100293#endif /* USB_EHCI_H */