mdfld_intel_display.c 28 KB

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