dce_v11_0.c 116 KB

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