dce_v11_0.c 115 KB

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