atombios_crtc.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/drm_crtc_helper.h>
  28. #include <drm/radeon_drm.h>
  29. #include <drm/drm_fixed.h>
  30. #include "radeon.h"
  31. #include "atom.h"
  32. #include "atom-bits.h"
  33. static void atombios_overscan_setup(struct drm_crtc *crtc,
  34. struct drm_display_mode *mode,
  35. struct drm_display_mode *adjusted_mode)
  36. {
  37. struct drm_device *dev = crtc->dev;
  38. struct radeon_device *rdev = dev->dev_private;
  39. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  40. SET_CRTC_OVERSCAN_PS_ALLOCATION args;
  41. int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_OverScan);
  42. int a1, a2;
  43. memset(&args, 0, sizeof(args));
  44. args.ucCRTC = radeon_crtc->crtc_id;
  45. switch (radeon_crtc->rmx_type) {
  46. case RMX_CENTER:
  47. args.usOverscanTop = cpu_to_le16((adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2);
  48. args.usOverscanBottom = cpu_to_le16((adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2);
  49. args.usOverscanLeft = cpu_to_le16((adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2);
  50. args.usOverscanRight = cpu_to_le16((adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2);
  51. break;
  52. case RMX_ASPECT:
  53. a1 = mode->crtc_vdisplay * adjusted_mode->crtc_hdisplay;
  54. a2 = adjusted_mode->crtc_vdisplay * mode->crtc_hdisplay;
  55. if (a1 > a2) {
  56. args.usOverscanLeft = cpu_to_le16((adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2);
  57. args.usOverscanRight = cpu_to_le16((adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2);
  58. } else if (a2 > a1) {
  59. args.usOverscanTop = cpu_to_le16((adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2);
  60. args.usOverscanBottom = cpu_to_le16((adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2);
  61. }
  62. break;
  63. case RMX_FULL:
  64. default:
  65. args.usOverscanRight = cpu_to_le16(radeon_crtc->h_border);
  66. args.usOverscanLeft = cpu_to_le16(radeon_crtc->h_border);
  67. args.usOverscanBottom = cpu_to_le16(radeon_crtc->v_border);
  68. args.usOverscanTop = cpu_to_le16(radeon_crtc->v_border);
  69. break;
  70. }
  71. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  72. }
  73. static void atombios_scaler_setup(struct drm_crtc *crtc)
  74. {
  75. struct drm_device *dev = crtc->dev;
  76. struct radeon_device *rdev = dev->dev_private;
  77. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  78. ENABLE_SCALER_PS_ALLOCATION args;
  79. int index = GetIndexIntoMasterTable(COMMAND, EnableScaler);
  80. /* fixme - fill in enc_priv for atom dac */
  81. enum radeon_tv_std tv_std = TV_STD_NTSC;
  82. bool is_tv = false, is_cv = false;
  83. struct drm_encoder *encoder;
  84. if (!ASIC_IS_AVIVO(rdev) && radeon_crtc->crtc_id)
  85. return;
  86. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  87. /* find tv std */
  88. if (encoder->crtc == crtc) {
  89. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  90. if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) {
  91. struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv;
  92. tv_std = tv_dac->tv_std;
  93. is_tv = true;
  94. }
  95. }
  96. }
  97. memset(&args, 0, sizeof(args));
  98. args.ucScaler = radeon_crtc->crtc_id;
  99. if (is_tv) {
  100. switch (tv_std) {
  101. case TV_STD_NTSC:
  102. default:
  103. args.ucTVStandard = ATOM_TV_NTSC;
  104. break;
  105. case TV_STD_PAL:
  106. args.ucTVStandard = ATOM_TV_PAL;
  107. break;
  108. case TV_STD_PAL_M:
  109. args.ucTVStandard = ATOM_TV_PALM;
  110. break;
  111. case TV_STD_PAL_60:
  112. args.ucTVStandard = ATOM_TV_PAL60;
  113. break;
  114. case TV_STD_NTSC_J:
  115. args.ucTVStandard = ATOM_TV_NTSCJ;
  116. break;
  117. case TV_STD_SCART_PAL:
  118. args.ucTVStandard = ATOM_TV_PAL; /* ??? */
  119. break;
  120. case TV_STD_SECAM:
  121. args.ucTVStandard = ATOM_TV_SECAM;
  122. break;
  123. case TV_STD_PAL_CN:
  124. args.ucTVStandard = ATOM_TV_PALCN;
  125. break;
  126. }
  127. args.ucEnable = SCALER_ENABLE_MULTITAP_MODE;
  128. } else if (is_cv) {
  129. args.ucTVStandard = ATOM_TV_CV;
  130. args.ucEnable = SCALER_ENABLE_MULTITAP_MODE;
  131. } else {
  132. switch (radeon_crtc->rmx_type) {
  133. case RMX_FULL:
  134. args.ucEnable = ATOM_SCALER_EXPANSION;
  135. break;
  136. case RMX_CENTER:
  137. args.ucEnable = ATOM_SCALER_CENTER;
  138. break;
  139. case RMX_ASPECT:
  140. args.ucEnable = ATOM_SCALER_EXPANSION;
  141. break;
  142. default:
  143. if (ASIC_IS_AVIVO(rdev))
  144. args.ucEnable = ATOM_SCALER_DISABLE;
  145. else
  146. args.ucEnable = ATOM_SCALER_CENTER;
  147. break;
  148. }
  149. }
  150. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  151. if ((is_tv || is_cv)
  152. && rdev->family >= CHIP_RV515 && rdev->family <= CHIP_R580) {
  153. atom_rv515_force_tv_scaler(rdev, radeon_crtc);
  154. }
  155. }
  156. static void atombios_lock_crtc(struct drm_crtc *crtc, int lock)
  157. {
  158. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  159. struct drm_device *dev = crtc->dev;
  160. struct radeon_device *rdev = dev->dev_private;
  161. int index =
  162. GetIndexIntoMasterTable(COMMAND, UpdateCRTC_DoubleBufferRegisters);
  163. ENABLE_CRTC_PS_ALLOCATION args;
  164. memset(&args, 0, sizeof(args));
  165. args.ucCRTC = radeon_crtc->crtc_id;
  166. args.ucEnable = lock;
  167. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  168. }
  169. static void atombios_enable_crtc(struct drm_crtc *crtc, int state)
  170. {
  171. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  172. struct drm_device *dev = crtc->dev;
  173. struct radeon_device *rdev = dev->dev_private;
  174. int index = GetIndexIntoMasterTable(COMMAND, EnableCRTC);
  175. ENABLE_CRTC_PS_ALLOCATION args;
  176. memset(&args, 0, sizeof(args));
  177. args.ucCRTC = radeon_crtc->crtc_id;
  178. args.ucEnable = state;
  179. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  180. }
  181. static void atombios_enable_crtc_memreq(struct drm_crtc *crtc, int state)
  182. {
  183. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  184. struct drm_device *dev = crtc->dev;
  185. struct radeon_device *rdev = dev->dev_private;
  186. int index = GetIndexIntoMasterTable(COMMAND, EnableCRTCMemReq);
  187. ENABLE_CRTC_PS_ALLOCATION args;
  188. memset(&args, 0, sizeof(args));
  189. args.ucCRTC = radeon_crtc->crtc_id;
  190. args.ucEnable = state;
  191. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  192. }
  193. static void atombios_blank_crtc(struct drm_crtc *crtc, int state)
  194. {
  195. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  196. struct drm_device *dev = crtc->dev;
  197. struct radeon_device *rdev = dev->dev_private;
  198. int index = GetIndexIntoMasterTable(COMMAND, BlankCRTC);
  199. BLANK_CRTC_PS_ALLOCATION args;
  200. memset(&args, 0, sizeof(args));
  201. args.ucCRTC = radeon_crtc->crtc_id;
  202. args.ucBlanking = state;
  203. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  204. }
  205. static void atombios_powergate_crtc(struct drm_crtc *crtc, int state)
  206. {
  207. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  208. struct drm_device *dev = crtc->dev;
  209. struct radeon_device *rdev = dev->dev_private;
  210. int index = GetIndexIntoMasterTable(COMMAND, EnableDispPowerGating);
  211. ENABLE_DISP_POWER_GATING_PARAMETERS_V2_1 args;
  212. memset(&args, 0, sizeof(args));
  213. args.ucDispPipeId = radeon_crtc->crtc_id;
  214. args.ucEnable = state;
  215. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  216. }
  217. void atombios_crtc_dpms(struct drm_crtc *crtc, int mode)
  218. {
  219. struct drm_device *dev = crtc->dev;
  220. struct radeon_device *rdev = dev->dev_private;
  221. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  222. switch (mode) {
  223. case DRM_MODE_DPMS_ON:
  224. radeon_crtc->enabled = true;
  225. /* adjust pm to dpms changes BEFORE enabling crtcs */
  226. radeon_pm_compute_clocks(rdev);
  227. atombios_enable_crtc(crtc, ATOM_ENABLE);
  228. if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev))
  229. atombios_enable_crtc_memreq(crtc, ATOM_ENABLE);
  230. atombios_blank_crtc(crtc, ATOM_DISABLE);
  231. drm_vblank_post_modeset(dev, radeon_crtc->crtc_id);
  232. radeon_crtc_load_lut(crtc);
  233. break;
  234. case DRM_MODE_DPMS_STANDBY:
  235. case DRM_MODE_DPMS_SUSPEND:
  236. case DRM_MODE_DPMS_OFF:
  237. drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id);
  238. if (radeon_crtc->enabled)
  239. atombios_blank_crtc(crtc, ATOM_ENABLE);
  240. if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev))
  241. atombios_enable_crtc_memreq(crtc, ATOM_DISABLE);
  242. atombios_enable_crtc(crtc, ATOM_DISABLE);
  243. radeon_crtc->enabled = false;
  244. /* adjust pm to dpms changes AFTER disabling crtcs */
  245. radeon_pm_compute_clocks(rdev);
  246. break;
  247. }
  248. }
  249. static void
  250. atombios_set_crtc_dtd_timing(struct drm_crtc *crtc,
  251. struct drm_display_mode *mode)
  252. {
  253. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  254. struct drm_device *dev = crtc->dev;
  255. struct radeon_device *rdev = dev->dev_private;
  256. SET_CRTC_USING_DTD_TIMING_PARAMETERS args;
  257. int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_UsingDTDTiming);
  258. u16 misc = 0;
  259. memset(&args, 0, sizeof(args));
  260. args.usH_Size = cpu_to_le16(mode->crtc_hdisplay - (radeon_crtc->h_border * 2));
  261. args.usH_Blanking_Time =
  262. cpu_to_le16(mode->crtc_hblank_end - mode->crtc_hdisplay + (radeon_crtc->h_border * 2));
  263. args.usV_Size = cpu_to_le16(mode->crtc_vdisplay - (radeon_crtc->v_border * 2));
  264. args.usV_Blanking_Time =
  265. cpu_to_le16(mode->crtc_vblank_end - mode->crtc_vdisplay + (radeon_crtc->v_border * 2));
  266. args.usH_SyncOffset =
  267. cpu_to_le16(mode->crtc_hsync_start - mode->crtc_hdisplay + radeon_crtc->h_border);
  268. args.usH_SyncWidth =
  269. cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start);
  270. args.usV_SyncOffset =
  271. cpu_to_le16(mode->crtc_vsync_start - mode->crtc_vdisplay + radeon_crtc->v_border);
  272. args.usV_SyncWidth =
  273. cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start);
  274. args.ucH_Border = radeon_crtc->h_border;
  275. args.ucV_Border = radeon_crtc->v_border;
  276. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  277. misc |= ATOM_VSYNC_POLARITY;
  278. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  279. misc |= ATOM_HSYNC_POLARITY;
  280. if (mode->flags & DRM_MODE_FLAG_CSYNC)
  281. misc |= ATOM_COMPOSITESYNC;
  282. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  283. misc |= ATOM_INTERLACE;
  284. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  285. misc |= ATOM_DOUBLE_CLOCK_MODE;
  286. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  287. misc |= ATOM_H_REPLICATIONBY2 | ATOM_V_REPLICATIONBY2;
  288. args.susModeMiscInfo.usAccess = cpu_to_le16(misc);
  289. args.ucCRTC = radeon_crtc->crtc_id;
  290. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  291. }
  292. static void atombios_crtc_set_timing(struct drm_crtc *crtc,
  293. struct drm_display_mode *mode)
  294. {
  295. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  296. struct drm_device *dev = crtc->dev;
  297. struct radeon_device *rdev = dev->dev_private;
  298. SET_CRTC_TIMING_PARAMETERS_PS_ALLOCATION args;
  299. int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_Timing);
  300. u16 misc = 0;
  301. memset(&args, 0, sizeof(args));
  302. args.usH_Total = cpu_to_le16(mode->crtc_htotal);
  303. args.usH_Disp = cpu_to_le16(mode->crtc_hdisplay);
  304. args.usH_SyncStart = cpu_to_le16(mode->crtc_hsync_start);
  305. args.usH_SyncWidth =
  306. cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start);
  307. args.usV_Total = cpu_to_le16(mode->crtc_vtotal);
  308. args.usV_Disp = cpu_to_le16(mode->crtc_vdisplay);
  309. args.usV_SyncStart = cpu_to_le16(mode->crtc_vsync_start);
  310. args.usV_SyncWidth =
  311. cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start);
  312. args.ucOverscanRight = radeon_crtc->h_border;
  313. args.ucOverscanLeft = radeon_crtc->h_border;
  314. args.ucOverscanBottom = radeon_crtc->v_border;
  315. args.ucOverscanTop = radeon_crtc->v_border;
  316. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  317. misc |= ATOM_VSYNC_POLARITY;
  318. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  319. misc |= ATOM_HSYNC_POLARITY;
  320. if (mode->flags & DRM_MODE_FLAG_CSYNC)
  321. misc |= ATOM_COMPOSITESYNC;
  322. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  323. misc |= ATOM_INTERLACE;
  324. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  325. misc |= ATOM_DOUBLE_CLOCK_MODE;
  326. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  327. misc |= ATOM_H_REPLICATIONBY2 | ATOM_V_REPLICATIONBY2;
  328. args.susModeMiscInfo.usAccess = cpu_to_le16(misc);
  329. args.ucCRTC = radeon_crtc->crtc_id;
  330. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  331. }
  332. static void atombios_disable_ss(struct radeon_device *rdev, int pll_id)
  333. {
  334. u32 ss_cntl;
  335. if (ASIC_IS_DCE4(rdev)) {
  336. switch (pll_id) {
  337. case ATOM_PPLL1:
  338. ss_cntl = RREG32(EVERGREEN_P1PLL_SS_CNTL);
  339. ss_cntl &= ~EVERGREEN_PxPLL_SS_EN;
  340. WREG32(EVERGREEN_P1PLL_SS_CNTL, ss_cntl);
  341. break;
  342. case ATOM_PPLL2:
  343. ss_cntl = RREG32(EVERGREEN_P2PLL_SS_CNTL);
  344. ss_cntl &= ~EVERGREEN_PxPLL_SS_EN;
  345. WREG32(EVERGREEN_P2PLL_SS_CNTL, ss_cntl);
  346. break;
  347. case ATOM_DCPLL:
  348. case ATOM_PPLL_INVALID:
  349. return;
  350. }
  351. } else if (ASIC_IS_AVIVO(rdev)) {
  352. switch (pll_id) {
  353. case ATOM_PPLL1:
  354. ss_cntl = RREG32(AVIVO_P1PLL_INT_SS_CNTL);
  355. ss_cntl &= ~1;
  356. WREG32(AVIVO_P1PLL_INT_SS_CNTL, ss_cntl);
  357. break;
  358. case ATOM_PPLL2:
  359. ss_cntl = RREG32(AVIVO_P2PLL_INT_SS_CNTL);
  360. ss_cntl &= ~1;
  361. WREG32(AVIVO_P2PLL_INT_SS_CNTL, ss_cntl);
  362. break;
  363. case ATOM_DCPLL:
  364. case ATOM_PPLL_INVALID:
  365. return;
  366. }
  367. }
  368. }
  369. union atom_enable_ss {
  370. ENABLE_LVDS_SS_PARAMETERS lvds_ss;
  371. ENABLE_LVDS_SS_PARAMETERS_V2 lvds_ss_2;
  372. ENABLE_SPREAD_SPECTRUM_ON_PPLL_PS_ALLOCATION v1;
  373. ENABLE_SPREAD_SPECTRUM_ON_PPLL_V2 v2;
  374. ENABLE_SPREAD_SPECTRUM_ON_PPLL_V3 v3;
  375. };
  376. static void atombios_crtc_program_ss(struct radeon_device *rdev,
  377. int enable,
  378. int pll_id,
  379. int crtc_id,
  380. struct radeon_atom_ss *ss)
  381. {
  382. unsigned i;
  383. int index = GetIndexIntoMasterTable(COMMAND, EnableSpreadSpectrumOnPPLL);
  384. union atom_enable_ss args;
  385. if (!enable) {
  386. for (i = 0; i < rdev->num_crtc; i++) {
  387. if (rdev->mode_info.crtcs[i] &&
  388. rdev->mode_info.crtcs[i]->enabled &&
  389. i != crtc_id &&
  390. pll_id == rdev->mode_info.crtcs[i]->pll_id) {
  391. /* one other crtc is using this pll don't turn
  392. * off spread spectrum as it might turn off
  393. * display on active crtc
  394. */
  395. return;
  396. }
  397. }
  398. }
  399. memset(&args, 0, sizeof(args));
  400. if (ASIC_IS_DCE5(rdev)) {
  401. args.v3.usSpreadSpectrumAmountFrac = cpu_to_le16(0);
  402. args.v3.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK;
  403. switch (pll_id) {
  404. case ATOM_PPLL1:
  405. args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_P1PLL;
  406. args.v3.usSpreadSpectrumAmount = cpu_to_le16(ss->amount);
  407. args.v3.usSpreadSpectrumStep = cpu_to_le16(ss->step);
  408. break;
  409. case ATOM_PPLL2:
  410. args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_P2PLL;
  411. args.v3.usSpreadSpectrumAmount = cpu_to_le16(ss->amount);
  412. args.v3.usSpreadSpectrumStep = cpu_to_le16(ss->step);
  413. break;
  414. case ATOM_DCPLL:
  415. args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_DCPLL;
  416. args.v3.usSpreadSpectrumAmount = cpu_to_le16(0);
  417. args.v3.usSpreadSpectrumStep = cpu_to_le16(0);
  418. break;
  419. case ATOM_PPLL_INVALID:
  420. return;
  421. }
  422. args.v3.ucEnable = enable;
  423. if ((ss->percentage == 0) || (ss->type & ATOM_EXTERNAL_SS_MASK) || ASIC_IS_DCE61(rdev))
  424. args.v3.ucEnable = ATOM_DISABLE;
  425. } else if (ASIC_IS_DCE4(rdev)) {
  426. args.v2.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage);
  427. args.v2.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK;
  428. switch (pll_id) {
  429. case ATOM_PPLL1:
  430. args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_P1PLL;
  431. args.v2.usSpreadSpectrumAmount = cpu_to_le16(ss->amount);
  432. args.v2.usSpreadSpectrumStep = cpu_to_le16(ss->step);
  433. break;
  434. case ATOM_PPLL2:
  435. args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_P2PLL;
  436. args.v2.usSpreadSpectrumAmount = cpu_to_le16(ss->amount);
  437. args.v2.usSpreadSpectrumStep = cpu_to_le16(ss->step);
  438. break;
  439. case ATOM_DCPLL:
  440. args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_DCPLL;
  441. args.v2.usSpreadSpectrumAmount = cpu_to_le16(0);
  442. args.v2.usSpreadSpectrumStep = cpu_to_le16(0);
  443. break;
  444. case ATOM_PPLL_INVALID:
  445. return;
  446. }
  447. args.v2.ucEnable = enable;
  448. if ((ss->percentage == 0) || (ss->type & ATOM_EXTERNAL_SS_MASK) || ASIC_IS_DCE41(rdev))
  449. args.v2.ucEnable = ATOM_DISABLE;
  450. } else if (ASIC_IS_DCE3(rdev)) {
  451. args.v1.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage);
  452. args.v1.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK;
  453. args.v1.ucSpreadSpectrumStep = ss->step;
  454. args.v1.ucSpreadSpectrumDelay = ss->delay;
  455. args.v1.ucSpreadSpectrumRange = ss->range;
  456. args.v1.ucPpll = pll_id;
  457. args.v1.ucEnable = enable;
  458. } else if (ASIC_IS_AVIVO(rdev)) {
  459. if ((enable == ATOM_DISABLE) || (ss->percentage == 0) ||
  460. (ss->type & ATOM_EXTERNAL_SS_MASK)) {
  461. atombios_disable_ss(rdev, pll_id);
  462. return;
  463. }
  464. args.lvds_ss_2.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage);
  465. args.lvds_ss_2.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK;
  466. args.lvds_ss_2.ucSpreadSpectrumStep = ss->step;
  467. args.lvds_ss_2.ucSpreadSpectrumDelay = ss->delay;
  468. args.lvds_ss_2.ucSpreadSpectrumRange = ss->range;
  469. args.lvds_ss_2.ucEnable = enable;
  470. } else {
  471. if ((enable == ATOM_DISABLE) || (ss->percentage == 0) ||
  472. (ss->type & ATOM_EXTERNAL_SS_MASK)) {
  473. atombios_disable_ss(rdev, pll_id);
  474. return;
  475. }
  476. args.lvds_ss.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage);
  477. args.lvds_ss.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK;
  478. args.lvds_ss.ucSpreadSpectrumStepSize_Delay = (ss->step & 3) << 2;
  479. args.lvds_ss.ucSpreadSpectrumStepSize_Delay |= (ss->delay & 7) << 4;
  480. args.lvds_ss.ucEnable = enable;
  481. }
  482. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  483. }
  484. union adjust_pixel_clock {
  485. ADJUST_DISPLAY_PLL_PS_ALLOCATION v1;
  486. ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3 v3;
  487. };
  488. static u32 atombios_adjust_pll(struct drm_crtc *crtc,
  489. struct drm_display_mode *mode,
  490. struct radeon_pll *pll,
  491. bool ss_enabled,
  492. struct radeon_atom_ss *ss)
  493. {
  494. struct drm_device *dev = crtc->dev;
  495. struct radeon_device *rdev = dev->dev_private;
  496. struct drm_encoder *encoder = NULL;
  497. struct radeon_encoder *radeon_encoder = NULL;
  498. struct drm_connector *connector = NULL;
  499. u32 adjusted_clock = mode->clock;
  500. int encoder_mode = 0;
  501. u32 dp_clock = mode->clock;
  502. int bpc = 8;
  503. bool is_duallink = false;
  504. /* reset the pll flags */
  505. pll->flags = 0;
  506. if (ASIC_IS_AVIVO(rdev)) {
  507. if ((rdev->family == CHIP_RS600) ||
  508. (rdev->family == CHIP_RS690) ||
  509. (rdev->family == CHIP_RS740))
  510. pll->flags |= (/*RADEON_PLL_USE_FRAC_FB_DIV |*/
  511. RADEON_PLL_PREFER_CLOSEST_LOWER);
  512. if (ASIC_IS_DCE32(rdev) && mode->clock > 200000) /* range limits??? */
  513. pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV;
  514. else
  515. pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV;
  516. if (rdev->family < CHIP_RV770)
  517. pll->flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP;
  518. /* use frac fb div on APUs */
  519. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev))
  520. pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV;
  521. /* use frac fb div on RS780/RS880 */
  522. if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
  523. pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV;
  524. if (ASIC_IS_DCE32(rdev) && mode->clock > 165000)
  525. pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV;
  526. } else {
  527. pll->flags |= RADEON_PLL_LEGACY;
  528. if (mode->clock > 200000) /* range limits??? */
  529. pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV;
  530. else
  531. pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV;
  532. }
  533. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  534. if (encoder->crtc == crtc) {
  535. radeon_encoder = to_radeon_encoder(encoder);
  536. connector = radeon_get_connector_for_encoder(encoder);
  537. /* if (connector && connector->display_info.bpc)
  538. bpc = connector->display_info.bpc; */
  539. encoder_mode = atombios_get_encoder_mode(encoder);
  540. is_duallink = radeon_dig_monitor_is_duallink(encoder, mode->clock);
  541. if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) ||
  542. (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)) {
  543. if (connector) {
  544. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  545. struct radeon_connector_atom_dig *dig_connector =
  546. radeon_connector->con_priv;
  547. dp_clock = dig_connector->dp_clock;
  548. }
  549. }
  550. /* use recommended ref_div for ss */
  551. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  552. if (ss_enabled) {
  553. if (ss->refdiv) {
  554. pll->flags |= RADEON_PLL_USE_REF_DIV;
  555. pll->reference_div = ss->refdiv;
  556. if (ASIC_IS_AVIVO(rdev))
  557. pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV;
  558. }
  559. }
  560. }
  561. if (ASIC_IS_AVIVO(rdev)) {
  562. /* DVO wants 2x pixel clock if the DVO chip is in 12 bit mode */
  563. if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1)
  564. adjusted_clock = mode->clock * 2;
  565. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  566. pll->flags |= RADEON_PLL_PREFER_CLOSEST_LOWER;
  567. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  568. pll->flags |= RADEON_PLL_IS_LCD;
  569. } else {
  570. if (encoder->encoder_type != DRM_MODE_ENCODER_DAC)
  571. pll->flags |= RADEON_PLL_NO_ODD_POST_DIV;
  572. if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS)
  573. pll->flags |= RADEON_PLL_USE_REF_DIV;
  574. }
  575. break;
  576. }
  577. }
  578. /* DCE3+ has an AdjustDisplayPll that will adjust the pixel clock
  579. * accordingly based on the encoder/transmitter to work around
  580. * special hw requirements.
  581. */
  582. if (ASIC_IS_DCE3(rdev)) {
  583. union adjust_pixel_clock args;
  584. u8 frev, crev;
  585. int index;
  586. index = GetIndexIntoMasterTable(COMMAND, AdjustDisplayPll);
  587. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev,
  588. &crev))
  589. return adjusted_clock;
  590. memset(&args, 0, sizeof(args));
  591. switch (frev) {
  592. case 1:
  593. switch (crev) {
  594. case 1:
  595. case 2:
  596. args.v1.usPixelClock = cpu_to_le16(mode->clock / 10);
  597. args.v1.ucTransmitterID = radeon_encoder->encoder_id;
  598. args.v1.ucEncodeMode = encoder_mode;
  599. if (ss_enabled && ss->percentage)
  600. args.v1.ucConfig |=
  601. ADJUST_DISPLAY_CONFIG_SS_ENABLE;
  602. atom_execute_table(rdev->mode_info.atom_context,
  603. index, (uint32_t *)&args);
  604. adjusted_clock = le16_to_cpu(args.v1.usPixelClock) * 10;
  605. break;
  606. case 3:
  607. args.v3.sInput.usPixelClock = cpu_to_le16(mode->clock / 10);
  608. args.v3.sInput.ucTransmitterID = radeon_encoder->encoder_id;
  609. args.v3.sInput.ucEncodeMode = encoder_mode;
  610. args.v3.sInput.ucDispPllConfig = 0;
  611. if (ss_enabled && ss->percentage)
  612. args.v3.sInput.ucDispPllConfig |=
  613. DISPPLL_CONFIG_SS_ENABLE;
  614. if (ENCODER_MODE_IS_DP(encoder_mode)) {
  615. args.v3.sInput.ucDispPllConfig |=
  616. DISPPLL_CONFIG_COHERENT_MODE;
  617. /* 16200 or 27000 */
  618. args.v3.sInput.usPixelClock = cpu_to_le16(dp_clock / 10);
  619. } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
  620. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  621. if (encoder_mode == ATOM_ENCODER_MODE_HDMI)
  622. /* deep color support */
  623. args.v3.sInput.usPixelClock =
  624. cpu_to_le16((mode->clock * bpc / 8) / 10);
  625. if (dig->coherent_mode)
  626. args.v3.sInput.ucDispPllConfig |=
  627. DISPPLL_CONFIG_COHERENT_MODE;
  628. if (is_duallink)
  629. args.v3.sInput.ucDispPllConfig |=
  630. DISPPLL_CONFIG_DUAL_LINK;
  631. }
  632. if (radeon_encoder_get_dp_bridge_encoder_id(encoder) !=
  633. ENCODER_OBJECT_ID_NONE)
  634. args.v3.sInput.ucExtTransmitterID =
  635. radeon_encoder_get_dp_bridge_encoder_id(encoder);
  636. else
  637. args.v3.sInput.ucExtTransmitterID = 0;
  638. atom_execute_table(rdev->mode_info.atom_context,
  639. index, (uint32_t *)&args);
  640. adjusted_clock = le32_to_cpu(args.v3.sOutput.ulDispPllFreq) * 10;
  641. if (args.v3.sOutput.ucRefDiv) {
  642. pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV;
  643. pll->flags |= RADEON_PLL_USE_REF_DIV;
  644. pll->reference_div = args.v3.sOutput.ucRefDiv;
  645. }
  646. if (args.v3.sOutput.ucPostDiv) {
  647. pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV;
  648. pll->flags |= RADEON_PLL_USE_POST_DIV;
  649. pll->post_div = args.v3.sOutput.ucPostDiv;
  650. }
  651. break;
  652. default:
  653. DRM_ERROR("Unknown table version %d %d\n", frev, crev);
  654. return adjusted_clock;
  655. }
  656. break;
  657. default:
  658. DRM_ERROR("Unknown table version %d %d\n", frev, crev);
  659. return adjusted_clock;
  660. }
  661. }
  662. return adjusted_clock;
  663. }
  664. union set_pixel_clock {
  665. SET_PIXEL_CLOCK_PS_ALLOCATION base;
  666. PIXEL_CLOCK_PARAMETERS v1;
  667. PIXEL_CLOCK_PARAMETERS_V2 v2;
  668. PIXEL_CLOCK_PARAMETERS_V3 v3;
  669. PIXEL_CLOCK_PARAMETERS_V5 v5;
  670. PIXEL_CLOCK_PARAMETERS_V6 v6;
  671. };
  672. /* on DCE5, make sure the voltage is high enough to support the
  673. * required disp clk.
  674. */
  675. static void atombios_crtc_set_disp_eng_pll(struct radeon_device *rdev,
  676. u32 dispclk)
  677. {
  678. u8 frev, crev;
  679. int index;
  680. union set_pixel_clock args;
  681. memset(&args, 0, sizeof(args));
  682. index = GetIndexIntoMasterTable(COMMAND, SetPixelClock);
  683. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev,
  684. &crev))
  685. return;
  686. switch (frev) {
  687. case 1:
  688. switch (crev) {
  689. case 5:
  690. /* if the default dcpll clock is specified,
  691. * SetPixelClock provides the dividers
  692. */
  693. args.v5.ucCRTC = ATOM_CRTC_INVALID;
  694. args.v5.usPixelClock = cpu_to_le16(dispclk);
  695. args.v5.ucPpll = ATOM_DCPLL;
  696. break;
  697. case 6:
  698. /* if the default dcpll clock is specified,
  699. * SetPixelClock provides the dividers
  700. */
  701. args.v6.ulDispEngClkFreq = cpu_to_le32(dispclk);
  702. if (ASIC_IS_DCE61(rdev))
  703. args.v6.ucPpll = ATOM_EXT_PLL1;
  704. else if (ASIC_IS_DCE6(rdev))
  705. args.v6.ucPpll = ATOM_PPLL0;
  706. else
  707. args.v6.ucPpll = ATOM_DCPLL;
  708. break;
  709. default:
  710. DRM_ERROR("Unknown table version %d %d\n", frev, crev);
  711. return;
  712. }
  713. break;
  714. default:
  715. DRM_ERROR("Unknown table version %d %d\n", frev, crev);
  716. return;
  717. }
  718. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  719. }
  720. static void atombios_crtc_program_pll(struct drm_crtc *crtc,
  721. u32 crtc_id,
  722. int pll_id,
  723. u32 encoder_mode,
  724. u32 encoder_id,
  725. u32 clock,
  726. u32 ref_div,
  727. u32 fb_div,
  728. u32 frac_fb_div,
  729. u32 post_div,
  730. int bpc,
  731. bool ss_enabled,
  732. struct radeon_atom_ss *ss)
  733. {
  734. struct drm_device *dev = crtc->dev;
  735. struct radeon_device *rdev = dev->dev_private;
  736. u8 frev, crev;
  737. int index = GetIndexIntoMasterTable(COMMAND, SetPixelClock);
  738. union set_pixel_clock args;
  739. memset(&args, 0, sizeof(args));
  740. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev,
  741. &crev))
  742. return;
  743. switch (frev) {
  744. case 1:
  745. switch (crev) {
  746. case 1:
  747. if (clock == ATOM_DISABLE)
  748. return;
  749. args.v1.usPixelClock = cpu_to_le16(clock / 10);
  750. args.v1.usRefDiv = cpu_to_le16(ref_div);
  751. args.v1.usFbDiv = cpu_to_le16(fb_div);
  752. args.v1.ucFracFbDiv = frac_fb_div;
  753. args.v1.ucPostDiv = post_div;
  754. args.v1.ucPpll = pll_id;
  755. args.v1.ucCRTC = crtc_id;
  756. args.v1.ucRefDivSrc = 1;
  757. break;
  758. case 2:
  759. args.v2.usPixelClock = cpu_to_le16(clock / 10);
  760. args.v2.usRefDiv = cpu_to_le16(ref_div);
  761. args.v2.usFbDiv = cpu_to_le16(fb_div);
  762. args.v2.ucFracFbDiv = frac_fb_div;
  763. args.v2.ucPostDiv = post_div;
  764. args.v2.ucPpll = pll_id;
  765. args.v2.ucCRTC = crtc_id;
  766. args.v2.ucRefDivSrc = 1;
  767. break;
  768. case 3:
  769. args.v3.usPixelClock = cpu_to_le16(clock / 10);
  770. args.v3.usRefDiv = cpu_to_le16(ref_div);
  771. args.v3.usFbDiv = cpu_to_le16(fb_div);
  772. args.v3.ucFracFbDiv = frac_fb_div;
  773. args.v3.ucPostDiv = post_div;
  774. args.v3.ucPpll = pll_id;
  775. args.v3.ucMiscInfo = (pll_id << 2);
  776. if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK))
  777. args.v3.ucMiscInfo |= PIXEL_CLOCK_MISC_REF_DIV_SRC;
  778. args.v3.ucTransmitterId = encoder_id;
  779. args.v3.ucEncoderMode = encoder_mode;
  780. break;
  781. case 5:
  782. args.v5.ucCRTC = crtc_id;
  783. args.v5.usPixelClock = cpu_to_le16(clock / 10);
  784. args.v5.ucRefDiv = ref_div;
  785. args.v5.usFbDiv = cpu_to_le16(fb_div);
  786. args.v5.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000);
  787. args.v5.ucPostDiv = post_div;
  788. args.v5.ucMiscInfo = 0; /* HDMI depth, etc. */
  789. if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK))
  790. args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_REF_DIV_SRC;
  791. if (encoder_mode == ATOM_ENCODER_MODE_HDMI) {
  792. switch (bpc) {
  793. case 8:
  794. default:
  795. args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_24BPP;
  796. break;
  797. case 10:
  798. args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_30BPP;
  799. break;
  800. }
  801. }
  802. args.v5.ucTransmitterID = encoder_id;
  803. args.v5.ucEncoderMode = encoder_mode;
  804. args.v5.ucPpll = pll_id;
  805. break;
  806. case 6:
  807. args.v6.ulDispEngClkFreq = cpu_to_le32(crtc_id << 24 | clock / 10);
  808. args.v6.ucRefDiv = ref_div;
  809. args.v6.usFbDiv = cpu_to_le16(fb_div);
  810. args.v6.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000);
  811. args.v6.ucPostDiv = post_div;
  812. args.v6.ucMiscInfo = 0; /* HDMI depth, etc. */
  813. if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK))
  814. args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_REF_DIV_SRC;
  815. if (encoder_mode == ATOM_ENCODER_MODE_HDMI) {
  816. switch (bpc) {
  817. case 8:
  818. default:
  819. args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_24BPP;
  820. break;
  821. case 10:
  822. args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_30BPP;
  823. break;
  824. case 12:
  825. args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_36BPP;
  826. break;
  827. case 16:
  828. args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_48BPP;
  829. break;
  830. }
  831. }
  832. args.v6.ucTransmitterID = encoder_id;
  833. args.v6.ucEncoderMode = encoder_mode;
  834. args.v6.ucPpll = pll_id;
  835. break;
  836. default:
  837. DRM_ERROR("Unknown table version %d %d\n", frev, crev);
  838. return;
  839. }
  840. break;
  841. default:
  842. DRM_ERROR("Unknown table version %d %d\n", frev, crev);
  843. return;
  844. }
  845. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  846. }
  847. static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode)
  848. {
  849. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  850. struct drm_device *dev = crtc->dev;
  851. struct radeon_device *rdev = dev->dev_private;
  852. struct drm_encoder *encoder = NULL;
  853. struct radeon_encoder *radeon_encoder = NULL;
  854. u32 pll_clock = mode->clock;
  855. u32 ref_div = 0, fb_div = 0, frac_fb_div = 0, post_div = 0;
  856. struct radeon_pll *pll;
  857. u32 adjusted_clock;
  858. int encoder_mode = 0;
  859. struct radeon_atom_ss ss;
  860. bool ss_enabled = false;
  861. int bpc = 8;
  862. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  863. if (encoder->crtc == crtc) {
  864. radeon_encoder = to_radeon_encoder(encoder);
  865. encoder_mode = atombios_get_encoder_mode(encoder);
  866. break;
  867. }
  868. }
  869. if (!radeon_encoder)
  870. return;
  871. switch (radeon_crtc->pll_id) {
  872. case ATOM_PPLL1:
  873. pll = &rdev->clock.p1pll;
  874. break;
  875. case ATOM_PPLL2:
  876. pll = &rdev->clock.p2pll;
  877. break;
  878. case ATOM_DCPLL:
  879. case ATOM_PPLL_INVALID:
  880. default:
  881. pll = &rdev->clock.dcpll;
  882. break;
  883. }
  884. if ((radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) ||
  885. (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)) {
  886. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  887. struct drm_connector *connector =
  888. radeon_get_connector_for_encoder(encoder);
  889. struct radeon_connector *radeon_connector =
  890. to_radeon_connector(connector);
  891. struct radeon_connector_atom_dig *dig_connector =
  892. radeon_connector->con_priv;
  893. int dp_clock;
  894. /* if (connector->display_info.bpc)
  895. bpc = connector->display_info.bpc; */
  896. switch (encoder_mode) {
  897. case ATOM_ENCODER_MODE_DP_MST:
  898. case ATOM_ENCODER_MODE_DP:
  899. /* DP/eDP */
  900. dp_clock = dig_connector->dp_clock / 10;
  901. if (ASIC_IS_DCE4(rdev))
  902. ss_enabled =
  903. radeon_atombios_get_asic_ss_info(rdev, &ss,
  904. ASIC_INTERNAL_SS_ON_DP,
  905. dp_clock);
  906. else {
  907. if (dp_clock == 16200) {
  908. ss_enabled =
  909. radeon_atombios_get_ppll_ss_info(rdev, &ss,
  910. ATOM_DP_SS_ID2);
  911. if (!ss_enabled)
  912. ss_enabled =
  913. radeon_atombios_get_ppll_ss_info(rdev, &ss,
  914. ATOM_DP_SS_ID1);
  915. } else
  916. ss_enabled =
  917. radeon_atombios_get_ppll_ss_info(rdev, &ss,
  918. ATOM_DP_SS_ID1);
  919. }
  920. break;
  921. case ATOM_ENCODER_MODE_LVDS:
  922. if (ASIC_IS_DCE4(rdev))
  923. ss_enabled = radeon_atombios_get_asic_ss_info(rdev, &ss,
  924. dig->lcd_ss_id,
  925. mode->clock / 10);
  926. else
  927. ss_enabled = radeon_atombios_get_ppll_ss_info(rdev, &ss,
  928. dig->lcd_ss_id);
  929. break;
  930. case ATOM_ENCODER_MODE_DVI:
  931. if (ASIC_IS_DCE4(rdev))
  932. ss_enabled =
  933. radeon_atombios_get_asic_ss_info(rdev, &ss,
  934. ASIC_INTERNAL_SS_ON_TMDS,
  935. mode->clock / 10);
  936. break;
  937. case ATOM_ENCODER_MODE_HDMI:
  938. if (ASIC_IS_DCE4(rdev))
  939. ss_enabled =
  940. radeon_atombios_get_asic_ss_info(rdev, &ss,
  941. ASIC_INTERNAL_SS_ON_HDMI,
  942. mode->clock / 10);
  943. break;
  944. default:
  945. break;
  946. }
  947. }
  948. /* adjust pixel clock as needed */
  949. adjusted_clock = atombios_adjust_pll(crtc, mode, pll, ss_enabled, &ss);
  950. if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
  951. /* TV seems to prefer the legacy algo on some boards */
  952. radeon_compute_pll_legacy(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div,
  953. &ref_div, &post_div);
  954. else if (ASIC_IS_AVIVO(rdev))
  955. radeon_compute_pll_avivo(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div,
  956. &ref_div, &post_div);
  957. else
  958. radeon_compute_pll_legacy(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div,
  959. &ref_div, &post_div);
  960. atombios_crtc_program_ss(rdev, ATOM_DISABLE, radeon_crtc->pll_id, radeon_crtc->crtc_id, &ss);
  961. atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id,
  962. encoder_mode, radeon_encoder->encoder_id, mode->clock,
  963. ref_div, fb_div, frac_fb_div, post_div, bpc, ss_enabled, &ss);
  964. if (ss_enabled) {
  965. /* calculate ss amount and step size */
  966. if (ASIC_IS_DCE4(rdev)) {
  967. u32 step_size;
  968. u32 amount = (((fb_div * 10) + frac_fb_div) * ss.percentage) / 10000;
  969. ss.amount = (amount / 10) & ATOM_PPLL_SS_AMOUNT_V2_FBDIV_MASK;
  970. ss.amount |= ((amount - (amount / 10)) << ATOM_PPLL_SS_AMOUNT_V2_NFRAC_SHIFT) &
  971. ATOM_PPLL_SS_AMOUNT_V2_NFRAC_MASK;
  972. if (ss.type & ATOM_PPLL_SS_TYPE_V2_CENTRE_SPREAD)
  973. step_size = (4 * amount * ref_div * (ss.rate * 2048)) /
  974. (125 * 25 * pll->reference_freq / 100);
  975. else
  976. step_size = (2 * amount * ref_div * (ss.rate * 2048)) /
  977. (125 * 25 * pll->reference_freq / 100);
  978. ss.step = step_size;
  979. }
  980. atombios_crtc_program_ss(rdev, ATOM_ENABLE, radeon_crtc->pll_id, radeon_crtc->crtc_id, &ss);
  981. }
  982. }
  983. static int dce4_crtc_do_set_base(struct drm_crtc *crtc,
  984. struct drm_framebuffer *fb,
  985. int x, int y, int atomic)
  986. {
  987. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  988. struct drm_device *dev = crtc->dev;
  989. struct radeon_device *rdev = dev->dev_private;
  990. struct radeon_framebuffer *radeon_fb;
  991. struct drm_framebuffer *target_fb;
  992. struct drm_gem_object *obj;
  993. struct radeon_bo *rbo;
  994. uint64_t fb_location;
  995. uint32_t fb_format, fb_pitch_pixels, tiling_flags;
  996. unsigned bankw, bankh, mtaspect, tile_split;
  997. u32 fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_NONE);
  998. u32 tmp, viewport_w, viewport_h;
  999. int r;
  1000. /* no fb bound */
  1001. if (!atomic && !crtc->fb) {
  1002. DRM_DEBUG_KMS("No FB bound\n");
  1003. return 0;
  1004. }
  1005. if (atomic) {
  1006. radeon_fb = to_radeon_framebuffer(fb);
  1007. target_fb = fb;
  1008. }
  1009. else {
  1010. radeon_fb = to_radeon_framebuffer(crtc->fb);
  1011. target_fb = crtc->fb;
  1012. }
  1013. /* If atomic, assume fb object is pinned & idle & fenced and
  1014. * just update base pointers
  1015. */
  1016. obj = radeon_fb->obj;
  1017. rbo = gem_to_radeon_bo(obj);
  1018. r = radeon_bo_reserve(rbo, false);
  1019. if (unlikely(r != 0))
  1020. return r;
  1021. if (atomic)
  1022. fb_location = radeon_bo_gpu_offset(rbo);
  1023. else {
  1024. r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location);
  1025. if (unlikely(r != 0)) {
  1026. radeon_bo_unreserve(rbo);
  1027. return -EINVAL;
  1028. }
  1029. }
  1030. radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL);
  1031. radeon_bo_unreserve(rbo);
  1032. switch (target_fb->bits_per_pixel) {
  1033. case 8:
  1034. fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_8BPP) |
  1035. EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_INDEXED));
  1036. break;
  1037. case 15:
  1038. fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) |
  1039. EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB1555));
  1040. break;
  1041. case 16:
  1042. fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) |
  1043. EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB565));
  1044. #ifdef __BIG_ENDIAN
  1045. fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN16);
  1046. #endif
  1047. break;
  1048. case 24:
  1049. case 32:
  1050. fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) |
  1051. EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB8888));
  1052. #ifdef __BIG_ENDIAN
  1053. fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN32);
  1054. #endif
  1055. break;
  1056. default:
  1057. DRM_ERROR("Unsupported screen depth %d\n",
  1058. target_fb->bits_per_pixel);
  1059. return -EINVAL;
  1060. }
  1061. if (tiling_flags & RADEON_TILING_MACRO) {
  1062. if (rdev->family >= CHIP_CAYMAN)
  1063. tmp = rdev->config.cayman.tile_config;
  1064. else
  1065. tmp = rdev->config.evergreen.tile_config;
  1066. switch ((tmp & 0xf0) >> 4) {
  1067. case 0: /* 4 banks */
  1068. fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_4_BANK);
  1069. break;
  1070. case 1: /* 8 banks */
  1071. default:
  1072. fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_8_BANK);
  1073. break;
  1074. case 2: /* 16 banks */
  1075. fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_16_BANK);
  1076. break;
  1077. }
  1078. fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_2D_TILED_THIN1);
  1079. evergreen_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split);
  1080. fb_format |= EVERGREEN_GRPH_TILE_SPLIT(tile_split);
  1081. fb_format |= EVERGREEN_GRPH_BANK_WIDTH(bankw);
  1082. fb_format |= EVERGREEN_GRPH_BANK_HEIGHT(bankh);
  1083. fb_format |= EVERGREEN_GRPH_MACRO_TILE_ASPECT(mtaspect);
  1084. } else if (tiling_flags & RADEON_TILING_MICRO)
  1085. fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_1D_TILED_THIN1);
  1086. switch (radeon_crtc->crtc_id) {
  1087. case 0:
  1088. WREG32(AVIVO_D1VGA_CONTROL, 0);
  1089. break;
  1090. case 1:
  1091. WREG32(AVIVO_D2VGA_CONTROL, 0);
  1092. break;
  1093. case 2:
  1094. WREG32(EVERGREEN_D3VGA_CONTROL, 0);
  1095. break;
  1096. case 3:
  1097. WREG32(EVERGREEN_D4VGA_CONTROL, 0);
  1098. break;
  1099. case 4:
  1100. WREG32(EVERGREEN_D5VGA_CONTROL, 0);
  1101. break;
  1102. case 5:
  1103. WREG32(EVERGREEN_D6VGA_CONTROL, 0);
  1104. break;
  1105. default:
  1106. break;
  1107. }
  1108. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  1109. upper_32_bits(fb_location));
  1110. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  1111. upper_32_bits(fb_location));
  1112. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1113. (u32)fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK);
  1114. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1115. (u32) fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK);
  1116. WREG32(EVERGREEN_GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format);
  1117. WREG32(EVERGREEN_GRPH_SWAP_CONTROL + radeon_crtc->crtc_offset, fb_swap);
  1118. WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0);
  1119. WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0);
  1120. WREG32(EVERGREEN_GRPH_X_START + radeon_crtc->crtc_offset, 0);
  1121. WREG32(EVERGREEN_GRPH_Y_START + radeon_crtc->crtc_offset, 0);
  1122. WREG32(EVERGREEN_GRPH_X_END + radeon_crtc->crtc_offset, target_fb->width);
  1123. WREG32(EVERGREEN_GRPH_Y_END + radeon_crtc->crtc_offset, target_fb->height);
  1124. fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8);
  1125. WREG32(EVERGREEN_GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels);
  1126. WREG32(EVERGREEN_GRPH_ENABLE + radeon_crtc->crtc_offset, 1);
  1127. WREG32(EVERGREEN_DESKTOP_HEIGHT + radeon_crtc->crtc_offset,
  1128. target_fb->height);
  1129. x &= ~3;
  1130. y &= ~1;
  1131. WREG32(EVERGREEN_VIEWPORT_START + radeon_crtc->crtc_offset,
  1132. (x << 16) | y);
  1133. viewport_w = crtc->mode.hdisplay;
  1134. viewport_h = (crtc->mode.vdisplay + 1) & ~1;
  1135. WREG32(EVERGREEN_VIEWPORT_SIZE + radeon_crtc->crtc_offset,
  1136. (viewport_w << 16) | viewport_h);
  1137. /* pageflip setup */
  1138. /* make sure flip is at vb rather than hb */
  1139. tmp = RREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset);
  1140. tmp &= ~EVERGREEN_GRPH_SURFACE_UPDATE_H_RETRACE_EN;
  1141. WREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset, tmp);
  1142. /* set pageflip to happen anywhere in vblank interval */
  1143. WREG32(EVERGREEN_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0);
  1144. if (!atomic && fb && fb != crtc->fb) {
  1145. radeon_fb = to_radeon_framebuffer(fb);
  1146. rbo = gem_to_radeon_bo(radeon_fb->obj);
  1147. r = radeon_bo_reserve(rbo, false);
  1148. if (unlikely(r != 0))
  1149. return r;
  1150. radeon_bo_unpin(rbo);
  1151. radeon_bo_unreserve(rbo);
  1152. }
  1153. /* Bytes per pixel may have changed */
  1154. radeon_bandwidth_update(rdev);
  1155. return 0;
  1156. }
  1157. static int avivo_crtc_do_set_base(struct drm_crtc *crtc,
  1158. struct drm_framebuffer *fb,
  1159. int x, int y, int atomic)
  1160. {
  1161. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1162. struct drm_device *dev = crtc->dev;
  1163. struct radeon_device *rdev = dev->dev_private;
  1164. struct radeon_framebuffer *radeon_fb;
  1165. struct drm_gem_object *obj;
  1166. struct radeon_bo *rbo;
  1167. struct drm_framebuffer *target_fb;
  1168. uint64_t fb_location;
  1169. uint32_t fb_format, fb_pitch_pixels, tiling_flags;
  1170. u32 fb_swap = R600_D1GRPH_SWAP_ENDIAN_NONE;
  1171. u32 tmp, viewport_w, viewport_h;
  1172. int r;
  1173. /* no fb bound */
  1174. if (!atomic && !crtc->fb) {
  1175. DRM_DEBUG_KMS("No FB bound\n");
  1176. return 0;
  1177. }
  1178. if (atomic) {
  1179. radeon_fb = to_radeon_framebuffer(fb);
  1180. target_fb = fb;
  1181. }
  1182. else {
  1183. radeon_fb = to_radeon_framebuffer(crtc->fb);
  1184. target_fb = crtc->fb;
  1185. }
  1186. obj = radeon_fb->obj;
  1187. rbo = gem_to_radeon_bo(obj);
  1188. r = radeon_bo_reserve(rbo, false);
  1189. if (unlikely(r != 0))
  1190. return r;
  1191. /* If atomic, assume fb object is pinned & idle & fenced and
  1192. * just update base pointers
  1193. */
  1194. if (atomic)
  1195. fb_location = radeon_bo_gpu_offset(rbo);
  1196. else {
  1197. r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location);
  1198. if (unlikely(r != 0)) {
  1199. radeon_bo_unreserve(rbo);
  1200. return -EINVAL;
  1201. }
  1202. }
  1203. radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL);
  1204. radeon_bo_unreserve(rbo);
  1205. switch (target_fb->bits_per_pixel) {
  1206. case 8:
  1207. fb_format =
  1208. AVIVO_D1GRPH_CONTROL_DEPTH_8BPP |
  1209. AVIVO_D1GRPH_CONTROL_8BPP_INDEXED;
  1210. break;
  1211. case 15:
  1212. fb_format =
  1213. AVIVO_D1GRPH_CONTROL_DEPTH_16BPP |
  1214. AVIVO_D1GRPH_CONTROL_16BPP_ARGB1555;
  1215. break;
  1216. case 16:
  1217. fb_format =
  1218. AVIVO_D1GRPH_CONTROL_DEPTH_16BPP |
  1219. AVIVO_D1GRPH_CONTROL_16BPP_RGB565;
  1220. #ifdef __BIG_ENDIAN
  1221. fb_swap = R600_D1GRPH_SWAP_ENDIAN_16BIT;
  1222. #endif
  1223. break;
  1224. case 24:
  1225. case 32:
  1226. fb_format =
  1227. AVIVO_D1GRPH_CONTROL_DEPTH_32BPP |
  1228. AVIVO_D1GRPH_CONTROL_32BPP_ARGB8888;
  1229. #ifdef __BIG_ENDIAN
  1230. fb_swap = R600_D1GRPH_SWAP_ENDIAN_32BIT;
  1231. #endif
  1232. break;
  1233. default:
  1234. DRM_ERROR("Unsupported screen depth %d\n",
  1235. target_fb->bits_per_pixel);
  1236. return -EINVAL;
  1237. }
  1238. if (rdev->family >= CHIP_R600) {
  1239. if (tiling_flags & RADEON_TILING_MACRO)
  1240. fb_format |= R600_D1GRPH_ARRAY_MODE_2D_TILED_THIN1;
  1241. else if (tiling_flags & RADEON_TILING_MICRO)
  1242. fb_format |= R600_D1GRPH_ARRAY_MODE_1D_TILED_THIN1;
  1243. } else {
  1244. if (tiling_flags & RADEON_TILING_MACRO)
  1245. fb_format |= AVIVO_D1GRPH_MACRO_ADDRESS_MODE;
  1246. if (tiling_flags & RADEON_TILING_MICRO)
  1247. fb_format |= AVIVO_D1GRPH_TILED;
  1248. }
  1249. if (radeon_crtc->crtc_id == 0)
  1250. WREG32(AVIVO_D1VGA_CONTROL, 0);
  1251. else
  1252. WREG32(AVIVO_D2VGA_CONTROL, 0);
  1253. if (rdev->family >= CHIP_RV770) {
  1254. if (radeon_crtc->crtc_id) {
  1255. WREG32(R700_D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location));
  1256. WREG32(R700_D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location));
  1257. } else {
  1258. WREG32(R700_D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location));
  1259. WREG32(R700_D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location));
  1260. }
  1261. }
  1262. WREG32(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1263. (u32) fb_location);
  1264. WREG32(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS +
  1265. radeon_crtc->crtc_offset, (u32) fb_location);
  1266. WREG32(AVIVO_D1GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format);
  1267. if (rdev->family >= CHIP_R600)
  1268. WREG32(R600_D1GRPH_SWAP_CONTROL + radeon_crtc->crtc_offset, fb_swap);
  1269. WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0);
  1270. WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0);
  1271. WREG32(AVIVO_D1GRPH_X_START + radeon_crtc->crtc_offset, 0);
  1272. WREG32(AVIVO_D1GRPH_Y_START + radeon_crtc->crtc_offset, 0);
  1273. WREG32(AVIVO_D1GRPH_X_END + radeon_crtc->crtc_offset, target_fb->width);
  1274. WREG32(AVIVO_D1GRPH_Y_END + radeon_crtc->crtc_offset, target_fb->height);
  1275. fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8);
  1276. WREG32(AVIVO_D1GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels);
  1277. WREG32(AVIVO_D1GRPH_ENABLE + radeon_crtc->crtc_offset, 1);
  1278. WREG32(AVIVO_D1MODE_DESKTOP_HEIGHT + radeon_crtc->crtc_offset,
  1279. target_fb->height);
  1280. x &= ~3;
  1281. y &= ~1;
  1282. WREG32(AVIVO_D1MODE_VIEWPORT_START + radeon_crtc->crtc_offset,
  1283. (x << 16) | y);
  1284. viewport_w = crtc->mode.hdisplay;
  1285. viewport_h = (crtc->mode.vdisplay + 1) & ~1;
  1286. WREG32(AVIVO_D1MODE_VIEWPORT_SIZE + radeon_crtc->crtc_offset,
  1287. (viewport_w << 16) | viewport_h);
  1288. /* pageflip setup */
  1289. /* make sure flip is at vb rather than hb */
  1290. tmp = RREG32(AVIVO_D1GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset);
  1291. tmp &= ~AVIVO_D1GRPH_SURFACE_UPDATE_H_RETRACE_EN;
  1292. WREG32(AVIVO_D1GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset, tmp);
  1293. /* set pageflip to happen anywhere in vblank interval */
  1294. WREG32(AVIVO_D1MODE_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0);
  1295. if (!atomic && fb && fb != crtc->fb) {
  1296. radeon_fb = to_radeon_framebuffer(fb);
  1297. rbo = gem_to_radeon_bo(radeon_fb->obj);
  1298. r = radeon_bo_reserve(rbo, false);
  1299. if (unlikely(r != 0))
  1300. return r;
  1301. radeon_bo_unpin(rbo);
  1302. radeon_bo_unreserve(rbo);
  1303. }
  1304. /* Bytes per pixel may have changed */
  1305. radeon_bandwidth_update(rdev);
  1306. return 0;
  1307. }
  1308. int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y,
  1309. struct drm_framebuffer *old_fb)
  1310. {
  1311. struct drm_device *dev = crtc->dev;
  1312. struct radeon_device *rdev = dev->dev_private;
  1313. if (ASIC_IS_DCE4(rdev))
  1314. return dce4_crtc_do_set_base(crtc, old_fb, x, y, 0);
  1315. else if (ASIC_IS_AVIVO(rdev))
  1316. return avivo_crtc_do_set_base(crtc, old_fb, x, y, 0);
  1317. else
  1318. return radeon_crtc_do_set_base(crtc, old_fb, x, y, 0);
  1319. }
  1320. int atombios_crtc_set_base_atomic(struct drm_crtc *crtc,
  1321. struct drm_framebuffer *fb,
  1322. int x, int y, enum mode_set_atomic state)
  1323. {
  1324. struct drm_device *dev = crtc->dev;
  1325. struct radeon_device *rdev = dev->dev_private;
  1326. if (ASIC_IS_DCE4(rdev))
  1327. return dce4_crtc_do_set_base(crtc, fb, x, y, 1);
  1328. else if (ASIC_IS_AVIVO(rdev))
  1329. return avivo_crtc_do_set_base(crtc, fb, x, y, 1);
  1330. else
  1331. return radeon_crtc_do_set_base(crtc, fb, x, y, 1);
  1332. }
  1333. /* properly set additional regs when using atombios */
  1334. static void radeon_legacy_atom_fixup(struct drm_crtc *crtc)
  1335. {
  1336. struct drm_device *dev = crtc->dev;
  1337. struct radeon_device *rdev = dev->dev_private;
  1338. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1339. u32 disp_merge_cntl;
  1340. switch (radeon_crtc->crtc_id) {
  1341. case 0:
  1342. disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL);
  1343. disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN;
  1344. WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl);
  1345. break;
  1346. case 1:
  1347. disp_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL);
  1348. disp_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN;
  1349. WREG32(RADEON_DISP2_MERGE_CNTL, disp_merge_cntl);
  1350. WREG32(RADEON_FP_H2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_H_SYNC_STRT_WID));
  1351. WREG32(RADEON_FP_V2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_V_SYNC_STRT_WID));
  1352. break;
  1353. }
  1354. }
  1355. static int radeon_atom_pick_pll(struct drm_crtc *crtc)
  1356. {
  1357. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1358. struct drm_device *dev = crtc->dev;
  1359. struct radeon_device *rdev = dev->dev_private;
  1360. struct drm_encoder *test_encoder;
  1361. struct drm_crtc *test_crtc;
  1362. uint32_t pll_in_use = 0;
  1363. if (ASIC_IS_DCE61(rdev)) {
  1364. list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) {
  1365. if (test_encoder->crtc && (test_encoder->crtc == crtc)) {
  1366. struct radeon_encoder *test_radeon_encoder =
  1367. to_radeon_encoder(test_encoder);
  1368. struct radeon_encoder_atom_dig *dig =
  1369. test_radeon_encoder->enc_priv;
  1370. if ((test_radeon_encoder->encoder_id ==
  1371. ENCODER_OBJECT_ID_INTERNAL_UNIPHY) &&
  1372. (dig->linkb == false)) /* UNIPHY A uses PPLL2 */
  1373. return ATOM_PPLL2;
  1374. }
  1375. }
  1376. /* UNIPHY B/C/D/E/F */
  1377. list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) {
  1378. struct radeon_crtc *radeon_test_crtc;
  1379. if (crtc == test_crtc)
  1380. continue;
  1381. radeon_test_crtc = to_radeon_crtc(test_crtc);
  1382. if ((radeon_test_crtc->pll_id == ATOM_PPLL0) ||
  1383. (radeon_test_crtc->pll_id == ATOM_PPLL1))
  1384. pll_in_use |= (1 << radeon_test_crtc->pll_id);
  1385. }
  1386. if (!(pll_in_use & 4))
  1387. return ATOM_PPLL0;
  1388. return ATOM_PPLL1;
  1389. } else if (ASIC_IS_DCE4(rdev)) {
  1390. list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) {
  1391. if (test_encoder->crtc && (test_encoder->crtc == crtc)) {
  1392. /* in DP mode, the DP ref clock can come from PPLL, DCPLL, or ext clock,
  1393. * depending on the asic:
  1394. * DCE4: PPLL or ext clock
  1395. * DCE5: DCPLL or ext clock
  1396. *
  1397. * Setting ATOM_PPLL_INVALID will cause SetPixelClock to skip
  1398. * PPLL/DCPLL programming and only program the DP DTO for the
  1399. * crtc virtual pixel clock.
  1400. */
  1401. if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(test_encoder))) {
  1402. if (rdev->clock.dp_extclk)
  1403. return ATOM_PPLL_INVALID;
  1404. else if (ASIC_IS_DCE6(rdev))
  1405. return ATOM_PPLL0;
  1406. else if (ASIC_IS_DCE5(rdev))
  1407. return ATOM_DCPLL;
  1408. }
  1409. }
  1410. }
  1411. /* otherwise, pick one of the plls */
  1412. list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) {
  1413. struct radeon_crtc *radeon_test_crtc;
  1414. if (crtc == test_crtc)
  1415. continue;
  1416. radeon_test_crtc = to_radeon_crtc(test_crtc);
  1417. if ((radeon_test_crtc->pll_id >= ATOM_PPLL1) &&
  1418. (radeon_test_crtc->pll_id <= ATOM_PPLL2))
  1419. pll_in_use |= (1 << radeon_test_crtc->pll_id);
  1420. }
  1421. if (!(pll_in_use & 1))
  1422. return ATOM_PPLL1;
  1423. return ATOM_PPLL2;
  1424. } else
  1425. return radeon_crtc->crtc_id;
  1426. }
  1427. void radeon_atom_disp_eng_pll_init(struct radeon_device *rdev)
  1428. {
  1429. /* always set DCPLL */
  1430. if (ASIC_IS_DCE6(rdev))
  1431. atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk);
  1432. else if (ASIC_IS_DCE4(rdev)) {
  1433. struct radeon_atom_ss ss;
  1434. bool ss_enabled = radeon_atombios_get_asic_ss_info(rdev, &ss,
  1435. ASIC_INTERNAL_SS_ON_DCPLL,
  1436. rdev->clock.default_dispclk);
  1437. if (ss_enabled)
  1438. atombios_crtc_program_ss(rdev, ATOM_DISABLE, ATOM_DCPLL, -1, &ss);
  1439. /* XXX: DCE5, make sure voltage, dispclk is high enough */
  1440. atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk);
  1441. if (ss_enabled)
  1442. atombios_crtc_program_ss(rdev, ATOM_ENABLE, ATOM_DCPLL, -1, &ss);
  1443. }
  1444. }
  1445. int atombios_crtc_mode_set(struct drm_crtc *crtc,
  1446. struct drm_display_mode *mode,
  1447. struct drm_display_mode *adjusted_mode,
  1448. int x, int y, struct drm_framebuffer *old_fb)
  1449. {
  1450. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1451. struct drm_device *dev = crtc->dev;
  1452. struct radeon_device *rdev = dev->dev_private;
  1453. struct drm_encoder *encoder;
  1454. bool is_tvcv = false;
  1455. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1456. /* find tv std */
  1457. if (encoder->crtc == crtc) {
  1458. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1459. if (radeon_encoder->active_device &
  1460. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
  1461. is_tvcv = true;
  1462. }
  1463. }
  1464. atombios_crtc_set_pll(crtc, adjusted_mode);
  1465. if (ASIC_IS_DCE4(rdev))
  1466. atombios_set_crtc_dtd_timing(crtc, adjusted_mode);
  1467. else if (ASIC_IS_AVIVO(rdev)) {
  1468. if (is_tvcv)
  1469. atombios_crtc_set_timing(crtc, adjusted_mode);
  1470. else
  1471. atombios_set_crtc_dtd_timing(crtc, adjusted_mode);
  1472. } else {
  1473. atombios_crtc_set_timing(crtc, adjusted_mode);
  1474. if (radeon_crtc->crtc_id == 0)
  1475. atombios_set_crtc_dtd_timing(crtc, adjusted_mode);
  1476. radeon_legacy_atom_fixup(crtc);
  1477. }
  1478. atombios_crtc_set_base(crtc, x, y, old_fb);
  1479. atombios_overscan_setup(crtc, mode, adjusted_mode);
  1480. atombios_scaler_setup(crtc);
  1481. return 0;
  1482. }
  1483. static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc,
  1484. struct drm_display_mode *mode,
  1485. struct drm_display_mode *adjusted_mode)
  1486. {
  1487. if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
  1488. return false;
  1489. return true;
  1490. }
  1491. static void atombios_crtc_prepare(struct drm_crtc *crtc)
  1492. {
  1493. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1494. struct drm_device *dev = crtc->dev;
  1495. struct radeon_device *rdev = dev->dev_private;
  1496. radeon_crtc->in_mode_set = true;
  1497. /* pick pll */
  1498. radeon_crtc->pll_id = radeon_atom_pick_pll(crtc);
  1499. /* disable crtc pair power gating before programming */
  1500. if (ASIC_IS_DCE6(rdev))
  1501. atombios_powergate_crtc(crtc, ATOM_DISABLE);
  1502. atombios_lock_crtc(crtc, ATOM_ENABLE);
  1503. atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  1504. }
  1505. static void atombios_crtc_commit(struct drm_crtc *crtc)
  1506. {
  1507. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1508. atombios_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
  1509. atombios_lock_crtc(crtc, ATOM_DISABLE);
  1510. radeon_crtc->in_mode_set = false;
  1511. }
  1512. static void atombios_crtc_disable(struct drm_crtc *crtc)
  1513. {
  1514. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1515. struct drm_device *dev = crtc->dev;
  1516. struct radeon_device *rdev = dev->dev_private;
  1517. struct radeon_atom_ss ss;
  1518. int i;
  1519. atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  1520. if (ASIC_IS_DCE6(rdev))
  1521. atombios_powergate_crtc(crtc, ATOM_ENABLE);
  1522. for (i = 0; i < rdev->num_crtc; i++) {
  1523. if (rdev->mode_info.crtcs[i] &&
  1524. rdev->mode_info.crtcs[i]->enabled &&
  1525. i != radeon_crtc->crtc_id &&
  1526. radeon_crtc->pll_id == rdev->mode_info.crtcs[i]->pll_id) {
  1527. /* one other crtc is using this pll don't turn
  1528. * off the pll
  1529. */
  1530. goto done;
  1531. }
  1532. }
  1533. switch (radeon_crtc->pll_id) {
  1534. case ATOM_PPLL1:
  1535. case ATOM_PPLL2:
  1536. /* disable the ppll */
  1537. atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id,
  1538. 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
  1539. break;
  1540. case ATOM_PPLL0:
  1541. /* disable the ppll */
  1542. if (ASIC_IS_DCE61(rdev))
  1543. atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id,
  1544. 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
  1545. break;
  1546. default:
  1547. break;
  1548. }
  1549. done:
  1550. radeon_crtc->pll_id = -1;
  1551. }
  1552. static const struct drm_crtc_helper_funcs atombios_helper_funcs = {
  1553. .dpms = atombios_crtc_dpms,
  1554. .mode_fixup = atombios_crtc_mode_fixup,
  1555. .mode_set = atombios_crtc_mode_set,
  1556. .mode_set_base = atombios_crtc_set_base,
  1557. .mode_set_base_atomic = atombios_crtc_set_base_atomic,
  1558. .prepare = atombios_crtc_prepare,
  1559. .commit = atombios_crtc_commit,
  1560. .load_lut = radeon_crtc_load_lut,
  1561. .disable = atombios_crtc_disable,
  1562. };
  1563. void radeon_atombios_init_crtc(struct drm_device *dev,
  1564. struct radeon_crtc *radeon_crtc)
  1565. {
  1566. struct radeon_device *rdev = dev->dev_private;
  1567. if (ASIC_IS_DCE4(rdev)) {
  1568. switch (radeon_crtc->crtc_id) {
  1569. case 0:
  1570. default:
  1571. radeon_crtc->crtc_offset = EVERGREEN_CRTC0_REGISTER_OFFSET;
  1572. break;
  1573. case 1:
  1574. radeon_crtc->crtc_offset = EVERGREEN_CRTC1_REGISTER_OFFSET;
  1575. break;
  1576. case 2:
  1577. radeon_crtc->crtc_offset = EVERGREEN_CRTC2_REGISTER_OFFSET;
  1578. break;
  1579. case 3:
  1580. radeon_crtc->crtc_offset = EVERGREEN_CRTC3_REGISTER_OFFSET;
  1581. break;
  1582. case 4:
  1583. radeon_crtc->crtc_offset = EVERGREEN_CRTC4_REGISTER_OFFSET;
  1584. break;
  1585. case 5:
  1586. radeon_crtc->crtc_offset = EVERGREEN_CRTC5_REGISTER_OFFSET;
  1587. break;
  1588. }
  1589. } else {
  1590. if (radeon_crtc->crtc_id == 1)
  1591. radeon_crtc->crtc_offset =
  1592. AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL;
  1593. else
  1594. radeon_crtc->crtc_offset = 0;
  1595. }
  1596. radeon_crtc->pll_id = -1;
  1597. drm_crtc_helper_add(&radeon_crtc->base, &atombios_helper_funcs);
  1598. }