807-usb-support-layerscape.patch 51 KB

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