dce_v6_0.c 89 KB

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