dce_v8_0.c 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #include "drmP.h"
  24. #include "amdgpu.h"
  25. #include "amdgpu_pm.h"
  26. #include "amdgpu_i2c.h"
  27. #include "cikd.h"
  28. #include "atom.h"
  29. #include "amdgpu_atombios.h"
  30. #include "atombios_crtc.h"
  31. #include "atombios_encoders.h"
  32. #include "amdgpu_pll.h"
  33. #include "amdgpu_connectors.h"
  34. #include "dce/dce_8_0_d.h"
  35. #include "dce/dce_8_0_sh_mask.h"
  36. #include "gca/gfx_7_2_enum.h"
  37. #include "gmc/gmc_7_1_d.h"
  38. #include "gmc/gmc_7_1_sh_mask.h"
  39. #include "oss/oss_2_0_d.h"
  40. #include "oss/oss_2_0_sh_mask.h"
  41. static void dce_v8_0_set_display_funcs(struct amdgpu_device *adev);
  42. static void dce_v8_0_set_irq_funcs(struct amdgpu_device *adev);
  43. static const u32 crtc_offsets[6] =
  44. {
  45. CRTC0_REGISTER_OFFSET,
  46. CRTC1_REGISTER_OFFSET,
  47. CRTC2_REGISTER_OFFSET,
  48. CRTC3_REGISTER_OFFSET,
  49. CRTC4_REGISTER_OFFSET,
  50. CRTC5_REGISTER_OFFSET
  51. };
  52. static const uint32_t dig_offsets[] = {
  53. CRTC0_REGISTER_OFFSET,
  54. CRTC1_REGISTER_OFFSET,
  55. CRTC2_REGISTER_OFFSET,
  56. CRTC3_REGISTER_OFFSET,
  57. CRTC4_REGISTER_OFFSET,
  58. CRTC5_REGISTER_OFFSET,
  59. (0x13830 - 0x7030) >> 2,
  60. };
  61. static const struct {
  62. uint32_t reg;
  63. uint32_t vblank;
  64. uint32_t vline;
  65. uint32_t hpd;
  66. } interrupt_status_offsets[6] = { {
  67. .reg = mmDISP_INTERRUPT_STATUS,
  68. .vblank = DISP_INTERRUPT_STATUS__LB_D1_VBLANK_INTERRUPT_MASK,
  69. .vline = DISP_INTERRUPT_STATUS__LB_D1_VLINE_INTERRUPT_MASK,
  70. .hpd = DISP_INTERRUPT_STATUS__DC_HPD1_INTERRUPT_MASK
  71. }, {
  72. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE,
  73. .vblank = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VBLANK_INTERRUPT_MASK,
  74. .vline = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VLINE_INTERRUPT_MASK,
  75. .hpd = DISP_INTERRUPT_STATUS_CONTINUE__DC_HPD2_INTERRUPT_MASK
  76. }, {
  77. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE2,
  78. .vblank = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VBLANK_INTERRUPT_MASK,
  79. .vline = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VLINE_INTERRUPT_MASK,
  80. .hpd = DISP_INTERRUPT_STATUS_CONTINUE2__DC_HPD3_INTERRUPT_MASK
  81. }, {
  82. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE3,
  83. .vblank = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VBLANK_INTERRUPT_MASK,
  84. .vline = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VLINE_INTERRUPT_MASK,
  85. .hpd = DISP_INTERRUPT_STATUS_CONTINUE3__DC_HPD4_INTERRUPT_MASK
  86. }, {
  87. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE4,
  88. .vblank = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VBLANK_INTERRUPT_MASK,
  89. .vline = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VLINE_INTERRUPT_MASK,
  90. .hpd = DISP_INTERRUPT_STATUS_CONTINUE4__DC_HPD5_INTERRUPT_MASK
  91. }, {
  92. .reg = mmDISP_INTERRUPT_STATUS_CONTINUE5,
  93. .vblank = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VBLANK_INTERRUPT_MASK,
  94. .vline = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VLINE_INTERRUPT_MASK,
  95. .hpd = DISP_INTERRUPT_STATUS_CONTINUE5__DC_HPD6_INTERRUPT_MASK
  96. } };
  97. static const uint32_t hpd_int_control_offsets[6] = {
  98. mmDC_HPD1_INT_CONTROL,
  99. mmDC_HPD2_INT_CONTROL,
  100. mmDC_HPD3_INT_CONTROL,
  101. mmDC_HPD4_INT_CONTROL,
  102. mmDC_HPD5_INT_CONTROL,
  103. mmDC_HPD6_INT_CONTROL,
  104. };
  105. static u32 dce_v8_0_audio_endpt_rreg(struct amdgpu_device *adev,
  106. u32 block_offset, u32 reg)
  107. {
  108. unsigned long flags;
  109. u32 r;
  110. spin_lock_irqsave(&adev->audio_endpt_idx_lock, flags);
  111. WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX + block_offset, reg);
  112. r = RREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA + block_offset);
  113. spin_unlock_irqrestore(&adev->audio_endpt_idx_lock, flags);
  114. return r;
  115. }
  116. static void dce_v8_0_audio_endpt_wreg(struct amdgpu_device *adev,
  117. u32 block_offset, u32 reg, u32 v)
  118. {
  119. unsigned long flags;
  120. spin_lock_irqsave(&adev->audio_endpt_idx_lock, flags);
  121. WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX + block_offset, reg);
  122. WREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA + block_offset, v);
  123. spin_unlock_irqrestore(&adev->audio_endpt_idx_lock, flags);
  124. }
  125. static bool dce_v8_0_is_in_vblank(struct amdgpu_device *adev, int crtc)
  126. {
  127. if (RREG32(mmCRTC_STATUS + crtc_offsets[crtc]) &
  128. CRTC_V_BLANK_START_END__CRTC_V_BLANK_START_MASK)
  129. return true;
  130. else
  131. return false;
  132. }
  133. static bool dce_v8_0_is_counter_moving(struct amdgpu_device *adev, int crtc)
  134. {
  135. u32 pos1, pos2;
  136. pos1 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  137. pos2 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  138. if (pos1 != pos2)
  139. return true;
  140. else
  141. return false;
  142. }
  143. /**
  144. * dce_v8_0_vblank_wait - vblank wait asic callback.
  145. *
  146. * @adev: amdgpu_device pointer
  147. * @crtc: crtc to wait for vblank on
  148. *
  149. * Wait for vblank on the requested crtc (evergreen+).
  150. */
  151. static void dce_v8_0_vblank_wait(struct amdgpu_device *adev, int crtc)
  152. {
  153. unsigned i = 0;
  154. if (crtc >= adev->mode_info.num_crtc)
  155. return;
  156. if (!(RREG32(mmCRTC_CONTROL + crtc_offsets[crtc]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK))
  157. return;
  158. /* depending on when we hit vblank, we may be close to active; if so,
  159. * wait for another frame.
  160. */
  161. while (dce_v8_0_is_in_vblank(adev, crtc)) {
  162. if (i++ % 100 == 0) {
  163. if (!dce_v8_0_is_counter_moving(adev, crtc))
  164. break;
  165. }
  166. }
  167. while (!dce_v8_0_is_in_vblank(adev, crtc)) {
  168. if (i++ % 100 == 0) {
  169. if (!dce_v8_0_is_counter_moving(adev, crtc))
  170. break;
  171. }
  172. }
  173. }
  174. static u32 dce_v8_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
  175. {
  176. if (crtc >= adev->mode_info.num_crtc)
  177. return 0;
  178. else
  179. return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
  180. }
  181. static void dce_v8_0_pageflip_interrupt_init(struct amdgpu_device *adev)
  182. {
  183. unsigned i;
  184. /* Enable pflip interrupts */
  185. for (i = 0; i < adev->mode_info.num_crtc; i++)
  186. amdgpu_irq_get(adev, &adev->pageflip_irq, i);
  187. }
  188. static void dce_v8_0_pageflip_interrupt_fini(struct amdgpu_device *adev)
  189. {
  190. unsigned i;
  191. /* Disable pflip interrupts */
  192. for (i = 0; i < adev->mode_info.num_crtc; i++)
  193. amdgpu_irq_put(adev, &adev->pageflip_irq, i);
  194. }
  195. /**
  196. * dce_v8_0_page_flip - pageflip callback.
  197. *
  198. * @adev: amdgpu_device pointer
  199. * @crtc_id: crtc to cleanup pageflip on
  200. * @crtc_base: new address of the crtc (GPU MC address)
  201. *
  202. * Triggers the actual pageflip by updating the primary
  203. * surface base address.
  204. */
  205. static void dce_v8_0_page_flip(struct amdgpu_device *adev,
  206. int crtc_id, u64 crtc_base)
  207. {
  208. struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
  209. /* update the primary scanout addresses */
  210. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  211. upper_32_bits(crtc_base));
  212. /* writing to the low address triggers the update */
  213. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  214. lower_32_bits(crtc_base));
  215. /* post the write */
  216. RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
  217. }
  218. static int dce_v8_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
  219. u32 *vbl, u32 *position)
  220. {
  221. if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
  222. return -EINVAL;
  223. *vbl = RREG32(mmCRTC_V_BLANK_START_END + crtc_offsets[crtc]);
  224. *position = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
  225. return 0;
  226. }
  227. /**
  228. * dce_v8_0_hpd_sense - hpd sense callback.
  229. *
  230. * @adev: amdgpu_device pointer
  231. * @hpd: hpd (hotplug detect) pin
  232. *
  233. * Checks if a digital monitor is connected (evergreen+).
  234. * Returns true if connected, false if not connected.
  235. */
  236. static bool dce_v8_0_hpd_sense(struct amdgpu_device *adev,
  237. enum amdgpu_hpd_id hpd)
  238. {
  239. bool connected = false;
  240. switch (hpd) {
  241. case AMDGPU_HPD_1:
  242. if (RREG32(mmDC_HPD1_INT_STATUS) & DC_HPD1_INT_STATUS__DC_HPD1_SENSE_MASK)
  243. connected = true;
  244. break;
  245. case AMDGPU_HPD_2:
  246. if (RREG32(mmDC_HPD2_INT_STATUS) & DC_HPD2_INT_STATUS__DC_HPD2_SENSE_MASK)
  247. connected = true;
  248. break;
  249. case AMDGPU_HPD_3:
  250. if (RREG32(mmDC_HPD3_INT_STATUS) & DC_HPD3_INT_STATUS__DC_HPD3_SENSE_MASK)
  251. connected = true;
  252. break;
  253. case AMDGPU_HPD_4:
  254. if (RREG32(mmDC_HPD4_INT_STATUS) & DC_HPD4_INT_STATUS__DC_HPD4_SENSE_MASK)
  255. connected = true;
  256. break;
  257. case AMDGPU_HPD_5:
  258. if (RREG32(mmDC_HPD5_INT_STATUS) & DC_HPD5_INT_STATUS__DC_HPD5_SENSE_MASK)
  259. connected = true;
  260. break;
  261. case AMDGPU_HPD_6:
  262. if (RREG32(mmDC_HPD6_INT_STATUS) & DC_HPD6_INT_STATUS__DC_HPD6_SENSE_MASK)
  263. connected = true;
  264. break;
  265. default:
  266. break;
  267. }
  268. return connected;
  269. }
  270. /**
  271. * dce_v8_0_hpd_set_polarity - hpd set polarity callback.
  272. *
  273. * @adev: amdgpu_device pointer
  274. * @hpd: hpd (hotplug detect) pin
  275. *
  276. * Set the polarity of the hpd pin (evergreen+).
  277. */
  278. static void dce_v8_0_hpd_set_polarity(struct amdgpu_device *adev,
  279. enum amdgpu_hpd_id hpd)
  280. {
  281. u32 tmp;
  282. bool connected = dce_v8_0_hpd_sense(adev, hpd);
  283. switch (hpd) {
  284. case AMDGPU_HPD_1:
  285. tmp = RREG32(mmDC_HPD1_INT_CONTROL);
  286. if (connected)
  287. tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
  288. else
  289. tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
  290. WREG32(mmDC_HPD1_INT_CONTROL, tmp);
  291. break;
  292. case AMDGPU_HPD_2:
  293. tmp = RREG32(mmDC_HPD2_INT_CONTROL);
  294. if (connected)
  295. tmp &= ~DC_HPD2_INT_CONTROL__DC_HPD2_INT_POLARITY_MASK;
  296. else
  297. tmp |= DC_HPD2_INT_CONTROL__DC_HPD2_INT_POLARITY_MASK;
  298. WREG32(mmDC_HPD2_INT_CONTROL, tmp);
  299. break;
  300. case AMDGPU_HPD_3:
  301. tmp = RREG32(mmDC_HPD3_INT_CONTROL);
  302. if (connected)
  303. tmp &= ~DC_HPD3_INT_CONTROL__DC_HPD3_INT_POLARITY_MASK;
  304. else
  305. tmp |= DC_HPD3_INT_CONTROL__DC_HPD3_INT_POLARITY_MASK;
  306. WREG32(mmDC_HPD3_INT_CONTROL, tmp);
  307. break;
  308. case AMDGPU_HPD_4:
  309. tmp = RREG32(mmDC_HPD4_INT_CONTROL);
  310. if (connected)
  311. tmp &= ~DC_HPD4_INT_CONTROL__DC_HPD4_INT_POLARITY_MASK;
  312. else
  313. tmp |= DC_HPD4_INT_CONTROL__DC_HPD4_INT_POLARITY_MASK;
  314. WREG32(mmDC_HPD4_INT_CONTROL, tmp);
  315. break;
  316. case AMDGPU_HPD_5:
  317. tmp = RREG32(mmDC_HPD5_INT_CONTROL);
  318. if (connected)
  319. tmp &= ~DC_HPD5_INT_CONTROL__DC_HPD5_INT_POLARITY_MASK;
  320. else
  321. tmp |= DC_HPD5_INT_CONTROL__DC_HPD5_INT_POLARITY_MASK;
  322. WREG32(mmDC_HPD5_INT_CONTROL, tmp);
  323. break;
  324. case AMDGPU_HPD_6:
  325. tmp = RREG32(mmDC_HPD6_INT_CONTROL);
  326. if (connected)
  327. tmp &= ~DC_HPD6_INT_CONTROL__DC_HPD6_INT_POLARITY_MASK;
  328. else
  329. tmp |= DC_HPD6_INT_CONTROL__DC_HPD6_INT_POLARITY_MASK;
  330. WREG32(mmDC_HPD6_INT_CONTROL, tmp);
  331. break;
  332. default:
  333. break;
  334. }
  335. }
  336. /**
  337. * dce_v8_0_hpd_init - hpd setup callback.
  338. *
  339. * @adev: amdgpu_device pointer
  340. *
  341. * Setup the hpd pins used by the card (evergreen+).
  342. * Enable the pin, set the polarity, and enable the hpd interrupts.
  343. */
  344. static void dce_v8_0_hpd_init(struct amdgpu_device *adev)
  345. {
  346. struct drm_device *dev = adev->ddev;
  347. struct drm_connector *connector;
  348. u32 tmp = (0x9c4 << DC_HPD1_CONTROL__DC_HPD1_CONNECTION_TIMER__SHIFT) |
  349. (0xfa << DC_HPD1_CONTROL__DC_HPD1_RX_INT_TIMER__SHIFT) |
  350. DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
  351. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  352. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  353. switch (amdgpu_connector->hpd.hpd) {
  354. case AMDGPU_HPD_1:
  355. WREG32(mmDC_HPD1_CONTROL, tmp);
  356. break;
  357. case AMDGPU_HPD_2:
  358. WREG32(mmDC_HPD2_CONTROL, tmp);
  359. break;
  360. case AMDGPU_HPD_3:
  361. WREG32(mmDC_HPD3_CONTROL, tmp);
  362. break;
  363. case AMDGPU_HPD_4:
  364. WREG32(mmDC_HPD4_CONTROL, tmp);
  365. break;
  366. case AMDGPU_HPD_5:
  367. WREG32(mmDC_HPD5_CONTROL, tmp);
  368. break;
  369. case AMDGPU_HPD_6:
  370. WREG32(mmDC_HPD6_CONTROL, tmp);
  371. break;
  372. default:
  373. break;
  374. }
  375. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  376. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  377. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  378. * aux dp channel on imac and help (but not completely fix)
  379. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  380. * also avoid interrupt storms during dpms.
  381. */
  382. u32 dc_hpd_int_cntl_reg, dc_hpd_int_cntl;
  383. switch (amdgpu_connector->hpd.hpd) {
  384. case AMDGPU_HPD_1:
  385. dc_hpd_int_cntl_reg = mmDC_HPD1_INT_CONTROL;
  386. break;
  387. case AMDGPU_HPD_2:
  388. dc_hpd_int_cntl_reg = mmDC_HPD2_INT_CONTROL;
  389. break;
  390. case AMDGPU_HPD_3:
  391. dc_hpd_int_cntl_reg = mmDC_HPD3_INT_CONTROL;
  392. break;
  393. case AMDGPU_HPD_4:
  394. dc_hpd_int_cntl_reg = mmDC_HPD4_INT_CONTROL;
  395. break;
  396. case AMDGPU_HPD_5:
  397. dc_hpd_int_cntl_reg = mmDC_HPD5_INT_CONTROL;
  398. break;
  399. case AMDGPU_HPD_6:
  400. dc_hpd_int_cntl_reg = mmDC_HPD6_INT_CONTROL;
  401. break;
  402. default:
  403. continue;
  404. }
  405. dc_hpd_int_cntl = RREG32(dc_hpd_int_cntl_reg);
  406. dc_hpd_int_cntl &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
  407. WREG32(dc_hpd_int_cntl_reg, dc_hpd_int_cntl);
  408. continue;
  409. }
  410. dce_v8_0_hpd_set_polarity(adev, amdgpu_connector->hpd.hpd);
  411. amdgpu_irq_get(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
  412. }
  413. }
  414. /**
  415. * dce_v8_0_hpd_fini - hpd tear down callback.
  416. *
  417. * @adev: amdgpu_device pointer
  418. *
  419. * Tear down the hpd pins used by the card (evergreen+).
  420. * Disable the hpd interrupts.
  421. */
  422. static void dce_v8_0_hpd_fini(struct amdgpu_device *adev)
  423. {
  424. struct drm_device *dev = adev->ddev;
  425. struct drm_connector *connector;
  426. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  427. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  428. switch (amdgpu_connector->hpd.hpd) {
  429. case AMDGPU_HPD_1:
  430. WREG32(mmDC_HPD1_CONTROL, 0);
  431. break;
  432. case AMDGPU_HPD_2:
  433. WREG32(mmDC_HPD2_CONTROL, 0);
  434. break;
  435. case AMDGPU_HPD_3:
  436. WREG32(mmDC_HPD3_CONTROL, 0);
  437. break;
  438. case AMDGPU_HPD_4:
  439. WREG32(mmDC_HPD4_CONTROL, 0);
  440. break;
  441. case AMDGPU_HPD_5:
  442. WREG32(mmDC_HPD5_CONTROL, 0);
  443. break;
  444. case AMDGPU_HPD_6:
  445. WREG32(mmDC_HPD6_CONTROL, 0);
  446. break;
  447. default:
  448. break;
  449. }
  450. amdgpu_irq_put(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
  451. }
  452. }
  453. static u32 dce_v8_0_hpd_get_gpio_reg(struct amdgpu_device *adev)
  454. {
  455. return mmDC_GPIO_HPD_A;
  456. }
  457. static bool dce_v8_0_is_display_hung(struct amdgpu_device *adev)
  458. {
  459. u32 crtc_hung = 0;
  460. u32 crtc_status[6];
  461. u32 i, j, tmp;
  462. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  463. if (RREG32(mmCRTC_CONTROL + crtc_offsets[i]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK) {
  464. crtc_status[i] = RREG32(mmCRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  465. crtc_hung |= (1 << i);
  466. }
  467. }
  468. for (j = 0; j < 10; j++) {
  469. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  470. if (crtc_hung & (1 << i)) {
  471. tmp = RREG32(mmCRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  472. if (tmp != crtc_status[i])
  473. crtc_hung &= ~(1 << i);
  474. }
  475. }
  476. if (crtc_hung == 0)
  477. return false;
  478. udelay(100);
  479. }
  480. return true;
  481. }
  482. static void dce_v8_0_stop_mc_access(struct amdgpu_device *adev,
  483. struct amdgpu_mode_mc_save *save)
  484. {
  485. u32 crtc_enabled, tmp;
  486. int i;
  487. save->vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
  488. save->vga_hdp_control = RREG32(mmVGA_HDP_CONTROL);
  489. /* disable VGA render */
  490. tmp = RREG32(mmVGA_RENDER_CONTROL);
  491. tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0);
  492. WREG32(mmVGA_RENDER_CONTROL, tmp);
  493. /* blank the display controllers */
  494. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  495. crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]),
  496. CRTC_CONTROL, CRTC_MASTER_EN);
  497. if (crtc_enabled) {
  498. #if 0
  499. u32 frame_count;
  500. int j;
  501. save->crtc_enabled[i] = true;
  502. tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
  503. if (REG_GET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN) == 0) {
  504. amdgpu_display_vblank_wait(adev, i);
  505. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  506. tmp = REG_SET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN, 1);
  507. WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  508. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  509. }
  510. /* wait for the next frame */
  511. frame_count = amdgpu_display_vblank_get_counter(adev, i);
  512. for (j = 0; j < adev->usec_timeout; j++) {
  513. if (amdgpu_display_vblank_get_counter(adev, i) != frame_count)
  514. break;
  515. udelay(1);
  516. }
  517. tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
  518. if (REG_GET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK) == 0) {
  519. tmp = REG_SET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK, 1);
  520. WREG32(mmGRPH_UPDATE + crtc_offsets[i], tmp);
  521. }
  522. tmp = RREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i]);
  523. if (REG_GET_FIELD(tmp, MASTER_UPDATE_LOCK, MASTER_UPDATE_LOCK) == 0) {
  524. tmp = REG_SET_FIELD(tmp, MASTER_UPDATE_LOCK, MASTER_UPDATE_LOCK, 1);
  525. WREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  526. }
  527. #else
  528. /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
  529. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  530. tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
  531. tmp = REG_SET_FIELD(tmp, CRTC_CONTROL, CRTC_MASTER_EN, 0);
  532. WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
  533. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  534. save->crtc_enabled[i] = false;
  535. /* ***** */
  536. #endif
  537. } else {
  538. save->crtc_enabled[i] = false;
  539. }
  540. }
  541. }
  542. static void dce_v8_0_resume_mc_access(struct amdgpu_device *adev,
  543. struct amdgpu_mode_mc_save *save)
  544. {
  545. u32 tmp, frame_count;
  546. int i, j;
  547. /* update crtc base addresses */
  548. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  549. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  550. upper_32_bits(adev->mc.vram_start));
  551. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  552. upper_32_bits(adev->mc.vram_start));
  553. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
  554. (u32)adev->mc.vram_start);
  555. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
  556. (u32)adev->mc.vram_start);
  557. if (save->crtc_enabled[i]) {
  558. tmp = RREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i]);
  559. if (REG_GET_FIELD(tmp, MASTER_UPDATE_MODE, MASTER_UPDATE_MODE) != 3) {
  560. tmp = REG_SET_FIELD(tmp, MASTER_UPDATE_MODE, MASTER_UPDATE_MODE, 3);
  561. WREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i], tmp);
  562. }
  563. tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
  564. if (REG_GET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK)) {
  565. tmp = REG_SET_FIELD(tmp, GRPH_UPDATE, GRPH_UPDATE_LOCK, 0);
  566. WREG32(mmGRPH_UPDATE + crtc_offsets[i], tmp);
  567. }
  568. tmp = RREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i]);
  569. if (REG_GET_FIELD(tmp, MASTER_UPDATE_LOCK, MASTER_UPDATE_LOCK)) {
  570. tmp = REG_SET_FIELD(tmp, MASTER_UPDATE_LOCK, MASTER_UPDATE_LOCK, 0);
  571. WREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  572. }
  573. for (j = 0; j < adev->usec_timeout; j++) {
  574. tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
  575. if (REG_GET_FIELD(tmp, GRPH_UPDATE, GRPH_SURFACE_UPDATE_PENDING) == 0)
  576. break;
  577. udelay(1);
  578. }
  579. tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
  580. tmp = REG_SET_FIELD(tmp, CRTC_BLANK_CONTROL, CRTC_BLANK_DATA_EN, 0);
  581. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  582. WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  583. WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  584. /* wait for the next frame */
  585. frame_count = amdgpu_display_vblank_get_counter(adev, i);
  586. for (j = 0; j < adev->usec_timeout; j++) {
  587. if (amdgpu_display_vblank_get_counter(adev, i) != frame_count)
  588. break;
  589. udelay(1);
  590. }
  591. }
  592. }
  593. WREG32(mmVGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(adev->mc.vram_start));
  594. WREG32(mmVGA_MEMORY_BASE_ADDRESS, lower_32_bits(adev->mc.vram_start));
  595. /* Unlock vga access */
  596. WREG32(mmVGA_HDP_CONTROL, save->vga_hdp_control);
  597. mdelay(1);
  598. WREG32(mmVGA_RENDER_CONTROL, save->vga_render_control);
  599. }
  600. static void dce_v8_0_set_vga_render_state(struct amdgpu_device *adev,
  601. bool render)
  602. {
  603. u32 tmp;
  604. /* Lockout access through VGA aperture*/
  605. tmp = RREG32(mmVGA_HDP_CONTROL);
  606. if (render)
  607. tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 0);
  608. else
  609. tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 1);
  610. WREG32(mmVGA_HDP_CONTROL, tmp);
  611. /* disable VGA render */
  612. tmp = RREG32(mmVGA_RENDER_CONTROL);
  613. if (render)
  614. tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 1);
  615. else
  616. tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0);
  617. WREG32(mmVGA_RENDER_CONTROL, tmp);
  618. }
  619. static void dce_v8_0_program_fmt(struct drm_encoder *encoder)
  620. {
  621. struct drm_device *dev = encoder->dev;
  622. struct amdgpu_device *adev = dev->dev_private;
  623. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  624. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
  625. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  626. int bpc = 0;
  627. u32 tmp = 0;
  628. enum amdgpu_connector_dither dither = AMDGPU_FMT_DITHER_DISABLE;
  629. if (connector) {
  630. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  631. bpc = amdgpu_connector_get_monitor_bpc(connector);
  632. dither = amdgpu_connector->dither;
  633. }
  634. /* LVDS/eDP FMT is set up by atom */
  635. if (amdgpu_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  636. return;
  637. /* not needed for analog */
  638. if ((amdgpu_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
  639. (amdgpu_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
  640. return;
  641. if (bpc == 0)
  642. return;
  643. switch (bpc) {
  644. case 6:
  645. if (dither == AMDGPU_FMT_DITHER_ENABLE)
  646. /* XXX sort out optimal dither settings */
  647. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
  648. FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
  649. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
  650. (0 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
  651. else
  652. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
  653. (0 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
  654. break;
  655. case 8:
  656. if (dither == AMDGPU_FMT_DITHER_ENABLE)
  657. /* XXX sort out optimal dither settings */
  658. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
  659. FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
  660. FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
  661. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
  662. (1 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
  663. else
  664. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
  665. (1 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
  666. break;
  667. case 10:
  668. if (dither == AMDGPU_FMT_DITHER_ENABLE)
  669. /* XXX sort out optimal dither settings */
  670. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
  671. FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
  672. FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
  673. FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
  674. (2 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
  675. else
  676. tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
  677. (2 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
  678. break;
  679. default:
  680. /* not needed */
  681. break;
  682. }
  683. WREG32(mmFMT_BIT_DEPTH_CONTROL + amdgpu_crtc->crtc_offset, tmp);
  684. }
  685. /* display watermark setup */
  686. /**
  687. * dce_v8_0_line_buffer_adjust - Set up the line buffer
  688. *
  689. * @adev: amdgpu_device pointer
  690. * @amdgpu_crtc: the selected display controller
  691. * @mode: the current display mode on the selected display
  692. * controller
  693. *
  694. * Setup up the line buffer allocation for
  695. * the selected display controller (CIK).
  696. * Returns the line buffer size in pixels.
  697. */
  698. static u32 dce_v8_0_line_buffer_adjust(struct amdgpu_device *adev,
  699. struct amdgpu_crtc *amdgpu_crtc,
  700. struct drm_display_mode *mode)
  701. {
  702. u32 tmp, buffer_alloc, i;
  703. u32 pipe_offset = amdgpu_crtc->crtc_id * 0x8;
  704. /*
  705. * Line Buffer Setup
  706. * There are 6 line buffers, one for each display controllers.
  707. * There are 3 partitions per LB. Select the number of partitions
  708. * to enable based on the display width. For display widths larger
  709. * than 4096, you need use to use 2 display controllers and combine
  710. * them using the stereo blender.
  711. */
  712. if (amdgpu_crtc->base.enabled && mode) {
  713. if (mode->crtc_hdisplay < 1920) {
  714. tmp = 1;
  715. buffer_alloc = 2;
  716. } else if (mode->crtc_hdisplay < 2560) {
  717. tmp = 2;
  718. buffer_alloc = 2;
  719. } else if (mode->crtc_hdisplay < 4096) {
  720. tmp = 0;
  721. buffer_alloc = (adev->flags & AMD_IS_APU) ? 2 : 4;
  722. } else {
  723. DRM_DEBUG_KMS("Mode too big for LB!\n");
  724. tmp = 0;
  725. buffer_alloc = (adev->flags & AMD_IS_APU) ? 2 : 4;
  726. }
  727. } else {
  728. tmp = 1;
  729. buffer_alloc = 0;
  730. }
  731. WREG32(mmLB_MEMORY_CTRL + amdgpu_crtc->crtc_offset,
  732. (tmp << LB_MEMORY_CTRL__LB_MEMORY_CONFIG__SHIFT) |
  733. (0x6B0 << LB_MEMORY_CTRL__LB_MEMORY_SIZE__SHIFT));
  734. WREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  735. (buffer_alloc << PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATED__SHIFT));
  736. for (i = 0; i < adev->usec_timeout; i++) {
  737. if (RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  738. PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATION_COMPLETED_MASK)
  739. break;
  740. udelay(1);
  741. }
  742. if (amdgpu_crtc->base.enabled && mode) {
  743. switch (tmp) {
  744. case 0:
  745. default:
  746. return 4096 * 2;
  747. case 1:
  748. return 1920 * 2;
  749. case 2:
  750. return 2560 * 2;
  751. }
  752. }
  753. /* controller not enabled, so no lb used */
  754. return 0;
  755. }
  756. /**
  757. * cik_get_number_of_dram_channels - get the number of dram channels
  758. *
  759. * @adev: amdgpu_device pointer
  760. *
  761. * Look up the number of video ram channels (CIK).
  762. * Used for display watermark bandwidth calculations
  763. * Returns the number of dram channels
  764. */
  765. static u32 cik_get_number_of_dram_channels(struct amdgpu_device *adev)
  766. {
  767. u32 tmp = RREG32(mmMC_SHARED_CHMAP);
  768. switch ((tmp & MC_SHARED_CHMAP__NOOFCHAN_MASK) >> MC_SHARED_CHMAP__NOOFCHAN__SHIFT) {
  769. case 0:
  770. default:
  771. return 1;
  772. case 1:
  773. return 2;
  774. case 2:
  775. return 4;
  776. case 3:
  777. return 8;
  778. case 4:
  779. return 3;
  780. case 5:
  781. return 6;
  782. case 6:
  783. return 10;
  784. case 7:
  785. return 12;
  786. case 8:
  787. return 16;
  788. }
  789. }
  790. struct dce8_wm_params {
  791. u32 dram_channels; /* number of dram channels */
  792. u32 yclk; /* bandwidth per dram data pin in kHz */
  793. u32 sclk; /* engine clock in kHz */
  794. u32 disp_clk; /* display clock in kHz */
  795. u32 src_width; /* viewport width */
  796. u32 active_time; /* active display time in ns */
  797. u32 blank_time; /* blank time in ns */
  798. bool interlaced; /* mode is interlaced */
  799. fixed20_12 vsc; /* vertical scale ratio */
  800. u32 num_heads; /* number of active crtcs */
  801. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  802. u32 lb_size; /* line buffer allocated to pipe */
  803. u32 vtaps; /* vertical scaler taps */
  804. };
  805. /**
  806. * dce_v8_0_dram_bandwidth - get the dram bandwidth
  807. *
  808. * @wm: watermark calculation data
  809. *
  810. * Calculate the raw dram bandwidth (CIK).
  811. * Used for display watermark bandwidth calculations
  812. * Returns the dram bandwidth in MBytes/s
  813. */
  814. static u32 dce_v8_0_dram_bandwidth(struct dce8_wm_params *wm)
  815. {
  816. /* Calculate raw DRAM Bandwidth */
  817. fixed20_12 dram_efficiency; /* 0.7 */
  818. fixed20_12 yclk, dram_channels, bandwidth;
  819. fixed20_12 a;
  820. a.full = dfixed_const(1000);
  821. yclk.full = dfixed_const(wm->yclk);
  822. yclk.full = dfixed_div(yclk, a);
  823. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  824. a.full = dfixed_const(10);
  825. dram_efficiency.full = dfixed_const(7);
  826. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  827. bandwidth.full = dfixed_mul(dram_channels, yclk);
  828. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  829. return dfixed_trunc(bandwidth);
  830. }
  831. /**
  832. * dce_v8_0_dram_bandwidth_for_display - get the dram bandwidth for display
  833. *
  834. * @wm: watermark calculation data
  835. *
  836. * Calculate the dram bandwidth used for display (CIK).
  837. * Used for display watermark bandwidth calculations
  838. * Returns the dram bandwidth for display in MBytes/s
  839. */
  840. static u32 dce_v8_0_dram_bandwidth_for_display(struct dce8_wm_params *wm)
  841. {
  842. /* Calculate DRAM Bandwidth and the part allocated to display. */
  843. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  844. fixed20_12 yclk, dram_channels, bandwidth;
  845. fixed20_12 a;
  846. a.full = dfixed_const(1000);
  847. yclk.full = dfixed_const(wm->yclk);
  848. yclk.full = dfixed_div(yclk, a);
  849. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  850. a.full = dfixed_const(10);
  851. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  852. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  853. bandwidth.full = dfixed_mul(dram_channels, yclk);
  854. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  855. return dfixed_trunc(bandwidth);
  856. }
  857. /**
  858. * dce_v8_0_data_return_bandwidth - get the data return bandwidth
  859. *
  860. * @wm: watermark calculation data
  861. *
  862. * Calculate the data return bandwidth used for display (CIK).
  863. * Used for display watermark bandwidth calculations
  864. * Returns the data return bandwidth in MBytes/s
  865. */
  866. static u32 dce_v8_0_data_return_bandwidth(struct dce8_wm_params *wm)
  867. {
  868. /* Calculate the display Data return Bandwidth */
  869. fixed20_12 return_efficiency; /* 0.8 */
  870. fixed20_12 sclk, bandwidth;
  871. fixed20_12 a;
  872. a.full = dfixed_const(1000);
  873. sclk.full = dfixed_const(wm->sclk);
  874. sclk.full = dfixed_div(sclk, a);
  875. a.full = dfixed_const(10);
  876. return_efficiency.full = dfixed_const(8);
  877. return_efficiency.full = dfixed_div(return_efficiency, a);
  878. a.full = dfixed_const(32);
  879. bandwidth.full = dfixed_mul(a, sclk);
  880. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  881. return dfixed_trunc(bandwidth);
  882. }
  883. /**
  884. * dce_v8_0_dmif_request_bandwidth - get the dmif bandwidth
  885. *
  886. * @wm: watermark calculation data
  887. *
  888. * Calculate the dmif bandwidth used for display (CIK).
  889. * Used for display watermark bandwidth calculations
  890. * Returns the dmif bandwidth in MBytes/s
  891. */
  892. static u32 dce_v8_0_dmif_request_bandwidth(struct dce8_wm_params *wm)
  893. {
  894. /* Calculate the DMIF Request Bandwidth */
  895. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  896. fixed20_12 disp_clk, bandwidth;
  897. fixed20_12 a, b;
  898. a.full = dfixed_const(1000);
  899. disp_clk.full = dfixed_const(wm->disp_clk);
  900. disp_clk.full = dfixed_div(disp_clk, a);
  901. a.full = dfixed_const(32);
  902. b.full = dfixed_mul(a, disp_clk);
  903. a.full = dfixed_const(10);
  904. disp_clk_request_efficiency.full = dfixed_const(8);
  905. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  906. bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
  907. return dfixed_trunc(bandwidth);
  908. }
  909. /**
  910. * dce_v8_0_available_bandwidth - get the min available bandwidth
  911. *
  912. * @wm: watermark calculation data
  913. *
  914. * Calculate the min available bandwidth used for display (CIK).
  915. * Used for display watermark bandwidth calculations
  916. * Returns the min available bandwidth in MBytes/s
  917. */
  918. static u32 dce_v8_0_available_bandwidth(struct dce8_wm_params *wm)
  919. {
  920. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  921. u32 dram_bandwidth = dce_v8_0_dram_bandwidth(wm);
  922. u32 data_return_bandwidth = dce_v8_0_data_return_bandwidth(wm);
  923. u32 dmif_req_bandwidth = dce_v8_0_dmif_request_bandwidth(wm);
  924. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  925. }
  926. /**
  927. * dce_v8_0_average_bandwidth - get the average available bandwidth
  928. *
  929. * @wm: watermark calculation data
  930. *
  931. * Calculate the average available bandwidth used for display (CIK).
  932. * Used for display watermark bandwidth calculations
  933. * Returns the average available bandwidth in MBytes/s
  934. */
  935. static u32 dce_v8_0_average_bandwidth(struct dce8_wm_params *wm)
  936. {
  937. /* Calculate the display mode Average Bandwidth
  938. * DisplayMode should contain the source and destination dimensions,
  939. * timing, etc.
  940. */
  941. fixed20_12 bpp;
  942. fixed20_12 line_time;
  943. fixed20_12 src_width;
  944. fixed20_12 bandwidth;
  945. fixed20_12 a;
  946. a.full = dfixed_const(1000);
  947. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  948. line_time.full = dfixed_div(line_time, a);
  949. bpp.full = dfixed_const(wm->bytes_per_pixel);
  950. src_width.full = dfixed_const(wm->src_width);
  951. bandwidth.full = dfixed_mul(src_width, bpp);
  952. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  953. bandwidth.full = dfixed_div(bandwidth, line_time);
  954. return dfixed_trunc(bandwidth);
  955. }
  956. /**
  957. * dce_v8_0_latency_watermark - get the latency watermark
  958. *
  959. * @wm: watermark calculation data
  960. *
  961. * Calculate the latency watermark (CIK).
  962. * Used for display watermark bandwidth calculations
  963. * Returns the latency watermark in ns
  964. */
  965. static u32 dce_v8_0_latency_watermark(struct dce8_wm_params *wm)
  966. {
  967. /* First calculate the latency in ns */
  968. u32 mc_latency = 2000; /* 2000 ns. */
  969. u32 available_bandwidth = dce_v8_0_available_bandwidth(wm);
  970. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  971. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  972. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  973. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  974. (wm->num_heads * cursor_line_pair_return_time);
  975. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  976. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  977. u32 tmp, dmif_size = 12288;
  978. fixed20_12 a, b, c;
  979. if (wm->num_heads == 0)
  980. return 0;
  981. a.full = dfixed_const(2);
  982. b.full = dfixed_const(1);
  983. if ((wm->vsc.full > a.full) ||
  984. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  985. (wm->vtaps >= 5) ||
  986. ((wm->vsc.full >= a.full) && wm->interlaced))
  987. max_src_lines_per_dst_line = 4;
  988. else
  989. max_src_lines_per_dst_line = 2;
  990. a.full = dfixed_const(available_bandwidth);
  991. b.full = dfixed_const(wm->num_heads);
  992. a.full = dfixed_div(a, b);
  993. tmp = div_u64((u64) dmif_size * (u64) wm->disp_clk, mc_latency + 512);
  994. tmp = min(dfixed_trunc(a), tmp);
  995. lb_fill_bw = min(tmp, wm->disp_clk * wm->bytes_per_pixel / 1000);
  996. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  997. b.full = dfixed_const(1000);
  998. c.full = dfixed_const(lb_fill_bw);
  999. b.full = dfixed_div(c, b);
  1000. a.full = dfixed_div(a, b);
  1001. line_fill_time = dfixed_trunc(a);
  1002. if (line_fill_time < wm->active_time)
  1003. return latency;
  1004. else
  1005. return latency + (line_fill_time - wm->active_time);
  1006. }
  1007. /**
  1008. * dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display - check
  1009. * average and available dram bandwidth
  1010. *
  1011. * @wm: watermark calculation data
  1012. *
  1013. * Check if the display average bandwidth fits in the display
  1014. * dram bandwidth (CIK).
  1015. * Used for display watermark bandwidth calculations
  1016. * Returns true if the display fits, false if not.
  1017. */
  1018. static bool dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
  1019. {
  1020. if (dce_v8_0_average_bandwidth(wm) <=
  1021. (dce_v8_0_dram_bandwidth_for_display(wm) / wm->num_heads))
  1022. return true;
  1023. else
  1024. return false;
  1025. }
  1026. /**
  1027. * dce_v8_0_average_bandwidth_vs_available_bandwidth - check
  1028. * average and available bandwidth
  1029. *
  1030. * @wm: watermark calculation data
  1031. *
  1032. * Check if the display average bandwidth fits in the display
  1033. * available bandwidth (CIK).
  1034. * Used for display watermark bandwidth calculations
  1035. * Returns true if the display fits, false if not.
  1036. */
  1037. static bool dce_v8_0_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
  1038. {
  1039. if (dce_v8_0_average_bandwidth(wm) <=
  1040. (dce_v8_0_available_bandwidth(wm) / wm->num_heads))
  1041. return true;
  1042. else
  1043. return false;
  1044. }
  1045. /**
  1046. * dce_v8_0_check_latency_hiding - check latency hiding
  1047. *
  1048. * @wm: watermark calculation data
  1049. *
  1050. * Check latency hiding (CIK).
  1051. * Used for display watermark bandwidth calculations
  1052. * Returns true if the display fits, false if not.
  1053. */
  1054. static bool dce_v8_0_check_latency_hiding(struct dce8_wm_params *wm)
  1055. {
  1056. u32 lb_partitions = wm->lb_size / wm->src_width;
  1057. u32 line_time = wm->active_time + wm->blank_time;
  1058. u32 latency_tolerant_lines;
  1059. u32 latency_hiding;
  1060. fixed20_12 a;
  1061. a.full = dfixed_const(1);
  1062. if (wm->vsc.full > a.full)
  1063. latency_tolerant_lines = 1;
  1064. else {
  1065. if (lb_partitions <= (wm->vtaps + 1))
  1066. latency_tolerant_lines = 1;
  1067. else
  1068. latency_tolerant_lines = 2;
  1069. }
  1070. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  1071. if (dce_v8_0_latency_watermark(wm) <= latency_hiding)
  1072. return true;
  1073. else
  1074. return false;
  1075. }
  1076. /**
  1077. * dce_v8_0_program_watermarks - program display watermarks
  1078. *
  1079. * @adev: amdgpu_device pointer
  1080. * @amdgpu_crtc: the selected display controller
  1081. * @lb_size: line buffer size
  1082. * @num_heads: number of display controllers in use
  1083. *
  1084. * Calculate and program the display watermarks for the
  1085. * selected display controller (CIK).
  1086. */
  1087. static void dce_v8_0_program_watermarks(struct amdgpu_device *adev,
  1088. struct amdgpu_crtc *amdgpu_crtc,
  1089. u32 lb_size, u32 num_heads)
  1090. {
  1091. struct drm_display_mode *mode = &amdgpu_crtc->base.mode;
  1092. struct dce8_wm_params wm_low, wm_high;
  1093. u32 active_time;
  1094. u32 line_time = 0;
  1095. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  1096. u32 tmp, wm_mask, lb_vblank_lead_lines = 0;
  1097. if (amdgpu_crtc->base.enabled && num_heads && mode) {
  1098. active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock;
  1099. line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535);
  1100. /* watermark for high clocks */
  1101. if (adev->pm.dpm_enabled) {
  1102. wm_high.yclk =
  1103. amdgpu_dpm_get_mclk(adev, false) * 10;
  1104. wm_high.sclk =
  1105. amdgpu_dpm_get_sclk(adev, false) * 10;
  1106. } else {
  1107. wm_high.yclk = adev->pm.current_mclk * 10;
  1108. wm_high.sclk = adev->pm.current_sclk * 10;
  1109. }
  1110. wm_high.disp_clk = mode->clock;
  1111. wm_high.src_width = mode->crtc_hdisplay;
  1112. wm_high.active_time = active_time;
  1113. wm_high.blank_time = line_time - wm_high.active_time;
  1114. wm_high.interlaced = false;
  1115. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1116. wm_high.interlaced = true;
  1117. wm_high.vsc = amdgpu_crtc->vsc;
  1118. wm_high.vtaps = 1;
  1119. if (amdgpu_crtc->rmx_type != RMX_OFF)
  1120. wm_high.vtaps = 2;
  1121. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1122. wm_high.lb_size = lb_size;
  1123. wm_high.dram_channels = cik_get_number_of_dram_channels(adev);
  1124. wm_high.num_heads = num_heads;
  1125. /* set for high clocks */
  1126. latency_watermark_a = min(dce_v8_0_latency_watermark(&wm_high), (u32)65535);
  1127. /* possibly force display priority to high */
  1128. /* should really do this at mode validation time... */
  1129. if (!dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  1130. !dce_v8_0_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  1131. !dce_v8_0_check_latency_hiding(&wm_high) ||
  1132. (adev->mode_info.disp_priority == 2)) {
  1133. DRM_DEBUG_KMS("force priority to high\n");
  1134. }
  1135. /* watermark for low clocks */
  1136. if (adev->pm.dpm_enabled) {
  1137. wm_low.yclk =
  1138. amdgpu_dpm_get_mclk(adev, true) * 10;
  1139. wm_low.sclk =
  1140. amdgpu_dpm_get_sclk(adev, true) * 10;
  1141. } else {
  1142. wm_low.yclk = adev->pm.current_mclk * 10;
  1143. wm_low.sclk = adev->pm.current_sclk * 10;
  1144. }
  1145. wm_low.disp_clk = mode->clock;
  1146. wm_low.src_width = mode->crtc_hdisplay;
  1147. wm_low.active_time = active_time;
  1148. wm_low.blank_time = line_time - wm_low.active_time;
  1149. wm_low.interlaced = false;
  1150. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1151. wm_low.interlaced = true;
  1152. wm_low.vsc = amdgpu_crtc->vsc;
  1153. wm_low.vtaps = 1;
  1154. if (amdgpu_crtc->rmx_type != RMX_OFF)
  1155. wm_low.vtaps = 2;
  1156. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1157. wm_low.lb_size = lb_size;
  1158. wm_low.dram_channels = cik_get_number_of_dram_channels(adev);
  1159. wm_low.num_heads = num_heads;
  1160. /* set for low clocks */
  1161. latency_watermark_b = min(dce_v8_0_latency_watermark(&wm_low), (u32)65535);
  1162. /* possibly force display priority to high */
  1163. /* should really do this at mode validation time... */
  1164. if (!dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  1165. !dce_v8_0_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  1166. !dce_v8_0_check_latency_hiding(&wm_low) ||
  1167. (adev->mode_info.disp_priority == 2)) {
  1168. DRM_DEBUG_KMS("force priority to high\n");
  1169. }
  1170. lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
  1171. }
  1172. /* select wm A */
  1173. wm_mask = RREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset);
  1174. tmp = wm_mask;
  1175. tmp &= ~(3 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
  1176. tmp |= (1 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
  1177. WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, tmp);
  1178. WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
  1179. ((latency_watermark_a << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
  1180. (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
  1181. /* select wm B */
  1182. tmp = RREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset);
  1183. tmp &= ~(3 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
  1184. tmp |= (2 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
  1185. WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, tmp);
  1186. WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
  1187. ((latency_watermark_b << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
  1188. (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
  1189. /* restore original selection */
  1190. WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, wm_mask);
  1191. /* save values for DPM */
  1192. amdgpu_crtc->line_time = line_time;
  1193. amdgpu_crtc->wm_high = latency_watermark_a;
  1194. amdgpu_crtc->wm_low = latency_watermark_b;
  1195. /* Save number of lines the linebuffer leads before the scanout */
  1196. amdgpu_crtc->lb_vblank_lead_lines = lb_vblank_lead_lines;
  1197. }
  1198. /**
  1199. * dce_v8_0_bandwidth_update - program display watermarks
  1200. *
  1201. * @adev: amdgpu_device pointer
  1202. *
  1203. * Calculate and program the display watermarks and line
  1204. * buffer allocation (CIK).
  1205. */
  1206. static void dce_v8_0_bandwidth_update(struct amdgpu_device *adev)
  1207. {
  1208. struct drm_display_mode *mode = NULL;
  1209. u32 num_heads = 0, lb_size;
  1210. int i;
  1211. amdgpu_update_display_priority(adev);
  1212. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1213. if (adev->mode_info.crtcs[i]->base.enabled)
  1214. num_heads++;
  1215. }
  1216. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  1217. mode = &adev->mode_info.crtcs[i]->base.mode;
  1218. lb_size = dce_v8_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i], mode);
  1219. dce_v8_0_program_watermarks(adev, adev->mode_info.crtcs[i],
  1220. lb_size, num_heads);
  1221. }
  1222. }
  1223. static void dce_v8_0_audio_get_connected_pins(struct amdgpu_device *adev)
  1224. {
  1225. int i;
  1226. u32 offset, tmp;
  1227. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1228. offset = adev->mode_info.audio.pin[i].offset;
  1229. tmp = RREG32_AUDIO_ENDPT(offset,
  1230. ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT);
  1231. if (((tmp &
  1232. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY_MASK) >>
  1233. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY__SHIFT) == 1)
  1234. adev->mode_info.audio.pin[i].connected = false;
  1235. else
  1236. adev->mode_info.audio.pin[i].connected = true;
  1237. }
  1238. }
  1239. static struct amdgpu_audio_pin *dce_v8_0_audio_get_pin(struct amdgpu_device *adev)
  1240. {
  1241. int i;
  1242. dce_v8_0_audio_get_connected_pins(adev);
  1243. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1244. if (adev->mode_info.audio.pin[i].connected)
  1245. return &adev->mode_info.audio.pin[i];
  1246. }
  1247. DRM_ERROR("No connected audio pins found!\n");
  1248. return NULL;
  1249. }
  1250. static void dce_v8_0_afmt_audio_select_pin(struct drm_encoder *encoder)
  1251. {
  1252. struct amdgpu_device *adev = encoder->dev->dev_private;
  1253. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1254. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1255. u32 offset;
  1256. if (!dig || !dig->afmt || !dig->afmt->pin)
  1257. return;
  1258. offset = dig->afmt->offset;
  1259. WREG32(mmAFMT_AUDIO_SRC_CONTROL + offset,
  1260. (dig->afmt->pin->id << AFMT_AUDIO_SRC_CONTROL__AFMT_AUDIO_SRC_SELECT__SHIFT));
  1261. }
  1262. static void dce_v8_0_audio_write_latency_fields(struct drm_encoder *encoder,
  1263. struct drm_display_mode *mode)
  1264. {
  1265. struct amdgpu_device *adev = encoder->dev->dev_private;
  1266. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1267. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1268. struct drm_connector *connector;
  1269. struct amdgpu_connector *amdgpu_connector = NULL;
  1270. u32 tmp = 0, offset;
  1271. if (!dig || !dig->afmt || !dig->afmt->pin)
  1272. return;
  1273. offset = dig->afmt->pin->offset;
  1274. list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
  1275. if (connector->encoder == encoder) {
  1276. amdgpu_connector = to_amdgpu_connector(connector);
  1277. break;
  1278. }
  1279. }
  1280. if (!amdgpu_connector) {
  1281. DRM_ERROR("Couldn't find encoder's connector\n");
  1282. return;
  1283. }
  1284. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  1285. if (connector->latency_present[1])
  1286. tmp =
  1287. (connector->video_latency[1] <<
  1288. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
  1289. (connector->audio_latency[1] <<
  1290. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
  1291. else
  1292. tmp =
  1293. (0 <<
  1294. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
  1295. (0 <<
  1296. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
  1297. } else {
  1298. if (connector->latency_present[0])
  1299. tmp =
  1300. (connector->video_latency[0] <<
  1301. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
  1302. (connector->audio_latency[0] <<
  1303. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
  1304. else
  1305. tmp =
  1306. (0 <<
  1307. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
  1308. (0 <<
  1309. AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
  1310. }
  1311. WREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, tmp);
  1312. }
  1313. static void dce_v8_0_audio_write_speaker_allocation(struct drm_encoder *encoder)
  1314. {
  1315. struct amdgpu_device *adev = encoder->dev->dev_private;
  1316. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1317. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1318. struct drm_connector *connector;
  1319. struct amdgpu_connector *amdgpu_connector = NULL;
  1320. u32 offset, tmp;
  1321. u8 *sadb = NULL;
  1322. int sad_count;
  1323. if (!dig || !dig->afmt || !dig->afmt->pin)
  1324. return;
  1325. offset = dig->afmt->pin->offset;
  1326. list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
  1327. if (connector->encoder == encoder) {
  1328. amdgpu_connector = to_amdgpu_connector(connector);
  1329. break;
  1330. }
  1331. }
  1332. if (!amdgpu_connector) {
  1333. DRM_ERROR("Couldn't find encoder's connector\n");
  1334. return;
  1335. }
  1336. sad_count = drm_edid_to_speaker_allocation(amdgpu_connector_edid(connector), &sadb);
  1337. if (sad_count < 0) {
  1338. DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
  1339. sad_count = 0;
  1340. }
  1341. /* program the speaker allocation */
  1342. tmp = RREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER);
  1343. tmp &= ~(AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__DP_CONNECTION_MASK |
  1344. AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION_MASK);
  1345. /* set HDMI mode */
  1346. tmp |= AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__HDMI_CONNECTION_MASK;
  1347. if (sad_count)
  1348. tmp |= (sadb[0] << AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION__SHIFT);
  1349. else
  1350. tmp |= (5 << AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION__SHIFT); /* stereo */
  1351. WREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
  1352. kfree(sadb);
  1353. }
  1354. static void dce_v8_0_audio_write_sad_regs(struct drm_encoder *encoder)
  1355. {
  1356. struct amdgpu_device *adev = encoder->dev->dev_private;
  1357. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1358. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1359. u32 offset;
  1360. struct drm_connector *connector;
  1361. struct amdgpu_connector *amdgpu_connector = NULL;
  1362. struct cea_sad *sads;
  1363. int i, sad_count;
  1364. static const u16 eld_reg_to_type[][2] = {
  1365. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
  1366. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
  1367. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
  1368. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
  1369. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
  1370. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
  1371. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
  1372. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
  1373. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
  1374. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
  1375. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
  1376. { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
  1377. };
  1378. if (!dig || !dig->afmt || !dig->afmt->pin)
  1379. return;
  1380. offset = dig->afmt->pin->offset;
  1381. list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
  1382. if (connector->encoder == encoder) {
  1383. amdgpu_connector = to_amdgpu_connector(connector);
  1384. break;
  1385. }
  1386. }
  1387. if (!amdgpu_connector) {
  1388. DRM_ERROR("Couldn't find encoder's connector\n");
  1389. return;
  1390. }
  1391. sad_count = drm_edid_to_sad(amdgpu_connector_edid(connector), &sads);
  1392. if (sad_count <= 0) {
  1393. DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
  1394. return;
  1395. }
  1396. BUG_ON(!sads);
  1397. for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
  1398. u32 value = 0;
  1399. u8 stereo_freqs = 0;
  1400. int max_channels = -1;
  1401. int j;
  1402. for (j = 0; j < sad_count; j++) {
  1403. struct cea_sad *sad = &sads[j];
  1404. if (sad->format == eld_reg_to_type[i][1]) {
  1405. if (sad->channels > max_channels) {
  1406. value = (sad->channels <<
  1407. AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__MAX_CHANNELS__SHIFT) |
  1408. (sad->byte2 <<
  1409. AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__DESCRIPTOR_BYTE_2__SHIFT) |
  1410. (sad->freq <<
  1411. AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES__SHIFT);
  1412. max_channels = sad->channels;
  1413. }
  1414. if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
  1415. stereo_freqs |= sad->freq;
  1416. else
  1417. break;
  1418. }
  1419. }
  1420. value |= (stereo_freqs <<
  1421. AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES_STEREO__SHIFT);
  1422. WREG32_AUDIO_ENDPT(offset, eld_reg_to_type[i][0], value);
  1423. }
  1424. kfree(sads);
  1425. }
  1426. static void dce_v8_0_audio_enable(struct amdgpu_device *adev,
  1427. struct amdgpu_audio_pin *pin,
  1428. bool enable)
  1429. {
  1430. if (!pin)
  1431. return;
  1432. WREG32_AUDIO_ENDPT(pin->offset, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
  1433. enable ? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK : 0);
  1434. }
  1435. static const u32 pin_offsets[7] =
  1436. {
  1437. (0x1780 - 0x1780),
  1438. (0x1786 - 0x1780),
  1439. (0x178c - 0x1780),
  1440. (0x1792 - 0x1780),
  1441. (0x1798 - 0x1780),
  1442. (0x179d - 0x1780),
  1443. (0x17a4 - 0x1780),
  1444. };
  1445. static int dce_v8_0_audio_init(struct amdgpu_device *adev)
  1446. {
  1447. int i;
  1448. if (!amdgpu_audio)
  1449. return 0;
  1450. adev->mode_info.audio.enabled = true;
  1451. if (adev->asic_type == CHIP_KAVERI) /* KV: 4 streams, 7 endpoints */
  1452. adev->mode_info.audio.num_pins = 7;
  1453. else if ((adev->asic_type == CHIP_KABINI) ||
  1454. (adev->asic_type == CHIP_MULLINS)) /* KB/ML: 2 streams, 3 endpoints */
  1455. adev->mode_info.audio.num_pins = 3;
  1456. else if ((adev->asic_type == CHIP_BONAIRE) ||
  1457. (adev->asic_type == CHIP_HAWAII))/* BN/HW: 6 streams, 7 endpoints */
  1458. adev->mode_info.audio.num_pins = 7;
  1459. else
  1460. adev->mode_info.audio.num_pins = 3;
  1461. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  1462. adev->mode_info.audio.pin[i].channels = -1;
  1463. adev->mode_info.audio.pin[i].rate = -1;
  1464. adev->mode_info.audio.pin[i].bits_per_sample = -1;
  1465. adev->mode_info.audio.pin[i].status_bits = 0;
  1466. adev->mode_info.audio.pin[i].category_code = 0;
  1467. adev->mode_info.audio.pin[i].connected = false;
  1468. adev->mode_info.audio.pin[i].offset = pin_offsets[i];
  1469. adev->mode_info.audio.pin[i].id = i;
  1470. /* disable audio. it will be set up later */
  1471. /* XXX remove once we switch to ip funcs */
  1472. dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  1473. }
  1474. return 0;
  1475. }
  1476. static void dce_v8_0_audio_fini(struct amdgpu_device *adev)
  1477. {
  1478. int i;
  1479. if (!adev->mode_info.audio.enabled)
  1480. return;
  1481. for (i = 0; i < adev->mode_info.audio.num_pins; i++)
  1482. dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  1483. adev->mode_info.audio.enabled = false;
  1484. }
  1485. /*
  1486. * update the N and CTS parameters for a given pixel clock rate
  1487. */
  1488. static void dce_v8_0_afmt_update_ACR(struct drm_encoder *encoder, uint32_t clock)
  1489. {
  1490. struct drm_device *dev = encoder->dev;
  1491. struct amdgpu_device *adev = dev->dev_private;
  1492. struct amdgpu_afmt_acr acr = amdgpu_afmt_acr(clock);
  1493. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1494. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1495. uint32_t offset = dig->afmt->offset;
  1496. WREG32(mmHDMI_ACR_32_0 + offset, (acr.cts_32khz << HDMI_ACR_44_0__HDMI_ACR_CTS_44__SHIFT));
  1497. WREG32(mmHDMI_ACR_32_1 + offset, acr.n_32khz);
  1498. WREG32(mmHDMI_ACR_44_0 + offset, (acr.cts_44_1khz << HDMI_ACR_44_0__HDMI_ACR_CTS_44__SHIFT));
  1499. WREG32(mmHDMI_ACR_44_1 + offset, acr.n_44_1khz);
  1500. WREG32(mmHDMI_ACR_48_0 + offset, (acr.cts_48khz << HDMI_ACR_48_0__HDMI_ACR_CTS_48__SHIFT));
  1501. WREG32(mmHDMI_ACR_48_1 + offset, acr.n_48khz);
  1502. }
  1503. /*
  1504. * build a HDMI Video Info Frame
  1505. */
  1506. static void dce_v8_0_afmt_update_avi_infoframe(struct drm_encoder *encoder,
  1507. void *buffer, size_t size)
  1508. {
  1509. struct drm_device *dev = encoder->dev;
  1510. struct amdgpu_device *adev = dev->dev_private;
  1511. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1512. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1513. uint32_t offset = dig->afmt->offset;
  1514. uint8_t *frame = buffer + 3;
  1515. uint8_t *header = buffer;
  1516. WREG32(mmAFMT_AVI_INFO0 + offset,
  1517. frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
  1518. WREG32(mmAFMT_AVI_INFO1 + offset,
  1519. frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
  1520. WREG32(mmAFMT_AVI_INFO2 + offset,
  1521. frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
  1522. WREG32(mmAFMT_AVI_INFO3 + offset,
  1523. frame[0xC] | (frame[0xD] << 8) | (header[1] << 24));
  1524. }
  1525. static void dce_v8_0_audio_set_dto(struct drm_encoder *encoder, u32 clock)
  1526. {
  1527. struct drm_device *dev = encoder->dev;
  1528. struct amdgpu_device *adev = dev->dev_private;
  1529. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1530. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1531. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
  1532. u32 dto_phase = 24 * 1000;
  1533. u32 dto_modulo = clock;
  1534. if (!dig || !dig->afmt)
  1535. return;
  1536. /* XXX two dtos; generally use dto0 for hdmi */
  1537. /* Express [24MHz / target pixel clock] as an exact rational
  1538. * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
  1539. * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
  1540. */
  1541. WREG32(mmDCCG_AUDIO_DTO_SOURCE, (amdgpu_crtc->crtc_id << DCCG_AUDIO_DTO_SOURCE__DCCG_AUDIO_DTO0_SOURCE_SEL__SHIFT));
  1542. WREG32(mmDCCG_AUDIO_DTO0_PHASE, dto_phase);
  1543. WREG32(mmDCCG_AUDIO_DTO0_MODULE, dto_modulo);
  1544. }
  1545. /*
  1546. * update the info frames with the data from the current display mode
  1547. */
  1548. static void dce_v8_0_afmt_setmode(struct drm_encoder *encoder,
  1549. struct drm_display_mode *mode)
  1550. {
  1551. struct drm_device *dev = encoder->dev;
  1552. struct amdgpu_device *adev = dev->dev_private;
  1553. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1554. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1555. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  1556. u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
  1557. struct hdmi_avi_infoframe frame;
  1558. uint32_t offset, val;
  1559. ssize_t err;
  1560. int bpc = 8;
  1561. if (!dig || !dig->afmt)
  1562. return;
  1563. /* Silent, r600_hdmi_enable will raise WARN for us */
  1564. if (!dig->afmt->enabled)
  1565. return;
  1566. offset = dig->afmt->offset;
  1567. /* hdmi deep color mode general control packets setup, if bpc > 8 */
  1568. if (encoder->crtc) {
  1569. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
  1570. bpc = amdgpu_crtc->bpc;
  1571. }
  1572. /* disable audio prior to setting up hw */
  1573. dig->afmt->pin = dce_v8_0_audio_get_pin(adev);
  1574. dce_v8_0_audio_enable(adev, dig->afmt->pin, false);
  1575. dce_v8_0_audio_set_dto(encoder, mode->clock);
  1576. WREG32(mmHDMI_VBI_PACKET_CONTROL + offset,
  1577. HDMI_VBI_PACKET_CONTROL__HDMI_NULL_SEND_MASK); /* send null packets when required */
  1578. WREG32(mmAFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
  1579. val = RREG32(mmHDMI_CONTROL + offset);
  1580. val &= ~HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
  1581. val &= ~HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH_MASK;
  1582. switch (bpc) {
  1583. case 0:
  1584. case 6:
  1585. case 8:
  1586. case 16:
  1587. default:
  1588. DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n",
  1589. connector->name, bpc);
  1590. break;
  1591. case 10:
  1592. val |= HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
  1593. val |= 1 << HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH__SHIFT;
  1594. DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n",
  1595. connector->name);
  1596. break;
  1597. case 12:
  1598. val |= HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
  1599. val |= 2 << HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH__SHIFT;
  1600. DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n",
  1601. connector->name);
  1602. break;
  1603. }
  1604. WREG32(mmHDMI_CONTROL + offset, val);
  1605. WREG32(mmHDMI_VBI_PACKET_CONTROL + offset,
  1606. HDMI_VBI_PACKET_CONTROL__HDMI_NULL_SEND_MASK | /* send null packets when required */
  1607. HDMI_VBI_PACKET_CONTROL__HDMI_GC_SEND_MASK | /* send general control packets */
  1608. HDMI_VBI_PACKET_CONTROL__HDMI_GC_CONT_MASK); /* send general control packets every frame */
  1609. WREG32(mmHDMI_INFOFRAME_CONTROL0 + offset,
  1610. HDMI_INFOFRAME_CONTROL0__HDMI_AUDIO_INFO_SEND_MASK | /* enable audio info frames (frames won't be set until audio is enabled) */
  1611. HDMI_INFOFRAME_CONTROL0__HDMI_AUDIO_INFO_CONT_MASK); /* required for audio info values to be updated */
  1612. WREG32(mmAFMT_INFOFRAME_CONTROL0 + offset,
  1613. AFMT_INFOFRAME_CONTROL0__AFMT_AUDIO_INFO_UPDATE_MASK); /* required for audio info values to be updated */
  1614. WREG32(mmHDMI_INFOFRAME_CONTROL1 + offset,
  1615. (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AUDIO_INFO_LINE__SHIFT)); /* anything other than 0 */
  1616. WREG32(mmHDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
  1617. WREG32(mmHDMI_AUDIO_PACKET_CONTROL + offset,
  1618. (1 << HDMI_AUDIO_PACKET_CONTROL__HDMI_AUDIO_DELAY_EN__SHIFT) | /* set the default audio delay */
  1619. (3 << HDMI_AUDIO_PACKET_CONTROL__HDMI_AUDIO_PACKETS_PER_LINE__SHIFT)); /* should be suffient for all audio modes and small enough for all hblanks */
  1620. WREG32(mmAFMT_AUDIO_PACKET_CONTROL + offset,
  1621. AFMT_AUDIO_PACKET_CONTROL__AFMT_60958_CS_UPDATE_MASK); /* allow 60958 channel status fields to be updated */
  1622. /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
  1623. if (bpc > 8)
  1624. WREG32(mmHDMI_ACR_PACKET_CONTROL + offset,
  1625. HDMI_ACR_PACKET_CONTROL__HDMI_ACR_AUTO_SEND_MASK); /* allow hw to sent ACR packets when required */
  1626. else
  1627. WREG32(mmHDMI_ACR_PACKET_CONTROL + offset,
  1628. HDMI_ACR_PACKET_CONTROL__HDMI_ACR_SOURCE_MASK | /* select SW CTS value */
  1629. HDMI_ACR_PACKET_CONTROL__HDMI_ACR_AUTO_SEND_MASK); /* allow hw to sent ACR packets when required */
  1630. dce_v8_0_afmt_update_ACR(encoder, mode->clock);
  1631. WREG32(mmAFMT_60958_0 + offset,
  1632. (1 << AFMT_60958_0__AFMT_60958_CS_CHANNEL_NUMBER_L__SHIFT));
  1633. WREG32(mmAFMT_60958_1 + offset,
  1634. (2 << AFMT_60958_1__AFMT_60958_CS_CHANNEL_NUMBER_R__SHIFT));
  1635. WREG32(mmAFMT_60958_2 + offset,
  1636. (3 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_2__SHIFT) |
  1637. (4 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_3__SHIFT) |
  1638. (5 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_4__SHIFT) |
  1639. (6 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_5__SHIFT) |
  1640. (7 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_6__SHIFT) |
  1641. (8 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_7__SHIFT));
  1642. dce_v8_0_audio_write_speaker_allocation(encoder);
  1643. WREG32(mmAFMT_AUDIO_PACKET_CONTROL2 + offset,
  1644. (0xff << AFMT_AUDIO_PACKET_CONTROL2__AFMT_AUDIO_CHANNEL_ENABLE__SHIFT));
  1645. dce_v8_0_afmt_audio_select_pin(encoder);
  1646. dce_v8_0_audio_write_sad_regs(encoder);
  1647. dce_v8_0_audio_write_latency_fields(encoder, mode);
  1648. err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
  1649. if (err < 0) {
  1650. DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
  1651. return;
  1652. }
  1653. err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
  1654. if (err < 0) {
  1655. DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
  1656. return;
  1657. }
  1658. dce_v8_0_afmt_update_avi_infoframe(encoder, buffer, sizeof(buffer));
  1659. WREG32_OR(mmHDMI_INFOFRAME_CONTROL0 + offset,
  1660. HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_SEND_MASK | /* enable AVI info frames */
  1661. HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_SEND_MASK); /* required for audio info values to be updated */
  1662. WREG32_P(mmHDMI_INFOFRAME_CONTROL1 + offset,
  1663. (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE__SHIFT), /* anything other than 0 */
  1664. ~HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE_MASK);
  1665. WREG32_OR(mmAFMT_AUDIO_PACKET_CONTROL + offset,
  1666. AFMT_AUDIO_PACKET_CONTROL__AFMT_AUDIO_SAMPLE_SEND_MASK); /* send audio packets */
  1667. /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
  1668. WREG32(mmAFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
  1669. WREG32(mmAFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
  1670. WREG32(mmAFMT_RAMP_CONTROL2 + offset, 0x00000001);
  1671. WREG32(mmAFMT_RAMP_CONTROL3 + offset, 0x00000001);
  1672. /* enable audio after to setting up hw */
  1673. dce_v8_0_audio_enable(adev, dig->afmt->pin, true);
  1674. }
  1675. static void dce_v8_0_afmt_enable(struct drm_encoder *encoder, bool enable)
  1676. {
  1677. struct drm_device *dev = encoder->dev;
  1678. struct amdgpu_device *adev = dev->dev_private;
  1679. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  1680. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  1681. if (!dig || !dig->afmt)
  1682. return;
  1683. /* Silent, r600_hdmi_enable will raise WARN for us */
  1684. if (enable && dig->afmt->enabled)
  1685. return;
  1686. if (!enable && !dig->afmt->enabled)
  1687. return;
  1688. if (!enable && dig->afmt->pin) {
  1689. dce_v8_0_audio_enable(adev, dig->afmt->pin, false);
  1690. dig->afmt->pin = NULL;
  1691. }
  1692. dig->afmt->enabled = enable;
  1693. DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
  1694. enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id);
  1695. }
  1696. static void dce_v8_0_afmt_init(struct amdgpu_device *adev)
  1697. {
  1698. int i;
  1699. for (i = 0; i < adev->mode_info.num_dig; i++)
  1700. adev->mode_info.afmt[i] = NULL;
  1701. /* DCE8 has audio blocks tied to DIG encoders */
  1702. for (i = 0; i < adev->mode_info.num_dig; i++) {
  1703. adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL);
  1704. if (adev->mode_info.afmt[i]) {
  1705. adev->mode_info.afmt[i]->offset = dig_offsets[i];
  1706. adev->mode_info.afmt[i]->id = i;
  1707. }
  1708. }
  1709. }
  1710. static void dce_v8_0_afmt_fini(struct amdgpu_device *adev)
  1711. {
  1712. int i;
  1713. for (i = 0; i < adev->mode_info.num_dig; i++) {
  1714. kfree(adev->mode_info.afmt[i]);
  1715. adev->mode_info.afmt[i] = NULL;
  1716. }
  1717. }
  1718. static const u32 vga_control_regs[6] =
  1719. {
  1720. mmD1VGA_CONTROL,
  1721. mmD2VGA_CONTROL,
  1722. mmD3VGA_CONTROL,
  1723. mmD4VGA_CONTROL,
  1724. mmD5VGA_CONTROL,
  1725. mmD6VGA_CONTROL,
  1726. };
  1727. static void dce_v8_0_vga_enable(struct drm_crtc *crtc, bool enable)
  1728. {
  1729. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1730. struct drm_device *dev = crtc->dev;
  1731. struct amdgpu_device *adev = dev->dev_private;
  1732. u32 vga_control;
  1733. vga_control = RREG32(vga_control_regs[amdgpu_crtc->crtc_id]) & ~1;
  1734. if (enable)
  1735. WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control | 1);
  1736. else
  1737. WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control);
  1738. }
  1739. static void dce_v8_0_grph_enable(struct drm_crtc *crtc, bool enable)
  1740. {
  1741. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1742. struct drm_device *dev = crtc->dev;
  1743. struct amdgpu_device *adev = dev->dev_private;
  1744. if (enable)
  1745. WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 1);
  1746. else
  1747. WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0);
  1748. }
  1749. static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
  1750. struct drm_framebuffer *fb,
  1751. int x, int y, int atomic)
  1752. {
  1753. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1754. struct drm_device *dev = crtc->dev;
  1755. struct amdgpu_device *adev = dev->dev_private;
  1756. struct amdgpu_framebuffer *amdgpu_fb;
  1757. struct drm_framebuffer *target_fb;
  1758. struct drm_gem_object *obj;
  1759. struct amdgpu_bo *rbo;
  1760. uint64_t fb_location, tiling_flags;
  1761. uint32_t fb_format, fb_pitch_pixels;
  1762. u32 fb_swap = (GRPH_ENDIAN_NONE << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1763. u32 pipe_config;
  1764. u32 tmp, viewport_w, viewport_h;
  1765. int r;
  1766. bool bypass_lut = false;
  1767. /* no fb bound */
  1768. if (!atomic && !crtc->primary->fb) {
  1769. DRM_DEBUG_KMS("No FB bound\n");
  1770. return 0;
  1771. }
  1772. if (atomic) {
  1773. amdgpu_fb = to_amdgpu_framebuffer(fb);
  1774. target_fb = fb;
  1775. }
  1776. else {
  1777. amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
  1778. target_fb = crtc->primary->fb;
  1779. }
  1780. /* If atomic, assume fb object is pinned & idle & fenced and
  1781. * just update base pointers
  1782. */
  1783. obj = amdgpu_fb->obj;
  1784. rbo = gem_to_amdgpu_bo(obj);
  1785. r = amdgpu_bo_reserve(rbo, false);
  1786. if (unlikely(r != 0))
  1787. return r;
  1788. if (atomic)
  1789. fb_location = amdgpu_bo_gpu_offset(rbo);
  1790. else {
  1791. r = amdgpu_bo_pin(rbo, AMDGPU_GEM_DOMAIN_VRAM, &fb_location);
  1792. if (unlikely(r != 0)) {
  1793. amdgpu_bo_unreserve(rbo);
  1794. return -EINVAL;
  1795. }
  1796. }
  1797. amdgpu_bo_get_tiling_flags(rbo, &tiling_flags);
  1798. amdgpu_bo_unreserve(rbo);
  1799. pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
  1800. switch (target_fb->pixel_format) {
  1801. case DRM_FORMAT_C8:
  1802. fb_format = ((GRPH_DEPTH_8BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1803. (GRPH_FORMAT_INDEXED << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1804. break;
  1805. case DRM_FORMAT_XRGB4444:
  1806. case DRM_FORMAT_ARGB4444:
  1807. fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1808. (GRPH_FORMAT_ARGB1555 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1809. #ifdef __BIG_ENDIAN
  1810. fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1811. #endif
  1812. break;
  1813. case DRM_FORMAT_XRGB1555:
  1814. case DRM_FORMAT_ARGB1555:
  1815. fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1816. (GRPH_FORMAT_ARGB1555 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1817. #ifdef __BIG_ENDIAN
  1818. fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1819. #endif
  1820. break;
  1821. case DRM_FORMAT_BGRX5551:
  1822. case DRM_FORMAT_BGRA5551:
  1823. fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1824. (GRPH_FORMAT_BGRA5551 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1825. #ifdef __BIG_ENDIAN
  1826. fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1827. #endif
  1828. break;
  1829. case DRM_FORMAT_RGB565:
  1830. fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1831. (GRPH_FORMAT_ARGB565 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1832. #ifdef __BIG_ENDIAN
  1833. fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1834. #endif
  1835. break;
  1836. case DRM_FORMAT_XRGB8888:
  1837. case DRM_FORMAT_ARGB8888:
  1838. fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1839. (GRPH_FORMAT_ARGB8888 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1840. #ifdef __BIG_ENDIAN
  1841. fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1842. #endif
  1843. break;
  1844. case DRM_FORMAT_XRGB2101010:
  1845. case DRM_FORMAT_ARGB2101010:
  1846. fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1847. (GRPH_FORMAT_ARGB2101010 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1848. #ifdef __BIG_ENDIAN
  1849. fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1850. #endif
  1851. /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
  1852. bypass_lut = true;
  1853. break;
  1854. case DRM_FORMAT_BGRX1010102:
  1855. case DRM_FORMAT_BGRA1010102:
  1856. fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
  1857. (GRPH_FORMAT_BGRA1010102 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
  1858. #ifdef __BIG_ENDIAN
  1859. fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
  1860. #endif
  1861. /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
  1862. bypass_lut = true;
  1863. break;
  1864. default:
  1865. DRM_ERROR("Unsupported screen format %s\n",
  1866. drm_get_format_name(target_fb->pixel_format));
  1867. return -EINVAL;
  1868. }
  1869. if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
  1870. unsigned bankw, bankh, mtaspect, tile_split, num_banks;
  1871. bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
  1872. bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
  1873. mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
  1874. tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
  1875. num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
  1876. fb_format |= (num_banks << GRPH_CONTROL__GRPH_NUM_BANKS__SHIFT);
  1877. fb_format |= (GRPH_ARRAY_2D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT);
  1878. fb_format |= (tile_split << GRPH_CONTROL__GRPH_TILE_SPLIT__SHIFT);
  1879. fb_format |= (bankw << GRPH_CONTROL__GRPH_BANK_WIDTH__SHIFT);
  1880. fb_format |= (bankh << GRPH_CONTROL__GRPH_BANK_HEIGHT__SHIFT);
  1881. fb_format |= (mtaspect << GRPH_CONTROL__GRPH_MACRO_TILE_ASPECT__SHIFT);
  1882. fb_format |= (DISPLAY_MICRO_TILING << GRPH_CONTROL__GRPH_MICRO_TILE_MODE__SHIFT);
  1883. } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
  1884. fb_format |= (GRPH_ARRAY_1D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT);
  1885. }
  1886. fb_format |= (pipe_config << GRPH_CONTROL__GRPH_PIPE_CONFIG__SHIFT);
  1887. dce_v8_0_vga_enable(crtc, false);
  1888. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1889. upper_32_bits(fb_location));
  1890. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  1891. upper_32_bits(fb_location));
  1892. WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1893. (u32)fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
  1894. WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  1895. (u32) fb_location & GRPH_SECONDARY_SURFACE_ADDRESS__GRPH_SECONDARY_SURFACE_ADDRESS_MASK);
  1896. WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format);
  1897. WREG32(mmGRPH_SWAP_CNTL + amdgpu_crtc->crtc_offset, fb_swap);
  1898. /*
  1899. * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
  1900. * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
  1901. * retain the full precision throughout the pipeline.
  1902. */
  1903. WREG32_P(mmGRPH_LUT_10BIT_BYPASS_CONTROL + amdgpu_crtc->crtc_offset,
  1904. (bypass_lut ? LUT_10BIT_BYPASS_EN : 0),
  1905. ~LUT_10BIT_BYPASS_EN);
  1906. if (bypass_lut)
  1907. DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
  1908. WREG32(mmGRPH_SURFACE_OFFSET_X + amdgpu_crtc->crtc_offset, 0);
  1909. WREG32(mmGRPH_SURFACE_OFFSET_Y + amdgpu_crtc->crtc_offset, 0);
  1910. WREG32(mmGRPH_X_START + amdgpu_crtc->crtc_offset, 0);
  1911. WREG32(mmGRPH_Y_START + amdgpu_crtc->crtc_offset, 0);
  1912. WREG32(mmGRPH_X_END + amdgpu_crtc->crtc_offset, target_fb->width);
  1913. WREG32(mmGRPH_Y_END + amdgpu_crtc->crtc_offset, target_fb->height);
  1914. fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8);
  1915. WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, fb_pitch_pixels);
  1916. dce_v8_0_grph_enable(crtc, true);
  1917. WREG32(mmLB_DESKTOP_HEIGHT + amdgpu_crtc->crtc_offset,
  1918. target_fb->height);
  1919. x &= ~3;
  1920. y &= ~1;
  1921. WREG32(mmVIEWPORT_START + amdgpu_crtc->crtc_offset,
  1922. (x << 16) | y);
  1923. viewport_w = crtc->mode.hdisplay;
  1924. viewport_h = (crtc->mode.vdisplay + 1) & ~1;
  1925. WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
  1926. (viewport_w << 16) | viewport_h);
  1927. /* pageflip setup */
  1928. /* make sure flip is at vb rather than hb */
  1929. tmp = RREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset);
  1930. tmp &= ~GRPH_FLIP_CONTROL__GRPH_SURFACE_UPDATE_H_RETRACE_EN_MASK;
  1931. WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, tmp);
  1932. /* set pageflip to happen only at start of vblank interval (front porch) */
  1933. WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 3);
  1934. if (!atomic && fb && fb != crtc->primary->fb) {
  1935. amdgpu_fb = to_amdgpu_framebuffer(fb);
  1936. rbo = gem_to_amdgpu_bo(amdgpu_fb->obj);
  1937. r = amdgpu_bo_reserve(rbo, false);
  1938. if (unlikely(r != 0))
  1939. return r;
  1940. amdgpu_bo_unpin(rbo);
  1941. amdgpu_bo_unreserve(rbo);
  1942. }
  1943. /* Bytes per pixel may have changed */
  1944. dce_v8_0_bandwidth_update(adev);
  1945. return 0;
  1946. }
  1947. static void dce_v8_0_set_interleave(struct drm_crtc *crtc,
  1948. struct drm_display_mode *mode)
  1949. {
  1950. struct drm_device *dev = crtc->dev;
  1951. struct amdgpu_device *adev = dev->dev_private;
  1952. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1953. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1954. WREG32(mmLB_DATA_FORMAT + amdgpu_crtc->crtc_offset,
  1955. LB_DATA_FORMAT__INTERLEAVE_EN__SHIFT);
  1956. else
  1957. WREG32(mmLB_DATA_FORMAT + amdgpu_crtc->crtc_offset, 0);
  1958. }
  1959. static void dce_v8_0_crtc_load_lut(struct drm_crtc *crtc)
  1960. {
  1961. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1962. struct drm_device *dev = crtc->dev;
  1963. struct amdgpu_device *adev = dev->dev_private;
  1964. int i;
  1965. DRM_DEBUG_KMS("%d\n", amdgpu_crtc->crtc_id);
  1966. WREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
  1967. ((INPUT_CSC_BYPASS << INPUT_CSC_CONTROL__INPUT_CSC_GRPH_MODE__SHIFT) |
  1968. (INPUT_CSC_BYPASS << INPUT_CSC_CONTROL__INPUT_CSC_OVL_MODE__SHIFT)));
  1969. WREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset,
  1970. PRESCALE_GRPH_CONTROL__GRPH_PRESCALE_BYPASS_MASK);
  1971. WREG32(mmPRESCALE_OVL_CONTROL + amdgpu_crtc->crtc_offset,
  1972. PRESCALE_OVL_CONTROL__OVL_PRESCALE_BYPASS_MASK);
  1973. WREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1974. ((INPUT_GAMMA_USE_LUT << INPUT_GAMMA_CONTROL__GRPH_INPUT_GAMMA_MODE__SHIFT) |
  1975. (INPUT_GAMMA_USE_LUT << INPUT_GAMMA_CONTROL__OVL_INPUT_GAMMA_MODE__SHIFT)));
  1976. WREG32(mmDC_LUT_CONTROL + amdgpu_crtc->crtc_offset, 0);
  1977. WREG32(mmDC_LUT_BLACK_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0);
  1978. WREG32(mmDC_LUT_BLACK_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0);
  1979. WREG32(mmDC_LUT_BLACK_OFFSET_RED + amdgpu_crtc->crtc_offset, 0);
  1980. WREG32(mmDC_LUT_WHITE_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0xffff);
  1981. WREG32(mmDC_LUT_WHITE_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0xffff);
  1982. WREG32(mmDC_LUT_WHITE_OFFSET_RED + amdgpu_crtc->crtc_offset, 0xffff);
  1983. WREG32(mmDC_LUT_RW_MODE + amdgpu_crtc->crtc_offset, 0);
  1984. WREG32(mmDC_LUT_WRITE_EN_MASK + amdgpu_crtc->crtc_offset, 0x00000007);
  1985. WREG32(mmDC_LUT_RW_INDEX + amdgpu_crtc->crtc_offset, 0);
  1986. for (i = 0; i < 256; i++) {
  1987. WREG32(mmDC_LUT_30_COLOR + amdgpu_crtc->crtc_offset,
  1988. (amdgpu_crtc->lut_r[i] << 20) |
  1989. (amdgpu_crtc->lut_g[i] << 10) |
  1990. (amdgpu_crtc->lut_b[i] << 0));
  1991. }
  1992. WREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  1993. ((DEGAMMA_BYPASS << DEGAMMA_CONTROL__GRPH_DEGAMMA_MODE__SHIFT) |
  1994. (DEGAMMA_BYPASS << DEGAMMA_CONTROL__OVL_DEGAMMA_MODE__SHIFT) |
  1995. (DEGAMMA_BYPASS << DEGAMMA_CONTROL__CURSOR_DEGAMMA_MODE__SHIFT)));
  1996. WREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset,
  1997. ((GAMUT_REMAP_BYPASS << GAMUT_REMAP_CONTROL__GRPH_GAMUT_REMAP_MODE__SHIFT) |
  1998. (GAMUT_REMAP_BYPASS << GAMUT_REMAP_CONTROL__OVL_GAMUT_REMAP_MODE__SHIFT)));
  1999. WREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
  2000. ((REGAMMA_BYPASS << REGAMMA_CONTROL__GRPH_REGAMMA_MODE__SHIFT) |
  2001. (REGAMMA_BYPASS << REGAMMA_CONTROL__OVL_REGAMMA_MODE__SHIFT)));
  2002. WREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
  2003. ((OUTPUT_CSC_BYPASS << OUTPUT_CSC_CONTROL__OUTPUT_CSC_GRPH_MODE__SHIFT) |
  2004. (OUTPUT_CSC_BYPASS << OUTPUT_CSC_CONTROL__OUTPUT_CSC_OVL_MODE__SHIFT)));
  2005. /* XXX match this to the depth of the crtc fmt block, move to modeset? */
  2006. WREG32(0x1a50 + amdgpu_crtc->crtc_offset, 0);
  2007. /* XXX this only needs to be programmed once per crtc at startup,
  2008. * not sure where the best place for it is
  2009. */
  2010. WREG32(mmALPHA_CONTROL + amdgpu_crtc->crtc_offset,
  2011. ALPHA_CONTROL__CURSOR_ALPHA_BLND_ENA_MASK);
  2012. }
  2013. static int dce_v8_0_pick_dig_encoder(struct drm_encoder *encoder)
  2014. {
  2015. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  2016. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  2017. switch (amdgpu_encoder->encoder_id) {
  2018. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  2019. if (dig->linkb)
  2020. return 1;
  2021. else
  2022. return 0;
  2023. break;
  2024. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  2025. if (dig->linkb)
  2026. return 3;
  2027. else
  2028. return 2;
  2029. break;
  2030. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  2031. if (dig->linkb)
  2032. return 5;
  2033. else
  2034. return 4;
  2035. break;
  2036. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  2037. return 6;
  2038. break;
  2039. default:
  2040. DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id);
  2041. return 0;
  2042. }
  2043. }
  2044. /**
  2045. * dce_v8_0_pick_pll - Allocate a PPLL for use by the crtc.
  2046. *
  2047. * @crtc: drm crtc
  2048. *
  2049. * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
  2050. * a single PPLL can be used for all DP crtcs/encoders. For non-DP
  2051. * monitors a dedicated PPLL must be used. If a particular board has
  2052. * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
  2053. * as there is no need to program the PLL itself. If we are not able to
  2054. * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
  2055. * avoid messing up an existing monitor.
  2056. *
  2057. * Asic specific PLL information
  2058. *
  2059. * DCE 8.x
  2060. * KB/KV
  2061. * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP)
  2062. * CI
  2063. * - PPLL0, PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC
  2064. *
  2065. */
  2066. static u32 dce_v8_0_pick_pll(struct drm_crtc *crtc)
  2067. {
  2068. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2069. struct drm_device *dev = crtc->dev;
  2070. struct amdgpu_device *adev = dev->dev_private;
  2071. u32 pll_in_use;
  2072. int pll;
  2073. if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) {
  2074. if (adev->clock.dp_extclk)
  2075. /* skip PPLL programming if using ext clock */
  2076. return ATOM_PPLL_INVALID;
  2077. else {
  2078. /* use the same PPLL for all DP monitors */
  2079. pll = amdgpu_pll_get_shared_dp_ppll(crtc);
  2080. if (pll != ATOM_PPLL_INVALID)
  2081. return pll;
  2082. }
  2083. } else {
  2084. /* use the same PPLL for all monitors with the same clock */
  2085. pll = amdgpu_pll_get_shared_nondp_ppll(crtc);
  2086. if (pll != ATOM_PPLL_INVALID)
  2087. return pll;
  2088. }
  2089. /* otherwise, pick one of the plls */
  2090. if ((adev->asic_type == CHIP_KABINI) ||
  2091. (adev->asic_type == CHIP_MULLINS)) {
  2092. /* KB/ML has PPLL1 and PPLL2 */
  2093. pll_in_use = amdgpu_pll_get_use_mask(crtc);
  2094. if (!(pll_in_use & (1 << ATOM_PPLL2)))
  2095. return ATOM_PPLL2;
  2096. if (!(pll_in_use & (1 << ATOM_PPLL1)))
  2097. return ATOM_PPLL1;
  2098. DRM_ERROR("unable to allocate a PPLL\n");
  2099. return ATOM_PPLL_INVALID;
  2100. } else {
  2101. /* CI/KV has PPLL0, PPLL1, and PPLL2 */
  2102. pll_in_use = amdgpu_pll_get_use_mask(crtc);
  2103. if (!(pll_in_use & (1 << ATOM_PPLL2)))
  2104. return ATOM_PPLL2;
  2105. if (!(pll_in_use & (1 << ATOM_PPLL1)))
  2106. return ATOM_PPLL1;
  2107. if (!(pll_in_use & (1 << ATOM_PPLL0)))
  2108. return ATOM_PPLL0;
  2109. DRM_ERROR("unable to allocate a PPLL\n");
  2110. return ATOM_PPLL_INVALID;
  2111. }
  2112. return ATOM_PPLL_INVALID;
  2113. }
  2114. static void dce_v8_0_lock_cursor(struct drm_crtc *crtc, bool lock)
  2115. {
  2116. struct amdgpu_device *adev = crtc->dev->dev_private;
  2117. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2118. uint32_t cur_lock;
  2119. cur_lock = RREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset);
  2120. if (lock)
  2121. cur_lock |= CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
  2122. else
  2123. cur_lock &= ~CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
  2124. WREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset, cur_lock);
  2125. }
  2126. static void dce_v8_0_hide_cursor(struct drm_crtc *crtc)
  2127. {
  2128. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2129. struct amdgpu_device *adev = crtc->dev->dev_private;
  2130. WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
  2131. (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
  2132. (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
  2133. }
  2134. static void dce_v8_0_show_cursor(struct drm_crtc *crtc)
  2135. {
  2136. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2137. struct amdgpu_device *adev = crtc->dev->dev_private;
  2138. WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
  2139. upper_32_bits(amdgpu_crtc->cursor_addr));
  2140. WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
  2141. lower_32_bits(amdgpu_crtc->cursor_addr));
  2142. WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
  2143. CUR_CONTROL__CURSOR_EN_MASK |
  2144. (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
  2145. (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
  2146. }
  2147. static int dce_v8_0_cursor_move_locked(struct drm_crtc *crtc,
  2148. int x, int y)
  2149. {
  2150. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2151. struct amdgpu_device *adev = crtc->dev->dev_private;
  2152. int xorigin = 0, yorigin = 0;
  2153. /* avivo cursor are offset into the total surface */
  2154. x += crtc->x;
  2155. y += crtc->y;
  2156. DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
  2157. if (x < 0) {
  2158. xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
  2159. x = 0;
  2160. }
  2161. if (y < 0) {
  2162. yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
  2163. y = 0;
  2164. }
  2165. WREG32(mmCUR_POSITION + amdgpu_crtc->crtc_offset, (x << 16) | y);
  2166. WREG32(mmCUR_HOT_SPOT + amdgpu_crtc->crtc_offset, (xorigin << 16) | yorigin);
  2167. WREG32(mmCUR_SIZE + amdgpu_crtc->crtc_offset,
  2168. ((amdgpu_crtc->cursor_width - 1) << 16) | (amdgpu_crtc->cursor_height - 1));
  2169. amdgpu_crtc->cursor_x = x;
  2170. amdgpu_crtc->cursor_y = y;
  2171. return 0;
  2172. }
  2173. static int dce_v8_0_crtc_cursor_move(struct drm_crtc *crtc,
  2174. int x, int y)
  2175. {
  2176. int ret;
  2177. dce_v8_0_lock_cursor(crtc, true);
  2178. ret = dce_v8_0_cursor_move_locked(crtc, x, y);
  2179. dce_v8_0_lock_cursor(crtc, false);
  2180. return ret;
  2181. }
  2182. static int dce_v8_0_crtc_cursor_set2(struct drm_crtc *crtc,
  2183. struct drm_file *file_priv,
  2184. uint32_t handle,
  2185. uint32_t width,
  2186. uint32_t height,
  2187. int32_t hot_x,
  2188. int32_t hot_y)
  2189. {
  2190. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2191. struct drm_gem_object *obj;
  2192. struct amdgpu_bo *aobj;
  2193. int ret;
  2194. if (!handle) {
  2195. /* turn off cursor */
  2196. dce_v8_0_hide_cursor(crtc);
  2197. obj = NULL;
  2198. goto unpin;
  2199. }
  2200. if ((width > amdgpu_crtc->max_cursor_width) ||
  2201. (height > amdgpu_crtc->max_cursor_height)) {
  2202. DRM_ERROR("bad cursor width or height %d x %d\n", width, height);
  2203. return -EINVAL;
  2204. }
  2205. obj = drm_gem_object_lookup(crtc->dev, file_priv, handle);
  2206. if (!obj) {
  2207. DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, amdgpu_crtc->crtc_id);
  2208. return -ENOENT;
  2209. }
  2210. aobj = gem_to_amdgpu_bo(obj);
  2211. ret = amdgpu_bo_reserve(aobj, false);
  2212. if (ret != 0) {
  2213. drm_gem_object_unreference_unlocked(obj);
  2214. return ret;
  2215. }
  2216. ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM, &amdgpu_crtc->cursor_addr);
  2217. amdgpu_bo_unreserve(aobj);
  2218. if (ret) {
  2219. DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret);
  2220. drm_gem_object_unreference_unlocked(obj);
  2221. return ret;
  2222. }
  2223. amdgpu_crtc->cursor_width = width;
  2224. amdgpu_crtc->cursor_height = height;
  2225. dce_v8_0_lock_cursor(crtc, true);
  2226. if (hot_x != amdgpu_crtc->cursor_hot_x ||
  2227. hot_y != amdgpu_crtc->cursor_hot_y) {
  2228. int x, y;
  2229. x = amdgpu_crtc->cursor_x + amdgpu_crtc->cursor_hot_x - hot_x;
  2230. y = amdgpu_crtc->cursor_y + amdgpu_crtc->cursor_hot_y - hot_y;
  2231. dce_v8_0_cursor_move_locked(crtc, x, y);
  2232. amdgpu_crtc->cursor_hot_x = hot_x;
  2233. amdgpu_crtc->cursor_hot_y = hot_y;
  2234. }
  2235. dce_v8_0_show_cursor(crtc);
  2236. dce_v8_0_lock_cursor(crtc, false);
  2237. unpin:
  2238. if (amdgpu_crtc->cursor_bo) {
  2239. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  2240. ret = amdgpu_bo_reserve(aobj, false);
  2241. if (likely(ret == 0)) {
  2242. amdgpu_bo_unpin(aobj);
  2243. amdgpu_bo_unreserve(aobj);
  2244. }
  2245. drm_gem_object_unreference_unlocked(amdgpu_crtc->cursor_bo);
  2246. }
  2247. amdgpu_crtc->cursor_bo = obj;
  2248. return 0;
  2249. }
  2250. static void dce_v8_0_cursor_reset(struct drm_crtc *crtc)
  2251. {
  2252. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2253. if (amdgpu_crtc->cursor_bo) {
  2254. dce_v8_0_lock_cursor(crtc, true);
  2255. dce_v8_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x,
  2256. amdgpu_crtc->cursor_y);
  2257. dce_v8_0_show_cursor(crtc);
  2258. dce_v8_0_lock_cursor(crtc, false);
  2259. }
  2260. }
  2261. static void dce_v8_0_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  2262. u16 *blue, uint32_t start, uint32_t size)
  2263. {
  2264. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2265. int end = (start + size > 256) ? 256 : start + size, i;
  2266. /* userspace palettes are always correct as is */
  2267. for (i = start; i < end; i++) {
  2268. amdgpu_crtc->lut_r[i] = red[i] >> 6;
  2269. amdgpu_crtc->lut_g[i] = green[i] >> 6;
  2270. amdgpu_crtc->lut_b[i] = blue[i] >> 6;
  2271. }
  2272. dce_v8_0_crtc_load_lut(crtc);
  2273. }
  2274. static void dce_v8_0_crtc_destroy(struct drm_crtc *crtc)
  2275. {
  2276. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2277. drm_crtc_cleanup(crtc);
  2278. destroy_workqueue(amdgpu_crtc->pflip_queue);
  2279. kfree(amdgpu_crtc);
  2280. }
  2281. static const struct drm_crtc_funcs dce_v8_0_crtc_funcs = {
  2282. .cursor_set2 = dce_v8_0_crtc_cursor_set2,
  2283. .cursor_move = dce_v8_0_crtc_cursor_move,
  2284. .gamma_set = dce_v8_0_crtc_gamma_set,
  2285. .set_config = amdgpu_crtc_set_config,
  2286. .destroy = dce_v8_0_crtc_destroy,
  2287. .page_flip = amdgpu_crtc_page_flip,
  2288. };
  2289. static void dce_v8_0_crtc_dpms(struct drm_crtc *crtc, int mode)
  2290. {
  2291. struct drm_device *dev = crtc->dev;
  2292. struct amdgpu_device *adev = dev->dev_private;
  2293. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2294. unsigned type;
  2295. switch (mode) {
  2296. case DRM_MODE_DPMS_ON:
  2297. amdgpu_crtc->enabled = true;
  2298. amdgpu_atombios_crtc_enable(crtc, ATOM_ENABLE);
  2299. dce_v8_0_vga_enable(crtc, true);
  2300. amdgpu_atombios_crtc_blank(crtc, ATOM_DISABLE);
  2301. dce_v8_0_vga_enable(crtc, false);
  2302. /* Make sure VBLANK and PFLIP interrupts are still enabled */
  2303. type = amdgpu_crtc_idx_to_irq_type(adev, amdgpu_crtc->crtc_id);
  2304. amdgpu_irq_update(adev, &adev->crtc_irq, type);
  2305. amdgpu_irq_update(adev, &adev->pageflip_irq, type);
  2306. drm_vblank_post_modeset(dev, amdgpu_crtc->crtc_id);
  2307. dce_v8_0_crtc_load_lut(crtc);
  2308. break;
  2309. case DRM_MODE_DPMS_STANDBY:
  2310. case DRM_MODE_DPMS_SUSPEND:
  2311. case DRM_MODE_DPMS_OFF:
  2312. drm_vblank_pre_modeset(dev, amdgpu_crtc->crtc_id);
  2313. if (amdgpu_crtc->enabled) {
  2314. dce_v8_0_vga_enable(crtc, true);
  2315. amdgpu_atombios_crtc_blank(crtc, ATOM_ENABLE);
  2316. dce_v8_0_vga_enable(crtc, false);
  2317. }
  2318. amdgpu_atombios_crtc_enable(crtc, ATOM_DISABLE);
  2319. amdgpu_crtc->enabled = false;
  2320. break;
  2321. }
  2322. /* adjust pm to dpms */
  2323. amdgpu_pm_compute_clocks(adev);
  2324. }
  2325. static void dce_v8_0_crtc_prepare(struct drm_crtc *crtc)
  2326. {
  2327. /* disable crtc pair power gating before programming */
  2328. amdgpu_atombios_crtc_powergate(crtc, ATOM_DISABLE);
  2329. amdgpu_atombios_crtc_lock(crtc, ATOM_ENABLE);
  2330. dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  2331. }
  2332. static void dce_v8_0_crtc_commit(struct drm_crtc *crtc)
  2333. {
  2334. dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
  2335. amdgpu_atombios_crtc_lock(crtc, ATOM_DISABLE);
  2336. }
  2337. static void dce_v8_0_crtc_disable(struct drm_crtc *crtc)
  2338. {
  2339. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2340. struct drm_device *dev = crtc->dev;
  2341. struct amdgpu_device *adev = dev->dev_private;
  2342. struct amdgpu_atom_ss ss;
  2343. int i;
  2344. dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  2345. if (crtc->primary->fb) {
  2346. int r;
  2347. struct amdgpu_framebuffer *amdgpu_fb;
  2348. struct amdgpu_bo *rbo;
  2349. amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
  2350. rbo = gem_to_amdgpu_bo(amdgpu_fb->obj);
  2351. r = amdgpu_bo_reserve(rbo, false);
  2352. if (unlikely(r))
  2353. DRM_ERROR("failed to reserve rbo before unpin\n");
  2354. else {
  2355. amdgpu_bo_unpin(rbo);
  2356. amdgpu_bo_unreserve(rbo);
  2357. }
  2358. }
  2359. /* disable the GRPH */
  2360. dce_v8_0_grph_enable(crtc, false);
  2361. amdgpu_atombios_crtc_powergate(crtc, ATOM_ENABLE);
  2362. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  2363. if (adev->mode_info.crtcs[i] &&
  2364. adev->mode_info.crtcs[i]->enabled &&
  2365. i != amdgpu_crtc->crtc_id &&
  2366. amdgpu_crtc->pll_id == adev->mode_info.crtcs[i]->pll_id) {
  2367. /* one other crtc is using this pll don't turn
  2368. * off the pll
  2369. */
  2370. goto done;
  2371. }
  2372. }
  2373. switch (amdgpu_crtc->pll_id) {
  2374. case ATOM_PPLL1:
  2375. case ATOM_PPLL2:
  2376. /* disable the ppll */
  2377. amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
  2378. 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
  2379. break;
  2380. case ATOM_PPLL0:
  2381. /* disable the ppll */
  2382. if ((adev->asic_type == CHIP_KAVERI) ||
  2383. (adev->asic_type == CHIP_BONAIRE) ||
  2384. (adev->asic_type == CHIP_HAWAII))
  2385. amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
  2386. 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
  2387. break;
  2388. default:
  2389. break;
  2390. }
  2391. done:
  2392. amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
  2393. amdgpu_crtc->adjusted_clock = 0;
  2394. amdgpu_crtc->encoder = NULL;
  2395. amdgpu_crtc->connector = NULL;
  2396. }
  2397. static int dce_v8_0_crtc_mode_set(struct drm_crtc *crtc,
  2398. struct drm_display_mode *mode,
  2399. struct drm_display_mode *adjusted_mode,
  2400. int x, int y, struct drm_framebuffer *old_fb)
  2401. {
  2402. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2403. if (!amdgpu_crtc->adjusted_clock)
  2404. return -EINVAL;
  2405. amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode);
  2406. amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode);
  2407. dce_v8_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
  2408. amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode);
  2409. amdgpu_atombios_crtc_scaler_setup(crtc);
  2410. dce_v8_0_cursor_reset(crtc);
  2411. /* update the hw version fpr dpm */
  2412. amdgpu_crtc->hw_mode = *adjusted_mode;
  2413. return 0;
  2414. }
  2415. static bool dce_v8_0_crtc_mode_fixup(struct drm_crtc *crtc,
  2416. const struct drm_display_mode *mode,
  2417. struct drm_display_mode *adjusted_mode)
  2418. {
  2419. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2420. struct drm_device *dev = crtc->dev;
  2421. struct drm_encoder *encoder;
  2422. /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
  2423. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  2424. if (encoder->crtc == crtc) {
  2425. amdgpu_crtc->encoder = encoder;
  2426. amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder);
  2427. break;
  2428. }
  2429. }
  2430. if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) {
  2431. amdgpu_crtc->encoder = NULL;
  2432. amdgpu_crtc->connector = NULL;
  2433. return false;
  2434. }
  2435. if (!amdgpu_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
  2436. return false;
  2437. if (amdgpu_atombios_crtc_prepare_pll(crtc, adjusted_mode))
  2438. return false;
  2439. /* pick pll */
  2440. amdgpu_crtc->pll_id = dce_v8_0_pick_pll(crtc);
  2441. /* if we can't get a PPLL for a non-DP encoder, fail */
  2442. if ((amdgpu_crtc->pll_id == ATOM_PPLL_INVALID) &&
  2443. !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder)))
  2444. return false;
  2445. return true;
  2446. }
  2447. static int dce_v8_0_crtc_set_base(struct drm_crtc *crtc, int x, int y,
  2448. struct drm_framebuffer *old_fb)
  2449. {
  2450. return dce_v8_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
  2451. }
  2452. static int dce_v8_0_crtc_set_base_atomic(struct drm_crtc *crtc,
  2453. struct drm_framebuffer *fb,
  2454. int x, int y, enum mode_set_atomic state)
  2455. {
  2456. return dce_v8_0_crtc_do_set_base(crtc, fb, x, y, 1);
  2457. }
  2458. static const struct drm_crtc_helper_funcs dce_v8_0_crtc_helper_funcs = {
  2459. .dpms = dce_v8_0_crtc_dpms,
  2460. .mode_fixup = dce_v8_0_crtc_mode_fixup,
  2461. .mode_set = dce_v8_0_crtc_mode_set,
  2462. .mode_set_base = dce_v8_0_crtc_set_base,
  2463. .mode_set_base_atomic = dce_v8_0_crtc_set_base_atomic,
  2464. .prepare = dce_v8_0_crtc_prepare,
  2465. .commit = dce_v8_0_crtc_commit,
  2466. .load_lut = dce_v8_0_crtc_load_lut,
  2467. .disable = dce_v8_0_crtc_disable,
  2468. };
  2469. static int dce_v8_0_crtc_init(struct amdgpu_device *adev, int index)
  2470. {
  2471. struct amdgpu_crtc *amdgpu_crtc;
  2472. int i;
  2473. amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) +
  2474. (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  2475. if (amdgpu_crtc == NULL)
  2476. return -ENOMEM;
  2477. drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_v8_0_crtc_funcs);
  2478. drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256);
  2479. amdgpu_crtc->crtc_id = index;
  2480. amdgpu_crtc->pflip_queue = create_singlethread_workqueue("amdgpu-pageflip-queue");
  2481. adev->mode_info.crtcs[index] = amdgpu_crtc;
  2482. amdgpu_crtc->max_cursor_width = CIK_CURSOR_WIDTH;
  2483. amdgpu_crtc->max_cursor_height = CIK_CURSOR_HEIGHT;
  2484. adev->ddev->mode_config.cursor_width = amdgpu_crtc->max_cursor_width;
  2485. adev->ddev->mode_config.cursor_height = amdgpu_crtc->max_cursor_height;
  2486. for (i = 0; i < 256; i++) {
  2487. amdgpu_crtc->lut_r[i] = i << 2;
  2488. amdgpu_crtc->lut_g[i] = i << 2;
  2489. amdgpu_crtc->lut_b[i] = i << 2;
  2490. }
  2491. amdgpu_crtc->crtc_offset = crtc_offsets[amdgpu_crtc->crtc_id];
  2492. amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
  2493. amdgpu_crtc->adjusted_clock = 0;
  2494. amdgpu_crtc->encoder = NULL;
  2495. amdgpu_crtc->connector = NULL;
  2496. drm_crtc_helper_add(&amdgpu_crtc->base, &dce_v8_0_crtc_helper_funcs);
  2497. return 0;
  2498. }
  2499. static int dce_v8_0_early_init(void *handle)
  2500. {
  2501. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2502. adev->audio_endpt_rreg = &dce_v8_0_audio_endpt_rreg;
  2503. adev->audio_endpt_wreg = &dce_v8_0_audio_endpt_wreg;
  2504. dce_v8_0_set_display_funcs(adev);
  2505. dce_v8_0_set_irq_funcs(adev);
  2506. switch (adev->asic_type) {
  2507. case CHIP_BONAIRE:
  2508. case CHIP_HAWAII:
  2509. adev->mode_info.num_crtc = 6;
  2510. adev->mode_info.num_hpd = 6;
  2511. adev->mode_info.num_dig = 6;
  2512. break;
  2513. case CHIP_KAVERI:
  2514. adev->mode_info.num_crtc = 4;
  2515. adev->mode_info.num_hpd = 6;
  2516. adev->mode_info.num_dig = 7;
  2517. break;
  2518. case CHIP_KABINI:
  2519. case CHIP_MULLINS:
  2520. adev->mode_info.num_crtc = 2;
  2521. adev->mode_info.num_hpd = 6;
  2522. adev->mode_info.num_dig = 6; /* ? */
  2523. break;
  2524. default:
  2525. /* FIXME: not supported yet */
  2526. return -EINVAL;
  2527. }
  2528. return 0;
  2529. }
  2530. static int dce_v8_0_sw_init(void *handle)
  2531. {
  2532. int r, i;
  2533. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2534. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  2535. r = amdgpu_irq_add_id(adev, i + 1, &adev->crtc_irq);
  2536. if (r)
  2537. return r;
  2538. }
  2539. for (i = 8; i < 20; i += 2) {
  2540. r = amdgpu_irq_add_id(adev, i, &adev->pageflip_irq);
  2541. if (r)
  2542. return r;
  2543. }
  2544. /* HPD hotplug */
  2545. r = amdgpu_irq_add_id(adev, 42, &adev->hpd_irq);
  2546. if (r)
  2547. return r;
  2548. adev->mode_info.mode_config_initialized = true;
  2549. adev->ddev->mode_config.funcs = &amdgpu_mode_funcs;
  2550. adev->ddev->mode_config.max_width = 16384;
  2551. adev->ddev->mode_config.max_height = 16384;
  2552. adev->ddev->mode_config.preferred_depth = 24;
  2553. adev->ddev->mode_config.prefer_shadow = 1;
  2554. adev->ddev->mode_config.fb_base = adev->mc.aper_base;
  2555. r = amdgpu_modeset_create_props(adev);
  2556. if (r)
  2557. return r;
  2558. adev->ddev->mode_config.max_width = 16384;
  2559. adev->ddev->mode_config.max_height = 16384;
  2560. /* allocate crtcs */
  2561. for (i = 0; i < adev->mode_info.num_crtc; i++) {
  2562. r = dce_v8_0_crtc_init(adev, i);
  2563. if (r)
  2564. return r;
  2565. }
  2566. if (amdgpu_atombios_get_connector_info_from_object_table(adev))
  2567. amdgpu_print_display_setup(adev->ddev);
  2568. else
  2569. return -EINVAL;
  2570. /* setup afmt */
  2571. dce_v8_0_afmt_init(adev);
  2572. r = dce_v8_0_audio_init(adev);
  2573. if (r)
  2574. return r;
  2575. drm_kms_helper_poll_init(adev->ddev);
  2576. return r;
  2577. }
  2578. static int dce_v8_0_sw_fini(void *handle)
  2579. {
  2580. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2581. kfree(adev->mode_info.bios_hardcoded_edid);
  2582. drm_kms_helper_poll_fini(adev->ddev);
  2583. dce_v8_0_audio_fini(adev);
  2584. dce_v8_0_afmt_fini(adev);
  2585. drm_mode_config_cleanup(adev->ddev);
  2586. adev->mode_info.mode_config_initialized = false;
  2587. return 0;
  2588. }
  2589. static int dce_v8_0_hw_init(void *handle)
  2590. {
  2591. int i;
  2592. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2593. /* init dig PHYs, disp eng pll */
  2594. amdgpu_atombios_encoder_init_dig(adev);
  2595. amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk);
  2596. /* initialize hpd */
  2597. dce_v8_0_hpd_init(adev);
  2598. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  2599. dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  2600. }
  2601. dce_v8_0_pageflip_interrupt_init(adev);
  2602. return 0;
  2603. }
  2604. static int dce_v8_0_hw_fini(void *handle)
  2605. {
  2606. int i;
  2607. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2608. dce_v8_0_hpd_fini(adev);
  2609. for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
  2610. dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
  2611. }
  2612. dce_v8_0_pageflip_interrupt_fini(adev);
  2613. return 0;
  2614. }
  2615. static int dce_v8_0_suspend(void *handle)
  2616. {
  2617. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2618. amdgpu_atombios_scratch_regs_save(adev);
  2619. return dce_v8_0_hw_fini(handle);
  2620. }
  2621. static int dce_v8_0_resume(void *handle)
  2622. {
  2623. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2624. int ret;
  2625. ret = dce_v8_0_hw_init(handle);
  2626. amdgpu_atombios_scratch_regs_restore(adev);
  2627. /* turn on the BL */
  2628. if (adev->mode_info.bl_encoder) {
  2629. u8 bl_level = amdgpu_display_backlight_get_level(adev,
  2630. adev->mode_info.bl_encoder);
  2631. amdgpu_display_backlight_set_level(adev, adev->mode_info.bl_encoder,
  2632. bl_level);
  2633. }
  2634. return ret;
  2635. }
  2636. static bool dce_v8_0_is_idle(void *handle)
  2637. {
  2638. return true;
  2639. }
  2640. static int dce_v8_0_wait_for_idle(void *handle)
  2641. {
  2642. return 0;
  2643. }
  2644. static void dce_v8_0_print_status(void *handle)
  2645. {
  2646. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2647. dev_info(adev->dev, "DCE 8.x registers\n");
  2648. /* XXX todo */
  2649. }
  2650. static int dce_v8_0_soft_reset(void *handle)
  2651. {
  2652. u32 srbm_soft_reset = 0, tmp;
  2653. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2654. if (dce_v8_0_is_display_hung(adev))
  2655. srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK;
  2656. if (srbm_soft_reset) {
  2657. dce_v8_0_print_status((void *)adev);
  2658. tmp = RREG32(mmSRBM_SOFT_RESET);
  2659. tmp |= srbm_soft_reset;
  2660. dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  2661. WREG32(mmSRBM_SOFT_RESET, tmp);
  2662. tmp = RREG32(mmSRBM_SOFT_RESET);
  2663. udelay(50);
  2664. tmp &= ~srbm_soft_reset;
  2665. WREG32(mmSRBM_SOFT_RESET, tmp);
  2666. tmp = RREG32(mmSRBM_SOFT_RESET);
  2667. /* Wait a little for things to settle down */
  2668. udelay(50);
  2669. dce_v8_0_print_status((void *)adev);
  2670. }
  2671. return 0;
  2672. }
  2673. static void dce_v8_0_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev,
  2674. int crtc,
  2675. enum amdgpu_interrupt_state state)
  2676. {
  2677. u32 reg_block, lb_interrupt_mask;
  2678. if (crtc >= adev->mode_info.num_crtc) {
  2679. DRM_DEBUG("invalid crtc %d\n", crtc);
  2680. return;
  2681. }
  2682. switch (crtc) {
  2683. case 0:
  2684. reg_block = CRTC0_REGISTER_OFFSET;
  2685. break;
  2686. case 1:
  2687. reg_block = CRTC1_REGISTER_OFFSET;
  2688. break;
  2689. case 2:
  2690. reg_block = CRTC2_REGISTER_OFFSET;
  2691. break;
  2692. case 3:
  2693. reg_block = CRTC3_REGISTER_OFFSET;
  2694. break;
  2695. case 4:
  2696. reg_block = CRTC4_REGISTER_OFFSET;
  2697. break;
  2698. case 5:
  2699. reg_block = CRTC5_REGISTER_OFFSET;
  2700. break;
  2701. default:
  2702. DRM_DEBUG("invalid crtc %d\n", crtc);
  2703. return;
  2704. }
  2705. switch (state) {
  2706. case AMDGPU_IRQ_STATE_DISABLE:
  2707. lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
  2708. lb_interrupt_mask &= ~LB_INTERRUPT_MASK__VBLANK_INTERRUPT_MASK_MASK;
  2709. WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
  2710. break;
  2711. case AMDGPU_IRQ_STATE_ENABLE:
  2712. lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
  2713. lb_interrupt_mask |= LB_INTERRUPT_MASK__VBLANK_INTERRUPT_MASK_MASK;
  2714. WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
  2715. break;
  2716. default:
  2717. break;
  2718. }
  2719. }
  2720. static void dce_v8_0_set_crtc_vline_interrupt_state(struct amdgpu_device *adev,
  2721. int crtc,
  2722. enum amdgpu_interrupt_state state)
  2723. {
  2724. u32 reg_block, lb_interrupt_mask;
  2725. if (crtc >= adev->mode_info.num_crtc) {
  2726. DRM_DEBUG("invalid crtc %d\n", crtc);
  2727. return;
  2728. }
  2729. switch (crtc) {
  2730. case 0:
  2731. reg_block = CRTC0_REGISTER_OFFSET;
  2732. break;
  2733. case 1:
  2734. reg_block = CRTC1_REGISTER_OFFSET;
  2735. break;
  2736. case 2:
  2737. reg_block = CRTC2_REGISTER_OFFSET;
  2738. break;
  2739. case 3:
  2740. reg_block = CRTC3_REGISTER_OFFSET;
  2741. break;
  2742. case 4:
  2743. reg_block = CRTC4_REGISTER_OFFSET;
  2744. break;
  2745. case 5:
  2746. reg_block = CRTC5_REGISTER_OFFSET;
  2747. break;
  2748. default:
  2749. DRM_DEBUG("invalid crtc %d\n", crtc);
  2750. return;
  2751. }
  2752. switch (state) {
  2753. case AMDGPU_IRQ_STATE_DISABLE:
  2754. lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
  2755. lb_interrupt_mask &= ~LB_INTERRUPT_MASK__VLINE_INTERRUPT_MASK_MASK;
  2756. WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
  2757. break;
  2758. case AMDGPU_IRQ_STATE_ENABLE:
  2759. lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
  2760. lb_interrupt_mask |= LB_INTERRUPT_MASK__VLINE_INTERRUPT_MASK_MASK;
  2761. WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
  2762. break;
  2763. default:
  2764. break;
  2765. }
  2766. }
  2767. static int dce_v8_0_set_hpd_interrupt_state(struct amdgpu_device *adev,
  2768. struct amdgpu_irq_src *src,
  2769. unsigned type,
  2770. enum amdgpu_interrupt_state state)
  2771. {
  2772. u32 dc_hpd_int_cntl_reg, dc_hpd_int_cntl;
  2773. switch (type) {
  2774. case AMDGPU_HPD_1:
  2775. dc_hpd_int_cntl_reg = mmDC_HPD1_INT_CONTROL;
  2776. break;
  2777. case AMDGPU_HPD_2:
  2778. dc_hpd_int_cntl_reg = mmDC_HPD2_INT_CONTROL;
  2779. break;
  2780. case AMDGPU_HPD_3:
  2781. dc_hpd_int_cntl_reg = mmDC_HPD3_INT_CONTROL;
  2782. break;
  2783. case AMDGPU_HPD_4:
  2784. dc_hpd_int_cntl_reg = mmDC_HPD4_INT_CONTROL;
  2785. break;
  2786. case AMDGPU_HPD_5:
  2787. dc_hpd_int_cntl_reg = mmDC_HPD5_INT_CONTROL;
  2788. break;
  2789. case AMDGPU_HPD_6:
  2790. dc_hpd_int_cntl_reg = mmDC_HPD6_INT_CONTROL;
  2791. break;
  2792. default:
  2793. DRM_DEBUG("invalid hdp %d\n", type);
  2794. return 0;
  2795. }
  2796. switch (state) {
  2797. case AMDGPU_IRQ_STATE_DISABLE:
  2798. dc_hpd_int_cntl = RREG32(dc_hpd_int_cntl_reg);
  2799. dc_hpd_int_cntl &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
  2800. WREG32(dc_hpd_int_cntl_reg, dc_hpd_int_cntl);
  2801. break;
  2802. case AMDGPU_IRQ_STATE_ENABLE:
  2803. dc_hpd_int_cntl = RREG32(dc_hpd_int_cntl_reg);
  2804. dc_hpd_int_cntl |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
  2805. WREG32(dc_hpd_int_cntl_reg, dc_hpd_int_cntl);
  2806. break;
  2807. default:
  2808. break;
  2809. }
  2810. return 0;
  2811. }
  2812. static int dce_v8_0_set_crtc_interrupt_state(struct amdgpu_device *adev,
  2813. struct amdgpu_irq_src *src,
  2814. unsigned type,
  2815. enum amdgpu_interrupt_state state)
  2816. {
  2817. switch (type) {
  2818. case AMDGPU_CRTC_IRQ_VBLANK1:
  2819. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 0, state);
  2820. break;
  2821. case AMDGPU_CRTC_IRQ_VBLANK2:
  2822. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 1, state);
  2823. break;
  2824. case AMDGPU_CRTC_IRQ_VBLANK3:
  2825. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 2, state);
  2826. break;
  2827. case AMDGPU_CRTC_IRQ_VBLANK4:
  2828. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 3, state);
  2829. break;
  2830. case AMDGPU_CRTC_IRQ_VBLANK5:
  2831. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 4, state);
  2832. break;
  2833. case AMDGPU_CRTC_IRQ_VBLANK6:
  2834. dce_v8_0_set_crtc_vblank_interrupt_state(adev, 5, state);
  2835. break;
  2836. case AMDGPU_CRTC_IRQ_VLINE1:
  2837. dce_v8_0_set_crtc_vline_interrupt_state(adev, 0, state);
  2838. break;
  2839. case AMDGPU_CRTC_IRQ_VLINE2:
  2840. dce_v8_0_set_crtc_vline_interrupt_state(adev, 1, state);
  2841. break;
  2842. case AMDGPU_CRTC_IRQ_VLINE3:
  2843. dce_v8_0_set_crtc_vline_interrupt_state(adev, 2, state);
  2844. break;
  2845. case AMDGPU_CRTC_IRQ_VLINE4:
  2846. dce_v8_0_set_crtc_vline_interrupt_state(adev, 3, state);
  2847. break;
  2848. case AMDGPU_CRTC_IRQ_VLINE5:
  2849. dce_v8_0_set_crtc_vline_interrupt_state(adev, 4, state);
  2850. break;
  2851. case AMDGPU_CRTC_IRQ_VLINE6:
  2852. dce_v8_0_set_crtc_vline_interrupt_state(adev, 5, state);
  2853. break;
  2854. default:
  2855. break;
  2856. }
  2857. return 0;
  2858. }
  2859. static int dce_v8_0_crtc_irq(struct amdgpu_device *adev,
  2860. struct amdgpu_irq_src *source,
  2861. struct amdgpu_iv_entry *entry)
  2862. {
  2863. unsigned crtc = entry->src_id - 1;
  2864. uint32_t disp_int = RREG32(interrupt_status_offsets[crtc].reg);
  2865. unsigned irq_type = amdgpu_crtc_idx_to_irq_type(adev, crtc);
  2866. switch (entry->src_data) {
  2867. case 0: /* vblank */
  2868. if (disp_int & interrupt_status_offsets[crtc].vblank)
  2869. WREG32(mmLB_VBLANK_STATUS + crtc_offsets[crtc], LB_VBLANK_STATUS__VBLANK_ACK_MASK);
  2870. else
  2871. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  2872. if (amdgpu_irq_enabled(adev, source, irq_type)) {
  2873. drm_handle_vblank(adev->ddev, crtc);
  2874. }
  2875. DRM_DEBUG("IH: D%d vblank\n", crtc + 1);
  2876. break;
  2877. case 1: /* vline */
  2878. if (disp_int & interrupt_status_offsets[crtc].vline)
  2879. WREG32(mmLB_VLINE_STATUS + crtc_offsets[crtc], LB_VLINE_STATUS__VLINE_ACK_MASK);
  2880. else
  2881. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  2882. DRM_DEBUG("IH: D%d vline\n", crtc + 1);
  2883. break;
  2884. default:
  2885. DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data);
  2886. break;
  2887. }
  2888. return 0;
  2889. }
  2890. static int dce_v8_0_set_pageflip_interrupt_state(struct amdgpu_device *adev,
  2891. struct amdgpu_irq_src *src,
  2892. unsigned type,
  2893. enum amdgpu_interrupt_state state)
  2894. {
  2895. u32 reg;
  2896. if (type >= adev->mode_info.num_crtc) {
  2897. DRM_ERROR("invalid pageflip crtc %d\n", type);
  2898. return -EINVAL;
  2899. }
  2900. reg = RREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type]);
  2901. if (state == AMDGPU_IRQ_STATE_DISABLE)
  2902. WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
  2903. reg & ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
  2904. else
  2905. WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
  2906. reg | GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
  2907. return 0;
  2908. }
  2909. static int dce_v8_0_pageflip_irq(struct amdgpu_device *adev,
  2910. struct amdgpu_irq_src *source,
  2911. struct amdgpu_iv_entry *entry)
  2912. {
  2913. unsigned long flags;
  2914. unsigned crtc_id;
  2915. struct amdgpu_crtc *amdgpu_crtc;
  2916. struct amdgpu_flip_work *works;
  2917. crtc_id = (entry->src_id - 8) >> 1;
  2918. amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
  2919. if (crtc_id >= adev->mode_info.num_crtc) {
  2920. DRM_ERROR("invalid pageflip crtc %d\n", crtc_id);
  2921. return -EINVAL;
  2922. }
  2923. if (RREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id]) &
  2924. GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK)
  2925. WREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id],
  2926. GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK);
  2927. /* IRQ could occur when in initial stage */
  2928. if (amdgpu_crtc == NULL)
  2929. return 0;
  2930. spin_lock_irqsave(&adev->ddev->event_lock, flags);
  2931. works = amdgpu_crtc->pflip_works;
  2932. if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){
  2933. DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
  2934. "AMDGPU_FLIP_SUBMITTED(%d)\n",
  2935. amdgpu_crtc->pflip_status,
  2936. AMDGPU_FLIP_SUBMITTED);
  2937. spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  2938. return 0;
  2939. }
  2940. /* page flip completed. clean up */
  2941. amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
  2942. amdgpu_crtc->pflip_works = NULL;
  2943. /* wakeup usersapce */
  2944. if (works->event)
  2945. drm_send_vblank_event(adev->ddev, crtc_id, works->event);
  2946. spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
  2947. drm_vblank_put(adev->ddev, amdgpu_crtc->crtc_id);
  2948. queue_work(amdgpu_crtc->pflip_queue, &works->unpin_work);
  2949. return 0;
  2950. }
  2951. static int dce_v8_0_hpd_irq(struct amdgpu_device *adev,
  2952. struct amdgpu_irq_src *source,
  2953. struct amdgpu_iv_entry *entry)
  2954. {
  2955. uint32_t disp_int, mask, int_control, tmp;
  2956. unsigned hpd;
  2957. if (entry->src_data >= adev->mode_info.num_hpd) {
  2958. DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data);
  2959. return 0;
  2960. }
  2961. hpd = entry->src_data;
  2962. disp_int = RREG32(interrupt_status_offsets[hpd].reg);
  2963. mask = interrupt_status_offsets[hpd].hpd;
  2964. int_control = hpd_int_control_offsets[hpd];
  2965. if (disp_int & mask) {
  2966. tmp = RREG32(int_control);
  2967. tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_ACK_MASK;
  2968. WREG32(int_control, tmp);
  2969. schedule_work(&adev->hotplug_work);
  2970. DRM_DEBUG("IH: HPD%d\n", hpd + 1);
  2971. }
  2972. return 0;
  2973. }
  2974. static int dce_v8_0_set_clockgating_state(void *handle,
  2975. enum amd_clockgating_state state)
  2976. {
  2977. return 0;
  2978. }
  2979. static int dce_v8_0_set_powergating_state(void *handle,
  2980. enum amd_powergating_state state)
  2981. {
  2982. return 0;
  2983. }
  2984. const struct amd_ip_funcs dce_v8_0_ip_funcs = {
  2985. .early_init = dce_v8_0_early_init,
  2986. .late_init = NULL,
  2987. .sw_init = dce_v8_0_sw_init,
  2988. .sw_fini = dce_v8_0_sw_fini,
  2989. .hw_init = dce_v8_0_hw_init,
  2990. .hw_fini = dce_v8_0_hw_fini,
  2991. .suspend = dce_v8_0_suspend,
  2992. .resume = dce_v8_0_resume,
  2993. .is_idle = dce_v8_0_is_idle,
  2994. .wait_for_idle = dce_v8_0_wait_for_idle,
  2995. .soft_reset = dce_v8_0_soft_reset,
  2996. .print_status = dce_v8_0_print_status,
  2997. .set_clockgating_state = dce_v8_0_set_clockgating_state,
  2998. .set_powergating_state = dce_v8_0_set_powergating_state,
  2999. };
  3000. static void
  3001. dce_v8_0_encoder_mode_set(struct drm_encoder *encoder,
  3002. struct drm_display_mode *mode,
  3003. struct drm_display_mode *adjusted_mode)
  3004. {
  3005. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  3006. amdgpu_encoder->pixel_clock = adjusted_mode->clock;
  3007. /* need to call this here rather than in prepare() since we need some crtc info */
  3008. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  3009. /* set scaler clears this on some chips */
  3010. dce_v8_0_set_interleave(encoder->crtc, mode);
  3011. if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
  3012. dce_v8_0_afmt_enable(encoder, true);
  3013. dce_v8_0_afmt_setmode(encoder, adjusted_mode);
  3014. }
  3015. }
  3016. static void dce_v8_0_encoder_prepare(struct drm_encoder *encoder)
  3017. {
  3018. struct amdgpu_device *adev = encoder->dev->dev_private;
  3019. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  3020. struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
  3021. if ((amdgpu_encoder->active_device &
  3022. (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
  3023. (amdgpu_encoder_get_dp_bridge_encoder_id(encoder) !=
  3024. ENCODER_OBJECT_ID_NONE)) {
  3025. struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
  3026. if (dig) {
  3027. dig->dig_encoder = dce_v8_0_pick_dig_encoder(encoder);
  3028. if (amdgpu_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT)
  3029. dig->afmt = adev->mode_info.afmt[dig->dig_encoder];
  3030. }
  3031. }
  3032. amdgpu_atombios_scratch_regs_lock(adev, true);
  3033. if (connector) {
  3034. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  3035. /* select the clock/data port if it uses a router */
  3036. if (amdgpu_connector->router.cd_valid)
  3037. amdgpu_i2c_router_select_cd_port(amdgpu_connector);
  3038. /* turn eDP panel on for mode set */
  3039. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  3040. amdgpu_atombios_encoder_set_edp_panel_power(connector,
  3041. ATOM_TRANSMITTER_ACTION_POWER_ON);
  3042. }
  3043. /* this is needed for the pll/ss setup to work correctly in some cases */
  3044. amdgpu_atombios_encoder_set_crtc_source(encoder);
  3045. /* set up the FMT blocks */
  3046. dce_v8_0_program_fmt(encoder);
  3047. }
  3048. static void dce_v8_0_encoder_commit(struct drm_encoder *encoder)
  3049. {
  3050. struct drm_device *dev = encoder->dev;
  3051. struct amdgpu_device *adev = dev->dev_private;
  3052. /* need to call this here as we need the crtc set up */
  3053. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
  3054. amdgpu_atombios_scratch_regs_lock(adev, false);
  3055. }
  3056. static void dce_v8_0_encoder_disable(struct drm_encoder *encoder)
  3057. {
  3058. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  3059. struct amdgpu_encoder_atom_dig *dig;
  3060. amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  3061. if (amdgpu_atombios_encoder_is_digital(encoder)) {
  3062. if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
  3063. dce_v8_0_afmt_enable(encoder, false);
  3064. dig = amdgpu_encoder->enc_priv;
  3065. dig->dig_encoder = -1;
  3066. }
  3067. amdgpu_encoder->active_device = 0;
  3068. }
  3069. /* these are handled by the primary encoders */
  3070. static void dce_v8_0_ext_prepare(struct drm_encoder *encoder)
  3071. {
  3072. }
  3073. static void dce_v8_0_ext_commit(struct drm_encoder *encoder)
  3074. {
  3075. }
  3076. static void
  3077. dce_v8_0_ext_mode_set(struct drm_encoder *encoder,
  3078. struct drm_display_mode *mode,
  3079. struct drm_display_mode *adjusted_mode)
  3080. {
  3081. }
  3082. static void dce_v8_0_ext_disable(struct drm_encoder *encoder)
  3083. {
  3084. }
  3085. static void
  3086. dce_v8_0_ext_dpms(struct drm_encoder *encoder, int mode)
  3087. {
  3088. }
  3089. static bool dce_v8_0_ext_mode_fixup(struct drm_encoder *encoder,
  3090. const struct drm_display_mode *mode,
  3091. struct drm_display_mode *adjusted_mode)
  3092. {
  3093. return true;
  3094. }
  3095. static const struct drm_encoder_helper_funcs dce_v8_0_ext_helper_funcs = {
  3096. .dpms = dce_v8_0_ext_dpms,
  3097. .mode_fixup = dce_v8_0_ext_mode_fixup,
  3098. .prepare = dce_v8_0_ext_prepare,
  3099. .mode_set = dce_v8_0_ext_mode_set,
  3100. .commit = dce_v8_0_ext_commit,
  3101. .disable = dce_v8_0_ext_disable,
  3102. /* no detect for TMDS/LVDS yet */
  3103. };
  3104. static const struct drm_encoder_helper_funcs dce_v8_0_dig_helper_funcs = {
  3105. .dpms = amdgpu_atombios_encoder_dpms,
  3106. .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
  3107. .prepare = dce_v8_0_encoder_prepare,
  3108. .mode_set = dce_v8_0_encoder_mode_set,
  3109. .commit = dce_v8_0_encoder_commit,
  3110. .disable = dce_v8_0_encoder_disable,
  3111. .detect = amdgpu_atombios_encoder_dig_detect,
  3112. };
  3113. static const struct drm_encoder_helper_funcs dce_v8_0_dac_helper_funcs = {
  3114. .dpms = amdgpu_atombios_encoder_dpms,
  3115. .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
  3116. .prepare = dce_v8_0_encoder_prepare,
  3117. .mode_set = dce_v8_0_encoder_mode_set,
  3118. .commit = dce_v8_0_encoder_commit,
  3119. .detect = amdgpu_atombios_encoder_dac_detect,
  3120. };
  3121. static void dce_v8_0_encoder_destroy(struct drm_encoder *encoder)
  3122. {
  3123. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  3124. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  3125. amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder);
  3126. kfree(amdgpu_encoder->enc_priv);
  3127. drm_encoder_cleanup(encoder);
  3128. kfree(amdgpu_encoder);
  3129. }
  3130. static const struct drm_encoder_funcs dce_v8_0_encoder_funcs = {
  3131. .destroy = dce_v8_0_encoder_destroy,
  3132. };
  3133. static void dce_v8_0_encoder_add(struct amdgpu_device *adev,
  3134. uint32_t encoder_enum,
  3135. uint32_t supported_device,
  3136. u16 caps)
  3137. {
  3138. struct drm_device *dev = adev->ddev;
  3139. struct drm_encoder *encoder;
  3140. struct amdgpu_encoder *amdgpu_encoder;
  3141. /* see if we already added it */
  3142. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  3143. amdgpu_encoder = to_amdgpu_encoder(encoder);
  3144. if (amdgpu_encoder->encoder_enum == encoder_enum) {
  3145. amdgpu_encoder->devices |= supported_device;
  3146. return;
  3147. }
  3148. }
  3149. /* add a new one */
  3150. amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL);
  3151. if (!amdgpu_encoder)
  3152. return;
  3153. encoder = &amdgpu_encoder->base;
  3154. switch (adev->mode_info.num_crtc) {
  3155. case 1:
  3156. encoder->possible_crtcs = 0x1;
  3157. break;
  3158. case 2:
  3159. default:
  3160. encoder->possible_crtcs = 0x3;
  3161. break;
  3162. case 4:
  3163. encoder->possible_crtcs = 0xf;
  3164. break;
  3165. case 6:
  3166. encoder->possible_crtcs = 0x3f;
  3167. break;
  3168. }
  3169. amdgpu_encoder->enc_priv = NULL;
  3170. amdgpu_encoder->encoder_enum = encoder_enum;
  3171. amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  3172. amdgpu_encoder->devices = supported_device;
  3173. amdgpu_encoder->rmx_type = RMX_OFF;
  3174. amdgpu_encoder->underscan_type = UNDERSCAN_OFF;
  3175. amdgpu_encoder->is_ext_encoder = false;
  3176. amdgpu_encoder->caps = caps;
  3177. switch (amdgpu_encoder->encoder_id) {
  3178. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
  3179. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
  3180. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3181. DRM_MODE_ENCODER_DAC);
  3182. drm_encoder_helper_add(encoder, &dce_v8_0_dac_helper_funcs);
  3183. break;
  3184. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  3185. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  3186. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  3187. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  3188. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  3189. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  3190. amdgpu_encoder->rmx_type = RMX_FULL;
  3191. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3192. DRM_MODE_ENCODER_LVDS);
  3193. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder);
  3194. } else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
  3195. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3196. DRM_MODE_ENCODER_DAC);
  3197. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
  3198. } else {
  3199. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3200. DRM_MODE_ENCODER_TMDS);
  3201. amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
  3202. }
  3203. drm_encoder_helper_add(encoder, &dce_v8_0_dig_helper_funcs);
  3204. break;
  3205. case ENCODER_OBJECT_ID_SI170B:
  3206. case ENCODER_OBJECT_ID_CH7303:
  3207. case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
  3208. case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
  3209. case ENCODER_OBJECT_ID_TITFP513:
  3210. case ENCODER_OBJECT_ID_VT1623:
  3211. case ENCODER_OBJECT_ID_HDMI_SI1930:
  3212. case ENCODER_OBJECT_ID_TRAVIS:
  3213. case ENCODER_OBJECT_ID_NUTMEG:
  3214. /* these are handled by the primary encoders */
  3215. amdgpu_encoder->is_ext_encoder = true;
  3216. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  3217. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3218. DRM_MODE_ENCODER_LVDS);
  3219. else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
  3220. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3221. DRM_MODE_ENCODER_DAC);
  3222. else
  3223. drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
  3224. DRM_MODE_ENCODER_TMDS);
  3225. drm_encoder_helper_add(encoder, &dce_v8_0_ext_helper_funcs);
  3226. break;
  3227. }
  3228. }
  3229. static const struct amdgpu_display_funcs dce_v8_0_display_funcs = {
  3230. .set_vga_render_state = &dce_v8_0_set_vga_render_state,
  3231. .bandwidth_update = &dce_v8_0_bandwidth_update,
  3232. .vblank_get_counter = &dce_v8_0_vblank_get_counter,
  3233. .vblank_wait = &dce_v8_0_vblank_wait,
  3234. .is_display_hung = &dce_v8_0_is_display_hung,
  3235. .backlight_set_level = &amdgpu_atombios_encoder_set_backlight_level,
  3236. .backlight_get_level = &amdgpu_atombios_encoder_get_backlight_level,
  3237. .hpd_sense = &dce_v8_0_hpd_sense,
  3238. .hpd_set_polarity = &dce_v8_0_hpd_set_polarity,
  3239. .hpd_get_gpio_reg = &dce_v8_0_hpd_get_gpio_reg,
  3240. .page_flip = &dce_v8_0_page_flip,
  3241. .page_flip_get_scanoutpos = &dce_v8_0_crtc_get_scanoutpos,
  3242. .add_encoder = &dce_v8_0_encoder_add,
  3243. .add_connector = &amdgpu_connector_add,
  3244. .stop_mc_access = &dce_v8_0_stop_mc_access,
  3245. .resume_mc_access = &dce_v8_0_resume_mc_access,
  3246. };
  3247. static void dce_v8_0_set_display_funcs(struct amdgpu_device *adev)
  3248. {
  3249. if (adev->mode_info.funcs == NULL)
  3250. adev->mode_info.funcs = &dce_v8_0_display_funcs;
  3251. }
  3252. static const struct amdgpu_irq_src_funcs dce_v8_0_crtc_irq_funcs = {
  3253. .set = dce_v8_0_set_crtc_interrupt_state,
  3254. .process = dce_v8_0_crtc_irq,
  3255. };
  3256. static const struct amdgpu_irq_src_funcs dce_v8_0_pageflip_irq_funcs = {
  3257. .set = dce_v8_0_set_pageflip_interrupt_state,
  3258. .process = dce_v8_0_pageflip_irq,
  3259. };
  3260. static const struct amdgpu_irq_src_funcs dce_v8_0_hpd_irq_funcs = {
  3261. .set = dce_v8_0_set_hpd_interrupt_state,
  3262. .process = dce_v8_0_hpd_irq,
  3263. };
  3264. static void dce_v8_0_set_irq_funcs(struct amdgpu_device *adev)
  3265. {
  3266. adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_LAST;
  3267. adev->crtc_irq.funcs = &dce_v8_0_crtc_irq_funcs;
  3268. adev->pageflip_irq.num_types = AMDGPU_PAGEFLIP_IRQ_LAST;
  3269. adev->pageflip_irq.funcs = &dce_v8_0_pageflip_irq_funcs;
  3270. adev->hpd_irq.num_types = AMDGPU_HPD_LAST;
  3271. adev->hpd_irq.funcs = &dce_v8_0_hpd_irq_funcs;
  3272. }