dce_v6_0.c 90 KB

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