oaktrail_crtc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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 "psb_intel_display.h"
  25. #include "power.h"
  26. struct psb_intel_range_t {
  27. int min, max;
  28. };
  29. struct oaktrail_limit_t {
  30. struct psb_intel_range_t dot, m, p1;
  31. };
  32. struct oaktrail_clock_t {
  33. /* derived values */
  34. int dot;
  35. int m;
  36. int p1;
  37. };
  38. #define MRST_LIMIT_LVDS_100L 0
  39. #define MRST_LIMIT_LVDS_83 1
  40. #define MRST_LIMIT_LVDS_100 2
  41. #define MRST_DOT_MIN 19750
  42. #define MRST_DOT_MAX 120000
  43. #define MRST_M_MIN_100L 20
  44. #define MRST_M_MIN_100 10
  45. #define MRST_M_MIN_83 12
  46. #define MRST_M_MAX_100L 34
  47. #define MRST_M_MAX_100 17
  48. #define MRST_M_MAX_83 20
  49. #define MRST_P1_MIN 2
  50. #define MRST_P1_MAX_0 7
  51. #define MRST_P1_MAX_1 8
  52. static const struct oaktrail_limit_t oaktrail_limits[] = {
  53. { /* MRST_LIMIT_LVDS_100L */
  54. .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
  55. .m = {.min = MRST_M_MIN_100L, .max = MRST_M_MAX_100L},
  56. .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1},
  57. },
  58. { /* MRST_LIMIT_LVDS_83L */
  59. .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
  60. .m = {.min = MRST_M_MIN_83, .max = MRST_M_MAX_83},
  61. .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_0},
  62. },
  63. { /* MRST_LIMIT_LVDS_100 */
  64. .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
  65. .m = {.min = MRST_M_MIN_100, .max = MRST_M_MAX_100},
  66. .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1},
  67. },
  68. };
  69. #define MRST_M_MIN 10
  70. static const u32 oaktrail_m_converts[] = {
  71. 0x2B, 0x15, 0x2A, 0x35, 0x1A, 0x0D, 0x26, 0x33, 0x19, 0x2C,
  72. 0x36, 0x3B, 0x1D, 0x2E, 0x37, 0x1B, 0x2D, 0x16, 0x0B, 0x25,
  73. 0x12, 0x09, 0x24, 0x32, 0x39, 0x1c,
  74. };
  75. static const struct oaktrail_limit_t *oaktrail_limit(struct drm_crtc *crtc)
  76. {
  77. const struct oaktrail_limit_t *limit = NULL;
  78. struct drm_device *dev = crtc->dev;
  79. struct drm_psb_private *dev_priv = dev->dev_private;
  80. if (psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)
  81. || psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_MIPI)) {
  82. switch (dev_priv->core_freq) {
  83. case 100:
  84. limit = &oaktrail_limits[MRST_LIMIT_LVDS_100L];
  85. break;
  86. case 166:
  87. limit = &oaktrail_limits[MRST_LIMIT_LVDS_83];
  88. break;
  89. case 200:
  90. limit = &oaktrail_limits[MRST_LIMIT_LVDS_100];
  91. break;
  92. }
  93. } else {
  94. limit = NULL;
  95. dev_err(dev->dev, "oaktrail_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 oaktrail_clock(int refclk, struct oaktrail_clock_t *clock)
  101. {
  102. clock->dot = (refclk * clock->m) / (14 * clock->p1);
  103. }
  104. static void mrstPrintPll(char *prefix, struct oaktrail_clock_t *clock)
  105. {
  106. pr_debug("%s: dotclock = %d, m = %d, p1 = %d.\n",
  107. prefix, clock->dot, clock->m, clock->p1);
  108. }
  109. /**
  110. * Returns a set of divisors for the desired target clock with the given refclk,
  111. * or FALSE. Divisor values are the actual divisors for
  112. */
  113. static bool
  114. mrstFindBestPLL(struct drm_crtc *crtc, int target, int refclk,
  115. struct oaktrail_clock_t *best_clock)
  116. {
  117. struct oaktrail_clock_t clock;
  118. const struct oaktrail_limit_t *limit = oaktrail_limit(crtc);
  119. int err = target;
  120. memset(best_clock, 0, sizeof(*best_clock));
  121. for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) {
  122. for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max;
  123. clock.p1++) {
  124. int this_err;
  125. oaktrail_clock(refclk, &clock);
  126. this_err = abs(clock.dot - target);
  127. if (this_err < err) {
  128. *best_clock = clock;
  129. err = this_err;
  130. }
  131. }
  132. }
  133. dev_dbg(crtc->dev->dev, "mrstFindBestPLL err = %d.\n", err);
  134. return err != target;
  135. }
  136. /**
  137. * Sets the power management mode of the pipe and plane.
  138. *
  139. * This code should probably grow support for turning the cursor off and back
  140. * on appropriately at the same time as we're turning the pipe off/on.
  141. */
  142. static void oaktrail_crtc_dpms(struct drm_crtc *crtc, int mode)
  143. {
  144. struct drm_device *dev = crtc->dev;
  145. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  146. int pipe = psb_intel_crtc->pipe;
  147. int dpll_reg = (pipe == 0) ? MRST_DPLL_A : DPLL_B;
  148. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  149. int dspbase_reg = (pipe == 0) ? MRST_DSPABASE : DSPBBASE;
  150. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  151. u32 temp;
  152. if (!gma_power_begin(dev, true))
  153. return;
  154. /* XXX: When our outputs are all unaware of DPMS modes other than off
  155. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  156. */
  157. switch (mode) {
  158. case DRM_MODE_DPMS_ON:
  159. case DRM_MODE_DPMS_STANDBY:
  160. case DRM_MODE_DPMS_SUSPEND:
  161. /* Enable the DPLL */
  162. temp = REG_READ(dpll_reg);
  163. if ((temp & DPLL_VCO_ENABLE) == 0) {
  164. REG_WRITE(dpll_reg, temp);
  165. REG_READ(dpll_reg);
  166. /* Wait for the clocks to stabilize. */
  167. udelay(150);
  168. REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  169. REG_READ(dpll_reg);
  170. /* Wait for the clocks to stabilize. */
  171. udelay(150);
  172. REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  173. REG_READ(dpll_reg);
  174. /* Wait for the clocks to stabilize. */
  175. udelay(150);
  176. }
  177. /* Enable the pipe */
  178. temp = REG_READ(pipeconf_reg);
  179. if ((temp & PIPEACONF_ENABLE) == 0)
  180. REG_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  181. /* Enable the plane */
  182. temp = REG_READ(dspcntr_reg);
  183. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  184. REG_WRITE(dspcntr_reg,
  185. temp | DISPLAY_PLANE_ENABLE);
  186. /* Flush the plane changes */
  187. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  188. }
  189. psb_intel_crtc_load_lut(crtc);
  190. /* Give the overlay scaler a chance to enable
  191. if it's on this pipe */
  192. /* psb_intel_crtc_dpms_video(crtc, true); TODO */
  193. break;
  194. case DRM_MODE_DPMS_OFF:
  195. /* Give the overlay scaler a chance to disable
  196. * if it's on this pipe */
  197. /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
  198. /* Disable the VGA plane that we never use */
  199. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  200. /* Disable display plane */
  201. temp = REG_READ(dspcntr_reg);
  202. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  203. REG_WRITE(dspcntr_reg,
  204. temp & ~DISPLAY_PLANE_ENABLE);
  205. /* Flush the plane changes */
  206. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  207. REG_READ(dspbase_reg);
  208. }
  209. /* Next, disable display pipes */
  210. temp = REG_READ(pipeconf_reg);
  211. if ((temp & PIPEACONF_ENABLE) != 0) {
  212. REG_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  213. REG_READ(pipeconf_reg);
  214. }
  215. /* Wait for for the pipe disable to take effect. */
  216. psb_intel_wait_for_vblank(dev);
  217. temp = REG_READ(dpll_reg);
  218. if ((temp & DPLL_VCO_ENABLE) != 0) {
  219. REG_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  220. REG_READ(dpll_reg);
  221. }
  222. /* Wait for the clocks to turn off. */
  223. udelay(150);
  224. break;
  225. }
  226. /*Set FIFO Watermarks*/
  227. REG_WRITE(DSPARB, 0x3FFF);
  228. REG_WRITE(DSPFW1, 0x3F88080A);
  229. REG_WRITE(DSPFW2, 0x0b060808);
  230. REG_WRITE(DSPFW3, 0x0);
  231. REG_WRITE(DSPFW4, 0x08030404);
  232. REG_WRITE(DSPFW5, 0x04040404);
  233. REG_WRITE(DSPFW6, 0x78);
  234. REG_WRITE(0x70400, REG_READ(0x70400) | 0x4000);
  235. /* Must write Bit 14 of the Chicken Bit Register */
  236. gma_power_end(dev);
  237. }
  238. /**
  239. * Return the pipe currently connected to the panel fitter,
  240. * or -1 if the panel fitter is not present or not in use
  241. */
  242. static int oaktrail_panel_fitter_pipe(struct drm_device *dev)
  243. {
  244. u32 pfit_control;
  245. pfit_control = REG_READ(PFIT_CONTROL);
  246. /* See if the panel fitter is in use */
  247. if ((pfit_control & PFIT_ENABLE) == 0)
  248. return -1;
  249. return (pfit_control >> 29) & 3;
  250. }
  251. static int oaktrail_crtc_mode_set(struct drm_crtc *crtc,
  252. struct drm_display_mode *mode,
  253. struct drm_display_mode *adjusted_mode,
  254. int x, int y,
  255. struct drm_framebuffer *old_fb)
  256. {
  257. struct drm_device *dev = crtc->dev;
  258. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  259. struct drm_psb_private *dev_priv = dev->dev_private;
  260. int pipe = psb_intel_crtc->pipe;
  261. int fp_reg = (pipe == 0) ? MRST_FPA0 : FPB0;
  262. int dpll_reg = (pipe == 0) ? MRST_DPLL_A : DPLL_B;
  263. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  264. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  265. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  266. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  267. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  268. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  269. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  270. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  271. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  272. int refclk = 0;
  273. struct oaktrail_clock_t clock;
  274. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  275. bool ok, is_sdvo = false;
  276. bool is_lvds = false;
  277. bool is_mipi = false;
  278. struct drm_mode_config *mode_config = &dev->mode_config;
  279. struct psb_intel_encoder *psb_intel_encoder = NULL;
  280. uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN;
  281. struct drm_connector *connector;
  282. if (!gma_power_begin(dev, true))
  283. return 0;
  284. memcpy(&psb_intel_crtc->saved_mode,
  285. mode,
  286. sizeof(struct drm_display_mode));
  287. memcpy(&psb_intel_crtc->saved_adjusted_mode,
  288. adjusted_mode,
  289. sizeof(struct drm_display_mode));
  290. list_for_each_entry(connector, &mode_config->connector_list, head) {
  291. if (!connector->encoder || connector->encoder->crtc != crtc)
  292. continue;
  293. psb_intel_encoder = psb_intel_attached_encoder(connector);
  294. switch (psb_intel_encoder->type) {
  295. case INTEL_OUTPUT_LVDS:
  296. is_lvds = true;
  297. break;
  298. case INTEL_OUTPUT_SDVO:
  299. is_sdvo = true;
  300. break;
  301. case INTEL_OUTPUT_MIPI:
  302. is_mipi = true;
  303. break;
  304. }
  305. }
  306. /* Disable the VGA plane that we never use */
  307. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  308. /* Disable the panel fitter if it was on our pipe */
  309. if (oaktrail_panel_fitter_pipe(dev) == pipe)
  310. REG_WRITE(PFIT_CONTROL, 0);
  311. REG_WRITE(pipesrc_reg,
  312. ((mode->crtc_hdisplay - 1) << 16) |
  313. (mode->crtc_vdisplay - 1));
  314. if (psb_intel_encoder)
  315. drm_connector_property_get_value(connector,
  316. dev->mode_config.scaling_mode_property, &scalingType);
  317. if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
  318. /* Moorestown doesn't have register support for centering so
  319. * we need to mess with the h/vblank and h/vsync start and
  320. * ends to get centering */
  321. int offsetX = 0, offsetY = 0;
  322. offsetX = (adjusted_mode->crtc_hdisplay -
  323. mode->crtc_hdisplay) / 2;
  324. offsetY = (adjusted_mode->crtc_vdisplay -
  325. mode->crtc_vdisplay) / 2;
  326. REG_WRITE(htot_reg, (mode->crtc_hdisplay - 1) |
  327. ((adjusted_mode->crtc_htotal - 1) << 16));
  328. REG_WRITE(vtot_reg, (mode->crtc_vdisplay - 1) |
  329. ((adjusted_mode->crtc_vtotal - 1) << 16));
  330. REG_WRITE(hblank_reg,
  331. (adjusted_mode->crtc_hblank_start - offsetX - 1) |
  332. ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16));
  333. REG_WRITE(hsync_reg,
  334. (adjusted_mode->crtc_hsync_start - offsetX - 1) |
  335. ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16));
  336. REG_WRITE(vblank_reg,
  337. (adjusted_mode->crtc_vblank_start - offsetY - 1) |
  338. ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16));
  339. REG_WRITE(vsync_reg,
  340. (adjusted_mode->crtc_vsync_start - offsetY - 1) |
  341. ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16));
  342. } else {
  343. REG_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  344. ((adjusted_mode->crtc_htotal - 1) << 16));
  345. REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  346. ((adjusted_mode->crtc_vtotal - 1) << 16));
  347. REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  348. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  349. REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  350. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  351. REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  352. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  353. REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  354. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  355. }
  356. /* Flush the plane changes */
  357. {
  358. struct drm_crtc_helper_funcs *crtc_funcs =
  359. crtc->helper_private;
  360. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  361. }
  362. /* setup pipeconf */
  363. pipeconf = REG_READ(pipeconf_reg);
  364. /* Set up the display plane register */
  365. dspcntr = REG_READ(dspcntr_reg);
  366. dspcntr |= DISPPLANE_GAMMA_ENABLE;
  367. if (pipe == 0)
  368. dspcntr |= DISPPLANE_SEL_PIPE_A;
  369. else
  370. dspcntr |= DISPPLANE_SEL_PIPE_B;
  371. if (is_mipi)
  372. goto oaktrail_crtc_mode_set_exit;
  373. refclk = dev_priv->core_freq * 1000;
  374. dpll = 0; /*BIT16 = 0 for 100MHz reference */
  375. ok = mrstFindBestPLL(crtc, adjusted_mode->clock, refclk, &clock);
  376. if (!ok) {
  377. dev_dbg(dev->dev, "mrstFindBestPLL fail in oaktrail_crtc_mode_set.\n");
  378. } else {
  379. dev_dbg(dev->dev, "oaktrail_crtc_mode_set pixel clock = %d,"
  380. "m = %x, p1 = %x.\n", clock.dot, clock.m,
  381. clock.p1);
  382. }
  383. fp = oaktrail_m_converts[(clock.m - MRST_M_MIN)] << 8;
  384. dpll |= DPLL_VGA_MODE_DIS;
  385. dpll |= DPLL_VCO_ENABLE;
  386. if (is_lvds)
  387. dpll |= DPLLA_MODE_LVDS;
  388. else
  389. dpll |= DPLLB_MODE_DAC_SERIAL;
  390. if (is_sdvo) {
  391. int sdvo_pixel_multiply =
  392. adjusted_mode->clock / mode->clock;
  393. dpll |= DPLL_DVO_HIGH_SPEED;
  394. dpll |=
  395. (sdvo_pixel_multiply -
  396. 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  397. }
  398. /* compute bitmask from p1 value */
  399. dpll |= (1 << (clock.p1 - 2)) << 17;
  400. dpll |= DPLL_VCO_ENABLE;
  401. mrstPrintPll("chosen", &clock);
  402. if (dpll & DPLL_VCO_ENABLE) {
  403. REG_WRITE(fp_reg, fp);
  404. REG_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  405. REG_READ(dpll_reg);
  406. /* Check the DPLLA lock bit PIPEACONF[29] */
  407. udelay(150);
  408. }
  409. REG_WRITE(fp_reg, fp);
  410. REG_WRITE(dpll_reg, dpll);
  411. REG_READ(dpll_reg);
  412. /* Wait for the clocks to stabilize. */
  413. udelay(150);
  414. /* write it again -- the BIOS does, after all */
  415. REG_WRITE(dpll_reg, dpll);
  416. REG_READ(dpll_reg);
  417. /* Wait for the clocks to stabilize. */
  418. udelay(150);
  419. REG_WRITE(pipeconf_reg, pipeconf);
  420. REG_READ(pipeconf_reg);
  421. psb_intel_wait_for_vblank(dev);
  422. REG_WRITE(dspcntr_reg, dspcntr);
  423. psb_intel_wait_for_vblank(dev);
  424. oaktrail_crtc_mode_set_exit:
  425. gma_power_end(dev);
  426. return 0;
  427. }
  428. static bool oaktrail_crtc_mode_fixup(struct drm_crtc *crtc,
  429. struct drm_display_mode *mode,
  430. struct drm_display_mode *adjusted_mode)
  431. {
  432. return true;
  433. }
  434. static int oaktrail_pipe_set_base(struct drm_crtc *crtc,
  435. int x, int y, struct drm_framebuffer *old_fb)
  436. {
  437. struct drm_device *dev = crtc->dev;
  438. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  439. struct psb_framebuffer *psbfb = to_psb_fb(crtc->fb);
  440. int pipe = psb_intel_crtc->pipe;
  441. unsigned long start, offset;
  442. int dspbase = (pipe == 0 ? DSPALINOFF : DSPBBASE);
  443. int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF);
  444. int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE;
  445. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  446. u32 dspcntr;
  447. int ret = 0;
  448. /* no fb bound */
  449. if (!crtc->fb) {
  450. dev_dbg(dev->dev, "No FB bound\n");
  451. return 0;
  452. }
  453. if (!gma_power_begin(dev, true))
  454. return 0;
  455. start = psbfb->gtt->offset;
  456. offset = y * crtc->fb->pitches[0] + x * (crtc->fb->bits_per_pixel / 8);
  457. REG_WRITE(dspstride, crtc->fb->pitches[0]);
  458. dspcntr = REG_READ(dspcntr_reg);
  459. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  460. switch (crtc->fb->bits_per_pixel) {
  461. case 8:
  462. dspcntr |= DISPPLANE_8BPP;
  463. break;
  464. case 16:
  465. if (crtc->fb->depth == 15)
  466. dspcntr |= DISPPLANE_15_16BPP;
  467. else
  468. dspcntr |= DISPPLANE_16BPP;
  469. break;
  470. case 24:
  471. case 32:
  472. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  473. break;
  474. default:
  475. dev_err(dev->dev, "Unknown color depth\n");
  476. ret = -EINVAL;
  477. goto pipe_set_base_exit;
  478. }
  479. REG_WRITE(dspcntr_reg, dspcntr);
  480. REG_WRITE(dspbase, offset);
  481. REG_READ(dspbase);
  482. REG_WRITE(dspsurf, start);
  483. REG_READ(dspsurf);
  484. pipe_set_base_exit:
  485. gma_power_end(dev);
  486. return ret;
  487. }
  488. static void oaktrail_crtc_prepare(struct drm_crtc *crtc)
  489. {
  490. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  491. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  492. }
  493. static void oaktrail_crtc_commit(struct drm_crtc *crtc)
  494. {
  495. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  496. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  497. }
  498. const struct drm_crtc_helper_funcs oaktrail_helper_funcs = {
  499. .dpms = oaktrail_crtc_dpms,
  500. .mode_fixup = oaktrail_crtc_mode_fixup,
  501. .mode_set = oaktrail_crtc_mode_set,
  502. .mode_set_base = oaktrail_pipe_set_base,
  503. .prepare = oaktrail_crtc_prepare,
  504. .commit = oaktrail_crtc_commit,
  505. };