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 | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 5 | #include <common.h> |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 6 | #include <dm.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 7 | #include <errno.h> |
| 8 | #include <fdtdec.h> |
| 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 | ab39d33 | 2016-03-11 22:06:56 -0700 | [diff] [blame] | 12 | #include <asm/intel_regs.h> |
Simon Glass | 6c9e1d8 | 2016-01-17 16:11:53 -0700 | [diff] [blame] | 13 | #include <asm/io.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 14 | #include <asm/lapic.h> |
Simon Glass | 63e08a2 | 2016-03-11 22:06:57 -0700 | [diff] [blame] | 15 | #include <asm/lpc_common.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 16 | #include <asm/pci.h> |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 17 | #include <asm/arch/model_206ax.h> |
| 18 | #include <asm/arch/pch.h> |
| 19 | #include <asm/arch/sandybridge.h> |
| 20 | |
Simon Glass | d87b092 | 2017-01-16 07:03:37 -0700 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Simon Glass | 1a9360d | 2019-02-16 20:24:52 -0700 | [diff] [blame] | 23 | #define GPIO_BASE 0x48 |
| 24 | #define BIOS_CTRL 0xdc |
| 25 | |
| 26 | #define RCBA_AUDIO_CONFIG 0x2030 |
| 27 | #define RCBA_AUDIO_CONFIG_HDA BIT(31) |
| 28 | #define RCBA_AUDIO_CONFIG_MASK 0xfe |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 29 | |
Bin Meng | 051f175 | 2016-02-17 00:16:24 -0800 | [diff] [blame] | 30 | #ifndef CONFIG_HAVE_FSP |
Simon Glass | 6c9e1d8 | 2016-01-17 16:11:53 -0700 | [diff] [blame] | 31 | static int pch_revision_id = -1; |
| 32 | static int pch_type = -1; |
| 33 | |
| 34 | /** |
| 35 | * pch_silicon_revision() - Read silicon revision ID from the PCH |
| 36 | * |
| 37 | * @dev: PCH device |
| 38 | * @return silicon revision ID |
| 39 | */ |
| 40 | static int pch_silicon_revision(struct udevice *dev) |
| 41 | { |
| 42 | u8 val; |
| 43 | |
| 44 | if (pch_revision_id < 0) { |
| 45 | dm_pci_read_config8(dev, PCI_REVISION_ID, &val); |
| 46 | pch_revision_id = val; |
| 47 | } |
| 48 | |
| 49 | return pch_revision_id; |
| 50 | } |
| 51 | |
| 52 | int pch_silicon_type(struct udevice *dev) |
| 53 | { |
| 54 | u8 val; |
| 55 | |
| 56 | if (pch_type < 0) { |
| 57 | dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val); |
| 58 | pch_type = val; |
| 59 | } |
| 60 | |
| 61 | return pch_type; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * pch_silicon_supported() - Check if a certain revision is supported |
| 66 | * |
| 67 | * @dev: PCH device |
| 68 | * @type: PCH type |
| 69 | * @rev: Minimum required resion |
| 70 | * @return 0 if not supported, 1 if supported |
| 71 | */ |
| 72 | static int pch_silicon_supported(struct udevice *dev, int type, int rev) |
| 73 | { |
| 74 | int cur_type = pch_silicon_type(dev); |
| 75 | int cur_rev = pch_silicon_revision(dev); |
| 76 | |
| 77 | switch (type) { |
| 78 | case PCH_TYPE_CPT: |
| 79 | /* CougarPoint minimum revision */ |
| 80 | if (cur_type == PCH_TYPE_CPT && cur_rev >= rev) |
| 81 | return 1; |
| 82 | /* PantherPoint any revision */ |
| 83 | if (cur_type == PCH_TYPE_PPT) |
| 84 | return 1; |
| 85 | break; |
| 86 | |
| 87 | case PCH_TYPE_PPT: |
| 88 | /* PantherPoint minimum revision */ |
| 89 | if (cur_type == PCH_TYPE_PPT && cur_rev >= rev) |
| 90 | return 1; |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | #define IOBP_RETRY 1000 |
| 98 | static inline int iobp_poll(void) |
| 99 | { |
| 100 | unsigned try = IOBP_RETRY; |
| 101 | u32 data; |
| 102 | |
| 103 | while (try--) { |
| 104 | data = readl(RCB_REG(IOBPS)); |
| 105 | if ((data & 1) == 0) |
| 106 | return 1; |
| 107 | udelay(10); |
| 108 | } |
| 109 | |
| 110 | printf("IOBP timeout\n"); |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue, |
| 115 | u32 orvalue) |
| 116 | { |
| 117 | u32 data; |
| 118 | |
| 119 | /* Set the address */ |
| 120 | writel(address, RCB_REG(IOBPIRI)); |
| 121 | |
| 122 | /* READ OPCODE */ |
| 123 | if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0)) |
| 124 | writel(IOBPS_RW_BX, RCB_REG(IOBPS)); |
| 125 | else |
| 126 | writel(IOBPS_READ_AX, RCB_REG(IOBPS)); |
| 127 | if (!iobp_poll()) |
| 128 | return; |
| 129 | |
| 130 | /* Read IOBP data */ |
| 131 | data = readl(RCB_REG(IOBPD)); |
| 132 | if (!iobp_poll()) |
| 133 | return; |
| 134 | |
| 135 | /* Check for successful transaction */ |
| 136 | if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) { |
| 137 | printf("IOBP read 0x%08x failed\n", address); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | /* Update the data */ |
| 142 | data &= andvalue; |
| 143 | data |= orvalue; |
| 144 | |
| 145 | /* WRITE OPCODE */ |
| 146 | if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0)) |
| 147 | writel(IOBPS_RW_BX, RCB_REG(IOBPS)); |
| 148 | else |
| 149 | writel(IOBPS_WRITE_AX, RCB_REG(IOBPS)); |
| 150 | if (!iobp_poll()) |
| 151 | return; |
| 152 | |
| 153 | /* Write IOBP data */ |
| 154 | writel(data, RCB_REG(IOBPD)); |
| 155 | if (!iobp_poll()) |
| 156 | return; |
| 157 | } |
| 158 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 159 | static int bd82x6x_probe(struct udevice *dev) |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 160 | { |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 161 | if (!(gd->flags & GD_FLG_RELOC)) |
| 162 | return 0; |
| 163 | |
Simon Glass | 39f3f8c | 2016-01-17 16:11:37 -0700 | [diff] [blame] | 164 | /* Cause the SATA device to do its init */ |
Simon Glass | 85ee165 | 2016-05-01 11:35:52 -0600 | [diff] [blame] | 165 | uclass_first_device(UCLASS_AHCI, &dev); |
Simon Glass | 39f3f8c | 2016-01-17 16:11:37 -0700 | [diff] [blame] | 166 | |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 167 | return 0; |
| 168 | } |
Bin Meng | 051f175 | 2016-02-17 00:16:24 -0800 | [diff] [blame] | 169 | #endif /* CONFIG_HAVE_FSP */ |
Simon Glass | 17f1c40 | 2014-11-14 18:18:32 -0700 | [diff] [blame] | 170 | |
Bin Meng | 06d66af | 2016-02-01 01:40:42 -0800 | [diff] [blame] | 171 | static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep) |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 172 | { |
| 173 | u32 rcba; |
| 174 | |
| 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; |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 183 | static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect) |
| 184 | { |
Simon Glass | 63e08a2 | 2016-03-11 22:06:57 -0700 | [diff] [blame] | 185 | return lpc_set_spi_protect(dev, BIOS_CTRL, protect); |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Bin Meng | fd2afdf | 2016-02-01 01:40:44 -0800 | [diff] [blame] | 188 | static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep) |
| 189 | { |
| 190 | u32 base; |
| 191 | |
| 192 | /* |
| 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. |
| 196 | * |
| 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 |
| 200 | * I/O space. |
| 201 | */ |
| 202 | dm_pci_read_config32(dev, GPIO_BASE, &base); |
| 203 | if (base == 0x00000000 || base == 0xffffffff) { |
| 204 | debug("%s: unexpected BASE value\n", __func__); |
| 205 | return -ENODEV; |
| 206 | } |
| 207 | |
| 208 | /* |
| 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. |
| 213 | */ |
| 214 | *gbasep = base & 1 ? base & ~3 : base & ~15; |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
Simon Glass | 1a9360d | 2019-02-16 20:24:52 -0700 | [diff] [blame] | 219 | static int bd82x6x_ioctl(struct udevice *dev, enum pch_req_t req, void *data, |
| 220 | int size) |
| 221 | { |
| 222 | u32 rcba, val; |
| 223 | |
| 224 | switch (req) { |
| 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)) |
| 229 | return -ENOENT; |
| 230 | |
| 231 | return val & RCBA_AUDIO_CONFIG_MASK; |
Simon Glass | 027f837 | 2019-04-25 21:59:02 -0600 | [diff] [blame] | 232 | case PCH_REQ_PMBASE_INFO: { |
| 233 | struct pch_pmbase_info *pm = data; |
| 234 | int ret; |
| 235 | |
| 236 | /* Find the base address of the powermanagement registers */ |
| 237 | ret = dm_pci_read_config16(dev, 0x40, &pm->base); |
| 238 | if (ret) |
| 239 | return ret; |
| 240 | pm->base &= 0xfffe; |
| 241 | pm->gpio0_en_ofs = GPE0_EN; |
| 242 | pm->pm1_sts_ofs = PM1_STS; |
| 243 | pm->pm1_cnt_ofs = PM1_CNT; |
| 244 | |
| 245 | return 0; |
| 246 | } |
Simon Glass | 1a9360d | 2019-02-16 20:24:52 -0700 | [diff] [blame] | 247 | default: |
| 248 | return -ENOSYS; |
| 249 | } |
| 250 | } |
| 251 | |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 252 | static const struct pch_ops bd82x6x_pch_ops = { |
Bin Meng | 06d66af | 2016-02-01 01:40:42 -0800 | [diff] [blame] | 253 | .get_spi_base = bd82x6x_pch_get_spi_base, |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 254 | .set_spi_protect = bd82x6x_set_spi_protect, |
Bin Meng | fd2afdf | 2016-02-01 01:40:44 -0800 | [diff] [blame] | 255 | .get_gpio_base = bd82x6x_get_gpio_base, |
Simon Glass | 1a9360d | 2019-02-16 20:24:52 -0700 | [diff] [blame] | 256 | .ioctl = bd82x6x_ioctl, |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 259 | static const struct udevice_id bd82x6x_ids[] = { |
| 260 | { .compatible = "intel,bd82x6x" }, |
| 261 | { } |
| 262 | }; |
| 263 | |
| 264 | U_BOOT_DRIVER(bd82x6x_drv) = { |
| 265 | .name = "bd82x6x", |
| 266 | .id = UCLASS_PCH, |
| 267 | .of_match = bd82x6x_ids, |
Bin Meng | 051f175 | 2016-02-17 00:16:24 -0800 | [diff] [blame] | 268 | #ifndef CONFIG_HAVE_FSP |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 269 | .probe = bd82x6x_probe, |
Bin Meng | 051f175 | 2016-02-17 00:16:24 -0800 | [diff] [blame] | 270 | #endif |
Simon Glass | 3276163 | 2016-01-18 20:19:21 -0700 | [diff] [blame] | 271 | .ops = &bd82x6x_pch_ops, |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 272 | }; |