phy-exynos5-usbdrd.c 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Samsung Exynos5 SoC series USB DRD PHY driver
  4. *
  5. * Phy provider for USB 3.0 DRD controller on Exynos5 SoC series
  6. *
  7. * Copyright (C) 2014 Samsung Electronics Co., Ltd.
  8. * Author: Vivek Gautam <gautam.vivek@samsung.com>
  9. */
  10. #include <linux/bitfield.h>
  11. #include <linux/clk.h>
  12. #include <linux/delay.h>
  13. #include <linux/io.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/of.h>
  17. #include <linux/iopoll.h>
  18. #include <linux/phy/phy.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/mutex.h>
  21. #include <linux/mfd/syscon.h>
  22. #include <linux/regmap.h>
  23. #include <linux/regulator/consumer.h>
  24. #include <linux/soc/samsung/exynos-regs-pmu.h>
  25. #include <linux/usb/typec.h>
  26. #include <linux/usb/typec_mux.h>
  27. /* Exynos USB PHY registers */
  28. #define EXYNOS5_FSEL_9MHZ6 0x0
  29. #define EXYNOS5_FSEL_10MHZ 0x1
  30. #define EXYNOS5_FSEL_12MHZ 0x2
  31. #define EXYNOS5_FSEL_19MHZ2 0x3
  32. #define EXYNOS5_FSEL_20MHZ 0x4
  33. #define EXYNOS5_FSEL_24MHZ 0x5
  34. #define EXYNOS5_FSEL_26MHZ 0x6
  35. #define EXYNOS5_FSEL_50MHZ 0x7
  36. /* USB 3.2 DRD 4nm PHY link controller registers */
  37. #define EXYNOS2200_DRD_CLKRST 0x0c
  38. #define EXYNOS2200_CLKRST_LINK_PCLK_SEL BIT(1)
  39. #define EXYNOS2200_DRD_UTMI 0x10
  40. /* ExynosAutov920 bits */
  41. #define UTMICTL_FORCE_UTMI_SUSPEND BIT(13)
  42. #define UTMICTL_FORCE_UTMI_SLEEP BIT(12)
  43. #define UTMICTL_FORCE_DPPULLDOWN BIT(9)
  44. #define UTMICTL_FORCE_DMPULLDOWN BIT(8)
  45. #define EXYNOS2200_UTMI_FORCE_VBUSVALID BIT(1)
  46. #define EXYNOS2200_UTMI_FORCE_BVALID BIT(0)
  47. #define EXYNOS2200_DRD_HSP_MISC 0x114
  48. #define HSP_MISC_SET_REQ_IN2 BIT(4)
  49. #define HSP_MISC_RES_TUNE GENMASK(1, 0)
  50. #define RES_TUNE_PHY1_PHY2 0x1
  51. #define RES_TUNE_PHY1 0x2
  52. #define RES_TUNE_PHY2 0x3
  53. /* Exynos5: USB 3.0 DRD PHY registers */
  54. #define EXYNOS5_DRD_LINKSYSTEM 0x04
  55. #define LINKSYSTEM_XHCI_VERSION_CONTROL BIT(27)
  56. #define LINKSYSTEM_FORCE_VBUSVALID BIT(8)
  57. #define LINKSYSTEM_FORCE_BVALID BIT(7)
  58. #define LINKSYSTEM_FLADJ GENMASK(6, 1)
  59. #define EXYNOS5_DRD_PHYUTMI 0x08
  60. #define PHYUTMI_UTMI_SUSPEND_COM_N BIT(12)
  61. #define PHYUTMI_UTMI_L1_SUSPEND_COM_N BIT(11)
  62. #define PHYUTMI_VBUSVLDEXTSEL BIT(10)
  63. #define PHYUTMI_VBUSVLDEXT BIT(9)
  64. #define PHYUTMI_TXBITSTUFFENH BIT(8)
  65. #define PHYUTMI_TXBITSTUFFEN BIT(7)
  66. #define PHYUTMI_OTGDISABLE BIT(6)
  67. #define PHYUTMI_IDPULLUP BIT(5)
  68. #define PHYUTMI_DRVVBUS BIT(4)
  69. #define PHYUTMI_DPPULLDOWN BIT(3)
  70. #define PHYUTMI_DMPULLDOWN BIT(2)
  71. #define PHYUTMI_FORCESUSPEND BIT(1)
  72. #define PHYUTMI_FORCESLEEP BIT(0)
  73. #define EXYNOS5_DRD_PHYPIPE 0x0c
  74. #define EXYNOS5_DRD_PHYCLKRST 0x10
  75. #define PHYCLKRST_EN_UTMISUSPEND BIT(31)
  76. #define PHYCLKRST_SSC_REFCLKSEL GENMASK(30, 23)
  77. #define PHYCLKRST_SSC_RANGE GENMASK(22, 21)
  78. #define PHYCLKRST_SSC_EN BIT(20)
  79. #define PHYCLKRST_REF_SSP_EN BIT(19)
  80. #define PHYCLKRST_REF_CLKDIV2 BIT(18)
  81. #define PHYCLKRST_MPLL_MULTIPLIER GENMASK(17, 11)
  82. #define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF 0x19
  83. #define PHYCLKRST_MPLL_MULTIPLIER_50M_REF 0x32
  84. #define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF 0x68
  85. #define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF 0x7d
  86. #define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF 0x02
  87. #define PHYCLKRST_FSEL_PIPE GENMASK(10, 8)
  88. #define PHYCLKRST_FSEL_UTMI GENMASK(7, 5)
  89. #define PHYCLKRST_FSEL_PAD_100MHZ 0x27
  90. #define PHYCLKRST_FSEL_PAD_24MHZ 0x2a
  91. #define PHYCLKRST_FSEL_PAD_20MHZ 0x31
  92. #define PHYCLKRST_FSEL_PAD_19_2MHZ 0x38
  93. #define PHYCLKRST_RETENABLEN BIT(4)
  94. #define PHYCLKRST_REFCLKSEL GENMASK(3, 2)
  95. #define PHYCLKRST_REFCLKSEL_PAD_REFCLK 0x2
  96. #define PHYCLKRST_REFCLKSEL_EXT_REFCLK 0x3
  97. #define PHYCLKRST_PORTRESET BIT(1)
  98. #define PHYCLKRST_COMMONONN BIT(0)
  99. #define EXYNOS5_DRD_PHYREG0 0x14
  100. #define PHYREG0_SSC_REF_CLK_SEL BIT(21)
  101. #define PHYREG0_SSC_RANGE BIT(20)
  102. #define PHYREG0_CR_WRITE BIT(19)
  103. #define PHYREG0_CR_READ BIT(18)
  104. #define PHYREG0_CR_DATA_IN GENMASK(17, 2)
  105. #define PHYREG0_CR_CAP_DATA BIT(1)
  106. #define PHYREG0_CR_CAP_ADDR BIT(0)
  107. #define EXYNOS5_DRD_PHYREG1 0x18
  108. #define PHYREG0_CR_DATA_OUT GENMASK(16, 1)
  109. #define PHYREG1_CR_ACK BIT(0)
  110. #define EXYNOS5_DRD_PHYPARAM0 0x1c
  111. #define PHYPARAM0_REF_USE_PAD BIT(31)
  112. #define PHYPARAM0_REF_LOSLEVEL GENMASK(30, 26)
  113. #define PHYPARAM0_REF_LOSLEVEL_VAL 0x9
  114. #define PHYPARAM0_TXVREFTUNE GENMASK(25, 22)
  115. #define PHYPARAM0_TXRISETUNE GENMASK(21, 20)
  116. #define PHYPARAM0_TXRESTUNE GENMASK(19, 18)
  117. #define PHYPARAM0_TXPREEMPPULSETUNE BIT(17)
  118. #define PHYPARAM0_TXPREEMPAMPTUNE GENMASK(16, 15)
  119. #define PHYPARAM0_TXHSXVTUNE GENMASK(14, 13)
  120. #define PHYPARAM0_TXFSLSTUNE GENMASK(12, 9)
  121. #define PHYPARAM0_SQRXTUNE GENMASK(8, 6)
  122. #define PHYPARAM0_OTGTUNE GENMASK(5, 3)
  123. #define PHYPARAM0_COMPDISTUNE GENMASK(2, 0)
  124. #define EXYNOS5_DRD_PHYPARAM1 0x20
  125. #define PHYPARAM1_PCS_TXDEEMPH GENMASK(4, 0)
  126. #define PHYPARAM1_PCS_TXDEEMPH_VAL 0x1c
  127. #define EXYNOS5_DRD_PHYTERM 0x24
  128. #define EXYNOS5_DRD_PHYTEST 0x28
  129. #define PHYTEST_POWERDOWN_SSP BIT(3)
  130. #define PHYTEST_POWERDOWN_HSP BIT(2)
  131. #define EXYNOS5_DRD_PHYADP 0x2c
  132. #define EXYNOS5_DRD_PHYUTMICLKSEL 0x30
  133. #define PHYUTMICLKSEL_UTMI_CLKSEL BIT(2)
  134. #define EXYNOS5_DRD_PHYRESUME 0x34
  135. #define EXYNOS5_DRD_LINKPORT 0x44
  136. #define LINKPORT_HOST_U3_PORT_DISABLE BIT(8)
  137. #define LINKPORT_HOST_U2_PORT_DISABLE BIT(7)
  138. #define LINKPORT_HOST_PORT_OVCR_U3 BIT(5)
  139. #define LINKPORT_HOST_PORT_OVCR_U2 BIT(4)
  140. #define LINKPORT_HOST_PORT_OVCR_U3_SEL BIT(3)
  141. #define LINKPORT_HOST_PORT_OVCR_U2_SEL BIT(2)
  142. /* USB 3.0 DRD PHY SS Function Control Reg; accessed by CR_PORT */
  143. #define EXYNOS5_DRD_PHYSS_LOSLEVEL_OVRD_IN (0x15)
  144. #define LOSLEVEL_OVRD_IN_LOS_BIAS_5420 (0x5 << 13)
  145. #define LOSLEVEL_OVRD_IN_LOS_BIAS_DEFAULT (0x0 << 13)
  146. #define LOSLEVEL_OVRD_IN_EN (0x1 << 10)
  147. #define LOSLEVEL_OVRD_IN_LOS_LEVEL_DEFAULT (0x9 << 0)
  148. #define EXYNOS5_DRD_PHYSS_TX_VBOOSTLEVEL_OVRD_IN (0x12)
  149. #define TX_VBOOSTLEVEL_OVRD_IN_VBOOST_5420 (0x5 << 13)
  150. #define TX_VBOOSTLEVEL_OVRD_IN_VBOOST_DEFAULT (0x4 << 13)
  151. #define EXYNOS5_DRD_PHYSS_LANE0_TX_DEBUG (0x1010)
  152. #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_19M2_20M (0x4 << 4)
  153. #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_24M (0x8 << 4)
  154. #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_25M_26M (0x8 << 4)
  155. #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_48M_50M_52M (0x20 << 4)
  156. #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_62M5 (0x20 << 4)
  157. #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_96M_100M (0x40 << 4)
  158. /* Exynos7870: USB DRD PHY registers */
  159. #define EXYNOS7870_DRD_PHYPCSVAL 0x3C
  160. #define PHYPCSVAL_PCS_RX_LOS_MASK GENMASK(9, 0)
  161. #define EXYNOS7870_DRD_PHYPARAM2 0x50
  162. #define PHYPARAM2_TX_VBOOST_LVL GENMASK(6, 4)
  163. #define PHYPARAM2_LOS_BIAS GENMASK(2, 0)
  164. #define EXYNOS7870_DRD_HSPHYCTRL 0x54
  165. #define HSPHYCTRL_PHYSWRSTALL BIT(31)
  166. #define HSPHYCTRL_SIDDQ BIT(6)
  167. #define HSPHYCTRL_PHYSWRST BIT(0)
  168. #define EXYNOS7870_DRD_HSPHYPLLTUNE 0x70
  169. #define HSPHYPLLTUNE_PLL_B_TUNE BIT(6)
  170. #define HSPHYPLLTUNE_PLL_I_TUNE GENMASK(5, 4)
  171. #define HSPHYPLLTUNE_PLL_P_TUNE GENMASK(3, 0)
  172. /* Exynos850: USB DRD PHY registers */
  173. #define EXYNOS850_DRD_LINKCTRL 0x04
  174. #define LINKCTRL_FORCE_RXELECIDLE BIT(18)
  175. #define LINKCTRL_FORCE_PHYSTATUS BIT(17)
  176. #define LINKCTRL_FORCE_PIPE_EN BIT(16)
  177. #define LINKCTRL_FORCE_QACT BIT(8)
  178. #define LINKCTRL_BUS_FILTER_BYPASS GENMASK(7, 4)
  179. #define EXYNOS850_DRD_LINKPORT 0x08
  180. #define LINKPORT_HOST_NUM_U3 GENMASK(19, 16)
  181. #define LINKPORT_HOST_NUM_U2 GENMASK(15, 12)
  182. #define EXYNOS850_DRD_CLKRST 0x20
  183. /*
  184. * On versions without SS ports (like E850), bit 3 is for the 2.0 phy (HS),
  185. * while on versions with (like gs101), bits 2 and 3 are for the 3.0 phy (SS)
  186. * and bits 12 & 13 for the 2.0 phy.
  187. */
  188. #define CLKRST_PHY20_SW_POR BIT(13)
  189. #define CLKRST_PHY20_SW_POR_SEL BIT(12)
  190. #define CLKRST_LINK_PCLK_SEL BIT(7)
  191. #define CLKRST_PHY_SW_RST BIT(3)
  192. #define CLKRST_PHY_RESET_SEL BIT(2)
  193. #define CLKRST_PORT_RST BIT(1)
  194. #define CLKRST_LINK_SW_RST BIT(0)
  195. #define EXYNOS850_DRD_SSPPLLCTL 0x30
  196. #define SSPPLLCTL_FSEL GENMASK(2, 0)
  197. #define EXYNOS850_DRD_UTMI 0x50
  198. #define UTMI_FORCE_VBUSVALID BIT(5)
  199. #define UTMI_FORCE_BVALID BIT(4)
  200. #define UTMI_DP_PULLDOWN BIT(3)
  201. #define UTMI_DM_PULLDOWN BIT(2)
  202. #define UTMI_FORCE_SUSPEND BIT(1)
  203. #define UTMI_FORCE_SLEEP BIT(0)
  204. #define EXYNOS850_DRD_HSP 0x54
  205. #define HSP_FSV_OUT_EN BIT(24)
  206. #define HSP_VBUSVLDEXTSEL BIT(13)
  207. #define HSP_VBUSVLDEXT BIT(12)
  208. #define HSP_EN_UTMISUSPEND BIT(9)
  209. #define HSP_COMMONONN BIT(8)
  210. #define EXYNOS850_DRD_HSPPARACON 0x58
  211. #define HSPPARACON_TXVREF GENMASK(31, 28)
  212. #define HSPPARACON_TXRISE GENMASK(25, 24)
  213. #define HSPPARACON_TXRES GENMASK(22, 21)
  214. #define HSPPARACON_TXPREEMPPULSE BIT(20)
  215. #define HSPPARACON_TXPREEMPAMP GENMASK(19, 18)
  216. #define HSPPARACON_TXHSXV GENMASK(17, 16)
  217. #define HSPPARACON_TXFSLS GENMASK(15, 12)
  218. #define HSPPARACON_SQRX GENMASK(10, 8)
  219. #define HSPPARACON_OTG GENMASK(6, 4)
  220. #define HSPPARACON_COMPDIS GENMASK(2, 0)
  221. #define EXYNOS850_DRD_HSP_TEST 0x5c
  222. #define HSP_TEST_SIDDQ BIT(24)
  223. #define EXYNOSAUTOV920_DRD_HSP_CLKRST 0x100
  224. #define HSPCLKRST_PHY20_SW_PORTRESET BIT(3)
  225. #define HSPCLKRST_PHY20_SW_POR BIT(1)
  226. #define HSPCLKRST_PHY20_SW_POR_SEL BIT(0)
  227. #define EXYNOSAUTOV920_DRD_HSPCTL 0x104
  228. #define HSPCTRL_VBUSVLDEXTSEL BIT(13)
  229. #define HSPCTRL_VBUSVLDEXT BIT(12)
  230. #define HSPCTRL_EN_UTMISUSPEND BIT(9)
  231. #define HSPCTRL_COMMONONN BIT(8)
  232. #define EXYNOSAUTOV920_DRD_HSP_TEST 0x10c
  233. #define EXYNOSAUTOV920_DRD_HSPPLLTUNE 0x110
  234. #define HSPPLLTUNE_FSEL GENMASK(18, 16)
  235. /* ExynosAutov920 phy usb31drd port reg */
  236. #define EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL 0x000
  237. #define PHY_RST_CTRL_PIPE_LANE0_RESET_N_OVRD_EN BIT(5)
  238. #define PHY_RST_CTRL_PIPE_LANE0_RESET_N BIT(4)
  239. #define PHY_RST_CTRL_PHY_RESET_OVRD_EN BIT(1)
  240. #define PHY_RST_CTRL_PHY_RESET BIT(0)
  241. #define EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0 0x0004
  242. #define PHY_CR_PARA_CON0_PHY0_CR_PARA_ADDR GENMASK(31, 16)
  243. #define PHY_CR_PARA_CON0_PHY0_CR_PARA_CLK BIT(8)
  244. #define PHY_CR_PARA_CON0_PHY0_CR_PARA_ACK BIT(4)
  245. #define PHY_CR_PARA_CON0_PHY0_CR_PARA_SEL BIT(0)
  246. #define EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON1 0x0008
  247. #define EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON2 0x000c
  248. #define PHY_CR_PARA_CON2_PHY0_CR_PARA_WR_EN BIT(0)
  249. #define PHY_CR_PARA_CON2_PHY0_CR_PARA_WR_DATA GENMASK(31, 16)
  250. #define EXYNOSAUTOV920_USB31DRD_PHY_CONFIG0 0x100
  251. #define PHY_CONFIG0_PHY0_PMA_PWR_STABLE BIT(14)
  252. #define PHY_CONFIG0_PHY0_PCS_PWR_STABLE BIT(13)
  253. #define PHY_CONFIG0_PHY0_ANA_PWR_EN BIT(1)
  254. #define EXYNOSAUTOV920_USB31DRD_PHY_CONFIG7 0x11c
  255. #define PHY_CONFIG7_PHY_TEST_POWERDOWN BIT(24)
  256. #define EXYNOSAUTOV920_USB31DRD_PHY_CONFIG4 0x110
  257. #define PHY_CONFIG4_PIPE_RX0_SRIS_MODE_EN BIT(2)
  258. /* Exynos9 - GS101 */
  259. #define EXYNOS850_DRD_SECPMACTL 0x48
  260. #define SECPMACTL_PMA_ROPLL_REF_CLK_SEL GENMASK(13, 12)
  261. #define SECPMACTL_PMA_LCPLL_REF_CLK_SEL GENMASK(11, 10)
  262. #define SECPMACTL_PMA_REF_FREQ_SEL GENMASK(9, 8)
  263. #define SECPMACTL_PMA_LOW_PWR BIT(4)
  264. #define SECPMACTL_PMA_TRSV_SW_RST BIT(3)
  265. #define SECPMACTL_PMA_CMN_SW_RST BIT(2)
  266. #define SECPMACTL_PMA_INIT_SW_RST BIT(1)
  267. #define SECPMACTL_PMA_APB_SW_RST BIT(0)
  268. /* PMA registers */
  269. #define EXYNOS9_PMA_USBDP_CMN_REG0008 0x0020
  270. #define CMN_REG0008_OVRD_AUX_EN BIT(3)
  271. #define CMN_REG0008_AUX_EN BIT(2)
  272. #define EXYNOS9_PMA_USBDP_CMN_REG00B8 0x02e0
  273. #define CMN_REG00B8_LANE_MUX_SEL_DP GENMASK(3, 0)
  274. #define CMN_REG00B8_LANE_MUX_SEL_DP_LANE3 BIT(3)
  275. #define CMN_REG00B8_LANE_MUX_SEL_DP_LANE2 BIT(2)
  276. #define CMN_REG00B8_LANE_MUX_SEL_DP_LANE1 BIT(1)
  277. #define CMN_REG00B8_LANE_MUX_SEL_DP_LANE0 BIT(0)
  278. #define EXYNOS9_PMA_USBDP_CMN_REG01C0 0x0700
  279. #define CMN_REG01C0_ANA_LCPLL_LOCK_DONE BIT(7)
  280. #define CMN_REG01C0_ANA_LCPLL_AFC_DONE BIT(6)
  281. /* these have similar register layout, for lanes 0 and 2 */
  282. #define EXYNOS9_PMA_USBDP_TRSV_REG03C3 0x0f0c
  283. #define EXYNOS9_PMA_USBDP_TRSV_REG07C3 0x1f0c
  284. #define TRSV_REG03C3_LN0_MON_RX_CDR_AFC_DONE BIT(3)
  285. #define TRSV_REG03C3_LN0_MON_RX_CDR_CAL_DONE BIT(2)
  286. #define TRSV_REG03C3_LN0_MON_RX_CDR_FLD_PLL_MODE_DONE BIT(1)
  287. #define TRSV_REG03C3_LN0_MON_RX_CDR_LOCK_DONE BIT(0)
  288. /* TRSV_REG0413 and TRSV_REG0813 have similar register layout */
  289. #define EXYNOS9_PMA_USBDP_TRSV_REG0413 0x104c
  290. #define TRSV_REG0413_OVRD_LN1_TX_RXD_COMP_EN BIT(7)
  291. #define TRSV_REG0413_OVRD_LN1_TX_RXD_EN BIT(5)
  292. #define EXYNOS9_PMA_USBDP_TRSV_REG0813 0x204c
  293. #define TRSV_REG0813_OVRD_LN3_TX_RXD_COMP_EN BIT(7)
  294. #define TRSV_REG0813_OVRD_LN3_TX_RXD_EN BIT(5)
  295. /* PCS registers */
  296. #define EXYNOS9_PCS_NS_VEC_PS1_N1 0x010c
  297. #define EXYNOS9_PCS_NS_VEC_PS2_N0 0x0110
  298. #define EXYNOS9_PCS_NS_VEC_PS3_N0 0x0118
  299. #define NS_VEC_NS_REQ GENMASK(31, 24)
  300. #define NS_VEC_ENABLE_TIMER BIT(22)
  301. #define NS_VEC_SEL_TIMEOUT GENMASK(21, 20)
  302. #define NS_VEC_INV_MASK GENMASK(19, 16)
  303. #define NS_VEC_COND_MASK GENMASK(11, 8)
  304. #define NS_VEC_EXP_COND GENMASK(3, 0)
  305. #define EXYNOS9_PCS_OUT_VEC_2 0x014c
  306. #define EXYNOS9_PCS_OUT_VEC_3 0x0150
  307. #define PCS_OUT_VEC_B9_DYNAMIC BIT(19)
  308. #define PCS_OUT_VEC_B9_SEL_OUT BIT(18)
  309. #define PCS_OUT_VEC_B8_DYNAMIC BIT(17)
  310. #define PCS_OUT_VEC_B8_SEL_OUT BIT(16)
  311. #define PCS_OUT_VEC_B7_DYNAMIC BIT(15)
  312. #define PCS_OUT_VEC_B7_SEL_OUT BIT(14)
  313. #define PCS_OUT_VEC_B6_DYNAMIC BIT(13)
  314. #define PCS_OUT_VEC_B6_SEL_OUT BIT(12)
  315. #define PCS_OUT_VEC_B5_DYNAMIC BIT(11)
  316. #define PCS_OUT_VEC_B5_SEL_OUT BIT(10)
  317. #define PCS_OUT_VEC_B4_DYNAMIC BIT(9)
  318. #define PCS_OUT_VEC_B4_SEL_OUT BIT(8)
  319. #define PCS_OUT_VEC_B3_DYNAMIC BIT(7)
  320. #define PCS_OUT_VEC_B3_SEL_OUT BIT(6)
  321. #define PCS_OUT_VEC_B2_DYNAMIC BIT(5)
  322. #define PCS_OUT_VEC_B2_SEL_OUT BIT(4)
  323. #define PCS_OUT_VEC_B1_DYNAMIC BIT(3)
  324. #define PCS_OUT_VEC_B1_SEL_OUT BIT(2)
  325. #define PCS_OUT_VEC_B0_DYNAMIC BIT(1)
  326. #define PCS_OUT_VEC_B0_SEL_OUT BIT(0)
  327. #define EXYNOS9_PCS_TIMEOUT_0 0x0170
  328. #define EXYNOS9_PCS_TIMEOUT_3 0x017c
  329. #define EXYNOS9_PCS_EBUF_PARAM 0x0304
  330. #define EBUF_PARAM_SKP_REMOVE_TH_EMPTY_MODE GENMASK(29, 24)
  331. #define EXYNOS9_PCS_BACK_END_MODE_VEC 0x030c
  332. #define BACK_END_MODE_VEC_FORCE_EBUF_EMPTY_MODE BIT(1)
  333. #define BACK_END_MODE_VEC_DISABLE_DATA_MASK BIT(0)
  334. #define EXYNOS9_PCS_RX_CONTROL 0x03f0
  335. #define RX_CONTROL_EN_BLOCK_ALIGNER_TYPE_B BIT(22)
  336. #define EXYNOS9_PCS_RX_CONTROL_DEBUG 0x03f4
  337. #define RX_CONTROL_DEBUG_EN_TS_CHECK BIT(5)
  338. #define RX_CONTROL_DEBUG_NUM_COM_FOUND GENMASK(3, 0)
  339. #define EXYNOS9_PCS_LOCAL_COEF 0x040c
  340. #define LOCAL_COEF_PMA_CENTER_COEF GENMASK(21, 16)
  341. #define LOCAL_COEF_LF GENMASK(13, 8)
  342. #define LOCAL_COEF_FS GENMASK(5, 0)
  343. #define EXYNOS9_PCS_HS_TX_COEF_MAP_0 0x0410
  344. #define HS_TX_COEF_MAP_0_SSTX_DEEMP GENMASK(17, 12)
  345. #define HS_TX_COEF_MAP_0_SSTX_LEVEL GENMASK(11, 6)
  346. #define HS_TX_COEF_MAP_0_SSTX_PRE_SHOOT GENMASK(5, 0)
  347. #define KHZ 1000
  348. #define MHZ (KHZ * KHZ)
  349. #define PHY_TUNING_ENTRY_PHY(o, m, v) { \
  350. .off = (o), \
  351. .mask = (m), \
  352. .val = (v), \
  353. .region = PTR_PHY \
  354. }
  355. #define PHY_TUNING_ENTRY_PCS(o, m, v) { \
  356. .off = (o), \
  357. .mask = (m), \
  358. .val = (v), \
  359. .region = PTR_PCS \
  360. }
  361. #define PHY_TUNING_ENTRY_PMA(o, m, v) { \
  362. .off = (o), \
  363. .mask = (m), \
  364. .val = (v), \
  365. .region = PTR_PMA, \
  366. }
  367. #define PHY_TUNING_ENTRY_LAST { .region = PTR_INVALID }
  368. #define for_each_phy_tune(tune) \
  369. for (; (tune)->region != PTR_INVALID; ++(tune))
  370. struct exynos5_usbdrd_phy_tuning {
  371. u32 off;
  372. u32 mask;
  373. u32 val;
  374. char region;
  375. #define PTR_INVALID 0
  376. #define PTR_PHY 1
  377. #define PTR_PCS 2
  378. #define PTR_PMA 3
  379. };
  380. enum exynos5_usbdrd_phy_tuning_state {
  381. PTS_UTMI_POSTINIT,
  382. PTS_PIPE3_PREINIT,
  383. PTS_PIPE3_INIT,
  384. PTS_PIPE3_POSTINIT,
  385. PTS_PIPE3_POSTLOCK,
  386. PTS_MAX,
  387. };
  388. enum exynos5_usbdrd_phy_id {
  389. EXYNOS5_DRDPHY_UTMI,
  390. EXYNOS5_DRDPHY_PIPE3,
  391. EXYNOS5_DRDPHYS_NUM,
  392. };
  393. struct phy_usb_instance;
  394. struct exynos5_usbdrd_phy;
  395. struct exynos5_usbdrd_phy_config {
  396. u32 id;
  397. void (*phy_isol)(struct phy_usb_instance *inst, bool isolate);
  398. void (*phy_init)(struct exynos5_usbdrd_phy *phy_drd);
  399. unsigned int (*set_refclk)(struct phy_usb_instance *inst);
  400. };
  401. struct exynos5_usbdrd_phy_drvdata {
  402. const struct exynos5_usbdrd_phy_config *phy_cfg;
  403. const struct exynos5_usbdrd_phy_tuning **phy_tunes;
  404. const struct phy_ops *phy_ops;
  405. const char * const *clk_names;
  406. int n_clks;
  407. const char * const *core_clk_names;
  408. int n_core_clks;
  409. const char * const *regulator_names;
  410. int n_regulators;
  411. u32 pmu_offset_usbdrd0_phy;
  412. u32 pmu_offset_usbdrd0_phy_ss;
  413. u32 pmu_offset_usbdrd1_phy;
  414. };
  415. /**
  416. * struct exynos5_usbdrd_phy - driver data for USB 3.0 PHY
  417. * @dev: pointer to device instance of this platform device
  418. * @reg_phy: usb phy controller register memory base
  419. * @reg_pcs: usb phy physical coding sublayer register memory base
  420. * @reg_pma: usb phy physical media attachment register memory base
  421. * @clks: clocks for register access
  422. * @core_clks: core clocks for phy (ref, pipe3, utmi+, ITP, etc. as required)
  423. * @drv_data: pointer to SoC level driver data structure
  424. * @hs_phy: pointer to non-Samsung IP high-speed phy controller
  425. * @phy_mutex: mutex protecting phy_init/exit & TCPC callbacks
  426. * @phys: array for 'EXYNOS5_DRDPHYS_NUM' number of PHY
  427. * instances each with its 'phy' and 'phy_cfg'.
  428. * @extrefclk: frequency select settings when using 'separate
  429. * reference clocks' for SS and HS operations
  430. * @regulators: regulators for phy
  431. * @sw: TypeC orientation switch handle
  432. * @orientation: TypeC connector orientation - normal or flipped
  433. */
  434. struct exynos5_usbdrd_phy {
  435. struct device *dev;
  436. void __iomem *reg_phy;
  437. void __iomem *reg_pcs;
  438. void __iomem *reg_pma;
  439. struct clk_bulk_data *clks;
  440. struct clk_bulk_data *core_clks;
  441. const struct exynos5_usbdrd_phy_drvdata *drv_data;
  442. struct phy *hs_phy;
  443. struct mutex phy_mutex;
  444. struct phy_usb_instance {
  445. struct phy *phy;
  446. u32 index;
  447. struct regmap *reg_pmu;
  448. u32 pmu_offset;
  449. const struct exynos5_usbdrd_phy_config *phy_cfg;
  450. } phys[EXYNOS5_DRDPHYS_NUM];
  451. u32 extrefclk;
  452. struct regulator_bulk_data *regulators;
  453. struct typec_switch_dev *sw;
  454. enum typec_orientation orientation;
  455. };
  456. static inline
  457. struct exynos5_usbdrd_phy *to_usbdrd_phy(struct phy_usb_instance *inst)
  458. {
  459. return container_of((inst), struct exynos5_usbdrd_phy,
  460. phys[(inst)->index]);
  461. }
  462. /*
  463. * exynos5_rate_to_clk() converts the supplied clock rate to the value that
  464. * can be written to the phy register.
  465. */
  466. static unsigned int exynos5_rate_to_clk(unsigned long rate, u32 *reg)
  467. {
  468. /* EXYNOS5_FSEL_MASK */
  469. switch (rate) {
  470. case 9600 * KHZ:
  471. *reg = EXYNOS5_FSEL_9MHZ6;
  472. break;
  473. case 10 * MHZ:
  474. *reg = EXYNOS5_FSEL_10MHZ;
  475. break;
  476. case 12 * MHZ:
  477. *reg = EXYNOS5_FSEL_12MHZ;
  478. break;
  479. case 19200 * KHZ:
  480. *reg = EXYNOS5_FSEL_19MHZ2;
  481. break;
  482. case 20 * MHZ:
  483. *reg = EXYNOS5_FSEL_20MHZ;
  484. break;
  485. case 24 * MHZ:
  486. *reg = EXYNOS5_FSEL_24MHZ;
  487. break;
  488. case 26 * MHZ:
  489. *reg = EXYNOS5_FSEL_26MHZ;
  490. break;
  491. case 50 * MHZ:
  492. *reg = EXYNOS5_FSEL_50MHZ;
  493. break;
  494. default:
  495. return -EINVAL;
  496. }
  497. return 0;
  498. }
  499. static void exynos5_usbdrd_phy_isol(struct phy_usb_instance *inst,
  500. bool isolate)
  501. {
  502. unsigned int val;
  503. if (!inst->reg_pmu)
  504. return;
  505. val = isolate ? 0 : EXYNOS4_PHY_ENABLE;
  506. regmap_update_bits(inst->reg_pmu, inst->pmu_offset,
  507. EXYNOS4_PHY_ENABLE, val);
  508. }
  509. /*
  510. * Sets the pipe3 phy's clk as EXTREFCLK (XXTI) which is internal clock
  511. * from clock core. Further sets multiplier values and spread spectrum
  512. * clock settings for SuperSpeed operations.
  513. */
  514. static unsigned int
  515. exynos5_usbdrd_pipe3_set_refclk(struct phy_usb_instance *inst)
  516. {
  517. u32 reg;
  518. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  519. /* restore any previous reference clock settings */
  520. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  521. /* Use EXTREFCLK as ref clock */
  522. reg &= ~PHYCLKRST_REFCLKSEL;
  523. reg |= FIELD_PREP(PHYCLKRST_REFCLKSEL, PHYCLKRST_REFCLKSEL_EXT_REFCLK);
  524. /* FSEL settings corresponding to reference clock */
  525. reg &= ~(PHYCLKRST_FSEL_PIPE |
  526. PHYCLKRST_MPLL_MULTIPLIER |
  527. PHYCLKRST_SSC_REFCLKSEL);
  528. switch (phy_drd->extrefclk) {
  529. case EXYNOS5_FSEL_50MHZ:
  530. reg |= (FIELD_PREP(PHYCLKRST_SSC_REFCLKSEL, 0x00) |
  531. FIELD_PREP(PHYCLKRST_MPLL_MULTIPLIER,
  532. PHYCLKRST_MPLL_MULTIPLIER_50M_REF));
  533. break;
  534. case EXYNOS5_FSEL_24MHZ:
  535. reg |= (FIELD_PREP(PHYCLKRST_SSC_REFCLKSEL, 0x88) |
  536. FIELD_PREP(PHYCLKRST_MPLL_MULTIPLIER,
  537. PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF));
  538. break;
  539. case EXYNOS5_FSEL_20MHZ:
  540. reg |= (FIELD_PREP(PHYCLKRST_SSC_REFCLKSEL, 0x00) |
  541. FIELD_PREP(PHYCLKRST_MPLL_MULTIPLIER,
  542. PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF));
  543. break;
  544. case EXYNOS5_FSEL_19MHZ2:
  545. reg |= (FIELD_PREP(PHYCLKRST_SSC_REFCLKSEL, 0x88) |
  546. FIELD_PREP(PHYCLKRST_MPLL_MULTIPLIER,
  547. PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF));
  548. break;
  549. default:
  550. dev_dbg(phy_drd->dev, "unsupported ref clk\n");
  551. break;
  552. }
  553. return reg;
  554. }
  555. /*
  556. * Sets the utmi phy's clk as EXTREFCLK (XXTI) which is internal clock
  557. * from clock core. Further sets the FSEL values for HighSpeed operations.
  558. */
  559. static unsigned int
  560. exynos5_usbdrd_utmi_set_refclk(struct phy_usb_instance *inst)
  561. {
  562. u32 reg;
  563. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  564. /* restore any previous reference clock settings */
  565. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  566. reg &= ~PHYCLKRST_REFCLKSEL;
  567. reg |= FIELD_PREP(PHYCLKRST_REFCLKSEL, PHYCLKRST_REFCLKSEL_EXT_REFCLK);
  568. reg &= ~(PHYCLKRST_FSEL_UTMI |
  569. PHYCLKRST_MPLL_MULTIPLIER |
  570. PHYCLKRST_SSC_REFCLKSEL);
  571. reg |= FIELD_PREP(PHYCLKRST_FSEL_UTMI, phy_drd->extrefclk);
  572. return reg;
  573. }
  574. static void
  575. exynos5_usbdrd_apply_phy_tunes(struct exynos5_usbdrd_phy *phy_drd,
  576. enum exynos5_usbdrd_phy_tuning_state state)
  577. {
  578. const struct exynos5_usbdrd_phy_tuning *tune;
  579. tune = phy_drd->drv_data->phy_tunes[state];
  580. if (!tune)
  581. return;
  582. for_each_phy_tune(tune) {
  583. void __iomem *reg_base;
  584. u32 reg = 0;
  585. switch (tune->region) {
  586. case PTR_PHY:
  587. reg_base = phy_drd->reg_phy;
  588. break;
  589. case PTR_PCS:
  590. reg_base = phy_drd->reg_pcs;
  591. break;
  592. case PTR_PMA:
  593. reg_base = phy_drd->reg_pma;
  594. break;
  595. default:
  596. dev_warn_once(phy_drd->dev,
  597. "unknown phy region %d\n", tune->region);
  598. continue;
  599. }
  600. if (~tune->mask) {
  601. reg = readl(reg_base + tune->off);
  602. reg &= ~tune->mask;
  603. }
  604. reg |= tune->val;
  605. writel(reg, reg_base + tune->off);
  606. }
  607. }
  608. static void exynos5_usbdrd_pipe3_init(struct exynos5_usbdrd_phy *phy_drd)
  609. {
  610. u32 reg;
  611. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  612. /* Set Tx De-Emphasis level */
  613. reg &= ~PHYPARAM1_PCS_TXDEEMPH;
  614. reg |= FIELD_PREP(PHYPARAM1_PCS_TXDEEMPH, PHYPARAM1_PCS_TXDEEMPH_VAL);
  615. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  616. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  617. reg &= ~PHYTEST_POWERDOWN_SSP;
  618. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  619. }
  620. static void
  621. exynos5_usbdrd_usbdp_g2_v4_ctrl_pma_ready(struct exynos5_usbdrd_phy *phy_drd)
  622. {
  623. void __iomem *regs_base = phy_drd->reg_phy;
  624. u32 reg;
  625. /* link pipe_clock selection to pclk of PMA */
  626. reg = readl(regs_base + EXYNOS850_DRD_CLKRST);
  627. reg |= CLKRST_LINK_PCLK_SEL;
  628. writel(reg, regs_base + EXYNOS850_DRD_CLKRST);
  629. reg = readl(regs_base + EXYNOS850_DRD_SECPMACTL);
  630. reg &= ~SECPMACTL_PMA_REF_FREQ_SEL;
  631. reg |= FIELD_PREP(SECPMACTL_PMA_REF_FREQ_SEL, 1);
  632. /* SFR reset */
  633. reg |= (SECPMACTL_PMA_LOW_PWR | SECPMACTL_PMA_APB_SW_RST);
  634. reg &= ~(SECPMACTL_PMA_ROPLL_REF_CLK_SEL |
  635. SECPMACTL_PMA_LCPLL_REF_CLK_SEL);
  636. /* PMA power off */
  637. reg |= (SECPMACTL_PMA_TRSV_SW_RST | SECPMACTL_PMA_CMN_SW_RST |
  638. SECPMACTL_PMA_INIT_SW_RST);
  639. writel(reg, regs_base + EXYNOS850_DRD_SECPMACTL);
  640. udelay(1);
  641. reg = readl(regs_base + EXYNOS850_DRD_SECPMACTL);
  642. reg &= ~SECPMACTL_PMA_LOW_PWR;
  643. writel(reg, regs_base + EXYNOS850_DRD_SECPMACTL);
  644. udelay(1);
  645. /* release override */
  646. reg = readl(regs_base + EXYNOS850_DRD_LINKCTRL);
  647. reg &= ~LINKCTRL_FORCE_PIPE_EN;
  648. writel(reg, regs_base + EXYNOS850_DRD_LINKCTRL);
  649. udelay(1);
  650. /* APB enable */
  651. reg = readl(regs_base + EXYNOS850_DRD_SECPMACTL);
  652. reg &= ~SECPMACTL_PMA_APB_SW_RST;
  653. writel(reg, regs_base + EXYNOS850_DRD_SECPMACTL);
  654. }
  655. static void
  656. exynos5_usbdrd_usbdp_g2_v4_pma_lane_mux_sel(struct exynos5_usbdrd_phy *phy_drd)
  657. {
  658. void __iomem *regs_base = phy_drd->reg_pma;
  659. u32 reg;
  660. /* lane configuration: USB on all lanes */
  661. reg = readl(regs_base + EXYNOS9_PMA_USBDP_CMN_REG00B8);
  662. reg &= ~CMN_REG00B8_LANE_MUX_SEL_DP;
  663. /*
  664. * USB on lanes 0 & 1 in normal mode, or 2 & 3 if reversed, DP on the
  665. * other ones.
  666. */
  667. reg |= FIELD_PREP(CMN_REG00B8_LANE_MUX_SEL_DP,
  668. ((phy_drd->orientation == TYPEC_ORIENTATION_NORMAL)
  669. ? (CMN_REG00B8_LANE_MUX_SEL_DP_LANE3
  670. | CMN_REG00B8_LANE_MUX_SEL_DP_LANE2)
  671. : (CMN_REG00B8_LANE_MUX_SEL_DP_LANE1
  672. | CMN_REG00B8_LANE_MUX_SEL_DP_LANE0)));
  673. writel(reg, regs_base + EXYNOS9_PMA_USBDP_CMN_REG00B8);
  674. /* override of TX receiver detector and comparator: lane 1 */
  675. reg = readl(regs_base + EXYNOS9_PMA_USBDP_TRSV_REG0413);
  676. if (phy_drd->orientation == TYPEC_ORIENTATION_NORMAL) {
  677. reg &= ~TRSV_REG0413_OVRD_LN1_TX_RXD_COMP_EN;
  678. reg &= ~TRSV_REG0413_OVRD_LN1_TX_RXD_EN;
  679. } else {
  680. reg |= TRSV_REG0413_OVRD_LN1_TX_RXD_COMP_EN;
  681. reg |= TRSV_REG0413_OVRD_LN1_TX_RXD_EN;
  682. }
  683. writel(reg, regs_base + EXYNOS9_PMA_USBDP_TRSV_REG0413);
  684. /* lane 3 */
  685. reg = readl(regs_base + EXYNOS9_PMA_USBDP_TRSV_REG0813);
  686. if (phy_drd->orientation == TYPEC_ORIENTATION_NORMAL) {
  687. reg |= TRSV_REG0813_OVRD_LN3_TX_RXD_COMP_EN;
  688. reg |= TRSV_REG0813_OVRD_LN3_TX_RXD_EN;
  689. } else {
  690. reg &= ~TRSV_REG0813_OVRD_LN3_TX_RXD_COMP_EN;
  691. reg &= ~TRSV_REG0813_OVRD_LN3_TX_RXD_EN;
  692. }
  693. writel(reg, regs_base + EXYNOS9_PMA_USBDP_TRSV_REG0813);
  694. }
  695. static int
  696. exynos5_usbdrd_usbdp_g2_v4_pma_check_pll_lock(struct exynos5_usbdrd_phy *phy_drd)
  697. {
  698. static const unsigned int timeout_us = 40000;
  699. static const unsigned int sleep_us = 40;
  700. static const u32 locked = (CMN_REG01C0_ANA_LCPLL_LOCK_DONE |
  701. CMN_REG01C0_ANA_LCPLL_AFC_DONE);
  702. u32 reg;
  703. int err;
  704. err = readl_poll_timeout(
  705. phy_drd->reg_pma + EXYNOS9_PMA_USBDP_CMN_REG01C0,
  706. reg, (reg & locked) == locked, sleep_us, timeout_us);
  707. if (err)
  708. dev_err(phy_drd->dev,
  709. "timed out waiting for PLL lock: %#.8x\n", reg);
  710. return err;
  711. }
  712. static void
  713. exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock(struct exynos5_usbdrd_phy *phy_drd)
  714. {
  715. static const unsigned int timeout_us = 40000;
  716. static const unsigned int sleep_us = 40;
  717. static const u32 locked =
  718. (TRSV_REG03C3_LN0_MON_RX_CDR_AFC_DONE
  719. | TRSV_REG03C3_LN0_MON_RX_CDR_CAL_DONE
  720. | TRSV_REG03C3_LN0_MON_RX_CDR_FLD_PLL_MODE_DONE
  721. | TRSV_REG03C3_LN0_MON_RX_CDR_LOCK_DONE);
  722. u32 reg;
  723. int err;
  724. err = readl_poll_timeout(
  725. /* lane depends on cable orientation */
  726. (phy_drd->reg_pma
  727. + ((phy_drd->orientation == TYPEC_ORIENTATION_NORMAL)
  728. ? EXYNOS9_PMA_USBDP_TRSV_REG03C3
  729. : EXYNOS9_PMA_USBDP_TRSV_REG07C3)),
  730. reg, (reg & locked) == locked, sleep_us, timeout_us);
  731. if (err)
  732. dev_err(phy_drd->dev,
  733. "timed out waiting for CDR(l%d) lock: %#.8x\n",
  734. ((phy_drd->orientation == TYPEC_ORIENTATION_NORMAL)
  735. ? 0
  736. : 2), reg);
  737. }
  738. static void exynos5_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)
  739. {
  740. u32 reg;
  741. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  742. /* Set Loss-of-Signal Detector sensitivity */
  743. reg &= ~PHYPARAM0_REF_LOSLEVEL;
  744. reg |= FIELD_PREP(PHYPARAM0_REF_LOSLEVEL, PHYPARAM0_REF_LOSLEVEL_VAL);
  745. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  746. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  747. /* Set Tx De-Emphasis level */
  748. reg &= ~PHYPARAM1_PCS_TXDEEMPH;
  749. reg |= FIELD_PREP(PHYPARAM1_PCS_TXDEEMPH, PHYPARAM1_PCS_TXDEEMPH_VAL);
  750. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  751. /* UTMI Power Control */
  752. writel(PHYUTMI_OTGDISABLE, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  753. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  754. reg &= ~PHYTEST_POWERDOWN_HSP;
  755. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  756. }
  757. static int exynos5_usbdrd_phy_init(struct phy *phy)
  758. {
  759. int ret;
  760. u32 reg;
  761. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  762. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  763. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  764. if (ret)
  765. return ret;
  766. /* Reset USB 3.0 PHY */
  767. writel(0x0, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
  768. writel(0x0, phy_drd->reg_phy + EXYNOS5_DRD_PHYRESUME);
  769. /*
  770. * Setting the Frame length Adj value[6:1] to default 0x20
  771. * See xHCI 1.0 spec, 5.2.4
  772. */
  773. reg = LINKSYSTEM_XHCI_VERSION_CONTROL |
  774. FIELD_PREP(LINKSYSTEM_FLADJ, 0x20);
  775. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_LINKSYSTEM);
  776. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  777. /* Select PHY CLK source */
  778. reg &= ~PHYPARAM0_REF_USE_PAD;
  779. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  780. /* This bit must be set for both HS and SS operations */
  781. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMICLKSEL);
  782. reg |= PHYUTMICLKSEL_UTMI_CLKSEL;
  783. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMICLKSEL);
  784. /* UTMI or PIPE3 specific init */
  785. inst->phy_cfg->phy_init(phy_drd);
  786. /* reference clock settings */
  787. reg = inst->phy_cfg->set_refclk(inst);
  788. /* Digital power supply in normal operating mode */
  789. reg |= PHYCLKRST_RETENABLEN |
  790. /* Enable ref clock for SS function */
  791. PHYCLKRST_REF_SSP_EN |
  792. /* Enable spread spectrum */
  793. PHYCLKRST_SSC_EN |
  794. /* Power down HS Bias and PLL blocks in suspend mode */
  795. PHYCLKRST_COMMONONN |
  796. /* Reset the port */
  797. PHYCLKRST_PORTRESET;
  798. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  799. fsleep(10);
  800. reg &= ~PHYCLKRST_PORTRESET;
  801. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  802. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  803. return 0;
  804. }
  805. static int exynos5_usbdrd_phy_exit(struct phy *phy)
  806. {
  807. int ret;
  808. u32 reg;
  809. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  810. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  811. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  812. if (ret)
  813. return ret;
  814. reg = PHYUTMI_OTGDISABLE |
  815. PHYUTMI_FORCESUSPEND |
  816. PHYUTMI_FORCESLEEP;
  817. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  818. /* Resetting the PHYCLKRST enable bits to reduce leakage current */
  819. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  820. reg &= ~(PHYCLKRST_REF_SSP_EN |
  821. PHYCLKRST_SSC_EN |
  822. PHYCLKRST_COMMONONN);
  823. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  824. /* Control PHYTEST to remove leakage current */
  825. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  826. reg |= PHYTEST_POWERDOWN_SSP |
  827. PHYTEST_POWERDOWN_HSP;
  828. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  829. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  830. return 0;
  831. }
  832. static int exynos5_usbdrd_phy_power_on(struct phy *phy)
  833. {
  834. int ret;
  835. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  836. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  837. dev_dbg(phy_drd->dev, "Request to power_on usbdrd_phy phy\n");
  838. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_core_clks,
  839. phy_drd->core_clks);
  840. if (ret)
  841. return ret;
  842. /* Enable VBUS supply */
  843. ret = regulator_bulk_enable(phy_drd->drv_data->n_regulators,
  844. phy_drd->regulators);
  845. if (ret) {
  846. dev_err(phy_drd->dev, "Failed to enable PHY regulator(s)\n");
  847. goto fail_vbus;
  848. }
  849. /* Power-on PHY */
  850. inst->phy_cfg->phy_isol(inst, false);
  851. return 0;
  852. fail_vbus:
  853. clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks,
  854. phy_drd->core_clks);
  855. return ret;
  856. }
  857. static int exynos5_usbdrd_phy_power_off(struct phy *phy)
  858. {
  859. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  860. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  861. dev_dbg(phy_drd->dev, "Request to power_off usbdrd_phy phy\n");
  862. /* Power-off the PHY */
  863. inst->phy_cfg->phy_isol(inst, true);
  864. /* Disable VBUS supply */
  865. regulator_bulk_disable(phy_drd->drv_data->n_regulators,
  866. phy_drd->regulators);
  867. clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks,
  868. phy_drd->core_clks);
  869. return 0;
  870. }
  871. static int crport_handshake(struct exynos5_usbdrd_phy *phy_drd,
  872. u32 val, u32 cmd)
  873. {
  874. unsigned int result;
  875. int err;
  876. writel(val | cmd, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
  877. err = readl_poll_timeout(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1,
  878. result, (result & PHYREG1_CR_ACK), 1, 100);
  879. if (err == -ETIMEDOUT) {
  880. dev_err(phy_drd->dev, "CRPORT handshake timeout1 (0x%08x)\n", val);
  881. return err;
  882. }
  883. writel(val, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
  884. err = readl_poll_timeout(phy_drd->reg_phy + EXYNOS5_DRD_PHYREG1,
  885. result, !(result & PHYREG1_CR_ACK), 1, 100);
  886. if (err == -ETIMEDOUT) {
  887. dev_err(phy_drd->dev, "CRPORT handshake timeout2 (0x%08x)\n", val);
  888. return err;
  889. }
  890. return 0;
  891. }
  892. static int crport_ctrl_write(struct exynos5_usbdrd_phy *phy_drd,
  893. u32 addr, u32 data)
  894. {
  895. u32 val;
  896. int ret;
  897. /* Write Address */
  898. val = FIELD_PREP(PHYREG0_CR_DATA_IN, addr);
  899. writel(val, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
  900. ret = crport_handshake(phy_drd, val, PHYREG0_CR_CAP_ADDR);
  901. if (ret)
  902. return ret;
  903. /* Write Data */
  904. val = FIELD_PREP(PHYREG0_CR_DATA_IN, data);
  905. writel(val, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
  906. ret = crport_handshake(phy_drd, val, PHYREG0_CR_CAP_DATA);
  907. if (ret)
  908. return ret;
  909. ret = crport_handshake(phy_drd, val, PHYREG0_CR_WRITE);
  910. return ret;
  911. }
  912. /*
  913. * Calibrate few PHY parameters using CR_PORT register to meet
  914. * SuperSpeed requirements on Exynos5420 and Exynos5800 systems,
  915. * which have 28nm USB 3.0 DRD PHY.
  916. */
  917. static int exynos5420_usbdrd_phy_calibrate(struct exynos5_usbdrd_phy *phy_drd)
  918. {
  919. unsigned int temp;
  920. int ret = 0;
  921. /*
  922. * Change los_bias to (0x5) for 28nm PHY from a
  923. * default value (0x0); los_level is set as default
  924. * (0x9) as also reflected in los_level[30:26] bits
  925. * of PHYPARAM0 register.
  926. */
  927. temp = LOSLEVEL_OVRD_IN_LOS_BIAS_5420 |
  928. LOSLEVEL_OVRD_IN_EN |
  929. LOSLEVEL_OVRD_IN_LOS_LEVEL_DEFAULT;
  930. ret = crport_ctrl_write(phy_drd,
  931. EXYNOS5_DRD_PHYSS_LOSLEVEL_OVRD_IN,
  932. temp);
  933. if (ret) {
  934. dev_err(phy_drd->dev,
  935. "Failed setting Loss-of-Signal level for SuperSpeed\n");
  936. return ret;
  937. }
  938. /*
  939. * Set tx_vboost_lvl to (0x5) for 28nm PHY Tuning,
  940. * to raise Tx signal level from its default value of (0x4)
  941. */
  942. temp = TX_VBOOSTLEVEL_OVRD_IN_VBOOST_5420;
  943. ret = crport_ctrl_write(phy_drd,
  944. EXYNOS5_DRD_PHYSS_TX_VBOOSTLEVEL_OVRD_IN,
  945. temp);
  946. if (ret) {
  947. dev_err(phy_drd->dev,
  948. "Failed setting Tx-Vboost-Level for SuperSpeed\n");
  949. return ret;
  950. }
  951. /*
  952. * Set proper time to wait for RxDetect measurement, for
  953. * desired reference clock of PHY, by tuning the CR_PORT
  954. * register LANE0.TX_DEBUG which is internal to PHY.
  955. * This fixes issue with few USB 3.0 devices, which are
  956. * not detected (not even generate interrupts on the bus
  957. * on insertion) without this change.
  958. * e.g. Samsung SUM-TSB16S 3.0 USB drive.
  959. */
  960. switch (phy_drd->extrefclk) {
  961. case EXYNOS5_FSEL_50MHZ:
  962. temp = LANE0_TX_DEBUG_RXDET_MEAS_TIME_48M_50M_52M;
  963. break;
  964. case EXYNOS5_FSEL_20MHZ:
  965. case EXYNOS5_FSEL_19MHZ2:
  966. temp = LANE0_TX_DEBUG_RXDET_MEAS_TIME_19M2_20M;
  967. break;
  968. case EXYNOS5_FSEL_24MHZ:
  969. default:
  970. temp = LANE0_TX_DEBUG_RXDET_MEAS_TIME_24M;
  971. break;
  972. }
  973. ret = crport_ctrl_write(phy_drd,
  974. EXYNOS5_DRD_PHYSS_LANE0_TX_DEBUG,
  975. temp);
  976. if (ret)
  977. dev_err(phy_drd->dev,
  978. "Fail to set RxDet measurement time for SuperSpeed\n");
  979. return ret;
  980. }
  981. static struct phy *exynos5_usbdrd_phy_xlate(struct device *dev,
  982. const struct of_phandle_args *args)
  983. {
  984. struct exynos5_usbdrd_phy *phy_drd = dev_get_drvdata(dev);
  985. if (WARN_ON(args->args[0] >= EXYNOS5_DRDPHYS_NUM))
  986. return ERR_PTR(-ENODEV);
  987. return phy_drd->phys[args->args[0]].phy;
  988. }
  989. static int exynos5_usbdrd_phy_calibrate(struct phy *phy)
  990. {
  991. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  992. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  993. if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI)
  994. return exynos5420_usbdrd_phy_calibrate(phy_drd);
  995. return 0;
  996. }
  997. static const struct phy_ops exynos5_usbdrd_phy_ops = {
  998. .init = exynos5_usbdrd_phy_init,
  999. .exit = exynos5_usbdrd_phy_exit,
  1000. .power_on = exynos5_usbdrd_phy_power_on,
  1001. .power_off = exynos5_usbdrd_phy_power_off,
  1002. .calibrate = exynos5_usbdrd_phy_calibrate,
  1003. .owner = THIS_MODULE,
  1004. };
  1005. static void exynos7870_usbdrd_phy_isol(struct phy_usb_instance *inst,
  1006. bool isolate)
  1007. {
  1008. unsigned int val;
  1009. if (!inst->reg_pmu)
  1010. return;
  1011. val = isolate ? 0 : EXYNOS7870_USB2PHY_ENABLE;
  1012. regmap_update_bits(inst->reg_pmu, inst->pmu_offset,
  1013. EXYNOS7870_USB2PHY_ENABLE, val);
  1014. }
  1015. static void exynos7870_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)
  1016. {
  1017. u32 reg;
  1018. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  1019. /* Use PADREFCLK as ref clock */
  1020. reg &= ~PHYCLKRST_REFCLKSEL;
  1021. reg |= FIELD_PREP(PHYCLKRST_REFCLKSEL, PHYCLKRST_REFCLKSEL_PAD_REFCLK);
  1022. /* Select ref clock rate */
  1023. reg &= ~PHYCLKRST_FSEL_UTMI;
  1024. reg &= ~PHYCLKRST_FSEL_PIPE;
  1025. reg |= FIELD_PREP(PHYCLKRST_FSEL_UTMI, phy_drd->extrefclk);
  1026. /* Enable suspend and reset the port */
  1027. reg |= PHYCLKRST_EN_UTMISUSPEND;
  1028. reg |= PHYCLKRST_COMMONONN;
  1029. reg |= PHYCLKRST_PORTRESET;
  1030. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  1031. udelay(10);
  1032. /* Clear the port reset bit */
  1033. reg &= ~PHYCLKRST_PORTRESET;
  1034. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  1035. /* Change PHY PLL tune value */
  1036. reg = readl(phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYPLLTUNE);
  1037. if (phy_drd->extrefclk == EXYNOS5_FSEL_24MHZ)
  1038. reg |= HSPHYPLLTUNE_PLL_B_TUNE;
  1039. else
  1040. reg &= ~HSPHYPLLTUNE_PLL_B_TUNE;
  1041. reg &= ~HSPHYPLLTUNE_PLL_P_TUNE;
  1042. reg |= FIELD_PREP(HSPHYPLLTUNE_PLL_P_TUNE, 14);
  1043. writel(reg, phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYPLLTUNE);
  1044. /* High-Speed PHY control */
  1045. reg = readl(phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYCTRL);
  1046. reg &= ~HSPHYCTRL_SIDDQ;
  1047. reg &= ~HSPHYCTRL_PHYSWRST;
  1048. reg &= ~HSPHYCTRL_PHYSWRSTALL;
  1049. writel(reg, phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYCTRL);
  1050. udelay(500);
  1051. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_LINKSYSTEM);
  1052. /*
  1053. * Setting the Frame length Adj value[6:1] to default 0x20
  1054. * See xHCI 1.0 spec, 5.2.4
  1055. */
  1056. reg |= LINKSYSTEM_XHCI_VERSION_CONTROL;
  1057. reg &= ~LINKSYSTEM_FLADJ;
  1058. reg |= FIELD_PREP(LINKSYSTEM_FLADJ, 0x20);
  1059. /* Set VBUSVALID signal as the VBUS pad is not used */
  1060. reg |= LINKSYSTEM_FORCE_BVALID;
  1061. reg |= LINKSYSTEM_FORCE_VBUSVALID;
  1062. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_LINKSYSTEM);
  1063. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  1064. /* Release force_sleep & force_suspend */
  1065. reg &= ~PHYUTMI_FORCESLEEP;
  1066. reg &= ~PHYUTMI_FORCESUSPEND;
  1067. /* DP/DM pull down control */
  1068. reg &= ~PHYUTMI_DMPULLDOWN;
  1069. reg &= ~PHYUTMI_DPPULLDOWN;
  1070. reg &= ~PHYUTMI_DRVVBUS;
  1071. /* Set DP-pull up as the VBUS pad is not used */
  1072. reg |= PHYUTMI_VBUSVLDEXTSEL;
  1073. reg |= PHYUTMI_VBUSVLDEXT;
  1074. /* Disable OTG block and VBUS valid comparator */
  1075. reg |= PHYUTMI_OTGDISABLE;
  1076. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  1077. /* Configure OVC IO usage */
  1078. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_LINKPORT);
  1079. reg |= LINKPORT_HOST_PORT_OVCR_U3_SEL | LINKPORT_HOST_PORT_OVCR_U2_SEL;
  1080. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_LINKPORT);
  1081. /* High-Speed PHY swrst */
  1082. reg = readl(phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYCTRL);
  1083. reg |= HSPHYCTRL_PHYSWRST;
  1084. writel(reg, phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYCTRL);
  1085. udelay(20);
  1086. /* Clear the PHY swrst bit */
  1087. reg = readl(phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYCTRL);
  1088. reg &= ~HSPHYCTRL_PHYSWRST;
  1089. writel(reg, phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYCTRL);
  1090. if (phy_drd->drv_data->phy_tunes)
  1091. exynos5_usbdrd_apply_phy_tunes(phy_drd,
  1092. PTS_UTMI_POSTINIT);
  1093. }
  1094. static int exynos7870_usbdrd_phy_init(struct phy *phy)
  1095. {
  1096. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  1097. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1098. int ret;
  1099. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  1100. if (ret)
  1101. return ret;
  1102. /* UTMI or PIPE3 specific init */
  1103. inst->phy_cfg->phy_init(phy_drd);
  1104. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  1105. return 0;
  1106. }
  1107. static int exynos7870_usbdrd_phy_exit(struct phy *phy)
  1108. {
  1109. int ret;
  1110. u32 reg;
  1111. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  1112. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1113. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  1114. if (ret)
  1115. return ret;
  1116. /*
  1117. * Disable the VBUS signal and the ID pull-up resistor.
  1118. * Enable force-suspend and force-sleep modes.
  1119. */
  1120. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  1121. reg &= ~(PHYUTMI_DRVVBUS | PHYUTMI_VBUSVLDEXT | PHYUTMI_VBUSVLDEXTSEL);
  1122. reg &= ~PHYUTMI_IDPULLUP;
  1123. reg |= PHYUTMI_FORCESUSPEND | PHYUTMI_FORCESLEEP;
  1124. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  1125. /* Power down PHY analog blocks */
  1126. reg = readl(phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYCTRL);
  1127. reg |= HSPHYCTRL_SIDDQ;
  1128. writel(reg, phy_drd->reg_phy + EXYNOS7870_DRD_HSPHYCTRL);
  1129. /* Clear VBUSVALID signal as the VBUS pad is not used */
  1130. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_LINKSYSTEM);
  1131. reg &= ~(LINKSYSTEM_FORCE_BVALID | LINKSYSTEM_FORCE_VBUSVALID);
  1132. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_LINKSYSTEM);
  1133. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  1134. return 0;
  1135. }
  1136. static const struct phy_ops exynos7870_usbdrd_phy_ops = {
  1137. .init = exynos7870_usbdrd_phy_init,
  1138. .exit = exynos7870_usbdrd_phy_exit,
  1139. .power_on = exynos5_usbdrd_phy_power_on,
  1140. .power_off = exynos5_usbdrd_phy_power_off,
  1141. .owner = THIS_MODULE,
  1142. };
  1143. static void exynos2200_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)
  1144. {
  1145. /* Configure non-Samsung IP PHY, responsible for UTMI */
  1146. phy_init(phy_drd->hs_phy);
  1147. }
  1148. static void exynos2200_usbdrd_link_init(struct exynos5_usbdrd_phy *phy_drd)
  1149. {
  1150. void __iomem *regs_base = phy_drd->reg_phy;
  1151. u32 reg;
  1152. /*
  1153. * Disable HWACG (hardware auto clock gating control). This will force
  1154. * QACTIVE signal in Q-Channel interface to HIGH level, to make sure
  1155. * the PHY clock is not gated by the hardware.
  1156. */
  1157. reg = readl(regs_base + EXYNOS850_DRD_LINKCTRL);
  1158. reg |= LINKCTRL_FORCE_QACT;
  1159. writel(reg, regs_base + EXYNOS850_DRD_LINKCTRL);
  1160. /* De-assert link reset */
  1161. reg = readl(regs_base + EXYNOS2200_DRD_CLKRST);
  1162. reg &= ~CLKRST_LINK_SW_RST;
  1163. writel(reg, regs_base + EXYNOS2200_DRD_CLKRST);
  1164. /* Set link VBUS Valid */
  1165. reg = readl(regs_base + EXYNOS2200_DRD_UTMI);
  1166. reg |= EXYNOS2200_UTMI_FORCE_BVALID | EXYNOS2200_UTMI_FORCE_VBUSVALID;
  1167. writel(reg, regs_base + EXYNOS2200_DRD_UTMI);
  1168. }
  1169. static void
  1170. exynos2200_usbdrd_link_attach_detach_pipe3_phy(struct phy_usb_instance *inst)
  1171. {
  1172. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1173. void __iomem *regs_base = phy_drd->reg_phy;
  1174. u32 reg;
  1175. reg = readl(regs_base + EXYNOS850_DRD_LINKCTRL);
  1176. if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI) {
  1177. /* force pipe3 signal for link */
  1178. reg &= ~LINKCTRL_FORCE_PHYSTATUS;
  1179. reg |= LINKCTRL_FORCE_PIPE_EN | LINKCTRL_FORCE_RXELECIDLE;
  1180. } else {
  1181. /* disable forcing pipe interface */
  1182. reg &= ~LINKCTRL_FORCE_PIPE_EN;
  1183. }
  1184. writel(reg, regs_base + EXYNOS850_DRD_LINKCTRL);
  1185. reg = readl(regs_base + EXYNOS2200_DRD_HSP_MISC);
  1186. if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI) {
  1187. /* calibrate only eUSB phy */
  1188. reg |= FIELD_PREP(HSP_MISC_RES_TUNE, RES_TUNE_PHY1);
  1189. reg |= HSP_MISC_SET_REQ_IN2;
  1190. } else {
  1191. /* calibrate for dual phy */
  1192. reg |= FIELD_PREP(HSP_MISC_RES_TUNE, RES_TUNE_PHY1_PHY2);
  1193. reg &= ~HSP_MISC_SET_REQ_IN2;
  1194. }
  1195. writel(reg, regs_base + EXYNOS2200_DRD_HSP_MISC);
  1196. reg = readl(regs_base + EXYNOS2200_DRD_CLKRST);
  1197. if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI)
  1198. reg &= ~EXYNOS2200_CLKRST_LINK_PCLK_SEL;
  1199. else
  1200. reg |= EXYNOS2200_CLKRST_LINK_PCLK_SEL;
  1201. writel(reg, regs_base + EXYNOS2200_DRD_CLKRST);
  1202. }
  1203. static int exynos2200_usbdrd_phy_init(struct phy *phy)
  1204. {
  1205. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  1206. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1207. int ret;
  1208. if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI) {
  1209. /* Power-on PHY ... */
  1210. ret = regulator_bulk_enable(phy_drd->drv_data->n_regulators,
  1211. phy_drd->regulators);
  1212. if (ret) {
  1213. dev_err(phy_drd->dev,
  1214. "Failed to enable PHY regulator(s)\n");
  1215. return ret;
  1216. }
  1217. }
  1218. /*
  1219. * ... and ungate power via PMU. Without this here, we get an SError
  1220. * trying to access PMA registers
  1221. */
  1222. exynos5_usbdrd_phy_isol(inst, false);
  1223. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  1224. if (ret)
  1225. return ret;
  1226. /* Set up the link controller */
  1227. exynos2200_usbdrd_link_init(phy_drd);
  1228. /* UTMI or PIPE3 link preparation */
  1229. exynos2200_usbdrd_link_attach_detach_pipe3_phy(inst);
  1230. /* UTMI or PIPE3 specific init */
  1231. inst->phy_cfg->phy_init(phy_drd);
  1232. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  1233. return 0;
  1234. }
  1235. static int exynos2200_usbdrd_phy_exit(struct phy *phy)
  1236. {
  1237. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  1238. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1239. void __iomem *regs_base = phy_drd->reg_phy;
  1240. u32 reg;
  1241. int ret;
  1242. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  1243. if (ret)
  1244. return ret;
  1245. reg = readl(regs_base + EXYNOS2200_DRD_UTMI);
  1246. reg &= ~(EXYNOS2200_UTMI_FORCE_BVALID | EXYNOS2200_UTMI_FORCE_VBUSVALID);
  1247. writel(reg, regs_base + EXYNOS2200_DRD_UTMI);
  1248. reg = readl(regs_base + EXYNOS2200_DRD_CLKRST);
  1249. reg |= CLKRST_LINK_SW_RST;
  1250. writel(reg, regs_base + EXYNOS2200_DRD_CLKRST);
  1251. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  1252. exynos5_usbdrd_phy_isol(inst, true);
  1253. return regulator_bulk_disable(phy_drd->drv_data->n_regulators,
  1254. phy_drd->regulators);
  1255. }
  1256. static const struct phy_ops exynos2200_usbdrd_phy_ops = {
  1257. .init = exynos2200_usbdrd_phy_init,
  1258. .exit = exynos2200_usbdrd_phy_exit,
  1259. .owner = THIS_MODULE,
  1260. };
  1261. static void
  1262. exynos5_usbdrd_usb_v3p1_pipe_override(struct exynos5_usbdrd_phy *phy_drd)
  1263. {
  1264. void __iomem *regs_base = phy_drd->reg_phy;
  1265. u32 reg;
  1266. /* force pipe3 signal for link */
  1267. reg = readl(regs_base + EXYNOS850_DRD_LINKCTRL);
  1268. reg &= ~LINKCTRL_FORCE_PHYSTATUS;
  1269. reg |= LINKCTRL_FORCE_PIPE_EN | LINKCTRL_FORCE_RXELECIDLE;
  1270. writel(reg, regs_base + EXYNOS850_DRD_LINKCTRL);
  1271. /* PMA disable */
  1272. reg = readl(regs_base + EXYNOS850_DRD_SECPMACTL);
  1273. reg |= SECPMACTL_PMA_LOW_PWR;
  1274. writel(reg, regs_base + EXYNOS850_DRD_SECPMACTL);
  1275. }
  1276. static void exynos850_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)
  1277. {
  1278. void __iomem *regs_base = phy_drd->reg_phy;
  1279. u32 reg;
  1280. u32 ss_ports;
  1281. /*
  1282. * Disable HWACG (hardware auto clock gating control). This will force
  1283. * QACTIVE signal in Q-Channel interface to HIGH level, to make sure
  1284. * the PHY clock is not gated by the hardware.
  1285. */
  1286. reg = readl(regs_base + EXYNOS850_DRD_LINKCTRL);
  1287. reg |= LINKCTRL_FORCE_QACT;
  1288. writel(reg, regs_base + EXYNOS850_DRD_LINKCTRL);
  1289. reg = readl(regs_base + EXYNOS850_DRD_LINKPORT);
  1290. ss_ports = FIELD_GET(LINKPORT_HOST_NUM_U3, reg);
  1291. /* Start PHY Reset (POR=high) */
  1292. reg = readl(regs_base + EXYNOS850_DRD_CLKRST);
  1293. if (ss_ports) {
  1294. reg |= CLKRST_PHY20_SW_POR;
  1295. reg |= CLKRST_PHY20_SW_POR_SEL;
  1296. reg |= CLKRST_PHY_RESET_SEL;
  1297. }
  1298. reg |= CLKRST_PHY_SW_RST;
  1299. writel(reg, regs_base + EXYNOS850_DRD_CLKRST);
  1300. /* Enable UTMI+ */
  1301. reg = readl(regs_base + EXYNOS850_DRD_UTMI);
  1302. reg &= ~(UTMI_FORCE_SUSPEND | UTMI_FORCE_SLEEP | UTMI_DP_PULLDOWN |
  1303. UTMI_DM_PULLDOWN);
  1304. writel(reg, regs_base + EXYNOS850_DRD_UTMI);
  1305. /* Set PHY clock and control HS PHY */
  1306. reg = readl(regs_base + EXYNOS850_DRD_HSP);
  1307. reg |= HSP_EN_UTMISUSPEND | HSP_COMMONONN;
  1308. writel(reg, regs_base + EXYNOS850_DRD_HSP);
  1309. /* Set VBUS Valid and D+ pull-up control by VBUS pad usage */
  1310. reg = readl(regs_base + EXYNOS850_DRD_LINKCTRL);
  1311. reg |= FIELD_PREP(LINKCTRL_BUS_FILTER_BYPASS, 0xf);
  1312. writel(reg, regs_base + EXYNOS850_DRD_LINKCTRL);
  1313. if (!phy_drd->sw) {
  1314. reg = readl(regs_base + EXYNOS850_DRD_UTMI);
  1315. reg |= UTMI_FORCE_BVALID | UTMI_FORCE_VBUSVALID;
  1316. writel(reg, regs_base + EXYNOS850_DRD_UTMI);
  1317. reg = readl(regs_base + EXYNOS850_DRD_HSP);
  1318. reg |= HSP_VBUSVLDEXT | HSP_VBUSVLDEXTSEL;
  1319. writel(reg, regs_base + EXYNOS850_DRD_HSP);
  1320. }
  1321. reg = readl(regs_base + EXYNOS850_DRD_SSPPLLCTL);
  1322. reg &= ~SSPPLLCTL_FSEL;
  1323. switch (phy_drd->extrefclk) {
  1324. case EXYNOS5_FSEL_50MHZ:
  1325. reg |= FIELD_PREP(SSPPLLCTL_FSEL, 7);
  1326. break;
  1327. case EXYNOS5_FSEL_26MHZ:
  1328. reg |= FIELD_PREP(SSPPLLCTL_FSEL, 6);
  1329. break;
  1330. case EXYNOS5_FSEL_24MHZ:
  1331. reg |= FIELD_PREP(SSPPLLCTL_FSEL, 2);
  1332. break;
  1333. case EXYNOS5_FSEL_20MHZ:
  1334. reg |= FIELD_PREP(SSPPLLCTL_FSEL, 1);
  1335. break;
  1336. case EXYNOS5_FSEL_19MHZ2:
  1337. reg |= FIELD_PREP(SSPPLLCTL_FSEL, 0);
  1338. break;
  1339. default:
  1340. dev_warn(phy_drd->dev, "unsupported ref clk: %#.2x\n",
  1341. phy_drd->extrefclk);
  1342. break;
  1343. }
  1344. writel(reg, regs_base + EXYNOS850_DRD_SSPPLLCTL);
  1345. if (phy_drd->drv_data->phy_tunes)
  1346. exynos5_usbdrd_apply_phy_tunes(phy_drd,
  1347. PTS_UTMI_POSTINIT);
  1348. /* Power up PHY analog blocks */
  1349. reg = readl(regs_base + EXYNOS850_DRD_HSP_TEST);
  1350. reg &= ~HSP_TEST_SIDDQ;
  1351. writel(reg, regs_base + EXYNOS850_DRD_HSP_TEST);
  1352. /* Finish PHY reset (POR=low) */
  1353. fsleep(10); /* required before doing POR=low */
  1354. reg = readl(regs_base + EXYNOS850_DRD_CLKRST);
  1355. if (ss_ports) {
  1356. reg |= CLKRST_PHY20_SW_POR_SEL;
  1357. reg &= ~CLKRST_PHY20_SW_POR;
  1358. }
  1359. reg &= ~(CLKRST_PHY_SW_RST | CLKRST_PORT_RST);
  1360. writel(reg, regs_base + EXYNOS850_DRD_CLKRST);
  1361. fsleep(75); /* required after POR=low for guaranteed PHY clock */
  1362. /* Disable single ended signal out */
  1363. reg = readl(regs_base + EXYNOS850_DRD_HSP);
  1364. reg &= ~HSP_FSV_OUT_EN;
  1365. writel(reg, regs_base + EXYNOS850_DRD_HSP);
  1366. if (ss_ports)
  1367. exynos5_usbdrd_usb_v3p1_pipe_override(phy_drd);
  1368. }
  1369. static int exynos850_usbdrd_phy_init(struct phy *phy)
  1370. {
  1371. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  1372. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1373. int ret;
  1374. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  1375. if (ret)
  1376. return ret;
  1377. /* UTMI or PIPE3 specific init */
  1378. scoped_guard(mutex, &phy_drd->phy_mutex)
  1379. inst->phy_cfg->phy_init(phy_drd);
  1380. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  1381. return 0;
  1382. }
  1383. static int exynos850_usbdrd_phy_exit(struct phy *phy)
  1384. {
  1385. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  1386. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1387. void __iomem *regs_base = phy_drd->reg_phy;
  1388. u32 reg;
  1389. int ret;
  1390. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  1391. if (ret)
  1392. return ret;
  1393. guard(mutex)(&phy_drd->phy_mutex);
  1394. /* Set PHY clock and control HS PHY */
  1395. reg = readl(regs_base + EXYNOS850_DRD_UTMI);
  1396. reg &= ~(UTMI_DP_PULLDOWN | UTMI_DM_PULLDOWN);
  1397. reg |= UTMI_FORCE_SUSPEND | UTMI_FORCE_SLEEP;
  1398. writel(reg, regs_base + EXYNOS850_DRD_UTMI);
  1399. /* Power down PHY analog blocks */
  1400. reg = readl(regs_base + EXYNOS850_DRD_HSP_TEST);
  1401. reg |= HSP_TEST_SIDDQ;
  1402. writel(reg, regs_base + EXYNOS850_DRD_HSP_TEST);
  1403. /* Link reset */
  1404. reg = readl(regs_base + EXYNOS850_DRD_CLKRST);
  1405. reg |= CLKRST_LINK_SW_RST;
  1406. writel(reg, regs_base + EXYNOS850_DRD_CLKRST);
  1407. fsleep(10); /* required before doing POR=low */
  1408. reg &= ~CLKRST_LINK_SW_RST;
  1409. writel(reg, regs_base + EXYNOS850_DRD_CLKRST);
  1410. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  1411. return 0;
  1412. }
  1413. static const struct phy_ops exynos850_usbdrd_phy_ops = {
  1414. .init = exynos850_usbdrd_phy_init,
  1415. .exit = exynos850_usbdrd_phy_exit,
  1416. .power_on = exynos5_usbdrd_phy_power_on,
  1417. .power_off = exynos5_usbdrd_phy_power_off,
  1418. .owner = THIS_MODULE,
  1419. };
  1420. static void exynos5_usbdrd_gs101_pipe3_init(struct exynos5_usbdrd_phy *phy_drd)
  1421. {
  1422. void __iomem *regs_pma = phy_drd->reg_pma;
  1423. void __iomem *regs_phy = phy_drd->reg_phy;
  1424. u32 reg;
  1425. exynos5_usbdrd_usbdp_g2_v4_ctrl_pma_ready(phy_drd);
  1426. /* force aux off */
  1427. reg = readl(regs_pma + EXYNOS9_PMA_USBDP_CMN_REG0008);
  1428. reg &= ~CMN_REG0008_AUX_EN;
  1429. reg |= CMN_REG0008_OVRD_AUX_EN;
  1430. writel(reg, regs_pma + EXYNOS9_PMA_USBDP_CMN_REG0008);
  1431. exynos5_usbdrd_apply_phy_tunes(phy_drd, PTS_PIPE3_PREINIT);
  1432. exynos5_usbdrd_apply_phy_tunes(phy_drd, PTS_PIPE3_INIT);
  1433. exynos5_usbdrd_apply_phy_tunes(phy_drd, PTS_PIPE3_POSTINIT);
  1434. exynos5_usbdrd_usbdp_g2_v4_pma_lane_mux_sel(phy_drd);
  1435. /* reset release from port */
  1436. reg = readl(regs_phy + EXYNOS850_DRD_SECPMACTL);
  1437. reg &= ~(SECPMACTL_PMA_TRSV_SW_RST | SECPMACTL_PMA_CMN_SW_RST |
  1438. SECPMACTL_PMA_INIT_SW_RST);
  1439. writel(reg, regs_phy + EXYNOS850_DRD_SECPMACTL);
  1440. if (!exynos5_usbdrd_usbdp_g2_v4_pma_check_pll_lock(phy_drd))
  1441. exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock(phy_drd);
  1442. }
  1443. static int exynos5_usbdrd_gs101_phy_init(struct phy *phy)
  1444. {
  1445. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  1446. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1447. int ret;
  1448. if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI) {
  1449. /* Power-on PHY ... */
  1450. ret = regulator_bulk_enable(phy_drd->drv_data->n_regulators,
  1451. phy_drd->regulators);
  1452. if (ret) {
  1453. dev_err(phy_drd->dev,
  1454. "Failed to enable PHY regulator(s)\n");
  1455. return ret;
  1456. }
  1457. }
  1458. /*
  1459. * ... and ungate power via PMU. Without this here, we get an SError
  1460. * trying to access PMA registers
  1461. */
  1462. exynos5_usbdrd_phy_isol(inst, false);
  1463. return exynos850_usbdrd_phy_init(phy);
  1464. }
  1465. static int exynos5_usbdrd_gs101_phy_exit(struct phy *phy)
  1466. {
  1467. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  1468. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  1469. int ret;
  1470. if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI) {
  1471. ret = exynos850_usbdrd_phy_exit(phy);
  1472. if (ret)
  1473. return ret;
  1474. }
  1475. exynos5_usbdrd_phy_isol(inst, true);
  1476. if (inst->phy_cfg->id != EXYNOS5_DRDPHY_UTMI)
  1477. return 0;
  1478. return regulator_bulk_disable(phy_drd->drv_data->n_regulators,
  1479. phy_drd->regulators);
  1480. }
  1481. static const struct phy_ops gs101_usbdrd_phy_ops = {
  1482. .init = exynos5_usbdrd_gs101_phy_init,
  1483. .exit = exynos5_usbdrd_gs101_phy_exit,
  1484. .owner = THIS_MODULE,
  1485. };
  1486. static int exynos5_usbdrd_phy_clk_handle(struct exynos5_usbdrd_phy *phy_drd)
  1487. {
  1488. int ret;
  1489. struct clk *ref_clk;
  1490. unsigned long ref_rate;
  1491. phy_drd->clks = devm_kcalloc(phy_drd->dev, phy_drd->drv_data->n_clks,
  1492. sizeof(*phy_drd->clks), GFP_KERNEL);
  1493. if (!phy_drd->clks)
  1494. return -ENOMEM;
  1495. for (int i = 0; i < phy_drd->drv_data->n_clks; ++i)
  1496. phy_drd->clks[i].id = phy_drd->drv_data->clk_names[i];
  1497. ret = devm_clk_bulk_get(phy_drd->dev, phy_drd->drv_data->n_clks,
  1498. phy_drd->clks);
  1499. if (ret)
  1500. return dev_err_probe(phy_drd->dev, ret,
  1501. "failed to get phy clock(s)\n");
  1502. phy_drd->core_clks = devm_kcalloc(phy_drd->dev,
  1503. phy_drd->drv_data->n_core_clks,
  1504. sizeof(*phy_drd->core_clks),
  1505. GFP_KERNEL);
  1506. if (!phy_drd->core_clks)
  1507. return -ENOMEM;
  1508. for (int i = 0; i < phy_drd->drv_data->n_core_clks; ++i)
  1509. phy_drd->core_clks[i].id = phy_drd->drv_data->core_clk_names[i];
  1510. ret = devm_clk_bulk_get(phy_drd->dev, phy_drd->drv_data->n_core_clks,
  1511. phy_drd->core_clks);
  1512. if (ret)
  1513. return dev_err_probe(phy_drd->dev, ret,
  1514. "failed to get phy core clock(s)\n");
  1515. if (phy_drd->drv_data->n_core_clks) {
  1516. ref_clk = NULL;
  1517. for (int i = 0; i < phy_drd->drv_data->n_core_clks; ++i) {
  1518. if (!strcmp(phy_drd->core_clks[i].id, "ref")) {
  1519. ref_clk = phy_drd->core_clks[i].clk;
  1520. break;
  1521. }
  1522. }
  1523. if (!ref_clk)
  1524. return dev_err_probe(phy_drd->dev, -ENODEV,
  1525. "failed to find phy reference clock\n");
  1526. ref_rate = clk_get_rate(ref_clk);
  1527. ret = exynos5_rate_to_clk(ref_rate, &phy_drd->extrefclk);
  1528. if (ret)
  1529. return dev_err_probe(phy_drd->dev, ret,
  1530. "clock rate (%ld) not supported\n",
  1531. ref_rate);
  1532. }
  1533. return 0;
  1534. }
  1535. static const struct exynos5_usbdrd_phy_config phy_cfg_exynos2200[] = {
  1536. {
  1537. .id = EXYNOS5_DRDPHY_UTMI,
  1538. .phy_isol = exynos5_usbdrd_phy_isol,
  1539. .phy_init = exynos2200_usbdrd_utmi_init,
  1540. },
  1541. };
  1542. static int exynos5_usbdrd_orien_sw_set(struct typec_switch_dev *sw,
  1543. enum typec_orientation orientation)
  1544. {
  1545. struct exynos5_usbdrd_phy *phy_drd = typec_switch_get_drvdata(sw);
  1546. int ret;
  1547. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  1548. if (ret) {
  1549. dev_err(phy_drd->dev, "Failed to enable PHY clocks(s)\n");
  1550. return ret;
  1551. }
  1552. scoped_guard(mutex, &phy_drd->phy_mutex) {
  1553. void __iomem * const regs_base = phy_drd->reg_phy;
  1554. unsigned int reg;
  1555. if (orientation == TYPEC_ORIENTATION_NONE) {
  1556. reg = readl(regs_base + EXYNOS850_DRD_UTMI);
  1557. reg &= ~(UTMI_FORCE_VBUSVALID | UTMI_FORCE_BVALID);
  1558. writel(reg, regs_base + EXYNOS850_DRD_UTMI);
  1559. reg = readl(regs_base + EXYNOS850_DRD_HSP);
  1560. reg |= HSP_VBUSVLDEXTSEL;
  1561. reg &= ~HSP_VBUSVLDEXT;
  1562. writel(reg, regs_base + EXYNOS850_DRD_HSP);
  1563. } else {
  1564. reg = readl(regs_base + EXYNOS850_DRD_UTMI);
  1565. reg |= UTMI_FORCE_VBUSVALID | UTMI_FORCE_BVALID;
  1566. writel(reg, regs_base + EXYNOS850_DRD_UTMI);
  1567. reg = readl(regs_base + EXYNOS850_DRD_HSP);
  1568. reg |= HSP_VBUSVLDEXTSEL | HSP_VBUSVLDEXT;
  1569. writel(reg, regs_base + EXYNOS850_DRD_HSP);
  1570. }
  1571. phy_drd->orientation = orientation;
  1572. }
  1573. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  1574. return 0;
  1575. }
  1576. static void exynos5_usbdrd_orien_switch_unregister(void *data)
  1577. {
  1578. struct exynos5_usbdrd_phy *phy_drd = data;
  1579. typec_switch_unregister(phy_drd->sw);
  1580. }
  1581. static int exynos5_usbdrd_setup_notifiers(struct exynos5_usbdrd_phy *phy_drd)
  1582. {
  1583. int ret;
  1584. if (!IS_ENABLED(CONFIG_TYPEC))
  1585. return 0;
  1586. if (device_property_present(phy_drd->dev, "orientation-switch")) {
  1587. struct typec_switch_desc sw_desc = { };
  1588. sw_desc.drvdata = phy_drd;
  1589. sw_desc.fwnode = dev_fwnode(phy_drd->dev);
  1590. sw_desc.set = exynos5_usbdrd_orien_sw_set;
  1591. phy_drd->sw = typec_switch_register(phy_drd->dev, &sw_desc);
  1592. if (IS_ERR(phy_drd->sw))
  1593. return dev_err_probe(phy_drd->dev,
  1594. PTR_ERR(phy_drd->sw),
  1595. "Failed to register TypeC orientation switch\n");
  1596. ret = devm_add_action_or_reset(phy_drd->dev,
  1597. exynos5_usbdrd_orien_switch_unregister,
  1598. phy_drd);
  1599. if (ret)
  1600. return dev_err_probe(phy_drd->dev, ret,
  1601. "Failed to register TypeC orientation devm action\n");
  1602. }
  1603. return 0;
  1604. }
  1605. static const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = {
  1606. {
  1607. .id = EXYNOS5_DRDPHY_UTMI,
  1608. .phy_isol = exynos5_usbdrd_phy_isol,
  1609. .phy_init = exynos5_usbdrd_utmi_init,
  1610. .set_refclk = exynos5_usbdrd_utmi_set_refclk,
  1611. },
  1612. {
  1613. .id = EXYNOS5_DRDPHY_PIPE3,
  1614. .phy_isol = exynos5_usbdrd_phy_isol,
  1615. .phy_init = exynos5_usbdrd_pipe3_init,
  1616. .set_refclk = exynos5_usbdrd_pipe3_set_refclk,
  1617. },
  1618. };
  1619. static const struct exynos5_usbdrd_phy_config phy_cfg_exynos7870[] = {
  1620. {
  1621. .id = EXYNOS5_DRDPHY_UTMI,
  1622. .phy_isol = exynos7870_usbdrd_phy_isol,
  1623. .phy_init = exynos7870_usbdrd_utmi_init,
  1624. },
  1625. };
  1626. static const struct exynos5_usbdrd_phy_config phy_cfg_exynos850[] = {
  1627. {
  1628. .id = EXYNOS5_DRDPHY_UTMI,
  1629. .phy_isol = exynos5_usbdrd_phy_isol,
  1630. .phy_init = exynos850_usbdrd_utmi_init,
  1631. },
  1632. };
  1633. static
  1634. const struct exynos5_usbdrd_phy_tuning exynos7870_tunes_utmi_postinit[] = {
  1635. PHY_TUNING_ENTRY_PHY(EXYNOS5_DRD_PHYPARAM0,
  1636. (PHYPARAM0_TXVREFTUNE | PHYPARAM0_TXRISETUNE |
  1637. PHYPARAM0_TXRESTUNE | PHYPARAM0_TXPREEMPPULSETUNE |
  1638. PHYPARAM0_TXPREEMPAMPTUNE | PHYPARAM0_TXHSXVTUNE |
  1639. PHYPARAM0_TXFSLSTUNE | PHYPARAM0_SQRXTUNE |
  1640. PHYPARAM0_OTGTUNE | PHYPARAM0_COMPDISTUNE),
  1641. (FIELD_PREP_CONST(PHYPARAM0_TXVREFTUNE, 14) |
  1642. FIELD_PREP_CONST(PHYPARAM0_TXRISETUNE, 1) |
  1643. FIELD_PREP_CONST(PHYPARAM0_TXRESTUNE, 3) |
  1644. FIELD_PREP_CONST(PHYPARAM0_TXPREEMPAMPTUNE, 0) |
  1645. FIELD_PREP_CONST(PHYPARAM0_TXHSXVTUNE, 0) |
  1646. FIELD_PREP_CONST(PHYPARAM0_TXFSLSTUNE, 3) |
  1647. FIELD_PREP_CONST(PHYPARAM0_SQRXTUNE, 6) |
  1648. FIELD_PREP_CONST(PHYPARAM0_OTGTUNE, 2) |
  1649. FIELD_PREP_CONST(PHYPARAM0_COMPDISTUNE, 3))),
  1650. PHY_TUNING_ENTRY_LAST
  1651. };
  1652. static const struct exynos5_usbdrd_phy_tuning *exynos7870_tunes[PTS_MAX] = {
  1653. [PTS_UTMI_POSTINIT] = exynos7870_tunes_utmi_postinit,
  1654. };
  1655. static const char * const exynos5_clk_names[] = {
  1656. "phy",
  1657. };
  1658. static const char * const exynos5_core_clk_names[] = {
  1659. "ref",
  1660. };
  1661. static const char * const exynos5433_core_clk_names[] = {
  1662. "ref", "phy_pipe", "phy_utmi", "itp",
  1663. };
  1664. static const char * const exynos5_regulator_names[] = {
  1665. "vbus", "vbus-boost",
  1666. };
  1667. static const struct exynos5_usbdrd_phy_drvdata exynos2200_usb32drd_phy = {
  1668. .phy_cfg = phy_cfg_exynos2200,
  1669. .phy_ops = &exynos2200_usbdrd_phy_ops,
  1670. .pmu_offset_usbdrd0_phy = EXYNOS2200_PHY_CTRL_USB20,
  1671. .clk_names = exynos5_clk_names,
  1672. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  1673. /* clocks and regulators are specific to the underlying PHY blocks */
  1674. .core_clk_names = NULL,
  1675. .n_core_clks = 0,
  1676. .regulator_names = NULL,
  1677. .n_regulators = 0,
  1678. };
  1679. static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = {
  1680. .phy_cfg = phy_cfg_exynos5,
  1681. .phy_ops = &exynos5_usbdrd_phy_ops,
  1682. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  1683. .pmu_offset_usbdrd1_phy = EXYNOS5420_USBDRD1_PHY_CONTROL,
  1684. .clk_names = exynos5_clk_names,
  1685. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  1686. .core_clk_names = exynos5_core_clk_names,
  1687. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  1688. .regulator_names = exynos5_regulator_names,
  1689. .n_regulators = ARRAY_SIZE(exynos5_regulator_names),
  1690. };
  1691. static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = {
  1692. .phy_cfg = phy_cfg_exynos5,
  1693. .phy_ops = &exynos5_usbdrd_phy_ops,
  1694. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  1695. .clk_names = exynos5_clk_names,
  1696. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  1697. .core_clk_names = exynos5_core_clk_names,
  1698. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  1699. .regulator_names = exynos5_regulator_names,
  1700. .n_regulators = ARRAY_SIZE(exynos5_regulator_names),
  1701. };
  1702. static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = {
  1703. .phy_cfg = phy_cfg_exynos5,
  1704. .phy_ops = &exynos5_usbdrd_phy_ops,
  1705. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  1706. .pmu_offset_usbdrd1_phy = EXYNOS5433_USBHOST30_PHY_CONTROL,
  1707. .clk_names = exynos5_clk_names,
  1708. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  1709. .core_clk_names = exynos5433_core_clk_names,
  1710. .n_core_clks = ARRAY_SIZE(exynos5433_core_clk_names),
  1711. .regulator_names = exynos5_regulator_names,
  1712. .n_regulators = ARRAY_SIZE(exynos5_regulator_names),
  1713. };
  1714. static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = {
  1715. .phy_cfg = phy_cfg_exynos5,
  1716. .phy_ops = &exynos5_usbdrd_phy_ops,
  1717. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  1718. .clk_names = exynos5_clk_names,
  1719. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  1720. .core_clk_names = exynos5433_core_clk_names,
  1721. .n_core_clks = ARRAY_SIZE(exynos5433_core_clk_names),
  1722. .regulator_names = exynos5_regulator_names,
  1723. .n_regulators = ARRAY_SIZE(exynos5_regulator_names),
  1724. };
  1725. static const struct exynos5_usbdrd_phy_drvdata exynos7870_usbdrd_phy = {
  1726. .phy_cfg = phy_cfg_exynos7870,
  1727. .phy_tunes = exynos7870_tunes,
  1728. .phy_ops = &exynos7870_usbdrd_phy_ops,
  1729. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  1730. .clk_names = exynos5_clk_names,
  1731. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  1732. .core_clk_names = exynos5_core_clk_names,
  1733. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  1734. .regulator_names = exynos5_regulator_names,
  1735. .n_regulators = ARRAY_SIZE(exynos5_regulator_names),
  1736. };
  1737. static const struct exynos5_usbdrd_phy_drvdata exynos850_usbdrd_phy = {
  1738. .phy_cfg = phy_cfg_exynos850,
  1739. .phy_ops = &exynos850_usbdrd_phy_ops,
  1740. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  1741. .clk_names = exynos5_clk_names,
  1742. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  1743. .core_clk_names = exynos5_core_clk_names,
  1744. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  1745. .regulator_names = exynos5_regulator_names,
  1746. .n_regulators = ARRAY_SIZE(exynos5_regulator_names),
  1747. };
  1748. static const struct exynos5_usbdrd_phy_tuning exynos990_tunes_utmi_postinit[] = {
  1749. PHY_TUNING_ENTRY_PHY(EXYNOS850_DRD_HSPPARACON,
  1750. (HSPPARACON_TXVREF |
  1751. HSPPARACON_TXPREEMPAMP | HSPPARACON_SQRX |
  1752. HSPPARACON_COMPDIS),
  1753. (FIELD_PREP_CONST(HSPPARACON_TXVREF, 7) |
  1754. FIELD_PREP_CONST(HSPPARACON_TXPREEMPAMP, 3) |
  1755. FIELD_PREP_CONST(HSPPARACON_SQRX, 5) |
  1756. FIELD_PREP_CONST(HSPPARACON_COMPDIS, 7))),
  1757. PHY_TUNING_ENTRY_LAST
  1758. };
  1759. static const struct exynos5_usbdrd_phy_tuning *exynos990_tunes[PTS_MAX] = {
  1760. [PTS_UTMI_POSTINIT] = exynos990_tunes_utmi_postinit,
  1761. };
  1762. static const struct exynos5_usbdrd_phy_drvdata exynos990_usbdrd_phy = {
  1763. .phy_cfg = phy_cfg_exynos850,
  1764. .phy_ops = &exynos850_usbdrd_phy_ops,
  1765. .phy_tunes = exynos990_tunes,
  1766. .pmu_offset_usbdrd0_phy = EXYNOS990_PHY_CTRL_USB20,
  1767. .clk_names = exynos5_clk_names,
  1768. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  1769. .core_clk_names = exynos5_core_clk_names,
  1770. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  1771. .regulator_names = exynos5_regulator_names,
  1772. .n_regulators = ARRAY_SIZE(exynos5_regulator_names),
  1773. };
  1774. static void
  1775. exynosautov920_usb31drd_cr_clk(struct exynos5_usbdrd_phy *phy_drd, bool high)
  1776. {
  1777. void __iomem *reg_phy = phy_drd->reg_phy;
  1778. u32 reg;
  1779. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1780. if (high)
  1781. reg |= PHY_CR_PARA_CON0_PHY0_CR_PARA_CLK;
  1782. else
  1783. reg &= ~PHY_CR_PARA_CON0_PHY0_CR_PARA_CLK;
  1784. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1785. fsleep(1);
  1786. }
  1787. static void
  1788. exynosautov920_usb31drd_port_phy_ready(struct exynos5_usbdrd_phy *phy_drd)
  1789. {
  1790. struct device *dev = phy_drd->dev;
  1791. void __iomem *reg_phy = phy_drd->reg_phy;
  1792. static const unsigned int timeout_us = 20000;
  1793. static const unsigned int sleep_us = 40;
  1794. u32 reg;
  1795. int err;
  1796. /* Clear cr_para_con */
  1797. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1798. reg &= ~(PHY_CR_PARA_CON0_PHY0_CR_PARA_CLK |
  1799. PHY_CR_PARA_CON0_PHY0_CR_PARA_ADDR);
  1800. reg |= PHY_CR_PARA_CON0_PHY0_CR_PARA_SEL;
  1801. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1802. writel(0x0, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON1);
  1803. writel(0x0, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON2);
  1804. exynosautov920_usb31drd_cr_clk(phy_drd, true);
  1805. exynosautov920_usb31drd_cr_clk(phy_drd, false);
  1806. /*
  1807. * The maximum time from phy reset de-assertion to de-assertion of
  1808. * tx/rx_ack can be as high as 5ms in fast simulation mode.
  1809. * Time to phy ready is < 20ms
  1810. */
  1811. err = readl_poll_timeout(reg_phy +
  1812. EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0,
  1813. reg, !(reg & PHY_CR_PARA_CON0_PHY0_CR_PARA_ACK),
  1814. sleep_us, timeout_us);
  1815. if (err)
  1816. dev_err(dev, "timed out waiting for rx/tx_ack: %#.8x\n", reg);
  1817. reg &= ~PHY_CR_PARA_CON0_PHY0_CR_PARA_CLK;
  1818. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1819. }
  1820. static void
  1821. exynosautov920_usb31drd_cr_write(struct exynos5_usbdrd_phy *phy_drd,
  1822. u16 addr, u16 data)
  1823. {
  1824. void __iomem *reg_phy = phy_drd->reg_phy;
  1825. u32 cnt = 0;
  1826. u32 reg;
  1827. /* Pre Clocking */
  1828. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1829. reg |= PHY_CR_PARA_CON0_PHY0_CR_PARA_SEL;
  1830. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1831. /*
  1832. * tx clks must be available prior to assertion of tx req.
  1833. * tx pstate p2 to p0 transition directly is not permitted.
  1834. * tx clk ready must be asserted synchronously on tx clk prior
  1835. * to internal transmit clk alignment sequence in the phy
  1836. * when entering from p2 to p1 to p0.
  1837. */
  1838. do {
  1839. exynosautov920_usb31drd_cr_clk(phy_drd, true);
  1840. exynosautov920_usb31drd_cr_clk(phy_drd, false);
  1841. cnt++;
  1842. } while (cnt < 15);
  1843. reg &= ~PHY_CR_PARA_CON0_PHY0_CR_PARA_SEL;
  1844. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1845. /*
  1846. * tx data path is active when tx lane is in p0 state
  1847. * and tx data en asserted. enable cr_para_wr_en.
  1848. */
  1849. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON2);
  1850. reg &= ~PHY_CR_PARA_CON2_PHY0_CR_PARA_WR_DATA;
  1851. reg |= FIELD_PREP(PHY_CR_PARA_CON2_PHY0_CR_PARA_WR_DATA, data) |
  1852. PHY_CR_PARA_CON2_PHY0_CR_PARA_WR_EN;
  1853. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON2);
  1854. /* write addr */
  1855. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1856. reg &= ~PHY_CR_PARA_CON0_PHY0_CR_PARA_ADDR;
  1857. reg |= FIELD_PREP(PHY_CR_PARA_CON0_PHY0_CR_PARA_ADDR, addr) |
  1858. PHY_CR_PARA_CON0_PHY0_CR_PARA_CLK |
  1859. PHY_CR_PARA_CON0_PHY0_CR_PARA_SEL;
  1860. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1861. /* check cr_para_ack*/
  1862. cnt = 0;
  1863. do {
  1864. /*
  1865. * data symbols are captured by phy on rising edge of the
  1866. * tx_clk when tx data enabled.
  1867. * completion of the write cycle is acknowledged by assertion
  1868. * of the cr_para_ack.
  1869. */
  1870. exynosautov920_usb31drd_cr_clk(phy_drd, true);
  1871. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CR_PARA_CON0);
  1872. if ((reg & PHY_CR_PARA_CON0_PHY0_CR_PARA_ACK))
  1873. break;
  1874. exynosautov920_usb31drd_cr_clk(phy_drd, false);
  1875. /*
  1876. * wait for minimum of 10 cr_para_clk cycles after phy reset
  1877. * is negated, before accessing control regs to allow for
  1878. * internal resets.
  1879. */
  1880. cnt++;
  1881. } while (cnt < 10);
  1882. if (cnt < 10)
  1883. exynosautov920_usb31drd_cr_clk(phy_drd, false);
  1884. }
  1885. static void
  1886. exynosautov920_usb31drd_phy_reset(struct exynos5_usbdrd_phy *phy_drd, int val)
  1887. {
  1888. void __iomem *reg_phy = phy_drd->reg_phy;
  1889. u32 reg;
  1890. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL);
  1891. reg &= ~PHY_RST_CTRL_PHY_RESET_OVRD_EN;
  1892. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL);
  1893. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL);
  1894. if (val)
  1895. reg |= PHY_RST_CTRL_PHY_RESET;
  1896. else
  1897. reg &= ~PHY_RST_CTRL_PHY_RESET;
  1898. reg |= PHY_RST_CTRL_PHY_RESET_OVRD_EN;
  1899. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL);
  1900. }
  1901. static void
  1902. exynosautov920_usb31drd_lane0_reset(struct exynos5_usbdrd_phy *phy_drd, int val)
  1903. {
  1904. void __iomem *reg_phy = phy_drd->reg_phy;
  1905. u32 reg;
  1906. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL);
  1907. reg |= PHY_RST_CTRL_PIPE_LANE0_RESET_N_OVRD_EN;
  1908. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL);
  1909. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL);
  1910. if (val)
  1911. reg &= ~PHY_RST_CTRL_PIPE_LANE0_RESET_N;
  1912. else
  1913. reg |= PHY_RST_CTRL_PIPE_LANE0_RESET_N;
  1914. reg &= ~PHY_RST_CTRL_PIPE_LANE0_RESET_N_OVRD_EN;
  1915. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_RST_CTRL);
  1916. }
  1917. static void
  1918. exynosautov920_usb31drd_pipe3_init(struct exynos5_usbdrd_phy *phy_drd)
  1919. {
  1920. void __iomem *reg_phy = phy_drd->reg_phy;
  1921. u32 reg;
  1922. /*
  1923. * Phy and Pipe Lane reset assert.
  1924. * assert reset (phy_reset = 1).
  1925. * The lane-ack outputs are asserted during reset (tx_ack = rx_ack = 1)
  1926. */
  1927. exynosautov920_usb31drd_phy_reset(phy_drd, 1);
  1928. exynosautov920_usb31drd_lane0_reset(phy_drd, 1);
  1929. /*
  1930. * ANA Power En, PCS & PMA PWR Stable Set
  1931. * ramp-up power suppiles
  1932. */
  1933. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CONFIG0);
  1934. reg |= PHY_CONFIG0_PHY0_ANA_PWR_EN | PHY_CONFIG0_PHY0_PCS_PWR_STABLE |
  1935. PHY_CONFIG0_PHY0_PMA_PWR_STABLE;
  1936. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CONFIG0);
  1937. fsleep(10);
  1938. /*
  1939. * phy is not functional in test_powerdown mode, test_powerdown to be
  1940. * de-asserted for normal operation
  1941. */
  1942. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CONFIG7);
  1943. reg &= ~PHY_CONFIG7_PHY_TEST_POWERDOWN;
  1944. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CONFIG7);
  1945. /*
  1946. * phy reset signal be asserted for minimum 10us after power
  1947. * supplies are ramped-up
  1948. */
  1949. fsleep(10);
  1950. /*
  1951. * Phy and Pipe Lane reset assert de-assert
  1952. */
  1953. exynosautov920_usb31drd_phy_reset(phy_drd, 0);
  1954. exynosautov920_usb31drd_lane0_reset(phy_drd, 0);
  1955. /* Pipe_rx0_sris_mode_en = 1 */
  1956. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CONFIG4);
  1957. reg |= PHY_CONFIG4_PIPE_RX0_SRIS_MODE_EN;
  1958. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CONFIG4);
  1959. /*
  1960. * wait for lane ack outputs to de-assert (tx_ack = rx_ack = 0)
  1961. * Exit from the reset state is indicated by de-assertion of *_ack
  1962. */
  1963. exynosautov920_usb31drd_port_phy_ready(phy_drd);
  1964. /* override values for level settings */
  1965. exynosautov920_usb31drd_cr_write(phy_drd, 0x22, 0x00F5);
  1966. }
  1967. static void
  1968. exynosautov920_usb31drd_ssphy_disable(struct exynos5_usbdrd_phy *phy_drd)
  1969. {
  1970. void __iomem *reg_phy = phy_drd->reg_phy;
  1971. u32 reg;
  1972. /* 1. Assert reset (phy_reset = 1) */
  1973. exynosautov920_usb31drd_lane0_reset(phy_drd, 1);
  1974. exynosautov920_usb31drd_phy_reset(phy_drd, 1);
  1975. /* phy test power down */
  1976. reg = readl(reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CONFIG7);
  1977. reg |= PHY_CONFIG7_PHY_TEST_POWERDOWN;
  1978. writel(reg, reg_phy + EXYNOSAUTOV920_USB31DRD_PHY_CONFIG7);
  1979. }
  1980. static void
  1981. exynosautov920_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)
  1982. {
  1983. void __iomem *reg_phy = phy_drd->reg_phy;
  1984. u32 reg;
  1985. /*
  1986. * Disable HWACG (hardware auto clock gating control). This
  1987. * forces QACTIVE signal in Q-Channel interface to HIGH level,
  1988. * to make sure the PHY clock is not gated by the hardware.
  1989. */
  1990. reg = readl(reg_phy + EXYNOS850_DRD_LINKCTRL);
  1991. reg |= LINKCTRL_FORCE_QACT;
  1992. writel(reg, reg_phy + EXYNOS850_DRD_LINKCTRL);
  1993. /* De-assert link reset */
  1994. reg = readl(reg_phy + EXYNOS2200_DRD_CLKRST);
  1995. reg &= ~CLKRST_LINK_SW_RST;
  1996. writel(reg, reg_phy + EXYNOS2200_DRD_CLKRST);
  1997. /* Set PHY POR High */
  1998. reg = readl(reg_phy + EXYNOSAUTOV920_DRD_HSP_CLKRST);
  1999. reg |= HSPCLKRST_PHY20_SW_POR | HSPCLKRST_PHY20_SW_POR_SEL;
  2000. writel(reg, reg_phy + EXYNOSAUTOV920_DRD_HSP_CLKRST);
  2001. /* Enable UTMI+ */
  2002. reg = readl(reg_phy + EXYNOS2200_DRD_UTMI);
  2003. reg &= ~(UTMICTL_FORCE_UTMI_SUSPEND | UTMICTL_FORCE_UTMI_SLEEP |
  2004. UTMICTL_FORCE_DPPULLDOWN | UTMICTL_FORCE_DMPULLDOWN);
  2005. writel(reg, reg_phy + EXYNOS2200_DRD_UTMI);
  2006. /* set phy clock & control HS phy */
  2007. reg = readl(reg_phy + EXYNOSAUTOV920_DRD_HSPCTL);
  2008. reg |= HSPCTRL_EN_UTMISUSPEND | HSPCTRL_COMMONONN;
  2009. writel(reg, reg_phy + EXYNOSAUTOV920_DRD_HSPCTL);
  2010. fsleep(100);
  2011. /* Set VBUS Valid and DP-Pull up control by VBUS pad usage */
  2012. reg = readl(reg_phy + EXYNOS850_DRD_LINKCTRL);
  2013. reg |= FIELD_PREP_CONST(LINKCTRL_BUS_FILTER_BYPASS, 0xf);
  2014. writel(reg, reg_phy + EXYNOS850_DRD_LINKCTRL);
  2015. reg = readl(reg_phy + EXYNOS2200_DRD_UTMI);
  2016. reg |= EXYNOS2200_UTMI_FORCE_VBUSVALID | EXYNOS2200_UTMI_FORCE_BVALID;
  2017. writel(reg, reg_phy + EXYNOS2200_DRD_UTMI);
  2018. reg = readl(reg_phy + EXYNOSAUTOV920_DRD_HSPCTL);
  2019. reg |= HSPCTRL_VBUSVLDEXTSEL | HSPCTRL_VBUSVLDEXT;
  2020. writel(reg, reg_phy + EXYNOSAUTOV920_DRD_HSPCTL);
  2021. /* Setting FSEL for refference clock */
  2022. reg = readl(reg_phy + EXYNOSAUTOV920_DRD_HSPPLLTUNE);
  2023. reg &= ~HSPPLLTUNE_FSEL;
  2024. switch (phy_drd->extrefclk) {
  2025. case EXYNOS5_FSEL_50MHZ:
  2026. reg |= FIELD_PREP(HSPPLLTUNE_FSEL, 7);
  2027. break;
  2028. case EXYNOS5_FSEL_26MHZ:
  2029. reg |= FIELD_PREP(HSPPLLTUNE_FSEL, 6);
  2030. break;
  2031. case EXYNOS5_FSEL_24MHZ:
  2032. reg |= FIELD_PREP(HSPPLLTUNE_FSEL, 2);
  2033. break;
  2034. case EXYNOS5_FSEL_20MHZ:
  2035. reg |= FIELD_PREP(HSPPLLTUNE_FSEL, 1);
  2036. break;
  2037. case EXYNOS5_FSEL_19MHZ2:
  2038. reg |= FIELD_PREP(HSPPLLTUNE_FSEL, 0);
  2039. break;
  2040. default:
  2041. dev_warn(phy_drd->dev, "unsupported ref clk: %#.2x\n",
  2042. phy_drd->extrefclk);
  2043. break;
  2044. }
  2045. writel(reg, reg_phy + EXYNOSAUTOV920_DRD_HSPPLLTUNE);
  2046. /* Enable PHY Power Mode */
  2047. reg = readl(reg_phy + EXYNOSAUTOV920_DRD_HSP_TEST);
  2048. reg &= ~HSP_TEST_SIDDQ;
  2049. writel(reg, reg_phy + EXYNOSAUTOV920_DRD_HSP_TEST);
  2050. /* before POR low, 10us delay is needed to Finish PHY reset */
  2051. fsleep(10);
  2052. /* Set PHY POR Low */
  2053. reg = readl(reg_phy + EXYNOSAUTOV920_DRD_HSP_CLKRST);
  2054. reg |= HSPCLKRST_PHY20_SW_POR_SEL;
  2055. reg &= ~(HSPCLKRST_PHY20_SW_POR | HSPCLKRST_PHY20_SW_PORTRESET);
  2056. writel(reg, reg_phy + EXYNOSAUTOV920_DRD_HSP_CLKRST);
  2057. /* after POR low and delay 75us, PHYCLOCK is guaranteed. */
  2058. fsleep(75);
  2059. /* Disable forcing pipe interface */
  2060. reg = readl(reg_phy + EXYNOS850_DRD_LINKCTRL);
  2061. reg &= ~LINKCTRL_FORCE_PIPE_EN;
  2062. writel(reg, reg_phy + EXYNOS850_DRD_LINKCTRL);
  2063. /* Pclk to pipe_clk */
  2064. reg = readl(reg_phy + EXYNOS2200_DRD_CLKRST);
  2065. reg |= EXYNOS2200_CLKRST_LINK_PCLK_SEL;
  2066. writel(reg, reg_phy + EXYNOS2200_DRD_CLKRST);
  2067. }
  2068. static void
  2069. exynosautov920_usbdrd_hsphy_disable(struct exynos5_usbdrd_phy *phy_drd)
  2070. {
  2071. u32 reg;
  2072. void __iomem *reg_phy = phy_drd->reg_phy;
  2073. /* set phy clock & control HS phy */
  2074. reg = readl(reg_phy + EXYNOS2200_DRD_UTMI);
  2075. reg |= UTMICTL_FORCE_UTMI_SUSPEND | UTMICTL_FORCE_UTMI_SLEEP;
  2076. reg &= ~(UTMICTL_FORCE_DPPULLDOWN | UTMICTL_FORCE_DMPULLDOWN);
  2077. writel(reg, reg_phy + EXYNOS2200_DRD_UTMI);
  2078. /* Disable PHY Power Mode */
  2079. reg = readl(reg_phy + EXYNOSAUTOV920_DRD_HSP_TEST);
  2080. reg |= HSP_TEST_SIDDQ;
  2081. writel(reg, reg_phy + EXYNOSAUTOV920_DRD_HSP_TEST);
  2082. /* clear force q-channel */
  2083. reg = readl(reg_phy + EXYNOS850_DRD_LINKCTRL);
  2084. reg &= ~LINKCTRL_FORCE_QACT;
  2085. writel(reg, reg_phy + EXYNOS850_DRD_LINKCTRL);
  2086. /* link sw reset is need for USB_DP/DM high-z in host mode */
  2087. reg = readl(reg_phy + EXYNOS2200_DRD_CLKRST);
  2088. reg |= CLKRST_LINK_SW_RST;
  2089. writel(reg, reg_phy + EXYNOS2200_DRD_CLKRST);
  2090. fsleep(10);
  2091. reg &= ~CLKRST_LINK_SW_RST;
  2092. writel(reg, reg_phy + EXYNOS2200_DRD_CLKRST);
  2093. }
  2094. static int exynosautov920_usbdrd_phy_init(struct phy *phy)
  2095. {
  2096. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  2097. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  2098. int ret;
  2099. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  2100. if (ret)
  2101. return ret;
  2102. /* Bypass PHY isol */
  2103. inst->phy_cfg->phy_isol(inst, false);
  2104. /* UTMI or PIPE3 specific init */
  2105. inst->phy_cfg->phy_init(phy_drd);
  2106. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  2107. return 0;
  2108. }
  2109. static int exynosautov920_usbdrd_phy_exit(struct phy *phy)
  2110. {
  2111. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  2112. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  2113. int ret;
  2114. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  2115. if (ret)
  2116. return ret;
  2117. exynos850_usbdrd_phy_exit(phy);
  2118. /* enable PHY isol */
  2119. inst->phy_cfg->phy_isol(inst, true);
  2120. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  2121. return 0;
  2122. }
  2123. static int exynosautov920_usbdrd_combo_phy_exit(struct phy *phy)
  2124. {
  2125. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  2126. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  2127. int ret = 0;
  2128. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_clks, phy_drd->clks);
  2129. if (ret)
  2130. return ret;
  2131. if (inst->phy_cfg->id == EXYNOS5_DRDPHY_UTMI)
  2132. exynosautov920_usbdrd_hsphy_disable(phy_drd);
  2133. else if (inst->phy_cfg->id == EXYNOS5_DRDPHY_PIPE3)
  2134. exynosautov920_usb31drd_ssphy_disable(phy_drd);
  2135. /* enable PHY isol */
  2136. inst->phy_cfg->phy_isol(inst, true);
  2137. clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
  2138. return 0;
  2139. }
  2140. static int exynosautov920_usbdrd_phy_power_on(struct phy *phy)
  2141. {
  2142. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  2143. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  2144. int ret;
  2145. dev_dbg(phy_drd->dev, "Request to power_on usbdrd_phy phy\n");
  2146. ret = clk_bulk_prepare_enable(phy_drd->drv_data->n_core_clks,
  2147. phy_drd->core_clks);
  2148. if (ret)
  2149. return ret;
  2150. /* Enable supply */
  2151. ret = regulator_bulk_enable(phy_drd->drv_data->n_regulators,
  2152. phy_drd->regulators);
  2153. if (ret) {
  2154. dev_err(phy_drd->dev, "Failed to enable PHY regulator(s)\n");
  2155. goto fail_supply;
  2156. }
  2157. return 0;
  2158. fail_supply:
  2159. clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks,
  2160. phy_drd->core_clks);
  2161. return ret;
  2162. }
  2163. static int exynosautov920_usbdrd_phy_power_off(struct phy *phy)
  2164. {
  2165. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  2166. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  2167. dev_dbg(phy_drd->dev, "Request to power_off usbdrd_phy phy\n");
  2168. /* Disable supply */
  2169. regulator_bulk_disable(phy_drd->drv_data->n_regulators,
  2170. phy_drd->regulators);
  2171. clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks,
  2172. phy_drd->core_clks);
  2173. return 0;
  2174. }
  2175. static const char * const exynosautov920_usb30_regulators[] = {
  2176. "dvdd", "vdd18",
  2177. };
  2178. static const char * const exynosautov920_usb20_regulators[] = {
  2179. "dvdd", "vdd18", "vdd33",
  2180. };
  2181. static const struct
  2182. exynos5_usbdrd_phy_config usb31drd_phy_cfg_exynosautov920[] = {
  2183. {
  2184. .id = EXYNOS5_DRDPHY_PIPE3,
  2185. .phy_isol = exynos5_usbdrd_phy_isol,
  2186. .phy_init = exynosautov920_usb31drd_pipe3_init,
  2187. },
  2188. };
  2189. static const struct phy_ops exynosautov920_usb31drd_combo_ssphy_ops = {
  2190. .init = exynosautov920_usbdrd_phy_init,
  2191. .exit = exynosautov920_usbdrd_combo_phy_exit,
  2192. .power_on = exynosautov920_usbdrd_phy_power_on,
  2193. .power_off = exynosautov920_usbdrd_phy_power_off,
  2194. .owner = THIS_MODULE,
  2195. };
  2196. static const
  2197. struct exynos5_usbdrd_phy_drvdata exynosautov920_usb31drd_combo_ssphy = {
  2198. .phy_cfg = usb31drd_phy_cfg_exynosautov920,
  2199. .phy_ops = &exynosautov920_usb31drd_combo_ssphy_ops,
  2200. .pmu_offset_usbdrd0_phy = EXYNOSAUTOV920_PHY_CTRL_USB31,
  2201. .clk_names = exynos5_clk_names,
  2202. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  2203. .core_clk_names = exynos5_core_clk_names,
  2204. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  2205. .regulator_names = exynosautov920_usb30_regulators,
  2206. .n_regulators = ARRAY_SIZE(exynosautov920_usb30_regulators),
  2207. };
  2208. static const struct phy_ops exynosautov920_usbdrd_combo_hsphy_ops = {
  2209. .init = exynosautov920_usbdrd_phy_init,
  2210. .exit = exynosautov920_usbdrd_combo_phy_exit,
  2211. .power_on = exynosautov920_usbdrd_phy_power_on,
  2212. .power_off = exynosautov920_usbdrd_phy_power_off,
  2213. .owner = THIS_MODULE,
  2214. };
  2215. static const struct
  2216. exynos5_usbdrd_phy_config usbdrd_hsphy_cfg_exynosautov920[] = {
  2217. {
  2218. .id = EXYNOS5_DRDPHY_UTMI,
  2219. .phy_isol = exynos5_usbdrd_phy_isol,
  2220. .phy_init = exynosautov920_usbdrd_utmi_init,
  2221. },
  2222. };
  2223. static const
  2224. struct exynos5_usbdrd_phy_drvdata exynosautov920_usbdrd_combo_hsphy = {
  2225. .phy_cfg = usbdrd_hsphy_cfg_exynosautov920,
  2226. .phy_ops = &exynosautov920_usbdrd_combo_hsphy_ops,
  2227. .pmu_offset_usbdrd0_phy = EXYNOSAUTOV920_PHY_CTRL_USB20,
  2228. .clk_names = exynos5_clk_names,
  2229. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  2230. .core_clk_names = exynos5_core_clk_names,
  2231. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  2232. .regulator_names = exynosautov920_usb20_regulators,
  2233. .n_regulators = ARRAY_SIZE(exynosautov920_usb20_regulators),
  2234. };
  2235. static const struct phy_ops exynosautov920_usbdrd_phy_ops = {
  2236. .init = exynosautov920_usbdrd_phy_init,
  2237. .exit = exynosautov920_usbdrd_phy_exit,
  2238. .power_on = exynosautov920_usbdrd_phy_power_on,
  2239. .power_off = exynosautov920_usbdrd_phy_power_off,
  2240. .owner = THIS_MODULE,
  2241. };
  2242. static const struct exynos5_usbdrd_phy_config phy_cfg_exynosautov920[] = {
  2243. {
  2244. .id = EXYNOS5_DRDPHY_UTMI,
  2245. .phy_isol = exynos5_usbdrd_phy_isol,
  2246. .phy_init = exynos850_usbdrd_utmi_init,
  2247. },
  2248. };
  2249. static const struct exynos5_usbdrd_phy_drvdata exynosautov920_usbdrd_phy = {
  2250. .phy_cfg = phy_cfg_exynosautov920,
  2251. .phy_ops = &exynosautov920_usbdrd_phy_ops,
  2252. .pmu_offset_usbdrd0_phy = EXYNOSAUTOV920_PHY_CTRL_USB20,
  2253. .clk_names = exynos5_clk_names,
  2254. .n_clks = ARRAY_SIZE(exynos5_clk_names),
  2255. .core_clk_names = exynos5_core_clk_names,
  2256. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  2257. .regulator_names = exynosautov920_usb20_regulators,
  2258. .n_regulators = ARRAY_SIZE(exynosautov920_usb20_regulators),
  2259. };
  2260. static const struct exynos5_usbdrd_phy_config phy_cfg_gs101[] = {
  2261. {
  2262. .id = EXYNOS5_DRDPHY_UTMI,
  2263. .phy_isol = exynos5_usbdrd_phy_isol,
  2264. .phy_init = exynos850_usbdrd_utmi_init,
  2265. },
  2266. {
  2267. .id = EXYNOS5_DRDPHY_PIPE3,
  2268. .phy_isol = exynos5_usbdrd_phy_isol,
  2269. .phy_init = exynos5_usbdrd_gs101_pipe3_init,
  2270. },
  2271. };
  2272. static const struct exynos5_usbdrd_phy_tuning gs101_tunes_utmi_postinit[] = {
  2273. PHY_TUNING_ENTRY_PHY(EXYNOS850_DRD_HSPPARACON,
  2274. (HSPPARACON_TXVREF | HSPPARACON_TXRES |
  2275. HSPPARACON_TXPREEMPAMP | HSPPARACON_SQRX |
  2276. HSPPARACON_COMPDIS),
  2277. (FIELD_PREP_CONST(HSPPARACON_TXVREF, 6) |
  2278. FIELD_PREP_CONST(HSPPARACON_TXRES, 1) |
  2279. FIELD_PREP_CONST(HSPPARACON_TXPREEMPAMP, 3) |
  2280. FIELD_PREP_CONST(HSPPARACON_SQRX, 5) |
  2281. FIELD_PREP_CONST(HSPPARACON_COMPDIS, 7))),
  2282. PHY_TUNING_ENTRY_LAST
  2283. };
  2284. static const struct exynos5_usbdrd_phy_tuning gs101_tunes_pipe3_preinit[] = {
  2285. /* preinit */
  2286. /* CDR data mode exit GEN1 ON / GEN2 OFF */
  2287. PHY_TUNING_ENTRY_PMA(0x0c8c, -1, 0xff),
  2288. PHY_TUNING_ENTRY_PMA(0x1c8c, -1, 0xff),
  2289. PHY_TUNING_ENTRY_PMA(0x0c9c, -1, 0x7d),
  2290. PHY_TUNING_ENTRY_PMA(0x1c9c, -1, 0x7d),
  2291. /* improve EDS distribution */
  2292. PHY_TUNING_ENTRY_PMA(0x0e7c, -1, 0x06),
  2293. PHY_TUNING_ENTRY_PMA(0x09e0, -1, 0x00),
  2294. PHY_TUNING_ENTRY_PMA(0x09e4, -1, 0x36),
  2295. PHY_TUNING_ENTRY_PMA(0x1e7c, -1, 0x06),
  2296. PHY_TUNING_ENTRY_PMA(0x19e0, -1, 0x00),
  2297. PHY_TUNING_ENTRY_PMA(0x19e4, -1, 0x36),
  2298. /* fix bootloader bug */
  2299. PHY_TUNING_ENTRY_PMA(0x1e90, -1, 0x02),
  2300. PHY_TUNING_ENTRY_PMA(0x1e94, -1, 0x0b),
  2301. /* improve LVCC */
  2302. PHY_TUNING_ENTRY_PMA(0x08f0, -1, 0x30),
  2303. PHY_TUNING_ENTRY_PMA(0x18f0, -1, 0x30),
  2304. /* LFPS RX VIH shmoo hole */
  2305. PHY_TUNING_ENTRY_PMA(0x0a08, -1, 0x0c),
  2306. PHY_TUNING_ENTRY_PMA(0x1a08, -1, 0x0c),
  2307. /* remove unrelated option for v4 phy */
  2308. PHY_TUNING_ENTRY_PMA(0x0a0c, -1, 0x05),
  2309. PHY_TUNING_ENTRY_PMA(0x1a0c, -1, 0x05),
  2310. /* improve Gen2 LVCC */
  2311. PHY_TUNING_ENTRY_PMA(0x00f8, -1, 0x1c),
  2312. PHY_TUNING_ENTRY_PMA(0x00fc, -1, 0x54),
  2313. /* Change Vth of RCV_DET because of TD 7.40 Polling Retry Test */
  2314. PHY_TUNING_ENTRY_PMA(0x104c, -1, 0x07),
  2315. PHY_TUNING_ENTRY_PMA(0x204c, -1, 0x07),
  2316. /* reduce Ux Exit time, assuming 26MHz clock */
  2317. /* Gen1 */
  2318. PHY_TUNING_ENTRY_PMA(0x0ca8, -1, 0x00),
  2319. PHY_TUNING_ENTRY_PMA(0x0cac, -1, 0x04),
  2320. PHY_TUNING_ENTRY_PMA(0x1ca8, -1, 0x00),
  2321. PHY_TUNING_ENTRY_PMA(0x1cac, -1, 0x04),
  2322. /* Gen2 */
  2323. PHY_TUNING_ENTRY_PMA(0x0cb8, -1, 0x00),
  2324. PHY_TUNING_ENTRY_PMA(0x0cbc, -1, 0x04),
  2325. PHY_TUNING_ENTRY_PMA(0x1cb8, -1, 0x00),
  2326. PHY_TUNING_ENTRY_PMA(0x1cbc, -1, 0x04),
  2327. /* RX impedance setting */
  2328. PHY_TUNING_ENTRY_PMA(0x0bb0, 0x03, 0x01),
  2329. PHY_TUNING_ENTRY_PMA(0x0bb4, 0xf0, 0xa0),
  2330. PHY_TUNING_ENTRY_PMA(0x1bb0, 0x03, 0x01),
  2331. PHY_TUNING_ENTRY_PMA(0x1bb4, 0xf0, 0xa0),
  2332. PHY_TUNING_ENTRY_LAST
  2333. };
  2334. static const struct exynos5_usbdrd_phy_tuning gs101_tunes_pipe3_init[] = {
  2335. /* init */
  2336. /* abnormal common pattern mask */
  2337. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_BACK_END_MODE_VEC,
  2338. BACK_END_MODE_VEC_DISABLE_DATA_MASK, 0),
  2339. /* de-serializer enabled when U2 */
  2340. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_OUT_VEC_2, PCS_OUT_VEC_B4_DYNAMIC,
  2341. PCS_OUT_VEC_B4_SEL_OUT),
  2342. /* TX Keeper Disable, Squelch on when U3 */
  2343. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_OUT_VEC_3, PCS_OUT_VEC_B7_DYNAMIC,
  2344. PCS_OUT_VEC_B7_SEL_OUT | PCS_OUT_VEC_B2_SEL_OUT),
  2345. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_NS_VEC_PS1_N1, -1,
  2346. (FIELD_PREP_CONST(NS_VEC_NS_REQ, 5) |
  2347. NS_VEC_ENABLE_TIMER |
  2348. FIELD_PREP_CONST(NS_VEC_SEL_TIMEOUT, 3))),
  2349. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_NS_VEC_PS2_N0, -1,
  2350. (FIELD_PREP_CONST(NS_VEC_NS_REQ, 1) |
  2351. NS_VEC_ENABLE_TIMER |
  2352. FIELD_PREP_CONST(NS_VEC_SEL_TIMEOUT, 3) |
  2353. FIELD_PREP_CONST(NS_VEC_COND_MASK, 2) |
  2354. FIELD_PREP_CONST(NS_VEC_EXP_COND, 2))),
  2355. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_NS_VEC_PS3_N0, -1,
  2356. (FIELD_PREP_CONST(NS_VEC_NS_REQ, 1) |
  2357. NS_VEC_ENABLE_TIMER |
  2358. FIELD_PREP_CONST(NS_VEC_SEL_TIMEOUT, 3) |
  2359. FIELD_PREP_CONST(NS_VEC_COND_MASK, 7) |
  2360. FIELD_PREP_CONST(NS_VEC_EXP_COND, 7))),
  2361. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_TIMEOUT_0, -1, 112),
  2362. /* Block Aligner Type B */
  2363. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_RX_CONTROL, 0,
  2364. RX_CONTROL_EN_BLOCK_ALIGNER_TYPE_B),
  2365. /* Block align at TS1/TS2 for Gen2 stability (Gen2 only) */
  2366. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_RX_CONTROL_DEBUG,
  2367. RX_CONTROL_DEBUG_NUM_COM_FOUND,
  2368. (RX_CONTROL_DEBUG_EN_TS_CHECK |
  2369. /*
  2370. * increase pcs ts1 adding packet-cnt 1 --> 4
  2371. * lnx_rx_valid_rstn_delay_rise_sp/ssp :
  2372. * 19.6us(0x200) -> 15.3us(0x4)
  2373. */
  2374. FIELD_PREP_CONST(RX_CONTROL_DEBUG_NUM_COM_FOUND, 4))),
  2375. /* Gen1 Tx DRIVER pre-shoot, de-emphasis, level ctrl */
  2376. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_HS_TX_COEF_MAP_0,
  2377. (HS_TX_COEF_MAP_0_SSTX_DEEMP | HS_TX_COEF_MAP_0_SSTX_LEVEL |
  2378. HS_TX_COEF_MAP_0_SSTX_PRE_SHOOT),
  2379. (FIELD_PREP_CONST(HS_TX_COEF_MAP_0_SSTX_DEEMP, 8) |
  2380. FIELD_PREP_CONST(HS_TX_COEF_MAP_0_SSTX_LEVEL, 0xb) |
  2381. FIELD_PREP_CONST(HS_TX_COEF_MAP_0_SSTX_PRE_SHOOT, 0))),
  2382. /* Gen2 Tx DRIVER level ctrl */
  2383. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_LOCAL_COEF,
  2384. LOCAL_COEF_PMA_CENTER_COEF,
  2385. FIELD_PREP_CONST(LOCAL_COEF_PMA_CENTER_COEF, 0xb)),
  2386. /* Gen2 U1 exit LFPS duration : 900ns ~ 1.2us */
  2387. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_TIMEOUT_3, -1, 4096),
  2388. /* set skp_remove_th 0x2 -> 0x7 for avoiding retry problem. */
  2389. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_EBUF_PARAM,
  2390. EBUF_PARAM_SKP_REMOVE_TH_EMPTY_MODE,
  2391. FIELD_PREP_CONST(EBUF_PARAM_SKP_REMOVE_TH_EMPTY_MODE, 0x7)),
  2392. PHY_TUNING_ENTRY_LAST
  2393. };
  2394. static const struct exynos5_usbdrd_phy_tuning gs101_tunes_pipe3_postlock[] = {
  2395. /* Squelch off when U3 */
  2396. PHY_TUNING_ENTRY_PCS(EXYNOS9_PCS_OUT_VEC_3, PCS_OUT_VEC_B2_SEL_OUT, 0),
  2397. PHY_TUNING_ENTRY_LAST
  2398. };
  2399. static const struct exynos5_usbdrd_phy_tuning *gs101_tunes[PTS_MAX] = {
  2400. [PTS_UTMI_POSTINIT] = gs101_tunes_utmi_postinit,
  2401. [PTS_PIPE3_PREINIT] = gs101_tunes_pipe3_preinit,
  2402. [PTS_PIPE3_INIT] = gs101_tunes_pipe3_init,
  2403. [PTS_PIPE3_POSTLOCK] = gs101_tunes_pipe3_postlock,
  2404. };
  2405. static const char * const gs101_clk_names[] = {
  2406. "phy", "ctrl_aclk", "ctrl_pclk", "scl_pclk",
  2407. };
  2408. static const char * const gs101_regulator_names[] = {
  2409. "pll",
  2410. "dvdd-usb20", "vddh-usb20", "vdd33-usb20",
  2411. "vdda-usbdp", "vddh-usbdp",
  2412. };
  2413. static const struct exynos5_usbdrd_phy_drvdata gs101_usbd31rd_phy = {
  2414. .phy_cfg = phy_cfg_gs101,
  2415. .phy_tunes = gs101_tunes,
  2416. .phy_ops = &gs101_usbdrd_phy_ops,
  2417. .pmu_offset_usbdrd0_phy = GS101_PHY_CTRL_USB20,
  2418. .pmu_offset_usbdrd0_phy_ss = GS101_PHY_CTRL_USBDP,
  2419. .clk_names = gs101_clk_names,
  2420. .n_clks = ARRAY_SIZE(gs101_clk_names),
  2421. .core_clk_names = exynos5_core_clk_names,
  2422. .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
  2423. .regulator_names = gs101_regulator_names,
  2424. .n_regulators = ARRAY_SIZE(gs101_regulator_names),
  2425. };
  2426. static const struct of_device_id exynos5_usbdrd_phy_of_match[] = {
  2427. {
  2428. .compatible = "google,gs101-usb31drd-phy",
  2429. .data = &gs101_usbd31rd_phy
  2430. }, {
  2431. .compatible = "samsung,exynos2200-usb32drd-phy",
  2432. .data = &exynos2200_usb32drd_phy,
  2433. }, {
  2434. .compatible = "samsung,exynos5250-usbdrd-phy",
  2435. .data = &exynos5250_usbdrd_phy
  2436. }, {
  2437. .compatible = "samsung,exynos5420-usbdrd-phy",
  2438. .data = &exynos5420_usbdrd_phy
  2439. }, {
  2440. .compatible = "samsung,exynos5433-usbdrd-phy",
  2441. .data = &exynos5433_usbdrd_phy
  2442. }, {
  2443. .compatible = "samsung,exynos7-usbdrd-phy",
  2444. .data = &exynos7_usbdrd_phy
  2445. }, {
  2446. .compatible = "samsung,exynos7870-usbdrd-phy",
  2447. .data = &exynos7870_usbdrd_phy
  2448. }, {
  2449. .compatible = "samsung,exynos850-usbdrd-phy",
  2450. .data = &exynos850_usbdrd_phy
  2451. }, {
  2452. .compatible = "samsung,exynos990-usbdrd-phy",
  2453. .data = &exynos990_usbdrd_phy
  2454. }, {
  2455. .compatible = "samsung,exynosautov920-usb31drd-combo-ssphy",
  2456. .data = &exynosautov920_usb31drd_combo_ssphy
  2457. }, {
  2458. .compatible = "samsung,exynosautov920-usbdrd-combo-hsphy",
  2459. .data = &exynosautov920_usbdrd_combo_hsphy
  2460. }, {
  2461. .compatible = "samsung,exynosautov920-usbdrd-phy",
  2462. .data = &exynosautov920_usbdrd_phy
  2463. },
  2464. { },
  2465. };
  2466. MODULE_DEVICE_TABLE(of, exynos5_usbdrd_phy_of_match);
  2467. static int exynos5_usbdrd_phy_probe(struct platform_device *pdev)
  2468. {
  2469. struct device *dev = &pdev->dev;
  2470. struct device_node *node = dev->of_node;
  2471. struct exynos5_usbdrd_phy *phy_drd;
  2472. struct phy_provider *phy_provider;
  2473. const struct exynos5_usbdrd_phy_drvdata *drv_data;
  2474. struct regmap *reg_pmu;
  2475. u32 pmu_offset;
  2476. int i, ret;
  2477. int channel;
  2478. phy_drd = devm_kzalloc(dev, sizeof(*phy_drd), GFP_KERNEL);
  2479. if (!phy_drd)
  2480. return -ENOMEM;
  2481. dev_set_drvdata(dev, phy_drd);
  2482. phy_drd->dev = dev;
  2483. drv_data = of_device_get_match_data(dev);
  2484. if (!drv_data)
  2485. return -EINVAL;
  2486. phy_drd->drv_data = drv_data;
  2487. ret = devm_mutex_init(dev, &phy_drd->phy_mutex);
  2488. if (ret)
  2489. return ret;
  2490. if (of_property_present(dev->of_node, "reg-names")) {
  2491. void __iomem *reg;
  2492. reg = devm_platform_ioremap_resource_byname(pdev, "phy");
  2493. if (IS_ERR(reg))
  2494. return PTR_ERR(reg);
  2495. phy_drd->reg_phy = reg;
  2496. reg = devm_platform_ioremap_resource_byname(pdev, "pcs");
  2497. if (IS_ERR(reg))
  2498. return PTR_ERR(reg);
  2499. phy_drd->reg_pcs = reg;
  2500. reg = devm_platform_ioremap_resource_byname(pdev, "pma");
  2501. if (IS_ERR(reg))
  2502. return PTR_ERR(reg);
  2503. phy_drd->reg_pma = reg;
  2504. } else {
  2505. /* DTB with just a single region */
  2506. phy_drd->reg_phy = devm_platform_ioremap_resource(pdev, 0);
  2507. if (IS_ERR(phy_drd->reg_phy))
  2508. return PTR_ERR(phy_drd->reg_phy);
  2509. }
  2510. /*
  2511. * USB32DRD 4nm controller implements Synopsys eUSB2.0 PHY
  2512. * and Synopsys SS/USBDP COMBOPHY, managed by external code.
  2513. */
  2514. if (of_property_present(dev->of_node, "phy-names")) {
  2515. phy_drd->hs_phy = devm_of_phy_get(dev, dev->of_node, "hs");
  2516. if (IS_ERR(phy_drd->hs_phy))
  2517. return dev_err_probe(dev, PTR_ERR(phy_drd->hs_phy),
  2518. "failed to get hs_phy\n");
  2519. }
  2520. ret = exynos5_usbdrd_phy_clk_handle(phy_drd);
  2521. if (ret)
  2522. return ret;
  2523. reg_pmu = syscon_regmap_lookup_by_phandle(dev->of_node,
  2524. "samsung,pmu-syscon");
  2525. if (IS_ERR(reg_pmu))
  2526. return dev_err_probe(dev, PTR_ERR(reg_pmu),
  2527. "Failed to lookup PMU regmap\n");
  2528. /*
  2529. * Exynos5420 SoC has multiple channels for USB 3.0 PHY, with
  2530. * each having separate power control registers.
  2531. * 'channel' facilitates to set such registers.
  2532. */
  2533. channel = of_alias_get_id(node, "usbdrdphy");
  2534. if (channel < 0)
  2535. dev_dbg(dev, "Not a multi-controller usbdrd phy\n");
  2536. /* Get regulators */
  2537. phy_drd->regulators = devm_kcalloc(dev,
  2538. drv_data->n_regulators,
  2539. sizeof(*phy_drd->regulators),
  2540. GFP_KERNEL);
  2541. if (!phy_drd->regulators)
  2542. return -ENOMEM;
  2543. regulator_bulk_set_supply_names(phy_drd->regulators,
  2544. drv_data->regulator_names,
  2545. drv_data->n_regulators);
  2546. ret = devm_regulator_bulk_get(dev, drv_data->n_regulators,
  2547. phy_drd->regulators);
  2548. if (ret)
  2549. return dev_err_probe(dev, ret, "failed to get regulators\n");
  2550. ret = exynos5_usbdrd_setup_notifiers(phy_drd);
  2551. if (ret)
  2552. return ret;
  2553. dev_vdbg(dev, "Creating usbdrd_phy phy\n");
  2554. for (i = 0; i < EXYNOS5_DRDPHYS_NUM; i++) {
  2555. struct phy *phy = devm_phy_create(dev, NULL, drv_data->phy_ops);
  2556. if (IS_ERR(phy))
  2557. return dev_err_probe(dev, PTR_ERR(phy),
  2558. "Failed to create usbdrd_phy phy\n");
  2559. phy_drd->phys[i].phy = phy;
  2560. phy_drd->phys[i].index = i;
  2561. phy_drd->phys[i].reg_pmu = reg_pmu;
  2562. switch (channel) {
  2563. case 1:
  2564. pmu_offset = drv_data->pmu_offset_usbdrd1_phy;
  2565. break;
  2566. case 0:
  2567. default:
  2568. pmu_offset = drv_data->pmu_offset_usbdrd0_phy;
  2569. if (i == EXYNOS5_DRDPHY_PIPE3 && drv_data
  2570. ->pmu_offset_usbdrd0_phy_ss)
  2571. pmu_offset = drv_data->pmu_offset_usbdrd0_phy_ss;
  2572. break;
  2573. }
  2574. phy_drd->phys[i].pmu_offset = pmu_offset;
  2575. phy_drd->phys[i].phy_cfg = &drv_data->phy_cfg[i];
  2576. phy_set_drvdata(phy, &phy_drd->phys[i]);
  2577. }
  2578. phy_provider = devm_of_phy_provider_register(dev,
  2579. exynos5_usbdrd_phy_xlate);
  2580. if (IS_ERR(phy_provider))
  2581. return dev_err_probe(phy_drd->dev, PTR_ERR(phy_provider),
  2582. "Failed to register phy provider\n");
  2583. return 0;
  2584. }
  2585. static struct platform_driver exynos5_usb3drd_phy = {
  2586. .probe = exynos5_usbdrd_phy_probe,
  2587. .driver = {
  2588. .of_match_table = exynos5_usbdrd_phy_of_match,
  2589. .name = "exynos5_usb3drd_phy",
  2590. .suppress_bind_attrs = true,
  2591. }
  2592. };
  2593. module_platform_driver(exynos5_usb3drd_phy);
  2594. MODULE_DESCRIPTION("Samsung Exynos5 SoCs USB 3.0 DRD controller PHY driver");
  2595. MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>");
  2596. MODULE_LICENSE("GPL v2");