oaktrail_crtc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. int i;
  202. int need_aux = gma_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ? 1 : 0;
  203. if (gma_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) {
  204. oaktrail_crtc_hdmi_dpms(crtc, mode);
  205. return;
  206. }
  207. if (!gma_power_begin(dev, true))
  208. return;
  209. /* XXX: When our outputs are all unaware of DPMS modes other than off
  210. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  211. */
  212. switch (mode) {
  213. case DRM_MODE_DPMS_ON:
  214. case DRM_MODE_DPMS_STANDBY:
  215. case DRM_MODE_DPMS_SUSPEND:
  216. for (i = 0; i <= need_aux; i++) {
  217. /* Enable the DPLL */
  218. temp = REG_READ_WITH_AUX(map->dpll, i);
  219. if ((temp & DPLL_VCO_ENABLE) == 0) {
  220. REG_WRITE_WITH_AUX(map->dpll, temp, i);
  221. REG_READ_WITH_AUX(map->dpll, i);
  222. /* Wait for the clocks to stabilize. */
  223. udelay(150);
  224. REG_WRITE_WITH_AUX(map->dpll,
  225. temp | DPLL_VCO_ENABLE, i);
  226. REG_READ_WITH_AUX(map->dpll, i);
  227. /* Wait for the clocks to stabilize. */
  228. udelay(150);
  229. REG_WRITE_WITH_AUX(map->dpll,
  230. temp | DPLL_VCO_ENABLE, i);
  231. REG_READ_WITH_AUX(map->dpll, i);
  232. /* Wait for the clocks to stabilize. */
  233. udelay(150);
  234. }
  235. /* Enable the pipe */
  236. temp = REG_READ_WITH_AUX(map->conf, i);
  237. if ((temp & PIPEACONF_ENABLE) == 0) {
  238. REG_WRITE_WITH_AUX(map->conf,
  239. temp | PIPEACONF_ENABLE, i);
  240. }
  241. /* Enable the plane */
  242. temp = REG_READ_WITH_AUX(map->cntr, i);
  243. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  244. REG_WRITE_WITH_AUX(map->cntr,
  245. temp | DISPLAY_PLANE_ENABLE,
  246. i);
  247. /* Flush the plane changes */
  248. REG_WRITE_WITH_AUX(map->base,
  249. REG_READ_WITH_AUX(map->base, i), i);
  250. }
  251. }
  252. gma_crtc_load_lut(crtc);
  253. /* Give the overlay scaler a chance to enable
  254. if it's on this pipe */
  255. /* psb_intel_crtc_dpms_video(crtc, true); TODO */
  256. break;
  257. case DRM_MODE_DPMS_OFF:
  258. /* Give the overlay scaler a chance to disable
  259. * if it's on this pipe */
  260. /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
  261. for (i = 0; i <= need_aux; i++) {
  262. /* Disable the VGA plane that we never use */
  263. REG_WRITE_WITH_AUX(VGACNTRL, VGA_DISP_DISABLE, i);
  264. /* Disable display plane */
  265. temp = REG_READ_WITH_AUX(map->cntr, i);
  266. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  267. REG_WRITE_WITH_AUX(map->cntr,
  268. temp & ~DISPLAY_PLANE_ENABLE, i);
  269. /* Flush the plane changes */
  270. REG_WRITE_WITH_AUX(map->base,
  271. REG_READ(map->base), i);
  272. REG_READ_WITH_AUX(map->base, i);
  273. }
  274. /* Next, disable display pipes */
  275. temp = REG_READ_WITH_AUX(map->conf, i);
  276. if ((temp & PIPEACONF_ENABLE) != 0) {
  277. REG_WRITE_WITH_AUX(map->conf,
  278. temp & ~PIPEACONF_ENABLE, i);
  279. REG_READ_WITH_AUX(map->conf, i);
  280. }
  281. /* Wait for for the pipe disable to take effect. */
  282. gma_wait_for_vblank(dev);
  283. temp = REG_READ_WITH_AUX(map->dpll, i);
  284. if ((temp & DPLL_VCO_ENABLE) != 0) {
  285. REG_WRITE_WITH_AUX(map->dpll,
  286. temp & ~DPLL_VCO_ENABLE, i);
  287. REG_READ_WITH_AUX(map->dpll, i);
  288. }
  289. /* Wait for the clocks to turn off. */
  290. udelay(150);
  291. }
  292. break;
  293. }
  294. /* Set FIFO Watermarks (values taken from EMGD) */
  295. REG_WRITE(DSPARB, 0x3f80);
  296. REG_WRITE(DSPFW1, 0x3f8f0404);
  297. REG_WRITE(DSPFW2, 0x04040f04);
  298. REG_WRITE(DSPFW3, 0x0);
  299. REG_WRITE(DSPFW4, 0x04040404);
  300. REG_WRITE(DSPFW5, 0x04040404);
  301. REG_WRITE(DSPFW6, 0x78);
  302. REG_WRITE(DSPCHICKENBIT, REG_READ(DSPCHICKENBIT) | 0xc040);
  303. gma_power_end(dev);
  304. }
  305. /**
  306. * Return the pipe currently connected to the panel fitter,
  307. * or -1 if the panel fitter is not present or not in use
  308. */
  309. static int oaktrail_panel_fitter_pipe(struct drm_device *dev)
  310. {
  311. u32 pfit_control;
  312. pfit_control = REG_READ(PFIT_CONTROL);
  313. /* See if the panel fitter is in use */
  314. if ((pfit_control & PFIT_ENABLE) == 0)
  315. return -1;
  316. return (pfit_control >> 29) & 3;
  317. }
  318. static int oaktrail_crtc_mode_set(struct drm_crtc *crtc,
  319. struct drm_display_mode *mode,
  320. struct drm_display_mode *adjusted_mode,
  321. int x, int y,
  322. struct drm_framebuffer *old_fb)
  323. {
  324. struct drm_device *dev = crtc->dev;
  325. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  326. struct drm_psb_private *dev_priv = dev->dev_private;
  327. int pipe = gma_crtc->pipe;
  328. const struct psb_offset *map = &dev_priv->regmap[pipe];
  329. int refclk = 0;
  330. struct gma_clock_t clock;
  331. const struct gma_limit_t *limit;
  332. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  333. bool ok, is_sdvo = false;
  334. bool is_lvds = false;
  335. bool is_mipi = false;
  336. struct drm_mode_config *mode_config = &dev->mode_config;
  337. struct gma_encoder *gma_encoder = NULL;
  338. uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN;
  339. struct drm_connector *connector;
  340. int i;
  341. int need_aux = gma_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ? 1 : 0;
  342. if (gma_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  343. return oaktrail_crtc_hdmi_mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
  344. if (!gma_power_begin(dev, true))
  345. return 0;
  346. memcpy(&gma_crtc->saved_mode,
  347. mode,
  348. sizeof(struct drm_display_mode));
  349. memcpy(&gma_crtc->saved_adjusted_mode,
  350. adjusted_mode,
  351. sizeof(struct drm_display_mode));
  352. list_for_each_entry(connector, &mode_config->connector_list, head) {
  353. if (!connector->encoder || connector->encoder->crtc != crtc)
  354. continue;
  355. gma_encoder = gma_attached_encoder(connector);
  356. switch (gma_encoder->type) {
  357. case INTEL_OUTPUT_LVDS:
  358. is_lvds = true;
  359. break;
  360. case INTEL_OUTPUT_SDVO:
  361. is_sdvo = true;
  362. break;
  363. case INTEL_OUTPUT_MIPI:
  364. is_mipi = true;
  365. break;
  366. }
  367. }
  368. /* Disable the VGA plane that we never use */
  369. for (i = 0; i <= need_aux; i++)
  370. REG_WRITE_WITH_AUX(VGACNTRL, VGA_DISP_DISABLE, i);
  371. /* Disable the panel fitter if it was on our pipe */
  372. if (oaktrail_panel_fitter_pipe(dev) == pipe)
  373. REG_WRITE(PFIT_CONTROL, 0);
  374. for (i = 0; i <= need_aux; i++) {
  375. REG_WRITE_WITH_AUX(map->src, ((mode->crtc_hdisplay - 1) << 16) |
  376. (mode->crtc_vdisplay - 1), i);
  377. }
  378. if (gma_encoder)
  379. drm_object_property_get_value(&connector->base,
  380. dev->mode_config.scaling_mode_property, &scalingType);
  381. if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
  382. /* Moorestown doesn't have register support for centering so
  383. * we need to mess with the h/vblank and h/vsync start and
  384. * ends to get centering */
  385. int offsetX = 0, offsetY = 0;
  386. offsetX = (adjusted_mode->crtc_hdisplay -
  387. mode->crtc_hdisplay) / 2;
  388. offsetY = (adjusted_mode->crtc_vdisplay -
  389. mode->crtc_vdisplay) / 2;
  390. for (i = 0; i <= need_aux; i++) {
  391. REG_WRITE_WITH_AUX(map->htotal, (mode->crtc_hdisplay - 1) |
  392. ((adjusted_mode->crtc_htotal - 1) << 16), i);
  393. REG_WRITE_WITH_AUX(map->vtotal, (mode->crtc_vdisplay - 1) |
  394. ((adjusted_mode->crtc_vtotal - 1) << 16), i);
  395. REG_WRITE_WITH_AUX(map->hblank,
  396. (adjusted_mode->crtc_hblank_start - offsetX - 1) |
  397. ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16), i);
  398. REG_WRITE_WITH_AUX(map->hsync,
  399. (adjusted_mode->crtc_hsync_start - offsetX - 1) |
  400. ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16), i);
  401. REG_WRITE_WITH_AUX(map->vblank,
  402. (adjusted_mode->crtc_vblank_start - offsetY - 1) |
  403. ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16), i);
  404. REG_WRITE_WITH_AUX(map->vsync,
  405. (adjusted_mode->crtc_vsync_start - offsetY - 1) |
  406. ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16), i);
  407. }
  408. } else {
  409. for (i = 0; i <= need_aux; i++) {
  410. REG_WRITE_WITH_AUX(map->htotal, (adjusted_mode->crtc_hdisplay - 1) |
  411. ((adjusted_mode->crtc_htotal - 1) << 16), i);
  412. REG_WRITE_WITH_AUX(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) |
  413. ((adjusted_mode->crtc_vtotal - 1) << 16), i);
  414. REG_WRITE_WITH_AUX(map->hblank, (adjusted_mode->crtc_hblank_start - 1) |
  415. ((adjusted_mode->crtc_hblank_end - 1) << 16), i);
  416. REG_WRITE_WITH_AUX(map->hsync, (adjusted_mode->crtc_hsync_start - 1) |
  417. ((adjusted_mode->crtc_hsync_end - 1) << 16), i);
  418. REG_WRITE_WITH_AUX(map->vblank, (adjusted_mode->crtc_vblank_start - 1) |
  419. ((adjusted_mode->crtc_vblank_end - 1) << 16), i);
  420. REG_WRITE_WITH_AUX(map->vsync, (adjusted_mode->crtc_vsync_start - 1) |
  421. ((adjusted_mode->crtc_vsync_end - 1) << 16), i);
  422. }
  423. }
  424. /* Flush the plane changes */
  425. {
  426. const struct drm_crtc_helper_funcs *crtc_funcs =
  427. crtc->helper_private;
  428. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  429. }
  430. /* setup pipeconf */
  431. pipeconf = REG_READ(map->conf);
  432. /* Set up the display plane register */
  433. dspcntr = REG_READ(map->cntr);
  434. dspcntr |= DISPPLANE_GAMMA_ENABLE;
  435. if (pipe == 0)
  436. dspcntr |= DISPPLANE_SEL_PIPE_A;
  437. else
  438. dspcntr |= DISPPLANE_SEL_PIPE_B;
  439. if (is_mipi)
  440. goto oaktrail_crtc_mode_set_exit;
  441. dpll = 0; /*BIT16 = 0 for 100MHz reference */
  442. refclk = is_sdvo ? 96000 : dev_priv->core_freq * 1000;
  443. limit = mrst_limit(crtc, refclk);
  444. ok = limit->find_pll(limit, crtc, adjusted_mode->clock,
  445. refclk, &clock);
  446. if (is_sdvo) {
  447. /* Convert calculated values to register values */
  448. clock.p1 = (1L << (clock.p1 - 1));
  449. clock.m -= 2;
  450. clock.n = (1L << (clock.n - 1));
  451. }
  452. if (!ok)
  453. DRM_ERROR("Failed to find proper PLL settings");
  454. mrst_print_pll(&clock);
  455. if (is_sdvo)
  456. fp = clock.n << 16 | clock.m;
  457. else
  458. fp = oaktrail_m_converts[(clock.m - MRST_M_MIN)] << 8;
  459. dpll |= DPLL_VGA_MODE_DIS;
  460. dpll |= DPLL_VCO_ENABLE;
  461. if (is_lvds)
  462. dpll |= DPLLA_MODE_LVDS;
  463. else
  464. dpll |= DPLLB_MODE_DAC_SERIAL;
  465. if (is_sdvo) {
  466. int sdvo_pixel_multiply =
  467. adjusted_mode->clock / mode->clock;
  468. dpll |= DPLL_DVO_HIGH_SPEED;
  469. dpll |=
  470. (sdvo_pixel_multiply -
  471. 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  472. }
  473. /* compute bitmask from p1 value */
  474. if (is_sdvo)
  475. dpll |= clock.p1 << 16; // dpll |= (1 << (clock.p1 - 1)) << 16;
  476. else
  477. dpll |= (1 << (clock.p1 - 2)) << 17;
  478. dpll |= DPLL_VCO_ENABLE;
  479. if (dpll & DPLL_VCO_ENABLE) {
  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 & ~DPLL_VCO_ENABLE, i);
  483. REG_READ_WITH_AUX(map->dpll, i);
  484. /* Check the DPLLA lock bit PIPEACONF[29] */
  485. udelay(150);
  486. }
  487. }
  488. for (i = 0; i <= need_aux; i++) {
  489. REG_WRITE_WITH_AUX(map->fp0, fp, i);
  490. REG_WRITE_WITH_AUX(map->dpll, dpll, i);
  491. REG_READ_WITH_AUX(map->dpll, i);
  492. /* Wait for the clocks to stabilize. */
  493. udelay(150);
  494. /* write it again -- the BIOS does, after all */
  495. REG_WRITE_WITH_AUX(map->dpll, dpll, i);
  496. REG_READ_WITH_AUX(map->dpll, i);
  497. /* Wait for the clocks to stabilize. */
  498. udelay(150);
  499. REG_WRITE_WITH_AUX(map->conf, pipeconf, i);
  500. REG_READ_WITH_AUX(map->conf, i);
  501. gma_wait_for_vblank(dev);
  502. REG_WRITE_WITH_AUX(map->cntr, dspcntr, i);
  503. gma_wait_for_vblank(dev);
  504. }
  505. oaktrail_crtc_mode_set_exit:
  506. gma_power_end(dev);
  507. return 0;
  508. }
  509. static int oaktrail_pipe_set_base(struct drm_crtc *crtc,
  510. int x, int y, struct drm_framebuffer *old_fb)
  511. {
  512. struct drm_device *dev = crtc->dev;
  513. struct drm_psb_private *dev_priv = dev->dev_private;
  514. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  515. struct psb_framebuffer *psbfb = to_psb_fb(crtc->primary->fb);
  516. int pipe = gma_crtc->pipe;
  517. const struct psb_offset *map = &dev_priv->regmap[pipe];
  518. unsigned long start, offset;
  519. u32 dspcntr;
  520. int ret = 0;
  521. /* no fb bound */
  522. if (!crtc->primary->fb) {
  523. dev_dbg(dev->dev, "No FB bound\n");
  524. return 0;
  525. }
  526. if (!gma_power_begin(dev, true))
  527. return 0;
  528. start = psbfb->gtt->offset;
  529. offset = y * crtc->primary->fb->pitches[0] + x * (crtc->primary->fb->bits_per_pixel / 8);
  530. REG_WRITE(map->stride, crtc->primary->fb->pitches[0]);
  531. dspcntr = REG_READ(map->cntr);
  532. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  533. switch (crtc->primary->fb->bits_per_pixel) {
  534. case 8:
  535. dspcntr |= DISPPLANE_8BPP;
  536. break;
  537. case 16:
  538. if (crtc->primary->fb->depth == 15)
  539. dspcntr |= DISPPLANE_15_16BPP;
  540. else
  541. dspcntr |= DISPPLANE_16BPP;
  542. break;
  543. case 24:
  544. case 32:
  545. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  546. break;
  547. default:
  548. dev_err(dev->dev, "Unknown color depth\n");
  549. ret = -EINVAL;
  550. goto pipe_set_base_exit;
  551. }
  552. REG_WRITE(map->cntr, dspcntr);
  553. REG_WRITE(map->base, offset);
  554. REG_READ(map->base);
  555. REG_WRITE(map->surf, start);
  556. REG_READ(map->surf);
  557. pipe_set_base_exit:
  558. gma_power_end(dev);
  559. return ret;
  560. }
  561. const struct drm_crtc_helper_funcs oaktrail_helper_funcs = {
  562. .dpms = oaktrail_crtc_dpms,
  563. .mode_fixup = gma_crtc_mode_fixup,
  564. .mode_set = oaktrail_crtc_mode_set,
  565. .mode_set_base = oaktrail_pipe_set_base,
  566. .prepare = gma_crtc_prepare,
  567. .commit = gma_crtc_commit,
  568. };
  569. /* Not used yet */
  570. const struct gma_clock_funcs mrst_clock_funcs = {
  571. .clock = mrst_lvds_clock,
  572. .limit = mrst_limit,
  573. .pll_is_valid = gma_pll_is_valid,
  574. };