pmc.c 126 KB

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