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>
21 #include <linux/delay.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 #define GPIO_BASE 0x48
26 #define BIOS_CTRL 0xdc
28 #define RCBA_AUDIO_CONFIG 0x2030
29 #define RCBA_AUDIO_CONFIG_HDA BIT(31)
30 #define RCBA_AUDIO_CONFIG_MASK 0xfe
32 #ifndef CONFIG_HAVE_FSP
33 static int pch_revision_id = -1;
34 static int pch_type = -1;
37 * pch_silicon_revision() - Read silicon revision ID from the PCH
40 * @return silicon revision ID
42 static int pch_silicon_revision(struct udevice *dev)
46 if (pch_revision_id < 0) {
47 dm_pci_read_config8(dev, PCI_REVISION_ID, &val);
48 pch_revision_id = val;
51 return pch_revision_id;
54 int pch_silicon_type(struct udevice *dev)
59 dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val);
67 * pch_silicon_supported() - Check if a certain revision is supported
71 * @rev: Minimum required resion
72 * @return 0 if not supported, 1 if supported
74 static int pch_silicon_supported(struct udevice *dev, int type, int rev)
76 int cur_type = pch_silicon_type(dev);
77 int cur_rev = pch_silicon_revision(dev);
81 /* CougarPoint minimum revision */
82 if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
84 /* PantherPoint any revision */
85 if (cur_type == PCH_TYPE_PPT)
90 /* PantherPoint minimum revision */
91 if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
99 #define IOBP_RETRY 1000
100 static inline int iobp_poll(void)
102 unsigned try = IOBP_RETRY;
106 data = readl(RCB_REG(IOBPS));
112 printf("IOBP timeout\n");
116 void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
121 /* Set the address */
122 writel(address, RCB_REG(IOBPIRI));
125 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
126 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
128 writel(IOBPS_READ_AX, RCB_REG(IOBPS));
133 data = readl(RCB_REG(IOBPD));
137 /* Check for successful transaction */
138 if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
139 printf("IOBP read 0x%08x failed\n", address);
143 /* Update the data */
148 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
149 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
151 writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
155 /* Write IOBP data */
156 writel(data, RCB_REG(IOBPD));
161 static int bd82x6x_probe(struct udevice *dev)
163 if (!(gd->flags & GD_FLG_RELOC))
166 /* Cause the SATA device to do its init */
167 uclass_first_device(UCLASS_AHCI, &dev);
171 #endif /* CONFIG_HAVE_FSP */
173 static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
177 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
178 /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
179 rcba = rcba & 0xffffc000;
180 *sbasep = rcba + 0x3800;
185 static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
187 return lpc_set_spi_protect(dev, BIOS_CTRL, protect);
190 static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
195 * GPIO_BASE moved to its current offset with ICH6, but prior to
196 * that it was unused (or undocumented). Check that it looks
197 * okay: not all ones or zeros.
199 * Note we don't need check bit0 here, because the Tunnel Creek
200 * GPIO base address register bit0 is reserved (read returns 0),
201 * while on the Ivybridge the bit0 is used to indicate it is an
204 dm_pci_read_config32(dev, GPIO_BASE, &base);
205 if (base == 0x00000000 || base == 0xffffffff) {
206 debug("%s: unexpected BASE value\n", __func__);
211 * Okay, I guess we're looking at the right device. The actual
212 * GPIO registers are in the PCI device's I/O space, starting
213 * at the offset that we just read. Bit 0 indicates that it's
214 * an I/O address, not a memory address, so mask that off.
216 *gbasep = base & 1 ? base & ~3 : base & ~15;
221 static int bd82x6x_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
227 case PCH_REQ_HDA_CONFIG:
228 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
229 val = readl(rcba + RCBA_AUDIO_CONFIG);
230 if (!(val & RCBA_AUDIO_CONFIG_HDA))
233 return val & RCBA_AUDIO_CONFIG_MASK;
234 case PCH_REQ_PMBASE_INFO: {
235 struct pch_pmbase_info *pm = data;
238 /* Find the base address of the powermanagement registers */
239 ret = dm_pci_read_config16(dev, 0x40, &pm->base);
243 pm->gpio0_en_ofs = GPE0_EN;
244 pm->pm1_sts_ofs = PM1_STS;
245 pm->pm1_cnt_ofs = PM1_CNT;
254 static const struct pch_ops bd82x6x_pch_ops = {
255 .get_spi_base = bd82x6x_pch_get_spi_base,
256 .set_spi_protect = bd82x6x_set_spi_protect,
257 .get_gpio_base = bd82x6x_get_gpio_base,
258 .ioctl = bd82x6x_ioctl,
261 static const struct udevice_id bd82x6x_ids[] = {
262 { .compatible = "intel,bd82x6x" },
266 U_BOOT_DRIVER(bd82x6x_drv) = {
269 .of_match = bd82x6x_ids,
270 #ifndef CONFIG_HAVE_FSP
271 .probe = bd82x6x_probe,
273 .ops = &bd82x6x_pch_ops,