gma.c 21 KB

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