mdfld_intel_display.c 31 KB

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