ivybridge_igd.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. /*
  2. * Copyright (C) 2016 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #include <common.h>
  7. #include <bios_emul.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <fdtdec.h>
  11. #include <pci_rom.h>
  12. #include <vbe.h>
  13. #include <asm/intel_regs.h>
  14. #include <asm/io.h>
  15. #include <asm/mtrr.h>
  16. #include <asm/pci.h>
  17. #include <asm/arch/pch.h>
  18. #include <asm/arch/sandybridge.h>
  19. struct gt_powermeter {
  20. u16 reg;
  21. u32 value;
  22. };
  23. /* These are magic values - unfortunately the meaning is unknown */
  24. static const struct gt_powermeter snb_pm_gt1[] = {
  25. { 0xa200, 0xcc000000 },
  26. { 0xa204, 0x07000040 },
  27. { 0xa208, 0x0000fe00 },
  28. { 0xa20c, 0x00000000 },
  29. { 0xa210, 0x17000000 },
  30. { 0xa214, 0x00000021 },
  31. { 0xa218, 0x0817fe19 },
  32. { 0xa21c, 0x00000000 },
  33. { 0xa220, 0x00000000 },
  34. { 0xa224, 0xcc000000 },
  35. { 0xa228, 0x07000040 },
  36. { 0xa22c, 0x0000fe00 },
  37. { 0xa230, 0x00000000 },
  38. { 0xa234, 0x17000000 },
  39. { 0xa238, 0x00000021 },
  40. { 0xa23c, 0x0817fe19 },
  41. { 0xa240, 0x00000000 },
  42. { 0xa244, 0x00000000 },
  43. { 0xa248, 0x8000421e },
  44. { 0 }
  45. };
  46. static const struct gt_powermeter snb_pm_gt2[] = {
  47. { 0xa200, 0x330000a6 },
  48. { 0xa204, 0x402d0031 },
  49. { 0xa208, 0x00165f83 },
  50. { 0xa20c, 0xf1000000 },
  51. { 0xa210, 0x00000000 },
  52. { 0xa214, 0x00160016 },
  53. { 0xa218, 0x002a002b },
  54. { 0xa21c, 0x00000000 },
  55. { 0xa220, 0x00000000 },
  56. { 0xa224, 0x330000a6 },
  57. { 0xa228, 0x402d0031 },
  58. { 0xa22c, 0x00165f83 },
  59. { 0xa230, 0xf1000000 },
  60. { 0xa234, 0x00000000 },
  61. { 0xa238, 0x00160016 },
  62. { 0xa23c, 0x002a002b },
  63. { 0xa240, 0x00000000 },
  64. { 0xa244, 0x00000000 },
  65. { 0xa248, 0x8000421e },
  66. { 0 }
  67. };
  68. static const struct gt_powermeter ivb_pm_gt1[] = {
  69. { 0xa800, 0x00000000 },
  70. { 0xa804, 0x00021c00 },
  71. { 0xa808, 0x00000403 },
  72. { 0xa80c, 0x02001700 },
  73. { 0xa810, 0x05000200 },
  74. { 0xa814, 0x00000000 },
  75. { 0xa818, 0x00690500 },
  76. { 0xa81c, 0x0000007f },
  77. { 0xa820, 0x01002501 },
  78. { 0xa824, 0x00000300 },
  79. { 0xa828, 0x01000331 },
  80. { 0xa82c, 0x0000000c },
  81. { 0xa830, 0x00010016 },
  82. { 0xa834, 0x01100101 },
  83. { 0xa838, 0x00010103 },
  84. { 0xa83c, 0x00041300 },
  85. { 0xa840, 0x00000b30 },
  86. { 0xa844, 0x00000000 },
  87. { 0xa848, 0x7f000000 },
  88. { 0xa84c, 0x05000008 },
  89. { 0xa850, 0x00000001 },
  90. { 0xa854, 0x00000004 },
  91. { 0xa858, 0x00000007 },
  92. { 0xa85c, 0x00000000 },
  93. { 0xa860, 0x00010000 },
  94. { 0xa248, 0x0000221e },
  95. { 0xa900, 0x00000000 },
  96. { 0xa904, 0x00001c00 },
  97. { 0xa908, 0x00000000 },
  98. { 0xa90c, 0x06000000 },
  99. { 0xa910, 0x09000200 },
  100. { 0xa914, 0x00000000 },
  101. { 0xa918, 0x00590000 },
  102. { 0xa91c, 0x00000000 },
  103. { 0xa920, 0x04002501 },
  104. { 0xa924, 0x00000100 },
  105. { 0xa928, 0x03000410 },
  106. { 0xa92c, 0x00000000 },
  107. { 0xa930, 0x00020000 },
  108. { 0xa934, 0x02070106 },
  109. { 0xa938, 0x00010100 },
  110. { 0xa93c, 0x00401c00 },
  111. { 0xa940, 0x00000000 },
  112. { 0xa944, 0x00000000 },
  113. { 0xa948, 0x10000e00 },
  114. { 0xa94c, 0x02000004 },
  115. { 0xa950, 0x00000001 },
  116. { 0xa954, 0x00000004 },
  117. { 0xa960, 0x00060000 },
  118. { 0xaa3c, 0x00001c00 },
  119. { 0xaa54, 0x00000004 },
  120. { 0xaa60, 0x00060000 },
  121. { 0 }
  122. };
  123. static const struct gt_powermeter ivb_pm_gt2[] = {
  124. { 0xa800, 0x10000000 },
  125. { 0xa804, 0x00033800 },
  126. { 0xa808, 0x00000902 },
  127. { 0xa80c, 0x0c002f00 },
  128. { 0xa810, 0x12000400 },
  129. { 0xa814, 0x00000000 },
  130. { 0xa818, 0x00d20800 },
  131. { 0xa81c, 0x00000002 },
  132. { 0xa820, 0x03004b02 },
  133. { 0xa824, 0x00000600 },
  134. { 0xa828, 0x07000773 },
  135. { 0xa82c, 0x00000000 },
  136. { 0xa830, 0x00010032 },
  137. { 0xa834, 0x1520040d },
  138. { 0xa838, 0x00020105 },
  139. { 0xa83c, 0x00083700 },
  140. { 0xa840, 0x0000151d },
  141. { 0xa844, 0x00000000 },
  142. { 0xa848, 0x20001b00 },
  143. { 0xa84c, 0x0a000010 },
  144. { 0xa850, 0x00000000 },
  145. { 0xa854, 0x00000008 },
  146. { 0xa858, 0x00000008 },
  147. { 0xa85c, 0x00000000 },
  148. { 0xa860, 0x00020000 },
  149. { 0xa248, 0x0000221e },
  150. { 0xa900, 0x00000000 },
  151. { 0xa904, 0x00003500 },
  152. { 0xa908, 0x00000000 },
  153. { 0xa90c, 0x0c000000 },
  154. { 0xa910, 0x12000500 },
  155. { 0xa914, 0x00000000 },
  156. { 0xa918, 0x00b20000 },
  157. { 0xa91c, 0x00000000 },
  158. { 0xa920, 0x08004b02 },
  159. { 0xa924, 0x00000200 },
  160. { 0xa928, 0x07000820 },
  161. { 0xa92c, 0x00000000 },
  162. { 0xa930, 0x00030000 },
  163. { 0xa934, 0x050f020d },
  164. { 0xa938, 0x00020300 },
  165. { 0xa93c, 0x00903900 },
  166. { 0xa940, 0x00000000 },
  167. { 0xa944, 0x00000000 },
  168. { 0xa948, 0x20001b00 },
  169. { 0xa94c, 0x0a000010 },
  170. { 0xa950, 0x00000000 },
  171. { 0xa954, 0x00000008 },
  172. { 0xa960, 0x00110000 },
  173. { 0xaa3c, 0x00003900 },
  174. { 0xaa54, 0x00000008 },
  175. { 0xaa60, 0x00110000 },
  176. { 0 }
  177. };
  178. static const struct gt_powermeter ivb_pm_gt2_17w[] = {
  179. { 0xa800, 0x20000000 },
  180. { 0xa804, 0x000e3800 },
  181. { 0xa808, 0x00000806 },
  182. { 0xa80c, 0x0c002f00 },
  183. { 0xa810, 0x0c000800 },
  184. { 0xa814, 0x00000000 },
  185. { 0xa818, 0x00d20d00 },
  186. { 0xa81c, 0x000000ff },
  187. { 0xa820, 0x03004b02 },
  188. { 0xa824, 0x00000600 },
  189. { 0xa828, 0x07000773 },
  190. { 0xa82c, 0x00000000 },
  191. { 0xa830, 0x00020032 },
  192. { 0xa834, 0x1520040d },
  193. { 0xa838, 0x00020105 },
  194. { 0xa83c, 0x00083700 },
  195. { 0xa840, 0x000016ff },
  196. { 0xa844, 0x00000000 },
  197. { 0xa848, 0xff000000 },
  198. { 0xa84c, 0x0a000010 },
  199. { 0xa850, 0x00000002 },
  200. { 0xa854, 0x00000008 },
  201. { 0xa858, 0x0000000f },
  202. { 0xa85c, 0x00000000 },
  203. { 0xa860, 0x00020000 },
  204. { 0xa248, 0x0000221e },
  205. { 0xa900, 0x00000000 },
  206. { 0xa904, 0x00003800 },
  207. { 0xa908, 0x00000000 },
  208. { 0xa90c, 0x0c000000 },
  209. { 0xa910, 0x12000800 },
  210. { 0xa914, 0x00000000 },
  211. { 0xa918, 0x00b20000 },
  212. { 0xa91c, 0x00000000 },
  213. { 0xa920, 0x08004b02 },
  214. { 0xa924, 0x00000300 },
  215. { 0xa928, 0x01000820 },
  216. { 0xa92c, 0x00000000 },
  217. { 0xa930, 0x00030000 },
  218. { 0xa934, 0x15150406 },
  219. { 0xa938, 0x00020300 },
  220. { 0xa93c, 0x00903900 },
  221. { 0xa940, 0x00000000 },
  222. { 0xa944, 0x00000000 },
  223. { 0xa948, 0x20001b00 },
  224. { 0xa94c, 0x0a000010 },
  225. { 0xa950, 0x00000000 },
  226. { 0xa954, 0x00000008 },
  227. { 0xa960, 0x00110000 },
  228. { 0xaa3c, 0x00003900 },
  229. { 0xaa54, 0x00000008 },
  230. { 0xaa60, 0x00110000 },
  231. { 0 }
  232. };
  233. static const struct gt_powermeter ivb_pm_gt2_35w[] = {
  234. { 0xa800, 0x00000000 },
  235. { 0xa804, 0x00030400 },
  236. { 0xa808, 0x00000806 },
  237. { 0xa80c, 0x0c002f00 },
  238. { 0xa810, 0x0c000300 },
  239. { 0xa814, 0x00000000 },
  240. { 0xa818, 0x00d20d00 },
  241. { 0xa81c, 0x000000ff },
  242. { 0xa820, 0x03004b02 },
  243. { 0xa824, 0x00000600 },
  244. { 0xa828, 0x07000773 },
  245. { 0xa82c, 0x00000000 },
  246. { 0xa830, 0x00020032 },
  247. { 0xa834, 0x1520040d },
  248. { 0xa838, 0x00020105 },
  249. { 0xa83c, 0x00083700 },
  250. { 0xa840, 0x000016ff },
  251. { 0xa844, 0x00000000 },
  252. { 0xa848, 0xff000000 },
  253. { 0xa84c, 0x0a000010 },
  254. { 0xa850, 0x00000001 },
  255. { 0xa854, 0x00000008 },
  256. { 0xa858, 0x00000008 },
  257. { 0xa85c, 0x00000000 },
  258. { 0xa860, 0x00020000 },
  259. { 0xa248, 0x0000221e },
  260. { 0xa900, 0x00000000 },
  261. { 0xa904, 0x00003800 },
  262. { 0xa908, 0x00000000 },
  263. { 0xa90c, 0x0c000000 },
  264. { 0xa910, 0x12000800 },
  265. { 0xa914, 0x00000000 },
  266. { 0xa918, 0x00b20000 },
  267. { 0xa91c, 0x00000000 },
  268. { 0xa920, 0x08004b02 },
  269. { 0xa924, 0x00000300 },
  270. { 0xa928, 0x01000820 },
  271. { 0xa92c, 0x00000000 },
  272. { 0xa930, 0x00030000 },
  273. { 0xa934, 0x15150406 },
  274. { 0xa938, 0x00020300 },
  275. { 0xa93c, 0x00903900 },
  276. { 0xa940, 0x00000000 },
  277. { 0xa944, 0x00000000 },
  278. { 0xa948, 0x20001b00 },
  279. { 0xa94c, 0x0a000010 },
  280. { 0xa950, 0x00000000 },
  281. { 0xa954, 0x00000008 },
  282. { 0xa960, 0x00110000 },
  283. { 0xaa3c, 0x00003900 },
  284. { 0xaa54, 0x00000008 },
  285. { 0xaa60, 0x00110000 },
  286. { 0 }
  287. };
  288. static inline u32 gtt_read(void *bar, u32 reg)
  289. {
  290. return readl(bar + reg);
  291. }
  292. static inline void gtt_write(void *bar, u32 reg, u32 data)
  293. {
  294. writel(data, bar + reg);
  295. }
  296. static void gtt_write_powermeter(void *bar, const struct gt_powermeter *pm)
  297. {
  298. for (; pm && pm->reg; pm++)
  299. gtt_write(bar, pm->reg, pm->value);
  300. }
  301. #define GTT_RETRY 1000
  302. static int gtt_poll(void *bar, u32 reg, u32 mask, u32 value)
  303. {
  304. unsigned try = GTT_RETRY;
  305. u32 data;
  306. while (try--) {
  307. data = gtt_read(bar, reg);
  308. if ((data & mask) == value)
  309. return 1;
  310. udelay(10);
  311. }
  312. printf("GT init timeout\n");
  313. return 0;
  314. }
  315. static int gma_pm_init_pre_vbios(void *gtt_bar, int rev)
  316. {
  317. u32 reg32;
  318. debug("GT Power Management Init, silicon = %#x\n", rev);
  319. if (rev < IVB_STEP_C0) {
  320. /* 1: Enable force wake */
  321. gtt_write(gtt_bar, 0xa18c, 0x00000001);
  322. gtt_poll(gtt_bar, 0x130090, (1 << 0), (1 << 0));
  323. } else {
  324. gtt_write(gtt_bar, 0xa180, 1 << 5);
  325. gtt_write(gtt_bar, 0xa188, 0xffff0001);
  326. gtt_poll(gtt_bar, 0x130040, (1 << 0), (1 << 0));
  327. }
  328. if ((rev & BASE_REV_MASK) == BASE_REV_SNB) {
  329. /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
  330. reg32 = gtt_read(gtt_bar, 0x42004);
  331. reg32 |= (1 << 14) | (1 << 15);
  332. gtt_write(gtt_bar, 0x42004, reg32);
  333. }
  334. if (rev >= IVB_STEP_A0) {
  335. /* Display Reset Acknowledge Settings */
  336. reg32 = gtt_read(gtt_bar, 0x45010);
  337. reg32 |= (1 << 1) | (1 << 0);
  338. gtt_write(gtt_bar, 0x45010, reg32);
  339. }
  340. /* 2: Get GT SKU from GTT+0x911c[13] */
  341. reg32 = gtt_read(gtt_bar, 0x911c);
  342. if ((rev & BASE_REV_MASK) == BASE_REV_SNB) {
  343. if (reg32 & (1 << 13)) {
  344. debug("SNB GT1 Power Meter Weights\n");
  345. gtt_write_powermeter(gtt_bar, snb_pm_gt1);
  346. } else {
  347. debug("SNB GT2 Power Meter Weights\n");
  348. gtt_write_powermeter(gtt_bar, snb_pm_gt2);
  349. }
  350. } else {
  351. u32 unit = readl(MCHBAR_REG(0x5938)) & 0xf;
  352. if (reg32 & (1 << 13)) {
  353. /* GT1 SKU */
  354. debug("IVB GT1 Power Meter Weights\n");
  355. gtt_write_powermeter(gtt_bar, ivb_pm_gt1);
  356. } else {
  357. /* GT2 SKU */
  358. u32 tdp = readl(MCHBAR_REG(0x5930)) & 0x7fff;
  359. tdp /= (1 << unit);
  360. if (tdp <= 17) {
  361. /* <=17W ULV */
  362. debug("IVB GT2 17W Power Meter Weights\n");
  363. gtt_write_powermeter(gtt_bar, ivb_pm_gt2_17w);
  364. } else if ((tdp >= 25) && (tdp <= 35)) {
  365. /* 25W-35W */
  366. debug("IVB GT2 25W-35W Power Meter Weights\n");
  367. gtt_write_powermeter(gtt_bar, ivb_pm_gt2_35w);
  368. } else {
  369. /* All others */
  370. debug("IVB GT2 35W Power Meter Weights\n");
  371. gtt_write_powermeter(gtt_bar, ivb_pm_gt2_35w);
  372. }
  373. }
  374. }
  375. /* 3: Gear ratio map */
  376. gtt_write(gtt_bar, 0xa004, 0x00000010);
  377. /* 4: GFXPAUSE */
  378. gtt_write(gtt_bar, 0xa000, 0x00070020);
  379. /* 5: Dynamic EU trip control */
  380. gtt_write(gtt_bar, 0xa080, 0x00000004);
  381. /* 6: ECO bits */
  382. reg32 = gtt_read(gtt_bar, 0xa180);
  383. reg32 |= (1 << 26) | (1 << 31);
  384. /* (bit 20=1 for SNB step D1+ / IVB A0+) */
  385. if (rev >= SNB_STEP_D1)
  386. reg32 |= (1 << 20);
  387. gtt_write(gtt_bar, 0xa180, reg32);
  388. /* 6a: for SnB step D2+ only */
  389. if (((rev & BASE_REV_MASK) == BASE_REV_SNB) &&
  390. (rev >= SNB_STEP_D2)) {
  391. reg32 = gtt_read(gtt_bar, 0x9400);
  392. reg32 |= (1 << 7);
  393. gtt_write(gtt_bar, 0x9400, reg32);
  394. reg32 = gtt_read(gtt_bar, 0x941c);
  395. reg32 &= 0xf;
  396. reg32 |= (1 << 1);
  397. gtt_write(gtt_bar, 0x941c, reg32);
  398. gtt_poll(gtt_bar, 0x941c, (1 << 1), (0 << 1));
  399. }
  400. if ((rev & BASE_REV_MASK) == BASE_REV_IVB) {
  401. reg32 = gtt_read(gtt_bar, 0x907c);
  402. reg32 |= (1 << 16);
  403. gtt_write(gtt_bar, 0x907c, reg32);
  404. /* 6b: Clocking reset controls */
  405. gtt_write(gtt_bar, 0x9424, 0x00000001);
  406. } else {
  407. /* 6b: Clocking reset controls */
  408. gtt_write(gtt_bar, 0x9424, 0x00000000);
  409. }
  410. /* 7 */
  411. if (gtt_poll(gtt_bar, 0x138124, (1 << 31), (0 << 31))) {
  412. gtt_write(gtt_bar, 0x138128, 0x00000029); /* Mailbox Data */
  413. /* Mailbox Cmd for RC6 VID */
  414. gtt_write(gtt_bar, 0x138124, 0x80000004);
  415. if (gtt_poll(gtt_bar, 0x138124, (1 << 31), (0 << 31)))
  416. gtt_write(gtt_bar, 0x138124, 0x8000000a);
  417. gtt_poll(gtt_bar, 0x138124, (1 << 31), (0 << 31));
  418. }
  419. /* 8 */
  420. gtt_write(gtt_bar, 0xa090, 0x00000000); /* RC Control */
  421. gtt_write(gtt_bar, 0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
  422. gtt_write(gtt_bar, 0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
  423. gtt_write(gtt_bar, 0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
  424. gtt_write(gtt_bar, 0xa0a8, 0x0001e848); /* RC Evaluation Interval */
  425. gtt_write(gtt_bar, 0xa0ac, 0x00000019); /* RC Idle Hysteresis */
  426. /* 9 */
  427. gtt_write(gtt_bar, 0x2054, 0x0000000a); /* Render Idle Max Count */
  428. gtt_write(gtt_bar, 0x12054, 0x0000000a); /* Video Idle Max Count */
  429. gtt_write(gtt_bar, 0x22054, 0x0000000a); /* Blitter Idle Max Count */
  430. /* 10 */
  431. gtt_write(gtt_bar, 0xa0b0, 0x00000000); /* Unblock Ack to Busy */
  432. gtt_write(gtt_bar, 0xa0b4, 0x000003e8); /* RC1e Threshold */
  433. gtt_write(gtt_bar, 0xa0b8, 0x0000c350); /* RC6 Threshold */
  434. gtt_write(gtt_bar, 0xa0bc, 0x000186a0); /* RC6p Threshold */
  435. gtt_write(gtt_bar, 0xa0c0, 0x0000fa00); /* RC6pp Threshold */
  436. /* 11 */
  437. gtt_write(gtt_bar, 0xa010, 0x000f4240); /* RP Down Timeout */
  438. gtt_write(gtt_bar, 0xa014, 0x12060000); /* RP Interrupt Limits */
  439. gtt_write(gtt_bar, 0xa02c, 0x00015f90); /* RP Up Threshold */
  440. gtt_write(gtt_bar, 0xa030, 0x000186a0); /* RP Down Threshold */
  441. gtt_write(gtt_bar, 0xa068, 0x000186a0); /* RP Up EI */
  442. gtt_write(gtt_bar, 0xa06c, 0x000493e0); /* RP Down EI */
  443. gtt_write(gtt_bar, 0xa070, 0x0000000a); /* RP Idle Hysteresis */
  444. /* 11a: Enable Render Standby (RC6) */
  445. if ((rev & BASE_REV_MASK) == BASE_REV_IVB) {
  446. /*
  447. * IvyBridge should also support DeepRenderStandby.
  448. *
  449. * Unfortunately it does not work reliably on all SKUs so
  450. * disable it here and it can be enabled by the kernel.
  451. */
  452. gtt_write(gtt_bar, 0xa090, 0x88040000); /* HW RC Control */
  453. } else {
  454. gtt_write(gtt_bar, 0xa090, 0x88040000); /* HW RC Control */
  455. }
  456. /* 12: Normal Frequency Request */
  457. /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
  458. reg32 = readl(MCHBAR_REG(0x5998));
  459. reg32 >>= 16;
  460. reg32 &= 0xef;
  461. reg32 <<= 25;
  462. gtt_write(gtt_bar, 0xa008, reg32);
  463. /* 13: RP Control */
  464. gtt_write(gtt_bar, 0xa024, 0x00000592);
  465. /* 14: Enable PM Interrupts */
  466. gtt_write(gtt_bar, 0x4402c, 0x03000076);
  467. /* Clear 0x6c024 [8:6] */
  468. reg32 = gtt_read(gtt_bar, 0x6c024);
  469. reg32 &= ~0x000001c0;
  470. gtt_write(gtt_bar, 0x6c024, reg32);
  471. return 0;
  472. }
  473. static int gma_pm_init_post_vbios(struct udevice *dev, int rev, void *gtt_bar)
  474. {
  475. const void *blob = gd->fdt_blob;
  476. int node = dev->of_offset;
  477. u32 reg32, cycle_delay;
  478. debug("GT Power Management Init (post VBIOS)\n");
  479. /* 15: Deassert Force Wake */
  480. if (rev < IVB_STEP_C0) {
  481. gtt_write(gtt_bar, 0xa18c, gtt_read(gtt_bar, 0xa18c) & ~1);
  482. gtt_poll(gtt_bar, 0x130090, (1 << 0), (0 << 0));
  483. } else {
  484. gtt_write(gtt_bar, 0xa188, 0x1fffe);
  485. if (gtt_poll(gtt_bar, 0x130040, (1 << 0), (0 << 0))) {
  486. gtt_write(gtt_bar, 0xa188,
  487. gtt_read(gtt_bar, 0xa188) | 1);
  488. }
  489. }
  490. /* 16: SW RC Control */
  491. gtt_write(gtt_bar, 0xa094, 0x00060000);
  492. /* Setup Digital Port Hotplug */
  493. reg32 = gtt_read(gtt_bar, 0xc4030);
  494. if (!reg32) {
  495. u32 dp_hotplug[3];
  496. if (fdtdec_get_int_array(blob, node, "intel,dp_hotplug",
  497. dp_hotplug, ARRAY_SIZE(dp_hotplug)))
  498. return -EINVAL;
  499. reg32 = (dp_hotplug[0] & 0x7) << 2;
  500. reg32 |= (dp_hotplug[0] & 0x7) << 10;
  501. reg32 |= (dp_hotplug[0] & 0x7) << 18;
  502. gtt_write(gtt_bar, 0xc4030, reg32);
  503. }
  504. /* Setup Panel Power On Delays */
  505. reg32 = gtt_read(gtt_bar, 0xc7208);
  506. if (!reg32) {
  507. reg32 = (unsigned)fdtdec_get_int(blob, node,
  508. "panel-port-select", 0) << 30;
  509. reg32 |= fdtdec_get_int(blob, node, "panel-power-up-delay", 0)
  510. << 16;
  511. reg32 |= fdtdec_get_int(blob, node,
  512. "panel-power-backlight-on-delay", 0);
  513. gtt_write(gtt_bar, 0xc7208, reg32);
  514. }
  515. /* Setup Panel Power Off Delays */
  516. reg32 = gtt_read(gtt_bar, 0xc720c);
  517. if (!reg32) {
  518. reg32 = fdtdec_get_int(blob, node, "panel-power-down-delay", 0)
  519. << 16;
  520. reg32 |= fdtdec_get_int(blob, node,
  521. "panel-power-backlight-off-delay", 0);
  522. gtt_write(gtt_bar, 0xc720c, reg32);
  523. }
  524. /* Setup Panel Power Cycle Delay */
  525. cycle_delay = fdtdec_get_int(blob, node,
  526. "intel,panel-power-cycle-delay", 0);
  527. if (cycle_delay) {
  528. reg32 = gtt_read(gtt_bar, 0xc7210);
  529. reg32 &= ~0xff;
  530. reg32 |= cycle_delay;
  531. gtt_write(gtt_bar, 0xc7210, reg32);
  532. }
  533. /* Enable Backlight if needed */
  534. reg32 = fdtdec_get_int(blob, node, "intel,cpu-backlight", 0);
  535. if (reg32) {
  536. gtt_write(gtt_bar, 0x48250, (1 << 31));
  537. gtt_write(gtt_bar, 0x48254, reg32);
  538. }
  539. reg32 = fdtdec_get_int(blob, node, "intel,pch-backlight", 0);
  540. if (reg32) {
  541. gtt_write(gtt_bar, 0xc8250, (1 << 31));
  542. gtt_write(gtt_bar, 0xc8254, reg32);
  543. }
  544. return 0;
  545. }
  546. /*
  547. * Some vga option roms are used for several chipsets but they only have one
  548. * PCI ID in their header. If we encounter such an option rom, we need to do
  549. * the mapping ourselves.
  550. */
  551. uint32_t board_map_oprom_vendev(uint32_t vendev)
  552. {
  553. switch (vendev) {
  554. case 0x80860102: /* GT1 Desktop */
  555. case 0x8086010a: /* GT1 Server */
  556. case 0x80860112: /* GT2 Desktop */
  557. case 0x80860116: /* GT2 Mobile */
  558. case 0x80860122: /* GT2 Desktop >=1.3GHz */
  559. case 0x80860126: /* GT2 Mobile >=1.3GHz */
  560. case 0x80860156: /* IVB */
  561. case 0x80860166: /* IVB */
  562. return 0x80860106; /* GT1 Mobile */
  563. }
  564. return vendev;
  565. }
  566. static int int15_handler(void)
  567. {
  568. int res = 0;
  569. debug("%s: INT15 function %04x!\n", __func__, M.x86.R_AX);
  570. switch (M.x86.R_AX) {
  571. case 0x5f34:
  572. /*
  573. * Set Panel Fitting Hook:
  574. * bit 2 = Graphics Stretching
  575. * bit 1 = Text Stretching
  576. * bit 0 = Centering (do not set with bit1 or bit2)
  577. * 0 = video bios default
  578. */
  579. M.x86.R_AX = 0x005f;
  580. M.x86.R_CL = 0x00; /* Use video bios default */
  581. res = 1;
  582. break;
  583. case 0x5f35:
  584. /*
  585. * Boot Display Device Hook:
  586. * bit 0 = CRT
  587. * bit 1 = TV (eDP)
  588. * bit 2 = EFP
  589. * bit 3 = LFP
  590. * bit 4 = CRT2
  591. * bit 5 = TV2 (eDP)
  592. * bit 6 = EFP2
  593. * bit 7 = LFP2
  594. */
  595. M.x86.R_AX = 0x005f;
  596. M.x86.R_CX = 0x0000; /* Use video bios default */
  597. res = 1;
  598. break;
  599. case 0x5f51:
  600. /*
  601. * Hook to select active LFP configuration:
  602. * 00h = No LVDS, VBIOS does not enable LVDS
  603. * 01h = Int-LVDS, LFP driven by integrated LVDS decoder
  604. * 02h = SVDO-LVDS, LFP driven by SVDO decoder
  605. * 03h = eDP, LFP Driven by Int-DisplayPort encoder
  606. */
  607. M.x86.R_AX = 0x005f;
  608. M.x86.R_CX = 0x0003; /* eDP */
  609. res = 1;
  610. break;
  611. case 0x5f70:
  612. switch (M.x86.R_CH) {
  613. case 0:
  614. /* Get Mux */
  615. M.x86.R_AX = 0x005f;
  616. M.x86.R_CX = 0x0000;
  617. res = 1;
  618. break;
  619. case 1:
  620. /* Set Mux */
  621. M.x86.R_AX = 0x005f;
  622. M.x86.R_CX = 0x0000;
  623. res = 1;
  624. break;
  625. case 2:
  626. /* Get SG/Non-SG mode */
  627. M.x86.R_AX = 0x005f;
  628. M.x86.R_CX = 0x0000;
  629. res = 1;
  630. break;
  631. default:
  632. /* Interrupt was not handled */
  633. debug("Unknown INT15 5f70 function: 0x%02x\n",
  634. M.x86.R_CH);
  635. break;
  636. }
  637. break;
  638. case 0x5fac:
  639. res = 1;
  640. break;
  641. default:
  642. debug("Unknown INT15 function %04x!\n", M.x86.R_AX);
  643. break;
  644. }
  645. return res;
  646. }
  647. static void sandybridge_setup_graphics(struct udevice *dev,
  648. struct udevice *video_dev)
  649. {
  650. u32 reg32;
  651. u16 reg16;
  652. u8 reg8;
  653. dm_pci_read_config16(video_dev, PCI_DEVICE_ID, &reg16);
  654. switch (reg16) {
  655. case 0x0102: /* GT1 Desktop */
  656. case 0x0106: /* GT1 Mobile */
  657. case 0x010a: /* GT1 Server */
  658. case 0x0112: /* GT2 Desktop */
  659. case 0x0116: /* GT2 Mobile */
  660. case 0x0122: /* GT2 Desktop >=1.3GHz */
  661. case 0x0126: /* GT2 Mobile >=1.3GHz */
  662. case 0x0156: /* IvyBridge */
  663. case 0x0166: /* IvyBridge */
  664. break;
  665. default:
  666. debug("Graphics not supported by this CPU/chipset\n");
  667. return;
  668. }
  669. debug("Initialising Graphics\n");
  670. /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */
  671. dm_pci_read_config16(dev, GGC, &reg16);
  672. reg16 &= ~0x00f8;
  673. reg16 |= 1 << 3;
  674. /* Program GTT memory by setting GGC[9:8] = 2MB */
  675. reg16 &= ~0x0300;
  676. reg16 |= 2 << 8;
  677. /* Enable VGA decode */
  678. reg16 &= ~0x0002;
  679. dm_pci_write_config16(dev, GGC, reg16);
  680. /* Enable 256MB aperture */
  681. dm_pci_read_config8(video_dev, MSAC, &reg8);
  682. reg8 &= ~0x06;
  683. reg8 |= 0x02;
  684. dm_pci_write_config8(video_dev, MSAC, reg8);
  685. /* Erratum workarounds */
  686. reg32 = readl(MCHBAR_REG(0x5f00));
  687. reg32 |= (1 << 9) | (1 << 10);
  688. writel(reg32, MCHBAR_REG(0x5f00));
  689. /* Enable SA Clock Gating */
  690. reg32 = readl(MCHBAR_REG(0x5f00));
  691. writel(reg32 | 1, MCHBAR_REG(0x5f00));
  692. /* GPU RC6 workaround for sighting 366252 */
  693. reg32 = readl(MCHBAR_REG(0x5d14));
  694. reg32 |= (1 << 31);
  695. writel(reg32, MCHBAR_REG(0x5d14));
  696. /* VLW */
  697. reg32 = readl(MCHBAR_REG(0x6120));
  698. reg32 &= ~(1 << 0);
  699. writel(reg32, MCHBAR_REG(0x6120));
  700. reg32 = readl(MCHBAR_REG(0x5418));
  701. reg32 |= (1 << 4) | (1 << 5);
  702. writel(reg32, MCHBAR_REG(0x5418));
  703. }
  704. static int gma_func0_init(struct udevice *dev)
  705. {
  706. struct udevice *nbridge;
  707. void *gtt_bar;
  708. ulong base;
  709. u32 reg32;
  710. int ret;
  711. int rev;
  712. /* Enable PCH Display Port */
  713. writew(0x0010, RCB_REG(DISPBDF));
  714. setbits_le32(RCB_REG(FD2), PCH_ENABLE_DBDF);
  715. ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &nbridge);
  716. if (ret)
  717. return ret;
  718. rev = bridge_silicon_revision(nbridge);
  719. sandybridge_setup_graphics(nbridge, dev);
  720. /* IGD needs to be Bus Master */
  721. dm_pci_read_config32(dev, PCI_COMMAND, &reg32);
  722. reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  723. dm_pci_write_config32(dev, PCI_COMMAND, reg32);
  724. /* Use write-combining for the graphics memory, 256MB */
  725. base = dm_pci_read_bar32(dev, 2);
  726. mtrr_add_request(MTRR_TYPE_WRCOMB, base, 256 << 20);
  727. mtrr_commit(true);
  728. gtt_bar = (void *)dm_pci_read_bar32(dev, 0);
  729. debug("GT bar %p\n", gtt_bar);
  730. ret = gma_pm_init_pre_vbios(gtt_bar, rev);
  731. if (ret)
  732. return ret;
  733. return rev;
  734. }
  735. static int bd82x6x_video_probe(struct udevice *dev)
  736. {
  737. void *gtt_bar;
  738. int ret, rev;
  739. rev = gma_func0_init(dev);
  740. if (rev < 0)
  741. return rev;
  742. ret = vbe_setup_video(dev, int15_handler);
  743. if (ret)
  744. return ret;
  745. /* Post VBIOS init */
  746. gtt_bar = (void *)dm_pci_read_bar32(dev, 0);
  747. ret = gma_pm_init_post_vbios(dev, rev, gtt_bar);
  748. if (ret)
  749. return ret;
  750. return 0;
  751. }
  752. static const struct udevice_id bd82x6x_video_ids[] = {
  753. { .compatible = "intel,gma" },
  754. { }
  755. };
  756. U_BOOT_DRIVER(bd82x6x_video) = {
  757. .name = "bd82x6x_video",
  758. .id = UCLASS_VIDEO,
  759. .of_match = bd82x6x_video_ids,
  760. .probe = bd82x6x_video_probe,
  761. };