lpc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. * From coreboot southbridge/intel/bd82x6x/lpc.c
  3. *
  4. * Copyright (C) 2008-2009 coresystems GmbH
  5. *
  6. * SPDX-License-Identifier: GPL-2.0
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <errno.h>
  11. #include <fdtdec.h>
  12. #include <rtc.h>
  13. #include <pci.h>
  14. #include <asm/acpi.h>
  15. #include <asm/interrupt.h>
  16. #include <asm/io.h>
  17. #include <asm/ioapic.h>
  18. #include <asm/pci.h>
  19. #include <asm/arch/pch.h>
  20. #define NMI_OFF 0
  21. #define ENABLE_ACPI_MODE_IN_COREBOOT 0
  22. #define TEST_SMM_FLASH_LOCKDOWN 0
  23. static int pch_enable_apic(struct udevice *pch)
  24. {
  25. u32 reg32;
  26. int i;
  27. /* Enable ACPI I/O and power management. Set SCI IRQ to IRQ9 */
  28. dm_pci_write_config8(pch, ACPI_CNTL, 0x80);
  29. writel(0, IO_APIC_INDEX);
  30. writel(1 << 25, IO_APIC_DATA);
  31. /* affirm full set of redirection table entries ("write once") */
  32. writel(1, IO_APIC_INDEX);
  33. reg32 = readl(IO_APIC_DATA);
  34. writel(1, IO_APIC_INDEX);
  35. writel(reg32, IO_APIC_DATA);
  36. writel(0, IO_APIC_INDEX);
  37. reg32 = readl(IO_APIC_DATA);
  38. debug("PCH APIC ID = %x\n", (reg32 >> 24) & 0x0f);
  39. if (reg32 != (1 << 25)) {
  40. printf("APIC Error - cannot write to registers\n");
  41. return -EPERM;
  42. }
  43. debug("Dumping IOAPIC registers\n");
  44. for (i = 0; i < 3; i++) {
  45. writel(i, IO_APIC_INDEX);
  46. debug(" reg 0x%04x:", i);
  47. reg32 = readl(IO_APIC_DATA);
  48. debug(" 0x%08x\n", reg32);
  49. }
  50. /* Select Boot Configuration register. */
  51. writel(3, IO_APIC_INDEX);
  52. /* Use Processor System Bus to deliver interrupts. */
  53. writel(1, IO_APIC_DATA);
  54. return 0;
  55. }
  56. static void pch_enable_serial_irqs(struct udevice *pch)
  57. {
  58. u32 value;
  59. /* Set packet length and toggle silent mode bit for one frame. */
  60. value = (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0);
  61. #ifdef CONFIG_SERIRQ_CONTINUOUS_MODE
  62. dm_pci_write_config8(pch, SERIRQ_CNTL, value);
  63. #else
  64. dm_pci_write_config8(pch, SERIRQ_CNTL, value | (1 << 6));
  65. #endif
  66. }
  67. static int pch_pirq_init(struct udevice *pch)
  68. {
  69. uint8_t route[8], *ptr;
  70. if (fdtdec_get_byte_array(gd->fdt_blob, pch->of_offset,
  71. "intel,pirq-routing", route, sizeof(route)))
  72. return -EINVAL;
  73. ptr = route;
  74. dm_pci_write_config8(pch, PIRQA_ROUT, *ptr++);
  75. dm_pci_write_config8(pch, PIRQB_ROUT, *ptr++);
  76. dm_pci_write_config8(pch, PIRQC_ROUT, *ptr++);
  77. dm_pci_write_config8(pch, PIRQD_ROUT, *ptr++);
  78. dm_pci_write_config8(pch, PIRQE_ROUT, *ptr++);
  79. dm_pci_write_config8(pch, PIRQF_ROUT, *ptr++);
  80. dm_pci_write_config8(pch, PIRQG_ROUT, *ptr++);
  81. dm_pci_write_config8(pch, PIRQH_ROUT, *ptr++);
  82. /*
  83. * TODO(sjg@chromium.org): U-Boot does not set up the interrupts
  84. * here. It's unclear if it is needed
  85. */
  86. return 0;
  87. }
  88. static int pch_gpi_routing(struct udevice *pch)
  89. {
  90. u8 route[16];
  91. u32 reg;
  92. int gpi;
  93. if (fdtdec_get_byte_array(gd->fdt_blob, pch->of_offset,
  94. "intel,gpi-routing", route, sizeof(route)))
  95. return -EINVAL;
  96. for (reg = 0, gpi = 0; gpi < ARRAY_SIZE(route); gpi++)
  97. reg |= route[gpi] << (gpi * 2);
  98. dm_pci_write_config32(pch, 0xb8, reg);
  99. return 0;
  100. }
  101. static int pch_power_options(struct udevice *pch)
  102. {
  103. const void *blob = gd->fdt_blob;
  104. int node = pch->of_offset;
  105. u8 reg8;
  106. u16 reg16, pmbase;
  107. u32 reg32;
  108. const char *state;
  109. int pwr_on;
  110. int nmi_option;
  111. int ret;
  112. /*
  113. * Which state do we want to goto after g3 (power restored)?
  114. * 0 == S0 Full On
  115. * 1 == S5 Soft Off
  116. *
  117. * If the option is not existent (Laptops), use Kconfig setting.
  118. * TODO(sjg@chromium.org): Make this configurable
  119. */
  120. pwr_on = MAINBOARD_POWER_ON;
  121. dm_pci_read_config16(pch, GEN_PMCON_3, &reg16);
  122. reg16 &= 0xfffe;
  123. switch (pwr_on) {
  124. case MAINBOARD_POWER_OFF:
  125. reg16 |= 1;
  126. state = "off";
  127. break;
  128. case MAINBOARD_POWER_ON:
  129. reg16 &= ~1;
  130. state = "on";
  131. break;
  132. case MAINBOARD_POWER_KEEP:
  133. reg16 &= ~1;
  134. state = "state keep";
  135. break;
  136. default:
  137. state = "undefined";
  138. }
  139. reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
  140. reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
  141. reg16 &= ~(1 << 10);
  142. reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
  143. reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
  144. dm_pci_write_config16(pch, GEN_PMCON_3, reg16);
  145. debug("Set power %s after power failure.\n", state);
  146. /* Set up NMI on errors. */
  147. reg8 = inb(0x61);
  148. reg8 &= 0x0f; /* Higher Nibble must be 0 */
  149. reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
  150. reg8 |= (1 << 2); /* PCI SERR# Disable for now */
  151. outb(reg8, 0x61);
  152. reg8 = inb(0x70);
  153. /* TODO(sjg@chromium.org): Make this configurable */
  154. nmi_option = NMI_OFF;
  155. if (nmi_option) {
  156. debug("NMI sources enabled.\n");
  157. reg8 &= ~(1 << 7); /* Set NMI. */
  158. } else {
  159. debug("NMI sources disabled.\n");
  160. /* Can't mask NMI from PCI-E and NMI_NOW */
  161. reg8 |= (1 << 7);
  162. }
  163. outb(reg8, 0x70);
  164. /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
  165. dm_pci_read_config16(pch, GEN_PMCON_1, &reg16);
  166. reg16 &= ~(3 << 0); /* SMI# rate 1 minute */
  167. reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
  168. #if DEBUG_PERIODIC_SMIS
  169. /* Set DEBUG_PERIODIC_SMIS in pch.h to debug using periodic SMIs */
  170. reg16 |= (3 << 0); /* Periodic SMI every 8s */
  171. #endif
  172. dm_pci_write_config16(pch, GEN_PMCON_1, reg16);
  173. /* Set the board's GPI routing. */
  174. ret = pch_gpi_routing(pch);
  175. if (ret)
  176. return ret;
  177. dm_pci_read_config16(pch, 0x40, &pmbase);
  178. pmbase &= 0xfffe;
  179. writel(pmbase + GPE0_EN, fdtdec_get_int(blob, node,
  180. "intel,gpe0-enable", 0));
  181. writew(pmbase + ALT_GP_SMI_EN, fdtdec_get_int(blob, node,
  182. "intel,alt-gp-smi-enable", 0));
  183. /* Set up power management block and determine sleep mode */
  184. reg32 = inl(pmbase + 0x04); /* PM1_CNT */
  185. reg32 &= ~(7 << 10); /* SLP_TYP */
  186. reg32 |= (1 << 0); /* SCI_EN */
  187. outl(reg32, pmbase + 0x04);
  188. /* Clear magic status bits to prevent unexpected wake */
  189. setbits_le32(RCB_REG(0x3310), (1 << 4) | (1 << 5) | (1 << 0));
  190. clrbits_le32(RCB_REG(0x3f02), 0xf);
  191. return 0;
  192. }
  193. static void pch_rtc_init(struct udevice *pch)
  194. {
  195. int rtc_failed;
  196. u8 reg8;
  197. dm_pci_read_config8(pch, GEN_PMCON_3, &reg8);
  198. rtc_failed = reg8 & RTC_BATTERY_DEAD;
  199. if (rtc_failed) {
  200. reg8 &= ~RTC_BATTERY_DEAD;
  201. dm_pci_write_config8(pch, GEN_PMCON_3, reg8);
  202. }
  203. debug("rtc_failed = 0x%x\n", rtc_failed);
  204. /* TODO: Handle power failure */
  205. if (rtc_failed)
  206. printf("RTC power failed\n");
  207. }
  208. /* CougarPoint PCH Power Management init */
  209. static void cpt_pm_init(struct udevice *pch)
  210. {
  211. debug("CougarPoint PM init\n");
  212. dm_pci_write_config8(pch, 0xa9, 0x47);
  213. setbits_le32(RCB_REG(0x2238), (1 << 6) | (1 << 0));
  214. setbits_le32(RCB_REG(0x228c), 1 << 0);
  215. setbits_le32(RCB_REG(0x1100), (1 << 13) | (1 << 14));
  216. setbits_le32(RCB_REG(0x0900), 1 << 14);
  217. writel(0xc0388400, RCB_REG(0x2304));
  218. setbits_le32(RCB_REG(0x2314), (1 << 5) | (1 << 18));
  219. setbits_le32(RCB_REG(0x2320), (1 << 15) | (1 << 1));
  220. clrsetbits_le32(RCB_REG(0x3314), ~0x1f, 0xf);
  221. writel(0x050f0000, RCB_REG(0x3318));
  222. writel(0x04000000, RCB_REG(0x3324));
  223. setbits_le32(RCB_REG(0x3340), 0xfffff);
  224. setbits_le32(RCB_REG(0x3344), 1 << 1);
  225. writel(0x0001c000, RCB_REG(0x3360));
  226. writel(0x00061100, RCB_REG(0x3368));
  227. writel(0x7f8fdfff, RCB_REG(0x3378));
  228. writel(0x000003fc, RCB_REG(0x337c));
  229. writel(0x00001000, RCB_REG(0x3388));
  230. writel(0x0001c000, RCB_REG(0x3390));
  231. writel(0x00000800, RCB_REG(0x33a0));
  232. writel(0x00001000, RCB_REG(0x33b0));
  233. writel(0x00093900, RCB_REG(0x33c0));
  234. writel(0x24653002, RCB_REG(0x33cc));
  235. writel(0x062108fe, RCB_REG(0x33d0));
  236. clrsetbits_le32(RCB_REG(0x33d4), 0x0fff0fff, 0x00670060);
  237. writel(0x01010000, RCB_REG(0x3a28));
  238. writel(0x01010404, RCB_REG(0x3a2c));
  239. writel(0x01041041, RCB_REG(0x3a80));
  240. clrsetbits_le32(RCB_REG(0x3a84), 0x0000ffff, 0x00001001);
  241. setbits_le32(RCB_REG(0x3a84), 1 << 24); /* SATA 2/3 disabled */
  242. setbits_le32(RCB_REG(0x3a88), 1 << 0); /* SATA 4/5 disabled */
  243. writel(0x00000001, RCB_REG(0x3a6c));
  244. clrsetbits_le32(RCB_REG(0x2344), ~0x00ffff00, 0xff00000c);
  245. clrsetbits_le32(RCB_REG(0x80c), 0xff << 20, 0x11 << 20);
  246. writel(0, RCB_REG(0x33c8));
  247. setbits_le32(RCB_REG(0x21b0), 0xf);
  248. }
  249. /* PantherPoint PCH Power Management init */
  250. static void ppt_pm_init(struct udevice *pch)
  251. {
  252. debug("PantherPoint PM init\n");
  253. dm_pci_write_config8(pch, 0xa9, 0x47);
  254. setbits_le32(RCB_REG(0x2238), 1 << 0);
  255. setbits_le32(RCB_REG(0x228c), 1 << 0);
  256. setbits_le16(RCB_REG(0x1100), (1 << 13) | (1 << 14));
  257. setbits_le16(RCB_REG(0x0900), 1 << 14);
  258. writel(0xc03b8400, RCB_REG(0x2304));
  259. setbits_le32(RCB_REG(0x2314), (1 << 5) | (1 << 18));
  260. setbits_le32(RCB_REG(0x2320), (1 << 15) | (1 << 1));
  261. clrsetbits_le32(RCB_REG(0x3314), 0x1f, 0xf);
  262. writel(0x054f0000, RCB_REG(0x3318));
  263. writel(0x04000000, RCB_REG(0x3324));
  264. setbits_le32(RCB_REG(0x3340), 0xfffff);
  265. setbits_le32(RCB_REG(0x3344), (1 << 1) | (1 << 0));
  266. writel(0x0001c000, RCB_REG(0x3360));
  267. writel(0x00061100, RCB_REG(0x3368));
  268. writel(0x7f8fdfff, RCB_REG(0x3378));
  269. writel(0x000003fd, RCB_REG(0x337c));
  270. writel(0x00001000, RCB_REG(0x3388));
  271. writel(0x0001c000, RCB_REG(0x3390));
  272. writel(0x00000800, RCB_REG(0x33a0));
  273. writel(0x00001000, RCB_REG(0x33b0));
  274. writel(0x00093900, RCB_REG(0x33c0));
  275. writel(0x24653002, RCB_REG(0x33cc));
  276. writel(0x067388fe, RCB_REG(0x33d0));
  277. clrsetbits_le32(RCB_REG(0x33d4), 0x0fff0fff, 0x00670060);
  278. writel(0x01010000, RCB_REG(0x3a28));
  279. writel(0x01010404, RCB_REG(0x3a2c));
  280. writel(0x01040000, RCB_REG(0x3a80));
  281. clrsetbits_le32(RCB_REG(0x3a84), 0x0000ffff, 0x00001001);
  282. /* SATA 2/3 disabled */
  283. setbits_le32(RCB_REG(0x3a84), 1 << 24);
  284. /* SATA 4/5 disabled */
  285. setbits_le32(RCB_REG(0x3a88), 1 << 0);
  286. writel(0x00000001, RCB_REG(0x3a6c));
  287. clrsetbits_le32(RCB_REG(0x2344), 0xff0000ff, 0xff00000c);
  288. clrsetbits_le32(RCB_REG(0x80c), 0xff << 20, 0x11 << 20);
  289. setbits_le32(RCB_REG(0x33a4), (1 << 0));
  290. writel(0, RCB_REG(0x33c8));
  291. setbits_le32(RCB_REG(0x21b0), 0xf);
  292. }
  293. static void enable_hpet(void)
  294. {
  295. /* Move HPET to default address 0xfed00000 and enable it */
  296. clrsetbits_le32(RCB_REG(HPTC), 3 << 0, 1 << 7);
  297. }
  298. static void enable_clock_gating(struct udevice *pch)
  299. {
  300. u32 reg32;
  301. u16 reg16;
  302. setbits_le32(RCB_REG(0x2234), 0xf);
  303. dm_pci_read_config16(pch, GEN_PMCON_1, &reg16);
  304. reg16 |= (1 << 2) | (1 << 11);
  305. dm_pci_write_config16(pch, GEN_PMCON_1, reg16);
  306. pch_iobp_update(0xEB007F07, ~0UL, (1 << 31));
  307. pch_iobp_update(0xEB004000, ~0UL, (1 << 7));
  308. pch_iobp_update(0xEC007F07, ~0UL, (1 << 31));
  309. pch_iobp_update(0xEC004000, ~0UL, (1 << 7));
  310. reg32 = readl(RCB_REG(CG));
  311. reg32 |= (1 << 31);
  312. reg32 |= (1 << 29) | (1 << 28);
  313. reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
  314. reg32 |= (1 << 16);
  315. reg32 |= (1 << 17);
  316. reg32 |= (1 << 18);
  317. reg32 |= (1 << 22);
  318. reg32 |= (1 << 23);
  319. reg32 &= ~(1 << 20);
  320. reg32 |= (1 << 19);
  321. reg32 |= (1 << 0);
  322. reg32 |= (0xf << 1);
  323. writel(reg32, RCB_REG(CG));
  324. setbits_le32(RCB_REG(0x38c0), 0x7);
  325. setbits_le32(RCB_REG(0x36d4), 0x6680c004);
  326. setbits_le32(RCB_REG(0x3564), 0x3);
  327. }
  328. #if CONFIG_HAVE_SMI_HANDLER
  329. static void pch_lock_smm(pci_dev_t dev)
  330. {
  331. #if TEST_SMM_FLASH_LOCKDOWN
  332. u8 reg8;
  333. #endif
  334. if (acpi_slp_type != 3) {
  335. #if ENABLE_ACPI_MODE_IN_COREBOOT
  336. debug("Enabling ACPI via APMC:\n");
  337. outb(0xe1, 0xb2); /* Enable ACPI mode */
  338. debug("done.\n");
  339. #else
  340. debug("Disabling ACPI via APMC:\n");
  341. outb(0x1e, 0xb2); /* Disable ACPI mode */
  342. debug("done.\n");
  343. #endif
  344. }
  345. /* Don't allow evil boot loaders, kernels, or
  346. * userspace applications to deceive us:
  347. */
  348. smm_lock();
  349. #if TEST_SMM_FLASH_LOCKDOWN
  350. /* Now try this: */
  351. debug("Locking BIOS to RO... ");
  352. reg8 = x86_pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
  353. debug(" BLE: %s; BWE: %s\n", (reg8 & 2) ? "on" : "off",
  354. (reg8 & 1) ? "rw" : "ro");
  355. reg8 &= ~(1 << 0); /* clear BIOSWE */
  356. x86_pci_write_config8(dev, 0xdc, reg8);
  357. reg8 |= (1 << 1); /* set BLE */
  358. x86_pci_write_config8(dev, 0xdc, reg8);
  359. debug("ok.\n");
  360. reg8 = x86_pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
  361. debug(" BLE: %s; BWE: %s\n", (reg8 & 2) ? "on" : "off",
  362. (reg8 & 1) ? "rw" : "ro");
  363. debug("Writing:\n");
  364. writeb(0, 0xfff00000);
  365. debug("Testing:\n");
  366. reg8 |= (1 << 0); /* set BIOSWE */
  367. x86_pci_write_config8(dev, 0xdc, reg8);
  368. reg8 = x86_pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
  369. debug(" BLE: %s; BWE: %s\n", (reg8 & 2) ? "on" : "off",
  370. (reg8 & 1) ? "rw" : "ro");
  371. debug("Done.\n");
  372. #endif
  373. }
  374. #endif
  375. static void pch_disable_smm_only_flashing(struct udevice *pch)
  376. {
  377. u8 reg8;
  378. debug("Enabling BIOS updates outside of SMM... ");
  379. dm_pci_read_config8(pch, 0xdc, &reg8); /* BIOS_CNTL */
  380. reg8 &= ~(1 << 5);
  381. dm_pci_write_config8(pch, 0xdc, reg8);
  382. }
  383. static void pch_fixups(struct udevice *pch)
  384. {
  385. u8 gen_pmcon_2;
  386. /* Indicate DRAM init done for MRC S3 to know it can resume */
  387. dm_pci_read_config8(pch, GEN_PMCON_2, &gen_pmcon_2);
  388. gen_pmcon_2 |= (1 << 7);
  389. dm_pci_write_config8(pch, GEN_PMCON_2, gen_pmcon_2);
  390. /* Enable DMI ASPM in the PCH */
  391. clrbits_le32(RCB_REG(0x2304), 1 << 10);
  392. setbits_le32(RCB_REG(0x21a4), (1 << 11) | (1 << 10));
  393. setbits_le32(RCB_REG(0x21a8), 0x3);
  394. }
  395. /*
  396. * Enable Prefetching and Caching.
  397. */
  398. static void enable_spi_prefetch(struct udevice *pch)
  399. {
  400. u8 reg8;
  401. dm_pci_read_config8(pch, 0xdc, &reg8);
  402. reg8 &= ~(3 << 2);
  403. reg8 |= (2 << 2); /* Prefetching and Caching Enabled */
  404. dm_pci_write_config8(pch, 0xdc, reg8);
  405. }
  406. static void enable_port80_on_lpc(struct udevice *pch)
  407. {
  408. /* Enable port 80 POST on LPC */
  409. dm_pci_write_config32(pch, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
  410. clrbits_le32(RCB_REG(GCS), 4);
  411. }
  412. static void set_spi_speed(void)
  413. {
  414. u32 fdod;
  415. /* Observe SPI Descriptor Component Section 0 */
  416. writel(0x1000, RCB_REG(SPI_DESC_COMP0));
  417. /* Extract the1 Write/Erase SPI Frequency from descriptor */
  418. fdod = readl(RCB_REG(SPI_FREQ_WR_ERA));
  419. fdod >>= 24;
  420. fdod &= 7;
  421. /* Set Software Sequence frequency to match */
  422. clrsetbits_8(RCB_REG(SPI_FREQ_SWSEQ), 7, fdod);
  423. }
  424. /**
  425. * lpc_early_init() - set up LPC serial ports and other early things
  426. *
  427. * @dev: LPC device
  428. * @return 0 if OK, -ve on error
  429. */
  430. static int lpc_early_init(struct udevice *dev)
  431. {
  432. struct reg_info {
  433. u32 base;
  434. u32 size;
  435. } values[4], *ptr;
  436. int count;
  437. int i;
  438. count = fdtdec_get_int_array_count(gd->fdt_blob, dev->of_offset,
  439. "intel,gen-dec", (u32 *)values,
  440. sizeof(values) / sizeof(u32));
  441. if (count < 0)
  442. return -EINVAL;
  443. /* Set COM1/COM2 decode range */
  444. dm_pci_write_config16(dev->parent, LPC_IO_DEC, 0x0010);
  445. /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */
  446. dm_pci_write_config16(dev->parent, LPC_EN, KBC_LPC_EN | MC_LPC_EN |
  447. GAMEL_LPC_EN | COMA_LPC_EN);
  448. /* Write all registers but use 0 if we run out of data */
  449. count = count * sizeof(u32) / sizeof(values[0]);
  450. for (i = 0, ptr = values; i < ARRAY_SIZE(values); i++, ptr++) {
  451. u32 reg = 0;
  452. if (i < count)
  453. reg = ptr->base | PCI_COMMAND_IO | (ptr->size << 16);
  454. dm_pci_write_config32(dev->parent, LPC_GENX_DEC(i), reg);
  455. }
  456. enable_spi_prefetch(dev->parent);
  457. /* This is already done in start.S, but let's do it in C */
  458. enable_port80_on_lpc(dev->parent);
  459. set_spi_speed();
  460. return 0;
  461. }
  462. static int lpc_init_extra(struct udevice *dev)
  463. {
  464. struct udevice *pch = dev->parent;
  465. const void *blob = gd->fdt_blob;
  466. int node;
  467. debug("pch: lpc_init\n");
  468. dm_pci_write_bar32(pch, 0, 0);
  469. dm_pci_write_bar32(pch, 1, 0xff800000);
  470. dm_pci_write_bar32(pch, 2, 0xfec00000);
  471. dm_pci_write_bar32(pch, 3, 0x800);
  472. dm_pci_write_bar32(pch, 4, 0x900);
  473. node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_PCH);
  474. if (node < 0)
  475. return -ENOENT;
  476. /* Set the value for PCI command register. */
  477. dm_pci_write_config16(pch, PCI_COMMAND, 0x000f);
  478. /* IO APIC initialization. */
  479. pch_enable_apic(pch);
  480. pch_enable_serial_irqs(pch);
  481. /* Setup the PIRQ. */
  482. pch_pirq_init(pch);
  483. /* Setup power options. */
  484. pch_power_options(pch);
  485. /* Initialize power management */
  486. switch (pch_silicon_type()) {
  487. case PCH_TYPE_CPT: /* CougarPoint */
  488. cpt_pm_init(pch);
  489. break;
  490. case PCH_TYPE_PPT: /* PantherPoint */
  491. ppt_pm_init(pch);
  492. break;
  493. default:
  494. printf("Unknown Chipset: %s\n", pch->name);
  495. return -ENOSYS;
  496. }
  497. /* Initialize the real time clock. */
  498. pch_rtc_init(pch);
  499. /* Initialize the High Precision Event Timers, if present. */
  500. enable_hpet();
  501. /* Initialize Clock Gating */
  502. enable_clock_gating(pch);
  503. pch_disable_smm_only_flashing(pch);
  504. #if CONFIG_HAVE_SMI_HANDLER
  505. pch_lock_smm(dev);
  506. #endif
  507. pch_fixups(pch);
  508. return 0;
  509. }
  510. static int bd82x6x_lpc_early_init(struct udevice *dev)
  511. {
  512. /* Setting up Southbridge. In the northbridge code. */
  513. debug("Setting up static southbridge registers\n");
  514. dm_pci_write_config32(dev->parent, PCH_RCBA_BASE, DEFAULT_RCBA | 1);
  515. dm_pci_write_config32(dev->parent, PMBASE, DEFAULT_PMBASE | 1);
  516. /* Enable ACPI BAR */
  517. dm_pci_write_config8(dev->parent, ACPI_CNTL, 0x80);
  518. debug("Disabling watchdog reboot\n");
  519. setbits_le32(RCB_REG(GCS), 1 >> 5); /* No reset */
  520. outw(1 << 11, DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
  521. dm_pci_write_config32(dev->parent, GPIO_BASE, DEFAULT_GPIOBASE | 1);
  522. dm_pci_write_config32(dev->parent, GPIO_CNTL, 0x10);
  523. return 0;
  524. }
  525. static int bd82x6x_lpc_probe(struct udevice *dev)
  526. {
  527. int ret;
  528. if (!(gd->flags & GD_FLG_RELOC)) {
  529. ret = lpc_early_init(dev);
  530. if (ret) {
  531. debug("%s: lpc_early_init() failed\n", __func__);
  532. return ret;
  533. }
  534. return bd82x6x_lpc_early_init(dev);
  535. }
  536. return lpc_init_extra(dev);
  537. }
  538. static const struct udevice_id bd82x6x_lpc_ids[] = {
  539. { .compatible = "intel,bd82x6x-lpc" },
  540. { }
  541. };
  542. U_BOOT_DRIVER(bd82x6x_lpc_drv) = {
  543. .name = "lpc",
  544. .id = UCLASS_LPC,
  545. .of_match = bd82x6x_lpc_ids,
  546. .probe = bd82x6x_lpc_probe,
  547. };