bd82x6x.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright (C) 2014 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <fdtdec.h>
  10. #include <malloc.h>
  11. #include <pch.h>
  12. #include <asm/cpu.h>
  13. #include <asm/intel_regs.h>
  14. #include <asm/io.h>
  15. #include <asm/lapic.h>
  16. #include <asm/lpc_common.h>
  17. #include <asm/pci.h>
  18. #include <asm/arch/model_206ax.h>
  19. #include <asm/arch/pch.h>
  20. #include <asm/arch/sandybridge.h>
  21. #define GPIO_BASE 0x48
  22. #define BIOS_CTRL 0xdc
  23. #ifndef CONFIG_HAVE_FSP
  24. static int pch_revision_id = -1;
  25. static int pch_type = -1;
  26. /**
  27. * pch_silicon_revision() - Read silicon revision ID from the PCH
  28. *
  29. * @dev: PCH device
  30. * @return silicon revision ID
  31. */
  32. static int pch_silicon_revision(struct udevice *dev)
  33. {
  34. u8 val;
  35. if (pch_revision_id < 0) {
  36. dm_pci_read_config8(dev, PCI_REVISION_ID, &val);
  37. pch_revision_id = val;
  38. }
  39. return pch_revision_id;
  40. }
  41. int pch_silicon_type(struct udevice *dev)
  42. {
  43. u8 val;
  44. if (pch_type < 0) {
  45. dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val);
  46. pch_type = val;
  47. }
  48. return pch_type;
  49. }
  50. /**
  51. * pch_silicon_supported() - Check if a certain revision is supported
  52. *
  53. * @dev: PCH device
  54. * @type: PCH type
  55. * @rev: Minimum required resion
  56. * @return 0 if not supported, 1 if supported
  57. */
  58. static int pch_silicon_supported(struct udevice *dev, int type, int rev)
  59. {
  60. int cur_type = pch_silicon_type(dev);
  61. int cur_rev = pch_silicon_revision(dev);
  62. switch (type) {
  63. case PCH_TYPE_CPT:
  64. /* CougarPoint minimum revision */
  65. if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
  66. return 1;
  67. /* PantherPoint any revision */
  68. if (cur_type == PCH_TYPE_PPT)
  69. return 1;
  70. break;
  71. case PCH_TYPE_PPT:
  72. /* PantherPoint minimum revision */
  73. if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
  74. return 1;
  75. break;
  76. }
  77. return 0;
  78. }
  79. #define IOBP_RETRY 1000
  80. static inline int iobp_poll(void)
  81. {
  82. unsigned try = IOBP_RETRY;
  83. u32 data;
  84. while (try--) {
  85. data = readl(RCB_REG(IOBPS));
  86. if ((data & 1) == 0)
  87. return 1;
  88. udelay(10);
  89. }
  90. printf("IOBP timeout\n");
  91. return 0;
  92. }
  93. void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
  94. u32 orvalue)
  95. {
  96. u32 data;
  97. /* Set the address */
  98. writel(address, RCB_REG(IOBPIRI));
  99. /* READ OPCODE */
  100. if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
  101. writel(IOBPS_RW_BX, RCB_REG(IOBPS));
  102. else
  103. writel(IOBPS_READ_AX, RCB_REG(IOBPS));
  104. if (!iobp_poll())
  105. return;
  106. /* Read IOBP data */
  107. data = readl(RCB_REG(IOBPD));
  108. if (!iobp_poll())
  109. return;
  110. /* Check for successful transaction */
  111. if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
  112. printf("IOBP read 0x%08x failed\n", address);
  113. return;
  114. }
  115. /* Update the data */
  116. data &= andvalue;
  117. data |= orvalue;
  118. /* WRITE OPCODE */
  119. if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
  120. writel(IOBPS_RW_BX, RCB_REG(IOBPS));
  121. else
  122. writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
  123. if (!iobp_poll())
  124. return;
  125. /* Write IOBP data */
  126. writel(data, RCB_REG(IOBPD));
  127. if (!iobp_poll())
  128. return;
  129. }
  130. static int bd82x6x_probe(struct udevice *dev)
  131. {
  132. if (!(gd->flags & GD_FLG_RELOC))
  133. return 0;
  134. /* Cause the SATA device to do its init */
  135. uclass_first_device(UCLASS_AHCI, &dev);
  136. return 0;
  137. }
  138. #endif /* CONFIG_HAVE_FSP */
  139. static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
  140. {
  141. u32 rcba;
  142. dm_pci_read_config32(dev, PCH_RCBA, &rcba);
  143. /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
  144. rcba = rcba & 0xffffc000;
  145. *sbasep = rcba + 0x3800;
  146. return 0;
  147. }
  148. static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
  149. {
  150. return lpc_set_spi_protect(dev, BIOS_CTRL, protect);
  151. }
  152. static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
  153. {
  154. u32 base;
  155. /*
  156. * GPIO_BASE moved to its current offset with ICH6, but prior to
  157. * that it was unused (or undocumented). Check that it looks
  158. * okay: not all ones or zeros.
  159. *
  160. * Note we don't need check bit0 here, because the Tunnel Creek
  161. * GPIO base address register bit0 is reserved (read returns 0),
  162. * while on the Ivybridge the bit0 is used to indicate it is an
  163. * I/O space.
  164. */
  165. dm_pci_read_config32(dev, GPIO_BASE, &base);
  166. if (base == 0x00000000 || base == 0xffffffff) {
  167. debug("%s: unexpected BASE value\n", __func__);
  168. return -ENODEV;
  169. }
  170. /*
  171. * Okay, I guess we're looking at the right device. The actual
  172. * GPIO registers are in the PCI device's I/O space, starting
  173. * at the offset that we just read. Bit 0 indicates that it's
  174. * an I/O address, not a memory address, so mask that off.
  175. */
  176. *gbasep = base & 1 ? base & ~3 : base & ~15;
  177. return 0;
  178. }
  179. static const struct pch_ops bd82x6x_pch_ops = {
  180. .get_spi_base = bd82x6x_pch_get_spi_base,
  181. .set_spi_protect = bd82x6x_set_spi_protect,
  182. .get_gpio_base = bd82x6x_get_gpio_base,
  183. };
  184. static const struct udevice_id bd82x6x_ids[] = {
  185. { .compatible = "intel,bd82x6x" },
  186. { }
  187. };
  188. U_BOOT_DRIVER(bd82x6x_drv) = {
  189. .name = "bd82x6x",
  190. .id = UCLASS_PCH,
  191. .of_match = bd82x6x_ids,
  192. #ifndef CONFIG_HAVE_FSP
  193. .probe = bd82x6x_probe,
  194. #endif
  195. .ops = &bd82x6x_pch_ops,
  196. };