mdfld_intel_display.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. /*
  2. * Copyright © 2006-2007 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. * Authors:
  18. * Eric Anholt <eric@anholt.net>
  19. */
  20. #include <linux/i2c.h>
  21. #include <linux/pm_runtime.h>
  22. #include <drm/drmP.h>
  23. #include "psb_intel_reg.h"
  24. #include "psb_intel_display.h"
  25. #include "framebuffer.h"
  26. #include "mdfld_output.h"
  27. #include "mdfld_dsi_output.h"
  28. /* Hardcoded currently */
  29. static int ksel = KSEL_CRYSTAL_19;
  30. struct psb_intel_range_t {
  31. int min, max;
  32. };
  33. struct mrst_limit_t {
  34. struct psb_intel_range_t dot, m, p1;
  35. };
  36. struct mrst_clock_t {
  37. /* derived values */
  38. int dot;
  39. int m;
  40. int p1;
  41. };
  42. #define COUNT_MAX 0x10000000
  43. void mdfldWaitForPipeDisable(struct drm_device *dev, int pipe)
  44. {
  45. int count, temp;
  46. u32 pipeconf_reg = PIPEACONF;
  47. switch (pipe) {
  48. case 0:
  49. break;
  50. case 1:
  51. pipeconf_reg = PIPEBCONF;
  52. break;
  53. case 2:
  54. pipeconf_reg = PIPECCONF;
  55. break;
  56. default:
  57. DRM_ERROR("Illegal Pipe Number.\n");
  58. return;
  59. }
  60. /* FIXME JLIU7_PO */
  61. psb_intel_wait_for_vblank(dev);
  62. return;
  63. /* Wait for for the pipe disable to take effect. */
  64. for (count = 0; count < COUNT_MAX; count++) {
  65. temp = REG_READ(pipeconf_reg);
  66. if ((temp & PIPEACONF_PIPE_STATE) == 0)
  67. break;
  68. }
  69. }
  70. void mdfldWaitForPipeEnable(struct drm_device *dev, int pipe)
  71. {
  72. int count, temp;
  73. u32 pipeconf_reg = PIPEACONF;
  74. switch (pipe) {
  75. case 0:
  76. break;
  77. case 1:
  78. pipeconf_reg = PIPEBCONF;
  79. break;
  80. case 2:
  81. pipeconf_reg = PIPECCONF;
  82. break;
  83. default:
  84. DRM_ERROR("Illegal Pipe Number.\n");
  85. return;
  86. }
  87. /* FIXME JLIU7_PO */
  88. psb_intel_wait_for_vblank(dev);
  89. return;
  90. /* Wait for for the pipe enable to take effect. */
  91. for (count = 0; count < COUNT_MAX; count++) {
  92. temp = REG_READ(pipeconf_reg);
  93. if ((temp & PIPEACONF_PIPE_STATE) == 1)
  94. break;
  95. }
  96. }
  97. static void psb_intel_crtc_prepare(struct drm_crtc *crtc)
  98. {
  99. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  100. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  101. }
  102. static void psb_intel_crtc_commit(struct drm_crtc *crtc)
  103. {
  104. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  105. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  106. }
  107. static bool psb_intel_crtc_mode_fixup(struct drm_crtc *crtc,
  108. struct drm_display_mode *mode,
  109. struct drm_display_mode *adjusted_mode)
  110. {
  111. return true;
  112. }
  113. /**
  114. * Return the pipe currently connected to the panel fitter,
  115. * or -1 if the panel fitter is not present or not in use
  116. */
  117. static int psb_intel_panel_fitter_pipe(struct drm_device *dev)
  118. {
  119. u32 pfit_control;
  120. pfit_control = REG_READ(PFIT_CONTROL);
  121. /* See if the panel fitter is in use */
  122. if ((pfit_control & PFIT_ENABLE) == 0)
  123. return -1;
  124. /* 965 can place panel fitter on either pipe */
  125. return (pfit_control >> 29) & 0x3;
  126. }
  127. static struct drm_device globle_dev;
  128. void mdfld__intel_plane_set_alpha(int enable)
  129. {
  130. struct drm_device *dev = &globle_dev;
  131. int dspcntr_reg = DSPACNTR;
  132. u32 dspcntr;
  133. dspcntr = REG_READ(dspcntr_reg);
  134. if (enable) {
  135. dspcntr &= ~DISPPLANE_32BPP_NO_ALPHA;
  136. dspcntr |= DISPPLANE_32BPP;
  137. } else {
  138. dspcntr &= ~DISPPLANE_32BPP;
  139. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  140. }
  141. REG_WRITE(dspcntr_reg, dspcntr);
  142. }
  143. static int check_fb(struct drm_framebuffer *fb)
  144. {
  145. if (!fb)
  146. return 0;
  147. switch (fb->bits_per_pixel) {
  148. case 8:
  149. case 16:
  150. case 24:
  151. case 32:
  152. return 0;
  153. default:
  154. DRM_ERROR("Unknown color depth\n");
  155. return -EINVAL;
  156. }
  157. }
  158. static int mdfld__intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  159. struct drm_framebuffer *old_fb)
  160. {
  161. struct drm_device *dev = crtc->dev;
  162. /* struct drm_i915_master_private *master_priv; */
  163. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  164. struct psb_framebuffer *psbfb = to_psb_fb(crtc->fb);
  165. int pipe = psb_intel_crtc->pipe;
  166. unsigned long start, offset;
  167. int dsplinoff = DSPALINOFF;
  168. int dspsurf = DSPASURF;
  169. int dspstride = DSPASTRIDE;
  170. int dspcntr_reg = DSPACNTR;
  171. u32 dspcntr;
  172. int ret;
  173. memcpy(&globle_dev, dev, sizeof(struct drm_device));
  174. dev_dbg(dev->dev, "pipe = 0x%x.\n", pipe);
  175. /* no fb bound */
  176. if (!crtc->fb) {
  177. dev_dbg(dev->dev, "No FB bound\n");
  178. return 0;
  179. }
  180. ret = check_fb(crtc->fb);
  181. if (ret)
  182. return ret;
  183. switch (pipe) {
  184. case 0:
  185. dsplinoff = DSPALINOFF;
  186. break;
  187. case 1:
  188. dsplinoff = DSPBLINOFF;
  189. dspsurf = DSPBSURF;
  190. dspstride = DSPBSTRIDE;
  191. dspcntr_reg = DSPBCNTR;
  192. break;
  193. case 2:
  194. dsplinoff = DSPCLINOFF;
  195. dspsurf = DSPCSURF;
  196. dspstride = DSPCSTRIDE;
  197. dspcntr_reg = DSPCCNTR;
  198. break;
  199. default:
  200. DRM_ERROR("Illegal Pipe Number.\n");
  201. return -EINVAL;
  202. }
  203. if (!gma_power_begin(dev, true))
  204. return 0;
  205. start = psbfb->gtt->offset;
  206. offset = y * crtc->fb->pitches[0] + x * (crtc->fb->bits_per_pixel / 8);
  207. REG_WRITE(dspstride, crtc->fb->pitches[0]);
  208. dspcntr = REG_READ(dspcntr_reg);
  209. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  210. switch (crtc->fb->bits_per_pixel) {
  211. case 8:
  212. dspcntr |= DISPPLANE_8BPP;
  213. break;
  214. case 16:
  215. if (crtc->fb->depth == 15)
  216. dspcntr |= DISPPLANE_15_16BPP;
  217. else
  218. dspcntr |= DISPPLANE_16BPP;
  219. break;
  220. case 24:
  221. case 32:
  222. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  223. break;
  224. }
  225. REG_WRITE(dspcntr_reg, dspcntr);
  226. dev_dbg(dev->dev, "Writing base %08lX %08lX %d %d\n",
  227. start, offset, x, y);
  228. REG_WRITE(dsplinoff, offset);
  229. REG_READ(dsplinoff);
  230. REG_WRITE(dspsurf, start);
  231. REG_READ(dspsurf);
  232. gma_power_end(dev);
  233. return 0;
  234. }
  235. /*
  236. * Disable the pipe, plane and pll.
  237. *
  238. */
  239. void mdfld_disable_crtc(struct drm_device *dev, int pipe)
  240. {
  241. int dpll_reg = MRST_DPLL_A;
  242. int dspcntr_reg = DSPACNTR;
  243. int dspbase_reg = MRST_DSPABASE;
  244. int pipeconf_reg = PIPEACONF;
  245. u32 temp;
  246. dev_dbg(dev->dev, "pipe = %d\n", pipe);
  247. switch (pipe) {
  248. case 0:
  249. break;
  250. case 1:
  251. dpll_reg = MDFLD_DPLL_B;
  252. dspcntr_reg = DSPBCNTR;
  253. dspbase_reg = DSPBSURF;
  254. pipeconf_reg = PIPEBCONF;
  255. break;
  256. case 2:
  257. dpll_reg = MRST_DPLL_A;
  258. dspcntr_reg = DSPCCNTR;
  259. dspbase_reg = MDFLD_DSPCBASE;
  260. pipeconf_reg = PIPECCONF;
  261. break;
  262. default:
  263. DRM_ERROR("Illegal Pipe Number.\n");
  264. return;
  265. }
  266. if (pipe != 1)
  267. mdfld_dsi_gen_fifo_ready(dev, MIPI_GEN_FIFO_STAT_REG(pipe),
  268. HS_CTRL_FIFO_EMPTY | HS_DATA_FIFO_EMPTY);
  269. /* Disable display plane */
  270. temp = REG_READ(dspcntr_reg);
  271. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  272. REG_WRITE(dspcntr_reg,
  273. temp & ~DISPLAY_PLANE_ENABLE);
  274. /* Flush the plane changes */
  275. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  276. REG_READ(dspbase_reg);
  277. }
  278. /* FIXME_JLIU7 MDFLD_PO revisit */
  279. /* Next, disable display pipes */
  280. temp = REG_READ(pipeconf_reg);
  281. if ((temp & PIPEACONF_ENABLE) != 0) {
  282. temp &= ~PIPEACONF_ENABLE;
  283. temp |= PIPECONF_PLANE_OFF | PIPECONF_CURSOR_OFF;
  284. REG_WRITE(pipeconf_reg, temp);
  285. REG_READ(pipeconf_reg);
  286. /* Wait for for the pipe disable to take effect. */
  287. mdfldWaitForPipeDisable(dev, pipe);
  288. }
  289. temp = REG_READ(dpll_reg);
  290. if (temp & DPLL_VCO_ENABLE) {
  291. if ((pipe != 1 &&
  292. !((REG_READ(PIPEACONF) | REG_READ(PIPECCONF))
  293. & PIPEACONF_ENABLE)) || pipe == 1) {
  294. temp &= ~(DPLL_VCO_ENABLE);
  295. REG_WRITE(dpll_reg, temp);
  296. REG_READ(dpll_reg);
  297. /* Wait for the clocks to turn off. */
  298. /* FIXME_MDFLD PO may need more delay */
  299. udelay(500);
  300. if (!(temp & MDFLD_PWR_GATE_EN)) {
  301. /* gating power of DPLL */
  302. REG_WRITE(dpll_reg, temp | MDFLD_PWR_GATE_EN);
  303. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  304. udelay(5000);
  305. }
  306. }
  307. }
  308. }
  309. /**
  310. * Sets the power management mode of the pipe and plane.
  311. *
  312. * This code should probably grow support for turning the cursor off and back
  313. * on appropriately at the same time as we're turning the pipe off/on.
  314. */
  315. static void mdfld_crtc_dpms(struct drm_crtc *crtc, int mode)
  316. {
  317. struct drm_device *dev = crtc->dev;
  318. struct drm_psb_private *dev_priv = dev->dev_private;
  319. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  320. int pipe = psb_intel_crtc->pipe;
  321. int dpll_reg = MRST_DPLL_A;
  322. int dspcntr_reg = DSPACNTR;
  323. int dspbase_reg = MRST_DSPABASE;
  324. int pipeconf_reg = PIPEACONF;
  325. u32 pipestat_reg = PIPEASTAT;
  326. u32 pipeconf = dev_priv->pipeconf[pipe];
  327. u32 temp;
  328. bool enabled;
  329. int timeout = 0;
  330. dev_dbg(dev->dev, "mode = %d, pipe = %d\n", mode, pipe);
  331. /* FIXME_JLIU7 MDFLD_PO replaced w/ the following function */
  332. /* mdfld_dbi_dpms (struct drm_device *dev, int pipe, bool enabled) */
  333. switch (pipe) {
  334. case 0:
  335. break;
  336. case 1:
  337. dpll_reg = DPLL_B;
  338. dspcntr_reg = DSPBCNTR;
  339. dspbase_reg = MRST_DSPBBASE;
  340. pipeconf_reg = PIPEBCONF;
  341. dpll_reg = MDFLD_DPLL_B;
  342. break;
  343. case 2:
  344. dpll_reg = MRST_DPLL_A;
  345. dspcntr_reg = DSPCCNTR;
  346. dspbase_reg = MDFLD_DSPCBASE;
  347. pipeconf_reg = PIPECCONF;
  348. pipestat_reg = PIPECSTAT;
  349. break;
  350. default:
  351. DRM_ERROR("Illegal Pipe Number.\n");
  352. return;
  353. }
  354. if (!gma_power_begin(dev, true))
  355. return;
  356. /* XXX: When our outputs are all unaware of DPMS modes other than off
  357. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  358. */
  359. switch (mode) {
  360. case DRM_MODE_DPMS_ON:
  361. case DRM_MODE_DPMS_STANDBY:
  362. case DRM_MODE_DPMS_SUSPEND:
  363. /* Enable the DPLL */
  364. temp = REG_READ(dpll_reg);
  365. if ((temp & DPLL_VCO_ENABLE) == 0) {
  366. /* When ungating power of DPLL, needs to wait 0.5us
  367. before enable the VCO */
  368. if (temp & MDFLD_PWR_GATE_EN) {
  369. temp &= ~MDFLD_PWR_GATE_EN;
  370. REG_WRITE(dpll_reg, temp);
  371. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  372. udelay(500);
  373. }
  374. REG_WRITE(dpll_reg, temp);
  375. REG_READ(dpll_reg);
  376. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  377. udelay(500);
  378. REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  379. REG_READ(dpll_reg);
  380. /**
  381. * wait for DSI PLL to lock
  382. * NOTE: only need to poll status of pipe 0 and pipe 1,
  383. * since both MIPI pipes share the same PLL.
  384. */
  385. while ((pipe != 2) && (timeout < 20000) &&
  386. !(REG_READ(pipeconf_reg) & PIPECONF_DSIPLL_LOCK)) {
  387. udelay(150);
  388. timeout++;
  389. }
  390. }
  391. /* Enable the plane */
  392. temp = REG_READ(dspcntr_reg);
  393. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  394. REG_WRITE(dspcntr_reg,
  395. temp | DISPLAY_PLANE_ENABLE);
  396. /* Flush the plane changes */
  397. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  398. }
  399. /* Enable the pipe */
  400. temp = REG_READ(pipeconf_reg);
  401. if ((temp & PIPEACONF_ENABLE) == 0) {
  402. REG_WRITE(pipeconf_reg, pipeconf);
  403. /* Wait for for the pipe enable to take effect. */
  404. mdfldWaitForPipeEnable(dev, pipe);
  405. }
  406. /*workaround for sighting 3741701 Random X blank display*/
  407. /*perform w/a in video mode only on pipe A or C*/
  408. if (pipe == 0 || pipe == 2) {
  409. REG_WRITE(pipestat_reg, REG_READ(pipestat_reg));
  410. msleep(100);
  411. if (PIPE_VBLANK_STATUS & REG_READ(pipestat_reg))
  412. dev_dbg(dev->dev, "OK");
  413. else {
  414. dev_dbg(dev->dev, "STUCK!!!!");
  415. /*shutdown controller*/
  416. temp = REG_READ(dspcntr_reg);
  417. REG_WRITE(dspcntr_reg,
  418. temp & ~DISPLAY_PLANE_ENABLE);
  419. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  420. /*mdfld_dsi_dpi_shut_down(dev, pipe);*/
  421. REG_WRITE(0xb048, 1);
  422. msleep(100);
  423. temp = REG_READ(pipeconf_reg);
  424. temp &= ~PIPEACONF_ENABLE;
  425. REG_WRITE(pipeconf_reg, temp);
  426. msleep(100); /*wait for pipe disable*/
  427. REG_WRITE(MIPI_DEVICE_READY_REG(pipe), 0);
  428. msleep(100);
  429. REG_WRITE(0xb004, REG_READ(0xb004));
  430. /* try to bring the controller back up again*/
  431. REG_WRITE(MIPI_DEVICE_READY_REG(pipe), 1);
  432. temp = REG_READ(dspcntr_reg);
  433. REG_WRITE(dspcntr_reg,
  434. temp | DISPLAY_PLANE_ENABLE);
  435. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  436. /*mdfld_dsi_dpi_turn_on(dev, pipe);*/
  437. REG_WRITE(0xb048, 2);
  438. msleep(100);
  439. temp = REG_READ(pipeconf_reg);
  440. temp |= PIPEACONF_ENABLE;
  441. REG_WRITE(pipeconf_reg, temp);
  442. }
  443. }
  444. psb_intel_crtc_load_lut(crtc);
  445. /* Give the overlay scaler a chance to enable
  446. if it's on this pipe */
  447. /* psb_intel_crtc_dpms_video(crtc, true); TODO */
  448. break;
  449. case DRM_MODE_DPMS_OFF:
  450. /* Give the overlay scaler a chance to disable
  451. * if it's on this pipe */
  452. /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
  453. if (pipe != 1)
  454. mdfld_dsi_gen_fifo_ready(dev,
  455. MIPI_GEN_FIFO_STAT_REG(pipe),
  456. HS_CTRL_FIFO_EMPTY | HS_DATA_FIFO_EMPTY);
  457. /* Disable the VGA plane that we never use */
  458. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  459. /* Disable display plane */
  460. temp = REG_READ(dspcntr_reg);
  461. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  462. REG_WRITE(dspcntr_reg,
  463. temp & ~DISPLAY_PLANE_ENABLE);
  464. /* Flush the plane changes */
  465. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  466. REG_READ(dspbase_reg);
  467. }
  468. /* Next, disable display pipes */
  469. temp = REG_READ(pipeconf_reg);
  470. if ((temp & PIPEACONF_ENABLE) != 0) {
  471. temp &= ~PIPEACONF_ENABLE;
  472. temp |= PIPECONF_PLANE_OFF | PIPECONF_CURSOR_OFF;
  473. REG_WRITE(pipeconf_reg, temp);
  474. REG_READ(pipeconf_reg);
  475. /* Wait for for the pipe disable to take effect. */
  476. mdfldWaitForPipeDisable(dev, pipe);
  477. }
  478. temp = REG_READ(dpll_reg);
  479. if (temp & DPLL_VCO_ENABLE) {
  480. if ((pipe != 1 && !((REG_READ(PIPEACONF)
  481. | REG_READ(PIPECCONF)) & PIPEACONF_ENABLE))
  482. || pipe == 1) {
  483. temp &= ~(DPLL_VCO_ENABLE);
  484. REG_WRITE(dpll_reg, temp);
  485. REG_READ(dpll_reg);
  486. /* Wait for the clocks to turn off. */
  487. /* FIXME_MDFLD PO may need more delay */
  488. udelay(500);
  489. }
  490. }
  491. break;
  492. }
  493. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  494. gma_power_end(dev);
  495. }
  496. #define MDFLD_LIMT_DPLL_19 0
  497. #define MDFLD_LIMT_DPLL_25 1
  498. #define MDFLD_LIMT_DPLL_83 2
  499. #define MDFLD_LIMT_DPLL_100 3
  500. #define MDFLD_LIMT_DSIPLL_19 4
  501. #define MDFLD_LIMT_DSIPLL_25 5
  502. #define MDFLD_LIMT_DSIPLL_83 6
  503. #define MDFLD_LIMT_DSIPLL_100 7
  504. #define MDFLD_DOT_MIN 19750
  505. #define MDFLD_DOT_MAX 120000
  506. #define MDFLD_DPLL_M_MIN_19 113
  507. #define MDFLD_DPLL_M_MAX_19 155
  508. #define MDFLD_DPLL_P1_MIN_19 2
  509. #define MDFLD_DPLL_P1_MAX_19 10
  510. #define MDFLD_DPLL_M_MIN_25 101
  511. #define MDFLD_DPLL_M_MAX_25 130
  512. #define MDFLD_DPLL_P1_MIN_25 2
  513. #define MDFLD_DPLL_P1_MAX_25 10
  514. #define MDFLD_DPLL_M_MIN_83 64
  515. #define MDFLD_DPLL_M_MAX_83 64
  516. #define MDFLD_DPLL_P1_MIN_83 2
  517. #define MDFLD_DPLL_P1_MAX_83 2
  518. #define MDFLD_DPLL_M_MIN_100 64
  519. #define MDFLD_DPLL_M_MAX_100 64
  520. #define MDFLD_DPLL_P1_MIN_100 2
  521. #define MDFLD_DPLL_P1_MAX_100 2
  522. #define MDFLD_DSIPLL_M_MIN_19 131
  523. #define MDFLD_DSIPLL_M_MAX_19 175
  524. #define MDFLD_DSIPLL_P1_MIN_19 3
  525. #define MDFLD_DSIPLL_P1_MAX_19 8
  526. #define MDFLD_DSIPLL_M_MIN_25 97
  527. #define MDFLD_DSIPLL_M_MAX_25 140
  528. #define MDFLD_DSIPLL_P1_MIN_25 3
  529. #define MDFLD_DSIPLL_P1_MAX_25 9
  530. #define MDFLD_DSIPLL_M_MIN_83 33
  531. #define MDFLD_DSIPLL_M_MAX_83 92
  532. #define MDFLD_DSIPLL_P1_MIN_83 2
  533. #define MDFLD_DSIPLL_P1_MAX_83 3
  534. #define MDFLD_DSIPLL_M_MIN_100 97
  535. #define MDFLD_DSIPLL_M_MAX_100 140
  536. #define MDFLD_DSIPLL_P1_MIN_100 3
  537. #define MDFLD_DSIPLL_P1_MAX_100 9
  538. static const struct mrst_limit_t mdfld_limits[] = {
  539. { /* MDFLD_LIMT_DPLL_19 */
  540. .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
  541. .m = {.min = MDFLD_DPLL_M_MIN_19, .max = MDFLD_DPLL_M_MAX_19},
  542. .p1 = {.min = MDFLD_DPLL_P1_MIN_19, .max = MDFLD_DPLL_P1_MAX_19},
  543. },
  544. { /* MDFLD_LIMT_DPLL_25 */
  545. .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
  546. .m = {.min = MDFLD_DPLL_M_MIN_25, .max = MDFLD_DPLL_M_MAX_25},
  547. .p1 = {.min = MDFLD_DPLL_P1_MIN_25, .max = MDFLD_DPLL_P1_MAX_25},
  548. },
  549. { /* MDFLD_LIMT_DPLL_83 */
  550. .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
  551. .m = {.min = MDFLD_DPLL_M_MIN_83, .max = MDFLD_DPLL_M_MAX_83},
  552. .p1 = {.min = MDFLD_DPLL_P1_MIN_83, .max = MDFLD_DPLL_P1_MAX_83},
  553. },
  554. { /* MDFLD_LIMT_DPLL_100 */
  555. .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
  556. .m = {.min = MDFLD_DPLL_M_MIN_100, .max = MDFLD_DPLL_M_MAX_100},
  557. .p1 = {.min = MDFLD_DPLL_P1_MIN_100, .max = MDFLD_DPLL_P1_MAX_100},
  558. },
  559. { /* MDFLD_LIMT_DSIPLL_19 */
  560. .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
  561. .m = {.min = MDFLD_DSIPLL_M_MIN_19, .max = MDFLD_DSIPLL_M_MAX_19},
  562. .p1 = {.min = MDFLD_DSIPLL_P1_MIN_19, .max = MDFLD_DSIPLL_P1_MAX_19},
  563. },
  564. { /* MDFLD_LIMT_DSIPLL_25 */
  565. .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
  566. .m = {.min = MDFLD_DSIPLL_M_MIN_25, .max = MDFLD_DSIPLL_M_MAX_25},
  567. .p1 = {.min = MDFLD_DSIPLL_P1_MIN_25, .max = MDFLD_DSIPLL_P1_MAX_25},
  568. },
  569. { /* MDFLD_LIMT_DSIPLL_83 */
  570. .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
  571. .m = {.min = MDFLD_DSIPLL_M_MIN_83, .max = MDFLD_DSIPLL_M_MAX_83},
  572. .p1 = {.min = MDFLD_DSIPLL_P1_MIN_83, .max = MDFLD_DSIPLL_P1_MAX_83},
  573. },
  574. { /* MDFLD_LIMT_DSIPLL_100 */
  575. .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
  576. .m = {.min = MDFLD_DSIPLL_M_MIN_100, .max = MDFLD_DSIPLL_M_MAX_100},
  577. .p1 = {.min = MDFLD_DSIPLL_P1_MIN_100, .max = MDFLD_DSIPLL_P1_MAX_100},
  578. },
  579. };
  580. #define MDFLD_M_MIN 21
  581. #define MDFLD_M_MAX 180
  582. static const u32 mdfld_m_converts[] = {
  583. /* M configuration table from 9-bit LFSR table */
  584. 224, 368, 440, 220, 366, 439, 219, 365, 182, 347, /* 21 - 30 */
  585. 173, 342, 171, 85, 298, 149, 74, 37, 18, 265, /* 31 - 40 */
  586. 388, 194, 353, 432, 216, 108, 310, 155, 333, 166, /* 41 - 50 */
  587. 83, 41, 276, 138, 325, 162, 337, 168, 340, 170, /* 51 - 60 */
  588. 341, 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 61 - 70 */
  589. 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */
  590. 106, 53, 282, 397, 354, 227, 113, 56, 284, 142, /* 81 - 90 */
  591. 71, 35, 273, 136, 324, 418, 465, 488, 500, 506, /* 91 - 100 */
  592. 253, 126, 63, 287, 399, 455, 483, 241, 376, 444, /* 101 - 110 */
  593. 478, 495, 503, 251, 381, 446, 479, 239, 375, 443, /* 111 - 120 */
  594. 477, 238, 119, 315, 157, 78, 295, 147, 329, 420, /* 121 - 130 */
  595. 210, 105, 308, 154, 77, 38, 275, 137, 68, 290, /* 131 - 140 */
  596. 145, 328, 164, 82, 297, 404, 458, 485, 498, 249, /* 141 - 150 */
  597. 380, 190, 351, 431, 471, 235, 117, 314, 413, 206, /* 151 - 160 */
  598. 103, 51, 25, 12, 262, 387, 193, 96, 48, 280, /* 161 - 170 */
  599. 396, 198, 99, 305, 152, 76, 294, 403, 457, 228, /* 171 - 180 */
  600. };
  601. static const struct mrst_limit_t *mdfld_limit(struct drm_crtc *crtc)
  602. {
  603. const struct mrst_limit_t *limit = NULL;
  604. struct drm_device *dev = crtc->dev;
  605. struct drm_psb_private *dev_priv = dev->dev_private;
  606. if (psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_MIPI)
  607. || psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_MIPI2)) {
  608. if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19))
  609. limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_19];
  610. else if (ksel == KSEL_BYPASS_25)
  611. limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_25];
  612. else if ((ksel == KSEL_BYPASS_83_100) &&
  613. (dev_priv->core_freq == 166))
  614. limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_83];
  615. else if ((ksel == KSEL_BYPASS_83_100) &&
  616. (dev_priv->core_freq == 100 ||
  617. dev_priv->core_freq == 200))
  618. limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_100];
  619. } else if (psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) {
  620. if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19))
  621. limit = &mdfld_limits[MDFLD_LIMT_DPLL_19];
  622. else if (ksel == KSEL_BYPASS_25)
  623. limit = &mdfld_limits[MDFLD_LIMT_DPLL_25];
  624. else if ((ksel == KSEL_BYPASS_83_100) &&
  625. (dev_priv->core_freq == 166))
  626. limit = &mdfld_limits[MDFLD_LIMT_DPLL_83];
  627. else if ((ksel == KSEL_BYPASS_83_100) &&
  628. (dev_priv->core_freq == 100 ||
  629. dev_priv->core_freq == 200))
  630. limit = &mdfld_limits[MDFLD_LIMT_DPLL_100];
  631. } else {
  632. limit = NULL;
  633. dev_dbg(dev->dev, "mdfld_limit Wrong display type.\n");
  634. }
  635. return limit;
  636. }
  637. /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
  638. static void mdfld_clock(int refclk, struct mrst_clock_t *clock)
  639. {
  640. clock->dot = (refclk * clock->m) / clock->p1;
  641. }
  642. /**
  643. * Returns a set of divisors for the desired target clock with the given refclk,
  644. * or FALSE. Divisor values are the actual divisors for
  645. */
  646. static bool
  647. mdfldFindBestPLL(struct drm_crtc *crtc, int target, int refclk,
  648. struct mrst_clock_t *best_clock)
  649. {
  650. struct mrst_clock_t clock;
  651. const struct mrst_limit_t *limit = mdfld_limit(crtc);
  652. int err = target;
  653. memset(best_clock, 0, sizeof(*best_clock));
  654. for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) {
  655. for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max;
  656. clock.p1++) {
  657. int this_err;
  658. mdfld_clock(refclk, &clock);
  659. this_err = abs(clock.dot - target);
  660. if (this_err < err) {
  661. *best_clock = clock;
  662. err = this_err;
  663. }
  664. }
  665. }
  666. return err != target;
  667. }
  668. static int mdfld_crtc_mode_set(struct drm_crtc *crtc,
  669. struct drm_display_mode *mode,
  670. struct drm_display_mode *adjusted_mode,
  671. int x, int y,
  672. struct drm_framebuffer *old_fb)
  673. {
  674. struct drm_device *dev = crtc->dev;
  675. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  676. struct drm_psb_private *dev_priv = dev->dev_private;
  677. int pipe = psb_intel_crtc->pipe;
  678. int fp_reg = MRST_FPA0;
  679. int dpll_reg = MRST_DPLL_A;
  680. int dspcntr_reg = DSPACNTR;
  681. int pipeconf_reg = PIPEACONF;
  682. int htot_reg = HTOTAL_A;
  683. int hblank_reg = HBLANK_A;
  684. int hsync_reg = HSYNC_A;
  685. int vtot_reg = VTOTAL_A;
  686. int vblank_reg = VBLANK_A;
  687. int vsync_reg = VSYNC_A;
  688. int dspsize_reg = DSPASIZE;
  689. int dsppos_reg = DSPAPOS;
  690. int pipesrc_reg = PIPEASRC;
  691. u32 *pipeconf = &dev_priv->pipeconf[pipe];
  692. u32 *dspcntr = &dev_priv->dspcntr[pipe];
  693. int refclk = 0;
  694. int clk_n = 0, clk_p2 = 0, clk_byte = 1, clk = 0, m_conv = 0,
  695. clk_tmp = 0;
  696. struct mrst_clock_t clock;
  697. bool ok;
  698. u32 dpll = 0, fp = 0;
  699. bool is_crt = false, is_lvds = false, is_tv = false;
  700. bool is_mipi = false, is_mipi2 = false, is_hdmi = false;
  701. struct drm_mode_config *mode_config = &dev->mode_config;
  702. struct psb_intel_encoder *psb_intel_encoder = NULL;
  703. uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN;
  704. struct drm_encoder *encoder;
  705. struct drm_connector *connector;
  706. int timeout = 0;
  707. int ret;
  708. dev_dbg(dev->dev, "pipe = 0x%x\n", pipe);
  709. #if 0
  710. if (pipe == 1) {
  711. if (!gma_power_begin(dev, true))
  712. return 0;
  713. android_hdmi_crtc_mode_set(crtc, mode, adjusted_mode,
  714. x, y, old_fb);
  715. goto mrst_crtc_mode_set_exit;
  716. }
  717. #endif
  718. switch (pipe) {
  719. case 0:
  720. break;
  721. case 1:
  722. fp_reg = FPB0;
  723. dpll_reg = DPLL_B;
  724. dspcntr_reg = DSPBCNTR;
  725. pipeconf_reg = PIPEBCONF;
  726. htot_reg = HTOTAL_B;
  727. hblank_reg = HBLANK_B;
  728. hsync_reg = HSYNC_B;
  729. vtot_reg = VTOTAL_B;
  730. vblank_reg = VBLANK_B;
  731. vsync_reg = VSYNC_B;
  732. dspsize_reg = DSPBSIZE;
  733. dsppos_reg = DSPBPOS;
  734. pipesrc_reg = PIPEBSRC;
  735. fp_reg = MDFLD_DPLL_DIV0;
  736. dpll_reg = MDFLD_DPLL_B;
  737. break;
  738. case 2:
  739. dpll_reg = MRST_DPLL_A;
  740. dspcntr_reg = DSPCCNTR;
  741. pipeconf_reg = PIPECCONF;
  742. htot_reg = HTOTAL_C;
  743. hblank_reg = HBLANK_C;
  744. hsync_reg = HSYNC_C;
  745. vtot_reg = VTOTAL_C;
  746. vblank_reg = VBLANK_C;
  747. vsync_reg = VSYNC_C;
  748. dspsize_reg = DSPCSIZE;
  749. dsppos_reg = DSPCPOS;
  750. pipesrc_reg = PIPECSRC;
  751. break;
  752. default:
  753. DRM_ERROR("Illegal Pipe Number.\n");
  754. return 0;
  755. }
  756. ret = check_fb(crtc->fb);
  757. if (ret)
  758. return ret;
  759. dev_dbg(dev->dev, "adjusted_hdisplay = %d\n",
  760. adjusted_mode->hdisplay);
  761. dev_dbg(dev->dev, "adjusted_vdisplay = %d\n",
  762. adjusted_mode->vdisplay);
  763. dev_dbg(dev->dev, "adjusted_hsync_start = %d\n",
  764. adjusted_mode->hsync_start);
  765. dev_dbg(dev->dev, "adjusted_hsync_end = %d\n",
  766. adjusted_mode->hsync_end);
  767. dev_dbg(dev->dev, "adjusted_htotal = %d\n",
  768. adjusted_mode->htotal);
  769. dev_dbg(dev->dev, "adjusted_vsync_start = %d\n",
  770. adjusted_mode->vsync_start);
  771. dev_dbg(dev->dev, "adjusted_vsync_end = %d\n",
  772. adjusted_mode->vsync_end);
  773. dev_dbg(dev->dev, "adjusted_vtotal = %d\n",
  774. adjusted_mode->vtotal);
  775. dev_dbg(dev->dev, "adjusted_clock = %d\n",
  776. adjusted_mode->clock);
  777. dev_dbg(dev->dev, "hdisplay = %d\n",
  778. mode->hdisplay);
  779. dev_dbg(dev->dev, "vdisplay = %d\n",
  780. mode->vdisplay);
  781. if (!gma_power_begin(dev, true))
  782. return 0;
  783. memcpy(&psb_intel_crtc->saved_mode, mode,
  784. sizeof(struct drm_display_mode));
  785. memcpy(&psb_intel_crtc->saved_adjusted_mode, adjusted_mode,
  786. sizeof(struct drm_display_mode));
  787. list_for_each_entry(connector, &mode_config->connector_list, head) {
  788. if (!connector)
  789. continue;
  790. encoder = connector->encoder;
  791. if (!encoder)
  792. continue;
  793. if (encoder->crtc != crtc)
  794. continue;
  795. psb_intel_encoder = psb_intel_attached_encoder(connector);
  796. switch (psb_intel_encoder->type) {
  797. case INTEL_OUTPUT_LVDS:
  798. is_lvds = true;
  799. break;
  800. case INTEL_OUTPUT_TVOUT:
  801. is_tv = true;
  802. break;
  803. case INTEL_OUTPUT_ANALOG:
  804. is_crt = true;
  805. break;
  806. case INTEL_OUTPUT_MIPI:
  807. is_mipi = true;
  808. break;
  809. case INTEL_OUTPUT_MIPI2:
  810. is_mipi2 = true;
  811. break;
  812. case INTEL_OUTPUT_HDMI:
  813. is_hdmi = true;
  814. break;
  815. }
  816. }
  817. /* Disable the VGA plane that we never use */
  818. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  819. /* Disable the panel fitter if it was on our pipe */
  820. if (psb_intel_panel_fitter_pipe(dev) == pipe)
  821. REG_WRITE(PFIT_CONTROL, 0);
  822. /* pipesrc and dspsize control the size that is scaled from,
  823. * which should always be the user's requested size.
  824. */
  825. if (pipe == 1) {
  826. /* FIXME: To make HDMI display with 864x480 (TPO), 480x864
  827. * (PYR) or 480x854 (TMD), set the sprite width/height and
  828. * souce image size registers with the adjusted mode for
  829. * pipe B.
  830. */
  831. /*
  832. * The defined sprite rectangle must always be completely
  833. * contained within the displayable area of the screen image
  834. * (frame buffer).
  835. */
  836. REG_WRITE(dspsize_reg, ((min(mode->crtc_vdisplay, adjusted_mode->crtc_vdisplay) - 1) << 16)
  837. | (min(mode->crtc_hdisplay, adjusted_mode->crtc_hdisplay) - 1));
  838. /* Set the CRTC with encoder mode. */
  839. REG_WRITE(pipesrc_reg, ((mode->crtc_hdisplay - 1) << 16)
  840. | (mode->crtc_vdisplay - 1));
  841. } else {
  842. REG_WRITE(dspsize_reg,
  843. ((mode->crtc_vdisplay - 1) << 16) |
  844. (mode->crtc_hdisplay - 1));
  845. REG_WRITE(pipesrc_reg,
  846. ((mode->crtc_hdisplay - 1) << 16) |
  847. (mode->crtc_vdisplay - 1));
  848. }
  849. REG_WRITE(dsppos_reg, 0);
  850. if (psb_intel_encoder)
  851. drm_connector_property_get_value(connector,
  852. dev->mode_config.scaling_mode_property, &scalingType);
  853. if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
  854. /* Medfield doesn't have register support for centering so we
  855. * need to mess with the h/vblank and h/vsync start and ends
  856. * to get centering
  857. */
  858. int offsetX = 0, offsetY = 0;
  859. offsetX = (adjusted_mode->crtc_hdisplay -
  860. mode->crtc_hdisplay) / 2;
  861. offsetY = (adjusted_mode->crtc_vdisplay -
  862. mode->crtc_vdisplay) / 2;
  863. REG_WRITE(htot_reg, (mode->crtc_hdisplay - 1) |
  864. ((adjusted_mode->crtc_htotal - 1) << 16));
  865. REG_WRITE(vtot_reg, (mode->crtc_vdisplay - 1) |
  866. ((adjusted_mode->crtc_vtotal - 1) << 16));
  867. REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start -
  868. offsetX - 1) |
  869. ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16));
  870. REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start -
  871. offsetX - 1) |
  872. ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16));
  873. REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start -
  874. offsetY - 1) |
  875. ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16));
  876. REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start -
  877. offsetY - 1) |
  878. ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16));
  879. } else {
  880. REG_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  881. ((adjusted_mode->crtc_htotal - 1) << 16));
  882. REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  883. ((adjusted_mode->crtc_vtotal - 1) << 16));
  884. REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  885. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  886. REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  887. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  888. REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  889. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  890. REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  891. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  892. }
  893. /* Flush the plane changes */
  894. {
  895. struct drm_crtc_helper_funcs *crtc_funcs =
  896. crtc->helper_private;
  897. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  898. }
  899. /* setup pipeconf */
  900. *pipeconf = PIPEACONF_ENABLE; /* FIXME_JLIU7 REG_READ(pipeconf_reg); */
  901. /* Set up the display plane register */
  902. *dspcntr = REG_READ(dspcntr_reg);
  903. *dspcntr |= pipe << DISPPLANE_SEL_PIPE_POS;
  904. *dspcntr |= DISPLAY_PLANE_ENABLE;
  905. if (is_mipi2)
  906. goto mrst_crtc_mode_set_exit;
  907. clk = adjusted_mode->clock;
  908. if (is_hdmi) {
  909. if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19)) {
  910. refclk = 19200;
  911. if (is_mipi || is_mipi2)
  912. clk_n = 1, clk_p2 = 8;
  913. else if (is_hdmi)
  914. clk_n = 1, clk_p2 = 10;
  915. } else if (ksel == KSEL_BYPASS_25) {
  916. refclk = 25000;
  917. if (is_mipi || is_mipi2)
  918. clk_n = 1, clk_p2 = 8;
  919. else if (is_hdmi)
  920. clk_n = 1, clk_p2 = 10;
  921. } else if ((ksel == KSEL_BYPASS_83_100) &&
  922. dev_priv->core_freq == 166) {
  923. refclk = 83000;
  924. if (is_mipi || is_mipi2)
  925. clk_n = 4, clk_p2 = 8;
  926. else if (is_hdmi)
  927. clk_n = 4, clk_p2 = 10;
  928. } else if ((ksel == KSEL_BYPASS_83_100) &&
  929. (dev_priv->core_freq == 100 ||
  930. dev_priv->core_freq == 200)) {
  931. refclk = 100000;
  932. if (is_mipi || is_mipi2)
  933. clk_n = 4, clk_p2 = 8;
  934. else if (is_hdmi)
  935. clk_n = 4, clk_p2 = 10;
  936. }
  937. if (is_mipi)
  938. clk_byte = dev_priv->bpp / 8;
  939. else if (is_mipi2)
  940. clk_byte = dev_priv->bpp2 / 8;
  941. clk_tmp = clk * clk_n * clk_p2 * clk_byte;
  942. dev_dbg(dev->dev, "clk = %d, clk_n = %d, clk_p2 = %d.\n",
  943. clk, clk_n, clk_p2);
  944. dev_dbg(dev->dev, "adjusted_mode->clock = %d, clk_tmp = %d.\n",
  945. adjusted_mode->clock, clk_tmp);
  946. ok = mdfldFindBestPLL(crtc, clk_tmp, refclk, &clock);
  947. if (!ok) {
  948. DRM_ERROR
  949. ("mdfldFindBestPLL fail in mdfld_crtc_mode_set.\n");
  950. } else {
  951. m_conv = mdfld_m_converts[(clock.m - MDFLD_M_MIN)];
  952. dev_dbg(dev->dev, "dot clock = %d,"
  953. "m = %d, p1 = %d, m_conv = %d.\n",
  954. clock.dot, clock.m,
  955. clock.p1, m_conv);
  956. }
  957. dpll = REG_READ(dpll_reg);
  958. if (dpll & DPLL_VCO_ENABLE) {
  959. dpll &= ~DPLL_VCO_ENABLE;
  960. REG_WRITE(dpll_reg, dpll);
  961. REG_READ(dpll_reg);
  962. /* FIXME jliu7 check the DPLL lock bit PIPEACONF[29] */
  963. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  964. udelay(500);
  965. /* reset M1, N1 & P1 */
  966. REG_WRITE(fp_reg, 0);
  967. dpll &= ~MDFLD_P1_MASK;
  968. REG_WRITE(dpll_reg, dpll);
  969. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  970. udelay(500);
  971. }
  972. /* When ungating power of DPLL, needs to wait 0.5us before
  973. * enable the VCO */
  974. if (dpll & MDFLD_PWR_GATE_EN) {
  975. dpll &= ~MDFLD_PWR_GATE_EN;
  976. REG_WRITE(dpll_reg, dpll);
  977. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  978. udelay(500);
  979. }
  980. dpll = 0;
  981. #if 0 /* FIXME revisit later */
  982. if (ksel == KSEL_CRYSTAL_19 || ksel == KSEL_BYPASS_19 ||
  983. ksel == KSEL_BYPASS_25)
  984. dpll &= ~MDFLD_INPUT_REF_SEL;
  985. else if (ksel == KSEL_BYPASS_83_100)
  986. dpll |= MDFLD_INPUT_REF_SEL;
  987. #endif /* FIXME revisit later */
  988. if (is_hdmi)
  989. dpll |= MDFLD_VCO_SEL;
  990. fp = (clk_n / 2) << 16;
  991. fp |= m_conv;
  992. /* compute bitmask from p1 value */
  993. dpll |= (1 << (clock.p1 - 2)) << 17;
  994. #if 0 /* 1080p30 & 720p */
  995. dpll = 0x00050000;
  996. fp = 0x000001be;
  997. #endif
  998. #if 0 /* 480p */
  999. dpll = 0x02010000;
  1000. fp = 0x000000d2;
  1001. #endif
  1002. } else {
  1003. #if 0 /*DBI_TPO_480x864*/
  1004. dpll = 0x00020000;
  1005. fp = 0x00000156;
  1006. #endif /* DBI_TPO_480x864 */ /* get from spec. */
  1007. dpll = 0x00800000;
  1008. fp = 0x000000c1;
  1009. }
  1010. REG_WRITE(fp_reg, fp);
  1011. REG_WRITE(dpll_reg, dpll);
  1012. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  1013. udelay(500);
  1014. dpll |= DPLL_VCO_ENABLE;
  1015. REG_WRITE(dpll_reg, dpll);
  1016. REG_READ(dpll_reg);
  1017. /* wait for DSI PLL to lock */
  1018. while (timeout < 20000 &&
  1019. !(REG_READ(pipeconf_reg) & PIPECONF_DSIPLL_LOCK)) {
  1020. udelay(150);
  1021. timeout++;
  1022. }
  1023. if (is_mipi)
  1024. goto mrst_crtc_mode_set_exit;
  1025. dev_dbg(dev->dev, "is_mipi = 0x%x\n", is_mipi);
  1026. REG_WRITE(pipeconf_reg, *pipeconf);
  1027. REG_READ(pipeconf_reg);
  1028. /* Wait for for the pipe enable to take effect. */
  1029. REG_WRITE(dspcntr_reg, *dspcntr);
  1030. psb_intel_wait_for_vblank(dev);
  1031. mrst_crtc_mode_set_exit:
  1032. gma_power_end(dev);
  1033. return 0;
  1034. }
  1035. const struct drm_crtc_helper_funcs mdfld_helper_funcs = {
  1036. .dpms = mdfld_crtc_dpms,
  1037. .mode_fixup = psb_intel_crtc_mode_fixup,
  1038. .mode_set = mdfld_crtc_mode_set,
  1039. .mode_set_base = mdfld__intel_pipe_set_base,
  1040. .prepare = psb_intel_crtc_prepare,
  1041. .commit = psb_intel_crtc_commit,
  1042. };