mdfld_intel_display.c 28 KB

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