oaktrail_crtc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) {
  128. for (clock.n = limit->n.min; clock.n <= limit->n.max;
  129. clock.n++) {
  130. for (clock.p1 = limit->p1.min;
  131. clock.p1 <= limit->p1.max; clock.p1++) {
  132. /* p2 value always stored in p2_slow on SDVO */
  133. clock.p = clock.p1 * limit->p2.p2_slow;
  134. target_vco = target * clock.p;
  135. /* VCO will increase at this point so break */
  136. if (target_vco > limit->vco.max)
  137. break;
  138. if (target_vco < limit->vco.min)
  139. continue;
  140. actual_freq = (refclk * clock.m) /
  141. (clock.n * clock.p);
  142. freq_error = 10000 -
  143. ((target * 10000) / actual_freq);
  144. if (freq_error < -min_error) {
  145. /* freq_error will start to decrease at
  146. this point so break */
  147. break;
  148. }
  149. if (freq_error < 0)
  150. freq_error = -freq_error;
  151. if (freq_error < min_error) {
  152. min_error = freq_error;
  153. *best_clock = clock;
  154. }
  155. }
  156. }
  157. if (min_error == 0)
  158. break;
  159. }
  160. return min_error == 0;
  161. }
  162. /**
  163. * Returns a set of divisors for the desired target clock with the given refclk,
  164. * or FALSE. Divisor values are the actual divisors for
  165. */
  166. static bool mrst_lvds_find_best_pll(const struct gma_limit_t *limit,
  167. struct drm_crtc *crtc, int target,
  168. int refclk, struct gma_clock_t *best_clock)
  169. {
  170. struct gma_clock_t clock;
  171. int err = target;
  172. memset(best_clock, 0, sizeof(*best_clock));
  173. for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) {
  174. for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max;
  175. clock.p1++) {
  176. int this_err;
  177. mrst_lvds_clock(refclk, &clock);
  178. this_err = abs(clock.dot - target);
  179. if (this_err < err) {
  180. *best_clock = clock;
  181. err = this_err;
  182. }
  183. }
  184. }
  185. return err != target;
  186. }
  187. /**
  188. * Sets the power management mode of the pipe and plane.
  189. *
  190. * This code should probably grow support for turning the cursor off and back
  191. * on appropriately at the same time as we're turning the pipe off/on.
  192. */
  193. static void oaktrail_crtc_dpms(struct drm_crtc *crtc, int mode)
  194. {
  195. struct drm_device *dev = crtc->dev;
  196. struct drm_psb_private *dev_priv = dev->dev_private;
  197. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  198. int pipe = gma_crtc->pipe;
  199. const struct psb_offset *map = &dev_priv->regmap[pipe];
  200. u32 temp;
  201. if (pipe == 1) {
  202. oaktrail_crtc_hdmi_dpms(crtc, mode);
  203. return;
  204. }
  205. if (!gma_power_begin(dev, true))
  206. return;
  207. /* XXX: When our outputs are all unaware of DPMS modes other than off
  208. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  209. */
  210. switch (mode) {
  211. case DRM_MODE_DPMS_ON:
  212. case DRM_MODE_DPMS_STANDBY:
  213. case DRM_MODE_DPMS_SUSPEND:
  214. /* Enable the DPLL */
  215. temp = REG_READ(map->dpll);
  216. if ((temp & DPLL_VCO_ENABLE) == 0) {
  217. REG_WRITE(map->dpll, temp);
  218. REG_READ(map->dpll);
  219. /* Wait for the clocks to stabilize. */
  220. udelay(150);
  221. REG_WRITE(map->dpll, temp | DPLL_VCO_ENABLE);
  222. REG_READ(map->dpll);
  223. /* Wait for the clocks to stabilize. */
  224. udelay(150);
  225. REG_WRITE(map->dpll, temp | DPLL_VCO_ENABLE);
  226. REG_READ(map->dpll);
  227. /* Wait for the clocks to stabilize. */
  228. udelay(150);
  229. }
  230. /* Enable the pipe */
  231. temp = REG_READ(map->conf);
  232. if ((temp & PIPEACONF_ENABLE) == 0)
  233. REG_WRITE(map->conf, temp | PIPEACONF_ENABLE);
  234. /* Enable the plane */
  235. temp = REG_READ(map->cntr);
  236. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  237. REG_WRITE(map->cntr,
  238. temp | DISPLAY_PLANE_ENABLE);
  239. /* Flush the plane changes */
  240. REG_WRITE(map->base, REG_READ(map->base));
  241. }
  242. gma_crtc_load_lut(crtc);
  243. /* Give the overlay scaler a chance to enable
  244. if it's on this pipe */
  245. /* psb_intel_crtc_dpms_video(crtc, true); TODO */
  246. break;
  247. case DRM_MODE_DPMS_OFF:
  248. /* Give the overlay scaler a chance to disable
  249. * if it's on this pipe */
  250. /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
  251. /* Disable the VGA plane that we never use */
  252. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  253. /* Disable display plane */
  254. temp = REG_READ(map->cntr);
  255. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  256. REG_WRITE(map->cntr,
  257. temp & ~DISPLAY_PLANE_ENABLE);
  258. /* Flush the plane changes */
  259. REG_WRITE(map->base, REG_READ(map->base));
  260. REG_READ(map->base);
  261. }
  262. /* Next, disable display pipes */
  263. temp = REG_READ(map->conf);
  264. if ((temp & PIPEACONF_ENABLE) != 0) {
  265. REG_WRITE(map->conf, temp & ~PIPEACONF_ENABLE);
  266. REG_READ(map->conf);
  267. }
  268. /* Wait for for the pipe disable to take effect. */
  269. gma_wait_for_vblank(dev);
  270. temp = REG_READ(map->dpll);
  271. if ((temp & DPLL_VCO_ENABLE) != 0) {
  272. REG_WRITE(map->dpll, temp & ~DPLL_VCO_ENABLE);
  273. REG_READ(map->dpll);
  274. }
  275. /* Wait for the clocks to turn off. */
  276. udelay(150);
  277. break;
  278. }
  279. /*Set FIFO Watermarks*/
  280. REG_WRITE(DSPARB, 0x3FFF);
  281. REG_WRITE(DSPFW1, 0x3F88080A);
  282. REG_WRITE(DSPFW2, 0x0b060808);
  283. REG_WRITE(DSPFW3, 0x0);
  284. REG_WRITE(DSPFW4, 0x08030404);
  285. REG_WRITE(DSPFW5, 0x04040404);
  286. REG_WRITE(DSPFW6, 0x78);
  287. REG_WRITE(0x70400, REG_READ(0x70400) | 0x4000);
  288. /* Must write Bit 14 of the Chicken Bit Register */
  289. gma_power_end(dev);
  290. }
  291. /**
  292. * Return the pipe currently connected to the panel fitter,
  293. * or -1 if the panel fitter is not present or not in use
  294. */
  295. static int oaktrail_panel_fitter_pipe(struct drm_device *dev)
  296. {
  297. u32 pfit_control;
  298. pfit_control = REG_READ(PFIT_CONTROL);
  299. /* See if the panel fitter is in use */
  300. if ((pfit_control & PFIT_ENABLE) == 0)
  301. return -1;
  302. return (pfit_control >> 29) & 3;
  303. }
  304. static int oaktrail_crtc_mode_set(struct drm_crtc *crtc,
  305. struct drm_display_mode *mode,
  306. struct drm_display_mode *adjusted_mode,
  307. int x, int y,
  308. struct drm_framebuffer *old_fb)
  309. {
  310. struct drm_device *dev = crtc->dev;
  311. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  312. struct drm_psb_private *dev_priv = dev->dev_private;
  313. int pipe = gma_crtc->pipe;
  314. const struct psb_offset *map = &dev_priv->regmap[pipe];
  315. int refclk = 0;
  316. struct gma_clock_t clock;
  317. const struct gma_limit_t *limit;
  318. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  319. bool ok, is_sdvo = false;
  320. bool is_lvds = false;
  321. bool is_mipi = false;
  322. struct drm_mode_config *mode_config = &dev->mode_config;
  323. struct gma_encoder *gma_encoder = NULL;
  324. uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN;
  325. struct drm_connector *connector;
  326. if (pipe == 1)
  327. return oaktrail_crtc_hdmi_mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
  328. if (!gma_power_begin(dev, true))
  329. return 0;
  330. memcpy(&gma_crtc->saved_mode,
  331. mode,
  332. sizeof(struct drm_display_mode));
  333. memcpy(&gma_crtc->saved_adjusted_mode,
  334. adjusted_mode,
  335. sizeof(struct drm_display_mode));
  336. list_for_each_entry(connector, &mode_config->connector_list, head) {
  337. if (!connector->encoder || connector->encoder->crtc != crtc)
  338. continue;
  339. gma_encoder = gma_attached_encoder(connector);
  340. switch (gma_encoder->type) {
  341. case INTEL_OUTPUT_LVDS:
  342. is_lvds = true;
  343. break;
  344. case INTEL_OUTPUT_SDVO:
  345. is_sdvo = true;
  346. break;
  347. case INTEL_OUTPUT_MIPI:
  348. is_mipi = true;
  349. break;
  350. }
  351. }
  352. /* Disable the VGA plane that we never use */
  353. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  354. /* Disable the panel fitter if it was on our pipe */
  355. if (oaktrail_panel_fitter_pipe(dev) == pipe)
  356. REG_WRITE(PFIT_CONTROL, 0);
  357. REG_WRITE(map->src,
  358. ((mode->crtc_hdisplay - 1) << 16) |
  359. (mode->crtc_vdisplay - 1));
  360. if (gma_encoder)
  361. drm_object_property_get_value(&connector->base,
  362. dev->mode_config.scaling_mode_property, &scalingType);
  363. if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
  364. /* Moorestown doesn't have register support for centering so
  365. * we need to mess with the h/vblank and h/vsync start and
  366. * ends to get centering */
  367. int offsetX = 0, offsetY = 0;
  368. offsetX = (adjusted_mode->crtc_hdisplay -
  369. mode->crtc_hdisplay) / 2;
  370. offsetY = (adjusted_mode->crtc_vdisplay -
  371. mode->crtc_vdisplay) / 2;
  372. REG_WRITE(map->htotal, (mode->crtc_hdisplay - 1) |
  373. ((adjusted_mode->crtc_htotal - 1) << 16));
  374. REG_WRITE(map->vtotal, (mode->crtc_vdisplay - 1) |
  375. ((adjusted_mode->crtc_vtotal - 1) << 16));
  376. REG_WRITE(map->hblank,
  377. (adjusted_mode->crtc_hblank_start - offsetX - 1) |
  378. ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16));
  379. REG_WRITE(map->hsync,
  380. (adjusted_mode->crtc_hsync_start - offsetX - 1) |
  381. ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16));
  382. REG_WRITE(map->vblank,
  383. (adjusted_mode->crtc_vblank_start - offsetY - 1) |
  384. ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16));
  385. REG_WRITE(map->vsync,
  386. (adjusted_mode->crtc_vsync_start - offsetY - 1) |
  387. ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16));
  388. } else {
  389. REG_WRITE(map->htotal, (adjusted_mode->crtc_hdisplay - 1) |
  390. ((adjusted_mode->crtc_htotal - 1) << 16));
  391. REG_WRITE(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) |
  392. ((adjusted_mode->crtc_vtotal - 1) << 16));
  393. REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start - 1) |
  394. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  395. REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start - 1) |
  396. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  397. REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start - 1) |
  398. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  399. REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start - 1) |
  400. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  401. }
  402. /* Flush the plane changes */
  403. {
  404. struct drm_crtc_helper_funcs *crtc_funcs =
  405. crtc->helper_private;
  406. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  407. }
  408. /* setup pipeconf */
  409. pipeconf = REG_READ(map->conf);
  410. /* Set up the display plane register */
  411. dspcntr = REG_READ(map->cntr);
  412. dspcntr |= DISPPLANE_GAMMA_ENABLE;
  413. if (pipe == 0)
  414. dspcntr |= DISPPLANE_SEL_PIPE_A;
  415. else
  416. dspcntr |= DISPPLANE_SEL_PIPE_B;
  417. if (is_mipi)
  418. goto oaktrail_crtc_mode_set_exit;
  419. dpll = 0; /*BIT16 = 0 for 100MHz reference */
  420. refclk = is_sdvo ? 96000 : dev_priv->core_freq * 1000;
  421. limit = mrst_limit(crtc, refclk);
  422. ok = limit->find_pll(limit, crtc, adjusted_mode->clock,
  423. refclk, &clock);
  424. if (is_sdvo) {
  425. /* Convert calculated values to register values */
  426. clock.p1 = (1L << (clock.p1 - 1));
  427. clock.m -= 2;
  428. clock.n = (1L << (clock.n - 1));
  429. }
  430. if (!ok)
  431. DRM_ERROR("Failed to find proper PLL settings");
  432. mrst_print_pll(&clock);
  433. if (is_sdvo)
  434. fp = clock.n << 16 | clock.m;
  435. else
  436. fp = oaktrail_m_converts[(clock.m - MRST_M_MIN)] << 8;
  437. dpll |= DPLL_VGA_MODE_DIS;
  438. dpll |= DPLL_VCO_ENABLE;
  439. if (is_lvds)
  440. dpll |= DPLLA_MODE_LVDS;
  441. else
  442. dpll |= DPLLB_MODE_DAC_SERIAL;
  443. if (is_sdvo) {
  444. int sdvo_pixel_multiply =
  445. adjusted_mode->clock / mode->clock;
  446. dpll |= DPLL_DVO_HIGH_SPEED;
  447. dpll |=
  448. (sdvo_pixel_multiply -
  449. 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  450. }
  451. /* compute bitmask from p1 value */
  452. if (is_sdvo)
  453. dpll |= clock.p1 << 16; // dpll |= (1 << (clock.p1 - 1)) << 16;
  454. else
  455. dpll |= (1 << (clock.p1 - 2)) << 17;
  456. dpll |= DPLL_VCO_ENABLE;
  457. if (dpll & DPLL_VCO_ENABLE) {
  458. REG_WRITE(map->fp0, fp);
  459. REG_WRITE(map->dpll, dpll & ~DPLL_VCO_ENABLE);
  460. REG_READ(map->dpll);
  461. /* Check the DPLLA lock bit PIPEACONF[29] */
  462. udelay(150);
  463. }
  464. REG_WRITE(map->fp0, fp);
  465. REG_WRITE(map->dpll, dpll);
  466. REG_READ(map->dpll);
  467. /* Wait for the clocks to stabilize. */
  468. udelay(150);
  469. /* write it again -- the BIOS does, after all */
  470. REG_WRITE(map->dpll, dpll);
  471. REG_READ(map->dpll);
  472. /* Wait for the clocks to stabilize. */
  473. udelay(150);
  474. REG_WRITE(map->conf, pipeconf);
  475. REG_READ(map->conf);
  476. gma_wait_for_vblank(dev);
  477. REG_WRITE(map->cntr, dspcntr);
  478. gma_wait_for_vblank(dev);
  479. oaktrail_crtc_mode_set_exit:
  480. gma_power_end(dev);
  481. return 0;
  482. }
  483. static int oaktrail_pipe_set_base(struct drm_crtc *crtc,
  484. int x, int y, struct drm_framebuffer *old_fb)
  485. {
  486. struct drm_device *dev = crtc->dev;
  487. struct drm_psb_private *dev_priv = dev->dev_private;
  488. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  489. struct psb_framebuffer *psbfb = to_psb_fb(crtc->fb);
  490. int pipe = gma_crtc->pipe;
  491. const struct psb_offset *map = &dev_priv->regmap[pipe];
  492. unsigned long start, offset;
  493. u32 dspcntr;
  494. int ret = 0;
  495. /* no fb bound */
  496. if (!crtc->fb) {
  497. dev_dbg(dev->dev, "No FB bound\n");
  498. return 0;
  499. }
  500. if (!gma_power_begin(dev, true))
  501. return 0;
  502. start = psbfb->gtt->offset;
  503. offset = y * crtc->fb->pitches[0] + x * (crtc->fb->bits_per_pixel / 8);
  504. REG_WRITE(map->stride, crtc->fb->pitches[0]);
  505. dspcntr = REG_READ(map->cntr);
  506. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  507. switch (crtc->fb->bits_per_pixel) {
  508. case 8:
  509. dspcntr |= DISPPLANE_8BPP;
  510. break;
  511. case 16:
  512. if (crtc->fb->depth == 15)
  513. dspcntr |= DISPPLANE_15_16BPP;
  514. else
  515. dspcntr |= DISPPLANE_16BPP;
  516. break;
  517. case 24:
  518. case 32:
  519. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  520. break;
  521. default:
  522. dev_err(dev->dev, "Unknown color depth\n");
  523. ret = -EINVAL;
  524. goto pipe_set_base_exit;
  525. }
  526. REG_WRITE(map->cntr, dspcntr);
  527. REG_WRITE(map->base, offset);
  528. REG_READ(map->base);
  529. REG_WRITE(map->surf, start);
  530. REG_READ(map->surf);
  531. pipe_set_base_exit:
  532. gma_power_end(dev);
  533. return ret;
  534. }
  535. const struct drm_crtc_helper_funcs oaktrail_helper_funcs = {
  536. .dpms = oaktrail_crtc_dpms,
  537. .mode_fixup = gma_crtc_mode_fixup,
  538. .mode_set = oaktrail_crtc_mode_set,
  539. .mode_set_base = oaktrail_pipe_set_base,
  540. .prepare = gma_crtc_prepare,
  541. .commit = gma_crtc_commit,
  542. };
  543. /* Not used yet */
  544. const struct gma_clock_funcs mrst_clock_funcs = {
  545. .clock = mrst_lvds_clock,
  546. .limit = mrst_limit,
  547. .pll_is_valid = gma_pll_is_valid,
  548. };