Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Google, Inc |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 4 | */ |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 5 | #include <dm.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 6 | #include <errno.h> |
| 7 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 10 | #include <pch.h> |
Simon Glass | a75abeb | 2016-01-17 16:11:59 -0700 | [diff] [blame] | 11 | #include <asm/cpu.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Simon Glass | ab39d33 | 2016-03-11 22:06:56 -0700 | [diff] [blame] | 13 | #include <asm/intel_regs.h> |
Simon Glass | 6c9e1d8 | 2016-01-17 16:11:53 -0700 | [diff] [blame] | 14 | #include <asm/io.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 15 | #include <asm/lapic.h> |
Simon Glass | 63e08a2 | 2016-03-11 22:06:57 -0700 | [diff] [blame] | 16 | #include <asm/lpc_common.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 17 | #include <asm/pci.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 18 | #include <asm/arch/model_206ax.h> |
| 19 | #include <asm/arch/pch.h> |
| 20 | #include <asm/arch/sandybridge.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 21 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 22 | #include <linux/delay.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 23 | |
Simon Glass | d87b092 | 2017-01-16 07:03:37 -0700 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Simon Glass | 1a9360d | 2019-02-16 20:24:52 -0700 | [diff] [blame] | 26 | #define GPIO_BASE 0x48 |
| 27 | #define BIOS_CTRL 0xdc |
| 28 | |
| 29 | #define RCBA_AUDIO_CONFIG 0x2030 |
| 30 | #define RCBA_AUDIO_CONFIG_HDA BIT(31) |
| 31 | #define RCBA_AUDIO_CONFIG_MASK 0xfe |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 32 | |
Simon Glass | 6c9e1d8 | 2016-01-17 16:11:53 -0700 | [diff] [blame] | 33 | static int pch_revision_id = -1; |
| 34 | static int pch_type = -1; |
| 35 | |
| 36 | /** |
| 37 | * pch_silicon_revision() - Read silicon revision ID from the PCH |
| 38 | * |
| 39 | * @dev: PCH device |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 40 | * Return: silicon revision ID |
Simon Glass | 6c9e1d8 | 2016-01-17 16:11:53 -0700 | [diff] [blame] | 41 | */ |
| 42 | static int pch_silicon_revision(struct udevice *dev) |
| 43 | { |
| 44 | u8 val; |
| 45 | |
| 46 | if (pch_revision_id < 0) { |
| 47 | dm_pci_read_config8(dev, PCI_REVISION_ID, &val); |
| 48 | pch_revision_id = val; |
| 49 | } |
| 50 | |
| 51 | return pch_revision_id; |
| 52 | } |
| 53 | |
| 54 | int pch_silicon_type(struct udevice *dev) |
| 55 | { |
| 56 | u8 val; |
| 57 | |
| 58 | if (pch_type < 0) { |
| 59 | dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val); |
| 60 | pch_type = val; |
| 61 | } |
| 62 | |
| 63 | return pch_type; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * pch_silicon_supported() - Check if a certain revision is supported |
| 68 | * |
| 69 | * @dev: PCH device |
| 70 | * @type: PCH type |
| 71 | * @rev: Minimum required resion |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 72 | * Return: 0 if not supported, 1 if supported |
Simon Glass | 6c9e1d8 | 2016-01-17 16:11:53 -0700 | [diff] [blame] | 73 | */ |
| 74 | static int pch_silicon_supported(struct udevice *dev, int type, int rev) |
| 75 | { |
| 76 | int cur_type = pch_silicon_type(dev); |
| 77 | int cur_rev = pch_silicon_revision(dev); |
| 78 | |
| 79 | switch (type) { |
| 80 | case PCH_TYPE_CPT: |
| 81 | /* CougarPoint minimum revision */ |
| 82 | if (cur_type == PCH_TYPE_CPT && cur_rev >= rev) |
| 83 | return 1; |
| 84 | /* PantherPoint any revision */ |
| 85 | if (cur_type == PCH_TYPE_PPT) |
| 86 | return 1; |
| 87 | break; |
| 88 | |
| 89 | case PCH_TYPE_PPT: |
| 90 | /* PantherPoint minimum revision */ |
| 91 | if (cur_type == PCH_TYPE_PPT && cur_rev >= rev) |
| 92 | return 1; |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | #define IOBP_RETRY 1000 |
| 100 | static inline int iobp_poll(void) |
| 101 | { |
| 102 | unsigned try = IOBP_RETRY; |
| 103 | u32 data; |
| 104 | |
| 105 | while (try--) { |
| 106 | data = readl(RCB_REG(IOBPS)); |
| 107 | if ((data & 1) == 0) |
| 108 | return 1; |
| 109 | udelay(10); |
| 110 | } |
| 111 | |
| 112 | printf("IOBP timeout\n"); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue, |
| 117 | u32 orvalue) |
| 118 | { |
| 119 | u32 data; |
| 120 | |
| 121 | /* Set the address */ |
| 122 | writel(address, RCB_REG(IOBPIRI)); |
| 123 | |
| 124 | /* READ OPCODE */ |
| 125 | if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0)) |
| 126 | writel(IOBPS_RW_BX, RCB_REG(IOBPS)); |
| 127 | else |
| 128 | writel(IOBPS_READ_AX, RCB_REG(IOBPS)); |
| 129 | if (!iobp_poll()) |
| 130 | return; |
| 131 | |
| 132 | /* Read IOBP data */ |
| 133 | data = readl(RCB_REG(IOBPD)); |
| 134 | if (!iobp_poll()) |
| 135 | return; |
| 136 | |
| 137 | /* Check for successful transaction */ |
| 138 | if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) { |
| 139 | printf("IOBP read 0x%08x failed\n", address); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | /* Update the data */ |
| 144 | data &= andvalue; |
| 145 | data |= orvalue; |
| 146 | |
| 147 | /* WRITE OPCODE */ |
| 148 | if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0)) |
| 149 | writel(IOBPS_RW_BX, RCB_REG(IOBPS)); |
| 150 | else |
| 151 | writel(IOBPS_WRITE_AX, RCB_REG(IOBPS)); |
| 152 | if (!iobp_poll()) |
| 153 | return; |
| 154 | |
| 155 | /* Write IOBP data */ |
| 156 | writel(data, RCB_REG(IOBPD)); |
| 157 | if (!iobp_poll()) |
| 158 | return; |
| 159 | } |
| 160 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 161 | static int bd82x6x_probe(struct udevice *dev) |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 162 | { |
Simon Glass | 833eecd | 2023-05-04 16:50:49 -0600 | [diff] [blame] | 163 | /* make sure the LPC is inited since it provides the gpio base */ |
| 164 | uclass_first_device(UCLASS_LPC, &dev); |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 165 | |
Simon Glass | 833eecd | 2023-05-04 16:50:49 -0600 | [diff] [blame] | 166 | if (!IS_ENABLED(CONFIG_HAVE_FSP)) { |
| 167 | if (!(gd->flags & GD_FLG_RELOC)) |
| 168 | return 0; |
| 169 | |
| 170 | /* Cause the SATA device to do its init */ |
| 171 | uclass_first_device(UCLASS_AHCI, &dev); |
| 172 | } |
Simon Glass | 39f3f8c | 2016-01-17 16:11:37 -0700 | [diff] [blame] | 173 | |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 174 | return 0; |
| 175 | } |
| 176 | |
Bin Meng | 06d66af | 2016-02-01 01:40:42 -0800 | [diff] [blame] | 177 | static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep) |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 178 | { |
| 179 | u32 rcba; |
| 180 | |
| 181 | dm_pci_read_config32(dev, PCH_RCBA, &rcba); |
| 182 | /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */ |
| 183 | rcba = rcba & 0xffffc000; |
| 184 | *sbasep = rcba + 0x3800; |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 189 | static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect) |
| 190 | { |
Simon Glass | 63e08a2 | 2016-03-11 22:06:57 -0700 | [diff] [blame] | 191 | return lpc_set_spi_protect(dev, BIOS_CTRL, protect); |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Bin Meng | fd2afdf | 2016-02-01 01:40:44 -0800 | [diff] [blame] | 194 | static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep) |
| 195 | { |
| 196 | u32 base; |
| 197 | |
| 198 | /* |
| 199 | * GPIO_BASE moved to its current offset with ICH6, but prior to |
| 200 | * that it was unused (or undocumented). Check that it looks |
| 201 | * okay: not all ones or zeros. |
| 202 | * |
| 203 | * Note we don't need check bit0 here, because the Tunnel Creek |
| 204 | * GPIO base address register bit0 is reserved (read returns 0), |
| 205 | * while on the Ivybridge the bit0 is used to indicate it is an |
| 206 | * I/O space. |
| 207 | */ |
| 208 | dm_pci_read_config32(dev, GPIO_BASE, &base); |
| 209 | if (base == 0x00000000 || base == 0xffffffff) { |
| 210 | debug("%s: unexpected BASE value\n", __func__); |
| 211 | return -ENODEV; |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Okay, I guess we're looking at the right device. The actual |
| 216 | * GPIO registers are in the PCI device's I/O space, starting |
| 217 | * at the offset that we just read. Bit 0 indicates that it's |
| 218 | * an I/O address, not a memory address, so mask that off. |
| 219 | */ |
| 220 | *gbasep = base & 1 ? base & ~3 : base & ~15; |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
Simon Glass | 1a9360d | 2019-02-16 20:24:52 -0700 | [diff] [blame] | 225 | static int bd82x6x_ioctl(struct udevice *dev, enum pch_req_t req, void *data, |
| 226 | int size) |
| 227 | { |
| 228 | u32 rcba, val; |
| 229 | |
| 230 | switch (req) { |
| 231 | case PCH_REQ_HDA_CONFIG: |
| 232 | dm_pci_read_config32(dev, PCH_RCBA, &rcba); |
| 233 | val = readl(rcba + RCBA_AUDIO_CONFIG); |
| 234 | if (!(val & RCBA_AUDIO_CONFIG_HDA)) |
| 235 | return -ENOENT; |
| 236 | |
| 237 | return val & RCBA_AUDIO_CONFIG_MASK; |
Simon Glass | 027f837 | 2019-04-25 21:59:02 -0600 | [diff] [blame] | 238 | case PCH_REQ_PMBASE_INFO: { |
| 239 | struct pch_pmbase_info *pm = data; |
| 240 | int ret; |
| 241 | |
| 242 | /* Find the base address of the powermanagement registers */ |
| 243 | ret = dm_pci_read_config16(dev, 0x40, &pm->base); |
| 244 | if (ret) |
| 245 | return ret; |
| 246 | pm->base &= 0xfffe; |
| 247 | pm->gpio0_en_ofs = GPE0_EN; |
| 248 | pm->pm1_sts_ofs = PM1_STS; |
| 249 | pm->pm1_cnt_ofs = PM1_CNT; |
| 250 | |
| 251 | return 0; |
| 252 | } |
Simon Glass | 1a9360d | 2019-02-16 20:24:52 -0700 | [diff] [blame] | 253 | default: |
| 254 | return -ENOSYS; |
| 255 | } |
| 256 | } |
| 257 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 258 | static const struct pch_ops bd82x6x_pch_ops = { |
Bin Meng | 06d66af | 2016-02-01 01:40:42 -0800 | [diff] [blame] | 259 | .get_spi_base = bd82x6x_pch_get_spi_base, |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 260 | .set_spi_protect = bd82x6x_set_spi_protect, |
Bin Meng | fd2afdf | 2016-02-01 01:40:44 -0800 | [diff] [blame] | 261 | .get_gpio_base = bd82x6x_get_gpio_base, |
Simon Glass | 1a9360d | 2019-02-16 20:24:52 -0700 | [diff] [blame] | 262 | .ioctl = bd82x6x_ioctl, |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 263 | }; |
| 264 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 265 | static const struct udevice_id bd82x6x_ids[] = { |
| 266 | { .compatible = "intel,bd82x6x" }, |
| 267 | { } |
| 268 | }; |
| 269 | |
| 270 | U_BOOT_DRIVER(bd82x6x_drv) = { |
| 271 | .name = "bd82x6x", |
| 272 | .id = UCLASS_PCH, |
| 273 | .of_match = bd82x6x_ids, |
| 274 | .probe = bd82x6x_probe, |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 275 | .ops = &bd82x6x_pch_ops, |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 276 | }; |