dce_v11_0.c 114 KB

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