radeon_display.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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 "drmP.h"
  27. #include "radeon_drm.h"
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include <asm/div64.h>
  31. #include "drm_crtc_helper.h"
  32. #include "drm_edid.h"
  33. static int radeon_ddc_dump(struct drm_connector *connector);
  34. static void avivo_crtc_load_lut(struct drm_crtc *crtc)
  35. {
  36. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  37. struct drm_device *dev = crtc->dev;
  38. struct radeon_device *rdev = dev->dev_private;
  39. int i;
  40. DRM_DEBUG("%d\n", radeon_crtc->crtc_id);
  41. WREG32(AVIVO_DC_LUTA_CONTROL + radeon_crtc->crtc_offset, 0);
  42. WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0);
  43. WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0);
  44. WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0);
  45. WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff);
  46. WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff);
  47. WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff);
  48. WREG32(AVIVO_DC_LUT_RW_SELECT, radeon_crtc->crtc_id);
  49. WREG32(AVIVO_DC_LUT_RW_MODE, 0);
  50. WREG32(AVIVO_DC_LUT_WRITE_EN_MASK, 0x0000003f);
  51. WREG8(AVIVO_DC_LUT_RW_INDEX, 0);
  52. for (i = 0; i < 256; i++) {
  53. WREG32(AVIVO_DC_LUT_30_COLOR,
  54. (radeon_crtc->lut_r[i] << 20) |
  55. (radeon_crtc->lut_g[i] << 10) |
  56. (radeon_crtc->lut_b[i] << 0));
  57. }
  58. WREG32(AVIVO_D1GRPH_LUT_SEL + radeon_crtc->crtc_offset, radeon_crtc->crtc_id);
  59. }
  60. static void evergreen_crtc_load_lut(struct drm_crtc *crtc)
  61. {
  62. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  63. struct drm_device *dev = crtc->dev;
  64. struct radeon_device *rdev = dev->dev_private;
  65. int i;
  66. DRM_DEBUG("%d\n", radeon_crtc->crtc_id);
  67. WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0);
  68. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0);
  69. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0);
  70. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0);
  71. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff);
  72. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff);
  73. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff);
  74. WREG32(EVERGREEN_DC_LUT_RW_MODE + radeon_crtc->crtc_offset, 0);
  75. WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK + radeon_crtc->crtc_offset, 0x00000007);
  76. WREG32(EVERGREEN_DC_LUT_RW_INDEX + radeon_crtc->crtc_offset, 0);
  77. for (i = 0; i < 256; i++) {
  78. WREG32(EVERGREEN_DC_LUT_30_COLOR + radeon_crtc->crtc_offset,
  79. (radeon_crtc->lut_r[i] << 20) |
  80. (radeon_crtc->lut_g[i] << 10) |
  81. (radeon_crtc->lut_b[i] << 0));
  82. }
  83. }
  84. static void legacy_crtc_load_lut(struct drm_crtc *crtc)
  85. {
  86. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  87. struct drm_device *dev = crtc->dev;
  88. struct radeon_device *rdev = dev->dev_private;
  89. int i;
  90. uint32_t dac2_cntl;
  91. dac2_cntl = RREG32(RADEON_DAC_CNTL2);
  92. if (radeon_crtc->crtc_id == 0)
  93. dac2_cntl &= (uint32_t)~RADEON_DAC2_PALETTE_ACC_CTL;
  94. else
  95. dac2_cntl |= RADEON_DAC2_PALETTE_ACC_CTL;
  96. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  97. WREG8(RADEON_PALETTE_INDEX, 0);
  98. for (i = 0; i < 256; i++) {
  99. WREG32(RADEON_PALETTE_30_DATA,
  100. (radeon_crtc->lut_r[i] << 20) |
  101. (radeon_crtc->lut_g[i] << 10) |
  102. (radeon_crtc->lut_b[i] << 0));
  103. }
  104. }
  105. void radeon_crtc_load_lut(struct drm_crtc *crtc)
  106. {
  107. struct drm_device *dev = crtc->dev;
  108. struct radeon_device *rdev = dev->dev_private;
  109. if (!crtc->enabled)
  110. return;
  111. if (ASIC_IS_DCE4(rdev))
  112. evergreen_crtc_load_lut(crtc);
  113. else if (ASIC_IS_AVIVO(rdev))
  114. avivo_crtc_load_lut(crtc);
  115. else
  116. legacy_crtc_load_lut(crtc);
  117. }
  118. /** Sets the color ramps on behalf of fbcon */
  119. void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  120. u16 blue, int regno)
  121. {
  122. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  123. radeon_crtc->lut_r[regno] = red >> 6;
  124. radeon_crtc->lut_g[regno] = green >> 6;
  125. radeon_crtc->lut_b[regno] = blue >> 6;
  126. }
  127. /** Gets the color ramps on behalf of fbcon */
  128. void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  129. u16 *blue, int regno)
  130. {
  131. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  132. *red = radeon_crtc->lut_r[regno] << 6;
  133. *green = radeon_crtc->lut_g[regno] << 6;
  134. *blue = radeon_crtc->lut_b[regno] << 6;
  135. }
  136. static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  137. u16 *blue, uint32_t size)
  138. {
  139. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  140. int i;
  141. if (size != 256) {
  142. return;
  143. }
  144. /* userspace palettes are always correct as is */
  145. for (i = 0; i < 256; i++) {
  146. radeon_crtc->lut_r[i] = red[i] >> 6;
  147. radeon_crtc->lut_g[i] = green[i] >> 6;
  148. radeon_crtc->lut_b[i] = blue[i] >> 6;
  149. }
  150. radeon_crtc_load_lut(crtc);
  151. }
  152. static void radeon_crtc_destroy(struct drm_crtc *crtc)
  153. {
  154. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  155. drm_crtc_cleanup(crtc);
  156. kfree(radeon_crtc);
  157. }
  158. static const struct drm_crtc_funcs radeon_crtc_funcs = {
  159. .cursor_set = radeon_crtc_cursor_set,
  160. .cursor_move = radeon_crtc_cursor_move,
  161. .gamma_set = radeon_crtc_gamma_set,
  162. .set_config = drm_crtc_helper_set_config,
  163. .destroy = radeon_crtc_destroy,
  164. };
  165. static void radeon_crtc_init(struct drm_device *dev, int index)
  166. {
  167. struct radeon_device *rdev = dev->dev_private;
  168. struct radeon_crtc *radeon_crtc;
  169. int i;
  170. radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  171. if (radeon_crtc == NULL)
  172. return;
  173. drm_crtc_init(dev, &radeon_crtc->base, &radeon_crtc_funcs);
  174. drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256);
  175. radeon_crtc->crtc_id = index;
  176. rdev->mode_info.crtcs[index] = radeon_crtc;
  177. #if 0
  178. radeon_crtc->mode_set.crtc = &radeon_crtc->base;
  179. radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1);
  180. radeon_crtc->mode_set.num_connectors = 0;
  181. #endif
  182. for (i = 0; i < 256; i++) {
  183. radeon_crtc->lut_r[i] = i << 2;
  184. radeon_crtc->lut_g[i] = i << 2;
  185. radeon_crtc->lut_b[i] = i << 2;
  186. }
  187. if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom))
  188. radeon_atombios_init_crtc(dev, radeon_crtc);
  189. else
  190. radeon_legacy_init_crtc(dev, radeon_crtc);
  191. }
  192. static const char *encoder_names[34] = {
  193. "NONE",
  194. "INTERNAL_LVDS",
  195. "INTERNAL_TMDS1",
  196. "INTERNAL_TMDS2",
  197. "INTERNAL_DAC1",
  198. "INTERNAL_DAC2",
  199. "INTERNAL_SDVOA",
  200. "INTERNAL_SDVOB",
  201. "SI170B",
  202. "CH7303",
  203. "CH7301",
  204. "INTERNAL_DVO1",
  205. "EXTERNAL_SDVOA",
  206. "EXTERNAL_SDVOB",
  207. "TITFP513",
  208. "INTERNAL_LVTM1",
  209. "VT1623",
  210. "HDMI_SI1930",
  211. "HDMI_INTERNAL",
  212. "INTERNAL_KLDSCP_TMDS1",
  213. "INTERNAL_KLDSCP_DVO1",
  214. "INTERNAL_KLDSCP_DAC1",
  215. "INTERNAL_KLDSCP_DAC2",
  216. "SI178",
  217. "MVPU_FPGA",
  218. "INTERNAL_DDI",
  219. "VT1625",
  220. "HDMI_SI1932",
  221. "DP_AN9801",
  222. "DP_DP501",
  223. "INTERNAL_UNIPHY",
  224. "INTERNAL_KLDSCP_LVTMA",
  225. "INTERNAL_UNIPHY1",
  226. "INTERNAL_UNIPHY2",
  227. };
  228. static const char *connector_names[15] = {
  229. "Unknown",
  230. "VGA",
  231. "DVI-I",
  232. "DVI-D",
  233. "DVI-A",
  234. "Composite",
  235. "S-video",
  236. "LVDS",
  237. "Component",
  238. "DIN",
  239. "DisplayPort",
  240. "HDMI-A",
  241. "HDMI-B",
  242. "TV",
  243. "eDP",
  244. };
  245. static const char *hpd_names[6] = {
  246. "HPD1",
  247. "HPD2",
  248. "HPD3",
  249. "HPD4",
  250. "HPD5",
  251. "HPD6",
  252. };
  253. static void radeon_print_display_setup(struct drm_device *dev)
  254. {
  255. struct drm_connector *connector;
  256. struct radeon_connector *radeon_connector;
  257. struct drm_encoder *encoder;
  258. struct radeon_encoder *radeon_encoder;
  259. uint32_t devices;
  260. int i = 0;
  261. DRM_INFO("Radeon Display Connectors\n");
  262. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  263. radeon_connector = to_radeon_connector(connector);
  264. DRM_INFO("Connector %d:\n", i);
  265. DRM_INFO(" %s\n", connector_names[connector->connector_type]);
  266. if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
  267. DRM_INFO(" %s\n", hpd_names[radeon_connector->hpd.hpd]);
  268. if (radeon_connector->ddc_bus) {
  269. DRM_INFO(" DDC: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
  270. radeon_connector->ddc_bus->rec.mask_clk_reg,
  271. radeon_connector->ddc_bus->rec.mask_data_reg,
  272. radeon_connector->ddc_bus->rec.a_clk_reg,
  273. radeon_connector->ddc_bus->rec.a_data_reg,
  274. radeon_connector->ddc_bus->rec.en_clk_reg,
  275. radeon_connector->ddc_bus->rec.en_data_reg,
  276. radeon_connector->ddc_bus->rec.y_clk_reg,
  277. radeon_connector->ddc_bus->rec.y_data_reg);
  278. } else {
  279. if (connector->connector_type == DRM_MODE_CONNECTOR_VGA ||
  280. connector->connector_type == DRM_MODE_CONNECTOR_DVII ||
  281. connector->connector_type == DRM_MODE_CONNECTOR_DVID ||
  282. connector->connector_type == DRM_MODE_CONNECTOR_DVIA ||
  283. connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
  284. connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)
  285. DRM_INFO(" DDC: no ddc bus - possible BIOS bug - please report to xorg-driver-ati@lists.x.org\n");
  286. }
  287. DRM_INFO(" Encoders:\n");
  288. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  289. radeon_encoder = to_radeon_encoder(encoder);
  290. devices = radeon_encoder->devices & radeon_connector->devices;
  291. if (devices) {
  292. if (devices & ATOM_DEVICE_CRT1_SUPPORT)
  293. DRM_INFO(" CRT1: %s\n", encoder_names[radeon_encoder->encoder_id]);
  294. if (devices & ATOM_DEVICE_CRT2_SUPPORT)
  295. DRM_INFO(" CRT2: %s\n", encoder_names[radeon_encoder->encoder_id]);
  296. if (devices & ATOM_DEVICE_LCD1_SUPPORT)
  297. DRM_INFO(" LCD1: %s\n", encoder_names[radeon_encoder->encoder_id]);
  298. if (devices & ATOM_DEVICE_DFP1_SUPPORT)
  299. DRM_INFO(" DFP1: %s\n", encoder_names[radeon_encoder->encoder_id]);
  300. if (devices & ATOM_DEVICE_DFP2_SUPPORT)
  301. DRM_INFO(" DFP2: %s\n", encoder_names[radeon_encoder->encoder_id]);
  302. if (devices & ATOM_DEVICE_DFP3_SUPPORT)
  303. DRM_INFO(" DFP3: %s\n", encoder_names[radeon_encoder->encoder_id]);
  304. if (devices & ATOM_DEVICE_DFP4_SUPPORT)
  305. DRM_INFO(" DFP4: %s\n", encoder_names[radeon_encoder->encoder_id]);
  306. if (devices & ATOM_DEVICE_DFP5_SUPPORT)
  307. DRM_INFO(" DFP5: %s\n", encoder_names[radeon_encoder->encoder_id]);
  308. if (devices & ATOM_DEVICE_TV1_SUPPORT)
  309. DRM_INFO(" TV1: %s\n", encoder_names[radeon_encoder->encoder_id]);
  310. if (devices & ATOM_DEVICE_CV_SUPPORT)
  311. DRM_INFO(" CV: %s\n", encoder_names[radeon_encoder->encoder_id]);
  312. }
  313. }
  314. i++;
  315. }
  316. }
  317. static bool radeon_setup_enc_conn(struct drm_device *dev)
  318. {
  319. struct radeon_device *rdev = dev->dev_private;
  320. struct drm_connector *drm_connector;
  321. bool ret = false;
  322. if (rdev->bios) {
  323. if (rdev->is_atom_bios) {
  324. ret = radeon_get_atom_connector_info_from_supported_devices_table(dev);
  325. if (ret == false)
  326. ret = radeon_get_atom_connector_info_from_object_table(dev);
  327. } else {
  328. ret = radeon_get_legacy_connector_info_from_bios(dev);
  329. if (ret == false)
  330. ret = radeon_get_legacy_connector_info_from_table(dev);
  331. }
  332. } else {
  333. if (!ASIC_IS_AVIVO(rdev))
  334. ret = radeon_get_legacy_connector_info_from_table(dev);
  335. }
  336. if (ret) {
  337. radeon_setup_encoder_clones(dev);
  338. radeon_print_display_setup(dev);
  339. list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head)
  340. radeon_ddc_dump(drm_connector);
  341. }
  342. return ret;
  343. }
  344. int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
  345. {
  346. struct drm_device *dev = radeon_connector->base.dev;
  347. struct radeon_device *rdev = dev->dev_private;
  348. int ret = 0;
  349. if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
  350. (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) {
  351. struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
  352. if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
  353. dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) && dig->dp_i2c_bus)
  354. radeon_connector->edid = drm_get_edid(&radeon_connector->base, &dig->dp_i2c_bus->adapter);
  355. }
  356. if (!radeon_connector->ddc_bus)
  357. return -1;
  358. if (!radeon_connector->edid) {
  359. radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
  360. }
  361. /* some servers provide a hardcoded edid in rom for KVMs */
  362. if (!radeon_connector->edid)
  363. radeon_connector->edid = radeon_combios_get_hardcoded_edid(rdev);
  364. if (radeon_connector->edid) {
  365. drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid);
  366. ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid);
  367. return ret;
  368. }
  369. drm_mode_connector_update_edid_property(&radeon_connector->base, NULL);
  370. return 0;
  371. }
  372. static int radeon_ddc_dump(struct drm_connector *connector)
  373. {
  374. struct edid *edid;
  375. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  376. int ret = 0;
  377. if (!radeon_connector->ddc_bus)
  378. return -1;
  379. edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter);
  380. if (edid) {
  381. kfree(edid);
  382. }
  383. return ret;
  384. }
  385. static inline uint32_t radeon_div(uint64_t n, uint32_t d)
  386. {
  387. uint64_t mod;
  388. n += d / 2;
  389. mod = do_div(n, d);
  390. return n;
  391. }
  392. static void radeon_compute_pll_legacy(struct radeon_pll *pll,
  393. uint64_t freq,
  394. uint32_t *dot_clock_p,
  395. uint32_t *fb_div_p,
  396. uint32_t *frac_fb_div_p,
  397. uint32_t *ref_div_p,
  398. uint32_t *post_div_p)
  399. {
  400. uint32_t min_ref_div = pll->min_ref_div;
  401. uint32_t max_ref_div = pll->max_ref_div;
  402. uint32_t min_post_div = pll->min_post_div;
  403. uint32_t max_post_div = pll->max_post_div;
  404. uint32_t min_fractional_feed_div = 0;
  405. uint32_t max_fractional_feed_div = 0;
  406. uint32_t best_vco = pll->best_vco;
  407. uint32_t best_post_div = 1;
  408. uint32_t best_ref_div = 1;
  409. uint32_t best_feedback_div = 1;
  410. uint32_t best_frac_feedback_div = 0;
  411. uint32_t best_freq = -1;
  412. uint32_t best_error = 0xffffffff;
  413. uint32_t best_vco_diff = 1;
  414. uint32_t post_div;
  415. u32 pll_out_min, pll_out_max;
  416. DRM_DEBUG("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
  417. freq = freq * 1000;
  418. if (pll->flags & RADEON_PLL_IS_LCD) {
  419. pll_out_min = pll->lcd_pll_out_min;
  420. pll_out_max = pll->lcd_pll_out_max;
  421. } else {
  422. pll_out_min = pll->pll_out_min;
  423. pll_out_max = pll->pll_out_max;
  424. }
  425. if (pll->flags & RADEON_PLL_USE_REF_DIV)
  426. min_ref_div = max_ref_div = pll->reference_div;
  427. else {
  428. while (min_ref_div < max_ref_div-1) {
  429. uint32_t mid = (min_ref_div + max_ref_div) / 2;
  430. uint32_t pll_in = pll->reference_freq / mid;
  431. if (pll_in < pll->pll_in_min)
  432. max_ref_div = mid;
  433. else if (pll_in > pll->pll_in_max)
  434. min_ref_div = mid;
  435. else
  436. break;
  437. }
  438. }
  439. if (pll->flags & RADEON_PLL_USE_POST_DIV)
  440. min_post_div = max_post_div = pll->post_div;
  441. if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) {
  442. min_fractional_feed_div = pll->min_frac_feedback_div;
  443. max_fractional_feed_div = pll->max_frac_feedback_div;
  444. }
  445. for (post_div = min_post_div; post_div <= max_post_div; ++post_div) {
  446. uint32_t ref_div;
  447. if ((pll->flags & RADEON_PLL_NO_ODD_POST_DIV) && (post_div & 1))
  448. continue;
  449. /* legacy radeons only have a few post_divs */
  450. if (pll->flags & RADEON_PLL_LEGACY) {
  451. if ((post_div == 5) ||
  452. (post_div == 7) ||
  453. (post_div == 9) ||
  454. (post_div == 10) ||
  455. (post_div == 11) ||
  456. (post_div == 13) ||
  457. (post_div == 14) ||
  458. (post_div == 15))
  459. continue;
  460. }
  461. for (ref_div = min_ref_div; ref_div <= max_ref_div; ++ref_div) {
  462. uint32_t feedback_div, current_freq = 0, error, vco_diff;
  463. uint32_t pll_in = pll->reference_freq / ref_div;
  464. uint32_t min_feed_div = pll->min_feedback_div;
  465. uint32_t max_feed_div = pll->max_feedback_div + 1;
  466. if (pll_in < pll->pll_in_min || pll_in > pll->pll_in_max)
  467. continue;
  468. while (min_feed_div < max_feed_div) {
  469. uint32_t vco;
  470. uint32_t min_frac_feed_div = min_fractional_feed_div;
  471. uint32_t max_frac_feed_div = max_fractional_feed_div + 1;
  472. uint32_t frac_feedback_div;
  473. uint64_t tmp;
  474. feedback_div = (min_feed_div + max_feed_div) / 2;
  475. tmp = (uint64_t)pll->reference_freq * feedback_div;
  476. vco = radeon_div(tmp, ref_div);
  477. if (vco < pll_out_min) {
  478. min_feed_div = feedback_div + 1;
  479. continue;
  480. } else if (vco > pll_out_max) {
  481. max_feed_div = feedback_div;
  482. continue;
  483. }
  484. while (min_frac_feed_div < max_frac_feed_div) {
  485. frac_feedback_div = (min_frac_feed_div + max_frac_feed_div) / 2;
  486. tmp = (uint64_t)pll->reference_freq * 10000 * feedback_div;
  487. tmp += (uint64_t)pll->reference_freq * 1000 * frac_feedback_div;
  488. current_freq = radeon_div(tmp, ref_div * post_div);
  489. if (pll->flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
  490. error = freq - current_freq;
  491. error = error < 0 ? 0xffffffff : error;
  492. } else
  493. error = abs(current_freq - freq);
  494. vco_diff = abs(vco - best_vco);
  495. if ((best_vco == 0 && error < best_error) ||
  496. (best_vco != 0 &&
  497. (error < best_error - 100 ||
  498. (abs(error - best_error) < 100 && vco_diff < best_vco_diff)))) {
  499. best_post_div = post_div;
  500. best_ref_div = ref_div;
  501. best_feedback_div = feedback_div;
  502. best_frac_feedback_div = frac_feedback_div;
  503. best_freq = current_freq;
  504. best_error = error;
  505. best_vco_diff = vco_diff;
  506. } else if (current_freq == freq) {
  507. if (best_freq == -1) {
  508. best_post_div = post_div;
  509. best_ref_div = ref_div;
  510. best_feedback_div = feedback_div;
  511. best_frac_feedback_div = frac_feedback_div;
  512. best_freq = current_freq;
  513. best_error = error;
  514. best_vco_diff = vco_diff;
  515. } else if (((pll->flags & RADEON_PLL_PREFER_LOW_REF_DIV) && (ref_div < best_ref_div)) ||
  516. ((pll->flags & RADEON_PLL_PREFER_HIGH_REF_DIV) && (ref_div > best_ref_div)) ||
  517. ((pll->flags & RADEON_PLL_PREFER_LOW_FB_DIV) && (feedback_div < best_feedback_div)) ||
  518. ((pll->flags & RADEON_PLL_PREFER_HIGH_FB_DIV) && (feedback_div > best_feedback_div)) ||
  519. ((pll->flags & RADEON_PLL_PREFER_LOW_POST_DIV) && (post_div < best_post_div)) ||
  520. ((pll->flags & RADEON_PLL_PREFER_HIGH_POST_DIV) && (post_div > best_post_div))) {
  521. best_post_div = post_div;
  522. best_ref_div = ref_div;
  523. best_feedback_div = feedback_div;
  524. best_frac_feedback_div = frac_feedback_div;
  525. best_freq = current_freq;
  526. best_error = error;
  527. best_vco_diff = vco_diff;
  528. }
  529. }
  530. if (current_freq < freq)
  531. min_frac_feed_div = frac_feedback_div + 1;
  532. else
  533. max_frac_feed_div = frac_feedback_div;
  534. }
  535. if (current_freq < freq)
  536. min_feed_div = feedback_div + 1;
  537. else
  538. max_feed_div = feedback_div;
  539. }
  540. }
  541. }
  542. *dot_clock_p = best_freq / 10000;
  543. *fb_div_p = best_feedback_div;
  544. *frac_fb_div_p = best_frac_feedback_div;
  545. *ref_div_p = best_ref_div;
  546. *post_div_p = best_post_div;
  547. }
  548. static bool
  549. calc_fb_div(struct radeon_pll *pll,
  550. uint32_t freq,
  551. uint32_t post_div,
  552. uint32_t ref_div,
  553. uint32_t *fb_div,
  554. uint32_t *fb_div_frac)
  555. {
  556. fixed20_12 feedback_divider, a, b;
  557. u32 vco_freq;
  558. vco_freq = freq * post_div;
  559. /* feedback_divider = vco_freq * ref_div / pll->reference_freq; */
  560. a.full = dfixed_const(pll->reference_freq);
  561. feedback_divider.full = dfixed_const(vco_freq);
  562. feedback_divider.full = dfixed_div(feedback_divider, a);
  563. a.full = dfixed_const(ref_div);
  564. feedback_divider.full = dfixed_mul(feedback_divider, a);
  565. if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) {
  566. /* feedback_divider = floor((feedback_divider * 10.0) + 0.5) * 0.1; */
  567. a.full = dfixed_const(10);
  568. feedback_divider.full = dfixed_mul(feedback_divider, a);
  569. feedback_divider.full += dfixed_const_half(0);
  570. feedback_divider.full = dfixed_floor(feedback_divider);
  571. feedback_divider.full = dfixed_div(feedback_divider, a);
  572. /* *fb_div = floor(feedback_divider); */
  573. a.full = dfixed_floor(feedback_divider);
  574. *fb_div = dfixed_trunc(a);
  575. /* *fb_div_frac = fmod(feedback_divider, 1.0) * 10.0; */
  576. a.full = dfixed_const(10);
  577. b.full = dfixed_mul(feedback_divider, a);
  578. feedback_divider.full = dfixed_floor(feedback_divider);
  579. feedback_divider.full = dfixed_mul(feedback_divider, a);
  580. feedback_divider.full = b.full - feedback_divider.full;
  581. *fb_div_frac = dfixed_trunc(feedback_divider);
  582. } else {
  583. /* *fb_div = floor(feedback_divider + 0.5); */
  584. feedback_divider.full += dfixed_const_half(0);
  585. feedback_divider.full = dfixed_floor(feedback_divider);
  586. *fb_div = dfixed_trunc(feedback_divider);
  587. *fb_div_frac = 0;
  588. }
  589. if (((*fb_div) < pll->min_feedback_div) || ((*fb_div) > pll->max_feedback_div))
  590. return false;
  591. else
  592. return true;
  593. }
  594. static bool
  595. calc_fb_ref_div(struct radeon_pll *pll,
  596. uint32_t freq,
  597. uint32_t post_div,
  598. uint32_t *fb_div,
  599. uint32_t *fb_div_frac,
  600. uint32_t *ref_div)
  601. {
  602. fixed20_12 ffreq, max_error, error, pll_out, a;
  603. u32 vco;
  604. u32 pll_out_min, pll_out_max;
  605. if (pll->flags & RADEON_PLL_IS_LCD) {
  606. pll_out_min = pll->lcd_pll_out_min;
  607. pll_out_max = pll->lcd_pll_out_max;
  608. } else {
  609. pll_out_min = pll->pll_out_min;
  610. pll_out_max = pll->pll_out_max;
  611. }
  612. ffreq.full = dfixed_const(freq);
  613. /* max_error = ffreq * 0.0025; */
  614. a.full = dfixed_const(400);
  615. max_error.full = dfixed_div(ffreq, a);
  616. for ((*ref_div) = pll->min_ref_div; (*ref_div) < pll->max_ref_div; ++(*ref_div)) {
  617. if (calc_fb_div(pll, freq, post_div, (*ref_div), fb_div, fb_div_frac)) {
  618. vco = pll->reference_freq * (((*fb_div) * 10) + (*fb_div_frac));
  619. vco = vco / ((*ref_div) * 10);
  620. if ((vco < pll_out_min) || (vco > pll_out_max))
  621. continue;
  622. /* pll_out = vco / post_div; */
  623. a.full = dfixed_const(post_div);
  624. pll_out.full = dfixed_const(vco);
  625. pll_out.full = dfixed_div(pll_out, a);
  626. if (pll_out.full >= ffreq.full) {
  627. error.full = pll_out.full - ffreq.full;
  628. if (error.full <= max_error.full)
  629. return true;
  630. }
  631. }
  632. }
  633. return false;
  634. }
  635. static void radeon_compute_pll_new(struct radeon_pll *pll,
  636. uint64_t freq,
  637. uint32_t *dot_clock_p,
  638. uint32_t *fb_div_p,
  639. uint32_t *frac_fb_div_p,
  640. uint32_t *ref_div_p,
  641. uint32_t *post_div_p)
  642. {
  643. u32 fb_div = 0, fb_div_frac = 0, post_div = 0, ref_div = 0;
  644. u32 best_freq = 0, vco_frequency;
  645. u32 pll_out_min, pll_out_max;
  646. if (pll->flags & RADEON_PLL_IS_LCD) {
  647. pll_out_min = pll->lcd_pll_out_min;
  648. pll_out_max = pll->lcd_pll_out_max;
  649. } else {
  650. pll_out_min = pll->pll_out_min;
  651. pll_out_max = pll->pll_out_max;
  652. }
  653. /* freq = freq / 10; */
  654. do_div(freq, 10);
  655. if (pll->flags & RADEON_PLL_USE_POST_DIV) {
  656. post_div = pll->post_div;
  657. if ((post_div < pll->min_post_div) || (post_div > pll->max_post_div))
  658. goto done;
  659. vco_frequency = freq * post_div;
  660. if ((vco_frequency < pll_out_min) || (vco_frequency > pll_out_max))
  661. goto done;
  662. if (pll->flags & RADEON_PLL_USE_REF_DIV) {
  663. ref_div = pll->reference_div;
  664. if ((ref_div < pll->min_ref_div) || (ref_div > pll->max_ref_div))
  665. goto done;
  666. if (!calc_fb_div(pll, freq, post_div, ref_div, &fb_div, &fb_div_frac))
  667. goto done;
  668. }
  669. } else {
  670. for (post_div = pll->max_post_div; post_div >= pll->min_post_div; --post_div) {
  671. if (pll->flags & RADEON_PLL_LEGACY) {
  672. if ((post_div == 5) ||
  673. (post_div == 7) ||
  674. (post_div == 9) ||
  675. (post_div == 10) ||
  676. (post_div == 11))
  677. continue;
  678. }
  679. if ((pll->flags & RADEON_PLL_NO_ODD_POST_DIV) && (post_div & 1))
  680. continue;
  681. vco_frequency = freq * post_div;
  682. if ((vco_frequency < pll_out_min) || (vco_frequency > pll_out_max))
  683. continue;
  684. if (pll->flags & RADEON_PLL_USE_REF_DIV) {
  685. ref_div = pll->reference_div;
  686. if ((ref_div < pll->min_ref_div) || (ref_div > pll->max_ref_div))
  687. goto done;
  688. if (calc_fb_div(pll, freq, post_div, ref_div, &fb_div, &fb_div_frac))
  689. break;
  690. } else {
  691. if (calc_fb_ref_div(pll, freq, post_div, &fb_div, &fb_div_frac, &ref_div))
  692. break;
  693. }
  694. }
  695. }
  696. best_freq = pll->reference_freq * 10 * fb_div;
  697. best_freq += pll->reference_freq * fb_div_frac;
  698. best_freq = best_freq / (ref_div * post_div);
  699. done:
  700. if (best_freq == 0)
  701. DRM_ERROR("Couldn't find valid PLL dividers\n");
  702. *dot_clock_p = best_freq / 10;
  703. *fb_div_p = fb_div;
  704. *frac_fb_div_p = fb_div_frac;
  705. *ref_div_p = ref_div;
  706. *post_div_p = post_div;
  707. DRM_DEBUG("%u %d.%d, %d, %d\n", *dot_clock_p, *fb_div_p, *frac_fb_div_p, *ref_div_p, *post_div_p);
  708. }
  709. void radeon_compute_pll(struct radeon_pll *pll,
  710. uint64_t freq,
  711. uint32_t *dot_clock_p,
  712. uint32_t *fb_div_p,
  713. uint32_t *frac_fb_div_p,
  714. uint32_t *ref_div_p,
  715. uint32_t *post_div_p)
  716. {
  717. switch (pll->algo) {
  718. case PLL_ALGO_NEW:
  719. radeon_compute_pll_new(pll, freq, dot_clock_p, fb_div_p,
  720. frac_fb_div_p, ref_div_p, post_div_p);
  721. break;
  722. case PLL_ALGO_LEGACY:
  723. default:
  724. radeon_compute_pll_legacy(pll, freq, dot_clock_p, fb_div_p,
  725. frac_fb_div_p, ref_div_p, post_div_p);
  726. break;
  727. }
  728. }
  729. static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb)
  730. {
  731. struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb);
  732. if (radeon_fb->obj)
  733. drm_gem_object_unreference_unlocked(radeon_fb->obj);
  734. drm_framebuffer_cleanup(fb);
  735. kfree(radeon_fb);
  736. }
  737. static int radeon_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  738. struct drm_file *file_priv,
  739. unsigned int *handle)
  740. {
  741. struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb);
  742. return drm_gem_handle_create(file_priv, radeon_fb->obj, handle);
  743. }
  744. static const struct drm_framebuffer_funcs radeon_fb_funcs = {
  745. .destroy = radeon_user_framebuffer_destroy,
  746. .create_handle = radeon_user_framebuffer_create_handle,
  747. };
  748. void
  749. radeon_framebuffer_init(struct drm_device *dev,
  750. struct radeon_framebuffer *rfb,
  751. struct drm_mode_fb_cmd *mode_cmd,
  752. struct drm_gem_object *obj)
  753. {
  754. rfb->obj = obj;
  755. drm_framebuffer_init(dev, &rfb->base, &radeon_fb_funcs);
  756. drm_helper_mode_fill_fb_struct(&rfb->base, mode_cmd);
  757. }
  758. static struct drm_framebuffer *
  759. radeon_user_framebuffer_create(struct drm_device *dev,
  760. struct drm_file *file_priv,
  761. struct drm_mode_fb_cmd *mode_cmd)
  762. {
  763. struct drm_gem_object *obj;
  764. struct radeon_framebuffer *radeon_fb;
  765. obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
  766. if (obj == NULL) {
  767. dev_err(&dev->pdev->dev, "No GEM object associated to handle 0x%08X, "
  768. "can't create framebuffer\n", mode_cmd->handle);
  769. return NULL;
  770. }
  771. radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL);
  772. if (radeon_fb == NULL) {
  773. return NULL;
  774. }
  775. radeon_framebuffer_init(dev, radeon_fb, mode_cmd, obj);
  776. return &radeon_fb->base;
  777. }
  778. static void radeon_output_poll_changed(struct drm_device *dev)
  779. {
  780. struct radeon_device *rdev = dev->dev_private;
  781. radeon_fb_output_poll_changed(rdev);
  782. }
  783. static const struct drm_mode_config_funcs radeon_mode_funcs = {
  784. .fb_create = radeon_user_framebuffer_create,
  785. .output_poll_changed = radeon_output_poll_changed
  786. };
  787. struct drm_prop_enum_list {
  788. int type;
  789. char *name;
  790. };
  791. static struct drm_prop_enum_list radeon_tmds_pll_enum_list[] =
  792. { { 0, "driver" },
  793. { 1, "bios" },
  794. };
  795. static struct drm_prop_enum_list radeon_tv_std_enum_list[] =
  796. { { TV_STD_NTSC, "ntsc" },
  797. { TV_STD_PAL, "pal" },
  798. { TV_STD_PAL_M, "pal-m" },
  799. { TV_STD_PAL_60, "pal-60" },
  800. { TV_STD_NTSC_J, "ntsc-j" },
  801. { TV_STD_SCART_PAL, "scart-pal" },
  802. { TV_STD_PAL_CN, "pal-cn" },
  803. { TV_STD_SECAM, "secam" },
  804. };
  805. static int radeon_modeset_create_props(struct radeon_device *rdev)
  806. {
  807. int i, sz;
  808. if (rdev->is_atom_bios) {
  809. rdev->mode_info.coherent_mode_property =
  810. drm_property_create(rdev->ddev,
  811. DRM_MODE_PROP_RANGE,
  812. "coherent", 2);
  813. if (!rdev->mode_info.coherent_mode_property)
  814. return -ENOMEM;
  815. rdev->mode_info.coherent_mode_property->values[0] = 0;
  816. rdev->mode_info.coherent_mode_property->values[1] = 1;
  817. }
  818. if (!ASIC_IS_AVIVO(rdev)) {
  819. sz = ARRAY_SIZE(radeon_tmds_pll_enum_list);
  820. rdev->mode_info.tmds_pll_property =
  821. drm_property_create(rdev->ddev,
  822. DRM_MODE_PROP_ENUM,
  823. "tmds_pll", sz);
  824. for (i = 0; i < sz; i++) {
  825. drm_property_add_enum(rdev->mode_info.tmds_pll_property,
  826. i,
  827. radeon_tmds_pll_enum_list[i].type,
  828. radeon_tmds_pll_enum_list[i].name);
  829. }
  830. }
  831. rdev->mode_info.load_detect_property =
  832. drm_property_create(rdev->ddev,
  833. DRM_MODE_PROP_RANGE,
  834. "load detection", 2);
  835. if (!rdev->mode_info.load_detect_property)
  836. return -ENOMEM;
  837. rdev->mode_info.load_detect_property->values[0] = 0;
  838. rdev->mode_info.load_detect_property->values[1] = 1;
  839. drm_mode_create_scaling_mode_property(rdev->ddev);
  840. sz = ARRAY_SIZE(radeon_tv_std_enum_list);
  841. rdev->mode_info.tv_std_property =
  842. drm_property_create(rdev->ddev,
  843. DRM_MODE_PROP_ENUM,
  844. "tv standard", sz);
  845. for (i = 0; i < sz; i++) {
  846. drm_property_add_enum(rdev->mode_info.tv_std_property,
  847. i,
  848. radeon_tv_std_enum_list[i].type,
  849. radeon_tv_std_enum_list[i].name);
  850. }
  851. return 0;
  852. }
  853. void radeon_update_display_priority(struct radeon_device *rdev)
  854. {
  855. /* adjustment options for the display watermarks */
  856. if ((radeon_disp_priority == 0) || (radeon_disp_priority > 2)) {
  857. /* set display priority to high for r3xx, rv515 chips
  858. * this avoids flickering due to underflow to the
  859. * display controllers during heavy acceleration.
  860. * Don't force high on rs4xx igp chips as it seems to
  861. * affect the sound card. See kernel bug 15982.
  862. */
  863. if ((ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV515)) &&
  864. !(rdev->flags & RADEON_IS_IGP))
  865. rdev->disp_priority = 2;
  866. else
  867. rdev->disp_priority = 0;
  868. } else
  869. rdev->disp_priority = radeon_disp_priority;
  870. }
  871. int radeon_modeset_init(struct radeon_device *rdev)
  872. {
  873. int i;
  874. int ret;
  875. drm_mode_config_init(rdev->ddev);
  876. rdev->mode_info.mode_config_initialized = true;
  877. rdev->ddev->mode_config.funcs = (void *)&radeon_mode_funcs;
  878. if (ASIC_IS_AVIVO(rdev)) {
  879. rdev->ddev->mode_config.max_width = 8192;
  880. rdev->ddev->mode_config.max_height = 8192;
  881. } else {
  882. rdev->ddev->mode_config.max_width = 4096;
  883. rdev->ddev->mode_config.max_height = 4096;
  884. }
  885. rdev->ddev->mode_config.fb_base = rdev->mc.aper_base;
  886. ret = radeon_modeset_create_props(rdev);
  887. if (ret) {
  888. return ret;
  889. }
  890. /* check combios for a valid hardcoded EDID - Sun servers */
  891. if (!rdev->is_atom_bios) {
  892. /* check for hardcoded EDID in BIOS */
  893. radeon_combios_check_hardcoded_edid(rdev);
  894. }
  895. /* allocate crtcs */
  896. for (i = 0; i < rdev->num_crtc; i++) {
  897. radeon_crtc_init(rdev->ddev, i);
  898. }
  899. /* okay we should have all the bios connectors */
  900. ret = radeon_setup_enc_conn(rdev->ddev);
  901. if (!ret) {
  902. return ret;
  903. }
  904. /* initialize hpd */
  905. radeon_hpd_init(rdev);
  906. /* Initialize power management */
  907. radeon_pm_init(rdev);
  908. radeon_fbdev_init(rdev);
  909. drm_kms_helper_poll_init(rdev->ddev);
  910. return 0;
  911. }
  912. void radeon_modeset_fini(struct radeon_device *rdev)
  913. {
  914. radeon_fbdev_fini(rdev);
  915. kfree(rdev->mode_info.bios_hardcoded_edid);
  916. radeon_pm_fini(rdev);
  917. if (rdev->mode_info.mode_config_initialized) {
  918. drm_kms_helper_poll_fini(rdev->ddev);
  919. radeon_hpd_fini(rdev);
  920. drm_mode_config_cleanup(rdev->ddev);
  921. rdev->mode_info.mode_config_initialized = false;
  922. }
  923. }
  924. bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
  925. struct drm_display_mode *mode,
  926. struct drm_display_mode *adjusted_mode)
  927. {
  928. struct drm_device *dev = crtc->dev;
  929. struct drm_encoder *encoder;
  930. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  931. struct radeon_encoder *radeon_encoder;
  932. bool first = true;
  933. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  934. radeon_encoder = to_radeon_encoder(encoder);
  935. if (encoder->crtc != crtc)
  936. continue;
  937. if (first) {
  938. /* set scaling */
  939. if (radeon_encoder->rmx_type == RMX_OFF)
  940. radeon_crtc->rmx_type = RMX_OFF;
  941. else if (mode->hdisplay < radeon_encoder->native_mode.hdisplay ||
  942. mode->vdisplay < radeon_encoder->native_mode.vdisplay)
  943. radeon_crtc->rmx_type = radeon_encoder->rmx_type;
  944. else
  945. radeon_crtc->rmx_type = RMX_OFF;
  946. /* copy native mode */
  947. memcpy(&radeon_crtc->native_mode,
  948. &radeon_encoder->native_mode,
  949. sizeof(struct drm_display_mode));
  950. first = false;
  951. } else {
  952. if (radeon_crtc->rmx_type != radeon_encoder->rmx_type) {
  953. /* WARNING: Right now this can't happen but
  954. * in the future we need to check that scaling
  955. * are consistent accross different encoder
  956. * (ie all encoder can work with the same
  957. * scaling).
  958. */
  959. DRM_ERROR("Scaling not consistent accross encoder.\n");
  960. return false;
  961. }
  962. }
  963. }
  964. if (radeon_crtc->rmx_type != RMX_OFF) {
  965. fixed20_12 a, b;
  966. a.full = dfixed_const(crtc->mode.vdisplay);
  967. b.full = dfixed_const(radeon_crtc->native_mode.hdisplay);
  968. radeon_crtc->vsc.full = dfixed_div(a, b);
  969. a.full = dfixed_const(crtc->mode.hdisplay);
  970. b.full = dfixed_const(radeon_crtc->native_mode.vdisplay);
  971. radeon_crtc->hsc.full = dfixed_div(a, b);
  972. } else {
  973. radeon_crtc->vsc.full = dfixed_const(1);
  974. radeon_crtc->hsc.full = dfixed_const(1);
  975. }
  976. return true;
  977. }