1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014 Google, Inc
12 #include <asm/intel_regs.h>
14 #include <asm/lapic.h>
15 #include <asm/lpc_common.h>
17 #include <asm/arch/model_206ax.h>
18 #include <asm/arch/pch.h>
19 #include <asm/arch/sandybridge.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 #define GPIO_BASE 0x48
24 #define BIOS_CTRL 0xdc
26 #define RCBA_AUDIO_CONFIG 0x2030
27 #define RCBA_AUDIO_CONFIG_HDA BIT(31)
28 #define RCBA_AUDIO_CONFIG_MASK 0xfe
30 #ifndef CONFIG_HAVE_FSP
31 static int pch_revision_id = -1;
32 static int pch_type = -1;
35 * pch_silicon_revision() - Read silicon revision ID from the PCH
38 * @return silicon revision ID
40 static int pch_silicon_revision(struct udevice *dev)
44 if (pch_revision_id < 0) {
45 dm_pci_read_config8(dev, PCI_REVISION_ID, &val);
46 pch_revision_id = val;
49 return pch_revision_id;
52 int pch_silicon_type(struct udevice *dev)
57 dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val);
65 * pch_silicon_supported() - Check if a certain revision is supported
69 * @rev: Minimum required resion
70 * @return 0 if not supported, 1 if supported
72 static int pch_silicon_supported(struct udevice *dev, int type, int rev)
74 int cur_type = pch_silicon_type(dev);
75 int cur_rev = pch_silicon_revision(dev);
79 /* CougarPoint minimum revision */
80 if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
82 /* PantherPoint any revision */
83 if (cur_type == PCH_TYPE_PPT)
88 /* PantherPoint minimum revision */
89 if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
97 #define IOBP_RETRY 1000
98 static inline int iobp_poll(void)
100 unsigned try = IOBP_RETRY;
104 data = readl(RCB_REG(IOBPS));
110 printf("IOBP timeout\n");
114 void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
119 /* Set the address */
120 writel(address, RCB_REG(IOBPIRI));
123 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
124 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
126 writel(IOBPS_READ_AX, RCB_REG(IOBPS));
131 data = readl(RCB_REG(IOBPD));
135 /* Check for successful transaction */
136 if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
137 printf("IOBP read 0x%08x failed\n", address);
141 /* Update the data */
146 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
147 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
149 writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
153 /* Write IOBP data */
154 writel(data, RCB_REG(IOBPD));
159 static int bd82x6x_probe(struct udevice *dev)
161 if (!(gd->flags & GD_FLG_RELOC))
164 /* Cause the SATA device to do its init */
165 uclass_first_device(UCLASS_AHCI, &dev);
169 #endif /* CONFIG_HAVE_FSP */
171 static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
175 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
176 /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
177 rcba = rcba & 0xffffc000;
178 *sbasep = rcba + 0x3800;
183 static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
185 return lpc_set_spi_protect(dev, BIOS_CTRL, protect);
188 static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
193 * GPIO_BASE moved to its current offset with ICH6, but prior to
194 * that it was unused (or undocumented). Check that it looks
195 * okay: not all ones or zeros.
197 * Note we don't need check bit0 here, because the Tunnel Creek
198 * GPIO base address register bit0 is reserved (read returns 0),
199 * while on the Ivybridge the bit0 is used to indicate it is an
202 dm_pci_read_config32(dev, GPIO_BASE, &base);
203 if (base == 0x00000000 || base == 0xffffffff) {
204 debug("%s: unexpected BASE value\n", __func__);
209 * Okay, I guess we're looking at the right device. The actual
210 * GPIO registers are in the PCI device's I/O space, starting
211 * at the offset that we just read. Bit 0 indicates that it's
212 * an I/O address, not a memory address, so mask that off.
214 *gbasep = base & 1 ? base & ~3 : base & ~15;
219 static int bd82x6x_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
225 case PCH_REQ_HDA_CONFIG:
226 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
227 val = readl(rcba + RCBA_AUDIO_CONFIG);
228 if (!(val & RCBA_AUDIO_CONFIG_HDA))
231 return val & RCBA_AUDIO_CONFIG_MASK;
237 static const struct pch_ops bd82x6x_pch_ops = {
238 .get_spi_base = bd82x6x_pch_get_spi_base,
239 .set_spi_protect = bd82x6x_set_spi_protect,
240 .get_gpio_base = bd82x6x_get_gpio_base,
241 .ioctl = bd82x6x_ioctl,
244 static const struct udevice_id bd82x6x_ids[] = {
245 { .compatible = "intel,bd82x6x" },
249 U_BOOT_DRIVER(bd82x6x_drv) = {
252 .of_match = bd82x6x_ids,
253 #ifndef CONFIG_HAVE_FSP
254 .probe = bd82x6x_probe,
256 .ops = &bd82x6x_pch_ops,