2 * Copyright (C) 2014 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
15 #include <asm/lapic.h>
17 #include <asm/arch/bd82x6x.h>
18 #include <asm/arch/model_206ax.h>
19 #include <asm/arch/pch.h>
20 #include <asm/arch/sandybridge.h>
22 #define GPIO_BASE 0x48
23 #define BIOS_CTRL 0xdc
25 static int pch_revision_id = -1;
26 static int pch_type = -1;
29 * pch_silicon_revision() - Read silicon revision ID from the PCH
32 * @return silicon revision ID
34 static int pch_silicon_revision(struct udevice *dev)
38 if (pch_revision_id < 0) {
39 dm_pci_read_config8(dev, PCI_REVISION_ID, &val);
40 pch_revision_id = val;
43 return pch_revision_id;
46 int pch_silicon_type(struct udevice *dev)
51 dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val);
59 * pch_silicon_supported() - Check if a certain revision is supported
63 * @rev: Minimum required resion
64 * @return 0 if not supported, 1 if supported
66 static int pch_silicon_supported(struct udevice *dev, int type, int rev)
68 int cur_type = pch_silicon_type(dev);
69 int cur_rev = pch_silicon_revision(dev);
73 /* CougarPoint minimum revision */
74 if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
76 /* PantherPoint any revision */
77 if (cur_type == PCH_TYPE_PPT)
82 /* PantherPoint minimum revision */
83 if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
91 #define IOBP_RETRY 1000
92 static inline int iobp_poll(void)
94 unsigned try = IOBP_RETRY;
98 data = readl(RCB_REG(IOBPS));
104 printf("IOBP timeout\n");
108 void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
113 /* Set the address */
114 writel(address, RCB_REG(IOBPIRI));
117 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
118 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
120 writel(IOBPS_READ_AX, RCB_REG(IOBPS));
125 data = readl(RCB_REG(IOBPD));
129 /* Check for successful transaction */
130 if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
131 printf("IOBP read 0x%08x failed\n", address);
135 /* Update the data */
140 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
141 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
143 writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
147 /* Write IOBP data */
148 writel(data, RCB_REG(IOBPD));
153 static int bd82x6x_probe(struct udevice *dev)
155 struct udevice *gma_dev;
158 if (!(gd->flags & GD_FLG_RELOC))
161 /* Cause the SATA device to do its init */
162 uclass_first_device(UCLASS_DISK, &dev);
164 ret = syscon_get_by_driver_data(X86_SYSCON_GMA, &gma_dev);
167 ret = gma_func0_init(gma_dev);
174 static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
178 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
179 /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
180 rcba = rcba & 0xffffc000;
181 *sbasep = rcba + 0x3800;
186 static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
190 /* Adjust the BIOS write protect and SMM BIOS Write Protect Disable */
191 dm_pci_read_config8(dev, BIOS_CTRL, &bios_cntl);
193 bios_cntl &= ~BIOS_CTRL_BIOSWE;
196 bios_cntl |= BIOS_CTRL_BIOSWE;
197 bios_cntl &= ~BIT(5);
199 dm_pci_write_config8(dev, BIOS_CTRL, bios_cntl);
204 static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
209 * GPIO_BASE moved to its current offset with ICH6, but prior to
210 * that it was unused (or undocumented). Check that it looks
211 * okay: not all ones or zeros.
213 * Note we don't need check bit0 here, because the Tunnel Creek
214 * GPIO base address register bit0 is reserved (read returns 0),
215 * while on the Ivybridge the bit0 is used to indicate it is an
218 dm_pci_read_config32(dev, GPIO_BASE, &base);
219 if (base == 0x00000000 || base == 0xffffffff) {
220 debug("%s: unexpected BASE value\n", __func__);
225 * Okay, I guess we're looking at the right device. The actual
226 * GPIO registers are in the PCI device's I/O space, starting
227 * at the offset that we just read. Bit 0 indicates that it's
228 * an I/O address, not a memory address, so mask that off.
230 *gbasep = base & 1 ? base & ~3 : base & ~15;
235 static const struct pch_ops bd82x6x_pch_ops = {
236 .get_spi_base = bd82x6x_pch_get_spi_base,
237 .set_spi_protect = bd82x6x_set_spi_protect,
238 .get_gpio_base = bd82x6x_get_gpio_base,
241 static const struct udevice_id bd82x6x_ids[] = {
242 { .compatible = "intel,bd82x6x" },
246 U_BOOT_DRIVER(bd82x6x_drv) = {
249 .of_match = bd82x6x_ids,
250 .probe = bd82x6x_probe,
251 .ops = &bd82x6x_pch_ops,