ivybridge_igd.c 21 KB

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