dce_v11_0.c 114 KB

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