dce_v11_0.c 115 KB

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