xusb-tegra186.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #include <linux/delay.h>
  6. #include <linux/io.h>
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/phy/phy.h>
  10. #include <linux/regulator/consumer.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/clk.h>
  13. #include <linux/slab.h>
  14. #include <soc/tegra/fuse.h>
  15. #include "xusb.h"
  16. /* FUSE USB_CALIB registers */
  17. #define HS_CURR_LEVEL_PADX_SHIFT(x) ((x) ? (11 + (x - 1) * 6) : 0)
  18. #define HS_CURR_LEVEL_PAD_MASK 0x3f
  19. #define HS_TERM_RANGE_ADJ_SHIFT 7
  20. #define HS_TERM_RANGE_ADJ_MASK 0xf
  21. #define HS_SQUELCH_SHIFT 29
  22. #define HS_SQUELCH_MASK 0x7
  23. #define RPD_CTRL_SHIFT 0
  24. #define RPD_CTRL_MASK 0x1f
  25. /* XUSB PADCTL registers */
  26. #define XUSB_PADCTL_USB2_PAD_MUX 0x4
  27. #define USB2_PORT_SHIFT(x) ((x) * 2)
  28. #define USB2_PORT_MASK 0x3
  29. #define PORT_XUSB 1
  30. #define HSIC_PORT_SHIFT(x) ((x) + 20)
  31. #define HSIC_PORT_MASK 0x1
  32. #define PORT_HSIC 0
  33. #define XUSB_PADCTL_USB2_PORT_CAP 0x8
  34. #define XUSB_PADCTL_SS_PORT_CAP 0xc
  35. #define PORTX_CAP_SHIFT(x) ((x) * 4)
  36. #define PORT_CAP_MASK 0x3
  37. #define PORT_CAP_DISABLED 0x0
  38. #define PORT_CAP_HOST 0x1
  39. #define PORT_CAP_DEVICE 0x2
  40. #define PORT_CAP_OTG 0x3
  41. #define XUSB_PADCTL_ELPG_PROGRAM 0x20
  42. #define USB2_PORT_WAKE_INTERRUPT_ENABLE(x) BIT(x)
  43. #define USB2_PORT_WAKEUP_EVENT(x) BIT((x) + 7)
  44. #define SS_PORT_WAKE_INTERRUPT_ENABLE(x) BIT((x) + 14)
  45. #define SS_PORT_WAKEUP_EVENT(x) BIT((x) + 21)
  46. #define USB2_HSIC_PORT_WAKE_INTERRUPT_ENABLE(x) BIT((x) + 28)
  47. #define USB2_HSIC_PORT_WAKEUP_EVENT(x) BIT((x) + 30)
  48. #define ALL_WAKE_EVENTS \
  49. (USB2_PORT_WAKEUP_EVENT(0) | USB2_PORT_WAKEUP_EVENT(1) | \
  50. USB2_PORT_WAKEUP_EVENT(2) | SS_PORT_WAKEUP_EVENT(0) | \
  51. SS_PORT_WAKEUP_EVENT(1) | SS_PORT_WAKEUP_EVENT(2) | \
  52. USB2_HSIC_PORT_WAKEUP_EVENT(0))
  53. #define XUSB_PADCTL_ELPG_PROGRAM_1 0x24
  54. #define SSPX_ELPG_CLAMP_EN(x) BIT(0 + (x) * 3)
  55. #define SSPX_ELPG_CLAMP_EN_EARLY(x) BIT(1 + (x) * 3)
  56. #define SSPX_ELPG_VCORE_DOWN(x) BIT(2 + (x) * 3)
  57. #define XUSB_PADCTL_SS_PORT_CFG 0x2c
  58. #define PORTX_SPEED_SUPPORT_SHIFT(x) ((x) * 4)
  59. #define PORTX_SPEED_SUPPORT_MASK (0x3)
  60. #define PORT_SPEED_SUPPORT_GEN1 (0x0)
  61. #define XUSB_PADCTL_USB2_OTG_PADX_CTL0(x) (0x88 + (x) * 0x40)
  62. #define HS_CURR_LEVEL(x) ((x) & 0x3f)
  63. #define TERM_SEL BIT(25)
  64. #define USB2_OTG_PD BIT(26)
  65. #define USB2_OTG_PD2 BIT(27)
  66. #define USB2_OTG_PD2_OVRD_EN BIT(28)
  67. #define USB2_OTG_PD_ZI BIT(29)
  68. #define XUSB_PADCTL_USB2_OTG_PADX_CTL1(x) (0x8c + (x) * 0x40)
  69. #define USB2_OTG_PD_DR BIT(2)
  70. #define TERM_RANGE_ADJ(x) (((x) & 0xf) << 3)
  71. #define RPD_CTRL(x) (((x) & 0x1f) << 26)
  72. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0 0x284
  73. #define BIAS_PAD_PD BIT(11)
  74. #define HS_SQUELCH_LEVEL(x) (((x) & 0x7) << 0)
  75. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1 0x288
  76. #define USB2_TRK_START_TIMER(x) (((x) & 0x7f) << 12)
  77. #define USB2_TRK_DONE_RESET_TIMER(x) (((x) & 0x7f) << 19)
  78. #define USB2_PD_TRK BIT(26)
  79. #define USB2_TRK_COMPLETED BIT(31)
  80. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL2 0x28c
  81. #define USB2_TRK_HW_MODE BIT(0)
  82. #define CYA_TRK_CODE_UPDATE_ON_IDLE BIT(31)
  83. #define XUSB_PADCTL_HSIC_PADX_CTL0(x) (0x300 + (x) * 0x20)
  84. #define HSIC_PD_TX_DATA0 BIT(1)
  85. #define HSIC_PD_TX_STROBE BIT(3)
  86. #define HSIC_PD_RX_DATA0 BIT(4)
  87. #define HSIC_PD_RX_STROBE BIT(6)
  88. #define HSIC_PD_ZI_DATA0 BIT(7)
  89. #define HSIC_PD_ZI_STROBE BIT(9)
  90. #define HSIC_RPD_DATA0 BIT(13)
  91. #define HSIC_RPD_STROBE BIT(15)
  92. #define HSIC_RPU_DATA0 BIT(16)
  93. #define HSIC_RPU_STROBE BIT(18)
  94. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL0 0x340
  95. #define HSIC_TRK_START_TIMER(x) (((x) & 0x7f) << 5)
  96. #define HSIC_TRK_DONE_RESET_TIMER(x) (((x) & 0x7f) << 12)
  97. #define HSIC_PD_TRK BIT(19)
  98. #define USB2_VBUS_ID 0x360
  99. #define VBUS_OVERRIDE BIT(14)
  100. #define ID_OVERRIDE(x) (((x) & 0xf) << 18)
  101. #define ID_OVERRIDE_FLOATING ID_OVERRIDE(8)
  102. #define ID_OVERRIDE_GROUNDED ID_OVERRIDE(0)
  103. /* XUSB AO registers */
  104. #define XUSB_AO_USB_DEBOUNCE_DEL (0x4)
  105. #define UHSIC_LINE_DEB_CNT(x) (((x) & 0xf) << 4)
  106. #define UTMIP_LINE_DEB_CNT(x) ((x) & 0xf)
  107. #define XUSB_AO_UTMIP_TRIGGERS(x) (0x40 + (x) * 4)
  108. #define CLR_WALK_PTR BIT(0)
  109. #define CAP_CFG BIT(1)
  110. #define CLR_WAKE_ALARM BIT(3)
  111. #define XUSB_AO_UHSIC_TRIGGERS(x) (0x60 + (x) * 4)
  112. #define HSIC_CLR_WALK_PTR BIT(0)
  113. #define HSIC_CLR_WAKE_ALARM BIT(3)
  114. #define HSIC_CAP_CFG BIT(4)
  115. #define XUSB_AO_UTMIP_SAVED_STATE(x) (0x70 + (x) * 4)
  116. #define SPEED(x) ((x) & 0x3)
  117. #define UTMI_HS SPEED(0)
  118. #define UTMI_FS SPEED(1)
  119. #define UTMI_LS SPEED(2)
  120. #define UTMI_RST SPEED(3)
  121. #define XUSB_AO_UHSIC_SAVED_STATE(x) (0x90 + (x) * 4)
  122. #define MODE(x) ((x) & 0x1)
  123. #define MODE_HS MODE(0)
  124. #define MODE_RST MODE(1)
  125. #define XUSB_AO_UTMIP_SLEEPWALK_STATUS(x) (0xa0 + (x) * 4)
  126. #define XUSB_AO_UTMIP_SLEEPWALK_CFG(x) (0xd0 + (x) * 4)
  127. #define XUSB_AO_UHSIC_SLEEPWALK_CFG(x) (0xf0 + (x) * 4)
  128. #define FAKE_USBOP_VAL BIT(0)
  129. #define FAKE_USBON_VAL BIT(1)
  130. #define FAKE_USBOP_EN BIT(2)
  131. #define FAKE_USBON_EN BIT(3)
  132. #define FAKE_STROBE_VAL BIT(0)
  133. #define FAKE_DATA_VAL BIT(1)
  134. #define FAKE_STROBE_EN BIT(2)
  135. #define FAKE_DATA_EN BIT(3)
  136. #define WAKE_WALK_EN BIT(14)
  137. #define MASTER_ENABLE BIT(15)
  138. #define LINEVAL_WALK_EN BIT(16)
  139. #define WAKE_VAL(x) (((x) & 0xf) << 17)
  140. #define WAKE_VAL_NONE WAKE_VAL(12)
  141. #define WAKE_VAL_ANY WAKE_VAL(15)
  142. #define WAKE_VAL_DS10 WAKE_VAL(2)
  143. #define LINE_WAKEUP_EN BIT(21)
  144. #define MASTER_CFG_SEL BIT(22)
  145. #define XUSB_AO_UTMIP_SLEEPWALK(x) (0x100 + (x) * 4)
  146. /* phase A */
  147. #define USBOP_RPD_A BIT(0)
  148. #define USBON_RPD_A BIT(1)
  149. #define AP_A BIT(4)
  150. #define AN_A BIT(5)
  151. #define HIGHZ_A BIT(6)
  152. #define MASTER_ENABLE_A BIT(7)
  153. /* phase B */
  154. #define USBOP_RPD_B BIT(8)
  155. #define USBON_RPD_B BIT(9)
  156. #define AP_B BIT(12)
  157. #define AN_B BIT(13)
  158. #define HIGHZ_B BIT(14)
  159. #define MASTER_ENABLE_B BIT(15)
  160. /* phase C */
  161. #define USBOP_RPD_C BIT(16)
  162. #define USBON_RPD_C BIT(17)
  163. #define AP_C BIT(20)
  164. #define AN_C BIT(21)
  165. #define HIGHZ_C BIT(22)
  166. #define MASTER_ENABLE_C BIT(23)
  167. /* phase D */
  168. #define USBOP_RPD_D BIT(24)
  169. #define USBON_RPD_D BIT(25)
  170. #define AP_D BIT(28)
  171. #define AN_D BIT(29)
  172. #define HIGHZ_D BIT(30)
  173. #define MASTER_ENABLE_D BIT(31)
  174. #define MASTER_ENABLE_B_C_D \
  175. (MASTER_ENABLE_B | MASTER_ENABLE_C | MASTER_ENABLE_D)
  176. #define XUSB_AO_UHSIC_SLEEPWALK(x) (0x120 + (x) * 4)
  177. /* phase A */
  178. #define RPD_STROBE_A BIT(0)
  179. #define RPD_DATA0_A BIT(1)
  180. #define RPU_STROBE_A BIT(2)
  181. #define RPU_DATA0_A BIT(3)
  182. /* phase B */
  183. #define RPD_STROBE_B BIT(8)
  184. #define RPD_DATA0_B BIT(9)
  185. #define RPU_STROBE_B BIT(10)
  186. #define RPU_DATA0_B BIT(11)
  187. /* phase C */
  188. #define RPD_STROBE_C BIT(16)
  189. #define RPD_DATA0_C BIT(17)
  190. #define RPU_STROBE_C BIT(18)
  191. #define RPU_DATA0_C BIT(19)
  192. /* phase D */
  193. #define RPD_STROBE_D BIT(24)
  194. #define RPD_DATA0_D BIT(25)
  195. #define RPU_STROBE_D BIT(26)
  196. #define RPU_DATA0_D BIT(27)
  197. #define XUSB_AO_UTMIP_PAD_CFG(x) (0x130 + (x) * 4)
  198. #define FSLS_USE_XUSB_AO BIT(3)
  199. #define TRK_CTRL_USE_XUSB_AO BIT(4)
  200. #define RPD_CTRL_USE_XUSB_AO BIT(5)
  201. #define RPU_USE_XUSB_AO BIT(6)
  202. #define VREG_USE_XUSB_AO BIT(7)
  203. #define USBOP_VAL_PD BIT(8)
  204. #define USBON_VAL_PD BIT(9)
  205. #define E_DPD_OVRD_EN BIT(10)
  206. #define E_DPD_OVRD_VAL BIT(11)
  207. #define XUSB_AO_UHSIC_PAD_CFG(x) (0x150 + (x) * 4)
  208. #define STROBE_VAL_PD BIT(0)
  209. #define DATA0_VAL_PD BIT(1)
  210. #define USE_XUSB_AO BIT(4)
  211. #define TEGRA_UTMI_PAD_MAX 4
  212. #define TEGRA186_LANE(_name, _offset, _shift, _mask, _type) \
  213. { \
  214. .name = _name, \
  215. .offset = _offset, \
  216. .shift = _shift, \
  217. .mask = _mask, \
  218. .num_funcs = ARRAY_SIZE(tegra186_##_type##_functions), \
  219. .funcs = tegra186_##_type##_functions, \
  220. }
  221. struct tegra_xusb_fuse_calibration {
  222. u32 *hs_curr_level;
  223. u32 hs_squelch;
  224. u32 hs_term_range_adj;
  225. u32 rpd_ctrl;
  226. };
  227. struct tegra186_xusb_padctl_context {
  228. u32 vbus_id;
  229. u32 usb2_pad_mux;
  230. u32 usb2_port_cap;
  231. u32 ss_port_cap;
  232. };
  233. struct tegra186_xusb_padctl {
  234. struct tegra_xusb_padctl base;
  235. void __iomem *ao_regs;
  236. struct tegra_xusb_fuse_calibration calib;
  237. /* UTMI bias and tracking */
  238. struct clk *usb2_trk_clk;
  239. DECLARE_BITMAP(utmi_pad_enabled, TEGRA_UTMI_PAD_MAX);
  240. /* padctl context */
  241. struct tegra186_xusb_padctl_context context;
  242. };
  243. static inline void ao_writel(struct tegra186_xusb_padctl *priv, u32 value, unsigned int offset)
  244. {
  245. writel(value, priv->ao_regs + offset);
  246. }
  247. static inline u32 ao_readl(struct tegra186_xusb_padctl *priv, unsigned int offset)
  248. {
  249. return readl(priv->ao_regs + offset);
  250. }
  251. static inline struct tegra186_xusb_padctl *
  252. to_tegra186_xusb_padctl(struct tegra_xusb_padctl *padctl)
  253. {
  254. return container_of(padctl, struct tegra186_xusb_padctl, base);
  255. }
  256. /* USB 2.0 UTMI PHY support */
  257. static struct tegra_xusb_lane *
  258. tegra186_usb2_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np,
  259. unsigned int index)
  260. {
  261. struct tegra_xusb_usb2_lane *usb2;
  262. int err;
  263. usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL);
  264. if (!usb2)
  265. return ERR_PTR(-ENOMEM);
  266. INIT_LIST_HEAD(&usb2->base.list);
  267. usb2->base.soc = &pad->soc->lanes[index];
  268. usb2->base.index = index;
  269. usb2->base.pad = pad;
  270. usb2->base.np = np;
  271. err = tegra_xusb_lane_parse_dt(&usb2->base, np);
  272. if (err < 0) {
  273. kfree(usb2);
  274. return ERR_PTR(err);
  275. }
  276. return &usb2->base;
  277. }
  278. static void tegra186_usb2_lane_remove(struct tegra_xusb_lane *lane)
  279. {
  280. struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane);
  281. kfree(usb2);
  282. }
  283. static int tegra186_utmi_enable_phy_sleepwalk(struct tegra_xusb_lane *lane,
  284. enum usb_device_speed speed)
  285. {
  286. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  287. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  288. unsigned int index = lane->index;
  289. u32 value;
  290. mutex_lock(&padctl->lock);
  291. /* ensure sleepwalk logic is disabled */
  292. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  293. value &= ~MASTER_ENABLE;
  294. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  295. /* ensure sleepwalk logics are in low power mode */
  296. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  297. value |= MASTER_CFG_SEL;
  298. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  299. /* set debounce time */
  300. value = ao_readl(priv, XUSB_AO_USB_DEBOUNCE_DEL);
  301. value &= ~UTMIP_LINE_DEB_CNT(~0);
  302. value |= UTMIP_LINE_DEB_CNT(1);
  303. ao_writel(priv, value, XUSB_AO_USB_DEBOUNCE_DEL);
  304. /* ensure fake events of sleepwalk logic are desiabled */
  305. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  306. value &= ~(FAKE_USBOP_VAL | FAKE_USBON_VAL |
  307. FAKE_USBOP_EN | FAKE_USBON_EN);
  308. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  309. /* ensure wake events of sleepwalk logic are not latched */
  310. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  311. value &= ~LINE_WAKEUP_EN;
  312. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  313. /* disable wake event triggers of sleepwalk logic */
  314. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  315. value &= ~WAKE_VAL(~0);
  316. value |= WAKE_VAL_NONE;
  317. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  318. /* power down the line state detectors of the pad */
  319. value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
  320. value |= (USBOP_VAL_PD | USBON_VAL_PD);
  321. ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
  322. /* save state per speed */
  323. value = ao_readl(priv, XUSB_AO_UTMIP_SAVED_STATE(index));
  324. value &= ~SPEED(~0);
  325. switch (speed) {
  326. case USB_SPEED_HIGH:
  327. value |= UTMI_HS;
  328. break;
  329. case USB_SPEED_FULL:
  330. value |= UTMI_FS;
  331. break;
  332. case USB_SPEED_LOW:
  333. value |= UTMI_LS;
  334. break;
  335. default:
  336. value |= UTMI_RST;
  337. break;
  338. }
  339. ao_writel(priv, value, XUSB_AO_UTMIP_SAVED_STATE(index));
  340. /* enable the trigger of the sleepwalk logic */
  341. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  342. value |= LINEVAL_WALK_EN;
  343. value &= ~WAKE_WALK_EN;
  344. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  345. /* reset the walk pointer and clear the alarm of the sleepwalk logic,
  346. * as well as capture the configuration of the USB2.0 pad
  347. */
  348. value = ao_readl(priv, XUSB_AO_UTMIP_TRIGGERS(index));
  349. value |= (CLR_WALK_PTR | CLR_WAKE_ALARM | CAP_CFG);
  350. ao_writel(priv, value, XUSB_AO_UTMIP_TRIGGERS(index));
  351. /* setup the pull-ups and pull-downs of the signals during the four
  352. * stages of sleepwalk.
  353. * if device is connected, program sleepwalk logic to maintain a J and
  354. * keep driving K upon seeing remote wake.
  355. */
  356. value = USBOP_RPD_A | USBOP_RPD_B | USBOP_RPD_C | USBOP_RPD_D;
  357. value |= USBON_RPD_A | USBON_RPD_B | USBON_RPD_C | USBON_RPD_D;
  358. switch (speed) {
  359. case USB_SPEED_HIGH:
  360. case USB_SPEED_FULL:
  361. /* J state: D+/D- = high/low, K state: D+/D- = low/high */
  362. value |= HIGHZ_A;
  363. value |= AP_A;
  364. value |= AN_B | AN_C | AN_D;
  365. if (padctl->soc->supports_lp_cfg_en)
  366. value |= MASTER_ENABLE_B_C_D;
  367. break;
  368. case USB_SPEED_LOW:
  369. /* J state: D+/D- = low/high, K state: D+/D- = high/low */
  370. value |= HIGHZ_A;
  371. value |= AN_A;
  372. value |= AP_B | AP_C | AP_D;
  373. if (padctl->soc->supports_lp_cfg_en)
  374. value |= MASTER_ENABLE_B_C_D;
  375. break;
  376. default:
  377. value |= HIGHZ_A | HIGHZ_B | HIGHZ_C | HIGHZ_D;
  378. break;
  379. }
  380. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK(index));
  381. /* power up the line state detectors of the pad */
  382. value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
  383. value &= ~(USBOP_VAL_PD | USBON_VAL_PD);
  384. ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
  385. usleep_range(150, 200);
  386. /* switch the electric control of the USB2.0 pad to XUSB_AO */
  387. value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
  388. value |= FSLS_USE_XUSB_AO | TRK_CTRL_USE_XUSB_AO | RPD_CTRL_USE_XUSB_AO |
  389. RPU_USE_XUSB_AO | VREG_USE_XUSB_AO;
  390. ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
  391. /* set the wake signaling trigger events */
  392. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  393. value &= ~WAKE_VAL(~0);
  394. value |= WAKE_VAL_ANY;
  395. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  396. /* enable the wake detection */
  397. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  398. value |= MASTER_ENABLE | LINE_WAKEUP_EN;
  399. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  400. mutex_unlock(&padctl->lock);
  401. return 0;
  402. }
  403. static int tegra186_utmi_disable_phy_sleepwalk(struct tegra_xusb_lane *lane)
  404. {
  405. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  406. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  407. unsigned int index = lane->index;
  408. u32 value;
  409. mutex_lock(&padctl->lock);
  410. /* disable the wake detection */
  411. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  412. value &= ~(MASTER_ENABLE | LINE_WAKEUP_EN);
  413. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  414. /* switch the electric control of the USB2.0 pad to XUSB vcore logic */
  415. value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
  416. value &= ~(FSLS_USE_XUSB_AO | TRK_CTRL_USE_XUSB_AO | RPD_CTRL_USE_XUSB_AO |
  417. RPU_USE_XUSB_AO | VREG_USE_XUSB_AO);
  418. ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
  419. /* disable wake event triggers of sleepwalk logic */
  420. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  421. value &= ~WAKE_VAL(~0);
  422. value |= WAKE_VAL_NONE;
  423. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK_CFG(index));
  424. if (padctl->soc->supports_lp_cfg_en) {
  425. /* disable the four stages of sleepwalk */
  426. value = ao_readl(priv, XUSB_AO_UTMIP_SLEEPWALK(index));
  427. value &= ~(MASTER_ENABLE_A | MASTER_ENABLE_B_C_D);
  428. ao_writel(priv, value, XUSB_AO_UTMIP_SLEEPWALK(index));
  429. }
  430. /* power down the line state detectors of the port */
  431. value = ao_readl(priv, XUSB_AO_UTMIP_PAD_CFG(index));
  432. value |= USBOP_VAL_PD | USBON_VAL_PD;
  433. ao_writel(priv, value, XUSB_AO_UTMIP_PAD_CFG(index));
  434. /* clear alarm of the sleepwalk logic */
  435. value = ao_readl(priv, XUSB_AO_UTMIP_TRIGGERS(index));
  436. value |= CLR_WAKE_ALARM;
  437. ao_writel(priv, value, XUSB_AO_UTMIP_TRIGGERS(index));
  438. mutex_unlock(&padctl->lock);
  439. return 0;
  440. }
  441. static int tegra186_utmi_enable_phy_wake(struct tegra_xusb_lane *lane)
  442. {
  443. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  444. unsigned int index = lane->index;
  445. u32 value;
  446. mutex_lock(&padctl->lock);
  447. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  448. value &= ~ALL_WAKE_EVENTS;
  449. value |= USB2_PORT_WAKEUP_EVENT(index);
  450. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
  451. usleep_range(10, 20);
  452. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  453. value &= ~ALL_WAKE_EVENTS;
  454. value |= USB2_PORT_WAKE_INTERRUPT_ENABLE(index);
  455. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
  456. mutex_unlock(&padctl->lock);
  457. return 0;
  458. }
  459. static int tegra186_utmi_disable_phy_wake(struct tegra_xusb_lane *lane)
  460. {
  461. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  462. unsigned int index = lane->index;
  463. u32 value;
  464. mutex_lock(&padctl->lock);
  465. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  466. value &= ~ALL_WAKE_EVENTS;
  467. value &= ~USB2_PORT_WAKE_INTERRUPT_ENABLE(index);
  468. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
  469. usleep_range(10, 20);
  470. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  471. value &= ~ALL_WAKE_EVENTS;
  472. value |= USB2_PORT_WAKEUP_EVENT(index);
  473. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
  474. mutex_unlock(&padctl->lock);
  475. return 0;
  476. }
  477. static bool tegra186_utmi_phy_remote_wake_detected(struct tegra_xusb_lane *lane)
  478. {
  479. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  480. unsigned int index = lane->index;
  481. u32 value;
  482. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  483. if ((value & USB2_PORT_WAKE_INTERRUPT_ENABLE(index)) &&
  484. (value & USB2_PORT_WAKEUP_EVENT(index)))
  485. return true;
  486. return false;
  487. }
  488. static const struct tegra_xusb_lane_ops tegra186_usb2_lane_ops = {
  489. .probe = tegra186_usb2_lane_probe,
  490. .remove = tegra186_usb2_lane_remove,
  491. .enable_phy_sleepwalk = tegra186_utmi_enable_phy_sleepwalk,
  492. .disable_phy_sleepwalk = tegra186_utmi_disable_phy_sleepwalk,
  493. .enable_phy_wake = tegra186_utmi_enable_phy_wake,
  494. .disable_phy_wake = tegra186_utmi_disable_phy_wake,
  495. .remote_wake_detected = tegra186_utmi_phy_remote_wake_detected,
  496. };
  497. static void tegra186_utmi_bias_pad_power_on(struct tegra_xusb_padctl *padctl)
  498. {
  499. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  500. struct device *dev = padctl->dev;
  501. u32 value;
  502. int err;
  503. if (!bitmap_empty(priv->utmi_pad_enabled, TEGRA_UTMI_PAD_MAX))
  504. return;
  505. err = clk_prepare_enable(priv->usb2_trk_clk);
  506. if (err < 0)
  507. dev_warn(dev, "failed to enable USB2 trk clock: %d\n", err);
  508. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  509. value &= ~USB2_TRK_START_TIMER(~0);
  510. value |= USB2_TRK_START_TIMER(0x1e);
  511. value &= ~USB2_TRK_DONE_RESET_TIMER(~0);
  512. value |= USB2_TRK_DONE_RESET_TIMER(0xa);
  513. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  514. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
  515. value &= ~BIAS_PAD_PD;
  516. value &= ~HS_SQUELCH_LEVEL(~0);
  517. value |= HS_SQUELCH_LEVEL(priv->calib.hs_squelch);
  518. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
  519. udelay(1);
  520. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  521. value &= ~USB2_PD_TRK;
  522. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  523. if (padctl->soc->poll_trk_completed) {
  524. err = padctl_readl_poll(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1,
  525. USB2_TRK_COMPLETED, USB2_TRK_COMPLETED, 100);
  526. if (err) {
  527. /* The failure with polling on trk complete will not
  528. * cause the failure of powering on the bias pad.
  529. */
  530. dev_warn(dev, "failed to poll USB2 trk completed: %d\n", err);
  531. }
  532. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  533. value |= USB2_TRK_COMPLETED;
  534. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  535. } else {
  536. udelay(100);
  537. }
  538. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL2);
  539. if (padctl->soc->trk_update_on_idle)
  540. value &= ~CYA_TRK_CODE_UPDATE_ON_IDLE;
  541. if (padctl->soc->trk_hw_mode)
  542. value |= USB2_TRK_HW_MODE;
  543. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL2);
  544. if (!padctl->soc->trk_hw_mode)
  545. clk_disable_unprepare(priv->usb2_trk_clk);
  546. }
  547. static void tegra186_utmi_bias_pad_power_off(struct tegra_xusb_padctl *padctl)
  548. {
  549. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  550. u32 value;
  551. if (!bitmap_empty(priv->utmi_pad_enabled, TEGRA_UTMI_PAD_MAX))
  552. return;
  553. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  554. value |= USB2_PD_TRK;
  555. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  556. if (padctl->soc->trk_hw_mode) {
  557. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL2);
  558. value &= ~USB2_TRK_HW_MODE;
  559. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL2);
  560. clk_disable_unprepare(priv->usb2_trk_clk);
  561. }
  562. }
  563. static void tegra186_utmi_pad_power_on(struct phy *phy)
  564. {
  565. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  566. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  567. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  568. struct tegra_xusb_usb2_port *port;
  569. struct device *dev = padctl->dev;
  570. unsigned int index = lane->index;
  571. u32 value;
  572. if (!phy)
  573. return;
  574. mutex_lock(&padctl->lock);
  575. if (test_bit(index, priv->utmi_pad_enabled)) {
  576. mutex_unlock(&padctl->lock);
  577. return;
  578. }
  579. port = tegra_xusb_find_usb2_port(padctl, index);
  580. if (!port) {
  581. dev_err(dev, "no port found for USB2 lane %u\n", index);
  582. mutex_unlock(&padctl->lock);
  583. return;
  584. }
  585. dev_dbg(dev, "power on UTMI pad %u\n", index);
  586. tegra186_utmi_bias_pad_power_on(padctl);
  587. udelay(2);
  588. value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
  589. value &= ~USB2_OTG_PD;
  590. padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
  591. value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
  592. value &= ~USB2_OTG_PD_DR;
  593. padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
  594. set_bit(index, priv->utmi_pad_enabled);
  595. mutex_unlock(&padctl->lock);
  596. }
  597. static void tegra186_utmi_pad_power_down(struct phy *phy)
  598. {
  599. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  600. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  601. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  602. unsigned int index = lane->index;
  603. u32 value;
  604. if (!phy)
  605. return;
  606. mutex_lock(&padctl->lock);
  607. if (!test_bit(index, priv->utmi_pad_enabled)) {
  608. mutex_unlock(&padctl->lock);
  609. return;
  610. }
  611. dev_dbg(padctl->dev, "power down UTMI pad %u\n", index);
  612. value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
  613. value |= USB2_OTG_PD;
  614. padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
  615. value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
  616. value |= USB2_OTG_PD_DR;
  617. padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
  618. udelay(2);
  619. clear_bit(index, priv->utmi_pad_enabled);
  620. tegra186_utmi_bias_pad_power_off(padctl);
  621. mutex_unlock(&padctl->lock);
  622. }
  623. static int tegra186_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl,
  624. bool status)
  625. {
  626. u32 value;
  627. dev_dbg(padctl->dev, "%s vbus override\n", status ? "set" : "clear");
  628. value = padctl_readl(padctl, USB2_VBUS_ID);
  629. if (status) {
  630. value |= VBUS_OVERRIDE;
  631. value &= ~ID_OVERRIDE(~0);
  632. value |= ID_OVERRIDE_FLOATING;
  633. } else {
  634. value &= ~VBUS_OVERRIDE;
  635. }
  636. padctl_writel(padctl, value, USB2_VBUS_ID);
  637. return 0;
  638. }
  639. static int tegra186_xusb_padctl_id_override(struct tegra_xusb_padctl *padctl,
  640. struct tegra_xusb_usb2_port *port, bool status)
  641. {
  642. u32 value, id_override;
  643. int err = 0;
  644. dev_dbg(padctl->dev, "%s id override\n", status ? "set" : "clear");
  645. value = padctl_readl(padctl, USB2_VBUS_ID);
  646. id_override = value & ID_OVERRIDE(~0);
  647. if (status) {
  648. if (value & VBUS_OVERRIDE) {
  649. value &= ~VBUS_OVERRIDE;
  650. padctl_writel(padctl, value, USB2_VBUS_ID);
  651. usleep_range(1000, 2000);
  652. value = padctl_readl(padctl, USB2_VBUS_ID);
  653. }
  654. if (id_override != ID_OVERRIDE_GROUNDED) {
  655. value &= ~ID_OVERRIDE(~0);
  656. value |= ID_OVERRIDE_GROUNDED;
  657. padctl_writel(padctl, value, USB2_VBUS_ID);
  658. err = regulator_enable(port->supply);
  659. if (err) {
  660. dev_err(padctl->dev, "Failed to enable regulator: %d\n", err);
  661. return err;
  662. }
  663. }
  664. } else {
  665. if (id_override == ID_OVERRIDE_GROUNDED) {
  666. /*
  667. * The regulator is disabled only when the role transitions
  668. * from USB_ROLE_HOST to USB_ROLE_NONE.
  669. */
  670. err = regulator_disable(port->supply);
  671. if (err) {
  672. dev_err(padctl->dev, "Failed to disable regulator: %d\n", err);
  673. return err;
  674. }
  675. value &= ~ID_OVERRIDE(~0);
  676. value |= ID_OVERRIDE_FLOATING;
  677. padctl_writel(padctl, value, USB2_VBUS_ID);
  678. }
  679. }
  680. return 0;
  681. }
  682. static int tegra186_utmi_phy_set_mode(struct phy *phy, enum phy_mode mode,
  683. int submode)
  684. {
  685. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  686. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  687. struct tegra_xusb_usb2_port *port = tegra_xusb_find_usb2_port(padctl,
  688. lane->index);
  689. int err = 0;
  690. mutex_lock(&padctl->lock);
  691. dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode);
  692. if (mode == PHY_MODE_USB_OTG) {
  693. if (submode == USB_ROLE_HOST) {
  694. err = tegra186_xusb_padctl_id_override(padctl, port, true);
  695. if (err)
  696. goto out;
  697. } else if (submode == USB_ROLE_DEVICE) {
  698. tegra186_xusb_padctl_vbus_override(padctl, true);
  699. } else if (submode == USB_ROLE_NONE) {
  700. err = tegra186_xusb_padctl_id_override(padctl, port, false);
  701. if (err)
  702. goto out;
  703. tegra186_xusb_padctl_vbus_override(padctl, false);
  704. }
  705. }
  706. out:
  707. mutex_unlock(&padctl->lock);
  708. return err;
  709. }
  710. static int tegra186_utmi_phy_power_on(struct phy *phy)
  711. {
  712. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  713. struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane);
  714. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  715. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  716. struct tegra_xusb_usb2_port *port;
  717. unsigned int index = lane->index;
  718. struct device *dev = padctl->dev;
  719. u32 value;
  720. port = tegra_xusb_find_usb2_port(padctl, index);
  721. if (!port) {
  722. dev_err(dev, "no port found for USB2 lane %u\n", index);
  723. return -ENODEV;
  724. }
  725. value = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX);
  726. value &= ~(USB2_PORT_MASK << USB2_PORT_SHIFT(index));
  727. value |= (PORT_XUSB << USB2_PORT_SHIFT(index));
  728. padctl_writel(padctl, value, XUSB_PADCTL_USB2_PAD_MUX);
  729. value = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP);
  730. value &= ~(PORT_CAP_MASK << PORTX_CAP_SHIFT(index));
  731. if (port->mode == USB_DR_MODE_UNKNOWN)
  732. value |= (PORT_CAP_DISABLED << PORTX_CAP_SHIFT(index));
  733. else if (port->mode == USB_DR_MODE_PERIPHERAL)
  734. value |= (PORT_CAP_DEVICE << PORTX_CAP_SHIFT(index));
  735. else if (port->mode == USB_DR_MODE_HOST)
  736. value |= (PORT_CAP_HOST << PORTX_CAP_SHIFT(index));
  737. else if (port->mode == USB_DR_MODE_OTG)
  738. value |= (PORT_CAP_OTG << PORTX_CAP_SHIFT(index));
  739. padctl_writel(padctl, value, XUSB_PADCTL_USB2_PORT_CAP);
  740. value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
  741. value &= ~USB2_OTG_PD_ZI;
  742. value |= TERM_SEL;
  743. value &= ~HS_CURR_LEVEL(~0);
  744. if (usb2->hs_curr_level_offset) {
  745. int hs_current_level;
  746. hs_current_level = (int)priv->calib.hs_curr_level[index] +
  747. usb2->hs_curr_level_offset;
  748. if (hs_current_level < 0)
  749. hs_current_level = 0;
  750. if (hs_current_level > 0x3f)
  751. hs_current_level = 0x3f;
  752. value |= HS_CURR_LEVEL(hs_current_level);
  753. } else {
  754. value |= HS_CURR_LEVEL(priv->calib.hs_curr_level[index]);
  755. }
  756. padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
  757. value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
  758. value &= ~TERM_RANGE_ADJ(~0);
  759. value |= TERM_RANGE_ADJ(priv->calib.hs_term_range_adj);
  760. value &= ~RPD_CTRL(~0);
  761. value |= RPD_CTRL(priv->calib.rpd_ctrl);
  762. padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
  763. tegra186_utmi_pad_power_on(phy);
  764. return 0;
  765. }
  766. static int tegra186_utmi_phy_power_off(struct phy *phy)
  767. {
  768. tegra186_utmi_pad_power_down(phy);
  769. return 0;
  770. }
  771. static int tegra186_utmi_phy_init(struct phy *phy)
  772. {
  773. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  774. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  775. struct tegra_xusb_usb2_port *port;
  776. unsigned int index = lane->index;
  777. struct device *dev = padctl->dev;
  778. int err;
  779. u32 reg;
  780. port = tegra_xusb_find_usb2_port(padctl, index);
  781. if (!port) {
  782. dev_err(dev, "no port found for USB2 lane %u\n", index);
  783. return -ENODEV;
  784. }
  785. if (port->mode == USB_DR_MODE_OTG ||
  786. port->mode == USB_DR_MODE_PERIPHERAL) {
  787. /* reset VBUS&ID OVERRIDE */
  788. reg = padctl_readl(padctl, USB2_VBUS_ID);
  789. reg &= ~VBUS_OVERRIDE;
  790. reg &= ~ID_OVERRIDE(~0);
  791. reg |= ID_OVERRIDE_FLOATING;
  792. padctl_writel(padctl, reg, USB2_VBUS_ID);
  793. }
  794. if (port->supply && port->mode == USB_DR_MODE_HOST) {
  795. err = regulator_enable(port->supply);
  796. if (err) {
  797. dev_err(dev, "failed to enable port %u VBUS: %d\n",
  798. index, err);
  799. return err;
  800. }
  801. }
  802. return 0;
  803. }
  804. static int tegra186_utmi_phy_exit(struct phy *phy)
  805. {
  806. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  807. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  808. struct tegra_xusb_usb2_port *port;
  809. unsigned int index = lane->index;
  810. struct device *dev = padctl->dev;
  811. int err;
  812. port = tegra_xusb_find_usb2_port(padctl, index);
  813. if (!port) {
  814. dev_err(dev, "no port found for USB2 lane %u\n", index);
  815. return -ENODEV;
  816. }
  817. if (port->supply && port->mode == USB_DR_MODE_HOST) {
  818. err = regulator_disable(port->supply);
  819. if (err) {
  820. dev_err(dev, "failed to disable port %u VBUS: %d\n",
  821. index, err);
  822. return err;
  823. }
  824. }
  825. return 0;
  826. }
  827. static const struct phy_ops utmi_phy_ops = {
  828. .init = tegra186_utmi_phy_init,
  829. .exit = tegra186_utmi_phy_exit,
  830. .power_on = tegra186_utmi_phy_power_on,
  831. .power_off = tegra186_utmi_phy_power_off,
  832. .set_mode = tegra186_utmi_phy_set_mode,
  833. .owner = THIS_MODULE,
  834. };
  835. static struct tegra_xusb_pad *
  836. tegra186_usb2_pad_probe(struct tegra_xusb_padctl *padctl,
  837. const struct tegra_xusb_pad_soc *soc,
  838. struct device_node *np)
  839. {
  840. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  841. struct tegra_xusb_usb2_pad *usb2;
  842. struct tegra_xusb_pad *pad;
  843. int err;
  844. usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL);
  845. if (!usb2)
  846. return ERR_PTR(-ENOMEM);
  847. pad = &usb2->base;
  848. pad->ops = &tegra186_usb2_lane_ops;
  849. pad->soc = soc;
  850. err = tegra_xusb_pad_init(pad, padctl, np);
  851. if (err < 0) {
  852. kfree(usb2);
  853. goto out;
  854. }
  855. priv->usb2_trk_clk = devm_clk_get(&pad->dev, "trk");
  856. if (IS_ERR(priv->usb2_trk_clk)) {
  857. err = PTR_ERR(priv->usb2_trk_clk);
  858. dev_dbg(&pad->dev, "failed to get usb2 trk clock: %d\n", err);
  859. goto unregister;
  860. }
  861. err = tegra_xusb_pad_register(pad, &utmi_phy_ops);
  862. if (err < 0)
  863. goto unregister;
  864. dev_set_drvdata(&pad->dev, pad);
  865. return pad;
  866. unregister:
  867. device_unregister(&pad->dev);
  868. out:
  869. return ERR_PTR(err);
  870. }
  871. static void tegra186_usb2_pad_remove(struct tegra_xusb_pad *pad)
  872. {
  873. struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad);
  874. kfree(usb2);
  875. }
  876. static const struct tegra_xusb_pad_ops tegra186_usb2_pad_ops = {
  877. .probe = tegra186_usb2_pad_probe,
  878. .remove = tegra186_usb2_pad_remove,
  879. };
  880. static const char * const tegra186_usb2_functions[] = {
  881. "xusb",
  882. };
  883. static int tegra186_usb2_port_enable(struct tegra_xusb_port *port)
  884. {
  885. return 0;
  886. }
  887. static void tegra186_usb2_port_disable(struct tegra_xusb_port *port)
  888. {
  889. }
  890. static struct tegra_xusb_lane *
  891. tegra186_usb2_port_map(struct tegra_xusb_port *port)
  892. {
  893. return tegra_xusb_find_lane(port->padctl, "usb2", port->index);
  894. }
  895. static const struct tegra_xusb_port_ops tegra186_usb2_port_ops = {
  896. .release = tegra_xusb_usb2_port_release,
  897. .remove = tegra_xusb_usb2_port_remove,
  898. .enable = tegra186_usb2_port_enable,
  899. .disable = tegra186_usb2_port_disable,
  900. .map = tegra186_usb2_port_map,
  901. };
  902. /* SuperSpeed PHY support */
  903. static struct tegra_xusb_lane *
  904. tegra186_usb3_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np,
  905. unsigned int index)
  906. {
  907. struct tegra_xusb_usb3_lane *usb3;
  908. int err;
  909. usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL);
  910. if (!usb3)
  911. return ERR_PTR(-ENOMEM);
  912. INIT_LIST_HEAD(&usb3->base.list);
  913. usb3->base.soc = &pad->soc->lanes[index];
  914. usb3->base.index = index;
  915. usb3->base.pad = pad;
  916. usb3->base.np = np;
  917. err = tegra_xusb_lane_parse_dt(&usb3->base, np);
  918. if (err < 0) {
  919. kfree(usb3);
  920. return ERR_PTR(err);
  921. }
  922. return &usb3->base;
  923. }
  924. static void tegra186_usb3_lane_remove(struct tegra_xusb_lane *lane)
  925. {
  926. struct tegra_xusb_usb3_lane *usb3 = to_usb3_lane(lane);
  927. kfree(usb3);
  928. }
  929. static int tegra186_usb3_enable_phy_sleepwalk(struct tegra_xusb_lane *lane,
  930. enum usb_device_speed speed)
  931. {
  932. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  933. unsigned int index = lane->index;
  934. u32 value;
  935. mutex_lock(&padctl->lock);
  936. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  937. value |= SSPX_ELPG_CLAMP_EN_EARLY(index);
  938. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  939. usleep_range(100, 200);
  940. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  941. value |= SSPX_ELPG_CLAMP_EN(index);
  942. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  943. usleep_range(250, 350);
  944. mutex_unlock(&padctl->lock);
  945. return 0;
  946. }
  947. static int tegra186_usb3_disable_phy_sleepwalk(struct tegra_xusb_lane *lane)
  948. {
  949. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  950. unsigned int index = lane->index;
  951. u32 value;
  952. mutex_lock(&padctl->lock);
  953. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  954. value &= ~SSPX_ELPG_CLAMP_EN_EARLY(index);
  955. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  956. usleep_range(100, 200);
  957. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  958. value &= ~SSPX_ELPG_CLAMP_EN(index);
  959. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  960. mutex_unlock(&padctl->lock);
  961. return 0;
  962. }
  963. static int tegra186_usb3_enable_phy_wake(struct tegra_xusb_lane *lane)
  964. {
  965. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  966. unsigned int index = lane->index;
  967. u32 value;
  968. mutex_lock(&padctl->lock);
  969. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  970. value &= ~ALL_WAKE_EVENTS;
  971. value |= SS_PORT_WAKEUP_EVENT(index);
  972. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
  973. usleep_range(10, 20);
  974. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  975. value &= ~ALL_WAKE_EVENTS;
  976. value |= SS_PORT_WAKE_INTERRUPT_ENABLE(index);
  977. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
  978. mutex_unlock(&padctl->lock);
  979. return 0;
  980. }
  981. static int tegra186_usb3_disable_phy_wake(struct tegra_xusb_lane *lane)
  982. {
  983. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  984. unsigned int index = lane->index;
  985. u32 value;
  986. mutex_lock(&padctl->lock);
  987. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  988. value &= ~ALL_WAKE_EVENTS;
  989. value &= ~SS_PORT_WAKE_INTERRUPT_ENABLE(index);
  990. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
  991. usleep_range(10, 20);
  992. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  993. value &= ~ALL_WAKE_EVENTS;
  994. value |= SS_PORT_WAKEUP_EVENT(index);
  995. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
  996. mutex_unlock(&padctl->lock);
  997. return 0;
  998. }
  999. static bool tegra186_usb3_phy_remote_wake_detected(struct tegra_xusb_lane *lane)
  1000. {
  1001. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  1002. unsigned int index = lane->index;
  1003. u32 value;
  1004. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
  1005. if ((value & SS_PORT_WAKE_INTERRUPT_ENABLE(index)) && (value & SS_PORT_WAKEUP_EVENT(index)))
  1006. return true;
  1007. return false;
  1008. }
  1009. static const struct tegra_xusb_lane_ops tegra186_usb3_lane_ops = {
  1010. .probe = tegra186_usb3_lane_probe,
  1011. .remove = tegra186_usb3_lane_remove,
  1012. .enable_phy_sleepwalk = tegra186_usb3_enable_phy_sleepwalk,
  1013. .disable_phy_sleepwalk = tegra186_usb3_disable_phy_sleepwalk,
  1014. .enable_phy_wake = tegra186_usb3_enable_phy_wake,
  1015. .disable_phy_wake = tegra186_usb3_disable_phy_wake,
  1016. .remote_wake_detected = tegra186_usb3_phy_remote_wake_detected,
  1017. };
  1018. static int tegra186_usb3_port_enable(struct tegra_xusb_port *port)
  1019. {
  1020. return 0;
  1021. }
  1022. static void tegra186_usb3_port_disable(struct tegra_xusb_port *port)
  1023. {
  1024. }
  1025. static struct tegra_xusb_lane *
  1026. tegra186_usb3_port_map(struct tegra_xusb_port *port)
  1027. {
  1028. return tegra_xusb_find_lane(port->padctl, "usb3", port->index);
  1029. }
  1030. static const struct tegra_xusb_port_ops tegra186_usb3_port_ops = {
  1031. .release = tegra_xusb_usb3_port_release,
  1032. .enable = tegra186_usb3_port_enable,
  1033. .disable = tegra186_usb3_port_disable,
  1034. .map = tegra186_usb3_port_map,
  1035. };
  1036. static int tegra186_usb3_phy_power_on(struct phy *phy)
  1037. {
  1038. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1039. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  1040. struct tegra_xusb_usb3_port *port;
  1041. struct tegra_xusb_usb2_port *usb2;
  1042. unsigned int index = lane->index;
  1043. struct device *dev = padctl->dev;
  1044. u32 value;
  1045. port = tegra_xusb_find_usb3_port(padctl, index);
  1046. if (!port) {
  1047. dev_err(dev, "no port found for USB3 lane %u\n", index);
  1048. return -ENODEV;
  1049. }
  1050. usb2 = tegra_xusb_find_usb2_port(padctl, port->port);
  1051. if (!usb2) {
  1052. dev_err(dev, "no companion port found for USB3 lane %u\n",
  1053. index);
  1054. return -ENODEV;
  1055. }
  1056. mutex_lock(&padctl->lock);
  1057. value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_CAP);
  1058. value &= ~(PORT_CAP_MASK << PORTX_CAP_SHIFT(index));
  1059. if (usb2->mode == USB_DR_MODE_UNKNOWN)
  1060. value |= (PORT_CAP_DISABLED << PORTX_CAP_SHIFT(index));
  1061. else if (usb2->mode == USB_DR_MODE_PERIPHERAL)
  1062. value |= (PORT_CAP_DEVICE << PORTX_CAP_SHIFT(index));
  1063. else if (usb2->mode == USB_DR_MODE_HOST)
  1064. value |= (PORT_CAP_HOST << PORTX_CAP_SHIFT(index));
  1065. else if (usb2->mode == USB_DR_MODE_OTG)
  1066. value |= (PORT_CAP_OTG << PORTX_CAP_SHIFT(index));
  1067. padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_CAP);
  1068. if (padctl->soc->supports_gen2 && port->disable_gen2) {
  1069. value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_CFG);
  1070. value &= ~(PORTX_SPEED_SUPPORT_MASK <<
  1071. PORTX_SPEED_SUPPORT_SHIFT(index));
  1072. value |= (PORT_SPEED_SUPPORT_GEN1 <<
  1073. PORTX_SPEED_SUPPORT_SHIFT(index));
  1074. padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_CFG);
  1075. }
  1076. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  1077. value &= ~SSPX_ELPG_VCORE_DOWN(index);
  1078. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  1079. usleep_range(100, 200);
  1080. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  1081. value &= ~SSPX_ELPG_CLAMP_EN_EARLY(index);
  1082. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  1083. usleep_range(100, 200);
  1084. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  1085. value &= ~SSPX_ELPG_CLAMP_EN(index);
  1086. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  1087. mutex_unlock(&padctl->lock);
  1088. return 0;
  1089. }
  1090. static int tegra186_usb3_phy_power_off(struct phy *phy)
  1091. {
  1092. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1093. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  1094. struct tegra_xusb_usb3_port *port;
  1095. unsigned int index = lane->index;
  1096. struct device *dev = padctl->dev;
  1097. u32 value;
  1098. port = tegra_xusb_find_usb3_port(padctl, index);
  1099. if (!port) {
  1100. dev_err(dev, "no port found for USB3 lane %u\n", index);
  1101. return -ENODEV;
  1102. }
  1103. mutex_lock(&padctl->lock);
  1104. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  1105. value |= SSPX_ELPG_CLAMP_EN_EARLY(index);
  1106. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  1107. usleep_range(100, 200);
  1108. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  1109. value |= SSPX_ELPG_CLAMP_EN(index);
  1110. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  1111. usleep_range(250, 350);
  1112. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM_1);
  1113. value |= SSPX_ELPG_VCORE_DOWN(index);
  1114. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM_1);
  1115. mutex_unlock(&padctl->lock);
  1116. return 0;
  1117. }
  1118. static int tegra186_usb3_phy_init(struct phy *phy)
  1119. {
  1120. return 0;
  1121. }
  1122. static int tegra186_usb3_phy_exit(struct phy *phy)
  1123. {
  1124. return 0;
  1125. }
  1126. static const struct phy_ops usb3_phy_ops = {
  1127. .init = tegra186_usb3_phy_init,
  1128. .exit = tegra186_usb3_phy_exit,
  1129. .power_on = tegra186_usb3_phy_power_on,
  1130. .power_off = tegra186_usb3_phy_power_off,
  1131. .owner = THIS_MODULE,
  1132. };
  1133. static struct tegra_xusb_pad *
  1134. tegra186_usb3_pad_probe(struct tegra_xusb_padctl *padctl,
  1135. const struct tegra_xusb_pad_soc *soc,
  1136. struct device_node *np)
  1137. {
  1138. struct tegra_xusb_usb3_pad *usb3;
  1139. struct tegra_xusb_pad *pad;
  1140. int err;
  1141. usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL);
  1142. if (!usb3)
  1143. return ERR_PTR(-ENOMEM);
  1144. pad = &usb3->base;
  1145. pad->ops = &tegra186_usb3_lane_ops;
  1146. pad->soc = soc;
  1147. err = tegra_xusb_pad_init(pad, padctl, np);
  1148. if (err < 0) {
  1149. kfree(usb3);
  1150. goto out;
  1151. }
  1152. err = tegra_xusb_pad_register(pad, &usb3_phy_ops);
  1153. if (err < 0)
  1154. goto unregister;
  1155. dev_set_drvdata(&pad->dev, pad);
  1156. return pad;
  1157. unregister:
  1158. device_unregister(&pad->dev);
  1159. out:
  1160. return ERR_PTR(err);
  1161. }
  1162. static void tegra186_usb3_pad_remove(struct tegra_xusb_pad *pad)
  1163. {
  1164. struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad);
  1165. kfree(usb2);
  1166. }
  1167. static const struct tegra_xusb_pad_ops tegra186_usb3_pad_ops = {
  1168. .probe = tegra186_usb3_pad_probe,
  1169. .remove = tegra186_usb3_pad_remove,
  1170. };
  1171. static const char * const tegra186_usb3_functions[] = {
  1172. "xusb",
  1173. };
  1174. static int
  1175. tegra186_xusb_read_fuse_calibration(struct tegra186_xusb_padctl *padctl)
  1176. {
  1177. struct device *dev = padctl->base.dev;
  1178. unsigned int i, count;
  1179. u32 value, *level;
  1180. int err;
  1181. count = padctl->base.soc->ports.usb2.count;
  1182. level = devm_kcalloc(dev, count, sizeof(u32), GFP_KERNEL);
  1183. if (!level)
  1184. return -ENOMEM;
  1185. err = tegra_fuse_readl(TEGRA_FUSE_SKU_CALIB_0, &value);
  1186. if (err)
  1187. return dev_err_probe(dev, err,
  1188. "failed to read calibration fuse\n");
  1189. dev_dbg(dev, "FUSE_USB_CALIB_0 %#x\n", value);
  1190. for (i = 0; i < count; i++)
  1191. level[i] = (value >> HS_CURR_LEVEL_PADX_SHIFT(i)) &
  1192. HS_CURR_LEVEL_PAD_MASK;
  1193. padctl->calib.hs_curr_level = level;
  1194. padctl->calib.hs_squelch = (value >> HS_SQUELCH_SHIFT) &
  1195. HS_SQUELCH_MASK;
  1196. padctl->calib.hs_term_range_adj = (value >> HS_TERM_RANGE_ADJ_SHIFT) &
  1197. HS_TERM_RANGE_ADJ_MASK;
  1198. err = tegra_fuse_readl(TEGRA_FUSE_USB_CALIB_EXT_0, &value);
  1199. if (err) {
  1200. dev_err(dev, "failed to read calibration fuse: %d\n", err);
  1201. return err;
  1202. }
  1203. dev_dbg(dev, "FUSE_USB_CALIB_EXT_0 %#x\n", value);
  1204. padctl->calib.rpd_ctrl = (value >> RPD_CTRL_SHIFT) & RPD_CTRL_MASK;
  1205. return 0;
  1206. }
  1207. static struct tegra_xusb_padctl *
  1208. tegra186_xusb_padctl_probe(struct device *dev,
  1209. const struct tegra_xusb_padctl_soc *soc)
  1210. {
  1211. struct platform_device *pdev = to_platform_device(dev);
  1212. struct tegra186_xusb_padctl *priv;
  1213. struct resource *res;
  1214. int err;
  1215. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  1216. if (!priv)
  1217. return ERR_PTR(-ENOMEM);
  1218. priv->base.dev = dev;
  1219. priv->base.soc = soc;
  1220. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ao");
  1221. priv->ao_regs = devm_ioremap_resource(dev, res);
  1222. if (IS_ERR(priv->ao_regs))
  1223. return ERR_CAST(priv->ao_regs);
  1224. err = tegra186_xusb_read_fuse_calibration(priv);
  1225. if (err < 0)
  1226. return ERR_PTR(err);
  1227. return &priv->base;
  1228. }
  1229. static void tegra186_xusb_padctl_save(struct tegra_xusb_padctl *padctl)
  1230. {
  1231. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  1232. priv->context.vbus_id = padctl_readl(padctl, USB2_VBUS_ID);
  1233. priv->context.usb2_pad_mux = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX);
  1234. priv->context.usb2_port_cap = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP);
  1235. priv->context.ss_port_cap = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_CAP);
  1236. }
  1237. static void tegra186_xusb_padctl_restore(struct tegra_xusb_padctl *padctl)
  1238. {
  1239. struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
  1240. padctl_writel(padctl, priv->context.usb2_pad_mux, XUSB_PADCTL_USB2_PAD_MUX);
  1241. padctl_writel(padctl, priv->context.usb2_port_cap, XUSB_PADCTL_USB2_PORT_CAP);
  1242. padctl_writel(padctl, priv->context.ss_port_cap, XUSB_PADCTL_SS_PORT_CAP);
  1243. padctl_writel(padctl, priv->context.vbus_id, USB2_VBUS_ID);
  1244. }
  1245. static int tegra186_xusb_padctl_suspend_noirq(struct tegra_xusb_padctl *padctl)
  1246. {
  1247. tegra186_xusb_padctl_save(padctl);
  1248. return 0;
  1249. }
  1250. static int tegra186_xusb_padctl_resume_noirq(struct tegra_xusb_padctl *padctl)
  1251. {
  1252. tegra186_xusb_padctl_restore(padctl);
  1253. return 0;
  1254. }
  1255. static void tegra186_xusb_padctl_remove(struct tegra_xusb_padctl *padctl)
  1256. {
  1257. }
  1258. static const struct tegra_xusb_padctl_ops tegra186_xusb_padctl_ops = {
  1259. .probe = tegra186_xusb_padctl_probe,
  1260. .remove = tegra186_xusb_padctl_remove,
  1261. .suspend_noirq = tegra186_xusb_padctl_suspend_noirq,
  1262. .resume_noirq = tegra186_xusb_padctl_resume_noirq,
  1263. .vbus_override = tegra186_xusb_padctl_vbus_override,
  1264. .utmi_pad_power_on = tegra186_utmi_pad_power_on,
  1265. .utmi_pad_power_down = tegra186_utmi_pad_power_down,
  1266. };
  1267. #if IS_ENABLED(CONFIG_ARCH_TEGRA_186_SOC)
  1268. static const char * const tegra186_xusb_padctl_supply_names[] = {
  1269. "avdd-pll-erefeut",
  1270. "avdd-usb",
  1271. "vclamp-usb",
  1272. "vddio-hsic",
  1273. };
  1274. static const struct tegra_xusb_lane_soc tegra186_usb2_lanes[] = {
  1275. TEGRA186_LANE("usb2-0", 0, 0, 0, usb2),
  1276. TEGRA186_LANE("usb2-1", 0, 0, 0, usb2),
  1277. TEGRA186_LANE("usb2-2", 0, 0, 0, usb2),
  1278. };
  1279. static const struct tegra_xusb_pad_soc tegra186_usb2_pad = {
  1280. .name = "usb2",
  1281. .num_lanes = ARRAY_SIZE(tegra186_usb2_lanes),
  1282. .lanes = tegra186_usb2_lanes,
  1283. .ops = &tegra186_usb2_pad_ops,
  1284. };
  1285. static const struct tegra_xusb_lane_soc tegra186_usb3_lanes[] = {
  1286. TEGRA186_LANE("usb3-0", 0, 0, 0, usb3),
  1287. TEGRA186_LANE("usb3-1", 0, 0, 0, usb3),
  1288. TEGRA186_LANE("usb3-2", 0, 0, 0, usb3),
  1289. };
  1290. static const struct tegra_xusb_pad_soc tegra186_usb3_pad = {
  1291. .name = "usb3",
  1292. .num_lanes = ARRAY_SIZE(tegra186_usb3_lanes),
  1293. .lanes = tegra186_usb3_lanes,
  1294. .ops = &tegra186_usb3_pad_ops,
  1295. };
  1296. static const struct tegra_xusb_pad_soc * const tegra186_pads[] = {
  1297. &tegra186_usb2_pad,
  1298. &tegra186_usb3_pad,
  1299. #if 0 /* TODO implement */
  1300. &tegra186_hsic_pad,
  1301. #endif
  1302. };
  1303. const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc = {
  1304. .num_pads = ARRAY_SIZE(tegra186_pads),
  1305. .pads = tegra186_pads,
  1306. .ports = {
  1307. .usb2 = {
  1308. .ops = &tegra186_usb2_port_ops,
  1309. .count = 3,
  1310. },
  1311. #if 0 /* TODO implement */
  1312. .hsic = {
  1313. .ops = &tegra186_hsic_port_ops,
  1314. .count = 1,
  1315. },
  1316. #endif
  1317. .usb3 = {
  1318. .ops = &tegra186_usb3_port_ops,
  1319. .count = 3,
  1320. },
  1321. },
  1322. .ops = &tegra186_xusb_padctl_ops,
  1323. .supply_names = tegra186_xusb_padctl_supply_names,
  1324. .num_supplies = ARRAY_SIZE(tegra186_xusb_padctl_supply_names),
  1325. };
  1326. EXPORT_SYMBOL_GPL(tegra186_xusb_padctl_soc);
  1327. #endif
  1328. #if IS_ENABLED(CONFIG_ARCH_TEGRA_194_SOC) || \
  1329. IS_ENABLED(CONFIG_ARCH_TEGRA_234_SOC)
  1330. static const char * const tegra194_xusb_padctl_supply_names[] = {
  1331. "avdd-usb",
  1332. "vclamp-usb",
  1333. };
  1334. static const struct tegra_xusb_lane_soc tegra194_usb2_lanes[] = {
  1335. TEGRA186_LANE("usb2-0", 0, 0, 0, usb2),
  1336. TEGRA186_LANE("usb2-1", 0, 0, 0, usb2),
  1337. TEGRA186_LANE("usb2-2", 0, 0, 0, usb2),
  1338. TEGRA186_LANE("usb2-3", 0, 0, 0, usb2),
  1339. };
  1340. static const struct tegra_xusb_pad_soc tegra194_usb2_pad = {
  1341. .name = "usb2",
  1342. .num_lanes = ARRAY_SIZE(tegra194_usb2_lanes),
  1343. .lanes = tegra194_usb2_lanes,
  1344. .ops = &tegra186_usb2_pad_ops,
  1345. };
  1346. static const struct tegra_xusb_lane_soc tegra194_usb3_lanes[] = {
  1347. TEGRA186_LANE("usb3-0", 0, 0, 0, usb3),
  1348. TEGRA186_LANE("usb3-1", 0, 0, 0, usb3),
  1349. TEGRA186_LANE("usb3-2", 0, 0, 0, usb3),
  1350. TEGRA186_LANE("usb3-3", 0, 0, 0, usb3),
  1351. };
  1352. static const struct tegra_xusb_pad_soc tegra194_usb3_pad = {
  1353. .name = "usb3",
  1354. .num_lanes = ARRAY_SIZE(tegra194_usb3_lanes),
  1355. .lanes = tegra194_usb3_lanes,
  1356. .ops = &tegra186_usb3_pad_ops,
  1357. };
  1358. static const struct tegra_xusb_pad_soc * const tegra194_pads[] = {
  1359. &tegra194_usb2_pad,
  1360. &tegra194_usb3_pad,
  1361. };
  1362. const struct tegra_xusb_padctl_soc tegra194_xusb_padctl_soc = {
  1363. .num_pads = ARRAY_SIZE(tegra194_pads),
  1364. .pads = tegra194_pads,
  1365. .ports = {
  1366. .usb2 = {
  1367. .ops = &tegra186_usb2_port_ops,
  1368. .count = 4,
  1369. },
  1370. .usb3 = {
  1371. .ops = &tegra186_usb3_port_ops,
  1372. .count = 4,
  1373. },
  1374. },
  1375. .ops = &tegra186_xusb_padctl_ops,
  1376. .supply_names = tegra194_xusb_padctl_supply_names,
  1377. .num_supplies = ARRAY_SIZE(tegra194_xusb_padctl_supply_names),
  1378. .supports_gen2 = true,
  1379. .poll_trk_completed = true,
  1380. };
  1381. EXPORT_SYMBOL_GPL(tegra194_xusb_padctl_soc);
  1382. const struct tegra_xusb_padctl_soc tegra234_xusb_padctl_soc = {
  1383. .num_pads = ARRAY_SIZE(tegra194_pads),
  1384. .pads = tegra194_pads,
  1385. .ports = {
  1386. .usb2 = {
  1387. .ops = &tegra186_usb2_port_ops,
  1388. .count = 4,
  1389. },
  1390. .usb3 = {
  1391. .ops = &tegra186_usb3_port_ops,
  1392. .count = 4,
  1393. },
  1394. },
  1395. .ops = &tegra186_xusb_padctl_ops,
  1396. .supply_names = tegra194_xusb_padctl_supply_names,
  1397. .num_supplies = ARRAY_SIZE(tegra194_xusb_padctl_supply_names),
  1398. .supports_gen2 = true,
  1399. .poll_trk_completed = true,
  1400. .trk_hw_mode = false,
  1401. .trk_update_on_idle = true,
  1402. .supports_lp_cfg_en = true,
  1403. };
  1404. EXPORT_SYMBOL_GPL(tegra234_xusb_padctl_soc);
  1405. #endif
  1406. MODULE_AUTHOR("JC Kuo <jckuo@nvidia.com>");
  1407. MODULE_DESCRIPTION("NVIDIA Tegra186 XUSB Pad Controller driver");
  1408. MODULE_LICENSE("GPL v2");