pmc.c 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * drivers/soc/tegra/pmc.c
  4. *
  5. * Copyright (c) 2010 Google, Inc
  6. * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
  7. *
  8. * Author:
  9. * Colin Cross <ccross@google.com>
  10. */
  11. #define pr_fmt(fmt) "tegra-pmc: " fmt
  12. #include <linux/arm-smccc.h>
  13. #include <linux/clk.h>
  14. #include <linux/clk-provider.h>
  15. #include <linux/clkdev.h>
  16. #include <linux/clk/clk-conf.h>
  17. #include <linux/clk/tegra.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/delay.h>
  20. #include <linux/device.h>
  21. #include <linux/err.h>
  22. #include <linux/export.h>
  23. #include <linux/init.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/io.h>
  26. #include <linux/iopoll.h>
  27. #include <linux/irqdomain.h>
  28. #include <linux/irq.h>
  29. #include <linux/kernel.h>
  30. #include <linux/of_address.h>
  31. #include <linux/of_clk.h>
  32. #include <linux/of.h>
  33. #include <linux/of_irq.h>
  34. #include <linux/of_platform.h>
  35. #include <linux/pinctrl/pinconf-generic.h>
  36. #include <linux/pinctrl/pinconf.h>
  37. #include <linux/pinctrl/pinctrl.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/pm_domain.h>
  40. #include <linux/pm_opp.h>
  41. #include <linux/power_supply.h>
  42. #include <linux/reboot.h>
  43. #include <linux/regmap.h>
  44. #include <linux/reset.h>
  45. #include <linux/seq_file.h>
  46. #include <linux/slab.h>
  47. #include <linux/spinlock.h>
  48. #include <linux/syscore_ops.h>
  49. #include <soc/tegra/common.h>
  50. #include <soc/tegra/fuse.h>
  51. #include <soc/tegra/pmc.h>
  52. #include <dt-bindings/interrupt-controller/arm-gic.h>
  53. #include <dt-bindings/pinctrl/pinctrl-tegra-io-pad.h>
  54. #include <dt-bindings/gpio/tegra186-gpio.h>
  55. #include <dt-bindings/gpio/tegra194-gpio.h>
  56. #include <dt-bindings/gpio/tegra234-gpio.h>
  57. #include <dt-bindings/soc/tegra-pmc.h>
  58. #define PMC_CNTRL 0x0
  59. #define PMC_CNTRL_INTR_POLARITY BIT(17) /* inverts INTR polarity */
  60. #define PMC_CNTRL_CPU_PWRREQ_OE BIT(16) /* CPU pwr req enable */
  61. #define PMC_CNTRL_CPU_PWRREQ_POLARITY BIT(15) /* CPU pwr req polarity */
  62. #define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) /* LP0 when CPU pwr gated */
  63. #define PMC_CNTRL_SYSCLK_OE BIT(11) /* system clock enable */
  64. #define PMC_CNTRL_SYSCLK_POLARITY BIT(10) /* sys clk polarity */
  65. #define PMC_CNTRL_PWRREQ_POLARITY BIT(8)
  66. #define PMC_CNTRL_BLINK_EN 7
  67. #define PMC_CNTRL_MAIN_RST BIT(4)
  68. #define PMC_WAKE_MASK 0x0c
  69. #define PMC_WAKE_LEVEL 0x10
  70. #define PMC_WAKE_STATUS 0x14
  71. #define PMC_SW_WAKE_STATUS 0x18
  72. #define PMC_DPD_PADS_ORIDE 0x1c
  73. #define PMC_DPD_PADS_ORIDE_BLINK 20
  74. #define DPD_SAMPLE 0x020
  75. #define DPD_SAMPLE_ENABLE BIT(0)
  76. #define DPD_SAMPLE_DISABLE (0 << 0)
  77. #define PWRGATE_TOGGLE 0x30
  78. #define PWRGATE_TOGGLE_START BIT(8)
  79. #define REMOVE_CLAMPING 0x34
  80. #define PWRGATE_STATUS 0x38
  81. #define PMC_BLINK_TIMER 0x40
  82. #define PMC_IMPL_E_33V_PWR 0x40
  83. #define PMC_PWR_DET 0x48
  84. #define PMC_SCRATCH0_MODE_RECOVERY BIT(31)
  85. #define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30)
  86. #define PMC_SCRATCH0_MODE_RCM BIT(1)
  87. #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
  88. PMC_SCRATCH0_MODE_BOOTLOADER | \
  89. PMC_SCRATCH0_MODE_RCM)
  90. #define PMC_CPUPWRGOOD_TIMER 0xc8
  91. #define PMC_CPUPWROFF_TIMER 0xcc
  92. #define PMC_COREPWRGOOD_TIMER 0x3c
  93. #define PMC_COREPWROFF_TIMER 0xe0
  94. #define PMC_PWR_DET_VALUE 0xe4
  95. #define PMC_USB_DEBOUNCE_DEL 0xec
  96. #define PMC_USB_AO 0xf0
  97. #define PMC_SCRATCH37 0x130
  98. #define PMC_SCRATCH41 0x140
  99. #define PMC_WAKE2_MASK 0x160
  100. #define PMC_WAKE2_LEVEL 0x164
  101. #define PMC_WAKE2_STATUS 0x168
  102. #define PMC_SW_WAKE2_STATUS 0x16c
  103. #define PMC_CLK_OUT_CNTRL 0x1a8
  104. #define PMC_CLK_OUT_MUX_MASK GENMASK(1, 0)
  105. #define PMC_SENSOR_CTRL 0x1b0
  106. #define PMC_SENSOR_CTRL_SCRATCH_WRITE BIT(2)
  107. #define PMC_SENSOR_CTRL_ENABLE_RST BIT(1)
  108. #define PMC_RST_STATUS_POR 0
  109. #define PMC_RST_STATUS_WATCHDOG 1
  110. #define PMC_RST_STATUS_SENSOR 2
  111. #define PMC_RST_STATUS_SW_MAIN 3
  112. #define PMC_RST_STATUS_LP0 4
  113. #define PMC_RST_STATUS_AOTAG 5
  114. #define IO_DPD_REQ 0x1b8
  115. #define IO_DPD_REQ_CODE_IDLE (0U << 30)
  116. #define IO_DPD_REQ_CODE_OFF (1U << 30)
  117. #define IO_DPD_REQ_CODE_ON (2U << 30)
  118. #define IO_DPD_REQ_CODE_MASK (3U << 30)
  119. #define IO_DPD_STATUS 0x1bc
  120. #define IO_DPD2_REQ 0x1c0
  121. #define IO_DPD2_STATUS 0x1c4
  122. #define SEL_DPD_TIM 0x1c8
  123. #define PMC_UTMIP_UHSIC_TRIGGERS 0x1ec
  124. #define PMC_UTMIP_UHSIC_SAVED_STATE 0x1f0
  125. #define PMC_UTMIP_TERM_PAD_CFG 0x1f8
  126. #define PMC_UTMIP_UHSIC_SLEEP_CFG 0x1fc
  127. #define PMC_UTMIP_UHSIC_FAKE 0x218
  128. #define PMC_SCRATCH54 0x258
  129. #define PMC_SCRATCH54_DATA_SHIFT 8
  130. #define PMC_SCRATCH54_ADDR_SHIFT 0
  131. #define PMC_SCRATCH55 0x25c
  132. #define PMC_SCRATCH55_RESET_TEGRA BIT(31)
  133. #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
  134. #define PMC_SCRATCH55_PINMUX_SHIFT 24
  135. #define PMC_SCRATCH55_16BITOP BIT(15)
  136. #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
  137. #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
  138. #define PMC_UTMIP_UHSIC_LINE_WAKEUP 0x26c
  139. #define PMC_UTMIP_BIAS_MASTER_CNTRL 0x270
  140. #define PMC_UTMIP_MASTER_CONFIG 0x274
  141. #define PMC_UTMIP_UHSIC2_TRIGGERS 0x27c
  142. #define PMC_UTMIP_MASTER2_CONFIG 0x29c
  143. #define GPU_RG_CNTRL 0x2d4
  144. #define PMC_UTMIP_PAD_CFG0 0x4c0
  145. #define PMC_UTMIP_UHSIC_SLEEP_CFG1 0x4d0
  146. #define PMC_UTMIP_SLEEPWALK_P3 0x4e0
  147. /* Tegra186 and later */
  148. #define WAKE_AOWAKE_CNTRL(x) (0x000 + ((x) << 2))
  149. #define WAKE_AOWAKE_CNTRL_LEVEL (1 << 3)
  150. #define WAKE_AOWAKE_CNTRL_SR_CAPTURE_EN (1 << 1)
  151. #define WAKE_AOWAKE_MASK_W(x) (0x180 + ((x) << 2))
  152. #define WAKE_AOWAKE_MASK_R(x) (0x300 + ((x) << 2))
  153. #define WAKE_AOWAKE_STATUS_W(x) (0x30c + ((x) << 2))
  154. #define WAKE_AOWAKE_STATUS_R(x) (0x48c + ((x) << 2))
  155. #define WAKE_AOWAKE_TIER0_ROUTING(x) (0x4b4 + ((x) << 2))
  156. #define WAKE_AOWAKE_TIER1_ROUTING(x) (0x4c0 + ((x) << 2))
  157. #define WAKE_AOWAKE_TIER2_ROUTING(x) (0x4cc + ((x) << 2))
  158. #define WAKE_AOWAKE_SW_STATUS_W_0 0x49c
  159. #define WAKE_AOWAKE_SW_STATUS(x) (0x4a0 + ((x) << 2))
  160. #define WAKE_LATCH_SW 0x498
  161. #define WAKE_AOWAKE_CTRL 0x4f4
  162. #define WAKE_AOWAKE_CTRL_INTR_POLARITY BIT(0)
  163. #define SW_WAKE_ID 83 /* wake83 */
  164. /* for secure PMC */
  165. #define TEGRA_SMC_PMC 0xc2fffe00
  166. #define TEGRA_SMC_PMC_READ 0xaa
  167. #define TEGRA_SMC_PMC_WRITE 0xbb
  168. struct pmc_clk {
  169. struct clk_hw hw;
  170. unsigned long offs;
  171. u32 mux_shift;
  172. u32 force_en_shift;
  173. };
  174. #define to_pmc_clk(_hw) container_of(_hw, struct pmc_clk, hw)
  175. struct pmc_clk_gate {
  176. struct clk_hw hw;
  177. unsigned long offs;
  178. u32 shift;
  179. };
  180. #define to_pmc_clk_gate(_hw) container_of(_hw, struct pmc_clk_gate, hw)
  181. struct pmc_clk_init_data {
  182. char *name;
  183. const char *const *parents;
  184. int num_parents;
  185. int clk_id;
  186. u8 mux_shift;
  187. u8 force_en_shift;
  188. };
  189. static const char * const clk_out1_parents[] = { "osc", "osc_div2",
  190. "osc_div4", "extern1",
  191. };
  192. static const char * const clk_out2_parents[] = { "osc", "osc_div2",
  193. "osc_div4", "extern2",
  194. };
  195. static const char * const clk_out3_parents[] = { "osc", "osc_div2",
  196. "osc_div4", "extern3",
  197. };
  198. static const struct pmc_clk_init_data tegra_pmc_clks_data[] = {
  199. {
  200. .name = "pmc_clk_out_1",
  201. .parents = clk_out1_parents,
  202. .num_parents = ARRAY_SIZE(clk_out1_parents),
  203. .clk_id = TEGRA_PMC_CLK_OUT_1,
  204. .mux_shift = 6,
  205. .force_en_shift = 2,
  206. },
  207. {
  208. .name = "pmc_clk_out_2",
  209. .parents = clk_out2_parents,
  210. .num_parents = ARRAY_SIZE(clk_out2_parents),
  211. .clk_id = TEGRA_PMC_CLK_OUT_2,
  212. .mux_shift = 14,
  213. .force_en_shift = 10,
  214. },
  215. {
  216. .name = "pmc_clk_out_3",
  217. .parents = clk_out3_parents,
  218. .num_parents = ARRAY_SIZE(clk_out3_parents),
  219. .clk_id = TEGRA_PMC_CLK_OUT_3,
  220. .mux_shift = 22,
  221. .force_en_shift = 18,
  222. },
  223. };
  224. struct tegra_powergate {
  225. struct generic_pm_domain genpd;
  226. struct tegra_pmc *pmc;
  227. unsigned int id;
  228. struct clk **clks;
  229. unsigned int num_clks;
  230. unsigned long *clk_rates;
  231. struct reset_control *reset;
  232. };
  233. struct tegra_io_pad_soc {
  234. enum tegra_io_pad id;
  235. unsigned int dpd;
  236. unsigned int request;
  237. unsigned int status;
  238. unsigned int voltage;
  239. const char *name;
  240. };
  241. struct tegra_pmc_regs {
  242. unsigned int scratch0;
  243. unsigned int rst_status;
  244. unsigned int rst_source_shift;
  245. unsigned int rst_source_mask;
  246. unsigned int rst_level_shift;
  247. unsigned int rst_level_mask;
  248. };
  249. struct tegra_wake_event {
  250. const char *name;
  251. unsigned int id;
  252. unsigned int irq;
  253. struct {
  254. unsigned int instance;
  255. unsigned int pin;
  256. } gpio;
  257. };
  258. #define TEGRA_WAKE_SIMPLE(_name, _id) \
  259. { \
  260. .name = _name, \
  261. .id = _id, \
  262. .irq = 0, \
  263. .gpio = { \
  264. .instance = UINT_MAX, \
  265. .pin = UINT_MAX, \
  266. }, \
  267. }
  268. #define TEGRA_WAKE_IRQ(_name, _id, _irq) \
  269. { \
  270. .name = _name, \
  271. .id = _id, \
  272. .irq = _irq, \
  273. .gpio = { \
  274. .instance = UINT_MAX, \
  275. .pin = UINT_MAX, \
  276. }, \
  277. }
  278. #define TEGRA_WAKE_GPIO(_name, _id, _instance, _pin) \
  279. { \
  280. .name = _name, \
  281. .id = _id, \
  282. .irq = 0, \
  283. .gpio = { \
  284. .instance = _instance, \
  285. .pin = _pin, \
  286. }, \
  287. }
  288. struct tegra_pmc_soc {
  289. unsigned int num_powergates;
  290. const char *const *powergates;
  291. unsigned int num_cpu_powergates;
  292. const u8 *cpu_powergates;
  293. bool has_tsense_reset;
  294. bool has_gpu_clamps;
  295. bool needs_mbist_war;
  296. bool has_impl_33v_pwr;
  297. bool maybe_tz_only;
  298. const struct tegra_io_pad_soc *io_pads;
  299. unsigned int num_io_pads;
  300. const struct pinctrl_pin_desc *pin_descs;
  301. unsigned int num_pin_descs;
  302. const struct tegra_pmc_regs *regs;
  303. void (*init)(struct tegra_pmc *pmc);
  304. void (*setup_irq_polarity)(struct tegra_pmc *pmc,
  305. struct device_node *np,
  306. bool invert);
  307. void (*set_wake_filters)(struct tegra_pmc *pmc);
  308. int (*irq_set_wake)(struct irq_data *data, unsigned int on);
  309. int (*irq_set_type)(struct irq_data *data, unsigned int type);
  310. int (*powergate_set)(struct tegra_pmc *pmc, unsigned int id,
  311. bool new_state);
  312. const char * const *reset_sources;
  313. unsigned int num_reset_sources;
  314. const char * const *reset_levels;
  315. unsigned int num_reset_levels;
  316. /*
  317. * These describe events that can wake the system from sleep (i.e.
  318. * LP0 or SC7). Wakeup from other sleep states (such as LP1 or LP2)
  319. * are dealt with in the LIC.
  320. */
  321. const struct tegra_wake_event *wake_events;
  322. unsigned int num_wake_events;
  323. unsigned int max_wake_events;
  324. unsigned int max_wake_vectors;
  325. const struct pmc_clk_init_data *pmc_clks_data;
  326. unsigned int num_pmc_clks;
  327. bool has_blink_output;
  328. bool has_usb_sleepwalk;
  329. bool supports_core_domain;
  330. bool has_single_mmio_aperture;
  331. };
  332. /**
  333. * struct tegra_pmc - NVIDIA Tegra PMC
  334. * @dev: pointer to PMC device structure
  335. * @base: pointer to I/O remapped register region
  336. * @wake: pointer to I/O remapped region for WAKE registers
  337. * @aotag: pointer to I/O remapped region for AOTAG registers
  338. * @scratch: pointer to I/O remapped region for scratch registers
  339. * @clk: pointer to pclk clock
  340. * @soc: pointer to SoC data structure
  341. * @tz_only: flag specifying if the PMC can only be accessed via TrustZone
  342. * @rate: currently configured rate of pclk
  343. * @suspend_mode: lowest suspend mode available
  344. * @cpu_good_time: CPU power good time (in microseconds)
  345. * @cpu_off_time: CPU power off time (in microsecends)
  346. * @core_osc_time: core power good OSC time (in microseconds)
  347. * @core_pmu_time: core power good PMU time (in microseconds)
  348. * @core_off_time: core power off time (in microseconds)
  349. * @corereq_high: core power request is active-high
  350. * @sysclkreq_high: system clock request is active-high
  351. * @combined_req: combined power request for CPU & core
  352. * @cpu_pwr_good_en: CPU power good signal is enabled
  353. * @lp0_vec_phys: physical base address of the LP0 warm boot code
  354. * @lp0_vec_size: size of the LP0 warm boot code
  355. * @powergates_available: Bitmap of available power gates
  356. * @powergates_lock: mutex for power gate register access
  357. * @pctl_dev: pin controller exposed by the PMC
  358. * @domain: IRQ domain provided by the PMC
  359. * @irq: chip implementation for the IRQ domain
  360. * @clk_nb: pclk clock changes handler
  361. * @core_domain_state_synced: flag marking the core domain's state as synced
  362. * @core_domain_registered: flag marking the core domain as registered
  363. * @wake_type_level_map: Bitmap indicating level type for non-dual edge wakes
  364. * @wake_type_dual_edge_map: Bitmap indicating if a wake is dual-edge or not
  365. * @wake_sw_status_map: Bitmap to hold raw status of wakes without mask
  366. * @wake_cntrl_level_map: Bitmap to hold wake levels to be programmed in
  367. * cntrl register associated with each wake during system suspend.
  368. */
  369. struct tegra_pmc {
  370. struct device *dev;
  371. void __iomem *base;
  372. void __iomem *wake;
  373. void __iomem *aotag;
  374. void __iomem *scratch;
  375. struct clk *clk;
  376. const struct tegra_pmc_soc *soc;
  377. bool tz_only;
  378. unsigned long rate;
  379. enum tegra_suspend_mode suspend_mode;
  380. u32 cpu_good_time;
  381. u32 cpu_off_time;
  382. u32 core_osc_time;
  383. u32 core_pmu_time;
  384. u32 core_off_time;
  385. bool corereq_high;
  386. bool sysclkreq_high;
  387. bool combined_req;
  388. bool cpu_pwr_good_en;
  389. u32 lp0_vec_phys;
  390. u32 lp0_vec_size;
  391. DECLARE_BITMAP(powergates_available, TEGRA_POWERGATE_MAX);
  392. struct mutex powergates_lock;
  393. struct pinctrl_dev *pctl_dev;
  394. struct irq_domain *domain;
  395. struct irq_chip irq;
  396. struct notifier_block clk_nb;
  397. bool core_domain_state_synced;
  398. bool core_domain_registered;
  399. unsigned long *wake_type_level_map;
  400. unsigned long *wake_type_dual_edge_map;
  401. unsigned long *wake_sw_status_map;
  402. unsigned long *wake_cntrl_level_map;
  403. struct syscore_ops syscore;
  404. };
  405. static struct tegra_pmc *pmc = &(struct tegra_pmc) {
  406. .base = NULL,
  407. .suspend_mode = TEGRA_SUSPEND_NOT_READY,
  408. };
  409. static inline struct tegra_powergate *
  410. to_powergate(struct generic_pm_domain *domain)
  411. {
  412. return container_of(domain, struct tegra_powergate, genpd);
  413. }
  414. static u32 tegra_pmc_readl(struct tegra_pmc *pmc, unsigned long offset)
  415. {
  416. struct arm_smccc_res res;
  417. if (pmc->tz_only) {
  418. arm_smccc_smc(TEGRA_SMC_PMC, TEGRA_SMC_PMC_READ, offset, 0, 0,
  419. 0, 0, 0, &res);
  420. if (res.a0) {
  421. if (pmc->dev)
  422. dev_warn(pmc->dev, "%s(): SMC failed: %lu\n",
  423. __func__, res.a0);
  424. else
  425. pr_warn("%s(): SMC failed: %lu\n", __func__,
  426. res.a0);
  427. }
  428. return res.a1;
  429. }
  430. return readl(pmc->base + offset);
  431. }
  432. static void tegra_pmc_writel(struct tegra_pmc *pmc, u32 value,
  433. unsigned long offset)
  434. {
  435. struct arm_smccc_res res;
  436. if (pmc->tz_only) {
  437. arm_smccc_smc(TEGRA_SMC_PMC, TEGRA_SMC_PMC_WRITE, offset,
  438. value, 0, 0, 0, 0, &res);
  439. if (res.a0) {
  440. if (pmc->dev)
  441. dev_warn(pmc->dev, "%s(): SMC failed: %lu\n",
  442. __func__, res.a0);
  443. else
  444. pr_warn("%s(): SMC failed: %lu\n", __func__,
  445. res.a0);
  446. }
  447. } else {
  448. writel(value, pmc->base + offset);
  449. }
  450. }
  451. static u32 tegra_pmc_scratch_readl(struct tegra_pmc *pmc, unsigned long offset)
  452. {
  453. if (pmc->tz_only)
  454. return tegra_pmc_readl(pmc, offset);
  455. return readl(pmc->scratch + offset);
  456. }
  457. static void tegra_pmc_scratch_writel(struct tegra_pmc *pmc, u32 value,
  458. unsigned long offset)
  459. {
  460. if (pmc->tz_only)
  461. tegra_pmc_writel(pmc, value, offset);
  462. else
  463. writel(value, pmc->scratch + offset);
  464. }
  465. /*
  466. * TODO Figure out a way to call this with the struct tegra_pmc * passed in.
  467. * This currently doesn't work because readx_poll_timeout() can only operate
  468. * on functions that take a single argument.
  469. */
  470. static inline bool tegra_powergate_state(int id)
  471. {
  472. if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps)
  473. return (tegra_pmc_readl(pmc, GPU_RG_CNTRL) & 0x1) == 0;
  474. else
  475. return (tegra_pmc_readl(pmc, PWRGATE_STATUS) & BIT(id)) != 0;
  476. }
  477. static inline bool tegra_powergate_is_valid(struct tegra_pmc *pmc, int id)
  478. {
  479. return (pmc->soc && pmc->soc->powergates[id]);
  480. }
  481. static inline bool tegra_powergate_is_available(struct tegra_pmc *pmc, int id)
  482. {
  483. return test_bit(id, pmc->powergates_available);
  484. }
  485. static int tegra_powergate_lookup(struct tegra_pmc *pmc, const char *name)
  486. {
  487. unsigned int i;
  488. if (!pmc || !pmc->soc || !name)
  489. return -EINVAL;
  490. for (i = 0; i < pmc->soc->num_powergates; i++) {
  491. if (!tegra_powergate_is_valid(pmc, i))
  492. continue;
  493. if (!strcmp(name, pmc->soc->powergates[i]))
  494. return i;
  495. }
  496. return -ENODEV;
  497. }
  498. static int tegra20_powergate_set(struct tegra_pmc *pmc, unsigned int id,
  499. bool new_state)
  500. {
  501. unsigned int retries = 100;
  502. bool status;
  503. int ret;
  504. /*
  505. * As per TRM documentation, the toggle command will be dropped by PMC
  506. * if there is contention with a HW-initiated toggling (i.e. CPU core
  507. * power-gated), the command should be retried in that case.
  508. */
  509. do {
  510. tegra_pmc_writel(pmc, PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE);
  511. /* wait for PMC to execute the command */
  512. ret = readx_poll_timeout(tegra_powergate_state, id, status,
  513. status == new_state, 1, 10);
  514. } while (ret == -ETIMEDOUT && retries--);
  515. return ret;
  516. }
  517. static inline bool tegra_powergate_toggle_ready(struct tegra_pmc *pmc)
  518. {
  519. return !(tegra_pmc_readl(pmc, PWRGATE_TOGGLE) & PWRGATE_TOGGLE_START);
  520. }
  521. static int tegra114_powergate_set(struct tegra_pmc *pmc, unsigned int id,
  522. bool new_state)
  523. {
  524. bool status;
  525. int err;
  526. /* wait while PMC power gating is contended */
  527. err = readx_poll_timeout(tegra_powergate_toggle_ready, pmc, status,
  528. status == true, 1, 100);
  529. if (err)
  530. return err;
  531. tegra_pmc_writel(pmc, PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE);
  532. /* wait for PMC to accept the command */
  533. err = readx_poll_timeout(tegra_powergate_toggle_ready, pmc, status,
  534. status == true, 1, 100);
  535. if (err)
  536. return err;
  537. /* wait for PMC to execute the command */
  538. err = readx_poll_timeout(tegra_powergate_state, id, status,
  539. status == new_state, 10, 100000);
  540. if (err)
  541. return err;
  542. return 0;
  543. }
  544. /**
  545. * tegra_powergate_set() - set the state of a partition
  546. * @pmc: power management controller
  547. * @id: partition ID
  548. * @new_state: new state of the partition
  549. */
  550. static int tegra_powergate_set(struct tegra_pmc *pmc, unsigned int id,
  551. bool new_state)
  552. {
  553. int err;
  554. if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps)
  555. return -EINVAL;
  556. mutex_lock(&pmc->powergates_lock);
  557. if (tegra_powergate_state(id) == new_state) {
  558. mutex_unlock(&pmc->powergates_lock);
  559. return 0;
  560. }
  561. err = pmc->soc->powergate_set(pmc, id, new_state);
  562. mutex_unlock(&pmc->powergates_lock);
  563. return err;
  564. }
  565. static int __tegra_powergate_remove_clamping(struct tegra_pmc *pmc,
  566. unsigned int id)
  567. {
  568. u32 mask;
  569. mutex_lock(&pmc->powergates_lock);
  570. /*
  571. * On Tegra124 and later, the clamps for the GPU are controlled by a
  572. * separate register (with different semantics).
  573. */
  574. if (id == TEGRA_POWERGATE_3D) {
  575. if (pmc->soc->has_gpu_clamps) {
  576. tegra_pmc_writel(pmc, 0, GPU_RG_CNTRL);
  577. goto out;
  578. }
  579. }
  580. /*
  581. * Tegra 2 has a bug where PCIE and VDE clamping masks are
  582. * swapped relatively to the partition ids
  583. */
  584. if (id == TEGRA_POWERGATE_VDEC)
  585. mask = (1 << TEGRA_POWERGATE_PCIE);
  586. else if (id == TEGRA_POWERGATE_PCIE)
  587. mask = (1 << TEGRA_POWERGATE_VDEC);
  588. else
  589. mask = (1 << id);
  590. tegra_pmc_writel(pmc, mask, REMOVE_CLAMPING);
  591. out:
  592. mutex_unlock(&pmc->powergates_lock);
  593. return 0;
  594. }
  595. static int tegra_powergate_prepare_clocks(struct tegra_powergate *pg)
  596. {
  597. unsigned long safe_rate = 100 * 1000 * 1000;
  598. unsigned int i;
  599. int err;
  600. for (i = 0; i < pg->num_clks; i++) {
  601. pg->clk_rates[i] = clk_get_rate(pg->clks[i]);
  602. if (!pg->clk_rates[i]) {
  603. err = -EINVAL;
  604. goto out;
  605. }
  606. if (pg->clk_rates[i] <= safe_rate)
  607. continue;
  608. /*
  609. * We don't know whether voltage state is okay for the
  610. * current clock rate, hence it's better to temporally
  611. * switch clock to a safe rate which is suitable for
  612. * all voltages, before enabling the clock.
  613. */
  614. err = clk_set_rate(pg->clks[i], safe_rate);
  615. if (err)
  616. goto out;
  617. }
  618. return 0;
  619. out:
  620. while (i--)
  621. clk_set_rate(pg->clks[i], pg->clk_rates[i]);
  622. return err;
  623. }
  624. static int tegra_powergate_unprepare_clocks(struct tegra_powergate *pg)
  625. {
  626. unsigned int i;
  627. int err;
  628. for (i = 0; i < pg->num_clks; i++) {
  629. err = clk_set_rate(pg->clks[i], pg->clk_rates[i]);
  630. if (err)
  631. return err;
  632. }
  633. return 0;
  634. }
  635. static void tegra_powergate_disable_clocks(struct tegra_powergate *pg)
  636. {
  637. unsigned int i;
  638. for (i = 0; i < pg->num_clks; i++)
  639. clk_disable_unprepare(pg->clks[i]);
  640. }
  641. static int tegra_powergate_enable_clocks(struct tegra_powergate *pg)
  642. {
  643. unsigned int i;
  644. int err;
  645. for (i = 0; i < pg->num_clks; i++) {
  646. err = clk_prepare_enable(pg->clks[i]);
  647. if (err)
  648. goto out;
  649. }
  650. return 0;
  651. out:
  652. while (i--)
  653. clk_disable_unprepare(pg->clks[i]);
  654. return err;
  655. }
  656. static int tegra_powergate_power_up(struct tegra_powergate *pg,
  657. bool disable_clocks)
  658. {
  659. int err;
  660. err = reset_control_assert(pg->reset);
  661. if (err)
  662. return err;
  663. usleep_range(10, 20);
  664. err = tegra_powergate_set(pg->pmc, pg->id, true);
  665. if (err < 0)
  666. return err;
  667. usleep_range(10, 20);
  668. err = tegra_powergate_prepare_clocks(pg);
  669. if (err)
  670. goto powergate_off;
  671. err = tegra_powergate_enable_clocks(pg);
  672. if (err)
  673. goto unprepare_clks;
  674. usleep_range(10, 20);
  675. err = __tegra_powergate_remove_clamping(pg->pmc, pg->id);
  676. if (err)
  677. goto disable_clks;
  678. usleep_range(10, 20);
  679. err = reset_control_deassert(pg->reset);
  680. if (err)
  681. goto disable_clks;
  682. usleep_range(10, 20);
  683. if (pg->pmc->soc->needs_mbist_war)
  684. err = tegra210_clk_handle_mbist_war(pg->id);
  685. if (err)
  686. goto disable_clks;
  687. if (disable_clocks)
  688. tegra_powergate_disable_clocks(pg);
  689. err = tegra_powergate_unprepare_clocks(pg);
  690. if (err)
  691. return err;
  692. return 0;
  693. disable_clks:
  694. tegra_powergate_disable_clocks(pg);
  695. usleep_range(10, 20);
  696. unprepare_clks:
  697. tegra_powergate_unprepare_clocks(pg);
  698. powergate_off:
  699. tegra_powergate_set(pg->pmc, pg->id, false);
  700. return err;
  701. }
  702. static int tegra_powergate_power_down(struct tegra_powergate *pg)
  703. {
  704. int err;
  705. err = tegra_powergate_prepare_clocks(pg);
  706. if (err)
  707. return err;
  708. err = tegra_powergate_enable_clocks(pg);
  709. if (err)
  710. goto unprepare_clks;
  711. usleep_range(10, 20);
  712. err = reset_control_assert(pg->reset);
  713. if (err)
  714. goto disable_clks;
  715. usleep_range(10, 20);
  716. tegra_powergate_disable_clocks(pg);
  717. usleep_range(10, 20);
  718. err = tegra_powergate_set(pg->pmc, pg->id, false);
  719. if (err)
  720. goto assert_resets;
  721. err = tegra_powergate_unprepare_clocks(pg);
  722. if (err)
  723. return err;
  724. return 0;
  725. assert_resets:
  726. tegra_powergate_enable_clocks(pg);
  727. usleep_range(10, 20);
  728. reset_control_deassert(pg->reset);
  729. usleep_range(10, 20);
  730. disable_clks:
  731. tegra_powergate_disable_clocks(pg);
  732. unprepare_clks:
  733. tegra_powergate_unprepare_clocks(pg);
  734. return err;
  735. }
  736. static int tegra_genpd_power_on(struct generic_pm_domain *domain)
  737. {
  738. struct tegra_powergate *pg = to_powergate(domain);
  739. struct device *dev = pg->pmc->dev;
  740. int err;
  741. err = tegra_powergate_power_up(pg, true);
  742. if (err) {
  743. dev_err(dev, "failed to turn on PM domain %s: %d\n",
  744. pg->genpd.name, err);
  745. goto out;
  746. }
  747. reset_control_release(pg->reset);
  748. out:
  749. return err;
  750. }
  751. static int tegra_genpd_power_off(struct generic_pm_domain *domain)
  752. {
  753. struct tegra_powergate *pg = to_powergate(domain);
  754. struct device *dev = pg->pmc->dev;
  755. int err;
  756. err = reset_control_acquire(pg->reset);
  757. if (err < 0) {
  758. dev_err(dev, "failed to acquire resets for PM domain %s: %d\n",
  759. pg->genpd.name, err);
  760. return err;
  761. }
  762. err = tegra_powergate_power_down(pg);
  763. if (err) {
  764. dev_err(dev, "failed to turn off PM domain %s: %d\n",
  765. pg->genpd.name, err);
  766. reset_control_release(pg->reset);
  767. }
  768. return err;
  769. }
  770. /**
  771. * tegra_powergate_power_on() - power on partition
  772. * @id: partition ID
  773. */
  774. int tegra_powergate_power_on(unsigned int id)
  775. {
  776. if (!tegra_powergate_is_available(pmc, id))
  777. return -EINVAL;
  778. return tegra_powergate_set(pmc, id, true);
  779. }
  780. EXPORT_SYMBOL(tegra_powergate_power_on);
  781. /**
  782. * tegra_powergate_power_off() - power off partition
  783. * @id: partition ID
  784. */
  785. int tegra_powergate_power_off(unsigned int id)
  786. {
  787. if (!tegra_powergate_is_available(pmc, id))
  788. return -EINVAL;
  789. return tegra_powergate_set(pmc, id, false);
  790. }
  791. EXPORT_SYMBOL(tegra_powergate_power_off);
  792. /**
  793. * tegra_powergate_is_powered() - check if partition is powered
  794. * @pmc: power management controller
  795. * @id: partition ID
  796. */
  797. static int tegra_powergate_is_powered(struct tegra_pmc *pmc, unsigned int id)
  798. {
  799. if (!tegra_powergate_is_valid(pmc, id))
  800. return -EINVAL;
  801. return tegra_powergate_state(id);
  802. }
  803. /**
  804. * tegra_powergate_remove_clamping() - remove power clamps for partition
  805. * @id: partition ID
  806. */
  807. int tegra_powergate_remove_clamping(unsigned int id)
  808. {
  809. if (!tegra_powergate_is_available(pmc, id))
  810. return -EINVAL;
  811. return __tegra_powergate_remove_clamping(pmc, id);
  812. }
  813. EXPORT_SYMBOL(tegra_powergate_remove_clamping);
  814. /**
  815. * tegra_powergate_sequence_power_up() - power up partition
  816. * @id: partition ID
  817. * @clk: clock for partition
  818. * @rst: reset for partition
  819. *
  820. * Must be called with clk disabled, and returns with clk enabled.
  821. */
  822. int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk,
  823. struct reset_control *rst)
  824. {
  825. struct tegra_powergate *pg;
  826. int err;
  827. if (!tegra_powergate_is_available(pmc, id))
  828. return -EINVAL;
  829. pg = kzalloc(sizeof(*pg), GFP_KERNEL);
  830. if (!pg)
  831. return -ENOMEM;
  832. pg->clk_rates = kzalloc(sizeof(*pg->clk_rates), GFP_KERNEL);
  833. if (!pg->clk_rates) {
  834. kfree(pg->clks);
  835. return -ENOMEM;
  836. }
  837. pg->id = id;
  838. pg->clks = &clk;
  839. pg->num_clks = 1;
  840. pg->reset = rst;
  841. pg->pmc = pmc;
  842. err = tegra_powergate_power_up(pg, false);
  843. if (err)
  844. dev_err(pmc->dev, "failed to turn on partition %d: %d\n", id,
  845. err);
  846. kfree(pg->clk_rates);
  847. kfree(pg);
  848. return err;
  849. }
  850. EXPORT_SYMBOL(tegra_powergate_sequence_power_up);
  851. /**
  852. * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
  853. * @pmc: power management controller
  854. * @cpuid: CPU partition ID
  855. *
  856. * Returns the partition ID corresponding to the CPU partition ID or a
  857. * negative error code on failure.
  858. */
  859. static int tegra_get_cpu_powergate_id(struct tegra_pmc *pmc,
  860. unsigned int cpuid)
  861. {
  862. if (pmc->soc && cpuid < pmc->soc->num_cpu_powergates)
  863. return pmc->soc->cpu_powergates[cpuid];
  864. return -EINVAL;
  865. }
  866. /**
  867. * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
  868. * @cpuid: CPU partition ID
  869. */
  870. bool tegra_pmc_cpu_is_powered(unsigned int cpuid)
  871. {
  872. int id;
  873. id = tegra_get_cpu_powergate_id(pmc, cpuid);
  874. if (id < 0)
  875. return false;
  876. return tegra_powergate_is_powered(pmc, id);
  877. }
  878. /**
  879. * tegra_pmc_cpu_power_on() - power on CPU partition
  880. * @cpuid: CPU partition ID
  881. */
  882. int tegra_pmc_cpu_power_on(unsigned int cpuid)
  883. {
  884. int id;
  885. id = tegra_get_cpu_powergate_id(pmc, cpuid);
  886. if (id < 0)
  887. return id;
  888. return tegra_powergate_set(pmc, id, true);
  889. }
  890. /**
  891. * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
  892. * @cpuid: CPU partition ID
  893. */
  894. int tegra_pmc_cpu_remove_clamping(unsigned int cpuid)
  895. {
  896. int id;
  897. id = tegra_get_cpu_powergate_id(pmc, cpuid);
  898. if (id < 0)
  899. return id;
  900. return tegra_powergate_remove_clamping(id);
  901. }
  902. static void tegra_pmc_program_reboot_reason(const char *cmd)
  903. {
  904. u32 value;
  905. value = tegra_pmc_scratch_readl(pmc, pmc->soc->regs->scratch0);
  906. value &= ~PMC_SCRATCH0_MODE_MASK;
  907. if (cmd) {
  908. if (strcmp(cmd, "recovery") == 0)
  909. value |= PMC_SCRATCH0_MODE_RECOVERY;
  910. if (strcmp(cmd, "bootloader") == 0)
  911. value |= PMC_SCRATCH0_MODE_BOOTLOADER;
  912. if (strcmp(cmd, "forced-recovery") == 0)
  913. value |= PMC_SCRATCH0_MODE_RCM;
  914. }
  915. tegra_pmc_scratch_writel(pmc, value, pmc->soc->regs->scratch0);
  916. }
  917. static int tegra_pmc_reboot_notify(struct notifier_block *this,
  918. unsigned long action, void *data)
  919. {
  920. if (action == SYS_RESTART)
  921. tegra_pmc_program_reboot_reason(data);
  922. return NOTIFY_DONE;
  923. }
  924. static struct notifier_block tegra_pmc_reboot_notifier = {
  925. .notifier_call = tegra_pmc_reboot_notify,
  926. };
  927. static void tegra_pmc_restart(void)
  928. {
  929. u32 value;
  930. /* reset everything but PMC_SCRATCH0 and PMC_RST_STATUS */
  931. value = tegra_pmc_readl(pmc, PMC_CNTRL);
  932. value |= PMC_CNTRL_MAIN_RST;
  933. tegra_pmc_writel(pmc, value, PMC_CNTRL);
  934. }
  935. static int tegra_pmc_restart_handler(struct sys_off_data *data)
  936. {
  937. tegra_pmc_restart();
  938. return NOTIFY_DONE;
  939. }
  940. static int tegra_pmc_power_off_handler(struct sys_off_data *data)
  941. {
  942. /*
  943. * Reboot Nexus 7 into special bootloader mode if USB cable is
  944. * connected in order to display battery status and power off.
  945. */
  946. if (of_machine_is_compatible("asus,grouper") &&
  947. power_supply_is_system_supplied()) {
  948. const u32 go_to_charger_mode = 0xa5a55a5a;
  949. tegra_pmc_writel(pmc, go_to_charger_mode, PMC_SCRATCH37);
  950. tegra_pmc_restart();
  951. }
  952. return NOTIFY_DONE;
  953. }
  954. static int powergate_show(struct seq_file *s, void *data)
  955. {
  956. unsigned int i;
  957. int status;
  958. seq_printf(s, " powergate powered\n");
  959. seq_printf(s, "------------------\n");
  960. for (i = 0; i < pmc->soc->num_powergates; i++) {
  961. status = tegra_powergate_is_powered(pmc, i);
  962. if (status < 0)
  963. continue;
  964. seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i],
  965. status ? "yes" : "no");
  966. }
  967. return 0;
  968. }
  969. DEFINE_SHOW_ATTRIBUTE(powergate);
  970. static int tegra_powergate_of_get_clks(struct tegra_powergate *pg,
  971. struct device_node *np)
  972. {
  973. struct clk *clk;
  974. unsigned int i, count;
  975. int err;
  976. count = of_clk_get_parent_count(np);
  977. if (count == 0)
  978. return -ENODEV;
  979. pg->clks = kcalloc(count, sizeof(clk), GFP_KERNEL);
  980. if (!pg->clks)
  981. return -ENOMEM;
  982. pg->clk_rates = kcalloc(count, sizeof(*pg->clk_rates), GFP_KERNEL);
  983. if (!pg->clk_rates) {
  984. kfree(pg->clks);
  985. return -ENOMEM;
  986. }
  987. for (i = 0; i < count; i++) {
  988. pg->clks[i] = of_clk_get(np, i);
  989. if (IS_ERR(pg->clks[i])) {
  990. err = PTR_ERR(pg->clks[i]);
  991. goto err;
  992. }
  993. }
  994. pg->num_clks = count;
  995. return 0;
  996. err:
  997. while (i--)
  998. clk_put(pg->clks[i]);
  999. kfree(pg->clk_rates);
  1000. kfree(pg->clks);
  1001. return err;
  1002. }
  1003. static int tegra_powergate_of_get_resets(struct tegra_powergate *pg,
  1004. struct device_node *np)
  1005. {
  1006. struct device *dev = pg->pmc->dev;
  1007. int err;
  1008. pg->reset = of_reset_control_array_get_exclusive_released(np);
  1009. if (IS_ERR(pg->reset)) {
  1010. err = PTR_ERR(pg->reset);
  1011. dev_err(dev, "failed to get device resets: %d\n", err);
  1012. return err;
  1013. }
  1014. err = reset_control_acquire(pg->reset);
  1015. if (err < 0) {
  1016. pr_err("failed to acquire resets: %d\n", err);
  1017. reset_control_put(pg->reset);
  1018. }
  1019. return err;
  1020. }
  1021. static int tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np)
  1022. {
  1023. struct device *dev = pmc->dev;
  1024. struct tegra_powergate *pg;
  1025. int id, err = 0;
  1026. bool off;
  1027. pg = kzalloc(sizeof(*pg), GFP_KERNEL);
  1028. if (!pg)
  1029. return -ENOMEM;
  1030. id = tegra_powergate_lookup(pmc, np->name);
  1031. if (id < 0) {
  1032. dev_err(dev, "powergate lookup failed for %pOFn: %d\n", np, id);
  1033. err = -ENODEV;
  1034. goto free_mem;
  1035. }
  1036. /*
  1037. * Clear the bit for this powergate so it cannot be managed
  1038. * directly via the legacy APIs for controlling powergates.
  1039. */
  1040. clear_bit(id, pmc->powergates_available);
  1041. pg->id = id;
  1042. pg->genpd.name = np->name;
  1043. pg->genpd.power_off = tegra_genpd_power_off;
  1044. pg->genpd.power_on = tegra_genpd_power_on;
  1045. pg->pmc = pmc;
  1046. off = !tegra_powergate_is_powered(pmc, pg->id);
  1047. err = tegra_powergate_of_get_clks(pg, np);
  1048. if (err < 0) {
  1049. dev_err(dev, "failed to get clocks for %pOFn: %d\n", np, err);
  1050. goto set_available;
  1051. }
  1052. err = tegra_powergate_of_get_resets(pg, np);
  1053. if (err < 0) {
  1054. dev_err(dev, "failed to get resets for %pOFn: %d\n", np, err);
  1055. goto remove_clks;
  1056. }
  1057. /*
  1058. * If the power-domain is off, then ensure the resets are asserted.
  1059. * If the power-domain is on, then power down to ensure that when is
  1060. * it turned on the power-domain, clocks and resets are all in the
  1061. * expected state.
  1062. */
  1063. if (off) {
  1064. err = reset_control_assert(pg->reset);
  1065. if (err) {
  1066. pr_err("failed to assert resets: %d\n", err);
  1067. goto remove_resets;
  1068. }
  1069. } else {
  1070. err = tegra_powergate_power_down(pg);
  1071. if (err) {
  1072. dev_err(dev, "failed to turn off PM domain %s: %d\n",
  1073. pg->genpd.name, err);
  1074. goto remove_resets;
  1075. }
  1076. }
  1077. /*
  1078. * If PM_GENERIC_DOMAINS is not enabled, power-on
  1079. * the domain and skip the genpd registration.
  1080. */
  1081. if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS)) {
  1082. WARN_ON(tegra_powergate_power_up(pg, true));
  1083. goto remove_resets;
  1084. }
  1085. err = pm_genpd_init(&pg->genpd, NULL, true);
  1086. if (err < 0) {
  1087. dev_err(dev, "failed to initialise PM domain %pOFn: %d\n", np,
  1088. err);
  1089. goto remove_resets;
  1090. }
  1091. err = of_genpd_add_provider_simple(np, &pg->genpd);
  1092. if (err < 0) {
  1093. dev_err(dev, "failed to add PM domain provider for %pOFn: %d\n",
  1094. np, err);
  1095. goto remove_genpd;
  1096. }
  1097. dev_dbg(dev, "added PM domain %s\n", pg->genpd.name);
  1098. return 0;
  1099. remove_genpd:
  1100. pm_genpd_remove(&pg->genpd);
  1101. remove_resets:
  1102. reset_control_put(pg->reset);
  1103. remove_clks:
  1104. while (pg->num_clks--)
  1105. clk_put(pg->clks[pg->num_clks]);
  1106. kfree(pg->clks);
  1107. set_available:
  1108. set_bit(id, pmc->powergates_available);
  1109. free_mem:
  1110. kfree(pg);
  1111. return err;
  1112. }
  1113. bool tegra_pmc_core_domain_state_synced(void)
  1114. {
  1115. return pmc->core_domain_state_synced;
  1116. }
  1117. static int
  1118. tegra_pmc_core_pd_set_performance_state(struct generic_pm_domain *genpd,
  1119. unsigned int level)
  1120. {
  1121. struct dev_pm_opp *opp;
  1122. int err;
  1123. opp = dev_pm_opp_find_level_ceil(&genpd->dev, &level);
  1124. if (IS_ERR(opp)) {
  1125. dev_err(&genpd->dev, "failed to find OPP for level %u: %pe\n",
  1126. level, opp);
  1127. return PTR_ERR(opp);
  1128. }
  1129. mutex_lock(&pmc->powergates_lock);
  1130. err = dev_pm_opp_set_opp(pmc->dev, opp);
  1131. mutex_unlock(&pmc->powergates_lock);
  1132. dev_pm_opp_put(opp);
  1133. if (err) {
  1134. dev_err(&genpd->dev, "failed to set voltage to %duV: %d\n",
  1135. level, err);
  1136. return err;
  1137. }
  1138. return 0;
  1139. }
  1140. static int tegra_pmc_core_pd_add(struct tegra_pmc *pmc, struct device_node *np)
  1141. {
  1142. struct generic_pm_domain *genpd;
  1143. const char *rname[] = { "core", NULL};
  1144. int err;
  1145. genpd = devm_kzalloc(pmc->dev, sizeof(*genpd), GFP_KERNEL);
  1146. if (!genpd)
  1147. return -ENOMEM;
  1148. genpd->name = "core";
  1149. genpd->set_performance_state = tegra_pmc_core_pd_set_performance_state;
  1150. err = devm_pm_opp_set_regulators(pmc->dev, rname);
  1151. if (err)
  1152. return dev_err_probe(pmc->dev, err,
  1153. "failed to set core OPP regulator\n");
  1154. err = pm_genpd_init(genpd, NULL, false);
  1155. if (err) {
  1156. dev_err(pmc->dev, "failed to init core genpd: %d\n", err);
  1157. return err;
  1158. }
  1159. err = of_genpd_add_provider_simple(np, genpd);
  1160. if (err) {
  1161. dev_err(pmc->dev, "failed to add core genpd: %d\n", err);
  1162. goto remove_genpd;
  1163. }
  1164. pmc->core_domain_registered = true;
  1165. return 0;
  1166. remove_genpd:
  1167. pm_genpd_remove(genpd);
  1168. return err;
  1169. }
  1170. static int tegra_powergate_init(struct tegra_pmc *pmc,
  1171. struct device_node *parent)
  1172. {
  1173. struct of_phandle_args child_args, parent_args;
  1174. struct device_node *np;
  1175. int err = 0;
  1176. /*
  1177. * Core power domain is the parent of powergate domains, hence it
  1178. * should be registered first.
  1179. */
  1180. np = of_get_child_by_name(parent, "core-domain");
  1181. if (np) {
  1182. err = tegra_pmc_core_pd_add(pmc, np);
  1183. of_node_put(np);
  1184. if (err)
  1185. return err;
  1186. }
  1187. np = of_get_child_by_name(parent, "powergates");
  1188. if (!np)
  1189. return 0;
  1190. for_each_child_of_node_scoped(np, child) {
  1191. err = tegra_powergate_add(pmc, child);
  1192. if (err < 0)
  1193. break;
  1194. if (of_parse_phandle_with_args(child, "power-domains",
  1195. "#power-domain-cells",
  1196. 0, &parent_args))
  1197. continue;
  1198. child_args.np = child;
  1199. child_args.args_count = 0;
  1200. err = of_genpd_add_subdomain(&parent_args, &child_args);
  1201. of_node_put(parent_args.np);
  1202. if (err)
  1203. break;
  1204. }
  1205. of_node_put(np);
  1206. return err;
  1207. }
  1208. static void tegra_powergate_remove(struct generic_pm_domain *genpd)
  1209. {
  1210. struct tegra_powergate *pg = to_powergate(genpd);
  1211. reset_control_put(pg->reset);
  1212. while (pg->num_clks--)
  1213. clk_put(pg->clks[pg->num_clks]);
  1214. kfree(pg->clks);
  1215. set_bit(pg->id, pmc->powergates_available);
  1216. kfree(pg);
  1217. }
  1218. static void tegra_powergate_remove_all(struct device_node *parent)
  1219. {
  1220. struct generic_pm_domain *genpd;
  1221. struct device_node *np, *child;
  1222. np = of_get_child_by_name(parent, "powergates");
  1223. if (!np)
  1224. return;
  1225. for_each_child_of_node(np, child) {
  1226. of_genpd_del_provider(child);
  1227. genpd = of_genpd_remove_last(child);
  1228. if (IS_ERR(genpd))
  1229. continue;
  1230. tegra_powergate_remove(genpd);
  1231. }
  1232. of_node_put(np);
  1233. np = of_get_child_by_name(parent, "core-domain");
  1234. if (np) {
  1235. of_genpd_del_provider(np);
  1236. of_genpd_remove_last(np);
  1237. }
  1238. }
  1239. static const struct tegra_io_pad_soc *
  1240. tegra_io_pad_find(struct tegra_pmc *pmc, enum tegra_io_pad id)
  1241. {
  1242. unsigned int i;
  1243. for (i = 0; i < pmc->soc->num_io_pads; i++)
  1244. if (pmc->soc->io_pads[i].id == id)
  1245. return &pmc->soc->io_pads[i];
  1246. return NULL;
  1247. }
  1248. static int tegra_io_pad_prepare(struct tegra_pmc *pmc,
  1249. const struct tegra_io_pad_soc *pad,
  1250. unsigned long *request,
  1251. unsigned long *status,
  1252. u32 *mask)
  1253. {
  1254. unsigned long rate, value;
  1255. if (pad->dpd == UINT_MAX)
  1256. return -EINVAL;
  1257. *request = pad->request;
  1258. *status = pad->status;
  1259. *mask = BIT(pad->dpd);
  1260. if (pmc->clk) {
  1261. rate = pmc->rate;
  1262. if (!rate) {
  1263. dev_err(pmc->dev, "failed to get clock rate\n");
  1264. return -ENODEV;
  1265. }
  1266. tegra_pmc_writel(pmc, DPD_SAMPLE_ENABLE, DPD_SAMPLE);
  1267. /* must be at least 200 ns, in APB (PCLK) clock cycles */
  1268. value = DIV_ROUND_UP(1000000000, rate);
  1269. value = DIV_ROUND_UP(200, value);
  1270. tegra_pmc_writel(pmc, value, SEL_DPD_TIM);
  1271. }
  1272. return 0;
  1273. }
  1274. static int tegra_io_pad_poll(struct tegra_pmc *pmc, unsigned long offset,
  1275. u32 mask, u32 val, unsigned long timeout)
  1276. {
  1277. u32 value;
  1278. timeout = jiffies + msecs_to_jiffies(timeout);
  1279. while (time_after(timeout, jiffies)) {
  1280. value = tegra_pmc_readl(pmc, offset);
  1281. if ((value & mask) == val)
  1282. return 0;
  1283. usleep_range(250, 1000);
  1284. }
  1285. return -ETIMEDOUT;
  1286. }
  1287. static void tegra_io_pad_unprepare(struct tegra_pmc *pmc)
  1288. {
  1289. if (pmc->clk)
  1290. tegra_pmc_writel(pmc, DPD_SAMPLE_DISABLE, DPD_SAMPLE);
  1291. }
  1292. /**
  1293. * tegra_io_pad_power_enable() - enable power to I/O pad
  1294. * @id: Tegra I/O pad ID for which to enable power
  1295. *
  1296. * Returns: 0 on success or a negative error code on failure.
  1297. */
  1298. int tegra_io_pad_power_enable(enum tegra_io_pad id)
  1299. {
  1300. const struct tegra_io_pad_soc *pad;
  1301. unsigned long request, status;
  1302. u32 mask;
  1303. int err;
  1304. pad = tegra_io_pad_find(pmc, id);
  1305. if (!pad) {
  1306. dev_err(pmc->dev, "invalid I/O pad ID %u\n", id);
  1307. return -ENOENT;
  1308. }
  1309. mutex_lock(&pmc->powergates_lock);
  1310. err = tegra_io_pad_prepare(pmc, pad, &request, &status, &mask);
  1311. if (err < 0) {
  1312. dev_err(pmc->dev, "failed to prepare I/O pad: %d\n", err);
  1313. goto unlock;
  1314. }
  1315. tegra_pmc_writel(pmc, IO_DPD_REQ_CODE_OFF | mask, request);
  1316. err = tegra_io_pad_poll(pmc, status, mask, 0, 250);
  1317. if (err < 0) {
  1318. dev_err(pmc->dev, "failed to enable I/O pad: %d\n", err);
  1319. goto unlock;
  1320. }
  1321. tegra_io_pad_unprepare(pmc);
  1322. unlock:
  1323. mutex_unlock(&pmc->powergates_lock);
  1324. return err;
  1325. }
  1326. EXPORT_SYMBOL(tegra_io_pad_power_enable);
  1327. /**
  1328. * tegra_io_pad_power_disable() - disable power to I/O pad
  1329. * @id: Tegra I/O pad ID for which to disable power
  1330. *
  1331. * Returns: 0 on success or a negative error code on failure.
  1332. */
  1333. int tegra_io_pad_power_disable(enum tegra_io_pad id)
  1334. {
  1335. const struct tegra_io_pad_soc *pad;
  1336. unsigned long request, status;
  1337. u32 mask;
  1338. int err;
  1339. pad = tegra_io_pad_find(pmc, id);
  1340. if (!pad) {
  1341. dev_err(pmc->dev, "invalid I/O pad ID %u\n", id);
  1342. return -ENOENT;
  1343. }
  1344. mutex_lock(&pmc->powergates_lock);
  1345. err = tegra_io_pad_prepare(pmc, pad, &request, &status, &mask);
  1346. if (err < 0) {
  1347. dev_err(pmc->dev, "failed to prepare I/O pad: %d\n", err);
  1348. goto unlock;
  1349. }
  1350. tegra_pmc_writel(pmc, IO_DPD_REQ_CODE_ON | mask, request);
  1351. err = tegra_io_pad_poll(pmc, status, mask, mask, 250);
  1352. if (err < 0) {
  1353. dev_err(pmc->dev, "failed to disable I/O pad: %d\n", err);
  1354. goto unlock;
  1355. }
  1356. tegra_io_pad_unprepare(pmc);
  1357. unlock:
  1358. mutex_unlock(&pmc->powergates_lock);
  1359. return err;
  1360. }
  1361. EXPORT_SYMBOL(tegra_io_pad_power_disable);
  1362. static int tegra_io_pad_is_powered(struct tegra_pmc *pmc, enum tegra_io_pad id)
  1363. {
  1364. const struct tegra_io_pad_soc *pad;
  1365. unsigned long status;
  1366. u32 mask, value;
  1367. pad = tegra_io_pad_find(pmc, id);
  1368. if (!pad) {
  1369. dev_err(pmc->dev, "invalid I/O pad ID %u\n", id);
  1370. return -ENOENT;
  1371. }
  1372. if (pad->dpd == UINT_MAX)
  1373. return -EINVAL;
  1374. status = pad->status;
  1375. mask = BIT(pad->dpd);
  1376. value = tegra_pmc_readl(pmc, status);
  1377. return !(value & mask);
  1378. }
  1379. static int tegra_io_pad_set_voltage(struct tegra_pmc *pmc, enum tegra_io_pad id,
  1380. int voltage)
  1381. {
  1382. const struct tegra_io_pad_soc *pad;
  1383. u32 value;
  1384. pad = tegra_io_pad_find(pmc, id);
  1385. if (!pad)
  1386. return -ENOENT;
  1387. if (pad->voltage == UINT_MAX)
  1388. return -ENOTSUPP;
  1389. mutex_lock(&pmc->powergates_lock);
  1390. if (pmc->soc->has_impl_33v_pwr) {
  1391. value = tegra_pmc_readl(pmc, PMC_IMPL_E_33V_PWR);
  1392. if (voltage == TEGRA_IO_PAD_VOLTAGE_1V8)
  1393. value &= ~BIT(pad->voltage);
  1394. else
  1395. value |= BIT(pad->voltage);
  1396. tegra_pmc_writel(pmc, value, PMC_IMPL_E_33V_PWR);
  1397. } else {
  1398. /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */
  1399. value = tegra_pmc_readl(pmc, PMC_PWR_DET);
  1400. value |= BIT(pad->voltage);
  1401. tegra_pmc_writel(pmc, value, PMC_PWR_DET);
  1402. /* update I/O voltage */
  1403. value = tegra_pmc_readl(pmc, PMC_PWR_DET_VALUE);
  1404. if (voltage == TEGRA_IO_PAD_VOLTAGE_1V8)
  1405. value &= ~BIT(pad->voltage);
  1406. else
  1407. value |= BIT(pad->voltage);
  1408. tegra_pmc_writel(pmc, value, PMC_PWR_DET_VALUE);
  1409. }
  1410. mutex_unlock(&pmc->powergates_lock);
  1411. usleep_range(100, 250);
  1412. return 0;
  1413. }
  1414. static int tegra_io_pad_get_voltage(struct tegra_pmc *pmc, enum tegra_io_pad id)
  1415. {
  1416. const struct tegra_io_pad_soc *pad;
  1417. u32 value;
  1418. pad = tegra_io_pad_find(pmc, id);
  1419. if (!pad)
  1420. return -ENOENT;
  1421. if (pad->voltage == UINT_MAX)
  1422. return -ENOTSUPP;
  1423. if (pmc->soc->has_impl_33v_pwr)
  1424. value = tegra_pmc_readl(pmc, PMC_IMPL_E_33V_PWR);
  1425. else
  1426. value = tegra_pmc_readl(pmc, PMC_PWR_DET_VALUE);
  1427. if ((value & BIT(pad->voltage)) == 0)
  1428. return TEGRA_IO_PAD_VOLTAGE_1V8;
  1429. return TEGRA_IO_PAD_VOLTAGE_3V3;
  1430. }
  1431. #ifdef CONFIG_PM_SLEEP
  1432. enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
  1433. {
  1434. return pmc->suspend_mode;
  1435. }
  1436. void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
  1437. {
  1438. if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
  1439. return;
  1440. pmc->suspend_mode = mode;
  1441. }
  1442. void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
  1443. {
  1444. unsigned long long rate = 0;
  1445. u64 ticks;
  1446. u32 value;
  1447. switch (mode) {
  1448. case TEGRA_SUSPEND_LP1:
  1449. rate = 32768;
  1450. break;
  1451. case TEGRA_SUSPEND_LP2:
  1452. rate = pmc->rate;
  1453. break;
  1454. default:
  1455. break;
  1456. }
  1457. if (WARN_ON_ONCE(rate == 0))
  1458. rate = 100000000;
  1459. ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1;
  1460. do_div(ticks, USEC_PER_SEC);
  1461. tegra_pmc_writel(pmc, ticks, PMC_CPUPWRGOOD_TIMER);
  1462. ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1;
  1463. do_div(ticks, USEC_PER_SEC);
  1464. tegra_pmc_writel(pmc, ticks, PMC_CPUPWROFF_TIMER);
  1465. value = tegra_pmc_readl(pmc, PMC_CNTRL);
  1466. value &= ~PMC_CNTRL_SIDE_EFFECT_LP0;
  1467. value |= PMC_CNTRL_CPU_PWRREQ_OE;
  1468. tegra_pmc_writel(pmc, value, PMC_CNTRL);
  1469. }
  1470. #endif
  1471. static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np)
  1472. {
  1473. u32 value, values[2];
  1474. if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) {
  1475. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  1476. } else {
  1477. switch (value) {
  1478. case 0:
  1479. pmc->suspend_mode = TEGRA_SUSPEND_LP0;
  1480. break;
  1481. case 1:
  1482. pmc->suspend_mode = TEGRA_SUSPEND_LP1;
  1483. break;
  1484. case 2:
  1485. pmc->suspend_mode = TEGRA_SUSPEND_LP2;
  1486. break;
  1487. default:
  1488. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  1489. break;
  1490. }
  1491. }
  1492. pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode);
  1493. if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value))
  1494. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  1495. pmc->cpu_good_time = value;
  1496. if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value))
  1497. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  1498. pmc->cpu_off_time = value;
  1499. if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time",
  1500. values, ARRAY_SIZE(values)))
  1501. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  1502. pmc->core_osc_time = values[0];
  1503. pmc->core_pmu_time = values[1];
  1504. if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value))
  1505. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  1506. pmc->core_off_time = value;
  1507. pmc->corereq_high = of_property_read_bool(np,
  1508. "nvidia,core-power-req-active-high");
  1509. pmc->sysclkreq_high = of_property_read_bool(np,
  1510. "nvidia,sys-clock-req-active-high");
  1511. pmc->combined_req = of_property_read_bool(np,
  1512. "nvidia,combined-power-req");
  1513. pmc->cpu_pwr_good_en = of_property_read_bool(np,
  1514. "nvidia,cpu-pwr-good-en");
  1515. if (of_property_read_u32_array(np, "nvidia,lp0-vec", values,
  1516. ARRAY_SIZE(values)))
  1517. if (pmc->suspend_mode == TEGRA_SUSPEND_LP0)
  1518. pmc->suspend_mode = TEGRA_SUSPEND_LP1;
  1519. pmc->lp0_vec_phys = values[0];
  1520. pmc->lp0_vec_size = values[1];
  1521. return 0;
  1522. }
  1523. static int tegra_pmc_init(struct tegra_pmc *pmc)
  1524. {
  1525. if (pmc->soc->max_wake_events > 0) {
  1526. pmc->wake_type_level_map = bitmap_zalloc(pmc->soc->max_wake_events, GFP_KERNEL);
  1527. if (!pmc->wake_type_level_map)
  1528. return -ENOMEM;
  1529. pmc->wake_type_dual_edge_map = bitmap_zalloc(pmc->soc->max_wake_events, GFP_KERNEL);
  1530. if (!pmc->wake_type_dual_edge_map)
  1531. return -ENOMEM;
  1532. pmc->wake_sw_status_map = bitmap_zalloc(pmc->soc->max_wake_events, GFP_KERNEL);
  1533. if (!pmc->wake_sw_status_map)
  1534. return -ENOMEM;
  1535. pmc->wake_cntrl_level_map = bitmap_zalloc(pmc->soc->max_wake_events, GFP_KERNEL);
  1536. if (!pmc->wake_cntrl_level_map)
  1537. return -ENOMEM;
  1538. }
  1539. if (pmc->soc->init)
  1540. pmc->soc->init(pmc);
  1541. return 0;
  1542. }
  1543. static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc)
  1544. {
  1545. static const char disabled[] = "emergency thermal reset disabled";
  1546. u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux;
  1547. struct device *dev = pmc->dev;
  1548. struct device_node *np;
  1549. u32 value, checksum;
  1550. if (!pmc->soc->has_tsense_reset)
  1551. return;
  1552. np = of_get_child_by_name(pmc->dev->of_node, "i2c-thermtrip");
  1553. if (!np) {
  1554. dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled);
  1555. return;
  1556. }
  1557. if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) {
  1558. dev_err(dev, "I2C controller ID missing, %s.\n", disabled);
  1559. goto out;
  1560. }
  1561. if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) {
  1562. dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled);
  1563. goto out;
  1564. }
  1565. if (of_property_read_u32(np, "nvidia,reg-addr", &reg_addr)) {
  1566. dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled);
  1567. goto out;
  1568. }
  1569. if (of_property_read_u32(np, "nvidia,reg-data", &reg_data)) {
  1570. dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled);
  1571. goto out;
  1572. }
  1573. if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux))
  1574. pinmux = 0;
  1575. value = tegra_pmc_readl(pmc, PMC_SENSOR_CTRL);
  1576. value |= PMC_SENSOR_CTRL_SCRATCH_WRITE;
  1577. tegra_pmc_writel(pmc, value, PMC_SENSOR_CTRL);
  1578. value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) |
  1579. (reg_addr << PMC_SCRATCH54_ADDR_SHIFT);
  1580. tegra_pmc_writel(pmc, value, PMC_SCRATCH54);
  1581. value = PMC_SCRATCH55_RESET_TEGRA;
  1582. value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT;
  1583. value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT;
  1584. value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT;
  1585. /*
  1586. * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
  1587. * contain the checksum and are currently zero, so they are not added.
  1588. */
  1589. checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff)
  1590. + ((value >> 24) & 0xff);
  1591. checksum &= 0xff;
  1592. checksum = 0x100 - checksum;
  1593. value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT;
  1594. tegra_pmc_writel(pmc, value, PMC_SCRATCH55);
  1595. value = tegra_pmc_readl(pmc, PMC_SENSOR_CTRL);
  1596. value |= PMC_SENSOR_CTRL_ENABLE_RST;
  1597. tegra_pmc_writel(pmc, value, PMC_SENSOR_CTRL);
  1598. dev_info(pmc->dev, "emergency thermal reset enabled\n");
  1599. out:
  1600. of_node_put(np);
  1601. }
  1602. static int tegra_io_pad_pinctrl_get_groups_count(struct pinctrl_dev *pctl_dev)
  1603. {
  1604. struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev);
  1605. return pmc->soc->num_io_pads;
  1606. }
  1607. static const char *tegra_io_pad_pinctrl_get_group_name(struct pinctrl_dev *pctl,
  1608. unsigned int group)
  1609. {
  1610. struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl);
  1611. return pmc->soc->io_pads[group].name;
  1612. }
  1613. static int tegra_io_pad_pinctrl_get_group_pins(struct pinctrl_dev *pctl_dev,
  1614. unsigned int group,
  1615. const unsigned int **pins,
  1616. unsigned int *num_pins)
  1617. {
  1618. struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev);
  1619. *pins = &pmc->soc->io_pads[group].id;
  1620. *num_pins = 1;
  1621. return 0;
  1622. }
  1623. static const struct pinctrl_ops tegra_io_pad_pinctrl_ops = {
  1624. .get_groups_count = tegra_io_pad_pinctrl_get_groups_count,
  1625. .get_group_name = tegra_io_pad_pinctrl_get_group_name,
  1626. .get_group_pins = tegra_io_pad_pinctrl_get_group_pins,
  1627. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  1628. .dt_free_map = pinconf_generic_dt_free_map,
  1629. };
  1630. static int tegra_io_pad_pinconf_get(struct pinctrl_dev *pctl_dev,
  1631. unsigned int pin, unsigned long *config)
  1632. {
  1633. enum pin_config_param param = pinconf_to_config_param(*config);
  1634. struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev);
  1635. const struct tegra_io_pad_soc *pad;
  1636. int ret;
  1637. u32 arg;
  1638. pad = tegra_io_pad_find(pmc, pin);
  1639. if (!pad)
  1640. return -EINVAL;
  1641. switch (param) {
  1642. case PIN_CONFIG_POWER_SOURCE:
  1643. ret = tegra_io_pad_get_voltage(pmc, pad->id);
  1644. if (ret < 0)
  1645. return ret;
  1646. arg = ret;
  1647. break;
  1648. case PIN_CONFIG_MODE_LOW_POWER:
  1649. ret = tegra_io_pad_is_powered(pmc, pad->id);
  1650. if (ret < 0)
  1651. return ret;
  1652. arg = !ret;
  1653. break;
  1654. default:
  1655. return -EINVAL;
  1656. }
  1657. *config = pinconf_to_config_packed(param, arg);
  1658. return 0;
  1659. }
  1660. static int tegra_io_pad_pinconf_set(struct pinctrl_dev *pctl_dev,
  1661. unsigned int pin, unsigned long *configs,
  1662. unsigned int num_configs)
  1663. {
  1664. struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev);
  1665. const struct tegra_io_pad_soc *pad;
  1666. enum pin_config_param param;
  1667. unsigned int i;
  1668. int err;
  1669. u32 arg;
  1670. pad = tegra_io_pad_find(pmc, pin);
  1671. if (!pad)
  1672. return -EINVAL;
  1673. for (i = 0; i < num_configs; ++i) {
  1674. param = pinconf_to_config_param(configs[i]);
  1675. arg = pinconf_to_config_argument(configs[i]);
  1676. switch (param) {
  1677. case PIN_CONFIG_MODE_LOW_POWER:
  1678. if (arg)
  1679. err = tegra_io_pad_power_disable(pad->id);
  1680. else
  1681. err = tegra_io_pad_power_enable(pad->id);
  1682. if (err)
  1683. return err;
  1684. break;
  1685. case PIN_CONFIG_POWER_SOURCE:
  1686. if (arg != TEGRA_IO_PAD_VOLTAGE_1V8 &&
  1687. arg != TEGRA_IO_PAD_VOLTAGE_3V3)
  1688. return -EINVAL;
  1689. err = tegra_io_pad_set_voltage(pmc, pad->id, arg);
  1690. if (err)
  1691. return err;
  1692. break;
  1693. default:
  1694. return -EINVAL;
  1695. }
  1696. }
  1697. return 0;
  1698. }
  1699. static const struct pinconf_ops tegra_io_pad_pinconf_ops = {
  1700. .pin_config_get = tegra_io_pad_pinconf_get,
  1701. .pin_config_set = tegra_io_pad_pinconf_set,
  1702. .is_generic = true,
  1703. };
  1704. static struct pinctrl_desc tegra_pmc_pctl_desc = {
  1705. .pctlops = &tegra_io_pad_pinctrl_ops,
  1706. .confops = &tegra_io_pad_pinconf_ops,
  1707. };
  1708. static int tegra_pmc_pinctrl_init(struct tegra_pmc *pmc)
  1709. {
  1710. int err;
  1711. if (!pmc->soc->num_pin_descs)
  1712. return 0;
  1713. tegra_pmc_pctl_desc.name = dev_name(pmc->dev);
  1714. tegra_pmc_pctl_desc.pins = pmc->soc->pin_descs;
  1715. tegra_pmc_pctl_desc.npins = pmc->soc->num_pin_descs;
  1716. pmc->pctl_dev = devm_pinctrl_register(pmc->dev, &tegra_pmc_pctl_desc,
  1717. pmc);
  1718. if (IS_ERR(pmc->pctl_dev)) {
  1719. err = PTR_ERR(pmc->pctl_dev);
  1720. dev_err(pmc->dev, "failed to register pin controller: %d\n",
  1721. err);
  1722. return err;
  1723. }
  1724. return 0;
  1725. }
  1726. static ssize_t reset_reason_show(struct device *dev,
  1727. struct device_attribute *attr, char *buf)
  1728. {
  1729. u32 value;
  1730. value = tegra_pmc_readl(pmc, pmc->soc->regs->rst_status);
  1731. value &= pmc->soc->regs->rst_source_mask;
  1732. value >>= pmc->soc->regs->rst_source_shift;
  1733. if (WARN_ON(value >= pmc->soc->num_reset_sources))
  1734. return sprintf(buf, "%s\n", "UNKNOWN");
  1735. return sprintf(buf, "%s\n", pmc->soc->reset_sources[value]);
  1736. }
  1737. static DEVICE_ATTR_RO(reset_reason);
  1738. static ssize_t reset_level_show(struct device *dev,
  1739. struct device_attribute *attr, char *buf)
  1740. {
  1741. u32 value;
  1742. value = tegra_pmc_readl(pmc, pmc->soc->regs->rst_status);
  1743. value &= pmc->soc->regs->rst_level_mask;
  1744. value >>= pmc->soc->regs->rst_level_shift;
  1745. if (WARN_ON(value >= pmc->soc->num_reset_levels))
  1746. return sprintf(buf, "%s\n", "UNKNOWN");
  1747. return sprintf(buf, "%s\n", pmc->soc->reset_levels[value]);
  1748. }
  1749. static DEVICE_ATTR_RO(reset_level);
  1750. static void tegra_pmc_reset_sysfs_init(struct tegra_pmc *pmc)
  1751. {
  1752. struct device *dev = pmc->dev;
  1753. int err = 0;
  1754. if (pmc->soc->reset_sources) {
  1755. err = device_create_file(dev, &dev_attr_reset_reason);
  1756. if (err < 0)
  1757. dev_warn(dev,
  1758. "failed to create attr \"reset_reason\": %d\n",
  1759. err);
  1760. }
  1761. if (pmc->soc->reset_levels) {
  1762. err = device_create_file(dev, &dev_attr_reset_level);
  1763. if (err < 0)
  1764. dev_warn(dev,
  1765. "failed to create attr \"reset_level\": %d\n",
  1766. err);
  1767. }
  1768. }
  1769. static int tegra_pmc_irq_translate(struct irq_domain *domain,
  1770. struct irq_fwspec *fwspec,
  1771. unsigned long *hwirq,
  1772. unsigned int *type)
  1773. {
  1774. if (WARN_ON(fwspec->param_count < 2))
  1775. return -EINVAL;
  1776. *hwirq = fwspec->param[0];
  1777. *type = fwspec->param[1];
  1778. return 0;
  1779. }
  1780. static int tegra_pmc_irq_alloc(struct irq_domain *domain, unsigned int virq,
  1781. unsigned int num_irqs, void *data)
  1782. {
  1783. struct tegra_pmc *pmc = domain->host_data;
  1784. const struct tegra_pmc_soc *soc = pmc->soc;
  1785. struct irq_fwspec *fwspec = data;
  1786. unsigned int i;
  1787. int err = 0;
  1788. if (WARN_ON(num_irqs > 1))
  1789. return -EINVAL;
  1790. for (i = 0; i < soc->num_wake_events; i++) {
  1791. const struct tegra_wake_event *event = &soc->wake_events[i];
  1792. /* IRQ and simple wake events */
  1793. if (fwspec->param_count == 2) {
  1794. struct irq_fwspec spec;
  1795. if (event->id != fwspec->param[0])
  1796. continue;
  1797. err = irq_domain_set_hwirq_and_chip(domain, virq,
  1798. event->id,
  1799. &pmc->irq, pmc);
  1800. if (err < 0)
  1801. break;
  1802. /* simple hierarchies stop at the PMC level */
  1803. if (event->irq == 0) {
  1804. err = irq_domain_disconnect_hierarchy(domain->parent, virq);
  1805. break;
  1806. }
  1807. spec.fwnode = &pmc->dev->of_node->fwnode;
  1808. spec.param_count = 3;
  1809. spec.param[0] = GIC_SPI;
  1810. spec.param[1] = event->irq;
  1811. spec.param[2] = fwspec->param[1];
  1812. err = irq_domain_alloc_irqs_parent(domain, virq,
  1813. num_irqs, &spec);
  1814. break;
  1815. }
  1816. /* GPIO wake events */
  1817. if (fwspec->param_count == 3) {
  1818. if (event->gpio.instance != fwspec->param[0] ||
  1819. event->gpio.pin != fwspec->param[1])
  1820. continue;
  1821. err = irq_domain_set_hwirq_and_chip(domain, virq,
  1822. event->id,
  1823. &pmc->irq, pmc);
  1824. /* GPIO hierarchies stop at the PMC level */
  1825. if (!err && domain->parent)
  1826. err = irq_domain_disconnect_hierarchy(domain->parent,
  1827. virq);
  1828. break;
  1829. }
  1830. }
  1831. /* If there is no wake-up event, there is no PMC mapping */
  1832. if (i == soc->num_wake_events)
  1833. err = irq_domain_disconnect_hierarchy(domain, virq);
  1834. return err;
  1835. }
  1836. static const struct irq_domain_ops tegra_pmc_irq_domain_ops = {
  1837. .translate = tegra_pmc_irq_translate,
  1838. .alloc = tegra_pmc_irq_alloc,
  1839. };
  1840. static int tegra210_pmc_irq_set_wake(struct irq_data *data, unsigned int on)
  1841. {
  1842. struct tegra_pmc *pmc = irq_data_get_irq_chip_data(data);
  1843. unsigned int offset, bit;
  1844. u32 value;
  1845. offset = data->hwirq / 32;
  1846. bit = data->hwirq % 32;
  1847. /* clear wake status */
  1848. tegra_pmc_writel(pmc, 0, PMC_SW_WAKE_STATUS);
  1849. tegra_pmc_writel(pmc, 0, PMC_SW_WAKE2_STATUS);
  1850. tegra_pmc_writel(pmc, 0, PMC_WAKE_STATUS);
  1851. tegra_pmc_writel(pmc, 0, PMC_WAKE2_STATUS);
  1852. /* enable PMC wake */
  1853. if (data->hwirq >= 32)
  1854. offset = PMC_WAKE2_MASK;
  1855. else
  1856. offset = PMC_WAKE_MASK;
  1857. value = tegra_pmc_readl(pmc, offset);
  1858. if (on)
  1859. value |= BIT(bit);
  1860. else
  1861. value &= ~BIT(bit);
  1862. tegra_pmc_writel(pmc, value, offset);
  1863. return 0;
  1864. }
  1865. static int tegra210_pmc_irq_set_type(struct irq_data *data, unsigned int type)
  1866. {
  1867. struct tegra_pmc *pmc = irq_data_get_irq_chip_data(data);
  1868. unsigned int offset, bit;
  1869. u32 value;
  1870. offset = data->hwirq / 32;
  1871. bit = data->hwirq % 32;
  1872. if (data->hwirq >= 32)
  1873. offset = PMC_WAKE2_LEVEL;
  1874. else
  1875. offset = PMC_WAKE_LEVEL;
  1876. value = tegra_pmc_readl(pmc, offset);
  1877. switch (type) {
  1878. case IRQ_TYPE_EDGE_RISING:
  1879. case IRQ_TYPE_LEVEL_HIGH:
  1880. value |= BIT(bit);
  1881. break;
  1882. case IRQ_TYPE_EDGE_FALLING:
  1883. case IRQ_TYPE_LEVEL_LOW:
  1884. value &= ~BIT(bit);
  1885. break;
  1886. case IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING:
  1887. value ^= BIT(bit);
  1888. break;
  1889. default:
  1890. return -EINVAL;
  1891. }
  1892. tegra_pmc_writel(pmc, value, offset);
  1893. return 0;
  1894. }
  1895. static void tegra186_pmc_set_wake_filters(struct tegra_pmc *pmc)
  1896. {
  1897. u32 value;
  1898. /* SW Wake (wake83) needs SR_CAPTURE filter to be enabled */
  1899. value = readl(pmc->wake + WAKE_AOWAKE_CNTRL(SW_WAKE_ID));
  1900. value |= WAKE_AOWAKE_CNTRL_SR_CAPTURE_EN;
  1901. writel(value, pmc->wake + WAKE_AOWAKE_CNTRL(SW_WAKE_ID));
  1902. dev_dbg(pmc->dev, "WAKE_AOWAKE_CNTRL_83 = 0x%x\n", value);
  1903. }
  1904. static int tegra186_pmc_irq_set_wake(struct irq_data *data, unsigned int on)
  1905. {
  1906. struct tegra_pmc *pmc = irq_data_get_irq_chip_data(data);
  1907. unsigned int offset, bit;
  1908. u32 value;
  1909. offset = data->hwirq / 32;
  1910. bit = data->hwirq % 32;
  1911. /* clear wake status */
  1912. writel(0x1, pmc->wake + WAKE_AOWAKE_STATUS_W(data->hwirq));
  1913. /* route wake to tier 2 */
  1914. value = readl(pmc->wake + WAKE_AOWAKE_TIER2_ROUTING(offset));
  1915. if (!on)
  1916. value &= ~(1 << bit);
  1917. else
  1918. value |= 1 << bit;
  1919. writel(value, pmc->wake + WAKE_AOWAKE_TIER2_ROUTING(offset));
  1920. /* enable wakeup event */
  1921. writel(!!on, pmc->wake + WAKE_AOWAKE_MASK_W(data->hwirq));
  1922. return 0;
  1923. }
  1924. static int tegra186_pmc_irq_set_type(struct irq_data *data, unsigned int type)
  1925. {
  1926. struct tegra_pmc *pmc = irq_data_get_irq_chip_data(data);
  1927. u32 value;
  1928. value = readl(pmc->wake + WAKE_AOWAKE_CNTRL(data->hwirq));
  1929. switch (type) {
  1930. case IRQ_TYPE_EDGE_RISING:
  1931. case IRQ_TYPE_LEVEL_HIGH:
  1932. value |= WAKE_AOWAKE_CNTRL_LEVEL;
  1933. set_bit(data->hwirq, pmc->wake_type_level_map);
  1934. clear_bit(data->hwirq, pmc->wake_type_dual_edge_map);
  1935. break;
  1936. case IRQ_TYPE_EDGE_FALLING:
  1937. case IRQ_TYPE_LEVEL_LOW:
  1938. value &= ~WAKE_AOWAKE_CNTRL_LEVEL;
  1939. clear_bit(data->hwirq, pmc->wake_type_level_map);
  1940. clear_bit(data->hwirq, pmc->wake_type_dual_edge_map);
  1941. break;
  1942. case IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING:
  1943. value ^= WAKE_AOWAKE_CNTRL_LEVEL;
  1944. clear_bit(data->hwirq, pmc->wake_type_level_map);
  1945. set_bit(data->hwirq, pmc->wake_type_dual_edge_map);
  1946. break;
  1947. default:
  1948. return -EINVAL;
  1949. }
  1950. writel(value, pmc->wake + WAKE_AOWAKE_CNTRL(data->hwirq));
  1951. return 0;
  1952. }
  1953. static void tegra_irq_mask_parent(struct irq_data *data)
  1954. {
  1955. if (data->parent_data)
  1956. irq_chip_mask_parent(data);
  1957. }
  1958. static void tegra_irq_unmask_parent(struct irq_data *data)
  1959. {
  1960. if (data->parent_data)
  1961. irq_chip_unmask_parent(data);
  1962. }
  1963. static void tegra_irq_eoi_parent(struct irq_data *data)
  1964. {
  1965. if (data->parent_data)
  1966. irq_chip_eoi_parent(data);
  1967. }
  1968. static int tegra_irq_set_affinity_parent(struct irq_data *data,
  1969. const struct cpumask *dest,
  1970. bool force)
  1971. {
  1972. if (data->parent_data)
  1973. return irq_chip_set_affinity_parent(data, dest, force);
  1974. return -EINVAL;
  1975. }
  1976. static int tegra_pmc_irq_init(struct tegra_pmc *pmc)
  1977. {
  1978. struct irq_domain *parent = NULL;
  1979. struct device_node *np;
  1980. np = of_irq_find_parent(pmc->dev->of_node);
  1981. if (np) {
  1982. parent = irq_find_host(np);
  1983. of_node_put(np);
  1984. }
  1985. if (!parent)
  1986. return 0;
  1987. pmc->irq.name = dev_name(pmc->dev);
  1988. pmc->irq.irq_mask = tegra_irq_mask_parent;
  1989. pmc->irq.irq_unmask = tegra_irq_unmask_parent;
  1990. pmc->irq.irq_eoi = tegra_irq_eoi_parent;
  1991. pmc->irq.irq_set_affinity = tegra_irq_set_affinity_parent;
  1992. pmc->irq.irq_set_type = pmc->soc->irq_set_type;
  1993. pmc->irq.irq_set_wake = pmc->soc->irq_set_wake;
  1994. pmc->domain = irq_domain_add_hierarchy(parent, 0, 96, pmc->dev->of_node,
  1995. &tegra_pmc_irq_domain_ops, pmc);
  1996. if (!pmc->domain) {
  1997. dev_err(pmc->dev, "failed to allocate domain\n");
  1998. return -ENOMEM;
  1999. }
  2000. return 0;
  2001. }
  2002. static int tegra_pmc_clk_notify_cb(struct notifier_block *nb,
  2003. unsigned long action, void *ptr)
  2004. {
  2005. struct tegra_pmc *pmc = container_of(nb, struct tegra_pmc, clk_nb);
  2006. struct clk_notifier_data *data = ptr;
  2007. switch (action) {
  2008. case PRE_RATE_CHANGE:
  2009. mutex_lock(&pmc->powergates_lock);
  2010. break;
  2011. case POST_RATE_CHANGE:
  2012. pmc->rate = data->new_rate;
  2013. fallthrough;
  2014. case ABORT_RATE_CHANGE:
  2015. mutex_unlock(&pmc->powergates_lock);
  2016. break;
  2017. default:
  2018. WARN_ON_ONCE(1);
  2019. return notifier_from_errno(-EINVAL);
  2020. }
  2021. return NOTIFY_OK;
  2022. }
  2023. static void pmc_clk_fence_udelay(u32 offset)
  2024. {
  2025. tegra_pmc_readl(pmc, offset);
  2026. /* pmc clk propagation delay 2 us */
  2027. udelay(2);
  2028. }
  2029. static u8 pmc_clk_mux_get_parent(struct clk_hw *hw)
  2030. {
  2031. struct pmc_clk *clk = to_pmc_clk(hw);
  2032. u32 val;
  2033. val = tegra_pmc_readl(pmc, clk->offs) >> clk->mux_shift;
  2034. val &= PMC_CLK_OUT_MUX_MASK;
  2035. return val;
  2036. }
  2037. static int pmc_clk_mux_set_parent(struct clk_hw *hw, u8 index)
  2038. {
  2039. struct pmc_clk *clk = to_pmc_clk(hw);
  2040. u32 val;
  2041. val = tegra_pmc_readl(pmc, clk->offs);
  2042. val &= ~(PMC_CLK_OUT_MUX_MASK << clk->mux_shift);
  2043. val |= index << clk->mux_shift;
  2044. tegra_pmc_writel(pmc, val, clk->offs);
  2045. pmc_clk_fence_udelay(clk->offs);
  2046. return 0;
  2047. }
  2048. static int pmc_clk_is_enabled(struct clk_hw *hw)
  2049. {
  2050. struct pmc_clk *clk = to_pmc_clk(hw);
  2051. u32 val;
  2052. val = tegra_pmc_readl(pmc, clk->offs) & BIT(clk->force_en_shift);
  2053. return val ? 1 : 0;
  2054. }
  2055. static void pmc_clk_set_state(unsigned long offs, u32 shift, int state)
  2056. {
  2057. u32 val;
  2058. val = tegra_pmc_readl(pmc, offs);
  2059. val = state ? (val | BIT(shift)) : (val & ~BIT(shift));
  2060. tegra_pmc_writel(pmc, val, offs);
  2061. pmc_clk_fence_udelay(offs);
  2062. }
  2063. static int pmc_clk_enable(struct clk_hw *hw)
  2064. {
  2065. struct pmc_clk *clk = to_pmc_clk(hw);
  2066. pmc_clk_set_state(clk->offs, clk->force_en_shift, 1);
  2067. return 0;
  2068. }
  2069. static void pmc_clk_disable(struct clk_hw *hw)
  2070. {
  2071. struct pmc_clk *clk = to_pmc_clk(hw);
  2072. pmc_clk_set_state(clk->offs, clk->force_en_shift, 0);
  2073. }
  2074. static const struct clk_ops pmc_clk_ops = {
  2075. .get_parent = pmc_clk_mux_get_parent,
  2076. .set_parent = pmc_clk_mux_set_parent,
  2077. .determine_rate = __clk_mux_determine_rate,
  2078. .is_enabled = pmc_clk_is_enabled,
  2079. .enable = pmc_clk_enable,
  2080. .disable = pmc_clk_disable,
  2081. };
  2082. static struct clk *
  2083. tegra_pmc_clk_out_register(struct tegra_pmc *pmc,
  2084. const struct pmc_clk_init_data *data,
  2085. unsigned long offset)
  2086. {
  2087. struct clk_init_data init;
  2088. struct pmc_clk *pmc_clk;
  2089. pmc_clk = devm_kzalloc(pmc->dev, sizeof(*pmc_clk), GFP_KERNEL);
  2090. if (!pmc_clk)
  2091. return ERR_PTR(-ENOMEM);
  2092. init.name = data->name;
  2093. init.ops = &pmc_clk_ops;
  2094. init.parent_names = data->parents;
  2095. init.num_parents = data->num_parents;
  2096. init.flags = CLK_SET_RATE_NO_REPARENT | CLK_SET_RATE_PARENT |
  2097. CLK_SET_PARENT_GATE;
  2098. pmc_clk->hw.init = &init;
  2099. pmc_clk->offs = offset;
  2100. pmc_clk->mux_shift = data->mux_shift;
  2101. pmc_clk->force_en_shift = data->force_en_shift;
  2102. return clk_register(NULL, &pmc_clk->hw);
  2103. }
  2104. static int pmc_clk_gate_is_enabled(struct clk_hw *hw)
  2105. {
  2106. struct pmc_clk_gate *gate = to_pmc_clk_gate(hw);
  2107. return tegra_pmc_readl(pmc, gate->offs) & BIT(gate->shift) ? 1 : 0;
  2108. }
  2109. static int pmc_clk_gate_enable(struct clk_hw *hw)
  2110. {
  2111. struct pmc_clk_gate *gate = to_pmc_clk_gate(hw);
  2112. pmc_clk_set_state(gate->offs, gate->shift, 1);
  2113. return 0;
  2114. }
  2115. static void pmc_clk_gate_disable(struct clk_hw *hw)
  2116. {
  2117. struct pmc_clk_gate *gate = to_pmc_clk_gate(hw);
  2118. pmc_clk_set_state(gate->offs, gate->shift, 0);
  2119. }
  2120. static const struct clk_ops pmc_clk_gate_ops = {
  2121. .is_enabled = pmc_clk_gate_is_enabled,
  2122. .enable = pmc_clk_gate_enable,
  2123. .disable = pmc_clk_gate_disable,
  2124. };
  2125. static struct clk *
  2126. tegra_pmc_clk_gate_register(struct tegra_pmc *pmc, const char *name,
  2127. const char *parent_name, unsigned long offset,
  2128. u32 shift)
  2129. {
  2130. struct clk_init_data init;
  2131. struct pmc_clk_gate *gate;
  2132. gate = devm_kzalloc(pmc->dev, sizeof(*gate), GFP_KERNEL);
  2133. if (!gate)
  2134. return ERR_PTR(-ENOMEM);
  2135. init.name = name;
  2136. init.ops = &pmc_clk_gate_ops;
  2137. init.parent_names = &parent_name;
  2138. init.num_parents = 1;
  2139. init.flags = 0;
  2140. gate->hw.init = &init;
  2141. gate->offs = offset;
  2142. gate->shift = shift;
  2143. return clk_register(NULL, &gate->hw);
  2144. }
  2145. static void tegra_pmc_clock_register(struct tegra_pmc *pmc,
  2146. struct device_node *np)
  2147. {
  2148. struct clk *clk;
  2149. struct clk_onecell_data *clk_data;
  2150. unsigned int num_clks;
  2151. int i, err;
  2152. num_clks = pmc->soc->num_pmc_clks;
  2153. if (pmc->soc->has_blink_output)
  2154. num_clks += 1;
  2155. if (!num_clks)
  2156. return;
  2157. clk_data = devm_kmalloc(pmc->dev, sizeof(*clk_data), GFP_KERNEL);
  2158. if (!clk_data)
  2159. return;
  2160. clk_data->clks = devm_kcalloc(pmc->dev, TEGRA_PMC_CLK_MAX,
  2161. sizeof(*clk_data->clks), GFP_KERNEL);
  2162. if (!clk_data->clks)
  2163. return;
  2164. clk_data->clk_num = TEGRA_PMC_CLK_MAX;
  2165. for (i = 0; i < TEGRA_PMC_CLK_MAX; i++)
  2166. clk_data->clks[i] = ERR_PTR(-ENOENT);
  2167. for (i = 0; i < pmc->soc->num_pmc_clks; i++) {
  2168. const struct pmc_clk_init_data *data;
  2169. data = pmc->soc->pmc_clks_data + i;
  2170. clk = tegra_pmc_clk_out_register(pmc, data, PMC_CLK_OUT_CNTRL);
  2171. if (IS_ERR(clk)) {
  2172. dev_warn(pmc->dev, "unable to register clock %s: %d\n",
  2173. data->name, PTR_ERR_OR_ZERO(clk));
  2174. return;
  2175. }
  2176. err = clk_register_clkdev(clk, data->name, NULL);
  2177. if (err) {
  2178. dev_warn(pmc->dev,
  2179. "unable to register %s clock lookup: %d\n",
  2180. data->name, err);
  2181. return;
  2182. }
  2183. clk_data->clks[data->clk_id] = clk;
  2184. }
  2185. if (pmc->soc->has_blink_output) {
  2186. tegra_pmc_writel(pmc, 0x0, PMC_BLINK_TIMER);
  2187. clk = tegra_pmc_clk_gate_register(pmc,
  2188. "pmc_blink_override",
  2189. "clk_32k",
  2190. PMC_DPD_PADS_ORIDE,
  2191. PMC_DPD_PADS_ORIDE_BLINK);
  2192. if (IS_ERR(clk)) {
  2193. dev_warn(pmc->dev,
  2194. "unable to register pmc_blink_override: %d\n",
  2195. PTR_ERR_OR_ZERO(clk));
  2196. return;
  2197. }
  2198. clk = tegra_pmc_clk_gate_register(pmc, "pmc_blink",
  2199. "pmc_blink_override",
  2200. PMC_CNTRL,
  2201. PMC_CNTRL_BLINK_EN);
  2202. if (IS_ERR(clk)) {
  2203. dev_warn(pmc->dev,
  2204. "unable to register pmc_blink: %d\n",
  2205. PTR_ERR_OR_ZERO(clk));
  2206. return;
  2207. }
  2208. err = clk_register_clkdev(clk, "pmc_blink", NULL);
  2209. if (err) {
  2210. dev_warn(pmc->dev,
  2211. "unable to register pmc_blink lookup: %d\n",
  2212. err);
  2213. return;
  2214. }
  2215. clk_data->clks[TEGRA_PMC_CLK_BLINK] = clk;
  2216. }
  2217. err = of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
  2218. if (err)
  2219. dev_warn(pmc->dev, "failed to add pmc clock provider: %d\n",
  2220. err);
  2221. }
  2222. static const struct regmap_range pmc_usb_sleepwalk_ranges[] = {
  2223. regmap_reg_range(PMC_USB_DEBOUNCE_DEL, PMC_USB_AO),
  2224. regmap_reg_range(PMC_UTMIP_UHSIC_TRIGGERS, PMC_UTMIP_UHSIC_SAVED_STATE),
  2225. regmap_reg_range(PMC_UTMIP_TERM_PAD_CFG, PMC_UTMIP_UHSIC_FAKE),
  2226. regmap_reg_range(PMC_UTMIP_UHSIC_LINE_WAKEUP, PMC_UTMIP_UHSIC_LINE_WAKEUP),
  2227. regmap_reg_range(PMC_UTMIP_BIAS_MASTER_CNTRL, PMC_UTMIP_MASTER_CONFIG),
  2228. regmap_reg_range(PMC_UTMIP_UHSIC2_TRIGGERS, PMC_UTMIP_MASTER2_CONFIG),
  2229. regmap_reg_range(PMC_UTMIP_PAD_CFG0, PMC_UTMIP_UHSIC_SLEEP_CFG1),
  2230. regmap_reg_range(PMC_UTMIP_SLEEPWALK_P3, PMC_UTMIP_SLEEPWALK_P3),
  2231. };
  2232. static const struct regmap_access_table pmc_usb_sleepwalk_table = {
  2233. .yes_ranges = pmc_usb_sleepwalk_ranges,
  2234. .n_yes_ranges = ARRAY_SIZE(pmc_usb_sleepwalk_ranges),
  2235. };
  2236. static int tegra_pmc_regmap_readl(void *context, unsigned int offset, unsigned int *value)
  2237. {
  2238. struct tegra_pmc *pmc = context;
  2239. *value = tegra_pmc_readl(pmc, offset);
  2240. return 0;
  2241. }
  2242. static int tegra_pmc_regmap_writel(void *context, unsigned int offset, unsigned int value)
  2243. {
  2244. struct tegra_pmc *pmc = context;
  2245. tegra_pmc_writel(pmc, value, offset);
  2246. return 0;
  2247. }
  2248. static const struct regmap_config usb_sleepwalk_regmap_config = {
  2249. .name = "usb_sleepwalk",
  2250. .reg_bits = 32,
  2251. .val_bits = 32,
  2252. .reg_stride = 4,
  2253. .fast_io = true,
  2254. .rd_table = &pmc_usb_sleepwalk_table,
  2255. .wr_table = &pmc_usb_sleepwalk_table,
  2256. .reg_read = tegra_pmc_regmap_readl,
  2257. .reg_write = tegra_pmc_regmap_writel,
  2258. };
  2259. static int tegra_pmc_regmap_init(struct tegra_pmc *pmc)
  2260. {
  2261. struct regmap *regmap;
  2262. int err;
  2263. if (pmc->soc->has_usb_sleepwalk) {
  2264. regmap = devm_regmap_init(pmc->dev, NULL, pmc, &usb_sleepwalk_regmap_config);
  2265. if (IS_ERR(regmap)) {
  2266. err = PTR_ERR(regmap);
  2267. dev_err(pmc->dev, "failed to allocate register map (%d)\n", err);
  2268. return err;
  2269. }
  2270. }
  2271. return 0;
  2272. }
  2273. static void tegra_pmc_reset_suspend_mode(void *data)
  2274. {
  2275. pmc->suspend_mode = TEGRA_SUSPEND_NOT_READY;
  2276. }
  2277. static int tegra_pmc_probe(struct platform_device *pdev)
  2278. {
  2279. void __iomem *base;
  2280. struct resource *res;
  2281. int err;
  2282. /*
  2283. * Early initialisation should have configured an initial
  2284. * register mapping and setup the soc data pointer. If these
  2285. * are not valid then something went badly wrong!
  2286. */
  2287. if (WARN_ON(!pmc->base || !pmc->soc))
  2288. return -ENODEV;
  2289. err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node);
  2290. if (err < 0)
  2291. return err;
  2292. err = devm_add_action_or_reset(&pdev->dev, tegra_pmc_reset_suspend_mode,
  2293. NULL);
  2294. if (err)
  2295. return err;
  2296. /* take over the memory region from the early initialization */
  2297. base = devm_platform_ioremap_resource(pdev, 0);
  2298. if (IS_ERR(base))
  2299. return PTR_ERR(base);
  2300. if (pmc->soc->has_single_mmio_aperture) {
  2301. pmc->wake = base;
  2302. pmc->aotag = base;
  2303. pmc->scratch = base;
  2304. } else {
  2305. pmc->wake = devm_platform_ioremap_resource_byname(pdev, "wake");
  2306. if (IS_ERR(pmc->wake))
  2307. return PTR_ERR(pmc->wake);
  2308. pmc->aotag = devm_platform_ioremap_resource_byname(pdev, "aotag");
  2309. if (IS_ERR(pmc->aotag))
  2310. return PTR_ERR(pmc->aotag);
  2311. /* "scratch" is an optional aperture */
  2312. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  2313. "scratch");
  2314. if (res) {
  2315. pmc->scratch = devm_ioremap_resource(&pdev->dev, res);
  2316. if (IS_ERR(pmc->scratch))
  2317. return PTR_ERR(pmc->scratch);
  2318. } else {
  2319. pmc->scratch = NULL;
  2320. }
  2321. }
  2322. pmc->clk = devm_clk_get_optional(&pdev->dev, "pclk");
  2323. if (IS_ERR(pmc->clk))
  2324. return dev_err_probe(&pdev->dev, PTR_ERR(pmc->clk),
  2325. "failed to get pclk\n");
  2326. /*
  2327. * PMC should be last resort for restarting since it soft-resets
  2328. * CPU without resetting everything else.
  2329. */
  2330. if (pmc->scratch) {
  2331. err = devm_register_reboot_notifier(&pdev->dev,
  2332. &tegra_pmc_reboot_notifier);
  2333. if (err) {
  2334. dev_err(&pdev->dev,
  2335. "unable to register reboot notifier, %d\n",
  2336. err);
  2337. return err;
  2338. }
  2339. }
  2340. err = devm_register_sys_off_handler(&pdev->dev,
  2341. SYS_OFF_MODE_RESTART,
  2342. SYS_OFF_PRIO_LOW,
  2343. tegra_pmc_restart_handler, NULL);
  2344. if (err) {
  2345. dev_err(&pdev->dev, "failed to register sys-off handler: %d\n",
  2346. err);
  2347. return err;
  2348. }
  2349. /*
  2350. * PMC should be primary power-off method if it soft-resets CPU,
  2351. * asking bootloader to shutdown hardware.
  2352. */
  2353. err = devm_register_sys_off_handler(&pdev->dev,
  2354. SYS_OFF_MODE_POWER_OFF,
  2355. SYS_OFF_PRIO_FIRMWARE,
  2356. tegra_pmc_power_off_handler, NULL);
  2357. if (err) {
  2358. dev_err(&pdev->dev, "failed to register sys-off handler: %d\n",
  2359. err);
  2360. return err;
  2361. }
  2362. /*
  2363. * PCLK clock rate can't be retrieved using CLK API because it
  2364. * causes lockup if CPU enters LP2 idle state from some other
  2365. * CLK notifier, hence we're caching the rate's value locally.
  2366. */
  2367. if (pmc->clk) {
  2368. pmc->clk_nb.notifier_call = tegra_pmc_clk_notify_cb;
  2369. err = devm_clk_notifier_register(&pdev->dev, pmc->clk,
  2370. &pmc->clk_nb);
  2371. if (err) {
  2372. dev_err(&pdev->dev,
  2373. "failed to register clk notifier\n");
  2374. return err;
  2375. }
  2376. pmc->rate = clk_get_rate(pmc->clk);
  2377. }
  2378. pmc->dev = &pdev->dev;
  2379. err = tegra_pmc_init(pmc);
  2380. if (err < 0) {
  2381. dev_err(&pdev->dev, "failed to initialize PMC: %d\n", err);
  2382. return err;
  2383. }
  2384. tegra_pmc_init_tsense_reset(pmc);
  2385. tegra_pmc_reset_sysfs_init(pmc);
  2386. err = tegra_pmc_pinctrl_init(pmc);
  2387. if (err)
  2388. goto cleanup_sysfs;
  2389. err = tegra_pmc_regmap_init(pmc);
  2390. if (err < 0)
  2391. goto cleanup_sysfs;
  2392. err = tegra_powergate_init(pmc, pdev->dev.of_node);
  2393. if (err < 0)
  2394. goto cleanup_powergates;
  2395. err = tegra_pmc_irq_init(pmc);
  2396. if (err < 0)
  2397. goto cleanup_powergates;
  2398. mutex_lock(&pmc->powergates_lock);
  2399. iounmap(pmc->base);
  2400. pmc->base = base;
  2401. mutex_unlock(&pmc->powergates_lock);
  2402. tegra_pmc_clock_register(pmc, pdev->dev.of_node);
  2403. platform_set_drvdata(pdev, pmc);
  2404. tegra_pm_init_suspend();
  2405. /* Some wakes require specific filter configuration */
  2406. if (pmc->soc->set_wake_filters)
  2407. pmc->soc->set_wake_filters(pmc);
  2408. debugfs_create_file("powergate", 0444, NULL, NULL, &powergate_fops);
  2409. return 0;
  2410. cleanup_powergates:
  2411. tegra_powergate_remove_all(pdev->dev.of_node);
  2412. cleanup_sysfs:
  2413. device_remove_file(&pdev->dev, &dev_attr_reset_reason);
  2414. device_remove_file(&pdev->dev, &dev_attr_reset_level);
  2415. return err;
  2416. }
  2417. /*
  2418. * Ensures that sufficient time is passed for a register write to
  2419. * serialize into the 32KHz domain.
  2420. */
  2421. static void wke_32kwritel(struct tegra_pmc *pmc, u32 value, unsigned int offset)
  2422. {
  2423. writel(value, pmc->wake + offset);
  2424. udelay(130);
  2425. }
  2426. static void wke_write_wake_level(struct tegra_pmc *pmc, int wake, int level)
  2427. {
  2428. unsigned int offset = WAKE_AOWAKE_CNTRL(wake);
  2429. u32 value;
  2430. value = readl(pmc->wake + offset);
  2431. if (level)
  2432. value |= WAKE_AOWAKE_CNTRL_LEVEL;
  2433. else
  2434. value &= ~WAKE_AOWAKE_CNTRL_LEVEL;
  2435. writel(value, pmc->wake + offset);
  2436. }
  2437. static void wke_write_wake_levels(struct tegra_pmc *pmc)
  2438. {
  2439. unsigned int i;
  2440. for (i = 0; i < pmc->soc->max_wake_events; i++)
  2441. wke_write_wake_level(pmc, i, test_bit(i, pmc->wake_cntrl_level_map));
  2442. }
  2443. static void wke_clear_sw_wake_status(struct tegra_pmc *pmc)
  2444. {
  2445. wke_32kwritel(pmc, 1, WAKE_AOWAKE_SW_STATUS_W_0);
  2446. }
  2447. static void wke_read_sw_wake_status(struct tegra_pmc *pmc)
  2448. {
  2449. unsigned long status;
  2450. unsigned int wake, i;
  2451. for (i = 0; i < pmc->soc->max_wake_events; i++)
  2452. wke_write_wake_level(pmc, i, 0);
  2453. wke_clear_sw_wake_status(pmc);
  2454. wke_32kwritel(pmc, 1, WAKE_LATCH_SW);
  2455. /*
  2456. * WAKE_AOWAKE_SW_STATUS is edge triggered, so in order to
  2457. * obtain the current status of the input wake signals, change
  2458. * the polarity of the wake level from 0->1 while latching to force
  2459. * a positive edge if the sampled signal is '1'.
  2460. */
  2461. for (i = 0; i < pmc->soc->max_wake_events; i++)
  2462. wke_write_wake_level(pmc, i, 1);
  2463. /*
  2464. * Wait for the update to be synced into the 32kHz domain,
  2465. * and let enough time lapse, so that the wake signals have time to
  2466. * be sampled.
  2467. */
  2468. udelay(300);
  2469. wke_32kwritel(pmc, 0, WAKE_LATCH_SW);
  2470. bitmap_zero(pmc->wake_sw_status_map, pmc->soc->max_wake_events);
  2471. for (i = 0; i < pmc->soc->max_wake_vectors; i++) {
  2472. status = readl(pmc->wake + WAKE_AOWAKE_SW_STATUS(i));
  2473. for_each_set_bit(wake, &status, 32)
  2474. set_bit(wake + (i * 32), pmc->wake_sw_status_map);
  2475. }
  2476. }
  2477. static void wke_clear_wake_status(struct tegra_pmc *pmc)
  2478. {
  2479. unsigned long status;
  2480. unsigned int i, wake;
  2481. u32 mask;
  2482. for (i = 0; i < pmc->soc->max_wake_vectors; i++) {
  2483. mask = readl(pmc->wake + WAKE_AOWAKE_TIER2_ROUTING(i));
  2484. status = readl(pmc->wake + WAKE_AOWAKE_STATUS_R(i)) & mask;
  2485. for_each_set_bit(wake, &status, 32)
  2486. wke_32kwritel(pmc, 0x1, WAKE_AOWAKE_STATUS_W((i * 32) + wake));
  2487. }
  2488. }
  2489. /* translate sc7 wake sources back into IRQs to catch edge triggered wakeups */
  2490. static void tegra186_pmc_process_wake_events(struct tegra_pmc *pmc, unsigned int index,
  2491. unsigned long status)
  2492. {
  2493. unsigned int wake;
  2494. dev_dbg(pmc->dev, "Wake[%d:%d] status=%#lx\n", (index * 32) + 31, index * 32, status);
  2495. for_each_set_bit(wake, &status, 32) {
  2496. irq_hw_number_t hwirq = wake + 32 * index;
  2497. struct irq_desc *desc;
  2498. unsigned int irq;
  2499. irq = irq_find_mapping(pmc->domain, hwirq);
  2500. desc = irq_to_desc(irq);
  2501. if (!desc || !desc->action || !desc->action->name) {
  2502. dev_dbg(pmc->dev, "Resume caused by WAKE%ld, IRQ %d\n", hwirq, irq);
  2503. continue;
  2504. }
  2505. dev_dbg(pmc->dev, "Resume caused by WAKE%ld, %s\n", hwirq, desc->action->name);
  2506. generic_handle_irq(irq);
  2507. }
  2508. }
  2509. static void tegra186_pmc_wake_syscore_resume(void)
  2510. {
  2511. u32 status, mask;
  2512. unsigned int i;
  2513. for (i = 0; i < pmc->soc->max_wake_vectors; i++) {
  2514. mask = readl(pmc->wake + WAKE_AOWAKE_TIER2_ROUTING(i));
  2515. status = readl(pmc->wake + WAKE_AOWAKE_STATUS_R(i)) & mask;
  2516. tegra186_pmc_process_wake_events(pmc, i, status);
  2517. }
  2518. }
  2519. static int tegra186_pmc_wake_syscore_suspend(void)
  2520. {
  2521. wke_read_sw_wake_status(pmc);
  2522. /* flip the wakeup trigger for dual-edge triggered pads
  2523. * which are currently asserting as wakeups
  2524. */
  2525. bitmap_andnot(pmc->wake_cntrl_level_map, pmc->wake_type_dual_edge_map,
  2526. pmc->wake_sw_status_map, pmc->soc->max_wake_events);
  2527. bitmap_or(pmc->wake_cntrl_level_map, pmc->wake_cntrl_level_map,
  2528. pmc->wake_type_level_map, pmc->soc->max_wake_events);
  2529. /* Clear PMC Wake Status registers while going to suspend */
  2530. wke_clear_wake_status(pmc);
  2531. wke_write_wake_levels(pmc);
  2532. return 0;
  2533. }
  2534. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
  2535. static int tegra_pmc_suspend(struct device *dev)
  2536. {
  2537. struct tegra_pmc *pmc = dev_get_drvdata(dev);
  2538. tegra_pmc_writel(pmc, virt_to_phys(tegra_resume), PMC_SCRATCH41);
  2539. return 0;
  2540. }
  2541. static int tegra_pmc_resume(struct device *dev)
  2542. {
  2543. struct tegra_pmc *pmc = dev_get_drvdata(dev);
  2544. tegra_pmc_writel(pmc, 0x0, PMC_SCRATCH41);
  2545. return 0;
  2546. }
  2547. static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume);
  2548. #endif
  2549. static const char * const tegra20_powergates[] = {
  2550. [TEGRA_POWERGATE_CPU] = "cpu",
  2551. [TEGRA_POWERGATE_3D] = "td",
  2552. [TEGRA_POWERGATE_VENC] = "venc",
  2553. [TEGRA_POWERGATE_VDEC] = "vdec",
  2554. [TEGRA_POWERGATE_PCIE] = "pcie",
  2555. [TEGRA_POWERGATE_L2] = "l2",
  2556. [TEGRA_POWERGATE_MPE] = "mpe",
  2557. };
  2558. static const struct tegra_pmc_regs tegra20_pmc_regs = {
  2559. .scratch0 = 0x50,
  2560. .rst_status = 0x1b4,
  2561. .rst_source_shift = 0x0,
  2562. .rst_source_mask = 0x7,
  2563. .rst_level_shift = 0x0,
  2564. .rst_level_mask = 0x0,
  2565. };
  2566. static void tegra20_pmc_init(struct tegra_pmc *pmc)
  2567. {
  2568. u32 value, osc, pmu, off;
  2569. /* Always enable CPU power request */
  2570. value = tegra_pmc_readl(pmc, PMC_CNTRL);
  2571. value |= PMC_CNTRL_CPU_PWRREQ_OE;
  2572. tegra_pmc_writel(pmc, value, PMC_CNTRL);
  2573. value = tegra_pmc_readl(pmc, PMC_CNTRL);
  2574. if (pmc->sysclkreq_high)
  2575. value &= ~PMC_CNTRL_SYSCLK_POLARITY;
  2576. else
  2577. value |= PMC_CNTRL_SYSCLK_POLARITY;
  2578. if (pmc->corereq_high)
  2579. value &= ~PMC_CNTRL_PWRREQ_POLARITY;
  2580. else
  2581. value |= PMC_CNTRL_PWRREQ_POLARITY;
  2582. /* configure the output polarity while the request is tristated */
  2583. tegra_pmc_writel(pmc, value, PMC_CNTRL);
  2584. /* now enable the request */
  2585. value = tegra_pmc_readl(pmc, PMC_CNTRL);
  2586. value |= PMC_CNTRL_SYSCLK_OE;
  2587. tegra_pmc_writel(pmc, value, PMC_CNTRL);
  2588. /* program core timings which are applicable only for suspend state */
  2589. if (pmc->suspend_mode != TEGRA_SUSPEND_NONE) {
  2590. osc = DIV_ROUND_UP(pmc->core_osc_time * 8192, 1000000);
  2591. pmu = DIV_ROUND_UP(pmc->core_pmu_time * 32768, 1000000);
  2592. off = DIV_ROUND_UP(pmc->core_off_time * 32768, 1000000);
  2593. tegra_pmc_writel(pmc, ((osc << 8) & 0xff00) | (pmu & 0xff),
  2594. PMC_COREPWRGOOD_TIMER);
  2595. tegra_pmc_writel(pmc, off, PMC_COREPWROFF_TIMER);
  2596. }
  2597. }
  2598. static void tegra20_pmc_setup_irq_polarity(struct tegra_pmc *pmc,
  2599. struct device_node *np,
  2600. bool invert)
  2601. {
  2602. u32 value;
  2603. value = tegra_pmc_readl(pmc, PMC_CNTRL);
  2604. if (invert)
  2605. value |= PMC_CNTRL_INTR_POLARITY;
  2606. else
  2607. value &= ~PMC_CNTRL_INTR_POLARITY;
  2608. tegra_pmc_writel(pmc, value, PMC_CNTRL);
  2609. }
  2610. static const struct tegra_pmc_soc tegra20_pmc_soc = {
  2611. .supports_core_domain = true,
  2612. .num_powergates = ARRAY_SIZE(tegra20_powergates),
  2613. .powergates = tegra20_powergates,
  2614. .num_cpu_powergates = 0,
  2615. .cpu_powergates = NULL,
  2616. .has_tsense_reset = false,
  2617. .has_gpu_clamps = false,
  2618. .needs_mbist_war = false,
  2619. .has_impl_33v_pwr = false,
  2620. .maybe_tz_only = false,
  2621. .num_io_pads = 0,
  2622. .io_pads = NULL,
  2623. .num_pin_descs = 0,
  2624. .pin_descs = NULL,
  2625. .regs = &tegra20_pmc_regs,
  2626. .init = tegra20_pmc_init,
  2627. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  2628. .powergate_set = tegra20_powergate_set,
  2629. .reset_sources = NULL,
  2630. .num_reset_sources = 0,
  2631. .reset_levels = NULL,
  2632. .num_reset_levels = 0,
  2633. .pmc_clks_data = NULL,
  2634. .num_pmc_clks = 0,
  2635. .has_blink_output = true,
  2636. .has_usb_sleepwalk = true,
  2637. .has_single_mmio_aperture = true,
  2638. };
  2639. static const char * const tegra30_powergates[] = {
  2640. [TEGRA_POWERGATE_CPU] = "cpu0",
  2641. [TEGRA_POWERGATE_3D] = "td",
  2642. [TEGRA_POWERGATE_VENC] = "venc",
  2643. [TEGRA_POWERGATE_VDEC] = "vdec",
  2644. [TEGRA_POWERGATE_PCIE] = "pcie",
  2645. [TEGRA_POWERGATE_L2] = "l2",
  2646. [TEGRA_POWERGATE_MPE] = "mpe",
  2647. [TEGRA_POWERGATE_HEG] = "heg",
  2648. [TEGRA_POWERGATE_SATA] = "sata",
  2649. [TEGRA_POWERGATE_CPU1] = "cpu1",
  2650. [TEGRA_POWERGATE_CPU2] = "cpu2",
  2651. [TEGRA_POWERGATE_CPU3] = "cpu3",
  2652. [TEGRA_POWERGATE_CELP] = "celp",
  2653. [TEGRA_POWERGATE_3D1] = "td2",
  2654. };
  2655. static const u8 tegra30_cpu_powergates[] = {
  2656. TEGRA_POWERGATE_CPU,
  2657. TEGRA_POWERGATE_CPU1,
  2658. TEGRA_POWERGATE_CPU2,
  2659. TEGRA_POWERGATE_CPU3,
  2660. };
  2661. static const char * const tegra30_reset_sources[] = {
  2662. "POWER_ON_RESET",
  2663. "WATCHDOG",
  2664. "SENSOR",
  2665. "SW_MAIN",
  2666. "LP0"
  2667. };
  2668. static const struct tegra_pmc_soc tegra30_pmc_soc = {
  2669. .supports_core_domain = true,
  2670. .num_powergates = ARRAY_SIZE(tegra30_powergates),
  2671. .powergates = tegra30_powergates,
  2672. .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates),
  2673. .cpu_powergates = tegra30_cpu_powergates,
  2674. .has_tsense_reset = true,
  2675. .has_gpu_clamps = false,
  2676. .needs_mbist_war = false,
  2677. .has_impl_33v_pwr = false,
  2678. .maybe_tz_only = false,
  2679. .num_io_pads = 0,
  2680. .io_pads = NULL,
  2681. .num_pin_descs = 0,
  2682. .pin_descs = NULL,
  2683. .regs = &tegra20_pmc_regs,
  2684. .init = tegra20_pmc_init,
  2685. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  2686. .powergate_set = tegra20_powergate_set,
  2687. .reset_sources = tegra30_reset_sources,
  2688. .num_reset_sources = ARRAY_SIZE(tegra30_reset_sources),
  2689. .reset_levels = NULL,
  2690. .num_reset_levels = 0,
  2691. .pmc_clks_data = tegra_pmc_clks_data,
  2692. .num_pmc_clks = ARRAY_SIZE(tegra_pmc_clks_data),
  2693. .has_blink_output = true,
  2694. .has_usb_sleepwalk = true,
  2695. .has_single_mmio_aperture = true,
  2696. };
  2697. static const char * const tegra114_powergates[] = {
  2698. [TEGRA_POWERGATE_CPU] = "crail",
  2699. [TEGRA_POWERGATE_3D] = "td",
  2700. [TEGRA_POWERGATE_VENC] = "venc",
  2701. [TEGRA_POWERGATE_VDEC] = "vdec",
  2702. [TEGRA_POWERGATE_MPE] = "mpe",
  2703. [TEGRA_POWERGATE_HEG] = "heg",
  2704. [TEGRA_POWERGATE_CPU1] = "cpu1",
  2705. [TEGRA_POWERGATE_CPU2] = "cpu2",
  2706. [TEGRA_POWERGATE_CPU3] = "cpu3",
  2707. [TEGRA_POWERGATE_CELP] = "celp",
  2708. [TEGRA_POWERGATE_CPU0] = "cpu0",
  2709. [TEGRA_POWERGATE_C0NC] = "c0nc",
  2710. [TEGRA_POWERGATE_C1NC] = "c1nc",
  2711. [TEGRA_POWERGATE_DIS] = "dis",
  2712. [TEGRA_POWERGATE_DISB] = "disb",
  2713. [TEGRA_POWERGATE_XUSBA] = "xusba",
  2714. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  2715. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  2716. };
  2717. static const u8 tegra114_cpu_powergates[] = {
  2718. TEGRA_POWERGATE_CPU0,
  2719. TEGRA_POWERGATE_CPU1,
  2720. TEGRA_POWERGATE_CPU2,
  2721. TEGRA_POWERGATE_CPU3,
  2722. };
  2723. static const struct tegra_pmc_soc tegra114_pmc_soc = {
  2724. .supports_core_domain = false,
  2725. .num_powergates = ARRAY_SIZE(tegra114_powergates),
  2726. .powergates = tegra114_powergates,
  2727. .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates),
  2728. .cpu_powergates = tegra114_cpu_powergates,
  2729. .has_tsense_reset = true,
  2730. .has_gpu_clamps = false,
  2731. .needs_mbist_war = false,
  2732. .has_impl_33v_pwr = false,
  2733. .maybe_tz_only = false,
  2734. .num_io_pads = 0,
  2735. .io_pads = NULL,
  2736. .num_pin_descs = 0,
  2737. .pin_descs = NULL,
  2738. .regs = &tegra20_pmc_regs,
  2739. .init = tegra20_pmc_init,
  2740. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  2741. .powergate_set = tegra114_powergate_set,
  2742. .reset_sources = tegra30_reset_sources,
  2743. .num_reset_sources = ARRAY_SIZE(tegra30_reset_sources),
  2744. .reset_levels = NULL,
  2745. .num_reset_levels = 0,
  2746. .pmc_clks_data = tegra_pmc_clks_data,
  2747. .num_pmc_clks = ARRAY_SIZE(tegra_pmc_clks_data),
  2748. .has_blink_output = true,
  2749. .has_usb_sleepwalk = true,
  2750. .has_single_mmio_aperture = true,
  2751. };
  2752. static const char * const tegra124_powergates[] = {
  2753. [TEGRA_POWERGATE_CPU] = "crail",
  2754. [TEGRA_POWERGATE_3D] = "3d",
  2755. [TEGRA_POWERGATE_VENC] = "venc",
  2756. [TEGRA_POWERGATE_PCIE] = "pcie",
  2757. [TEGRA_POWERGATE_VDEC] = "vdec",
  2758. [TEGRA_POWERGATE_MPE] = "mpe",
  2759. [TEGRA_POWERGATE_HEG] = "heg",
  2760. [TEGRA_POWERGATE_SATA] = "sata",
  2761. [TEGRA_POWERGATE_CPU1] = "cpu1",
  2762. [TEGRA_POWERGATE_CPU2] = "cpu2",
  2763. [TEGRA_POWERGATE_CPU3] = "cpu3",
  2764. [TEGRA_POWERGATE_CELP] = "celp",
  2765. [TEGRA_POWERGATE_CPU0] = "cpu0",
  2766. [TEGRA_POWERGATE_C0NC] = "c0nc",
  2767. [TEGRA_POWERGATE_C1NC] = "c1nc",
  2768. [TEGRA_POWERGATE_SOR] = "sor",
  2769. [TEGRA_POWERGATE_DIS] = "dis",
  2770. [TEGRA_POWERGATE_DISB] = "disb",
  2771. [TEGRA_POWERGATE_XUSBA] = "xusba",
  2772. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  2773. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  2774. [TEGRA_POWERGATE_VIC] = "vic",
  2775. [TEGRA_POWERGATE_IRAM] = "iram",
  2776. };
  2777. static const u8 tegra124_cpu_powergates[] = {
  2778. TEGRA_POWERGATE_CPU0,
  2779. TEGRA_POWERGATE_CPU1,
  2780. TEGRA_POWERGATE_CPU2,
  2781. TEGRA_POWERGATE_CPU3,
  2782. };
  2783. #define TEGRA_IO_PAD(_id, _dpd, _request, _status, _voltage, _name) \
  2784. ((struct tegra_io_pad_soc) { \
  2785. .id = (_id), \
  2786. .dpd = (_dpd), \
  2787. .request = (_request), \
  2788. .status = (_status), \
  2789. .voltage = (_voltage), \
  2790. .name = (_name), \
  2791. })
  2792. #define TEGRA_IO_PIN_DESC(_id, _name) \
  2793. ((struct pinctrl_pin_desc) { \
  2794. .number = (_id), \
  2795. .name = (_name), \
  2796. })
  2797. static const struct tegra_io_pad_soc tegra124_io_pads[] = {
  2798. TEGRA_IO_PAD(TEGRA_IO_PAD_AUDIO, 17, 0x1b8, 0x1bc, UINT_MAX, "audio"),
  2799. TEGRA_IO_PAD(TEGRA_IO_PAD_BB, 15, 0x1b8, 0x1bc, UINT_MAX, "bb"),
  2800. TEGRA_IO_PAD(TEGRA_IO_PAD_CAM, 4, 0x1c0, 0x1c4, UINT_MAX, "cam"),
  2801. TEGRA_IO_PAD(TEGRA_IO_PAD_COMP, 22, 0x1b8, 0x1bc, UINT_MAX, "comp"),
  2802. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIA, 0, 0x1b8, 0x1bc, UINT_MAX, "csia"),
  2803. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIB, 1, 0x1b8, 0x1bc, UINT_MAX, "csib"),
  2804. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIE, 12, 0x1c0, 0x1c4, UINT_MAX, "csie"),
  2805. TEGRA_IO_PAD(TEGRA_IO_PAD_DSI, 2, 0x1b8, 0x1bc, UINT_MAX, "dsi"),
  2806. TEGRA_IO_PAD(TEGRA_IO_PAD_DSIB, 7, 0x1c0, 0x1c4, UINT_MAX, "dsib"),
  2807. TEGRA_IO_PAD(TEGRA_IO_PAD_DSIC, 8, 0x1c0, 0x1c4, UINT_MAX, "dsic"),
  2808. TEGRA_IO_PAD(TEGRA_IO_PAD_DSID, 9, 0x1c0, 0x1c4, UINT_MAX, "dsid"),
  2809. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI, 28, 0x1b8, 0x1bc, UINT_MAX, "hdmi"),
  2810. TEGRA_IO_PAD(TEGRA_IO_PAD_HSIC, 19, 0x1b8, 0x1bc, UINT_MAX, "hsic"),
  2811. TEGRA_IO_PAD(TEGRA_IO_PAD_HV, 6, 0x1c0, 0x1c4, UINT_MAX, "hv"),
  2812. TEGRA_IO_PAD(TEGRA_IO_PAD_LVDS, 25, 0x1c0, 0x1c4, UINT_MAX, "lvds"),
  2813. TEGRA_IO_PAD(TEGRA_IO_PAD_MIPI_BIAS, 3, 0x1b8, 0x1bc, UINT_MAX, "mipi-bias"),
  2814. TEGRA_IO_PAD(TEGRA_IO_PAD_NAND, 13, 0x1b8, 0x1bc, UINT_MAX, "nand"),
  2815. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_BIAS, 4, 0x1b8, 0x1bc, UINT_MAX, "pex-bias"),
  2816. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK1, 5, 0x1b8, 0x1bc, UINT_MAX, "pex-clk1"),
  2817. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK2, 6, 0x1b8, 0x1bc, UINT_MAX, "pex-clk2"),
  2818. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CNTRL, 0, 0x1c0, 0x1c4, UINT_MAX, "pex-cntrl"),
  2819. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC1, 1, 0x1c0, 0x1c4, UINT_MAX, "sdmmc1"),
  2820. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC3, 2, 0x1c0, 0x1c4, UINT_MAX, "sdmmc3"),
  2821. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC4, 3, 0x1c0, 0x1c4, UINT_MAX, "sdmmc4"),
  2822. TEGRA_IO_PAD(TEGRA_IO_PAD_SYS_DDC, 26, 0x1c0, 0x1c4, UINT_MAX, "sys_ddc"),
  2823. TEGRA_IO_PAD(TEGRA_IO_PAD_UART, 14, 0x1b8, 0x1bc, UINT_MAX, "uart"),
  2824. TEGRA_IO_PAD(TEGRA_IO_PAD_USB0, 9, 0x1b8, 0x1bc, UINT_MAX, "usb0"),
  2825. TEGRA_IO_PAD(TEGRA_IO_PAD_USB1, 10, 0x1b8, 0x1bc, UINT_MAX, "usb1"),
  2826. TEGRA_IO_PAD(TEGRA_IO_PAD_USB2, 11, 0x1b8, 0x1bc, UINT_MAX, "usb2"),
  2827. TEGRA_IO_PAD(TEGRA_IO_PAD_USB_BIAS, 12, 0x1b8, 0x1bc, UINT_MAX, "usb_bias"),
  2828. };
  2829. static const struct pinctrl_pin_desc tegra124_pin_descs[] = {
  2830. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AUDIO, "audio"),
  2831. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_BB, "bb"),
  2832. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CAM, "cam"),
  2833. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_COMP, "comp"),
  2834. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIA, "csia"),
  2835. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIB, "csib"),
  2836. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIE, "csie"),
  2837. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSI, "dsi"),
  2838. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSIB, "dsib"),
  2839. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSIC, "dsic"),
  2840. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSID, "dsid"),
  2841. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI, "hdmi"),
  2842. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HSIC, "hsic"),
  2843. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HV, "hv"),
  2844. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_LVDS, "lvds"),
  2845. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_MIPI_BIAS, "mipi-bias"),
  2846. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_NAND, "nand"),
  2847. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_BIAS, "pex-bias"),
  2848. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK1, "pex-clk1"),
  2849. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK2, "pex-clk2"),
  2850. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CNTRL, "pex-cntrl"),
  2851. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC1, "sdmmc1"),
  2852. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC3, "sdmmc3"),
  2853. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC4, "sdmmc4"),
  2854. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SYS_DDC, "sys_ddc"),
  2855. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UART, "uart"),
  2856. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB0, "usb0"),
  2857. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB1, "usb1"),
  2858. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB2, "usb2"),
  2859. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB_BIAS, "usb_bias"),
  2860. };
  2861. static const struct tegra_pmc_soc tegra124_pmc_soc = {
  2862. .supports_core_domain = false,
  2863. .num_powergates = ARRAY_SIZE(tegra124_powergates),
  2864. .powergates = tegra124_powergates,
  2865. .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates),
  2866. .cpu_powergates = tegra124_cpu_powergates,
  2867. .has_tsense_reset = true,
  2868. .has_gpu_clamps = true,
  2869. .needs_mbist_war = false,
  2870. .has_impl_33v_pwr = false,
  2871. .maybe_tz_only = false,
  2872. .num_io_pads = ARRAY_SIZE(tegra124_io_pads),
  2873. .io_pads = tegra124_io_pads,
  2874. .num_pin_descs = ARRAY_SIZE(tegra124_pin_descs),
  2875. .pin_descs = tegra124_pin_descs,
  2876. .regs = &tegra20_pmc_regs,
  2877. .init = tegra20_pmc_init,
  2878. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  2879. .powergate_set = tegra114_powergate_set,
  2880. .reset_sources = tegra30_reset_sources,
  2881. .num_reset_sources = ARRAY_SIZE(tegra30_reset_sources),
  2882. .reset_levels = NULL,
  2883. .num_reset_levels = 0,
  2884. .pmc_clks_data = tegra_pmc_clks_data,
  2885. .num_pmc_clks = ARRAY_SIZE(tegra_pmc_clks_data),
  2886. .has_blink_output = true,
  2887. .has_usb_sleepwalk = true,
  2888. .has_single_mmio_aperture = true,
  2889. };
  2890. static const char * const tegra210_powergates[] = {
  2891. [TEGRA_POWERGATE_CPU] = "crail",
  2892. [TEGRA_POWERGATE_3D] = "3d",
  2893. [TEGRA_POWERGATE_VENC] = "venc",
  2894. [TEGRA_POWERGATE_PCIE] = "pcie",
  2895. [TEGRA_POWERGATE_MPE] = "mpe",
  2896. [TEGRA_POWERGATE_SATA] = "sata",
  2897. [TEGRA_POWERGATE_CPU1] = "cpu1",
  2898. [TEGRA_POWERGATE_CPU2] = "cpu2",
  2899. [TEGRA_POWERGATE_CPU3] = "cpu3",
  2900. [TEGRA_POWERGATE_CPU0] = "cpu0",
  2901. [TEGRA_POWERGATE_C0NC] = "c0nc",
  2902. [TEGRA_POWERGATE_SOR] = "sor",
  2903. [TEGRA_POWERGATE_DIS] = "dis",
  2904. [TEGRA_POWERGATE_DISB] = "disb",
  2905. [TEGRA_POWERGATE_XUSBA] = "xusba",
  2906. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  2907. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  2908. [TEGRA_POWERGATE_VIC] = "vic",
  2909. [TEGRA_POWERGATE_IRAM] = "iram",
  2910. [TEGRA_POWERGATE_NVDEC] = "nvdec",
  2911. [TEGRA_POWERGATE_NVJPG] = "nvjpg",
  2912. [TEGRA_POWERGATE_AUD] = "aud",
  2913. [TEGRA_POWERGATE_DFD] = "dfd",
  2914. [TEGRA_POWERGATE_VE2] = "ve2",
  2915. };
  2916. static const u8 tegra210_cpu_powergates[] = {
  2917. TEGRA_POWERGATE_CPU0,
  2918. TEGRA_POWERGATE_CPU1,
  2919. TEGRA_POWERGATE_CPU2,
  2920. TEGRA_POWERGATE_CPU3,
  2921. };
  2922. static const struct tegra_io_pad_soc tegra210_io_pads[] = {
  2923. TEGRA_IO_PAD(TEGRA_IO_PAD_AUDIO, 17, 0x1b8, 0x1bc, 5, "audio"),
  2924. TEGRA_IO_PAD(TEGRA_IO_PAD_AUDIO_HV, 29, 0x1c0, 0x1c4, 18, "audio-hv"),
  2925. TEGRA_IO_PAD(TEGRA_IO_PAD_CAM, 4, 0x1c0, 0x1c4, 10, "cam"),
  2926. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIA, 0, 0x1b8, 0x1bc, UINT_MAX, "csia"),
  2927. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIB, 1, 0x1b8, 0x1bc, UINT_MAX, "csib"),
  2928. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIC, 10, 0x1c0, 0x1c4, UINT_MAX, "csic"),
  2929. TEGRA_IO_PAD(TEGRA_IO_PAD_CSID, 11, 0x1c0, 0x1c4, UINT_MAX, "csid"),
  2930. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIE, 12, 0x1c0, 0x1c4, UINT_MAX, "csie"),
  2931. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIF, 13, 0x1c0, 0x1c4, UINT_MAX, "csif"),
  2932. TEGRA_IO_PAD(TEGRA_IO_PAD_DBG, 25, 0x1b8, 0x1bc, 19, "dbg"),
  2933. TEGRA_IO_PAD(TEGRA_IO_PAD_DEBUG_NONAO, 26, 0x1b8, 0x1bc, UINT_MAX, "debug-nonao"),
  2934. TEGRA_IO_PAD(TEGRA_IO_PAD_DMIC, 18, 0x1c0, 0x1c4, 20, "dmic"),
  2935. TEGRA_IO_PAD(TEGRA_IO_PAD_DP, 19, 0x1c0, 0x1c4, UINT_MAX, "dp"),
  2936. TEGRA_IO_PAD(TEGRA_IO_PAD_DSI, 2, 0x1b8, 0x1bc, UINT_MAX, "dsi"),
  2937. TEGRA_IO_PAD(TEGRA_IO_PAD_DSIB, 7, 0x1c0, 0x1c4, UINT_MAX, "dsib"),
  2938. TEGRA_IO_PAD(TEGRA_IO_PAD_DSIC, 8, 0x1c0, 0x1c4, UINT_MAX, "dsic"),
  2939. TEGRA_IO_PAD(TEGRA_IO_PAD_DSID, 9, 0x1c0, 0x1c4, UINT_MAX, "dsid"),
  2940. TEGRA_IO_PAD(TEGRA_IO_PAD_EMMC, 3, 0x1c0, 0x1c4, UINT_MAX, "emmc"),
  2941. TEGRA_IO_PAD(TEGRA_IO_PAD_EMMC2, 5, 0x1c0, 0x1c4, UINT_MAX, "emmc2"),
  2942. TEGRA_IO_PAD(TEGRA_IO_PAD_GPIO, 27, 0x1b8, 0x1bc, 21, "gpio"),
  2943. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI, 28, 0x1b8, 0x1bc, UINT_MAX, "hdmi"),
  2944. TEGRA_IO_PAD(TEGRA_IO_PAD_HSIC, 19, 0x1b8, 0x1bc, UINT_MAX, "hsic"),
  2945. TEGRA_IO_PAD(TEGRA_IO_PAD_LVDS, 25, 0x1c0, 0x1c4, UINT_MAX, "lvds"),
  2946. TEGRA_IO_PAD(TEGRA_IO_PAD_MIPI_BIAS, 3, 0x1b8, 0x1bc, UINT_MAX, "mipi-bias"),
  2947. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_BIAS, 4, 0x1b8, 0x1bc, UINT_MAX, "pex-bias"),
  2948. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK1, 5, 0x1b8, 0x1bc, UINT_MAX, "pex-clk1"),
  2949. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK2, 6, 0x1b8, 0x1bc, UINT_MAX, "pex-clk2"),
  2950. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CNTRL, UINT_MAX, UINT_MAX, UINT_MAX, 11, "pex-cntrl"),
  2951. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC1, 1, 0x1c0, 0x1c4, 12, "sdmmc1"),
  2952. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC3, 2, 0x1c0, 0x1c4, 13, "sdmmc3"),
  2953. TEGRA_IO_PAD(TEGRA_IO_PAD_SPI, 14, 0x1c0, 0x1c4, 22, "spi"),
  2954. TEGRA_IO_PAD(TEGRA_IO_PAD_SPI_HV, 15, 0x1c0, 0x1c4, 23, "spi-hv"),
  2955. TEGRA_IO_PAD(TEGRA_IO_PAD_UART, 14, 0x1b8, 0x1bc, 2, "uart"),
  2956. TEGRA_IO_PAD(TEGRA_IO_PAD_USB0, 9, 0x1b8, 0x1bc, UINT_MAX, "usb0"),
  2957. TEGRA_IO_PAD(TEGRA_IO_PAD_USB1, 10, 0x1b8, 0x1bc, UINT_MAX, "usb1"),
  2958. TEGRA_IO_PAD(TEGRA_IO_PAD_USB2, 11, 0x1b8, 0x1bc, UINT_MAX, "usb2"),
  2959. TEGRA_IO_PAD(TEGRA_IO_PAD_USB3, 18, 0x1b8, 0x1bc, UINT_MAX, "usb3"),
  2960. TEGRA_IO_PAD(TEGRA_IO_PAD_USB_BIAS, 12, 0x1b8, 0x1bc, UINT_MAX, "usb-bias"),
  2961. };
  2962. static const struct pinctrl_pin_desc tegra210_pin_descs[] = {
  2963. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AUDIO, "audio"),
  2964. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AUDIO_HV, "audio-hv"),
  2965. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CAM, "cam"),
  2966. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIA, "csia"),
  2967. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIB, "csib"),
  2968. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIC, "csic"),
  2969. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSID, "csid"),
  2970. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIE, "csie"),
  2971. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIF, "csif"),
  2972. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DBG, "dbg"),
  2973. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DEBUG_NONAO, "debug-nonao"),
  2974. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DMIC, "dmic"),
  2975. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DP, "dp"),
  2976. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSI, "dsi"),
  2977. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSIB, "dsib"),
  2978. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSIC, "dsic"),
  2979. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSID, "dsid"),
  2980. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_EMMC, "emmc"),
  2981. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_EMMC2, "emmc2"),
  2982. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_GPIO, "gpio"),
  2983. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI, "hdmi"),
  2984. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HSIC, "hsic"),
  2985. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_LVDS, "lvds"),
  2986. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_MIPI_BIAS, "mipi-bias"),
  2987. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_BIAS, "pex-bias"),
  2988. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK1, "pex-clk1"),
  2989. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK2, "pex-clk2"),
  2990. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CNTRL, "pex-cntrl"),
  2991. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC1, "sdmmc1"),
  2992. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC3, "sdmmc3"),
  2993. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SPI, "spi"),
  2994. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SPI_HV, "spi-hv"),
  2995. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UART, "uart"),
  2996. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB0, "usb0"),
  2997. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB1, "usb1"),
  2998. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB2, "usb2"),
  2999. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB3, "usb3"),
  3000. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB_BIAS, "usb-bias"),
  3001. };
  3002. static const char * const tegra210_reset_sources[] = {
  3003. "POWER_ON_RESET",
  3004. "WATCHDOG",
  3005. "SENSOR",
  3006. "SW_MAIN",
  3007. "LP0",
  3008. "AOTAG"
  3009. };
  3010. static const struct tegra_wake_event tegra210_wake_events[] = {
  3011. TEGRA_WAKE_IRQ("rtc", 16, 2),
  3012. TEGRA_WAKE_IRQ("pmu", 51, 86),
  3013. };
  3014. static const struct tegra_pmc_soc tegra210_pmc_soc = {
  3015. .supports_core_domain = false,
  3016. .num_powergates = ARRAY_SIZE(tegra210_powergates),
  3017. .powergates = tegra210_powergates,
  3018. .num_cpu_powergates = ARRAY_SIZE(tegra210_cpu_powergates),
  3019. .cpu_powergates = tegra210_cpu_powergates,
  3020. .has_tsense_reset = true,
  3021. .has_gpu_clamps = true,
  3022. .needs_mbist_war = true,
  3023. .has_impl_33v_pwr = false,
  3024. .maybe_tz_only = true,
  3025. .num_io_pads = ARRAY_SIZE(tegra210_io_pads),
  3026. .io_pads = tegra210_io_pads,
  3027. .num_pin_descs = ARRAY_SIZE(tegra210_pin_descs),
  3028. .pin_descs = tegra210_pin_descs,
  3029. .regs = &tegra20_pmc_regs,
  3030. .init = tegra20_pmc_init,
  3031. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  3032. .powergate_set = tegra114_powergate_set,
  3033. .irq_set_wake = tegra210_pmc_irq_set_wake,
  3034. .irq_set_type = tegra210_pmc_irq_set_type,
  3035. .reset_sources = tegra210_reset_sources,
  3036. .num_reset_sources = ARRAY_SIZE(tegra210_reset_sources),
  3037. .reset_levels = NULL,
  3038. .num_reset_levels = 0,
  3039. .num_wake_events = ARRAY_SIZE(tegra210_wake_events),
  3040. .wake_events = tegra210_wake_events,
  3041. .pmc_clks_data = tegra_pmc_clks_data,
  3042. .num_pmc_clks = ARRAY_SIZE(tegra_pmc_clks_data),
  3043. .has_blink_output = true,
  3044. .has_usb_sleepwalk = true,
  3045. .has_single_mmio_aperture = true,
  3046. };
  3047. static const struct tegra_io_pad_soc tegra186_io_pads[] = {
  3048. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIA, 0, 0x74, 0x78, UINT_MAX, "csia"),
  3049. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIB, 1, 0x74, 0x78, UINT_MAX, "csib"),
  3050. TEGRA_IO_PAD(TEGRA_IO_PAD_DSI, 2, 0x74, 0x78, UINT_MAX, "dsi"),
  3051. TEGRA_IO_PAD(TEGRA_IO_PAD_MIPI_BIAS, 3, 0x74, 0x78, UINT_MAX, "mipi-bias"),
  3052. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK_BIAS, 4, 0x74, 0x78, UINT_MAX, "pex-clk-bias"),
  3053. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK3, 5, 0x74, 0x78, UINT_MAX, "pex-clk3"),
  3054. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK2, 6, 0x74, 0x78, UINT_MAX, "pex-clk2"),
  3055. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK1, 7, 0x74, 0x78, UINT_MAX, "pex-clk1"),
  3056. TEGRA_IO_PAD(TEGRA_IO_PAD_USB0, 9, 0x74, 0x78, UINT_MAX, "usb0"),
  3057. TEGRA_IO_PAD(TEGRA_IO_PAD_USB1, 10, 0x74, 0x78, UINT_MAX, "usb1"),
  3058. TEGRA_IO_PAD(TEGRA_IO_PAD_USB2, 11, 0x74, 0x78, UINT_MAX, "usb2"),
  3059. TEGRA_IO_PAD(TEGRA_IO_PAD_USB_BIAS, 12, 0x74, 0x78, UINT_MAX, "usb-bias"),
  3060. TEGRA_IO_PAD(TEGRA_IO_PAD_UART, 14, 0x74, 0x78, UINT_MAX, "uart"),
  3061. TEGRA_IO_PAD(TEGRA_IO_PAD_AUDIO, 17, 0x74, 0x78, UINT_MAX, "audio"),
  3062. TEGRA_IO_PAD(TEGRA_IO_PAD_HSIC, 19, 0x74, 0x78, UINT_MAX, "hsic"),
  3063. TEGRA_IO_PAD(TEGRA_IO_PAD_DBG, 25, 0x74, 0x78, UINT_MAX, "dbg"),
  3064. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI_DP0, 28, 0x74, 0x78, UINT_MAX, "hdmi-dp0"),
  3065. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI_DP1, 29, 0x74, 0x78, UINT_MAX, "hdmi-dp1"),
  3066. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CNTRL, 0, 0x7c, 0x80, UINT_MAX, "pex-cntrl"),
  3067. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC2_HV, 2, 0x7c, 0x80, 5, "sdmmc2-hv"),
  3068. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC4, 4, 0x7c, 0x80, UINT_MAX, "sdmmc4"),
  3069. TEGRA_IO_PAD(TEGRA_IO_PAD_CAM, 6, 0x7c, 0x80, UINT_MAX, "cam"),
  3070. TEGRA_IO_PAD(TEGRA_IO_PAD_DSIB, 8, 0x7c, 0x80, UINT_MAX, "dsib"),
  3071. TEGRA_IO_PAD(TEGRA_IO_PAD_DSIC, 9, 0x7c, 0x80, UINT_MAX, "dsic"),
  3072. TEGRA_IO_PAD(TEGRA_IO_PAD_DSID, 10, 0x7c, 0x80, UINT_MAX, "dsid"),
  3073. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIC, 11, 0x7c, 0x80, UINT_MAX, "csic"),
  3074. TEGRA_IO_PAD(TEGRA_IO_PAD_CSID, 12, 0x7c, 0x80, UINT_MAX, "csid"),
  3075. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIE, 13, 0x7c, 0x80, UINT_MAX, "csie"),
  3076. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIF, 14, 0x7c, 0x80, UINT_MAX, "csif"),
  3077. TEGRA_IO_PAD(TEGRA_IO_PAD_SPI, 15, 0x7c, 0x80, UINT_MAX, "spi"),
  3078. TEGRA_IO_PAD(TEGRA_IO_PAD_UFS, 17, 0x7c, 0x80, UINT_MAX, "ufs"),
  3079. TEGRA_IO_PAD(TEGRA_IO_PAD_DMIC_HV, 20, 0x7c, 0x80, 2, "dmic-hv"),
  3080. TEGRA_IO_PAD(TEGRA_IO_PAD_EDP, 21, 0x7c, 0x80, UINT_MAX, "edp"),
  3081. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC1_HV, 23, 0x7c, 0x80, 4, "sdmmc1-hv"),
  3082. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC3_HV, 24, 0x7c, 0x80, 6, "sdmmc3-hv"),
  3083. TEGRA_IO_PAD(TEGRA_IO_PAD_CONN, 28, 0x7c, 0x80, UINT_MAX, "conn"),
  3084. TEGRA_IO_PAD(TEGRA_IO_PAD_AUDIO_HV, 29, 0x7c, 0x80, 1, "audio-hv"),
  3085. TEGRA_IO_PAD(TEGRA_IO_PAD_AO_HV, UINT_MAX, UINT_MAX, UINT_MAX, 0, "ao-hv"),
  3086. };
  3087. static const struct pinctrl_pin_desc tegra186_pin_descs[] = {
  3088. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIA, "csia"),
  3089. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIB, "csib"),
  3090. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSI, "dsi"),
  3091. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_MIPI_BIAS, "mipi-bias"),
  3092. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK_BIAS, "pex-clk-bias"),
  3093. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK3, "pex-clk3"),
  3094. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK2, "pex-clk2"),
  3095. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK1, "pex-clk1"),
  3096. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB0, "usb0"),
  3097. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB1, "usb1"),
  3098. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB2, "usb2"),
  3099. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_USB_BIAS, "usb-bias"),
  3100. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UART, "uart"),
  3101. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AUDIO, "audio"),
  3102. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HSIC, "hsic"),
  3103. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DBG, "dbg"),
  3104. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI_DP0, "hdmi-dp0"),
  3105. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI_DP1, "hdmi-dp1"),
  3106. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CNTRL, "pex-cntrl"),
  3107. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC2_HV, "sdmmc2-hv"),
  3108. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC4, "sdmmc4"),
  3109. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CAM, "cam"),
  3110. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSIB, "dsib"),
  3111. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSIC, "dsic"),
  3112. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DSID, "dsid"),
  3113. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIC, "csic"),
  3114. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSID, "csid"),
  3115. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIE, "csie"),
  3116. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIF, "csif"),
  3117. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SPI, "spi"),
  3118. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UFS, "ufs"),
  3119. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DMIC_HV, "dmic-hv"),
  3120. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_EDP, "edp"),
  3121. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC1_HV, "sdmmc1-hv"),
  3122. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC3_HV, "sdmmc3-hv"),
  3123. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CONN, "conn"),
  3124. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AUDIO_HV, "audio-hv"),
  3125. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AO_HV, "ao-hv"),
  3126. };
  3127. static const struct tegra_pmc_regs tegra186_pmc_regs = {
  3128. .scratch0 = 0x2000,
  3129. .rst_status = 0x70,
  3130. .rst_source_shift = 0x2,
  3131. .rst_source_mask = 0x3c,
  3132. .rst_level_shift = 0x0,
  3133. .rst_level_mask = 0x3,
  3134. };
  3135. static void tegra186_pmc_init(struct tegra_pmc *pmc)
  3136. {
  3137. pmc->syscore.suspend = tegra186_pmc_wake_syscore_suspend;
  3138. pmc->syscore.resume = tegra186_pmc_wake_syscore_resume;
  3139. register_syscore_ops(&pmc->syscore);
  3140. }
  3141. static void tegra186_pmc_setup_irq_polarity(struct tegra_pmc *pmc,
  3142. struct device_node *np,
  3143. bool invert)
  3144. {
  3145. struct resource regs;
  3146. void __iomem *wake;
  3147. u32 value;
  3148. int index;
  3149. index = of_property_match_string(np, "reg-names", "wake");
  3150. if (index < 0) {
  3151. dev_err(pmc->dev, "failed to find PMC wake registers\n");
  3152. return;
  3153. }
  3154. of_address_to_resource(np, index, &regs);
  3155. wake = ioremap(regs.start, resource_size(&regs));
  3156. if (!wake) {
  3157. dev_err(pmc->dev, "failed to map PMC wake registers\n");
  3158. return;
  3159. }
  3160. value = readl(wake + WAKE_AOWAKE_CTRL);
  3161. if (invert)
  3162. value |= WAKE_AOWAKE_CTRL_INTR_POLARITY;
  3163. else
  3164. value &= ~WAKE_AOWAKE_CTRL_INTR_POLARITY;
  3165. writel(value, wake + WAKE_AOWAKE_CTRL);
  3166. iounmap(wake);
  3167. }
  3168. static const char * const tegra186_reset_sources[] = {
  3169. "SYS_RESET",
  3170. "AOWDT",
  3171. "MCCPLEXWDT",
  3172. "BPMPWDT",
  3173. "SCEWDT",
  3174. "SPEWDT",
  3175. "APEWDT",
  3176. "BCCPLEXWDT",
  3177. "SENSOR",
  3178. "AOTAG",
  3179. "VFSENSOR",
  3180. "SWREST",
  3181. "SC7",
  3182. "HSM",
  3183. "CORESIGHT"
  3184. };
  3185. static const char * const tegra186_reset_levels[] = {
  3186. "L0", "L1", "L2", "WARM"
  3187. };
  3188. static const struct tegra_wake_event tegra186_wake_events[] = {
  3189. TEGRA_WAKE_IRQ("pmu", 24, 209),
  3190. TEGRA_WAKE_GPIO("power", 29, 1, TEGRA186_AON_GPIO(FF, 0)),
  3191. TEGRA_WAKE_IRQ("rtc", 73, 10),
  3192. };
  3193. static const struct tegra_pmc_soc tegra186_pmc_soc = {
  3194. .supports_core_domain = false,
  3195. .num_powergates = 0,
  3196. .powergates = NULL,
  3197. .num_cpu_powergates = 0,
  3198. .cpu_powergates = NULL,
  3199. .has_tsense_reset = false,
  3200. .has_gpu_clamps = false,
  3201. .needs_mbist_war = false,
  3202. .has_impl_33v_pwr = true,
  3203. .maybe_tz_only = false,
  3204. .num_io_pads = ARRAY_SIZE(tegra186_io_pads),
  3205. .io_pads = tegra186_io_pads,
  3206. .num_pin_descs = ARRAY_SIZE(tegra186_pin_descs),
  3207. .pin_descs = tegra186_pin_descs,
  3208. .regs = &tegra186_pmc_regs,
  3209. .init = tegra186_pmc_init,
  3210. .setup_irq_polarity = tegra186_pmc_setup_irq_polarity,
  3211. .set_wake_filters = tegra186_pmc_set_wake_filters,
  3212. .irq_set_wake = tegra186_pmc_irq_set_wake,
  3213. .irq_set_type = tegra186_pmc_irq_set_type,
  3214. .reset_sources = tegra186_reset_sources,
  3215. .num_reset_sources = ARRAY_SIZE(tegra186_reset_sources),
  3216. .reset_levels = tegra186_reset_levels,
  3217. .num_reset_levels = ARRAY_SIZE(tegra186_reset_levels),
  3218. .num_wake_events = ARRAY_SIZE(tegra186_wake_events),
  3219. .wake_events = tegra186_wake_events,
  3220. .max_wake_events = 96,
  3221. .max_wake_vectors = 3,
  3222. .pmc_clks_data = NULL,
  3223. .num_pmc_clks = 0,
  3224. .has_blink_output = false,
  3225. .has_usb_sleepwalk = false,
  3226. .has_single_mmio_aperture = false,
  3227. };
  3228. static const struct tegra_io_pad_soc tegra194_io_pads[] = {
  3229. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIA, 0, 0x74, 0x78, UINT_MAX, "csia"),
  3230. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIB, 1, 0x74, 0x78, UINT_MAX, "csib"),
  3231. TEGRA_IO_PAD(TEGRA_IO_PAD_MIPI_BIAS, 3, 0x74, 0x78, UINT_MAX, "mipi-bias"),
  3232. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK_BIAS, 4, 0x74, 0x78, UINT_MAX, "pex-clk-bias"),
  3233. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK3, 5, 0x74, 0x78, UINT_MAX, "pex-clk3"),
  3234. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK2, 6, 0x74, 0x78, UINT_MAX, "pex-clk2"),
  3235. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK1, 7, 0x74, 0x78, UINT_MAX, "pex-clk1"),
  3236. TEGRA_IO_PAD(TEGRA_IO_PAD_EQOS, 8, 0x74, 0x78, UINT_MAX, "eqos"),
  3237. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK_2_BIAS, 9, 0x74, 0x78, UINT_MAX, "pex-clk-2-bias"),
  3238. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CLK_2, 10, 0x74, 0x78, UINT_MAX, "pex-clk-2"),
  3239. TEGRA_IO_PAD(TEGRA_IO_PAD_DAP3, 11, 0x74, 0x78, UINT_MAX, "dap3"),
  3240. TEGRA_IO_PAD(TEGRA_IO_PAD_DAP5, 12, 0x74, 0x78, UINT_MAX, "dap5"),
  3241. TEGRA_IO_PAD(TEGRA_IO_PAD_UART, 14, 0x74, 0x78, UINT_MAX, "uart"),
  3242. TEGRA_IO_PAD(TEGRA_IO_PAD_PWR_CTL, 15, 0x74, 0x78, UINT_MAX, "pwr-ctl"),
  3243. TEGRA_IO_PAD(TEGRA_IO_PAD_SOC_GPIO53, 16, 0x74, 0x78, UINT_MAX, "soc-gpio53"),
  3244. TEGRA_IO_PAD(TEGRA_IO_PAD_AUDIO, 17, 0x74, 0x78, UINT_MAX, "audio"),
  3245. TEGRA_IO_PAD(TEGRA_IO_PAD_GP_PWM2, 18, 0x74, 0x78, UINT_MAX, "gp-pwm2"),
  3246. TEGRA_IO_PAD(TEGRA_IO_PAD_GP_PWM3, 19, 0x74, 0x78, UINT_MAX, "gp-pwm3"),
  3247. TEGRA_IO_PAD(TEGRA_IO_PAD_SOC_GPIO12, 20, 0x74, 0x78, UINT_MAX, "soc-gpio12"),
  3248. TEGRA_IO_PAD(TEGRA_IO_PAD_SOC_GPIO13, 21, 0x74, 0x78, UINT_MAX, "soc-gpio13"),
  3249. TEGRA_IO_PAD(TEGRA_IO_PAD_SOC_GPIO10, 22, 0x74, 0x78, UINT_MAX, "soc-gpio10"),
  3250. TEGRA_IO_PAD(TEGRA_IO_PAD_UART4, 23, 0x74, 0x78, UINT_MAX, "uart4"),
  3251. TEGRA_IO_PAD(TEGRA_IO_PAD_UART5, 24, 0x74, 0x78, UINT_MAX, "uart5"),
  3252. TEGRA_IO_PAD(TEGRA_IO_PAD_DBG, 25, 0x74, 0x78, UINT_MAX, "dbg"),
  3253. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI_DP3, 26, 0x74, 0x78, UINT_MAX, "hdmi-dp3"),
  3254. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI_DP2, 27, 0x74, 0x78, UINT_MAX, "hdmi-dp2"),
  3255. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI_DP0, 28, 0x74, 0x78, UINT_MAX, "hdmi-dp0"),
  3256. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI_DP1, 29, 0x74, 0x78, UINT_MAX, "hdmi-dp1"),
  3257. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CNTRL, 0, 0x7c, 0x80, UINT_MAX, "pex-cntrl"),
  3258. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_CTL2, 1, 0x7c, 0x80, UINT_MAX, "pex-ctl2"),
  3259. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_L0_RST, 2, 0x7c, 0x80, UINT_MAX, "pex-l0-rst"),
  3260. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_L1_RST, 3, 0x7c, 0x80, UINT_MAX, "pex-l1-rst"),
  3261. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC4, 4, 0x7c, 0x80, UINT_MAX, "sdmmc4"),
  3262. TEGRA_IO_PAD(TEGRA_IO_PAD_PEX_L5_RST, 5, 0x7c, 0x80, UINT_MAX, "pex-l5-rst"),
  3263. TEGRA_IO_PAD(TEGRA_IO_PAD_CAM, 6, 0x7c, 0x80, UINT_MAX, "cam"),
  3264. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIC, 11, 0x7c, 0x80, UINT_MAX, "csic"),
  3265. TEGRA_IO_PAD(TEGRA_IO_PAD_CSID, 12, 0x7c, 0x80, UINT_MAX, "csid"),
  3266. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIE, 13, 0x7c, 0x80, UINT_MAX, "csie"),
  3267. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIF, 14, 0x7c, 0x80, UINT_MAX, "csif"),
  3268. TEGRA_IO_PAD(TEGRA_IO_PAD_SPI, 15, 0x7c, 0x80, UINT_MAX, "spi"),
  3269. TEGRA_IO_PAD(TEGRA_IO_PAD_UFS, 17, 0x7c, 0x80, UINT_MAX, "ufs"),
  3270. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIG, 18, 0x7c, 0x80, UINT_MAX, "csig"),
  3271. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIH, 19, 0x7c, 0x80, UINT_MAX, "csih"),
  3272. TEGRA_IO_PAD(TEGRA_IO_PAD_EDP, 21, 0x7c, 0x80, UINT_MAX, "edp"),
  3273. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC1_HV, 23, 0x7c, 0x80, 4, "sdmmc1-hv"),
  3274. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC3_HV, 24, 0x7c, 0x80, 6, "sdmmc3-hv"),
  3275. TEGRA_IO_PAD(TEGRA_IO_PAD_CONN, 28, 0x7c, 0x80, UINT_MAX, "conn"),
  3276. TEGRA_IO_PAD(TEGRA_IO_PAD_AUDIO_HV, 29, 0x7c, 0x80, 1, "audio-hv"),
  3277. TEGRA_IO_PAD(TEGRA_IO_PAD_AO_HV, UINT_MAX, UINT_MAX, UINT_MAX, 0, "ao-hv"),
  3278. };
  3279. static const struct pinctrl_pin_desc tegra194_pin_descs[] = {
  3280. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIA, "csia"),
  3281. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIB, "csib"),
  3282. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_MIPI_BIAS, "mipi-bias"),
  3283. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK_BIAS, "pex-clk-bias"),
  3284. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK3, "pex-clk3"),
  3285. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK2, "pex-clk2"),
  3286. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK1, "pex-clk1"),
  3287. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_EQOS, "eqos"),
  3288. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK_2_BIAS, "pex-clk-2-bias"),
  3289. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CLK_2, "pex-clk-2"),
  3290. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DAP3, "dap3"),
  3291. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DAP5, "dap5"),
  3292. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UART, "uart"),
  3293. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PWR_CTL, "pwr-ctl"),
  3294. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SOC_GPIO53, "soc-gpio53"),
  3295. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AUDIO, "audio"),
  3296. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_GP_PWM2, "gp-pwm2"),
  3297. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_GP_PWM3, "gp-pwm3"),
  3298. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SOC_GPIO12, "soc-gpio12"),
  3299. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SOC_GPIO13, "soc-gpio13"),
  3300. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SOC_GPIO10, "soc-gpio10"),
  3301. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UART4, "uart4"),
  3302. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UART5, "uart5"),
  3303. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_DBG, "dbg"),
  3304. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI_DP3, "hdmi-dp3"),
  3305. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI_DP2, "hdmi-dp2"),
  3306. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI_DP0, "hdmi-dp0"),
  3307. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI_DP1, "hdmi-dp1"),
  3308. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CNTRL, "pex-cntrl"),
  3309. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_CTL2, "pex-ctl2"),
  3310. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_L0_RST, "pex-l0-rst"),
  3311. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_L1_RST, "pex-l1-rst"),
  3312. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC4, "sdmmc4"),
  3313. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_PEX_L5_RST, "pex-l5-rst"),
  3314. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CAM, "cam"),
  3315. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIC, "csic"),
  3316. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSID, "csid"),
  3317. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIE, "csie"),
  3318. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIF, "csif"),
  3319. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SPI, "spi"),
  3320. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UFS, "ufs"),
  3321. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIG, "csig"),
  3322. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIH, "csih"),
  3323. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_EDP, "edp"),
  3324. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC1_HV, "sdmmc1-hv"),
  3325. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC3_HV, "sdmmc3-hv"),
  3326. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CONN, "conn"),
  3327. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AUDIO_HV, "audio-hv"),
  3328. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AO_HV, "ao-hv"),
  3329. };
  3330. static const struct tegra_pmc_regs tegra194_pmc_regs = {
  3331. .scratch0 = 0x2000,
  3332. .rst_status = 0x70,
  3333. .rst_source_shift = 0x2,
  3334. .rst_source_mask = 0x7c,
  3335. .rst_level_shift = 0x0,
  3336. .rst_level_mask = 0x3,
  3337. };
  3338. static const char * const tegra194_reset_sources[] = {
  3339. "SYS_RESET_N",
  3340. "AOWDT",
  3341. "BCCPLEXWDT",
  3342. "BPMPWDT",
  3343. "SCEWDT",
  3344. "SPEWDT",
  3345. "APEWDT",
  3346. "LCCPLEXWDT",
  3347. "SENSOR",
  3348. "AOTAG",
  3349. "VFSENSOR",
  3350. "MAINSWRST",
  3351. "SC7",
  3352. "HSM",
  3353. "CSITE",
  3354. "RCEWDT",
  3355. "PVA0WDT",
  3356. "PVA1WDT",
  3357. "L1A_ASYNC",
  3358. "BPMPBOOT",
  3359. "FUSECRC",
  3360. };
  3361. static const struct tegra_wake_event tegra194_wake_events[] = {
  3362. TEGRA_WAKE_GPIO("eqos", 20, 0, TEGRA194_MAIN_GPIO(G, 4)),
  3363. TEGRA_WAKE_IRQ("pmu", 24, 209),
  3364. TEGRA_WAKE_GPIO("power", 29, 1, TEGRA194_AON_GPIO(EE, 4)),
  3365. TEGRA_WAKE_IRQ("rtc", 73, 10),
  3366. TEGRA_WAKE_SIMPLE("usb3-port-0", 76),
  3367. TEGRA_WAKE_SIMPLE("usb3-port-1", 77),
  3368. TEGRA_WAKE_SIMPLE("usb3-port-2-3", 78),
  3369. TEGRA_WAKE_SIMPLE("usb2-port-0", 79),
  3370. TEGRA_WAKE_SIMPLE("usb2-port-1", 80),
  3371. TEGRA_WAKE_SIMPLE("usb2-port-2", 81),
  3372. TEGRA_WAKE_SIMPLE("usb2-port-3", 82),
  3373. };
  3374. static const struct tegra_pmc_soc tegra194_pmc_soc = {
  3375. .supports_core_domain = false,
  3376. .num_powergates = 0,
  3377. .powergates = NULL,
  3378. .num_cpu_powergates = 0,
  3379. .cpu_powergates = NULL,
  3380. .has_tsense_reset = false,
  3381. .has_gpu_clamps = false,
  3382. .needs_mbist_war = false,
  3383. .has_impl_33v_pwr = true,
  3384. .maybe_tz_only = false,
  3385. .num_io_pads = ARRAY_SIZE(tegra194_io_pads),
  3386. .io_pads = tegra194_io_pads,
  3387. .num_pin_descs = ARRAY_SIZE(tegra194_pin_descs),
  3388. .pin_descs = tegra194_pin_descs,
  3389. .regs = &tegra194_pmc_regs,
  3390. .init = tegra186_pmc_init,
  3391. .setup_irq_polarity = tegra186_pmc_setup_irq_polarity,
  3392. .set_wake_filters = tegra186_pmc_set_wake_filters,
  3393. .irq_set_wake = tegra186_pmc_irq_set_wake,
  3394. .irq_set_type = tegra186_pmc_irq_set_type,
  3395. .reset_sources = tegra194_reset_sources,
  3396. .num_reset_sources = ARRAY_SIZE(tegra194_reset_sources),
  3397. .reset_levels = tegra186_reset_levels,
  3398. .num_reset_levels = ARRAY_SIZE(tegra186_reset_levels),
  3399. .num_wake_events = ARRAY_SIZE(tegra194_wake_events),
  3400. .wake_events = tegra194_wake_events,
  3401. .max_wake_events = 96,
  3402. .max_wake_vectors = 3,
  3403. .pmc_clks_data = NULL,
  3404. .num_pmc_clks = 0,
  3405. .has_blink_output = false,
  3406. .has_usb_sleepwalk = false,
  3407. .has_single_mmio_aperture = false,
  3408. };
  3409. static const struct tegra_io_pad_soc tegra234_io_pads[] = {
  3410. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIA, 0, 0xe0c0, 0xe0c4, UINT_MAX, "csia"),
  3411. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIB, 1, 0xe0c0, 0xe0c4, UINT_MAX, "csib"),
  3412. TEGRA_IO_PAD(TEGRA_IO_PAD_HDMI_DP0, 0, 0xe0d0, 0xe0d4, UINT_MAX, "hdmi-dp0"),
  3413. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIC, 2, 0xe0c0, 0xe0c4, UINT_MAX, "csic"),
  3414. TEGRA_IO_PAD(TEGRA_IO_PAD_CSID, 3, 0xe0c0, 0xe0c4, UINT_MAX, "csid"),
  3415. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIE, 4, 0xe0c0, 0xe0c4, UINT_MAX, "csie"),
  3416. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIF, 5, 0xe0c0, 0xe0c4, UINT_MAX, "csif"),
  3417. TEGRA_IO_PAD(TEGRA_IO_PAD_UFS, 0, 0xe064, 0xe068, UINT_MAX, "ufs"),
  3418. TEGRA_IO_PAD(TEGRA_IO_PAD_EDP, 1, 0xe05c, 0xe060, UINT_MAX, "edp"),
  3419. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC1_HV, 0, 0xe054, 0xe058, 4, "sdmmc1-hv"),
  3420. TEGRA_IO_PAD(TEGRA_IO_PAD_SDMMC3_HV, UINT_MAX, UINT_MAX, UINT_MAX, 6, "sdmmc3-hv"),
  3421. TEGRA_IO_PAD(TEGRA_IO_PAD_AUDIO_HV, UINT_MAX, UINT_MAX, UINT_MAX, 1, "audio-hv"),
  3422. TEGRA_IO_PAD(TEGRA_IO_PAD_AO_HV, UINT_MAX, UINT_MAX, UINT_MAX, 0, "ao-hv"),
  3423. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIG, 6, 0xe0c0, 0xe0c4, UINT_MAX, "csig"),
  3424. TEGRA_IO_PAD(TEGRA_IO_PAD_CSIH, 7, 0xe0c0, 0xe0c4, UINT_MAX, "csih"),
  3425. };
  3426. static const struct pinctrl_pin_desc tegra234_pin_descs[] = {
  3427. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIA, "csia"),
  3428. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIB, "csib"),
  3429. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_HDMI_DP0, "hdmi-dp0"),
  3430. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIC, "csic"),
  3431. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSID, "csid"),
  3432. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIE, "csie"),
  3433. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIF, "csif"),
  3434. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_UFS, "ufs"),
  3435. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_EDP, "edp"),
  3436. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC1_HV, "sdmmc1-hv"),
  3437. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_SDMMC3_HV, "sdmmc3-hv"),
  3438. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AUDIO_HV, "audio-hv"),
  3439. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_AO_HV, "ao-hv"),
  3440. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIG, "csig"),
  3441. TEGRA_IO_PIN_DESC(TEGRA_IO_PAD_CSIH, "csih"),
  3442. };
  3443. static const struct tegra_pmc_regs tegra234_pmc_regs = {
  3444. .scratch0 = 0x2000,
  3445. .rst_status = 0x70,
  3446. .rst_source_shift = 0x2,
  3447. .rst_source_mask = 0xfc,
  3448. .rst_level_shift = 0x0,
  3449. .rst_level_mask = 0x3,
  3450. };
  3451. static const char * const tegra234_reset_sources[] = {
  3452. "SYS_RESET_N", /* 0x0 */
  3453. "AOWDT",
  3454. "BCCPLEXWDT",
  3455. "BPMPWDT",
  3456. "SCEWDT",
  3457. "SPEWDT",
  3458. "APEWDT",
  3459. "LCCPLEXWDT",
  3460. "SENSOR", /* 0x8 */
  3461. NULL,
  3462. NULL,
  3463. "MAINSWRST",
  3464. "SC7",
  3465. "HSM",
  3466. NULL,
  3467. "RCEWDT",
  3468. NULL, /* 0x10 */
  3469. NULL,
  3470. NULL,
  3471. "BPMPBOOT",
  3472. "FUSECRC",
  3473. "DCEWDT",
  3474. "PSCWDT",
  3475. "PSC",
  3476. "CSITE_SW", /* 0x18 */
  3477. "POD",
  3478. "SCPM",
  3479. "VREFRO_POWERBAD",
  3480. "VMON",
  3481. "FMON",
  3482. "FSI_R5WDT",
  3483. "FSI_THERM",
  3484. "FSI_R52C0WDT", /* 0x20 */
  3485. "FSI_R52C1WDT",
  3486. "FSI_R52C2WDT",
  3487. "FSI_R52C3WDT",
  3488. "FSI_FMON",
  3489. "FSI_VMON", /* 0x25 */
  3490. };
  3491. static const struct tegra_wake_event tegra234_wake_events[] = {
  3492. TEGRA_WAKE_GPIO("sd-wake", 8, 0, TEGRA234_MAIN_GPIO(G, 7)),
  3493. TEGRA_WAKE_GPIO("eqos", 20, 0, TEGRA234_MAIN_GPIO(G, 4)),
  3494. TEGRA_WAKE_IRQ("pmu", 24, 209),
  3495. TEGRA_WAKE_GPIO("power", 29, 1, TEGRA234_AON_GPIO(EE, 4)),
  3496. TEGRA_WAKE_GPIO("mgbe", 56, 0, TEGRA234_MAIN_GPIO(Y, 3)),
  3497. TEGRA_WAKE_IRQ("rtc", 73, 10),
  3498. TEGRA_WAKE_IRQ("sw-wake", SW_WAKE_ID, 179),
  3499. };
  3500. static const struct tegra_pmc_soc tegra234_pmc_soc = {
  3501. .supports_core_domain = false,
  3502. .num_powergates = 0,
  3503. .powergates = NULL,
  3504. .num_cpu_powergates = 0,
  3505. .cpu_powergates = NULL,
  3506. .has_tsense_reset = false,
  3507. .has_gpu_clamps = false,
  3508. .needs_mbist_war = false,
  3509. .has_impl_33v_pwr = true,
  3510. .maybe_tz_only = false,
  3511. .num_io_pads = ARRAY_SIZE(tegra234_io_pads),
  3512. .io_pads = tegra234_io_pads,
  3513. .num_pin_descs = ARRAY_SIZE(tegra234_pin_descs),
  3514. .pin_descs = tegra234_pin_descs,
  3515. .regs = &tegra234_pmc_regs,
  3516. .init = tegra186_pmc_init,
  3517. .setup_irq_polarity = tegra186_pmc_setup_irq_polarity,
  3518. .set_wake_filters = tegra186_pmc_set_wake_filters,
  3519. .irq_set_wake = tegra186_pmc_irq_set_wake,
  3520. .irq_set_type = tegra186_pmc_irq_set_type,
  3521. .reset_sources = tegra234_reset_sources,
  3522. .num_reset_sources = ARRAY_SIZE(tegra234_reset_sources),
  3523. .reset_levels = tegra186_reset_levels,
  3524. .num_reset_levels = ARRAY_SIZE(tegra186_reset_levels),
  3525. .num_wake_events = ARRAY_SIZE(tegra234_wake_events),
  3526. .wake_events = tegra234_wake_events,
  3527. .max_wake_events = 96,
  3528. .max_wake_vectors = 3,
  3529. .pmc_clks_data = NULL,
  3530. .num_pmc_clks = 0,
  3531. .has_blink_output = false,
  3532. .has_single_mmio_aperture = false,
  3533. };
  3534. static const struct of_device_id tegra_pmc_match[] = {
  3535. { .compatible = "nvidia,tegra234-pmc", .data = &tegra234_pmc_soc },
  3536. { .compatible = "nvidia,tegra194-pmc", .data = &tegra194_pmc_soc },
  3537. { .compatible = "nvidia,tegra186-pmc", .data = &tegra186_pmc_soc },
  3538. { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc },
  3539. { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc },
  3540. { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
  3541. { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
  3542. { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
  3543. { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
  3544. { }
  3545. };
  3546. static void tegra_pmc_sync_state(struct device *dev)
  3547. {
  3548. int err;
  3549. /*
  3550. * Newer device-trees have power domains, but we need to prepare all
  3551. * device drivers with runtime PM and OPP support first, otherwise
  3552. * state syncing is unsafe.
  3553. */
  3554. if (!pmc->soc->supports_core_domain)
  3555. return;
  3556. /*
  3557. * Older device-trees don't have core PD, and thus, there are
  3558. * no dependencies that will block the state syncing. We shouldn't
  3559. * mark the domain as synced in this case.
  3560. */
  3561. if (!pmc->core_domain_registered)
  3562. return;
  3563. pmc->core_domain_state_synced = true;
  3564. /* this is a no-op if core regulator isn't used */
  3565. mutex_lock(&pmc->powergates_lock);
  3566. err = dev_pm_opp_sync_regulators(dev);
  3567. mutex_unlock(&pmc->powergates_lock);
  3568. if (err)
  3569. dev_err(dev, "failed to sync regulators: %d\n", err);
  3570. }
  3571. static struct platform_driver tegra_pmc_driver = {
  3572. .driver = {
  3573. .name = "tegra-pmc",
  3574. .suppress_bind_attrs = true,
  3575. .of_match_table = tegra_pmc_match,
  3576. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
  3577. .pm = &tegra_pmc_pm_ops,
  3578. #endif
  3579. .sync_state = tegra_pmc_sync_state,
  3580. },
  3581. .probe = tegra_pmc_probe,
  3582. };
  3583. builtin_platform_driver(tegra_pmc_driver);
  3584. static bool __init tegra_pmc_detect_tz_only(struct tegra_pmc *pmc)
  3585. {
  3586. u32 value, saved;
  3587. saved = readl(pmc->base + pmc->soc->regs->scratch0);
  3588. value = saved ^ 0xffffffff;
  3589. if (value == 0xffffffff)
  3590. value = 0xdeadbeef;
  3591. /* write pattern and read it back */
  3592. writel(value, pmc->base + pmc->soc->regs->scratch0);
  3593. value = readl(pmc->base + pmc->soc->regs->scratch0);
  3594. /* if we read all-zeroes, access is restricted to TZ only */
  3595. if (value == 0) {
  3596. pr_info("access to PMC is restricted to TZ\n");
  3597. return true;
  3598. }
  3599. /* restore original value */
  3600. writel(saved, pmc->base + pmc->soc->regs->scratch0);
  3601. return false;
  3602. }
  3603. /*
  3604. * Early initialization to allow access to registers in the very early boot
  3605. * process.
  3606. */
  3607. static int __init tegra_pmc_early_init(void)
  3608. {
  3609. const struct of_device_id *match;
  3610. struct device_node *np;
  3611. struct resource regs;
  3612. unsigned int i;
  3613. bool invert;
  3614. mutex_init(&pmc->powergates_lock);
  3615. np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
  3616. if (!np) {
  3617. /*
  3618. * Fall back to legacy initialization for 32-bit ARM only. All
  3619. * 64-bit ARM device tree files for Tegra are required to have
  3620. * a PMC node.
  3621. *
  3622. * This is for backwards-compatibility with old device trees
  3623. * that didn't contain a PMC node. Note that in this case the
  3624. * SoC data can't be matched and therefore powergating is
  3625. * disabled.
  3626. */
  3627. if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
  3628. pr_warn("DT node not found, powergating disabled\n");
  3629. regs.start = 0x7000e400;
  3630. regs.end = 0x7000e7ff;
  3631. regs.flags = IORESOURCE_MEM;
  3632. pr_warn("Using memory region %pR\n", &regs);
  3633. } else {
  3634. /*
  3635. * At this point we're not running on Tegra, so play
  3636. * nice with multi-platform kernels.
  3637. */
  3638. return 0;
  3639. }
  3640. } else {
  3641. /*
  3642. * Extract information from the device tree if we've found a
  3643. * matching node.
  3644. */
  3645. if (of_address_to_resource(np, 0, &regs) < 0) {
  3646. pr_err("failed to get PMC registers\n");
  3647. of_node_put(np);
  3648. return -ENXIO;
  3649. }
  3650. }
  3651. pmc->base = ioremap(regs.start, resource_size(&regs));
  3652. if (!pmc->base) {
  3653. pr_err("failed to map PMC registers\n");
  3654. of_node_put(np);
  3655. return -ENXIO;
  3656. }
  3657. if (of_device_is_available(np)) {
  3658. pmc->soc = match->data;
  3659. if (pmc->soc->maybe_tz_only)
  3660. pmc->tz_only = tegra_pmc_detect_tz_only(pmc);
  3661. /* Create a bitmap of the available and valid partitions */
  3662. for (i = 0; i < pmc->soc->num_powergates; i++)
  3663. if (pmc->soc->powergates[i])
  3664. set_bit(i, pmc->powergates_available);
  3665. /*
  3666. * Invert the interrupt polarity if a PMC device tree node
  3667. * exists and contains the nvidia,invert-interrupt property.
  3668. */
  3669. invert = of_property_read_bool(np, "nvidia,invert-interrupt");
  3670. pmc->soc->setup_irq_polarity(pmc, np, invert);
  3671. of_node_put(np);
  3672. }
  3673. return 0;
  3674. }
  3675. early_initcall(tegra_pmc_early_init);