oaktrail_crtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright © 2009 Intel Corporation
  4. */
  5. #include <linux/delay.h>
  6. #include <linux/i2c.h>
  7. #include <linux/pm_runtime.h>
  8. #include <drm/drm_fourcc.h>
  9. #include <drm/drm_framebuffer.h>
  10. #include "framebuffer.h"
  11. #include "gem.h"
  12. #include "gma_display.h"
  13. #include "power.h"
  14. #include "psb_drv.h"
  15. #include "psb_intel_drv.h"
  16. #include "psb_intel_reg.h"
  17. #define MRST_LIMIT_LVDS_100L 0
  18. #define MRST_LIMIT_LVDS_83 1
  19. #define MRST_LIMIT_LVDS_100 2
  20. #define MRST_LIMIT_SDVO 3
  21. #define MRST_DOT_MIN 19750
  22. #define MRST_DOT_MAX 120000
  23. #define MRST_M_MIN_100L 20
  24. #define MRST_M_MIN_100 10
  25. #define MRST_M_MIN_83 12
  26. #define MRST_M_MAX_100L 34
  27. #define MRST_M_MAX_100 17
  28. #define MRST_M_MAX_83 20
  29. #define MRST_P1_MIN 2
  30. #define MRST_P1_MAX_0 7
  31. #define MRST_P1_MAX_1 8
  32. static bool mrst_lvds_find_best_pll(const struct gma_limit_t *limit,
  33. struct drm_crtc *crtc, int target,
  34. int refclk, struct gma_clock_t *best_clock);
  35. static bool mrst_sdvo_find_best_pll(const struct gma_limit_t *limit,
  36. struct drm_crtc *crtc, int target,
  37. int refclk, struct gma_clock_t *best_clock);
  38. static const struct gma_limit_t mrst_limits[] = {
  39. { /* MRST_LIMIT_LVDS_100L */
  40. .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
  41. .m = {.min = MRST_M_MIN_100L, .max = MRST_M_MAX_100L},
  42. .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1},
  43. .find_pll = mrst_lvds_find_best_pll,
  44. },
  45. { /* MRST_LIMIT_LVDS_83L */
  46. .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
  47. .m = {.min = MRST_M_MIN_83, .max = MRST_M_MAX_83},
  48. .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_0},
  49. .find_pll = mrst_lvds_find_best_pll,
  50. },
  51. { /* MRST_LIMIT_LVDS_100 */
  52. .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
  53. .m = {.min = MRST_M_MIN_100, .max = MRST_M_MAX_100},
  54. .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1},
  55. .find_pll = mrst_lvds_find_best_pll,
  56. },
  57. { /* MRST_LIMIT_SDVO */
  58. .vco = {.min = 1400000, .max = 2800000},
  59. .n = {.min = 3, .max = 7},
  60. .m = {.min = 80, .max = 137},
  61. .p1 = {.min = 1, .max = 2},
  62. .p2 = {.dot_limit = 200000, .p2_slow = 10, .p2_fast = 10},
  63. .find_pll = mrst_sdvo_find_best_pll,
  64. },
  65. };
  66. #define MRST_M_MIN 10
  67. static const u32 oaktrail_m_converts[] = {
  68. 0x2B, 0x15, 0x2A, 0x35, 0x1A, 0x0D, 0x26, 0x33, 0x19, 0x2C,
  69. 0x36, 0x3B, 0x1D, 0x2E, 0x37, 0x1B, 0x2D, 0x16, 0x0B, 0x25,
  70. 0x12, 0x09, 0x24, 0x32, 0x39, 0x1c,
  71. };
  72. static const struct gma_limit_t *mrst_limit(struct drm_crtc *crtc,
  73. int refclk)
  74. {
  75. const struct gma_limit_t *limit = NULL;
  76. struct drm_device *dev = crtc->dev;
  77. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  78. if (gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)
  79. || gma_pipe_has_type(crtc, INTEL_OUTPUT_MIPI)) {
  80. switch (dev_priv->core_freq) {
  81. case 100:
  82. limit = &mrst_limits[MRST_LIMIT_LVDS_100L];
  83. break;
  84. case 166:
  85. limit = &mrst_limits[MRST_LIMIT_LVDS_83];
  86. break;
  87. case 200:
  88. limit = &mrst_limits[MRST_LIMIT_LVDS_100];
  89. break;
  90. }
  91. } else if (gma_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  92. limit = &mrst_limits[MRST_LIMIT_SDVO];
  93. } else {
  94. limit = NULL;
  95. dev_err(dev->dev, "mrst_limit Wrong display type.\n");
  96. }
  97. return limit;
  98. }
  99. /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
  100. static void mrst_lvds_clock(int refclk, struct gma_clock_t *clock)
  101. {
  102. clock->dot = (refclk * clock->m) / (14 * clock->p1);
  103. }
  104. static void mrst_print_pll(struct gma_clock_t *clock)
  105. {
  106. DRM_DEBUG_DRIVER("dotclock=%d, m=%d, m1=%d, m2=%d, n=%d, p1=%d, p2=%d\n",
  107. clock->dot, clock->m, clock->m1, clock->m2, clock->n,
  108. clock->p1, clock->p2);
  109. }
  110. static bool mrst_sdvo_find_best_pll(const struct gma_limit_t *limit,
  111. struct drm_crtc *crtc, int target,
  112. int refclk, struct gma_clock_t *best_clock)
  113. {
  114. struct gma_clock_t clock;
  115. u32 target_vco, actual_freq;
  116. s32 freq_error, min_error = 100000;
  117. memset(best_clock, 0, sizeof(*best_clock));
  118. memset(&clock, 0, sizeof(clock));
  119. for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) {
  120. for (clock.n = limit->n.min; clock.n <= limit->n.max;
  121. clock.n++) {
  122. for (clock.p1 = limit->p1.min;
  123. clock.p1 <= limit->p1.max; clock.p1++) {
  124. /* p2 value always stored in p2_slow on SDVO */
  125. clock.p = clock.p1 * limit->p2.p2_slow;
  126. target_vco = target * clock.p;
  127. /* VCO will increase at this point so break */
  128. if (target_vco > limit->vco.max)
  129. break;
  130. if (target_vco < limit->vco.min)
  131. continue;
  132. actual_freq = (refclk * clock.m) /
  133. (clock.n * clock.p);
  134. freq_error = 10000 -
  135. ((target * 10000) / actual_freq);
  136. if (freq_error < -min_error) {
  137. /* freq_error will start to decrease at
  138. this point so break */
  139. break;
  140. }
  141. if (freq_error < 0)
  142. freq_error = -freq_error;
  143. if (freq_error < min_error) {
  144. min_error = freq_error;
  145. *best_clock = clock;
  146. }
  147. }
  148. }
  149. if (min_error == 0)
  150. break;
  151. }
  152. return min_error == 0;
  153. }
  154. /*
  155. * Returns a set of divisors for the desired target clock with the given refclk,
  156. * or FALSE. Divisor values are the actual divisors for
  157. */
  158. static bool mrst_lvds_find_best_pll(const struct gma_limit_t *limit,
  159. struct drm_crtc *crtc, int target,
  160. int refclk, struct gma_clock_t *best_clock)
  161. {
  162. struct gma_clock_t clock;
  163. int err = target;
  164. memset(best_clock, 0, sizeof(*best_clock));
  165. memset(&clock, 0, sizeof(clock));
  166. for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) {
  167. for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max;
  168. clock.p1++) {
  169. int this_err;
  170. mrst_lvds_clock(refclk, &clock);
  171. this_err = abs(clock.dot - target);
  172. if (this_err < err) {
  173. *best_clock = clock;
  174. err = this_err;
  175. }
  176. }
  177. }
  178. return err != target;
  179. }
  180. /*
  181. * Sets the power management mode of the pipe and plane.
  182. *
  183. * This code should probably grow support for turning the cursor off and back
  184. * on appropriately at the same time as we're turning the pipe off/on.
  185. */
  186. static void oaktrail_crtc_dpms(struct drm_crtc *crtc, int mode)
  187. {
  188. struct drm_device *dev = crtc->dev;
  189. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  190. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  191. int pipe = gma_crtc->pipe;
  192. const struct psb_offset *map = &dev_priv->regmap[pipe];
  193. u32 temp;
  194. int i;
  195. int need_aux = gma_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ? 1 : 0;
  196. if (gma_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) {
  197. oaktrail_crtc_hdmi_dpms(crtc, mode);
  198. return;
  199. }
  200. if (!gma_power_begin(dev, true))
  201. return;
  202. /* XXX: When our outputs are all unaware of DPMS modes other than off
  203. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  204. */
  205. switch (mode) {
  206. case DRM_MODE_DPMS_ON:
  207. case DRM_MODE_DPMS_STANDBY:
  208. case DRM_MODE_DPMS_SUSPEND:
  209. for (i = 0; i <= need_aux; i++) {
  210. /* Enable the DPLL */
  211. temp = REG_READ_WITH_AUX(map->dpll, i);
  212. if ((temp & DPLL_VCO_ENABLE) == 0) {
  213. REG_WRITE_WITH_AUX(map->dpll, temp, i);
  214. REG_READ_WITH_AUX(map->dpll, i);
  215. /* Wait for the clocks to stabilize. */
  216. udelay(150);
  217. REG_WRITE_WITH_AUX(map->dpll,
  218. temp | DPLL_VCO_ENABLE, i);
  219. REG_READ_WITH_AUX(map->dpll, i);
  220. /* Wait for the clocks to stabilize. */
  221. udelay(150);
  222. REG_WRITE_WITH_AUX(map->dpll,
  223. temp | DPLL_VCO_ENABLE, i);
  224. REG_READ_WITH_AUX(map->dpll, i);
  225. /* Wait for the clocks to stabilize. */
  226. udelay(150);
  227. }
  228. /* Enable the pipe */
  229. temp = REG_READ_WITH_AUX(map->conf, i);
  230. if ((temp & PIPEACONF_ENABLE) == 0) {
  231. REG_WRITE_WITH_AUX(map->conf,
  232. temp | PIPEACONF_ENABLE, i);
  233. }
  234. /* Enable the plane */
  235. temp = REG_READ_WITH_AUX(map->cntr, i);
  236. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  237. REG_WRITE_WITH_AUX(map->cntr,
  238. temp | DISPLAY_PLANE_ENABLE,
  239. i);
  240. /* Flush the plane changes */
  241. REG_WRITE_WITH_AUX(map->base,
  242. REG_READ_WITH_AUX(map->base, i), i);
  243. }
  244. }
  245. gma_crtc_load_lut(crtc);
  246. /* Give the overlay scaler a chance to enable
  247. if it's on this pipe */
  248. /* psb_intel_crtc_dpms_video(crtc, true); TODO */
  249. break;
  250. case DRM_MODE_DPMS_OFF:
  251. /* Give the overlay scaler a chance to disable
  252. * if it's on this pipe */
  253. /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
  254. for (i = 0; i <= need_aux; i++) {
  255. /* Disable the VGA plane that we never use */
  256. REG_WRITE_WITH_AUX(VGACNTRL, VGA_DISP_DISABLE, i);
  257. /* Disable display plane */
  258. temp = REG_READ_WITH_AUX(map->cntr, i);
  259. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  260. REG_WRITE_WITH_AUX(map->cntr,
  261. temp & ~DISPLAY_PLANE_ENABLE, i);
  262. /* Flush the plane changes */
  263. REG_WRITE_WITH_AUX(map->base,
  264. REG_READ(map->base), i);
  265. REG_READ_WITH_AUX(map->base, i);
  266. }
  267. /* Next, disable display pipes */
  268. temp = REG_READ_WITH_AUX(map->conf, i);
  269. if ((temp & PIPEACONF_ENABLE) != 0) {
  270. REG_WRITE_WITH_AUX(map->conf,
  271. temp & ~PIPEACONF_ENABLE, i);
  272. REG_READ_WITH_AUX(map->conf, i);
  273. }
  274. /* Wait for the pipe disable to take effect. */
  275. gma_wait_for_vblank(dev);
  276. temp = REG_READ_WITH_AUX(map->dpll, i);
  277. if ((temp & DPLL_VCO_ENABLE) != 0) {
  278. REG_WRITE_WITH_AUX(map->dpll,
  279. temp & ~DPLL_VCO_ENABLE, i);
  280. REG_READ_WITH_AUX(map->dpll, i);
  281. }
  282. /* Wait for the clocks to turn off. */
  283. udelay(150);
  284. }
  285. break;
  286. }
  287. /* Set FIFO Watermarks (values taken from EMGD) */
  288. REG_WRITE(DSPARB, 0x3f80);
  289. REG_WRITE(DSPFW1, 0x3f8f0404);
  290. REG_WRITE(DSPFW2, 0x04040f04);
  291. REG_WRITE(DSPFW3, 0x0);
  292. REG_WRITE(DSPFW4, 0x04040404);
  293. REG_WRITE(DSPFW5, 0x04040404);
  294. REG_WRITE(DSPFW6, 0x78);
  295. REG_WRITE(DSPCHICKENBIT, REG_READ(DSPCHICKENBIT) | 0xc040);
  296. gma_power_end(dev);
  297. }
  298. /*
  299. * Return the pipe currently connected to the panel fitter,
  300. * or -1 if the panel fitter is not present or not in use
  301. */
  302. static int oaktrail_panel_fitter_pipe(struct drm_device *dev)
  303. {
  304. u32 pfit_control;
  305. pfit_control = REG_READ(PFIT_CONTROL);
  306. /* See if the panel fitter is in use */
  307. if ((pfit_control & PFIT_ENABLE) == 0)
  308. return -1;
  309. return (pfit_control >> 29) & 3;
  310. }
  311. static int oaktrail_crtc_mode_set(struct drm_crtc *crtc,
  312. struct drm_display_mode *mode,
  313. struct drm_display_mode *adjusted_mode,
  314. int x, int y,
  315. struct drm_framebuffer *old_fb)
  316. {
  317. struct drm_device *dev = crtc->dev;
  318. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  319. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  320. int pipe = gma_crtc->pipe;
  321. const struct psb_offset *map = &dev_priv->regmap[pipe];
  322. int refclk = 0;
  323. struct gma_clock_t clock;
  324. const struct gma_limit_t *limit;
  325. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  326. bool ok, is_sdvo = false;
  327. bool is_lvds = false;
  328. bool is_mipi = false;
  329. struct gma_encoder *gma_encoder = NULL;
  330. uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN;
  331. struct drm_connector_list_iter conn_iter;
  332. struct drm_connector *connector;
  333. int i;
  334. int need_aux = gma_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ? 1 : 0;
  335. if (gma_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  336. return oaktrail_crtc_hdmi_mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
  337. if (!gma_power_begin(dev, true))
  338. return 0;
  339. drm_mode_copy(&gma_crtc->saved_mode, mode);
  340. drm_mode_copy(&gma_crtc->saved_adjusted_mode, adjusted_mode);
  341. drm_connector_list_iter_begin(dev, &conn_iter);
  342. drm_for_each_connector_iter(connector, &conn_iter) {
  343. if (!connector->encoder || connector->encoder->crtc != crtc)
  344. continue;
  345. gma_encoder = gma_attached_encoder(connector);
  346. switch (gma_encoder->type) {
  347. case INTEL_OUTPUT_LVDS:
  348. is_lvds = true;
  349. break;
  350. case INTEL_OUTPUT_SDVO:
  351. is_sdvo = true;
  352. break;
  353. case INTEL_OUTPUT_MIPI:
  354. is_mipi = true;
  355. break;
  356. }
  357. break;
  358. }
  359. if (gma_encoder)
  360. drm_object_property_get_value(&connector->base,
  361. dev->mode_config.scaling_mode_property, &scalingType);
  362. drm_connector_list_iter_end(&conn_iter);
  363. /* Disable the VGA plane that we never use */
  364. for (i = 0; i <= need_aux; i++)
  365. REG_WRITE_WITH_AUX(VGACNTRL, VGA_DISP_DISABLE, i);
  366. /* Disable the panel fitter if it was on our pipe */
  367. if (oaktrail_panel_fitter_pipe(dev) == pipe)
  368. REG_WRITE(PFIT_CONTROL, 0);
  369. for (i = 0; i <= need_aux; i++) {
  370. REG_WRITE_WITH_AUX(map->src, ((mode->crtc_hdisplay - 1) << 16) |
  371. (mode->crtc_vdisplay - 1), i);
  372. }
  373. if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
  374. /* Moorestown doesn't have register support for centering so
  375. * we need to mess with the h/vblank and h/vsync start and
  376. * ends to get centering */
  377. int offsetX = 0, offsetY = 0;
  378. offsetX = (adjusted_mode->crtc_hdisplay -
  379. mode->crtc_hdisplay) / 2;
  380. offsetY = (adjusted_mode->crtc_vdisplay -
  381. mode->crtc_vdisplay) / 2;
  382. for (i = 0; i <= need_aux; i++) {
  383. REG_WRITE_WITH_AUX(map->htotal, (mode->crtc_hdisplay - 1) |
  384. ((adjusted_mode->crtc_htotal - 1) << 16), i);
  385. REG_WRITE_WITH_AUX(map->vtotal, (mode->crtc_vdisplay - 1) |
  386. ((adjusted_mode->crtc_vtotal - 1) << 16), i);
  387. REG_WRITE_WITH_AUX(map->hblank,
  388. (adjusted_mode->crtc_hblank_start - offsetX - 1) |
  389. ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16), i);
  390. REG_WRITE_WITH_AUX(map->hsync,
  391. (adjusted_mode->crtc_hsync_start - offsetX - 1) |
  392. ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16), i);
  393. REG_WRITE_WITH_AUX(map->vblank,
  394. (adjusted_mode->crtc_vblank_start - offsetY - 1) |
  395. ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16), i);
  396. REG_WRITE_WITH_AUX(map->vsync,
  397. (adjusted_mode->crtc_vsync_start - offsetY - 1) |
  398. ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16), i);
  399. }
  400. } else {
  401. for (i = 0; i <= need_aux; i++) {
  402. REG_WRITE_WITH_AUX(map->htotal, (adjusted_mode->crtc_hdisplay - 1) |
  403. ((adjusted_mode->crtc_htotal - 1) << 16), i);
  404. REG_WRITE_WITH_AUX(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) |
  405. ((adjusted_mode->crtc_vtotal - 1) << 16), i);
  406. REG_WRITE_WITH_AUX(map->hblank, (adjusted_mode->crtc_hblank_start - 1) |
  407. ((adjusted_mode->crtc_hblank_end - 1) << 16), i);
  408. REG_WRITE_WITH_AUX(map->hsync, (adjusted_mode->crtc_hsync_start - 1) |
  409. ((adjusted_mode->crtc_hsync_end - 1) << 16), i);
  410. REG_WRITE_WITH_AUX(map->vblank, (adjusted_mode->crtc_vblank_start - 1) |
  411. ((adjusted_mode->crtc_vblank_end - 1) << 16), i);
  412. REG_WRITE_WITH_AUX(map->vsync, (adjusted_mode->crtc_vsync_start - 1) |
  413. ((adjusted_mode->crtc_vsync_end - 1) << 16), i);
  414. }
  415. }
  416. /* Flush the plane changes */
  417. {
  418. const struct drm_crtc_helper_funcs *crtc_funcs =
  419. crtc->helper_private;
  420. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  421. }
  422. /* setup pipeconf */
  423. pipeconf = REG_READ(map->conf);
  424. /* Set up the display plane register */
  425. dspcntr = REG_READ(map->cntr);
  426. dspcntr |= DISPPLANE_GAMMA_ENABLE;
  427. if (pipe == 0)
  428. dspcntr |= DISPPLANE_SEL_PIPE_A;
  429. else
  430. dspcntr |= DISPPLANE_SEL_PIPE_B;
  431. if (is_mipi)
  432. goto oaktrail_crtc_mode_set_exit;
  433. dpll = 0; /*BIT16 = 0 for 100MHz reference */
  434. refclk = is_sdvo ? 96000 : dev_priv->core_freq * 1000;
  435. limit = mrst_limit(crtc, refclk);
  436. ok = limit->find_pll(limit, crtc, adjusted_mode->clock,
  437. refclk, &clock);
  438. if (is_sdvo) {
  439. /* Convert calculated values to register values */
  440. clock.p1 = (1L << (clock.p1 - 1));
  441. clock.m -= 2;
  442. clock.n = (1L << (clock.n - 1));
  443. }
  444. if (!ok)
  445. DRM_ERROR("Failed to find proper PLL settings");
  446. mrst_print_pll(&clock);
  447. if (is_sdvo)
  448. fp = clock.n << 16 | clock.m;
  449. else
  450. fp = oaktrail_m_converts[(clock.m - MRST_M_MIN)] << 8;
  451. dpll |= DPLL_VGA_MODE_DIS;
  452. dpll |= DPLL_VCO_ENABLE;
  453. if (is_lvds)
  454. dpll |= DPLLA_MODE_LVDS;
  455. else
  456. dpll |= DPLLB_MODE_DAC_SERIAL;
  457. if (is_sdvo) {
  458. int sdvo_pixel_multiply =
  459. adjusted_mode->clock / mode->clock;
  460. dpll |= DPLL_DVO_HIGH_SPEED;
  461. dpll |=
  462. (sdvo_pixel_multiply -
  463. 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  464. }
  465. /* compute bitmask from p1 value */
  466. if (is_sdvo)
  467. dpll |= clock.p1 << 16; // dpll |= (1 << (clock.p1 - 1)) << 16;
  468. else
  469. dpll |= (1 << (clock.p1 - 2)) << 17;
  470. dpll |= DPLL_VCO_ENABLE;
  471. if (dpll & DPLL_VCO_ENABLE) {
  472. for (i = 0; i <= need_aux; i++) {
  473. REG_WRITE_WITH_AUX(map->fp0, fp, i);
  474. REG_WRITE_WITH_AUX(map->dpll, dpll & ~DPLL_VCO_ENABLE, i);
  475. REG_READ_WITH_AUX(map->dpll, i);
  476. /* Check the DPLLA lock bit PIPEACONF[29] */
  477. udelay(150);
  478. }
  479. }
  480. for (i = 0; i <= need_aux; i++) {
  481. REG_WRITE_WITH_AUX(map->fp0, fp, i);
  482. REG_WRITE_WITH_AUX(map->dpll, dpll, i);
  483. REG_READ_WITH_AUX(map->dpll, i);
  484. /* Wait for the clocks to stabilize. */
  485. udelay(150);
  486. /* write it again -- the BIOS does, after all */
  487. REG_WRITE_WITH_AUX(map->dpll, dpll, i);
  488. REG_READ_WITH_AUX(map->dpll, i);
  489. /* Wait for the clocks to stabilize. */
  490. udelay(150);
  491. REG_WRITE_WITH_AUX(map->conf, pipeconf, i);
  492. REG_READ_WITH_AUX(map->conf, i);
  493. gma_wait_for_vblank(dev);
  494. REG_WRITE_WITH_AUX(map->cntr, dspcntr, i);
  495. gma_wait_for_vblank(dev);
  496. }
  497. oaktrail_crtc_mode_set_exit:
  498. gma_power_end(dev);
  499. return 0;
  500. }
  501. static int oaktrail_pipe_set_base(struct drm_crtc *crtc,
  502. int x, int y, struct drm_framebuffer *old_fb)
  503. {
  504. struct drm_device *dev = crtc->dev;
  505. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  506. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  507. struct drm_framebuffer *fb = crtc->primary->fb;
  508. int pipe = gma_crtc->pipe;
  509. const struct psb_offset *map = &dev_priv->regmap[pipe];
  510. unsigned long start, offset;
  511. u32 dspcntr;
  512. int ret = 0;
  513. /* no fb bound */
  514. if (!fb) {
  515. dev_dbg(dev->dev, "No FB bound\n");
  516. return 0;
  517. }
  518. if (!gma_power_begin(dev, true))
  519. return 0;
  520. start = to_psb_gem_object(fb->obj[0])->offset;
  521. offset = y * fb->pitches[0] + x * fb->format->cpp[0];
  522. REG_WRITE(map->stride, fb->pitches[0]);
  523. dspcntr = REG_READ(map->cntr);
  524. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  525. switch (fb->format->cpp[0] * 8) {
  526. case 8:
  527. dspcntr |= DISPPLANE_8BPP;
  528. break;
  529. case 16:
  530. if (fb->format->depth == 15)
  531. dspcntr |= DISPPLANE_15_16BPP;
  532. else
  533. dspcntr |= DISPPLANE_16BPP;
  534. break;
  535. case 24:
  536. case 32:
  537. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  538. break;
  539. default:
  540. dev_err(dev->dev, "Unknown color depth\n");
  541. ret = -EINVAL;
  542. goto pipe_set_base_exit;
  543. }
  544. REG_WRITE(map->cntr, dspcntr);
  545. REG_WRITE(map->base, offset);
  546. REG_READ(map->base);
  547. REG_WRITE(map->surf, start);
  548. REG_READ(map->surf);
  549. pipe_set_base_exit:
  550. gma_power_end(dev);
  551. return ret;
  552. }
  553. const struct drm_crtc_helper_funcs oaktrail_helper_funcs = {
  554. .dpms = oaktrail_crtc_dpms,
  555. .mode_set = oaktrail_crtc_mode_set,
  556. .mode_set_base = oaktrail_pipe_set_base,
  557. .prepare = gma_crtc_prepare,
  558. .commit = gma_crtc_commit,
  559. };
  560. /* Not used yet */
  561. const struct gma_clock_funcs mrst_clock_funcs = {
  562. .clock = mrst_lvds_clock,
  563. .limit = mrst_limit,
  564. .pll_is_valid = gma_pll_is_valid,
  565. };