oaktrail_crtc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. 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. bool enabled;
  153. if (!gma_power_begin(dev, true))
  154. return;
  155. /* XXX: When our outputs are all unaware of DPMS modes other than off
  156. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  157. */
  158. switch (mode) {
  159. case DRM_MODE_DPMS_ON:
  160. case DRM_MODE_DPMS_STANDBY:
  161. case DRM_MODE_DPMS_SUSPEND:
  162. /* Enable the DPLL */
  163. temp = REG_READ(dpll_reg);
  164. if ((temp & DPLL_VCO_ENABLE) == 0) {
  165. REG_WRITE(dpll_reg, temp);
  166. REG_READ(dpll_reg);
  167. /* Wait for the clocks to stabilize. */
  168. udelay(150);
  169. REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  170. REG_READ(dpll_reg);
  171. /* Wait for the clocks to stabilize. */
  172. udelay(150);
  173. REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  174. REG_READ(dpll_reg);
  175. /* Wait for the clocks to stabilize. */
  176. udelay(150);
  177. }
  178. /* Enable the pipe */
  179. temp = REG_READ(pipeconf_reg);
  180. if ((temp & PIPEACONF_ENABLE) == 0)
  181. REG_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  182. /* Enable the plane */
  183. temp = REG_READ(dspcntr_reg);
  184. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  185. REG_WRITE(dspcntr_reg,
  186. temp | DISPLAY_PLANE_ENABLE);
  187. /* Flush the plane changes */
  188. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  189. }
  190. psb_intel_crtc_load_lut(crtc);
  191. /* Give the overlay scaler a chance to enable
  192. if it's on this pipe */
  193. /* psb_intel_crtc_dpms_video(crtc, true); TODO */
  194. break;
  195. case DRM_MODE_DPMS_OFF:
  196. /* Give the overlay scaler a chance to disable
  197. * if it's on this pipe */
  198. /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
  199. /* Disable the VGA plane that we never use */
  200. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  201. /* Disable display plane */
  202. temp = REG_READ(dspcntr_reg);
  203. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  204. REG_WRITE(dspcntr_reg,
  205. temp & ~DISPLAY_PLANE_ENABLE);
  206. /* Flush the plane changes */
  207. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  208. REG_READ(dspbase_reg);
  209. }
  210. /* Next, disable display pipes */
  211. temp = REG_READ(pipeconf_reg);
  212. if ((temp & PIPEACONF_ENABLE) != 0) {
  213. REG_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  214. REG_READ(pipeconf_reg);
  215. }
  216. /* Wait for for the pipe disable to take effect. */
  217. psb_intel_wait_for_vblank(dev);
  218. temp = REG_READ(dpll_reg);
  219. if ((temp & DPLL_VCO_ENABLE) != 0) {
  220. REG_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  221. REG_READ(dpll_reg);
  222. }
  223. /* Wait for the clocks to turn off. */
  224. udelay(150);
  225. break;
  226. }
  227. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  228. /*Set FIFO Watermarks*/
  229. REG_WRITE(DSPARB, 0x3FFF);
  230. REG_WRITE(DSPFW1, 0x3F88080A);
  231. REG_WRITE(DSPFW2, 0x0b060808);
  232. REG_WRITE(DSPFW3, 0x0);
  233. REG_WRITE(DSPFW4, 0x08030404);
  234. REG_WRITE(DSPFW5, 0x04040404);
  235. REG_WRITE(DSPFW6, 0x78);
  236. REG_WRITE(0x70400, REG_READ(0x70400) | 0x4000);
  237. /* Must write Bit 14 of the Chicken Bit Register */
  238. gma_power_end(dev);
  239. }
  240. /**
  241. * Return the pipe currently connected to the panel fitter,
  242. * or -1 if the panel fitter is not present or not in use
  243. */
  244. static int oaktrail_panel_fitter_pipe(struct drm_device *dev)
  245. {
  246. u32 pfit_control;
  247. pfit_control = REG_READ(PFIT_CONTROL);
  248. /* See if the panel fitter is in use */
  249. if ((pfit_control & PFIT_ENABLE) == 0)
  250. return -1;
  251. return (pfit_control >> 29) & 3;
  252. }
  253. static int oaktrail_crtc_mode_set(struct drm_crtc *crtc,
  254. struct drm_display_mode *mode,
  255. struct drm_display_mode *adjusted_mode,
  256. int x, int y,
  257. struct drm_framebuffer *old_fb)
  258. {
  259. struct drm_device *dev = crtc->dev;
  260. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  261. struct drm_psb_private *dev_priv = dev->dev_private;
  262. int pipe = psb_intel_crtc->pipe;
  263. int fp_reg = (pipe == 0) ? MRST_FPA0 : FPB0;
  264. int dpll_reg = (pipe == 0) ? MRST_DPLL_A : DPLL_B;
  265. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  266. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  267. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  268. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  269. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  270. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  271. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  272. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  273. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  274. int refclk = 0;
  275. struct oaktrail_clock_t clock;
  276. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  277. bool ok, is_sdvo = false;
  278. bool is_crt = false, is_lvds = false, is_tv = false;
  279. bool is_mipi = false;
  280. struct drm_mode_config *mode_config = &dev->mode_config;
  281. struct psb_intel_encoder *psb_intel_encoder = NULL;
  282. uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN;
  283. struct drm_connector *connector;
  284. if (!gma_power_begin(dev, true))
  285. return 0;
  286. memcpy(&psb_intel_crtc->saved_mode,
  287. mode,
  288. sizeof(struct drm_display_mode));
  289. memcpy(&psb_intel_crtc->saved_adjusted_mode,
  290. adjusted_mode,
  291. sizeof(struct drm_display_mode));
  292. list_for_each_entry(connector, &mode_config->connector_list, head) {
  293. if (!connector->encoder || connector->encoder->crtc != crtc)
  294. continue;
  295. psb_intel_encoder = psb_intel_attached_encoder(connector);
  296. switch (psb_intel_encoder->type) {
  297. case INTEL_OUTPUT_LVDS:
  298. is_lvds = true;
  299. break;
  300. case INTEL_OUTPUT_SDVO:
  301. is_sdvo = true;
  302. break;
  303. case INTEL_OUTPUT_TVOUT:
  304. is_tv = true;
  305. break;
  306. case INTEL_OUTPUT_ANALOG:
  307. is_crt = true;
  308. break;
  309. case INTEL_OUTPUT_MIPI:
  310. is_mipi = true;
  311. break;
  312. }
  313. }
  314. /* Disable the VGA plane that we never use */
  315. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  316. /* Disable the panel fitter if it was on our pipe */
  317. if (oaktrail_panel_fitter_pipe(dev) == pipe)
  318. REG_WRITE(PFIT_CONTROL, 0);
  319. REG_WRITE(pipesrc_reg,
  320. ((mode->crtc_hdisplay - 1) << 16) |
  321. (mode->crtc_vdisplay - 1));
  322. if (psb_intel_encoder)
  323. drm_connector_property_get_value(connector,
  324. dev->mode_config.scaling_mode_property, &scalingType);
  325. if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
  326. /* Moorestown doesn't have register support for centering so
  327. * we need to mess with the h/vblank and h/vsync start and
  328. * ends to get centering */
  329. int offsetX = 0, offsetY = 0;
  330. offsetX = (adjusted_mode->crtc_hdisplay -
  331. mode->crtc_hdisplay) / 2;
  332. offsetY = (adjusted_mode->crtc_vdisplay -
  333. mode->crtc_vdisplay) / 2;
  334. REG_WRITE(htot_reg, (mode->crtc_hdisplay - 1) |
  335. ((adjusted_mode->crtc_htotal - 1) << 16));
  336. REG_WRITE(vtot_reg, (mode->crtc_vdisplay - 1) |
  337. ((adjusted_mode->crtc_vtotal - 1) << 16));
  338. REG_WRITE(hblank_reg,
  339. (adjusted_mode->crtc_hblank_start - offsetX - 1) |
  340. ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16));
  341. REG_WRITE(hsync_reg,
  342. (adjusted_mode->crtc_hsync_start - offsetX - 1) |
  343. ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16));
  344. REG_WRITE(vblank_reg,
  345. (adjusted_mode->crtc_vblank_start - offsetY - 1) |
  346. ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16));
  347. REG_WRITE(vsync_reg,
  348. (adjusted_mode->crtc_vsync_start - offsetY - 1) |
  349. ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16));
  350. } else {
  351. REG_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  352. ((adjusted_mode->crtc_htotal - 1) << 16));
  353. REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  354. ((adjusted_mode->crtc_vtotal - 1) << 16));
  355. REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  356. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  357. REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  358. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  359. REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  360. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  361. REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  362. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  363. }
  364. /* Flush the plane changes */
  365. {
  366. struct drm_crtc_helper_funcs *crtc_funcs =
  367. crtc->helper_private;
  368. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  369. }
  370. /* setup pipeconf */
  371. pipeconf = REG_READ(pipeconf_reg);
  372. /* Set up the display plane register */
  373. dspcntr = REG_READ(dspcntr_reg);
  374. dspcntr |= DISPPLANE_GAMMA_ENABLE;
  375. if (pipe == 0)
  376. dspcntr |= DISPPLANE_SEL_PIPE_A;
  377. else
  378. dspcntr |= DISPPLANE_SEL_PIPE_B;
  379. dev_priv->dspcntr = dspcntr |= DISPLAY_PLANE_ENABLE;
  380. dev_priv->pipeconf = pipeconf |= PIPEACONF_ENABLE;
  381. if (is_mipi)
  382. goto oaktrail_crtc_mode_set_exit;
  383. refclk = dev_priv->core_freq * 1000;
  384. dpll = 0; /*BIT16 = 0 for 100MHz reference */
  385. ok = mrstFindBestPLL(crtc, adjusted_mode->clock, refclk, &clock);
  386. if (!ok) {
  387. dev_dbg(dev->dev, "mrstFindBestPLL fail in oaktrail_crtc_mode_set.\n");
  388. } else {
  389. dev_dbg(dev->dev, "oaktrail_crtc_mode_set pixel clock = %d,"
  390. "m = %x, p1 = %x.\n", clock.dot, clock.m,
  391. clock.p1);
  392. }
  393. fp = oaktrail_m_converts[(clock.m - MRST_M_MIN)] << 8;
  394. dpll |= DPLL_VGA_MODE_DIS;
  395. dpll |= DPLL_VCO_ENABLE;
  396. if (is_lvds)
  397. dpll |= DPLLA_MODE_LVDS;
  398. else
  399. dpll |= DPLLB_MODE_DAC_SERIAL;
  400. if (is_sdvo) {
  401. int sdvo_pixel_multiply =
  402. adjusted_mode->clock / mode->clock;
  403. dpll |= DPLL_DVO_HIGH_SPEED;
  404. dpll |=
  405. (sdvo_pixel_multiply -
  406. 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  407. }
  408. /* compute bitmask from p1 value */
  409. dpll |= (1 << (clock.p1 - 2)) << 17;
  410. dpll |= DPLL_VCO_ENABLE;
  411. mrstPrintPll("chosen", &clock);
  412. if (dpll & DPLL_VCO_ENABLE) {
  413. REG_WRITE(fp_reg, fp);
  414. REG_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  415. REG_READ(dpll_reg);
  416. /* Check the DPLLA lock bit PIPEACONF[29] */
  417. udelay(150);
  418. }
  419. REG_WRITE(fp_reg, fp);
  420. REG_WRITE(dpll_reg, dpll);
  421. REG_READ(dpll_reg);
  422. /* Wait for the clocks to stabilize. */
  423. udelay(150);
  424. /* write it again -- the BIOS does, after all */
  425. REG_WRITE(dpll_reg, dpll);
  426. REG_READ(dpll_reg);
  427. /* Wait for the clocks to stabilize. */
  428. udelay(150);
  429. REG_WRITE(pipeconf_reg, pipeconf);
  430. REG_READ(pipeconf_reg);
  431. psb_intel_wait_for_vblank(dev);
  432. REG_WRITE(dspcntr_reg, dspcntr);
  433. psb_intel_wait_for_vblank(dev);
  434. oaktrail_crtc_mode_set_exit:
  435. gma_power_end(dev);
  436. return 0;
  437. }
  438. static bool oaktrail_crtc_mode_fixup(struct drm_crtc *crtc,
  439. struct drm_display_mode *mode,
  440. struct drm_display_mode *adjusted_mode)
  441. {
  442. return true;
  443. }
  444. int oaktrail_pipe_set_base(struct drm_crtc *crtc,
  445. int x, int y, struct drm_framebuffer *old_fb)
  446. {
  447. struct drm_device *dev = crtc->dev;
  448. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  449. struct psb_framebuffer *psbfb = to_psb_fb(crtc->fb);
  450. int pipe = psb_intel_crtc->pipe;
  451. unsigned long start, offset;
  452. int dspbase = (pipe == 0 ? DSPALINOFF : DSPBBASE);
  453. int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF);
  454. int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE;
  455. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  456. u32 dspcntr;
  457. int ret = 0;
  458. /* no fb bound */
  459. if (!crtc->fb) {
  460. dev_dbg(dev->dev, "No FB bound\n");
  461. return 0;
  462. }
  463. if (!gma_power_begin(dev, true))
  464. return 0;
  465. start = psbfb->gtt->offset;
  466. offset = y * crtc->fb->pitches[0] + x * (crtc->fb->bits_per_pixel / 8);
  467. REG_WRITE(dspstride, crtc->fb->pitches[0]);
  468. dspcntr = REG_READ(dspcntr_reg);
  469. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  470. switch (crtc->fb->bits_per_pixel) {
  471. case 8:
  472. dspcntr |= DISPPLANE_8BPP;
  473. break;
  474. case 16:
  475. if (crtc->fb->depth == 15)
  476. dspcntr |= DISPPLANE_15_16BPP;
  477. else
  478. dspcntr |= DISPPLANE_16BPP;
  479. break;
  480. case 24:
  481. case 32:
  482. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  483. break;
  484. default:
  485. dev_err(dev->dev, "Unknown color depth\n");
  486. ret = -EINVAL;
  487. goto pipe_set_base_exit;
  488. }
  489. REG_WRITE(dspcntr_reg, dspcntr);
  490. REG_WRITE(dspbase, offset);
  491. REG_READ(dspbase);
  492. REG_WRITE(dspsurf, start);
  493. REG_READ(dspsurf);
  494. pipe_set_base_exit:
  495. gma_power_end(dev);
  496. return ret;
  497. }
  498. static void oaktrail_crtc_prepare(struct drm_crtc *crtc)
  499. {
  500. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  501. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  502. }
  503. static void oaktrail_crtc_commit(struct drm_crtc *crtc)
  504. {
  505. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  506. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  507. }
  508. const struct drm_crtc_helper_funcs oaktrail_helper_funcs = {
  509. .dpms = oaktrail_crtc_dpms,
  510. .mode_fixup = oaktrail_crtc_mode_fixup,
  511. .mode_set = oaktrail_crtc_mode_set,
  512. .mode_set_base = oaktrail_pipe_set_base,
  513. .prepare = oaktrail_crtc_prepare,
  514. .commit = oaktrail_crtc_commit,
  515. };