1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014 Google, Inc
13 #include <asm/intel_regs.h>
15 #include <asm/lapic.h>
16 #include <asm/lpc_common.h>
18 #include <asm/arch/model_206ax.h>
19 #include <asm/arch/pch.h>
20 #include <asm/arch/sandybridge.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 #define GPIO_BASE 0x48
25 #define BIOS_CTRL 0xdc
27 #define RCBA_AUDIO_CONFIG 0x2030
28 #define RCBA_AUDIO_CONFIG_HDA BIT(31)
29 #define RCBA_AUDIO_CONFIG_MASK 0xfe
31 #ifndef CONFIG_HAVE_FSP
32 static int pch_revision_id = -1;
33 static int pch_type = -1;
36 * pch_silicon_revision() - Read silicon revision ID from the PCH
39 * @return silicon revision ID
41 static int pch_silicon_revision(struct udevice *dev)
45 if (pch_revision_id < 0) {
46 dm_pci_read_config8(dev, PCI_REVISION_ID, &val);
47 pch_revision_id = val;
50 return pch_revision_id;
53 int pch_silicon_type(struct udevice *dev)
58 dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val);
66 * pch_silicon_supported() - Check if a certain revision is supported
70 * @rev: Minimum required resion
71 * @return 0 if not supported, 1 if supported
73 static int pch_silicon_supported(struct udevice *dev, int type, int rev)
75 int cur_type = pch_silicon_type(dev);
76 int cur_rev = pch_silicon_revision(dev);
80 /* CougarPoint minimum revision */
81 if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
83 /* PantherPoint any revision */
84 if (cur_type == PCH_TYPE_PPT)
89 /* PantherPoint minimum revision */
90 if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
98 #define IOBP_RETRY 1000
99 static inline int iobp_poll(void)
101 unsigned try = IOBP_RETRY;
105 data = readl(RCB_REG(IOBPS));
111 printf("IOBP timeout\n");
115 void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
120 /* Set the address */
121 writel(address, RCB_REG(IOBPIRI));
124 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
125 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
127 writel(IOBPS_READ_AX, RCB_REG(IOBPS));
132 data = readl(RCB_REG(IOBPD));
136 /* Check for successful transaction */
137 if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
138 printf("IOBP read 0x%08x failed\n", address);
142 /* Update the data */
147 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
148 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
150 writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
154 /* Write IOBP data */
155 writel(data, RCB_REG(IOBPD));
160 static int bd82x6x_probe(struct udevice *dev)
162 if (!(gd->flags & GD_FLG_RELOC))
165 /* Cause the SATA device to do its init */
166 uclass_first_device(UCLASS_AHCI, &dev);
170 #endif /* CONFIG_HAVE_FSP */
172 static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
176 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
177 /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
178 rcba = rcba & 0xffffc000;
179 *sbasep = rcba + 0x3800;
184 static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
186 return lpc_set_spi_protect(dev, BIOS_CTRL, protect);
189 static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
194 * GPIO_BASE moved to its current offset with ICH6, but prior to
195 * that it was unused (or undocumented). Check that it looks
196 * okay: not all ones or zeros.
198 * Note we don't need check bit0 here, because the Tunnel Creek
199 * GPIO base address register bit0 is reserved (read returns 0),
200 * while on the Ivybridge the bit0 is used to indicate it is an
203 dm_pci_read_config32(dev, GPIO_BASE, &base);
204 if (base == 0x00000000 || base == 0xffffffff) {
205 debug("%s: unexpected BASE value\n", __func__);
210 * Okay, I guess we're looking at the right device. The actual
211 * GPIO registers are in the PCI device's I/O space, starting
212 * at the offset that we just read. Bit 0 indicates that it's
213 * an I/O address, not a memory address, so mask that off.
215 *gbasep = base & 1 ? base & ~3 : base & ~15;
220 static int bd82x6x_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
226 case PCH_REQ_HDA_CONFIG:
227 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
228 val = readl(rcba + RCBA_AUDIO_CONFIG);
229 if (!(val & RCBA_AUDIO_CONFIG_HDA))
232 return val & RCBA_AUDIO_CONFIG_MASK;
233 case PCH_REQ_PMBASE_INFO: {
234 struct pch_pmbase_info *pm = data;
237 /* Find the base address of the powermanagement registers */
238 ret = dm_pci_read_config16(dev, 0x40, &pm->base);
242 pm->gpio0_en_ofs = GPE0_EN;
243 pm->pm1_sts_ofs = PM1_STS;
244 pm->pm1_cnt_ofs = PM1_CNT;
253 static const struct pch_ops bd82x6x_pch_ops = {
254 .get_spi_base = bd82x6x_pch_get_spi_base,
255 .set_spi_protect = bd82x6x_set_spi_protect,
256 .get_gpio_base = bd82x6x_get_gpio_base,
257 .ioctl = bd82x6x_ioctl,
260 static const struct udevice_id bd82x6x_ids[] = {
261 { .compatible = "intel,bd82x6x" },
265 U_BOOT_DRIVER(bd82x6x_drv) = {
268 .of_match = bd82x6x_ids,
269 #ifndef CONFIG_HAVE_FSP
270 .probe = bd82x6x_probe,
272 .ops = &bd82x6x_pch_ops,