mdfld_intel_display.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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) == 1)
  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. if (!connector)
  648. continue;
  649. encoder = connector->encoder;
  650. if (!encoder)
  651. continue;
  652. if (encoder->crtc != crtc)
  653. continue;
  654. gma_encoder = gma_attached_encoder(connector);
  655. switch (gma_encoder->type) {
  656. case INTEL_OUTPUT_MIPI:
  657. is_mipi = true;
  658. break;
  659. case INTEL_OUTPUT_MIPI2:
  660. is_mipi2 = true;
  661. break;
  662. case INTEL_OUTPUT_HDMI:
  663. is_hdmi = true;
  664. break;
  665. }
  666. }
  667. /* Disable the VGA plane that we never use */
  668. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  669. /* Disable the panel fitter if it was on our pipe */
  670. if (psb_intel_panel_fitter_pipe(dev) == pipe)
  671. REG_WRITE(PFIT_CONTROL, 0);
  672. /* pipesrc and dspsize control the size that is scaled from,
  673. * which should always be the user's requested size.
  674. */
  675. if (pipe == 1) {
  676. /* FIXME: To make HDMI display with 864x480 (TPO), 480x864
  677. * (PYR) or 480x854 (TMD), set the sprite width/height and
  678. * souce image size registers with the adjusted mode for
  679. * pipe B.
  680. */
  681. /*
  682. * The defined sprite rectangle must always be completely
  683. * contained within the displayable area of the screen image
  684. * (frame buffer).
  685. */
  686. REG_WRITE(map->size, ((min(mode->crtc_vdisplay, adjusted_mode->crtc_vdisplay) - 1) << 16)
  687. | (min(mode->crtc_hdisplay, adjusted_mode->crtc_hdisplay) - 1));
  688. /* Set the CRTC with encoder mode. */
  689. REG_WRITE(map->src, ((mode->crtc_hdisplay - 1) << 16)
  690. | (mode->crtc_vdisplay - 1));
  691. } else {
  692. REG_WRITE(map->size,
  693. ((mode->crtc_vdisplay - 1) << 16) |
  694. (mode->crtc_hdisplay - 1));
  695. REG_WRITE(map->src,
  696. ((mode->crtc_hdisplay - 1) << 16) |
  697. (mode->crtc_vdisplay - 1));
  698. }
  699. REG_WRITE(map->pos, 0);
  700. if (gma_encoder)
  701. drm_object_property_get_value(&connector->base,
  702. dev->mode_config.scaling_mode_property, &scalingType);
  703. if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
  704. /* Medfield doesn't have register support for centering so we
  705. * need to mess with the h/vblank and h/vsync start and ends
  706. * to get centering
  707. */
  708. int offsetX = 0, offsetY = 0;
  709. offsetX = (adjusted_mode->crtc_hdisplay -
  710. mode->crtc_hdisplay) / 2;
  711. offsetY = (adjusted_mode->crtc_vdisplay -
  712. mode->crtc_vdisplay) / 2;
  713. REG_WRITE(map->htotal, (mode->crtc_hdisplay - 1) |
  714. ((adjusted_mode->crtc_htotal - 1) << 16));
  715. REG_WRITE(map->vtotal, (mode->crtc_vdisplay - 1) |
  716. ((adjusted_mode->crtc_vtotal - 1) << 16));
  717. REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start -
  718. offsetX - 1) |
  719. ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16));
  720. REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start -
  721. offsetX - 1) |
  722. ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16));
  723. REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start -
  724. offsetY - 1) |
  725. ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16));
  726. REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start -
  727. offsetY - 1) |
  728. ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16));
  729. } else {
  730. REG_WRITE(map->htotal, (adjusted_mode->crtc_hdisplay - 1) |
  731. ((adjusted_mode->crtc_htotal - 1) << 16));
  732. REG_WRITE(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) |
  733. ((adjusted_mode->crtc_vtotal - 1) << 16));
  734. REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start - 1) |
  735. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  736. REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start - 1) |
  737. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  738. REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start - 1) |
  739. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  740. REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start - 1) |
  741. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  742. }
  743. /* Flush the plane changes */
  744. {
  745. const struct drm_crtc_helper_funcs *crtc_funcs =
  746. crtc->helper_private;
  747. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  748. }
  749. /* setup pipeconf */
  750. dev_priv->pipeconf[pipe] = PIPEACONF_ENABLE; /* FIXME_JLIU7 REG_READ(pipeconf_reg); */
  751. /* Set up the display plane register */
  752. dev_priv->dspcntr[pipe] = REG_READ(map->cntr);
  753. dev_priv->dspcntr[pipe] |= pipe << DISPPLANE_SEL_PIPE_POS;
  754. dev_priv->dspcntr[pipe] |= DISPLAY_PLANE_ENABLE;
  755. if (is_mipi2)
  756. goto mrst_crtc_mode_set_exit;
  757. clk = adjusted_mode->clock;
  758. if (is_hdmi) {
  759. if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19)) {
  760. refclk = 19200;
  761. if (is_mipi || is_mipi2)
  762. clk_n = 1, clk_p2 = 8;
  763. else if (is_hdmi)
  764. clk_n = 1, clk_p2 = 10;
  765. } else if (ksel == KSEL_BYPASS_25) {
  766. refclk = 25000;
  767. if (is_mipi || is_mipi2)
  768. clk_n = 1, clk_p2 = 8;
  769. else if (is_hdmi)
  770. clk_n = 1, clk_p2 = 10;
  771. } else if ((ksel == KSEL_BYPASS_83_100) &&
  772. dev_priv->core_freq == 166) {
  773. refclk = 83000;
  774. if (is_mipi || is_mipi2)
  775. clk_n = 4, clk_p2 = 8;
  776. else if (is_hdmi)
  777. clk_n = 4, clk_p2 = 10;
  778. } else if ((ksel == KSEL_BYPASS_83_100) &&
  779. (dev_priv->core_freq == 100 ||
  780. dev_priv->core_freq == 200)) {
  781. refclk = 100000;
  782. if (is_mipi || is_mipi2)
  783. clk_n = 4, clk_p2 = 8;
  784. else if (is_hdmi)
  785. clk_n = 4, clk_p2 = 10;
  786. }
  787. if (is_mipi)
  788. clk_byte = dev_priv->bpp / 8;
  789. else if (is_mipi2)
  790. clk_byte = dev_priv->bpp2 / 8;
  791. clk_tmp = clk * clk_n * clk_p2 * clk_byte;
  792. dev_dbg(dev->dev, "clk = %d, clk_n = %d, clk_p2 = %d.\n",
  793. clk, clk_n, clk_p2);
  794. dev_dbg(dev->dev, "adjusted_mode->clock = %d, clk_tmp = %d.\n",
  795. adjusted_mode->clock, clk_tmp);
  796. ok = mdfldFindBestPLL(crtc, clk_tmp, refclk, &clock);
  797. if (!ok) {
  798. DRM_ERROR
  799. ("mdfldFindBestPLL fail in mdfld_crtc_mode_set.\n");
  800. } else {
  801. m_conv = mdfld_m_converts[(clock.m - MDFLD_M_MIN)];
  802. dev_dbg(dev->dev, "dot clock = %d,"
  803. "m = %d, p1 = %d, m_conv = %d.\n",
  804. clock.dot, clock.m,
  805. clock.p1, m_conv);
  806. }
  807. dpll = REG_READ(map->dpll);
  808. if (dpll & DPLL_VCO_ENABLE) {
  809. dpll &= ~DPLL_VCO_ENABLE;
  810. REG_WRITE(map->dpll, dpll);
  811. REG_READ(map->dpll);
  812. /* FIXME jliu7 check the DPLL lock bit PIPEACONF[29] */
  813. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  814. udelay(500);
  815. /* reset M1, N1 & P1 */
  816. REG_WRITE(map->fp0, 0);
  817. dpll &= ~MDFLD_P1_MASK;
  818. REG_WRITE(map->dpll, dpll);
  819. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  820. udelay(500);
  821. }
  822. /* When ungating power of DPLL, needs to wait 0.5us before
  823. * enable the VCO */
  824. if (dpll & MDFLD_PWR_GATE_EN) {
  825. dpll &= ~MDFLD_PWR_GATE_EN;
  826. REG_WRITE(map->dpll, dpll);
  827. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  828. udelay(500);
  829. }
  830. dpll = 0;
  831. #if 0 /* FIXME revisit later */
  832. if (ksel == KSEL_CRYSTAL_19 || ksel == KSEL_BYPASS_19 ||
  833. ksel == KSEL_BYPASS_25)
  834. dpll &= ~MDFLD_INPUT_REF_SEL;
  835. else if (ksel == KSEL_BYPASS_83_100)
  836. dpll |= MDFLD_INPUT_REF_SEL;
  837. #endif /* FIXME revisit later */
  838. if (is_hdmi)
  839. dpll |= MDFLD_VCO_SEL;
  840. fp = (clk_n / 2) << 16;
  841. fp |= m_conv;
  842. /* compute bitmask from p1 value */
  843. dpll |= (1 << (clock.p1 - 2)) << 17;
  844. #if 0 /* 1080p30 & 720p */
  845. dpll = 0x00050000;
  846. fp = 0x000001be;
  847. #endif
  848. #if 0 /* 480p */
  849. dpll = 0x02010000;
  850. fp = 0x000000d2;
  851. #endif
  852. } else {
  853. #if 0 /*DBI_TPO_480x864*/
  854. dpll = 0x00020000;
  855. fp = 0x00000156;
  856. #endif /* DBI_TPO_480x864 */ /* get from spec. */
  857. dpll = 0x00800000;
  858. fp = 0x000000c1;
  859. }
  860. REG_WRITE(map->fp0, fp);
  861. REG_WRITE(map->dpll, dpll);
  862. /* FIXME_MDFLD PO - change 500 to 1 after PO */
  863. udelay(500);
  864. dpll |= DPLL_VCO_ENABLE;
  865. REG_WRITE(map->dpll, dpll);
  866. REG_READ(map->dpll);
  867. /* wait for DSI PLL to lock */
  868. while (timeout < 20000 &&
  869. !(REG_READ(map->conf) & PIPECONF_DSIPLL_LOCK)) {
  870. udelay(150);
  871. timeout++;
  872. }
  873. if (is_mipi)
  874. goto mrst_crtc_mode_set_exit;
  875. dev_dbg(dev->dev, "is_mipi = 0x%x\n", is_mipi);
  876. REG_WRITE(map->conf, dev_priv->pipeconf[pipe]);
  877. REG_READ(map->conf);
  878. /* Wait for for the pipe enable to take effect. */
  879. REG_WRITE(map->cntr, dev_priv->dspcntr[pipe]);
  880. gma_wait_for_vblank(dev);
  881. mrst_crtc_mode_set_exit:
  882. gma_power_end(dev);
  883. return 0;
  884. }
  885. const struct drm_crtc_helper_funcs mdfld_helper_funcs = {
  886. .dpms = mdfld_crtc_dpms,
  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. };