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 --- a/drivers/net/usb/r8152.c
39 +++ b/drivers/net/usb/r8152.c
40 @@ -1816,6 +1816,10 @@ static int rx_bottom(struct r8152 *tp, i
44 + /* limite the skb numbers for rx_queue */
45 + if (unlikely(skb_queue_len(&tp->rx_queue) >= 1000))
48 pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK;
49 if (pkt_len < ETH_ZLEN)
51 --- a/drivers/usb/common/common.c
52 +++ b/drivers/usb/common/common.c
53 @@ -105,6 +105,56 @@ static const char *const usb_dr_modes[]
54 [USB_DR_MODE_OTG] = "otg",
58 + * of_usb_get_dr_mode - Get dual role mode for given device_node
59 + * @np: Pointer to the given device_node
61 + * The function gets phy interface string from property 'dr_mode',
62 + * and returns the correspondig enum usb_dr_mode
64 +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
66 + const char *dr_mode;
69 + err = of_property_read_string(np, "dr_mode", &dr_mode);
71 + return USB_DR_MODE_UNKNOWN;
73 + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
74 + if (!strcmp(dr_mode, usb_dr_modes[i]))
77 + return USB_DR_MODE_UNKNOWN;
79 +EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
82 + * of_usb_get_maximum_speed - Get maximum requested speed for a given USB
84 + * @np: Pointer to the given device_node
86 + * The function gets the maximum speed string from property "maximum-speed",
87 + * and returns the corresponding enum usb_device_speed.
89 +enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np)
91 + const char *maximum_speed;
95 + err = of_property_read_string(np, "maximum-speed", &maximum_speed);
97 + return USB_SPEED_UNKNOWN;
99 + for (i = 0; i < ARRAY_SIZE(speed_names); i++)
100 + if (strcmp(maximum_speed, speed_names[i]) == 0)
103 + return USB_SPEED_UNKNOWN;
105 +EXPORT_SYMBOL_GPL(of_usb_get_maximum_speed);
107 static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
110 --- a/drivers/usb/core/hub.c
111 +++ b/drivers/usb/core/hub.c
112 @@ -4415,6 +4415,14 @@ hub_port_init(struct usb_hub *hub, struc
114 speed = usb_speed_string(udev->speed);
116 +#if !defined(CONFIG_FSL_USB2_OTG) && !defined(CONFIG_FSL_USB2_OTG_MODULE)
117 +if (udev->speed != USB_SPEED_SUPER)
118 + dev_info(&udev->dev,
119 + "%s %s USB device number %d using %s\n",
120 + (udev->config) ? "reset" : "new", speed,
121 + devnum, udev->bus->controller->driver->name);
124 if (udev->speed < USB_SPEED_SUPER)
126 "%s %s USB device number %d using %s\n",
127 --- a/drivers/usb/dwc3/core.c
128 +++ b/drivers/usb/dwc3/core.c
129 @@ -58,6 +58,7 @@ static int dwc3_get_dr_mode(struct dwc3
130 enum usb_dr_mode mode;
131 struct device *dev = dwc->dev;
132 unsigned int hw_mode;
133 + struct device_node *node = dev->of_node;
135 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
136 dwc->dr_mode = USB_DR_MODE_OTG;
137 @@ -83,6 +84,24 @@ static int dwc3_get_dr_mode(struct dwc3
138 mode = USB_DR_MODE_HOST;
141 + /* Adjust Frame Length */
142 + if (dwc->configure_gfladj)
143 + dwc3_writel(dwc->regs, DWC3_GFLADJ, GFLADJ_30MHZ_REG_SEL |
144 + GFLADJ_30MHZ(GFLADJ_30MHZ_DEFAULT));
146 + /* Change burst beat and outstanding pipelined transfers requests */
147 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
148 + (dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) & ~0xff) | 0xf);
149 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG1,
150 + dwc3_readl(dwc->regs, DWC3_GSBUSCFG1) | 0xf00);
152 + /* Enable Snooping */
153 + if (node && of_dma_is_coherent(node)) {
154 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
155 + dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) | 0x22220000);
156 + dev_dbg(dev, "enabled snooping for usb\n");
159 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
160 mode = USB_DR_MODE_HOST;
161 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
162 @@ -213,8 +232,9 @@ static void dwc3_frame_length_adjustment
164 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
165 dft = reg & DWC3_GFLADJ_30MHZ_MASK;
166 - if (!dev_WARN_ONCE(dwc->dev, dft == dwc->fladj,
167 - "request value same as default, ignoring\n")) {
168 + if (dft == dwc->fladj) {
169 + dev_warn(dwc->dev, "request value same as default, ignoring\n");
171 reg &= ~DWC3_GFLADJ_30MHZ_MASK;
172 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj;
173 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
174 @@ -579,6 +599,99 @@ static int dwc3_phy_setup(struct dwc3 *d
178 +/* set global soc bus configuration registers */
179 +static void dwc3_set_soc_bus_cfg(struct dwc3 *dwc)
181 + struct device *dev = dwc->dev;
188 + cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0);
191 + * Handle property "snps,incr-burst-type-adjustment".
192 + * Get the number of value from this property:
193 + * result <= 0, means this property is not supported.
194 + * result = 1, means INCRx burst mode supported.
195 + * result > 1, means undefined length burst mode supported.
197 + ntype = device_property_read_u32_array(dev,
198 + "snps,incr-burst-type-adjustment", NULL, 0);
200 + vals = kcalloc(ntype, sizeof(u32), GFP_KERNEL);
202 + dev_err(dev, "Error to get memory\n");
205 + /* Get INCR burst type, and parse it */
206 + ret = device_property_read_u32_array(dev,
207 + "snps,incr-burst-type-adjustment", vals, ntype);
209 + dev_err(dev, "Error to get property\n");
212 + *(dwc->incrx_type + 1) = vals[0];
214 + *dwc->incrx_type = 1;
215 + for (i = 1; i < ntype; i++) {
216 + if (vals[i] > *(dwc->incrx_type + 1))
217 + *(dwc->incrx_type + 1) = vals[i];
220 + *dwc->incrx_type = 0;
222 + /* Enable Undefined Length INCR Burst and Enable INCRx Burst */
223 + cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK;
224 + if (*dwc->incrx_type)
225 + cfg |= DWC3_GSBUSCFG0_INCRBRSTENA;
226 + switch (*(dwc->incrx_type + 1)) {
228 + cfg |= DWC3_GSBUSCFG0_INCR256BRSTENA;
231 + cfg |= DWC3_GSBUSCFG0_INCR128BRSTENA;
234 + cfg |= DWC3_GSBUSCFG0_INCR64BRSTENA;
237 + cfg |= DWC3_GSBUSCFG0_INCR32BRSTENA;
240 + cfg |= DWC3_GSBUSCFG0_INCR16BRSTENA;
243 + cfg |= DWC3_GSBUSCFG0_INCR8BRSTENA;
246 + cfg |= DWC3_GSBUSCFG0_INCR4BRSTENA;
251 + dev_err(dev, "Invalid property\n");
256 + /* Handle usb snooping */
257 + if (dwc->dma_snooping_quirk) {
258 + cfg &= ~DWC3_GSBUSCFG0_SNP_MASK;
259 + cfg |= (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DATARD_SHIFT) |
260 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DESCRD_SHIFT) |
261 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DATAWR_SHIFT) |
262 + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DESCWR_SHIFT);
265 + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg);
271 static void dwc3_core_exit(struct dwc3 *dwc)
273 dwc3_event_buffers_cleanup(dwc);
274 @@ -721,6 +834,8 @@ static int dwc3_core_init(struct dwc3 *d
278 + dwc3_set_soc_bus_cfg(dwc);
280 /* Adjust Frame Length */
281 dwc3_frame_length_adjustment(dwc);
283 @@ -919,11 +1034,109 @@ static void dwc3_core_exit_mode(struct d
287 +static void dwc3_get_properties(struct dwc3 *dwc)
289 + struct device *dev = dwc->dev;
290 + struct device_node *node = dev->of_node;
291 + u8 lpm_nyet_threshold;
295 + /* default to highest possible threshold */
296 + lpm_nyet_threshold = 0xff;
298 + /* default to -3.5dB de-emphasis */
299 + tx_de_emphasis = 1;
302 + * default to assert utmi_sleep_n and use maximum allowed HIRD
303 + * threshold value of 0b1100
305 + hird_threshold = 12;
307 + dwc->maximum_speed = usb_get_maximum_speed(dev);
308 + dwc->dr_mode = usb_get_dr_mode(dev);
309 + dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
311 + dwc->sysdev_is_parent = device_property_read_bool(dev,
312 + "linux,sysdev_is_parent");
313 + if (dwc->sysdev_is_parent)
314 + dwc->sysdev = dwc->dev->parent;
316 + dwc->sysdev = dwc->dev;
318 + dwc->has_lpm_erratum = device_property_read_bool(dev,
319 + "snps,has-lpm-erratum");
320 + device_property_read_u8(dev, "snps,lpm-nyet-threshold",
321 + &lpm_nyet_threshold);
322 + dwc->is_utmi_l1_suspend = device_property_read_bool(dev,
323 + "snps,is-utmi-l1-suspend");
324 + device_property_read_u8(dev, "snps,hird-threshold",
326 + dwc->usb3_lpm_capable = device_property_read_bool(dev,
327 + "snps,usb3_lpm_capable");
329 + dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
331 + dwc->configure_gfladj =
332 + of_property_read_bool(node, "configure-gfladj");
333 + dwc->dr_mode = usb_get_dr_mode(dev);
335 + dwc->disable_scramble_quirk = device_property_read_bool(dev,
336 + "snps,disable_scramble_quirk");
337 + dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
338 + "snps,u2exit_lfps_quirk");
339 + dwc->u2ss_inp3_quirk = device_property_read_bool(dev,
340 + "snps,u2ss_inp3_quirk");
341 + dwc->req_p1p2p3_quirk = device_property_read_bool(dev,
342 + "snps,req_p1p2p3_quirk");
343 + dwc->del_p1p2p3_quirk = device_property_read_bool(dev,
344 + "snps,del_p1p2p3_quirk");
345 + dwc->del_phy_power_chg_quirk = device_property_read_bool(dev,
346 + "snps,del_phy_power_chg_quirk");
347 + dwc->lfps_filter_quirk = device_property_read_bool(dev,
348 + "snps,lfps_filter_quirk");
349 + dwc->rx_detect_poll_quirk = device_property_read_bool(dev,
350 + "snps,rx_detect_poll_quirk");
351 + dwc->dis_u3_susphy_quirk = device_property_read_bool(dev,
352 + "snps,dis_u3_susphy_quirk");
353 + dwc->dis_u2_susphy_quirk = device_property_read_bool(dev,
354 + "snps,dis_u2_susphy_quirk");
355 + dwc->dis_enblslpm_quirk = device_property_read_bool(dev,
356 + "snps,dis_enblslpm_quirk");
357 + dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
358 + "snps,dis_rxdet_inp3_quirk");
359 + dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
360 + "snps,dis-u2-freeclk-exists-quirk");
361 + dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev,
362 + "snps,dis-del-phy-power-chg-quirk");
363 + dwc->dma_snooping_quirk = device_property_read_bool(dev,
364 + "snps,dma-snooping");
366 + dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
367 + "snps,tx_de_emphasis_quirk");
368 + device_property_read_u8(dev, "snps,tx_de_emphasis",
370 + device_property_read_string(dev, "snps,hsphy_interface",
371 + &dwc->hsphy_interface);
372 + device_property_read_u32(dev, "snps,quirk-frame-length-adjustment",
375 + dwc->lpm_nyet_threshold = lpm_nyet_threshold;
376 + dwc->tx_de_emphasis = tx_de_emphasis;
378 + dwc->hird_threshold = hird_threshold
379 + | (dwc->is_utmi_l1_suspend << 4);
381 + dwc->imod_interval = 0;
384 #define DWC3_ALIGN_MASK (16 - 1)
386 static int dwc3_probe(struct platform_device *pdev)
388 struct device *dev = &pdev->dev;
389 + struct device_node *node = dev->of_node;
390 struct resource *res;
392 u8 lpm_nyet_threshold;
393 @@ -955,6 +1168,11 @@ static int dwc3_probe(struct platform_de
394 dwc->xhci_resources[0].flags = res->flags;
395 dwc->xhci_resources[0].name = res->name;
398 + dwc->configure_gfladj =
399 + of_property_read_bool(node, "configure-gfladj");
402 res->start += DWC3_GLOBALS_REGS_START;
405 @@ -997,6 +1215,12 @@ static int dwc3_probe(struct platform_de
406 dwc->usb3_lpm_capable = device_property_read_bool(dev,
407 "snps,usb3_lpm_capable");
409 + dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
411 + dwc->configure_gfladj =
412 + of_property_read_bool(node, "configure-gfladj");
413 + dwc->dr_mode = of_usb_get_dr_mode(node);
415 dwc->disable_scramble_quirk = device_property_read_bool(dev,
416 "snps,disable_scramble_quirk");
417 dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
418 @@ -1041,6 +1265,8 @@ static int dwc3_probe(struct platform_de
419 dwc->hird_threshold = hird_threshold
420 | (dwc->is_utmi_l1_suspend << 4);
422 + dwc3_get_properties(dwc);
424 platform_set_drvdata(pdev, dwc);
425 dwc3_cache_hwparams(dwc);
427 @@ -1064,6 +1290,11 @@ static int dwc3_probe(struct platform_de
431 + /* Adjust Frame Length */
432 + if (dwc->configure_gfladj)
433 + dwc3_writel(dwc->regs, DWC3_GFLADJ, GFLADJ_30MHZ_REG_SEL |
434 + GFLADJ_30MHZ(GFLADJ_30MHZ_DEFAULT));
436 pm_runtime_forbid(dev);
438 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
439 --- a/drivers/usb/dwc3/core.h
440 +++ b/drivers/usb/dwc3/core.h
442 #include <linux/dma-mapping.h>
443 #include <linux/mm.h>
444 #include <linux/debugfs.h>
445 +#include <linux/of_address.h>
447 #include <linux/usb/ch9.h>
448 #include <linux/usb/gadget.h>
453 +/* Global SoC Bus Configuration Register 0 */
454 +#define AXI3_CACHE_TYPE_AW 0x8 /* write allocate */
455 +#define AXI3_CACHE_TYPE_AR 0x4 /* read allocate */
456 +#define AXI3_CACHE_TYPE_SNP 0x2 /* cacheable */
457 +#define AXI3_CACHE_TYPE_BUF 0x1 /* bufferable */
458 +#define DWC3_GSBUSCFG0_DATARD_SHIFT 28
459 +#define DWC3_GSBUSCFG0_DESCRD_SHIFT 24
460 +#define DWC3_GSBUSCFG0_DATAWR_SHIFT 20
461 +#define DWC3_GSBUSCFG0_DESCWR_SHIFT 16
462 +#define DWC3_GSBUSCFG0_SNP_MASK 0xffff0000
463 +#define DWC3_GSBUSCFG0_DATABIGEND (1 << 11)
464 +#define DWC3_GSBUSCFG0_DESCBIGEND (1 << 10)
465 +#define DWC3_GSBUSCFG0_INCR256BRSTENA (1 << 7) /* INCR256 burst */
466 +#define DWC3_GSBUSCFG0_INCR128BRSTENA (1 << 6) /* INCR128 burst */
467 +#define DWC3_GSBUSCFG0_INCR64BRSTENA (1 << 5) /* INCR64 burst */
468 +#define DWC3_GSBUSCFG0_INCR32BRSTENA (1 << 4) /* INCR32 burst */
469 +#define DWC3_GSBUSCFG0_INCR16BRSTENA (1 << 3) /* INCR16 burst */
470 +#define DWC3_GSBUSCFG0_INCR8BRSTENA (1 << 2) /* INCR8 burst */
471 +#define DWC3_GSBUSCFG0_INCR4BRSTENA (1 << 1) /* INCR4 burst */
472 +#define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0) /* undefined length enable */
473 +#define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff
475 +/* Global SoC Bus Configuration Register 1 */
476 +#define DWC3_GSBUSCFG1_1KPAGEENA (1 << 12) /* 1K page boundary enable */
477 +#define DWC3_GSBUSCFG1_PTRANSLIMIT_MASK 0xf00
479 /* Global Debug Queue/FIFO Space Available Register */
480 #define DWC3_GDBGFIFOSPACE_NUM(n) ((n) & 0x1f)
481 #define DWC3_GDBGFIFOSPACE_TYPE(n) (((n) << 5) & 0x1e0)
483 #define DWC3_GCTL_CLK_PIPE (1)
484 #define DWC3_GCTL_CLK_PIPEHALF (2)
485 #define DWC3_GCTL_CLK_MASK (3)
487 #define DWC3_GCTL_PRTCAP(n) (((n) & (3 << 12)) >> 12)
488 #define DWC3_GCTL_PRTCAPDIR(n) ((n) << 12)
489 #define DWC3_GCTL_PRTCAP_HOST 1
491 /* Global Frame Length Adjustment Register */
492 #define DWC3_GFLADJ_30MHZ_SDBND_SEL (1 << 7)
493 #define DWC3_GFLADJ_30MHZ_MASK 0x3f
494 +#define GFLADJ_30MHZ_REG_SEL (1 << 7)
495 +#define GFLADJ_30MHZ(n) ((n) & 0x3f)
496 +#define GFLADJ_30MHZ_DEFAULT 0x20
499 /* Global User Control Register 2 */
500 #define DWC3_GUCTL2_RST_ACTBITLATER (1 << 14)
501 @@ -753,6 +783,7 @@ struct dwc3_scratchpad_array {
502 * @regs: base address for our registers
503 * @regs_size: address space size
504 * @fladj: frame length adjustment
505 + * @incrx_type: INCR burst type adjustment
506 * @irq_gadget: peripheral controller's IRQ number
507 * @nr_scratch: number of scratch buffers
508 * @u1u2: only used on revisions <1.83a for workaround
509 @@ -847,6 +878,7 @@ struct dwc3 {
513 + struct device *sysdev;
515 struct platform_device *xhci;
516 struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM];
517 @@ -872,6 +904,12 @@ struct dwc3 {
518 enum usb_phy_interface hsphy_mode;
522 + * For INCR burst type.
523 + * First field: for undefined length INCR burst type enable.
524 + * Second field: for INCRx burst type enable
530 @@ -948,9 +986,12 @@ struct dwc3 {
531 unsigned ep0_bounced:1;
532 unsigned ep0_expect_in:1;
533 unsigned has_hibernation:1;
534 + unsigned sysdev_is_parent:1;
535 unsigned has_lpm_erratum:1;
536 unsigned is_utmi_l1_suspend:1;
538 + unsigned needs_fifo_resize:1;
539 + unsigned configure_gfladj:1;
540 unsigned pending_events:1;
541 unsigned pullups_connected:1;
542 unsigned setup_packet_pending:1;
543 @@ -971,9 +1012,12 @@ struct dwc3 {
544 unsigned dis_rxdet_inp3_quirk:1;
545 unsigned dis_u2_freeclk_exists_quirk:1;
546 unsigned dis_del_phy_power_chg_quirk:1;
547 + unsigned dma_snooping_quirk:1;
549 unsigned tx_de_emphasis_quirk:1;
550 unsigned tx_de_emphasis:2;
555 /* -------------------------------------------------------------------------- */
556 --- a/drivers/usb/dwc3/host.c
557 +++ b/drivers/usb/dwc3/host.c
560 #include <linux/platform_device.h>
562 +#include <linux/of_device.h>
566 int dwc3_host_init(struct dwc3 *dwc)
567 @@ -73,12 +75,21 @@ int dwc3_host_init(struct dwc3 *dwc)
571 - dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
572 + if (IS_ENABLED(CONFIG_OF) && dwc->dev->of_node)
573 + of_dma_configure(&xhci->dev, dwc->dev->of_node);
575 + dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
577 - xhci->dev.parent = dwc->dev;
578 + xhci->dev.parent = dwc->dev;
579 xhci->dev.dma_mask = dwc->dev->dma_mask;
580 xhci->dev.dma_parms = dwc->dev->dma_parms;
582 + /* set DMA operations */
583 + if (dwc->dev->of_node && of_dma_is_coherent(dwc->dev->of_node)) {
584 + xhci->dev.archdata.dma_ops = dwc->dev->archdata.dma_ops;
585 + dev_dbg(dwc->dev, "set dma_ops for usb\n");
590 ret = platform_device_add_resources(xhci, dwc->xhci_resources,
591 --- a/drivers/usb/gadget/udc/fsl_udc_core.c
592 +++ b/drivers/usb/gadget/udc/fsl_udc_core.c
593 @@ -198,7 +198,11 @@ __acquires(ep->udc->lock)
595 spin_unlock(&ep->udc->lock);
597 - usb_gadget_giveback_request(&ep->ep, &req->req);
598 + /* this complete() should a func implemented by gadget layer,
599 + * eg fsg->bulk_in_complete()
601 + if (req->req.complete)
602 + usb_gadget_giveback_request(&ep->ep, &req->req);
604 spin_lock(&ep->udc->lock);
605 ep->stopped = stopped;
606 @@ -245,10 +249,10 @@ static int dr_controller_setup(struct fs
607 if (udc->pdata->have_sysif_regs) {
608 if (udc->pdata->controller_ver) {
609 /* controller version 1.6 or above */
610 - ctrl = __raw_readl(&usb_sys_regs->control);
611 + ctrl = ioread32be(&usb_sys_regs->control);
612 ctrl &= ~USB_CTRL_UTMI_PHY_EN;
613 ctrl |= USB_CTRL_USB_EN;
614 - __raw_writel(ctrl, &usb_sys_regs->control);
615 + iowrite32be(ctrl, &usb_sys_regs->control);
618 portctrl |= PORTSCX_PTS_ULPI;
619 @@ -257,13 +261,14 @@ static int dr_controller_setup(struct fs
620 portctrl |= PORTSCX_PTW_16BIT;
622 case FSL_USB2_PHY_UTMI:
623 + case FSL_USB2_PHY_UTMI_DUAL:
624 if (udc->pdata->have_sysif_regs) {
625 if (udc->pdata->controller_ver) {
626 /* controller version 1.6 or above */
627 - ctrl = __raw_readl(&usb_sys_regs->control);
628 + ctrl = ioread32be(&usb_sys_regs->control);
629 ctrl |= (USB_CTRL_UTMI_PHY_EN |
631 - __raw_writel(ctrl, &usb_sys_regs->control);
632 + iowrite32be(ctrl, &usb_sys_regs->control);
633 mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI
634 PHY CLK to become stable - 10ms*/
636 @@ -329,22 +334,22 @@ static int dr_controller_setup(struct fs
637 /* Config control enable i/o output, cpu endian register */
638 #ifndef CONFIG_ARCH_MXC
639 if (udc->pdata->have_sysif_regs) {
640 - ctrl = __raw_readl(&usb_sys_regs->control);
641 + ctrl = ioread32be(&usb_sys_regs->control);
642 ctrl |= USB_CTRL_IOENB;
643 - __raw_writel(ctrl, &usb_sys_regs->control);
644 + iowrite32be(ctrl, &usb_sys_regs->control);
648 -#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
649 +#if !defined(CONFIG_NOT_COHERENT_CACHE)
650 /* Turn on cache snooping hardware, since some PowerPC platforms
651 * wholly rely on hardware to deal with cache coherent. */
653 if (udc->pdata->have_sysif_regs) {
654 /* Setup Snooping for all the 4GB space */
655 tmp = SNOOP_SIZE_2GB; /* starts from 0x0, size 2G */
656 - __raw_writel(tmp, &usb_sys_regs->snoop1);
657 + iowrite32be(tmp, &usb_sys_regs->snoop1);
658 tmp |= 0x80000000; /* starts from 0x8000000, size 2G */
659 - __raw_writel(tmp, &usb_sys_regs->snoop2);
660 + iowrite32be(tmp, &usb_sys_regs->snoop2);
664 @@ -1057,7 +1062,7 @@ static int fsl_ep_fifo_status(struct usb
665 struct ep_queue_head *qh;
667 ep = container_of(_ep, struct fsl_ep, ep);
668 - if (!_ep || (!ep->ep.desc && ep_index(ep) != 0))
669 + if (!_ep || !ep->ep.desc || (ep_index(ep) == 0))
672 udc = (struct fsl_udc *)ep->udc;
673 @@ -1599,14 +1604,13 @@ static int process_ep_req(struct fsl_udc
674 struct fsl_req *curr_req)
676 struct ep_td_struct *curr_td;
677 - int td_complete, actual, remaining_length, j, tmp;
678 + int actual, remaining_length, j, tmp;
681 struct ep_queue_head *curr_qh = &udc->ep_qh[pipe];
682 int direction = pipe % 2;
684 curr_td = curr_req->head;
686 actual = curr_req->req.length;
688 for (j = 0; j < curr_req->dtd_count; j++) {
689 @@ -1651,11 +1655,9 @@ static int process_ep_req(struct fsl_udc
698 VDBG("dTD transmitted successful");
701 @@ -1698,7 +1700,7 @@ static void dtd_complete_irq(struct fsl_
702 curr_ep = get_ep_by_pipe(udc, i);
704 /* If the ep is configured */
705 - if (curr_ep->name == NULL) {
706 + if (strncmp(curr_ep->name, "ep", 2)) {
707 WARNING("Invalid EP?");
710 @@ -2420,10 +2422,12 @@ static int fsl_udc_probe(struct platform
711 usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
714 +#ifdef CONFIG_ARCH_MXC
715 /* Initialize USB clocks */
716 ret = fsl_udc_clk_init(pdev);
718 goto err_iounmap_noclk;
721 /* Read Device Controller Capability Parameters register */
722 dccparams = fsl_readl(&dr_regs->dccparams);
723 @@ -2463,9 +2467,11 @@ static int fsl_udc_probe(struct platform
724 dr_controller_setup(udc_controller);
727 +#ifdef CONFIG_ARCH_MXC
728 ret = fsl_udc_clk_finalize(pdev);
733 /* Setup gadget structure */
734 udc_controller->gadget.ops = &fsl_gadget_ops;
735 @@ -2478,6 +2484,7 @@ static int fsl_udc_probe(struct platform
736 /* Setup gadget.dev and register with kernel */
737 dev_set_name(&udc_controller->gadget.dev, "gadget");
738 udc_controller->gadget.dev.of_node = pdev->dev.of_node;
739 + set_dma_ops(&udc_controller->gadget.dev, pdev->dev.archdata.dma_ops);
741 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
742 udc_controller->gadget.is_otg = 1;
743 @@ -2529,7 +2536,9 @@ err_free_irq:
747 +#ifdef CONFIG_ARCH_MXC
748 fsl_udc_clk_release();
752 err_release_mem_region:
753 @@ -2557,8 +2566,9 @@ static int fsl_udc_remove(struct platfor
754 udc_controller->done = &done;
755 usb_del_gadget_udc(&udc_controller->gadget);
757 +#ifdef CONFIG_ARCH_MXC
758 fsl_udc_clk_release();
761 /* DR has been stopped in usb_gadget_unregister_driver() */
764 @@ -2570,7 +2580,7 @@ static int fsl_udc_remove(struct platfor
765 dma_pool_destroy(udc_controller->td_pool);
766 free_irq(udc_controller->irq, udc_controller);
768 - if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
769 + if (res && (pdata->operating_mode == FSL_USB2_DR_DEVICE))
770 release_mem_region(res->start, resource_size(res));
772 /* free udc --wait for the release() finished */
773 --- a/drivers/usb/gadget/udc/fsl_usb2_udc.h
774 +++ b/drivers/usb/gadget/udc/fsl_usb2_udc.h
776 #define USB_MAX_CTRL_PAYLOAD 64
777 #define USB_DR_SYS_OFFSET 0x400
779 +#ifdef CONFIG_SOC_LS1021A
780 +#undef CONFIG_ARCH_MXC
783 /* USB DR device mode registers (Little Endian) */
784 struct usb_dr_device {
785 /* Capability register */
786 @@ -597,18 +601,6 @@ struct platform_device;
787 int fsl_udc_clk_init(struct platform_device *pdev);
788 int fsl_udc_clk_finalize(struct platform_device *pdev);
789 void fsl_udc_clk_release(void);
791 -static inline int fsl_udc_clk_init(struct platform_device *pdev)
795 -static inline int fsl_udc_clk_finalize(struct platform_device *pdev)
799 -static inline void fsl_udc_clk_release(void)
805 --- a/drivers/usb/host/Kconfig
806 +++ b/drivers/usb/host/Kconfig
807 @@ -165,7 +165,7 @@ config XPS_USB_HCD_XILINX
810 tristate "Support for Freescale PPC on-chip EHCI USB controller"
812 + depends on USB_EHCI_HCD
813 select USB_EHCI_ROOT_HUB_TT
815 Variation of ARC USB block used in some Freescale chips.
816 --- a/drivers/usb/host/ehci-fsl.c
817 +++ b/drivers/usb/host/ehci-fsl.c
819 #include <linux/fsl_devices.h>
820 #include <linux/of_platform.h>
823 +#include <asm/fsl_pm.h>
824 +#include <linux/suspend.h>
828 #include "ehci-fsl.h"
830 +#define FSL_USB_PHY_ADDR 0xffe214000
832 +struct ccsr_usb_port_ctrl {
849 +struct ccsr_usb_phy {
851 + struct ccsr_usb_port_ctrl port1;
859 + struct ccsr_usb_port_ctrl port2;
863 #define DRIVER_DESC "Freescale EHCI Host controller driver"
864 #define DRV_NAME "ehci-fsl"
866 static struct hc_driver __read_mostly fsl_ehci_hc_driver;
868 + /* store current hcd state for otg;
869 + * have_hcd is true when host drv al already part of otg framework,
871 + * hcd_add is true when otg framework wants to add host
872 + * drv as part of otg;flase when it wants to remove it
874 +unsigned have_hcd:1;
878 +static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
880 +struct ehci_hcd *ehci = hcd_to_ehci(hcd);
882 +return container_of(ehci, struct ehci_fsl, ehci);
885 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
886 +static void do_change_hcd(struct work_struct *work)
888 +struct ehci_hcd *ehci = container_of(work, struct ehci_hcd,
890 +struct usb_hcd *hcd = ehci_to_hcd(ehci);
891 +struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
892 +void __iomem *non_ehci = hcd->regs;
895 + if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
896 + writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
897 + /* host, gadget and otg share same int line */
898 + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
900 + ehci_fsl->have_hcd = 1;
901 + } else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
902 + usb_remove_hcd(hcd);
903 + ehci_fsl->have_hcd = 0;
909 + struct ehci_hcd ehci;
912 +struct ehci_regs saved_regs;
913 +struct ccsr_usb_phy saved_phy_regs;
914 +/* Saved USB PHY settings, need to restore after deep sleep. */
918 + * store current hcd state for otg;
919 + * have_hcd is true when host drv al already part of otg framework,
921 + * hcd_add is true when otg framework wants to add host
922 + * drv as part of otg;flase when it wants to remove it
924 +unsigned have_hcd:1;
928 +static strut ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
930 +struct ehci_hcd *ehci = hcd_to_ehci(hcd);
932 +return container_of(ehci, struct ehci_fsl, ehci);
935 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
936 +static void do_change_hcd(struct work_struct *work)
938 +struct ehci_hcd *ehci = container_of(work, struct ehci_hcd,
940 +struct usb_hcd *hcd = ehci_to_hcd(ehci);
941 +struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
942 +void __iomem *non_ehci = hcd->regs;
945 +if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
946 +writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
947 +/* host, gadget and otg share same int line */
948 +retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
950 +ehci_fsl->have_hcd = 1;
951 +} else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
952 + usb_remove_hcd(hcd);
953 +ehci_fsl->have_hcd = 0;
958 /* configure so an HC device and id are always provided */
959 /* always called with process context; sleeping is OK */
960 @@ -131,6 +259,12 @@ static int fsl_ehci_drv_probe(struct pla
961 clrsetbits_be32(hcd->regs + FSL_SOC_USB_CTRL,
962 CONTROL_REGISTER_W1C_MASK, 0x4);
964 + /* Set USB_EN bit to select ULPI phy for USB controller version 2.5 */
965 + if (pdata->controller_ver == FSL_USB_VER_2_5 &&
966 + pdata->phy_mode == FSL_USB2_PHY_ULPI)
967 + iowrite32be(USB_CTRL_USB_EN, hcd->regs + FSL_SOC_USB_CTRL);
971 * Enable UTMI phy and program PTS field in UTMI mode before asserting
972 * controller reset for USB Controller version 2.5
973 @@ -143,16 +277,20 @@ static int fsl_ehci_drv_probe(struct pla
975 /* Don't need to set host mode here. It will be done by tdi_reset() */
977 - retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
978 + retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_NO_SUSPEND);
981 device_wakeup_enable(hcd->self.controller);
983 -#ifdef CONFIG_USB_OTG
984 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
985 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
986 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
987 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
989 hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2);
991 + INIT_WORK(&ehci->change_hcd_work, do_change_hcd);
993 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
994 hcd, ehci, hcd->usb_phy);
996 @@ -168,6 +306,11 @@ static int fsl_ehci_drv_probe(struct pla
1001 + ehci_fsl->have_hcd = 1;
1003 + dev_err(&pdev->dev, "wrong operating mode\n");
1008 @@ -181,6 +324,18 @@ static int fsl_ehci_drv_probe(struct pla
1012 +static bool usb_phy_clk_valid(struct usb_hcd *hcd,
1013 + enum fsl_usb2_phy_modes phy_mode)
1015 + void __iomem *non_ehci = hcd->regs;
1018 + if (!(in_be32(non_ehci + FSL_SOC_USB_CTRL) & PHY_CLK_VALID))
1024 static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
1025 enum fsl_usb2_phy_modes phy_mode,
1026 unsigned int port_offset)
1027 @@ -219,6 +374,21 @@ static int ehci_fsl_setup_phy(struct usb
1029 case FSL_USB2_PHY_UTMI:
1030 case FSL_USB2_PHY_UTMI_DUAL:
1031 + if (pdata->has_fsl_erratum_a006918) {
1032 + pr_warn("fsl-ehci: USB PHY clock invalid\n");
1036 + /* PHY_CLK_VALID bit is de-featured from all controller
1037 + * versions below 2.4 and is to be checked only for
1038 + * internal UTMI phy
1040 + if (pdata->controller_ver > FSL_USB_VER_2_4 &&
1041 + pdata->have_sysif_regs && !usb_phy_clk_valid(hcd)) {
1042 + pr_err("fsl-ehci: USB PHY clock invalid\n");
1046 if (pdata->have_sysif_regs && pdata->controller_ver) {
1047 /* controller version 1.6 or above */
1048 clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
1049 @@ -292,14 +462,9 @@ static int ehci_fsl_usb_setup(struct ehc
1052 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
1053 - unsigned int chip, rev, svr;
1055 - svr = mfspr(SPRN_SVR);
1057 - rev = (svr >> 4) & 0xf;
1059 /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
1060 - if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
1061 + if (pdata->has_fsl_erratum_14 == 1)
1062 ehci->has_fsl_port_bug = 1;
1064 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
1065 @@ -379,16 +544,57 @@ static int ehci_fsl_setup(struct usb_hcd
1070 - struct ehci_hcd ehci;
1073 - /* Saved USB PHY settings, need to restore after deep sleep. */
1077 +void __iomem *phy_reg;
1081 +/* save usb registers */
1082 +static int ehci_fsl_save_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) {
1091 + phy_reg = ioremap(FSL_USB_PHY_ADDR,
1092 + sizeof(struct ccsr_usb_phy));
1093 + _memcpy_fromio((void *)&ehci_fsl->saved_phy_regs, phy_reg,
1094 + sizeof(struct ccsr_usb_phy));
1097 + _memcpy_fromio((void *)&ehci_fsl->saved_regs, ehci->regs,
1098 + sizeof(struct ehci_regs));
1099 + ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
1104 +/*Restore usb registers */
1105 +static int ehci_fsl_restore_context(struct usb_hcd *hcd)
1107 + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1108 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1109 + void __iomem *non_ehci = hcd->regs;
1110 + struct device *dev = hcd->self.controller;
1111 + struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
1113 + if (pdata->phy_mode == FSL_USB2_PHY_UTMI_DUAL) {
1115 + _memcpy_toio(phy_reg,
1116 + (void *)&ehci_fsl->saved_phy_regs,
1117 + sizeof(struct ccsr_usb_phy));
1120 + _memcpy_toio(ehci->regs, (void *)&ehci_fsl->saved_regs,
1121 + sizeof(struct ehci_regs));
1122 + iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL);
1128 #ifdef CONFIG_PPC_MPC512x
1129 static int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
1130 @@ -535,26 +741,43 @@ static inline int ehci_fsl_mpc512x_drv_r
1132 #endif /* CONFIG_PPC_MPC512x */
1134 -static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
1136 - struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1138 - return container_of(ehci, struct ehci_fsl, ehci);
1141 static int ehci_fsl_drv_suspend(struct device *dev)
1143 struct usb_hcd *hcd = dev_get_drvdata(dev);
1144 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1145 void __iomem *non_ehci = hcd->regs;
1146 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1147 + struct usb_bus host = hcd->self;
1151 +suspend_state_t pm_state;
1152 +pm_state = pm_suspend_state();
1154 +if (pm_state == PM_SUSPEND_MEM)
1155 + ehci_fsl_save_context(hcd);
1158 if (of_device_is_compatible(dev->parent->of_node,
1159 "fsl,mpc5121-usb2-dr")) {
1160 return ehci_fsl_mpc512x_drv_suspend(dev);
1163 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1164 + if (host.is_otg) {
1165 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1168 + ehci_fsl->hcd_add = 0;
1169 + schedule_work(&ehci->change_hcd_work);
1175 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
1176 device_may_wakeup(dev));
1178 if (!fsl_deep_sleep())
1181 @@ -568,12 +791,34 @@ static int ehci_fsl_drv_resume(struct de
1182 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
1183 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1184 void __iomem *non_ehci = hcd->regs;
1185 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1186 + struct usb_bus host = hcd->self;
1190 +suspend_state_t pm_state;
1191 +pm_state = pm_suspend_state();
1193 +if (pm_state == PM_SUSPEND_MEM)
1194 + ehci_fsl_restore_context(hcd);
1197 if (of_device_is_compatible(dev->parent->of_node,
1198 "fsl,mpc5121-usb2-dr")) {
1199 return ehci_fsl_mpc512x_drv_resume(dev);
1202 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1203 + if (host.is_otg) {
1205 + ehci_fsl->hcd_add = 1;
1206 + schedule_work(&ehci->change_hcd_work);
1207 + usb_hcd_resume_root_hub(hcd);
1213 ehci_prepare_ports_for_controller_resume(ehci);
1214 if (!fsl_deep_sleep())
1216 --- a/drivers/usb/host/ehci-fsl.h
1217 +++ b/drivers/usb/host/ehci-fsl.h
1219 #define UTMI_PHY_EN (1<<9)
1220 #define ULPI_PHY_CLK_SEL (1<<10)
1221 #define PHY_CLK_VALID (1<<17)
1223 +/* Retry count for checking UTMI PHY CLK validity */
1224 +#define UTMI_PHY_CLK_VALID_CHK_RETRY 5
1225 #endif /* _EHCI_FSL_H */
1226 --- a/drivers/usb/host/ehci-hub.c
1227 +++ b/drivers/usb/host/ehci-hub.c
1228 @@ -305,6 +305,8 @@ static int ehci_bus_suspend (struct usb_
1229 USB_PORT_STAT_HIGH_SPEED)
1230 fs_idle_delay = true;
1231 ehci_writel(ehci, t2, reg);
1232 + if (ehci_has_fsl_susp_errata(ehci))
1233 + usleep_range(10000, 20000);
1237 --- a/drivers/usb/host/ehci.h
1238 +++ b/drivers/usb/host/ehci.h
1239 @@ -180,6 +180,9 @@ struct ehci_hcd { /* one per controlle
1240 unsigned periodic_count; /* periodic activity count */
1241 unsigned uframe_periodic_max; /* max periodic time per uframe */
1243 +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
1244 + struct work_struct change_hcd_work;
1247 /* list of itds & sitds completed while now_frame was still active */
1248 struct list_head cached_itd_list;
1249 @@ -706,8 +709,10 @@ ehci_port_speed(struct ehci_hcd *ehci, u
1250 * incoming packets get corrupted in HS mode
1252 #define ehci_has_fsl_hs_errata(e) ((e)->has_fsl_hs_errata)
1253 +#define ehci_has_fsl_susp_errata(e) ((e)->has_fsl_susp_errata)
1255 #define ehci_has_fsl_hs_errata(e) (0)
1256 +#define ehci_has_fsl_susp_errata(e) (0)
1260 --- a/drivers/usb/host/fsl-mph-dr-of.c
1261 +++ b/drivers/usb/host/fsl-mph-dr-of.c
1262 @@ -226,6 +226,18 @@ static int fsl_usb2_mph_dr_of_probe(stru
1263 of_property_read_bool(np, "fsl,usb-erratum-a007792");
1264 pdata->has_fsl_erratum_a005275 =
1265 of_property_read_bool(np, "fsl,usb-erratum-a005275");
1266 + pdata->has_fsl_erratum_a005697 =
1267 + of_property_read_bool(np, "fsl,usb_erratum-a005697");
1268 + if (of_get_property(np, "fsl,erratum_a006918", NULL))
1269 + pdata->has_fsl_erratum_a006918 = 1;
1271 + pdata->has_fsl_erratum_a006918 = 0;
1273 + if (of_get_property(np, "fsl,usb_erratum_14", NULL))
1274 + pdata->has_fsl_erratum_14 = 1;
1276 + pdata->has_fsl_erratum_14 = 0;
1280 * Determine whether phy_clk_valid needs to be checked
1281 --- a/drivers/usb/phy/phy-fsl-usb.c
1282 +++ b/drivers/usb/phy/phy-fsl-usb.c
1285 - * Copyright (C) 2007,2008 Freescale semiconductor, Inc.
1286 + * Copyright 2007,2008 Freescale Semiconductor, Inc.
1288 * Author: Li Yang <LeoLi@freescale.com>
1289 * Jerry Huang <Chang-Ming.Huang@freescale.com>
1290 @@ -463,6 +463,7 @@ void otg_reset_controller(void)
1291 int fsl_otg_start_host(struct otg_fsm *fsm, int on)
1293 struct usb_otg *otg = fsm->otg;
1294 + struct usb_bus *host = otg->host;
1296 struct fsl_otg *otg_dev =
1297 container_of(otg->usb_phy, struct fsl_otg, phy);
1298 @@ -486,6 +487,7 @@ int fsl_otg_start_host(struct otg_fsm *f
1299 otg_reset_controller();
1300 VDBG("host on......\n");
1301 if (dev->driver->pm && dev->driver->pm->resume) {
1303 retval = dev->driver->pm->resume(dev);
1306 @@ -510,8 +512,11 @@ int fsl_otg_start_host(struct otg_fsm *f
1308 VDBG("host off......\n");
1309 if (dev && dev->driver) {
1310 - if (dev->driver->pm && dev->driver->pm->suspend)
1311 + if (dev->driver->pm &&
1312 + dev->driver->pm->suspend) {
1314 retval = dev->driver->pm->suspend(dev);
1318 fsl_otg_drv_vbus(fsm, 0);
1319 @@ -539,8 +544,17 @@ int fsl_otg_start_gadget(struct otg_fsm
1320 dev = otg->gadget->dev.parent;
1323 - if (dev->driver->resume)
1324 + /* Delay gadget resume to synchronize between host and gadget
1325 + * drivers. Upon role-reversal host drv is shutdown by kernel
1326 + * worker thread. By the time host drv shuts down, controller
1327 + * gets programmed for gadget role. Shutting host drv after
1328 + * this results in controller getting reset, and it stops
1329 + * responding to otg events
1331 + if (dev->driver->resume) {
1333 dev->driver->resume(dev);
1336 if (dev->driver->suspend)
1337 dev->driver->suspend(dev, otg_suspend_state);
1338 @@ -672,6 +686,10 @@ static void fsl_otg_event(struct work_st
1339 fsl_otg_start_host(fsm, 0);
1340 otg_drv_vbus(fsm, 0);
1341 fsl_otg_start_gadget(fsm, 1);
1343 + fsl_otg_start_gadget(fsm, 0);
1344 + otg_drv_vbus(fsm, 1);
1345 + fsl_otg_start_host(fsm, 1);
1349 @@ -724,6 +742,7 @@ irqreturn_t fsl_otg_isr(int irq, void *d
1351 struct otg_fsm *fsm = &((struct fsl_otg *)dev_id)->fsm;
1352 struct usb_otg *otg = ((struct fsl_otg *)dev_id)->phy.otg;
1353 + struct fsl_otg *otg_dev = dev_id;
1354 u32 otg_int_src, otg_sc;
1356 otg_sc = fsl_readl(&usb_dr_regs->otgsc);
1357 @@ -753,18 +772,8 @@ irqreturn_t fsl_otg_isr(int irq, void *d
1358 otg->gadget->is_a_peripheral = !fsm->id;
1359 VDBG("ID int (ID is %d)\n", fsm->id);
1361 - if (fsm->id) { /* switch to gadget */
1362 - schedule_delayed_work(
1363 - &((struct fsl_otg *)dev_id)->otg_event,
1365 - } else { /* switch to host */
1366 - cancel_delayed_work(&
1367 - ((struct fsl_otg *)dev_id)->
1369 - fsl_otg_start_gadget(fsm, 0);
1370 - otg_drv_vbus(fsm, 1);
1371 - fsl_otg_start_host(fsm, 1);
1373 + schedule_delayed_work(&otg_dev->otg_event, 100);
1378 @@ -923,12 +932,32 @@ int usb_otg_start(struct platform_device
1379 temp &= ~(PORTSC_PHY_TYPE_SEL | PORTSC_PTW);
1380 switch (pdata->phy_mode) {
1381 case FSL_USB2_PHY_ULPI:
1382 + if (pdata->controller_ver) {
1383 + /* controller version 1.6 or above */
1384 + setbits32(&p_otg->dr_mem_map->control,
1385 + USB_CTRL_ULPI_PHY_CLK_SEL);
1387 + * Due to controller issue of PHY_CLK_VALID in ULPI
1388 + * mode, we set USB_CTRL_USB_EN before checking
1389 + * PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
1391 + clrsetbits_be32(&p_otg->dr_mem_map->control,
1392 + USB_CTRL_UTMI_PHY_EN, USB_CTRL_IOENB);
1394 temp |= PORTSC_PTS_ULPI;
1396 case FSL_USB2_PHY_UTMI_WIDE:
1397 temp |= PORTSC_PTW_16BIT;
1399 case FSL_USB2_PHY_UTMI:
1400 + if (pdata->controller_ver) {
1401 + /* controller version 1.6 or above */
1402 + setbits32(&p_otg->dr_mem_map->control,
1403 + USB_CTRL_UTMI_PHY_EN);
1404 + /* Delay for UTMI PHY CLK to become stable - 10ms */
1405 + mdelay(FSL_UTMI_PHY_DLY);
1407 + setbits32(&p_otg->dr_mem_map->control, USB_CTRL_UTMI_PHY_EN);
1408 temp |= PORTSC_PTS_UTMI;
1411 --- a/drivers/usb/phy/phy-fsl-usb.h
1412 +++ b/drivers/usb/phy/phy-fsl-usb.h
1413 @@ -199,6 +199,14 @@
1414 /* control Register Bit Masks */
1415 #define USB_CTRL_IOENB (0x1<<2)
1416 #define USB_CTRL_ULPI_INT0EN (0x1<<0)
1417 +#define USB_CTRL_WU_INT_EN (0x1<<1)
1418 +#define USB_CTRL_LINE_STATE_FILTER__EN (0x1<<3)
1419 +#define USB_CTRL_KEEP_OTG_ON (0x1<<4)
1420 +#define USB_CTRL_OTG_PORT (0x1<<5)
1421 +#define USB_CTRL_PLL_RESET (0x1<<8)
1422 +#define USB_CTRL_UTMI_PHY_EN (0x1<<9)
1423 +#define USB_CTRL_ULPI_PHY_CLK_SEL (0x1<<10)
1424 +#define USB_CTRL_PHY_CLK_VALID (0x1<<17)
1427 #define BCSR5_INT_USB (0x02)
1428 --- a/include/linux/usb.h
1429 +++ b/include/linux/usb.h
1430 @@ -362,6 +362,7 @@ struct usb_bus {
1431 * for control transfers?
1433 u8 otg_port; /* 0, or number of OTG/HNP port */
1434 + unsigned is_otg:1; /* true when host is also otg */
1435 unsigned is_b_host:1; /* true during some HNP roleswitches */
1436 unsigned b_hnp_enable:1; /* OTG: did A-Host enable HNP? */
1437 unsigned no_stop_on_short:1; /*
1438 --- a/include/linux/usb/of.h
1439 +++ b/include/linux/usb/of.h
1441 #include <linux/usb/otg.h>
1442 #include <linux/usb/phy.h>
1444 +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
1446 #if IS_ENABLED(CONFIG_OF)
1447 enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0);
1448 bool of_usb_host_tpl_support(struct device_node *np);