psb_intel_display.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * Copyright © 2006-2011 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 <drm/drmP.h>
  22. #include "framebuffer.h"
  23. #include "psb_drv.h"
  24. #include "psb_intel_drv.h"
  25. #include "psb_intel_reg.h"
  26. #include "gma_display.h"
  27. #include "power.h"
  28. #define INTEL_LIMIT_I9XX_SDVO_DAC 0
  29. #define INTEL_LIMIT_I9XX_LVDS 1
  30. static const struct gma_limit_t psb_intel_limits[] = {
  31. { /* INTEL_LIMIT_I9XX_SDVO_DAC */
  32. .dot = {.min = 20000, .max = 400000},
  33. .vco = {.min = 1400000, .max = 2800000},
  34. .n = {.min = 1, .max = 6},
  35. .m = {.min = 70, .max = 120},
  36. .m1 = {.min = 8, .max = 18},
  37. .m2 = {.min = 3, .max = 7},
  38. .p = {.min = 5, .max = 80},
  39. .p1 = {.min = 1, .max = 8},
  40. .p2 = {.dot_limit = 200000, .p2_slow = 10, .p2_fast = 5},
  41. .find_pll = gma_find_best_pll,
  42. },
  43. { /* INTEL_LIMIT_I9XX_LVDS */
  44. .dot = {.min = 20000, .max = 400000},
  45. .vco = {.min = 1400000, .max = 2800000},
  46. .n = {.min = 1, .max = 6},
  47. .m = {.min = 70, .max = 120},
  48. .m1 = {.min = 8, .max = 18},
  49. .m2 = {.min = 3, .max = 7},
  50. .p = {.min = 7, .max = 98},
  51. .p1 = {.min = 1, .max = 8},
  52. /* The single-channel range is 25-112Mhz, and dual-channel
  53. * is 80-224Mhz. Prefer single channel as much as possible.
  54. */
  55. .p2 = {.dot_limit = 112000, .p2_slow = 14, .p2_fast = 7},
  56. .find_pll = gma_find_best_pll,
  57. },
  58. };
  59. static const struct gma_limit_t *psb_intel_limit(struct drm_crtc *crtc,
  60. int refclk)
  61. {
  62. const struct gma_limit_t *limit;
  63. if (gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  64. limit = &psb_intel_limits[INTEL_LIMIT_I9XX_LVDS];
  65. else
  66. limit = &psb_intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC];
  67. return limit;
  68. }
  69. static void psb_intel_clock(int refclk, struct gma_clock_t *clock)
  70. {
  71. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  72. clock->p = clock->p1 * clock->p2;
  73. clock->vco = refclk * clock->m / (clock->n + 2);
  74. clock->dot = clock->vco / clock->p;
  75. }
  76. /**
  77. * Return the pipe currently connected to the panel fitter,
  78. * or -1 if the panel fitter is not present or not in use
  79. */
  80. static int psb_intel_panel_fitter_pipe(struct drm_device *dev)
  81. {
  82. u32 pfit_control;
  83. pfit_control = REG_READ(PFIT_CONTROL);
  84. /* See if the panel fitter is in use */
  85. if ((pfit_control & PFIT_ENABLE) == 0)
  86. return -1;
  87. /* Must be on PIPE 1 for PSB */
  88. return 1;
  89. }
  90. static int psb_intel_crtc_mode_set(struct drm_crtc *crtc,
  91. struct drm_display_mode *mode,
  92. struct drm_display_mode *adjusted_mode,
  93. int x, int y,
  94. struct drm_framebuffer *old_fb)
  95. {
  96. struct drm_device *dev = crtc->dev;
  97. struct drm_psb_private *dev_priv = dev->dev_private;
  98. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  99. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  100. int pipe = gma_crtc->pipe;
  101. const struct psb_offset *map = &dev_priv->regmap[pipe];
  102. int refclk;
  103. struct gma_clock_t clock;
  104. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  105. bool ok, is_sdvo = false;
  106. bool is_lvds = false, is_tv = false;
  107. struct drm_mode_config *mode_config = &dev->mode_config;
  108. struct drm_connector *connector;
  109. const struct gma_limit_t *limit;
  110. /* No scan out no play */
  111. if (crtc->fb == NULL) {
  112. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  113. return 0;
  114. }
  115. list_for_each_entry(connector, &mode_config->connector_list, head) {
  116. struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
  117. if (!connector->encoder
  118. || connector->encoder->crtc != crtc)
  119. continue;
  120. switch (gma_encoder->type) {
  121. case INTEL_OUTPUT_LVDS:
  122. is_lvds = true;
  123. break;
  124. case INTEL_OUTPUT_SDVO:
  125. is_sdvo = true;
  126. break;
  127. case INTEL_OUTPUT_TVOUT:
  128. is_tv = true;
  129. break;
  130. }
  131. }
  132. refclk = 96000;
  133. limit = gma_crtc->clock_funcs->limit(crtc, refclk);
  134. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk,
  135. &clock);
  136. if (!ok) {
  137. DRM_ERROR("Couldn't find PLL settings for mode! target: %d, actual: %d",
  138. adjusted_mode->clock, clock.dot);
  139. return 0;
  140. }
  141. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  142. dpll = DPLL_VGA_MODE_DIS;
  143. if (is_lvds) {
  144. dpll |= DPLLB_MODE_LVDS;
  145. dpll |= DPLL_DVO_HIGH_SPEED;
  146. } else
  147. dpll |= DPLLB_MODE_DAC_SERIAL;
  148. if (is_sdvo) {
  149. int sdvo_pixel_multiply =
  150. adjusted_mode->clock / mode->clock;
  151. dpll |= DPLL_DVO_HIGH_SPEED;
  152. dpll |=
  153. (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  154. }
  155. /* compute bitmask from p1 value */
  156. dpll |= (1 << (clock.p1 - 1)) << 16;
  157. switch (clock.p2) {
  158. case 5:
  159. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  160. break;
  161. case 7:
  162. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  163. break;
  164. case 10:
  165. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  166. break;
  167. case 14:
  168. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  169. break;
  170. }
  171. if (is_tv) {
  172. /* XXX: just matching BIOS for now */
  173. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  174. dpll |= 3;
  175. }
  176. dpll |= PLL_REF_INPUT_DREFCLK;
  177. /* setup pipeconf */
  178. pipeconf = REG_READ(map->conf);
  179. /* Set up the display plane register */
  180. dspcntr = DISPPLANE_GAMMA_ENABLE;
  181. if (pipe == 0)
  182. dspcntr |= DISPPLANE_SEL_PIPE_A;
  183. else
  184. dspcntr |= DISPPLANE_SEL_PIPE_B;
  185. dspcntr |= DISPLAY_PLANE_ENABLE;
  186. pipeconf |= PIPEACONF_ENABLE;
  187. dpll |= DPLL_VCO_ENABLE;
  188. /* Disable the panel fitter if it was on our pipe */
  189. if (psb_intel_panel_fitter_pipe(dev) == pipe)
  190. REG_WRITE(PFIT_CONTROL, 0);
  191. drm_mode_debug_printmodeline(mode);
  192. if (dpll & DPLL_VCO_ENABLE) {
  193. REG_WRITE(map->fp0, fp);
  194. REG_WRITE(map->dpll, dpll & ~DPLL_VCO_ENABLE);
  195. REG_READ(map->dpll);
  196. udelay(150);
  197. }
  198. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  199. * This is an exception to the general rule that mode_set doesn't turn
  200. * things on.
  201. */
  202. if (is_lvds) {
  203. u32 lvds = REG_READ(LVDS);
  204. lvds &= ~LVDS_PIPEB_SELECT;
  205. if (pipe == 1)
  206. lvds |= LVDS_PIPEB_SELECT;
  207. lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  208. /* Set the B0-B3 data pairs corresponding to
  209. * whether we're going to
  210. * set the DPLLs for dual-channel mode or not.
  211. */
  212. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  213. if (clock.p2 == 7)
  214. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  215. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  216. * appropriately here, but we need to look more
  217. * thoroughly into how panels behave in the two modes.
  218. */
  219. REG_WRITE(LVDS, lvds);
  220. REG_READ(LVDS);
  221. }
  222. REG_WRITE(map->fp0, fp);
  223. REG_WRITE(map->dpll, dpll);
  224. REG_READ(map->dpll);
  225. /* Wait for the clocks to stabilize. */
  226. udelay(150);
  227. /* write it again -- the BIOS does, after all */
  228. REG_WRITE(map->dpll, dpll);
  229. REG_READ(map->dpll);
  230. /* Wait for the clocks to stabilize. */
  231. udelay(150);
  232. REG_WRITE(map->htotal, (adjusted_mode->crtc_hdisplay - 1) |
  233. ((adjusted_mode->crtc_htotal - 1) << 16));
  234. REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start - 1) |
  235. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  236. REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start - 1) |
  237. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  238. REG_WRITE(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) |
  239. ((adjusted_mode->crtc_vtotal - 1) << 16));
  240. REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start - 1) |
  241. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  242. REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start - 1) |
  243. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  244. /* pipesrc and dspsize control the size that is scaled from,
  245. * which should always be the user's requested size.
  246. */
  247. REG_WRITE(map->size,
  248. ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  249. REG_WRITE(map->pos, 0);
  250. REG_WRITE(map->src,
  251. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  252. REG_WRITE(map->conf, pipeconf);
  253. REG_READ(map->conf);
  254. gma_wait_for_vblank(dev);
  255. REG_WRITE(map->cntr, dspcntr);
  256. /* Flush the plane changes */
  257. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  258. gma_wait_for_vblank(dev);
  259. return 0;
  260. }
  261. /* Returns the clock of the currently programmed mode of the given pipe. */
  262. static int psb_intel_crtc_clock_get(struct drm_device *dev,
  263. struct drm_crtc *crtc)
  264. {
  265. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  266. struct drm_psb_private *dev_priv = dev->dev_private;
  267. int pipe = gma_crtc->pipe;
  268. const struct psb_offset *map = &dev_priv->regmap[pipe];
  269. u32 dpll;
  270. u32 fp;
  271. struct gma_clock_t clock;
  272. bool is_lvds;
  273. struct psb_pipe *p = &dev_priv->regs.pipe[pipe];
  274. if (gma_power_begin(dev, false)) {
  275. dpll = REG_READ(map->dpll);
  276. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  277. fp = REG_READ(map->fp0);
  278. else
  279. fp = REG_READ(map->fp1);
  280. is_lvds = (pipe == 1) && (REG_READ(LVDS) & LVDS_PORT_EN);
  281. gma_power_end(dev);
  282. } else {
  283. dpll = p->dpll;
  284. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  285. fp = p->fp0;
  286. else
  287. fp = p->fp1;
  288. is_lvds = (pipe == 1) && (dev_priv->regs.psb.saveLVDS &
  289. LVDS_PORT_EN);
  290. }
  291. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  292. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  293. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  294. if (is_lvds) {
  295. clock.p1 =
  296. ffs((dpll &
  297. DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  298. DPLL_FPA01_P1_POST_DIV_SHIFT);
  299. clock.p2 = 14;
  300. if ((dpll & PLL_REF_INPUT_MASK) ==
  301. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  302. /* XXX: might not be 66MHz */
  303. psb_intel_clock(66000, &clock);
  304. } else
  305. psb_intel_clock(48000, &clock);
  306. } else {
  307. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  308. clock.p1 = 2;
  309. else {
  310. clock.p1 =
  311. ((dpll &
  312. DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  313. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  314. }
  315. if (dpll & PLL_P2_DIVIDE_BY_4)
  316. clock.p2 = 4;
  317. else
  318. clock.p2 = 2;
  319. psb_intel_clock(48000, &clock);
  320. }
  321. /* XXX: It would be nice to validate the clocks, but we can't reuse
  322. * i830PllIsValid() because it relies on the xf86_config connector
  323. * configuration being accurate, which it isn't necessarily.
  324. */
  325. return clock.dot;
  326. }
  327. /** Returns the currently programmed mode of the given pipe. */
  328. struct drm_display_mode *psb_intel_crtc_mode_get(struct drm_device *dev,
  329. struct drm_crtc *crtc)
  330. {
  331. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  332. int pipe = gma_crtc->pipe;
  333. struct drm_display_mode *mode;
  334. int htot;
  335. int hsync;
  336. int vtot;
  337. int vsync;
  338. struct drm_psb_private *dev_priv = dev->dev_private;
  339. struct psb_pipe *p = &dev_priv->regs.pipe[pipe];
  340. const struct psb_offset *map = &dev_priv->regmap[pipe];
  341. if (gma_power_begin(dev, false)) {
  342. htot = REG_READ(map->htotal);
  343. hsync = REG_READ(map->hsync);
  344. vtot = REG_READ(map->vtotal);
  345. vsync = REG_READ(map->vsync);
  346. gma_power_end(dev);
  347. } else {
  348. htot = p->htotal;
  349. hsync = p->hsync;
  350. vtot = p->vtotal;
  351. vsync = p->vsync;
  352. }
  353. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  354. if (!mode)
  355. return NULL;
  356. mode->clock = psb_intel_crtc_clock_get(dev, crtc);
  357. mode->hdisplay = (htot & 0xffff) + 1;
  358. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  359. mode->hsync_start = (hsync & 0xffff) + 1;
  360. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  361. mode->vdisplay = (vtot & 0xffff) + 1;
  362. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  363. mode->vsync_start = (vsync & 0xffff) + 1;
  364. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  365. drm_mode_set_name(mode);
  366. drm_mode_set_crtcinfo(mode, 0);
  367. return mode;
  368. }
  369. const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
  370. .dpms = gma_crtc_dpms,
  371. .mode_fixup = gma_crtc_mode_fixup,
  372. .mode_set = psb_intel_crtc_mode_set,
  373. .mode_set_base = gma_pipe_set_base,
  374. .prepare = gma_crtc_prepare,
  375. .commit = gma_crtc_commit,
  376. .disable = gma_crtc_disable,
  377. };
  378. const struct drm_crtc_funcs psb_intel_crtc_funcs = {
  379. .save = gma_crtc_save,
  380. .restore = gma_crtc_restore,
  381. .cursor_set = gma_crtc_cursor_set,
  382. .cursor_move = gma_crtc_cursor_move,
  383. .gamma_set = gma_crtc_gamma_set,
  384. .set_config = gma_crtc_set_config,
  385. .destroy = gma_crtc_destroy,
  386. };
  387. const struct gma_clock_funcs psb_clock_funcs = {
  388. .clock = psb_intel_clock,
  389. .limit = psb_intel_limit,
  390. .pll_is_valid = gma_pll_is_valid,
  391. };
  392. /*
  393. * Set the default value of cursor control and base register
  394. * to zero. This is a workaround for h/w defect on Oaktrail
  395. */
  396. static void psb_intel_cursor_init(struct drm_device *dev,
  397. struct gma_crtc *gma_crtc)
  398. {
  399. struct drm_psb_private *dev_priv = dev->dev_private;
  400. u32 control[3] = { CURACNTR, CURBCNTR, CURCCNTR };
  401. u32 base[3] = { CURABASE, CURBBASE, CURCBASE };
  402. struct gtt_range *cursor_gt;
  403. if (dev_priv->ops->cursor_needs_phys) {
  404. /* Allocate 4 pages of stolen mem for a hardware cursor. That
  405. * is enough for the 64 x 64 ARGB cursors we support.
  406. */
  407. cursor_gt = psb_gtt_alloc_range(dev, 4 * PAGE_SIZE, "cursor", 1);
  408. if (!cursor_gt) {
  409. gma_crtc->cursor_gt = NULL;
  410. goto out;
  411. }
  412. gma_crtc->cursor_gt = cursor_gt;
  413. gma_crtc->cursor_addr = dev_priv->stolen_base +
  414. cursor_gt->offset;
  415. } else {
  416. gma_crtc->cursor_gt = NULL;
  417. }
  418. out:
  419. REG_WRITE(control[gma_crtc->pipe], 0);
  420. REG_WRITE(base[gma_crtc->pipe], 0);
  421. }
  422. void psb_intel_crtc_init(struct drm_device *dev, int pipe,
  423. struct psb_intel_mode_device *mode_dev)
  424. {
  425. struct drm_psb_private *dev_priv = dev->dev_private;
  426. struct gma_crtc *gma_crtc;
  427. int i;
  428. uint16_t *r_base, *g_base, *b_base;
  429. /* We allocate a extra array of drm_connector pointers
  430. * for fbdev after the crtc */
  431. gma_crtc = kzalloc(sizeof(struct gma_crtc) +
  432. (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)),
  433. GFP_KERNEL);
  434. if (gma_crtc == NULL)
  435. return;
  436. gma_crtc->crtc_state =
  437. kzalloc(sizeof(struct psb_intel_crtc_state), GFP_KERNEL);
  438. if (!gma_crtc->crtc_state) {
  439. dev_err(dev->dev, "Crtc state error: No memory\n");
  440. kfree(gma_crtc);
  441. return;
  442. }
  443. /* Set the CRTC operations from the chip specific data */
  444. drm_crtc_init(dev, &gma_crtc->base, dev_priv->ops->crtc_funcs);
  445. /* Set the CRTC clock functions from chip specific data */
  446. gma_crtc->clock_funcs = dev_priv->ops->clock_funcs;
  447. drm_mode_crtc_set_gamma_size(&gma_crtc->base, 256);
  448. gma_crtc->pipe = pipe;
  449. gma_crtc->plane = pipe;
  450. r_base = gma_crtc->base.gamma_store;
  451. g_base = r_base + 256;
  452. b_base = g_base + 256;
  453. for (i = 0; i < 256; i++) {
  454. gma_crtc->lut_r[i] = i;
  455. gma_crtc->lut_g[i] = i;
  456. gma_crtc->lut_b[i] = i;
  457. r_base[i] = i << 8;
  458. g_base[i] = i << 8;
  459. b_base[i] = i << 8;
  460. gma_crtc->lut_adj[i] = 0;
  461. }
  462. gma_crtc->mode_dev = mode_dev;
  463. gma_crtc->cursor_addr = 0;
  464. drm_crtc_helper_add(&gma_crtc->base,
  465. dev_priv->ops->crtc_helper);
  466. /* Setup the array of drm_connector pointer array */
  467. gma_crtc->mode_set.crtc = &gma_crtc->base;
  468. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  469. dev_priv->plane_to_crtc_mapping[gma_crtc->plane] != NULL);
  470. dev_priv->plane_to_crtc_mapping[gma_crtc->plane] = &gma_crtc->base;
  471. dev_priv->pipe_to_crtc_mapping[gma_crtc->pipe] = &gma_crtc->base;
  472. gma_crtc->mode_set.connectors = (struct drm_connector **)(gma_crtc + 1);
  473. gma_crtc->mode_set.num_connectors = 0;
  474. psb_intel_cursor_init(dev, gma_crtc);
  475. /* Set to true so that the pipe is forced off on initial config. */
  476. gma_crtc->active = true;
  477. }
  478. int psb_intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  479. struct drm_file *file_priv)
  480. {
  481. struct drm_psb_private *dev_priv = dev->dev_private;
  482. struct drm_psb_get_pipe_from_crtc_id_arg *pipe_from_crtc_id = data;
  483. struct drm_mode_object *drmmode_obj;
  484. struct gma_crtc *crtc;
  485. if (!dev_priv) {
  486. dev_err(dev->dev, "called with no initialization\n");
  487. return -EINVAL;
  488. }
  489. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  490. DRM_MODE_OBJECT_CRTC);
  491. if (!drmmode_obj) {
  492. dev_err(dev->dev, "no such CRTC id\n");
  493. return -EINVAL;
  494. }
  495. crtc = to_gma_crtc(obj_to_crtc(drmmode_obj));
  496. pipe_from_crtc_id->pipe = crtc->pipe;
  497. return 0;
  498. }
  499. struct drm_crtc *psb_intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
  500. {
  501. struct drm_crtc *crtc = NULL;
  502. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  503. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  504. if (gma_crtc->pipe == pipe)
  505. break;
  506. }
  507. return crtc;
  508. }
  509. int gma_connector_clones(struct drm_device *dev, int type_mask)
  510. {
  511. int index_mask = 0;
  512. struct drm_connector *connector;
  513. int entry = 0;
  514. list_for_each_entry(connector, &dev->mode_config.connector_list,
  515. head) {
  516. struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
  517. if (type_mask & (1 << gma_encoder->type))
  518. index_mask |= (1 << entry);
  519. entry++;
  520. }
  521. return index_mask;
  522. }