817-usb-support-layerscape.patch 54 KB

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