2
0

807-usb-support-layerscape.patch 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  1. From 01b1b2989e907305d8b885468c2743f5e35e1b9a Mon Sep 17 00:00:00 2001
  2. From: Biwen Li <[email protected]>
  3. Date: Thu, 13 Dec 2018 11:15:15 +0800
  4. Subject: [PATCH] usb: support layerscape
  5. This is an integrated patch of usb for layerscape
  6. Signed-off-by: Catalin Marinas <[email protected]>
  7. Signed-off-by: Changming Huang <[email protected]>
  8. Signed-off-by: Felipe Balbi <[email protected]>
  9. Signed-off-by: Li Yang <[email protected]>
  10. Signed-off-by: Nikhil Badola <[email protected]>
  11. Signed-off-by: Rajesh Bhagat <[email protected]>
  12. Signed-off-by: Ramneek Mehresh <[email protected]>
  13. Signed-off-by: Ran Wang <[email protected]>
  14. Signed-off-by: Roger Quadros <[email protected]>
  15. Signed-off-by: Shengzhou Liu <[email protected]>
  16. Signed-off-by: Suresh Gupta <[email protected]>
  17. Signed-off-by: yinbo.zhu <[email protected]>
  18. Signed-off-by: Zhao Chenhui <[email protected]>
  19. Signed-off-by: Biwen Li <[email protected]>
  20. Signed-off-by: Yangbo Lu <[email protected]>
  21. ---
  22. .../devicetree/bindings/usb/dwc3.txt | 2 +
  23. arch/arm64/include/asm/io.h | 28 ++
  24. drivers/usb/common/common.c | 50 ++++
  25. drivers/usb/core/usb.c | 1 +
  26. drivers/usb/dwc3/core.c | 104 +++++++
  27. drivers/usb/dwc3/core.h | 44 +++
  28. drivers/usb/dwc3/ep0.c | 4 +-
  29. drivers/usb/dwc3/gadget.c | 7 +
  30. drivers/usb/dwc3/host.c | 9 +
  31. drivers/usb/gadget/udc/fsl_udc_core.c | 46 +--
  32. drivers/usb/gadget/udc/fsl_usb2_udc.h | 16 +-
  33. drivers/usb/host/Kconfig | 2 +-
  34. drivers/usb/host/ehci-fsl.c | 276 ++++++++++++++++--
  35. drivers/usb/host/ehci-fsl.h | 3 +
  36. drivers/usb/host/ehci-hub.c | 2 +
  37. drivers/usb/host/ehci.h | 3 +
  38. drivers/usb/host/fsl-mph-dr-of.c | 11 +
  39. drivers/usb/host/xhci-hub.c | 22 ++
  40. drivers/usb/host/xhci-plat.c | 16 +-
  41. drivers/usb/host/xhci-ring.c | 28 +-
  42. drivers/usb/host/xhci.c | 39 ++-
  43. drivers/usb/host/xhci.h | 6 +-
  44. drivers/usb/phy/phy-fsl-usb.c | 59 +++-
  45. drivers/usb/phy/phy-fsl-usb.h | 8 +
  46. include/linux/usb.h | 1 +
  47. include/linux/usb/of.h | 2 +
  48. 26 files changed, 704 insertions(+), 85 deletions(-)
  49. --- a/Documentation/devicetree/bindings/usb/dwc3.txt
  50. +++ b/Documentation/devicetree/bindings/usb/dwc3.txt
  51. @@ -47,6 +47,8 @@ Optional properties:
  52. from P0 to P1/P2/P3 without delay.
  53. - snps,dis-tx-ipgap-linecheck-quirk: when set, disable u2mac linestate check
  54. during HS transmit.
  55. + - snps,disable_devinit_u1u2: when set, disable device-initiated U1/U2
  56. + LPM request in USB device mode.
  57. - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal
  58. utmi_l1_suspend_n, false when asserts utmi_sleep_n
  59. - snps,hird-threshold: HIRD threshold
  60. --- a/arch/arm64/include/asm/io.h
  61. +++ b/arch/arm64/include/asm/io.h
  62. @@ -210,6 +210,34 @@ extern void __iomem *ioremap_cache(phys_
  63. #define iowrite32be(v,p) ({ __iowmb(); __raw_writel((__force __u32)cpu_to_be32(v), p); })
  64. #define iowrite64be(v,p) ({ __iowmb(); __raw_writeq((__force __u64)cpu_to_be64(v), p); })
  65. +/* access ports */
  66. +#define setbits32(_addr, _v) iowrite32be(ioread32be(_addr) | (_v), (_addr))
  67. +#define clrbits32(_addr, _v) iowrite32be(ioread32be(_addr) & ~(_v), (_addr))
  68. +
  69. +#define setbits16(_addr, _v) iowrite16be(ioread16be(_addr) | (_v), (_addr))
  70. +#define clrbits16(_addr, _v) iowrite16be(ioread16be(_addr) & ~(_v), (_addr))
  71. +
  72. +#define setbits8(_addr, _v) iowrite8(ioread8(_addr) | (_v), (_addr))
  73. +#define clrbits8(_addr, _v) iowrite8(ioread8(_addr) & ~(_v), (_addr))
  74. +
  75. +/* Clear and set bits in one shot. These macros can be used to clear and
  76. + * set multiple bits in a register using a single read-modify-write. These
  77. + * macros can also be used to set a multiple-bit bit pattern using a mask,
  78. + * by specifying the mask in the 'clear' parameter and the new bit pattern
  79. + * in the 'set' parameter.
  80. + */
  81. +
  82. +#define clrsetbits_be32(addr, clear, set) \
  83. + iowrite32be((ioread32be(addr) & ~(clear)) | (set), (addr))
  84. +#define clrsetbits_le32(addr, clear, set) \
  85. + iowrite32le((ioread32le(addr) & ~(clear)) | (set), (addr))
  86. +#define clrsetbits_be16(addr, clear, set) \
  87. + iowrite16be((ioread16be(addr) & ~(clear)) | (set), (addr))
  88. +#define clrsetbits_le16(addr, clear, set) \
  89. + iowrite16le((ioread16le(addr) & ~(clear)) | (set), (addr))
  90. +#define clrsetbits_8(addr, clear, set) \
  91. + iowrite8((ioread8(addr) & ~(clear)) | (set), (addr))
  92. +
  93. #include <asm-generic/io.h>
  94. /*
  95. --- a/drivers/usb/common/common.c
  96. +++ b/drivers/usb/common/common.c
  97. @@ -105,6 +105,56 @@ static const char *const usb_dr_modes[]
  98. [USB_DR_MODE_OTG] = "otg",
  99. };
  100. +/**
  101. + * of_usb_get_dr_mode - Get dual role mode for given device_node
  102. + * @np: Pointer to the given device_node
  103. + *
  104. + * The function gets phy interface string from property 'dr_mode',
  105. + * and returns the correspondig enum usb_dr_mode
  106. + */
  107. +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
  108. +{
  109. + const char *dr_mode;
  110. + int err, i;
  111. +
  112. + err = of_property_read_string(np, "dr_mode", &dr_mode);
  113. + if (err < 0)
  114. + return USB_DR_MODE_UNKNOWN;
  115. +
  116. + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
  117. + if (!strcmp(dr_mode, usb_dr_modes[i]))
  118. + return i;
  119. +
  120. + return USB_DR_MODE_UNKNOWN;
  121. +}
  122. +EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
  123. +
  124. +/**
  125. + * of_usb_get_maximum_speed - Get maximum requested speed for a given USB
  126. + * controller.
  127. + * @np: Pointer to the given device_node
  128. + *
  129. + * The function gets the maximum speed string from property "maximum-speed",
  130. + * and returns the corresponding enum usb_device_speed.
  131. + */
  132. +enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np)
  133. +{
  134. + const char *maximum_speed;
  135. + int err;
  136. + int i;
  137. +
  138. + err = of_property_read_string(np, "maximum-speed", &maximum_speed);
  139. + if (err < 0)
  140. + return USB_SPEED_UNKNOWN;
  141. +
  142. + for (i = 0; i < ARRAY_SIZE(speed_names); i++)
  143. + if (strcmp(maximum_speed, speed_names[i]) == 0)
  144. + return i;
  145. +
  146. + return USB_SPEED_UNKNOWN;
  147. +}
  148. +EXPORT_SYMBOL_GPL(of_usb_get_maximum_speed);
  149. +
  150. static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
  151. {
  152. int ret;
  153. --- a/drivers/usb/core/usb.c
  154. +++ b/drivers/usb/core/usb.c
  155. @@ -593,6 +593,7 @@ struct usb_device *usb_alloc_dev(struct
  156. dev->dev.dma_mask = bus->sysdev->dma_mask;
  157. dev->dev.dma_pfn_offset = bus->sysdev->dma_pfn_offset;
  158. set_dev_node(&dev->dev, dev_to_node(bus->sysdev));
  159. + dev->dev.of_node = bus->controller->of_node;
  160. dev->state = USB_STATE_ATTACHED;
  161. dev->lpm_disable_count = 1;
  162. atomic_set(&dev->urbnum, 0);
  163. --- a/drivers/usb/dwc3/core.c
  164. +++ b/drivers/usb/dwc3/core.c
  165. @@ -766,6 +766,96 @@ static void dwc3_core_setup_global_contr
  166. static int dwc3_core_get_phy(struct dwc3 *dwc);
  167. static int dwc3_core_ulpi_init(struct dwc3 *dwc);
  168. +/* set global soc bus configuration registers */
  169. +static void dwc3_set_soc_bus_cfg(struct dwc3 *dwc)
  170. +{
  171. + struct device *dev = dwc->dev;
  172. + u32 *vals;
  173. + u32 cfg;
  174. + int ntype;
  175. + int ret;
  176. + int i;
  177. +
  178. + cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0);
  179. +
  180. + /*
  181. + * Handle property "snps,incr-burst-type-adjustment".
  182. + * Get the number of value from this property:
  183. + * result <= 0, means this property is not supported.
  184. + * result = 1, means INCRx burst mode supported.
  185. + * result > 1, means undefined length burst mode supported.
  186. + */
  187. + ntype = device_property_read_u32_array(dev,
  188. + "snps,incr-burst-type-adjustment", NULL, 0);
  189. + if (ntype > 0) {
  190. + vals = kcalloc(ntype, sizeof(u32), GFP_KERNEL);
  191. + if (!vals) {
  192. + dev_err(dev, "Error to get memory\n");
  193. + return;
  194. + }
  195. + /* Get INCR burst type, and parse it */
  196. + ret = device_property_read_u32_array(dev,
  197. + "snps,incr-burst-type-adjustment", vals, ntype);
  198. + if (ret) {
  199. + dev_err(dev, "Error to get property\n");
  200. + return;
  201. + }
  202. + *(dwc->incrx_type + 1) = vals[0];
  203. + if (ntype > 1) {
  204. + *dwc->incrx_type = 1;
  205. + for (i = 1; i < ntype; i++) {
  206. + if (vals[i] > *(dwc->incrx_type + 1))
  207. + *(dwc->incrx_type + 1) = vals[i];
  208. + }
  209. + } else
  210. + *dwc->incrx_type = 0;
  211. +
  212. + /* Enable Undefined Length INCR Burst and Enable INCRx Burst */
  213. + cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK;
  214. + if (*dwc->incrx_type)
  215. + cfg |= DWC3_GSBUSCFG0_INCRBRSTENA;
  216. + switch (*(dwc->incrx_type + 1)) {
  217. + case 256:
  218. + cfg |= DWC3_GSBUSCFG0_INCR256BRSTENA;
  219. + break;
  220. + case 128:
  221. + cfg |= DWC3_GSBUSCFG0_INCR128BRSTENA;
  222. + break;
  223. + case 64:
  224. + cfg |= DWC3_GSBUSCFG0_INCR64BRSTENA;
  225. + break;
  226. + case 32:
  227. + cfg |= DWC3_GSBUSCFG0_INCR32BRSTENA;
  228. + break;
  229. + case 16:
  230. + cfg |= DWC3_GSBUSCFG0_INCR16BRSTENA;
  231. + break;
  232. + case 8:
  233. + cfg |= DWC3_GSBUSCFG0_INCR8BRSTENA;
  234. + break;
  235. + case 4:
  236. + cfg |= DWC3_GSBUSCFG0_INCR4BRSTENA;
  237. + break;
  238. + case 1:
  239. + break;
  240. + default:
  241. + dev_err(dev, "Invalid property\n");
  242. + break;
  243. + }
  244. + }
  245. +
  246. + /* Handle usb snooping */
  247. + if (dwc->dma_coherent) {
  248. + cfg &= ~DWC3_GSBUSCFG0_SNP_MASK;
  249. + cfg |= (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DATARD_SHIFT) |
  250. + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DESCRD_SHIFT) |
  251. + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DATAWR_SHIFT) |
  252. + (AXI3_CACHE_TYPE_SNP << DWC3_GSBUSCFG0_DESCWR_SHIFT);
  253. + }
  254. +
  255. + dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg);
  256. +}
  257. +
  258. /**
  259. * dwc3_core_init - Low-level initialization of DWC3 Core
  260. * @dwc: Pointer to our controller context structure
  261. @@ -828,6 +918,8 @@ static int dwc3_core_init(struct dwc3 *d
  262. /* Adjust Frame Length */
  263. dwc3_frame_length_adjustment(dwc);
  264. + dwc3_set_soc_bus_cfg(dwc);
  265. +
  266. usb_phy_set_suspend(dwc->usb2_phy, 0);
  267. usb_phy_set_suspend(dwc->usb3_phy, 0);
  268. ret = phy_power_on(dwc->usb2_generic_phy);
  269. @@ -1074,6 +1166,8 @@ static void dwc3_get_properties(struct d
  270. &hird_threshold);
  271. dwc->usb3_lpm_capable = device_property_read_bool(dev,
  272. "snps,usb3_lpm_capable");
  273. + dwc->dma_coherent = device_property_read_bool(dev,
  274. + "dma-coherent");
  275. dwc->disable_scramble_quirk = device_property_read_bool(dev,
  276. "snps,disable_scramble_quirk");
  277. @@ -1106,8 +1200,16 @@ static void dwc3_get_properties(struct d
  278. dwc->dis_tx_ipgap_linecheck_quirk = device_property_read_bool(dev,
  279. "snps,dis-tx-ipgap-linecheck-quirk");
  280. + dwc->quirk_reverse_in_out = device_property_read_bool(dev,
  281. + "snps,quirk_reverse_in_out");
  282. + dwc->quirk_stop_transfer_in_block = device_property_read_bool(dev,
  283. + "snps,quirk_stop_transfer_in_block");
  284. + dwc->quirk_stop_ep_in_u1 = device_property_read_bool(dev,
  285. + "snps,quirk_stop_ep_in_u1");
  286. dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
  287. "snps,tx_de_emphasis_quirk");
  288. + dwc->disable_devinit_u1u2_quirk = device_property_read_bool(dev,
  289. + "snps,disable_devinit_u1u2");
  290. device_property_read_u8(dev, "snps,tx_de_emphasis",
  291. &tx_de_emphasis);
  292. device_property_read_string(dev, "snps,hsphy_interface",
  293. @@ -1365,12 +1467,14 @@ static int dwc3_resume_common(struct dwc
  294. switch (dwc->dr_mode) {
  295. case USB_DR_MODE_PERIPHERAL:
  296. + dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
  297. case USB_DR_MODE_OTG:
  298. spin_lock_irqsave(&dwc->lock, flags);
  299. dwc3_gadget_resume(dwc);
  300. spin_unlock_irqrestore(&dwc->lock, flags);
  301. /* FALLTHROUGH */
  302. case USB_DR_MODE_HOST:
  303. + dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
  304. default:
  305. /* do nothing */
  306. break;
  307. --- a/drivers/usb/dwc3/core.h
  308. +++ b/drivers/usb/dwc3/core.h
  309. @@ -161,6 +161,32 @@
  310. /* Bit fields */
  311. +/* Global SoC Bus Configuration Register 0 */
  312. +#define AXI3_CACHE_TYPE_AW 0x8 /* write allocate */
  313. +#define AXI3_CACHE_TYPE_AR 0x4 /* read allocate */
  314. +#define AXI3_CACHE_TYPE_SNP 0x2 /* cacheable */
  315. +#define AXI3_CACHE_TYPE_BUF 0x1 /* bufferable */
  316. +#define DWC3_GSBUSCFG0_DATARD_SHIFT 28
  317. +#define DWC3_GSBUSCFG0_DESCRD_SHIFT 24
  318. +#define DWC3_GSBUSCFG0_DATAWR_SHIFT 20
  319. +#define DWC3_GSBUSCFG0_DESCWR_SHIFT 16
  320. +#define DWC3_GSBUSCFG0_SNP_MASK 0xffff0000
  321. +#define DWC3_GSBUSCFG0_DATABIGEND (1 << 11)
  322. +#define DWC3_GSBUSCFG0_DESCBIGEND (1 << 10)
  323. +#define DWC3_GSBUSCFG0_INCR256BRSTENA (1 << 7) /* INCR256 burst */
  324. +#define DWC3_GSBUSCFG0_INCR128BRSTENA (1 << 6) /* INCR128 burst */
  325. +#define DWC3_GSBUSCFG0_INCR64BRSTENA (1 << 5) /* INCR64 burst */
  326. +#define DWC3_GSBUSCFG0_INCR32BRSTENA (1 << 4) /* INCR32 burst */
  327. +#define DWC3_GSBUSCFG0_INCR16BRSTENA (1 << 3) /* INCR16 burst */
  328. +#define DWC3_GSBUSCFG0_INCR8BRSTENA (1 << 2) /* INCR8 burst */
  329. +#define DWC3_GSBUSCFG0_INCR4BRSTENA (1 << 1) /* INCR4 burst */
  330. +#define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0) /* undefined length enable */
  331. +#define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff
  332. +
  333. +/* Global SoC Bus Configuration Register 1 */
  334. +#define DWC3_GSBUSCFG1_1KPAGEENA (1 << 12) /* 1K page boundary enable */
  335. +#define DWC3_GSBUSCFG1_PTRANSLIMIT_MASK 0xf00
  336. +
  337. /* Global Debug Queue/FIFO Space Available Register */
  338. #define DWC3_GDBGFIFOSPACE_NUM(n) ((n) & 0x1f)
  339. #define DWC3_GDBGFIFOSPACE_TYPE(n) (((n) << 5) & 0x1e0)
  340. @@ -788,6 +814,7 @@ struct dwc3_scratchpad_array {
  341. * @regs: base address for our registers
  342. * @regs_size: address space size
  343. * @fladj: frame length adjustment
  344. + * @incrx_type: INCR burst type adjustment
  345. * @irq_gadget: peripheral controller's IRQ number
  346. * @nr_scratch: number of scratch buffers
  347. * @u1u2: only used on revisions <1.83a for workaround
  348. @@ -843,6 +870,7 @@ struct dwc3_scratchpad_array {
  349. * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
  350. * @three_stage_setup: set if we perform a three phase setup
  351. * @usb3_lpm_capable: set if hadrware supports Link Power Management
  352. + * @dma_coherent: set if hadrware supports DMA snoop
  353. * @disable_scramble_quirk: set if we enable the disable scramble quirk
  354. * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
  355. * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
  356. @@ -869,6 +897,11 @@ struct dwc3_scratchpad_array {
  357. * 1 - -3.5dB de-emphasis
  358. * 2 - No de-emphasis
  359. * 3 - Reserved
  360. + * @disable_devinit_u1u2_quirk: disable device-initiated U1/U2 request.
  361. + * @quirk_reverse_in_out: prevent tx fifo reverse the data direction
  362. + * @quirk_stop_transfer_in_block: prevent block transmission from being
  363. + * interrupted
  364. + * @quirk_stop_ep_in_u1: replace stop commad with disable slot command
  365. * @imod_interval: set the interrupt moderation interval in 250ns
  366. * increments or 0 to disable.
  367. */
  368. @@ -921,6 +954,12 @@ struct dwc3 {
  369. enum usb_phy_interface hsphy_mode;
  370. u32 fladj;
  371. + /*
  372. + * For INCR burst type.
  373. + * First field: for undefined length INCR burst type enable.
  374. + * Second field: for INCRx burst type enable
  375. + */
  376. + u32 incrx_type[2];
  377. u32 irq_gadget;
  378. u32 nr_scratch;
  379. u32 u1u2;
  380. @@ -1005,6 +1044,7 @@ struct dwc3 {
  381. unsigned setup_packet_pending:1;
  382. unsigned three_stage_setup:1;
  383. unsigned usb3_lpm_capable:1;
  384. + unsigned dma_coherent:1;
  385. unsigned disable_scramble_quirk:1;
  386. unsigned u2exit_lfps_quirk:1;
  387. @@ -1024,6 +1064,10 @@ struct dwc3 {
  388. unsigned tx_de_emphasis_quirk:1;
  389. unsigned tx_de_emphasis:2;
  390. + unsigned disable_devinit_u1u2_quirk:1;
  391. + unsigned quirk_reverse_in_out:1;
  392. + unsigned quirk_stop_transfer_in_block:1;
  393. + unsigned quirk_stop_ep_in_u1:1;
  394. u16 imod_interval;
  395. };
  396. --- a/drivers/usb/dwc3/ep0.c
  397. +++ b/drivers/usb/dwc3/ep0.c
  398. @@ -391,7 +391,7 @@ static int dwc3_ep0_handle_u1(struct dwc
  399. return -EINVAL;
  400. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  401. - if (set)
  402. + if (set && !dwc->disable_devinit_u1u2_quirk)
  403. reg |= DWC3_DCTL_INITU1ENA;
  404. else
  405. reg &= ~DWC3_DCTL_INITU1ENA;
  406. @@ -413,7 +413,7 @@ static int dwc3_ep0_handle_u2(struct dwc
  407. return -EINVAL;
  408. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  409. - if (set)
  410. + if (set && !dwc->disable_devinit_u1u2_quirk)
  411. reg |= DWC3_DCTL_INITU2ENA;
  412. else
  413. reg &= ~DWC3_DCTL_INITU2ENA;
  414. --- a/drivers/usb/dwc3/gadget.c
  415. +++ b/drivers/usb/dwc3/gadget.c
  416. @@ -3210,6 +3210,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
  417. {
  418. int ret;
  419. int irq;
  420. + u32 reg;
  421. irq = dwc3_gadget_get_irq(dwc);
  422. if (irq < 0) {
  423. @@ -3288,6 +3289,12 @@ int dwc3_gadget_init(struct dwc3 *dwc)
  424. dwc3_gadget_set_speed(&dwc->gadget, dwc->maximum_speed);
  425. + if (dwc->disable_devinit_u1u2_quirk) {
  426. + reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  427. + reg &= ~(DWC3_DCTL_INITU1ENA | DWC3_DCTL_INITU2ENA);
  428. + dwc3_writel(dwc->regs, DWC3_DCTL, reg);
  429. + }
  430. +
  431. return 0;
  432. err4:
  433. --- a/drivers/usb/dwc3/host.c
  434. +++ b/drivers/usb/dwc3/host.c
  435. @@ -98,6 +98,15 @@ int dwc3_host_init(struct dwc3 *dwc)
  436. memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props));
  437. + if (dwc->quirk_reverse_in_out)
  438. + props[prop_idx++].name = "quirk-reverse-in-out";
  439. +
  440. + if (dwc->quirk_stop_transfer_in_block)
  441. + props[prop_idx++].name = "quirk-stop-transfer-in-block";
  442. +
  443. + if (dwc->quirk_stop_ep_in_u1)
  444. + props[prop_idx++].name = "quirk-stop-ep-in-u1";
  445. +
  446. if (dwc->usb3_lpm_capable)
  447. props[prop_idx++].name = "usb3-lpm-capable";
  448. --- a/drivers/usb/gadget/udc/fsl_udc_core.c
  449. +++ b/drivers/usb/gadget/udc/fsl_udc_core.c
  450. @@ -198,7 +198,11 @@ __acquires(ep->udc->lock)
  451. spin_unlock(&ep->udc->lock);
  452. - usb_gadget_giveback_request(&ep->ep, &req->req);
  453. + /* this complete() should a func implemented by gadget layer,
  454. + * eg fsg->bulk_in_complete()
  455. + */
  456. + if (req->req.complete)
  457. + usb_gadget_giveback_request(&ep->ep, &req->req);
  458. spin_lock(&ep->udc->lock);
  459. ep->stopped = stopped;
  460. @@ -245,10 +249,10 @@ static int dr_controller_setup(struct fs
  461. if (udc->pdata->have_sysif_regs) {
  462. if (udc->pdata->controller_ver) {
  463. /* controller version 1.6 or above */
  464. - ctrl = __raw_readl(&usb_sys_regs->control);
  465. + ctrl = ioread32be(&usb_sys_regs->control);
  466. ctrl &= ~USB_CTRL_UTMI_PHY_EN;
  467. ctrl |= USB_CTRL_USB_EN;
  468. - __raw_writel(ctrl, &usb_sys_regs->control);
  469. + iowrite32be(ctrl, &usb_sys_regs->control);
  470. }
  471. }
  472. portctrl |= PORTSCX_PTS_ULPI;
  473. @@ -257,13 +261,14 @@ static int dr_controller_setup(struct fs
  474. portctrl |= PORTSCX_PTW_16BIT;
  475. /* fall through */
  476. case FSL_USB2_PHY_UTMI:
  477. + case FSL_USB2_PHY_UTMI_DUAL:
  478. if (udc->pdata->have_sysif_regs) {
  479. if (udc->pdata->controller_ver) {
  480. /* controller version 1.6 or above */
  481. - ctrl = __raw_readl(&usb_sys_regs->control);
  482. + ctrl = ioread32be(&usb_sys_regs->control);
  483. ctrl |= (USB_CTRL_UTMI_PHY_EN |
  484. USB_CTRL_USB_EN);
  485. - __raw_writel(ctrl, &usb_sys_regs->control);
  486. + iowrite32be(ctrl, &usb_sys_regs->control);
  487. mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI
  488. PHY CLK to become stable - 10ms*/
  489. }
  490. @@ -329,22 +334,22 @@ static int dr_controller_setup(struct fs
  491. /* Config control enable i/o output, cpu endian register */
  492. #ifndef CONFIG_ARCH_MXC
  493. if (udc->pdata->have_sysif_regs) {
  494. - ctrl = __raw_readl(&usb_sys_regs->control);
  495. + ctrl = ioread32be(&usb_sys_regs->control);
  496. ctrl |= USB_CTRL_IOENB;
  497. - __raw_writel(ctrl, &usb_sys_regs->control);
  498. + iowrite32be(ctrl, &usb_sys_regs->control);
  499. }
  500. #endif
  501. -#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
  502. +#if !defined(CONFIG_NOT_COHERENT_CACHE)
  503. /* Turn on cache snooping hardware, since some PowerPC platforms
  504. * wholly rely on hardware to deal with cache coherent. */
  505. if (udc->pdata->have_sysif_regs) {
  506. /* Setup Snooping for all the 4GB space */
  507. tmp = SNOOP_SIZE_2GB; /* starts from 0x0, size 2G */
  508. - __raw_writel(tmp, &usb_sys_regs->snoop1);
  509. + iowrite32be(tmp, &usb_sys_regs->snoop1);
  510. tmp |= 0x80000000; /* starts from 0x8000000, size 2G */
  511. - __raw_writel(tmp, &usb_sys_regs->snoop2);
  512. + iowrite32be(tmp, &usb_sys_regs->snoop2);
  513. }
  514. #endif
  515. @@ -1056,7 +1061,7 @@ static int fsl_ep_fifo_status(struct usb
  516. struct ep_queue_head *qh;
  517. ep = container_of(_ep, struct fsl_ep, ep);
  518. - if (!_ep || (!ep->ep.desc && ep_index(ep) != 0))
  519. + if (!_ep || !ep->ep.desc || (ep_index(ep) == 0))
  520. return -ENODEV;
  521. udc = (struct fsl_udc *)ep->udc;
  522. @@ -1598,14 +1603,13 @@ static int process_ep_req(struct fsl_udc
  523. struct fsl_req *curr_req)
  524. {
  525. struct ep_td_struct *curr_td;
  526. - int td_complete, actual, remaining_length, j, tmp;
  527. + int actual, remaining_length, j, tmp;
  528. int status = 0;
  529. int errors = 0;
  530. struct ep_queue_head *curr_qh = &udc->ep_qh[pipe];
  531. int direction = pipe % 2;
  532. curr_td = curr_req->head;
  533. - td_complete = 0;
  534. actual = curr_req->req.length;
  535. for (j = 0; j < curr_req->dtd_count; j++) {
  536. @@ -1650,11 +1654,9 @@ static int process_ep_req(struct fsl_udc
  537. status = -EPROTO;
  538. break;
  539. } else {
  540. - td_complete++;
  541. break;
  542. }
  543. } else {
  544. - td_complete++;
  545. VDBG("dTD transmitted successful");
  546. }
  547. @@ -1697,7 +1699,7 @@ static void dtd_complete_irq(struct fsl_
  548. curr_ep = get_ep_by_pipe(udc, i);
  549. /* If the ep is configured */
  550. - if (!curr_ep->ep.name) {
  551. + if (strncmp(curr_ep->name, "ep", 2)) {
  552. WARNING("Invalid EP?");
  553. continue;
  554. }
  555. @@ -2419,10 +2421,12 @@ static int fsl_udc_probe(struct platform
  556. usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
  557. #endif
  558. +#ifdef CONFIG_ARCH_MXC
  559. /* Initialize USB clocks */
  560. ret = fsl_udc_clk_init(pdev);
  561. if (ret < 0)
  562. goto err_iounmap_noclk;
  563. +#endif
  564. /* Read Device Controller Capability Parameters register */
  565. dccparams = fsl_readl(&dr_regs->dccparams);
  566. @@ -2462,9 +2466,11 @@ static int fsl_udc_probe(struct platform
  567. dr_controller_setup(udc_controller);
  568. }
  569. +#ifdef CONFIG_ARCH_MXC
  570. ret = fsl_udc_clk_finalize(pdev);
  571. if (ret)
  572. goto err_free_irq;
  573. +#endif
  574. /* Setup gadget structure */
  575. udc_controller->gadget.ops = &fsl_gadget_ops;
  576. @@ -2477,6 +2483,7 @@ static int fsl_udc_probe(struct platform
  577. /* Setup gadget.dev and register with kernel */
  578. dev_set_name(&udc_controller->gadget.dev, "gadget");
  579. udc_controller->gadget.dev.of_node = pdev->dev.of_node;
  580. + set_dma_ops(&udc_controller->gadget.dev, pdev->dev.dma_ops);
  581. if (!IS_ERR_OR_NULL(udc_controller->transceiver))
  582. udc_controller->gadget.is_otg = 1;
  583. @@ -2528,7 +2535,9 @@ err_free_irq:
  584. err_iounmap:
  585. if (pdata->exit)
  586. pdata->exit(pdev);
  587. +#ifdef CONFIG_ARCH_MXC
  588. fsl_udc_clk_release();
  589. +#endif
  590. err_iounmap_noclk:
  591. iounmap(dr_regs);
  592. err_release_mem_region:
  593. @@ -2556,8 +2565,9 @@ static int fsl_udc_remove(struct platfor
  594. udc_controller->done = &done;
  595. usb_del_gadget_udc(&udc_controller->gadget);
  596. +#ifdef CONFIG_ARCH_MXC
  597. fsl_udc_clk_release();
  598. -
  599. +#endif
  600. /* DR has been stopped in usb_gadget_unregister_driver() */
  601. remove_proc_file();
  602. @@ -2569,7 +2579,7 @@ static int fsl_udc_remove(struct platfor
  603. dma_pool_destroy(udc_controller->td_pool);
  604. free_irq(udc_controller->irq, udc_controller);
  605. iounmap(dr_regs);
  606. - if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
  607. + if (res && (pdata->operating_mode == FSL_USB2_DR_DEVICE))
  608. release_mem_region(res->start, resource_size(res));
  609. /* free udc --wait for the release() finished */
  610. --- a/drivers/usb/gadget/udc/fsl_usb2_udc.h
  611. +++ b/drivers/usb/gadget/udc/fsl_usb2_udc.h
  612. @@ -20,6 +20,10 @@
  613. #define USB_MAX_CTRL_PAYLOAD 64
  614. #define USB_DR_SYS_OFFSET 0x400
  615. +#ifdef CONFIG_SOC_LS1021A
  616. +#undef CONFIG_ARCH_MXC
  617. +#endif
  618. +
  619. /* USB DR device mode registers (Little Endian) */
  620. struct usb_dr_device {
  621. /* Capability register */
  622. @@ -597,18 +601,6 @@ struct platform_device;
  623. int fsl_udc_clk_init(struct platform_device *pdev);
  624. int fsl_udc_clk_finalize(struct platform_device *pdev);
  625. void fsl_udc_clk_release(void);
  626. -#else
  627. -static inline int fsl_udc_clk_init(struct platform_device *pdev)
  628. -{
  629. - return 0;
  630. -}
  631. -static inline int fsl_udc_clk_finalize(struct platform_device *pdev)
  632. -{
  633. - return 0;
  634. -}
  635. -static inline void fsl_udc_clk_release(void)
  636. -{
  637. -}
  638. #endif
  639. #endif
  640. --- a/drivers/usb/host/Kconfig
  641. +++ b/drivers/usb/host/Kconfig
  642. @@ -165,7 +165,7 @@ config XPS_USB_HCD_XILINX
  643. config USB_EHCI_FSL
  644. tristate "Support for Freescale PPC on-chip EHCI USB controller"
  645. - depends on FSL_SOC
  646. + depends on USB_EHCI_HCD
  647. select USB_EHCI_ROOT_HUB_TT
  648. ---help---
  649. Variation of ARC USB block used in some Freescale chips.
  650. --- a/drivers/usb/host/ehci-fsl.c
  651. +++ b/drivers/usb/host/ehci-fsl.c
  652. @@ -36,15 +36,126 @@
  653. #include <linux/platform_device.h>
  654. #include <linux/fsl_devices.h>
  655. #include <linux/of_platform.h>
  656. +#include <linux/io.h>
  657. +
  658. +#ifdef CONFIG_PM
  659. +#include <linux/suspend.h>
  660. +#endif
  661. #include "ehci.h"
  662. #include "ehci-fsl.h"
  663. +#define FSL_USB_PHY_ADDR 0xffe214000
  664. +
  665. +struct ccsr_usb_port_ctrl {
  666. + u32 ctrl;
  667. + u32 drvvbuscfg;
  668. + u32 pwrfltcfg;
  669. + u32 sts;
  670. + u8 res_14[0xc];
  671. + u32 bistcfg;
  672. + u32 biststs;
  673. + u32 abistcfg;
  674. + u32 abiststs;
  675. + u8 res_30[0x10];
  676. + u32 xcvrprg;
  677. + u32 anaprg;
  678. + u32 anadrv;
  679. + u32 anasts;
  680. +};
  681. +
  682. +struct ccsr_usb_phy {
  683. + u32 id;
  684. + struct ccsr_usb_port_ctrl port1;
  685. + u8 res_50[0xc];
  686. + u32 tvr;
  687. + u32 pllprg[4];
  688. + u8 res_70[0x4];
  689. + u32 anaccfg;
  690. + u32 dbg;
  691. + u8 res_7c[0x4];
  692. + struct ccsr_usb_port_ctrl port2;
  693. + u8 res_dc[0x334];
  694. +};
  695. +
  696. #define DRIVER_DESC "Freescale EHCI Host controller driver"
  697. #define DRV_NAME "ehci-fsl"
  698. static struct hc_driver __read_mostly fsl_ehci_hc_driver;
  699. +struct ehci_fsl {
  700. + struct ehci_hcd ehci;
  701. +
  702. +#ifdef CONFIG_PM
  703. +struct ehci_regs saved_regs;
  704. +struct ccsr_usb_phy saved_phy_regs;
  705. +/* Saved USB PHY settings, need to restore after deep sleep. */
  706. +u32 usb_ctrl;
  707. +#endif
  708. + /*
  709. + * store current hcd state for otg;
  710. + * have_hcd is true when host drv al already part of otg framework,
  711. + * otherwise false;
  712. + * hcd_add is true when otg framework wants to add host
  713. + * drv as part of otg;flase when it wants to remove it
  714. + */
  715. +unsigned have_hcd:1;
  716. +unsigned hcd_add:1;
  717. +};
  718. +
  719. +static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
  720. +{
  721. +struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  722. +
  723. +return container_of(ehci, struct ehci_fsl, ehci);
  724. +}
  725. +
  726. +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
  727. +static void do_change_hcd(struct work_struct *work)
  728. +{
  729. + struct ehci_hcd *ehci = container_of(work, struct ehci_hcd,
  730. + change_hcd_work);
  731. + struct usb_hcd *hcd = ehci_to_hcd(ehci);
  732. + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  733. + void __iomem *non_ehci = hcd->regs;
  734. + int retval;
  735. +
  736. + if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
  737. + writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
  738. + /* host, gadget and otg share same int line */
  739. + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
  740. + if (retval == 0)
  741. + ehci_fsl->have_hcd = 1;
  742. + } else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
  743. + usb_remove_hcd(hcd);
  744. + ehci_fsl->have_hcd = 0;
  745. + }
  746. +}
  747. +#endif
  748. +
  749. +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
  750. +static void do_change_hcd(struct work_struct *work)
  751. +{
  752. + struct ehci_hcd *ehci = container_of(work, struct ehci_hcd,
  753. + change_hcd_work);
  754. + struct usb_hcd *hcd = ehci_to_hcd(ehci);
  755. + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  756. + void __iomem *non_ehci = hcd->regs;
  757. + int retval;
  758. +
  759. + if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) {
  760. + writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE);
  761. + /* host, gadget and otg share same int line */
  762. + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
  763. + if (retval == 0)
  764. + ehci_fsl->have_hcd = 1;
  765. + } else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) {
  766. + usb_remove_hcd(hcd);
  767. + ehci_fsl->have_hcd = 0;
  768. + }
  769. +}
  770. +#endif
  771. +
  772. /* configure so an HC device and id are always provided */
  773. /* always called with process context; sleeping is OK */
  774. @@ -131,6 +242,12 @@ static int fsl_ehci_drv_probe(struct pla
  775. clrsetbits_be32(hcd->regs + FSL_SOC_USB_CTRL,
  776. CONTROL_REGISTER_W1C_MASK, 0x4);
  777. + /* Set USB_EN bit to select ULPI phy for USB controller version 2.5 */
  778. + if (pdata->controller_ver == FSL_USB_VER_2_5 &&
  779. + pdata->phy_mode == FSL_USB2_PHY_ULPI)
  780. + iowrite32be(USB_CTRL_USB_EN, hcd->regs + FSL_SOC_USB_CTRL);
  781. +
  782. +
  783. /*
  784. * Enable UTMI phy and program PTS field in UTMI mode before asserting
  785. * controller reset for USB Controller version 2.5
  786. @@ -143,16 +260,20 @@ static int fsl_ehci_drv_probe(struct pla
  787. /* Don't need to set host mode here. It will be done by tdi_reset() */
  788. - retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  789. + retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_NO_SUSPEND);
  790. if (retval != 0)
  791. goto err2;
  792. device_wakeup_enable(hcd->self.controller);
  793. -#ifdef CONFIG_USB_OTG
  794. +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
  795. if (pdata->operating_mode == FSL_USB2_DR_OTG) {
  796. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  797. + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  798. hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2);
  799. +
  800. + INIT_WORK(&ehci->change_hcd_work, do_change_hcd);
  801. +
  802. dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
  803. hcd, ehci, hcd->usb_phy);
  804. @@ -168,6 +289,11 @@ static int fsl_ehci_drv_probe(struct pla
  805. retval = -ENODEV;
  806. goto err2;
  807. }
  808. +
  809. + ehci_fsl->have_hcd = 1;
  810. + } else {
  811. + dev_err(&pdev->dev, "wrong operating mode\n");
  812. + return -ENODEV;
  813. }
  814. #endif
  815. return retval;
  816. @@ -181,6 +307,17 @@ static int fsl_ehci_drv_probe(struct pla
  817. return retval;
  818. }
  819. +static bool usb_phy_clk_valid(struct usb_hcd *hcd)
  820. +{
  821. + void __iomem *non_ehci = hcd->regs;
  822. + bool ret = true;
  823. +
  824. + if (!(ioread32be(non_ehci + FSL_SOC_USB_CTRL) & PHY_CLK_VALID))
  825. + ret = false;
  826. +
  827. + return ret;
  828. +}
  829. +
  830. static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
  831. enum fsl_usb2_phy_modes phy_mode,
  832. unsigned int port_offset)
  833. @@ -219,6 +356,21 @@ static int ehci_fsl_setup_phy(struct usb
  834. /* fall through */
  835. case FSL_USB2_PHY_UTMI:
  836. case FSL_USB2_PHY_UTMI_DUAL:
  837. + if (pdata->has_fsl_erratum_a006918) {
  838. + pr_warn("fsl-ehci: USB PHY clock invalid\n");
  839. + return -EINVAL;
  840. + }
  841. +
  842. + /* PHY_CLK_VALID bit is de-featured from all controller
  843. + * versions below 2.4 and is to be checked only for
  844. + * internal UTMI phy
  845. + */
  846. + if (pdata->controller_ver > FSL_USB_VER_2_4 &&
  847. + pdata->have_sysif_regs && !usb_phy_clk_valid(hcd)) {
  848. + pr_err("fsl-ehci: USB PHY clock invalid\n");
  849. + return -EINVAL;
  850. + }
  851. +
  852. if (pdata->have_sysif_regs && pdata->controller_ver) {
  853. /* controller version 1.6 or above */
  854. clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
  855. @@ -295,14 +447,9 @@ static int ehci_fsl_usb_setup(struct ehc
  856. return -EINVAL;
  857. if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
  858. - unsigned int chip, rev, svr;
  859. -
  860. - svr = mfspr(SPRN_SVR);
  861. - chip = svr >> 16;
  862. - rev = (svr >> 4) & 0xf;
  863. /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
  864. - if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
  865. + if (pdata->has_fsl_erratum_14 == 1)
  866. ehci->has_fsl_port_bug = 1;
  867. if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
  868. @@ -382,16 +529,56 @@ static int ehci_fsl_setup(struct usb_hcd
  869. return retval;
  870. }
  871. -struct ehci_fsl {
  872. - struct ehci_hcd ehci;
  873. -
  874. #ifdef CONFIG_PM
  875. - /* Saved USB PHY settings, need to restore after deep sleep. */
  876. - u32 usb_ctrl;
  877. -#endif
  878. -};
  879. +void __iomem *phy_reg;
  880. -#ifdef CONFIG_PM
  881. +#ifdef CONFIG_PPC
  882. +/* save usb registers */
  883. +static int ehci_fsl_save_context(struct usb_hcd *hcd)
  884. +{
  885. + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  886. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  887. + void __iomem *non_ehci = hcd->regs;
  888. + struct device *dev = hcd->self.controller;
  889. + struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
  890. +
  891. + if (pdata->phy_mode == FSL_USB2_PHY_UTMI_DUAL) {
  892. + phy_reg = ioremap(FSL_USB_PHY_ADDR,
  893. + sizeof(struct ccsr_usb_phy));
  894. + _memcpy_fromio((void *)&ehci_fsl->saved_phy_regs, phy_reg,
  895. + sizeof(struct ccsr_usb_phy));
  896. + }
  897. +
  898. + _memcpy_fromio((void *)&ehci_fsl->saved_regs, ehci->regs,
  899. + sizeof(struct ehci_regs));
  900. + ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
  901. +
  902. + return 0;
  903. +}
  904. +
  905. +/*Restore usb registers */
  906. +static int ehci_fsl_restore_context(struct usb_hcd *hcd)
  907. +{
  908. + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  909. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  910. + void __iomem *non_ehci = hcd->regs;
  911. + struct device *dev = hcd->self.controller;
  912. + struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
  913. +
  914. + if (pdata->phy_mode == FSL_USB2_PHY_UTMI_DUAL) {
  915. + if (phy_reg)
  916. + _memcpy_toio(phy_reg,
  917. + (void *)&ehci_fsl->saved_phy_regs,
  918. + sizeof(struct ccsr_usb_phy));
  919. + }
  920. +
  921. + _memcpy_toio(ehci->regs, (void *)&ehci_fsl->saved_regs,
  922. + sizeof(struct ehci_regs));
  923. + iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL);
  924. +
  925. + return 0;
  926. +}
  927. +#endif
  928. #ifdef CONFIG_PPC_MPC512x
  929. static int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
  930. @@ -538,26 +725,45 @@ static inline int ehci_fsl_mpc512x_drv_r
  931. }
  932. #endif /* CONFIG_PPC_MPC512x */
  933. -static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
  934. -{
  935. - struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  936. -
  937. - return container_of(ehci, struct ehci_fsl, ehci);
  938. -}
  939. -
  940. static int ehci_fsl_drv_suspend(struct device *dev)
  941. {
  942. struct usb_hcd *hcd = dev_get_drvdata(dev);
  943. struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  944. void __iomem *non_ehci = hcd->regs;
  945. +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
  946. + struct usb_bus host = hcd->self;
  947. +#endif
  948. +
  949. +#ifdef CONFIG_PPC
  950. + suspend_state_t pm_state;
  951. + /* FIXME:Need to port fsl_pm.h before enable below code. */
  952. + /*pm_state = pm_suspend_state();*/
  953. + pm_state = PM_SUSPEND_MEM;
  954. +
  955. +if (pm_state == PM_SUSPEND_MEM)
  956. + ehci_fsl_save_context(hcd);
  957. +#endif
  958. if (of_device_is_compatible(dev->parent->of_node,
  959. "fsl,mpc5121-usb2-dr")) {
  960. return ehci_fsl_mpc512x_drv_suspend(dev);
  961. }
  962. +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
  963. + if (host.is_otg) {
  964. + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  965. +
  966. + /* remove hcd */
  967. + ehci_fsl->hcd_add = 0;
  968. + schedule_work(&ehci->change_hcd_work);
  969. + host.is_otg = 0;
  970. + return 0;
  971. + }
  972. +#endif
  973. +
  974. ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
  975. device_may_wakeup(dev));
  976. +
  977. if (!fsl_deep_sleep())
  978. return 0;
  979. @@ -571,12 +777,36 @@ static int ehci_fsl_drv_resume(struct de
  980. struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  981. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  982. void __iomem *non_ehci = hcd->regs;
  983. +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
  984. + struct usb_bus host = hcd->self;
  985. +#endif
  986. +
  987. +#ifdef CONFIG_PPC
  988. + suspend_state_t pm_state;
  989. + /* FIXME:Need to port fsl_pm.h before enable below code.*/
  990. + /* pm_state = pm_suspend_state(); */
  991. + pm_state = PM_SUSPEND_MEM;
  992. +
  993. + if (pm_state == PM_SUSPEND_MEM)
  994. + ehci_fsl_restore_context(hcd);
  995. +#endif
  996. if (of_device_is_compatible(dev->parent->of_node,
  997. "fsl,mpc5121-usb2-dr")) {
  998. return ehci_fsl_mpc512x_drv_resume(dev);
  999. }
  1000. +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
  1001. + if (host.is_otg) {
  1002. + /* add hcd */
  1003. + ehci_fsl->hcd_add = 1;
  1004. + schedule_work(&ehci->change_hcd_work);
  1005. + usb_hcd_resume_root_hub(hcd);
  1006. + host.is_otg = 0;
  1007. + return 0;
  1008. + }
  1009. +#endif
  1010. +
  1011. ehci_prepare_ports_for_controller_resume(ehci);
  1012. if (!fsl_deep_sleep())
  1013. return 0;
  1014. --- a/drivers/usb/host/ehci-fsl.h
  1015. +++ b/drivers/usb/host/ehci-fsl.h
  1016. @@ -63,4 +63,7 @@
  1017. #define UTMI_PHY_EN (1<<9)
  1018. #define ULPI_PHY_CLK_SEL (1<<10)
  1019. #define PHY_CLK_VALID (1<<17)
  1020. +
  1021. +/* Retry count for checking UTMI PHY CLK validity */
  1022. +#define UTMI_PHY_CLK_VALID_CHK_RETRY 5
  1023. #endif /* _EHCI_FSL_H */
  1024. --- a/drivers/usb/host/ehci-hub.c
  1025. +++ b/drivers/usb/host/ehci-hub.c
  1026. @@ -305,6 +305,8 @@ static int ehci_bus_suspend (struct usb_
  1027. USB_PORT_STAT_HIGH_SPEED)
  1028. fs_idle_delay = true;
  1029. ehci_writel(ehci, t2, reg);
  1030. + if (ehci_has_fsl_susp_errata(ehci))
  1031. + usleep_range(10000, 20000);
  1032. changed = 1;
  1033. }
  1034. }
  1035. --- a/drivers/usb/host/ehci.h
  1036. +++ b/drivers/usb/host/ehci.h
  1037. @@ -180,6 +180,9 @@ struct ehci_hcd { /* one per controlle
  1038. unsigned periodic_count; /* periodic activity count */
  1039. unsigned uframe_periodic_max; /* max periodic time per uframe */
  1040. +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE)
  1041. + struct work_struct change_hcd_work;
  1042. +#endif
  1043. /* list of itds & sitds completed while now_frame was still active */
  1044. struct list_head cached_itd_list;
  1045. --- a/drivers/usb/host/fsl-mph-dr-of.c
  1046. +++ b/drivers/usb/host/fsl-mph-dr-of.c
  1047. @@ -229,6 +229,17 @@ static int fsl_usb2_mph_dr_of_probe(stru
  1048. pdata->has_fsl_erratum_a005697 =
  1049. of_property_read_bool(np, "fsl,usb_erratum-a005697");
  1050. + if (of_get_property(np, "fsl,erratum_a006918", NULL))
  1051. + pdata->has_fsl_erratum_a006918 = 1;
  1052. + else
  1053. + pdata->has_fsl_erratum_a006918 = 0;
  1054. +
  1055. + if (of_get_property(np, "fsl,usb_erratum_14", NULL))
  1056. + pdata->has_fsl_erratum_14 = 1;
  1057. + else
  1058. + pdata->has_fsl_erratum_14 = 0;
  1059. +
  1060. +
  1061. /*
  1062. * Determine whether phy_clk_valid needs to be checked
  1063. * by reading property in device tree
  1064. --- a/drivers/usb/host/xhci-hub.c
  1065. +++ b/drivers/usb/host/xhci-hub.c
  1066. @@ -689,12 +689,34 @@ void xhci_set_link_state(struct xhci_hcd
  1067. int port_id, u32 link_state)
  1068. {
  1069. u32 temp;
  1070. + u32 portpmsc_u2_backup = 0;
  1071. +
  1072. + /* Backup U2 timeout info before initiating U3 entry erratum A-010131 */
  1073. + if (xhci->shared_hcd->speed >= HCD_USB3 &&
  1074. + link_state == USB_SS_PORT_LS_U3 &&
  1075. + (xhci->quirks & XHCI_DIS_U1U2_WHEN_U3)) {
  1076. + portpmsc_u2_backup = readl(port_array[port_id] + PORTPMSC);
  1077. + portpmsc_u2_backup &= PORT_U2_TIMEOUT_MASK;
  1078. + temp = readl(port_array[port_id] + PORTPMSC);
  1079. + temp |= PORT_U2_TIMEOUT_MASK;
  1080. + writel(temp, port_array[port_id] + PORTPMSC);
  1081. + }
  1082. temp = readl(port_array[port_id]);
  1083. temp = xhci_port_state_to_neutral(temp);
  1084. temp &= ~PORT_PLS_MASK;
  1085. temp |= PORT_LINK_STROBE | link_state;
  1086. writel(temp, port_array[port_id]);
  1087. +
  1088. + /* Restore U2 timeout info after U3 entry complete */
  1089. + if (xhci->shared_hcd->speed >= HCD_USB3 &&
  1090. + link_state == USB_SS_PORT_LS_U3 &&
  1091. + (xhci->quirks & XHCI_DIS_U1U2_WHEN_U3)) {
  1092. + temp = readl(port_array[port_id] + PORTPMSC);
  1093. + temp &= ~PORT_U2_TIMEOUT_MASK;
  1094. + temp |= portpmsc_u2_backup;
  1095. + writel(temp, port_array[port_id] + PORTPMSC);
  1096. + }
  1097. }
  1098. static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
  1099. --- a/drivers/usb/host/xhci-plat.c
  1100. +++ b/drivers/usb/host/xhci-plat.c
  1101. @@ -263,8 +263,22 @@ static int xhci_plat_probe(struct platfo
  1102. goto disable_clk;
  1103. }
  1104. - if (device_property_read_bool(sysdev, "usb3-lpm-capable"))
  1105. + if (device_property_read_bool(sysdev, "usb3-lpm-capable")) {
  1106. xhci->quirks |= XHCI_LPM_SUPPORT;
  1107. + if (device_property_read_bool(sysdev,
  1108. + "snps,dis-u1u2-when-u3-quirk"))
  1109. + xhci->quirks |= XHCI_DIS_U1U2_WHEN_U3;
  1110. + }
  1111. +
  1112. + if (device_property_read_bool(&pdev->dev, "quirk-reverse-in-out"))
  1113. + xhci->quirks |= XHCI_REVERSE_IN_OUT;
  1114. +
  1115. + if (device_property_read_bool(&pdev->dev,
  1116. + "quirk-stop-transfer-in-block"))
  1117. + xhci->quirks |= XHCI_STOP_TRANSFER_IN_BLOCK;
  1118. +
  1119. + if (device_property_read_bool(&pdev->dev, "quirk-stop-ep-in-u1"))
  1120. + xhci->quirks |= XHCI_STOP_EP_IN_U1;
  1121. if (device_property_read_bool(&pdev->dev, "quirk-broken-port-ped"))
  1122. xhci->quirks |= XHCI_BROKEN_PORT_PED;
  1123. --- a/drivers/usb/host/xhci-ring.c
  1124. +++ b/drivers/usb/host/xhci-ring.c
  1125. @@ -1972,10 +1972,12 @@ static int finish_td(struct xhci_hcd *xh
  1126. union xhci_trb *ep_trb, struct xhci_transfer_event *event,
  1127. struct xhci_virt_ep *ep, int *status)
  1128. {
  1129. + struct xhci_dequeue_state deq_state;
  1130. struct xhci_virt_device *xdev;
  1131. struct xhci_ep_ctx *ep_ctx;
  1132. struct xhci_ring *ep_ring;
  1133. unsigned int slot_id;
  1134. + u32 remaining;
  1135. u32 trb_comp_code;
  1136. int ep_index;
  1137. @@ -1998,14 +2000,30 @@ static int finish_td(struct xhci_hcd *xh
  1138. if (trb_comp_code == COMP_STALL_ERROR ||
  1139. xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
  1140. trb_comp_code)) {
  1141. - /* Issue a reset endpoint command to clear the host side
  1142. - * halt, followed by a set dequeue command to move the
  1143. - * dequeue pointer past the TD.
  1144. - * The class driver clears the device side halt later.
  1145. + /*erratum A-007463:
  1146. + *After transaction error, controller switches control transfer
  1147. + *data stage from IN to OUT direction.
  1148. */
  1149. - xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index,
  1150. + remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
  1151. + if (remaining && xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
  1152. + trb_comp_code) &&
  1153. + (xhci->quirks & XHCI_REVERSE_IN_OUT)) {
  1154. + memset(&deq_state, 0, sizeof(deq_state));
  1155. + xhci_find_new_dequeue_state(xhci, slot_id,
  1156. + ep_index, td->urb->stream_id, td, &deq_state);
  1157. + xhci_queue_new_dequeue_state(xhci, slot_id, ep_index,
  1158. + &deq_state);
  1159. + xhci_ring_cmd_db(xhci);
  1160. + } else {
  1161. + /* Issue a reset endpoint command to clear the host side
  1162. + * halt, followed by a set dequeue command to move the
  1163. + * dequeue pointer past the TD.
  1164. + * The class driver clears the device side halt later.
  1165. + */
  1166. + xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index,
  1167. ep_ring->stream_id, td, ep_trb,
  1168. EP_HARD_RESET);
  1169. + }
  1170. } else {
  1171. /* Update ring dequeue pointer */
  1172. while (ep_ring->dequeue != td->last_trb)
  1173. --- a/drivers/usb/host/xhci.c
  1174. +++ b/drivers/usb/host/xhci.c
  1175. @@ -1597,13 +1597,38 @@ static int xhci_urb_dequeue(struct usb_h
  1176. ret = -ENOMEM;
  1177. goto done;
  1178. }
  1179. - ep->ep_state |= EP_STOP_CMD_PENDING;
  1180. - ep->stop_cmd_timer.expires = jiffies +
  1181. + /*
  1182. + *erratum A-009611: Issuing an End Transfer command on an IN
  1183. + *endpoint. when a transfer is in progress on USB blocks the
  1184. + *transmission.
  1185. + *Workaround: Software must wait for all existing TRBs to
  1186. + *complete before issuing End transfer command.
  1187. + */
  1188. + if ((ep_ring->enqueue == ep_ring->dequeue &&
  1189. + (xhci->quirks & XHCI_STOP_TRANSFER_IN_BLOCK)) ||
  1190. + !(xhci->quirks & XHCI_STOP_TRANSFER_IN_BLOCK)) {
  1191. + ep->ep_state |= EP_STOP_CMD_PENDING;
  1192. + ep->stop_cmd_timer.expires = jiffies +
  1193. XHCI_STOP_EP_CMD_TIMEOUT * HZ;
  1194. - add_timer(&ep->stop_cmd_timer);
  1195. - xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id,
  1196. - ep_index, 0);
  1197. - xhci_ring_cmd_db(xhci);
  1198. + add_timer(&ep->stop_cmd_timer);
  1199. + xhci_queue_stop_endpoint(xhci, command,
  1200. + urb->dev->slot_id,
  1201. + ep_index, 0);
  1202. + xhci_ring_cmd_db(xhci);
  1203. + }
  1204. +
  1205. + /*
  1206. + *erratum A-009668: Stop Endpoint Command does not complete.
  1207. + *Workaround: Instead of issuing a Stop Endpoint Command,
  1208. + *issue a Disable Slot Command with the corresponding slot ID.
  1209. + *Alternately, you can issue an Address Device Command with
  1210. + *BSR=1
  1211. + */
  1212. + if ((urb->dev->speed <= USB_SPEED_HIGH) &&
  1213. + (xhci->quirks & XHCI_STOP_EP_IN_U1)) {
  1214. + xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT,
  1215. + urb->dev->slot_id);
  1216. + }
  1217. }
  1218. done:
  1219. spin_unlock_irqrestore(&xhci->lock, flags);
  1220. @@ -4988,7 +5013,7 @@ int xhci_gen_setup(struct usb_hcd *hcd,
  1221. return retval;
  1222. xhci_dbg(xhci, "Called HCD init\n");
  1223. - xhci_info(xhci, "hcc params 0x%08x hci version 0x%x quirks 0x%016llx\n",
  1224. + xhci_info(xhci, "hcc params 0x%08x hci version 0x%x quirks 0x%llx\n",
  1225. xhci->hcc_params, xhci->hci_version, xhci->quirks);
  1226. return 0;
  1227. --- a/drivers/usb/host/xhci.h
  1228. +++ b/drivers/usb/host/xhci.h
  1229. @@ -1794,7 +1794,7 @@ struct xhci_hcd {
  1230. #define XHCI_STATE_DYING (1 << 0)
  1231. #define XHCI_STATE_HALTED (1 << 1)
  1232. #define XHCI_STATE_REMOVING (1 << 2)
  1233. - unsigned long long quirks;
  1234. + u64 quirks;
  1235. #define XHCI_LINK_TRB_QUIRK BIT_ULL(0)
  1236. #define XHCI_RESET_EP_QUIRK BIT_ULL(1)
  1237. #define XHCI_NEC_HOST BIT_ULL(2)
  1238. @@ -1830,6 +1830,9 @@ struct xhci_hcd {
  1239. #define XHCI_SSIC_PORT_UNUSED BIT_ULL(22)
  1240. #define XHCI_NO_64BIT_SUPPORT BIT_ULL(23)
  1241. #define XHCI_MISSING_CAS BIT_ULL(24)
  1242. +#define XHCI_REVERSE_IN_OUT BIT(32)
  1243. +#define XHCI_STOP_TRANSFER_IN_BLOCK BIT(33)
  1244. +#define XHCI_STOP_EP_IN_U1 BIT(34)
  1245. /* For controller with a broken Port Disable implementation */
  1246. #define XHCI_BROKEN_PORT_PED BIT_ULL(25)
  1247. #define XHCI_LIMIT_ENDPOINT_INTERVAL_7 BIT_ULL(26)
  1248. @@ -1840,6 +1843,7 @@ struct xhci_hcd {
  1249. #define XHCI_INTEL_USB_ROLE_SW BIT_ULL(31)
  1250. #define XHCI_RESET_PLL_ON_DISCONNECT BIT_ULL(34)
  1251. #define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(35)
  1252. +#define XHCI_DIS_U1U2_WHEN_U3 BIT(36)
  1253. unsigned int num_active_eps;
  1254. unsigned int limit_active_eps;
  1255. --- a/drivers/usb/phy/phy-fsl-usb.c
  1256. +++ b/drivers/usb/phy/phy-fsl-usb.c
  1257. @@ -1,5 +1,5 @@
  1258. /*
  1259. - * Copyright (C) 2007,2008 Freescale semiconductor, Inc.
  1260. + * Copyright 2007,2008 Freescale Semiconductor, Inc.
  1261. *
  1262. * Author: Li Yang <[email protected]>
  1263. * Jerry Huang <[email protected]>
  1264. @@ -470,6 +470,7 @@ void otg_reset_controller(void)
  1265. int fsl_otg_start_host(struct otg_fsm *fsm, int on)
  1266. {
  1267. struct usb_otg *otg = fsm->otg;
  1268. + struct usb_bus *host = otg->host;
  1269. struct device *dev;
  1270. struct fsl_otg *otg_dev =
  1271. container_of(otg->usb_phy, struct fsl_otg, phy);
  1272. @@ -493,6 +494,7 @@ int fsl_otg_start_host(struct otg_fsm *f
  1273. otg_reset_controller();
  1274. VDBG("host on......\n");
  1275. if (dev->driver->pm && dev->driver->pm->resume) {
  1276. + host->is_otg = 1;
  1277. retval = dev->driver->pm->resume(dev);
  1278. if (fsm->id) {
  1279. /* default-b */
  1280. @@ -517,8 +519,11 @@ int fsl_otg_start_host(struct otg_fsm *f
  1281. else {
  1282. VDBG("host off......\n");
  1283. if (dev && dev->driver) {
  1284. - if (dev->driver->pm && dev->driver->pm->suspend)
  1285. + if (dev->driver->pm &&
  1286. + dev->driver->pm->suspend) {
  1287. + host->is_otg = 1;
  1288. retval = dev->driver->pm->suspend(dev);
  1289. + }
  1290. if (fsm->id)
  1291. /* default-b */
  1292. fsl_otg_drv_vbus(fsm, 0);
  1293. @@ -546,8 +551,17 @@ int fsl_otg_start_gadget(struct otg_fsm
  1294. dev = otg->gadget->dev.parent;
  1295. if (on) {
  1296. - if (dev->driver->resume)
  1297. + /* Delay gadget resume to synchronize between host and gadget
  1298. + * drivers. Upon role-reversal host drv is shutdown by kernel
  1299. + * worker thread. By the time host drv shuts down, controller
  1300. + * gets programmed for gadget role. Shutting host drv after
  1301. + * this results in controller getting reset, and it stops
  1302. + * responding to otg events
  1303. + */
  1304. + if (dev->driver->resume) {
  1305. + msleep(1000);
  1306. dev->driver->resume(dev);
  1307. + }
  1308. } else {
  1309. if (dev->driver->suspend)
  1310. dev->driver->suspend(dev, otg_suspend_state);
  1311. @@ -668,6 +682,10 @@ static void fsl_otg_event(struct work_st
  1312. fsl_otg_start_host(fsm, 0);
  1313. otg_drv_vbus(fsm, 0);
  1314. fsl_otg_start_gadget(fsm, 1);
  1315. + } else {
  1316. + fsl_otg_start_gadget(fsm, 0);
  1317. + otg_drv_vbus(fsm, 1);
  1318. + fsl_otg_start_host(fsm, 1);
  1319. }
  1320. }
  1321. @@ -720,6 +738,7 @@ irqreturn_t fsl_otg_isr(int irq, void *d
  1322. {
  1323. struct otg_fsm *fsm = &((struct fsl_otg *)dev_id)->fsm;
  1324. struct usb_otg *otg = ((struct fsl_otg *)dev_id)->phy.otg;
  1325. + struct fsl_otg *otg_dev = dev_id;
  1326. u32 otg_int_src, otg_sc;
  1327. otg_sc = fsl_readl(&usb_dr_regs->otgsc);
  1328. @@ -749,18 +768,8 @@ irqreturn_t fsl_otg_isr(int irq, void *d
  1329. otg->gadget->is_a_peripheral = !fsm->id;
  1330. VDBG("ID int (ID is %d)\n", fsm->id);
  1331. - if (fsm->id) { /* switch to gadget */
  1332. - schedule_delayed_work(
  1333. - &((struct fsl_otg *)dev_id)->otg_event,
  1334. - 100);
  1335. - } else { /* switch to host */
  1336. - cancel_delayed_work(&
  1337. - ((struct fsl_otg *)dev_id)->
  1338. - otg_event);
  1339. - fsl_otg_start_gadget(fsm, 0);
  1340. - otg_drv_vbus(fsm, 1);
  1341. - fsl_otg_start_host(fsm, 1);
  1342. - }
  1343. + schedule_delayed_work(&otg_dev->otg_event, 100);
  1344. +
  1345. return IRQ_HANDLED;
  1346. }
  1347. }
  1348. @@ -920,12 +929,32 @@ int usb_otg_start(struct platform_device
  1349. temp &= ~(PORTSC_PHY_TYPE_SEL | PORTSC_PTW);
  1350. switch (pdata->phy_mode) {
  1351. case FSL_USB2_PHY_ULPI:
  1352. + if (pdata->controller_ver) {
  1353. + /* controller version 1.6 or above */
  1354. + setbits32(&p_otg->dr_mem_map->control,
  1355. + USB_CTRL_ULPI_PHY_CLK_SEL);
  1356. + /*
  1357. + * Due to controller issue of PHY_CLK_VALID in ULPI
  1358. + * mode, we set USB_CTRL_USB_EN before checking
  1359. + * PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
  1360. + */
  1361. + clrsetbits_be32(&p_otg->dr_mem_map->control,
  1362. + USB_CTRL_UTMI_PHY_EN, USB_CTRL_IOENB);
  1363. + }
  1364. temp |= PORTSC_PTS_ULPI;
  1365. break;
  1366. case FSL_USB2_PHY_UTMI_WIDE:
  1367. temp |= PORTSC_PTW_16BIT;
  1368. /* fall through */
  1369. case FSL_USB2_PHY_UTMI:
  1370. + if (pdata->controller_ver) {
  1371. + /* controller version 1.6 or above */
  1372. + setbits32(&p_otg->dr_mem_map->control,
  1373. + USB_CTRL_UTMI_PHY_EN);
  1374. + /* Delay for UTMI PHY CLK to become stable - 10ms */
  1375. + mdelay(FSL_UTMI_PHY_DLY);
  1376. + }
  1377. + setbits32(&p_otg->dr_mem_map->control, USB_CTRL_UTMI_PHY_EN);
  1378. temp |= PORTSC_PTS_UTMI;
  1379. /* fall through */
  1380. default:
  1381. --- a/drivers/usb/phy/phy-fsl-usb.h
  1382. +++ b/drivers/usb/phy/phy-fsl-usb.h
  1383. @@ -199,6 +199,14 @@
  1384. /* control Register Bit Masks */
  1385. #define USB_CTRL_IOENB (0x1<<2)
  1386. #define USB_CTRL_ULPI_INT0EN (0x1<<0)
  1387. +#define USB_CTRL_WU_INT_EN (0x1<<1)
  1388. +#define USB_CTRL_LINE_STATE_FILTER__EN (0x1<<3)
  1389. +#define USB_CTRL_KEEP_OTG_ON (0x1<<4)
  1390. +#define USB_CTRL_OTG_PORT (0x1<<5)
  1391. +#define USB_CTRL_PLL_RESET (0x1<<8)
  1392. +#define USB_CTRL_UTMI_PHY_EN (0x1<<9)
  1393. +#define USB_CTRL_ULPI_PHY_CLK_SEL (0x1<<10)
  1394. +#define USB_CTRL_PHY_CLK_VALID (0x1<<17)
  1395. /* BCSR5 */
  1396. #define BCSR5_INT_USB (0x02)
  1397. --- a/include/linux/usb.h
  1398. +++ b/include/linux/usb.h
  1399. @@ -434,6 +434,7 @@ struct usb_bus {
  1400. * for control transfers?
  1401. */
  1402. u8 otg_port; /* 0, or number of OTG/HNP port */
  1403. + unsigned is_otg:1; /* true when host is also otg */
  1404. unsigned is_b_host:1; /* true during some HNP roleswitches */
  1405. unsigned b_hnp_enable:1; /* OTG: did A-Host enable HNP? */
  1406. unsigned no_stop_on_short:1; /*
  1407. --- a/include/linux/usb/of.h
  1408. +++ b/include/linux/usb/of.h
  1409. @@ -11,6 +11,8 @@
  1410. #include <linux/usb/otg.h>
  1411. #include <linux/usb/phy.h>
  1412. +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
  1413. +
  1414. #if IS_ENABLED(CONFIG_OF)
  1415. enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0);
  1416. bool of_usb_host_tpl_support(struct device_node *np);