1 From ca86ebf3fddbdfa8aecc4b887ef059948ee79621 Mon Sep 17 00:00:00 2001
2 From: Biwen Li <biwen.li@nxp.com>
3 Date: Wed, 17 Apr 2019 18:59:08 +0800
4 Subject: [PATCH] usb: support layerscape
6 This is an integrated patch of usb for layerscape
8 Signed-off-by: Anurag Kumar Vulisha <anurag.kumar.vulisha@xilinx.com>
9 Signed-off-by: Biwen Li <biwen.li@nxp.com>
10 Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
11 Signed-off-by: Changming Huang <jerry.huang@nxp.com>
12 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14 Signed-off-by: Li Yang <leoli@freescale.com>
15 Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
16 Signed-off-by: Nikhil Badola <nikhil.badola@freescale.com>
17 Signed-off-by: Rajesh Bhagat <rajesh.bhagat@nxp.com>
18 Signed-off-by: Ramneek Mehresh <ramneek.mehresh@freescale.com>
19 Signed-off-by: Ran Wang <ran.wang_1@nxp.com>
20 Signed-off-by: Roger Quadros <rogerq@ti.com>
21 Signed-off-by: Shengzhou Liu <Shengzhou.Liu@freescale.com>
22 Signed-off-by: Suresh Gupta <suresh.gupta@freescale.com>
23 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
24 Signed-off-by: Yinbo Zhu <yinbo.zhu@nxp.com>
25 Signed-off-by: Zhao Chenhui <chenhui.zhao@freescale.com>
27 arch/arm64/include/asm/io.h | 28 +++
28 drivers/usb/common/common.c | 50 +++++
29 drivers/usb/core/usb.c | 1 +
30 drivers/usb/dwc3/core.c | 167 ++++++++++++++++
31 drivers/usb/dwc3/core.h | 58 ++++++
32 drivers/usb/dwc3/ep0.c | 4 +-
33 drivers/usb/dwc3/gadget.c | 7 +
34 drivers/usb/dwc3/host.c | 9 +
35 drivers/usb/gadget/udc/fsl_udc_core.c | 46 +++--
36 drivers/usb/gadget/udc/fsl_usb2_udc.h | 16 +-
37 drivers/usb/host/Kconfig | 2 +-
38 drivers/usb/host/ehci-fsl.c | 276 +++++++++++++++++++++++---
39 drivers/usb/host/ehci-fsl.h | 3 +
40 drivers/usb/host/ehci-hub.c | 2 +
41 drivers/usb/host/ehci.h | 3 +
42 drivers/usb/host/fsl-mph-dr-of.c | 11 +
43 drivers/usb/host/xhci-hub.c | 22 ++
44 drivers/usb/host/xhci-plat.c | 16 +-
45 drivers/usb/host/xhci-ring.c | 28 ++-
46 drivers/usb/host/xhci.c | 37 +++-
47 drivers/usb/host/xhci.h | 10 +-
48 drivers/usb/phy/phy-fsl-usb.c | 59 ++++--
49 drivers/usb/phy/phy-fsl-usb.h | 8 +
50 include/linux/usb.h | 1 +
51 include/linux/usb/of.h | 2 +
52 25 files changed, 780 insertions(+), 86 deletions(-)
54 --- a/arch/arm64/include/asm/io.h
55 +++ b/arch/arm64/include/asm/io.h
56 @@ -210,6 +210,34 @@ extern void __iomem *ioremap_cache(phys_
57 #define iowrite32be(v,p) ({ __iowmb(); __raw_writel((__force __u32)cpu_to_be32(v), p); })
58 #define iowrite64be(v,p) ({ __iowmb(); __raw_writeq((__force __u64)cpu_to_be64(v), p); })
61 +#define setbits32(_addr, _v) iowrite32be(ioread32be(_addr) | (_v), (_addr))
62 +#define clrbits32(_addr, _v) iowrite32be(ioread32be(_addr) & ~(_v), (_addr))
64 +#define setbits16(_addr, _v) iowrite16be(ioread16be(_addr) | (_v), (_addr))
65 +#define clrbits16(_addr, _v) iowrite16be(ioread16be(_addr) & ~(_v), (_addr))
67 +#define setbits8(_addr, _v) iowrite8(ioread8(_addr) | (_v), (_addr))
68 +#define clrbits8(_addr, _v) iowrite8(ioread8(_addr) & ~(_v), (_addr))
70 +/* Clear and set bits in one shot. These macros can be used to clear and
71 + * set multiple bits in a register using a single read-modify-write. These
72 + * macros can also be used to set a multiple-bit bit pattern using a mask,
73 + * by specifying the mask in the 'clear' parameter and the new bit pattern
74 + * in the 'set' parameter.
77 +#define clrsetbits_be32(addr, clear, set) \
78 + iowrite32be((ioread32be(addr) & ~(clear)) | (set), (addr))
79 +#define clrsetbits_le32(addr, clear, set) \
80 + iowrite32le((ioread32le(addr) & ~(clear)) | (set), (addr))
81 +#define clrsetbits_be16(addr, clear, set) \
82 + iowrite16be((ioread16be(addr) & ~(clear)) | (set), (addr))
83 +#define clrsetbits_le16(addr, clear, set) \
84 + iowrite16le((ioread16le(addr) & ~(clear)) | (set), (addr))
85 +#define clrsetbits_8(addr, clear, set) \
86 + iowrite8((ioread8(addr) & ~(clear)) | (set), (addr))
88 #include <asm-generic/io.h>
91 --- a/drivers/usb/common/common.c
92 +++ b/drivers/usb/common/common.c
93 @@ -105,6 +105,56 @@ static const char *const usb_dr_modes[]
94 [USB_DR_MODE_OTG] = "otg",
98 + * of_usb_get_dr_mode - Get dual role mode for given device_node
99 + * @np: Pointer to the given device_node
101 + * The function gets phy interface string from property 'dr_mode',
102 + * and returns the correspondig enum usb_dr_mode
104 +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
106 + const char *dr_mode;
109 + err = of_property_read_string(np, "dr_mode", &dr_mode);
111 + return USB_DR_MODE_UNKNOWN;
113 + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
114 + if (!strcmp(dr_mode, usb_dr_modes[i]))
117 + return USB_DR_MODE_UNKNOWN;
119 +EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
122 + * of_usb_get_maximum_speed - Get maximum requested speed for a given USB
124 + * @np: Pointer to the given device_node
126 + * The function gets the maximum speed string from property "maximum-speed",
127 + * and returns the corresponding enum usb_device_speed.
129 +enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np)
131 + const char *maximum_speed;
135 + err = of_property_read_string(np, "maximum-speed", &maximum_speed);
137 + return USB_SPEED_UNKNOWN;
139 + for (i = 0; i < ARRAY_SIZE(speed_names); i++)
140 + if (strcmp(maximum_speed, speed_names[i]) == 0)
143 + return USB_SPEED_UNKNOWN;
145 +EXPORT_SYMBOL_GPL(of_usb_get_maximum_speed);
147 static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
150 --- a/drivers/usb/core/usb.c
151 +++ b/drivers/usb/core/usb.c
152 @@ -593,6 +593,7 @@ struct usb_device *usb_alloc_dev(struct
153 dev->dev.dma_mask = bus->sysdev->dma_mask;
154 dev->dev.dma_pfn_offset = bus->sysdev->dma_pfn_offset;
155 set_dev_node(&dev->dev, dev_to_node(bus->sysdev));
156 + dev->dev.of_node = bus->controller->of_node;
157 dev->state = USB_STATE_ATTACHED;
158 dev->lpm_disable_count = 1;
159 atomic_set(&dev->urbnum, 0);
160 --- a/drivers/usb/dwc3/core.c
161 +++ b/drivers/usb/dwc3/core.c
162 @@ -103,6 +103,41 @@ static int dwc3_get_dr_mode(struct dwc3
163 static void dwc3_event_buffers_cleanup(struct dwc3 *dwc);
164 static int dwc3_event_buffers_setup(struct dwc3 *dwc);
167 + * dwc3_power_of_all_roothub_ports - Power off all Root hub ports
168 + * @dwc3: Pointer to our controller context structure
170 +static void dwc3_power_off_all_roothub_ports(struct dwc3 *dwc)
173 + u32 reg, op_regs_base, offset;
174 + void __iomem *xhci_regs;
176 + /* xhci regs is not mapped yet, do it temperary here */
177 + if (dwc->xhci_resources[0].start) {
178 + xhci_regs = ioremap(dwc->xhci_resources[0].start,
179 + DWC3_XHCI_REGS_END);
180 + if (IS_ERR(xhci_regs)) {
181 + dev_err(dwc->dev, "Failed to ioremap xhci_regs\n");
185 + op_regs_base = HC_LENGTH(readl(xhci_regs));
186 + reg = readl(xhci_regs + XHCI_HCSPARAMS1);
187 + port_num = HCS_MAX_PORTS(reg);
189 + for (i = 1; i <= port_num; i++) {
190 + offset = op_regs_base + XHCI_PORTSC_BASE + 0x10*(i-1);
191 + reg = readl(xhci_regs + offset);
192 + reg &= ~PORT_POWER;
193 + writel(reg, xhci_regs + offset);
196 + iounmap(xhci_regs);
198 + dev_err(dwc->dev, "xhci base reg invalid\n");
201 static void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
204 @@ -111,6 +146,15 @@ static void dwc3_set_prtcap(struct dwc3
205 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
206 reg |= DWC3_GCTL_PRTCAPDIR(mode);
207 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
210 + * We have to power off all Root hub ports immediately after DWC3 set
211 + * to host mode to avoid VBUS glitch happen when xhci get reset later.
213 + if (dwc->host_vbus_glitches) {
214 + if (mode == DWC3_GCTL_PRTCAP_HOST)
215 + dwc3_power_off_all_roothub_ports(dwc);
219 static void __dwc3_set_mode(struct work_struct *work)
220 @@ -766,6 +810,96 @@ static void dwc3_core_setup_global_contr
221 static int dwc3_core_get_phy(struct dwc3 *dwc);
222 static int dwc3_core_ulpi_init(struct dwc3 *dwc);
224 +/* set global soc bus configuration registers */
225 +static void dwc3_set_soc_bus_cfg(struct dwc3 *dwc)
227 + struct device *dev = dwc->dev;
234 + cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0);
237 + * Handle property "snps,incr-burst-type-adjustment".
238 + * Get the number of value from this property:
239 + * result <= 0, means this property is not supported.
240 + * result = 1, means INCRx burst mode supported.
241 + * result > 1, means undefined length burst mode supported.
243 + ntype = device_property_read_u32_array(dev,
244 + "snps,incr-burst-type-adjustment", NULL, 0);
246 + vals = kcalloc(ntype, sizeof(u32), GFP_KERNEL);
248 + dev_err(dev, "Error to get memory\n");
251 + /* Get INCR burst type, and parse it */
252 + ret = device_property_read_u32_array(dev,
253 + "snps,incr-burst-type-adjustment", vals, ntype);
255 + dev_err(dev, "Error to get property\n");
258 + *(dwc->incrx_type + 1) = vals[0];
260 + *dwc->incrx_type = 1;
261 + for (i = 1; i < ntype; i++) {
262 + if (vals[i] > *(dwc->incrx_type + 1))
263 + *(dwc->incrx_type + 1) = vals[i];
266 + *dwc->incrx_type = 0;
268 + /* Enable Undefined Length INCR Burst and Enable INCRx Burst */
269 + cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK;
270 + if (*dwc->incrx_type)
271 + cfg |= DWC3_GSBUSCFG0_INCRBRSTENA;
272 + switch (*(dwc->incrx_type + 1)) {
274 + cfg |= DWC3_GSBUSCFG0_INCR256BRSTENA;
277 + cfg |= DWC3_GSBUSCFG0_INCR128BRSTENA;
280 + cfg |= DWC3_GSBUSCFG0_INCR64BRSTENA;
283 + cfg |= DWC3_GSBUSCFG0_INCR32BRSTENA;
286 + cfg |= DWC3_GSBUSCFG0_INCR16BRSTENA;
289 + cfg |= DWC3_GSBUSCFG0_INCR8BRSTENA;
292 + cfg |= DWC3_GSBUSCFG0_INCR4BRSTENA;
297 + dev_err(dev, "Invalid property\n");
302 + /* Handle usb snooping */
303 + if (dwc->dma_coherent) {
304 + cfg &= ~DWC3_GSBUSCFG0_SNP_MASK;
305 + cfg |= (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DATARD_SHIFT) |
306 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DESCRD_SHIFT) |
307 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DATAWR_SHIFT) |
308 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DESCWR_SHIFT);
311 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg);
315 * dwc3_core_init - Low-level initialization of DWC3 Core
316 * @dwc: Pointer to our controller context structure
317 @@ -828,6 +962,8 @@ static int dwc3_core_init(struct dwc3 *d
318 /* Adjust Frame Length */
319 dwc3_frame_length_adjustment(dwc);
321 + dwc3_set_soc_bus_cfg(dwc);
323 usb_phy_set_suspend(dwc->usb2_phy, 0);
324 usb_phy_set_suspend(dwc->usb3_phy, 0);
325 ret = phy_power_on(dwc->usb2_generic_phy);
326 @@ -871,6 +1007,22 @@ static int dwc3_core_init(struct dwc3 *d
327 dwc3_writel(dwc->regs, DWC3_GUCTL1, reg);
330 + if (dwc->dr_mode == USB_DR_MODE_HOST ||
331 + dwc->dr_mode == USB_DR_MODE_OTG) {
332 + reg = dwc3_readl(dwc->regs, DWC3_GUCTL);
335 + * Enable Auto retry Feature to make the controller operating in
336 + * Host mode on seeing transaction errors(CRC errors or internal
337 + * overrun scenerios) on IN transfers to reply to the device
338 + * with a non-terminating retry ACK (i.e, an ACK transcation
339 + * packet with Retry=1 & Nump != 0)
341 + reg |= DWC3_GUCTL_HSTINAUTORETRY;
343 + dwc3_writel(dwc->regs, DWC3_GUCTL, reg);
349 @@ -1074,6 +1226,8 @@ static void dwc3_get_properties(struct d
351 dwc->usb3_lpm_capable = device_property_read_bool(dev,
352 "snps,usb3_lpm_capable");
353 + dwc->dma_coherent = device_property_read_bool(dev,
356 dwc->disable_scramble_quirk = device_property_read_bool(dev,
357 "snps,disable_scramble_quirk");
358 @@ -1106,8 +1260,16 @@ static void dwc3_get_properties(struct d
359 dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev,
360 "snps,dis-tx-ipgap-linecheck-quirk");
362 + dwc->quirk_reverse_in_out = device_property_read_bool(dev,
363 + "snps,quirk_reverse_in_out");
364 + dwc->quirk_stop_transfer_in_block = device_property_read_bool(dev,
365 + "snps,quirk_stop_transfer_in_block");
366 + dwc->quirk_stop_ep_in_u1 = device_property_read_bool(dev,
367 + "snps,quirk_stop_ep_in_u1");
368 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
369 "snps,tx_de_emphasis_quirk");
370 + dwc->disable_devinit_u1u2_quirk = device_property_read_bool(dev,
371 + "snps,disable_devinit_u1u2");
372 device_property_read_u8(dev, "snps,tx_de_emphasis",
374 device_property_read_string(dev, "snps,hsphy_interface",
375 @@ -1115,6 +1277,9 @@ static void dwc3_get_properties(struct d
376 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment",
379 + dwc->host_vbus_glitches = device_property_read_bool(dev,
380 + "snps,host-vbus-glitches");
382 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
383 dwc->tx_de_emphasis = tx_de_emphasis;
385 @@ -1365,12 +1530,14 @@ static int dwc3_resume_common(struct dwc
387 switch (dwc->dr_mode) {
388 case USB_DR_MODE_PERIPHERAL:
389 + dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
390 case USB_DR_MODE_OTG:
391 spin_lock_irqsave(&dwc->lock, flags);
392 dwc3_gadget_resume(dwc);
393 spin_unlock_irqrestore(&dwc->lock, flags);
395 case USB_DR_MODE_HOST:
396 + dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
400 --- a/drivers/usb/dwc3/core.h
401 +++ b/drivers/usb/dwc3/core.h
406 +/* Global SoC Bus Configuration Register 0 */
407 +#define AXI3_CACHE_TYPE_AW 0x8 /* write allocate */
408 +#define AXI3_CACHE_TYPE_AR 0x4 /* read allocate */
409 +#define AXI3_CACHE_TYPE_SNP 0x2 /* cacheable */
410 +#define AXI3_CACHE_TYPE_BUF 0x1 /* bufferable */
411 +#define DWC3_GSBUSCFG0_DATARD_SHIFT 28
412 +#define DWC3_GSBUSCFG0_DESCRD_SHIFT 24
413 +#define DWC3_GSBUSCFG0_DATAWR_SHIFT 20
414 +#define DWC3_GSBUSCFG0_DESCWR_SHIFT 16
415 +#define DWC3_GSBUSCFG0_SNP_MASK 0xffff0000
416 +#define DWC3_GSBUSCFG0_DATABIGEND (1 << 11)
417 +#define DWC3_GSBUSCFG0_DESCBIGEND (1 << 10)
418 +#define DWC3_GSBUSCFG0_INCR256BRSTENA (1 << 7) /* INCR256 burst */
419 +#define DWC3_GSBUSCFG0_INCR128BRSTENA (1 << 6) /* INCR128 burst */
420 +#define DWC3_GSBUSCFG0_INCR64BRSTENA (1 << 5) /* INCR64 burst */
421 +#define DWC3_GSBUSCFG0_INCR32BRSTENA (1 << 4) /* INCR32 burst */
422 +#define DWC3_GSBUSCFG0_INCR16BRSTENA (1 << 3) /* INCR16 burst */
423 +#define DWC3_GSBUSCFG0_INCR8BRSTENA (1 << 2) /* INCR8 burst */
424 +#define DWC3_GSBUSCFG0_INCR4BRSTENA (1 << 1) /* INCR4 burst */
425 +#define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0) /* undefined length enable */
426 +#define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff
428 +/* Global SoC Bus Configuration Register 1 */
429 +#define DWC3_GSBUSCFG1_1KPAGEENA (1 << 12) /* 1K page boundary enable */
430 +#define DWC3_GSBUSCFG1_PTRANSLIMIT_MASK 0xf00
432 /* Global Debug Queue/FIFO Space Available Register */
433 #define DWC3_GDBGFIFOSPACE_NUM(n) ((n) & 0x1f)
434 #define DWC3_GDBGFIFOSPACE_TYPE(n) (((n) << 5) & 0x1e0)
436 #define DWC3_GCTL_GBLHIBERNATIONEN BIT(1)
437 #define DWC3_GCTL_DSBLCLKGTNG BIT(0)
439 +/* Global User Control Register */
440 +#define DWC3_GUCTL_HSTINAUTORETRY BIT(14)
442 /* Global User Control 1 Register */
443 #define DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS BIT(28)
444 #define DWC3_GUCTL1_DEV_L1_EXIT_BY_HW BIT(24)
446 #define DWC3_DEV_IMOD_INTERVAL_SHIFT 0
447 #define DWC3_DEV_IMOD_INTERVAL_MASK (0xffff << 0)
449 +/* Partial XHCI Register and Bit fields for quirk */
450 +#define XHCI_HCSPARAMS1 0x4
451 +#define XHCI_PORTSC_BASE 0x400
452 +#define PORT_POWER (1 << 9)
453 +#define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f)
454 +#define XHCI_HC_LENGTH(p) (((p)>>00)&0x00ff)
455 +#define HC_LENGTH(p) XHCI_HC_LENGTH(p)
460 @@ -788,6 +825,7 @@ struct dwc3_scratchpad_array {
461 * @regs: base address for our registers
462 * @regs_size: address space size
463 * @fladj: frame length adjustment
464 + * @incrx_type: INCR burst type adjustment
465 * @irq_gadget: peripheral controller's IRQ number
466 * @nr_scratch: number of scratch buffers
467 * @u1u2: only used on revisions <1.83a for workaround
468 @@ -843,6 +881,7 @@ struct dwc3_scratchpad_array {
469 * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
470 * @three_stage_setup: set if we perform a three phase setup
471 * @usb3_lpm_capable: set if hadrware supports Link Power Management
472 + * @dma_coherent: set if hadrware supports DMA snoop
473 * @disable_scramble_quirk: set if we enable the disable scramble quirk
474 * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
475 * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
476 @@ -869,6 +908,13 @@ struct dwc3_scratchpad_array {
477 * 1 - -3.5dB de-emphasis
480 + * @disable_devinit_u1u2_quirk: disable device-initiated U1/U2 request.
481 + * @quirk_reverse_in_out: prevent tx fifo reverse the data direction
482 + * @quirk_stop_transfer_in_block: prevent block transmission from being
484 + * @quirk_stop_ep_in_u1: replace stop commad with disable slot command
485 + * @host-vbus-glitches: set to avoid vbus glitch during
487 * @imod_interval: set the interrupt moderation interval in 250ns
488 * increments or 0 to disable.
490 @@ -921,6 +967,12 @@ struct dwc3 {
491 enum usb_phy_interface hsphy_mode;
495 + * For INCR burst type.
496 + * First field: for undefined length INCR burst type enable.
497 + * Second field: for INCRx burst type enable
503 @@ -1005,6 +1057,7 @@ struct dwc3 {
504 unsigned setup_packet_pending:1;
505 unsigned three_stage_setup:1;
506 unsigned usb3_lpm_capable:1;
507 + unsigned dma_coherent:1;
509 unsigned disable_scramble_quirk:1;
510 unsigned u2exit_lfps_quirk:1;
511 @@ -1024,6 +1077,11 @@ struct dwc3 {
513 unsigned tx_de_emphasis_quirk:1;
514 unsigned tx_de_emphasis:2;
515 + unsigned disable_devinit_u1u2_quirk:1;
516 + unsigned quirk_reverse_in_out:1;
517 + unsigned quirk_stop_transfer_in_block:1;
518 + unsigned quirk_stop_ep_in_u1:1;
519 + unsigned host_vbus_glitches:1;
523 --- a/drivers/usb/dwc3/ep0.c
524 +++ b/drivers/usb/dwc3/ep0.c
525 @@ -391,7 +391,7 @@ static int dwc3_ep0_handle_u1(struct dwc
528 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
530 + if (set && !dwc->disable_devinit_u1u2_quirk)
531 reg |= DWC3_DCTL_INITU1ENA;
533 reg &= ~DWC3_DCTL_INITU1ENA;
534 @@ -413,7 +413,7 @@ static int dwc3_ep0_handle_u2(struct dwc
537 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
539 + if (set && !dwc->disable_devinit_u1u2_quirk)
540 reg |= DWC3_DCTL_INITU2ENA;
542 reg &= ~DWC3_DCTL_INITU2ENA;
543 --- a/drivers/usb/dwc3/gadget.c
544 +++ b/drivers/usb/dwc3/gadget.c
545 @@ -3210,6 +3210,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
551 irq = dwc3_gadget_get_irq(dwc);
553 @@ -3288,6 +3289,12 @@ int dwc3_gadget_init(struct dwc3 *dwc)
555 dwc3_gadget_set_speed(&dwc->gadget, dwc->maximum_speed);
557 + if (dwc->disable_devinit_u1u2_quirk) {
558 + reg = dwc3_readl(dwc->regs, DWC3_DCTL);
559 + reg &= ~(DWC3_DCTL_INITU1ENA | DWC3_DCTL_INITU2ENA);
560 + dwc3_writel(dwc->regs, DWC3_DCTL, reg);
566 --- a/drivers/usb/dwc3/host.c
567 +++ b/drivers/usb/dwc3/host.c
568 @@ -98,6 +98,15 @@ int dwc3_host_init(struct dwc3 *dwc)
570 memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props));
572 + if (dwc->quirk_reverse_in_out)
573 + props[prop_idx++].name = "quirk-reverse-in-out";
575 + if (dwc->quirk_stop_transfer_in_block)
576 + props[prop_idx++].name = "quirk-stop-transfer-in-block";
578 + if (dwc->quirk_stop_ep_in_u1)
579 + props[prop_idx++].name = "quirk-stop-ep-in-u1";
581 if (dwc->usb3_lpm_capable)
582 props[prop_idx++].name = "usb3-lpm-capable";
584 --- a/drivers/usb/gadget/udc/fsl_udc_core.c
585 +++ b/drivers/usb/gadget/udc/fsl_udc_core.c
586 @@ -198,7 +198,11 @@ __acquires(ep->udc->lock)
588 spin_unlock(&ep->udc->lock);
590 - usb_gadget_giveback_request(&ep->ep, &req->req);
591 + /* this complete() should a func implemented by gadget layer,
592 + * eg fsg->bulk_in_complete()
594 + if (req->req.complete)
595 + usb_gadget_giveback_request(&ep->ep, &req->req);
597 spin_lock(&ep->udc->lock);
598 ep->stopped = stopped;
599 @@ -245,10 +249,10 @@ static int dr_controller_setup(struct fs
600 if (udc->pdata->have_sysif_regs) {
601 if (udc->pdata->controller_ver) {
602 /* controller version 1.6 or above */
603 - ctrl = __raw_readl(&usb_sys_regs->control);
604 + ctrl = ioread32be(&usb_sys_regs->control);
605 ctrl &= ~USB_CTRL_UTMI_PHY_EN;
606 ctrl |= USB_CTRL_USB_EN;
607 - __raw_writel(ctrl, &usb_sys_regs->control);
608 + iowrite32be(ctrl, &usb_sys_regs->control);
611 portctrl |= PORTSCX_PTS_ULPI;
612 @@ -257,13 +261,14 @@ static int dr_controller_setup(struct fs
613 portctrl |= PORTSCX_PTW_16BIT;
615 case FSL_USB2_PHY_UTMI:
616 + case FSL_USB2_PHY_UTMI_DUAL:
617 if (udc->pdata->have_sysif_regs) {
618 if (udc->pdata->controller_ver) {
619 /* controller version 1.6 or above */
620 - ctrl = __raw_readl(&usb_sys_regs->control);
621 + ctrl = ioread32be(&usb_sys_regs->control);
622 ctrl |= (USB_CTRL_UTMI_PHY_EN |
624 - __raw_writel(ctrl, &usb_sys_regs->control);
625 + iowrite32be(ctrl, &usb_sys_regs->control);
626 mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI
627 PHY CLK to become stable - 10ms*/
629 @@ -329,22 +334,22 @@ static int dr_controller_setup(struct fs
630 /* Config control enable i/o output, cpu endian register */
631 #ifndef CONFIG_ARCH_MXC
632 if (udc->pdata->have_sysif_regs) {
633 - ctrl = __raw_readl(&usb_sys_regs->control);
634 + ctrl = ioread32be(&usb_sys_regs->control);
635 ctrl |= USB_CTRL_IOENB;
636 - __raw_writel(ctrl, &usb_sys_regs->control);
637 + iowrite32be(ctrl, &usb_sys_regs->control);
641 -#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
642 +#if !defined(CONFIG_NOT_COHERENT_CACHE)
643 /* Turn on cache snooping hardware, since some PowerPC platforms
644 * wholly rely on hardware to deal with cache coherent. */
646 if (udc->pdata->have_sysif_regs) {
647 /* Setup Snooping for all the 4GB space */
648 tmp = SNOOP_SIZE_2GB; /* starts from 0x0, size 2G */
649 - __raw_writel(tmp, &usb_sys_regs->snoop1);
650 + iowrite32be(tmp, &usb_sys_regs->snoop1);
651 tmp |= 0x80000000; /* starts from 0x8000000, size 2G */
652 - __raw_writel(tmp, &usb_sys_regs->snoop2);
653 + iowrite32be(tmp, &usb_sys_regs->snoop2);
657 @@ -1056,7 +1061,7 @@ static int fsl_ep_fifo_status(struct usb
658 struct ep_queue_head *qh;
660 ep = container_of(_ep, struct fsl_ep, ep);
661 - if (!_ep || (!ep->ep.desc && ep_index(ep) != 0))
662 + if (!_ep || !ep->ep.desc || (ep_index(ep) == 0))
665 udc = (struct fsl_udc *)ep->udc;
666 @@ -1598,14 +1603,13 @@ static int process_ep_req(struct fsl_udc
667 struct fsl_req *curr_req)
669 struct ep_td_struct *curr_td;
670 - int td_complete, actual, remaining_length, j, tmp;
671 + int actual, remaining_length, j, tmp;
674 struct ep_queue_head *curr_qh = &udc->ep_qh[pipe];
675 int direction = pipe % 2;
677 curr_td = curr_req->head;
679 actual = curr_req->req.length;
681 for (j = 0; j < curr_req->dtd_count; j++) {
682 @@ -1650,11 +1654,9 @@ static int process_ep_req(struct fsl_udc
691 VDBG("dTD transmitted successful");
694 @@ -1697,7 +1699,7 @@ static void dtd_complete_irq(struct fsl_
695 curr_ep = get_ep_by_pipe(udc, i);
697 /* If the ep is configured */
698 - if (!curr_ep->ep.name) {
699 + if (strncmp(curr_ep->name, "ep", 2)) {
700 WARNING("Invalid EP?");
703 @@ -2419,10 +2421,12 @@ static int fsl_udc_probe(struct platform
704 usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
707 +#ifdef CONFIG_ARCH_MXC
708 /* Initialize USB clocks */
709 ret = fsl_udc_clk_init(pdev);
711 goto err_iounmap_noclk;
714 /* Read Device Controller Capability Parameters register */
715 dccparams = fsl_readl(&dr_regs->dccparams);
716 @@ -2462,9 +2466,11 @@ static int fsl_udc_probe(struct platform
717 dr_controller_setup(udc_controller);
720 +#ifdef CONFIG_ARCH_MXC
721 ret = fsl_udc_clk_finalize(pdev);
726 /* Setup gadget structure */
727 udc_controller->gadget.ops = &fsl_gadget_ops;
728 @@ -2477,6 +2483,7 @@ static int fsl_udc_probe(struct platform
729 /* Setup gadget.dev and register with kernel */
730 dev_set_name(&udc_controller->gadget.dev, "gadget");
731 udc_controller->gadget.dev.of_node = pdev->dev.of_node;
732 + set_dma_ops(&udc_controller->gadget.dev, pdev->dev.dma_ops);
734 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
735 udc_controller->gadget.is_otg = 1;
736 @@ -2528,7 +2535,9 @@ err_free_irq:
740 +#ifdef CONFIG_ARCH_MXC
741 fsl_udc_clk_release();
745 err_release_mem_region:
746 @@ -2556,8 +2565,9 @@ static int fsl_udc_remove(struct platfor
747 udc_controller->done = &done;
748 usb_del_gadget_udc(&udc_controller->gadget);
750 +#ifdef CONFIG_ARCH_MXC
751 fsl_udc_clk_release();
754 /* DR has been stopped in usb_gadget_unregister_driver() */
757 @@ -2569,7 +2579,7 @@ static int fsl_udc_remove(struct platfor
758 dma_pool_destroy(udc_controller->td_pool);
759 free_irq(udc_controller->irq, udc_controller);
761 - if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
762 + if (res && (pdata->operating_mode == FSL_USB2_DR_DEVICE))
763 release_mem_region(res->start, resource_size(res));
765 /* free udc --wait for the release() finished */
766 --- a/drivers/usb/gadget/udc/fsl_usb2_udc.h
767 +++ b/drivers/usb/gadget/udc/fsl_usb2_udc.h
769 #define USB_MAX_CTRL_PAYLOAD 64
770 #define USB_DR_SYS_OFFSET 0x400
772 +#ifdef CONFIG_SOC_LS1021A
773 +#undef CONFIG_ARCH_MXC
776 /* USB DR device mode registers (Little Endian) */
777 struct usb_dr_device {
778 /* Capability register */
779 @@ -597,18 +601,6 @@ struct platform_device;
780 int fsl_udc_clk_init(struct platform_device *pdev);
781 int fsl_udc_clk_finalize(struct platform_device *pdev);
782 void fsl_udc_clk_release(void);
784 -static inline int fsl_udc_clk_init(struct platform_device *pdev)
788 -static inline int fsl_udc_clk_finalize(struct platform_device *pdev)
792 -static inline void fsl_udc_clk_release(void)
798 --- a/drivers/usb/host/Kconfig
799 +++ b/drivers/usb/host/Kconfig
800 @@ -165,7 +165,7 @@ config XPS_USB_HCD_XILINX
803 tristate "Support for Freescale PPC on-chip EHCI USB controller"
805 + depends on USB_EHCI_HCD
806 select USB_EHCI_ROOT_HUB_TT
808 Variation of ARC USB block used in some Freescale chips.
809 --- a/drivers/usb/host/ehci-fsl.c
810 +++ b/drivers/usb/host/ehci-fsl.c
812 #include <linux/platform_device.h>
813 #include <linux/fsl_devices.h>
814 #include <linux/of_platform.h>
815 +#include <linux/io.h>
818 +#include <linux/suspend.h>
822 #include "ehci-fsl.h"
824 +#define FSL_USB_PHY_ADDR 0xffe214000
826 +struct ccsr_usb_port_ctrl {
843 +struct ccsr_usb_phy {
845 + struct ccsr_usb_port_ctrl port1;
853 + struct ccsr_usb_port_ctrl port2;
857 #define DRIVER_DESC "Freescale EHCI Host controller driver"
858 #define DRV_NAME "ehci-fsl"
860 static struct hc_driver __read_mostly fsl_ehci_hc_driver;
863 + struct ehci_hcd ehci;
866 +struct ehci_regs saved_regs;
867 +struct ccsr_usb_phy saved_phy_regs;
868 +/* Saved USB PHY settings, need to restore after deep sleep. */
872 + * store current hcd state for otg;
873 + * have_hcd is true when host drv al already part of otg framework,
875 + * hcd_add is true when otg framework wants to add host
876 + * drv as part of otg;flase when it wants to remove it
878 +unsigned have_hcd:1;
882 +static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
884 +struct ehci_hcd *ehci = hcd_to_ehci(hcd);
886 +return container_of(ehci, struct ehci_fsl, ehci);
889 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
890 +static void do_change_hcd(struct work_struct *work)
892 + struct ehci_hcd *ehci = container_of(work, struct ehci_hcd,
894 + struct usb_hcd *hcd = ehci_to_hcd(ehci);
895 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
896 + void __iomem *non_ehci = hcd->regs;
899 + if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
900 + writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
901 + /* host, gadget and otg share same int line */
902 + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
904 + ehci_fsl->have_hcd = 1;
905 + } else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
906 + usb_remove_hcd(hcd);
907 + ehci_fsl->have_hcd = 0;
912 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
913 +static void do_change_hcd(struct work_struct *work)
915 + struct ehci_hcd *ehci = container_of(work, struct ehci_hcd,
917 + struct usb_hcd *hcd = ehci_to_hcd(ehci);
918 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
919 + void __iomem *non_ehci = hcd->regs;
922 + if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
923 + writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
924 + /* host, gadget and otg share same int line */
925 + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
927 + ehci_fsl->have_hcd = 1;
928 + } else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
929 + usb_remove_hcd(hcd);
930 + ehci_fsl->have_hcd = 0;
935 /* configure so an HC device and id are always provided */
936 /* always called with process context; sleeping is OK */
938 @@ -131,6 +242,12 @@ static int fsl_ehci_drv_probe(struct pla
939 clrsetbits_be32(hcd->regs + FSL_SOC_USB_CTRL,
940 CONTROL_REGISTER_W1C_MASK, 0x4);
942 + /* Set USB_EN bit to select ULPI phy for USB controller version 2.5 */
943 + if (pdata->controller_ver == FSL_USB_VER_2_5 &&
944 + pdata->phy_mode == FSL_USB2_PHY_ULPI)
945 + iowrite32be(USB_CTRL_USB_EN, hcd->regs + FSL_SOC_USB_CTRL);
949 * Enable UTMI phy and program PTS field in UTMI mode before asserting
950 * controller reset for USB Controller version 2.5
951 @@ -143,16 +260,20 @@ static int fsl_ehci_drv_probe(struct pla
953 /* Don't need to set host mode here. It will be done by tdi_reset() */
955 - retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
956 + retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_NO_SUSPEND);
959 device_wakeup_enable(hcd->self.controller);
961 -#ifdef CONFIG_USB_OTG
962 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
963 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
964 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
965 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
967 hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2);
969 + INIT_WORK(&ehci->change_hcd_work, do_change_hcd);
971 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
972 hcd, ehci, hcd->usb_phy);
974 @@ -168,6 +289,11 @@ static int fsl_ehci_drv_probe(struct pla
979 + ehci_fsl->have_hcd = 1;
981 + dev_err(&pdev->dev, "wrong operating mode\n");
986 @@ -181,6 +307,17 @@ static int fsl_ehci_drv_probe(struct pla
990 +static bool usb_phy_clk_valid(struct usb_hcd *hcd)
992 + void __iomem *non_ehci = hcd->regs;
995 + if (!(ioread32be(non_ehci + FSL_SOC_USB_CTRL) & PHY_CLK_VALID))
1001 static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
1002 enum fsl_usb2_phy_modes phy_mode,
1003 unsigned int port_offset)
1004 @@ -219,6 +356,21 @@ static int ehci_fsl_setup_phy(struct usb
1006 case FSL_USB2_PHY_UTMI:
1007 case FSL_USB2_PHY_UTMI_DUAL:
1008 + if (pdata->has_fsl_erratum_a006918) {
1009 + pr_warn("fsl-ehci: USB PHY clock invalid\n");
1013 + /* PHY_CLK_VALID bit is de-featured from all controller
1014 + * versions below 2.4 and is to be checked only for
1015 + * internal UTMI phy
1017 + if (pdata->controller_ver > FSL_USB_VER_2_4 &&
1018 + pdata->have_sysif_regs && !usb_phy_clk_valid(hcd)) {
1019 + pr_err("fsl-ehci: USB PHY clock invalid\n");
1023 if (pdata->have_sysif_regs && pdata->controller_ver) {
1024 /* controller version 1.6 or above */
1025 clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
1026 @@ -295,14 +447,9 @@ static int ehci_fsl_usb_setup(struct ehc
1029 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
1030 - unsigned int chip, rev, svr;
1032 - svr = mfspr(SPRN_SVR);
1034 - rev = (svr >> 4) & 0xf;
1036 /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
1037 - if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
1038 + if (pdata->has_fsl_erratum_14 == 1)
1039 ehci->has_fsl_port_bug = 1;
1041 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
1042 @@ -382,16 +529,56 @@ static int ehci_fsl_setup(struct usb_hcd
1047 - struct ehci_hcd ehci;
1050 - /* Saved USB PHY settings, need to restore after deep sleep. */
1054 +void __iomem *phy_reg;
1058 +/* save usb registers */
1059 +static int ehci_fsl_save_context(struct usb_hcd *hcd)
1061 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1062 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1063 + void __iomem *non_ehci = hcd->regs;
1064 + struct device *dev = hcd->self.controller;
1065 + struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
1067 + if (pdata->phy_mode == FSL_USB2_PHY_UTMI_DUAL) {
1068 + phy_reg = ioremap(FSL_USB_PHY_ADDR,
1069 + sizeof(struct ccsr_usb_phy));
1070 + _memcpy_fromio((void *)&ehci_fsl->saved_phy_regs, phy_reg,
1071 + sizeof(struct ccsr_usb_phy));
1074 + _memcpy_fromio((void *)&ehci_fsl->saved_regs, ehci->regs,
1075 + sizeof(struct ehci_regs));
1076 + ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
1081 +/*Restore usb registers */
1082 +static int ehci_fsl_restore_context(struct usb_hcd *hcd)
1084 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1085 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1086 + void __iomem *non_ehci = hcd->regs;
1087 + struct device *dev = hcd->self.controller;
1088 + struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
1090 + if (pdata->phy_mode == FSL_USB2_PHY_UTMI_DUAL) {
1092 + _memcpy_toio(phy_reg,
1093 + (void *)&ehci_fsl->saved_phy_regs,
1094 + sizeof(struct ccsr_usb_phy));
1097 + _memcpy_toio(ehci->regs, (void *)&ehci_fsl->saved_regs,
1098 + sizeof(struct ehci_regs));
1099 + iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL);
1105 #ifdef CONFIG_PPC_MPC512x
1106 static int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
1107 @@ -538,26 +725,45 @@ static inline int ehci_fsl_mpc512x_drv_r
1109 #endif /* CONFIG_PPC_MPC512x */
1111 -static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
1113 - struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1115 - return container_of(ehci, struct ehci_fsl, ehci);
1118 static int ehci_fsl_drv_suspend(struct device *dev)
1120 struct usb_hcd *hcd = dev_get_drvdata(dev);
1121 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1122 void __iomem *non_ehci = hcd->regs;
1123 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1124 + struct usb_bus host = hcd->self;
1128 + suspend_state_t pm_state;
1129 + /* FIXME:Need to port fsl_pm.h before enable below code. */
1130 + /*pm_state = pm_suspend_state();*/
1131 + pm_state = PM_SUSPEND_MEM;
1133 +if (pm_state == PM_SUSPEND_MEM)
1134 + ehci_fsl_save_context(hcd);
1137 if (of_device_is_compatible(dev->parent->of_node,
1138 "fsl,mpc5121-usb2-dr")) {
1139 return ehci_fsl_mpc512x_drv_suspend(dev);
1142 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1143 + if (host.is_otg) {
1144 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1147 + ehci_fsl->hcd_add = 0;
1148 + schedule_work(&ehci->change_hcd_work);
1154 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
1155 device_may_wakeup(dev));
1157 if (!fsl_deep_sleep())
1160 @@ -571,12 +777,36 @@ static int ehci_fsl_drv_resume(struct de
1161 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1162 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1163 void __iomem *non_ehci = hcd->regs;
1164 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1165 + struct usb_bus host = hcd->self;
1169 + suspend_state_t pm_state;
1170 + /* FIXME:Need to port fsl_pm.h before enable below code.*/
1171 + /* pm_state = pm_suspend_state(); */
1172 + pm_state = PM_SUSPEND_MEM;
1174 + if (pm_state == PM_SUSPEND_MEM)
1175 + ehci_fsl_restore_context(hcd);
1178 if (of_device_is_compatible(dev->parent->of_node,
1179 "fsl,mpc5121-usb2-dr")) {
1180 return ehci_fsl_mpc512x_drv_resume(dev);
1183 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1184 + if (host.is_otg) {
1186 + ehci_fsl->hcd_add = 1;
1187 + schedule_work(&ehci->change_hcd_work);
1188 + usb_hcd_resume_root_hub(hcd);
1194 ehci_prepare_ports_for_controller_resume(ehci);
1195 if (!fsl_deep_sleep())
1197 --- a/drivers/usb/host/ehci-fsl.h
1198 +++ b/drivers/usb/host/ehci-fsl.h
1200 #define UTMI_PHY_EN (1<<9)
1201 #define ULPI_PHY_CLK_SEL (1<<10)
1202 #define PHY_CLK_VALID (1<<17)
1204 +/* Retry count for checking UTMI PHY CLK validity */
1205 +#define UTMI_PHY_CLK_VALID_CHK_RETRY 5
1206 #endif /* _EHCI_FSL_H */
1207 --- a/drivers/usb/host/ehci-hub.c
1208 +++ b/drivers/usb/host/ehci-hub.c
1209 @@ -305,6 +305,8 @@ static int ehci_bus_suspend (struct usb_
1210 USB_PORT_STAT_HIGH_SPEED)
1211 fs_idle_delay = true;
1212 ehci_writel(ehci, t2, reg);
1213 + if (ehci_has_fsl_susp_errata(ehci))
1214 + usleep_range(10000, 20000);
1218 --- a/drivers/usb/host/ehci.h
1219 +++ b/drivers/usb/host/ehci.h
1220 @@ -180,6 +180,9 @@ struct ehci_hcd { /* one per controlle
1221 unsigned periodic_count; /* periodic activity count */
1222 unsigned uframe_periodic_max; /* max periodic time per uframe */
1224 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1225 + struct work_struct change_hcd_work;
1228 /* list of itds & sitds completed while now_frame was still active */
1229 struct list_head cached_itd_list;
1230 --- a/drivers/usb/host/fsl-mph-dr-of.c
1231 +++ b/drivers/usb/host/fsl-mph-dr-of.c
1232 @@ -229,6 +229,17 @@ static int fsl_usb2_mph_dr_of_probe(stru
1233 pdata->has_fsl_erratum_a005697 =
1234 of_property_read_bool(np, "fsl,usb_erratum-a005697");
1236 + if (of_get_property(np, "fsl,erratum_a006918", NULL))
1237 + pdata->has_fsl_erratum_a006918 = 1;
1239 + pdata->has_fsl_erratum_a006918 = 0;
1241 + if (of_get_property(np, "fsl,usb_erratum_14", NULL))
1242 + pdata->has_fsl_erratum_14 = 1;
1244 + pdata->has_fsl_erratum_14 = 0;
1248 * Determine whether phy_clk_valid needs to be checked
1249 * by reading property in device tree
1250 --- a/drivers/usb/host/xhci-hub.c
1251 +++ b/drivers/usb/host/xhci-hub.c
1252 @@ -689,12 +689,34 @@ void xhci_set_link_state(struct xhci_hcd
1253 int port_id, u32 link_state)
1256 + u32 portpmsc_u2_backup = 0;
1258 + /* Backup U2 timeout info before initiating U3 entry erratum A-010131 */
1259 + if (xhci->shared_hcd->speed >= HCD_USB3 &&
1260 + link_state == USB_SS_PORT_LS_U3 &&
1261 + (xhci->quirks & XHCI_DIS_U1U2_WHEN_U3)) {
1262 + portpmsc_u2_backup = readl(port_array[port_id] + PORTPMSC);
1263 + portpmsc_u2_backup &= PORT_U2_TIMEOUT_MASK;
1264 + temp = readl(port_array[port_id] + PORTPMSC);
1265 + temp |= PORT_U2_TIMEOUT_MASK;
1266 + writel(temp, port_array[port_id] + PORTPMSC);
1269 temp = readl(port_array[port_id]);
1270 temp = xhci_port_state_to_neutral(temp);
1271 temp &= ~PORT_PLS_MASK;
1272 temp |= PORT_LINK_STROBE | link_state;
1273 writel(temp, port_array[port_id]);
1275 + /* Restore U2 timeout info after U3 entry complete */
1276 + if (xhci->shared_hcd->speed >= HCD_USB3 &&
1277 + link_state == USB_SS_PORT_LS_U3 &&
1278 + (xhci->quirks & XHCI_DIS_U1U2_WHEN_U3)) {
1279 + temp = readl(port_array[port_id] + PORTPMSC);
1280 + temp &= ~PORT_U2_TIMEOUT_MASK;
1281 + temp |= portpmsc_u2_backup;
1282 + writel(temp, port_array[port_id] + PORTPMSC);
1286 static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
1287 --- a/drivers/usb/host/xhci-plat.c
1288 +++ b/drivers/usb/host/xhci-plat.c
1289 @@ -263,8 +263,22 @@ static int xhci_plat_probe(struct platfo
1293 - if (device_property_read_bool(sysdev, "usb3-lpm-capable"))
1294 + if (device_property_read_bool(sysdev, "usb3-lpm-capable")) {
1295 xhci->quirks |= XHCI_LPM_SUPPORT;
1296 + if (device_property_read_bool(sysdev,
1297 + "snps,dis-u1u2-when-u3-quirk"))
1298 + xhci->quirks |= XHCI_DIS_U1U2_WHEN_U3;
1301 + if (device_property_read_bool(&pdev->dev, "quirk-reverse-in-out"))
1302 + xhci->quirks |= XHCI_REVERSE_IN_OUT;
1304 + if (device_property_read_bool(&pdev->dev,
1305 + "quirk-stop-transfer-in-block"))
1306 + xhci->quirks |= XHCI_STOP_TRANSFER_IN_BLOCK;
1308 + if (device_property_read_bool(&pdev->dev, "quirk-stop-ep-in-u1"))
1309 + xhci->quirks |= XHCI_STOP_EP_IN_U1;
1311 if (device_property_read_bool(&pdev->dev, "quirk-broken-port-ped"))
1312 xhci->quirks |= XHCI_BROKEN_PORT_PED;
1313 --- a/drivers/usb/host/xhci-ring.c
1314 +++ b/drivers/usb/host/xhci-ring.c
1315 @@ -1976,10 +1976,12 @@ static int finish_td(struct xhci_hcd *xh
1316 union xhci_trb *ep_trb, struct xhci_transfer_event *event,
1317 struct xhci_virt_ep *ep, int *status)
1319 + struct xhci_dequeue_state deq_state;
1320 struct xhci_virt_device *xdev;
1321 struct xhci_ep_ctx *ep_ctx;
1322 struct xhci_ring *ep_ring;
1323 unsigned int slot_id;
1328 @@ -2002,14 +2004,30 @@ static int finish_td(struct xhci_hcd *xh
1329 if (trb_comp_code == COMP_STALL_ERROR ||
1330 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
1332 - /* Issue a reset endpoint command to clear the host side
1333 - * halt, followed by a set dequeue command to move the
1334 - * dequeue pointer past the TD.
1335 - * The class driver clears the device side halt later.
1336 + /*erratum A-007463:
1337 + *After transaction error, controller switches control transfer
1338 + *data stage from IN to OUT direction.
1340 - xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index,
1341 + remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
1342 + if (remaining && xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
1344 + (xhci->quirks & XHCI_REVERSE_IN_OUT)) {
1345 + memset(&deq_state, 0, sizeof(deq_state));
1346 + xhci_find_new_dequeue_state(xhci, slot_id,
1347 + ep_index, td->urb->stream_id, td, &deq_state);
1348 + xhci_queue_new_dequeue_state(xhci, slot_id, ep_index,
1350 + xhci_ring_cmd_db(xhci);
1352 + /* Issue a reset endpoint command to clear the host side
1353 + * halt, followed by a set dequeue command to move the
1354 + * dequeue pointer past the TD.
1355 + * The class driver clears the device side halt later.
1357 + xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index,
1358 ep_ring->stream_id, td, ep_trb,
1362 /* Update ring dequeue pointer */
1363 while (ep_ring->dequeue != td->last_trb)
1364 --- a/drivers/usb/host/xhci.c
1365 +++ b/drivers/usb/host/xhci.c
1366 @@ -1607,13 +1607,38 @@ static int xhci_urb_dequeue(struct usb_h
1370 - ep->ep_state |= EP_STOP_CMD_PENDING;
1371 - ep->stop_cmd_timer.expires = jiffies +
1373 + *erratum A-009611: Issuing an End Transfer command on an IN
1374 + *endpoint. when a transfer is in progress on USB blocks the
1376 + *Workaround: Software must wait for all existing TRBs to
1377 + *complete before issuing End transfer command.
1379 + if ((ep_ring->enqueue == ep_ring->dequeue &&
1380 + (xhci->quirks & XHCI_STOP_TRANSFER_IN_BLOCK)) ||
1381 + !(xhci->quirks & XHCI_STOP_TRANSFER_IN_BLOCK)) {
1382 + ep->ep_state |= EP_STOP_CMD_PENDING;
1383 + ep->stop_cmd_timer.expires = jiffies +
1384 XHCI_STOP_EP_CMD_TIMEOUT * HZ;
1385 - add_timer(&ep->stop_cmd_timer);
1386 - xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id,
1388 - xhci_ring_cmd_db(xhci);
1389 + add_timer(&ep->stop_cmd_timer);
1390 + xhci_queue_stop_endpoint(xhci, command,
1391 + urb->dev->slot_id,
1393 + xhci_ring_cmd_db(xhci);
1397 + *erratum A-009668: Stop Endpoint Command does not complete.
1398 + *Workaround: Instead of issuing a Stop Endpoint Command,
1399 + *issue a Disable Slot Command with the corresponding slot ID.
1400 + *Alternately, you can issue an Address Device Command with
1403 + if ((urb->dev->speed <= USB_SPEED_HIGH) &&
1404 + (xhci->quirks & XHCI_STOP_EP_IN_U1)) {
1405 + xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT,
1406 + urb->dev->slot_id);
1410 spin_unlock_irqrestore(&xhci->lock, flags);
1411 --- a/drivers/usb/host/xhci.h
1412 +++ b/drivers/usb/host/xhci.h
1413 @@ -1794,7 +1794,7 @@ struct xhci_hcd {
1414 #define XHCI_STATE_DYING (1 << 0)
1415 #define XHCI_STATE_HALTED (1 << 1)
1416 #define XHCI_STATE_REMOVING (1 << 2)
1417 - unsigned long long quirks;
1418 + unsigned long long quirks;
1419 #define XHCI_LINK_TRB_QUIRK BIT_ULL(0)
1420 #define XHCI_RESET_EP_QUIRK BIT_ULL(1)
1421 #define XHCI_NEC_HOST BIT_ULL(2)
1422 @@ -1830,6 +1830,9 @@ struct xhci_hcd {
1423 #define XHCI_SSIC_PORT_UNUSED BIT_ULL(22)
1424 #define XHCI_NO_64BIT_SUPPORT BIT_ULL(23)
1425 #define XHCI_MISSING_CAS BIT_ULL(24)
1426 +#define XHCI_REVERSE_IN_OUT BIT(32)
1427 +#define XHCI_STOP_TRANSFER_IN_BLOCK BIT(33)
1428 +#define XHCI_STOP_EP_IN_U1 BIT(34)
1429 /* For controller with a broken Port Disable implementation */
1430 #define XHCI_BROKEN_PORT_PED BIT_ULL(25)
1431 #define XHCI_LIMIT_ENDPOINT_INTERVAL_7 BIT_ULL(26)
1432 @@ -1838,8 +1841,9 @@ struct xhci_hcd {
1433 #define XHCI_HW_LPM_DISABLE BIT_ULL(29)
1434 #define XHCI_SUSPEND_DELAY BIT_ULL(30)
1435 #define XHCI_INTEL_USB_ROLE_SW BIT_ULL(31)
1436 -#define XHCI_RESET_PLL_ON_DISCONNECT BIT_ULL(34)
1437 -#define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(35)
1438 +#define XHCI_RESET_PLL_ON_DISCONNECT BIT_ULL(35)
1439 +#define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(36)
1440 +#define XHCI_DIS_U1U2_WHEN_U3 BIT(37)
1442 unsigned int num_active_eps;
1443 unsigned int limit_active_eps;
1444 --- a/drivers/usb/phy/phy-fsl-usb.c
1445 +++ b/drivers/usb/phy/phy-fsl-usb.c
1448 - * Copyright (C) 2007,2008 Freescale semiconductor, Inc.
1449 + * Copyright 2007,2008 Freescale Semiconductor, Inc.
1451 * Author: Li Yang <LeoLi@freescale.com>
1452 * Jerry Huang <Chang-Ming.Huang@freescale.com>
1453 @@ -470,6 +470,7 @@ void otg_reset_controller(void)
1454 int fsl_otg_start_host(struct otg_fsm *fsm, int on)
1456 struct usb_otg *otg = fsm->otg;
1457 + struct usb_bus *host = otg->host;
1459 struct fsl_otg *otg_dev =
1460 container_of(otg->usb_phy, struct fsl_otg, phy);
1461 @@ -493,6 +494,7 @@ int fsl_otg_start_host(struct otg_fsm *f
1462 otg_reset_controller();
1463 VDBG("host on......\n");
1464 if (dev->driver->pm && dev->driver->pm->resume) {
1466 retval = dev->driver->pm->resume(dev);
1469 @@ -517,8 +519,11 @@ int fsl_otg_start_host(struct otg_fsm *f
1471 VDBG("host off......\n");
1472 if (dev && dev->driver) {
1473 - if (dev->driver->pm && dev->driver->pm->suspend)
1474 + if (dev->driver->pm &&
1475 + dev->driver->pm->suspend) {
1477 retval = dev->driver->pm->suspend(dev);
1481 fsl_otg_drv_vbus(fsm, 0);
1482 @@ -546,8 +551,17 @@ int fsl_otg_start_gadget(struct otg_fsm
1483 dev = otg->gadget->dev.parent;
1486 - if (dev->driver->resume)
1487 + /* Delay gadget resume to synchronize between host and gadget
1488 + * drivers. Upon role-reversal host drv is shutdown by kernel
1489 + * worker thread. By the time host drv shuts down, controller
1490 + * gets programmed for gadget role. Shutting host drv after
1491 + * this results in controller getting reset, and it stops
1492 + * responding to otg events
1494 + if (dev->driver->resume) {
1496 dev->driver->resume(dev);
1499 if (dev->driver->suspend)
1500 dev->driver->suspend(dev, otg_suspend_state);
1501 @@ -668,6 +682,10 @@ static void fsl_otg_event(struct work_st
1502 fsl_otg_start_host(fsm, 0);
1503 otg_drv_vbus(fsm, 0);
1504 fsl_otg_start_gadget(fsm, 1);
1506 + fsl_otg_start_gadget(fsm, 0);
1507 + otg_drv_vbus(fsm, 1);
1508 + fsl_otg_start_host(fsm, 1);
1512 @@ -720,6 +738,7 @@ irqreturn_t fsl_otg_isr(int irq, void *d
1514 struct otg_fsm *fsm = &((struct fsl_otg *)dev_id)->fsm;
1515 struct usb_otg *otg = ((struct fsl_otg *)dev_id)->phy.otg;
1516 + struct fsl_otg *otg_dev = dev_id;
1517 u32 otg_int_src, otg_sc;
1519 otg_sc = fsl_readl(&usb_dr_regs->otgsc);
1520 @@ -749,18 +768,8 @@ irqreturn_t fsl_otg_isr(int irq, void *d
1521 otg->gadget->is_a_peripheral = !fsm->id;
1522 VDBG("ID int (ID is %d)\n", fsm->id);
1524 - if (fsm->id) { /* switch to gadget */
1525 - schedule_delayed_work(
1526 - &((struct fsl_otg *)dev_id)->otg_event,
1528 - } else { /* switch to host */
1529 - cancel_delayed_work(&
1530 - ((struct fsl_otg *)dev_id)->
1532 - fsl_otg_start_gadget(fsm, 0);
1533 - otg_drv_vbus(fsm, 1);
1534 - fsl_otg_start_host(fsm, 1);
1536 + schedule_delayed_work(&otg_dev->otg_event, 100);
1541 @@ -920,12 +929,32 @@ int usb_otg_start(struct platform_device
1542 temp &= ~(PORTSC_PHY_TYPE_SEL | PORTSC_PTW);
1543 switch (pdata->phy_mode) {
1544 case FSL_USB2_PHY_ULPI:
1545 + if (pdata->controller_ver) {
1546 + /* controller version 1.6 or above */
1547 + setbits32(&p_otg->dr_mem_map->control,
1548 + USB_CTRL_ULPI_PHY_CLK_SEL);
1550 + * Due to controller issue of PHY_CLK_VALID in ULPI
1551 + * mode, we set USB_CTRL_USB_EN before checking
1552 + * PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
1554 + clrsetbits_be32(&p_otg->dr_mem_map->control,
1555 + USB_CTRL_UTMI_PHY_EN, USB_CTRL_IOENB);
1557 temp |= PORTSC_PTS_ULPI;
1559 case FSL_USB2_PHY_UTMI_WIDE:
1560 temp |= PORTSC_PTW_16BIT;
1562 case FSL_USB2_PHY_UTMI:
1563 + if (pdata->controller_ver) {
1564 + /* controller version 1.6 or above */
1565 + setbits32(&p_otg->dr_mem_map->control,
1566 + USB_CTRL_UTMI_PHY_EN);
1567 + /* Delay for UTMI PHY CLK to become stable - 10ms */
1568 + mdelay(FSL_UTMI_PHY_DLY);
1570 + setbits32(&p_otg->dr_mem_map->control, USB_CTRL_UTMI_PHY_EN);
1571 temp |= PORTSC_PTS_UTMI;
1574 --- a/drivers/usb/phy/phy-fsl-usb.h
1575 +++ b/drivers/usb/phy/phy-fsl-usb.h
1576 @@ -199,6 +199,14 @@
1577 /* control Register Bit Masks */
1578 #define USB_CTRL_IOENB (0x1<<2)
1579 #define USB_CTRL_ULPI_INT0EN (0x1<<0)
1580 +#define USB_CTRL_WU_INT_EN (0x1<<1)
1581 +#define USB_CTRL_LINE_STATE_FILTER__EN (0x1<<3)
1582 +#define USB_CTRL_KEEP_OTG_ON (0x1<<4)
1583 +#define USB_CTRL_OTG_PORT (0x1<<5)
1584 +#define USB_CTRL_PLL_RESET (0x1<<8)
1585 +#define USB_CTRL_UTMI_PHY_EN (0x1<<9)
1586 +#define USB_CTRL_ULPI_PHY_CLK_SEL (0x1<<10)
1587 +#define USB_CTRL_PHY_CLK_VALID (0x1<<17)
1590 #define BCSR5_INT_USB (0x02)
1591 --- a/include/linux/usb.h
1592 +++ b/include/linux/usb.h
1593 @@ -432,6 +432,7 @@ struct usb_bus {
1594 * for control transfers?
1596 u8 otg_port; /* 0, or number of OTG/HNP port */
1597 + unsigned is_otg:1; /* true when host is also otg */
1598 unsigned is_b_host:1; /* true during some HNP roleswitches */
1599 unsigned b_hnp_enable:1; /* OTG: did A-Host enable HNP? */
1600 unsigned no_stop_on_short:1; /*
1601 --- a/include/linux/usb/of.h
1602 +++ b/include/linux/usb/of.h
1604 #include <linux/usb/otg.h>
1605 #include <linux/usb/phy.h>
1607 +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
1609 #if IS_ENABLED(CONFIG_OF)
1610 enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0);
1611 bool of_usb_host_tpl_support(struct device_node *np);