cdv_intel_display.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653
  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 <linux/pm_runtime.h>
  22. #include <drm/drmP.h>
  23. #include "framebuffer.h"
  24. #include "psb_drv.h"
  25. #include "psb_intel_drv.h"
  26. #include "psb_intel_reg.h"
  27. #include "psb_intel_display.h"
  28. #include "power.h"
  29. #include "cdv_device.h"
  30. struct cdv_intel_range_t {
  31. int min, max;
  32. };
  33. struct cdv_intel_p2_t {
  34. int dot_limit;
  35. int p2_slow, p2_fast;
  36. };
  37. struct cdv_intel_clock_t {
  38. /* given values */
  39. int n;
  40. int m1, m2;
  41. int p1, p2;
  42. /* derived values */
  43. int dot;
  44. int vco;
  45. int m;
  46. int p;
  47. };
  48. #define INTEL_P2_NUM 2
  49. struct cdv_intel_limit_t {
  50. struct cdv_intel_range_t dot, vco, n, m, m1, m2, p, p1;
  51. struct cdv_intel_p2_t p2;
  52. };
  53. #define CDV_LIMIT_SINGLE_LVDS_96 0
  54. #define CDV_LIMIT_SINGLE_LVDS_100 1
  55. #define CDV_LIMIT_DAC_HDMI_27 2
  56. #define CDV_LIMIT_DAC_HDMI_96 3
  57. static const struct cdv_intel_limit_t cdv_intel_limits[] = {
  58. { /* CDV_SIGNLE_LVDS_96MHz */
  59. .dot = {.min = 20000, .max = 115500},
  60. .vco = {.min = 1800000, .max = 3600000},
  61. .n = {.min = 2, .max = 6},
  62. .m = {.min = 60, .max = 160},
  63. .m1 = {.min = 0, .max = 0},
  64. .m2 = {.min = 58, .max = 158},
  65. .p = {.min = 28, .max = 140},
  66. .p1 = {.min = 2, .max = 10},
  67. .p2 = {.dot_limit = 200000,
  68. .p2_slow = 14, .p2_fast = 14},
  69. },
  70. { /* CDV_SINGLE_LVDS_100MHz */
  71. .dot = {.min = 20000, .max = 115500},
  72. .vco = {.min = 1800000, .max = 3600000},
  73. .n = {.min = 2, .max = 6},
  74. .m = {.min = 60, .max = 160},
  75. .m1 = {.min = 0, .max = 0},
  76. .m2 = {.min = 58, .max = 158},
  77. .p = {.min = 28, .max = 140},
  78. .p1 = {.min = 2, .max = 10},
  79. /* The single-channel range is 25-112Mhz, and dual-channel
  80. * is 80-224Mhz. Prefer single channel as much as possible.
  81. */
  82. .p2 = {.dot_limit = 200000, .p2_slow = 14, .p2_fast = 14},
  83. },
  84. { /* CDV_DAC_HDMI_27MHz */
  85. .dot = {.min = 20000, .max = 400000},
  86. .vco = {.min = 1809000, .max = 3564000},
  87. .n = {.min = 1, .max = 1},
  88. .m = {.min = 67, .max = 132},
  89. .m1 = {.min = 0, .max = 0},
  90. .m2 = {.min = 65, .max = 130},
  91. .p = {.min = 5, .max = 90},
  92. .p1 = {.min = 1, .max = 9},
  93. .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 5},
  94. },
  95. { /* CDV_DAC_HDMI_96MHz */
  96. .dot = {.min = 20000, .max = 400000},
  97. .vco = {.min = 1800000, .max = 3600000},
  98. .n = {.min = 2, .max = 6},
  99. .m = {.min = 60, .max = 160},
  100. .m1 = {.min = 0, .max = 0},
  101. .m2 = {.min = 58, .max = 158},
  102. .p = {.min = 5, .max = 100},
  103. .p1 = {.min = 1, .max = 10},
  104. .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 5},
  105. },
  106. };
  107. #define _wait_for(COND, MS, W) ({ \
  108. unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
  109. int ret__ = 0; \
  110. while (!(COND)) { \
  111. if (time_after(jiffies, timeout__)) { \
  112. ret__ = -ETIMEDOUT; \
  113. break; \
  114. } \
  115. if (W && !in_dbg_master()) \
  116. msleep(W); \
  117. } \
  118. ret__; \
  119. })
  120. #define wait_for(COND, MS) _wait_for(COND, MS, 1)
  121. static int cdv_sb_read(struct drm_device *dev, u32 reg, u32 *val)
  122. {
  123. int ret;
  124. ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000);
  125. if (ret) {
  126. DRM_ERROR("timeout waiting for SB to idle before read\n");
  127. return ret;
  128. }
  129. REG_WRITE(SB_ADDR, reg);
  130. REG_WRITE(SB_PCKT,
  131. SET_FIELD(SB_OPCODE_READ, SB_OPCODE) |
  132. SET_FIELD(SB_DEST_DPLL, SB_DEST) |
  133. SET_FIELD(0xf, SB_BYTE_ENABLE));
  134. ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000);
  135. if (ret) {
  136. DRM_ERROR("timeout waiting for SB to idle after read\n");
  137. return ret;
  138. }
  139. *val = REG_READ(SB_DATA);
  140. return 0;
  141. }
  142. static int cdv_sb_write(struct drm_device *dev, u32 reg, u32 val)
  143. {
  144. int ret;
  145. static bool dpio_debug = true;
  146. u32 temp;
  147. if (dpio_debug) {
  148. if (cdv_sb_read(dev, reg, &temp) == 0)
  149. DRM_DEBUG_KMS("0x%08x: 0x%08x (before)\n", reg, temp);
  150. DRM_DEBUG_KMS("0x%08x: 0x%08x\n", reg, val);
  151. }
  152. ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000);
  153. if (ret) {
  154. DRM_ERROR("timeout waiting for SB to idle before write\n");
  155. return ret;
  156. }
  157. REG_WRITE(SB_ADDR, reg);
  158. REG_WRITE(SB_DATA, val);
  159. REG_WRITE(SB_PCKT,
  160. SET_FIELD(SB_OPCODE_WRITE, SB_OPCODE) |
  161. SET_FIELD(SB_DEST_DPLL, SB_DEST) |
  162. SET_FIELD(0xf, SB_BYTE_ENABLE));
  163. ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000);
  164. if (ret) {
  165. DRM_ERROR("timeout waiting for SB to idle after write\n");
  166. return ret;
  167. }
  168. if (dpio_debug) {
  169. if (cdv_sb_read(dev, reg, &temp) == 0)
  170. DRM_DEBUG_KMS("0x%08x: 0x%08x (after)\n", reg, temp);
  171. }
  172. return 0;
  173. }
  174. /* Reset the DPIO configuration register. The BIOS does this at every
  175. * mode set.
  176. */
  177. static void cdv_sb_reset(struct drm_device *dev)
  178. {
  179. REG_WRITE(DPIO_CFG, 0);
  180. REG_READ(DPIO_CFG);
  181. REG_WRITE(DPIO_CFG, DPIO_MODE_SELECT_0 | DPIO_CMN_RESET_N);
  182. }
  183. /* Unlike most Intel display engines, on Cedarview the DPLL registers
  184. * are behind this sideband bus. They must be programmed while the
  185. * DPLL reference clock is on in the DPLL control register, but before
  186. * the DPLL is enabled in the DPLL control register.
  187. */
  188. static int
  189. cdv_dpll_set_clock_cdv(struct drm_device *dev, struct drm_crtc *crtc,
  190. struct cdv_intel_clock_t *clock, bool is_lvds)
  191. {
  192. struct psb_intel_crtc *psb_crtc =
  193. to_psb_intel_crtc(crtc);
  194. int pipe = psb_crtc->pipe;
  195. u32 m, n_vco, p;
  196. int ret = 0;
  197. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  198. int ref_sfr = (pipe == 0) ? SB_REF_DPLLA : SB_REF_DPLLB;
  199. u32 ref_value;
  200. u32 lane_reg, lane_value;
  201. cdv_sb_reset(dev);
  202. REG_WRITE(dpll_reg, DPLL_SYNCLOCK_ENABLE | DPLL_VGA_MODE_DIS);
  203. udelay(100);
  204. /* Follow the BIOS and write the REF/SFR Register. Hardcoded value */
  205. ref_value = 0x68A701;
  206. cdv_sb_write(dev, SB_REF_SFR(pipe), ref_value);
  207. /* We don't know what the other fields of these regs are, so
  208. * leave them in place.
  209. */
  210. /*
  211. * The BIT 14:13 of 0x8010/0x8030 is used to select the ref clk
  212. * for the pipe A/B. Display spec 1.06 has wrong definition.
  213. * Correct definition is like below:
  214. *
  215. * refclka mean use clock from same PLL
  216. *
  217. * if DPLLA sets 01 and DPLLB sets 01, they use clock from their pll
  218. *
  219. * if DPLLA sets 01 and DPLLB sets 02, both use clk from DPLLA
  220. *
  221. */
  222. ret = cdv_sb_read(dev, ref_sfr, &ref_value);
  223. if (ret)
  224. return ret;
  225. ref_value &= ~(REF_CLK_MASK);
  226. /* use DPLL_A for pipeB on CRT/HDMI */
  227. if (pipe == 1 && !is_lvds) {
  228. DRM_DEBUG_KMS("use DPLLA for pipe B\n");
  229. ref_value |= REF_CLK_DPLLA;
  230. } else {
  231. DRM_DEBUG_KMS("use their DPLL for pipe A/B\n");
  232. ref_value |= REF_CLK_DPLL;
  233. }
  234. ret = cdv_sb_write(dev, ref_sfr, ref_value);
  235. if (ret)
  236. return ret;
  237. ret = cdv_sb_read(dev, SB_M(pipe), &m);
  238. if (ret)
  239. return ret;
  240. m &= ~SB_M_DIVIDER_MASK;
  241. m |= ((clock->m2) << SB_M_DIVIDER_SHIFT);
  242. ret = cdv_sb_write(dev, SB_M(pipe), m);
  243. if (ret)
  244. return ret;
  245. ret = cdv_sb_read(dev, SB_N_VCO(pipe), &n_vco);
  246. if (ret)
  247. return ret;
  248. /* Follow the BIOS to program the N_DIVIDER REG */
  249. n_vco &= 0xFFFF;
  250. n_vco |= 0x107;
  251. n_vco &= ~(SB_N_VCO_SEL_MASK |
  252. SB_N_DIVIDER_MASK |
  253. SB_N_CB_TUNE_MASK);
  254. n_vco |= ((clock->n) << SB_N_DIVIDER_SHIFT);
  255. if (clock->vco < 2250000) {
  256. n_vco |= (2 << SB_N_CB_TUNE_SHIFT);
  257. n_vco |= (0 << SB_N_VCO_SEL_SHIFT);
  258. } else if (clock->vco < 2750000) {
  259. n_vco |= (1 << SB_N_CB_TUNE_SHIFT);
  260. n_vco |= (1 << SB_N_VCO_SEL_SHIFT);
  261. } else if (clock->vco < 3300000) {
  262. n_vco |= (0 << SB_N_CB_TUNE_SHIFT);
  263. n_vco |= (2 << SB_N_VCO_SEL_SHIFT);
  264. } else {
  265. n_vco |= (0 << SB_N_CB_TUNE_SHIFT);
  266. n_vco |= (3 << SB_N_VCO_SEL_SHIFT);
  267. }
  268. ret = cdv_sb_write(dev, SB_N_VCO(pipe), n_vco);
  269. if (ret)
  270. return ret;
  271. ret = cdv_sb_read(dev, SB_P(pipe), &p);
  272. if (ret)
  273. return ret;
  274. p &= ~(SB_P2_DIVIDER_MASK | SB_P1_DIVIDER_MASK);
  275. p |= SET_FIELD(clock->p1, SB_P1_DIVIDER);
  276. switch (clock->p2) {
  277. case 5:
  278. p |= SET_FIELD(SB_P2_5, SB_P2_DIVIDER);
  279. break;
  280. case 10:
  281. p |= SET_FIELD(SB_P2_10, SB_P2_DIVIDER);
  282. break;
  283. case 14:
  284. p |= SET_FIELD(SB_P2_14, SB_P2_DIVIDER);
  285. break;
  286. case 7:
  287. p |= SET_FIELD(SB_P2_7, SB_P2_DIVIDER);
  288. break;
  289. default:
  290. DRM_ERROR("Bad P2 clock: %d\n", clock->p2);
  291. return -EINVAL;
  292. }
  293. ret = cdv_sb_write(dev, SB_P(pipe), p);
  294. if (ret)
  295. return ret;
  296. lane_reg = PSB_LANE0;
  297. cdv_sb_read(dev, lane_reg, &lane_value);
  298. lane_value &= ~(LANE_PLL_MASK);
  299. lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe);
  300. cdv_sb_write(dev, lane_reg, lane_value);
  301. lane_reg = PSB_LANE1;
  302. cdv_sb_read(dev, lane_reg, &lane_value);
  303. lane_value &= ~(LANE_PLL_MASK);
  304. lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe);
  305. cdv_sb_write(dev, lane_reg, lane_value);
  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. return 0;
  317. }
  318. /*
  319. * Returns whether any encoder on the specified pipe is of the specified type
  320. */
  321. static bool cdv_intel_pipe_has_type(struct drm_crtc *crtc, int type)
  322. {
  323. struct drm_device *dev = crtc->dev;
  324. struct drm_mode_config *mode_config = &dev->mode_config;
  325. struct drm_connector *l_entry;
  326. list_for_each_entry(l_entry, &mode_config->connector_list, head) {
  327. if (l_entry->encoder && l_entry->encoder->crtc == crtc) {
  328. struct psb_intel_encoder *psb_intel_encoder =
  329. psb_intel_attached_encoder(l_entry);
  330. if (psb_intel_encoder->type == type)
  331. return true;
  332. }
  333. }
  334. return false;
  335. }
  336. static const struct cdv_intel_limit_t *cdv_intel_limit(struct drm_crtc *crtc,
  337. int refclk)
  338. {
  339. const struct cdv_intel_limit_t *limit;
  340. if (cdv_intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  341. /*
  342. * Now only single-channel LVDS is supported on CDV. If it is
  343. * incorrect, please add the dual-channel LVDS.
  344. */
  345. if (refclk == 96000)
  346. limit = &cdv_intel_limits[CDV_LIMIT_SINGLE_LVDS_96];
  347. else
  348. limit = &cdv_intel_limits[CDV_LIMIT_SINGLE_LVDS_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(struct drm_device *dev,
  359. int refclk, struct cdv_intel_clock_t *clock)
  360. {
  361. clock->m = clock->m2 + 2;
  362. clock->p = clock->p1 * clock->p2;
  363. clock->vco = (refclk * clock->m) / clock->n;
  364. clock->dot = clock->vco / clock->p;
  365. }
  366. #define INTELPllInvalid(s) { /* ErrorF (s) */; return false; }
  367. static bool cdv_intel_PLL_is_valid(struct drm_crtc *crtc,
  368. const struct cdv_intel_limit_t *limit,
  369. struct cdv_intel_clock_t *clock)
  370. {
  371. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  372. INTELPllInvalid("p1 out of range\n");
  373. if (clock->p < limit->p.min || limit->p.max < clock->p)
  374. INTELPllInvalid("p out of range\n");
  375. /* unnecessary to check the range of m(m1/M2)/n again */
  376. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  377. INTELPllInvalid("vco out of range\n");
  378. /* XXX: We may need to be checking "Dot clock"
  379. * depending on the multiplier, connector, etc.,
  380. * rather than just a single range.
  381. */
  382. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  383. INTELPllInvalid("dot out of range\n");
  384. return true;
  385. }
  386. static bool cdv_intel_find_best_PLL(struct drm_crtc *crtc, int target,
  387. int refclk,
  388. struct cdv_intel_clock_t *best_clock)
  389. {
  390. struct drm_device *dev = crtc->dev;
  391. struct cdv_intel_clock_t clock;
  392. const struct cdv_intel_limit_t *limit = cdv_intel_limit(crtc, refclk);
  393. int err = target;
  394. if (cdv_intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  395. (REG_READ(LVDS) & LVDS_PORT_EN) != 0) {
  396. /*
  397. * For LVDS, if the panel is on, just rely on its current
  398. * settings for dual-channel. We haven't figured out how to
  399. * reliably set up different single/dual channel state, if we
  400. * even can.
  401. */
  402. if ((REG_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  403. LVDS_CLKB_POWER_UP)
  404. clock.p2 = limit->p2.p2_fast;
  405. else
  406. clock.p2 = limit->p2.p2_slow;
  407. } else {
  408. if (target < limit->p2.dot_limit)
  409. clock.p2 = limit->p2.p2_slow;
  410. else
  411. clock.p2 = limit->p2.p2_fast;
  412. }
  413. memset(best_clock, 0, sizeof(*best_clock));
  414. clock.m1 = 0;
  415. /* m1 is reserved as 0 in CDV, n is a ring counter.
  416. So skip the m1 loop */
  417. for (clock.n = limit->n.min; clock.n <= limit->n.max; clock.n++) {
  418. for (clock.m2 = limit->m2.min; clock.m2 <= limit->m2.max;
  419. clock.m2++) {
  420. for (clock.p1 = limit->p1.min;
  421. clock.p1 <= limit->p1.max;
  422. clock.p1++) {
  423. int this_err;
  424. cdv_intel_clock(dev, refclk, &clock);
  425. if (!cdv_intel_PLL_is_valid(crtc,
  426. limit, &clock))
  427. continue;
  428. this_err = abs(clock.dot - target);
  429. if (this_err < err) {
  430. *best_clock = clock;
  431. err = this_err;
  432. }
  433. }
  434. }
  435. }
  436. return err != target;
  437. }
  438. static int cdv_intel_pipe_set_base(struct drm_crtc *crtc,
  439. int x, int y, struct drm_framebuffer *old_fb)
  440. {
  441. struct drm_device *dev = crtc->dev;
  442. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  443. struct psb_framebuffer *psbfb = to_psb_fb(crtc->fb);
  444. int pipe = psb_intel_crtc->pipe;
  445. unsigned long start, offset;
  446. int dspbase = (pipe == 0 ? DSPABASE : DSPBBASE);
  447. int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF);
  448. int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE;
  449. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  450. u32 dspcntr;
  451. int ret = 0;
  452. if (!gma_power_begin(dev, true))
  453. return 0;
  454. /* no fb bound */
  455. if (!crtc->fb) {
  456. dev_err(dev->dev, "No FB bound\n");
  457. goto psb_intel_pipe_cleaner;
  458. }
  459. /* We are displaying this buffer, make sure it is actually loaded
  460. into the GTT */
  461. ret = psb_gtt_pin(psbfb->gtt);
  462. if (ret < 0)
  463. goto psb_intel_pipe_set_base_exit;
  464. start = psbfb->gtt->offset;
  465. offset = y * crtc->fb->pitches[0] + x * (crtc->fb->bits_per_pixel / 8);
  466. REG_WRITE(dspstride, crtc->fb->pitches[0]);
  467. dspcntr = REG_READ(dspcntr_reg);
  468. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  469. switch (crtc->fb->bits_per_pixel) {
  470. case 8:
  471. dspcntr |= DISPPLANE_8BPP;
  472. break;
  473. case 16:
  474. if (crtc->fb->depth == 15)
  475. dspcntr |= DISPPLANE_15_16BPP;
  476. else
  477. dspcntr |= DISPPLANE_16BPP;
  478. break;
  479. case 24:
  480. case 32:
  481. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  482. break;
  483. default:
  484. dev_err(dev->dev, "Unknown color depth\n");
  485. ret = -EINVAL;
  486. goto psb_intel_pipe_set_base_exit;
  487. }
  488. REG_WRITE(dspcntr_reg, dspcntr);
  489. dev_dbg(dev->dev,
  490. "Writing base %08lX %08lX %d %d\n", start, offset, x, y);
  491. REG_WRITE(dspbase, offset);
  492. REG_READ(dspbase);
  493. REG_WRITE(dspsurf, start);
  494. REG_READ(dspsurf);
  495. psb_intel_pipe_cleaner:
  496. /* If there was a previous display we can now unpin it */
  497. if (old_fb)
  498. psb_gtt_unpin(to_psb_fb(old_fb)->gtt);
  499. psb_intel_pipe_set_base_exit:
  500. gma_power_end(dev);
  501. return ret;
  502. }
  503. #define FIFO_PIPEA (1 << 0)
  504. #define FIFO_PIPEB (1 << 1)
  505. static bool cdv_intel_pipe_enabled(struct drm_device *dev, int pipe)
  506. {
  507. struct drm_crtc *crtc;
  508. struct drm_psb_private *dev_priv = dev->dev_private;
  509. struct psb_intel_crtc *psb_intel_crtc = NULL;
  510. crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  511. psb_intel_crtc = to_psb_intel_crtc(crtc);
  512. if (crtc->fb == NULL || !psb_intel_crtc->active)
  513. return false;
  514. return true;
  515. }
  516. static bool cdv_intel_single_pipe_active (struct drm_device *dev)
  517. {
  518. uint32_t pipe_enabled = 0;
  519. if (cdv_intel_pipe_enabled(dev, 0))
  520. pipe_enabled |= FIFO_PIPEA;
  521. if (cdv_intel_pipe_enabled(dev, 1))
  522. pipe_enabled |= FIFO_PIPEB;
  523. DRM_DEBUG_KMS("pipe enabled %x\n", pipe_enabled);
  524. if (pipe_enabled == FIFO_PIPEA || pipe_enabled == FIFO_PIPEB)
  525. return true;
  526. else
  527. return false;
  528. }
  529. static bool is_pipeb_lvds(struct drm_device *dev, struct drm_crtc *crtc)
  530. {
  531. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  532. struct drm_mode_config *mode_config = &dev->mode_config;
  533. struct drm_connector *connector;
  534. if (psb_intel_crtc->pipe != 1)
  535. return false;
  536. list_for_each_entry(connector, &mode_config->connector_list, head) {
  537. struct psb_intel_encoder *psb_intel_encoder =
  538. psb_intel_attached_encoder(connector);
  539. if (!connector->encoder
  540. || connector->encoder->crtc != crtc)
  541. continue;
  542. if (psb_intel_encoder->type == INTEL_OUTPUT_LVDS)
  543. return true;
  544. }
  545. return false;
  546. }
  547. static void cdv_intel_disable_self_refresh (struct drm_device *dev)
  548. {
  549. if (REG_READ(FW_BLC_SELF) & FW_BLC_SELF_EN) {
  550. /* Disable self-refresh before adjust WM */
  551. REG_WRITE(FW_BLC_SELF, (REG_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN));
  552. REG_READ(FW_BLC_SELF);
  553. cdv_intel_wait_for_vblank(dev);
  554. /* Cedarview workaround to write ovelay plane, which force to leave
  555. * MAX_FIFO state.
  556. */
  557. REG_WRITE(OV_OVADD, 0/*dev_priv->ovl_offset*/);
  558. REG_READ(OV_OVADD);
  559. cdv_intel_wait_for_vblank(dev);
  560. }
  561. }
  562. static void cdv_intel_update_watermark (struct drm_device *dev, struct drm_crtc *crtc)
  563. {
  564. if (cdv_intel_single_pipe_active(dev)) {
  565. u32 fw;
  566. fw = REG_READ(DSPFW1);
  567. fw &= ~DSP_FIFO_SR_WM_MASK;
  568. fw |= (0x7e << DSP_FIFO_SR_WM_SHIFT);
  569. fw &= ~CURSOR_B_FIFO_WM_MASK;
  570. fw |= (0x4 << CURSOR_B_FIFO_WM_SHIFT);
  571. REG_WRITE(DSPFW1, fw);
  572. fw = REG_READ(DSPFW2);
  573. fw &= ~CURSOR_A_FIFO_WM_MASK;
  574. fw |= (0x6 << CURSOR_A_FIFO_WM_SHIFT);
  575. fw &= ~DSP_PLANE_C_FIFO_WM_MASK;
  576. fw |= (0x8 << DSP_PLANE_C_FIFO_WM_SHIFT);
  577. REG_WRITE(DSPFW2, fw);
  578. REG_WRITE(DSPFW3, 0x36000000);
  579. /* ignore FW4 */
  580. if (is_pipeb_lvds(dev, crtc)) {
  581. REG_WRITE(DSPFW5, 0x00040330);
  582. } else {
  583. fw = (3 << DSP_PLANE_B_FIFO_WM1_SHIFT) |
  584. (4 << DSP_PLANE_A_FIFO_WM1_SHIFT) |
  585. (3 << CURSOR_B_FIFO_WM1_SHIFT) |
  586. (4 << CURSOR_FIFO_SR_WM1_SHIFT);
  587. REG_WRITE(DSPFW5, fw);
  588. }
  589. REG_WRITE(DSPFW6, 0x10);
  590. cdv_intel_wait_for_vblank(dev);
  591. /* enable self-refresh for single pipe active */
  592. REG_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  593. REG_READ(FW_BLC_SELF);
  594. cdv_intel_wait_for_vblank(dev);
  595. } else {
  596. /* HW team suggested values... */
  597. REG_WRITE(DSPFW1, 0x3f880808);
  598. REG_WRITE(DSPFW2, 0x0b020202);
  599. REG_WRITE(DSPFW3, 0x24000000);
  600. REG_WRITE(DSPFW4, 0x08030202);
  601. REG_WRITE(DSPFW5, 0x01010101);
  602. REG_WRITE(DSPFW6, 0x1d0);
  603. cdv_intel_wait_for_vblank(dev);
  604. cdv_intel_disable_self_refresh(dev);
  605. }
  606. }
  607. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  608. static void cdv_intel_crtc_load_lut(struct drm_crtc *crtc)
  609. {
  610. struct drm_device *dev = crtc->dev;
  611. struct drm_psb_private *dev_priv =
  612. (struct drm_psb_private *)dev->dev_private;
  613. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  614. int palreg = PALETTE_A;
  615. int i;
  616. /* The clocks have to be on to load the palette. */
  617. if (!crtc->enabled)
  618. return;
  619. switch (psb_intel_crtc->pipe) {
  620. case 0:
  621. break;
  622. case 1:
  623. palreg = PALETTE_B;
  624. break;
  625. case 2:
  626. palreg = PALETTE_C;
  627. break;
  628. default:
  629. dev_err(dev->dev, "Illegal Pipe Number.\n");
  630. return;
  631. }
  632. if (gma_power_begin(dev, false)) {
  633. for (i = 0; i < 256; i++) {
  634. REG_WRITE(palreg + 4 * i,
  635. ((psb_intel_crtc->lut_r[i] +
  636. psb_intel_crtc->lut_adj[i]) << 16) |
  637. ((psb_intel_crtc->lut_g[i] +
  638. psb_intel_crtc->lut_adj[i]) << 8) |
  639. (psb_intel_crtc->lut_b[i] +
  640. psb_intel_crtc->lut_adj[i]));
  641. }
  642. gma_power_end(dev);
  643. } else {
  644. for (i = 0; i < 256; i++) {
  645. dev_priv->regs.psb.save_palette_a[i] =
  646. ((psb_intel_crtc->lut_r[i] +
  647. psb_intel_crtc->lut_adj[i]) << 16) |
  648. ((psb_intel_crtc->lut_g[i] +
  649. psb_intel_crtc->lut_adj[i]) << 8) |
  650. (psb_intel_crtc->lut_b[i] +
  651. psb_intel_crtc->lut_adj[i]);
  652. }
  653. }
  654. }
  655. /**
  656. * Sets the power management mode of the pipe and plane.
  657. *
  658. * This code should probably grow support for turning the cursor off and back
  659. * on appropriately at the same time as we're turning the pipe off/on.
  660. */
  661. static void cdv_intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  662. {
  663. struct drm_device *dev = crtc->dev;
  664. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  665. int pipe = psb_intel_crtc->pipe;
  666. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  667. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  668. int dspbase_reg = (pipe == 0) ? DSPABASE : DSPBBASE;
  669. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  670. int pipestat_reg = (pipe == 0) ? PIPEASTAT : PIPEBSTAT;
  671. u32 temp;
  672. /* XXX: When our outputs are all unaware of DPMS modes other than off
  673. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  674. */
  675. cdv_intel_disable_self_refresh(dev);
  676. switch (mode) {
  677. case DRM_MODE_DPMS_ON:
  678. case DRM_MODE_DPMS_STANDBY:
  679. case DRM_MODE_DPMS_SUSPEND:
  680. if (psb_intel_crtc->active)
  681. return;
  682. psb_intel_crtc->active = true;
  683. /* Enable the DPLL */
  684. temp = REG_READ(dpll_reg);
  685. if ((temp & DPLL_VCO_ENABLE) == 0) {
  686. REG_WRITE(dpll_reg, temp);
  687. REG_READ(dpll_reg);
  688. /* Wait for the clocks to stabilize. */
  689. udelay(150);
  690. REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  691. REG_READ(dpll_reg);
  692. /* Wait for the clocks to stabilize. */
  693. udelay(150);
  694. REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  695. REG_READ(dpll_reg);
  696. /* Wait for the clocks to stabilize. */
  697. udelay(150);
  698. }
  699. /* Jim Bish - switch plan and pipe per scott */
  700. /* Enable the plane */
  701. temp = REG_READ(dspcntr_reg);
  702. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  703. REG_WRITE(dspcntr_reg,
  704. temp | DISPLAY_PLANE_ENABLE);
  705. /* Flush the plane changes */
  706. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  707. }
  708. udelay(150);
  709. /* Enable the pipe */
  710. temp = REG_READ(pipeconf_reg);
  711. if ((temp & PIPEACONF_ENABLE) == 0)
  712. REG_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  713. temp = REG_READ(pipestat_reg);
  714. temp &= ~(0xFFFF);
  715. temp |= PIPE_FIFO_UNDERRUN;
  716. REG_WRITE(pipestat_reg, temp);
  717. REG_READ(pipestat_reg);
  718. cdv_intel_update_watermark(dev, crtc);
  719. cdv_intel_crtc_load_lut(crtc);
  720. /* Give the overlay scaler a chance to enable
  721. * if it's on this pipe */
  722. /* psb_intel_crtc_dpms_video(crtc, true); TODO */
  723. psb_intel_crtc->crtc_enable = true;
  724. break;
  725. case DRM_MODE_DPMS_OFF:
  726. if (!psb_intel_crtc->active)
  727. return;
  728. psb_intel_crtc->active = false;
  729. /* Give the overlay scaler a chance to disable
  730. * if it's on this pipe */
  731. /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
  732. /* Disable the VGA plane that we never use */
  733. REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  734. /* Jim Bish - changed pipe/plane here as well. */
  735. drm_vblank_off(dev, pipe);
  736. /* Wait for vblank for the disable to take effect */
  737. cdv_intel_wait_for_vblank(dev);
  738. /* Next, disable display pipes */
  739. temp = REG_READ(pipeconf_reg);
  740. if ((temp & PIPEACONF_ENABLE) != 0) {
  741. REG_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  742. REG_READ(pipeconf_reg);
  743. }
  744. /* Wait for vblank for the disable to take effect. */
  745. cdv_intel_wait_for_vblank(dev);
  746. udelay(150);
  747. /* Disable display plane */
  748. temp = REG_READ(dspcntr_reg);
  749. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  750. REG_WRITE(dspcntr_reg,
  751. temp & ~DISPLAY_PLANE_ENABLE);
  752. /* Flush the plane changes */
  753. REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
  754. REG_READ(dspbase_reg);
  755. }
  756. temp = REG_READ(dpll_reg);
  757. if ((temp & DPLL_VCO_ENABLE) != 0) {
  758. REG_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  759. REG_READ(dpll_reg);
  760. }
  761. /* Wait for the clocks to turn off. */
  762. udelay(150);
  763. cdv_intel_update_watermark(dev, crtc);
  764. psb_intel_crtc->crtc_enable = false;
  765. break;
  766. }
  767. /*Set FIFO Watermarks*/
  768. REG_WRITE(DSPARB, 0x3F3E);
  769. }
  770. static void cdv_intel_crtc_prepare(struct drm_crtc *crtc)
  771. {
  772. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  773. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  774. }
  775. static void cdv_intel_crtc_commit(struct drm_crtc *crtc)
  776. {
  777. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  778. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  779. }
  780. static bool cdv_intel_crtc_mode_fixup(struct drm_crtc *crtc,
  781. struct drm_display_mode *mode,
  782. struct drm_display_mode *adjusted_mode)
  783. {
  784. return true;
  785. }
  786. /**
  787. * Return the pipe currently connected to the panel fitter,
  788. * or -1 if the panel fitter is not present or not in use
  789. */
  790. static int cdv_intel_panel_fitter_pipe(struct drm_device *dev)
  791. {
  792. u32 pfit_control;
  793. pfit_control = REG_READ(PFIT_CONTROL);
  794. /* See if the panel fitter is in use */
  795. if ((pfit_control & PFIT_ENABLE) == 0)
  796. return -1;
  797. return (pfit_control >> 29) & 0x3;
  798. }
  799. static int cdv_intel_crtc_mode_set(struct drm_crtc *crtc,
  800. struct drm_display_mode *mode,
  801. struct drm_display_mode *adjusted_mode,
  802. int x, int y,
  803. struct drm_framebuffer *old_fb)
  804. {
  805. struct drm_device *dev = crtc->dev;
  806. struct drm_psb_private *dev_priv = dev->dev_private;
  807. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  808. int pipe = psb_intel_crtc->pipe;
  809. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  810. int dpll_md_reg = (psb_intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD;
  811. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  812. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  813. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  814. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  815. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  816. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  817. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  818. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  819. int dspsize_reg = (pipe == 0) ? DSPASIZE : DSPBSIZE;
  820. int dsppos_reg = (pipe == 0) ? DSPAPOS : DSPBPOS;
  821. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  822. int refclk;
  823. struct cdv_intel_clock_t clock;
  824. u32 dpll = 0, dspcntr, pipeconf;
  825. bool ok;
  826. bool is_crt = false, is_lvds = false, is_tv = false;
  827. bool is_hdmi = false;
  828. struct drm_mode_config *mode_config = &dev->mode_config;
  829. struct drm_connector *connector;
  830. list_for_each_entry(connector, &mode_config->connector_list, head) {
  831. struct psb_intel_encoder *psb_intel_encoder =
  832. psb_intel_attached_encoder(connector);
  833. if (!connector->encoder
  834. || connector->encoder->crtc != crtc)
  835. continue;
  836. switch (psb_intel_encoder->type) {
  837. case INTEL_OUTPUT_LVDS:
  838. is_lvds = true;
  839. break;
  840. case INTEL_OUTPUT_TVOUT:
  841. is_tv = true;
  842. break;
  843. case INTEL_OUTPUT_ANALOG:
  844. is_crt = true;
  845. break;
  846. case INTEL_OUTPUT_HDMI:
  847. is_hdmi = true;
  848. break;
  849. }
  850. }
  851. if (dev_priv->dplla_96mhz)
  852. /* low-end sku, 96/100 mhz */
  853. refclk = 96000;
  854. else
  855. /* high-end sku, 27/100 mhz */
  856. refclk = 27000;
  857. if (is_lvds && dev_priv->lvds_use_ssc) {
  858. refclk = dev_priv->lvds_ssc_freq * 1000;
  859. DRM_DEBUG_KMS("Use SSC reference clock %d Mhz\n", dev_priv->lvds_ssc_freq);
  860. }
  861. drm_mode_debug_printmodeline(adjusted_mode);
  862. ok = cdv_intel_find_best_PLL(crtc, adjusted_mode->clock, refclk,
  863. &clock);
  864. if (!ok) {
  865. dev_err(dev->dev, "Couldn't find PLL settings for mode!\n");
  866. return 0;
  867. }
  868. dpll = DPLL_VGA_MODE_DIS;
  869. if (is_tv) {
  870. /* XXX: just matching BIOS for now */
  871. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  872. dpll |= 3;
  873. }
  874. /* dpll |= PLL_REF_INPUT_DREFCLK; */
  875. dpll |= DPLL_SYNCLOCK_ENABLE;
  876. /* if (is_lvds)
  877. dpll |= DPLLB_MODE_LVDS;
  878. else
  879. dpll |= DPLLB_MODE_DAC_SERIAL; */
  880. /* dpll |= (2 << 11); */
  881. /* setup pipeconf */
  882. pipeconf = REG_READ(pipeconf_reg);
  883. /* Set up the display plane register */
  884. dspcntr = DISPPLANE_GAMMA_ENABLE;
  885. if (pipe == 0)
  886. dspcntr |= DISPPLANE_SEL_PIPE_A;
  887. else
  888. dspcntr |= DISPPLANE_SEL_PIPE_B;
  889. dspcntr |= DISPLAY_PLANE_ENABLE;
  890. pipeconf |= PIPEACONF_ENABLE;
  891. REG_WRITE(dpll_reg, dpll | DPLL_VGA_MODE_DIS | DPLL_SYNCLOCK_ENABLE);
  892. REG_READ(dpll_reg);
  893. cdv_dpll_set_clock_cdv(dev, crtc, &clock, is_lvds);
  894. udelay(150);
  895. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  896. * This is an exception to the general rule that mode_set doesn't turn
  897. * things on.
  898. */
  899. if (is_lvds) {
  900. u32 lvds = REG_READ(LVDS);
  901. lvds |=
  902. LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP |
  903. LVDS_PIPEB_SELECT;
  904. /* Set the B0-B3 data pairs corresponding to
  905. * whether we're going to
  906. * set the DPLLs for dual-channel mode or not.
  907. */
  908. if (clock.p2 == 7)
  909. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  910. else
  911. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  912. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  913. * appropriately here, but we need to look more
  914. * thoroughly into how panels behave in the two modes.
  915. */
  916. REG_WRITE(LVDS, lvds);
  917. REG_READ(LVDS);
  918. }
  919. dpll |= DPLL_VCO_ENABLE;
  920. /* Disable the panel fitter if it was on our pipe */
  921. if (cdv_intel_panel_fitter_pipe(dev) == pipe)
  922. REG_WRITE(PFIT_CONTROL, 0);
  923. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  924. drm_mode_debug_printmodeline(mode);
  925. REG_WRITE(dpll_reg,
  926. (REG_READ(dpll_reg) & ~DPLL_LOCK) | DPLL_VCO_ENABLE);
  927. REG_READ(dpll_reg);
  928. /* Wait for the clocks to stabilize. */
  929. udelay(150); /* 42 usec w/o calibration, 110 with. rounded up. */
  930. if (!(REG_READ(dpll_reg) & DPLL_LOCK)) {
  931. dev_err(dev->dev, "Failed to get DPLL lock\n");
  932. return -EBUSY;
  933. }
  934. {
  935. int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  936. REG_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) | ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT));
  937. }
  938. REG_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  939. ((adjusted_mode->crtc_htotal - 1) << 16));
  940. REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  941. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  942. REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  943. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  944. REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  945. ((adjusted_mode->crtc_vtotal - 1) << 16));
  946. REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  947. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  948. REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  949. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  950. /* pipesrc and dspsize control the size that is scaled from,
  951. * which should always be the user's requested size.
  952. */
  953. REG_WRITE(dspsize_reg,
  954. ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  955. REG_WRITE(dsppos_reg, 0);
  956. REG_WRITE(pipesrc_reg,
  957. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  958. REG_WRITE(pipeconf_reg, pipeconf);
  959. REG_READ(pipeconf_reg);
  960. cdv_intel_wait_for_vblank(dev);
  961. REG_WRITE(dspcntr_reg, dspcntr);
  962. /* Flush the plane changes */
  963. {
  964. struct drm_crtc_helper_funcs *crtc_funcs =
  965. crtc->helper_private;
  966. crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  967. }
  968. cdv_intel_wait_for_vblank(dev);
  969. return 0;
  970. }
  971. /**
  972. * Save HW states of giving crtc
  973. */
  974. static void cdv_intel_crtc_save(struct drm_crtc *crtc)
  975. {
  976. struct drm_device *dev = crtc->dev;
  977. /* struct drm_psb_private *dev_priv =
  978. (struct drm_psb_private *)dev->dev_private; */
  979. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  980. struct psb_intel_crtc_state *crtc_state = psb_intel_crtc->crtc_state;
  981. int pipeA = (psb_intel_crtc->pipe == 0);
  982. uint32_t paletteReg;
  983. int i;
  984. if (!crtc_state) {
  985. dev_dbg(dev->dev, "No CRTC state found\n");
  986. return;
  987. }
  988. crtc_state->saveDSPCNTR = REG_READ(pipeA ? DSPACNTR : DSPBCNTR);
  989. crtc_state->savePIPECONF = REG_READ(pipeA ? PIPEACONF : PIPEBCONF);
  990. crtc_state->savePIPESRC = REG_READ(pipeA ? PIPEASRC : PIPEBSRC);
  991. crtc_state->saveFP0 = REG_READ(pipeA ? FPA0 : FPB0);
  992. crtc_state->saveFP1 = REG_READ(pipeA ? FPA1 : FPB1);
  993. crtc_state->saveDPLL = REG_READ(pipeA ? DPLL_A : DPLL_B);
  994. crtc_state->saveHTOTAL = REG_READ(pipeA ? HTOTAL_A : HTOTAL_B);
  995. crtc_state->saveHBLANK = REG_READ(pipeA ? HBLANK_A : HBLANK_B);
  996. crtc_state->saveHSYNC = REG_READ(pipeA ? HSYNC_A : HSYNC_B);
  997. crtc_state->saveVTOTAL = REG_READ(pipeA ? VTOTAL_A : VTOTAL_B);
  998. crtc_state->saveVBLANK = REG_READ(pipeA ? VBLANK_A : VBLANK_B);
  999. crtc_state->saveVSYNC = REG_READ(pipeA ? VSYNC_A : VSYNC_B);
  1000. crtc_state->saveDSPSTRIDE = REG_READ(pipeA ? DSPASTRIDE : DSPBSTRIDE);
  1001. /*NOTE: DSPSIZE DSPPOS only for psb*/
  1002. crtc_state->saveDSPSIZE = REG_READ(pipeA ? DSPASIZE : DSPBSIZE);
  1003. crtc_state->saveDSPPOS = REG_READ(pipeA ? DSPAPOS : DSPBPOS);
  1004. crtc_state->saveDSPBASE = REG_READ(pipeA ? DSPABASE : DSPBBASE);
  1005. DRM_DEBUG("(%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
  1006. crtc_state->saveDSPCNTR,
  1007. crtc_state->savePIPECONF,
  1008. crtc_state->savePIPESRC,
  1009. crtc_state->saveFP0,
  1010. crtc_state->saveFP1,
  1011. crtc_state->saveDPLL,
  1012. crtc_state->saveHTOTAL,
  1013. crtc_state->saveHBLANK,
  1014. crtc_state->saveHSYNC,
  1015. crtc_state->saveVTOTAL,
  1016. crtc_state->saveVBLANK,
  1017. crtc_state->saveVSYNC,
  1018. crtc_state->saveDSPSTRIDE,
  1019. crtc_state->saveDSPSIZE,
  1020. crtc_state->saveDSPPOS,
  1021. crtc_state->saveDSPBASE
  1022. );
  1023. paletteReg = pipeA ? PALETTE_A : PALETTE_B;
  1024. for (i = 0; i < 256; ++i)
  1025. crtc_state->savePalette[i] = REG_READ(paletteReg + (i << 2));
  1026. }
  1027. /**
  1028. * Restore HW states of giving crtc
  1029. */
  1030. static void cdv_intel_crtc_restore(struct drm_crtc *crtc)
  1031. {
  1032. struct drm_device *dev = crtc->dev;
  1033. /* struct drm_psb_private * dev_priv =
  1034. (struct drm_psb_private *)dev->dev_private; */
  1035. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  1036. struct psb_intel_crtc_state *crtc_state = psb_intel_crtc->crtc_state;
  1037. /* struct drm_crtc_helper_funcs * crtc_funcs = crtc->helper_private; */
  1038. int pipeA = (psb_intel_crtc->pipe == 0);
  1039. uint32_t paletteReg;
  1040. int i;
  1041. if (!crtc_state) {
  1042. dev_dbg(dev->dev, "No crtc state\n");
  1043. return;
  1044. }
  1045. DRM_DEBUG(
  1046. "current:(%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
  1047. REG_READ(pipeA ? DSPACNTR : DSPBCNTR),
  1048. REG_READ(pipeA ? PIPEACONF : PIPEBCONF),
  1049. REG_READ(pipeA ? PIPEASRC : PIPEBSRC),
  1050. REG_READ(pipeA ? FPA0 : FPB0),
  1051. REG_READ(pipeA ? FPA1 : FPB1),
  1052. REG_READ(pipeA ? DPLL_A : DPLL_B),
  1053. REG_READ(pipeA ? HTOTAL_A : HTOTAL_B),
  1054. REG_READ(pipeA ? HBLANK_A : HBLANK_B),
  1055. REG_READ(pipeA ? HSYNC_A : HSYNC_B),
  1056. REG_READ(pipeA ? VTOTAL_A : VTOTAL_B),
  1057. REG_READ(pipeA ? VBLANK_A : VBLANK_B),
  1058. REG_READ(pipeA ? VSYNC_A : VSYNC_B),
  1059. REG_READ(pipeA ? DSPASTRIDE : DSPBSTRIDE),
  1060. REG_READ(pipeA ? DSPASIZE : DSPBSIZE),
  1061. REG_READ(pipeA ? DSPAPOS : DSPBPOS),
  1062. REG_READ(pipeA ? DSPABASE : DSPBBASE)
  1063. );
  1064. DRM_DEBUG(
  1065. "saved: (%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
  1066. crtc_state->saveDSPCNTR,
  1067. crtc_state->savePIPECONF,
  1068. crtc_state->savePIPESRC,
  1069. crtc_state->saveFP0,
  1070. crtc_state->saveFP1,
  1071. crtc_state->saveDPLL,
  1072. crtc_state->saveHTOTAL,
  1073. crtc_state->saveHBLANK,
  1074. crtc_state->saveHSYNC,
  1075. crtc_state->saveVTOTAL,
  1076. crtc_state->saveVBLANK,
  1077. crtc_state->saveVSYNC,
  1078. crtc_state->saveDSPSTRIDE,
  1079. crtc_state->saveDSPSIZE,
  1080. crtc_state->saveDSPPOS,
  1081. crtc_state->saveDSPBASE
  1082. );
  1083. if (crtc_state->saveDPLL & DPLL_VCO_ENABLE) {
  1084. REG_WRITE(pipeA ? DPLL_A : DPLL_B,
  1085. crtc_state->saveDPLL & ~DPLL_VCO_ENABLE);
  1086. REG_READ(pipeA ? DPLL_A : DPLL_B);
  1087. DRM_DEBUG("write dpll: %x\n",
  1088. REG_READ(pipeA ? DPLL_A : DPLL_B));
  1089. udelay(150);
  1090. }
  1091. REG_WRITE(pipeA ? FPA0 : FPB0, crtc_state->saveFP0);
  1092. REG_READ(pipeA ? FPA0 : FPB0);
  1093. REG_WRITE(pipeA ? FPA1 : FPB1, crtc_state->saveFP1);
  1094. REG_READ(pipeA ? FPA1 : FPB1);
  1095. REG_WRITE(pipeA ? DPLL_A : DPLL_B, crtc_state->saveDPLL);
  1096. REG_READ(pipeA ? DPLL_A : DPLL_B);
  1097. udelay(150);
  1098. REG_WRITE(pipeA ? HTOTAL_A : HTOTAL_B, crtc_state->saveHTOTAL);
  1099. REG_WRITE(pipeA ? HBLANK_A : HBLANK_B, crtc_state->saveHBLANK);
  1100. REG_WRITE(pipeA ? HSYNC_A : HSYNC_B, crtc_state->saveHSYNC);
  1101. REG_WRITE(pipeA ? VTOTAL_A : VTOTAL_B, crtc_state->saveVTOTAL);
  1102. REG_WRITE(pipeA ? VBLANK_A : VBLANK_B, crtc_state->saveVBLANK);
  1103. REG_WRITE(pipeA ? VSYNC_A : VSYNC_B, crtc_state->saveVSYNC);
  1104. REG_WRITE(pipeA ? DSPASTRIDE : DSPBSTRIDE, crtc_state->saveDSPSTRIDE);
  1105. REG_WRITE(pipeA ? DSPASIZE : DSPBSIZE, crtc_state->saveDSPSIZE);
  1106. REG_WRITE(pipeA ? DSPAPOS : DSPBPOS, crtc_state->saveDSPPOS);
  1107. REG_WRITE(pipeA ? PIPEASRC : PIPEBSRC, crtc_state->savePIPESRC);
  1108. REG_WRITE(pipeA ? DSPABASE : DSPBBASE, crtc_state->saveDSPBASE);
  1109. REG_WRITE(pipeA ? PIPEACONF : PIPEBCONF, crtc_state->savePIPECONF);
  1110. cdv_intel_wait_for_vblank(dev);
  1111. REG_WRITE(pipeA ? DSPACNTR : DSPBCNTR, crtc_state->saveDSPCNTR);
  1112. REG_WRITE(pipeA ? DSPABASE : DSPBBASE, crtc_state->saveDSPBASE);
  1113. cdv_intel_wait_for_vblank(dev);
  1114. paletteReg = pipeA ? PALETTE_A : PALETTE_B;
  1115. for (i = 0; i < 256; ++i)
  1116. REG_WRITE(paletteReg + (i << 2), crtc_state->savePalette[i]);
  1117. }
  1118. static int cdv_intel_crtc_cursor_set(struct drm_crtc *crtc,
  1119. struct drm_file *file_priv,
  1120. uint32_t handle,
  1121. uint32_t width, uint32_t height)
  1122. {
  1123. struct drm_device *dev = crtc->dev;
  1124. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  1125. int pipe = psb_intel_crtc->pipe;
  1126. uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
  1127. uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
  1128. uint32_t temp;
  1129. size_t addr = 0;
  1130. struct gtt_range *gt;
  1131. struct drm_gem_object *obj;
  1132. int ret;
  1133. /* if we want to turn of the cursor ignore width and height */
  1134. if (!handle) {
  1135. /* turn off the cursor */
  1136. temp = CURSOR_MODE_DISABLE;
  1137. if (gma_power_begin(dev, false)) {
  1138. REG_WRITE(control, temp);
  1139. REG_WRITE(base, 0);
  1140. gma_power_end(dev);
  1141. }
  1142. /* unpin the old GEM object */
  1143. if (psb_intel_crtc->cursor_obj) {
  1144. gt = container_of(psb_intel_crtc->cursor_obj,
  1145. struct gtt_range, gem);
  1146. psb_gtt_unpin(gt);
  1147. drm_gem_object_unreference(psb_intel_crtc->cursor_obj);
  1148. psb_intel_crtc->cursor_obj = NULL;
  1149. }
  1150. return 0;
  1151. }
  1152. /* Currently we only support 64x64 cursors */
  1153. if (width != 64 || height != 64) {
  1154. dev_dbg(dev->dev, "we currently only support 64x64 cursors\n");
  1155. return -EINVAL;
  1156. }
  1157. obj = drm_gem_object_lookup(dev, file_priv, handle);
  1158. if (!obj)
  1159. return -ENOENT;
  1160. if (obj->size < width * height * 4) {
  1161. dev_dbg(dev->dev, "buffer is to small\n");
  1162. return -ENOMEM;
  1163. }
  1164. gt = container_of(obj, struct gtt_range, gem);
  1165. /* Pin the memory into the GTT */
  1166. ret = psb_gtt_pin(gt);
  1167. if (ret) {
  1168. dev_err(dev->dev, "Can not pin down handle 0x%x\n", handle);
  1169. return ret;
  1170. }
  1171. addr = gt->offset; /* Or resource.start ??? */
  1172. psb_intel_crtc->cursor_addr = addr;
  1173. temp = 0;
  1174. /* set the pipe for the cursor */
  1175. temp |= (pipe << 28);
  1176. temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  1177. if (gma_power_begin(dev, false)) {
  1178. REG_WRITE(control, temp);
  1179. REG_WRITE(base, addr);
  1180. gma_power_end(dev);
  1181. }
  1182. /* unpin the old GEM object */
  1183. if (psb_intel_crtc->cursor_obj) {
  1184. gt = container_of(psb_intel_crtc->cursor_obj,
  1185. struct gtt_range, gem);
  1186. psb_gtt_unpin(gt);
  1187. drm_gem_object_unreference(psb_intel_crtc->cursor_obj);
  1188. psb_intel_crtc->cursor_obj = obj;
  1189. }
  1190. return 0;
  1191. }
  1192. static int cdv_intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  1193. {
  1194. struct drm_device *dev = crtc->dev;
  1195. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  1196. int pipe = psb_intel_crtc->pipe;
  1197. uint32_t temp = 0;
  1198. uint32_t adder;
  1199. if (x < 0) {
  1200. temp |= (CURSOR_POS_SIGN << CURSOR_X_SHIFT);
  1201. x = -x;
  1202. }
  1203. if (y < 0) {
  1204. temp |= (CURSOR_POS_SIGN << CURSOR_Y_SHIFT);
  1205. y = -y;
  1206. }
  1207. temp |= ((x & CURSOR_POS_MASK) << CURSOR_X_SHIFT);
  1208. temp |= ((y & CURSOR_POS_MASK) << CURSOR_Y_SHIFT);
  1209. adder = psb_intel_crtc->cursor_addr;
  1210. if (gma_power_begin(dev, false)) {
  1211. REG_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
  1212. REG_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder);
  1213. gma_power_end(dev);
  1214. }
  1215. return 0;
  1216. }
  1217. static void cdv_intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red,
  1218. u16 *green, u16 *blue, uint32_t start, uint32_t size)
  1219. {
  1220. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  1221. int i;
  1222. int end = (start + size > 256) ? 256 : start + size;
  1223. for (i = start; i < end; i++) {
  1224. psb_intel_crtc->lut_r[i] = red[i] >> 8;
  1225. psb_intel_crtc->lut_g[i] = green[i] >> 8;
  1226. psb_intel_crtc->lut_b[i] = blue[i] >> 8;
  1227. }
  1228. cdv_intel_crtc_load_lut(crtc);
  1229. }
  1230. static int cdv_crtc_set_config(struct drm_mode_set *set)
  1231. {
  1232. int ret = 0;
  1233. struct drm_device *dev = set->crtc->dev;
  1234. struct drm_psb_private *dev_priv = dev->dev_private;
  1235. if (!dev_priv->rpm_enabled)
  1236. return drm_crtc_helper_set_config(set);
  1237. pm_runtime_forbid(&dev->pdev->dev);
  1238. ret = drm_crtc_helper_set_config(set);
  1239. pm_runtime_allow(&dev->pdev->dev);
  1240. return ret;
  1241. }
  1242. /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
  1243. /* FIXME: why are we using this, should it be cdv_ in this tree ? */
  1244. static void i8xx_clock(int refclk, struct cdv_intel_clock_t *clock)
  1245. {
  1246. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  1247. clock->p = clock->p1 * clock->p2;
  1248. clock->vco = refclk * clock->m / (clock->n + 2);
  1249. clock->dot = clock->vco / clock->p;
  1250. }
  1251. /* Returns the clock of the currently programmed mode of the given pipe. */
  1252. static int cdv_intel_crtc_clock_get(struct drm_device *dev,
  1253. struct drm_crtc *crtc)
  1254. {
  1255. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  1256. int pipe = psb_intel_crtc->pipe;
  1257. u32 dpll;
  1258. u32 fp;
  1259. struct cdv_intel_clock_t clock;
  1260. bool is_lvds;
  1261. struct drm_psb_private *dev_priv = dev->dev_private;
  1262. if (gma_power_begin(dev, false)) {
  1263. dpll = REG_READ((pipe == 0) ? DPLL_A : DPLL_B);
  1264. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  1265. fp = REG_READ((pipe == 0) ? FPA0 : FPB0);
  1266. else
  1267. fp = REG_READ((pipe == 0) ? FPA1 : FPB1);
  1268. is_lvds = (pipe == 1) && (REG_READ(LVDS) & LVDS_PORT_EN);
  1269. gma_power_end(dev);
  1270. } else {
  1271. dpll = (pipe == 0) ?
  1272. dev_priv->regs.psb.saveDPLL_A :
  1273. dev_priv->regs.psb.saveDPLL_B;
  1274. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  1275. fp = (pipe == 0) ?
  1276. dev_priv->regs.psb.saveFPA0 :
  1277. dev_priv->regs.psb.saveFPB0;
  1278. else
  1279. fp = (pipe == 0) ?
  1280. dev_priv->regs.psb.saveFPA1 :
  1281. dev_priv->regs.psb.saveFPB1;
  1282. is_lvds = (pipe == 1) &&
  1283. (dev_priv->regs.psb.saveLVDS & LVDS_PORT_EN);
  1284. }
  1285. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  1286. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  1287. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  1288. if (is_lvds) {
  1289. clock.p1 =
  1290. ffs((dpll &
  1291. DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  1292. DPLL_FPA01_P1_POST_DIV_SHIFT);
  1293. if (clock.p1 == 0) {
  1294. clock.p1 = 4;
  1295. dev_err(dev->dev, "PLL %d\n", dpll);
  1296. }
  1297. clock.p2 = 14;
  1298. if ((dpll & PLL_REF_INPUT_MASK) ==
  1299. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  1300. /* XXX: might not be 66MHz */
  1301. i8xx_clock(66000, &clock);
  1302. } else
  1303. i8xx_clock(48000, &clock);
  1304. } else {
  1305. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  1306. clock.p1 = 2;
  1307. else {
  1308. clock.p1 =
  1309. ((dpll &
  1310. DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  1311. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  1312. }
  1313. if (dpll & PLL_P2_DIVIDE_BY_4)
  1314. clock.p2 = 4;
  1315. else
  1316. clock.p2 = 2;
  1317. i8xx_clock(48000, &clock);
  1318. }
  1319. /* XXX: It would be nice to validate the clocks, but we can't reuse
  1320. * i830PllIsValid() because it relies on the xf86_config connector
  1321. * configuration being accurate, which it isn't necessarily.
  1322. */
  1323. return clock.dot;
  1324. }
  1325. /** Returns the currently programmed mode of the given pipe. */
  1326. struct drm_display_mode *cdv_intel_crtc_mode_get(struct drm_device *dev,
  1327. struct drm_crtc *crtc)
  1328. {
  1329. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  1330. int pipe = psb_intel_crtc->pipe;
  1331. struct drm_display_mode *mode;
  1332. int htot;
  1333. int hsync;
  1334. int vtot;
  1335. int vsync;
  1336. struct drm_psb_private *dev_priv = dev->dev_private;
  1337. if (gma_power_begin(dev, false)) {
  1338. htot = REG_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B);
  1339. hsync = REG_READ((pipe == 0) ? HSYNC_A : HSYNC_B);
  1340. vtot = REG_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B);
  1341. vsync = REG_READ((pipe == 0) ? VSYNC_A : VSYNC_B);
  1342. gma_power_end(dev);
  1343. } else {
  1344. htot = (pipe == 0) ?
  1345. dev_priv->regs.psb.saveHTOTAL_A :
  1346. dev_priv->regs.psb.saveHTOTAL_B;
  1347. hsync = (pipe == 0) ?
  1348. dev_priv->regs.psb.saveHSYNC_A :
  1349. dev_priv->regs.psb.saveHSYNC_B;
  1350. vtot = (pipe == 0) ?
  1351. dev_priv->regs.psb.saveVTOTAL_A :
  1352. dev_priv->regs.psb.saveVTOTAL_B;
  1353. vsync = (pipe == 0) ?
  1354. dev_priv->regs.psb.saveVSYNC_A :
  1355. dev_priv->regs.psb.saveVSYNC_B;
  1356. }
  1357. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  1358. if (!mode)
  1359. return NULL;
  1360. mode->clock = cdv_intel_crtc_clock_get(dev, crtc);
  1361. mode->hdisplay = (htot & 0xffff) + 1;
  1362. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  1363. mode->hsync_start = (hsync & 0xffff) + 1;
  1364. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  1365. mode->vdisplay = (vtot & 0xffff) + 1;
  1366. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  1367. mode->vsync_start = (vsync & 0xffff) + 1;
  1368. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  1369. drm_mode_set_name(mode);
  1370. drm_mode_set_crtcinfo(mode, 0);
  1371. return mode;
  1372. }
  1373. static void cdv_intel_crtc_destroy(struct drm_crtc *crtc)
  1374. {
  1375. struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
  1376. kfree(psb_intel_crtc->crtc_state);
  1377. drm_crtc_cleanup(crtc);
  1378. kfree(psb_intel_crtc);
  1379. }
  1380. const struct drm_crtc_helper_funcs cdv_intel_helper_funcs = {
  1381. .dpms = cdv_intel_crtc_dpms,
  1382. .mode_fixup = cdv_intel_crtc_mode_fixup,
  1383. .mode_set = cdv_intel_crtc_mode_set,
  1384. .mode_set_base = cdv_intel_pipe_set_base,
  1385. .prepare = cdv_intel_crtc_prepare,
  1386. .commit = cdv_intel_crtc_commit,
  1387. };
  1388. const struct drm_crtc_funcs cdv_intel_crtc_funcs = {
  1389. .save = cdv_intel_crtc_save,
  1390. .restore = cdv_intel_crtc_restore,
  1391. .cursor_set = cdv_intel_crtc_cursor_set,
  1392. .cursor_move = cdv_intel_crtc_cursor_move,
  1393. .gamma_set = cdv_intel_crtc_gamma_set,
  1394. .set_config = cdv_crtc_set_config,
  1395. .destroy = cdv_intel_crtc_destroy,
  1396. };