oaktrail_crtc.c 19 KB

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