xusb-tegra210.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046
  1. /*
  2. * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
  3. * Copyright (C) 2015 Google, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/clk/tegra.h>
  16. #include <linux/delay.h>
  17. #include <linux/io.h>
  18. #include <linux/mailbox_client.h>
  19. #include <linux/module.h>
  20. #include <linux/of.h>
  21. #include <linux/phy/phy.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/regulator/consumer.h>
  24. #include <linux/reset.h>
  25. #include <linux/slab.h>
  26. #include <soc/tegra/fuse.h>
  27. #include "xusb.h"
  28. #define FUSE_SKU_CALIB_HS_CURR_LEVEL_PADX_SHIFT(x) \
  29. ((x) ? (11 + ((x) - 1) * 6) : 0)
  30. #define FUSE_SKU_CALIB_HS_CURR_LEVEL_PAD_MASK 0x3f
  31. #define FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_SHIFT 7
  32. #define FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_MASK 0xf
  33. #define FUSE_USB_CALIB_EXT_RPD_CTRL_SHIFT 0
  34. #define FUSE_USB_CALIB_EXT_RPD_CTRL_MASK 0x1f
  35. #define XUSB_PADCTL_USB2_PAD_MUX 0x004
  36. #define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT 16
  37. #define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_MASK 0x3
  38. #define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_XUSB 0x1
  39. #define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT 18
  40. #define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_MASK 0x3
  41. #define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_XUSB 0x1
  42. #define XUSB_PADCTL_USB2_PORT_CAP 0x008
  43. #define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_HOST(x) (0x1 << ((x) * 4))
  44. #define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_MASK(x) (0x3 << ((x) * 4))
  45. #define XUSB_PADCTL_SS_PORT_MAP 0x014
  46. #define XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(x) (1 << (((x) * 5) + 4))
  47. #define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_SHIFT(x) ((x) * 5)
  48. #define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(x) (0x7 << ((x) * 5))
  49. #define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(x, v) (((v) & 0x7) << ((x) * 5))
  50. #define XUSB_PADCTL_ELPG_PROGRAM1 0x024
  51. #define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN (1 << 31)
  52. #define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY (1 << 30)
  53. #define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN (1 << 29)
  54. #define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(x) (1 << (2 + (x) * 3))
  55. #define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(x) \
  56. (1 << (1 + (x) * 3))
  57. #define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(x) (1 << ((x) * 3))
  58. #define XUSB_PADCTL_USB3_PAD_MUX 0x028
  59. #define XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(x) (1 << (1 + (x)))
  60. #define XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(x) (1 << (8 + (x)))
  61. #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(x) (0x084 + (x) * 0x40)
  62. #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_SHIFT 7
  63. #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_MASK 0x3
  64. #define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_FIX18 (1 << 6)
  65. #define XUSB_PADCTL_USB2_OTG_PADX_CTL0(x) (0x088 + (x) * 0x40)
  66. #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD_ZI (1 << 29)
  67. #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD2 (1 << 27)
  68. #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD (1 << 26)
  69. #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT 0
  70. #define XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_MASK 0x3f
  71. #define XUSB_PADCTL_USB2_OTG_PADX_CTL1(x) (0x08c + (x) * 0x40)
  72. #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT 26
  73. #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_MASK 0x1f
  74. #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT 3
  75. #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_MASK 0xf
  76. #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DR (1 << 2)
  77. #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DISC_OVRD (1 << 1)
  78. #define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_CHRP_OVRD (1 << 0)
  79. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0 0x284
  80. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD (1 << 11)
  81. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT 3
  82. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_MASK 0x7
  83. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_VAL 0x7
  84. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT 0
  85. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_MASK 0x7
  86. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_VAL 0x2
  87. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1 0x288
  88. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_PD_TRK (1 << 26)
  89. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT 19
  90. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_MASK 0x7f
  91. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_VAL 0x0a
  92. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT 12
  93. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_MASK 0x7f
  94. #define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_VAL 0x1e
  95. #define XUSB_PADCTL_HSIC_PADX_CTL0(x) (0x300 + (x) * 0x20)
  96. #define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE (1 << 18)
  97. #define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1 (1 << 17)
  98. #define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0 (1 << 16)
  99. #define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE (1 << 15)
  100. #define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 (1 << 14)
  101. #define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 (1 << 13)
  102. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE (1 << 9)
  103. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1 (1 << 8)
  104. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0 (1 << 7)
  105. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE (1 << 6)
  106. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1 (1 << 5)
  107. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0 (1 << 4)
  108. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE (1 << 3)
  109. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1 (1 << 2)
  110. #define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0 (1 << 1)
  111. #define XUSB_PADCTL_HSIC_PADX_CTL1(x) (0x304 + (x) * 0x20)
  112. #define XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT 0
  113. #define XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_MASK 0xf
  114. #define XUSB_PADCTL_HSIC_PADX_CTL2(x) (0x308 + (x) * 0x20)
  115. #define XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT 8
  116. #define XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_MASK 0xf
  117. #define XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT 0
  118. #define XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_MASK 0xff
  119. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL 0x340
  120. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_PD_TRK (1 << 19)
  121. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT 12
  122. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_MASK 0x7f
  123. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_VAL 0x0a
  124. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT 5
  125. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_MASK 0x7f
  126. #define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_VAL 0x1e
  127. #define XUSB_PADCTL_HSIC_STRB_TRIM_CONTROL 0x344
  128. #define XUSB_PADCTL_UPHY_PLL_P0_CTL1 0x360
  129. #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT 20
  130. #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK 0xff
  131. #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL 0x19
  132. #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SATA_VAL 0x1e
  133. #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT 16
  134. #define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK 0x3
  135. #define XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS (1 << 15)
  136. #define XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD (1 << 4)
  137. #define XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE (1 << 3)
  138. #define XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT 1
  139. #define XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK 0x3
  140. #define XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ (1 << 0)
  141. #define XUSB_PADCTL_UPHY_PLL_P0_CTL2 0x364
  142. #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT 4
  143. #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK 0xffffff
  144. #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL 0x136
  145. #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD (1 << 2)
  146. #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE (1 << 1)
  147. #define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN (1 << 0)
  148. #define XUSB_PADCTL_UPHY_PLL_P0_CTL4 0x36c
  149. #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN (1 << 15)
  150. #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT 12
  151. #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK 0x3
  152. #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL 0x2
  153. #define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SATA_VAL 0x0
  154. #define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN (1 << 8)
  155. #define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT 4
  156. #define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK 0xf
  157. #define XUSB_PADCTL_UPHY_PLL_P0_CTL5 0x370
  158. #define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT 16
  159. #define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK 0xff
  160. #define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL 0x2a
  161. #define XUSB_PADCTL_UPHY_PLL_P0_CTL8 0x37c
  162. #define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE (1 << 31)
  163. #define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD (1 << 15)
  164. #define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN (1 << 13)
  165. #define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN (1 << 12)
  166. #define XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL1(x) (0x460 + (x) * 0x40)
  167. #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT 20
  168. #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_MASK 0x3
  169. #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_VAL 0x1
  170. #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN BIT(18)
  171. #define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD BIT(13)
  172. #define XUSB_PADCTL_UPHY_PLL_S0_CTL1 0x860
  173. #define XUSB_PADCTL_UPHY_PLL_S0_CTL2 0x864
  174. #define XUSB_PADCTL_UPHY_PLL_S0_CTL4 0x86c
  175. #define XUSB_PADCTL_UPHY_PLL_S0_CTL5 0x870
  176. #define XUSB_PADCTL_UPHY_PLL_S0_CTL8 0x87c
  177. #define XUSB_PADCTL_UPHY_MISC_PAD_S0_CTL1 0x960
  178. #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(x) (0xa60 + (x) * 0x40)
  179. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT 16
  180. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_MASK 0x3
  181. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_VAL 0x2
  182. #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(x) (0xa64 + (x) * 0x40)
  183. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT 0
  184. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_MASK 0xffff
  185. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_VAL 0x00fc
  186. #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL3(x) (0xa68 + (x) * 0x40)
  187. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL3_RX_DFE_VAL 0xc0077f1f
  188. #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(x) (0xa6c + (x) * 0x40)
  189. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT 16
  190. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_MASK 0xffff
  191. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_VAL 0x01c7
  192. #define XUSB_PADCTL_UPHY_USB3_PADX_ECTL6(x) (0xa74 + (x) * 0x40)
  193. #define XUSB_PADCTL_UPHY_USB3_PAD_ECTL6_RX_EQ_CTRL_H_VAL 0xfcf01368
  194. struct tegra210_xusb_fuse_calibration {
  195. u32 hs_curr_level[4];
  196. u32 hs_term_range_adj;
  197. u32 rpd_ctrl;
  198. };
  199. struct tegra210_xusb_padctl {
  200. struct tegra_xusb_padctl base;
  201. struct tegra210_xusb_fuse_calibration fuse;
  202. };
  203. static inline struct tegra210_xusb_padctl *
  204. to_tegra210_xusb_padctl(struct tegra_xusb_padctl *padctl)
  205. {
  206. return container_of(padctl, struct tegra210_xusb_padctl, base);
  207. }
  208. /* must be called under padctl->lock */
  209. static int tegra210_pex_uphy_enable(struct tegra_xusb_padctl *padctl)
  210. {
  211. struct tegra_xusb_pcie_pad *pcie = to_pcie_pad(padctl->pcie);
  212. unsigned long timeout;
  213. u32 value;
  214. int err;
  215. if (pcie->enable > 0) {
  216. pcie->enable++;
  217. return 0;
  218. }
  219. err = clk_prepare_enable(pcie->pll);
  220. if (err < 0)
  221. return err;
  222. err = reset_control_deassert(pcie->rst);
  223. if (err < 0)
  224. goto disable;
  225. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  226. value &= ~(XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK <<
  227. XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT);
  228. value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL <<
  229. XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT;
  230. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  231. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL5);
  232. value &= ~(XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK <<
  233. XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT);
  234. value |= XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL <<
  235. XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT;
  236. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL5);
  237. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  238. value |= XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD;
  239. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  240. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  241. value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD;
  242. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  243. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  244. value |= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD;
  245. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  246. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL4);
  247. value &= ~((XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK <<
  248. XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT) |
  249. (XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK <<
  250. XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT));
  251. value |= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL <<
  252. XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT) |
  253. XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN;
  254. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL4);
  255. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  256. value &= ~((XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK <<
  257. XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT) |
  258. (XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK <<
  259. XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT));
  260. value |= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL <<
  261. XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT;
  262. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  263. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  264. value &= ~XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ;
  265. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  266. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  267. value &= ~(XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK <<
  268. XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT);
  269. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  270. usleep_range(10, 20);
  271. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL4);
  272. value |= XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN;
  273. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL4);
  274. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  275. value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN;
  276. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  277. timeout = jiffies + msecs_to_jiffies(100);
  278. while (time_before(jiffies, timeout)) {
  279. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  280. if (value & XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE)
  281. break;
  282. usleep_range(10, 20);
  283. }
  284. if (time_after_eq(jiffies, timeout)) {
  285. err = -ETIMEDOUT;
  286. goto reset;
  287. }
  288. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  289. value &= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN;
  290. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  291. timeout = jiffies + msecs_to_jiffies(100);
  292. while (time_before(jiffies, timeout)) {
  293. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  294. if (!(value & XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE))
  295. break;
  296. usleep_range(10, 20);
  297. }
  298. if (time_after_eq(jiffies, timeout)) {
  299. err = -ETIMEDOUT;
  300. goto reset;
  301. }
  302. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  303. value |= XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE;
  304. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  305. timeout = jiffies + msecs_to_jiffies(100);
  306. while (time_before(jiffies, timeout)) {
  307. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  308. if (value & XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS)
  309. break;
  310. usleep_range(10, 20);
  311. }
  312. if (time_after_eq(jiffies, timeout)) {
  313. err = -ETIMEDOUT;
  314. goto reset;
  315. }
  316. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  317. value |= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN |
  318. XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN;
  319. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  320. timeout = jiffies + msecs_to_jiffies(100);
  321. while (time_before(jiffies, timeout)) {
  322. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  323. if (value & XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE)
  324. break;
  325. usleep_range(10, 20);
  326. }
  327. if (time_after_eq(jiffies, timeout)) {
  328. err = -ETIMEDOUT;
  329. goto reset;
  330. }
  331. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  332. value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN;
  333. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  334. timeout = jiffies + msecs_to_jiffies(100);
  335. while (time_before(jiffies, timeout)) {
  336. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  337. if (!(value & XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE))
  338. break;
  339. usleep_range(10, 20);
  340. }
  341. if (time_after_eq(jiffies, timeout)) {
  342. err = -ETIMEDOUT;
  343. goto reset;
  344. }
  345. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  346. value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN;
  347. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  348. tegra210_xusb_pll_hw_control_enable();
  349. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  350. value &= ~XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD;
  351. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
  352. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  353. value &= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD;
  354. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
  355. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  356. value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD;
  357. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
  358. usleep_range(10, 20);
  359. tegra210_xusb_pll_hw_sequence_start();
  360. pcie->enable++;
  361. return 0;
  362. reset:
  363. reset_control_assert(pcie->rst);
  364. disable:
  365. clk_disable_unprepare(pcie->pll);
  366. return err;
  367. }
  368. static void tegra210_pex_uphy_disable(struct tegra_xusb_padctl *padctl)
  369. {
  370. struct tegra_xusb_pcie_pad *pcie = to_pcie_pad(padctl->pcie);
  371. mutex_lock(&padctl->lock);
  372. if (WARN_ON(pcie->enable == 0))
  373. goto unlock;
  374. if (--pcie->enable > 0)
  375. goto unlock;
  376. reset_control_assert(pcie->rst);
  377. clk_disable_unprepare(pcie->pll);
  378. unlock:
  379. mutex_unlock(&padctl->lock);
  380. }
  381. /* must be called under padctl->lock */
  382. static int tegra210_sata_uphy_enable(struct tegra_xusb_padctl *padctl, bool usb)
  383. {
  384. struct tegra_xusb_sata_pad *sata = to_sata_pad(padctl->sata);
  385. unsigned long timeout;
  386. u32 value;
  387. int err;
  388. if (sata->enable > 0) {
  389. sata->enable++;
  390. return 0;
  391. }
  392. err = clk_prepare_enable(sata->pll);
  393. if (err < 0)
  394. return err;
  395. err = reset_control_deassert(sata->rst);
  396. if (err < 0)
  397. goto disable;
  398. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  399. value &= ~(XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK <<
  400. XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT);
  401. value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL <<
  402. XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT;
  403. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  404. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL5);
  405. value &= ~(XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK <<
  406. XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT);
  407. value |= XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL <<
  408. XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT;
  409. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL5);
  410. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  411. value |= XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD;
  412. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  413. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  414. value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD;
  415. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  416. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  417. value |= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD;
  418. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  419. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL4);
  420. value &= ~((XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK <<
  421. XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT) |
  422. (XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK <<
  423. XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT));
  424. value |= XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN;
  425. if (usb)
  426. value |= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL <<
  427. XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT);
  428. else
  429. value |= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SATA_VAL <<
  430. XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT);
  431. /* XXX PLL0_XDIGCLK_EN */
  432. /*
  433. value &= ~(1 << 19);
  434. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL4);
  435. */
  436. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  437. value &= ~((XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK <<
  438. XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT) |
  439. (XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK <<
  440. XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT));
  441. if (usb)
  442. value |= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL <<
  443. XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT;
  444. else
  445. value |= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SATA_VAL <<
  446. XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT;
  447. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  448. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  449. value &= ~XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ;
  450. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  451. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  452. value &= ~(XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK <<
  453. XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT);
  454. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  455. usleep_range(10, 20);
  456. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL4);
  457. value |= XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN;
  458. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL4);
  459. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  460. value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN;
  461. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  462. timeout = jiffies + msecs_to_jiffies(100);
  463. while (time_before(jiffies, timeout)) {
  464. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  465. if (value & XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE)
  466. break;
  467. usleep_range(10, 20);
  468. }
  469. if (time_after_eq(jiffies, timeout)) {
  470. err = -ETIMEDOUT;
  471. goto reset;
  472. }
  473. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  474. value &= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN;
  475. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  476. timeout = jiffies + msecs_to_jiffies(100);
  477. while (time_before(jiffies, timeout)) {
  478. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  479. if (!(value & XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE))
  480. break;
  481. usleep_range(10, 20);
  482. }
  483. if (time_after_eq(jiffies, timeout)) {
  484. err = -ETIMEDOUT;
  485. goto reset;
  486. }
  487. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  488. value |= XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE;
  489. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  490. timeout = jiffies + msecs_to_jiffies(100);
  491. while (time_before(jiffies, timeout)) {
  492. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  493. if (value & XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS)
  494. break;
  495. usleep_range(10, 20);
  496. }
  497. if (time_after_eq(jiffies, timeout)) {
  498. err = -ETIMEDOUT;
  499. goto reset;
  500. }
  501. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  502. value |= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN |
  503. XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN;
  504. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  505. timeout = jiffies + msecs_to_jiffies(100);
  506. while (time_before(jiffies, timeout)) {
  507. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  508. if (value & XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE)
  509. break;
  510. usleep_range(10, 20);
  511. }
  512. if (time_after_eq(jiffies, timeout)) {
  513. err = -ETIMEDOUT;
  514. goto reset;
  515. }
  516. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  517. value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN;
  518. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  519. timeout = jiffies + msecs_to_jiffies(100);
  520. while (time_before(jiffies, timeout)) {
  521. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  522. if (!(value & XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE))
  523. break;
  524. usleep_range(10, 20);
  525. }
  526. if (time_after_eq(jiffies, timeout)) {
  527. err = -ETIMEDOUT;
  528. goto reset;
  529. }
  530. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  531. value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN;
  532. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  533. tegra210_sata_pll_hw_control_enable();
  534. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  535. value &= ~XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD;
  536. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1);
  537. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  538. value &= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD;
  539. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2);
  540. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  541. value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD;
  542. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8);
  543. usleep_range(10, 20);
  544. tegra210_sata_pll_hw_sequence_start();
  545. sata->enable++;
  546. return 0;
  547. reset:
  548. reset_control_assert(sata->rst);
  549. disable:
  550. clk_disable_unprepare(sata->pll);
  551. return err;
  552. }
  553. static void tegra210_sata_uphy_disable(struct tegra_xusb_padctl *padctl)
  554. {
  555. struct tegra_xusb_sata_pad *sata = to_sata_pad(padctl->sata);
  556. mutex_lock(&padctl->lock);
  557. if (WARN_ON(sata->enable == 0))
  558. goto unlock;
  559. if (--sata->enable > 0)
  560. goto unlock;
  561. reset_control_assert(sata->rst);
  562. clk_disable_unprepare(sata->pll);
  563. unlock:
  564. mutex_unlock(&padctl->lock);
  565. }
  566. static int tegra210_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
  567. {
  568. u32 value;
  569. mutex_lock(&padctl->lock);
  570. if (padctl->enable++ > 0)
  571. goto out;
  572. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  573. value &= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN;
  574. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  575. usleep_range(100, 200);
  576. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  577. value &= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY;
  578. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  579. usleep_range(100, 200);
  580. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  581. value &= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN;
  582. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  583. out:
  584. mutex_unlock(&padctl->lock);
  585. return 0;
  586. }
  587. static int tegra210_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
  588. {
  589. u32 value;
  590. mutex_lock(&padctl->lock);
  591. if (WARN_ON(padctl->enable == 0))
  592. goto out;
  593. if (--padctl->enable > 0)
  594. goto out;
  595. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  596. value |= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN;
  597. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  598. usleep_range(100, 200);
  599. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  600. value |= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY;
  601. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  602. usleep_range(100, 200);
  603. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  604. value |= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN;
  605. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  606. out:
  607. mutex_unlock(&padctl->lock);
  608. return 0;
  609. }
  610. static int tegra210_hsic_set_idle(struct tegra_xusb_padctl *padctl,
  611. unsigned int index, bool idle)
  612. {
  613. u32 value;
  614. value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL0(index));
  615. value &= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0 |
  616. XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1 |
  617. XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE);
  618. if (idle)
  619. value |= XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 |
  620. XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 |
  621. XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE;
  622. else
  623. value &= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 |
  624. XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 |
  625. XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE);
  626. padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL0(index));
  627. return 0;
  628. }
  629. static int tegra210_usb3_set_lfps_detect(struct tegra_xusb_padctl *padctl,
  630. unsigned int index, bool enable)
  631. {
  632. struct tegra_xusb_port *port;
  633. struct tegra_xusb_lane *lane;
  634. u32 value, offset;
  635. port = tegra_xusb_find_port(padctl, "usb3", index);
  636. if (!port)
  637. return -ENODEV;
  638. lane = port->lane;
  639. if (lane->pad == padctl->pcie)
  640. offset = XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL1(lane->index);
  641. else
  642. offset = XUSB_PADCTL_UPHY_MISC_PAD_S0_CTL1;
  643. value = padctl_readl(padctl, offset);
  644. value &= ~((XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_MASK <<
  645. XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT) |
  646. XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN |
  647. XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD);
  648. if (!enable) {
  649. value |= (XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_VAL <<
  650. XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT) |
  651. XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN |
  652. XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD;
  653. }
  654. padctl_writel(padctl, value, offset);
  655. return 0;
  656. }
  657. #define TEGRA210_LANE(_name, _offset, _shift, _mask, _type) \
  658. { \
  659. .name = _name, \
  660. .offset = _offset, \
  661. .shift = _shift, \
  662. .mask = _mask, \
  663. .num_funcs = ARRAY_SIZE(tegra210_##_type##_functions), \
  664. .funcs = tegra210_##_type##_functions, \
  665. }
  666. static const char *tegra210_usb2_functions[] = {
  667. "snps",
  668. "xusb",
  669. "uart"
  670. };
  671. static const struct tegra_xusb_lane_soc tegra210_usb2_lanes[] = {
  672. TEGRA210_LANE("usb2-0", 0x004, 0, 0x3, usb2),
  673. TEGRA210_LANE("usb2-1", 0x004, 2, 0x3, usb2),
  674. TEGRA210_LANE("usb2-2", 0x004, 4, 0x3, usb2),
  675. TEGRA210_LANE("usb2-3", 0x004, 6, 0x3, usb2),
  676. };
  677. static struct tegra_xusb_lane *
  678. tegra210_usb2_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np,
  679. unsigned int index)
  680. {
  681. struct tegra_xusb_usb2_lane *usb2;
  682. int err;
  683. usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL);
  684. if (!usb2)
  685. return ERR_PTR(-ENOMEM);
  686. INIT_LIST_HEAD(&usb2->base.list);
  687. usb2->base.soc = &pad->soc->lanes[index];
  688. usb2->base.index = index;
  689. usb2->base.pad = pad;
  690. usb2->base.np = np;
  691. err = tegra_xusb_lane_parse_dt(&usb2->base, np);
  692. if (err < 0) {
  693. kfree(usb2);
  694. return ERR_PTR(err);
  695. }
  696. return &usb2->base;
  697. }
  698. static void tegra210_usb2_lane_remove(struct tegra_xusb_lane *lane)
  699. {
  700. struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane);
  701. kfree(usb2);
  702. }
  703. static const struct tegra_xusb_lane_ops tegra210_usb2_lane_ops = {
  704. .probe = tegra210_usb2_lane_probe,
  705. .remove = tegra210_usb2_lane_remove,
  706. };
  707. static int tegra210_usb2_phy_init(struct phy *phy)
  708. {
  709. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  710. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  711. u32 value;
  712. value = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX);
  713. value &= ~(XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_MASK <<
  714. XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT);
  715. value |= XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_XUSB <<
  716. XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT;
  717. padctl_writel(padctl, value, XUSB_PADCTL_USB2_PAD_MUX);
  718. return tegra210_xusb_padctl_enable(padctl);
  719. }
  720. static int tegra210_usb2_phy_exit(struct phy *phy)
  721. {
  722. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  723. return tegra210_xusb_padctl_disable(lane->pad->padctl);
  724. }
  725. static int tegra210_usb2_phy_power_on(struct phy *phy)
  726. {
  727. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  728. struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane);
  729. struct tegra_xusb_usb2_pad *pad = to_usb2_pad(lane->pad);
  730. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  731. struct tegra210_xusb_padctl *priv;
  732. struct tegra_xusb_usb2_port *port;
  733. unsigned int index = lane->index;
  734. u32 value;
  735. int err;
  736. port = tegra_xusb_find_usb2_port(padctl, index);
  737. if (!port) {
  738. dev_err(&phy->dev, "no port found for USB2 lane %u\n", index);
  739. return -ENODEV;
  740. }
  741. priv = to_tegra210_xusb_padctl(padctl);
  742. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
  743. value &= ~((XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_MASK <<
  744. XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT) |
  745. (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_MASK <<
  746. XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT));
  747. value |= (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_VAL <<
  748. XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT);
  749. if (tegra_sku_info.revision < TEGRA_REVISION_A02)
  750. value |=
  751. (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_VAL <<
  752. XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT);
  753. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
  754. value = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP);
  755. value &= ~XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_MASK(index);
  756. value |= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_HOST(index);
  757. padctl_writel(padctl, value, XUSB_PADCTL_USB2_PORT_CAP);
  758. value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
  759. value &= ~((XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_MASK <<
  760. XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT) |
  761. XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD |
  762. XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD2 |
  763. XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD_ZI);
  764. value |= (priv->fuse.hs_curr_level[index] +
  765. usb2->hs_curr_level_offset) <<
  766. XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT;
  767. padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
  768. value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
  769. value &= ~((XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_MASK <<
  770. XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT) |
  771. (XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_MASK <<
  772. XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT) |
  773. XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DR |
  774. XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_CHRP_OVRD |
  775. XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DISC_OVRD);
  776. value |= (priv->fuse.hs_term_range_adj <<
  777. XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT) |
  778. (priv->fuse.rpd_ctrl <<
  779. XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT);
  780. padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
  781. value = padctl_readl(padctl,
  782. XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(index));
  783. value &= ~(XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_MASK <<
  784. XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_SHIFT);
  785. value |= XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_FIX18;
  786. padctl_writel(padctl, value,
  787. XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(index));
  788. err = regulator_enable(port->supply);
  789. if (err)
  790. return err;
  791. mutex_lock(&padctl->lock);
  792. if (pad->enable > 0) {
  793. pad->enable++;
  794. mutex_unlock(&padctl->lock);
  795. return 0;
  796. }
  797. err = clk_prepare_enable(pad->clk);
  798. if (err)
  799. goto disable_regulator;
  800. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  801. value &= ~((XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_MASK <<
  802. XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT) |
  803. (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_MASK <<
  804. XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT));
  805. value |= (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_VAL <<
  806. XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT) |
  807. (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_VAL <<
  808. XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT);
  809. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  810. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
  811. value &= ~XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD;
  812. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
  813. udelay(1);
  814. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  815. value &= ~XUSB_PADCTL_USB2_BIAS_PAD_CTL1_PD_TRK;
  816. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
  817. udelay(50);
  818. clk_disable_unprepare(pad->clk);
  819. pad->enable++;
  820. mutex_unlock(&padctl->lock);
  821. return 0;
  822. disable_regulator:
  823. regulator_disable(port->supply);
  824. mutex_unlock(&padctl->lock);
  825. return err;
  826. }
  827. static int tegra210_usb2_phy_power_off(struct phy *phy)
  828. {
  829. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  830. struct tegra_xusb_usb2_pad *pad = to_usb2_pad(lane->pad);
  831. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  832. struct tegra_xusb_usb2_port *port;
  833. u32 value;
  834. port = tegra_xusb_find_usb2_port(padctl, lane->index);
  835. if (!port) {
  836. dev_err(&phy->dev, "no port found for USB2 lane %u\n",
  837. lane->index);
  838. return -ENODEV;
  839. }
  840. mutex_lock(&padctl->lock);
  841. if (WARN_ON(pad->enable == 0))
  842. goto out;
  843. if (--pad->enable > 0)
  844. goto out;
  845. value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
  846. value |= XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD;
  847. padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
  848. out:
  849. regulator_disable(port->supply);
  850. mutex_unlock(&padctl->lock);
  851. return 0;
  852. }
  853. static const struct phy_ops tegra210_usb2_phy_ops = {
  854. .init = tegra210_usb2_phy_init,
  855. .exit = tegra210_usb2_phy_exit,
  856. .power_on = tegra210_usb2_phy_power_on,
  857. .power_off = tegra210_usb2_phy_power_off,
  858. .owner = THIS_MODULE,
  859. };
  860. static struct tegra_xusb_pad *
  861. tegra210_usb2_pad_probe(struct tegra_xusb_padctl *padctl,
  862. const struct tegra_xusb_pad_soc *soc,
  863. struct device_node *np)
  864. {
  865. struct tegra_xusb_usb2_pad *usb2;
  866. struct tegra_xusb_pad *pad;
  867. int err;
  868. usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL);
  869. if (!usb2)
  870. return ERR_PTR(-ENOMEM);
  871. pad = &usb2->base;
  872. pad->ops = &tegra210_usb2_lane_ops;
  873. pad->soc = soc;
  874. err = tegra_xusb_pad_init(pad, padctl, np);
  875. if (err < 0) {
  876. kfree(usb2);
  877. goto out;
  878. }
  879. usb2->clk = devm_clk_get(&pad->dev, "trk");
  880. if (IS_ERR(usb2->clk)) {
  881. err = PTR_ERR(usb2->clk);
  882. dev_err(&pad->dev, "failed to get trk clock: %d\n", err);
  883. goto unregister;
  884. }
  885. err = tegra_xusb_pad_register(pad, &tegra210_usb2_phy_ops);
  886. if (err < 0)
  887. goto unregister;
  888. dev_set_drvdata(&pad->dev, pad);
  889. return pad;
  890. unregister:
  891. device_unregister(&pad->dev);
  892. out:
  893. return ERR_PTR(err);
  894. }
  895. static void tegra210_usb2_pad_remove(struct tegra_xusb_pad *pad)
  896. {
  897. struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad);
  898. kfree(usb2);
  899. }
  900. static const struct tegra_xusb_pad_ops tegra210_usb2_ops = {
  901. .probe = tegra210_usb2_pad_probe,
  902. .remove = tegra210_usb2_pad_remove,
  903. };
  904. static const struct tegra_xusb_pad_soc tegra210_usb2_pad = {
  905. .name = "usb2",
  906. .num_lanes = ARRAY_SIZE(tegra210_usb2_lanes),
  907. .lanes = tegra210_usb2_lanes,
  908. .ops = &tegra210_usb2_ops,
  909. };
  910. static const char *tegra210_hsic_functions[] = {
  911. "snps",
  912. "xusb",
  913. };
  914. static const struct tegra_xusb_lane_soc tegra210_hsic_lanes[] = {
  915. TEGRA210_LANE("hsic-0", 0x004, 14, 0x1, hsic),
  916. };
  917. static struct tegra_xusb_lane *
  918. tegra210_hsic_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np,
  919. unsigned int index)
  920. {
  921. struct tegra_xusb_hsic_lane *hsic;
  922. int err;
  923. hsic = kzalloc(sizeof(*hsic), GFP_KERNEL);
  924. if (!hsic)
  925. return ERR_PTR(-ENOMEM);
  926. INIT_LIST_HEAD(&hsic->base.list);
  927. hsic->base.soc = &pad->soc->lanes[index];
  928. hsic->base.index = index;
  929. hsic->base.pad = pad;
  930. hsic->base.np = np;
  931. err = tegra_xusb_lane_parse_dt(&hsic->base, np);
  932. if (err < 0) {
  933. kfree(hsic);
  934. return ERR_PTR(err);
  935. }
  936. return &hsic->base;
  937. }
  938. static void tegra210_hsic_lane_remove(struct tegra_xusb_lane *lane)
  939. {
  940. struct tegra_xusb_hsic_lane *hsic = to_hsic_lane(lane);
  941. kfree(hsic);
  942. }
  943. static const struct tegra_xusb_lane_ops tegra210_hsic_lane_ops = {
  944. .probe = tegra210_hsic_lane_probe,
  945. .remove = tegra210_hsic_lane_remove,
  946. };
  947. static int tegra210_hsic_phy_init(struct phy *phy)
  948. {
  949. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  950. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  951. u32 value;
  952. value = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX);
  953. value &= ~(XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_MASK <<
  954. XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT);
  955. value |= XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_XUSB <<
  956. XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT;
  957. padctl_writel(padctl, value, XUSB_PADCTL_USB2_PAD_MUX);
  958. return tegra210_xusb_padctl_enable(padctl);
  959. }
  960. static int tegra210_hsic_phy_exit(struct phy *phy)
  961. {
  962. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  963. return tegra210_xusb_padctl_disable(lane->pad->padctl);
  964. }
  965. static int tegra210_hsic_phy_power_on(struct phy *phy)
  966. {
  967. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  968. struct tegra_xusb_hsic_lane *hsic = to_hsic_lane(lane);
  969. struct tegra_xusb_hsic_pad *pad = to_hsic_pad(lane->pad);
  970. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  971. struct tegra210_xusb_padctl *priv;
  972. unsigned int index = lane->index;
  973. u32 value;
  974. int err;
  975. priv = to_tegra210_xusb_padctl(padctl);
  976. err = regulator_enable(pad->supply);
  977. if (err)
  978. return err;
  979. padctl_writel(padctl, hsic->strobe_trim,
  980. XUSB_PADCTL_HSIC_STRB_TRIM_CONTROL);
  981. value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL1(index));
  982. value &= ~(XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_MASK <<
  983. XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT);
  984. value |= (hsic->tx_rtune_p <<
  985. XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT);
  986. padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL1(index));
  987. value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL2(index));
  988. value &= ~((XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_MASK <<
  989. XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT) |
  990. (XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_MASK <<
  991. XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT));
  992. value |= (hsic->rx_strobe_trim <<
  993. XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT) |
  994. (hsic->rx_data_trim <<
  995. XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT);
  996. padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL2(index));
  997. value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL0(index));
  998. value &= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0 |
  999. XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1 |
  1000. XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE |
  1001. XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0 |
  1002. XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1 |
  1003. XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE |
  1004. XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0 |
  1005. XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1 |
  1006. XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE |
  1007. XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0 |
  1008. XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1 |
  1009. XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE);
  1010. value |= XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 |
  1011. XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 |
  1012. XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE;
  1013. padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL0(index));
  1014. err = clk_prepare_enable(pad->clk);
  1015. if (err)
  1016. goto disable;
  1017. value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PAD_TRK_CTL);
  1018. value &= ~((XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_MASK <<
  1019. XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT) |
  1020. (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_MASK <<
  1021. XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT));
  1022. value |= (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_VAL <<
  1023. XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT) |
  1024. (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_VAL <<
  1025. XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT);
  1026. padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PAD_TRK_CTL);
  1027. udelay(1);
  1028. value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PAD_TRK_CTL);
  1029. value &= ~XUSB_PADCTL_HSIC_PAD_TRK_CTL_PD_TRK;
  1030. padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PAD_TRK_CTL);
  1031. udelay(50);
  1032. clk_disable_unprepare(pad->clk);
  1033. return 0;
  1034. disable:
  1035. regulator_disable(pad->supply);
  1036. return err;
  1037. }
  1038. static int tegra210_hsic_phy_power_off(struct phy *phy)
  1039. {
  1040. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1041. struct tegra_xusb_hsic_pad *pad = to_hsic_pad(lane->pad);
  1042. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  1043. unsigned int index = lane->index;
  1044. u32 value;
  1045. value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL0(index));
  1046. value |= XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0 |
  1047. XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1 |
  1048. XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE |
  1049. XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0 |
  1050. XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1 |
  1051. XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE |
  1052. XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0 |
  1053. XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1 |
  1054. XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE;
  1055. padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL1(index));
  1056. regulator_disable(pad->supply);
  1057. return 0;
  1058. }
  1059. static const struct phy_ops tegra210_hsic_phy_ops = {
  1060. .init = tegra210_hsic_phy_init,
  1061. .exit = tegra210_hsic_phy_exit,
  1062. .power_on = tegra210_hsic_phy_power_on,
  1063. .power_off = tegra210_hsic_phy_power_off,
  1064. .owner = THIS_MODULE,
  1065. };
  1066. static struct tegra_xusb_pad *
  1067. tegra210_hsic_pad_probe(struct tegra_xusb_padctl *padctl,
  1068. const struct tegra_xusb_pad_soc *soc,
  1069. struct device_node *np)
  1070. {
  1071. struct tegra_xusb_hsic_pad *hsic;
  1072. struct tegra_xusb_pad *pad;
  1073. int err;
  1074. hsic = kzalloc(sizeof(*hsic), GFP_KERNEL);
  1075. if (!hsic)
  1076. return ERR_PTR(-ENOMEM);
  1077. pad = &hsic->base;
  1078. pad->ops = &tegra210_hsic_lane_ops;
  1079. pad->soc = soc;
  1080. err = tegra_xusb_pad_init(pad, padctl, np);
  1081. if (err < 0) {
  1082. kfree(hsic);
  1083. goto out;
  1084. }
  1085. hsic->clk = devm_clk_get(&pad->dev, "trk");
  1086. if (IS_ERR(hsic->clk)) {
  1087. err = PTR_ERR(hsic->clk);
  1088. dev_err(&pad->dev, "failed to get trk clock: %d\n", err);
  1089. goto unregister;
  1090. }
  1091. err = tegra_xusb_pad_register(pad, &tegra210_hsic_phy_ops);
  1092. if (err < 0)
  1093. goto unregister;
  1094. dev_set_drvdata(&pad->dev, pad);
  1095. return pad;
  1096. unregister:
  1097. device_unregister(&pad->dev);
  1098. out:
  1099. return ERR_PTR(err);
  1100. }
  1101. static void tegra210_hsic_pad_remove(struct tegra_xusb_pad *pad)
  1102. {
  1103. struct tegra_xusb_hsic_pad *hsic = to_hsic_pad(pad);
  1104. kfree(hsic);
  1105. }
  1106. static const struct tegra_xusb_pad_ops tegra210_hsic_ops = {
  1107. .probe = tegra210_hsic_pad_probe,
  1108. .remove = tegra210_hsic_pad_remove,
  1109. };
  1110. static const struct tegra_xusb_pad_soc tegra210_hsic_pad = {
  1111. .name = "hsic",
  1112. .num_lanes = ARRAY_SIZE(tegra210_hsic_lanes),
  1113. .lanes = tegra210_hsic_lanes,
  1114. .ops = &tegra210_hsic_ops,
  1115. };
  1116. static const char *tegra210_pcie_functions[] = {
  1117. "pcie-x1",
  1118. "usb3-ss",
  1119. "sata",
  1120. "pcie-x4",
  1121. };
  1122. static const struct tegra_xusb_lane_soc tegra210_pcie_lanes[] = {
  1123. TEGRA210_LANE("pcie-0", 0x028, 12, 0x3, pcie),
  1124. TEGRA210_LANE("pcie-1", 0x028, 14, 0x3, pcie),
  1125. TEGRA210_LANE("pcie-2", 0x028, 16, 0x3, pcie),
  1126. TEGRA210_LANE("pcie-3", 0x028, 18, 0x3, pcie),
  1127. TEGRA210_LANE("pcie-4", 0x028, 20, 0x3, pcie),
  1128. TEGRA210_LANE("pcie-5", 0x028, 22, 0x3, pcie),
  1129. TEGRA210_LANE("pcie-6", 0x028, 24, 0x3, pcie),
  1130. };
  1131. static struct tegra_xusb_lane *
  1132. tegra210_pcie_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np,
  1133. unsigned int index)
  1134. {
  1135. struct tegra_xusb_pcie_lane *pcie;
  1136. int err;
  1137. pcie = kzalloc(sizeof(*pcie), GFP_KERNEL);
  1138. if (!pcie)
  1139. return ERR_PTR(-ENOMEM);
  1140. INIT_LIST_HEAD(&pcie->base.list);
  1141. pcie->base.soc = &pad->soc->lanes[index];
  1142. pcie->base.index = index;
  1143. pcie->base.pad = pad;
  1144. pcie->base.np = np;
  1145. err = tegra_xusb_lane_parse_dt(&pcie->base, np);
  1146. if (err < 0) {
  1147. kfree(pcie);
  1148. return ERR_PTR(err);
  1149. }
  1150. return &pcie->base;
  1151. }
  1152. static void tegra210_pcie_lane_remove(struct tegra_xusb_lane *lane)
  1153. {
  1154. struct tegra_xusb_pcie_lane *pcie = to_pcie_lane(lane);
  1155. kfree(pcie);
  1156. }
  1157. static const struct tegra_xusb_lane_ops tegra210_pcie_lane_ops = {
  1158. .probe = tegra210_pcie_lane_probe,
  1159. .remove = tegra210_pcie_lane_remove,
  1160. };
  1161. static int tegra210_pcie_phy_init(struct phy *phy)
  1162. {
  1163. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1164. return tegra210_xusb_padctl_enable(lane->pad->padctl);
  1165. }
  1166. static int tegra210_pcie_phy_exit(struct phy *phy)
  1167. {
  1168. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1169. return tegra210_xusb_padctl_disable(lane->pad->padctl);
  1170. }
  1171. static int tegra210_pcie_phy_power_on(struct phy *phy)
  1172. {
  1173. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1174. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  1175. u32 value;
  1176. int err;
  1177. mutex_lock(&padctl->lock);
  1178. err = tegra210_pex_uphy_enable(padctl);
  1179. if (err < 0)
  1180. goto unlock;
  1181. value = padctl_readl(padctl, XUSB_PADCTL_USB3_PAD_MUX);
  1182. value |= XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(lane->index);
  1183. padctl_writel(padctl, value, XUSB_PADCTL_USB3_PAD_MUX);
  1184. unlock:
  1185. mutex_unlock(&padctl->lock);
  1186. return err;
  1187. }
  1188. static int tegra210_pcie_phy_power_off(struct phy *phy)
  1189. {
  1190. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1191. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  1192. u32 value;
  1193. value = padctl_readl(padctl, XUSB_PADCTL_USB3_PAD_MUX);
  1194. value &= ~XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(lane->index);
  1195. padctl_writel(padctl, value, XUSB_PADCTL_USB3_PAD_MUX);
  1196. tegra210_pex_uphy_disable(padctl);
  1197. return 0;
  1198. }
  1199. static const struct phy_ops tegra210_pcie_phy_ops = {
  1200. .init = tegra210_pcie_phy_init,
  1201. .exit = tegra210_pcie_phy_exit,
  1202. .power_on = tegra210_pcie_phy_power_on,
  1203. .power_off = tegra210_pcie_phy_power_off,
  1204. .owner = THIS_MODULE,
  1205. };
  1206. static struct tegra_xusb_pad *
  1207. tegra210_pcie_pad_probe(struct tegra_xusb_padctl *padctl,
  1208. const struct tegra_xusb_pad_soc *soc,
  1209. struct device_node *np)
  1210. {
  1211. struct tegra_xusb_pcie_pad *pcie;
  1212. struct tegra_xusb_pad *pad;
  1213. int err;
  1214. pcie = kzalloc(sizeof(*pcie), GFP_KERNEL);
  1215. if (!pcie)
  1216. return ERR_PTR(-ENOMEM);
  1217. pad = &pcie->base;
  1218. pad->ops = &tegra210_pcie_lane_ops;
  1219. pad->soc = soc;
  1220. err = tegra_xusb_pad_init(pad, padctl, np);
  1221. if (err < 0) {
  1222. kfree(pcie);
  1223. goto out;
  1224. }
  1225. pcie->pll = devm_clk_get(&pad->dev, "pll");
  1226. if (IS_ERR(pcie->pll)) {
  1227. err = PTR_ERR(pcie->pll);
  1228. dev_err(&pad->dev, "failed to get PLL: %d\n", err);
  1229. goto unregister;
  1230. }
  1231. pcie->rst = devm_reset_control_get(&pad->dev, "phy");
  1232. if (IS_ERR(pcie->rst)) {
  1233. err = PTR_ERR(pcie->rst);
  1234. dev_err(&pad->dev, "failed to get PCIe pad reset: %d\n", err);
  1235. goto unregister;
  1236. }
  1237. err = tegra_xusb_pad_register(pad, &tegra210_pcie_phy_ops);
  1238. if (err < 0)
  1239. goto unregister;
  1240. dev_set_drvdata(&pad->dev, pad);
  1241. return pad;
  1242. unregister:
  1243. device_unregister(&pad->dev);
  1244. out:
  1245. return ERR_PTR(err);
  1246. }
  1247. static void tegra210_pcie_pad_remove(struct tegra_xusb_pad *pad)
  1248. {
  1249. struct tegra_xusb_pcie_pad *pcie = to_pcie_pad(pad);
  1250. kfree(pcie);
  1251. }
  1252. static const struct tegra_xusb_pad_ops tegra210_pcie_ops = {
  1253. .probe = tegra210_pcie_pad_probe,
  1254. .remove = tegra210_pcie_pad_remove,
  1255. };
  1256. static const struct tegra_xusb_pad_soc tegra210_pcie_pad = {
  1257. .name = "pcie",
  1258. .num_lanes = ARRAY_SIZE(tegra210_pcie_lanes),
  1259. .lanes = tegra210_pcie_lanes,
  1260. .ops = &tegra210_pcie_ops,
  1261. };
  1262. static const struct tegra_xusb_lane_soc tegra210_sata_lanes[] = {
  1263. TEGRA210_LANE("sata-0", 0x028, 30, 0x3, pcie),
  1264. };
  1265. static struct tegra_xusb_lane *
  1266. tegra210_sata_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np,
  1267. unsigned int index)
  1268. {
  1269. struct tegra_xusb_sata_lane *sata;
  1270. int err;
  1271. sata = kzalloc(sizeof(*sata), GFP_KERNEL);
  1272. if (!sata)
  1273. return ERR_PTR(-ENOMEM);
  1274. INIT_LIST_HEAD(&sata->base.list);
  1275. sata->base.soc = &pad->soc->lanes[index];
  1276. sata->base.index = index;
  1277. sata->base.pad = pad;
  1278. sata->base.np = np;
  1279. err = tegra_xusb_lane_parse_dt(&sata->base, np);
  1280. if (err < 0) {
  1281. kfree(sata);
  1282. return ERR_PTR(err);
  1283. }
  1284. return &sata->base;
  1285. }
  1286. static void tegra210_sata_lane_remove(struct tegra_xusb_lane *lane)
  1287. {
  1288. struct tegra_xusb_sata_lane *sata = to_sata_lane(lane);
  1289. kfree(sata);
  1290. }
  1291. static const struct tegra_xusb_lane_ops tegra210_sata_lane_ops = {
  1292. .probe = tegra210_sata_lane_probe,
  1293. .remove = tegra210_sata_lane_remove,
  1294. };
  1295. static int tegra210_sata_phy_init(struct phy *phy)
  1296. {
  1297. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1298. return tegra210_xusb_padctl_enable(lane->pad->padctl);
  1299. }
  1300. static int tegra210_sata_phy_exit(struct phy *phy)
  1301. {
  1302. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1303. return tegra210_xusb_padctl_disable(lane->pad->padctl);
  1304. }
  1305. static int tegra210_sata_phy_power_on(struct phy *phy)
  1306. {
  1307. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1308. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  1309. u32 value;
  1310. int err;
  1311. mutex_lock(&padctl->lock);
  1312. err = tegra210_sata_uphy_enable(padctl, false);
  1313. if (err < 0)
  1314. goto unlock;
  1315. value = padctl_readl(padctl, XUSB_PADCTL_USB3_PAD_MUX);
  1316. value |= XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(lane->index);
  1317. padctl_writel(padctl, value, XUSB_PADCTL_USB3_PAD_MUX);
  1318. unlock:
  1319. mutex_unlock(&padctl->lock);
  1320. return err;
  1321. }
  1322. static int tegra210_sata_phy_power_off(struct phy *phy)
  1323. {
  1324. struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
  1325. struct tegra_xusb_padctl *padctl = lane->pad->padctl;
  1326. u32 value;
  1327. value = padctl_readl(padctl, XUSB_PADCTL_USB3_PAD_MUX);
  1328. value &= ~XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(lane->index);
  1329. padctl_writel(padctl, value, XUSB_PADCTL_USB3_PAD_MUX);
  1330. tegra210_sata_uphy_disable(lane->pad->padctl);
  1331. return 0;
  1332. }
  1333. static const struct phy_ops tegra210_sata_phy_ops = {
  1334. .init = tegra210_sata_phy_init,
  1335. .exit = tegra210_sata_phy_exit,
  1336. .power_on = tegra210_sata_phy_power_on,
  1337. .power_off = tegra210_sata_phy_power_off,
  1338. .owner = THIS_MODULE,
  1339. };
  1340. static struct tegra_xusb_pad *
  1341. tegra210_sata_pad_probe(struct tegra_xusb_padctl *padctl,
  1342. const struct tegra_xusb_pad_soc *soc,
  1343. struct device_node *np)
  1344. {
  1345. struct tegra_xusb_sata_pad *sata;
  1346. struct tegra_xusb_pad *pad;
  1347. int err;
  1348. sata = kzalloc(sizeof(*sata), GFP_KERNEL);
  1349. if (!sata)
  1350. return ERR_PTR(-ENOMEM);
  1351. pad = &sata->base;
  1352. pad->ops = &tegra210_sata_lane_ops;
  1353. pad->soc = soc;
  1354. err = tegra_xusb_pad_init(pad, padctl, np);
  1355. if (err < 0) {
  1356. kfree(sata);
  1357. goto out;
  1358. }
  1359. sata->rst = devm_reset_control_get(&pad->dev, "phy");
  1360. if (IS_ERR(sata->rst)) {
  1361. err = PTR_ERR(sata->rst);
  1362. dev_err(&pad->dev, "failed to get SATA pad reset: %d\n", err);
  1363. goto unregister;
  1364. }
  1365. err = tegra_xusb_pad_register(pad, &tegra210_sata_phy_ops);
  1366. if (err < 0)
  1367. goto unregister;
  1368. dev_set_drvdata(&pad->dev, pad);
  1369. return pad;
  1370. unregister:
  1371. device_unregister(&pad->dev);
  1372. out:
  1373. return ERR_PTR(err);
  1374. }
  1375. static void tegra210_sata_pad_remove(struct tegra_xusb_pad *pad)
  1376. {
  1377. struct tegra_xusb_sata_pad *sata = to_sata_pad(pad);
  1378. kfree(sata);
  1379. }
  1380. static const struct tegra_xusb_pad_ops tegra210_sata_ops = {
  1381. .probe = tegra210_sata_pad_probe,
  1382. .remove = tegra210_sata_pad_remove,
  1383. };
  1384. static const struct tegra_xusb_pad_soc tegra210_sata_pad = {
  1385. .name = "sata",
  1386. .num_lanes = ARRAY_SIZE(tegra210_sata_lanes),
  1387. .lanes = tegra210_sata_lanes,
  1388. .ops = &tegra210_sata_ops,
  1389. };
  1390. static const struct tegra_xusb_pad_soc * const tegra210_pads[] = {
  1391. &tegra210_usb2_pad,
  1392. &tegra210_hsic_pad,
  1393. &tegra210_pcie_pad,
  1394. &tegra210_sata_pad,
  1395. };
  1396. static int tegra210_usb2_port_enable(struct tegra_xusb_port *port)
  1397. {
  1398. return 0;
  1399. }
  1400. static void tegra210_usb2_port_disable(struct tegra_xusb_port *port)
  1401. {
  1402. }
  1403. static struct tegra_xusb_lane *
  1404. tegra210_usb2_port_map(struct tegra_xusb_port *port)
  1405. {
  1406. return tegra_xusb_find_lane(port->padctl, "usb2", port->index);
  1407. }
  1408. static const struct tegra_xusb_port_ops tegra210_usb2_port_ops = {
  1409. .enable = tegra210_usb2_port_enable,
  1410. .disable = tegra210_usb2_port_disable,
  1411. .map = tegra210_usb2_port_map,
  1412. };
  1413. static int tegra210_hsic_port_enable(struct tegra_xusb_port *port)
  1414. {
  1415. return 0;
  1416. }
  1417. static void tegra210_hsic_port_disable(struct tegra_xusb_port *port)
  1418. {
  1419. }
  1420. static struct tegra_xusb_lane *
  1421. tegra210_hsic_port_map(struct tegra_xusb_port *port)
  1422. {
  1423. return tegra_xusb_find_lane(port->padctl, "hsic", port->index);
  1424. }
  1425. static const struct tegra_xusb_port_ops tegra210_hsic_port_ops = {
  1426. .enable = tegra210_hsic_port_enable,
  1427. .disable = tegra210_hsic_port_disable,
  1428. .map = tegra210_hsic_port_map,
  1429. };
  1430. static int tegra210_usb3_port_enable(struct tegra_xusb_port *port)
  1431. {
  1432. struct tegra_xusb_usb3_port *usb3 = to_usb3_port(port);
  1433. struct tegra_xusb_padctl *padctl = port->padctl;
  1434. struct tegra_xusb_lane *lane = usb3->base.lane;
  1435. unsigned int index = port->index;
  1436. u32 value;
  1437. int err;
  1438. value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_MAP);
  1439. if (!usb3->internal)
  1440. value &= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(index);
  1441. else
  1442. value |= XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(index);
  1443. value &= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(index);
  1444. value |= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(index, usb3->port);
  1445. padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_MAP);
  1446. /*
  1447. * TODO: move this code into the PCIe/SATA PHY ->power_on() callbacks
  1448. * and conditionalize based on mux function? This seems to work, but
  1449. * might not be the exact proper sequence.
  1450. */
  1451. err = regulator_enable(usb3->supply);
  1452. if (err < 0)
  1453. return err;
  1454. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(index));
  1455. value &= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_MASK <<
  1456. XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT);
  1457. value |= XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_VAL <<
  1458. XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT;
  1459. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(index));
  1460. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(index));
  1461. value &= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_MASK <<
  1462. XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT);
  1463. value |= XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_VAL <<
  1464. XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT;
  1465. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(index));
  1466. padctl_writel(padctl, XUSB_PADCTL_UPHY_USB3_PAD_ECTL3_RX_DFE_VAL,
  1467. XUSB_PADCTL_UPHY_USB3_PADX_ECTL3(index));
  1468. value = padctl_readl(padctl, XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(index));
  1469. value &= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_MASK <<
  1470. XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT);
  1471. value |= XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_VAL <<
  1472. XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT;
  1473. padctl_writel(padctl, value, XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(index));
  1474. padctl_writel(padctl, XUSB_PADCTL_UPHY_USB3_PAD_ECTL6_RX_EQ_CTRL_H_VAL,
  1475. XUSB_PADCTL_UPHY_USB3_PADX_ECTL6(index));
  1476. if (lane->pad == padctl->sata)
  1477. err = tegra210_sata_uphy_enable(padctl, true);
  1478. else
  1479. err = tegra210_pex_uphy_enable(padctl);
  1480. if (err) {
  1481. dev_err(&port->dev, "%s: failed to enable UPHY: %d\n",
  1482. __func__, err);
  1483. return err;
  1484. }
  1485. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  1486. value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(index);
  1487. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  1488. usleep_range(100, 200);
  1489. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  1490. value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(index);
  1491. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  1492. usleep_range(100, 200);
  1493. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  1494. value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(index);
  1495. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  1496. return 0;
  1497. }
  1498. static void tegra210_usb3_port_disable(struct tegra_xusb_port *port)
  1499. {
  1500. struct tegra_xusb_usb3_port *usb3 = to_usb3_port(port);
  1501. struct tegra_xusb_padctl *padctl = port->padctl;
  1502. struct tegra_xusb_lane *lane = port->lane;
  1503. unsigned int index = port->index;
  1504. u32 value;
  1505. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  1506. value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(index);
  1507. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  1508. usleep_range(100, 200);
  1509. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  1510. value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(index);
  1511. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  1512. usleep_range(250, 350);
  1513. value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1);
  1514. value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(index);
  1515. padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1);
  1516. if (lane->pad == padctl->sata)
  1517. tegra210_sata_uphy_disable(padctl);
  1518. else
  1519. tegra210_pex_uphy_disable(padctl);
  1520. regulator_disable(usb3->supply);
  1521. value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_MAP);
  1522. value &= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(index);
  1523. value |= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(index, 0x7);
  1524. padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_MAP);
  1525. }
  1526. static const struct tegra_xusb_lane_map tegra210_usb3_map[] = {
  1527. { 0, "pcie", 6 },
  1528. { 1, "pcie", 5 },
  1529. { 2, "pcie", 0 },
  1530. { 2, "pcie", 3 },
  1531. { 3, "pcie", 4 },
  1532. { 3, "pcie", 4 },
  1533. { 0, NULL, 0 }
  1534. };
  1535. static struct tegra_xusb_lane *
  1536. tegra210_usb3_port_map(struct tegra_xusb_port *port)
  1537. {
  1538. return tegra_xusb_port_find_lane(port, tegra210_usb3_map, "usb3-ss");
  1539. }
  1540. static const struct tegra_xusb_port_ops tegra210_usb3_port_ops = {
  1541. .enable = tegra210_usb3_port_enable,
  1542. .disable = tegra210_usb3_port_disable,
  1543. .map = tegra210_usb3_port_map,
  1544. };
  1545. static int
  1546. tegra210_xusb_read_fuse_calibration(struct tegra210_xusb_fuse_calibration *fuse)
  1547. {
  1548. unsigned int i;
  1549. u32 value;
  1550. int err;
  1551. err = tegra_fuse_readl(TEGRA_FUSE_SKU_CALIB_0, &value);
  1552. if (err < 0)
  1553. return err;
  1554. for (i = 0; i < ARRAY_SIZE(fuse->hs_curr_level); i++) {
  1555. fuse->hs_curr_level[i] =
  1556. (value >> FUSE_SKU_CALIB_HS_CURR_LEVEL_PADX_SHIFT(i)) &
  1557. FUSE_SKU_CALIB_HS_CURR_LEVEL_PAD_MASK;
  1558. }
  1559. fuse->hs_term_range_adj =
  1560. (value >> FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_SHIFT) &
  1561. FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_MASK;
  1562. err = tegra_fuse_readl(TEGRA_FUSE_USB_CALIB_EXT_0, &value);
  1563. if (err < 0)
  1564. return err;
  1565. fuse->rpd_ctrl =
  1566. (value >> FUSE_USB_CALIB_EXT_RPD_CTRL_SHIFT) &
  1567. FUSE_USB_CALIB_EXT_RPD_CTRL_MASK;
  1568. return 0;
  1569. }
  1570. static struct tegra_xusb_padctl *
  1571. tegra210_xusb_padctl_probe(struct device *dev,
  1572. const struct tegra_xusb_padctl_soc *soc)
  1573. {
  1574. struct tegra210_xusb_padctl *padctl;
  1575. int err;
  1576. padctl = devm_kzalloc(dev, sizeof(*padctl), GFP_KERNEL);
  1577. if (!padctl)
  1578. return ERR_PTR(-ENOMEM);
  1579. padctl->base.dev = dev;
  1580. padctl->base.soc = soc;
  1581. err = tegra210_xusb_read_fuse_calibration(&padctl->fuse);
  1582. if (err < 0)
  1583. return ERR_PTR(err);
  1584. return &padctl->base;
  1585. }
  1586. static void tegra210_xusb_padctl_remove(struct tegra_xusb_padctl *padctl)
  1587. {
  1588. }
  1589. static const struct tegra_xusb_padctl_ops tegra210_xusb_padctl_ops = {
  1590. .probe = tegra210_xusb_padctl_probe,
  1591. .remove = tegra210_xusb_padctl_remove,
  1592. .usb3_set_lfps_detect = tegra210_usb3_set_lfps_detect,
  1593. .hsic_set_idle = tegra210_hsic_set_idle,
  1594. };
  1595. const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc = {
  1596. .num_pads = ARRAY_SIZE(tegra210_pads),
  1597. .pads = tegra210_pads,
  1598. .ports = {
  1599. .usb2 = {
  1600. .ops = &tegra210_usb2_port_ops,
  1601. .count = 4,
  1602. },
  1603. .hsic = {
  1604. .ops = &tegra210_hsic_port_ops,
  1605. .count = 1,
  1606. },
  1607. .usb3 = {
  1608. .ops = &tegra210_usb3_port_ops,
  1609. .count = 4,
  1610. },
  1611. },
  1612. .ops = &tegra210_xusb_padctl_ops,
  1613. };
  1614. EXPORT_SYMBOL_GPL(tegra210_xusb_padctl_soc);
  1615. MODULE_AUTHOR("Andrew Bresticker <abrestic@chromium.org>");
  1616. MODULE_DESCRIPTION("NVIDIA Tegra 210 XUSB Pad Controller driver");
  1617. MODULE_LICENSE("GPL v2");