dce_v6_0.c 89 KB

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