1 From b14460ee524a34d3b94b44032b52155c4cd708e5 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Wed, 27 Sep 2017 10:34:07 +0800
4 Subject: [PATCH] usb: support layerscape
6 This is a integrated patch for layerscape usb support.
8 Signed-off-by: yinbo.zhu <yinbo.zhu@nxp.com>
9 Signed-off-by: Ramneek Mehresh <ramneek.mehresh@freescale.com>
10 Signed-off-by: Nikhil Badola <nikhil.badola@freescale.com>
11 Signed-off-by: Changming Huang <jerry.huang@nxp.com>
12 Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
13 Signed-off-by: Rajesh Bhagat <rajesh.bhagat@freescale.com>
14 Signed-off-by: Suresh Gupta <suresh.gupta@freescale.com>
15 Signed-off-by: Zhao Chenhui <chenhui.zhao@freescale.com>
16 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
18 drivers/net/usb/r8152.c | 4 +
19 drivers/usb/common/common.c | 50 ++++++
20 drivers/usb/core/hub.c | 8 +
21 drivers/usb/dwc3/core.c | 235 ++++++++++++++++++++++++++-
22 drivers/usb/dwc3/core.h | 46 +++++-
23 drivers/usb/dwc3/host.c | 15 +-
24 drivers/usb/gadget/udc/fsl_udc_core.c | 46 +++---
25 drivers/usb/gadget/udc/fsl_usb2_udc.h | 16 +-
26 drivers/usb/host/Kconfig | 2 +-
27 drivers/usb/host/ehci-fsl.c | 289 +++++++++++++++++++++++++++++++---
28 drivers/usb/host/ehci-fsl.h | 3 +
29 drivers/usb/host/ehci-hub.c | 2 +
30 drivers/usb/host/ehci.h | 5 +
31 drivers/usb/host/fsl-mph-dr-of.c | 12 ++
32 drivers/usb/phy/phy-fsl-usb.c | 59 +++++--
33 drivers/usb/phy/phy-fsl-usb.h | 8 +
34 include/linux/usb.h | 1 +
35 include/linux/usb/of.h | 2 +
36 18 files changed, 730 insertions(+), 73 deletions(-)
38 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
39 index afb953a2..c9c86495 100644
40 --- a/drivers/net/usb/r8152.c
41 +++ b/drivers/net/usb/r8152.c
42 @@ -1812,6 +1812,10 @@ static int rx_bottom(struct r8152 *tp, int budget)
46 + /* limite the skb numbers for rx_queue */
47 + if (unlikely(skb_queue_len(&tp->rx_queue) >= 1000))
50 pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK;
51 if (pkt_len < ETH_ZLEN)
53 diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
54 index 5ef8da6e..176dee01 100644
55 --- a/drivers/usb/common/common.c
56 +++ b/drivers/usb/common/common.c
57 @@ -105,6 +105,56 @@ static const char *const usb_dr_modes[] = {
58 [USB_DR_MODE_OTG] = "otg",
62 + * of_usb_get_dr_mode - Get dual role mode for given device_node
63 + * @np: Pointer to the given device_node
65 + * The function gets phy interface string from property 'dr_mode',
66 + * and returns the correspondig enum usb_dr_mode
68 +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
70 + const char *dr_mode;
73 + err = of_property_read_string(np, "dr_mode", &dr_mode);
75 + return USB_DR_MODE_UNKNOWN;
77 + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
78 + if (!strcmp(dr_mode, usb_dr_modes[i]))
81 + return USB_DR_MODE_UNKNOWN;
83 +EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
86 + * of_usb_get_maximum_speed - Get maximum requested speed for a given USB
88 + * @np: Pointer to the given device_node
90 + * The function gets the maximum speed string from property "maximum-speed",
91 + * and returns the corresponding enum usb_device_speed.
93 +enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np)
95 + const char *maximum_speed;
99 + err = of_property_read_string(np, "maximum-speed", &maximum_speed);
101 + return USB_SPEED_UNKNOWN;
103 + for (i = 0; i < ARRAY_SIZE(speed_names); i++)
104 + if (strcmp(maximum_speed, speed_names[i]) == 0)
107 + return USB_SPEED_UNKNOWN;
109 +EXPORT_SYMBOL_GPL(of_usb_get_maximum_speed);
111 static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
114 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
115 index 80d4ef31..e23acf03 100644
116 --- a/drivers/usb/core/hub.c
117 +++ b/drivers/usb/core/hub.c
118 @@ -4412,6 +4412,14 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
120 speed = usb_speed_string(udev->speed);
122 +#if !defined(CONFIG_FSL_USB2_OTG) && !defined(CONFIG_FSL_USB2_OTG_MODULE)
123 +if (udev->speed != USB_SPEED_SUPER)
124 + dev_info(&udev->dev,
125 + "%s %s USB device number %d using %s\n",
126 + (udev->config) ? "reset" : "new", speed,
127 + devnum, udev->bus->controller->driver->name);
130 if (udev->speed < USB_SPEED_SUPER)
132 "%s %s USB device number %d using %s\n",
133 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
134 index fea44690..e34ef90a 100644
135 --- a/drivers/usb/dwc3/core.c
136 +++ b/drivers/usb/dwc3/core.c
137 @@ -58,6 +58,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
138 enum usb_dr_mode mode;
139 struct device *dev = dwc->dev;
140 unsigned int hw_mode;
141 + struct device_node *node = dev->of_node;
143 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
144 dwc->dr_mode = USB_DR_MODE_OTG;
145 @@ -83,6 +84,24 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
146 mode = USB_DR_MODE_HOST;
149 + /* Adjust Frame Length */
150 + if (dwc->configure_gfladj)
151 + dwc3_writel(dwc->regs, DWC3_GFLADJ, GFLADJ_30MHZ_REG_SEL |
152 + GFLADJ_30MHZ(GFLADJ_30MHZ_DEFAULT));
154 + /* Change burst beat and outstanding pipelined transfers requests */
155 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
156 + (dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) & ~0xff) | 0xf);
157 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG1,
158 + dwc3_readl(dwc->regs, DWC3_GSBUSCFG1) | 0xf00);
160 + /* Enable Snooping */
161 + if (node && of_dma_is_coherent(node)) {
162 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
163 + dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) | 0x22220000);
164 + dev_dbg(dev, "enabled snooping for usb\n");
167 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
168 mode = USB_DR_MODE_HOST;
169 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
170 @@ -213,8 +232,9 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc)
172 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
173 dft = reg & DWC3_GFLADJ_30MHZ_MASK;
174 - if (!dev_WARN_ONCE(dwc->dev, dft == dwc->fladj,
175 - "request value same as default, ignoring\n")) {
176 + if (dft == dwc->fladj) {
177 + dev_warn(dwc->dev, "request value same as default, ignoring\n");
179 reg &= ~DWC3_GFLADJ_30MHZ_MASK;
180 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj;
181 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
182 @@ -579,6 +599,99 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
186 +/* set global soc bus configuration registers */
187 +static void dwc3_set_soc_bus_cfg(struct dwc3 *dwc)
189 + struct device *dev = dwc->dev;
196 + cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0);
199 + * Handle property "snps,incr-burst-type-adjustment".
200 + * Get the number of value from this property:
201 + * result <= 0, means this property is not supported.
202 + * result = 1, means INCRx burst mode supported.
203 + * result > 1, means undefined length burst mode supported.
205 + ntype = device_property_read_u32_array(dev,
206 + "snps,incr-burst-type-adjustment", NULL, 0);
208 + vals = kcalloc(ntype, sizeof(u32), GFP_KERNEL);
210 + dev_err(dev, "Error to get memory\n");
213 + /* Get INCR burst type, and parse it */
214 + ret = device_property_read_u32_array(dev,
215 + "snps,incr-burst-type-adjustment", vals, ntype);
217 + dev_err(dev, "Error to get property\n");
220 + *(dwc->incrx_type + 1) = vals[0];
222 + *dwc->incrx_type = 1;
223 + for (i = 1; i < ntype; i++) {
224 + if (vals[i] > *(dwc->incrx_type + 1))
225 + *(dwc->incrx_type + 1) = vals[i];
228 + *dwc->incrx_type = 0;
230 + /* Enable Undefined Length INCR Burst and Enable INCRx Burst */
231 + cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK;
232 + if (*dwc->incrx_type)
233 + cfg |= DWC3_GSBUSCFG0_INCRBRSTENA;
234 + switch (*(dwc->incrx_type + 1)) {
236 + cfg |= DWC3_GSBUSCFG0_INCR256BRSTENA;
239 + cfg |= DWC3_GSBUSCFG0_INCR128BRSTENA;
242 + cfg |= DWC3_GSBUSCFG0_INCR64BRSTENA;
245 + cfg |= DWC3_GSBUSCFG0_INCR32BRSTENA;
248 + cfg |= DWC3_GSBUSCFG0_INCR16BRSTENA;
251 + cfg |= DWC3_GSBUSCFG0_INCR8BRSTENA;
254 + cfg |= DWC3_GSBUSCFG0_INCR4BRSTENA;
259 + dev_err(dev, "Invalid property\n");
264 + /* Handle usb snooping */
265 + if (dwc->dma_snooping_quirk) {
266 + cfg &= ~DWC3_GSBUSCFG0_SNP_MASK;
267 + cfg |= (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DATARD_SHIFT) |
268 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DESCRD_SHIFT) |
269 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DATAWR_SHIFT) |
270 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DESCWR_SHIFT);
273 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg);
279 static void dwc3_core_exit(struct dwc3 *dwc)
281 dwc3_event_buffers_cleanup(dwc);
282 @@ -721,6 +834,8 @@ static int dwc3_core_init(struct dwc3 *dwc)
286 + dwc3_set_soc_bus_cfg(dwc);
288 /* Adjust Frame Length */
289 dwc3_frame_length_adjustment(dwc);
291 @@ -919,11 +1034,109 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
295 +static void dwc3_get_properties(struct dwc3 *dwc)
297 + struct device *dev = dwc->dev;
298 + struct device_node *node = dev->of_node;
299 + u8 lpm_nyet_threshold;
303 + /* default to highest possible threshold */
304 + lpm_nyet_threshold = 0xff;
306 + /* default to -3.5dB de-emphasis */
307 + tx_de_emphasis = 1;
310 + * default to assert utmi_sleep_n and use maximum allowed HIRD
311 + * threshold value of 0b1100
313 + hird_threshold = 12;
315 + dwc->maximum_speed = usb_get_maximum_speed(dev);
316 + dwc->dr_mode = usb_get_dr_mode(dev);
317 + dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
319 + dwc->sysdev_is_parent = device_property_read_bool(dev,
320 + "linux,sysdev_is_parent");
321 + if (dwc->sysdev_is_parent)
322 + dwc->sysdev = dwc->dev->parent;
324 + dwc->sysdev = dwc->dev;
326 + dwc->has_lpm_erratum = device_property_read_bool(dev,
327 + "snps,has-lpm-erratum");
328 + device_property_read_u8(dev, "snps,lpm-nyet-threshold",
329 + &lpm_nyet_threshold);
330 + dwc->is_utmi_l1_suspend = device_property_read_bool(dev,
331 + "snps,is-utmi-l1-suspend");
332 + device_property_read_u8(dev, "snps,hird-threshold",
334 + dwc->usb3_lpm_capable = device_property_read_bool(dev,
335 + "snps,usb3_lpm_capable");
337 + dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
339 + dwc->configure_gfladj =
340 + of_property_read_bool(node, "configure-gfladj");
341 + dwc->dr_mode = usb_get_dr_mode(dev);
343 + dwc->disable_scramble_quirk = device_property_read_bool(dev,
344 + "snps,disable_scramble_quirk");
345 + dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
346 + "snps,u2exit_lfps_quirk");
347 + dwc->u2ss_inp3_quirk = device_property_read_bool(dev,
348 + "snps,u2ss_inp3_quirk");
349 + dwc->req_p1p2p3_quirk = device_property_read_bool(dev,
350 + "snps,req_p1p2p3_quirk");
351 + dwc->del_p1p2p3_quirk = device_property_read_bool(dev,
352 + "snps,del_p1p2p3_quirk");
353 + dwc->del_phy_power_chg_quirk = device_property_read_bool(dev,
354 + "snps,del_phy_power_chg_quirk");
355 + dwc->lfps_filter_quirk = device_property_read_bool(dev,
356 + "snps,lfps_filter_quirk");
357 + dwc->rx_detect_poll_quirk = device_property_read_bool(dev,
358 + "snps,rx_detect_poll_quirk");
359 + dwc->dis_u3_susphy_quirk = device_property_read_bool(dev,
360 + "snps,dis_u3_susphy_quirk");
361 + dwc->dis_u2_susphy_quirk = device_property_read_bool(dev,
362 + "snps,dis_u2_susphy_quirk");
363 + dwc->dis_enblslpm_quirk = device_property_read_bool(dev,
364 + "snps,dis_enblslpm_quirk");
365 + dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
366 + "snps,dis_rxdet_inp3_quirk");
367 + dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
368 + "snps,dis-u2-freeclk-exists-quirk");
369 + dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev,
370 + "snps,dis-del-phy-power-chg-quirk");
371 + dwc->dma_snooping_quirk = device_property_read_bool(dev,
372 + "snps,dma-snooping");
374 + dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
375 + "snps,tx_de_emphasis_quirk");
376 + device_property_read_u8(dev, "snps,tx_de_emphasis",
378 + device_property_read_string(dev, "snps,hsphy_interface",
379 + &dwc->hsphy_interface);
380 + device_property_read_u32(dev, "snps,quirk-frame-length-adjustment",
383 + dwc->lpm_nyet_threshold = lpm_nyet_threshold;
384 + dwc->tx_de_emphasis = tx_de_emphasis;
386 + dwc->hird_threshold = hird_threshold
387 + | (dwc->is_utmi_l1_suspend << 4);
389 + dwc->imod_interval = 0;
392 #define DWC3_ALIGN_MASK (16 - 1)
394 static int dwc3_probe(struct platform_device *pdev)
396 struct device *dev = &pdev->dev;
397 + struct device_node *node = dev->of_node;
398 struct resource *res;
400 u8 lpm_nyet_threshold;
401 @@ -955,6 +1168,11 @@ static int dwc3_probe(struct platform_device *pdev)
402 dwc->xhci_resources[0].flags = res->flags;
403 dwc->xhci_resources[0].name = res->name;
406 + dwc->configure_gfladj =
407 + of_property_read_bool(node, "configure-gfladj");
410 res->start += DWC3_GLOBALS_REGS_START;
413 @@ -997,6 +1215,12 @@ static int dwc3_probe(struct platform_device *pdev)
414 dwc->usb3_lpm_capable = device_property_read_bool(dev,
415 "snps,usb3_lpm_capable");
417 + dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
419 + dwc->configure_gfladj =
420 + of_property_read_bool(node, "configure-gfladj");
421 + dwc->dr_mode = of_usb_get_dr_mode(node);
423 dwc->disable_scramble_quirk = device_property_read_bool(dev,
424 "snps,disable_scramble_quirk");
425 dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
426 @@ -1041,6 +1265,8 @@ static int dwc3_probe(struct platform_device *pdev)
427 dwc->hird_threshold = hird_threshold
428 | (dwc->is_utmi_l1_suspend << 4);
430 + dwc3_get_properties(dwc);
432 platform_set_drvdata(pdev, dwc);
433 dwc3_cache_hwparams(dwc);
435 @@ -1064,6 +1290,11 @@ static int dwc3_probe(struct platform_device *pdev)
439 + /* Adjust Frame Length */
440 + if (dwc->configure_gfladj)
441 + dwc3_writel(dwc->regs, DWC3_GFLADJ, GFLADJ_30MHZ_REG_SEL |
442 + GFLADJ_30MHZ(GFLADJ_30MHZ_DEFAULT));
444 pm_runtime_forbid(dev);
446 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
447 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
448 index 884c4371..9151eef4 100644
449 --- a/drivers/usb/dwc3/core.h
450 +++ b/drivers/usb/dwc3/core.h
452 #include <linux/dma-mapping.h>
453 #include <linux/mm.h>
454 #include <linux/debugfs.h>
455 +#include <linux/of_address.h>
457 #include <linux/usb/ch9.h>
458 #include <linux/usb/gadget.h>
463 +/* Global SoC Bus Configuration Register 0 */
464 +#define AXI3_CACHE_TYPE_AW 0x8 /* write allocate */
465 +#define AXI3_CACHE_TYPE_AR 0x4 /* read allocate */
466 +#define AXI3_CACHE_TYPE_SNP 0x2 /* cacheable */
467 +#define AXI3_CACHE_TYPE_BUF 0x1 /* bufferable */
468 +#define DWC3_GSBUSCFG0_DATARD_SHIFT 28
469 +#define DWC3_GSBUSCFG0_DESCRD_SHIFT 24
470 +#define DWC3_GSBUSCFG0_DATAWR_SHIFT 20
471 +#define DWC3_GSBUSCFG0_DESCWR_SHIFT 16
472 +#define DWC3_GSBUSCFG0_SNP_MASK 0xffff0000
473 +#define DWC3_GSBUSCFG0_DATABIGEND (1 << 11)
474 +#define DWC3_GSBUSCFG0_DESCBIGEND (1 << 10)
475 +#define DWC3_GSBUSCFG0_INCR256BRSTENA (1 << 7) /* INCR256 burst */
476 +#define DWC3_GSBUSCFG0_INCR128BRSTENA (1 << 6) /* INCR128 burst */
477 +#define DWC3_GSBUSCFG0_INCR64BRSTENA (1 << 5) /* INCR64 burst */
478 +#define DWC3_GSBUSCFG0_INCR32BRSTENA (1 << 4) /* INCR32 burst */
479 +#define DWC3_GSBUSCFG0_INCR16BRSTENA (1 << 3) /* INCR16 burst */
480 +#define DWC3_GSBUSCFG0_INCR8BRSTENA (1 << 2) /* INCR8 burst */
481 +#define DWC3_GSBUSCFG0_INCR4BRSTENA (1 << 1) /* INCR4 burst */
482 +#define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0) /* undefined length enable */
483 +#define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff
485 +/* Global SoC Bus Configuration Register 1 */
486 +#define DWC3_GSBUSCFG1_1KPAGEENA (1 << 12) /* 1K page boundary enable */
487 +#define DWC3_GSBUSCFG1_PTRANSLIMIT_MASK 0xf00
489 /* Global Debug Queue/FIFO Space Available Register */
490 #define DWC3_GDBGFIFOSPACE_NUM(n) ((n) & 0x1f)
491 #define DWC3_GDBGFIFOSPACE_TYPE(n) (((n) << 5) & 0x1e0)
493 #define DWC3_GCTL_CLK_PIPE (1)
494 #define DWC3_GCTL_CLK_PIPEHALF (2)
495 #define DWC3_GCTL_CLK_MASK (3)
497 #define DWC3_GCTL_PRTCAP(n) (((n) & (3 << 12)) >> 12)
498 #define DWC3_GCTL_PRTCAPDIR(n) ((n) << 12)
499 #define DWC3_GCTL_PRTCAP_HOST 1
501 /* Global Frame Length Adjustment Register */
502 #define DWC3_GFLADJ_30MHZ_SDBND_SEL (1 << 7)
503 #define DWC3_GFLADJ_30MHZ_MASK 0x3f
504 +#define GFLADJ_30MHZ_REG_SEL (1 << 7)
505 +#define GFLADJ_30MHZ(n) ((n) & 0x3f)
506 +#define GFLADJ_30MHZ_DEFAULT 0x20
509 /* Global User Control Register 2 */
510 #define DWC3_GUCTL2_RST_ACTBITLATER (1 << 14)
511 @@ -753,6 +783,7 @@ struct dwc3_scratchpad_array {
512 * @regs: base address for our registers
513 * @regs_size: address space size
514 * @fladj: frame length adjustment
515 + * @incrx_type: INCR burst type adjustment
516 * @irq_gadget: peripheral controller's IRQ number
517 * @nr_scratch: number of scratch buffers
518 * @u1u2: only used on revisions <1.83a for workaround
519 @@ -847,6 +878,7 @@ struct dwc3 {
523 + struct device *sysdev;
525 struct platform_device *xhci;
526 struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM];
527 @@ -872,6 +904,12 @@ struct dwc3 {
528 enum usb_phy_interface hsphy_mode;
532 + * For INCR burst type.
533 + * First field: for undefined length INCR burst type enable.
534 + * Second field: for INCRx burst type enable
540 @@ -948,9 +986,12 @@ struct dwc3 {
541 unsigned ep0_bounced:1;
542 unsigned ep0_expect_in:1;
543 unsigned has_hibernation:1;
544 + unsigned sysdev_is_parent:1;
545 unsigned has_lpm_erratum:1;
546 unsigned is_utmi_l1_suspend:1;
548 + unsigned needs_fifo_resize:1;
549 + unsigned configure_gfladj:1;
550 unsigned pending_events:1;
551 unsigned pullups_connected:1;
552 unsigned setup_packet_pending:1;
553 @@ -971,9 +1012,12 @@ struct dwc3 {
554 unsigned dis_rxdet_inp3_quirk:1;
555 unsigned dis_u2_freeclk_exists_quirk:1;
556 unsigned dis_del_phy_power_chg_quirk:1;
557 + unsigned dma_snooping_quirk:1;
559 unsigned tx_de_emphasis_quirk:1;
560 unsigned tx_de_emphasis:2;
565 /* -------------------------------------------------------------------------- */
566 diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
567 index 626d87d5..f1b98273 100644
568 --- a/drivers/usb/dwc3/host.c
569 +++ b/drivers/usb/dwc3/host.c
572 #include <linux/platform_device.h>
574 +#include <linux/of_device.h>
578 int dwc3_host_init(struct dwc3 *dwc)
579 @@ -73,12 +75,21 @@ int dwc3_host_init(struct dwc3 *dwc)
583 - dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
584 + if (IS_ENABLED(CONFIG_OF) && dwc->dev->of_node)
585 + of_dma_configure(&xhci->dev, dwc->dev->of_node);
587 + dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
589 - xhci->dev.parent = dwc->dev;
590 + xhci->dev.parent = dwc->dev;
591 xhci->dev.dma_mask = dwc->dev->dma_mask;
592 xhci->dev.dma_parms = dwc->dev->dma_parms;
594 + /* set DMA operations */
595 + if (dwc->dev->of_node && of_dma_is_coherent(dwc->dev->of_node)) {
596 + xhci->dev.archdata.dma_ops = dwc->dev->archdata.dma_ops;
597 + dev_dbg(dwc->dev, "set dma_ops for usb\n");
602 ret = platform_device_add_resources(xhci, dwc->xhci_resources,
603 diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c
604 index aac0ce8a..fe49e758 100644
605 --- a/drivers/usb/gadget/udc/fsl_udc_core.c
606 +++ b/drivers/usb/gadget/udc/fsl_udc_core.c
607 @@ -198,7 +198,11 @@ __acquires(ep->udc->lock)
609 spin_unlock(&ep->udc->lock);
611 - usb_gadget_giveback_request(&ep->ep, &req->req);
612 + /* this complete() should a func implemented by gadget layer,
613 + * eg fsg->bulk_in_complete()
615 + if (req->req.complete)
616 + usb_gadget_giveback_request(&ep->ep, &req->req);
618 spin_lock(&ep->udc->lock);
619 ep->stopped = stopped;
620 @@ -245,10 +249,10 @@ static int dr_controller_setup(struct fsl_udc *udc)
621 if (udc->pdata->have_sysif_regs) {
622 if (udc->pdata->controller_ver) {
623 /* controller version 1.6 or above */
624 - ctrl = __raw_readl(&usb_sys_regs->control);
625 + ctrl = ioread32be(&usb_sys_regs->control);
626 ctrl &= ~USB_CTRL_UTMI_PHY_EN;
627 ctrl |= USB_CTRL_USB_EN;
628 - __raw_writel(ctrl, &usb_sys_regs->control);
629 + iowrite32be(ctrl, &usb_sys_regs->control);
632 portctrl |= PORTSCX_PTS_ULPI;
633 @@ -257,13 +261,14 @@ static int dr_controller_setup(struct fsl_udc *udc)
634 portctrl |= PORTSCX_PTW_16BIT;
636 case FSL_USB2_PHY_UTMI:
637 + case FSL_USB2_PHY_UTMI_DUAL:
638 if (udc->pdata->have_sysif_regs) {
639 if (udc->pdata->controller_ver) {
640 /* controller version 1.6 or above */
641 - ctrl = __raw_readl(&usb_sys_regs->control);
642 + ctrl = ioread32be(&usb_sys_regs->control);
643 ctrl |= (USB_CTRL_UTMI_PHY_EN |
645 - __raw_writel(ctrl, &usb_sys_regs->control);
646 + iowrite32be(ctrl, &usb_sys_regs->control);
647 mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI
648 PHY CLK to become stable - 10ms*/
650 @@ -329,22 +334,22 @@ static int dr_controller_setup(struct fsl_udc *udc)
651 /* Config control enable i/o output, cpu endian register */
652 #ifndef CONFIG_ARCH_MXC
653 if (udc->pdata->have_sysif_regs) {
654 - ctrl = __raw_readl(&usb_sys_regs->control);
655 + ctrl = ioread32be(&usb_sys_regs->control);
656 ctrl |= USB_CTRL_IOENB;
657 - __raw_writel(ctrl, &usb_sys_regs->control);
658 + iowrite32be(ctrl, &usb_sys_regs->control);
662 -#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
663 +#if !defined(CONFIG_NOT_COHERENT_CACHE)
664 /* Turn on cache snooping hardware, since some PowerPC platforms
665 * wholly rely on hardware to deal with cache coherent. */
667 if (udc->pdata->have_sysif_regs) {
668 /* Setup Snooping for all the 4GB space */
669 tmp = SNOOP_SIZE_2GB; /* starts from 0x0, size 2G */
670 - __raw_writel(tmp, &usb_sys_regs->snoop1);
671 + iowrite32be(tmp, &usb_sys_regs->snoop1);
672 tmp |= 0x80000000; /* starts from 0x8000000, size 2G */
673 - __raw_writel(tmp, &usb_sys_regs->snoop2);
674 + iowrite32be(tmp, &usb_sys_regs->snoop2);
678 @@ -1057,7 +1062,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
679 struct ep_queue_head *qh;
681 ep = container_of(_ep, struct fsl_ep, ep);
682 - if (!_ep || (!ep->ep.desc && ep_index(ep) != 0))
683 + if (!_ep || !ep->ep.desc || (ep_index(ep) == 0))
686 udc = (struct fsl_udc *)ep->udc;
687 @@ -1599,14 +1604,13 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
688 struct fsl_req *curr_req)
690 struct ep_td_struct *curr_td;
691 - int td_complete, actual, remaining_length, j, tmp;
692 + int actual, remaining_length, j, tmp;
695 struct ep_queue_head *curr_qh = &udc->ep_qh[pipe];
696 int direction = pipe % 2;
698 curr_td = curr_req->head;
700 actual = curr_req->req.length;
702 for (j = 0; j < curr_req->dtd_count; j++) {
703 @@ -1651,11 +1655,9 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
712 VDBG("dTD transmitted successful");
715 @@ -1698,7 +1700,7 @@ static void dtd_complete_irq(struct fsl_udc *udc)
716 curr_ep = get_ep_by_pipe(udc, i);
718 /* If the ep is configured */
719 - if (curr_ep->name == NULL) {
720 + if (strncmp(curr_ep->name, "ep", 2)) {
721 WARNING("Invalid EP?");
724 @@ -2420,10 +2422,12 @@ static int fsl_udc_probe(struct platform_device *pdev)
725 usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
728 +#ifdef CONFIG_ARCH_MXC
729 /* Initialize USB clocks */
730 ret = fsl_udc_clk_init(pdev);
732 goto err_iounmap_noclk;
735 /* Read Device Controller Capability Parameters register */
736 dccparams = fsl_readl(&dr_regs->dccparams);
737 @@ -2463,9 +2467,11 @@ static int fsl_udc_probe(struct platform_device *pdev)
738 dr_controller_setup(udc_controller);
741 +#ifdef CONFIG_ARCH_MXC
742 ret = fsl_udc_clk_finalize(pdev);
747 /* Setup gadget structure */
748 udc_controller->gadget.ops = &fsl_gadget_ops;
749 @@ -2478,6 +2484,7 @@ static int fsl_udc_probe(struct platform_device *pdev)
750 /* Setup gadget.dev and register with kernel */
751 dev_set_name(&udc_controller->gadget.dev, "gadget");
752 udc_controller->gadget.dev.of_node = pdev->dev.of_node;
753 + set_dma_ops(&udc_controller->gadget.dev, pdev->dev.archdata.dma_ops);
755 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
756 udc_controller->gadget.is_otg = 1;
757 @@ -2529,7 +2536,9 @@ static int fsl_udc_probe(struct platform_device *pdev)
761 +#ifdef CONFIG_ARCH_MXC
762 fsl_udc_clk_release();
766 err_release_mem_region:
767 @@ -2557,8 +2566,9 @@ static int fsl_udc_remove(struct platform_device *pdev)
768 udc_controller->done = &done;
769 usb_del_gadget_udc(&udc_controller->gadget);
771 +#ifdef CONFIG_ARCH_MXC
772 fsl_udc_clk_release();
775 /* DR has been stopped in usb_gadget_unregister_driver() */
778 @@ -2570,7 +2580,7 @@ static int fsl_udc_remove(struct platform_device *pdev)
779 dma_pool_destroy(udc_controller->td_pool);
780 free_irq(udc_controller->irq, udc_controller);
782 - if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
783 + if (res && (pdata->operating_mode == FSL_USB2_DR_DEVICE))
784 release_mem_region(res->start, resource_size(res));
786 /* free udc --wait for the release() finished */
787 diff --git a/drivers/usb/gadget/udc/fsl_usb2_udc.h b/drivers/usb/gadget/udc/fsl_usb2_udc.h
788 index 84715625..f76c4ddd 100644
789 --- a/drivers/usb/gadget/udc/fsl_usb2_udc.h
790 +++ b/drivers/usb/gadget/udc/fsl_usb2_udc.h
792 #define USB_MAX_CTRL_PAYLOAD 64
793 #define USB_DR_SYS_OFFSET 0x400
795 +#ifdef CONFIG_SOC_LS1021A
796 +#undef CONFIG_ARCH_MXC
799 /* USB DR device mode registers (Little Endian) */
800 struct usb_dr_device {
801 /* Capability register */
802 @@ -597,18 +601,6 @@ struct platform_device;
803 int fsl_udc_clk_init(struct platform_device *pdev);
804 int fsl_udc_clk_finalize(struct platform_device *pdev);
805 void fsl_udc_clk_release(void);
807 -static inline int fsl_udc_clk_init(struct platform_device *pdev)
811 -static inline int fsl_udc_clk_finalize(struct platform_device *pdev)
815 -static inline void fsl_udc_clk_release(void)
821 diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
822 index 0b80cee3..a57d95c3 100644
823 --- a/drivers/usb/host/Kconfig
824 +++ b/drivers/usb/host/Kconfig
825 @@ -165,7 +165,7 @@ config XPS_USB_HCD_XILINX
828 tristate "Support for Freescale PPC on-chip EHCI USB controller"
830 + depends on USB_EHCI_HCD
831 select USB_EHCI_ROOT_HUB_TT
833 Variation of ARC USB block used in some Freescale chips.
834 diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
835 index 9f5ffb62..cd16860c 100644
836 --- a/drivers/usb/host/ehci-fsl.c
837 +++ b/drivers/usb/host/ehci-fsl.c
839 #include <linux/fsl_devices.h>
840 #include <linux/of_platform.h>
843 +#include <asm/fsl_pm.h>
844 +#include <linux/suspend.h>
848 #include "ehci-fsl.h"
850 +#define FSL_USB_PHY_ADDR 0xffe214000
852 +struct ccsr_usb_port_ctrl {
869 +struct ccsr_usb_phy {
871 + struct ccsr_usb_port_ctrl port1;
879 + struct ccsr_usb_port_ctrl port2;
883 #define DRIVER_DESC "Freescale EHCI Host controller driver"
884 #define DRV_NAME "ehci-fsl"
886 static struct hc_driver __read_mostly fsl_ehci_hc_driver;
888 + /* store current hcd state for otg;
889 + * have_hcd is true when host drv al already part of otg framework,
891 + * hcd_add is true when otg framework wants to add host
892 + * drv as part of otg;flase when it wants to remove it
894 +unsigned have_hcd:1;
898 +static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
900 +struct ehci_hcd *ehci = hcd_to_ehci(hcd);
902 +return container_of(ehci, struct ehci_fsl, ehci);
905 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
906 +static void do_change_hcd(struct work_struct *work)
908 +struct ehci_hcd *ehci = container_of(work, struct ehci_hcd,
910 +struct usb_hcd *hcd = ehci_to_hcd(ehci);
911 +struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
912 +void __iomem *non_ehci = hcd->regs;
915 + if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
916 + writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
917 + /* host, gadget and otg share same int line */
918 + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
920 + ehci_fsl->have_hcd = 1;
921 + } else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
922 + usb_remove_hcd(hcd);
923 + ehci_fsl->have_hcd = 0;
929 + struct ehci_hcd ehci;
932 +struct ehci_regs saved_regs;
933 +struct ccsr_usb_phy saved_phy_regs;
934 +/* Saved USB PHY settings, need to restore after deep sleep. */
938 + * store current hcd state for otg;
939 + * have_hcd is true when host drv al already part of otg framework,
941 + * hcd_add is true when otg framework wants to add host
942 + * drv as part of otg;flase when it wants to remove it
944 +unsigned have_hcd:1;
948 +static strut ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
950 +struct ehci_hcd *ehci = hcd_to_ehci(hcd);
952 +return container_of(ehci, struct ehci_fsl, ehci);
955 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
956 +static void do_change_hcd(struct work_struct *work)
958 +struct ehci_hcd *ehci = container_of(work, struct ehci_hcd,
960 +struct usb_hcd *hcd = ehci_to_hcd(ehci);
961 +struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
962 +void __iomem *non_ehci = hcd->regs;
965 +if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
966 +writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
967 +/* host, gadget and otg share same int line */
968 +retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
970 +ehci_fsl->have_hcd = 1;
971 +} else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
972 + usb_remove_hcd(hcd);
973 +ehci_fsl->have_hcd = 0;
978 /* configure so an HC device and id are always provided */
979 /* always called with process context; sleeping is OK */
980 @@ -131,6 +259,12 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev)
981 clrsetbits_be32(hcd->regs + FSL_SOC_USB_CTRL,
982 CONTROL_REGISTER_W1C_MASK, 0x4);
984 + /* Set USB_EN bit to select ULPI phy for USB controller version 2.5 */
985 + if (pdata->controller_ver == FSL_USB_VER_2_5 &&
986 + pdata->phy_mode == FSL_USB2_PHY_ULPI)
987 + iowrite32be(USB_CTRL_USB_EN, hcd->regs + FSL_SOC_USB_CTRL);
991 * Enable UTMI phy and program PTS field in UTMI mode before asserting
992 * controller reset for USB Controller version 2.5
993 @@ -143,16 +277,20 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev)
995 /* Don't need to set host mode here. It will be done by tdi_reset() */
997 - retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
998 + retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_NO_SUSPEND);
1001 device_wakeup_enable(hcd->self.controller);
1003 -#ifdef CONFIG_USB_OTG
1004 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1005 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
1006 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1007 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1009 hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2);
1011 + INIT_WORK(&ehci->change_hcd_work, do_change_hcd);
1013 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
1014 hcd, ehci, hcd->usb_phy);
1016 @@ -168,6 +306,11 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev)
1021 + ehci_fsl->have_hcd = 1;
1023 + dev_err(&pdev->dev, "wrong operating mode\n");
1028 @@ -181,6 +324,18 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev)
1032 +static bool usb_phy_clk_valid(struct usb_hcd *hcd,
1033 + enum fsl_usb2_phy_modes phy_mode)
1035 + void __iomem *non_ehci = hcd->regs;
1038 + if (!(in_be32(non_ehci + FSL_SOC_USB_CTRL) & PHY_CLK_VALID))
1044 static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
1045 enum fsl_usb2_phy_modes phy_mode,
1046 unsigned int port_offset)
1047 @@ -219,6 +374,21 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
1049 case FSL_USB2_PHY_UTMI:
1050 case FSL_USB2_PHY_UTMI_DUAL:
1051 + if (pdata->has_fsl_erratum_a006918) {
1052 + pr_warn("fsl-ehci: USB PHY clock invalid\n");
1056 + /* PHY_CLK_VALID bit is de-featured from all controller
1057 + * versions below 2.4 and is to be checked only for
1058 + * internal UTMI phy
1060 + if (pdata->controller_ver > FSL_USB_VER_2_4 &&
1061 + pdata->have_sysif_regs && !usb_phy_clk_valid(hcd)) {
1062 + pr_err("fsl-ehci: USB PHY clock invalid\n");
1066 if (pdata->have_sysif_regs && pdata->controller_ver) {
1067 /* controller version 1.6 or above */
1068 clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
1069 @@ -292,14 +462,9 @@ static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
1072 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
1073 - unsigned int chip, rev, svr;
1075 - svr = mfspr(SPRN_SVR);
1077 - rev = (svr >> 4) & 0xf;
1079 /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
1080 - if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
1081 + if (pdata->has_fsl_erratum_14 == 1)
1082 ehci->has_fsl_port_bug = 1;
1084 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
1085 @@ -379,16 +544,57 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
1090 - struct ehci_hcd ehci;
1093 - /* Saved USB PHY settings, need to restore after deep sleep. */
1097 +void __iomem *phy_reg;
1101 +/* save usb registers */
1102 +static int ehci_fsl_save_context(struct usb_hcd *hcd)
1104 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1105 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1106 + void __iomem *non_ehci = hcd->regs;
1107 + struct device *dev = hcd->self.controller;
1108 + struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
1110 + if (pdata->phy_mode == FSL_USB2_PHY_UTMI_DUAL) {
1111 + phy_reg = ioremap(FSL_USB_PHY_ADDR,
1112 + sizeof(struct ccsr_usb_phy));
1113 + _memcpy_fromio((void *)&ehci_fsl->saved_phy_regs, phy_reg,
1114 + sizeof(struct ccsr_usb_phy));
1117 + _memcpy_fromio((void *)&ehci_fsl->saved_regs, ehci->regs,
1118 + sizeof(struct ehci_regs));
1119 + ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
1124 +/*Restore usb registers */
1125 +static int ehci_fsl_restore_context(struct usb_hcd *hcd)
1127 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1128 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1129 + void __iomem *non_ehci = hcd->regs;
1130 + struct device *dev = hcd->self.controller;
1131 + struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
1133 + if (pdata->phy_mode == FSL_USB2_PHY_UTMI_DUAL) {
1135 + _memcpy_toio(phy_reg,
1136 + (void *)&ehci_fsl->saved_phy_regs,
1137 + sizeof(struct ccsr_usb_phy));
1140 + _memcpy_toio(ehci->regs, (void *)&ehci_fsl->saved_regs,
1141 + sizeof(struct ehci_regs));
1142 + iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL);
1148 #ifdef CONFIG_PPC_MPC512x
1149 static int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
1150 @@ -535,26 +741,43 @@ static inline int ehci_fsl_mpc512x_drv_resume(struct device *dev)
1152 #endif /* CONFIG_PPC_MPC512x */
1154 -static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
1156 - struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1158 - return container_of(ehci, struct ehci_fsl, ehci);
1161 static int ehci_fsl_drv_suspend(struct device *dev)
1163 struct usb_hcd *hcd = dev_get_drvdata(dev);
1164 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1165 void __iomem *non_ehci = hcd->regs;
1166 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1167 + struct usb_bus host = hcd->self;
1171 +suspend_state_t pm_state;
1172 +pm_state = pm_suspend_state();
1174 +if (pm_state == PM_SUSPEND_MEM)
1175 + ehci_fsl_save_context(hcd);
1178 if (of_device_is_compatible(dev->parent->of_node,
1179 "fsl,mpc5121-usb2-dr")) {
1180 return ehci_fsl_mpc512x_drv_suspend(dev);
1183 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1184 + if (host.is_otg) {
1185 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1188 + ehci_fsl->hcd_add = 0;
1189 + schedule_work(&ehci->change_hcd_work);
1195 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
1196 device_may_wakeup(dev));
1198 if (!fsl_deep_sleep())
1201 @@ -568,12 +791,34 @@ static int ehci_fsl_drv_resume(struct device *dev)
1202 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1203 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1204 void __iomem *non_ehci = hcd->regs;
1205 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1206 + struct usb_bus host = hcd->self;
1210 +suspend_state_t pm_state;
1211 +pm_state = pm_suspend_state();
1213 +if (pm_state == PM_SUSPEND_MEM)
1214 + ehci_fsl_restore_context(hcd);
1217 if (of_device_is_compatible(dev->parent->of_node,
1218 "fsl,mpc5121-usb2-dr")) {
1219 return ehci_fsl_mpc512x_drv_resume(dev);
1222 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1223 + if (host.is_otg) {
1225 + ehci_fsl->hcd_add = 1;
1226 + schedule_work(&ehci->change_hcd_work);
1227 + usb_hcd_resume_root_hub(hcd);
1233 ehci_prepare_ports_for_controller_resume(ehci);
1234 if (!fsl_deep_sleep())
1236 diff --git a/drivers/usb/host/ehci-fsl.h b/drivers/usb/host/ehci-fsl.h
1237 index 1a8a60a5..42ea2976 100644
1238 --- a/drivers/usb/host/ehci-fsl.h
1239 +++ b/drivers/usb/host/ehci-fsl.h
1241 #define UTMI_PHY_EN (1<<9)
1242 #define ULPI_PHY_CLK_SEL (1<<10)
1243 #define PHY_CLK_VALID (1<<17)
1245 +/* Retry count for checking UTMI PHY CLK validity */
1246 +#define UTMI_PHY_CLK_VALID_CHK_RETRY 5
1247 #endif /* _EHCI_FSL_H */
1248 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
1249 index 255acca8..c8838c33 100644
1250 --- a/drivers/usb/host/ehci-hub.c
1251 +++ b/drivers/usb/host/ehci-hub.c
1252 @@ -305,6 +305,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
1253 USB_PORT_STAT_HIGH_SPEED)
1254 fs_idle_delay = true;
1255 ehci_writel(ehci, t2, reg);
1256 + if (ehci_has_fsl_susp_errata(ehci))
1257 + usleep_range(10000, 20000);
1261 diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
1262 index 3b06bb77..f296d1fb 100644
1263 --- a/drivers/usb/host/ehci.h
1264 +++ b/drivers/usb/host/ehci.h
1265 @@ -180,6 +180,9 @@ struct ehci_hcd { /* one per controller */
1266 unsigned periodic_count; /* periodic activity count */
1267 unsigned uframe_periodic_max; /* max periodic time per uframe */
1269 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1270 + struct work_struct change_hcd_work;
1273 /* list of itds & sitds completed while now_frame was still active */
1274 struct list_head cached_itd_list;
1275 @@ -706,8 +709,10 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
1276 * incoming packets get corrupted in HS mode
1278 #define ehci_has_fsl_hs_errata(e) ((e)->has_fsl_hs_errata)
1279 +#define ehci_has_fsl_susp_errata(e) ((e)->has_fsl_susp_errata)
1281 #define ehci_has_fsl_hs_errata(e) (0)
1282 +#define ehci_has_fsl_susp_errata(e) (0)
1286 diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
1287 index f07ccb25..1e59ea9f 100644
1288 --- a/drivers/usb/host/fsl-mph-dr-of.c
1289 +++ b/drivers/usb/host/fsl-mph-dr-of.c
1290 @@ -226,6 +226,18 @@ static int fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev)
1291 of_property_read_bool(np, "fsl,usb-erratum-a007792");
1292 pdata->has_fsl_erratum_a005275 =
1293 of_property_read_bool(np, "fsl,usb-erratum-a005275");
1294 + pdata->has_fsl_erratum_a005697 =
1295 + of_property_read_bool(np, "fsl,usb_erratum-a005697");
1296 + if (of_get_property(np, "fsl,erratum_a006918", NULL))
1297 + pdata->has_fsl_erratum_a006918 = 1;
1299 + pdata->has_fsl_erratum_a006918 = 0;
1301 + if (of_get_property(np, "fsl,usb_erratum_14", NULL))
1302 + pdata->has_fsl_erratum_14 = 1;
1304 + pdata->has_fsl_erratum_14 = 0;
1308 * Determine whether phy_clk_valid needs to be checked
1309 diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c
1310 index 94eb2923..836355fa 100644
1311 --- a/drivers/usb/phy/phy-fsl-usb.c
1312 +++ b/drivers/usb/phy/phy-fsl-usb.c
1315 - * Copyright (C) 2007,2008 Freescale semiconductor, Inc.
1316 + * Copyright 2007,2008 Freescale Semiconductor, Inc.
1318 * Author: Li Yang <LeoLi@freescale.com>
1319 * Jerry Huang <Chang-Ming.Huang@freescale.com>
1320 @@ -463,6 +463,7 @@ void otg_reset_controller(void)
1321 int fsl_otg_start_host(struct otg_fsm *fsm, int on)
1323 struct usb_otg *otg = fsm->otg;
1324 + struct usb_bus *host = otg->host;
1326 struct fsl_otg *otg_dev =
1327 container_of(otg->usb_phy, struct fsl_otg, phy);
1328 @@ -486,6 +487,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on)
1329 otg_reset_controller();
1330 VDBG("host on......\n");
1331 if (dev->driver->pm && dev->driver->pm->resume) {
1333 retval = dev->driver->pm->resume(dev);
1336 @@ -510,8 +512,11 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on)
1338 VDBG("host off......\n");
1339 if (dev && dev->driver) {
1340 - if (dev->driver->pm && dev->driver->pm->suspend)
1341 + if (dev->driver->pm &&
1342 + dev->driver->pm->suspend) {
1344 retval = dev->driver->pm->suspend(dev);
1348 fsl_otg_drv_vbus(fsm, 0);
1349 @@ -539,8 +544,17 @@ int fsl_otg_start_gadget(struct otg_fsm *fsm, int on)
1350 dev = otg->gadget->dev.parent;
1353 - if (dev->driver->resume)
1354 + /* Delay gadget resume to synchronize between host and gadget
1355 + * drivers. Upon role-reversal host drv is shutdown by kernel
1356 + * worker thread. By the time host drv shuts down, controller
1357 + * gets programmed for gadget role. Shutting host drv after
1358 + * this results in controller getting reset, and it stops
1359 + * responding to otg events
1361 + if (dev->driver->resume) {
1363 dev->driver->resume(dev);
1366 if (dev->driver->suspend)
1367 dev->driver->suspend(dev, otg_suspend_state);
1368 @@ -672,6 +686,10 @@ static void fsl_otg_event(struct work_struct *work)
1369 fsl_otg_start_host(fsm, 0);
1370 otg_drv_vbus(fsm, 0);
1371 fsl_otg_start_gadget(fsm, 1);
1373 + fsl_otg_start_gadget(fsm, 0);
1374 + otg_drv_vbus(fsm, 1);
1375 + fsl_otg_start_host(fsm, 1);
1379 @@ -724,6 +742,7 @@ irqreturn_t fsl_otg_isr(int irq, void *dev_id)
1381 struct otg_fsm *fsm = &((struct fsl_otg *)dev_id)->fsm;
1382 struct usb_otg *otg = ((struct fsl_otg *)dev_id)->phy.otg;
1383 + struct fsl_otg *otg_dev = dev_id;
1384 u32 otg_int_src, otg_sc;
1386 otg_sc = fsl_readl(&usb_dr_regs->otgsc);
1387 @@ -753,18 +772,8 @@ irqreturn_t fsl_otg_isr(int irq, void *dev_id)
1388 otg->gadget->is_a_peripheral = !fsm->id;
1389 VDBG("ID int (ID is %d)\n", fsm->id);
1391 - if (fsm->id) { /* switch to gadget */
1392 - schedule_delayed_work(
1393 - &((struct fsl_otg *)dev_id)->otg_event,
1395 - } else { /* switch to host */
1396 - cancel_delayed_work(&
1397 - ((struct fsl_otg *)dev_id)->
1399 - fsl_otg_start_gadget(fsm, 0);
1400 - otg_drv_vbus(fsm, 1);
1401 - fsl_otg_start_host(fsm, 1);
1403 + schedule_delayed_work(&otg_dev->otg_event, 100);
1408 @@ -923,12 +932,32 @@ int usb_otg_start(struct platform_device *pdev)
1409 temp &= ~(PORTSC_PHY_TYPE_SEL | PORTSC_PTW);
1410 switch (pdata->phy_mode) {
1411 case FSL_USB2_PHY_ULPI:
1412 + if (pdata->controller_ver) {
1413 + /* controller version 1.6 or above */
1414 + setbits32(&p_otg->dr_mem_map->control,
1415 + USB_CTRL_ULPI_PHY_CLK_SEL);
1417 + * Due to controller issue of PHY_CLK_VALID in ULPI
1418 + * mode, we set USB_CTRL_USB_EN before checking
1419 + * PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
1421 + clrsetbits_be32(&p_otg->dr_mem_map->control,
1422 + USB_CTRL_UTMI_PHY_EN, USB_CTRL_IOENB);
1424 temp |= PORTSC_PTS_ULPI;
1426 case FSL_USB2_PHY_UTMI_WIDE:
1427 temp |= PORTSC_PTW_16BIT;
1429 case FSL_USB2_PHY_UTMI:
1430 + if (pdata->controller_ver) {
1431 + /* controller version 1.6 or above */
1432 + setbits32(&p_otg->dr_mem_map->control,
1433 + USB_CTRL_UTMI_PHY_EN);
1434 + /* Delay for UTMI PHY CLK to become stable - 10ms */
1435 + mdelay(FSL_UTMI_PHY_DLY);
1437 + setbits32(&p_otg->dr_mem_map->control, USB_CTRL_UTMI_PHY_EN);
1438 temp |= PORTSC_PTS_UTMI;
1441 diff --git a/drivers/usb/phy/phy-fsl-usb.h b/drivers/usb/phy/phy-fsl-usb.h
1442 index 23149954..c4c08730 100644
1443 --- a/drivers/usb/phy/phy-fsl-usb.h
1444 +++ b/drivers/usb/phy/phy-fsl-usb.h
1445 @@ -199,6 +199,14 @@
1446 /* control Register Bit Masks */
1447 #define USB_CTRL_IOENB (0x1<<2)
1448 #define USB_CTRL_ULPI_INT0EN (0x1<<0)
1449 +#define USB_CTRL_WU_INT_EN (0x1<<1)
1450 +#define USB_CTRL_LINE_STATE_FILTER__EN (0x1<<3)
1451 +#define USB_CTRL_KEEP_OTG_ON (0x1<<4)
1452 +#define USB_CTRL_OTG_PORT (0x1<<5)
1453 +#define USB_CTRL_PLL_RESET (0x1<<8)
1454 +#define USB_CTRL_UTMI_PHY_EN (0x1<<9)
1455 +#define USB_CTRL_ULPI_PHY_CLK_SEL (0x1<<10)
1456 +#define USB_CTRL_PHY_CLK_VALID (0x1<<17)
1459 #define BCSR5_INT_USB (0x02)
1460 diff --git a/include/linux/usb.h b/include/linux/usb.h
1461 index eba1f10e..c334e281 100644
1462 --- a/include/linux/usb.h
1463 +++ b/include/linux/usb.h
1464 @@ -362,6 +362,7 @@ struct usb_bus {
1465 * for control transfers?
1467 u8 otg_port; /* 0, or number of OTG/HNP port */
1468 + unsigned is_otg:1; /* true when host is also otg */
1469 unsigned is_b_host:1; /* true during some HNP roleswitches */
1470 unsigned b_hnp_enable:1; /* OTG: did A-Host enable HNP? */
1471 unsigned no_stop_on_short:1; /*
1472 diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
1473 index 5ff9032e..2a57e0d2 100644
1474 --- a/include/linux/usb/of.h
1475 +++ b/include/linux/usb/of.h
1477 #include <linux/usb/otg.h>
1478 #include <linux/usb/phy.h>
1480 +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
1482 #if IS_ENABLED(CONFIG_OF)
1483 enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0);
1484 bool of_usb_host_tpl_support(struct device_node *np);