mdfld_intel_display.c 29 KB

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