cdv_intel_display.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright © 2006-2011 Intel Corporation
  4. *
  5. * Authors:
  6. * Eric Anholt <eric@anholt.net>
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/i2c.h>
  10. #include <drm/drm_crtc.h>
  11. #include <drm/drm_modeset_helper_vtables.h>
  12. #include "cdv_device.h"
  13. #include "framebuffer.h"
  14. #include "gma_display.h"
  15. #include "power.h"
  16. #include "psb_drv.h"
  17. #include "psb_intel_drv.h"
  18. #include "psb_intel_reg.h"
  19. static bool cdv_intel_find_dp_pll(const struct gma_limit_t *limit,
  20. struct drm_crtc *crtc, int target,
  21. int refclk, struct gma_clock_t *best_clock);
  22. #define CDV_LIMIT_SINGLE_LVDS_96 0
  23. #define CDV_LIMIT_SINGLE_LVDS_100 1
  24. #define CDV_LIMIT_DAC_HDMI_27 2
  25. #define CDV_LIMIT_DAC_HDMI_96 3
  26. #define CDV_LIMIT_DP_27 4
  27. #define CDV_LIMIT_DP_100 5
  28. static const struct gma_limit_t cdv_intel_limits[] = {
  29. { /* CDV_SINGLE_LVDS_96MHz */
  30. .dot = {.min = 20000, .max = 115500},
  31. .vco = {.min = 1800000, .max = 3600000},
  32. .n = {.min = 2, .max = 6},
  33. .m = {.min = 60, .max = 160},
  34. .m1 = {.min = 0, .max = 0},
  35. .m2 = {.min = 58, .max = 158},
  36. .p = {.min = 28, .max = 140},
  37. .p1 = {.min = 2, .max = 10},
  38. .p2 = {.dot_limit = 200000, .p2_slow = 14, .p2_fast = 14},
  39. .find_pll = gma_find_best_pll,
  40. },
  41. { /* CDV_SINGLE_LVDS_100MHz */
  42. .dot = {.min = 20000, .max = 115500},
  43. .vco = {.min = 1800000, .max = 3600000},
  44. .n = {.min = 2, .max = 6},
  45. .m = {.min = 60, .max = 160},
  46. .m1 = {.min = 0, .max = 0},
  47. .m2 = {.min = 58, .max = 158},
  48. .p = {.min = 28, .max = 140},
  49. .p1 = {.min = 2, .max = 10},
  50. /* The single-channel range is 25-112Mhz, and dual-channel
  51. * is 80-224Mhz. Prefer single channel as much as possible.
  52. */
  53. .p2 = {.dot_limit = 200000, .p2_slow = 14, .p2_fast = 14},
  54. .find_pll = gma_find_best_pll,
  55. },
  56. { /* CDV_DAC_HDMI_27MHz */
  57. .dot = {.min = 20000, .max = 400000},
  58. .vco = {.min = 1809000, .max = 3564000},
  59. .n = {.min = 1, .max = 1},
  60. .m = {.min = 67, .max = 132},
  61. .m1 = {.min = 0, .max = 0},
  62. .m2 = {.min = 65, .max = 130},
  63. .p = {.min = 5, .max = 90},
  64. .p1 = {.min = 1, .max = 9},
  65. .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 5},
  66. .find_pll = gma_find_best_pll,
  67. },
  68. { /* CDV_DAC_HDMI_96MHz */
  69. .dot = {.min = 20000, .max = 400000},
  70. .vco = {.min = 1800000, .max = 3600000},
  71. .n = {.min = 2, .max = 6},
  72. .m = {.min = 60, .max = 160},
  73. .m1 = {.min = 0, .max = 0},
  74. .m2 = {.min = 58, .max = 158},
  75. .p = {.min = 5, .max = 100},
  76. .p1 = {.min = 1, .max = 10},
  77. .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 5},
  78. .find_pll = gma_find_best_pll,
  79. },
  80. { /* CDV_DP_27MHz */
  81. .dot = {.min = 160000, .max = 272000},
  82. .vco = {.min = 1809000, .max = 3564000},
  83. .n = {.min = 1, .max = 1},
  84. .m = {.min = 67, .max = 132},
  85. .m1 = {.min = 0, .max = 0},
  86. .m2 = {.min = 65, .max = 130},
  87. .p = {.min = 5, .max = 90},
  88. .p1 = {.min = 1, .max = 9},
  89. .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 10},
  90. .find_pll = cdv_intel_find_dp_pll,
  91. },
  92. { /* CDV_DP_100MHz */
  93. .dot = {.min = 160000, .max = 272000},
  94. .vco = {.min = 1800000, .max = 3600000},
  95. .n = {.min = 2, .max = 6},
  96. .m = {.min = 60, .max = 164},
  97. .m1 = {.min = 0, .max = 0},
  98. .m2 = {.min = 58, .max = 162},
  99. .p = {.min = 5, .max = 100},
  100. .p1 = {.min = 1, .max = 10},
  101. .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 10},
  102. .find_pll = cdv_intel_find_dp_pll,
  103. }
  104. };
  105. #define _wait_for(COND, MS, W) ({ \
  106. unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
  107. int ret__ = 0; \
  108. while (!(COND)) { \
  109. if (time_after(jiffies, timeout__)) { \
  110. ret__ = -ETIMEDOUT; \
  111. break; \
  112. } \
  113. if (W && !in_dbg_master()) \
  114. msleep(W); \
  115. } \
  116. ret__; \
  117. })
  118. #define wait_for(COND, MS) _wait_for(COND, MS, 1)
  119. int cdv_sb_read(struct drm_device *dev, u32 reg, u32 *val)
  120. {
  121. int ret;
  122. ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000);
  123. if (ret) {
  124. DRM_ERROR("timeout waiting for SB to idle before read\n");
  125. return ret;
  126. }
  127. REG_WRITE(SB_ADDR, reg);
  128. REG_WRITE(SB_PCKT,
  129. SET_FIELD(SB_OPCODE_READ, SB_OPCODE) |
  130. SET_FIELD(SB_DEST_DPLL, SB_DEST) |
  131. SET_FIELD(0xf, SB_BYTE_ENABLE));
  132. ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000);
  133. if (ret) {
  134. DRM_ERROR("timeout waiting for SB to idle after read\n");
  135. return ret;
  136. }
  137. *val = REG_READ(SB_DATA);
  138. return 0;
  139. }
  140. int cdv_sb_write(struct drm_device *dev, u32 reg, u32 val)
  141. {
  142. int ret;
  143. static bool dpio_debug = true;
  144. u32 temp;
  145. if (dpio_debug) {
  146. if (cdv_sb_read(dev, reg, &temp) == 0)
  147. DRM_DEBUG_KMS("0x%08x: 0x%08x (before)\n", reg, temp);
  148. DRM_DEBUG_KMS("0x%08x: 0x%08x\n", reg, val);
  149. }
  150. ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000);
  151. if (ret) {
  152. DRM_ERROR("timeout waiting for SB to idle before write\n");
  153. return ret;
  154. }
  155. REG_WRITE(SB_ADDR, reg);
  156. REG_WRITE(SB_DATA, val);
  157. REG_WRITE(SB_PCKT,
  158. SET_FIELD(SB_OPCODE_WRITE, SB_OPCODE) |
  159. SET_FIELD(SB_DEST_DPLL, SB_DEST) |
  160. SET_FIELD(0xf, SB_BYTE_ENABLE));
  161. ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000);
  162. if (ret) {
  163. DRM_ERROR("timeout waiting for SB to idle after write\n");
  164. return ret;
  165. }
  166. if (dpio_debug) {
  167. if (cdv_sb_read(dev, reg, &temp) == 0)
  168. DRM_DEBUG_KMS("0x%08x: 0x%08x (after)\n", reg, temp);
  169. }
  170. return 0;
  171. }
  172. /* Reset the DPIO configuration register. The BIOS does this at every
  173. * mode set.
  174. */
  175. void cdv_sb_reset(struct drm_device *dev)
  176. {
  177. REG_WRITE(DPIO_CFG, 0);
  178. REG_READ(DPIO_CFG);
  179. REG_WRITE(DPIO_CFG, DPIO_MODE_SELECT_0 | DPIO_CMN_RESET_N);
  180. }
  181. /* Unlike most Intel display engines, on Cedarview the DPLL registers
  182. * are behind this sideband bus. They must be programmed while the
  183. * DPLL reference clock is on in the DPLL control register, but before
  184. * the DPLL is enabled in the DPLL control register.
  185. */
  186. static int
  187. cdv_dpll_set_clock_cdv(struct drm_device *dev, struct drm_crtc *crtc,
  188. struct gma_clock_t *clock, bool is_lvds, u32 ddi_select)
  189. {
  190. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  191. int pipe = gma_crtc->pipe;
  192. u32 m, n_vco, p;
  193. int ret = 0;
  194. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  195. int ref_sfr = (pipe == 0) ? SB_REF_DPLLA : SB_REF_DPLLB;
  196. u32 ref_value;
  197. u32 lane_reg, lane_value;
  198. cdv_sb_reset(dev);
  199. REG_WRITE(dpll_reg, DPLL_SYNCLOCK_ENABLE | DPLL_VGA_MODE_DIS);
  200. udelay(100);
  201. /* Follow the BIOS and write the REF/SFR Register. Hardcoded value */
  202. ref_value = 0x68A701;
  203. cdv_sb_write(dev, SB_REF_SFR(pipe), ref_value);
  204. /* We don't know what the other fields of these regs are, so
  205. * leave them in place.
  206. */
  207. /*
  208. * The BIT 14:13 of 0x8010/0x8030 is used to select the ref clk
  209. * for the pipe A/B. Display spec 1.06 has wrong definition.
  210. * Correct definition is like below:
  211. *
  212. * refclka mean use clock from same PLL
  213. *
  214. * if DPLLA sets 01 and DPLLB sets 01, they use clock from their pll
  215. *
  216. * if DPLLA sets 01 and DPLLB sets 02, both use clk from DPLLA
  217. *
  218. */
  219. ret = cdv_sb_read(dev, ref_sfr, &ref_value);
  220. if (ret)
  221. return ret;
  222. ref_value &= ~(REF_CLK_MASK);
  223. /* use DPLL_A for pipeB on CRT/HDMI */
  224. if (pipe == 1 && !is_lvds && !(ddi_select & DP_MASK)) {
  225. DRM_DEBUG_KMS("use DPLLA for pipe B\n");
  226. ref_value |= REF_CLK_DPLLA;
  227. } else {
  228. DRM_DEBUG_KMS("use their DPLL for pipe A/B\n");
  229. ref_value |= REF_CLK_DPLL;
  230. }
  231. ret = cdv_sb_write(dev, ref_sfr, ref_value);
  232. if (ret)
  233. return ret;
  234. ret = cdv_sb_read(dev, SB_M(pipe), &m);
  235. if (ret)
  236. return ret;
  237. m &= ~SB_M_DIVIDER_MASK;
  238. m |= ((clock->m2) << SB_M_DIVIDER_SHIFT);
  239. ret = cdv_sb_write(dev, SB_M(pipe), m);
  240. if (ret)
  241. return ret;
  242. ret = cdv_sb_read(dev, SB_N_VCO(pipe), &n_vco);
  243. if (ret)
  244. return ret;
  245. /* Follow the BIOS to program the N_DIVIDER REG */
  246. n_vco &= 0xFFFF;
  247. n_vco |= 0x107;
  248. n_vco &= ~(SB_N_VCO_SEL_MASK |
  249. SB_N_DIVIDER_MASK |
  250. SB_N_CB_TUNE_MASK);
  251. n_vco |= ((clock->n) << SB_N_DIVIDER_SHIFT);
  252. if (clock->vco < 2250000) {
  253. n_vco |= (2 << SB_N_CB_TUNE_SHIFT);
  254. n_vco |= (0 << SB_N_VCO_SEL_SHIFT);
  255. } else if (clock->vco < 2750000) {
  256. n_vco |= (1 << SB_N_CB_TUNE_SHIFT);
  257. n_vco |= (1 << SB_N_VCO_SEL_SHIFT);
  258. } else if (clock->vco < 3300000) {
  259. n_vco |= (0 << SB_N_CB_TUNE_SHIFT);
  260. n_vco |= (2 << SB_N_VCO_SEL_SHIFT);
  261. } else {
  262. n_vco |= (0 << SB_N_CB_TUNE_SHIFT);
  263. n_vco |= (3 << SB_N_VCO_SEL_SHIFT);
  264. }
  265. ret = cdv_sb_write(dev, SB_N_VCO(pipe), n_vco);
  266. if (ret)
  267. return ret;
  268. ret = cdv_sb_read(dev, SB_P(pipe), &p);
  269. if (ret)
  270. return ret;
  271. p &= ~(SB_P2_DIVIDER_MASK | SB_P1_DIVIDER_MASK);
  272. p |= SET_FIELD(clock->p1, SB_P1_DIVIDER);
  273. switch (clock->p2) {
  274. case 5:
  275. p |= SET_FIELD(SB_P2_5, SB_P2_DIVIDER);
  276. break;
  277. case 10:
  278. p |= SET_FIELD(SB_P2_10, SB_P2_DIVIDER);
  279. break;
  280. case 14:
  281. p |= SET_FIELD(SB_P2_14, SB_P2_DIVIDER);
  282. break;
  283. case 7:
  284. p |= SET_FIELD(SB_P2_7, SB_P2_DIVIDER);
  285. break;
  286. default:
  287. DRM_ERROR("Bad P2 clock: %d\n", clock->p2);
  288. return -EINVAL;
  289. }
  290. ret = cdv_sb_write(dev, SB_P(pipe), p);
  291. if (ret)
  292. return ret;
  293. if (ddi_select) {
  294. if ((ddi_select & DDI_MASK) == DDI0_SELECT) {
  295. lane_reg = PSB_LANE0;
  296. cdv_sb_read(dev, lane_reg, &lane_value);
  297. lane_value &= ~(LANE_PLL_MASK);
  298. lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe);
  299. cdv_sb_write(dev, lane_reg, lane_value);
  300. lane_reg = PSB_LANE1;
  301. cdv_sb_read(dev, lane_reg, &lane_value);
  302. lane_value &= ~(LANE_PLL_MASK);
  303. lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe);
  304. cdv_sb_write(dev, lane_reg, lane_value);
  305. } else {
  306. lane_reg = PSB_LANE2;
  307. cdv_sb_read(dev, lane_reg, &lane_value);
  308. lane_value &= ~(LANE_PLL_MASK);
  309. lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe);
  310. cdv_sb_write(dev, lane_reg, lane_value);
  311. lane_reg = PSB_LANE3;
  312. cdv_sb_read(dev, lane_reg, &lane_value);
  313. lane_value &= ~(LANE_PLL_MASK);
  314. lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe);
  315. cdv_sb_write(dev, lane_reg, lane_value);
  316. }
  317. }
  318. return 0;
  319. }
  320. static const struct gma_limit_t *cdv_intel_limit(struct drm_crtc *crtc,
  321. int refclk)
  322. {
  323. const struct gma_limit_t *limit;
  324. if (gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  325. /*
  326. * Now only single-channel LVDS is supported on CDV. If it is
  327. * incorrect, please add the dual-channel LVDS.
  328. */
  329. if (refclk == 96000)
  330. limit = &cdv_intel_limits[CDV_LIMIT_SINGLE_LVDS_96];
  331. else
  332. limit = &cdv_intel_limits[CDV_LIMIT_SINGLE_LVDS_100];
  333. } else if (gma_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  334. gma_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  335. if (refclk == 27000)
  336. limit = &cdv_intel_limits[CDV_LIMIT_DP_27];
  337. else
  338. limit = &cdv_intel_limits[CDV_LIMIT_DP_100];
  339. } else {
  340. if (refclk == 27000)
  341. limit = &cdv_intel_limits[CDV_LIMIT_DAC_HDMI_27];
  342. else
  343. limit = &cdv_intel_limits[CDV_LIMIT_DAC_HDMI_96];
  344. }
  345. return limit;
  346. }
  347. /* m1 is reserved as 0 in CDV, n is a ring counter */
  348. static void cdv_intel_clock(int refclk, struct gma_clock_t *clock)
  349. {
  350. clock->m = clock->m2 + 2;
  351. clock->p = clock->p1 * clock->p2;
  352. clock->vco = (refclk * clock->m) / clock->n;
  353. clock->dot = clock->vco / clock->p;
  354. }
  355. static bool cdv_intel_find_dp_pll(const struct gma_limit_t *limit,
  356. struct drm_crtc *crtc, int target,
  357. int refclk,
  358. struct gma_clock_t *best_clock)
  359. {
  360. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  361. struct gma_clock_t clock;
  362. memset(&clock, 0, sizeof(clock));
  363. switch (refclk) {
  364. case 27000:
  365. if (target < 200000) {
  366. clock.p1 = 2;
  367. clock.p2 = 10;
  368. clock.n = 1;
  369. clock.m1 = 0;
  370. clock.m2 = 118;
  371. } else {
  372. clock.p1 = 1;
  373. clock.p2 = 10;
  374. clock.n = 1;
  375. clock.m1 = 0;
  376. clock.m2 = 98;
  377. }
  378. break;
  379. case 100000:
  380. if (target < 200000) {
  381. clock.p1 = 2;
  382. clock.p2 = 10;
  383. clock.n = 5;
  384. clock.m1 = 0;
  385. clock.m2 = 160;
  386. } else {
  387. clock.p1 = 1;
  388. clock.p2 = 10;
  389. clock.n = 5;
  390. clock.m1 = 0;
  391. clock.m2 = 133;
  392. }
  393. break;
  394. default:
  395. return false;
  396. }
  397. gma_crtc->clock_funcs->clock(refclk, &clock);
  398. memcpy(best_clock, &clock, sizeof(struct gma_clock_t));
  399. return true;
  400. }
  401. #define FIFO_PIPEA (1 << 0)
  402. #define FIFO_PIPEB (1 << 1)
  403. static bool cdv_intel_pipe_enabled(struct drm_device *dev, int pipe)
  404. {
  405. struct drm_crtc *crtc;
  406. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  407. struct gma_crtc *gma_crtc = NULL;
  408. crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  409. gma_crtc = to_gma_crtc(crtc);
  410. if (crtc->primary->fb == NULL || !gma_crtc->active)
  411. return false;
  412. return true;
  413. }
  414. void cdv_disable_sr(struct drm_device *dev)
  415. {
  416. if (REG_READ(FW_BLC_SELF) & FW_BLC_SELF_EN) {
  417. /* Disable self-refresh before adjust WM */
  418. REG_WRITE(FW_BLC_SELF, (REG_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN));
  419. REG_READ(FW_BLC_SELF);
  420. gma_wait_for_vblank(dev);
  421. /* Cedarview workaround to write ovelay plane, which force to leave
  422. * MAX_FIFO state.
  423. */
  424. REG_WRITE(OV_OVADD, 0/*dev_priv->ovl_offset*/);
  425. REG_READ(OV_OVADD);
  426. gma_wait_for_vblank(dev);
  427. }
  428. }
  429. void cdv_update_wm(struct drm_device *dev, struct drm_crtc *crtc)
  430. {
  431. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  432. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  433. /* Is only one pipe enabled? */
  434. if (cdv_intel_pipe_enabled(dev, 0) ^ cdv_intel_pipe_enabled(dev, 1)) {
  435. u32 fw;
  436. fw = REG_READ(DSPFW1);
  437. fw &= ~DSP_FIFO_SR_WM_MASK;
  438. fw |= (0x7e << DSP_FIFO_SR_WM_SHIFT);
  439. fw &= ~CURSOR_B_FIFO_WM_MASK;
  440. fw |= (0x4 << CURSOR_B_FIFO_WM_SHIFT);
  441. REG_WRITE(DSPFW1, fw);
  442. fw = REG_READ(DSPFW2);
  443. fw &= ~CURSOR_A_FIFO_WM_MASK;
  444. fw |= (0x6 << CURSOR_A_FIFO_WM_SHIFT);
  445. fw &= ~DSP_PLANE_C_FIFO_WM_MASK;
  446. fw |= (0x8 << DSP_PLANE_C_FIFO_WM_SHIFT);
  447. REG_WRITE(DSPFW2, fw);
  448. REG_WRITE(DSPFW3, 0x36000000);
  449. /* ignore FW4 */
  450. /* Is pipe b lvds ? */
  451. if (gma_crtc->pipe == 1 &&
  452. gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  453. REG_WRITE(DSPFW5, 0x00040330);
  454. } else {
  455. fw = (3 << DSP_PLANE_B_FIFO_WM1_SHIFT) |
  456. (4 << DSP_PLANE_A_FIFO_WM1_SHIFT) |
  457. (3 << CURSOR_B_FIFO_WM1_SHIFT) |
  458. (4 << CURSOR_FIFO_SR_WM1_SHIFT);
  459. REG_WRITE(DSPFW5, fw);
  460. }
  461. REG_WRITE(DSPFW6, 0x10);
  462. gma_wait_for_vblank(dev);
  463. /* enable self-refresh for single pipe active */
  464. REG_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  465. REG_READ(FW_BLC_SELF);
  466. gma_wait_for_vblank(dev);
  467. } else {
  468. /* HW team suggested values... */
  469. REG_WRITE(DSPFW1, 0x3f880808);
  470. REG_WRITE(DSPFW2, 0x0b020202);
  471. REG_WRITE(DSPFW3, 0x24000000);
  472. REG_WRITE(DSPFW4, 0x08030202);
  473. REG_WRITE(DSPFW5, 0x01010101);
  474. REG_WRITE(DSPFW6, 0x1d0);
  475. gma_wait_for_vblank(dev);
  476. dev_priv->ops->disable_sr(dev);
  477. }
  478. }
  479. /*
  480. * Return the pipe currently connected to the panel fitter,
  481. * or -1 if the panel fitter is not present or not in use
  482. */
  483. static int cdv_intel_panel_fitter_pipe(struct drm_device *dev)
  484. {
  485. u32 pfit_control;
  486. pfit_control = REG_READ(PFIT_CONTROL);
  487. /* See if the panel fitter is in use */
  488. if ((pfit_control & PFIT_ENABLE) == 0)
  489. return -1;
  490. return (pfit_control >> 29) & 0x3;
  491. }
  492. static int cdv_intel_crtc_mode_set(struct drm_crtc *crtc,
  493. struct drm_display_mode *mode,
  494. struct drm_display_mode *adjusted_mode,
  495. int x, int y,
  496. struct drm_framebuffer *old_fb)
  497. {
  498. struct drm_device *dev = crtc->dev;
  499. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  500. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  501. int pipe = gma_crtc->pipe;
  502. const struct psb_offset *map = &dev_priv->regmap[pipe];
  503. int refclk;
  504. struct gma_clock_t clock;
  505. u32 dpll = 0, dspcntr, pipeconf;
  506. bool ok;
  507. bool is_lvds = false;
  508. bool is_dp = false;
  509. struct drm_connector_list_iter conn_iter;
  510. struct drm_connector *connector;
  511. const struct gma_limit_t *limit;
  512. u32 ddi_select = 0;
  513. bool is_edp = false;
  514. drm_connector_list_iter_begin(dev, &conn_iter);
  515. drm_for_each_connector_iter(connector, &conn_iter) {
  516. struct gma_encoder *gma_encoder =
  517. gma_attached_encoder(connector);
  518. if (!connector->encoder
  519. || connector->encoder->crtc != crtc)
  520. continue;
  521. ddi_select = gma_encoder->ddi_select;
  522. switch (gma_encoder->type) {
  523. case INTEL_OUTPUT_LVDS:
  524. is_lvds = true;
  525. break;
  526. case INTEL_OUTPUT_ANALOG:
  527. case INTEL_OUTPUT_HDMI:
  528. break;
  529. case INTEL_OUTPUT_DISPLAYPORT:
  530. is_dp = true;
  531. break;
  532. case INTEL_OUTPUT_EDP:
  533. is_edp = true;
  534. break;
  535. default:
  536. drm_connector_list_iter_end(&conn_iter);
  537. DRM_ERROR("invalid output type.\n");
  538. return 0;
  539. }
  540. break;
  541. }
  542. drm_connector_list_iter_end(&conn_iter);
  543. if (dev_priv->dplla_96mhz)
  544. /* low-end sku, 96/100 mhz */
  545. refclk = 96000;
  546. else
  547. /* high-end sku, 27/100 mhz */
  548. refclk = 27000;
  549. if (is_dp || is_edp) {
  550. /*
  551. * Based on the spec the low-end SKU has only CRT/LVDS. So it is
  552. * unnecessary to consider it for DP/eDP.
  553. * On the high-end SKU, it will use the 27/100M reference clk
  554. * for DP/eDP. When using SSC clock, the ref clk is 100MHz.Otherwise
  555. * it will be 27MHz. From the VBIOS code it seems that the pipe A choose
  556. * 27MHz for DP/eDP while the Pipe B chooses the 100MHz.
  557. */
  558. if (pipe == 0)
  559. refclk = 27000;
  560. else
  561. refclk = 100000;
  562. }
  563. if (is_lvds && dev_priv->lvds_use_ssc) {
  564. refclk = dev_priv->lvds_ssc_freq * 1000;
  565. DRM_DEBUG_KMS("Use SSC reference clock %d Mhz\n", dev_priv->lvds_ssc_freq);
  566. }
  567. drm_mode_debug_printmodeline(adjusted_mode);
  568. limit = gma_crtc->clock_funcs->limit(crtc, refclk);
  569. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk,
  570. &clock);
  571. if (!ok) {
  572. DRM_ERROR("Couldn't find PLL settings for mode! target: %d, actual: %d",
  573. adjusted_mode->clock, clock.dot);
  574. return 0;
  575. }
  576. dpll = DPLL_VGA_MODE_DIS;
  577. if (is_dp || is_edp) {
  578. cdv_intel_dp_set_m_n(crtc, mode, adjusted_mode);
  579. } else {
  580. REG_WRITE(PIPE_GMCH_DATA_M(pipe), 0);
  581. REG_WRITE(PIPE_GMCH_DATA_N(pipe), 0);
  582. REG_WRITE(PIPE_DP_LINK_M(pipe), 0);
  583. REG_WRITE(PIPE_DP_LINK_N(pipe), 0);
  584. }
  585. dpll |= DPLL_SYNCLOCK_ENABLE;
  586. /* if (is_lvds)
  587. dpll |= DPLLB_MODE_LVDS;
  588. else
  589. dpll |= DPLLB_MODE_DAC_SERIAL; */
  590. /* dpll |= (2 << 11); */
  591. /* setup pipeconf */
  592. pipeconf = REG_READ(map->conf);
  593. pipeconf &= ~(PIPE_BPC_MASK);
  594. if (is_edp) {
  595. switch (dev_priv->edp.bpp) {
  596. case 24:
  597. pipeconf |= PIPE_8BPC;
  598. break;
  599. case 18:
  600. pipeconf |= PIPE_6BPC;
  601. break;
  602. case 30:
  603. pipeconf |= PIPE_10BPC;
  604. break;
  605. default:
  606. pipeconf |= PIPE_8BPC;
  607. break;
  608. }
  609. } else if (is_lvds) {
  610. /* the BPC will be 6 if it is 18-bit LVDS panel */
  611. if ((REG_READ(LVDS) & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP)
  612. pipeconf |= PIPE_8BPC;
  613. else
  614. pipeconf |= PIPE_6BPC;
  615. } else
  616. pipeconf |= PIPE_8BPC;
  617. /* Set up the display plane register */
  618. dspcntr = DISPPLANE_GAMMA_ENABLE;
  619. if (pipe == 0)
  620. dspcntr |= DISPPLANE_SEL_PIPE_A;
  621. else
  622. dspcntr |= DISPPLANE_SEL_PIPE_B;
  623. dspcntr |= DISPLAY_PLANE_ENABLE;
  624. pipeconf |= PIPEACONF_ENABLE;
  625. REG_WRITE(map->dpll, dpll | DPLL_VGA_MODE_DIS | DPLL_SYNCLOCK_ENABLE);
  626. REG_READ(map->dpll);
  627. cdv_dpll_set_clock_cdv(dev, crtc, &clock, is_lvds, ddi_select);
  628. udelay(150);
  629. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  630. * This is an exception to the general rule that mode_set doesn't turn
  631. * things on.
  632. */
  633. if (is_lvds) {
  634. u32 lvds = REG_READ(LVDS);
  635. lvds |=
  636. LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP |
  637. LVDS_PIPEB_SELECT;
  638. /* Set the B0-B3 data pairs corresponding to
  639. * whether we're going to
  640. * set the DPLLs for dual-channel mode or not.
  641. */
  642. if (clock.p2 == 7)
  643. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  644. else
  645. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  646. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  647. * appropriately here, but we need to look more
  648. * thoroughly into how panels behave in the two modes.
  649. */
  650. REG_WRITE(LVDS, lvds);
  651. REG_READ(LVDS);
  652. }
  653. dpll |= DPLL_VCO_ENABLE;
  654. /* Disable the panel fitter if it was on our pipe */
  655. if (cdv_intel_panel_fitter_pipe(dev) == pipe)
  656. REG_WRITE(PFIT_CONTROL, 0);
  657. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  658. drm_mode_debug_printmodeline(mode);
  659. REG_WRITE(map->dpll,
  660. (REG_READ(map->dpll) & ~DPLL_LOCK) | DPLL_VCO_ENABLE);
  661. REG_READ(map->dpll);
  662. /* Wait for the clocks to stabilize. */
  663. udelay(150); /* 42 usec w/o calibration, 110 with. rounded up. */
  664. if (!(REG_READ(map->dpll) & DPLL_LOCK)) {
  665. dev_err(dev->dev, "Failed to get DPLL lock\n");
  666. return -EBUSY;
  667. }
  668. {
  669. int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  670. REG_WRITE(map->dpll_md, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) | ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT));
  671. }
  672. REG_WRITE(map->htotal, (adjusted_mode->crtc_hdisplay - 1) |
  673. ((adjusted_mode->crtc_htotal - 1) << 16));
  674. REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start - 1) |
  675. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  676. REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start - 1) |
  677. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  678. REG_WRITE(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) |
  679. ((adjusted_mode->crtc_vtotal - 1) << 16));
  680. REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start - 1) |
  681. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  682. REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start - 1) |
  683. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  684. /* pipesrc and dspsize control the size that is scaled from,
  685. * which should always be the user's requested size.
  686. */
  687. REG_WRITE(map->size,
  688. ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  689. REG_WRITE(map->pos, 0);
  690. REG_WRITE(map->src,
  691. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  692. REG_WRITE(map->conf, pipeconf);
  693. REG_READ(map->conf);
  694. gma_wait_for_vblank(dev);
  695. REG_WRITE(map->cntr, dspcntr);
  696. /* Flush the plane changes */
  697. {
  698. const struct drm_crtc_helper_funcs *crtc_funcs =
  699. crtc->helper_private;
  700. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  701. }
  702. gma_wait_for_vblank(dev);
  703. return 0;
  704. }
  705. /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
  706. /* FIXME: why are we using this, should it be cdv_ in this tree ? */
  707. static void i8xx_clock(int refclk, struct gma_clock_t *clock)
  708. {
  709. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  710. clock->p = clock->p1 * clock->p2;
  711. clock->vco = refclk * clock->m / (clock->n + 2);
  712. clock->dot = clock->vco / clock->p;
  713. }
  714. /* Returns the clock of the currently programmed mode of the given pipe. */
  715. static int cdv_intel_crtc_clock_get(struct drm_device *dev,
  716. struct drm_crtc *crtc)
  717. {
  718. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  719. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  720. int pipe = gma_crtc->pipe;
  721. const struct psb_offset *map = &dev_priv->regmap[pipe];
  722. u32 dpll;
  723. u32 fp;
  724. struct gma_clock_t clock;
  725. bool is_lvds;
  726. struct psb_pipe *p = &dev_priv->regs.pipe[pipe];
  727. if (gma_power_begin(dev, false)) {
  728. dpll = REG_READ(map->dpll);
  729. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  730. fp = REG_READ(map->fp0);
  731. else
  732. fp = REG_READ(map->fp1);
  733. is_lvds = (pipe == 1) && (REG_READ(LVDS) & LVDS_PORT_EN);
  734. gma_power_end(dev);
  735. } else {
  736. dpll = p->dpll;
  737. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  738. fp = p->fp0;
  739. else
  740. fp = p->fp1;
  741. is_lvds = (pipe == 1) &&
  742. (dev_priv->regs.psb.saveLVDS & LVDS_PORT_EN);
  743. }
  744. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  745. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  746. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  747. if (is_lvds) {
  748. clock.p1 =
  749. ffs((dpll &
  750. DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  751. DPLL_FPA01_P1_POST_DIV_SHIFT);
  752. if (clock.p1 == 0) {
  753. clock.p1 = 4;
  754. dev_err(dev->dev, "PLL %d\n", dpll);
  755. }
  756. clock.p2 = 14;
  757. if ((dpll & PLL_REF_INPUT_MASK) ==
  758. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  759. /* XXX: might not be 66MHz */
  760. i8xx_clock(66000, &clock);
  761. } else
  762. i8xx_clock(48000, &clock);
  763. } else {
  764. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  765. clock.p1 = 2;
  766. else {
  767. clock.p1 =
  768. ((dpll &
  769. DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  770. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  771. }
  772. if (dpll & PLL_P2_DIVIDE_BY_4)
  773. clock.p2 = 4;
  774. else
  775. clock.p2 = 2;
  776. i8xx_clock(48000, &clock);
  777. }
  778. /* XXX: It would be nice to validate the clocks, but we can't reuse
  779. * i830PllIsValid() because it relies on the xf86_config connector
  780. * configuration being accurate, which it isn't necessarily.
  781. */
  782. return clock.dot;
  783. }
  784. /** Returns the currently programmed mode of the given pipe. */
  785. struct drm_display_mode *cdv_intel_crtc_mode_get(struct drm_device *dev,
  786. struct drm_crtc *crtc)
  787. {
  788. struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
  789. int pipe = gma_crtc->pipe;
  790. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  791. struct psb_pipe *p = &dev_priv->regs.pipe[pipe];
  792. const struct psb_offset *map = &dev_priv->regmap[pipe];
  793. struct drm_display_mode *mode;
  794. int htot;
  795. int hsync;
  796. int vtot;
  797. int vsync;
  798. if (gma_power_begin(dev, false)) {
  799. htot = REG_READ(map->htotal);
  800. hsync = REG_READ(map->hsync);
  801. vtot = REG_READ(map->vtotal);
  802. vsync = REG_READ(map->vsync);
  803. gma_power_end(dev);
  804. } else {
  805. htot = p->htotal;
  806. hsync = p->hsync;
  807. vtot = p->vtotal;
  808. vsync = p->vsync;
  809. }
  810. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  811. if (!mode)
  812. return NULL;
  813. mode->clock = cdv_intel_crtc_clock_get(dev, crtc);
  814. mode->hdisplay = (htot & 0xffff) + 1;
  815. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  816. mode->hsync_start = (hsync & 0xffff) + 1;
  817. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  818. mode->vdisplay = (vtot & 0xffff) + 1;
  819. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  820. mode->vsync_start = (vsync & 0xffff) + 1;
  821. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  822. drm_mode_set_name(mode);
  823. drm_mode_set_crtcinfo(mode, 0);
  824. return mode;
  825. }
  826. const struct drm_crtc_helper_funcs cdv_intel_helper_funcs = {
  827. .dpms = gma_crtc_dpms,
  828. .mode_set = cdv_intel_crtc_mode_set,
  829. .mode_set_base = gma_pipe_set_base,
  830. .prepare = gma_crtc_prepare,
  831. .commit = gma_crtc_commit,
  832. .disable = gma_crtc_disable,
  833. };
  834. const struct gma_clock_funcs cdv_clock_funcs = {
  835. .clock = cdv_intel_clock,
  836. .limit = cdv_intel_limit,
  837. .pll_is_valid = gma_pll_is_valid,
  838. };