dce_v6_0.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084
  1. /*
  2. * Copyright 2015 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 "drmP.h"
  24. #include "amdgpu.h"
  25. #include "amdgpu_pm.h"
  26. #include "amdgpu_i2c.h"
  27. #include "atom.h"
  28. #include "amdgpu_atombios.h"
  29. #include "atombios_crtc.h"
  30. #include "atombios_encoders.h"
  31. #include "amdgpu_pll.h"
  32. #include "amdgpu_connectors.h"
  33. #include "bif/bif_3_0_d.h"
  34. #include "bif/bif_3_0_sh_mask.h"
  35. #include "oss/oss_1_0_d.h"
  36. #include "oss/oss_1_0_sh_mask.h"
  37. #include "gca/gfx_6_0_d.h"
  38. #include "gca/gfx_6_0_sh_mask.h"
  39. #include "gmc/gmc_6_0_d.h"
  40. #include "gmc/gmc_6_0_sh_mask.h"
  41. #include "dce/dce_6_0_d.h"
  42. #include "dce/dce_6_0_sh_mask.h"
  43. #include "gca/gfx_7_2_enum.h"
  44. #include "si_enums.h"
  45. static void dce_v6_0_set_display_funcs(struct amdgpu_device *adev);
  46. static void dce_v6_0_set_irq_funcs(struct amdgpu_device *adev);
  47. static const u32 crtc_offsets[6] =
  48. {
  49. SI_CRTC0_REGISTER_OFFSET,
  50. SI_CRTC1_REGISTER_OFFSET,
  51. SI_CRTC2_REGISTER_OFFSET,
  52. SI_CRTC3_REGISTER_OFFSET,
  53. SI_CRTC4_REGISTER_OFFSET,
  54. SI_CRTC5_REGISTER_OFFSET
  55. };
  56. static const u32 hpd_offsets[] =
  57. {
  58. mmDC_HPD1_INT_STATUS - mmDC_HPD1_INT_STATUS,
  59. mmDC_HPD2_INT_STATUS - mmDC_HPD1_INT_STATUS,
  60. mmDC_HPD3_INT_STATUS - mmDC_HPD1_INT_STATUS,
  61. mmDC_HPD4_INT_STATUS - mmDC_HPD1_INT_STATUS,
  62. mmDC_HPD5_INT_STATUS - mmDC_HPD1_INT_STATUS,
  63. mmDC_HPD6_INT_STATUS - mmDC_HPD1_INT_STATUS,
  64. };
  65. static const uint32_t dig_offsets[] = {
  66. SI_CRTC0_REGISTER_OFFSET,
  67. SI_CRTC1_REGISTER_OFFSET,
  68. SI_CRTC2_REGISTER_OFFSET,
  69. SI_CRTC3_REGISTER_OFFSET,
  70. SI_CRTC4_REGISTER_OFFSET,
  71. SI_CRTC5_REGISTER_OFFSET,
  72. (0x13830 - 0x7030) >> 2,
  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[6] = { {
  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 u32 dce_v6_0_audio_endpt_rreg(struct amdgpu_device *adev,
  111. u32 block_offset, u32 reg)
  112. {
  113. DRM_INFO("xxxx: dce_v6_0_audio_endpt_rreg ----no impl!!!!\n");
  114. return 0;
  115. }
  116. static void dce_v6_0_audio_endpt_wreg(struct amdgpu_device *adev,
  117. u32 block_offset, u32 reg, u32 v)
  118. {
  119. DRM_INFO("xxxx: dce_v6_0_audio_endpt_wreg ----no impl!!!!\n");
  120. }
  121. static bool dce_v6_0_is_in_vblank(struct amdgpu_device *adev, int crtc)
  122. {
  123. if (RREG32(mmCRTC_STATUS + crtc_offsets[crtc]) & CRTC_STATUS__CRTC_V_BLANK_MASK)
  124. return true;
  125. else
  126. return false;
  127. }
  128. static bool dce_v6_0_is_counter_moving(struct amdgpu_device *adev, int crtc)
  129. {
  130. u32 pos1, pos2;
  131. pos1 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  132. pos2 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  133. if (pos1 != pos2)
  134. return true;
  135. else
  136. return false;
  137. }
  138. /**
  139. * dce_v6_0_wait_for_vblank - vblank wait asic callback.
  140. *
  141. * @crtc: crtc to wait for vblank on
  142. *
  143. * Wait for vblank on the requested crtc (evergreen+).
  144. */
  145. static void dce_v6_0_vblank_wait(struct amdgpu_device *adev, int crtc)
  146. {
  147. unsigned i = 100;
  148. if (crtc >= adev->mode_info.num_crtc)
  149. return;
  150. if (!(RREG32(mmCRTC_CONTROL + crtc_offsets[crtc]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK))
  151. return;
  152. /* depending on when we hit vblank, we may be close to active; if so,
  153. * wait for another frame.
  154. */
  155. while (dce_v6_0_is_in_vblank(adev, crtc)) {
  156. if (i++ == 100) {
  157. i = 0;
  158. if (!dce_v6_0_is_counter_moving(adev, crtc))
  159. break;
  160. }
  161. }
  162. while (!dce_v6_0_is_in_vblank(adev, crtc)) {
  163. if (i++ == 100) {
  164. i = 0;
  165. if (!dce_v6_0_is_counter_moving(adev, crtc))
  166. break;
  167. }
  168. }
  169. }
  170. static u32 dce_v6_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
  171. {
  172. if (crtc >= adev->mode_info.num_crtc)
  173. return 0;
  174. else
  175. return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
  176. }
  177. static void dce_v6_0_pageflip_interrupt_init(struct amdgpu_device *adev)
  178. {
  179. unsigned i;
  180. /* Enable pflip interrupts */
  181. for (i = 0; i < adev->mode_info.num_crtc; i++)
  182. amdgpu_irq_get(adev, &adev->pageflip_irq, i);
  183. }
  184. static void dce_v6_0_pageflip_interrupt_fini(struct amdgpu_device *adev)
  185. {
  186. unsigned i;
  187. /* Disable pflip interrupts */
  188. for (i = 0; i < adev->mode_info.num_crtc; i++)
  189. amdgpu_irq_put(adev, &adev->pageflip_irq, i);
  190. }
  191. /**
  192. * dce_v6_0_page_flip - pageflip callback.
  193. *
  194. * @adev: amdgpu_device pointer
  195. * @crtc_id: crtc to cleanup pageflip on
  196. * @crtc_base: new address of the crtc (GPU MC address)
  197. *
  198. * Does the actual pageflip (evergreen+).
  199. * During vblank we take the crtc lock and wait for the update_pending
  200. * bit to go high, when it does, we release the lock, and allow the
  201. * double buffered update to take place.
  202. * Returns the current update pending status.
  203. */
  204. static void dce_v6_0_page_flip(struct amdgpu_device *adev,
  205. int crtc_id, u64 crtc_base, bool async)
  206. {
  207. struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
  208. /* flip at hsync for async, default is vsync */
  209. WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, async ?
  210. GRPH_FLIP_CONTROL__GRPH_SURFACE_UPDATE_H_RETRACE_EN_MASK : 0);
  211. /* update the scanout addresses */
  212. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  213. upper_32_bits(crtc_base));
  214. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  215. (u32)crtc_base);
  216. /* post the write */
  217. RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
  218. }
  219. static int dce_v6_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
  220. u32 *vbl, u32 *position)
  221. {
  222. if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
  223. return -EINVAL;
  224. *vbl = RREG32(mmCRTC_V_BLANK_START_END + crtc_offsets[crtc]);
  225. *position = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  226. return 0;
  227. }
  228. /**
  229. * dce_v6_0_hpd_sense - hpd sense callback.
  230. *
  231. * @adev: amdgpu_device pointer
  232. * @hpd: hpd (hotplug detect) pin
  233. *
  234. * Checks if a digital monitor is connected (evergreen+).
  235. * Returns true if connected, false if not connected.
  236. */
  237. static bool dce_v6_0_hpd_sense(struct amdgpu_device *adev,
  238. enum amdgpu_hpd_id hpd)
  239. {
  240. bool connected = false;
  241. if (hpd >= adev->mode_info.num_hpd)
  242. return connected;
  243. if (RREG32(mmDC_HPD1_INT_STATUS + hpd_offsets[hpd]) & DC_HPD1_INT_STATUS__DC_HPD1_SENSE_MASK)
  244. connected = true;
  245. return connected;
  246. }
  247. /**
  248. * dce_v6_0_hpd_set_polarity - hpd set polarity callback.
  249. *
  250. * @adev: amdgpu_device pointer
  251. * @hpd: hpd (hotplug detect) pin
  252. *
  253. * Set the polarity of the hpd pin (evergreen+).
  254. */
  255. static void dce_v6_0_hpd_set_polarity(struct amdgpu_device *adev,
  256. enum amdgpu_hpd_id hpd)
  257. {
  258. u32 tmp;
  259. bool connected = dce_v6_0_hpd_sense(adev, hpd);
  260. if (hpd >= adev->mode_info.num_hpd)
  261. return;
  262. tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
  263. if (connected)
  264. tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
  265. else
  266. tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
  267. WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
  268. }
  269. /**
  270. * dce_v6_0_hpd_init - hpd setup callback.
  271. *
  272. * @adev: amdgpu_device pointer
  273. *
  274. * Setup the hpd pins used by the card (evergreen+).
  275. * Enable the pin, set the polarity, and enable the hpd interrupts.
  276. */
  277. static void dce_v6_0_hpd_init(struct amdgpu_device *adev)
  278. {
  279. struct drm_device *dev = adev->ddev;
  280. struct drm_connector *connector;
  281. u32 tmp;
  282. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  283. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  284. if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
  285. continue;
  286. tmp = RREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
  287. tmp |= DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
  288. WREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
  289. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  290. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  291. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  292. * aux dp channel on imac and help (but not completely fix)
  293. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  294. * also avoid interrupt storms during dpms.
  295. */
  296. tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
  297. tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
  298. WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
  299. continue;
  300. }
  301. dce_v6_0_hpd_set_polarity(adev, amdgpu_connector->hpd.hpd);
  302. amdgpu_irq_get(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
  303. }
  304. }
  305. /**
  306. * dce_v6_0_hpd_fini - hpd tear down callback.
  307. *
  308. * @adev: amdgpu_device pointer
  309. *
  310. * Tear down the hpd pins used by the card (evergreen+).
  311. * Disable the hpd interrupts.
  312. */
  313. static void dce_v6_0_hpd_fini(struct amdgpu_device *adev)
  314. {
  315. struct drm_device *dev = adev->ddev;
  316. struct drm_connector *connector;
  317. u32 tmp;
  318. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  319. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  320. if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
  321. continue;
  322. tmp = RREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
  323. tmp &= ~DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
  324. WREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], 0);
  325. amdgpu_irq_put(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
  326. }
  327. }
  328. static u32 dce_v6_0_hpd_get_gpio_reg(struct amdgpu_device *adev)
  329. {
  330. return mmDC_GPIO_HPD_A;
  331. }
  332. static u32 evergreen_get_vblank_counter(struct amdgpu_device* adev, int crtc)
  333. {
  334. if (crtc >= adev->mode_info.num_crtc)
  335. return 0;
  336. else
  337. return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
  338. }
  339. static void dce_v6_0_stop_mc_access(struct amdgpu_device *adev,
  340. struct amdgpu_mode_mc_save *save)
  341. {
  342. u32 crtc_enabled, tmp, frame_count;
  343. int i, j;
  344. save->vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
  345. save->vga_hdp_control = RREG32(mmVGA_HDP_CONTROL);
  346. /* disable VGA render */
  347. WREG32(mmVGA_RENDER_CONTROL, 0);
  348. /* blank the display controllers */
  349. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  350. crtc_enabled = RREG32(mmCRTC_CONTROL + crtc_offsets[i]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK;
  351. if (crtc_enabled) {
  352. save->crtc_enabled[i] = true;
  353. tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
  354. if (!(tmp & CRTC_BLANK_CONTROL__CRTC_BLANK_DATA_EN_MASK)) {
  355. dce_v6_0_vblank_wait(adev, i);
  356. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  357. tmp |= CRTC_BLANK_CONTROL__CRTC_BLANK_DATA_EN_MASK;
  358. WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  359. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  360. }
  361. /* wait for the next frame */
  362. frame_count = evergreen_get_vblank_counter(adev, i);
  363. for (j = 0; j < adev->usec_timeout; j++) {
  364. if (evergreen_get_vblank_counter(adev, i) != frame_count)
  365. break;
  366. udelay(1);
  367. }
  368. /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
  369. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  370. tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
  371. tmp &= ~CRTC_CONTROL__CRTC_MASTER_EN_MASK;
  372. WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
  373. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  374. save->crtc_enabled[i] = false;
  375. /* ***** */
  376. } else {
  377. save->crtc_enabled[i] = false;
  378. }
  379. }
  380. }
  381. static void dce_v6_0_resume_mc_access(struct amdgpu_device *adev,
  382. struct amdgpu_mode_mc_save *save)
  383. {
  384. u32 tmp;
  385. int i, j;
  386. /* update crtc base addresses */
  387. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  388. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  389. upper_32_bits(adev->mc.vram_start));
  390. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  391. upper_32_bits(adev->mc.vram_start));
  392. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
  393. (u32)adev->mc.vram_start);
  394. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
  395. (u32)adev->mc.vram_start);
  396. }
  397. WREG32(mmVGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(adev->mc.vram_start));
  398. WREG32(mmVGA_MEMORY_BASE_ADDRESS, (u32)adev->mc.vram_start);
  399. /* unlock regs and wait for update */
  400. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  401. if (save->crtc_enabled[i]) {
  402. tmp = RREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i]);
  403. if ((tmp & 0x7) != 0) {
  404. tmp &= ~0x7;
  405. WREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i], tmp);
  406. }
  407. tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
  408. if (tmp & GRPH_UPDATE__GRPH_UPDATE_LOCK_MASK) {
  409. tmp &= ~GRPH_UPDATE__GRPH_UPDATE_LOCK_MASK;
  410. WREG32(mmGRPH_UPDATE + crtc_offsets[i], tmp);
  411. }
  412. tmp = RREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i]);
  413. if (tmp & 1) {
  414. tmp &= ~1;
  415. WREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  416. }
  417. for (j = 0; j < adev->usec_timeout; j++) {
  418. tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
  419. if ((tmp & GRPH_UPDATE__GRPH_SURFACE_UPDATE_PENDING_MASK) == 0)
  420. break;
  421. udelay(1);
  422. }
  423. }
  424. }
  425. /* Unlock vga access */
  426. WREG32(mmVGA_HDP_CONTROL, save->vga_hdp_control);
  427. mdelay(1);
  428. WREG32(mmVGA_RENDER_CONTROL, save->vga_render_control);
  429. }
  430. static void dce_v6_0_set_vga_render_state(struct amdgpu_device *adev,
  431. bool render)
  432. {
  433. if (!render)
  434. WREG32(mmVGA_RENDER_CONTROL,
  435. RREG32(mmVGA_RENDER_CONTROL) & VGA_VSTATUS_CNTL);
  436. }
  437. static int dce_v6_0_get_num_crtc(struct amdgpu_device *adev)
  438. {
  439. int num_crtc = 0;
  440. switch (adev->asic_type) {
  441. case CHIP_TAHITI:
  442. case CHIP_PITCAIRN:
  443. case CHIP_VERDE:
  444. num_crtc = 6;
  445. break;
  446. case CHIP_OLAND:
  447. num_crtc = 2;
  448. break;
  449. default:
  450. num_crtc = 0;
  451. }
  452. return num_crtc;
  453. }
  454. void dce_v6_0_disable_dce(struct amdgpu_device *adev)
  455. {
  456. /*Disable VGA render and enabled crtc, if has DCE engine*/
  457. if (amdgpu_atombios_has_dce_engine_info(adev)) {
  458. u32 tmp;
  459. int crtc_enabled, i;
  460. dce_v6_0_set_vga_render_state(adev, false);
  461. /*Disable crtc*/
  462. for (i = 0; i < dce_v6_0_get_num_crtc(adev); i++) {
  463. crtc_enabled = RREG32(mmCRTC_CONTROL + crtc_offsets[i]) &
  464. CRTC_CONTROL__CRTC_MASTER_EN_MASK;
  465. if (crtc_enabled) {
  466. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  467. tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
  468. tmp &= ~CRTC_CONTROL__CRTC_MASTER_EN_MASK;
  469. WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
  470. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  471. }
  472. }
  473. }
  474. }
  475. static void dce_v6_0_program_fmt(struct drm_encoder *encoder)
  476. {
  477. struct drm_device *dev = encoder->dev;
  478. struct amdgpu_device *adev = dev->dev_private;
  479. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  480. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  481. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
  482. int bpc = 0;
  483. u32 tmp = 0;
  484. enum amdgpu_connector_dither dither = AMDGPU_FMT_DITHER_DISABLE;
  485. if (connector) {
  486. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  487. bpc = amdgpu_connector_get_monitor_bpc(connector);
  488. dither = amdgpu_connector->dither;
  489. }
  490. /* LVDS FMT is set up by atom */
  491. if (amdgpu_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  492. return;
  493. if (bpc == 0)
  494. return;
  495. switch (bpc) {
  496. case 6:
  497. if (dither == AMDGPU_FMT_DITHER_ENABLE)
  498. /* XXX sort out optimal dither settings */
  499. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
  500. FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
  501. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK);
  502. else
  503. tmp |= FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK;
  504. break;
  505. case 8:
  506. if (dither == AMDGPU_FMT_DITHER_ENABLE)
  507. /* XXX sort out optimal dither settings */
  508. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
  509. FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
  510. FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
  511. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
  512. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH_MASK);
  513. else
  514. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
  515. FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH_MASK);
  516. break;
  517. case 10:
  518. default:
  519. /* not needed */
  520. break;
  521. }
  522. WREG32(mmFMT_BIT_DEPTH_CONTROL + amdgpu_crtc->crtc_offset, tmp);
  523. }
  524. /**
  525. * cik_get_number_of_dram_channels - get the number of dram channels
  526. *
  527. * @adev: amdgpu_device pointer
  528. *
  529. * Look up the number of video ram channels (CIK).
  530. * Used for display watermark bandwidth calculations
  531. * Returns the number of dram channels
  532. */
  533. static u32 si_get_number_of_dram_channels(struct amdgpu_device *adev)
  534. {
  535. u32 tmp = RREG32(mmMC_SHARED_CHMAP);
  536. switch ((tmp & MC_SHARED_CHMAP__NOOFCHAN_MASK) >> MC_SHARED_CHMAP__NOOFCHAN__SHIFT) {
  537. case 0:
  538. default:
  539. return 1;
  540. case 1:
  541. return 2;
  542. case 2:
  543. return 4;
  544. case 3:
  545. return 8;
  546. case 4:
  547. return 3;
  548. case 5:
  549. return 6;
  550. case 6:
  551. return 10;
  552. case 7:
  553. return 12;
  554. case 8:
  555. return 16;
  556. }
  557. }
  558. struct dce6_wm_params {
  559. u32 dram_channels; /* number of dram channels */
  560. u32 yclk; /* bandwidth per dram data pin in kHz */
  561. u32 sclk; /* engine clock in kHz */
  562. u32 disp_clk; /* display clock in kHz */
  563. u32 src_width; /* viewport width */
  564. u32 active_time; /* active display time in ns */
  565. u32 blank_time; /* blank time in ns */
  566. bool interlaced; /* mode is interlaced */
  567. fixed20_12 vsc; /* vertical scale ratio */
  568. u32 num_heads; /* number of active crtcs */
  569. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  570. u32 lb_size; /* line buffer allocated to pipe */
  571. u32 vtaps; /* vertical scaler taps */
  572. };
  573. /**
  574. * dce_v6_0_dram_bandwidth - get the dram bandwidth
  575. *
  576. * @wm: watermark calculation data
  577. *
  578. * Calculate the raw dram bandwidth (CIK).
  579. * Used for display watermark bandwidth calculations
  580. * Returns the dram bandwidth in MBytes/s
  581. */
  582. static u32 dce_v6_0_dram_bandwidth(struct dce6_wm_params *wm)
  583. {
  584. /* Calculate raw DRAM Bandwidth */
  585. fixed20_12 dram_efficiency; /* 0.7 */
  586. fixed20_12 yclk, dram_channels, bandwidth;
  587. fixed20_12 a;
  588. a.full = dfixed_const(1000);
  589. yclk.full = dfixed_const(wm->yclk);
  590. yclk.full = dfixed_div(yclk, a);
  591. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  592. a.full = dfixed_const(10);
  593. dram_efficiency.full = dfixed_const(7);
  594. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  595. bandwidth.full = dfixed_mul(dram_channels, yclk);
  596. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  597. return dfixed_trunc(bandwidth);
  598. }
  599. /**
  600. * dce_v6_0_dram_bandwidth_for_display - get the dram bandwidth for display
  601. *
  602. * @wm: watermark calculation data
  603. *
  604. * Calculate the dram bandwidth used for display (CIK).
  605. * Used for display watermark bandwidth calculations
  606. * Returns the dram bandwidth for display in MBytes/s
  607. */
  608. static u32 dce_v6_0_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  609. {
  610. /* Calculate DRAM Bandwidth and the part allocated to display. */
  611. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  612. fixed20_12 yclk, dram_channels, bandwidth;
  613. fixed20_12 a;
  614. a.full = dfixed_const(1000);
  615. yclk.full = dfixed_const(wm->yclk);
  616. yclk.full = dfixed_div(yclk, a);
  617. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  618. a.full = dfixed_const(10);
  619. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  620. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  621. bandwidth.full = dfixed_mul(dram_channels, yclk);
  622. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  623. return dfixed_trunc(bandwidth);
  624. }
  625. /**
  626. * dce_v6_0_data_return_bandwidth - get the data return bandwidth
  627. *
  628. * @wm: watermark calculation data
  629. *
  630. * Calculate the data return bandwidth used for display (CIK).
  631. * Used for display watermark bandwidth calculations
  632. * Returns the data return bandwidth in MBytes/s
  633. */
  634. static u32 dce_v6_0_data_return_bandwidth(struct dce6_wm_params *wm)
  635. {
  636. /* Calculate the display Data return Bandwidth */
  637. fixed20_12 return_efficiency; /* 0.8 */
  638. fixed20_12 sclk, bandwidth;
  639. fixed20_12 a;
  640. a.full = dfixed_const(1000);
  641. sclk.full = dfixed_const(wm->sclk);
  642. sclk.full = dfixed_div(sclk, a);
  643. a.full = dfixed_const(10);
  644. return_efficiency.full = dfixed_const(8);
  645. return_efficiency.full = dfixed_div(return_efficiency, a);
  646. a.full = dfixed_const(32);
  647. bandwidth.full = dfixed_mul(a, sclk);
  648. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  649. return dfixed_trunc(bandwidth);
  650. }
  651. /**
  652. * dce_v6_0_dmif_request_bandwidth - get the dmif bandwidth
  653. *
  654. * @wm: watermark calculation data
  655. *
  656. * Calculate the dmif bandwidth used for display (CIK).
  657. * Used for display watermark bandwidth calculations
  658. * Returns the dmif bandwidth in MBytes/s
  659. */
  660. static u32 dce_v6_0_dmif_request_bandwidth(struct dce6_wm_params *wm)
  661. {
  662. /* Calculate the DMIF Request Bandwidth */
  663. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  664. fixed20_12 disp_clk, bandwidth;
  665. fixed20_12 a, b;
  666. a.full = dfixed_const(1000);
  667. disp_clk.full = dfixed_const(wm->disp_clk);
  668. disp_clk.full = dfixed_div(disp_clk, a);
  669. a.full = dfixed_const(32);
  670. b.full = dfixed_mul(a, disp_clk);
  671. a.full = dfixed_const(10);
  672. disp_clk_request_efficiency.full = dfixed_const(8);
  673. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  674. bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
  675. return dfixed_trunc(bandwidth);
  676. }
  677. /**
  678. * dce_v6_0_available_bandwidth - get the min available bandwidth
  679. *
  680. * @wm: watermark calculation data
  681. *
  682. * Calculate the min available bandwidth used for display (CIK).
  683. * Used for display watermark bandwidth calculations
  684. * Returns the min available bandwidth in MBytes/s
  685. */
  686. static u32 dce_v6_0_available_bandwidth(struct dce6_wm_params *wm)
  687. {
  688. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  689. u32 dram_bandwidth = dce_v6_0_dram_bandwidth(wm);
  690. u32 data_return_bandwidth = dce_v6_0_data_return_bandwidth(wm);
  691. u32 dmif_req_bandwidth = dce_v6_0_dmif_request_bandwidth(wm);
  692. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  693. }
  694. /**
  695. * dce_v6_0_average_bandwidth - get the average available bandwidth
  696. *
  697. * @wm: watermark calculation data
  698. *
  699. * Calculate the average available bandwidth used for display (CIK).
  700. * Used for display watermark bandwidth calculations
  701. * Returns the average available bandwidth in MBytes/s
  702. */
  703. static u32 dce_v6_0_average_bandwidth(struct dce6_wm_params *wm)
  704. {
  705. /* Calculate the display mode Average Bandwidth
  706. * DisplayMode should contain the source and destination dimensions,
  707. * timing, etc.
  708. */
  709. fixed20_12 bpp;
  710. fixed20_12 line_time;
  711. fixed20_12 src_width;
  712. fixed20_12 bandwidth;
  713. fixed20_12 a;
  714. a.full = dfixed_const(1000);
  715. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  716. line_time.full = dfixed_div(line_time, a);
  717. bpp.full = dfixed_const(wm->bytes_per_pixel);
  718. src_width.full = dfixed_const(wm->src_width);
  719. bandwidth.full = dfixed_mul(src_width, bpp);
  720. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  721. bandwidth.full = dfixed_div(bandwidth, line_time);
  722. return dfixed_trunc(bandwidth);
  723. }
  724. /**
  725. * dce_v6_0_latency_watermark - get the latency watermark
  726. *
  727. * @wm: watermark calculation data
  728. *
  729. * Calculate the latency watermark (CIK).
  730. * Used for display watermark bandwidth calculations
  731. * Returns the latency watermark in ns
  732. */
  733. static u32 dce_v6_0_latency_watermark(struct dce6_wm_params *wm)
  734. {
  735. /* First calculate the latency in ns */
  736. u32 mc_latency = 2000; /* 2000 ns. */
  737. u32 available_bandwidth = dce_v6_0_available_bandwidth(wm);
  738. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  739. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  740. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  741. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  742. (wm->num_heads * cursor_line_pair_return_time);
  743. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  744. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  745. u32 tmp, dmif_size = 12288;
  746. fixed20_12 a, b, c;
  747. if (wm->num_heads == 0)
  748. return 0;
  749. a.full = dfixed_const(2);
  750. b.full = dfixed_const(1);
  751. if ((wm->vsc.full > a.full) ||
  752. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  753. (wm->vtaps >= 5) ||
  754. ((wm->vsc.full >= a.full) && wm->interlaced))
  755. max_src_lines_per_dst_line = 4;
  756. else
  757. max_src_lines_per_dst_line = 2;
  758. a.full = dfixed_const(available_bandwidth);
  759. b.full = dfixed_const(wm->num_heads);
  760. a.full = dfixed_div(a, b);
  761. tmp = div_u64((u64) dmif_size * (u64) wm->disp_clk, mc_latency + 512);
  762. tmp = min(dfixed_trunc(a), tmp);
  763. lb_fill_bw = min(tmp, wm->disp_clk * wm->bytes_per_pixel / 1000);
  764. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  765. b.full = dfixed_const(1000);
  766. c.full = dfixed_const(lb_fill_bw);
  767. b.full = dfixed_div(c, b);
  768. a.full = dfixed_div(a, b);
  769. line_fill_time = dfixed_trunc(a);
  770. if (line_fill_time < wm->active_time)
  771. return latency;
  772. else
  773. return latency + (line_fill_time - wm->active_time);
  774. }
  775. /**
  776. * dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display - check
  777. * average and available dram bandwidth
  778. *
  779. * @wm: watermark calculation data
  780. *
  781. * Check if the display average bandwidth fits in the display
  782. * dram bandwidth (CIK).
  783. * Used for display watermark bandwidth calculations
  784. * Returns true if the display fits, false if not.
  785. */
  786. static bool dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  787. {
  788. if (dce_v6_0_average_bandwidth(wm) <=
  789. (dce_v6_0_dram_bandwidth_for_display(wm) / wm->num_heads))
  790. return true;
  791. else
  792. return false;
  793. }
  794. /**
  795. * dce_v6_0_average_bandwidth_vs_available_bandwidth - check
  796. * average and available bandwidth
  797. *
  798. * @wm: watermark calculation data
  799. *
  800. * Check if the display average bandwidth fits in the display
  801. * available bandwidth (CIK).
  802. * Used for display watermark bandwidth calculations
  803. * Returns true if the display fits, false if not.
  804. */
  805. static bool dce_v6_0_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
  806. {
  807. if (dce_v6_0_average_bandwidth(wm) <=
  808. (dce_v6_0_available_bandwidth(wm) / wm->num_heads))
  809. return true;
  810. else
  811. return false;
  812. }
  813. /**
  814. * dce_v6_0_check_latency_hiding - check latency hiding
  815. *
  816. * @wm: watermark calculation data
  817. *
  818. * Check latency hiding (CIK).
  819. * Used for display watermark bandwidth calculations
  820. * Returns true if the display fits, false if not.
  821. */
  822. static bool dce_v6_0_check_latency_hiding(struct dce6_wm_params *wm)
  823. {
  824. u32 lb_partitions = wm->lb_size / wm->src_width;
  825. u32 line_time = wm->active_time + wm->blank_time;
  826. u32 latency_tolerant_lines;
  827. u32 latency_hiding;
  828. fixed20_12 a;
  829. a.full = dfixed_const(1);
  830. if (wm->vsc.full > a.full)
  831. latency_tolerant_lines = 1;
  832. else {
  833. if (lb_partitions <= (wm->vtaps + 1))
  834. latency_tolerant_lines = 1;
  835. else
  836. latency_tolerant_lines = 2;
  837. }
  838. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  839. if (dce_v6_0_latency_watermark(wm) <= latency_hiding)
  840. return true;
  841. else
  842. return false;
  843. }
  844. /**
  845. * dce_v6_0_program_watermarks - program display watermarks
  846. *
  847. * @adev: amdgpu_device pointer
  848. * @amdgpu_crtc: the selected display controller
  849. * @lb_size: line buffer size
  850. * @num_heads: number of display controllers in use
  851. *
  852. * Calculate and program the display watermarks for the
  853. * selected display controller (CIK).
  854. */
  855. static void dce_v6_0_program_watermarks(struct amdgpu_device *adev,
  856. struct amdgpu_crtc *amdgpu_crtc,
  857. u32 lb_size, u32 num_heads)
  858. {
  859. struct drm_display_mode *mode = &amdgpu_crtc->base.mode;
  860. struct dce6_wm_params wm_low, wm_high;
  861. u32 dram_channels;
  862. u32 active_time;
  863. u32 line_time = 0;
  864. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  865. u32 priority_a_mark = 0, priority_b_mark = 0;
  866. u32 priority_a_cnt = PRIORITY_OFF;
  867. u32 priority_b_cnt = PRIORITY_OFF;
  868. u32 tmp, arb_control3;
  869. fixed20_12 a, b, c;
  870. if (amdgpu_crtc->base.enabled && num_heads && mode) {
  871. active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock;
  872. line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535);
  873. priority_a_cnt = 0;
  874. priority_b_cnt = 0;
  875. dram_channels = si_get_number_of_dram_channels(adev);
  876. /* watermark for high clocks */
  877. if (adev->pm.dpm_enabled) {
  878. wm_high.yclk =
  879. amdgpu_dpm_get_mclk(adev, false) * 10;
  880. wm_high.sclk =
  881. amdgpu_dpm_get_sclk(adev, false) * 10;
  882. } else {
  883. wm_high.yclk = adev->pm.current_mclk * 10;
  884. wm_high.sclk = adev->pm.current_sclk * 10;
  885. }
  886. wm_high.disp_clk = mode->clock;
  887. wm_high.src_width = mode->crtc_hdisplay;
  888. wm_high.active_time = active_time;
  889. wm_high.blank_time = line_time - wm_high.active_time;
  890. wm_high.interlaced = false;
  891. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  892. wm_high.interlaced = true;
  893. wm_high.vsc = amdgpu_crtc->vsc;
  894. wm_high.vtaps = 1;
  895. if (amdgpu_crtc->rmx_type != RMX_OFF)
  896. wm_high.vtaps = 2;
  897. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  898. wm_high.lb_size = lb_size;
  899. wm_high.dram_channels = dram_channels;
  900. wm_high.num_heads = num_heads;
  901. if (adev->pm.dpm_enabled) {
  902. /* watermark for low clocks */
  903. wm_low.yclk =
  904. amdgpu_dpm_get_mclk(adev, true) * 10;
  905. wm_low.sclk =
  906. amdgpu_dpm_get_sclk(adev, true) * 10;
  907. } else {
  908. wm_low.yclk = adev->pm.current_mclk * 10;
  909. wm_low.sclk = adev->pm.current_sclk * 10;
  910. }
  911. wm_low.disp_clk = mode->clock;
  912. wm_low.src_width = mode->crtc_hdisplay;
  913. wm_low.active_time = active_time;
  914. wm_low.blank_time = line_time - wm_low.active_time;
  915. wm_low.interlaced = false;
  916. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  917. wm_low.interlaced = true;
  918. wm_low.vsc = amdgpu_crtc->vsc;
  919. wm_low.vtaps = 1;
  920. if (amdgpu_crtc->rmx_type != RMX_OFF)
  921. wm_low.vtaps = 2;
  922. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  923. wm_low.lb_size = lb_size;
  924. wm_low.dram_channels = dram_channels;
  925. wm_low.num_heads = num_heads;
  926. /* set for high clocks */
  927. latency_watermark_a = min(dce_v6_0_latency_watermark(&wm_high), (u32)65535);
  928. /* set for low clocks */
  929. latency_watermark_b = min(dce_v6_0_latency_watermark(&wm_low), (u32)65535);
  930. /* possibly force display priority to high */
  931. /* should really do this at mode validation time... */
  932. if (!dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  933. !dce_v6_0_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  934. !dce_v6_0_check_latency_hiding(&wm_high) ||
  935. (adev->mode_info.disp_priority == 2)) {
  936. DRM_DEBUG_KMS("force priority to high\n");
  937. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  938. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  939. }
  940. if (!dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  941. !dce_v6_0_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  942. !dce_v6_0_check_latency_hiding(&wm_low) ||
  943. (adev->mode_info.disp_priority == 2)) {
  944. DRM_DEBUG_KMS("force priority to high\n");
  945. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  946. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  947. }
  948. a.full = dfixed_const(1000);
  949. b.full = dfixed_const(mode->clock);
  950. b.full = dfixed_div(b, a);
  951. c.full = dfixed_const(latency_watermark_a);
  952. c.full = dfixed_mul(c, b);
  953. c.full = dfixed_mul(c, amdgpu_crtc->hsc);
  954. c.full = dfixed_div(c, a);
  955. a.full = dfixed_const(16);
  956. c.full = dfixed_div(c, a);
  957. priority_a_mark = dfixed_trunc(c);
  958. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  959. a.full = dfixed_const(1000);
  960. b.full = dfixed_const(mode->clock);
  961. b.full = dfixed_div(b, a);
  962. c.full = dfixed_const(latency_watermark_b);
  963. c.full = dfixed_mul(c, b);
  964. c.full = dfixed_mul(c, amdgpu_crtc->hsc);
  965. c.full = dfixed_div(c, a);
  966. a.full = dfixed_const(16);
  967. c.full = dfixed_div(c, a);
  968. priority_b_mark = dfixed_trunc(c);
  969. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  970. }
  971. /* select wm A */
  972. arb_control3 = RREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset);
  973. tmp = arb_control3;
  974. tmp &= ~LATENCY_WATERMARK_MASK(3);
  975. tmp |= LATENCY_WATERMARK_MASK(1);
  976. WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, tmp);
  977. WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
  978. ((latency_watermark_a << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
  979. (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
  980. /* select wm B */
  981. tmp = RREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset);
  982. tmp &= ~LATENCY_WATERMARK_MASK(3);
  983. tmp |= LATENCY_WATERMARK_MASK(2);
  984. WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, tmp);
  985. WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
  986. ((latency_watermark_b << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
  987. (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
  988. /* restore original selection */
  989. WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, arb_control3);
  990. /* write the priority marks */
  991. WREG32(mmPRIORITY_A_CNT + amdgpu_crtc->crtc_offset, priority_a_cnt);
  992. WREG32(mmPRIORITY_B_CNT + amdgpu_crtc->crtc_offset, priority_b_cnt);
  993. /* save values for DPM */
  994. amdgpu_crtc->line_time = line_time;
  995. amdgpu_crtc->wm_high = latency_watermark_a;
  996. }
  997. /* watermark setup */
  998. static u32 dce_v6_0_line_buffer_adjust(struct amdgpu_device *adev,
  999. struct amdgpu_crtc *amdgpu_crtc,
  1000. struct drm_display_mode *mode,
  1001. struct drm_display_mode *other_mode)
  1002. {
  1003. u32 tmp, buffer_alloc, i;
  1004. u32 pipe_offset = amdgpu_crtc->crtc_id * 0x8;
  1005. /*
  1006. * Line Buffer Setup
  1007. * There are 3 line buffers, each one shared by 2 display controllers.
  1008. * mmDC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1009. * the display controllers. The paritioning is done via one of four
  1010. * preset allocations specified in bits 21:20:
  1011. * 0 - half lb
  1012. * 2 - whole lb, other crtc must be disabled
  1013. */
  1014. /* this can get tricky if we have two large displays on a paired group
  1015. * of crtcs. Ideally for multiple large displays we'd assign them to
  1016. * non-linked crtcs for maximum line buffer allocation.
  1017. */
  1018. if (amdgpu_crtc->base.enabled && mode) {
  1019. if (other_mode) {
  1020. tmp = 0; /* 1/2 */
  1021. buffer_alloc = 1;
  1022. } else {
  1023. tmp = 2; /* whole */
  1024. buffer_alloc = 2;
  1025. }
  1026. } else {
  1027. tmp = 0;
  1028. buffer_alloc = 0;
  1029. }
  1030. WREG32(mmDC_LB_MEMORY_SPLIT + amdgpu_crtc->crtc_offset,
  1031. DC_LB_MEMORY_CONFIG(tmp));
  1032. WREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1033. (buffer_alloc << PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATED__SHIFT));
  1034. for (i = 0; i < adev->usec_timeout; i++) {
  1035. if (RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1036. PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATION_COMPLETED_MASK)
  1037. break;
  1038. udelay(1);
  1039. }
  1040. if (amdgpu_crtc->base.enabled && mode) {
  1041. switch (tmp) {
  1042. case 0:
  1043. default:
  1044. return 4096 * 2;
  1045. case 2:
  1046. return 8192 * 2;
  1047. }
  1048. }
  1049. /* controller not enabled, so no lb used */
  1050. return 0;
  1051. }
  1052. /**
  1053. *
  1054. * dce_v6_0_bandwidth_update - program display watermarks
  1055. *
  1056. * @adev: amdgpu_device pointer
  1057. *
  1058. * Calculate and program the display watermarks and line
  1059. * buffer allocation (CIK).
  1060. */
  1061. static void dce_v6_0_bandwidth_update(struct amdgpu_device *adev)
  1062. {
  1063. struct drm_display_mode *mode0 = NULL;
  1064. struct drm_display_mode *mode1 = NULL;
  1065. u32 num_heads = 0, lb_size;
  1066. int i;
  1067. if (!adev->mode_info.mode_config_initialized)
  1068. return;
  1069. amdgpu_update_display_priority(adev);
  1070. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1071. if (adev->mode_info.crtcs[i]->base.enabled)
  1072. num_heads++;
  1073. }
  1074. for (i = 0; i < adev->mode_info.num_crtc; i += 2) {
  1075. mode0 = &adev->mode_info.crtcs[i]->base.mode;
  1076. mode1 = &adev->mode_info.crtcs[i+1]->base.mode;
  1077. lb_size = dce_v6_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i], mode0, mode1);
  1078. dce_v6_0_program_watermarks(adev, adev->mode_info.crtcs[i], lb_size, num_heads);
  1079. lb_size = dce_v6_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i+1], mode1, mode0);
  1080. dce_v6_0_program_watermarks(adev, adev->mode_info.crtcs[i+1], lb_size, num_heads);
  1081. }
  1082. }
  1083. /*
  1084. static void dce_v6_0_audio_get_connected_pins(struct amdgpu_device *adev)
  1085. {
  1086. int i;
  1087. u32 offset, tmp;
  1088. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1089. offset = adev->mode_info.audio.pin[i].offset;
  1090. tmp = RREG32_AUDIO_ENDPT(offset,
  1091. AZ_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT);
  1092. if (((tmp & PORT_CONNECTIVITY_MASK) >> PORT_CONNECTIVITY_SHIFT) == 1)
  1093. adev->mode_info.audio.pin[i].connected = false;
  1094. else
  1095. adev->mode_info.audio.pin[i].connected = true;
  1096. }
  1097. }
  1098. static struct amdgpu_audio_pin *dce_v6_0_audio_get_pin(struct amdgpu_device *adev)
  1099. {
  1100. int i;
  1101. dce_v6_0_audio_get_connected_pins(adev);
  1102. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1103. if (adev->mode_info.audio.pin[i].connected)
  1104. return &adev->mode_info.audio.pin[i];
  1105. }
  1106. DRM_ERROR("No connected audio pins found!\n");
  1107. return NULL;
  1108. }
  1109. static void dce_v6_0_afmt_audio_select_pin(struct drm_encoder *encoder)
  1110. {
  1111. struct amdgpu_device *adev = encoder->dev->dev_private;
  1112. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1113. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1114. u32 offset;
  1115. if (!dig || !dig->afmt || !dig->afmt->pin)
  1116. return;
  1117. offset = dig->afmt->offset;
  1118. WREG32(AFMT_AUDIO_SRC_CONTROL + offset,
  1119. AFMT_AUDIO_SRC_SELECT(dig->afmt->pin->id));
  1120. }
  1121. static void dce_v6_0_audio_write_latency_fields(struct drm_encoder *encoder,
  1122. struct drm_display_mode *mode)
  1123. {
  1124. DRM_INFO("xxxx: dce_v6_0_audio_write_latency_fields---no imp!!!!!\n");
  1125. }
  1126. static void dce_v6_0_audio_write_speaker_allocation(struct drm_encoder *encoder)
  1127. {
  1128. DRM_INFO("xxxx: dce_v6_0_audio_write_speaker_allocation---no imp!!!!!\n");
  1129. }
  1130. static void dce_v6_0_audio_write_sad_regs(struct drm_encoder *encoder)
  1131. {
  1132. DRM_INFO("xxxx: dce_v6_0_audio_write_sad_regs---no imp!!!!!\n");
  1133. }
  1134. */
  1135. static void dce_v6_0_audio_enable(struct amdgpu_device *adev,
  1136. struct amdgpu_audio_pin *pin,
  1137. bool enable)
  1138. {
  1139. DRM_INFO("xxxx: dce_v6_0_audio_enable---no imp!!!!!\n");
  1140. }
  1141. static const u32 pin_offsets[7] =
  1142. {
  1143. (0x1780 - 0x1780),
  1144. (0x1786 - 0x1780),
  1145. (0x178c - 0x1780),
  1146. (0x1792 - 0x1780),
  1147. (0x1798 - 0x1780),
  1148. (0x179d - 0x1780),
  1149. (0x17a4 - 0x1780),
  1150. };
  1151. static int dce_v6_0_audio_init(struct amdgpu_device *adev)
  1152. {
  1153. return 0;
  1154. }
  1155. static void dce_v6_0_audio_fini(struct amdgpu_device *adev)
  1156. {
  1157. }
  1158. /*
  1159. static void dce_v6_0_afmt_update_ACR(struct drm_encoder *encoder, uint32_t clock)
  1160. {
  1161. DRM_INFO("xxxx: dce_v6_0_afmt_update_ACR---no imp!!!!!\n");
  1162. }
  1163. */
  1164. /*
  1165. * build a HDMI Video Info Frame
  1166. */
  1167. /*
  1168. static void dce_v6_0_afmt_update_avi_infoframe(struct drm_encoder *encoder,
  1169. void *buffer, size_t size)
  1170. {
  1171. DRM_INFO("xxxx: dce_v6_0_afmt_update_avi_infoframe---no imp!!!!!\n");
  1172. }
  1173. static void dce_v6_0_audio_set_dto(struct drm_encoder *encoder, u32 clock)
  1174. {
  1175. DRM_INFO("xxxx: dce_v6_0_audio_set_dto---no imp!!!!!\n");
  1176. }
  1177. */
  1178. /*
  1179. * update the info frames with the data from the current display mode
  1180. */
  1181. static void dce_v6_0_afmt_setmode(struct drm_encoder *encoder,
  1182. struct drm_display_mode *mode)
  1183. {
  1184. DRM_INFO("xxxx: dce_v6_0_afmt_setmode ----no impl !!!!!!!!\n");
  1185. }
  1186. static void dce_v6_0_afmt_enable(struct drm_encoder *encoder, bool enable)
  1187. {
  1188. struct drm_device *dev = encoder->dev;
  1189. struct amdgpu_device *adev = dev->dev_private;
  1190. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1191. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1192. if (!dig || !dig->afmt)
  1193. return;
  1194. /* Silent, r600_hdmi_enable will raise WARN for us */
  1195. if (enable && dig->afmt->enabled)
  1196. return;
  1197. if (!enable && !dig->afmt->enabled)
  1198. return;
  1199. if (!enable && dig->afmt->pin) {
  1200. dce_v6_0_audio_enable(adev, dig->afmt->pin, false);
  1201. dig->afmt->pin = NULL;
  1202. }
  1203. dig->afmt->enabled = enable;
  1204. DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
  1205. enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id);
  1206. }
  1207. static int dce_v6_0_afmt_init(struct amdgpu_device *adev)
  1208. {
  1209. int i, j;
  1210. for (i = 0; i < adev->mode_info.num_dig; i++)
  1211. adev->mode_info.afmt[i] = NULL;
  1212. /* DCE6 has audio blocks tied to DIG encoders */
  1213. for (i = 0; i < adev->mode_info.num_dig; i++) {
  1214. adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL);
  1215. if (adev->mode_info.afmt[i]) {
  1216. adev->mode_info.afmt[i]->offset = dig_offsets[i];
  1217. adev->mode_info.afmt[i]->id = i;
  1218. } else {
  1219. for (j = 0; j < i; j++) {
  1220. kfree(adev->mode_info.afmt[j]);
  1221. adev->mode_info.afmt[j] = NULL;
  1222. }
  1223. DRM_ERROR("Out of memory allocating afmt table\n");
  1224. return -ENOMEM;
  1225. }
  1226. }
  1227. return 0;
  1228. }
  1229. static void dce_v6_0_afmt_fini(struct amdgpu_device *adev)
  1230. {
  1231. int i;
  1232. for (i = 0; i < adev->mode_info.num_dig; i++) {
  1233. kfree(adev->mode_info.afmt[i]);
  1234. adev->mode_info.afmt[i] = NULL;
  1235. }
  1236. }
  1237. static const u32 vga_control_regs[6] =
  1238. {
  1239. mmD1VGA_CONTROL,
  1240. mmD2VGA_CONTROL,
  1241. mmD3VGA_CONTROL,
  1242. mmD4VGA_CONTROL,
  1243. mmD5VGA_CONTROL,
  1244. mmD6VGA_CONTROL,
  1245. };
  1246. static void dce_v6_0_vga_enable(struct drm_crtc *crtc, bool enable)
  1247. {
  1248. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1249. struct drm_device *dev = crtc->dev;
  1250. struct amdgpu_device *adev = dev->dev_private;
  1251. u32 vga_control;
  1252. vga_control = RREG32(vga_control_regs[amdgpu_crtc->crtc_id]) & ~1;
  1253. WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control | (enable ? 1 : 0));
  1254. }
  1255. static void dce_v6_0_grph_enable(struct drm_crtc *crtc, bool enable)
  1256. {
  1257. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1258. struct drm_device *dev = crtc->dev;
  1259. struct amdgpu_device *adev = dev->dev_private;
  1260. WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, enable ? 1 : 0);
  1261. }
  1262. static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
  1263. struct drm_framebuffer *fb,
  1264. int x, int y, int atomic)
  1265. {
  1266. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1267. struct drm_device *dev = crtc->dev;
  1268. struct amdgpu_device *adev = dev->dev_private;
  1269. struct amdgpu_framebuffer *amdgpu_fb;
  1270. struct drm_framebuffer *target_fb;
  1271. struct drm_gem_object *obj;
  1272. struct amdgpu_bo *abo;
  1273. uint64_t fb_location, tiling_flags;
  1274. uint32_t fb_format, fb_pitch_pixels, pipe_config;
  1275. u32 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_NONE);
  1276. u32 viewport_w, viewport_h;
  1277. int r;
  1278. bool bypass_lut = false;
  1279. struct drm_format_name_buf format_name;
  1280. /* no fb bound */
  1281. if (!atomic && !crtc->primary->fb) {
  1282. DRM_DEBUG_KMS("No FB bound\n");
  1283. return 0;
  1284. }
  1285. if (atomic) {
  1286. amdgpu_fb = to_amdgpu_framebuffer(fb);
  1287. target_fb = fb;
  1288. } else {
  1289. amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
  1290. target_fb = crtc->primary->fb;
  1291. }
  1292. /* If atomic, assume fb object is pinned & idle & fenced and
  1293. * just update base pointers
  1294. */
  1295. obj = amdgpu_fb->obj;
  1296. abo = gem_to_amdgpu_bo(obj);
  1297. r = amdgpu_bo_reserve(abo, false);
  1298. if (unlikely(r != 0))
  1299. return r;
  1300. if (atomic) {
  1301. fb_location = amdgpu_bo_gpu_offset(abo);
  1302. } else {
  1303. r = amdgpu_bo_pin(abo, AMDGPU_GEM_DOMAIN_VRAM, &fb_location);
  1304. if (unlikely(r != 0)) {
  1305. amdgpu_bo_unreserve(abo);
  1306. return -EINVAL;
  1307. }
  1308. }
  1309. amdgpu_bo_get_tiling_flags(abo, &tiling_flags);
  1310. amdgpu_bo_unreserve(abo);
  1311. switch (target_fb->format->format) {
  1312. case DRM_FORMAT_C8:
  1313. fb_format = (GRPH_DEPTH(GRPH_DEPTH_8BPP) |
  1314. GRPH_FORMAT(GRPH_FORMAT_INDEXED));
  1315. break;
  1316. case DRM_FORMAT_XRGB4444:
  1317. case DRM_FORMAT_ARGB4444:
  1318. fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
  1319. GRPH_FORMAT(GRPH_FORMAT_ARGB4444));
  1320. #ifdef __BIG_ENDIAN
  1321. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
  1322. #endif
  1323. break;
  1324. case DRM_FORMAT_XRGB1555:
  1325. case DRM_FORMAT_ARGB1555:
  1326. fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
  1327. GRPH_FORMAT(GRPH_FORMAT_ARGB1555));
  1328. #ifdef __BIG_ENDIAN
  1329. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
  1330. #endif
  1331. break;
  1332. case DRM_FORMAT_BGRX5551:
  1333. case DRM_FORMAT_BGRA5551:
  1334. fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
  1335. GRPH_FORMAT(GRPH_FORMAT_BGRA5551));
  1336. #ifdef __BIG_ENDIAN
  1337. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
  1338. #endif
  1339. break;
  1340. case DRM_FORMAT_RGB565:
  1341. fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
  1342. GRPH_FORMAT(GRPH_FORMAT_ARGB565));
  1343. #ifdef __BIG_ENDIAN
  1344. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
  1345. #endif
  1346. break;
  1347. case DRM_FORMAT_XRGB8888:
  1348. case DRM_FORMAT_ARGB8888:
  1349. fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
  1350. GRPH_FORMAT(GRPH_FORMAT_ARGB8888));
  1351. #ifdef __BIG_ENDIAN
  1352. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
  1353. #endif
  1354. break;
  1355. case DRM_FORMAT_XRGB2101010:
  1356. case DRM_FORMAT_ARGB2101010:
  1357. fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
  1358. GRPH_FORMAT(GRPH_FORMAT_ARGB2101010));
  1359. #ifdef __BIG_ENDIAN
  1360. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
  1361. #endif
  1362. /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
  1363. bypass_lut = true;
  1364. break;
  1365. case DRM_FORMAT_BGRX1010102:
  1366. case DRM_FORMAT_BGRA1010102:
  1367. fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
  1368. GRPH_FORMAT(GRPH_FORMAT_BGRA1010102));
  1369. #ifdef __BIG_ENDIAN
  1370. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
  1371. #endif
  1372. /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
  1373. bypass_lut = true;
  1374. break;
  1375. default:
  1376. DRM_ERROR("Unsupported screen format %s\n",
  1377. drm_get_format_name(target_fb->format->format, &format_name));
  1378. return -EINVAL;
  1379. }
  1380. if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
  1381. unsigned bankw, bankh, mtaspect, tile_split, num_banks;
  1382. bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
  1383. bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
  1384. mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
  1385. tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
  1386. num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
  1387. fb_format |= GRPH_NUM_BANKS(num_banks);
  1388. fb_format |= GRPH_ARRAY_MODE(GRPH_ARRAY_2D_TILED_THIN1);
  1389. fb_format |= GRPH_TILE_SPLIT(tile_split);
  1390. fb_format |= GRPH_BANK_WIDTH(bankw);
  1391. fb_format |= GRPH_BANK_HEIGHT(bankh);
  1392. fb_format |= GRPH_MACRO_TILE_ASPECT(mtaspect);
  1393. } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
  1394. fb_format |= GRPH_ARRAY_MODE(GRPH_ARRAY_1D_TILED_THIN1);
  1395. }
  1396. pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
  1397. fb_format |= GRPH_PIPE_CONFIG(pipe_config);
  1398. dce_v6_0_vga_enable(crtc, false);
  1399. /* Make sure surface address is updated at vertical blank rather than
  1400. * horizontal blank
  1401. */
  1402. WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, 0);
  1403. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1404. upper_32_bits(fb_location));
  1405. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1406. upper_32_bits(fb_location));
  1407. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1408. (u32)fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
  1409. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1410. (u32) fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
  1411. WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format);
  1412. WREG32(mmGRPH_SWAP_CNTL + amdgpu_crtc->crtc_offset, fb_swap);
  1413. /*
  1414. * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
  1415. * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
  1416. * retain the full precision throughout the pipeline.
  1417. */
  1418. WREG32_P(mmGRPH_LUT_10BIT_BYPASS + amdgpu_crtc->crtc_offset,
  1419. (bypass_lut ? GRPH_LUT_10BIT_BYPASS__GRPH_LUT_10BIT_BYPASS_EN_MASK : 0),
  1420. ~GRPH_LUT_10BIT_BYPASS__GRPH_LUT_10BIT_BYPASS_EN_MASK);
  1421. if (bypass_lut)
  1422. DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
  1423. WREG32(mmGRPH_SURFACE_OFFSET_X + amdgpu_crtc->crtc_offset, 0);
  1424. WREG32(mmGRPH_SURFACE_OFFSET_Y + amdgpu_crtc->crtc_offset, 0);
  1425. WREG32(mmGRPH_X_START + amdgpu_crtc->crtc_offset, 0);
  1426. WREG32(mmGRPH_Y_START + amdgpu_crtc->crtc_offset, 0);
  1427. WREG32(mmGRPH_X_END + amdgpu_crtc->crtc_offset, target_fb->width);
  1428. WREG32(mmGRPH_Y_END + amdgpu_crtc->crtc_offset, target_fb->height);
  1429. fb_pitch_pixels = target_fb->pitches[0] / target_fb->format->cpp[0];
  1430. WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, fb_pitch_pixels);
  1431. dce_v6_0_grph_enable(crtc, true);
  1432. WREG32(mmDESKTOP_HEIGHT + amdgpu_crtc->crtc_offset,
  1433. target_fb->height);
  1434. x &= ~3;
  1435. y &= ~1;
  1436. WREG32(mmVIEWPORT_START + amdgpu_crtc->crtc_offset,
  1437. (x << 16) | y);
  1438. viewport_w = crtc->mode.hdisplay;
  1439. viewport_h = (crtc->mode.vdisplay + 1) & ~1;
  1440. WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
  1441. (viewport_w << 16) | viewport_h);
  1442. /* set pageflip to happen anywhere in vblank interval */
  1443. WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
  1444. if (!atomic && fb && fb != crtc->primary->fb) {
  1445. amdgpu_fb = to_amdgpu_framebuffer(fb);
  1446. abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
  1447. r = amdgpu_bo_reserve(abo, false);
  1448. if (unlikely(r != 0))
  1449. return r;
  1450. amdgpu_bo_unpin(abo);
  1451. amdgpu_bo_unreserve(abo);
  1452. }
  1453. /* Bytes per pixel may have changed */
  1454. dce_v6_0_bandwidth_update(adev);
  1455. return 0;
  1456. }
  1457. static void dce_v6_0_set_interleave(struct drm_crtc *crtc,
  1458. struct drm_display_mode *mode)
  1459. {
  1460. struct drm_device *dev = crtc->dev;
  1461. struct amdgpu_device *adev = dev->dev_private;
  1462. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1463. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1464. WREG32(mmDATA_FORMAT + amdgpu_crtc->crtc_offset,
  1465. INTERLEAVE_EN);
  1466. else
  1467. WREG32(mmDATA_FORMAT + amdgpu_crtc->crtc_offset, 0);
  1468. }
  1469. static void dce_v6_0_crtc_load_lut(struct drm_crtc *crtc)
  1470. {
  1471. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1472. struct drm_device *dev = crtc->dev;
  1473. struct amdgpu_device *adev = dev->dev_private;
  1474. int i;
  1475. DRM_DEBUG_KMS("%d\n", amdgpu_crtc->crtc_id);
  1476. WREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
  1477. ((0 << INPUT_CSC_CONTROL__INPUT_CSC_GRPH_MODE__SHIFT) |
  1478. (0 << INPUT_CSC_CONTROL__INPUT_CSC_OVL_MODE__SHIFT)));
  1479. WREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset,
  1480. PRESCALE_GRPH_CONTROL__GRPH_PRESCALE_BYPASS_MASK);
  1481. WREG32(mmPRESCALE_OVL_CONTROL + amdgpu_crtc->crtc_offset,
  1482. PRESCALE_OVL_CONTROL__OVL_PRESCALE_BYPASS_MASK);
  1483. WREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1484. ((0 << INPUT_GAMMA_CONTROL__GRPH_INPUT_GAMMA_MODE__SHIFT) |
  1485. (0 << INPUT_GAMMA_CONTROL__OVL_INPUT_GAMMA_MODE__SHIFT)));
  1486. WREG32(mmDC_LUT_CONTROL + amdgpu_crtc->crtc_offset, 0);
  1487. WREG32(mmDC_LUT_BLACK_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0);
  1488. WREG32(mmDC_LUT_BLACK_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0);
  1489. WREG32(mmDC_LUT_BLACK_OFFSET_RED + amdgpu_crtc->crtc_offset, 0);
  1490. WREG32(mmDC_LUT_WHITE_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0xffff);
  1491. WREG32(mmDC_LUT_WHITE_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0xffff);
  1492. WREG32(mmDC_LUT_WHITE_OFFSET_RED + amdgpu_crtc->crtc_offset, 0xffff);
  1493. WREG32(mmDC_LUT_RW_MODE + amdgpu_crtc->crtc_offset, 0);
  1494. WREG32(mmDC_LUT_WRITE_EN_MASK + amdgpu_crtc->crtc_offset, 0x00000007);
  1495. WREG32(mmDC_LUT_RW_INDEX + amdgpu_crtc->crtc_offset, 0);
  1496. for (i = 0; i < 256; i++) {
  1497. WREG32(mmDC_LUT_30_COLOR + amdgpu_crtc->crtc_offset,
  1498. (amdgpu_crtc->lut_r[i] << 20) |
  1499. (amdgpu_crtc->lut_g[i] << 10) |
  1500. (amdgpu_crtc->lut_b[i] << 0));
  1501. }
  1502. WREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1503. ((0 << DEGAMMA_CONTROL__GRPH_DEGAMMA_MODE__SHIFT) |
  1504. (0 << DEGAMMA_CONTROL__OVL_DEGAMMA_MODE__SHIFT) |
  1505. ICON_DEGAMMA_MODE(0) |
  1506. (0 << DEGAMMA_CONTROL__CURSOR_DEGAMMA_MODE__SHIFT)));
  1507. WREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset,
  1508. ((0 << GAMUT_REMAP_CONTROL__GRPH_GAMUT_REMAP_MODE__SHIFT) |
  1509. (0 << GAMUT_REMAP_CONTROL__OVL_GAMUT_REMAP_MODE__SHIFT)));
  1510. WREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1511. ((0 << REGAMMA_CONTROL__GRPH_REGAMMA_MODE__SHIFT) |
  1512. (0 << REGAMMA_CONTROL__OVL_REGAMMA_MODE__SHIFT)));
  1513. WREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
  1514. ((0 << OUTPUT_CSC_CONTROL__OUTPUT_CSC_GRPH_MODE__SHIFT) |
  1515. (0 << OUTPUT_CSC_CONTROL__OUTPUT_CSC_OVL_MODE__SHIFT)));
  1516. /* XXX match this to the depth of the crtc fmt block, move to modeset? */
  1517. WREG32(0x1a50 + amdgpu_crtc->crtc_offset, 0);
  1518. }
  1519. static int dce_v6_0_pick_dig_encoder(struct drm_encoder *encoder)
  1520. {
  1521. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1522. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1523. switch (amdgpu_encoder->encoder_id) {
  1524. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1525. return dig->linkb ? 1 : 0;
  1526. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1527. return dig->linkb ? 3 : 2;
  1528. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1529. return dig->linkb ? 5 : 4;
  1530. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  1531. return 6;
  1532. default:
  1533. DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id);
  1534. return 0;
  1535. }
  1536. }
  1537. /**
  1538. * dce_v6_0_pick_pll - Allocate a PPLL for use by the crtc.
  1539. *
  1540. * @crtc: drm crtc
  1541. *
  1542. * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
  1543. * a single PPLL can be used for all DP crtcs/encoders. For non-DP
  1544. * monitors a dedicated PPLL must be used. If a particular board has
  1545. * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
  1546. * as there is no need to program the PLL itself. If we are not able to
  1547. * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
  1548. * avoid messing up an existing monitor.
  1549. *
  1550. *
  1551. */
  1552. static u32 dce_v6_0_pick_pll(struct drm_crtc *crtc)
  1553. {
  1554. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1555. struct drm_device *dev = crtc->dev;
  1556. struct amdgpu_device *adev = dev->dev_private;
  1557. u32 pll_in_use;
  1558. int pll;
  1559. if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) {
  1560. if (adev->clock.dp_extclk)
  1561. /* skip PPLL programming if using ext clock */
  1562. return ATOM_PPLL_INVALID;
  1563. else
  1564. return ATOM_PPLL0;
  1565. } else {
  1566. /* use the same PPLL for all monitors with the same clock */
  1567. pll = amdgpu_pll_get_shared_nondp_ppll(crtc);
  1568. if (pll != ATOM_PPLL_INVALID)
  1569. return pll;
  1570. }
  1571. /* PPLL1, and PPLL2 */
  1572. pll_in_use = amdgpu_pll_get_use_mask(crtc);
  1573. if (!(pll_in_use & (1 << ATOM_PPLL2)))
  1574. return ATOM_PPLL2;
  1575. if (!(pll_in_use & (1 << ATOM_PPLL1)))
  1576. return ATOM_PPLL1;
  1577. DRM_ERROR("unable to allocate a PPLL\n");
  1578. return ATOM_PPLL_INVALID;
  1579. }
  1580. static void dce_v6_0_lock_cursor(struct drm_crtc *crtc, bool lock)
  1581. {
  1582. struct amdgpu_device *adev = crtc->dev->dev_private;
  1583. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1584. uint32_t cur_lock;
  1585. cur_lock = RREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset);
  1586. if (lock)
  1587. cur_lock |= CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
  1588. else
  1589. cur_lock &= ~CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
  1590. WREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset, cur_lock);
  1591. }
  1592. static void dce_v6_0_hide_cursor(struct drm_crtc *crtc)
  1593. {
  1594. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1595. struct amdgpu_device *adev = crtc->dev->dev_private;
  1596. WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
  1597. (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
  1598. (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
  1599. }
  1600. static void dce_v6_0_show_cursor(struct drm_crtc *crtc)
  1601. {
  1602. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1603. struct amdgpu_device *adev = crtc->dev->dev_private;
  1604. WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1605. upper_32_bits(amdgpu_crtc->cursor_addr));
  1606. WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1607. lower_32_bits(amdgpu_crtc->cursor_addr));
  1608. WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
  1609. CUR_CONTROL__CURSOR_EN_MASK |
  1610. (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
  1611. (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
  1612. }
  1613. static int dce_v6_0_cursor_move_locked(struct drm_crtc *crtc,
  1614. int x, int y)
  1615. {
  1616. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1617. struct amdgpu_device *adev = crtc->dev->dev_private;
  1618. int xorigin = 0, yorigin = 0;
  1619. int w = amdgpu_crtc->cursor_width;
  1620. amdgpu_crtc->cursor_x = x;
  1621. amdgpu_crtc->cursor_y = y;
  1622. /* avivo cursor are offset into the total surface */
  1623. x += crtc->x;
  1624. y += crtc->y;
  1625. DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
  1626. if (x < 0) {
  1627. xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
  1628. x = 0;
  1629. }
  1630. if (y < 0) {
  1631. yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
  1632. y = 0;
  1633. }
  1634. WREG32(mmCUR_POSITION + amdgpu_crtc->crtc_offset, (x << 16) | y);
  1635. WREG32(mmCUR_HOT_SPOT + amdgpu_crtc->crtc_offset, (xorigin << 16) | yorigin);
  1636. WREG32(mmCUR_SIZE + amdgpu_crtc->crtc_offset,
  1637. ((w - 1) << 16) | (amdgpu_crtc->cursor_height - 1));
  1638. return 0;
  1639. }
  1640. static int dce_v6_0_crtc_cursor_move(struct drm_crtc *crtc,
  1641. int x, int y)
  1642. {
  1643. int ret;
  1644. dce_v6_0_lock_cursor(crtc, true);
  1645. ret = dce_v6_0_cursor_move_locked(crtc, x, y);
  1646. dce_v6_0_lock_cursor(crtc, false);
  1647. return ret;
  1648. }
  1649. static int dce_v6_0_crtc_cursor_set2(struct drm_crtc *crtc,
  1650. struct drm_file *file_priv,
  1651. uint32_t handle,
  1652. uint32_t width,
  1653. uint32_t height,
  1654. int32_t hot_x,
  1655. int32_t hot_y)
  1656. {
  1657. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1658. struct drm_gem_object *obj;
  1659. struct amdgpu_bo *aobj;
  1660. int ret;
  1661. if (!handle) {
  1662. /* turn off cursor */
  1663. dce_v6_0_hide_cursor(crtc);
  1664. obj = NULL;
  1665. goto unpin;
  1666. }
  1667. if ((width > amdgpu_crtc->max_cursor_width) ||
  1668. (height > amdgpu_crtc->max_cursor_height)) {
  1669. DRM_ERROR("bad cursor width or height %d x %d\n", width, height);
  1670. return -EINVAL;
  1671. }
  1672. obj = drm_gem_object_lookup(file_priv, handle);
  1673. if (!obj) {
  1674. DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, amdgpu_crtc->crtc_id);
  1675. return -ENOENT;
  1676. }
  1677. aobj = gem_to_amdgpu_bo(obj);
  1678. ret = amdgpu_bo_reserve(aobj, false);
  1679. if (ret != 0) {
  1680. drm_gem_object_unreference_unlocked(obj);
  1681. return ret;
  1682. }
  1683. ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM, &amdgpu_crtc->cursor_addr);
  1684. amdgpu_bo_unreserve(aobj);
  1685. if (ret) {
  1686. DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret);
  1687. drm_gem_object_unreference_unlocked(obj);
  1688. return ret;
  1689. }
  1690. dce_v6_0_lock_cursor(crtc, true);
  1691. if (width != amdgpu_crtc->cursor_width ||
  1692. height != amdgpu_crtc->cursor_height ||
  1693. hot_x != amdgpu_crtc->cursor_hot_x ||
  1694. hot_y != amdgpu_crtc->cursor_hot_y) {
  1695. int x, y;
  1696. x = amdgpu_crtc->cursor_x + amdgpu_crtc->cursor_hot_x - hot_x;
  1697. y = amdgpu_crtc->cursor_y + amdgpu_crtc->cursor_hot_y - hot_y;
  1698. dce_v6_0_cursor_move_locked(crtc, x, y);
  1699. amdgpu_crtc->cursor_width = width;
  1700. amdgpu_crtc->cursor_height = height;
  1701. amdgpu_crtc->cursor_hot_x = hot_x;
  1702. amdgpu_crtc->cursor_hot_y = hot_y;
  1703. }
  1704. dce_v6_0_show_cursor(crtc);
  1705. dce_v6_0_lock_cursor(crtc, false);
  1706. unpin:
  1707. if (amdgpu_crtc->cursor_bo) {
  1708. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  1709. ret = amdgpu_bo_reserve(aobj, false);
  1710. if (likely(ret == 0)) {
  1711. amdgpu_bo_unpin(aobj);
  1712. amdgpu_bo_unreserve(aobj);
  1713. }
  1714. drm_gem_object_unreference_unlocked(amdgpu_crtc->cursor_bo);
  1715. }
  1716. amdgpu_crtc->cursor_bo = obj;
  1717. return 0;
  1718. }
  1719. static void dce_v6_0_cursor_reset(struct drm_crtc *crtc)
  1720. {
  1721. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1722. if (amdgpu_crtc->cursor_bo) {
  1723. dce_v6_0_lock_cursor(crtc, true);
  1724. dce_v6_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x,
  1725. amdgpu_crtc->cursor_y);
  1726. dce_v6_0_show_cursor(crtc);
  1727. dce_v6_0_lock_cursor(crtc, false);
  1728. }
  1729. }
  1730. static int dce_v6_0_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  1731. u16 *blue, uint32_t size,
  1732. struct drm_modeset_acquire_ctx *ctx)
  1733. {
  1734. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1735. int i;
  1736. /* userspace palettes are always correct as is */
  1737. for (i = 0; i < size; i++) {
  1738. amdgpu_crtc->lut_r[i] = red[i] >> 6;
  1739. amdgpu_crtc->lut_g[i] = green[i] >> 6;
  1740. amdgpu_crtc->lut_b[i] = blue[i] >> 6;
  1741. }
  1742. dce_v6_0_crtc_load_lut(crtc);
  1743. return 0;
  1744. }
  1745. static void dce_v6_0_crtc_destroy(struct drm_crtc *crtc)
  1746. {
  1747. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1748. drm_crtc_cleanup(crtc);
  1749. kfree(amdgpu_crtc);
  1750. }
  1751. static const struct drm_crtc_funcs dce_v6_0_crtc_funcs = {
  1752. .cursor_set2 = dce_v6_0_crtc_cursor_set2,
  1753. .cursor_move = dce_v6_0_crtc_cursor_move,
  1754. .gamma_set = dce_v6_0_crtc_gamma_set,
  1755. .set_config = amdgpu_crtc_set_config,
  1756. .destroy = dce_v6_0_crtc_destroy,
  1757. .page_flip_target = amdgpu_crtc_page_flip_target,
  1758. };
  1759. static void dce_v6_0_crtc_dpms(struct drm_crtc *crtc, int mode)
  1760. {
  1761. struct drm_device *dev = crtc->dev;
  1762. struct amdgpu_device *adev = dev->dev_private;
  1763. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1764. unsigned type;
  1765. switch (mode) {
  1766. case DRM_MODE_DPMS_ON:
  1767. amdgpu_crtc->enabled = true;
  1768. amdgpu_atombios_crtc_enable(crtc, ATOM_ENABLE);
  1769. amdgpu_atombios_crtc_blank(crtc, ATOM_DISABLE);
  1770. /* Make sure VBLANK and PFLIP interrupts are still enabled */
  1771. type = amdgpu_crtc_idx_to_irq_type(adev, amdgpu_crtc->crtc_id);
  1772. amdgpu_irq_update(adev, &adev->crtc_irq, type);
  1773. amdgpu_irq_update(adev, &adev->pageflip_irq, type);
  1774. drm_crtc_vblank_on(crtc);
  1775. dce_v6_0_crtc_load_lut(crtc);
  1776. break;
  1777. case DRM_MODE_DPMS_STANDBY:
  1778. case DRM_MODE_DPMS_SUSPEND:
  1779. case DRM_MODE_DPMS_OFF:
  1780. drm_crtc_vblank_off(crtc);
  1781. if (amdgpu_crtc->enabled)
  1782. amdgpu_atombios_crtc_blank(crtc, ATOM_ENABLE);
  1783. amdgpu_atombios_crtc_enable(crtc, ATOM_DISABLE);
  1784. amdgpu_crtc->enabled = false;
  1785. break;
  1786. }
  1787. /* adjust pm to dpms */
  1788. amdgpu_pm_compute_clocks(adev);
  1789. }
  1790. static void dce_v6_0_crtc_prepare(struct drm_crtc *crtc)
  1791. {
  1792. /* disable crtc pair power gating before programming */
  1793. amdgpu_atombios_crtc_powergate(crtc, ATOM_DISABLE);
  1794. amdgpu_atombios_crtc_lock(crtc, ATOM_ENABLE);
  1795. dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  1796. }
  1797. static void dce_v6_0_crtc_commit(struct drm_crtc *crtc)
  1798. {
  1799. dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
  1800. amdgpu_atombios_crtc_lock(crtc, ATOM_DISABLE);
  1801. }
  1802. static void dce_v6_0_crtc_disable(struct drm_crtc *crtc)
  1803. {
  1804. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1805. struct drm_device *dev = crtc->dev;
  1806. struct amdgpu_device *adev = dev->dev_private;
  1807. struct amdgpu_atom_ss ss;
  1808. int i;
  1809. dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  1810. if (crtc->primary->fb) {
  1811. int r;
  1812. struct amdgpu_framebuffer *amdgpu_fb;
  1813. struct amdgpu_bo *abo;
  1814. amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
  1815. abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
  1816. r = amdgpu_bo_reserve(abo, false);
  1817. if (unlikely(r))
  1818. DRM_ERROR("failed to reserve abo before unpin\n");
  1819. else {
  1820. amdgpu_bo_unpin(abo);
  1821. amdgpu_bo_unreserve(abo);
  1822. }
  1823. }
  1824. /* disable the GRPH */
  1825. dce_v6_0_grph_enable(crtc, false);
  1826. amdgpu_atombios_crtc_powergate(crtc, ATOM_ENABLE);
  1827. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1828. if (adev->mode_info.crtcs[i] &&
  1829. adev->mode_info.crtcs[i]->enabled &&
  1830. i != amdgpu_crtc->crtc_id &&
  1831. amdgpu_crtc->pll_id == adev->mode_info.crtcs[i]->pll_id) {
  1832. /* one other crtc is using this pll don't turn
  1833. * off the pll
  1834. */
  1835. goto done;
  1836. }
  1837. }
  1838. switch (amdgpu_crtc->pll_id) {
  1839. case ATOM_PPLL1:
  1840. case ATOM_PPLL2:
  1841. /* disable the ppll */
  1842. amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
  1843. 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
  1844. break;
  1845. default:
  1846. break;
  1847. }
  1848. done:
  1849. amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
  1850. amdgpu_crtc->adjusted_clock = 0;
  1851. amdgpu_crtc->encoder = NULL;
  1852. amdgpu_crtc->connector = NULL;
  1853. }
  1854. static int dce_v6_0_crtc_mode_set(struct drm_crtc *crtc,
  1855. struct drm_display_mode *mode,
  1856. struct drm_display_mode *adjusted_mode,
  1857. int x, int y, struct drm_framebuffer *old_fb)
  1858. {
  1859. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1860. if (!amdgpu_crtc->adjusted_clock)
  1861. return -EINVAL;
  1862. amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode);
  1863. amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode);
  1864. dce_v6_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
  1865. amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode);
  1866. amdgpu_atombios_crtc_scaler_setup(crtc);
  1867. dce_v6_0_cursor_reset(crtc);
  1868. /* update the hw version fpr dpm */
  1869. amdgpu_crtc->hw_mode = *adjusted_mode;
  1870. return 0;
  1871. }
  1872. static bool dce_v6_0_crtc_mode_fixup(struct drm_crtc *crtc,
  1873. const struct drm_display_mode *mode,
  1874. struct drm_display_mode *adjusted_mode)
  1875. {
  1876. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1877. struct drm_device *dev = crtc->dev;
  1878. struct drm_encoder *encoder;
  1879. /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
  1880. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1881. if (encoder->crtc == crtc) {
  1882. amdgpu_crtc->encoder = encoder;
  1883. amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder);
  1884. break;
  1885. }
  1886. }
  1887. if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) {
  1888. amdgpu_crtc->encoder = NULL;
  1889. amdgpu_crtc->connector = NULL;
  1890. return false;
  1891. }
  1892. if (!amdgpu_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
  1893. return false;
  1894. if (amdgpu_atombios_crtc_prepare_pll(crtc, adjusted_mode))
  1895. return false;
  1896. /* pick pll */
  1897. amdgpu_crtc->pll_id = dce_v6_0_pick_pll(crtc);
  1898. /* if we can't get a PPLL for a non-DP encoder, fail */
  1899. if ((amdgpu_crtc->pll_id == ATOM_PPLL_INVALID) &&
  1900. !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder)))
  1901. return false;
  1902. return true;
  1903. }
  1904. static int dce_v6_0_crtc_set_base(struct drm_crtc *crtc, int x, int y,
  1905. struct drm_framebuffer *old_fb)
  1906. {
  1907. return dce_v6_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
  1908. }
  1909. static int dce_v6_0_crtc_set_base_atomic(struct drm_crtc *crtc,
  1910. struct drm_framebuffer *fb,
  1911. int x, int y, enum mode_set_atomic state)
  1912. {
  1913. return dce_v6_0_crtc_do_set_base(crtc, fb, x, y, 1);
  1914. }
  1915. static const struct drm_crtc_helper_funcs dce_v6_0_crtc_helper_funcs = {
  1916. .dpms = dce_v6_0_crtc_dpms,
  1917. .mode_fixup = dce_v6_0_crtc_mode_fixup,
  1918. .mode_set = dce_v6_0_crtc_mode_set,
  1919. .mode_set_base = dce_v6_0_crtc_set_base,
  1920. .mode_set_base_atomic = dce_v6_0_crtc_set_base_atomic,
  1921. .prepare = dce_v6_0_crtc_prepare,
  1922. .commit = dce_v6_0_crtc_commit,
  1923. .load_lut = dce_v6_0_crtc_load_lut,
  1924. .disable = dce_v6_0_crtc_disable,
  1925. };
  1926. static int dce_v6_0_crtc_init(struct amdgpu_device *adev, int index)
  1927. {
  1928. struct amdgpu_crtc *amdgpu_crtc;
  1929. int i;
  1930. amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) +
  1931. (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  1932. if (amdgpu_crtc == NULL)
  1933. return -ENOMEM;
  1934. drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_v6_0_crtc_funcs);
  1935. drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256);
  1936. amdgpu_crtc->crtc_id = index;
  1937. adev->mode_info.crtcs[index] = amdgpu_crtc;
  1938. amdgpu_crtc->max_cursor_width = CURSOR_WIDTH;
  1939. amdgpu_crtc->max_cursor_height = CURSOR_HEIGHT;
  1940. adev->ddev->mode_config.cursor_width = amdgpu_crtc->max_cursor_width;
  1941. adev->ddev->mode_config.cursor_height = amdgpu_crtc->max_cursor_height;
  1942. for (i = 0; i < 256; i++) {
  1943. amdgpu_crtc->lut_r[i] = i << 2;
  1944. amdgpu_crtc->lut_g[i] = i << 2;
  1945. amdgpu_crtc->lut_b[i] = i << 2;
  1946. }
  1947. amdgpu_crtc->crtc_offset = crtc_offsets[amdgpu_crtc->crtc_id];
  1948. amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
  1949. amdgpu_crtc->adjusted_clock = 0;
  1950. amdgpu_crtc->encoder = NULL;
  1951. amdgpu_crtc->connector = NULL;
  1952. drm_crtc_helper_add(&amdgpu_crtc->base, &dce_v6_0_crtc_helper_funcs);
  1953. return 0;
  1954. }
  1955. static int dce_v6_0_early_init(void *handle)
  1956. {
  1957. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1958. adev->audio_endpt_rreg = &dce_v6_0_audio_endpt_rreg;
  1959. adev->audio_endpt_wreg = &dce_v6_0_audio_endpt_wreg;
  1960. dce_v6_0_set_display_funcs(adev);
  1961. dce_v6_0_set_irq_funcs(adev);
  1962. adev->mode_info.num_crtc = dce_v6_0_get_num_crtc(adev);
  1963. switch (adev->asic_type) {
  1964. case CHIP_TAHITI:
  1965. case CHIP_PITCAIRN:
  1966. case CHIP_VERDE:
  1967. adev->mode_info.num_hpd = 6;
  1968. adev->mode_info.num_dig = 6;
  1969. break;
  1970. case CHIP_OLAND:
  1971. adev->mode_info.num_hpd = 2;
  1972. adev->mode_info.num_dig = 2;
  1973. break;
  1974. default:
  1975. return -EINVAL;
  1976. }
  1977. return 0;
  1978. }
  1979. static int dce_v6_0_sw_init(void *handle)
  1980. {
  1981. int r, i;
  1982. bool ret;
  1983. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1984. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1985. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, i + 1, &adev->crtc_irq);
  1986. if (r)
  1987. return r;
  1988. }
  1989. for (i = 8; i < 20; i += 2) {
  1990. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, i, &adev->pageflip_irq);
  1991. if (r)
  1992. return r;
  1993. }
  1994. /* HPD hotplug */
  1995. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 42, &adev->hpd_irq);
  1996. if (r)
  1997. return r;
  1998. adev->mode_info.mode_config_initialized = true;
  1999. adev->ddev->mode_config.funcs = &amdgpu_mode_funcs;
  2000. adev->ddev->mode_config.async_page_flip = true;
  2001. adev->ddev->mode_config.max_width = 16384;
  2002. adev->ddev->mode_config.max_height = 16384;
  2003. adev->ddev->mode_config.preferred_depth = 24;
  2004. adev->ddev->mode_config.prefer_shadow = 1;
  2005. adev->ddev->mode_config.fb_base = adev->mc.aper_base;
  2006. r = amdgpu_modeset_create_props(adev);
  2007. if (r)
  2008. return r;
  2009. adev->ddev->mode_config.max_width = 16384;
  2010. adev->ddev->mode_config.max_height = 16384;
  2011. /* allocate crtcs */
  2012. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  2013. r = dce_v6_0_crtc_init(adev, i);
  2014. if (r)
  2015. return r;
  2016. }
  2017. ret = amdgpu_atombios_get_connector_info_from_object_table(adev);
  2018. if (ret)
  2019. amdgpu_print_display_setup(adev->ddev);
  2020. else
  2021. return -EINVAL;
  2022. /* setup afmt */
  2023. r = dce_v6_0_afmt_init(adev);
  2024. if (r)
  2025. return r;
  2026. r = dce_v6_0_audio_init(adev);
  2027. if (r)
  2028. return r;
  2029. drm_kms_helper_poll_init(adev->ddev);
  2030. return r;
  2031. }
  2032. static int dce_v6_0_sw_fini(void *handle)
  2033. {
  2034. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2035. kfree(adev->mode_info.bios_hardcoded_edid);
  2036. drm_kms_helper_poll_fini(adev->ddev);
  2037. dce_v6_0_audio_fini(adev);
  2038. dce_v6_0_afmt_fini(adev);
  2039. drm_mode_config_cleanup(adev->ddev);
  2040. adev->mode_info.mode_config_initialized = false;
  2041. return 0;
  2042. }
  2043. static int dce_v6_0_hw_init(void *handle)
  2044. {
  2045. int i;
  2046. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2047. /* init dig PHYs, disp eng pll */
  2048. amdgpu_atombios_encoder_init_dig(adev);
  2049. amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk);
  2050. /* initialize hpd */
  2051. dce_v6_0_hpd_init(adev);
  2052. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  2053. dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  2054. }
  2055. dce_v6_0_pageflip_interrupt_init(adev);
  2056. return 0;
  2057. }
  2058. static int dce_v6_0_hw_fini(void *handle)
  2059. {
  2060. int i;
  2061. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2062. dce_v6_0_hpd_fini(adev);
  2063. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  2064. dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  2065. }
  2066. dce_v6_0_pageflip_interrupt_fini(adev);
  2067. return 0;
  2068. }
  2069. static int dce_v6_0_suspend(void *handle)
  2070. {
  2071. return dce_v6_0_hw_fini(handle);
  2072. }
  2073. static int dce_v6_0_resume(void *handle)
  2074. {
  2075. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2076. int ret;
  2077. ret = dce_v6_0_hw_init(handle);
  2078. /* turn on the BL */
  2079. if (adev->mode_info.bl_encoder) {
  2080. u8 bl_level = amdgpu_display_backlight_get_level(adev,
  2081. adev->mode_info.bl_encoder);
  2082. amdgpu_display_backlight_set_level(adev, adev->mode_info.bl_encoder,
  2083. bl_level);
  2084. }
  2085. return ret;
  2086. }
  2087. static bool dce_v6_0_is_idle(void *handle)
  2088. {
  2089. return true;
  2090. }
  2091. static int dce_v6_0_wait_for_idle(void *handle)
  2092. {
  2093. return 0;
  2094. }
  2095. static int dce_v6_0_soft_reset(void *handle)
  2096. {
  2097. DRM_INFO("xxxx: dce_v6_0_soft_reset --- no impl!!\n");
  2098. return 0;
  2099. }
  2100. static void dce_v6_0_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev,
  2101. int crtc,
  2102. enum amdgpu_interrupt_state state)
  2103. {
  2104. u32 reg_block, interrupt_mask;
  2105. if (crtc >= adev->mode_info.num_crtc) {
  2106. DRM_DEBUG("invalid crtc %d\n", crtc);
  2107. return;
  2108. }
  2109. switch (crtc) {
  2110. case 0:
  2111. reg_block = SI_CRTC0_REGISTER_OFFSET;
  2112. break;
  2113. case 1:
  2114. reg_block = SI_CRTC1_REGISTER_OFFSET;
  2115. break;
  2116. case 2:
  2117. reg_block = SI_CRTC2_REGISTER_OFFSET;
  2118. break;
  2119. case 3:
  2120. reg_block = SI_CRTC3_REGISTER_OFFSET;
  2121. break;
  2122. case 4:
  2123. reg_block = SI_CRTC4_REGISTER_OFFSET;
  2124. break;
  2125. case 5:
  2126. reg_block = SI_CRTC5_REGISTER_OFFSET;
  2127. break;
  2128. default:
  2129. DRM_DEBUG("invalid crtc %d\n", crtc);
  2130. return;
  2131. }
  2132. switch (state) {
  2133. case AMDGPU_IRQ_STATE_DISABLE:
  2134. interrupt_mask = RREG32(mmINT_MASK + reg_block);
  2135. interrupt_mask &= ~VBLANK_INT_MASK;
  2136. WREG32(mmINT_MASK + reg_block, interrupt_mask);
  2137. break;
  2138. case AMDGPU_IRQ_STATE_ENABLE:
  2139. interrupt_mask = RREG32(mmINT_MASK + reg_block);
  2140. interrupt_mask |= VBLANK_INT_MASK;
  2141. WREG32(mmINT_MASK + reg_block, interrupt_mask);
  2142. break;
  2143. default:
  2144. break;
  2145. }
  2146. }
  2147. static void dce_v6_0_set_crtc_vline_interrupt_state(struct amdgpu_device *adev,
  2148. int crtc,
  2149. enum amdgpu_interrupt_state state)
  2150. {
  2151. }
  2152. static int dce_v6_0_set_hpd_interrupt_state(struct amdgpu_device *adev,
  2153. struct amdgpu_irq_src *src,
  2154. unsigned type,
  2155. enum amdgpu_interrupt_state state)
  2156. {
  2157. u32 dc_hpd_int_cntl;
  2158. if (type >= adev->mode_info.num_hpd) {
  2159. DRM_DEBUG("invalid hdp %d\n", type);
  2160. return 0;
  2161. }
  2162. switch (state) {
  2163. case AMDGPU_IRQ_STATE_DISABLE:
  2164. dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
  2165. dc_hpd_int_cntl &= ~DC_HPDx_INT_EN;
  2166. WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
  2167. break;
  2168. case AMDGPU_IRQ_STATE_ENABLE:
  2169. dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
  2170. dc_hpd_int_cntl |= DC_HPDx_INT_EN;
  2171. WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
  2172. break;
  2173. default:
  2174. break;
  2175. }
  2176. return 0;
  2177. }
  2178. static int dce_v6_0_set_crtc_interrupt_state(struct amdgpu_device *adev,
  2179. struct amdgpu_irq_src *src,
  2180. unsigned type,
  2181. enum amdgpu_interrupt_state state)
  2182. {
  2183. switch (type) {
  2184. case AMDGPU_CRTC_IRQ_VBLANK1:
  2185. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 0, state);
  2186. break;
  2187. case AMDGPU_CRTC_IRQ_VBLANK2:
  2188. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 1, state);
  2189. break;
  2190. case AMDGPU_CRTC_IRQ_VBLANK3:
  2191. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 2, state);
  2192. break;
  2193. case AMDGPU_CRTC_IRQ_VBLANK4:
  2194. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 3, state);
  2195. break;
  2196. case AMDGPU_CRTC_IRQ_VBLANK5:
  2197. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 4, state);
  2198. break;
  2199. case AMDGPU_CRTC_IRQ_VBLANK6:
  2200. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 5, state);
  2201. break;
  2202. case AMDGPU_CRTC_IRQ_VLINE1:
  2203. dce_v6_0_set_crtc_vline_interrupt_state(adev, 0, state);
  2204. break;
  2205. case AMDGPU_CRTC_IRQ_VLINE2:
  2206. dce_v6_0_set_crtc_vline_interrupt_state(adev, 1, state);
  2207. break;
  2208. case AMDGPU_CRTC_IRQ_VLINE3:
  2209. dce_v6_0_set_crtc_vline_interrupt_state(adev, 2, state);
  2210. break;
  2211. case AMDGPU_CRTC_IRQ_VLINE4:
  2212. dce_v6_0_set_crtc_vline_interrupt_state(adev, 3, state);
  2213. break;
  2214. case AMDGPU_CRTC_IRQ_VLINE5:
  2215. dce_v6_0_set_crtc_vline_interrupt_state(adev, 4, state);
  2216. break;
  2217. case AMDGPU_CRTC_IRQ_VLINE6:
  2218. dce_v6_0_set_crtc_vline_interrupt_state(adev, 5, state);
  2219. break;
  2220. default:
  2221. break;
  2222. }
  2223. return 0;
  2224. }
  2225. static int dce_v6_0_crtc_irq(struct amdgpu_device *adev,
  2226. struct amdgpu_irq_src *source,
  2227. struct amdgpu_iv_entry *entry)
  2228. {
  2229. unsigned crtc = entry->src_id - 1;
  2230. uint32_t disp_int = RREG32(interrupt_status_offsets[crtc].reg);
  2231. unsigned irq_type = amdgpu_crtc_idx_to_irq_type(adev, crtc);
  2232. switch (entry->src_data[0]) {
  2233. case 0: /* vblank */
  2234. if (disp_int & interrupt_status_offsets[crtc].vblank)
  2235. WREG32(mmVBLANK_STATUS + crtc_offsets[crtc], VBLANK_ACK);
  2236. else
  2237. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  2238. if (amdgpu_irq_enabled(adev, source, irq_type)) {
  2239. drm_handle_vblank(adev->ddev, crtc);
  2240. }
  2241. DRM_DEBUG("IH: D%d vblank\n", crtc + 1);
  2242. break;
  2243. case 1: /* vline */
  2244. if (disp_int & interrupt_status_offsets[crtc].vline)
  2245. WREG32(mmVLINE_STATUS + crtc_offsets[crtc], VLINE_ACK);
  2246. else
  2247. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  2248. DRM_DEBUG("IH: D%d vline\n", crtc + 1);
  2249. break;
  2250. default:
  2251. DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]);
  2252. break;
  2253. }
  2254. return 0;
  2255. }
  2256. static int dce_v6_0_set_pageflip_interrupt_state(struct amdgpu_device *adev,
  2257. struct amdgpu_irq_src *src,
  2258. unsigned type,
  2259. enum amdgpu_interrupt_state state)
  2260. {
  2261. u32 reg;
  2262. if (type >= adev->mode_info.num_crtc) {
  2263. DRM_ERROR("invalid pageflip crtc %d\n", type);
  2264. return -EINVAL;
  2265. }
  2266. reg = RREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type]);
  2267. if (state == AMDGPU_IRQ_STATE_DISABLE)
  2268. WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
  2269. reg & ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
  2270. else
  2271. WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
  2272. reg | GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
  2273. return 0;
  2274. }
  2275. static int dce_v6_0_pageflip_irq(struct amdgpu_device *adev,
  2276. struct amdgpu_irq_src *source,
  2277. struct amdgpu_iv_entry *entry)
  2278. {
  2279. unsigned long flags;
  2280. unsigned crtc_id;
  2281. struct amdgpu_crtc *amdgpu_crtc;
  2282. struct amdgpu_flip_work *works;
  2283. crtc_id = (entry->src_id - 8) >> 1;
  2284. amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
  2285. if (crtc_id >= adev->mode_info.num_crtc) {
  2286. DRM_ERROR("invalid pageflip crtc %d\n", crtc_id);
  2287. return -EINVAL;
  2288. }
  2289. if (RREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id]) &
  2290. GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK)
  2291. WREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id],
  2292. GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK);
  2293. /* IRQ could occur when in initial stage */
  2294. if (amdgpu_crtc == NULL)
  2295. return 0;
  2296. spin_lock_irqsave(&adev->ddev->event_lock, flags);
  2297. works = amdgpu_crtc->pflip_works;
  2298. if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){
  2299. DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
  2300. "AMDGPU_FLIP_SUBMITTED(%d)\n",
  2301. amdgpu_crtc->pflip_status,
  2302. AMDGPU_FLIP_SUBMITTED);
  2303. spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  2304. return 0;
  2305. }
  2306. /* page flip completed. clean up */
  2307. amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
  2308. amdgpu_crtc->pflip_works = NULL;
  2309. /* wakeup usersapce */
  2310. if (works->event)
  2311. drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event);
  2312. spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  2313. drm_crtc_vblank_put(&amdgpu_crtc->base);
  2314. schedule_work(&works->unpin_work);
  2315. return 0;
  2316. }
  2317. static int dce_v6_0_hpd_irq(struct amdgpu_device *adev,
  2318. struct amdgpu_irq_src *source,
  2319. struct amdgpu_iv_entry *entry)
  2320. {
  2321. uint32_t disp_int, mask, tmp;
  2322. unsigned hpd;
  2323. if (entry->src_data[0] >= adev->mode_info.num_hpd) {
  2324. DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]);
  2325. return 0;
  2326. }
  2327. hpd = entry->src_data[0];
  2328. disp_int = RREG32(interrupt_status_offsets[hpd].reg);
  2329. mask = interrupt_status_offsets[hpd].hpd;
  2330. if (disp_int & mask) {
  2331. tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
  2332. tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_ACK_MASK;
  2333. WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
  2334. schedule_work(&adev->hotplug_work);
  2335. DRM_INFO("IH: HPD%d\n", hpd + 1);
  2336. }
  2337. return 0;
  2338. }
  2339. static int dce_v6_0_set_clockgating_state(void *handle,
  2340. enum amd_clockgating_state state)
  2341. {
  2342. return 0;
  2343. }
  2344. static int dce_v6_0_set_powergating_state(void *handle,
  2345. enum amd_powergating_state state)
  2346. {
  2347. return 0;
  2348. }
  2349. static const struct amd_ip_funcs dce_v6_0_ip_funcs = {
  2350. .name = "dce_v6_0",
  2351. .early_init = dce_v6_0_early_init,
  2352. .late_init = NULL,
  2353. .sw_init = dce_v6_0_sw_init,
  2354. .sw_fini = dce_v6_0_sw_fini,
  2355. .hw_init = dce_v6_0_hw_init,
  2356. .hw_fini = dce_v6_0_hw_fini,
  2357. .suspend = dce_v6_0_suspend,
  2358. .resume = dce_v6_0_resume,
  2359. .is_idle = dce_v6_0_is_idle,
  2360. .wait_for_idle = dce_v6_0_wait_for_idle,
  2361. .soft_reset = dce_v6_0_soft_reset,
  2362. .set_clockgating_state = dce_v6_0_set_clockgating_state,
  2363. .set_powergating_state = dce_v6_0_set_powergating_state,
  2364. };
  2365. static void
  2366. dce_v6_0_encoder_mode_set(struct drm_encoder *encoder,
  2367. struct drm_display_mode *mode,
  2368. struct drm_display_mode *adjusted_mode)
  2369. {
  2370. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2371. amdgpu_encoder->pixel_clock = adjusted_mode->clock;
  2372. /* need to call this here rather than in prepare() since we need some crtc info */
  2373. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  2374. /* set scaler clears this on some chips */
  2375. dce_v6_0_set_interleave(encoder->crtc, mode);
  2376. if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
  2377. dce_v6_0_afmt_enable(encoder, true);
  2378. dce_v6_0_afmt_setmode(encoder, adjusted_mode);
  2379. }
  2380. }
  2381. static void dce_v6_0_encoder_prepare(struct drm_encoder *encoder)
  2382. {
  2383. struct amdgpu_device *adev = encoder->dev->dev_private;
  2384. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2385. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  2386. if ((amdgpu_encoder->active_device &
  2387. (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
  2388. (amdgpu_encoder_get_dp_bridge_encoder_id(encoder) !=
  2389. ENCODER_OBJECT_ID_NONE)) {
  2390. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  2391. if (dig) {
  2392. dig->dig_encoder = dce_v6_0_pick_dig_encoder(encoder);
  2393. if (amdgpu_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT)
  2394. dig->afmt = adev->mode_info.afmt[dig->dig_encoder];
  2395. }
  2396. }
  2397. amdgpu_atombios_scratch_regs_lock(adev, true);
  2398. if (connector) {
  2399. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  2400. /* select the clock/data port if it uses a router */
  2401. if (amdgpu_connector->router.cd_valid)
  2402. amdgpu_i2c_router_select_cd_port(amdgpu_connector);
  2403. /* turn eDP panel on for mode set */
  2404. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  2405. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  2406. ATOM_TRANSMITTER_ACTION_POWER_ON);
  2407. }
  2408. /* this is needed for the pll/ss setup to work correctly in some cases */
  2409. amdgpu_atombios_encoder_set_crtc_source(encoder);
  2410. /* set up the FMT blocks */
  2411. dce_v6_0_program_fmt(encoder);
  2412. }
  2413. static void dce_v6_0_encoder_commit(struct drm_encoder *encoder)
  2414. {
  2415. struct drm_device *dev = encoder->dev;
  2416. struct amdgpu_device *adev = dev->dev_private;
  2417. /* need to call this here as we need the crtc set up */
  2418. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
  2419. amdgpu_atombios_scratch_regs_lock(adev, false);
  2420. }
  2421. static void dce_v6_0_encoder_disable(struct drm_encoder *encoder)
  2422. {
  2423. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2424. struct amdgpu_encoder_atom_dig *dig;
  2425. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  2426. if (amdgpu_atombios_encoder_is_digital(encoder)) {
  2427. if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
  2428. dce_v6_0_afmt_enable(encoder, false);
  2429. dig = amdgpu_encoder->enc_priv;
  2430. dig->dig_encoder = -1;
  2431. }
  2432. amdgpu_encoder->active_device = 0;
  2433. }
  2434. /* these are handled by the primary encoders */
  2435. static void dce_v6_0_ext_prepare(struct drm_encoder *encoder)
  2436. {
  2437. }
  2438. static void dce_v6_0_ext_commit(struct drm_encoder *encoder)
  2439. {
  2440. }
  2441. static void
  2442. dce_v6_0_ext_mode_set(struct drm_encoder *encoder,
  2443. struct drm_display_mode *mode,
  2444. struct drm_display_mode *adjusted_mode)
  2445. {
  2446. }
  2447. static void dce_v6_0_ext_disable(struct drm_encoder *encoder)
  2448. {
  2449. }
  2450. static void
  2451. dce_v6_0_ext_dpms(struct drm_encoder *encoder, int mode)
  2452. {
  2453. }
  2454. static bool dce_v6_0_ext_mode_fixup(struct drm_encoder *encoder,
  2455. const struct drm_display_mode *mode,
  2456. struct drm_display_mode *adjusted_mode)
  2457. {
  2458. return true;
  2459. }
  2460. static const struct drm_encoder_helper_funcs dce_v6_0_ext_helper_funcs = {
  2461. .dpms = dce_v6_0_ext_dpms,
  2462. .mode_fixup = dce_v6_0_ext_mode_fixup,
  2463. .prepare = dce_v6_0_ext_prepare,
  2464. .mode_set = dce_v6_0_ext_mode_set,
  2465. .commit = dce_v6_0_ext_commit,
  2466. .disable = dce_v6_0_ext_disable,
  2467. /* no detect for TMDS/LVDS yet */
  2468. };
  2469. static const struct drm_encoder_helper_funcs dce_v6_0_dig_helper_funcs = {
  2470. .dpms = amdgpu_atombios_encoder_dpms,
  2471. .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
  2472. .prepare = dce_v6_0_encoder_prepare,
  2473. .mode_set = dce_v6_0_encoder_mode_set,
  2474. .commit = dce_v6_0_encoder_commit,
  2475. .disable = dce_v6_0_encoder_disable,
  2476. .detect = amdgpu_atombios_encoder_dig_detect,
  2477. };
  2478. static const struct drm_encoder_helper_funcs dce_v6_0_dac_helper_funcs = {
  2479. .dpms = amdgpu_atombios_encoder_dpms,
  2480. .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
  2481. .prepare = dce_v6_0_encoder_prepare,
  2482. .mode_set = dce_v6_0_encoder_mode_set,
  2483. .commit = dce_v6_0_encoder_commit,
  2484. .detect = amdgpu_atombios_encoder_dac_detect,
  2485. };
  2486. static void dce_v6_0_encoder_destroy(struct drm_encoder *encoder)
  2487. {
  2488. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2489. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  2490. amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder);
  2491. kfree(amdgpu_encoder->enc_priv);
  2492. drm_encoder_cleanup(encoder);
  2493. kfree(amdgpu_encoder);
  2494. }
  2495. static const struct drm_encoder_funcs dce_v6_0_encoder_funcs = {
  2496. .destroy = dce_v6_0_encoder_destroy,
  2497. };
  2498. static void dce_v6_0_encoder_add(struct amdgpu_device *adev,
  2499. uint32_t encoder_enum,
  2500. uint32_t supported_device,
  2501. u16 caps)
  2502. {
  2503. struct drm_device *dev = adev->ddev;
  2504. struct drm_encoder *encoder;
  2505. struct amdgpu_encoder *amdgpu_encoder;
  2506. /* see if we already added it */
  2507. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  2508. amdgpu_encoder = to_amdgpu_encoder(encoder);
  2509. if (amdgpu_encoder->encoder_enum == encoder_enum) {
  2510. amdgpu_encoder->devices |= supported_device;
  2511. return;
  2512. }
  2513. }
  2514. /* add a new one */
  2515. amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL);
  2516. if (!amdgpu_encoder)
  2517. return;
  2518. encoder = &amdgpu_encoder->base;
  2519. switch (adev->mode_info.num_crtc) {
  2520. case 1:
  2521. encoder->possible_crtcs = 0x1;
  2522. break;
  2523. case 2:
  2524. default:
  2525. encoder->possible_crtcs = 0x3;
  2526. break;
  2527. case 4:
  2528. encoder->possible_crtcs = 0xf;
  2529. break;
  2530. case 6:
  2531. encoder->possible_crtcs = 0x3f;
  2532. break;
  2533. }
  2534. amdgpu_encoder->enc_priv = NULL;
  2535. amdgpu_encoder->encoder_enum = encoder_enum;
  2536. amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  2537. amdgpu_encoder->devices = supported_device;
  2538. amdgpu_encoder->rmx_type = RMX_OFF;
  2539. amdgpu_encoder->underscan_type = UNDERSCAN_OFF;
  2540. amdgpu_encoder->is_ext_encoder = false;
  2541. amdgpu_encoder->caps = caps;
  2542. switch (amdgpu_encoder->encoder_id) {
  2543. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  2544. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  2545. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2546. DRM_MODE_ENCODER_DAC, NULL);
  2547. drm_encoder_helper_add(encoder, &dce_v6_0_dac_helper_funcs);
  2548. break;
  2549. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  2550. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  2551. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  2552. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  2553. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  2554. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  2555. amdgpu_encoder->rmx_type = RMX_FULL;
  2556. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2557. DRM_MODE_ENCODER_LVDS, NULL);
  2558. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder);
  2559. } else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  2560. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2561. DRM_MODE_ENCODER_DAC, NULL);
  2562. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
  2563. } else {
  2564. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2565. DRM_MODE_ENCODER_TMDS, NULL);
  2566. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
  2567. }
  2568. drm_encoder_helper_add(encoder, &dce_v6_0_dig_helper_funcs);
  2569. break;
  2570. case ENCODER_OBJECT_ID_SI170B:
  2571. case ENCODER_OBJECT_ID_CH7303:
  2572. case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
  2573. case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
  2574. case ENCODER_OBJECT_ID_TITFP513:
  2575. case ENCODER_OBJECT_ID_VT1623:
  2576. case ENCODER_OBJECT_ID_HDMI_SI1930:
  2577. case ENCODER_OBJECT_ID_TRAVIS:
  2578. case ENCODER_OBJECT_ID_NUTMEG:
  2579. /* these are handled by the primary encoders */
  2580. amdgpu_encoder->is_ext_encoder = true;
  2581. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  2582. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2583. DRM_MODE_ENCODER_LVDS, NULL);
  2584. else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
  2585. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2586. DRM_MODE_ENCODER_DAC, NULL);
  2587. else
  2588. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2589. DRM_MODE_ENCODER_TMDS, NULL);
  2590. drm_encoder_helper_add(encoder, &dce_v6_0_ext_helper_funcs);
  2591. break;
  2592. }
  2593. }
  2594. static const struct amdgpu_display_funcs dce_v6_0_display_funcs = {
  2595. .set_vga_render_state = &dce_v6_0_set_vga_render_state,
  2596. .bandwidth_update = &dce_v6_0_bandwidth_update,
  2597. .vblank_get_counter = &dce_v6_0_vblank_get_counter,
  2598. .vblank_wait = &dce_v6_0_vblank_wait,
  2599. .backlight_set_level = &amdgpu_atombios_encoder_set_backlight_level,
  2600. .backlight_get_level = &amdgpu_atombios_encoder_get_backlight_level,
  2601. .hpd_sense = &dce_v6_0_hpd_sense,
  2602. .hpd_set_polarity = &dce_v6_0_hpd_set_polarity,
  2603. .hpd_get_gpio_reg = &dce_v6_0_hpd_get_gpio_reg,
  2604. .page_flip = &dce_v6_0_page_flip,
  2605. .page_flip_get_scanoutpos = &dce_v6_0_crtc_get_scanoutpos,
  2606. .add_encoder = &dce_v6_0_encoder_add,
  2607. .add_connector = &amdgpu_connector_add,
  2608. .stop_mc_access = &dce_v6_0_stop_mc_access,
  2609. .resume_mc_access = &dce_v6_0_resume_mc_access,
  2610. };
  2611. static void dce_v6_0_set_display_funcs(struct amdgpu_device *adev)
  2612. {
  2613. if (adev->mode_info.funcs == NULL)
  2614. adev->mode_info.funcs = &dce_v6_0_display_funcs;
  2615. }
  2616. static const struct amdgpu_irq_src_funcs dce_v6_0_crtc_irq_funcs = {
  2617. .set = dce_v6_0_set_crtc_interrupt_state,
  2618. .process = dce_v6_0_crtc_irq,
  2619. };
  2620. static const struct amdgpu_irq_src_funcs dce_v6_0_pageflip_irq_funcs = {
  2621. .set = dce_v6_0_set_pageflip_interrupt_state,
  2622. .process = dce_v6_0_pageflip_irq,
  2623. };
  2624. static const struct amdgpu_irq_src_funcs dce_v6_0_hpd_irq_funcs = {
  2625. .set = dce_v6_0_set_hpd_interrupt_state,
  2626. .process = dce_v6_0_hpd_irq,
  2627. };
  2628. static void dce_v6_0_set_irq_funcs(struct amdgpu_device *adev)
  2629. {
  2630. adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_LAST;
  2631. adev->crtc_irq.funcs = &dce_v6_0_crtc_irq_funcs;
  2632. adev->pageflip_irq.num_types = AMDGPU_PAGEFLIP_IRQ_LAST;
  2633. adev->pageflip_irq.funcs = &dce_v6_0_pageflip_irq_funcs;
  2634. adev->hpd_irq.num_types = AMDGPU_HPD_LAST;
  2635. adev->hpd_irq.funcs = &dce_v6_0_hpd_irq_funcs;
  2636. }
  2637. const struct amdgpu_ip_block_version dce_v6_0_ip_block =
  2638. {
  2639. .type = AMD_IP_BLOCK_TYPE_DCE,
  2640. .major = 6,
  2641. .minor = 0,
  2642. .rev = 0,
  2643. .funcs = &dce_v6_0_ip_funcs,
  2644. };
  2645. const struct amdgpu_ip_block_version dce_v6_4_ip_block =
  2646. {
  2647. .type = AMD_IP_BLOCK_TYPE_DCE,
  2648. .major = 6,
  2649. .minor = 4,
  2650. .rev = 0,
  2651. .funcs = &dce_v6_0_ip_funcs,
  2652. };