817-usb-support-layerscape.patch 56 KB

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