dce_v6_0.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096
  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. b.full = dfixed_const(mc_latency + 512);
  762. c.full = dfixed_const(wm->disp_clk);
  763. b.full = dfixed_div(b, c);
  764. c.full = dfixed_const(dmif_size);
  765. b.full = dfixed_div(c, b);
  766. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  767. b.full = dfixed_const(1000);
  768. c.full = dfixed_const(wm->disp_clk);
  769. b.full = dfixed_div(c, b);
  770. c.full = dfixed_const(wm->bytes_per_pixel);
  771. b.full = dfixed_mul(b, c);
  772. lb_fill_bw = min(tmp, dfixed_trunc(b));
  773. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  774. b.full = dfixed_const(1000);
  775. c.full = dfixed_const(lb_fill_bw);
  776. b.full = dfixed_div(c, b);
  777. a.full = dfixed_div(a, b);
  778. line_fill_time = dfixed_trunc(a);
  779. if (line_fill_time < wm->active_time)
  780. return latency;
  781. else
  782. return latency + (line_fill_time - wm->active_time);
  783. }
  784. /**
  785. * dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display - check
  786. * average and available dram bandwidth
  787. *
  788. * @wm: watermark calculation data
  789. *
  790. * Check if the display average bandwidth fits in the display
  791. * dram bandwidth (CIK).
  792. * Used for display watermark bandwidth calculations
  793. * Returns true if the display fits, false if not.
  794. */
  795. static bool dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  796. {
  797. if (dce_v6_0_average_bandwidth(wm) <=
  798. (dce_v6_0_dram_bandwidth_for_display(wm) / wm->num_heads))
  799. return true;
  800. else
  801. return false;
  802. }
  803. /**
  804. * dce_v6_0_average_bandwidth_vs_available_bandwidth - check
  805. * average and available bandwidth
  806. *
  807. * @wm: watermark calculation data
  808. *
  809. * Check if the display average bandwidth fits in the display
  810. * available bandwidth (CIK).
  811. * Used for display watermark bandwidth calculations
  812. * Returns true if the display fits, false if not.
  813. */
  814. static bool dce_v6_0_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
  815. {
  816. if (dce_v6_0_average_bandwidth(wm) <=
  817. (dce_v6_0_available_bandwidth(wm) / wm->num_heads))
  818. return true;
  819. else
  820. return false;
  821. }
  822. /**
  823. * dce_v6_0_check_latency_hiding - check latency hiding
  824. *
  825. * @wm: watermark calculation data
  826. *
  827. * Check latency hiding (CIK).
  828. * Used for display watermark bandwidth calculations
  829. * Returns true if the display fits, false if not.
  830. */
  831. static bool dce_v6_0_check_latency_hiding(struct dce6_wm_params *wm)
  832. {
  833. u32 lb_partitions = wm->lb_size / wm->src_width;
  834. u32 line_time = wm->active_time + wm->blank_time;
  835. u32 latency_tolerant_lines;
  836. u32 latency_hiding;
  837. fixed20_12 a;
  838. a.full = dfixed_const(1);
  839. if (wm->vsc.full > a.full)
  840. latency_tolerant_lines = 1;
  841. else {
  842. if (lb_partitions <= (wm->vtaps + 1))
  843. latency_tolerant_lines = 1;
  844. else
  845. latency_tolerant_lines = 2;
  846. }
  847. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  848. if (dce_v6_0_latency_watermark(wm) <= latency_hiding)
  849. return true;
  850. else
  851. return false;
  852. }
  853. /**
  854. * dce_v6_0_program_watermarks - program display watermarks
  855. *
  856. * @adev: amdgpu_device pointer
  857. * @amdgpu_crtc: the selected display controller
  858. * @lb_size: line buffer size
  859. * @num_heads: number of display controllers in use
  860. *
  861. * Calculate and program the display watermarks for the
  862. * selected display controller (CIK).
  863. */
  864. static void dce_v6_0_program_watermarks(struct amdgpu_device *adev,
  865. struct amdgpu_crtc *amdgpu_crtc,
  866. u32 lb_size, u32 num_heads)
  867. {
  868. struct drm_display_mode *mode = &amdgpu_crtc->base.mode;
  869. struct dce6_wm_params wm_low, wm_high;
  870. u32 dram_channels;
  871. u32 pixel_period;
  872. u32 line_time = 0;
  873. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  874. u32 priority_a_mark = 0, priority_b_mark = 0;
  875. u32 priority_a_cnt = PRIORITY_OFF;
  876. u32 priority_b_cnt = PRIORITY_OFF;
  877. u32 tmp, arb_control3;
  878. fixed20_12 a, b, c;
  879. if (amdgpu_crtc->base.enabled && num_heads && mode) {
  880. pixel_period = 1000000 / (u32)mode->clock;
  881. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  882. priority_a_cnt = 0;
  883. priority_b_cnt = 0;
  884. dram_channels = si_get_number_of_dram_channels(adev);
  885. /* watermark for high clocks */
  886. if (adev->pm.dpm_enabled) {
  887. wm_high.yclk =
  888. amdgpu_dpm_get_mclk(adev, false) * 10;
  889. wm_high.sclk =
  890. amdgpu_dpm_get_sclk(adev, false) * 10;
  891. } else {
  892. wm_high.yclk = adev->pm.current_mclk * 10;
  893. wm_high.sclk = adev->pm.current_sclk * 10;
  894. }
  895. wm_high.disp_clk = mode->clock;
  896. wm_high.src_width = mode->crtc_hdisplay;
  897. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  898. wm_high.blank_time = line_time - wm_high.active_time;
  899. wm_high.interlaced = false;
  900. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  901. wm_high.interlaced = true;
  902. wm_high.vsc = amdgpu_crtc->vsc;
  903. wm_high.vtaps = 1;
  904. if (amdgpu_crtc->rmx_type != RMX_OFF)
  905. wm_high.vtaps = 2;
  906. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  907. wm_high.lb_size = lb_size;
  908. wm_high.dram_channels = dram_channels;
  909. wm_high.num_heads = num_heads;
  910. if (adev->pm.dpm_enabled) {
  911. /* watermark for low clocks */
  912. wm_low.yclk =
  913. amdgpu_dpm_get_mclk(adev, true) * 10;
  914. wm_low.sclk =
  915. amdgpu_dpm_get_sclk(adev, true) * 10;
  916. } else {
  917. wm_low.yclk = adev->pm.current_mclk * 10;
  918. wm_low.sclk = adev->pm.current_sclk * 10;
  919. }
  920. wm_low.disp_clk = mode->clock;
  921. wm_low.src_width = mode->crtc_hdisplay;
  922. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  923. wm_low.blank_time = line_time - wm_low.active_time;
  924. wm_low.interlaced = false;
  925. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  926. wm_low.interlaced = true;
  927. wm_low.vsc = amdgpu_crtc->vsc;
  928. wm_low.vtaps = 1;
  929. if (amdgpu_crtc->rmx_type != RMX_OFF)
  930. wm_low.vtaps = 2;
  931. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  932. wm_low.lb_size = lb_size;
  933. wm_low.dram_channels = dram_channels;
  934. wm_low.num_heads = num_heads;
  935. /* set for high clocks */
  936. latency_watermark_a = min(dce_v6_0_latency_watermark(&wm_high), (u32)65535);
  937. /* set for low clocks */
  938. latency_watermark_b = min(dce_v6_0_latency_watermark(&wm_low), (u32)65535);
  939. /* possibly force display priority to high */
  940. /* should really do this at mode validation time... */
  941. if (!dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  942. !dce_v6_0_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  943. !dce_v6_0_check_latency_hiding(&wm_high) ||
  944. (adev->mode_info.disp_priority == 2)) {
  945. DRM_DEBUG_KMS("force priority to high\n");
  946. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  947. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  948. }
  949. if (!dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  950. !dce_v6_0_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  951. !dce_v6_0_check_latency_hiding(&wm_low) ||
  952. (adev->mode_info.disp_priority == 2)) {
  953. DRM_DEBUG_KMS("force priority to high\n");
  954. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  955. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  956. }
  957. a.full = dfixed_const(1000);
  958. b.full = dfixed_const(mode->clock);
  959. b.full = dfixed_div(b, a);
  960. c.full = dfixed_const(latency_watermark_a);
  961. c.full = dfixed_mul(c, b);
  962. c.full = dfixed_mul(c, amdgpu_crtc->hsc);
  963. c.full = dfixed_div(c, a);
  964. a.full = dfixed_const(16);
  965. c.full = dfixed_div(c, a);
  966. priority_a_mark = dfixed_trunc(c);
  967. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  968. a.full = dfixed_const(1000);
  969. b.full = dfixed_const(mode->clock);
  970. b.full = dfixed_div(b, a);
  971. c.full = dfixed_const(latency_watermark_b);
  972. c.full = dfixed_mul(c, b);
  973. c.full = dfixed_mul(c, amdgpu_crtc->hsc);
  974. c.full = dfixed_div(c, a);
  975. a.full = dfixed_const(16);
  976. c.full = dfixed_div(c, a);
  977. priority_b_mark = dfixed_trunc(c);
  978. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  979. }
  980. /* select wm A */
  981. arb_control3 = RREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset);
  982. tmp = arb_control3;
  983. tmp &= ~LATENCY_WATERMARK_MASK(3);
  984. tmp |= LATENCY_WATERMARK_MASK(1);
  985. WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, tmp);
  986. WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
  987. ((latency_watermark_a << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
  988. (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
  989. /* select wm B */
  990. tmp = RREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset);
  991. tmp &= ~LATENCY_WATERMARK_MASK(3);
  992. tmp |= LATENCY_WATERMARK_MASK(2);
  993. WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, tmp);
  994. WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
  995. ((latency_watermark_b << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
  996. (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
  997. /* restore original selection */
  998. WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, arb_control3);
  999. /* write the priority marks */
  1000. WREG32(mmPRIORITY_A_CNT + amdgpu_crtc->crtc_offset, priority_a_cnt);
  1001. WREG32(mmPRIORITY_B_CNT + amdgpu_crtc->crtc_offset, priority_b_cnt);
  1002. /* save values for DPM */
  1003. amdgpu_crtc->line_time = line_time;
  1004. amdgpu_crtc->wm_high = latency_watermark_a;
  1005. }
  1006. /* watermark setup */
  1007. static u32 dce_v6_0_line_buffer_adjust(struct amdgpu_device *adev,
  1008. struct amdgpu_crtc *amdgpu_crtc,
  1009. struct drm_display_mode *mode,
  1010. struct drm_display_mode *other_mode)
  1011. {
  1012. u32 tmp, buffer_alloc, i;
  1013. u32 pipe_offset = amdgpu_crtc->crtc_id * 0x8;
  1014. /*
  1015. * Line Buffer Setup
  1016. * There are 3 line buffers, each one shared by 2 display controllers.
  1017. * mmDC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1018. * the display controllers. The paritioning is done via one of four
  1019. * preset allocations specified in bits 21:20:
  1020. * 0 - half lb
  1021. * 2 - whole lb, other crtc must be disabled
  1022. */
  1023. /* this can get tricky if we have two large displays on a paired group
  1024. * of crtcs. Ideally for multiple large displays we'd assign them to
  1025. * non-linked crtcs for maximum line buffer allocation.
  1026. */
  1027. if (amdgpu_crtc->base.enabled && mode) {
  1028. if (other_mode) {
  1029. tmp = 0; /* 1/2 */
  1030. buffer_alloc = 1;
  1031. } else {
  1032. tmp = 2; /* whole */
  1033. buffer_alloc = 2;
  1034. }
  1035. } else {
  1036. tmp = 0;
  1037. buffer_alloc = 0;
  1038. }
  1039. WREG32(mmDC_LB_MEMORY_SPLIT + amdgpu_crtc->crtc_offset,
  1040. DC_LB_MEMORY_CONFIG(tmp));
  1041. WREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1042. (buffer_alloc << PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATED__SHIFT));
  1043. for (i = 0; i < adev->usec_timeout; i++) {
  1044. if (RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1045. PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATION_COMPLETED_MASK)
  1046. break;
  1047. udelay(1);
  1048. }
  1049. if (amdgpu_crtc->base.enabled && mode) {
  1050. switch (tmp) {
  1051. case 0:
  1052. default:
  1053. return 4096 * 2;
  1054. case 2:
  1055. return 8192 * 2;
  1056. }
  1057. }
  1058. /* controller not enabled, so no lb used */
  1059. return 0;
  1060. }
  1061. /**
  1062. *
  1063. * dce_v6_0_bandwidth_update - program display watermarks
  1064. *
  1065. * @adev: amdgpu_device pointer
  1066. *
  1067. * Calculate and program the display watermarks and line
  1068. * buffer allocation (CIK).
  1069. */
  1070. static void dce_v6_0_bandwidth_update(struct amdgpu_device *adev)
  1071. {
  1072. struct drm_display_mode *mode0 = NULL;
  1073. struct drm_display_mode *mode1 = NULL;
  1074. u32 num_heads = 0, lb_size;
  1075. int i;
  1076. if (!adev->mode_info.mode_config_initialized)
  1077. return;
  1078. amdgpu_update_display_priority(adev);
  1079. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1080. if (adev->mode_info.crtcs[i]->base.enabled)
  1081. num_heads++;
  1082. }
  1083. for (i = 0; i < adev->mode_info.num_crtc; i += 2) {
  1084. mode0 = &adev->mode_info.crtcs[i]->base.mode;
  1085. mode1 = &adev->mode_info.crtcs[i+1]->base.mode;
  1086. lb_size = dce_v6_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i], mode0, mode1);
  1087. dce_v6_0_program_watermarks(adev, adev->mode_info.crtcs[i], lb_size, num_heads);
  1088. lb_size = dce_v6_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i+1], mode1, mode0);
  1089. dce_v6_0_program_watermarks(adev, adev->mode_info.crtcs[i+1], lb_size, num_heads);
  1090. }
  1091. }
  1092. /*
  1093. static void dce_v6_0_audio_get_connected_pins(struct amdgpu_device *adev)
  1094. {
  1095. int i;
  1096. u32 offset, tmp;
  1097. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1098. offset = adev->mode_info.audio.pin[i].offset;
  1099. tmp = RREG32_AUDIO_ENDPT(offset,
  1100. AZ_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT);
  1101. if (((tmp & PORT_CONNECTIVITY_MASK) >> PORT_CONNECTIVITY_SHIFT) == 1)
  1102. adev->mode_info.audio.pin[i].connected = false;
  1103. else
  1104. adev->mode_info.audio.pin[i].connected = true;
  1105. }
  1106. }
  1107. static struct amdgpu_audio_pin *dce_v6_0_audio_get_pin(struct amdgpu_device *adev)
  1108. {
  1109. int i;
  1110. dce_v6_0_audio_get_connected_pins(adev);
  1111. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1112. if (adev->mode_info.audio.pin[i].connected)
  1113. return &adev->mode_info.audio.pin[i];
  1114. }
  1115. DRM_ERROR("No connected audio pins found!\n");
  1116. return NULL;
  1117. }
  1118. static void dce_v6_0_afmt_audio_select_pin(struct drm_encoder *encoder)
  1119. {
  1120. struct amdgpu_device *adev = encoder->dev->dev_private;
  1121. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1122. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1123. u32 offset;
  1124. if (!dig || !dig->afmt || !dig->afmt->pin)
  1125. return;
  1126. offset = dig->afmt->offset;
  1127. WREG32(AFMT_AUDIO_SRC_CONTROL + offset,
  1128. AFMT_AUDIO_SRC_SELECT(dig->afmt->pin->id));
  1129. }
  1130. static void dce_v6_0_audio_write_latency_fields(struct drm_encoder *encoder,
  1131. struct drm_display_mode *mode)
  1132. {
  1133. DRM_INFO("xxxx: dce_v6_0_audio_write_latency_fields---no imp!!!!!\n");
  1134. }
  1135. static void dce_v6_0_audio_write_speaker_allocation(struct drm_encoder *encoder)
  1136. {
  1137. DRM_INFO("xxxx: dce_v6_0_audio_write_speaker_allocation---no imp!!!!!\n");
  1138. }
  1139. static void dce_v6_0_audio_write_sad_regs(struct drm_encoder *encoder)
  1140. {
  1141. DRM_INFO("xxxx: dce_v6_0_audio_write_sad_regs---no imp!!!!!\n");
  1142. }
  1143. */
  1144. static void dce_v6_0_audio_enable(struct amdgpu_device *adev,
  1145. struct amdgpu_audio_pin *pin,
  1146. bool enable)
  1147. {
  1148. DRM_INFO("xxxx: dce_v6_0_audio_enable---no imp!!!!!\n");
  1149. }
  1150. static const u32 pin_offsets[7] =
  1151. {
  1152. (0x1780 - 0x1780),
  1153. (0x1786 - 0x1780),
  1154. (0x178c - 0x1780),
  1155. (0x1792 - 0x1780),
  1156. (0x1798 - 0x1780),
  1157. (0x179d - 0x1780),
  1158. (0x17a4 - 0x1780),
  1159. };
  1160. static int dce_v6_0_audio_init(struct amdgpu_device *adev)
  1161. {
  1162. return 0;
  1163. }
  1164. static void dce_v6_0_audio_fini(struct amdgpu_device *adev)
  1165. {
  1166. }
  1167. /*
  1168. static void dce_v6_0_afmt_update_ACR(struct drm_encoder *encoder, uint32_t clock)
  1169. {
  1170. DRM_INFO("xxxx: dce_v6_0_afmt_update_ACR---no imp!!!!!\n");
  1171. }
  1172. */
  1173. /*
  1174. * build a HDMI Video Info Frame
  1175. */
  1176. /*
  1177. static void dce_v6_0_afmt_update_avi_infoframe(struct drm_encoder *encoder,
  1178. void *buffer, size_t size)
  1179. {
  1180. DRM_INFO("xxxx: dce_v6_0_afmt_update_avi_infoframe---no imp!!!!!\n");
  1181. }
  1182. static void dce_v6_0_audio_set_dto(struct drm_encoder *encoder, u32 clock)
  1183. {
  1184. DRM_INFO("xxxx: dce_v6_0_audio_set_dto---no imp!!!!!\n");
  1185. }
  1186. */
  1187. /*
  1188. * update the info frames with the data from the current display mode
  1189. */
  1190. static void dce_v6_0_afmt_setmode(struct drm_encoder *encoder,
  1191. struct drm_display_mode *mode)
  1192. {
  1193. DRM_INFO("xxxx: dce_v6_0_afmt_setmode ----no impl !!!!!!!!\n");
  1194. }
  1195. static void dce_v6_0_afmt_enable(struct drm_encoder *encoder, bool enable)
  1196. {
  1197. struct drm_device *dev = encoder->dev;
  1198. struct amdgpu_device *adev = dev->dev_private;
  1199. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1200. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1201. if (!dig || !dig->afmt)
  1202. return;
  1203. /* Silent, r600_hdmi_enable will raise WARN for us */
  1204. if (enable && dig->afmt->enabled)
  1205. return;
  1206. if (!enable && !dig->afmt->enabled)
  1207. return;
  1208. if (!enable && dig->afmt->pin) {
  1209. dce_v6_0_audio_enable(adev, dig->afmt->pin, false);
  1210. dig->afmt->pin = NULL;
  1211. }
  1212. dig->afmt->enabled = enable;
  1213. DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
  1214. enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id);
  1215. }
  1216. static int dce_v6_0_afmt_init(struct amdgpu_device *adev)
  1217. {
  1218. int i, j;
  1219. for (i = 0; i < adev->mode_info.num_dig; i++)
  1220. adev->mode_info.afmt[i] = NULL;
  1221. /* DCE6 has audio blocks tied to DIG encoders */
  1222. for (i = 0; i < adev->mode_info.num_dig; i++) {
  1223. adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL);
  1224. if (adev->mode_info.afmt[i]) {
  1225. adev->mode_info.afmt[i]->offset = dig_offsets[i];
  1226. adev->mode_info.afmt[i]->id = i;
  1227. } else {
  1228. for (j = 0; j < i; j++) {
  1229. kfree(adev->mode_info.afmt[j]);
  1230. adev->mode_info.afmt[j] = NULL;
  1231. }
  1232. DRM_ERROR("Out of memory allocating afmt table\n");
  1233. return -ENOMEM;
  1234. }
  1235. }
  1236. return 0;
  1237. }
  1238. static void dce_v6_0_afmt_fini(struct amdgpu_device *adev)
  1239. {
  1240. int i;
  1241. for (i = 0; i < adev->mode_info.num_dig; i++) {
  1242. kfree(adev->mode_info.afmt[i]);
  1243. adev->mode_info.afmt[i] = NULL;
  1244. }
  1245. }
  1246. static const u32 vga_control_regs[6] =
  1247. {
  1248. mmD1VGA_CONTROL,
  1249. mmD2VGA_CONTROL,
  1250. mmD3VGA_CONTROL,
  1251. mmD4VGA_CONTROL,
  1252. mmD5VGA_CONTROL,
  1253. mmD6VGA_CONTROL,
  1254. };
  1255. static void dce_v6_0_vga_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. u32 vga_control;
  1261. vga_control = RREG32(vga_control_regs[amdgpu_crtc->crtc_id]) & ~1;
  1262. WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control | (enable ? 1 : 0));
  1263. }
  1264. static void dce_v6_0_grph_enable(struct drm_crtc *crtc, bool enable)
  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. WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, enable ? 1 : 0);
  1270. }
  1271. static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
  1272. struct drm_framebuffer *fb,
  1273. int x, int y, int atomic)
  1274. {
  1275. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1276. struct drm_device *dev = crtc->dev;
  1277. struct amdgpu_device *adev = dev->dev_private;
  1278. struct amdgpu_framebuffer *amdgpu_fb;
  1279. struct drm_framebuffer *target_fb;
  1280. struct drm_gem_object *obj;
  1281. struct amdgpu_bo *abo;
  1282. uint64_t fb_location, tiling_flags;
  1283. uint32_t fb_format, fb_pitch_pixels, pipe_config;
  1284. u32 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_NONE);
  1285. u32 viewport_w, viewport_h;
  1286. int r;
  1287. bool bypass_lut = false;
  1288. struct drm_format_name_buf format_name;
  1289. /* no fb bound */
  1290. if (!atomic && !crtc->primary->fb) {
  1291. DRM_DEBUG_KMS("No FB bound\n");
  1292. return 0;
  1293. }
  1294. if (atomic) {
  1295. amdgpu_fb = to_amdgpu_framebuffer(fb);
  1296. target_fb = fb;
  1297. } else {
  1298. amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
  1299. target_fb = crtc->primary->fb;
  1300. }
  1301. /* If atomic, assume fb object is pinned & idle & fenced and
  1302. * just update base pointers
  1303. */
  1304. obj = amdgpu_fb->obj;
  1305. abo = gem_to_amdgpu_bo(obj);
  1306. r = amdgpu_bo_reserve(abo, false);
  1307. if (unlikely(r != 0))
  1308. return r;
  1309. if (atomic) {
  1310. fb_location = amdgpu_bo_gpu_offset(abo);
  1311. } else {
  1312. r = amdgpu_bo_pin(abo, AMDGPU_GEM_DOMAIN_VRAM, &fb_location);
  1313. if (unlikely(r != 0)) {
  1314. amdgpu_bo_unreserve(abo);
  1315. return -EINVAL;
  1316. }
  1317. }
  1318. amdgpu_bo_get_tiling_flags(abo, &tiling_flags);
  1319. amdgpu_bo_unreserve(abo);
  1320. switch (target_fb->format->format) {
  1321. case DRM_FORMAT_C8:
  1322. fb_format = (GRPH_DEPTH(GRPH_DEPTH_8BPP) |
  1323. GRPH_FORMAT(GRPH_FORMAT_INDEXED));
  1324. break;
  1325. case DRM_FORMAT_XRGB4444:
  1326. case DRM_FORMAT_ARGB4444:
  1327. fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
  1328. GRPH_FORMAT(GRPH_FORMAT_ARGB4444));
  1329. #ifdef __BIG_ENDIAN
  1330. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
  1331. #endif
  1332. break;
  1333. case DRM_FORMAT_XRGB1555:
  1334. case DRM_FORMAT_ARGB1555:
  1335. fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
  1336. GRPH_FORMAT(GRPH_FORMAT_ARGB1555));
  1337. #ifdef __BIG_ENDIAN
  1338. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
  1339. #endif
  1340. break;
  1341. case DRM_FORMAT_BGRX5551:
  1342. case DRM_FORMAT_BGRA5551:
  1343. fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
  1344. GRPH_FORMAT(GRPH_FORMAT_BGRA5551));
  1345. #ifdef __BIG_ENDIAN
  1346. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
  1347. #endif
  1348. break;
  1349. case DRM_FORMAT_RGB565:
  1350. fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
  1351. GRPH_FORMAT(GRPH_FORMAT_ARGB565));
  1352. #ifdef __BIG_ENDIAN
  1353. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
  1354. #endif
  1355. break;
  1356. case DRM_FORMAT_XRGB8888:
  1357. case DRM_FORMAT_ARGB8888:
  1358. fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
  1359. GRPH_FORMAT(GRPH_FORMAT_ARGB8888));
  1360. #ifdef __BIG_ENDIAN
  1361. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
  1362. #endif
  1363. break;
  1364. case DRM_FORMAT_XRGB2101010:
  1365. case DRM_FORMAT_ARGB2101010:
  1366. fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
  1367. GRPH_FORMAT(GRPH_FORMAT_ARGB2101010));
  1368. #ifdef __BIG_ENDIAN
  1369. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
  1370. #endif
  1371. /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
  1372. bypass_lut = true;
  1373. break;
  1374. case DRM_FORMAT_BGRX1010102:
  1375. case DRM_FORMAT_BGRA1010102:
  1376. fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
  1377. GRPH_FORMAT(GRPH_FORMAT_BGRA1010102));
  1378. #ifdef __BIG_ENDIAN
  1379. fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
  1380. #endif
  1381. /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
  1382. bypass_lut = true;
  1383. break;
  1384. default:
  1385. DRM_ERROR("Unsupported screen format %s\n",
  1386. drm_get_format_name(target_fb->format->format, &format_name));
  1387. return -EINVAL;
  1388. }
  1389. if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
  1390. unsigned bankw, bankh, mtaspect, tile_split, num_banks;
  1391. bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
  1392. bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
  1393. mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
  1394. tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
  1395. num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
  1396. fb_format |= GRPH_NUM_BANKS(num_banks);
  1397. fb_format |= GRPH_ARRAY_MODE(GRPH_ARRAY_2D_TILED_THIN1);
  1398. fb_format |= GRPH_TILE_SPLIT(tile_split);
  1399. fb_format |= GRPH_BANK_WIDTH(bankw);
  1400. fb_format |= GRPH_BANK_HEIGHT(bankh);
  1401. fb_format |= GRPH_MACRO_TILE_ASPECT(mtaspect);
  1402. } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
  1403. fb_format |= GRPH_ARRAY_MODE(GRPH_ARRAY_1D_TILED_THIN1);
  1404. }
  1405. pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
  1406. fb_format |= GRPH_PIPE_CONFIG(pipe_config);
  1407. dce_v6_0_vga_enable(crtc, false);
  1408. /* Make sure surface address is updated at vertical blank rather than
  1409. * horizontal blank
  1410. */
  1411. WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, 0);
  1412. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1413. upper_32_bits(fb_location));
  1414. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1415. upper_32_bits(fb_location));
  1416. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1417. (u32)fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
  1418. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1419. (u32) fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
  1420. WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format);
  1421. WREG32(mmGRPH_SWAP_CNTL + amdgpu_crtc->crtc_offset, fb_swap);
  1422. /*
  1423. * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
  1424. * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
  1425. * retain the full precision throughout the pipeline.
  1426. */
  1427. WREG32_P(mmGRPH_LUT_10BIT_BYPASS + amdgpu_crtc->crtc_offset,
  1428. (bypass_lut ? GRPH_LUT_10BIT_BYPASS__GRPH_LUT_10BIT_BYPASS_EN_MASK : 0),
  1429. ~GRPH_LUT_10BIT_BYPASS__GRPH_LUT_10BIT_BYPASS_EN_MASK);
  1430. if (bypass_lut)
  1431. DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
  1432. WREG32(mmGRPH_SURFACE_OFFSET_X + amdgpu_crtc->crtc_offset, 0);
  1433. WREG32(mmGRPH_SURFACE_OFFSET_Y + amdgpu_crtc->crtc_offset, 0);
  1434. WREG32(mmGRPH_X_START + amdgpu_crtc->crtc_offset, 0);
  1435. WREG32(mmGRPH_Y_START + amdgpu_crtc->crtc_offset, 0);
  1436. WREG32(mmGRPH_X_END + amdgpu_crtc->crtc_offset, target_fb->width);
  1437. WREG32(mmGRPH_Y_END + amdgpu_crtc->crtc_offset, target_fb->height);
  1438. fb_pitch_pixels = target_fb->pitches[0] / target_fb->format->cpp[0];
  1439. WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, fb_pitch_pixels);
  1440. dce_v6_0_grph_enable(crtc, true);
  1441. WREG32(mmDESKTOP_HEIGHT + amdgpu_crtc->crtc_offset,
  1442. target_fb->height);
  1443. x &= ~3;
  1444. y &= ~1;
  1445. WREG32(mmVIEWPORT_START + amdgpu_crtc->crtc_offset,
  1446. (x << 16) | y);
  1447. viewport_w = crtc->mode.hdisplay;
  1448. viewport_h = (crtc->mode.vdisplay + 1) & ~1;
  1449. WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
  1450. (viewport_w << 16) | viewport_h);
  1451. /* set pageflip to happen anywhere in vblank interval */
  1452. WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
  1453. if (!atomic && fb && fb != crtc->primary->fb) {
  1454. amdgpu_fb = to_amdgpu_framebuffer(fb);
  1455. abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
  1456. r = amdgpu_bo_reserve(abo, false);
  1457. if (unlikely(r != 0))
  1458. return r;
  1459. amdgpu_bo_unpin(abo);
  1460. amdgpu_bo_unreserve(abo);
  1461. }
  1462. /* Bytes per pixel may have changed */
  1463. dce_v6_0_bandwidth_update(adev);
  1464. return 0;
  1465. }
  1466. static void dce_v6_0_set_interleave(struct drm_crtc *crtc,
  1467. struct drm_display_mode *mode)
  1468. {
  1469. struct drm_device *dev = crtc->dev;
  1470. struct amdgpu_device *adev = dev->dev_private;
  1471. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1472. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1473. WREG32(mmDATA_FORMAT + amdgpu_crtc->crtc_offset,
  1474. INTERLEAVE_EN);
  1475. else
  1476. WREG32(mmDATA_FORMAT + amdgpu_crtc->crtc_offset, 0);
  1477. }
  1478. static void dce_v6_0_crtc_load_lut(struct drm_crtc *crtc)
  1479. {
  1480. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1481. struct drm_device *dev = crtc->dev;
  1482. struct amdgpu_device *adev = dev->dev_private;
  1483. int i;
  1484. DRM_DEBUG_KMS("%d\n", amdgpu_crtc->crtc_id);
  1485. WREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
  1486. ((0 << INPUT_CSC_CONTROL__INPUT_CSC_GRPH_MODE__SHIFT) |
  1487. (0 << INPUT_CSC_CONTROL__INPUT_CSC_OVL_MODE__SHIFT)));
  1488. WREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset,
  1489. PRESCALE_GRPH_CONTROL__GRPH_PRESCALE_BYPASS_MASK);
  1490. WREG32(mmPRESCALE_OVL_CONTROL + amdgpu_crtc->crtc_offset,
  1491. PRESCALE_OVL_CONTROL__OVL_PRESCALE_BYPASS_MASK);
  1492. WREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1493. ((0 << INPUT_GAMMA_CONTROL__GRPH_INPUT_GAMMA_MODE__SHIFT) |
  1494. (0 << INPUT_GAMMA_CONTROL__OVL_INPUT_GAMMA_MODE__SHIFT)));
  1495. WREG32(mmDC_LUT_CONTROL + amdgpu_crtc->crtc_offset, 0);
  1496. WREG32(mmDC_LUT_BLACK_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0);
  1497. WREG32(mmDC_LUT_BLACK_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0);
  1498. WREG32(mmDC_LUT_BLACK_OFFSET_RED + amdgpu_crtc->crtc_offset, 0);
  1499. WREG32(mmDC_LUT_WHITE_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0xffff);
  1500. WREG32(mmDC_LUT_WHITE_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0xffff);
  1501. WREG32(mmDC_LUT_WHITE_OFFSET_RED + amdgpu_crtc->crtc_offset, 0xffff);
  1502. WREG32(mmDC_LUT_RW_MODE + amdgpu_crtc->crtc_offset, 0);
  1503. WREG32(mmDC_LUT_WRITE_EN_MASK + amdgpu_crtc->crtc_offset, 0x00000007);
  1504. WREG32(mmDC_LUT_RW_INDEX + amdgpu_crtc->crtc_offset, 0);
  1505. for (i = 0; i < 256; i++) {
  1506. WREG32(mmDC_LUT_30_COLOR + amdgpu_crtc->crtc_offset,
  1507. (amdgpu_crtc->lut_r[i] << 20) |
  1508. (amdgpu_crtc->lut_g[i] << 10) |
  1509. (amdgpu_crtc->lut_b[i] << 0));
  1510. }
  1511. WREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1512. ((0 << DEGAMMA_CONTROL__GRPH_DEGAMMA_MODE__SHIFT) |
  1513. (0 << DEGAMMA_CONTROL__OVL_DEGAMMA_MODE__SHIFT) |
  1514. ICON_DEGAMMA_MODE(0) |
  1515. (0 << DEGAMMA_CONTROL__CURSOR_DEGAMMA_MODE__SHIFT)));
  1516. WREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset,
  1517. ((0 << GAMUT_REMAP_CONTROL__GRPH_GAMUT_REMAP_MODE__SHIFT) |
  1518. (0 << GAMUT_REMAP_CONTROL__OVL_GAMUT_REMAP_MODE__SHIFT)));
  1519. WREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1520. ((0 << REGAMMA_CONTROL__GRPH_REGAMMA_MODE__SHIFT) |
  1521. (0 << REGAMMA_CONTROL__OVL_REGAMMA_MODE__SHIFT)));
  1522. WREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
  1523. ((0 << OUTPUT_CSC_CONTROL__OUTPUT_CSC_GRPH_MODE__SHIFT) |
  1524. (0 << OUTPUT_CSC_CONTROL__OUTPUT_CSC_OVL_MODE__SHIFT)));
  1525. /* XXX match this to the depth of the crtc fmt block, move to modeset? */
  1526. WREG32(0x1a50 + amdgpu_crtc->crtc_offset, 0);
  1527. }
  1528. static int dce_v6_0_pick_dig_encoder(struct drm_encoder *encoder)
  1529. {
  1530. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1531. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1532. switch (amdgpu_encoder->encoder_id) {
  1533. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  1534. return dig->linkb ? 1 : 0;
  1535. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  1536. return dig->linkb ? 3 : 2;
  1537. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  1538. return dig->linkb ? 5 : 4;
  1539. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  1540. return 6;
  1541. default:
  1542. DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id);
  1543. return 0;
  1544. }
  1545. }
  1546. /**
  1547. * dce_v6_0_pick_pll - Allocate a PPLL for use by the crtc.
  1548. *
  1549. * @crtc: drm crtc
  1550. *
  1551. * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
  1552. * a single PPLL can be used for all DP crtcs/encoders. For non-DP
  1553. * monitors a dedicated PPLL must be used. If a particular board has
  1554. * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
  1555. * as there is no need to program the PLL itself. If we are not able to
  1556. * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
  1557. * avoid messing up an existing monitor.
  1558. *
  1559. *
  1560. */
  1561. static u32 dce_v6_0_pick_pll(struct drm_crtc *crtc)
  1562. {
  1563. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1564. struct drm_device *dev = crtc->dev;
  1565. struct amdgpu_device *adev = dev->dev_private;
  1566. u32 pll_in_use;
  1567. int pll;
  1568. if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) {
  1569. if (adev->clock.dp_extclk)
  1570. /* skip PPLL programming if using ext clock */
  1571. return ATOM_PPLL_INVALID;
  1572. else
  1573. return ATOM_PPLL0;
  1574. } else {
  1575. /* use the same PPLL for all monitors with the same clock */
  1576. pll = amdgpu_pll_get_shared_nondp_ppll(crtc);
  1577. if (pll != ATOM_PPLL_INVALID)
  1578. return pll;
  1579. }
  1580. /* PPLL1, and PPLL2 */
  1581. pll_in_use = amdgpu_pll_get_use_mask(crtc);
  1582. if (!(pll_in_use & (1 << ATOM_PPLL2)))
  1583. return ATOM_PPLL2;
  1584. if (!(pll_in_use & (1 << ATOM_PPLL1)))
  1585. return ATOM_PPLL1;
  1586. DRM_ERROR("unable to allocate a PPLL\n");
  1587. return ATOM_PPLL_INVALID;
  1588. }
  1589. static void dce_v6_0_lock_cursor(struct drm_crtc *crtc, bool lock)
  1590. {
  1591. struct amdgpu_device *adev = crtc->dev->dev_private;
  1592. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1593. uint32_t cur_lock;
  1594. cur_lock = RREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset);
  1595. if (lock)
  1596. cur_lock |= CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
  1597. else
  1598. cur_lock &= ~CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
  1599. WREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset, cur_lock);
  1600. }
  1601. static void dce_v6_0_hide_cursor(struct drm_crtc *crtc)
  1602. {
  1603. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1604. struct amdgpu_device *adev = crtc->dev->dev_private;
  1605. WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
  1606. (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
  1607. (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
  1608. }
  1609. static void dce_v6_0_show_cursor(struct drm_crtc *crtc)
  1610. {
  1611. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1612. struct amdgpu_device *adev = crtc->dev->dev_private;
  1613. WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1614. upper_32_bits(amdgpu_crtc->cursor_addr));
  1615. WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1616. lower_32_bits(amdgpu_crtc->cursor_addr));
  1617. WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
  1618. CUR_CONTROL__CURSOR_EN_MASK |
  1619. (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
  1620. (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
  1621. }
  1622. static int dce_v6_0_cursor_move_locked(struct drm_crtc *crtc,
  1623. int x, int y)
  1624. {
  1625. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1626. struct amdgpu_device *adev = crtc->dev->dev_private;
  1627. int xorigin = 0, yorigin = 0;
  1628. int w = amdgpu_crtc->cursor_width;
  1629. amdgpu_crtc->cursor_x = x;
  1630. amdgpu_crtc->cursor_y = y;
  1631. /* avivo cursor are offset into the total surface */
  1632. x += crtc->x;
  1633. y += crtc->y;
  1634. DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
  1635. if (x < 0) {
  1636. xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
  1637. x = 0;
  1638. }
  1639. if (y < 0) {
  1640. yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
  1641. y = 0;
  1642. }
  1643. WREG32(mmCUR_POSITION + amdgpu_crtc->crtc_offset, (x << 16) | y);
  1644. WREG32(mmCUR_HOT_SPOT + amdgpu_crtc->crtc_offset, (xorigin << 16) | yorigin);
  1645. WREG32(mmCUR_SIZE + amdgpu_crtc->crtc_offset,
  1646. ((w - 1) << 16) | (amdgpu_crtc->cursor_height - 1));
  1647. return 0;
  1648. }
  1649. static int dce_v6_0_crtc_cursor_move(struct drm_crtc *crtc,
  1650. int x, int y)
  1651. {
  1652. int ret;
  1653. dce_v6_0_lock_cursor(crtc, true);
  1654. ret = dce_v6_0_cursor_move_locked(crtc, x, y);
  1655. dce_v6_0_lock_cursor(crtc, false);
  1656. return ret;
  1657. }
  1658. static int dce_v6_0_crtc_cursor_set2(struct drm_crtc *crtc,
  1659. struct drm_file *file_priv,
  1660. uint32_t handle,
  1661. uint32_t width,
  1662. uint32_t height,
  1663. int32_t hot_x,
  1664. int32_t hot_y)
  1665. {
  1666. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1667. struct drm_gem_object *obj;
  1668. struct amdgpu_bo *aobj;
  1669. int ret;
  1670. if (!handle) {
  1671. /* turn off cursor */
  1672. dce_v6_0_hide_cursor(crtc);
  1673. obj = NULL;
  1674. goto unpin;
  1675. }
  1676. if ((width > amdgpu_crtc->max_cursor_width) ||
  1677. (height > amdgpu_crtc->max_cursor_height)) {
  1678. DRM_ERROR("bad cursor width or height %d x %d\n", width, height);
  1679. return -EINVAL;
  1680. }
  1681. obj = drm_gem_object_lookup(file_priv, handle);
  1682. if (!obj) {
  1683. DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, amdgpu_crtc->crtc_id);
  1684. return -ENOENT;
  1685. }
  1686. aobj = gem_to_amdgpu_bo(obj);
  1687. ret = amdgpu_bo_reserve(aobj, false);
  1688. if (ret != 0) {
  1689. drm_gem_object_unreference_unlocked(obj);
  1690. return ret;
  1691. }
  1692. ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM, &amdgpu_crtc->cursor_addr);
  1693. amdgpu_bo_unreserve(aobj);
  1694. if (ret) {
  1695. DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret);
  1696. drm_gem_object_unreference_unlocked(obj);
  1697. return ret;
  1698. }
  1699. dce_v6_0_lock_cursor(crtc, true);
  1700. if (width != amdgpu_crtc->cursor_width ||
  1701. height != amdgpu_crtc->cursor_height ||
  1702. hot_x != amdgpu_crtc->cursor_hot_x ||
  1703. hot_y != amdgpu_crtc->cursor_hot_y) {
  1704. int x, y;
  1705. x = amdgpu_crtc->cursor_x + amdgpu_crtc->cursor_hot_x - hot_x;
  1706. y = amdgpu_crtc->cursor_y + amdgpu_crtc->cursor_hot_y - hot_y;
  1707. dce_v6_0_cursor_move_locked(crtc, x, y);
  1708. amdgpu_crtc->cursor_width = width;
  1709. amdgpu_crtc->cursor_height = height;
  1710. amdgpu_crtc->cursor_hot_x = hot_x;
  1711. amdgpu_crtc->cursor_hot_y = hot_y;
  1712. }
  1713. dce_v6_0_show_cursor(crtc);
  1714. dce_v6_0_lock_cursor(crtc, false);
  1715. unpin:
  1716. if (amdgpu_crtc->cursor_bo) {
  1717. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  1718. ret = amdgpu_bo_reserve(aobj, false);
  1719. if (likely(ret == 0)) {
  1720. amdgpu_bo_unpin(aobj);
  1721. amdgpu_bo_unreserve(aobj);
  1722. }
  1723. drm_gem_object_unreference_unlocked(amdgpu_crtc->cursor_bo);
  1724. }
  1725. amdgpu_crtc->cursor_bo = obj;
  1726. return 0;
  1727. }
  1728. static void dce_v6_0_cursor_reset(struct drm_crtc *crtc)
  1729. {
  1730. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1731. if (amdgpu_crtc->cursor_bo) {
  1732. dce_v6_0_lock_cursor(crtc, true);
  1733. dce_v6_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x,
  1734. amdgpu_crtc->cursor_y);
  1735. dce_v6_0_show_cursor(crtc);
  1736. dce_v6_0_lock_cursor(crtc, false);
  1737. }
  1738. }
  1739. static int dce_v6_0_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  1740. u16 *blue, uint32_t size)
  1741. {
  1742. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1743. int i;
  1744. /* userspace palettes are always correct as is */
  1745. for (i = 0; i < size; i++) {
  1746. amdgpu_crtc->lut_r[i] = red[i] >> 6;
  1747. amdgpu_crtc->lut_g[i] = green[i] >> 6;
  1748. amdgpu_crtc->lut_b[i] = blue[i] >> 6;
  1749. }
  1750. dce_v6_0_crtc_load_lut(crtc);
  1751. return 0;
  1752. }
  1753. static void dce_v6_0_crtc_destroy(struct drm_crtc *crtc)
  1754. {
  1755. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1756. drm_crtc_cleanup(crtc);
  1757. kfree(amdgpu_crtc);
  1758. }
  1759. static const struct drm_crtc_funcs dce_v6_0_crtc_funcs = {
  1760. .cursor_set2 = dce_v6_0_crtc_cursor_set2,
  1761. .cursor_move = dce_v6_0_crtc_cursor_move,
  1762. .gamma_set = dce_v6_0_crtc_gamma_set,
  1763. .set_config = amdgpu_crtc_set_config,
  1764. .destroy = dce_v6_0_crtc_destroy,
  1765. .page_flip_target = amdgpu_crtc_page_flip_target,
  1766. };
  1767. static void dce_v6_0_crtc_dpms(struct drm_crtc *crtc, int mode)
  1768. {
  1769. struct drm_device *dev = crtc->dev;
  1770. struct amdgpu_device *adev = dev->dev_private;
  1771. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1772. unsigned type;
  1773. switch (mode) {
  1774. case DRM_MODE_DPMS_ON:
  1775. amdgpu_crtc->enabled = true;
  1776. amdgpu_atombios_crtc_enable(crtc, ATOM_ENABLE);
  1777. amdgpu_atombios_crtc_blank(crtc, ATOM_DISABLE);
  1778. /* Make sure VBLANK and PFLIP interrupts are still enabled */
  1779. type = amdgpu_crtc_idx_to_irq_type(adev, amdgpu_crtc->crtc_id);
  1780. amdgpu_irq_update(adev, &adev->crtc_irq, type);
  1781. amdgpu_irq_update(adev, &adev->pageflip_irq, type);
  1782. drm_crtc_vblank_on(crtc);
  1783. dce_v6_0_crtc_load_lut(crtc);
  1784. break;
  1785. case DRM_MODE_DPMS_STANDBY:
  1786. case DRM_MODE_DPMS_SUSPEND:
  1787. case DRM_MODE_DPMS_OFF:
  1788. drm_crtc_vblank_off(crtc);
  1789. if (amdgpu_crtc->enabled)
  1790. amdgpu_atombios_crtc_blank(crtc, ATOM_ENABLE);
  1791. amdgpu_atombios_crtc_enable(crtc, ATOM_DISABLE);
  1792. amdgpu_crtc->enabled = false;
  1793. break;
  1794. }
  1795. /* adjust pm to dpms */
  1796. amdgpu_pm_compute_clocks(adev);
  1797. }
  1798. static void dce_v6_0_crtc_prepare(struct drm_crtc *crtc)
  1799. {
  1800. /* disable crtc pair power gating before programming */
  1801. amdgpu_atombios_crtc_powergate(crtc, ATOM_DISABLE);
  1802. amdgpu_atombios_crtc_lock(crtc, ATOM_ENABLE);
  1803. dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  1804. }
  1805. static void dce_v6_0_crtc_commit(struct drm_crtc *crtc)
  1806. {
  1807. dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
  1808. amdgpu_atombios_crtc_lock(crtc, ATOM_DISABLE);
  1809. }
  1810. static void dce_v6_0_crtc_disable(struct drm_crtc *crtc)
  1811. {
  1812. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1813. struct drm_device *dev = crtc->dev;
  1814. struct amdgpu_device *adev = dev->dev_private;
  1815. struct amdgpu_atom_ss ss;
  1816. int i;
  1817. dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  1818. if (crtc->primary->fb) {
  1819. int r;
  1820. struct amdgpu_framebuffer *amdgpu_fb;
  1821. struct amdgpu_bo *abo;
  1822. amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
  1823. abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
  1824. r = amdgpu_bo_reserve(abo, false);
  1825. if (unlikely(r))
  1826. DRM_ERROR("failed to reserve abo before unpin\n");
  1827. else {
  1828. amdgpu_bo_unpin(abo);
  1829. amdgpu_bo_unreserve(abo);
  1830. }
  1831. }
  1832. /* disable the GRPH */
  1833. dce_v6_0_grph_enable(crtc, false);
  1834. amdgpu_atombios_crtc_powergate(crtc, ATOM_ENABLE);
  1835. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1836. if (adev->mode_info.crtcs[i] &&
  1837. adev->mode_info.crtcs[i]->enabled &&
  1838. i != amdgpu_crtc->crtc_id &&
  1839. amdgpu_crtc->pll_id == adev->mode_info.crtcs[i]->pll_id) {
  1840. /* one other crtc is using this pll don't turn
  1841. * off the pll
  1842. */
  1843. goto done;
  1844. }
  1845. }
  1846. switch (amdgpu_crtc->pll_id) {
  1847. case ATOM_PPLL1:
  1848. case ATOM_PPLL2:
  1849. /* disable the ppll */
  1850. amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
  1851. 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
  1852. break;
  1853. default:
  1854. break;
  1855. }
  1856. done:
  1857. amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
  1858. amdgpu_crtc->adjusted_clock = 0;
  1859. amdgpu_crtc->encoder = NULL;
  1860. amdgpu_crtc->connector = NULL;
  1861. }
  1862. static int dce_v6_0_crtc_mode_set(struct drm_crtc *crtc,
  1863. struct drm_display_mode *mode,
  1864. struct drm_display_mode *adjusted_mode,
  1865. int x, int y, struct drm_framebuffer *old_fb)
  1866. {
  1867. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1868. if (!amdgpu_crtc->adjusted_clock)
  1869. return -EINVAL;
  1870. amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode);
  1871. amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode);
  1872. dce_v6_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
  1873. amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode);
  1874. amdgpu_atombios_crtc_scaler_setup(crtc);
  1875. dce_v6_0_cursor_reset(crtc);
  1876. /* update the hw version fpr dpm */
  1877. amdgpu_crtc->hw_mode = *adjusted_mode;
  1878. return 0;
  1879. }
  1880. static bool dce_v6_0_crtc_mode_fixup(struct drm_crtc *crtc,
  1881. const struct drm_display_mode *mode,
  1882. struct drm_display_mode *adjusted_mode)
  1883. {
  1884. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1885. struct drm_device *dev = crtc->dev;
  1886. struct drm_encoder *encoder;
  1887. /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
  1888. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1889. if (encoder->crtc == crtc) {
  1890. amdgpu_crtc->encoder = encoder;
  1891. amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder);
  1892. break;
  1893. }
  1894. }
  1895. if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) {
  1896. amdgpu_crtc->encoder = NULL;
  1897. amdgpu_crtc->connector = NULL;
  1898. return false;
  1899. }
  1900. if (!amdgpu_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
  1901. return false;
  1902. if (amdgpu_atombios_crtc_prepare_pll(crtc, adjusted_mode))
  1903. return false;
  1904. /* pick pll */
  1905. amdgpu_crtc->pll_id = dce_v6_0_pick_pll(crtc);
  1906. /* if we can't get a PPLL for a non-DP encoder, fail */
  1907. if ((amdgpu_crtc->pll_id == ATOM_PPLL_INVALID) &&
  1908. !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder)))
  1909. return false;
  1910. return true;
  1911. }
  1912. static int dce_v6_0_crtc_set_base(struct drm_crtc *crtc, int x, int y,
  1913. struct drm_framebuffer *old_fb)
  1914. {
  1915. return dce_v6_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
  1916. }
  1917. static int dce_v6_0_crtc_set_base_atomic(struct drm_crtc *crtc,
  1918. struct drm_framebuffer *fb,
  1919. int x, int y, enum mode_set_atomic state)
  1920. {
  1921. return dce_v6_0_crtc_do_set_base(crtc, fb, x, y, 1);
  1922. }
  1923. static const struct drm_crtc_helper_funcs dce_v6_0_crtc_helper_funcs = {
  1924. .dpms = dce_v6_0_crtc_dpms,
  1925. .mode_fixup = dce_v6_0_crtc_mode_fixup,
  1926. .mode_set = dce_v6_0_crtc_mode_set,
  1927. .mode_set_base = dce_v6_0_crtc_set_base,
  1928. .mode_set_base_atomic = dce_v6_0_crtc_set_base_atomic,
  1929. .prepare = dce_v6_0_crtc_prepare,
  1930. .commit = dce_v6_0_crtc_commit,
  1931. .load_lut = dce_v6_0_crtc_load_lut,
  1932. .disable = dce_v6_0_crtc_disable,
  1933. };
  1934. static int dce_v6_0_crtc_init(struct amdgpu_device *adev, int index)
  1935. {
  1936. struct amdgpu_crtc *amdgpu_crtc;
  1937. int i;
  1938. amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) +
  1939. (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  1940. if (amdgpu_crtc == NULL)
  1941. return -ENOMEM;
  1942. drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_v6_0_crtc_funcs);
  1943. drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256);
  1944. amdgpu_crtc->crtc_id = index;
  1945. adev->mode_info.crtcs[index] = amdgpu_crtc;
  1946. amdgpu_crtc->max_cursor_width = CURSOR_WIDTH;
  1947. amdgpu_crtc->max_cursor_height = CURSOR_HEIGHT;
  1948. adev->ddev->mode_config.cursor_width = amdgpu_crtc->max_cursor_width;
  1949. adev->ddev->mode_config.cursor_height = amdgpu_crtc->max_cursor_height;
  1950. for (i = 0; i < 256; i++) {
  1951. amdgpu_crtc->lut_r[i] = i << 2;
  1952. amdgpu_crtc->lut_g[i] = i << 2;
  1953. amdgpu_crtc->lut_b[i] = i << 2;
  1954. }
  1955. amdgpu_crtc->crtc_offset = crtc_offsets[amdgpu_crtc->crtc_id];
  1956. amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
  1957. amdgpu_crtc->adjusted_clock = 0;
  1958. amdgpu_crtc->encoder = NULL;
  1959. amdgpu_crtc->connector = NULL;
  1960. drm_crtc_helper_add(&amdgpu_crtc->base, &dce_v6_0_crtc_helper_funcs);
  1961. return 0;
  1962. }
  1963. static int dce_v6_0_early_init(void *handle)
  1964. {
  1965. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1966. adev->audio_endpt_rreg = &dce_v6_0_audio_endpt_rreg;
  1967. adev->audio_endpt_wreg = &dce_v6_0_audio_endpt_wreg;
  1968. dce_v6_0_set_display_funcs(adev);
  1969. dce_v6_0_set_irq_funcs(adev);
  1970. adev->mode_info.num_crtc = dce_v6_0_get_num_crtc(adev);
  1971. switch (adev->asic_type) {
  1972. case CHIP_TAHITI:
  1973. case CHIP_PITCAIRN:
  1974. case CHIP_VERDE:
  1975. adev->mode_info.num_hpd = 6;
  1976. adev->mode_info.num_dig = 6;
  1977. break;
  1978. case CHIP_OLAND:
  1979. adev->mode_info.num_hpd = 2;
  1980. adev->mode_info.num_dig = 2;
  1981. break;
  1982. default:
  1983. return -EINVAL;
  1984. }
  1985. return 0;
  1986. }
  1987. static int dce_v6_0_sw_init(void *handle)
  1988. {
  1989. int r, i;
  1990. bool ret;
  1991. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1992. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1993. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, i + 1, &adev->crtc_irq);
  1994. if (r)
  1995. return r;
  1996. }
  1997. for (i = 8; i < 20; i += 2) {
  1998. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, i, &adev->pageflip_irq);
  1999. if (r)
  2000. return r;
  2001. }
  2002. /* HPD hotplug */
  2003. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 42, &adev->hpd_irq);
  2004. if (r)
  2005. return r;
  2006. adev->mode_info.mode_config_initialized = true;
  2007. adev->ddev->mode_config.funcs = &amdgpu_mode_funcs;
  2008. adev->ddev->mode_config.async_page_flip = true;
  2009. adev->ddev->mode_config.max_width = 16384;
  2010. adev->ddev->mode_config.max_height = 16384;
  2011. adev->ddev->mode_config.preferred_depth = 24;
  2012. adev->ddev->mode_config.prefer_shadow = 1;
  2013. adev->ddev->mode_config.fb_base = adev->mc.aper_base;
  2014. r = amdgpu_modeset_create_props(adev);
  2015. if (r)
  2016. return r;
  2017. adev->ddev->mode_config.max_width = 16384;
  2018. adev->ddev->mode_config.max_height = 16384;
  2019. /* allocate crtcs */
  2020. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  2021. r = dce_v6_0_crtc_init(adev, i);
  2022. if (r)
  2023. return r;
  2024. }
  2025. ret = amdgpu_atombios_get_connector_info_from_object_table(adev);
  2026. if (ret)
  2027. amdgpu_print_display_setup(adev->ddev);
  2028. else
  2029. return -EINVAL;
  2030. /* setup afmt */
  2031. r = dce_v6_0_afmt_init(adev);
  2032. if (r)
  2033. return r;
  2034. r = dce_v6_0_audio_init(adev);
  2035. if (r)
  2036. return r;
  2037. drm_kms_helper_poll_init(adev->ddev);
  2038. return r;
  2039. }
  2040. static int dce_v6_0_sw_fini(void *handle)
  2041. {
  2042. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2043. kfree(adev->mode_info.bios_hardcoded_edid);
  2044. drm_kms_helper_poll_fini(adev->ddev);
  2045. dce_v6_0_audio_fini(adev);
  2046. dce_v6_0_afmt_fini(adev);
  2047. drm_mode_config_cleanup(adev->ddev);
  2048. adev->mode_info.mode_config_initialized = false;
  2049. return 0;
  2050. }
  2051. static int dce_v6_0_hw_init(void *handle)
  2052. {
  2053. int i;
  2054. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2055. /* init dig PHYs, disp eng pll */
  2056. amdgpu_atombios_encoder_init_dig(adev);
  2057. amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk);
  2058. /* initialize hpd */
  2059. dce_v6_0_hpd_init(adev);
  2060. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  2061. dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  2062. }
  2063. dce_v6_0_pageflip_interrupt_init(adev);
  2064. return 0;
  2065. }
  2066. static int dce_v6_0_hw_fini(void *handle)
  2067. {
  2068. int i;
  2069. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2070. dce_v6_0_hpd_fini(adev);
  2071. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  2072. dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  2073. }
  2074. dce_v6_0_pageflip_interrupt_fini(adev);
  2075. return 0;
  2076. }
  2077. static int dce_v6_0_suspend(void *handle)
  2078. {
  2079. return dce_v6_0_hw_fini(handle);
  2080. }
  2081. static int dce_v6_0_resume(void *handle)
  2082. {
  2083. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2084. int ret;
  2085. ret = dce_v6_0_hw_init(handle);
  2086. /* turn on the BL */
  2087. if (adev->mode_info.bl_encoder) {
  2088. u8 bl_level = amdgpu_display_backlight_get_level(adev,
  2089. adev->mode_info.bl_encoder);
  2090. amdgpu_display_backlight_set_level(adev, adev->mode_info.bl_encoder,
  2091. bl_level);
  2092. }
  2093. return ret;
  2094. }
  2095. static bool dce_v6_0_is_idle(void *handle)
  2096. {
  2097. return true;
  2098. }
  2099. static int dce_v6_0_wait_for_idle(void *handle)
  2100. {
  2101. return 0;
  2102. }
  2103. static int dce_v6_0_soft_reset(void *handle)
  2104. {
  2105. DRM_INFO("xxxx: dce_v6_0_soft_reset --- no impl!!\n");
  2106. return 0;
  2107. }
  2108. static void dce_v6_0_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev,
  2109. int crtc,
  2110. enum amdgpu_interrupt_state state)
  2111. {
  2112. u32 reg_block, interrupt_mask;
  2113. if (crtc >= adev->mode_info.num_crtc) {
  2114. DRM_DEBUG("invalid crtc %d\n", crtc);
  2115. return;
  2116. }
  2117. switch (crtc) {
  2118. case 0:
  2119. reg_block = SI_CRTC0_REGISTER_OFFSET;
  2120. break;
  2121. case 1:
  2122. reg_block = SI_CRTC1_REGISTER_OFFSET;
  2123. break;
  2124. case 2:
  2125. reg_block = SI_CRTC2_REGISTER_OFFSET;
  2126. break;
  2127. case 3:
  2128. reg_block = SI_CRTC3_REGISTER_OFFSET;
  2129. break;
  2130. case 4:
  2131. reg_block = SI_CRTC4_REGISTER_OFFSET;
  2132. break;
  2133. case 5:
  2134. reg_block = SI_CRTC5_REGISTER_OFFSET;
  2135. break;
  2136. default:
  2137. DRM_DEBUG("invalid crtc %d\n", crtc);
  2138. return;
  2139. }
  2140. switch (state) {
  2141. case AMDGPU_IRQ_STATE_DISABLE:
  2142. interrupt_mask = RREG32(mmINT_MASK + reg_block);
  2143. interrupt_mask &= ~VBLANK_INT_MASK;
  2144. WREG32(mmINT_MASK + reg_block, interrupt_mask);
  2145. break;
  2146. case AMDGPU_IRQ_STATE_ENABLE:
  2147. interrupt_mask = RREG32(mmINT_MASK + reg_block);
  2148. interrupt_mask |= VBLANK_INT_MASK;
  2149. WREG32(mmINT_MASK + reg_block, interrupt_mask);
  2150. break;
  2151. default:
  2152. break;
  2153. }
  2154. }
  2155. static void dce_v6_0_set_crtc_vline_interrupt_state(struct amdgpu_device *adev,
  2156. int crtc,
  2157. enum amdgpu_interrupt_state state)
  2158. {
  2159. }
  2160. static int dce_v6_0_set_hpd_interrupt_state(struct amdgpu_device *adev,
  2161. struct amdgpu_irq_src *src,
  2162. unsigned type,
  2163. enum amdgpu_interrupt_state state)
  2164. {
  2165. u32 dc_hpd_int_cntl;
  2166. if (type >= adev->mode_info.num_hpd) {
  2167. DRM_DEBUG("invalid hdp %d\n", type);
  2168. return 0;
  2169. }
  2170. switch (state) {
  2171. case AMDGPU_IRQ_STATE_DISABLE:
  2172. dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
  2173. dc_hpd_int_cntl &= ~DC_HPDx_INT_EN;
  2174. WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
  2175. break;
  2176. case AMDGPU_IRQ_STATE_ENABLE:
  2177. dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
  2178. dc_hpd_int_cntl |= DC_HPDx_INT_EN;
  2179. WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
  2180. break;
  2181. default:
  2182. break;
  2183. }
  2184. return 0;
  2185. }
  2186. static int dce_v6_0_set_crtc_interrupt_state(struct amdgpu_device *adev,
  2187. struct amdgpu_irq_src *src,
  2188. unsigned type,
  2189. enum amdgpu_interrupt_state state)
  2190. {
  2191. switch (type) {
  2192. case AMDGPU_CRTC_IRQ_VBLANK1:
  2193. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 0, state);
  2194. break;
  2195. case AMDGPU_CRTC_IRQ_VBLANK2:
  2196. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 1, state);
  2197. break;
  2198. case AMDGPU_CRTC_IRQ_VBLANK3:
  2199. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 2, state);
  2200. break;
  2201. case AMDGPU_CRTC_IRQ_VBLANK4:
  2202. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 3, state);
  2203. break;
  2204. case AMDGPU_CRTC_IRQ_VBLANK5:
  2205. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 4, state);
  2206. break;
  2207. case AMDGPU_CRTC_IRQ_VBLANK6:
  2208. dce_v6_0_set_crtc_vblank_interrupt_state(adev, 5, state);
  2209. break;
  2210. case AMDGPU_CRTC_IRQ_VLINE1:
  2211. dce_v6_0_set_crtc_vline_interrupt_state(adev, 0, state);
  2212. break;
  2213. case AMDGPU_CRTC_IRQ_VLINE2:
  2214. dce_v6_0_set_crtc_vline_interrupt_state(adev, 1, state);
  2215. break;
  2216. case AMDGPU_CRTC_IRQ_VLINE3:
  2217. dce_v6_0_set_crtc_vline_interrupt_state(adev, 2, state);
  2218. break;
  2219. case AMDGPU_CRTC_IRQ_VLINE4:
  2220. dce_v6_0_set_crtc_vline_interrupt_state(adev, 3, state);
  2221. break;
  2222. case AMDGPU_CRTC_IRQ_VLINE5:
  2223. dce_v6_0_set_crtc_vline_interrupt_state(adev, 4, state);
  2224. break;
  2225. case AMDGPU_CRTC_IRQ_VLINE6:
  2226. dce_v6_0_set_crtc_vline_interrupt_state(adev, 5, state);
  2227. break;
  2228. default:
  2229. break;
  2230. }
  2231. return 0;
  2232. }
  2233. static int dce_v6_0_crtc_irq(struct amdgpu_device *adev,
  2234. struct amdgpu_irq_src *source,
  2235. struct amdgpu_iv_entry *entry)
  2236. {
  2237. unsigned crtc = entry->src_id - 1;
  2238. uint32_t disp_int = RREG32(interrupt_status_offsets[crtc].reg);
  2239. unsigned irq_type = amdgpu_crtc_idx_to_irq_type(adev, crtc);
  2240. switch (entry->src_data[0]) {
  2241. case 0: /* vblank */
  2242. if (disp_int & interrupt_status_offsets[crtc].vblank)
  2243. WREG32(mmVBLANK_STATUS + crtc_offsets[crtc], VBLANK_ACK);
  2244. else
  2245. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  2246. if (amdgpu_irq_enabled(adev, source, irq_type)) {
  2247. drm_handle_vblank(adev->ddev, crtc);
  2248. }
  2249. DRM_DEBUG("IH: D%d vblank\n", crtc + 1);
  2250. break;
  2251. case 1: /* vline */
  2252. if (disp_int & interrupt_status_offsets[crtc].vline)
  2253. WREG32(mmVLINE_STATUS + crtc_offsets[crtc], VLINE_ACK);
  2254. else
  2255. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  2256. DRM_DEBUG("IH: D%d vline\n", crtc + 1);
  2257. break;
  2258. default:
  2259. DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]);
  2260. break;
  2261. }
  2262. return 0;
  2263. }
  2264. static int dce_v6_0_set_pageflip_interrupt_state(struct amdgpu_device *adev,
  2265. struct amdgpu_irq_src *src,
  2266. unsigned type,
  2267. enum amdgpu_interrupt_state state)
  2268. {
  2269. u32 reg;
  2270. if (type >= adev->mode_info.num_crtc) {
  2271. DRM_ERROR("invalid pageflip crtc %d\n", type);
  2272. return -EINVAL;
  2273. }
  2274. reg = RREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type]);
  2275. if (state == AMDGPU_IRQ_STATE_DISABLE)
  2276. WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
  2277. reg & ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
  2278. else
  2279. WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
  2280. reg | GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
  2281. return 0;
  2282. }
  2283. static int dce_v6_0_pageflip_irq(struct amdgpu_device *adev,
  2284. struct amdgpu_irq_src *source,
  2285. struct amdgpu_iv_entry *entry)
  2286. {
  2287. unsigned long flags;
  2288. unsigned crtc_id;
  2289. struct amdgpu_crtc *amdgpu_crtc;
  2290. struct amdgpu_flip_work *works;
  2291. crtc_id = (entry->src_id - 8) >> 1;
  2292. amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
  2293. if (crtc_id >= adev->mode_info.num_crtc) {
  2294. DRM_ERROR("invalid pageflip crtc %d\n", crtc_id);
  2295. return -EINVAL;
  2296. }
  2297. if (RREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id]) &
  2298. GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK)
  2299. WREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id],
  2300. GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK);
  2301. /* IRQ could occur when in initial stage */
  2302. if (amdgpu_crtc == NULL)
  2303. return 0;
  2304. spin_lock_irqsave(&adev->ddev->event_lock, flags);
  2305. works = amdgpu_crtc->pflip_works;
  2306. if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){
  2307. DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
  2308. "AMDGPU_FLIP_SUBMITTED(%d)\n",
  2309. amdgpu_crtc->pflip_status,
  2310. AMDGPU_FLIP_SUBMITTED);
  2311. spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  2312. return 0;
  2313. }
  2314. /* page flip completed. clean up */
  2315. amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
  2316. amdgpu_crtc->pflip_works = NULL;
  2317. /* wakeup usersapce */
  2318. if (works->event)
  2319. drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event);
  2320. spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  2321. drm_crtc_vblank_put(&amdgpu_crtc->base);
  2322. schedule_work(&works->unpin_work);
  2323. return 0;
  2324. }
  2325. static int dce_v6_0_hpd_irq(struct amdgpu_device *adev,
  2326. struct amdgpu_irq_src *source,
  2327. struct amdgpu_iv_entry *entry)
  2328. {
  2329. uint32_t disp_int, mask, tmp;
  2330. unsigned hpd;
  2331. if (entry->src_data[0] >= adev->mode_info.num_hpd) {
  2332. DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]);
  2333. return 0;
  2334. }
  2335. hpd = entry->src_data[0];
  2336. disp_int = RREG32(interrupt_status_offsets[hpd].reg);
  2337. mask = interrupt_status_offsets[hpd].hpd;
  2338. if (disp_int & mask) {
  2339. tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
  2340. tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_ACK_MASK;
  2341. WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
  2342. schedule_work(&adev->hotplug_work);
  2343. DRM_INFO("IH: HPD%d\n", hpd + 1);
  2344. }
  2345. return 0;
  2346. }
  2347. static int dce_v6_0_set_clockgating_state(void *handle,
  2348. enum amd_clockgating_state state)
  2349. {
  2350. return 0;
  2351. }
  2352. static int dce_v6_0_set_powergating_state(void *handle,
  2353. enum amd_powergating_state state)
  2354. {
  2355. return 0;
  2356. }
  2357. static const struct amd_ip_funcs dce_v6_0_ip_funcs = {
  2358. .name = "dce_v6_0",
  2359. .early_init = dce_v6_0_early_init,
  2360. .late_init = NULL,
  2361. .sw_init = dce_v6_0_sw_init,
  2362. .sw_fini = dce_v6_0_sw_fini,
  2363. .hw_init = dce_v6_0_hw_init,
  2364. .hw_fini = dce_v6_0_hw_fini,
  2365. .suspend = dce_v6_0_suspend,
  2366. .resume = dce_v6_0_resume,
  2367. .is_idle = dce_v6_0_is_idle,
  2368. .wait_for_idle = dce_v6_0_wait_for_idle,
  2369. .soft_reset = dce_v6_0_soft_reset,
  2370. .set_clockgating_state = dce_v6_0_set_clockgating_state,
  2371. .set_powergating_state = dce_v6_0_set_powergating_state,
  2372. };
  2373. static void
  2374. dce_v6_0_encoder_mode_set(struct drm_encoder *encoder,
  2375. struct drm_display_mode *mode,
  2376. struct drm_display_mode *adjusted_mode)
  2377. {
  2378. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2379. amdgpu_encoder->pixel_clock = adjusted_mode->clock;
  2380. /* need to call this here rather than in prepare() since we need some crtc info */
  2381. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  2382. /* set scaler clears this on some chips */
  2383. dce_v6_0_set_interleave(encoder->crtc, mode);
  2384. if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
  2385. dce_v6_0_afmt_enable(encoder, true);
  2386. dce_v6_0_afmt_setmode(encoder, adjusted_mode);
  2387. }
  2388. }
  2389. static void dce_v6_0_encoder_prepare(struct drm_encoder *encoder)
  2390. {
  2391. struct amdgpu_device *adev = encoder->dev->dev_private;
  2392. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2393. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  2394. if ((amdgpu_encoder->active_device &
  2395. (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
  2396. (amdgpu_encoder_get_dp_bridge_encoder_id(encoder) !=
  2397. ENCODER_OBJECT_ID_NONE)) {
  2398. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  2399. if (dig) {
  2400. dig->dig_encoder = dce_v6_0_pick_dig_encoder(encoder);
  2401. if (amdgpu_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT)
  2402. dig->afmt = adev->mode_info.afmt[dig->dig_encoder];
  2403. }
  2404. }
  2405. amdgpu_atombios_scratch_regs_lock(adev, true);
  2406. if (connector) {
  2407. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  2408. /* select the clock/data port if it uses a router */
  2409. if (amdgpu_connector->router.cd_valid)
  2410. amdgpu_i2c_router_select_cd_port(amdgpu_connector);
  2411. /* turn eDP panel on for mode set */
  2412. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  2413. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  2414. ATOM_TRANSMITTER_ACTION_POWER_ON);
  2415. }
  2416. /* this is needed for the pll/ss setup to work correctly in some cases */
  2417. amdgpu_atombios_encoder_set_crtc_source(encoder);
  2418. /* set up the FMT blocks */
  2419. dce_v6_0_program_fmt(encoder);
  2420. }
  2421. static void dce_v6_0_encoder_commit(struct drm_encoder *encoder)
  2422. {
  2423. struct drm_device *dev = encoder->dev;
  2424. struct amdgpu_device *adev = dev->dev_private;
  2425. /* need to call this here as we need the crtc set up */
  2426. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
  2427. amdgpu_atombios_scratch_regs_lock(adev, false);
  2428. }
  2429. static void dce_v6_0_encoder_disable(struct drm_encoder *encoder)
  2430. {
  2431. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2432. struct amdgpu_encoder_atom_dig *dig;
  2433. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  2434. if (amdgpu_atombios_encoder_is_digital(encoder)) {
  2435. if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
  2436. dce_v6_0_afmt_enable(encoder, false);
  2437. dig = amdgpu_encoder->enc_priv;
  2438. dig->dig_encoder = -1;
  2439. }
  2440. amdgpu_encoder->active_device = 0;
  2441. }
  2442. /* these are handled by the primary encoders */
  2443. static void dce_v6_0_ext_prepare(struct drm_encoder *encoder)
  2444. {
  2445. }
  2446. static void dce_v6_0_ext_commit(struct drm_encoder *encoder)
  2447. {
  2448. }
  2449. static void
  2450. dce_v6_0_ext_mode_set(struct drm_encoder *encoder,
  2451. struct drm_display_mode *mode,
  2452. struct drm_display_mode *adjusted_mode)
  2453. {
  2454. }
  2455. static void dce_v6_0_ext_disable(struct drm_encoder *encoder)
  2456. {
  2457. }
  2458. static void
  2459. dce_v6_0_ext_dpms(struct drm_encoder *encoder, int mode)
  2460. {
  2461. }
  2462. static bool dce_v6_0_ext_mode_fixup(struct drm_encoder *encoder,
  2463. const struct drm_display_mode *mode,
  2464. struct drm_display_mode *adjusted_mode)
  2465. {
  2466. return true;
  2467. }
  2468. static const struct drm_encoder_helper_funcs dce_v6_0_ext_helper_funcs = {
  2469. .dpms = dce_v6_0_ext_dpms,
  2470. .mode_fixup = dce_v6_0_ext_mode_fixup,
  2471. .prepare = dce_v6_0_ext_prepare,
  2472. .mode_set = dce_v6_0_ext_mode_set,
  2473. .commit = dce_v6_0_ext_commit,
  2474. .disable = dce_v6_0_ext_disable,
  2475. /* no detect for TMDS/LVDS yet */
  2476. };
  2477. static const struct drm_encoder_helper_funcs dce_v6_0_dig_helper_funcs = {
  2478. .dpms = amdgpu_atombios_encoder_dpms,
  2479. .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
  2480. .prepare = dce_v6_0_encoder_prepare,
  2481. .mode_set = dce_v6_0_encoder_mode_set,
  2482. .commit = dce_v6_0_encoder_commit,
  2483. .disable = dce_v6_0_encoder_disable,
  2484. .detect = amdgpu_atombios_encoder_dig_detect,
  2485. };
  2486. static const struct drm_encoder_helper_funcs dce_v6_0_dac_helper_funcs = {
  2487. .dpms = amdgpu_atombios_encoder_dpms,
  2488. .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
  2489. .prepare = dce_v6_0_encoder_prepare,
  2490. .mode_set = dce_v6_0_encoder_mode_set,
  2491. .commit = dce_v6_0_encoder_commit,
  2492. .detect = amdgpu_atombios_encoder_dac_detect,
  2493. };
  2494. static void dce_v6_0_encoder_destroy(struct drm_encoder *encoder)
  2495. {
  2496. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2497. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  2498. amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder);
  2499. kfree(amdgpu_encoder->enc_priv);
  2500. drm_encoder_cleanup(encoder);
  2501. kfree(amdgpu_encoder);
  2502. }
  2503. static const struct drm_encoder_funcs dce_v6_0_encoder_funcs = {
  2504. .destroy = dce_v6_0_encoder_destroy,
  2505. };
  2506. static void dce_v6_0_encoder_add(struct amdgpu_device *adev,
  2507. uint32_t encoder_enum,
  2508. uint32_t supported_device,
  2509. u16 caps)
  2510. {
  2511. struct drm_device *dev = adev->ddev;
  2512. struct drm_encoder *encoder;
  2513. struct amdgpu_encoder *amdgpu_encoder;
  2514. /* see if we already added it */
  2515. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  2516. amdgpu_encoder = to_amdgpu_encoder(encoder);
  2517. if (amdgpu_encoder->encoder_enum == encoder_enum) {
  2518. amdgpu_encoder->devices |= supported_device;
  2519. return;
  2520. }
  2521. }
  2522. /* add a new one */
  2523. amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL);
  2524. if (!amdgpu_encoder)
  2525. return;
  2526. encoder = &amdgpu_encoder->base;
  2527. switch (adev->mode_info.num_crtc) {
  2528. case 1:
  2529. encoder->possible_crtcs = 0x1;
  2530. break;
  2531. case 2:
  2532. default:
  2533. encoder->possible_crtcs = 0x3;
  2534. break;
  2535. case 4:
  2536. encoder->possible_crtcs = 0xf;
  2537. break;
  2538. case 6:
  2539. encoder->possible_crtcs = 0x3f;
  2540. break;
  2541. }
  2542. amdgpu_encoder->enc_priv = NULL;
  2543. amdgpu_encoder->encoder_enum = encoder_enum;
  2544. amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  2545. amdgpu_encoder->devices = supported_device;
  2546. amdgpu_encoder->rmx_type = RMX_OFF;
  2547. amdgpu_encoder->underscan_type = UNDERSCAN_OFF;
  2548. amdgpu_encoder->is_ext_encoder = false;
  2549. amdgpu_encoder->caps = caps;
  2550. switch (amdgpu_encoder->encoder_id) {
  2551. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  2552. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  2553. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2554. DRM_MODE_ENCODER_DAC, NULL);
  2555. drm_encoder_helper_add(encoder, &dce_v6_0_dac_helper_funcs);
  2556. break;
  2557. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  2558. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  2559. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  2560. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  2561. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  2562. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  2563. amdgpu_encoder->rmx_type = RMX_FULL;
  2564. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2565. DRM_MODE_ENCODER_LVDS, NULL);
  2566. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder);
  2567. } else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  2568. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2569. DRM_MODE_ENCODER_DAC, NULL);
  2570. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
  2571. } else {
  2572. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2573. DRM_MODE_ENCODER_TMDS, NULL);
  2574. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
  2575. }
  2576. drm_encoder_helper_add(encoder, &dce_v6_0_dig_helper_funcs);
  2577. break;
  2578. case ENCODER_OBJECT_ID_SI170B:
  2579. case ENCODER_OBJECT_ID_CH7303:
  2580. case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
  2581. case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
  2582. case ENCODER_OBJECT_ID_TITFP513:
  2583. case ENCODER_OBJECT_ID_VT1623:
  2584. case ENCODER_OBJECT_ID_HDMI_SI1930:
  2585. case ENCODER_OBJECT_ID_TRAVIS:
  2586. case ENCODER_OBJECT_ID_NUTMEG:
  2587. /* these are handled by the primary encoders */
  2588. amdgpu_encoder->is_ext_encoder = true;
  2589. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  2590. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2591. DRM_MODE_ENCODER_LVDS, NULL);
  2592. else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
  2593. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2594. DRM_MODE_ENCODER_DAC, NULL);
  2595. else
  2596. drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
  2597. DRM_MODE_ENCODER_TMDS, NULL);
  2598. drm_encoder_helper_add(encoder, &dce_v6_0_ext_helper_funcs);
  2599. break;
  2600. }
  2601. }
  2602. static const struct amdgpu_display_funcs dce_v6_0_display_funcs = {
  2603. .set_vga_render_state = &dce_v6_0_set_vga_render_state,
  2604. .bandwidth_update = &dce_v6_0_bandwidth_update,
  2605. .vblank_get_counter = &dce_v6_0_vblank_get_counter,
  2606. .vblank_wait = &dce_v6_0_vblank_wait,
  2607. .backlight_set_level = &amdgpu_atombios_encoder_set_backlight_level,
  2608. .backlight_get_level = &amdgpu_atombios_encoder_get_backlight_level,
  2609. .hpd_sense = &dce_v6_0_hpd_sense,
  2610. .hpd_set_polarity = &dce_v6_0_hpd_set_polarity,
  2611. .hpd_get_gpio_reg = &dce_v6_0_hpd_get_gpio_reg,
  2612. .page_flip = &dce_v6_0_page_flip,
  2613. .page_flip_get_scanoutpos = &dce_v6_0_crtc_get_scanoutpos,
  2614. .add_encoder = &dce_v6_0_encoder_add,
  2615. .add_connector = &amdgpu_connector_add,
  2616. .stop_mc_access = &dce_v6_0_stop_mc_access,
  2617. .resume_mc_access = &dce_v6_0_resume_mc_access,
  2618. };
  2619. static void dce_v6_0_set_display_funcs(struct amdgpu_device *adev)
  2620. {
  2621. if (adev->mode_info.funcs == NULL)
  2622. adev->mode_info.funcs = &dce_v6_0_display_funcs;
  2623. }
  2624. static const struct amdgpu_irq_src_funcs dce_v6_0_crtc_irq_funcs = {
  2625. .set = dce_v6_0_set_crtc_interrupt_state,
  2626. .process = dce_v6_0_crtc_irq,
  2627. };
  2628. static const struct amdgpu_irq_src_funcs dce_v6_0_pageflip_irq_funcs = {
  2629. .set = dce_v6_0_set_pageflip_interrupt_state,
  2630. .process = dce_v6_0_pageflip_irq,
  2631. };
  2632. static const struct amdgpu_irq_src_funcs dce_v6_0_hpd_irq_funcs = {
  2633. .set = dce_v6_0_set_hpd_interrupt_state,
  2634. .process = dce_v6_0_hpd_irq,
  2635. };
  2636. static void dce_v6_0_set_irq_funcs(struct amdgpu_device *adev)
  2637. {
  2638. adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_LAST;
  2639. adev->crtc_irq.funcs = &dce_v6_0_crtc_irq_funcs;
  2640. adev->pageflip_irq.num_types = AMDGPU_PAGEFLIP_IRQ_LAST;
  2641. adev->pageflip_irq.funcs = &dce_v6_0_pageflip_irq_funcs;
  2642. adev->hpd_irq.num_types = AMDGPU_HPD_LAST;
  2643. adev->hpd_irq.funcs = &dce_v6_0_hpd_irq_funcs;
  2644. }
  2645. const struct amdgpu_ip_block_version dce_v6_0_ip_block =
  2646. {
  2647. .type = AMD_IP_BLOCK_TYPE_DCE,
  2648. .major = 6,
  2649. .minor = 0,
  2650. .rev = 0,
  2651. .funcs = &dce_v6_0_ip_funcs,
  2652. };
  2653. const struct amdgpu_ip_block_version dce_v6_4_ip_block =
  2654. {
  2655. .type = AMD_IP_BLOCK_TYPE_DCE,
  2656. .major = 6,
  2657. .minor = 4,
  2658. .rev = 0,
  2659. .funcs = &dce_v6_0_ip_funcs,
  2660. };