dce_v6_0.c 90 KB

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