cdv_intel_display.c 26 KB

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