dce_v8_0.c 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #include "drmP.h"
  24. #include "amdgpu.h"
  25. #include "amdgpu_pm.h"
  26. #include "amdgpu_i2c.h"
  27. #include "cikd.h"
  28. #include "atom.h"
  29. #include "amdgpu_atombios.h"
  30. #include "atombios_crtc.h"
  31. #include "atombios_encoders.h"
  32. #include "amdgpu_pll.h"
  33. #include "amdgpu_connectors.h"
  34. #include "dce/dce_8_0_d.h"
  35. #include "dce/dce_8_0_sh_mask.h"
  36. #include "gca/gfx_7_2_enum.h"
  37. #include "gmc/gmc_7_1_d.h"
  38. #include "gmc/gmc_7_1_sh_mask.h"
  39. #include "oss/oss_2_0_d.h"
  40. #include "oss/oss_2_0_sh_mask.h"
  41. static void dce_v8_0_set_display_funcs(struct amdgpu_device *adev);
  42. static void dce_v8_0_set_irq_funcs(struct amdgpu_device *adev);
  43. static const u32 crtc_offsets[6] =
  44. {
  45. CRTC0_REGISTER_OFFSET,
  46. CRTC1_REGISTER_OFFSET,
  47. CRTC2_REGISTER_OFFSET,
  48. CRTC3_REGISTER_OFFSET,
  49. CRTC4_REGISTER_OFFSET,
  50. CRTC5_REGISTER_OFFSET
  51. };
  52. static const uint32_t dig_offsets[] = {
  53. CRTC0_REGISTER_OFFSET,
  54. CRTC1_REGISTER_OFFSET,
  55. CRTC2_REGISTER_OFFSET,
  56. CRTC3_REGISTER_OFFSET,
  57. CRTC4_REGISTER_OFFSET,
  58. CRTC5_REGISTER_OFFSET,
  59. (0x13830 - 0x7030) >> 2,
  60. };
  61. static const struct {
  62. uint32_t reg;
  63. uint32_t vblank;
  64. uint32_t vline;
  65. uint32_t hpd;
  66. } interrupt_status_offsets[6] = { {
  67. .reg = mmDISP_INTERRUPT_STATUS,
  68. .vblank = DISP_INTERRUPT_STATUS__LB_D1_VBLANK_INTERRUPT_MASK,
  69. .vline = DISP_INTERRUPT_STATUS__LB_D1_VLINE_INTERRUPT_MASK,
  70. .hpd = DISP_INTERRUPT_STATUS__DC_HPD1_INTERRUPT_MASK
  71. }, {
  72. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE,
  73. .vblank = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VBLANK_INTERRUPT_MASK,
  74. .vline = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VLINE_INTERRUPT_MASK,
  75. .hpd = DISP_INTERRUPT_STATUS_CONTINUE__DC_HPD2_INTERRUPT_MASK
  76. }, {
  77. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE2,
  78. .vblank = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VBLANK_INTERRUPT_MASK,
  79. .vline = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VLINE_INTERRUPT_MASK,
  80. .hpd = DISP_INTERRUPT_STATUS_CONTINUE2__DC_HPD3_INTERRUPT_MASK
  81. }, {
  82. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE3,
  83. .vblank = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VBLANK_INTERRUPT_MASK,
  84. .vline = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VLINE_INTERRUPT_MASK,
  85. .hpd = DISP_INTERRUPT_STATUS_CONTINUE3__DC_HPD4_INTERRUPT_MASK
  86. }, {
  87. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE4,
  88. .vblank = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VBLANK_INTERRUPT_MASK,
  89. .vline = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VLINE_INTERRUPT_MASK,
  90. .hpd = DISP_INTERRUPT_STATUS_CONTINUE4__DC_HPD5_INTERRUPT_MASK
  91. }, {
  92. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE5,
  93. .vblank = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VBLANK_INTERRUPT_MASK,
  94. .vline = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VLINE_INTERRUPT_MASK,
  95. .hpd = DISP_INTERRUPT_STATUS_CONTINUE5__DC_HPD6_INTERRUPT_MASK
  96. } };
  97. static const uint32_t hpd_int_control_offsets[6] = {
  98. mmDC_HPD1_INT_CONTROL,
  99. mmDC_HPD2_INT_CONTROL,
  100. mmDC_HPD3_INT_CONTROL,
  101. mmDC_HPD4_INT_CONTROL,
  102. mmDC_HPD5_INT_CONTROL,
  103. mmDC_HPD6_INT_CONTROL,
  104. };
  105. static u32 dce_v8_0_audio_endpt_rreg(struct amdgpu_device *adev,
  106. u32 block_offset, u32 reg)
  107. {
  108. unsigned long flags;
  109. u32 r;
  110. spin_lock_irqsave(&adev->audio_endpt_idx_lock, flags);
  111. WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX + block_offset, reg);
  112. r = RREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA + block_offset);
  113. spin_unlock_irqrestore(&adev->audio_endpt_idx_lock, flags);
  114. return r;
  115. }
  116. static void dce_v8_0_audio_endpt_wreg(struct amdgpu_device *adev,
  117. u32 block_offset, u32 reg, u32 v)
  118. {
  119. unsigned long flags;
  120. spin_lock_irqsave(&adev->audio_endpt_idx_lock, flags);
  121. WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX + block_offset, reg);
  122. WREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA + block_offset, v);
  123. spin_unlock_irqrestore(&adev->audio_endpt_idx_lock, flags);
  124. }
  125. static bool dce_v8_0_is_in_vblank(struct amdgpu_device *adev, int crtc)
  126. {
  127. if (RREG32(mmCRTC_STATUS + crtc_offsets[crtc]) &
  128. CRTC_V_BLANK_START_END__CRTC_V_BLANK_START_MASK)
  129. return true;
  130. else
  131. return false;
  132. }
  133. static bool dce_v8_0_is_counter_moving(struct amdgpu_device *adev, int crtc)
  134. {
  135. u32 pos1, pos2;
  136. pos1 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  137. pos2 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  138. if (pos1 != pos2)
  139. return true;
  140. else
  141. return false;
  142. }
  143. /**
  144. * dce_v8_0_vblank_wait - vblank wait asic callback.
  145. *
  146. * @adev: amdgpu_device pointer
  147. * @crtc: crtc to wait for vblank on
  148. *
  149. * Wait for vblank on the requested crtc (evergreen+).
  150. */
  151. static void dce_v8_0_vblank_wait(struct amdgpu_device *adev, int crtc)
  152. {
  153. unsigned i = 0;
  154. if (crtc >= adev->mode_info.num_crtc)
  155. return;
  156. if (!(RREG32(mmCRTC_CONTROL + crtc_offsets[crtc]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK))
  157. return;
  158. /* depending on when we hit vblank, we may be close to active; if so,
  159. * wait for another frame.
  160. */
  161. while (dce_v8_0_is_in_vblank(adev, crtc)) {
  162. if (i++ % 100 == 0) {
  163. if (!dce_v8_0_is_counter_moving(adev, crtc))
  164. break;
  165. }
  166. }
  167. while (!dce_v8_0_is_in_vblank(adev, crtc)) {
  168. if (i++ % 100 == 0) {
  169. if (!dce_v8_0_is_counter_moving(adev, crtc))
  170. break;
  171. }
  172. }
  173. }
  174. static u32 dce_v8_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
  175. {
  176. if (crtc >= adev->mode_info.num_crtc)
  177. return 0;
  178. else
  179. return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
  180. }
  181. static void dce_v8_0_pageflip_interrupt_init(struct amdgpu_device *adev)
  182. {
  183. unsigned i;
  184. /* Enable pflip interrupts */
  185. for (i = 0; i < adev->mode_info.num_crtc; i++)
  186. amdgpu_irq_get(adev, &adev->pageflip_irq, i);
  187. }
  188. static void dce_v8_0_pageflip_interrupt_fini(struct amdgpu_device *adev)
  189. {
  190. unsigned i;
  191. /* Disable pflip interrupts */
  192. for (i = 0; i < adev->mode_info.num_crtc; i++)
  193. amdgpu_irq_put(adev, &adev->pageflip_irq, i);
  194. }
  195. /**
  196. * dce_v8_0_page_flip - pageflip callback.
  197. *
  198. * @adev: amdgpu_device pointer
  199. * @crtc_id: crtc to cleanup pageflip on
  200. * @crtc_base: new address of the crtc (GPU MC address)
  201. *
  202. * Triggers the actual pageflip by updating the primary
  203. * surface base address.
  204. */
  205. static void dce_v8_0_page_flip(struct amdgpu_device *adev,
  206. int crtc_id, u64 crtc_base, bool async)
  207. {
  208. struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
  209. /* flip at hsync for async, default is vsync */
  210. WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, async ?
  211. GRPH_FLIP_CONTROL__GRPH_SURFACE_UPDATE_H_RETRACE_EN_MASK : 0);
  212. /* update the primary scanout addresses */
  213. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  214. upper_32_bits(crtc_base));
  215. /* writing to the low address triggers the update */
  216. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  217. lower_32_bits(crtc_base));
  218. /* post the write */
  219. RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
  220. }
  221. static int dce_v8_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
  222. u32 *vbl, u32 *position)
  223. {
  224. if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
  225. return -EINVAL;
  226. *vbl = RREG32(mmCRTC_V_BLANK_START_END + crtc_offsets[crtc]);
  227. *position = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  228. return 0;
  229. }
  230. /**
  231. * dce_v8_0_hpd_sense - hpd sense callback.
  232. *
  233. * @adev: amdgpu_device pointer
  234. * @hpd: hpd (hotplug detect) pin
  235. *
  236. * Checks if a digital monitor is connected (evergreen+).
  237. * Returns true if connected, false if not connected.
  238. */
  239. static bool dce_v8_0_hpd_sense(struct amdgpu_device *adev,
  240. enum amdgpu_hpd_id hpd)
  241. {
  242. bool connected = false;
  243. switch (hpd) {
  244. case AMDGPU_HPD_1:
  245. if (RREG32(mmDC_HPD1_INT_STATUS) & DC_HPD1_INT_STATUS__DC_HPD1_SENSE_MASK)
  246. connected = true;
  247. break;
  248. case AMDGPU_HPD_2:
  249. if (RREG32(mmDC_HPD2_INT_STATUS) & DC_HPD2_INT_STATUS__DC_HPD2_SENSE_MASK)
  250. connected = true;
  251. break;
  252. case AMDGPU_HPD_3:
  253. if (RREG32(mmDC_HPD3_INT_STATUS) & DC_HPD3_INT_STATUS__DC_HPD3_SENSE_MASK)
  254. connected = true;
  255. break;
  256. case AMDGPU_HPD_4:
  257. if (RREG32(mmDC_HPD4_INT_STATUS) & DC_HPD4_INT_STATUS__DC_HPD4_SENSE_MASK)
  258. connected = true;
  259. break;
  260. case AMDGPU_HPD_5:
  261. if (RREG32(mmDC_HPD5_INT_STATUS) & DC_HPD5_INT_STATUS__DC_HPD5_SENSE_MASK)
  262. connected = true;
  263. break;
  264. case AMDGPU_HPD_6:
  265. if (RREG32(mmDC_HPD6_INT_STATUS) & DC_HPD6_INT_STATUS__DC_HPD6_SENSE_MASK)
  266. connected = true;
  267. break;
  268. default:
  269. break;
  270. }
  271. return connected;
  272. }
  273. /**
  274. * dce_v8_0_hpd_set_polarity - hpd set polarity callback.
  275. *
  276. * @adev: amdgpu_device pointer
  277. * @hpd: hpd (hotplug detect) pin
  278. *
  279. * Set the polarity of the hpd pin (evergreen+).
  280. */
  281. static void dce_v8_0_hpd_set_polarity(struct amdgpu_device *adev,
  282. enum amdgpu_hpd_id hpd)
  283. {
  284. u32 tmp;
  285. bool connected = dce_v8_0_hpd_sense(adev, hpd);
  286. switch (hpd) {
  287. case AMDGPU_HPD_1:
  288. tmp = RREG32(mmDC_HPD1_INT_CONTROL);
  289. if (connected)
  290. tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
  291. else
  292. tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
  293. WREG32(mmDC_HPD1_INT_CONTROL, tmp);
  294. break;
  295. case AMDGPU_HPD_2:
  296. tmp = RREG32(mmDC_HPD2_INT_CONTROL);
  297. if (connected)
  298. tmp &= ~DC_HPD2_INT_CONTROL__DC_HPD2_INT_POLARITY_MASK;
  299. else
  300. tmp |= DC_HPD2_INT_CONTROL__DC_HPD2_INT_POLARITY_MASK;
  301. WREG32(mmDC_HPD2_INT_CONTROL, tmp);
  302. break;
  303. case AMDGPU_HPD_3:
  304. tmp = RREG32(mmDC_HPD3_INT_CONTROL);
  305. if (connected)
  306. tmp &= ~DC_HPD3_INT_CONTROL__DC_HPD3_INT_POLARITY_MASK;
  307. else
  308. tmp |= DC_HPD3_INT_CONTROL__DC_HPD3_INT_POLARITY_MASK;
  309. WREG32(mmDC_HPD3_INT_CONTROL, tmp);
  310. break;
  311. case AMDGPU_HPD_4:
  312. tmp = RREG32(mmDC_HPD4_INT_CONTROL);
  313. if (connected)
  314. tmp &= ~DC_HPD4_INT_CONTROL__DC_HPD4_INT_POLARITY_MASK;
  315. else
  316. tmp |= DC_HPD4_INT_CONTROL__DC_HPD4_INT_POLARITY_MASK;
  317. WREG32(mmDC_HPD4_INT_CONTROL, tmp);
  318. break;
  319. case AMDGPU_HPD_5:
  320. tmp = RREG32(mmDC_HPD5_INT_CONTROL);
  321. if (connected)
  322. tmp &= ~DC_HPD5_INT_CONTROL__DC_HPD5_INT_POLARITY_MASK;
  323. else
  324. tmp |= DC_HPD5_INT_CONTROL__DC_HPD5_INT_POLARITY_MASK;
  325. WREG32(mmDC_HPD5_INT_CONTROL, tmp);
  326. break;
  327. case AMDGPU_HPD_6:
  328. tmp = RREG32(mmDC_HPD6_INT_CONTROL);
  329. if (connected)
  330. tmp &= ~DC_HPD6_INT_CONTROL__DC_HPD6_INT_POLARITY_MASK;
  331. else
  332. tmp |= DC_HPD6_INT_CONTROL__DC_HPD6_INT_POLARITY_MASK;
  333. WREG32(mmDC_HPD6_INT_CONTROL, tmp);
  334. break;
  335. default:
  336. break;
  337. }
  338. }
  339. /**
  340. * dce_v8_0_hpd_init - hpd setup callback.
  341. *
  342. * @adev: amdgpu_device pointer
  343. *
  344. * Setup the hpd pins used by the card (evergreen+).
  345. * Enable the pin, set the polarity, and enable the hpd interrupts.
  346. */
  347. static void dce_v8_0_hpd_init(struct amdgpu_device *adev)
  348. {
  349. struct drm_device *dev = adev->ddev;
  350. struct drm_connector *connector;
  351. u32 tmp = (0x9c4 << DC_HPD1_CONTROL__DC_HPD1_CONNECTION_TIMER__SHIFT) |
  352. (0xfa << DC_HPD1_CONTROL__DC_HPD1_RX_INT_TIMER__SHIFT) |
  353. DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
  354. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  355. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  356. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  357. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  358. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  359. * aux dp channel on imac and help (but not completely fix)
  360. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  361. * also avoid interrupt storms during dpms.
  362. */
  363. continue;
  364. }
  365. switch (amdgpu_connector->hpd.hpd) {
  366. case AMDGPU_HPD_1:
  367. WREG32(mmDC_HPD1_CONTROL, tmp);
  368. break;
  369. case AMDGPU_HPD_2:
  370. WREG32(mmDC_HPD2_CONTROL, tmp);
  371. break;
  372. case AMDGPU_HPD_3:
  373. WREG32(mmDC_HPD3_CONTROL, tmp);
  374. break;
  375. case AMDGPU_HPD_4:
  376. WREG32(mmDC_HPD4_CONTROL, tmp);
  377. break;
  378. case AMDGPU_HPD_5:
  379. WREG32(mmDC_HPD5_CONTROL, tmp);
  380. break;
  381. case AMDGPU_HPD_6:
  382. WREG32(mmDC_HPD6_CONTROL, tmp);
  383. break;
  384. default:
  385. break;
  386. }
  387. dce_v8_0_hpd_set_polarity(adev, amdgpu_connector->hpd.hpd);
  388. amdgpu_irq_get(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
  389. }
  390. }
  391. /**
  392. * dce_v8_0_hpd_fini - hpd tear down callback.
  393. *
  394. * @adev: amdgpu_device pointer
  395. *
  396. * Tear down the hpd pins used by the card (evergreen+).
  397. * Disable the hpd interrupts.
  398. */
  399. static void dce_v8_0_hpd_fini(struct amdgpu_device *adev)
  400. {
  401. struct drm_device *dev = adev->ddev;
  402. struct drm_connector *connector;
  403. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  404. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  405. switch (amdgpu_connector->hpd.hpd) {
  406. case AMDGPU_HPD_1:
  407. WREG32(mmDC_HPD1_CONTROL, 0);
  408. break;
  409. case AMDGPU_HPD_2:
  410. WREG32(mmDC_HPD2_CONTROL, 0);
  411. break;
  412. case AMDGPU_HPD_3:
  413. WREG32(mmDC_HPD3_CONTROL, 0);
  414. break;
  415. case AMDGPU_HPD_4:
  416. WREG32(mmDC_HPD4_CONTROL, 0);
  417. break;
  418. case AMDGPU_HPD_5:
  419. WREG32(mmDC_HPD5_CONTROL, 0);
  420. break;
  421. case AMDGPU_HPD_6:
  422. WREG32(mmDC_HPD6_CONTROL, 0);
  423. break;
  424. default:
  425. break;
  426. }
  427. amdgpu_irq_put(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
  428. }
  429. }
  430. static u32 dce_v8_0_hpd_get_gpio_reg(struct amdgpu_device *adev)
  431. {
  432. return mmDC_GPIO_HPD_A;
  433. }
  434. static bool dce_v8_0_is_display_hung(struct amdgpu_device *adev)
  435. {
  436. u32 crtc_hung = 0;
  437. u32 crtc_status[6];
  438. u32 i, j, tmp;
  439. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  440. if (RREG32(mmCRTC_CONTROL + crtc_offsets[i]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK) {
  441. crtc_status[i] = RREG32(mmCRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  442. crtc_hung |= (1 << i);
  443. }
  444. }
  445. for (j = 0; j < 10; j++) {
  446. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  447. if (crtc_hung & (1 << i)) {
  448. tmp = RREG32(mmCRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  449. if (tmp != crtc_status[i])
  450. crtc_hung &= ~(1 << i);
  451. }
  452. }
  453. if (crtc_hung == 0)
  454. return false;
  455. udelay(100);
  456. }
  457. return true;
  458. }
  459. static void dce_v8_0_stop_mc_access(struct amdgpu_device *adev,
  460. struct amdgpu_mode_mc_save *save)
  461. {
  462. u32 crtc_enabled, tmp;
  463. int i;
  464. save->vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
  465. save->vga_hdp_control = RREG32(mmVGA_HDP_CONTROL);
  466. /* disable VGA render */
  467. tmp = RREG32(mmVGA_RENDER_CONTROL);
  468. tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0);
  469. WREG32(mmVGA_RENDER_CONTROL, tmp);
  470. /* blank the display controllers */
  471. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  472. crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]),
  473. CRTC_CONTROL, CRTC_MASTER_EN);
  474. if (crtc_enabled) {
  475. #if 1
  476. save->crtc_enabled[i] = true;
  477. tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
  478. if (REG_GET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN) == 0) {
  479. /*it is correct only for RGB ; black is 0*/
  480. WREG32(mmCRTC_BLANK_DATA_COLOR + crtc_offsets[i], 0);
  481. tmp = REG_SET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN, 1);
  482. WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  483. }
  484. mdelay(20);
  485. #else
  486. /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
  487. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  488. tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
  489. tmp = REG_SET_FIELD(tmp, CRTC_CONTROL, CRTC_MASTER_EN, 0);
  490. WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
  491. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  492. save->crtc_enabled[i] = false;
  493. /* ***** */
  494. #endif
  495. } else {
  496. save->crtc_enabled[i] = false;
  497. }
  498. }
  499. }
  500. static void dce_v8_0_resume_mc_access(struct amdgpu_device *adev,
  501. struct amdgpu_mode_mc_save *save)
  502. {
  503. u32 tmp;
  504. int i;
  505. /* update crtc base addresses */
  506. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  507. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  508. upper_32_bits(adev->mc.vram_start));
  509. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
  510. (u32)adev->mc.vram_start);
  511. if (save->crtc_enabled[i]) {
  512. tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
  513. tmp = REG_SET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN, 0);
  514. WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  515. }
  516. mdelay(20);
  517. }
  518. WREG32(mmVGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(adev->mc.vram_start));
  519. WREG32(mmVGA_MEMORY_BASE_ADDRESS, lower_32_bits(adev->mc.vram_start));
  520. /* Unlock vga access */
  521. WREG32(mmVGA_HDP_CONTROL, save->vga_hdp_control);
  522. mdelay(1);
  523. WREG32(mmVGA_RENDER_CONTROL, save->vga_render_control);
  524. }
  525. static void dce_v8_0_set_vga_render_state(struct amdgpu_device *adev,
  526. bool render)
  527. {
  528. u32 tmp;
  529. /* Lockout access through VGA aperture*/
  530. tmp = RREG32(mmVGA_HDP_CONTROL);
  531. if (render)
  532. tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 0);
  533. else
  534. tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 1);
  535. WREG32(mmVGA_HDP_CONTROL, tmp);
  536. /* disable VGA render */
  537. tmp = RREG32(mmVGA_RENDER_CONTROL);
  538. if (render)
  539. tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 1);
  540. else
  541. tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0);
  542. WREG32(mmVGA_RENDER_CONTROL, tmp);
  543. }
  544. static void dce_v8_0_program_fmt(struct drm_encoder *encoder)
  545. {
  546. struct drm_device *dev = encoder->dev;
  547. struct amdgpu_device *adev = dev->dev_private;
  548. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  549. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
  550. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  551. int bpc = 0;
  552. u32 tmp = 0;
  553. enum amdgpu_connector_dither dither = AMDGPU_FMT_DITHER_DISABLE;
  554. if (connector) {
  555. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  556. bpc = amdgpu_connector_get_monitor_bpc(connector);
  557. dither = amdgpu_connector->dither;
  558. }
  559. /* LVDS/eDP FMT is set up by atom */
  560. if (amdgpu_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  561. return;
  562. /* not needed for analog */
  563. if ((amdgpu_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
  564. (amdgpu_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
  565. return;
  566. if (bpc == 0)
  567. return;
  568. switch (bpc) {
  569. case 6:
  570. if (dither == AMDGPU_FMT_DITHER_ENABLE)
  571. /* XXX sort out optimal dither settings */
  572. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
  573. FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
  574. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
  575. (0 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
  576. else
  577. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
  578. (0 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
  579. break;
  580. case 8:
  581. if (dither == AMDGPU_FMT_DITHER_ENABLE)
  582. /* XXX sort out optimal dither settings */
  583. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
  584. FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
  585. FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
  586. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
  587. (1 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
  588. else
  589. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
  590. (1 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
  591. break;
  592. case 10:
  593. if (dither == AMDGPU_FMT_DITHER_ENABLE)
  594. /* XXX sort out optimal dither settings */
  595. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
  596. FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
  597. FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
  598. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
  599. (2 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
  600. else
  601. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
  602. (2 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
  603. break;
  604. default:
  605. /* not needed */
  606. break;
  607. }
  608. WREG32(mmFMT_BIT_DEPTH_CONTROL + amdgpu_crtc->crtc_offset, tmp);
  609. }
  610. /* display watermark setup */
  611. /**
  612. * dce_v8_0_line_buffer_adjust - Set up the line buffer
  613. *
  614. * @adev: amdgpu_device pointer
  615. * @amdgpu_crtc: the selected display controller
  616. * @mode: the current display mode on the selected display
  617. * controller
  618. *
  619. * Setup up the line buffer allocation for
  620. * the selected display controller (CIK).
  621. * Returns the line buffer size in pixels.
  622. */
  623. static u32 dce_v8_0_line_buffer_adjust(struct amdgpu_device *adev,
  624. struct amdgpu_crtc *amdgpu_crtc,
  625. struct drm_display_mode *mode)
  626. {
  627. u32 tmp, buffer_alloc, i;
  628. u32 pipe_offset = amdgpu_crtc->crtc_id * 0x8;
  629. /*
  630. * Line Buffer Setup
  631. * There are 6 line buffers, one for each display controllers.
  632. * There are 3 partitions per LB. Select the number of partitions
  633. * to enable based on the display width. For display widths larger
  634. * than 4096, you need use to use 2 display controllers and combine
  635. * them using the stereo blender.
  636. */
  637. if (amdgpu_crtc->base.enabled && mode) {
  638. if (mode->crtc_hdisplay < 1920) {
  639. tmp = 1;
  640. buffer_alloc = 2;
  641. } else if (mode->crtc_hdisplay < 2560) {
  642. tmp = 2;
  643. buffer_alloc = 2;
  644. } else if (mode->crtc_hdisplay < 4096) {
  645. tmp = 0;
  646. buffer_alloc = (adev->flags & AMD_IS_APU) ? 2 : 4;
  647. } else {
  648. DRM_DEBUG_KMS("Mode too big for LB!\n");
  649. tmp = 0;
  650. buffer_alloc = (adev->flags & AMD_IS_APU) ? 2 : 4;
  651. }
  652. } else {
  653. tmp = 1;
  654. buffer_alloc = 0;
  655. }
  656. WREG32(mmLB_MEMORY_CTRL + amdgpu_crtc->crtc_offset,
  657. (tmp << LB_MEMORY_CTRL__LB_MEMORY_CONFIG__SHIFT) |
  658. (0x6B0 << LB_MEMORY_CTRL__LB_MEMORY_SIZE__SHIFT));
  659. WREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  660. (buffer_alloc << PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATED__SHIFT));
  661. for (i = 0; i < adev->usec_timeout; i++) {
  662. if (RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  663. PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATION_COMPLETED_MASK)
  664. break;
  665. udelay(1);
  666. }
  667. if (amdgpu_crtc->base.enabled && mode) {
  668. switch (tmp) {
  669. case 0:
  670. default:
  671. return 4096 * 2;
  672. case 1:
  673. return 1920 * 2;
  674. case 2:
  675. return 2560 * 2;
  676. }
  677. }
  678. /* controller not enabled, so no lb used */
  679. return 0;
  680. }
  681. /**
  682. * cik_get_number_of_dram_channels - get the number of dram channels
  683. *
  684. * @adev: amdgpu_device pointer
  685. *
  686. * Look up the number of video ram channels (CIK).
  687. * Used for display watermark bandwidth calculations
  688. * Returns the number of dram channels
  689. */
  690. static u32 cik_get_number_of_dram_channels(struct amdgpu_device *adev)
  691. {
  692. u32 tmp = RREG32(mmMC_SHARED_CHMAP);
  693. switch ((tmp & MC_SHARED_CHMAP__NOOFCHAN_MASK) >> MC_SHARED_CHMAP__NOOFCHAN__SHIFT) {
  694. case 0:
  695. default:
  696. return 1;
  697. case 1:
  698. return 2;
  699. case 2:
  700. return 4;
  701. case 3:
  702. return 8;
  703. case 4:
  704. return 3;
  705. case 5:
  706. return 6;
  707. case 6:
  708. return 10;
  709. case 7:
  710. return 12;
  711. case 8:
  712. return 16;
  713. }
  714. }
  715. struct dce8_wm_params {
  716. u32 dram_channels; /* number of dram channels */
  717. u32 yclk; /* bandwidth per dram data pin in kHz */
  718. u32 sclk; /* engine clock in kHz */
  719. u32 disp_clk; /* display clock in kHz */
  720. u32 src_width; /* viewport width */
  721. u32 active_time; /* active display time in ns */
  722. u32 blank_time; /* blank time in ns */
  723. bool interlaced; /* mode is interlaced */
  724. fixed20_12 vsc; /* vertical scale ratio */
  725. u32 num_heads; /* number of active crtcs */
  726. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  727. u32 lb_size; /* line buffer allocated to pipe */
  728. u32 vtaps; /* vertical scaler taps */
  729. };
  730. /**
  731. * dce_v8_0_dram_bandwidth - get the dram bandwidth
  732. *
  733. * @wm: watermark calculation data
  734. *
  735. * Calculate the raw dram bandwidth (CIK).
  736. * Used for display watermark bandwidth calculations
  737. * Returns the dram bandwidth in MBytes/s
  738. */
  739. static u32 dce_v8_0_dram_bandwidth(struct dce8_wm_params *wm)
  740. {
  741. /* Calculate raw DRAM Bandwidth */
  742. fixed20_12 dram_efficiency; /* 0.7 */
  743. fixed20_12 yclk, dram_channels, bandwidth;
  744. fixed20_12 a;
  745. a.full = dfixed_const(1000);
  746. yclk.full = dfixed_const(wm->yclk);
  747. yclk.full = dfixed_div(yclk, a);
  748. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  749. a.full = dfixed_const(10);
  750. dram_efficiency.full = dfixed_const(7);
  751. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  752. bandwidth.full = dfixed_mul(dram_channels, yclk);
  753. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  754. return dfixed_trunc(bandwidth);
  755. }
  756. /**
  757. * dce_v8_0_dram_bandwidth_for_display - get the dram bandwidth for display
  758. *
  759. * @wm: watermark calculation data
  760. *
  761. * Calculate the dram bandwidth used for display (CIK).
  762. * Used for display watermark bandwidth calculations
  763. * Returns the dram bandwidth for display in MBytes/s
  764. */
  765. static u32 dce_v8_0_dram_bandwidth_for_display(struct dce8_wm_params *wm)
  766. {
  767. /* Calculate DRAM Bandwidth and the part allocated to display. */
  768. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  769. fixed20_12 yclk, dram_channels, bandwidth;
  770. fixed20_12 a;
  771. a.full = dfixed_const(1000);
  772. yclk.full = dfixed_const(wm->yclk);
  773. yclk.full = dfixed_div(yclk, a);
  774. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  775. a.full = dfixed_const(10);
  776. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  777. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  778. bandwidth.full = dfixed_mul(dram_channels, yclk);
  779. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  780. return dfixed_trunc(bandwidth);
  781. }
  782. /**
  783. * dce_v8_0_data_return_bandwidth - get the data return bandwidth
  784. *
  785. * @wm: watermark calculation data
  786. *
  787. * Calculate the data return bandwidth used for display (CIK).
  788. * Used for display watermark bandwidth calculations
  789. * Returns the data return bandwidth in MBytes/s
  790. */
  791. static u32 dce_v8_0_data_return_bandwidth(struct dce8_wm_params *wm)
  792. {
  793. /* Calculate the display Data return Bandwidth */
  794. fixed20_12 return_efficiency; /* 0.8 */
  795. fixed20_12 sclk, bandwidth;
  796. fixed20_12 a;
  797. a.full = dfixed_const(1000);
  798. sclk.full = dfixed_const(wm->sclk);
  799. sclk.full = dfixed_div(sclk, a);
  800. a.full = dfixed_const(10);
  801. return_efficiency.full = dfixed_const(8);
  802. return_efficiency.full = dfixed_div(return_efficiency, a);
  803. a.full = dfixed_const(32);
  804. bandwidth.full = dfixed_mul(a, sclk);
  805. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  806. return dfixed_trunc(bandwidth);
  807. }
  808. /**
  809. * dce_v8_0_dmif_request_bandwidth - get the dmif bandwidth
  810. *
  811. * @wm: watermark calculation data
  812. *
  813. * Calculate the dmif bandwidth used for display (CIK).
  814. * Used for display watermark bandwidth calculations
  815. * Returns the dmif bandwidth in MBytes/s
  816. */
  817. static u32 dce_v8_0_dmif_request_bandwidth(struct dce8_wm_params *wm)
  818. {
  819. /* Calculate the DMIF Request Bandwidth */
  820. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  821. fixed20_12 disp_clk, bandwidth;
  822. fixed20_12 a, b;
  823. a.full = dfixed_const(1000);
  824. disp_clk.full = dfixed_const(wm->disp_clk);
  825. disp_clk.full = dfixed_div(disp_clk, a);
  826. a.full = dfixed_const(32);
  827. b.full = dfixed_mul(a, disp_clk);
  828. a.full = dfixed_const(10);
  829. disp_clk_request_efficiency.full = dfixed_const(8);
  830. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  831. bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
  832. return dfixed_trunc(bandwidth);
  833. }
  834. /**
  835. * dce_v8_0_available_bandwidth - get the min available bandwidth
  836. *
  837. * @wm: watermark calculation data
  838. *
  839. * Calculate the min available bandwidth used for display (CIK).
  840. * Used for display watermark bandwidth calculations
  841. * Returns the min available bandwidth in MBytes/s
  842. */
  843. static u32 dce_v8_0_available_bandwidth(struct dce8_wm_params *wm)
  844. {
  845. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  846. u32 dram_bandwidth = dce_v8_0_dram_bandwidth(wm);
  847. u32 data_return_bandwidth = dce_v8_0_data_return_bandwidth(wm);
  848. u32 dmif_req_bandwidth = dce_v8_0_dmif_request_bandwidth(wm);
  849. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  850. }
  851. /**
  852. * dce_v8_0_average_bandwidth - get the average available bandwidth
  853. *
  854. * @wm: watermark calculation data
  855. *
  856. * Calculate the average available bandwidth used for display (CIK).
  857. * Used for display watermark bandwidth calculations
  858. * Returns the average available bandwidth in MBytes/s
  859. */
  860. static u32 dce_v8_0_average_bandwidth(struct dce8_wm_params *wm)
  861. {
  862. /* Calculate the display mode Average Bandwidth
  863. * DisplayMode should contain the source and destination dimensions,
  864. * timing, etc.
  865. */
  866. fixed20_12 bpp;
  867. fixed20_12 line_time;
  868. fixed20_12 src_width;
  869. fixed20_12 bandwidth;
  870. fixed20_12 a;
  871. a.full = dfixed_const(1000);
  872. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  873. line_time.full = dfixed_div(line_time, a);
  874. bpp.full = dfixed_const(wm->bytes_per_pixel);
  875. src_width.full = dfixed_const(wm->src_width);
  876. bandwidth.full = dfixed_mul(src_width, bpp);
  877. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  878. bandwidth.full = dfixed_div(bandwidth, line_time);
  879. return dfixed_trunc(bandwidth);
  880. }
  881. /**
  882. * dce_v8_0_latency_watermark - get the latency watermark
  883. *
  884. * @wm: watermark calculation data
  885. *
  886. * Calculate the latency watermark (CIK).
  887. * Used for display watermark bandwidth calculations
  888. * Returns the latency watermark in ns
  889. */
  890. static u32 dce_v8_0_latency_watermark(struct dce8_wm_params *wm)
  891. {
  892. /* First calculate the latency in ns */
  893. u32 mc_latency = 2000; /* 2000 ns. */
  894. u32 available_bandwidth = dce_v8_0_available_bandwidth(wm);
  895. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  896. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  897. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  898. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  899. (wm->num_heads * cursor_line_pair_return_time);
  900. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  901. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  902. u32 tmp, dmif_size = 12288;
  903. fixed20_12 a, b, c;
  904. if (wm->num_heads == 0)
  905. return 0;
  906. a.full = dfixed_const(2);
  907. b.full = dfixed_const(1);
  908. if ((wm->vsc.full > a.full) ||
  909. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  910. (wm->vtaps >= 5) ||
  911. ((wm->vsc.full >= a.full) && wm->interlaced))
  912. max_src_lines_per_dst_line = 4;
  913. else
  914. max_src_lines_per_dst_line = 2;
  915. a.full = dfixed_const(available_bandwidth);
  916. b.full = dfixed_const(wm->num_heads);
  917. a.full = dfixed_div(a, b);
  918. b.full = dfixed_const(mc_latency + 512);
  919. c.full = dfixed_const(wm->disp_clk);
  920. b.full = dfixed_div(b, c);
  921. c.full = dfixed_const(dmif_size);
  922. b.full = dfixed_div(c, b);
  923. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  924. b.full = dfixed_const(1000);
  925. c.full = dfixed_const(wm->disp_clk);
  926. b.full = dfixed_div(c, b);
  927. c.full = dfixed_const(wm->bytes_per_pixel);
  928. b.full = dfixed_mul(b, c);
  929. lb_fill_bw = min(tmp, dfixed_trunc(b));
  930. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  931. b.full = dfixed_const(1000);
  932. c.full = dfixed_const(lb_fill_bw);
  933. b.full = dfixed_div(c, b);
  934. a.full = dfixed_div(a, b);
  935. line_fill_time = dfixed_trunc(a);
  936. if (line_fill_time < wm->active_time)
  937. return latency;
  938. else
  939. return latency + (line_fill_time - wm->active_time);
  940. }
  941. /**
  942. * dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display - check
  943. * average and available dram bandwidth
  944. *
  945. * @wm: watermark calculation data
  946. *
  947. * Check if the display average bandwidth fits in the display
  948. * dram bandwidth (CIK).
  949. * Used for display watermark bandwidth calculations
  950. * Returns true if the display fits, false if not.
  951. */
  952. static bool dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
  953. {
  954. if (dce_v8_0_average_bandwidth(wm) <=
  955. (dce_v8_0_dram_bandwidth_for_display(wm) / wm->num_heads))
  956. return true;
  957. else
  958. return false;
  959. }
  960. /**
  961. * dce_v8_0_average_bandwidth_vs_available_bandwidth - check
  962. * average and available bandwidth
  963. *
  964. * @wm: watermark calculation data
  965. *
  966. * Check if the display average bandwidth fits in the display
  967. * available bandwidth (CIK).
  968. * Used for display watermark bandwidth calculations
  969. * Returns true if the display fits, false if not.
  970. */
  971. static bool dce_v8_0_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
  972. {
  973. if (dce_v8_0_average_bandwidth(wm) <=
  974. (dce_v8_0_available_bandwidth(wm) / wm->num_heads))
  975. return true;
  976. else
  977. return false;
  978. }
  979. /**
  980. * dce_v8_0_check_latency_hiding - check latency hiding
  981. *
  982. * @wm: watermark calculation data
  983. *
  984. * Check latency hiding (CIK).
  985. * Used for display watermark bandwidth calculations
  986. * Returns true if the display fits, false if not.
  987. */
  988. static bool dce_v8_0_check_latency_hiding(struct dce8_wm_params *wm)
  989. {
  990. u32 lb_partitions = wm->lb_size / wm->src_width;
  991. u32 line_time = wm->active_time + wm->blank_time;
  992. u32 latency_tolerant_lines;
  993. u32 latency_hiding;
  994. fixed20_12 a;
  995. a.full = dfixed_const(1);
  996. if (wm->vsc.full > a.full)
  997. latency_tolerant_lines = 1;
  998. else {
  999. if (lb_partitions <= (wm->vtaps + 1))
  1000. latency_tolerant_lines = 1;
  1001. else
  1002. latency_tolerant_lines = 2;
  1003. }
  1004. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  1005. if (dce_v8_0_latency_watermark(wm) <= latency_hiding)
  1006. return true;
  1007. else
  1008. return false;
  1009. }
  1010. /**
  1011. * dce_v8_0_program_watermarks - program display watermarks
  1012. *
  1013. * @adev: amdgpu_device pointer
  1014. * @amdgpu_crtc: the selected display controller
  1015. * @lb_size: line buffer size
  1016. * @num_heads: number of display controllers in use
  1017. *
  1018. * Calculate and program the display watermarks for the
  1019. * selected display controller (CIK).
  1020. */
  1021. static void dce_v8_0_program_watermarks(struct amdgpu_device *adev,
  1022. struct amdgpu_crtc *amdgpu_crtc,
  1023. u32 lb_size, u32 num_heads)
  1024. {
  1025. struct drm_display_mode *mode = &amdgpu_crtc->base.mode;
  1026. struct dce8_wm_params wm_low, wm_high;
  1027. u32 pixel_period;
  1028. u32 line_time = 0;
  1029. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  1030. u32 tmp, wm_mask, lb_vblank_lead_lines = 0;
  1031. if (amdgpu_crtc->base.enabled && num_heads && mode) {
  1032. pixel_period = 1000000 / (u32)mode->clock;
  1033. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  1034. /* watermark for high clocks */
  1035. if (adev->pm.dpm_enabled) {
  1036. wm_high.yclk =
  1037. amdgpu_dpm_get_mclk(adev, false) * 10;
  1038. wm_high.sclk =
  1039. amdgpu_dpm_get_sclk(adev, false) * 10;
  1040. } else {
  1041. wm_high.yclk = adev->pm.current_mclk * 10;
  1042. wm_high.sclk = adev->pm.current_sclk * 10;
  1043. }
  1044. wm_high.disp_clk = mode->clock;
  1045. wm_high.src_width = mode->crtc_hdisplay;
  1046. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  1047. wm_high.blank_time = line_time - wm_high.active_time;
  1048. wm_high.interlaced = false;
  1049. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1050. wm_high.interlaced = true;
  1051. wm_high.vsc = amdgpu_crtc->vsc;
  1052. wm_high.vtaps = 1;
  1053. if (amdgpu_crtc->rmx_type != RMX_OFF)
  1054. wm_high.vtaps = 2;
  1055. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1056. wm_high.lb_size = lb_size;
  1057. wm_high.dram_channels = cik_get_number_of_dram_channels(adev);
  1058. wm_high.num_heads = num_heads;
  1059. /* set for high clocks */
  1060. latency_watermark_a = min(dce_v8_0_latency_watermark(&wm_high), (u32)65535);
  1061. /* possibly force display priority to high */
  1062. /* should really do this at mode validation time... */
  1063. if (!dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  1064. !dce_v8_0_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  1065. !dce_v8_0_check_latency_hiding(&wm_high) ||
  1066. (adev->mode_info.disp_priority == 2)) {
  1067. DRM_DEBUG_KMS("force priority to high\n");
  1068. }
  1069. /* watermark for low clocks */
  1070. if (adev->pm.dpm_enabled) {
  1071. wm_low.yclk =
  1072. amdgpu_dpm_get_mclk(adev, true) * 10;
  1073. wm_low.sclk =
  1074. amdgpu_dpm_get_sclk(adev, true) * 10;
  1075. } else {
  1076. wm_low.yclk = adev->pm.current_mclk * 10;
  1077. wm_low.sclk = adev->pm.current_sclk * 10;
  1078. }
  1079. wm_low.disp_clk = mode->clock;
  1080. wm_low.src_width = mode->crtc_hdisplay;
  1081. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  1082. wm_low.blank_time = line_time - wm_low.active_time;
  1083. wm_low.interlaced = false;
  1084. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1085. wm_low.interlaced = true;
  1086. wm_low.vsc = amdgpu_crtc->vsc;
  1087. wm_low.vtaps = 1;
  1088. if (amdgpu_crtc->rmx_type != RMX_OFF)
  1089. wm_low.vtaps = 2;
  1090. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1091. wm_low.lb_size = lb_size;
  1092. wm_low.dram_channels = cik_get_number_of_dram_channels(adev);
  1093. wm_low.num_heads = num_heads;
  1094. /* set for low clocks */
  1095. latency_watermark_b = min(dce_v8_0_latency_watermark(&wm_low), (u32)65535);
  1096. /* possibly force display priority to high */
  1097. /* should really do this at mode validation time... */
  1098. if (!dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  1099. !dce_v8_0_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  1100. !dce_v8_0_check_latency_hiding(&wm_low) ||
  1101. (adev->mode_info.disp_priority == 2)) {
  1102. DRM_DEBUG_KMS("force priority to high\n");
  1103. }
  1104. lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
  1105. }
  1106. /* select wm A */
  1107. wm_mask = RREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset);
  1108. tmp = wm_mask;
  1109. tmp &= ~(3 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
  1110. tmp |= (1 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
  1111. WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, tmp);
  1112. WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
  1113. ((latency_watermark_a << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
  1114. (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
  1115. /* select wm B */
  1116. tmp = RREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset);
  1117. tmp &= ~(3 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
  1118. tmp |= (2 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
  1119. WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, tmp);
  1120. WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
  1121. ((latency_watermark_b << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
  1122. (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
  1123. /* restore original selection */
  1124. WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, wm_mask);
  1125. /* save values for DPM */
  1126. amdgpu_crtc->line_time = line_time;
  1127. amdgpu_crtc->wm_high = latency_watermark_a;
  1128. amdgpu_crtc->wm_low = latency_watermark_b;
  1129. /* Save number of lines the linebuffer leads before the scanout */
  1130. amdgpu_crtc->lb_vblank_lead_lines = lb_vblank_lead_lines;
  1131. }
  1132. /**
  1133. * dce_v8_0_bandwidth_update - program display watermarks
  1134. *
  1135. * @adev: amdgpu_device pointer
  1136. *
  1137. * Calculate and program the display watermarks and line
  1138. * buffer allocation (CIK).
  1139. */
  1140. static void dce_v8_0_bandwidth_update(struct amdgpu_device *adev)
  1141. {
  1142. struct drm_display_mode *mode = NULL;
  1143. u32 num_heads = 0, lb_size;
  1144. int i;
  1145. amdgpu_update_display_priority(adev);
  1146. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1147. if (adev->mode_info.crtcs[i]->base.enabled)
  1148. num_heads++;
  1149. }
  1150. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1151. mode = &adev->mode_info.crtcs[i]->base.mode;
  1152. lb_size = dce_v8_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i], mode);
  1153. dce_v8_0_program_watermarks(adev, adev->mode_info.crtcs[i],
  1154. lb_size, num_heads);
  1155. }
  1156. }
  1157. static void dce_v8_0_audio_get_connected_pins(struct amdgpu_device *adev)
  1158. {
  1159. int i;
  1160. u32 offset, tmp;
  1161. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1162. offset = adev->mode_info.audio.pin[i].offset;
  1163. tmp = RREG32_AUDIO_ENDPT(offset,
  1164. ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT);
  1165. if (((tmp &
  1166. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY_MASK) >>
  1167. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY__SHIFT) == 1)
  1168. adev->mode_info.audio.pin[i].connected = false;
  1169. else
  1170. adev->mode_info.audio.pin[i].connected = true;
  1171. }
  1172. }
  1173. static struct amdgpu_audio_pin *dce_v8_0_audio_get_pin(struct amdgpu_device *adev)
  1174. {
  1175. int i;
  1176. dce_v8_0_audio_get_connected_pins(adev);
  1177. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1178. if (adev->mode_info.audio.pin[i].connected)
  1179. return &adev->mode_info.audio.pin[i];
  1180. }
  1181. DRM_ERROR("No connected audio pins found!\n");
  1182. return NULL;
  1183. }
  1184. static void dce_v8_0_afmt_audio_select_pin(struct drm_encoder *encoder)
  1185. {
  1186. struct amdgpu_device *adev = encoder->dev->dev_private;
  1187. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1188. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1189. u32 offset;
  1190. if (!dig || !dig->afmt || !dig->afmt->pin)
  1191. return;
  1192. offset = dig->afmt->offset;
  1193. WREG32(mmAFMT_AUDIO_SRC_CONTROL + offset,
  1194. (dig->afmt->pin->id << AFMT_AUDIO_SRC_CONTROL__AFMT_AUDIO_SRC_SELECT__SHIFT));
  1195. }
  1196. static void dce_v8_0_audio_write_latency_fields(struct drm_encoder *encoder,
  1197. struct drm_display_mode *mode)
  1198. {
  1199. struct amdgpu_device *adev = encoder->dev->dev_private;
  1200. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1201. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1202. struct drm_connector *connector;
  1203. struct amdgpu_connector *amdgpu_connector = NULL;
  1204. u32 tmp = 0, offset;
  1205. if (!dig || !dig->afmt || !dig->afmt->pin)
  1206. return;
  1207. offset = dig->afmt->pin->offset;
  1208. list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
  1209. if (connector->encoder == encoder) {
  1210. amdgpu_connector = to_amdgpu_connector(connector);
  1211. break;
  1212. }
  1213. }
  1214. if (!amdgpu_connector) {
  1215. DRM_ERROR("Couldn't find encoder's connector\n");
  1216. return;
  1217. }
  1218. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  1219. if (connector->latency_present[1])
  1220. tmp =
  1221. (connector->video_latency[1] <<
  1222. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
  1223. (connector->audio_latency[1] <<
  1224. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
  1225. else
  1226. tmp =
  1227. (0 <<
  1228. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
  1229. (0 <<
  1230. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
  1231. } else {
  1232. if (connector->latency_present[0])
  1233. tmp =
  1234. (connector->video_latency[0] <<
  1235. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
  1236. (connector->audio_latency[0] <<
  1237. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
  1238. else
  1239. tmp =
  1240. (0 <<
  1241. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
  1242. (0 <<
  1243. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
  1244. }
  1245. WREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, tmp);
  1246. }
  1247. static void dce_v8_0_audio_write_speaker_allocation(struct drm_encoder *encoder)
  1248. {
  1249. struct amdgpu_device *adev = encoder->dev->dev_private;
  1250. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1251. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1252. struct drm_connector *connector;
  1253. struct amdgpu_connector *amdgpu_connector = NULL;
  1254. u32 offset, tmp;
  1255. u8 *sadb = NULL;
  1256. int sad_count;
  1257. if (!dig || !dig->afmt || !dig->afmt->pin)
  1258. return;
  1259. offset = dig->afmt->pin->offset;
  1260. list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
  1261. if (connector->encoder == encoder) {
  1262. amdgpu_connector = to_amdgpu_connector(connector);
  1263. break;
  1264. }
  1265. }
  1266. if (!amdgpu_connector) {
  1267. DRM_ERROR("Couldn't find encoder's connector\n");
  1268. return;
  1269. }
  1270. sad_count = drm_edid_to_speaker_allocation(amdgpu_connector_edid(connector), &sadb);
  1271. if (sad_count < 0) {
  1272. DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
  1273. sad_count = 0;
  1274. }
  1275. /* program the speaker allocation */
  1276. tmp = RREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER);
  1277. tmp &= ~(AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__DP_CONNECTION_MASK |
  1278. AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION_MASK);
  1279. /* set HDMI mode */
  1280. tmp |= AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__HDMI_CONNECTION_MASK;
  1281. if (sad_count)
  1282. tmp |= (sadb[0] << AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION__SHIFT);
  1283. else
  1284. tmp |= (5 << AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION__SHIFT); /* stereo */
  1285. WREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
  1286. kfree(sadb);
  1287. }
  1288. static void dce_v8_0_audio_write_sad_regs(struct drm_encoder *encoder)
  1289. {
  1290. struct amdgpu_device *adev = encoder->dev->dev_private;
  1291. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1292. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1293. u32 offset;
  1294. struct drm_connector *connector;
  1295. struct amdgpu_connector *amdgpu_connector = NULL;
  1296. struct cea_sad *sads;
  1297. int i, sad_count;
  1298. static const u16 eld_reg_to_type[][2] = {
  1299. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
  1300. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
  1301. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
  1302. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
  1303. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
  1304. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
  1305. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
  1306. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
  1307. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
  1308. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
  1309. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
  1310. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
  1311. };
  1312. if (!dig || !dig->afmt || !dig->afmt->pin)
  1313. return;
  1314. offset = dig->afmt->pin->offset;
  1315. list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
  1316. if (connector->encoder == encoder) {
  1317. amdgpu_connector = to_amdgpu_connector(connector);
  1318. break;
  1319. }
  1320. }
  1321. if (!amdgpu_connector) {
  1322. DRM_ERROR("Couldn't find encoder's connector\n");
  1323. return;
  1324. }
  1325. sad_count = drm_edid_to_sad(amdgpu_connector_edid(connector), &sads);
  1326. if (sad_count <= 0) {
  1327. DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
  1328. return;
  1329. }
  1330. BUG_ON(!sads);
  1331. for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
  1332. u32 value = 0;
  1333. u8 stereo_freqs = 0;
  1334. int max_channels = -1;
  1335. int j;
  1336. for (j = 0; j < sad_count; j++) {
  1337. struct cea_sad *sad = &sads[j];
  1338. if (sad->format == eld_reg_to_type[i][1]) {
  1339. if (sad->channels > max_channels) {
  1340. value = (sad->channels <<
  1341. AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__MAX_CHANNELS__SHIFT) |
  1342. (sad->byte2 <<
  1343. AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__DESCRIPTOR_BYTE_2__SHIFT) |
  1344. (sad->freq <<
  1345. AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES__SHIFT);
  1346. max_channels = sad->channels;
  1347. }
  1348. if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
  1349. stereo_freqs |= sad->freq;
  1350. else
  1351. break;
  1352. }
  1353. }
  1354. value |= (stereo_freqs <<
  1355. AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES_STEREO__SHIFT);
  1356. WREG32_AUDIO_ENDPT(offset, eld_reg_to_type[i][0], value);
  1357. }
  1358. kfree(sads);
  1359. }
  1360. static void dce_v8_0_audio_enable(struct amdgpu_device *adev,
  1361. struct amdgpu_audio_pin *pin,
  1362. bool enable)
  1363. {
  1364. if (!pin)
  1365. return;
  1366. WREG32_AUDIO_ENDPT(pin->offset, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
  1367. enable ? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK : 0);
  1368. }
  1369. static const u32 pin_offsets[7] =
  1370. {
  1371. (0x1780 - 0x1780),
  1372. (0x1786 - 0x1780),
  1373. (0x178c - 0x1780),
  1374. (0x1792 - 0x1780),
  1375. (0x1798 - 0x1780),
  1376. (0x179d - 0x1780),
  1377. (0x17a4 - 0x1780),
  1378. };
  1379. static int dce_v8_0_audio_init(struct amdgpu_device *adev)
  1380. {
  1381. int i;
  1382. if (!amdgpu_audio)
  1383. return 0;
  1384. adev->mode_info.audio.enabled = true;
  1385. if (adev->asic_type == CHIP_KAVERI) /* KV: 4 streams, 7 endpoints */
  1386. adev->mode_info.audio.num_pins = 7;
  1387. else if ((adev->asic_type == CHIP_KABINI) ||
  1388. (adev->asic_type == CHIP_MULLINS)) /* KB/ML: 2 streams, 3 endpoints */
  1389. adev->mode_info.audio.num_pins = 3;
  1390. else if ((adev->asic_type == CHIP_BONAIRE) ||
  1391. (adev->asic_type == CHIP_HAWAII))/* BN/HW: 6 streams, 7 endpoints */
  1392. adev->mode_info.audio.num_pins = 7;
  1393. else
  1394. adev->mode_info.audio.num_pins = 3;
  1395. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1396. adev->mode_info.audio.pin[i].channels = -1;
  1397. adev->mode_info.audio.pin[i].rate = -1;
  1398. adev->mode_info.audio.pin[i].bits_per_sample = -1;
  1399. adev->mode_info.audio.pin[i].status_bits = 0;
  1400. adev->mode_info.audio.pin[i].category_code = 0;
  1401. adev->mode_info.audio.pin[i].connected = false;
  1402. adev->mode_info.audio.pin[i].offset = pin_offsets[i];
  1403. adev->mode_info.audio.pin[i].id = i;
  1404. /* disable audio. it will be set up later */
  1405. /* XXX remove once we switch to ip funcs */
  1406. dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  1407. }
  1408. return 0;
  1409. }
  1410. static void dce_v8_0_audio_fini(struct amdgpu_device *adev)
  1411. {
  1412. int i;
  1413. if (!amdgpu_audio)
  1414. return;
  1415. if (!adev->mode_info.audio.enabled)
  1416. return;
  1417. for (i = 0; i < adev->mode_info.audio.num_pins; i++)
  1418. dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  1419. adev->mode_info.audio.enabled = false;
  1420. }
  1421. /*
  1422. * update the N and CTS parameters for a given pixel clock rate
  1423. */
  1424. static void dce_v8_0_afmt_update_ACR(struct drm_encoder *encoder, uint32_t clock)
  1425. {
  1426. struct drm_device *dev = encoder->dev;
  1427. struct amdgpu_device *adev = dev->dev_private;
  1428. struct amdgpu_afmt_acr acr = amdgpu_afmt_acr(clock);
  1429. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1430. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1431. uint32_t offset = dig->afmt->offset;
  1432. WREG32(mmHDMI_ACR_32_0 + offset, (acr.cts_32khz << HDMI_ACR_44_0__HDMI_ACR_CTS_44__SHIFT));
  1433. WREG32(mmHDMI_ACR_32_1 + offset, acr.n_32khz);
  1434. WREG32(mmHDMI_ACR_44_0 + offset, (acr.cts_44_1khz << HDMI_ACR_44_0__HDMI_ACR_CTS_44__SHIFT));
  1435. WREG32(mmHDMI_ACR_44_1 + offset, acr.n_44_1khz);
  1436. WREG32(mmHDMI_ACR_48_0 + offset, (acr.cts_48khz << HDMI_ACR_48_0__HDMI_ACR_CTS_48__SHIFT));
  1437. WREG32(mmHDMI_ACR_48_1 + offset, acr.n_48khz);
  1438. }
  1439. /*
  1440. * build a HDMI Video Info Frame
  1441. */
  1442. static void dce_v8_0_afmt_update_avi_infoframe(struct drm_encoder *encoder,
  1443. void *buffer, size_t size)
  1444. {
  1445. struct drm_device *dev = encoder->dev;
  1446. struct amdgpu_device *adev = dev->dev_private;
  1447. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1448. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1449. uint32_t offset = dig->afmt->offset;
  1450. uint8_t *frame = buffer + 3;
  1451. uint8_t *header = buffer;
  1452. WREG32(mmAFMT_AVI_INFO0 + offset,
  1453. frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
  1454. WREG32(mmAFMT_AVI_INFO1 + offset,
  1455. frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
  1456. WREG32(mmAFMT_AVI_INFO2 + offset,
  1457. frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
  1458. WREG32(mmAFMT_AVI_INFO3 + offset,
  1459. frame[0xC] | (frame[0xD] << 8) | (header[1] << 24));
  1460. }
  1461. static void dce_v8_0_audio_set_dto(struct drm_encoder *encoder, u32 clock)
  1462. {
  1463. struct drm_device *dev = encoder->dev;
  1464. struct amdgpu_device *adev = dev->dev_private;
  1465. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1466. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1467. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
  1468. u32 dto_phase = 24 * 1000;
  1469. u32 dto_modulo = clock;
  1470. if (!dig || !dig->afmt)
  1471. return;
  1472. /* XXX two dtos; generally use dto0 for hdmi */
  1473. /* Express [24MHz / target pixel clock] as an exact rational
  1474. * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
  1475. * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
  1476. */
  1477. WREG32(mmDCCG_AUDIO_DTO_SOURCE, (amdgpu_crtc->crtc_id << DCCG_AUDIO_DTO_SOURCE__DCCG_AUDIO_DTO0_SOURCE_SEL__SHIFT));
  1478. WREG32(mmDCCG_AUDIO_DTO0_PHASE, dto_phase);
  1479. WREG32(mmDCCG_AUDIO_DTO0_MODULE, dto_modulo);
  1480. }
  1481. /*
  1482. * update the info frames with the data from the current display mode
  1483. */
  1484. static void dce_v8_0_afmt_setmode(struct drm_encoder *encoder,
  1485. struct drm_display_mode *mode)
  1486. {
  1487. struct drm_device *dev = encoder->dev;
  1488. struct amdgpu_device *adev = dev->dev_private;
  1489. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1490. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1491. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  1492. u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
  1493. struct hdmi_avi_infoframe frame;
  1494. uint32_t offset, val;
  1495. ssize_t err;
  1496. int bpc = 8;
  1497. if (!dig || !dig->afmt)
  1498. return;
  1499. /* Silent, r600_hdmi_enable will raise WARN for us */
  1500. if (!dig->afmt->enabled)
  1501. return;
  1502. offset = dig->afmt->offset;
  1503. /* hdmi deep color mode general control packets setup, if bpc > 8 */
  1504. if (encoder->crtc) {
  1505. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
  1506. bpc = amdgpu_crtc->bpc;
  1507. }
  1508. /* disable audio prior to setting up hw */
  1509. dig->afmt->pin = dce_v8_0_audio_get_pin(adev);
  1510. dce_v8_0_audio_enable(adev, dig->afmt->pin, false);
  1511. dce_v8_0_audio_set_dto(encoder, mode->clock);
  1512. WREG32(mmHDMI_VBI_PACKET_CONTROL + offset,
  1513. HDMI_VBI_PACKET_CONTROL__HDMI_NULL_SEND_MASK); /* send null packets when required */
  1514. WREG32(mmAFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
  1515. val = RREG32(mmHDMI_CONTROL + offset);
  1516. val &= ~HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
  1517. val &= ~HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH_MASK;
  1518. switch (bpc) {
  1519. case 0:
  1520. case 6:
  1521. case 8:
  1522. case 16:
  1523. default:
  1524. DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n",
  1525. connector->name, bpc);
  1526. break;
  1527. case 10:
  1528. val |= HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
  1529. val |= 1 << HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH__SHIFT;
  1530. DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n",
  1531. connector->name);
  1532. break;
  1533. case 12:
  1534. val |= HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
  1535. val |= 2 << HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH__SHIFT;
  1536. DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n",
  1537. connector->name);
  1538. break;
  1539. }
  1540. WREG32(mmHDMI_CONTROL + offset, val);
  1541. WREG32(mmHDMI_VBI_PACKET_CONTROL + offset,
  1542. HDMI_VBI_PACKET_CONTROL__HDMI_NULL_SEND_MASK | /* send null packets when required */
  1543. HDMI_VBI_PACKET_CONTROL__HDMI_GC_SEND_MASK | /* send general control packets */
  1544. HDMI_VBI_PACKET_CONTROL__HDMI_GC_CONT_MASK); /* send general control packets every frame */
  1545. WREG32(mmHDMI_INFOFRAME_CONTROL0 + offset,
  1546. HDMI_INFOFRAME_CONTROL0__HDMI_AUDIO_INFO_SEND_MASK | /* enable audio info frames (frames won't be set until audio is enabled) */
  1547. HDMI_INFOFRAME_CONTROL0__HDMI_AUDIO_INFO_CONT_MASK); /* required for audio info values to be updated */
  1548. WREG32(mmAFMT_INFOFRAME_CONTROL0 + offset,
  1549. AFMT_INFOFRAME_CONTROL0__AFMT_AUDIO_INFO_UPDATE_MASK); /* required for audio info values to be updated */
  1550. WREG32(mmHDMI_INFOFRAME_CONTROL1 + offset,
  1551. (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AUDIO_INFO_LINE__SHIFT)); /* anything other than 0 */
  1552. WREG32(mmHDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
  1553. WREG32(mmHDMI_AUDIO_PACKET_CONTROL + offset,
  1554. (1 << HDMI_AUDIO_PACKET_CONTROL__HDMI_AUDIO_DELAY_EN__SHIFT) | /* set the default audio delay */
  1555. (3 << HDMI_AUDIO_PACKET_CONTROL__HDMI_AUDIO_PACKETS_PER_LINE__SHIFT)); /* should be suffient for all audio modes and small enough for all hblanks */
  1556. WREG32(mmAFMT_AUDIO_PACKET_CONTROL + offset,
  1557. AFMT_AUDIO_PACKET_CONTROL__AFMT_60958_CS_UPDATE_MASK); /* allow 60958 channel status fields to be updated */
  1558. /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
  1559. if (bpc > 8)
  1560. WREG32(mmHDMI_ACR_PACKET_CONTROL + offset,
  1561. HDMI_ACR_PACKET_CONTROL__HDMI_ACR_AUTO_SEND_MASK); /* allow hw to sent ACR packets when required */
  1562. else
  1563. WREG32(mmHDMI_ACR_PACKET_CONTROL + offset,
  1564. HDMI_ACR_PACKET_CONTROL__HDMI_ACR_SOURCE_MASK | /* select SW CTS value */
  1565. HDMI_ACR_PACKET_CONTROL__HDMI_ACR_AUTO_SEND_MASK); /* allow hw to sent ACR packets when required */
  1566. dce_v8_0_afmt_update_ACR(encoder, mode->clock);
  1567. WREG32(mmAFMT_60958_0 + offset,
  1568. (1 << AFMT_60958_0__AFMT_60958_CS_CHANNEL_NUMBER_L__SHIFT));
  1569. WREG32(mmAFMT_60958_1 + offset,
  1570. (2 << AFMT_60958_1__AFMT_60958_CS_CHANNEL_NUMBER_R__SHIFT));
  1571. WREG32(mmAFMT_60958_2 + offset,
  1572. (3 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_2__SHIFT) |
  1573. (4 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_3__SHIFT) |
  1574. (5 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_4__SHIFT) |
  1575. (6 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_5__SHIFT) |
  1576. (7 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_6__SHIFT) |
  1577. (8 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_7__SHIFT));
  1578. dce_v8_0_audio_write_speaker_allocation(encoder);
  1579. WREG32(mmAFMT_AUDIO_PACKET_CONTROL2 + offset,
  1580. (0xff << AFMT_AUDIO_PACKET_CONTROL2__AFMT_AUDIO_CHANNEL_ENABLE__SHIFT));
  1581. dce_v8_0_afmt_audio_select_pin(encoder);
  1582. dce_v8_0_audio_write_sad_regs(encoder);
  1583. dce_v8_0_audio_write_latency_fields(encoder, mode);
  1584. err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
  1585. if (err < 0) {
  1586. DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
  1587. return;
  1588. }
  1589. err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
  1590. if (err < 0) {
  1591. DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
  1592. return;
  1593. }
  1594. dce_v8_0_afmt_update_avi_infoframe(encoder, buffer, sizeof(buffer));
  1595. WREG32_OR(mmHDMI_INFOFRAME_CONTROL0 + offset,
  1596. HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_SEND_MASK | /* enable AVI info frames */
  1597. HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_SEND_MASK); /* required for audio info values to be updated */
  1598. WREG32_P(mmHDMI_INFOFRAME_CONTROL1 + offset,
  1599. (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE__SHIFT), /* anything other than 0 */
  1600. ~HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE_MASK);
  1601. WREG32_OR(mmAFMT_AUDIO_PACKET_CONTROL + offset,
  1602. AFMT_AUDIO_PACKET_CONTROL__AFMT_AUDIO_SAMPLE_SEND_MASK); /* send audio packets */
  1603. /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
  1604. WREG32(mmAFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
  1605. WREG32(mmAFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
  1606. WREG32(mmAFMT_RAMP_CONTROL2 + offset, 0x00000001);
  1607. WREG32(mmAFMT_RAMP_CONTROL3 + offset, 0x00000001);
  1608. /* enable audio after to setting up hw */
  1609. dce_v8_0_audio_enable(adev, dig->afmt->pin, true);
  1610. }
  1611. static void dce_v8_0_afmt_enable(struct drm_encoder *encoder, bool enable)
  1612. {
  1613. struct drm_device *dev = encoder->dev;
  1614. struct amdgpu_device *adev = dev->dev_private;
  1615. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1616. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1617. if (!dig || !dig->afmt)
  1618. return;
  1619. /* Silent, r600_hdmi_enable will raise WARN for us */
  1620. if (enable && dig->afmt->enabled)
  1621. return;
  1622. if (!enable && !dig->afmt->enabled)
  1623. return;
  1624. if (!enable && dig->afmt->pin) {
  1625. dce_v8_0_audio_enable(adev, dig->afmt->pin, false);
  1626. dig->afmt->pin = NULL;
  1627. }
  1628. dig->afmt->enabled = enable;
  1629. DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
  1630. enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id);
  1631. }
  1632. static int dce_v8_0_afmt_init(struct amdgpu_device *adev)
  1633. {
  1634. int i;
  1635. for (i = 0; i < adev->mode_info.num_dig; i++)
  1636. adev->mode_info.afmt[i] = NULL;
  1637. /* DCE8 has audio blocks tied to DIG encoders */
  1638. for (i = 0; i < adev->mode_info.num_dig; i++) {
  1639. adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL);
  1640. if (adev->mode_info.afmt[i]) {
  1641. adev->mode_info.afmt[i]->offset = dig_offsets[i];
  1642. adev->mode_info.afmt[i]->id = i;
  1643. } else {
  1644. int j;
  1645. for (j = 0; j < i; j++) {
  1646. kfree(adev->mode_info.afmt[j]);
  1647. adev->mode_info.afmt[j] = NULL;
  1648. }
  1649. return -ENOMEM;
  1650. }
  1651. }
  1652. return 0;
  1653. }
  1654. static void dce_v8_0_afmt_fini(struct amdgpu_device *adev)
  1655. {
  1656. int i;
  1657. for (i = 0; i < adev->mode_info.num_dig; i++) {
  1658. kfree(adev->mode_info.afmt[i]);
  1659. adev->mode_info.afmt[i] = NULL;
  1660. }
  1661. }
  1662. static const u32 vga_control_regs[6] =
  1663. {
  1664. mmD1VGA_CONTROL,
  1665. mmD2VGA_CONTROL,
  1666. mmD3VGA_CONTROL,
  1667. mmD4VGA_CONTROL,
  1668. mmD5VGA_CONTROL,
  1669. mmD6VGA_CONTROL,
  1670. };
  1671. static void dce_v8_0_vga_enable(struct drm_crtc *crtc, bool enable)
  1672. {
  1673. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1674. struct drm_device *dev = crtc->dev;
  1675. struct amdgpu_device *adev = dev->dev_private;
  1676. u32 vga_control;
  1677. vga_control = RREG32(vga_control_regs[amdgpu_crtc->crtc_id]) & ~1;
  1678. if (enable)
  1679. WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control | 1);
  1680. else
  1681. WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control);
  1682. }
  1683. static void dce_v8_0_grph_enable(struct drm_crtc *crtc, bool enable)
  1684. {
  1685. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1686. struct drm_device *dev = crtc->dev;
  1687. struct amdgpu_device *adev = dev->dev_private;
  1688. if (enable)
  1689. WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 1);
  1690. else
  1691. WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0);
  1692. }
  1693. static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
  1694. struct drm_framebuffer *fb,
  1695. int x, int y, int atomic)
  1696. {
  1697. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1698. struct drm_device *dev = crtc->dev;
  1699. struct amdgpu_device *adev = dev->dev_private;
  1700. struct amdgpu_framebuffer *amdgpu_fb;
  1701. struct drm_framebuffer *target_fb;
  1702. struct drm_gem_object *obj;
  1703. struct amdgpu_bo *rbo;
  1704. uint64_t fb_location, tiling_flags;
  1705. uint32_t fb_format, fb_pitch_pixels;
  1706. u32 fb_swap = (GRPH_ENDIAN_NONE << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1707. u32 pipe_config;
  1708. u32 viewport_w, viewport_h;
  1709. int r;
  1710. bool bypass_lut = false;
  1711. /* no fb bound */
  1712. if (!atomic && !crtc->primary->fb) {
  1713. DRM_DEBUG_KMS("No FB bound\n");
  1714. return 0;
  1715. }
  1716. if (atomic) {
  1717. amdgpu_fb = to_amdgpu_framebuffer(fb);
  1718. target_fb = fb;
  1719. } else {
  1720. amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
  1721. target_fb = crtc->primary->fb;
  1722. }
  1723. /* If atomic, assume fb object is pinned & idle & fenced and
  1724. * just update base pointers
  1725. */
  1726. obj = amdgpu_fb->obj;
  1727. rbo = gem_to_amdgpu_bo(obj);
  1728. r = amdgpu_bo_reserve(rbo, false);
  1729. if (unlikely(r != 0))
  1730. return r;
  1731. if (atomic) {
  1732. fb_location = amdgpu_bo_gpu_offset(rbo);
  1733. } else {
  1734. r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &fb_location);
  1735. if (unlikely(r != 0)) {
  1736. amdgpu_bo_unreserve(rbo);
  1737. return -EINVAL;
  1738. }
  1739. }
  1740. amdgpu_bo_get_tiling_flags(rbo, &tiling_flags);
  1741. amdgpu_bo_unreserve(rbo);
  1742. pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
  1743. switch (target_fb->pixel_format) {
  1744. case DRM_FORMAT_C8:
  1745. fb_format = ((GRPH_DEPTH_8BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1746. (GRPH_FORMAT_INDEXED << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1747. break;
  1748. case DRM_FORMAT_XRGB4444:
  1749. case DRM_FORMAT_ARGB4444:
  1750. fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1751. (GRPH_FORMAT_ARGB1555 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1752. #ifdef __BIG_ENDIAN
  1753. fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1754. #endif
  1755. break;
  1756. case DRM_FORMAT_XRGB1555:
  1757. case DRM_FORMAT_ARGB1555:
  1758. fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1759. (GRPH_FORMAT_ARGB1555 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1760. #ifdef __BIG_ENDIAN
  1761. fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1762. #endif
  1763. break;
  1764. case DRM_FORMAT_BGRX5551:
  1765. case DRM_FORMAT_BGRA5551:
  1766. fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1767. (GRPH_FORMAT_BGRA5551 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1768. #ifdef __BIG_ENDIAN
  1769. fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1770. #endif
  1771. break;
  1772. case DRM_FORMAT_RGB565:
  1773. fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1774. (GRPH_FORMAT_ARGB565 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1775. #ifdef __BIG_ENDIAN
  1776. fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1777. #endif
  1778. break;
  1779. case DRM_FORMAT_XRGB8888:
  1780. case DRM_FORMAT_ARGB8888:
  1781. fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1782. (GRPH_FORMAT_ARGB8888 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1783. #ifdef __BIG_ENDIAN
  1784. fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1785. #endif
  1786. break;
  1787. case DRM_FORMAT_XRGB2101010:
  1788. case DRM_FORMAT_ARGB2101010:
  1789. fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1790. (GRPH_FORMAT_ARGB2101010 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1791. #ifdef __BIG_ENDIAN
  1792. fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1793. #endif
  1794. /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
  1795. bypass_lut = true;
  1796. break;
  1797. case DRM_FORMAT_BGRX1010102:
  1798. case DRM_FORMAT_BGRA1010102:
  1799. fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1800. (GRPH_FORMAT_BGRA1010102 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1801. #ifdef __BIG_ENDIAN
  1802. fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1803. #endif
  1804. /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
  1805. bypass_lut = true;
  1806. break;
  1807. default:
  1808. DRM_ERROR("Unsupported screen format %s\n",
  1809. drm_get_format_name(target_fb->pixel_format));
  1810. return -EINVAL;
  1811. }
  1812. if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
  1813. unsigned bankw, bankh, mtaspect, tile_split, num_banks;
  1814. bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
  1815. bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
  1816. mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
  1817. tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
  1818. num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
  1819. fb_format |= (num_banks << GRPH_CONTROL__GRPH_NUM_BANKS__SHIFT);
  1820. fb_format |= (GRPH_ARRAY_2D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT);
  1821. fb_format |= (tile_split << GRPH_CONTROL__GRPH_TILE_SPLIT__SHIFT);
  1822. fb_format |= (bankw << GRPH_CONTROL__GRPH_BANK_WIDTH__SHIFT);
  1823. fb_format |= (bankh << GRPH_CONTROL__GRPH_BANK_HEIGHT__SHIFT);
  1824. fb_format |= (mtaspect << GRPH_CONTROL__GRPH_MACRO_TILE_ASPECT__SHIFT);
  1825. fb_format |= (DISPLAY_MICRO_TILING << GRPH_CONTROL__GRPH_MICRO_TILE_MODE__SHIFT);
  1826. } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
  1827. fb_format |= (GRPH_ARRAY_1D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT);
  1828. }
  1829. fb_format |= (pipe_config << GRPH_CONTROL__GRPH_PIPE_CONFIG__SHIFT);
  1830. dce_v8_0_vga_enable(crtc, false);
  1831. /* Make sure surface address is updated at vertical blank rather than
  1832. * horizontal blank
  1833. */
  1834. WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, 0);
  1835. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1836. upper_32_bits(fb_location));
  1837. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1838. upper_32_bits(fb_location));
  1839. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1840. (u32)fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
  1841. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1842. (u32) fb_location & GRPH_SECONDARY_SURFACE_ADDRESS__GRPH_SECONDARY_SURFACE_ADDRESS_MASK);
  1843. WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format);
  1844. WREG32(mmGRPH_SWAP_CNTL + amdgpu_crtc->crtc_offset, fb_swap);
  1845. /*
  1846. * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
  1847. * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
  1848. * retain the full precision throughout the pipeline.
  1849. */
  1850. WREG32_P(mmGRPH_LUT_10BIT_BYPASS_CONTROL + amdgpu_crtc->crtc_offset,
  1851. (bypass_lut ? LUT_10BIT_BYPASS_EN : 0),
  1852. ~LUT_10BIT_BYPASS_EN);
  1853. if (bypass_lut)
  1854. DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
  1855. WREG32(mmGRPH_SURFACE_OFFSET_X + amdgpu_crtc->crtc_offset, 0);
  1856. WREG32(mmGRPH_SURFACE_OFFSET_Y + amdgpu_crtc->crtc_offset, 0);
  1857. WREG32(mmGRPH_X_START + amdgpu_crtc->crtc_offset, 0);
  1858. WREG32(mmGRPH_Y_START + amdgpu_crtc->crtc_offset, 0);
  1859. WREG32(mmGRPH_X_END + amdgpu_crtc->crtc_offset, target_fb->width);
  1860. WREG32(mmGRPH_Y_END + amdgpu_crtc->crtc_offset, target_fb->height);
  1861. fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8);
  1862. WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, fb_pitch_pixels);
  1863. dce_v8_0_grph_enable(crtc, true);
  1864. WREG32(mmLB_DESKTOP_HEIGHT + amdgpu_crtc->crtc_offset,
  1865. target_fb->height);
  1866. x &= ~3;
  1867. y &= ~1;
  1868. WREG32(mmVIEWPORT_START + amdgpu_crtc->crtc_offset,
  1869. (x << 16) | y);
  1870. viewport_w = crtc->mode.hdisplay;
  1871. viewport_h = (crtc->mode.vdisplay + 1) & ~1;
  1872. WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
  1873. (viewport_w << 16) | viewport_h);
  1874. /* set pageflip to happen only at start of vblank interval (front porch) */
  1875. WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 3);
  1876. if (!atomic && fb && fb != crtc->primary->fb) {
  1877. amdgpu_fb = to_amdgpu_framebuffer(fb);
  1878. rbo = gem_to_amdgpu_bo(amdgpu_fb->obj);
  1879. r = amdgpu_bo_reserve(rbo, false);
  1880. if (unlikely(r != 0))
  1881. return r;
  1882. amdgpu_bo_unpin(rbo);
  1883. amdgpu_bo_unreserve(rbo);
  1884. }
  1885. /* Bytes per pixel may have changed */
  1886. dce_v8_0_bandwidth_update(adev);
  1887. return 0;
  1888. }
  1889. static void dce_v8_0_set_interleave(struct drm_crtc *crtc,
  1890. struct drm_display_mode *mode)
  1891. {
  1892. struct drm_device *dev = crtc->dev;
  1893. struct amdgpu_device *adev = dev->dev_private;
  1894. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1895. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1896. WREG32(mmLB_DATA_FORMAT + amdgpu_crtc->crtc_offset,
  1897. LB_DATA_FORMAT__INTERLEAVE_EN__SHIFT);
  1898. else
  1899. WREG32(mmLB_DATA_FORMAT + amdgpu_crtc->crtc_offset, 0);
  1900. }
  1901. static void dce_v8_0_crtc_load_lut(struct drm_crtc *crtc)
  1902. {
  1903. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1904. struct drm_device *dev = crtc->dev;
  1905. struct amdgpu_device *adev = dev->dev_private;
  1906. int i;
  1907. DRM_DEBUG_KMS("%d\n", amdgpu_crtc->crtc_id);
  1908. WREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
  1909. ((INPUT_CSC_BYPASS << INPUT_CSC_CONTROL__INPUT_CSC_GRPH_MODE__SHIFT) |
  1910. (INPUT_CSC_BYPASS << INPUT_CSC_CONTROL__INPUT_CSC_OVL_MODE__SHIFT)));
  1911. WREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset,
  1912. PRESCALE_GRPH_CONTROL__GRPH_PRESCALE_BYPASS_MASK);
  1913. WREG32(mmPRESCALE_OVL_CONTROL + amdgpu_crtc->crtc_offset,
  1914. PRESCALE_OVL_CONTROL__OVL_PRESCALE_BYPASS_MASK);
  1915. WREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1916. ((INPUT_GAMMA_USE_LUT << INPUT_GAMMA_CONTROL__GRPH_INPUT_GAMMA_MODE__SHIFT) |
  1917. (INPUT_GAMMA_USE_LUT << INPUT_GAMMA_CONTROL__OVL_INPUT_GAMMA_MODE__SHIFT)));
  1918. WREG32(mmDC_LUT_CONTROL + amdgpu_crtc->crtc_offset, 0);
  1919. WREG32(mmDC_LUT_BLACK_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0);
  1920. WREG32(mmDC_LUT_BLACK_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0);
  1921. WREG32(mmDC_LUT_BLACK_OFFSET_RED + amdgpu_crtc->crtc_offset, 0);
  1922. WREG32(mmDC_LUT_WHITE_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0xffff);
  1923. WREG32(mmDC_LUT_WHITE_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0xffff);
  1924. WREG32(mmDC_LUT_WHITE_OFFSET_RED + amdgpu_crtc->crtc_offset, 0xffff);
  1925. WREG32(mmDC_LUT_RW_MODE + amdgpu_crtc->crtc_offset, 0);
  1926. WREG32(mmDC_LUT_WRITE_EN_MASK + amdgpu_crtc->crtc_offset, 0x00000007);
  1927. WREG32(mmDC_LUT_RW_INDEX + amdgpu_crtc->crtc_offset, 0);
  1928. for (i = 0; i < 256; i++) {
  1929. WREG32(mmDC_LUT_30_COLOR + amdgpu_crtc->crtc_offset,
  1930. (amdgpu_crtc->lut_r[i] << 20) |
  1931. (amdgpu_crtc->lut_g[i] << 10) |
  1932. (amdgpu_crtc->lut_b[i] << 0));
  1933. }
  1934. WREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1935. ((DEGAMMA_BYPASS << DEGAMMA_CONTROL__GRPH_DEGAMMA_MODE__SHIFT) |
  1936. (DEGAMMA_BYPASS << DEGAMMA_CONTROL__OVL_DEGAMMA_MODE__SHIFT) |
  1937. (DEGAMMA_BYPASS << DEGAMMA_CONTROL__CURSOR_DEGAMMA_MODE__SHIFT)));
  1938. WREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset,
  1939. ((GAMUT_REMAP_BYPASS << GAMUT_REMAP_CONTROL__GRPH_GAMUT_REMAP_MODE__SHIFT) |
  1940. (GAMUT_REMAP_BYPASS << GAMUT_REMAP_CONTROL__OVL_GAMUT_REMAP_MODE__SHIFT)));
  1941. WREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1942. ((REGAMMA_BYPASS << REGAMMA_CONTROL__GRPH_REGAMMA_MODE__SHIFT) |
  1943. (REGAMMA_BYPASS << REGAMMA_CONTROL__OVL_REGAMMA_MODE__SHIFT)));
  1944. WREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
  1945. ((OUTPUT_CSC_BYPASS << OUTPUT_CSC_CONTROL__OUTPUT_CSC_GRPH_MODE__SHIFT) |
  1946. (OUTPUT_CSC_BYPASS << OUTPUT_CSC_CONTROL__OUTPUT_CSC_OVL_MODE__SHIFT)));
  1947. /* XXX match this to the depth of the crtc fmt block, move to modeset? */
  1948. WREG32(0x1a50 + amdgpu_crtc->crtc_offset, 0);
  1949. /* XXX this only needs to be programmed once per crtc at startup,
  1950. * not sure where the best place for it is
  1951. */
  1952. WREG32(mmALPHA_CONTROL + amdgpu_crtc->crtc_offset,
  1953. ALPHA_CONTROL__CURSOR_ALPHA_BLND_ENA_MASK);
  1954. }
  1955. static int dce_v8_0_pick_dig_encoder(struct drm_encoder *encoder)
  1956. {
  1957. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1958. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1959. switch (amdgpu_encoder->encoder_id) {
  1960. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1961. if (dig->linkb)
  1962. return 1;
  1963. else
  1964. return 0;
  1965. break;
  1966. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1967. if (dig->linkb)
  1968. return 3;
  1969. else
  1970. return 2;
  1971. break;
  1972. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1973. if (dig->linkb)
  1974. return 5;
  1975. else
  1976. return 4;
  1977. break;
  1978. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  1979. return 6;
  1980. break;
  1981. default:
  1982. DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id);
  1983. return 0;
  1984. }
  1985. }
  1986. /**
  1987. * dce_v8_0_pick_pll - Allocate a PPLL for use by the crtc.
  1988. *
  1989. * @crtc: drm crtc
  1990. *
  1991. * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
  1992. * a single PPLL can be used for all DP crtcs/encoders. For non-DP
  1993. * monitors a dedicated PPLL must be used. If a particular board has
  1994. * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
  1995. * as there is no need to program the PLL itself. If we are not able to
  1996. * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
  1997. * avoid messing up an existing monitor.
  1998. *
  1999. * Asic specific PLL information
  2000. *
  2001. * DCE 8.x
  2002. * KB/KV
  2003. * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP)
  2004. * CI
  2005. * - PPLL0, PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC
  2006. *
  2007. */
  2008. static u32 dce_v8_0_pick_pll(struct drm_crtc *crtc)
  2009. {
  2010. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2011. struct drm_device *dev = crtc->dev;
  2012. struct amdgpu_device *adev = dev->dev_private;
  2013. u32 pll_in_use;
  2014. int pll;
  2015. if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) {
  2016. if (adev->clock.dp_extclk)
  2017. /* skip PPLL programming if using ext clock */
  2018. return ATOM_PPLL_INVALID;
  2019. else {
  2020. /* use the same PPLL for all DP monitors */
  2021. pll = amdgpu_pll_get_shared_dp_ppll(crtc);
  2022. if (pll != ATOM_PPLL_INVALID)
  2023. return pll;
  2024. }
  2025. } else {
  2026. /* use the same PPLL for all monitors with the same clock */
  2027. pll = amdgpu_pll_get_shared_nondp_ppll(crtc);
  2028. if (pll != ATOM_PPLL_INVALID)
  2029. return pll;
  2030. }
  2031. /* otherwise, pick one of the plls */
  2032. if ((adev->asic_type == CHIP_KABINI) ||
  2033. (adev->asic_type == CHIP_MULLINS)) {
  2034. /* KB/ML has PPLL1 and PPLL2 */
  2035. pll_in_use = amdgpu_pll_get_use_mask(crtc);
  2036. if (!(pll_in_use & (1 << ATOM_PPLL2)))
  2037. return ATOM_PPLL2;
  2038. if (!(pll_in_use & (1 << ATOM_PPLL1)))
  2039. return ATOM_PPLL1;
  2040. DRM_ERROR("unable to allocate a PPLL\n");
  2041. return ATOM_PPLL_INVALID;
  2042. } else {
  2043. /* CI/KV has PPLL0, PPLL1, and PPLL2 */
  2044. pll_in_use = amdgpu_pll_get_use_mask(crtc);
  2045. if (!(pll_in_use & (1 << ATOM_PPLL2)))
  2046. return ATOM_PPLL2;
  2047. if (!(pll_in_use & (1 << ATOM_PPLL1)))
  2048. return ATOM_PPLL1;
  2049. if (!(pll_in_use & (1 << ATOM_PPLL0)))
  2050. return ATOM_PPLL0;
  2051. DRM_ERROR("unable to allocate a PPLL\n");
  2052. return ATOM_PPLL_INVALID;
  2053. }
  2054. return ATOM_PPLL_INVALID;
  2055. }
  2056. static void dce_v8_0_lock_cursor(struct drm_crtc *crtc, bool lock)
  2057. {
  2058. struct amdgpu_device *adev = crtc->dev->dev_private;
  2059. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2060. uint32_t cur_lock;
  2061. cur_lock = RREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset);
  2062. if (lock)
  2063. cur_lock |= CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
  2064. else
  2065. cur_lock &= ~CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
  2066. WREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset, cur_lock);
  2067. }
  2068. static void dce_v8_0_hide_cursor(struct drm_crtc *crtc)
  2069. {
  2070. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2071. struct amdgpu_device *adev = crtc->dev->dev_private;
  2072. WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
  2073. (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
  2074. (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
  2075. }
  2076. static void dce_v8_0_show_cursor(struct drm_crtc *crtc)
  2077. {
  2078. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2079. struct amdgpu_device *adev = crtc->dev->dev_private;
  2080. WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  2081. upper_32_bits(amdgpu_crtc->cursor_addr));
  2082. WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  2083. lower_32_bits(amdgpu_crtc->cursor_addr));
  2084. WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
  2085. CUR_CONTROL__CURSOR_EN_MASK |
  2086. (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
  2087. (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
  2088. }
  2089. static int dce_v8_0_cursor_move_locked(struct drm_crtc *crtc,
  2090. int x, int y)
  2091. {
  2092. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2093. struct amdgpu_device *adev = crtc->dev->dev_private;
  2094. int xorigin = 0, yorigin = 0;
  2095. /* avivo cursor are offset into the total surface */
  2096. x += crtc->x;
  2097. y += crtc->y;
  2098. DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
  2099. if (x < 0) {
  2100. xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
  2101. x = 0;
  2102. }
  2103. if (y < 0) {
  2104. yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
  2105. y = 0;
  2106. }
  2107. WREG32(mmCUR_POSITION + amdgpu_crtc->crtc_offset, (x << 16) | y);
  2108. WREG32(mmCUR_HOT_SPOT + amdgpu_crtc->crtc_offset, (xorigin << 16) | yorigin);
  2109. WREG32(mmCUR_SIZE + amdgpu_crtc->crtc_offset,
  2110. ((amdgpu_crtc->cursor_width - 1) << 16) | (amdgpu_crtc->cursor_height - 1));
  2111. amdgpu_crtc->cursor_x = x;
  2112. amdgpu_crtc->cursor_y = y;
  2113. return 0;
  2114. }
  2115. static int dce_v8_0_crtc_cursor_move(struct drm_crtc *crtc,
  2116. int x, int y)
  2117. {
  2118. int ret;
  2119. dce_v8_0_lock_cursor(crtc, true);
  2120. ret = dce_v8_0_cursor_move_locked(crtc, x, y);
  2121. dce_v8_0_lock_cursor(crtc, false);
  2122. return ret;
  2123. }
  2124. static int dce_v8_0_crtc_cursor_set2(struct drm_crtc *crtc,
  2125. struct drm_file *file_priv,
  2126. uint32_t handle,
  2127. uint32_t width,
  2128. uint32_t height,
  2129. int32_t hot_x,
  2130. int32_t hot_y)
  2131. {
  2132. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2133. struct drm_gem_object *obj;
  2134. struct amdgpu_bo *aobj;
  2135. int ret;
  2136. if (!handle) {
  2137. /* turn off cursor */
  2138. dce_v8_0_hide_cursor(crtc);
  2139. obj = NULL;
  2140. goto unpin;
  2141. }
  2142. if ((width > amdgpu_crtc->max_cursor_width) ||
  2143. (height > amdgpu_crtc->max_cursor_height)) {
  2144. DRM_ERROR("bad cursor width or height %d x %d\n", width, height);
  2145. return -EINVAL;
  2146. }
  2147. obj = drm_gem_object_lookup(file_priv, handle);
  2148. if (!obj) {
  2149. DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, amdgpu_crtc->crtc_id);
  2150. return -ENOENT;
  2151. }
  2152. aobj = gem_to_amdgpu_bo(obj);
  2153. ret = amdgpu_bo_reserve(aobj, false);
  2154. if (ret != 0) {
  2155. drm_gem_object_unreference_unlocked(obj);
  2156. return ret;
  2157. }
  2158. ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM, &amdgpu_crtc->cursor_addr);
  2159. amdgpu_bo_unreserve(aobj);
  2160. if (ret) {
  2161. DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret);
  2162. drm_gem_object_unreference_unlocked(obj);
  2163. return ret;
  2164. }
  2165. amdgpu_crtc->cursor_width = width;
  2166. amdgpu_crtc->cursor_height = height;
  2167. dce_v8_0_lock_cursor(crtc, true);
  2168. if (hot_x != amdgpu_crtc->cursor_hot_x ||
  2169. hot_y != amdgpu_crtc->cursor_hot_y) {
  2170. int x, y;
  2171. x = amdgpu_crtc->cursor_x + amdgpu_crtc->cursor_hot_x - hot_x;
  2172. y = amdgpu_crtc->cursor_y + amdgpu_crtc->cursor_hot_y - hot_y;
  2173. dce_v8_0_cursor_move_locked(crtc, x, y);
  2174. amdgpu_crtc->cursor_hot_x = hot_x;
  2175. amdgpu_crtc->cursor_hot_y = hot_y;
  2176. }
  2177. dce_v8_0_show_cursor(crtc);
  2178. dce_v8_0_lock_cursor(crtc, false);
  2179. unpin:
  2180. if (amdgpu_crtc->cursor_bo) {
  2181. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  2182. ret = amdgpu_bo_reserve(aobj, false);
  2183. if (likely(ret == 0)) {
  2184. amdgpu_bo_unpin(aobj);
  2185. amdgpu_bo_unreserve(aobj);
  2186. }
  2187. drm_gem_object_unreference_unlocked(amdgpu_crtc->cursor_bo);
  2188. }
  2189. amdgpu_crtc->cursor_bo = obj;
  2190. return 0;
  2191. }
  2192. static void dce_v8_0_cursor_reset(struct drm_crtc *crtc)
  2193. {
  2194. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2195. if (amdgpu_crtc->cursor_bo) {
  2196. dce_v8_0_lock_cursor(crtc, true);
  2197. dce_v8_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x,
  2198. amdgpu_crtc->cursor_y);
  2199. dce_v8_0_show_cursor(crtc);
  2200. dce_v8_0_lock_cursor(crtc, false);
  2201. }
  2202. }
  2203. static int dce_v8_0_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  2204. u16 *blue, uint32_t size)
  2205. {
  2206. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2207. int i;
  2208. /* userspace palettes are always correct as is */
  2209. for (i = 0; i < size; i++) {
  2210. amdgpu_crtc->lut_r[i] = red[i] >> 6;
  2211. amdgpu_crtc->lut_g[i] = green[i] >> 6;
  2212. amdgpu_crtc->lut_b[i] = blue[i] >> 6;
  2213. }
  2214. dce_v8_0_crtc_load_lut(crtc);
  2215. return 0;
  2216. }
  2217. static void dce_v8_0_crtc_destroy(struct drm_crtc *crtc)
  2218. {
  2219. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2220. drm_crtc_cleanup(crtc);
  2221. kfree(amdgpu_crtc);
  2222. }
  2223. static const struct drm_crtc_funcs dce_v8_0_crtc_funcs = {
  2224. .cursor_set2 = dce_v8_0_crtc_cursor_set2,
  2225. .cursor_move = dce_v8_0_crtc_cursor_move,
  2226. .gamma_set = dce_v8_0_crtc_gamma_set,
  2227. .set_config = amdgpu_crtc_set_config,
  2228. .destroy = dce_v8_0_crtc_destroy,
  2229. .page_flip = amdgpu_crtc_page_flip,
  2230. };
  2231. static void dce_v8_0_crtc_dpms(struct drm_crtc *crtc, int mode)
  2232. {
  2233. struct drm_device *dev = crtc->dev;
  2234. struct amdgpu_device *adev = dev->dev_private;
  2235. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2236. unsigned type;
  2237. switch (mode) {
  2238. case DRM_MODE_DPMS_ON:
  2239. amdgpu_crtc->enabled = true;
  2240. amdgpu_atombios_crtc_enable(crtc, ATOM_ENABLE);
  2241. dce_v8_0_vga_enable(crtc, true);
  2242. amdgpu_atombios_crtc_blank(crtc, ATOM_DISABLE);
  2243. dce_v8_0_vga_enable(crtc, false);
  2244. /* Make sure VBLANK and PFLIP interrupts are still enabled */
  2245. type = amdgpu_crtc_idx_to_irq_type(adev, amdgpu_crtc->crtc_id);
  2246. amdgpu_irq_update(adev, &adev->crtc_irq, type);
  2247. amdgpu_irq_update(adev, &adev->pageflip_irq, type);
  2248. drm_crtc_vblank_on(crtc);
  2249. dce_v8_0_crtc_load_lut(crtc);
  2250. break;
  2251. case DRM_MODE_DPMS_STANDBY:
  2252. case DRM_MODE_DPMS_SUSPEND:
  2253. case DRM_MODE_DPMS_OFF:
  2254. drm_crtc_vblank_off(crtc);
  2255. if (amdgpu_crtc->enabled) {
  2256. dce_v8_0_vga_enable(crtc, true);
  2257. amdgpu_atombios_crtc_blank(crtc, ATOM_ENABLE);
  2258. dce_v8_0_vga_enable(crtc, false);
  2259. }
  2260. amdgpu_atombios_crtc_enable(crtc, ATOM_DISABLE);
  2261. amdgpu_crtc->enabled = false;
  2262. break;
  2263. }
  2264. /* adjust pm to dpms */
  2265. amdgpu_pm_compute_clocks(adev);
  2266. }
  2267. static void dce_v8_0_crtc_prepare(struct drm_crtc *crtc)
  2268. {
  2269. /* disable crtc pair power gating before programming */
  2270. amdgpu_atombios_crtc_powergate(crtc, ATOM_DISABLE);
  2271. amdgpu_atombios_crtc_lock(crtc, ATOM_ENABLE);
  2272. dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  2273. }
  2274. static void dce_v8_0_crtc_commit(struct drm_crtc *crtc)
  2275. {
  2276. dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
  2277. amdgpu_atombios_crtc_lock(crtc, ATOM_DISABLE);
  2278. }
  2279. static void dce_v8_0_crtc_disable(struct drm_crtc *crtc)
  2280. {
  2281. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2282. struct drm_device *dev = crtc->dev;
  2283. struct amdgpu_device *adev = dev->dev_private;
  2284. struct amdgpu_atom_ss ss;
  2285. int i;
  2286. dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  2287. if (crtc->primary->fb) {
  2288. int r;
  2289. struct amdgpu_framebuffer *amdgpu_fb;
  2290. struct amdgpu_bo *rbo;
  2291. amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
  2292. rbo = gem_to_amdgpu_bo(amdgpu_fb->obj);
  2293. r = amdgpu_bo_reserve(rbo, false);
  2294. if (unlikely(r))
  2295. DRM_ERROR("failed to reserve rbo before unpin\n");
  2296. else {
  2297. amdgpu_bo_unpin(rbo);
  2298. amdgpu_bo_unreserve(rbo);
  2299. }
  2300. }
  2301. /* disable the GRPH */
  2302. dce_v8_0_grph_enable(crtc, false);
  2303. amdgpu_atombios_crtc_powergate(crtc, ATOM_ENABLE);
  2304. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  2305. if (adev->mode_info.crtcs[i] &&
  2306. adev->mode_info.crtcs[i]->enabled &&
  2307. i != amdgpu_crtc->crtc_id &&
  2308. amdgpu_crtc->pll_id == adev->mode_info.crtcs[i]->pll_id) {
  2309. /* one other crtc is using this pll don't turn
  2310. * off the pll
  2311. */
  2312. goto done;
  2313. }
  2314. }
  2315. switch (amdgpu_crtc->pll_id) {
  2316. case ATOM_PPLL1:
  2317. case ATOM_PPLL2:
  2318. /* disable the ppll */
  2319. amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
  2320. 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
  2321. break;
  2322. case ATOM_PPLL0:
  2323. /* disable the ppll */
  2324. if ((adev->asic_type == CHIP_KAVERI) ||
  2325. (adev->asic_type == CHIP_BONAIRE) ||
  2326. (adev->asic_type == CHIP_HAWAII))
  2327. amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
  2328. 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
  2329. break;
  2330. default:
  2331. break;
  2332. }
  2333. done:
  2334. amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
  2335. amdgpu_crtc->adjusted_clock = 0;
  2336. amdgpu_crtc->encoder = NULL;
  2337. amdgpu_crtc->connector = NULL;
  2338. }
  2339. static int dce_v8_0_crtc_mode_set(struct drm_crtc *crtc,
  2340. struct drm_display_mode *mode,
  2341. struct drm_display_mode *adjusted_mode,
  2342. int x, int y, struct drm_framebuffer *old_fb)
  2343. {
  2344. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2345. if (!amdgpu_crtc->adjusted_clock)
  2346. return -EINVAL;
  2347. amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode);
  2348. amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode);
  2349. dce_v8_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
  2350. amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode);
  2351. amdgpu_atombios_crtc_scaler_setup(crtc);
  2352. dce_v8_0_cursor_reset(crtc);
  2353. /* update the hw version fpr dpm */
  2354. amdgpu_crtc->hw_mode = *adjusted_mode;
  2355. return 0;
  2356. }
  2357. static bool dce_v8_0_crtc_mode_fixup(struct drm_crtc *crtc,
  2358. const struct drm_display_mode *mode,
  2359. struct drm_display_mode *adjusted_mode)
  2360. {
  2361. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2362. struct drm_device *dev = crtc->dev;
  2363. struct drm_encoder *encoder;
  2364. /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
  2365. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  2366. if (encoder->crtc == crtc) {
  2367. amdgpu_crtc->encoder = encoder;
  2368. amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder);
  2369. break;
  2370. }
  2371. }
  2372. if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) {
  2373. amdgpu_crtc->encoder = NULL;
  2374. amdgpu_crtc->connector = NULL;
  2375. return false;
  2376. }
  2377. if (!amdgpu_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
  2378. return false;
  2379. if (amdgpu_atombios_crtc_prepare_pll(crtc, adjusted_mode))
  2380. return false;
  2381. /* pick pll */
  2382. amdgpu_crtc->pll_id = dce_v8_0_pick_pll(crtc);
  2383. /* if we can't get a PPLL for a non-DP encoder, fail */
  2384. if ((amdgpu_crtc->pll_id == ATOM_PPLL_INVALID) &&
  2385. !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder)))
  2386. return false;
  2387. return true;
  2388. }
  2389. static int dce_v8_0_crtc_set_base(struct drm_crtc *crtc, int x, int y,
  2390. struct drm_framebuffer *old_fb)
  2391. {
  2392. return dce_v8_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
  2393. }
  2394. static int dce_v8_0_crtc_set_base_atomic(struct drm_crtc *crtc,
  2395. struct drm_framebuffer *fb,
  2396. int x, int y, enum mode_set_atomic state)
  2397. {
  2398. return dce_v8_0_crtc_do_set_base(crtc, fb, x, y, 1);
  2399. }
  2400. static const struct drm_crtc_helper_funcs dce_v8_0_crtc_helper_funcs = {
  2401. .dpms = dce_v8_0_crtc_dpms,
  2402. .mode_fixup = dce_v8_0_crtc_mode_fixup,
  2403. .mode_set = dce_v8_0_crtc_mode_set,
  2404. .mode_set_base = dce_v8_0_crtc_set_base,
  2405. .mode_set_base_atomic = dce_v8_0_crtc_set_base_atomic,
  2406. .prepare = dce_v8_0_crtc_prepare,
  2407. .commit = dce_v8_0_crtc_commit,
  2408. .load_lut = dce_v8_0_crtc_load_lut,
  2409. .disable = dce_v8_0_crtc_disable,
  2410. };
  2411. static int dce_v8_0_crtc_init(struct amdgpu_device *adev, int index)
  2412. {
  2413. struct amdgpu_crtc *amdgpu_crtc;
  2414. int i;
  2415. amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) +
  2416. (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  2417. if (amdgpu_crtc == NULL)
  2418. return -ENOMEM;
  2419. drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_v8_0_crtc_funcs);
  2420. drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256);
  2421. amdgpu_crtc->crtc_id = index;
  2422. adev->mode_info.crtcs[index] = amdgpu_crtc;
  2423. amdgpu_crtc->max_cursor_width = CIK_CURSOR_WIDTH;
  2424. amdgpu_crtc->max_cursor_height = CIK_CURSOR_HEIGHT;
  2425. adev->ddev->mode_config.cursor_width = amdgpu_crtc->max_cursor_width;
  2426. adev->ddev->mode_config.cursor_height = amdgpu_crtc->max_cursor_height;
  2427. for (i = 0; i < 256; i++) {
  2428. amdgpu_crtc->lut_r[i] = i << 2;
  2429. amdgpu_crtc->lut_g[i] = i << 2;
  2430. amdgpu_crtc->lut_b[i] = i << 2;
  2431. }
  2432. amdgpu_crtc->crtc_offset = crtc_offsets[amdgpu_crtc->crtc_id];
  2433. amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
  2434. amdgpu_crtc->adjusted_clock = 0;
  2435. amdgpu_crtc->encoder = NULL;
  2436. amdgpu_crtc->connector = NULL;
  2437. drm_crtc_helper_add(&amdgpu_crtc->base, &dce_v8_0_crtc_helper_funcs);
  2438. return 0;
  2439. }
  2440. static int dce_v8_0_early_init(void *handle)
  2441. {
  2442. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2443. adev->audio_endpt_rreg = &dce_v8_0_audio_endpt_rreg;
  2444. adev->audio_endpt_wreg = &dce_v8_0_audio_endpt_wreg;
  2445. dce_v8_0_set_display_funcs(adev);
  2446. dce_v8_0_set_irq_funcs(adev);
  2447. switch (adev->asic_type) {
  2448. case CHIP_BONAIRE:
  2449. case CHIP_HAWAII:
  2450. adev->mode_info.num_crtc = 6;
  2451. adev->mode_info.num_hpd = 6;
  2452. adev->mode_info.num_dig = 6;
  2453. break;
  2454. case CHIP_KAVERI:
  2455. adev->mode_info.num_crtc = 4;
  2456. adev->mode_info.num_hpd = 6;
  2457. adev->mode_info.num_dig = 7;
  2458. break;
  2459. case CHIP_KABINI:
  2460. case CHIP_MULLINS:
  2461. adev->mode_info.num_crtc = 2;
  2462. adev->mode_info.num_hpd = 6;
  2463. adev->mode_info.num_dig = 6; /* ? */
  2464. break;
  2465. default:
  2466. /* FIXME: not supported yet */
  2467. return -EINVAL;
  2468. }
  2469. return 0;
  2470. }
  2471. static int dce_v8_0_sw_init(void *handle)
  2472. {
  2473. int r, i;
  2474. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2475. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  2476. r = amdgpu_irq_add_id(adev, i + 1, &adev->crtc_irq);
  2477. if (r)
  2478. return r;
  2479. }
  2480. for (i = 8; i < 20; i += 2) {
  2481. r = amdgpu_irq_add_id(adev, i, &adev->pageflip_irq);
  2482. if (r)
  2483. return r;
  2484. }
  2485. /* HPD hotplug */
  2486. r = amdgpu_irq_add_id(adev, 42, &adev->hpd_irq);
  2487. if (r)
  2488. return r;
  2489. adev->ddev->mode_config.funcs = &amdgpu_mode_funcs;
  2490. adev->ddev->mode_config.async_page_flip = true;
  2491. adev->ddev->mode_config.max_width = 16384;
  2492. adev->ddev->mode_config.max_height = 16384;
  2493. adev->ddev->mode_config.preferred_depth = 24;
  2494. adev->ddev->mode_config.prefer_shadow = 1;
  2495. adev->ddev->mode_config.fb_base = adev->mc.aper_base;
  2496. r = amdgpu_modeset_create_props(adev);
  2497. if (r)
  2498. return r;
  2499. adev->ddev->mode_config.max_width = 16384;
  2500. adev->ddev->mode_config.max_height = 16384;
  2501. /* allocate crtcs */
  2502. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  2503. r = dce_v8_0_crtc_init(adev, i);
  2504. if (r)
  2505. return r;
  2506. }
  2507. if (amdgpu_atombios_get_connector_info_from_object_table(adev))
  2508. amdgpu_print_display_setup(adev->ddev);
  2509. else
  2510. return -EINVAL;
  2511. /* setup afmt */
  2512. r = dce_v8_0_afmt_init(adev);
  2513. if (r)
  2514. return r;
  2515. r = dce_v8_0_audio_init(adev);
  2516. if (r)
  2517. return r;
  2518. drm_kms_helper_poll_init(adev->ddev);
  2519. adev->mode_info.mode_config_initialized = true;
  2520. return 0;
  2521. }
  2522. static int dce_v8_0_sw_fini(void *handle)
  2523. {
  2524. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2525. kfree(adev->mode_info.bios_hardcoded_edid);
  2526. drm_kms_helper_poll_fini(adev->ddev);
  2527. dce_v8_0_audio_fini(adev);
  2528. dce_v8_0_afmt_fini(adev);
  2529. drm_mode_config_cleanup(adev->ddev);
  2530. adev->mode_info.mode_config_initialized = false;
  2531. return 0;
  2532. }
  2533. static int dce_v8_0_hw_init(void *handle)
  2534. {
  2535. int i;
  2536. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2537. /* init dig PHYs, disp eng pll */
  2538. amdgpu_atombios_encoder_init_dig(adev);
  2539. amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk);
  2540. /* initialize hpd */
  2541. dce_v8_0_hpd_init(adev);
  2542. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  2543. dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  2544. }
  2545. dce_v8_0_pageflip_interrupt_init(adev);
  2546. return 0;
  2547. }
  2548. static int dce_v8_0_hw_fini(void *handle)
  2549. {
  2550. int i;
  2551. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2552. dce_v8_0_hpd_fini(adev);
  2553. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  2554. dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  2555. }
  2556. dce_v8_0_pageflip_interrupt_fini(adev);
  2557. return 0;
  2558. }
  2559. static int dce_v8_0_suspend(void *handle)
  2560. {
  2561. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2562. amdgpu_atombios_scratch_regs_save(adev);
  2563. return dce_v8_0_hw_fini(handle);
  2564. }
  2565. static int dce_v8_0_resume(void *handle)
  2566. {
  2567. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2568. int ret;
  2569. ret = dce_v8_0_hw_init(handle);
  2570. amdgpu_atombios_scratch_regs_restore(adev);
  2571. /* turn on the BL */
  2572. if (adev->mode_info.bl_encoder) {
  2573. u8 bl_level = amdgpu_display_backlight_get_level(adev,
  2574. adev->mode_info.bl_encoder);
  2575. amdgpu_display_backlight_set_level(adev, adev->mode_info.bl_encoder,
  2576. bl_level);
  2577. }
  2578. return ret;
  2579. }
  2580. static bool dce_v8_0_is_idle(void *handle)
  2581. {
  2582. return true;
  2583. }
  2584. static int dce_v8_0_wait_for_idle(void *handle)
  2585. {
  2586. return 0;
  2587. }
  2588. static int dce_v8_0_soft_reset(void *handle)
  2589. {
  2590. u32 srbm_soft_reset = 0, tmp;
  2591. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2592. if (dce_v8_0_is_display_hung(adev))
  2593. srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK;
  2594. if (srbm_soft_reset) {
  2595. tmp = RREG32(mmSRBM_SOFT_RESET);
  2596. tmp |= srbm_soft_reset;
  2597. dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  2598. WREG32(mmSRBM_SOFT_RESET, tmp);
  2599. tmp = RREG32(mmSRBM_SOFT_RESET);
  2600. udelay(50);
  2601. tmp &= ~srbm_soft_reset;
  2602. WREG32(mmSRBM_SOFT_RESET, tmp);
  2603. tmp = RREG32(mmSRBM_SOFT_RESET);
  2604. /* Wait a little for things to settle down */
  2605. udelay(50);
  2606. }
  2607. return 0;
  2608. }
  2609. static void dce_v8_0_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev,
  2610. int crtc,
  2611. enum amdgpu_interrupt_state state)
  2612. {
  2613. u32 reg_block, lb_interrupt_mask;
  2614. if (crtc >= adev->mode_info.num_crtc) {
  2615. DRM_DEBUG("invalid crtc %d\n", crtc);
  2616. return;
  2617. }
  2618. switch (crtc) {
  2619. case 0:
  2620. reg_block = CRTC0_REGISTER_OFFSET;
  2621. break;
  2622. case 1:
  2623. reg_block = CRTC1_REGISTER_OFFSET;
  2624. break;
  2625. case 2:
  2626. reg_block = CRTC2_REGISTER_OFFSET;
  2627. break;
  2628. case 3:
  2629. reg_block = CRTC3_REGISTER_OFFSET;
  2630. break;
  2631. case 4:
  2632. reg_block = CRTC4_REGISTER_OFFSET;
  2633. break;
  2634. case 5:
  2635. reg_block = CRTC5_REGISTER_OFFSET;
  2636. break;
  2637. default:
  2638. DRM_DEBUG("invalid crtc %d\n", crtc);
  2639. return;
  2640. }
  2641. switch (state) {
  2642. case AMDGPU_IRQ_STATE_DISABLE:
  2643. lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
  2644. lb_interrupt_mask &= ~LB_INTERRUPT_MASK__VBLANK_INTERRUPT_MASK_MASK;
  2645. WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
  2646. break;
  2647. case AMDGPU_IRQ_STATE_ENABLE:
  2648. lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
  2649. lb_interrupt_mask |= LB_INTERRUPT_MASK__VBLANK_INTERRUPT_MASK_MASK;
  2650. WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
  2651. break;
  2652. default:
  2653. break;
  2654. }
  2655. }
  2656. static void dce_v8_0_set_crtc_vline_interrupt_state(struct amdgpu_device *adev,
  2657. int crtc,
  2658. enum amdgpu_interrupt_state state)
  2659. {
  2660. u32 reg_block, lb_interrupt_mask;
  2661. if (crtc >= adev->mode_info.num_crtc) {
  2662. DRM_DEBUG("invalid crtc %d\n", crtc);
  2663. return;
  2664. }
  2665. switch (crtc) {
  2666. case 0:
  2667. reg_block = CRTC0_REGISTER_OFFSET;
  2668. break;
  2669. case 1:
  2670. reg_block = CRTC1_REGISTER_OFFSET;
  2671. break;
  2672. case 2:
  2673. reg_block = CRTC2_REGISTER_OFFSET;
  2674. break;
  2675. case 3:
  2676. reg_block = CRTC3_REGISTER_OFFSET;
  2677. break;
  2678. case 4:
  2679. reg_block = CRTC4_REGISTER_OFFSET;
  2680. break;
  2681. case 5:
  2682. reg_block = CRTC5_REGISTER_OFFSET;
  2683. break;
  2684. default:
  2685. DRM_DEBUG("invalid crtc %d\n", crtc);
  2686. return;
  2687. }
  2688. switch (state) {
  2689. case AMDGPU_IRQ_STATE_DISABLE:
  2690. lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
  2691. lb_interrupt_mask &= ~LB_INTERRUPT_MASK__VLINE_INTERRUPT_MASK_MASK;
  2692. WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
  2693. break;
  2694. case AMDGPU_IRQ_STATE_ENABLE:
  2695. lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
  2696. lb_interrupt_mask |= LB_INTERRUPT_MASK__VLINE_INTERRUPT_MASK_MASK;
  2697. WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
  2698. break;
  2699. default:
  2700. break;
  2701. }
  2702. }
  2703. static int dce_v8_0_set_hpd_interrupt_state(struct amdgpu_device *adev,
  2704. struct amdgpu_irq_src *src,
  2705. unsigned type,
  2706. enum amdgpu_interrupt_state state)
  2707. {
  2708. u32 dc_hpd_int_cntl_reg, dc_hpd_int_cntl;
  2709. switch (type) {
  2710. case AMDGPU_HPD_1:
  2711. dc_hpd_int_cntl_reg = mmDC_HPD1_INT_CONTROL;
  2712. break;
  2713. case AMDGPU_HPD_2:
  2714. dc_hpd_int_cntl_reg = mmDC_HPD2_INT_CONTROL;
  2715. break;
  2716. case AMDGPU_HPD_3:
  2717. dc_hpd_int_cntl_reg = mmDC_HPD3_INT_CONTROL;
  2718. break;
  2719. case AMDGPU_HPD_4:
  2720. dc_hpd_int_cntl_reg = mmDC_HPD4_INT_CONTROL;
  2721. break;
  2722. case AMDGPU_HPD_5:
  2723. dc_hpd_int_cntl_reg = mmDC_HPD5_INT_CONTROL;
  2724. break;
  2725. case AMDGPU_HPD_6:
  2726. dc_hpd_int_cntl_reg = mmDC_HPD6_INT_CONTROL;
  2727. break;
  2728. default:
  2729. DRM_DEBUG("invalid hdp %d\n", type);
  2730. return 0;
  2731. }
  2732. switch (state) {
  2733. case AMDGPU_IRQ_STATE_DISABLE:
  2734. dc_hpd_int_cntl = RREG32(dc_hpd_int_cntl_reg);
  2735. dc_hpd_int_cntl &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
  2736. WREG32(dc_hpd_int_cntl_reg, dc_hpd_int_cntl);
  2737. break;
  2738. case AMDGPU_IRQ_STATE_ENABLE:
  2739. dc_hpd_int_cntl = RREG32(dc_hpd_int_cntl_reg);
  2740. dc_hpd_int_cntl |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
  2741. WREG32(dc_hpd_int_cntl_reg, dc_hpd_int_cntl);
  2742. break;
  2743. default:
  2744. break;
  2745. }
  2746. return 0;
  2747. }
  2748. static int dce_v8_0_set_crtc_interrupt_state(struct amdgpu_device *adev,
  2749. struct amdgpu_irq_src *src,
  2750. unsigned type,
  2751. enum amdgpu_interrupt_state state)
  2752. {
  2753. switch (type) {
  2754. case AMDGPU_CRTC_IRQ_VBLANK1:
  2755. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 0, state);
  2756. break;
  2757. case AMDGPU_CRTC_IRQ_VBLANK2:
  2758. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 1, state);
  2759. break;
  2760. case AMDGPU_CRTC_IRQ_VBLANK3:
  2761. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 2, state);
  2762. break;
  2763. case AMDGPU_CRTC_IRQ_VBLANK4:
  2764. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 3, state);
  2765. break;
  2766. case AMDGPU_CRTC_IRQ_VBLANK5:
  2767. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 4, state);
  2768. break;
  2769. case AMDGPU_CRTC_IRQ_VBLANK6:
  2770. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 5, state);
  2771. break;
  2772. case AMDGPU_CRTC_IRQ_VLINE1:
  2773. dce_v8_0_set_crtc_vline_interrupt_state(adev, 0, state);
  2774. break;
  2775. case AMDGPU_CRTC_IRQ_VLINE2:
  2776. dce_v8_0_set_crtc_vline_interrupt_state(adev, 1, state);
  2777. break;
  2778. case AMDGPU_CRTC_IRQ_VLINE3:
  2779. dce_v8_0_set_crtc_vline_interrupt_state(adev, 2, state);
  2780. break;
  2781. case AMDGPU_CRTC_IRQ_VLINE4:
  2782. dce_v8_0_set_crtc_vline_interrupt_state(adev, 3, state);
  2783. break;
  2784. case AMDGPU_CRTC_IRQ_VLINE5:
  2785. dce_v8_0_set_crtc_vline_interrupt_state(adev, 4, state);
  2786. break;
  2787. case AMDGPU_CRTC_IRQ_VLINE6:
  2788. dce_v8_0_set_crtc_vline_interrupt_state(adev, 5, state);
  2789. break;
  2790. default:
  2791. break;
  2792. }
  2793. return 0;
  2794. }
  2795. static int dce_v8_0_crtc_irq(struct amdgpu_device *adev,
  2796. struct amdgpu_irq_src *source,
  2797. struct amdgpu_iv_entry *entry)
  2798. {
  2799. unsigned crtc = entry->src_id - 1;
  2800. uint32_t disp_int = RREG32(interrupt_status_offsets[crtc].reg);
  2801. unsigned irq_type = amdgpu_crtc_idx_to_irq_type(adev, crtc);
  2802. switch (entry->src_data) {
  2803. case 0: /* vblank */
  2804. if (disp_int & interrupt_status_offsets[crtc].vblank)
  2805. WREG32(mmLB_VBLANK_STATUS + crtc_offsets[crtc], LB_VBLANK_STATUS__VBLANK_ACK_MASK);
  2806. else
  2807. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  2808. if (amdgpu_irq_enabled(adev, source, irq_type)) {
  2809. drm_handle_vblank(adev->ddev, crtc);
  2810. }
  2811. DRM_DEBUG("IH: D%d vblank\n", crtc + 1);
  2812. break;
  2813. case 1: /* vline */
  2814. if (disp_int & interrupt_status_offsets[crtc].vline)
  2815. WREG32(mmLB_VLINE_STATUS + crtc_offsets[crtc], LB_VLINE_STATUS__VLINE_ACK_MASK);
  2816. else
  2817. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  2818. DRM_DEBUG("IH: D%d vline\n", crtc + 1);
  2819. break;
  2820. default:
  2821. DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data);
  2822. break;
  2823. }
  2824. return 0;
  2825. }
  2826. static int dce_v8_0_set_pageflip_interrupt_state(struct amdgpu_device *adev,
  2827. struct amdgpu_irq_src *src,
  2828. unsigned type,
  2829. enum amdgpu_interrupt_state state)
  2830. {
  2831. u32 reg;
  2832. if (type >= adev->mode_info.num_crtc) {
  2833. DRM_ERROR("invalid pageflip crtc %d\n", type);
  2834. return -EINVAL;
  2835. }
  2836. reg = RREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type]);
  2837. if (state == AMDGPU_IRQ_STATE_DISABLE)
  2838. WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
  2839. reg & ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
  2840. else
  2841. WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
  2842. reg | GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
  2843. return 0;
  2844. }
  2845. static int dce_v8_0_pageflip_irq(struct amdgpu_device *adev,
  2846. struct amdgpu_irq_src *source,
  2847. struct amdgpu_iv_entry *entry)
  2848. {
  2849. unsigned long flags;
  2850. unsigned crtc_id;
  2851. struct amdgpu_crtc *amdgpu_crtc;
  2852. struct amdgpu_flip_work *works;
  2853. crtc_id = (entry->src_id - 8) >> 1;
  2854. amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
  2855. if (crtc_id >= adev->mode_info.num_crtc) {
  2856. DRM_ERROR("invalid pageflip crtc %d\n", crtc_id);
  2857. return -EINVAL;
  2858. }
  2859. if (RREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id]) &
  2860. GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK)
  2861. WREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id],
  2862. GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK);
  2863. /* IRQ could occur when in initial stage */
  2864. if (amdgpu_crtc == NULL)
  2865. return 0;
  2866. spin_lock_irqsave(&adev->ddev->event_lock, flags);
  2867. works = amdgpu_crtc->pflip_works;
  2868. if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){
  2869. DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
  2870. "AMDGPU_FLIP_SUBMITTED(%d)\n",
  2871. amdgpu_crtc->pflip_status,
  2872. AMDGPU_FLIP_SUBMITTED);
  2873. spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  2874. return 0;
  2875. }
  2876. /* page flip completed. clean up */
  2877. amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
  2878. amdgpu_crtc->pflip_works = NULL;
  2879. /* wakeup usersapce */
  2880. if (works->event)
  2881. drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event);
  2882. spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  2883. drm_crtc_vblank_put(&amdgpu_crtc->base);
  2884. schedule_work(&works->unpin_work);
  2885. return 0;
  2886. }
  2887. static int dce_v8_0_hpd_irq(struct amdgpu_device *adev,
  2888. struct amdgpu_irq_src *source,
  2889. struct amdgpu_iv_entry *entry)
  2890. {
  2891. uint32_t disp_int, mask, int_control, tmp;
  2892. unsigned hpd;
  2893. if (entry->src_data >= adev->mode_info.num_hpd) {
  2894. DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data);
  2895. return 0;
  2896. }
  2897. hpd = entry->src_data;
  2898. disp_int = RREG32(interrupt_status_offsets[hpd].reg);
  2899. mask = interrupt_status_offsets[hpd].hpd;
  2900. int_control = hpd_int_control_offsets[hpd];
  2901. if (disp_int & mask) {
  2902. tmp = RREG32(int_control);
  2903. tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_ACK_MASK;
  2904. WREG32(int_control, tmp);
  2905. schedule_work(&adev->hotplug_work);
  2906. DRM_DEBUG("IH: HPD%d\n", hpd + 1);
  2907. }
  2908. return 0;
  2909. }
  2910. static int dce_v8_0_set_clockgating_state(void *handle,
  2911. enum amd_clockgating_state state)
  2912. {
  2913. return 0;
  2914. }
  2915. static int dce_v8_0_set_powergating_state(void *handle,
  2916. enum amd_powergating_state state)
  2917. {
  2918. return 0;
  2919. }
  2920. const struct amd_ip_funcs dce_v8_0_ip_funcs = {
  2921. .name = "dce_v8_0",
  2922. .early_init = dce_v8_0_early_init,
  2923. .late_init = NULL,
  2924. .sw_init = dce_v8_0_sw_init,
  2925. .sw_fini = dce_v8_0_sw_fini,
  2926. .hw_init = dce_v8_0_hw_init,
  2927. .hw_fini = dce_v8_0_hw_fini,
  2928. .suspend = dce_v8_0_suspend,
  2929. .resume = dce_v8_0_resume,
  2930. .is_idle = dce_v8_0_is_idle,
  2931. .wait_for_idle = dce_v8_0_wait_for_idle,
  2932. .soft_reset = dce_v8_0_soft_reset,
  2933. .set_clockgating_state = dce_v8_0_set_clockgating_state,
  2934. .set_powergating_state = dce_v8_0_set_powergating_state,
  2935. };
  2936. static void
  2937. dce_v8_0_encoder_mode_set(struct drm_encoder *encoder,
  2938. struct drm_display_mode *mode,
  2939. struct drm_display_mode *adjusted_mode)
  2940. {
  2941. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2942. amdgpu_encoder->pixel_clock = adjusted_mode->clock;
  2943. /* need to call this here rather than in prepare() since we need some crtc info */
  2944. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  2945. /* set scaler clears this on some chips */
  2946. dce_v8_0_set_interleave(encoder->crtc, mode);
  2947. if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
  2948. dce_v8_0_afmt_enable(encoder, true);
  2949. dce_v8_0_afmt_setmode(encoder, adjusted_mode);
  2950. }
  2951. }
  2952. static void dce_v8_0_encoder_prepare(struct drm_encoder *encoder)
  2953. {
  2954. struct amdgpu_device *adev = encoder->dev->dev_private;
  2955. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2956. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  2957. if ((amdgpu_encoder->active_device &
  2958. (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
  2959. (amdgpu_encoder_get_dp_bridge_encoder_id(encoder) !=
  2960. ENCODER_OBJECT_ID_NONE)) {
  2961. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  2962. if (dig) {
  2963. dig->dig_encoder = dce_v8_0_pick_dig_encoder(encoder);
  2964. if (amdgpu_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT)
  2965. dig->afmt = adev->mode_info.afmt[dig->dig_encoder];
  2966. }
  2967. }
  2968. amdgpu_atombios_scratch_regs_lock(adev, true);
  2969. if (connector) {
  2970. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  2971. /* select the clock/data port if it uses a router */
  2972. if (amdgpu_connector->router.cd_valid)
  2973. amdgpu_i2c_router_select_cd_port(amdgpu_connector);
  2974. /* turn eDP panel on for mode set */
  2975. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  2976. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  2977. ATOM_TRANSMITTER_ACTION_POWER_ON);
  2978. }
  2979. /* this is needed for the pll/ss setup to work correctly in some cases */
  2980. amdgpu_atombios_encoder_set_crtc_source(encoder);
  2981. /* set up the FMT blocks */
  2982. dce_v8_0_program_fmt(encoder);
  2983. }
  2984. static void dce_v8_0_encoder_commit(struct drm_encoder *encoder)
  2985. {
  2986. struct drm_device *dev = encoder->dev;
  2987. struct amdgpu_device *adev = dev->dev_private;
  2988. /* need to call this here as we need the crtc set up */
  2989. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
  2990. amdgpu_atombios_scratch_regs_lock(adev, false);
  2991. }
  2992. static void dce_v8_0_encoder_disable(struct drm_encoder *encoder)
  2993. {
  2994. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2995. struct amdgpu_encoder_atom_dig *dig;
  2996. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  2997. if (amdgpu_atombios_encoder_is_digital(encoder)) {
  2998. if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
  2999. dce_v8_0_afmt_enable(encoder, false);
  3000. dig = amdgpu_encoder->enc_priv;
  3001. dig->dig_encoder = -1;
  3002. }
  3003. amdgpu_encoder->active_device = 0;
  3004. }
  3005. /* these are handled by the primary encoders */
  3006. static void dce_v8_0_ext_prepare(struct drm_encoder *encoder)
  3007. {
  3008. }
  3009. static void dce_v8_0_ext_commit(struct drm_encoder *encoder)
  3010. {
  3011. }
  3012. static void
  3013. dce_v8_0_ext_mode_set(struct drm_encoder *encoder,
  3014. struct drm_display_mode *mode,
  3015. struct drm_display_mode *adjusted_mode)
  3016. {
  3017. }
  3018. static void dce_v8_0_ext_disable(struct drm_encoder *encoder)
  3019. {
  3020. }
  3021. static void
  3022. dce_v8_0_ext_dpms(struct drm_encoder *encoder, int mode)
  3023. {
  3024. }
  3025. static const struct drm_encoder_helper_funcs dce_v8_0_ext_helper_funcs = {
  3026. .dpms = dce_v8_0_ext_dpms,
  3027. .prepare = dce_v8_0_ext_prepare,
  3028. .mode_set = dce_v8_0_ext_mode_set,
  3029. .commit = dce_v8_0_ext_commit,
  3030. .disable = dce_v8_0_ext_disable,
  3031. /* no detect for TMDS/LVDS yet */
  3032. };
  3033. static const struct drm_encoder_helper_funcs dce_v8_0_dig_helper_funcs = {
  3034. .dpms = amdgpu_atombios_encoder_dpms,
  3035. .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
  3036. .prepare = dce_v8_0_encoder_prepare,
  3037. .mode_set = dce_v8_0_encoder_mode_set,
  3038. .commit = dce_v8_0_encoder_commit,
  3039. .disable = dce_v8_0_encoder_disable,
  3040. .detect = amdgpu_atombios_encoder_dig_detect,
  3041. };
  3042. static const struct drm_encoder_helper_funcs dce_v8_0_dac_helper_funcs = {
  3043. .dpms = amdgpu_atombios_encoder_dpms,
  3044. .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
  3045. .prepare = dce_v8_0_encoder_prepare,
  3046. .mode_set = dce_v8_0_encoder_mode_set,
  3047. .commit = dce_v8_0_encoder_commit,
  3048. .detect = amdgpu_atombios_encoder_dac_detect,
  3049. };
  3050. static void dce_v8_0_encoder_destroy(struct drm_encoder *encoder)
  3051. {
  3052. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  3053. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  3054. amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder);
  3055. kfree(amdgpu_encoder->enc_priv);
  3056. drm_encoder_cleanup(encoder);
  3057. kfree(amdgpu_encoder);
  3058. }
  3059. static const struct drm_encoder_funcs dce_v8_0_encoder_funcs = {
  3060. .destroy = dce_v8_0_encoder_destroy,
  3061. };
  3062. static void dce_v8_0_encoder_add(struct amdgpu_device *adev,
  3063. uint32_t encoder_enum,
  3064. uint32_t supported_device,
  3065. u16 caps)
  3066. {
  3067. struct drm_device *dev = adev->ddev;
  3068. struct drm_encoder *encoder;
  3069. struct amdgpu_encoder *amdgpu_encoder;
  3070. /* see if we already added it */
  3071. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  3072. amdgpu_encoder = to_amdgpu_encoder(encoder);
  3073. if (amdgpu_encoder->encoder_enum == encoder_enum) {
  3074. amdgpu_encoder->devices |= supported_device;
  3075. return;
  3076. }
  3077. }
  3078. /* add a new one */
  3079. amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL);
  3080. if (!amdgpu_encoder)
  3081. return;
  3082. encoder = &amdgpu_encoder->base;
  3083. switch (adev->mode_info.num_crtc) {
  3084. case 1:
  3085. encoder->possible_crtcs = 0x1;
  3086. break;
  3087. case 2:
  3088. default:
  3089. encoder->possible_crtcs = 0x3;
  3090. break;
  3091. case 4:
  3092. encoder->possible_crtcs = 0xf;
  3093. break;
  3094. case 6:
  3095. encoder->possible_crtcs = 0x3f;
  3096. break;
  3097. }
  3098. amdgpu_encoder->enc_priv = NULL;
  3099. amdgpu_encoder->encoder_enum = encoder_enum;
  3100. amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  3101. amdgpu_encoder->devices = supported_device;
  3102. amdgpu_encoder->rmx_type = RMX_OFF;
  3103. amdgpu_encoder->underscan_type = UNDERSCAN_OFF;
  3104. amdgpu_encoder->is_ext_encoder = false;
  3105. amdgpu_encoder->caps = caps;
  3106. switch (amdgpu_encoder->encoder_id) {
  3107. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  3108. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  3109. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3110. DRM_MODE_ENCODER_DAC, NULL);
  3111. drm_encoder_helper_add(encoder, &dce_v8_0_dac_helper_funcs);
  3112. break;
  3113. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  3114. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  3115. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  3116. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  3117. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  3118. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  3119. amdgpu_encoder->rmx_type = RMX_FULL;
  3120. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3121. DRM_MODE_ENCODER_LVDS, NULL);
  3122. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder);
  3123. } else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  3124. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3125. DRM_MODE_ENCODER_DAC, NULL);
  3126. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
  3127. } else {
  3128. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3129. DRM_MODE_ENCODER_TMDS, NULL);
  3130. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
  3131. }
  3132. drm_encoder_helper_add(encoder, &dce_v8_0_dig_helper_funcs);
  3133. break;
  3134. case ENCODER_OBJECT_ID_SI170B:
  3135. case ENCODER_OBJECT_ID_CH7303:
  3136. case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
  3137. case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
  3138. case ENCODER_OBJECT_ID_TITFP513:
  3139. case ENCODER_OBJECT_ID_VT1623:
  3140. case ENCODER_OBJECT_ID_HDMI_SI1930:
  3141. case ENCODER_OBJECT_ID_TRAVIS:
  3142. case ENCODER_OBJECT_ID_NUTMEG:
  3143. /* these are handled by the primary encoders */
  3144. amdgpu_encoder->is_ext_encoder = true;
  3145. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  3146. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3147. DRM_MODE_ENCODER_LVDS, NULL);
  3148. else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
  3149. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3150. DRM_MODE_ENCODER_DAC, NULL);
  3151. else
  3152. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3153. DRM_MODE_ENCODER_TMDS, NULL);
  3154. drm_encoder_helper_add(encoder, &dce_v8_0_ext_helper_funcs);
  3155. break;
  3156. }
  3157. }
  3158. static const struct amdgpu_display_funcs dce_v8_0_display_funcs = {
  3159. .set_vga_render_state = &dce_v8_0_set_vga_render_state,
  3160. .bandwidth_update = &dce_v8_0_bandwidth_update,
  3161. .vblank_get_counter = &dce_v8_0_vblank_get_counter,
  3162. .vblank_wait = &dce_v8_0_vblank_wait,
  3163. .is_display_hung = &dce_v8_0_is_display_hung,
  3164. .backlight_set_level = &amdgpu_atombios_encoder_set_backlight_level,
  3165. .backlight_get_level = &amdgpu_atombios_encoder_get_backlight_level,
  3166. .hpd_sense = &dce_v8_0_hpd_sense,
  3167. .hpd_set_polarity = &dce_v8_0_hpd_set_polarity,
  3168. .hpd_get_gpio_reg = &dce_v8_0_hpd_get_gpio_reg,
  3169. .page_flip = &dce_v8_0_page_flip,
  3170. .page_flip_get_scanoutpos = &dce_v8_0_crtc_get_scanoutpos,
  3171. .add_encoder = &dce_v8_0_encoder_add,
  3172. .add_connector = &amdgpu_connector_add,
  3173. .stop_mc_access = &dce_v8_0_stop_mc_access,
  3174. .resume_mc_access = &dce_v8_0_resume_mc_access,
  3175. };
  3176. static void dce_v8_0_set_display_funcs(struct amdgpu_device *adev)
  3177. {
  3178. if (adev->mode_info.funcs == NULL)
  3179. adev->mode_info.funcs = &dce_v8_0_display_funcs;
  3180. }
  3181. static const struct amdgpu_irq_src_funcs dce_v8_0_crtc_irq_funcs = {
  3182. .set = dce_v8_0_set_crtc_interrupt_state,
  3183. .process = dce_v8_0_crtc_irq,
  3184. };
  3185. static const struct amdgpu_irq_src_funcs dce_v8_0_pageflip_irq_funcs = {
  3186. .set = dce_v8_0_set_pageflip_interrupt_state,
  3187. .process = dce_v8_0_pageflip_irq,
  3188. };
  3189. static const struct amdgpu_irq_src_funcs dce_v8_0_hpd_irq_funcs = {
  3190. .set = dce_v8_0_set_hpd_interrupt_state,
  3191. .process = dce_v8_0_hpd_irq,
  3192. };
  3193. static void dce_v8_0_set_irq_funcs(struct amdgpu_device *adev)
  3194. {
  3195. adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_LAST;
  3196. adev->crtc_irq.funcs = &dce_v8_0_crtc_irq_funcs;
  3197. adev->pageflip_irq.num_types = AMDGPU_PAGEFLIP_IRQ_LAST;
  3198. adev->pageflip_irq.funcs = &dce_v8_0_pageflip_irq_funcs;
  3199. adev->hpd_irq.num_types = AMDGPU_HPD_LAST;
  3200. adev->hpd_irq.funcs = &dce_v8_0_hpd_irq_funcs;
  3201. }