dce_v6_0.c 90 KB

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