Angel Pons | f94ac9a | 2020-04-05 15:46:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 4 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Marc Jones | a6354a1 | 2014-12-26 22:11:14 -0700 | [diff] [blame] | 6 | #include <bootmode.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <delay.h> |
| 9 | #include <device/device.h> |
| 10 | #include <device/pci.h> |
| 11 | #include <device/pci_ids.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 12 | #include <string.h> |
| 13 | #include <reg_script.h> |
Matt DeVillier | 53e2446 | 2016-08-05 02:20:15 -0500 | [diff] [blame] | 14 | #include <drivers/intel/gma/i915.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | #include <drivers/intel/gma/i915_reg.h> |
Nico Huber | a06689c | 2019-10-08 20:56:41 +0200 | [diff] [blame] | 16 | #include <drivers/intel/gma/libgfxinit.h> |
Matt DeVillier | 773488f | 2017-10-18 12:27:25 -0500 | [diff] [blame] | 17 | #include <drivers/intel/gma/opregion.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 18 | #include <soc/cpu.h> |
Duncan Laurie | 1e6b591 | 2015-01-30 16:33:43 -0800 | [diff] [blame] | 19 | #include <soc/pm.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 20 | #include <soc/ramstage.h> |
| 21 | #include <soc/systemagent.h> |
| 22 | #include <soc/intel/broadwell/chip.h> |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 23 | #include <security/vboot/vbnv.h> |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 24 | #include <soc/igd.h> |
Elyes HAOUAS | 27d02d8 | 2019-05-15 21:11:39 +0200 | [diff] [blame] | 25 | #include <types.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 26 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 27 | #define GT_RETRY 1000 |
| 28 | enum { |
| 29 | GT_CDCLK_DEFAULT = 0, |
| 30 | GT_CDCLK_337, |
| 31 | GT_CDCLK_450, |
| 32 | GT_CDCLK_540, |
| 33 | GT_CDCLK_675, |
| 34 | }; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 35 | |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 36 | static u32 reg_em4; |
| 37 | static u32 reg_em5; |
| 38 | |
| 39 | u32 igd_get_reg_em4(void) { return reg_em4; } |
| 40 | u32 igd_get_reg_em5(void) { return reg_em5; } |
| 41 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 42 | struct reg_script haswell_early_init_script[] = { |
| 43 | /* Enable Force Wake */ |
| 44 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa180, 0x00000020), |
| 45 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010001), |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 46 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 1, GT_RETRY), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 47 | |
| 48 | /* Enable Counters */ |
| 49 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa248, 0x00000016), |
| 50 | |
| 51 | /* GFXPAUSE settings */ |
| 52 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa000, 0x00070020), |
| 53 | |
| 54 | /* ECO Settings */ |
| 55 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0xa180, 0xff3fffff, 0x15000000), |
| 56 | |
| 57 | /* Enable DOP Clock Gating */ |
| 58 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9424, 0x000003fd), |
| 59 | |
| 60 | /* Enable Unit Level Clock Gating */ |
| 61 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9400, 0x00000080), |
| 62 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9404, 0x40401000), |
| 63 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9408, 0x00000000), |
| 64 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x940c, 0x02000001), |
| 65 | |
| 66 | /* |
| 67 | * RC6 Settings |
| 68 | */ |
| 69 | |
| 70 | /* Wake Rate Limits */ |
| 71 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa090, 0x00000000), |
| 72 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa098, 0x03e80000), |
| 73 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa09c, 0x00280000), |
| 74 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0a8, 0x0001e848), |
| 75 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0ac, 0x00000019), |
| 76 | |
| 77 | /* Render/Video/Blitter Idle Max Count */ |
| 78 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x02054, 0x0000000a), |
| 79 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x12054, 0x0000000a), |
| 80 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x22054, 0x0000000a), |
| 81 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1a054, 0x0000000a), |
| 82 | |
| 83 | /* RC Sleep / RCx Thresholds */ |
| 84 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b0, 0x00000000), |
| 85 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b4, 0x000003e8), |
| 86 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b8, 0x0000c350), |
| 87 | |
| 88 | /* RP Settings */ |
| 89 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa010, 0x000f4240), |
| 90 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa014, 0x12060000), |
| 91 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa02c, 0x0000e808), |
| 92 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa030, 0x0003bd08), |
| 93 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa068, 0x000101d0), |
| 94 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa06c, 0x00055730), |
| 95 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa070, 0x0000000a), |
| 96 | |
| 97 | /* RP Control */ |
| 98 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa024, 0x00000b92), |
| 99 | |
| 100 | /* HW RC6 Control */ |
| 101 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa090, 0x88040000), |
| 102 | |
| 103 | /* Video Frequency Request */ |
| 104 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa00c, 0x08000000), |
| 105 | |
| 106 | /* Set RC6 VIDs */ |
| 107 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY), |
| 108 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138128, 0), |
| 109 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138124, 0x80000004), |
| 110 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY), |
| 111 | |
| 112 | /* Enable PM Interrupts */ |
| 113 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x4402c, 0x03000076), |
| 114 | |
| 115 | /* Enable RC6 in idle */ |
| 116 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa094, 0x00040000), |
| 117 | |
| 118 | REG_SCRIPT_END |
| 119 | }; |
| 120 | |
| 121 | static const struct reg_script haswell_late_init_script[] = { |
| 122 | /* Lock settings */ |
| 123 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a248, (1 << 31)), |
| 124 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a004, (1 << 4)), |
| 125 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a080, (1 << 2)), |
| 126 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a180, (1 << 31)), |
| 127 | |
| 128 | /* Disable Force Wake */ |
| 129 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010000), |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 130 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 0, GT_RETRY), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 131 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00000001), |
| 132 | |
| 133 | /* Enable power well for DP and Audio */ |
| 134 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x45400, (1 << 31)), |
| 135 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x45400, |
| 136 | (1 << 30), (1 << 30), GT_RETRY), |
| 137 | |
| 138 | REG_SCRIPT_END |
| 139 | }; |
| 140 | |
| 141 | static const struct reg_script broadwell_early_init_script[] = { |
| 142 | /* Enable Force Wake */ |
| 143 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010001), |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 144 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 1, GT_RETRY), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 145 | |
| 146 | /* Enable push bus metric control and shift */ |
| 147 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa248, 0x00000004), |
| 148 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa250, 0x000000ff), |
| 149 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa25c, 0x00000010), |
| 150 | |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 151 | /* GFXPAUSE settings (set based on stepping) */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 152 | |
| 153 | /* ECO Settings */ |
| 154 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa180, 0x45200000), |
| 155 | |
| 156 | /* Enable DOP Clock Gating */ |
| 157 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9424, 0x000000fd), |
| 158 | |
| 159 | /* Enable Unit Level Clock Gating */ |
| 160 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9400, 0x00000000), |
| 161 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9404, 0x40401000), |
| 162 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9408, 0x00000000), |
| 163 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x940c, 0x02000001), |
| 164 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1a054, 0x0000000a), |
| 165 | |
| 166 | /* Video Frequency Request */ |
| 167 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa00c, 0x08000000), |
| 168 | |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 169 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138158, 0x00000009), |
| 170 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x13815c, 0x0000000d), |
| 171 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 172 | /* |
| 173 | * RC6 Settings |
| 174 | */ |
| 175 | |
| 176 | /* Wake Rate Limits */ |
| 177 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x0a090, 0, 0), |
| 178 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a098, 0x03e80000), |
| 179 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a09c, 0x00280000), |
| 180 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0a8, 0x0001e848), |
| 181 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0ac, 0x00000019), |
| 182 | |
| 183 | /* Render/Video/Blitter Idle Max Count */ |
| 184 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x02054, 0x0000000a), |
| 185 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x12054, 0x0000000a), |
| 186 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x22054, 0x0000000a), |
| 187 | |
| 188 | /* RC Sleep / RCx Thresholds */ |
| 189 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0b0, 0x00000000), |
| 190 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0b8, 0x00000271), |
| 191 | |
| 192 | /* RP Settings */ |
| 193 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a010, 0x000f4240), |
| 194 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a014, 0x12060000), |
| 195 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a02c, 0x0000e808), |
| 196 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a030, 0x0003bd08), |
| 197 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a068, 0x000101d0), |
| 198 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a06c, 0x00055730), |
| 199 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a070, 0x0000000a), |
| 200 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a168, 0x00000006), |
| 201 | |
| 202 | /* RP Control */ |
| 203 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa024, 0x00000b92), |
| 204 | |
| 205 | /* HW RC6 Control */ |
| 206 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa090, 0x90040000), |
| 207 | |
| 208 | /* Set RC6 VIDs */ |
| 209 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY), |
| 210 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138128, 0), |
| 211 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138124, 0x80000004), |
| 212 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY), |
| 213 | |
| 214 | /* Enable PM Interrupts */ |
| 215 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x4402c, 0x03000076), |
| 216 | |
| 217 | /* Enable RC6 in idle */ |
| 218 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa094, 0x00040000), |
| 219 | |
| 220 | REG_SCRIPT_END |
| 221 | }; |
| 222 | |
| 223 | static const struct reg_script broadwell_late_init_script[] = { |
| 224 | /* Lock settings */ |
| 225 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a248, (1 << 31)), |
| 226 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a000, (1 << 18)), |
| 227 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a180, (1 << 31)), |
| 228 | |
| 229 | /* Disable Force Wake */ |
| 230 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010000), |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 231 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 0, GT_RETRY), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 232 | |
| 233 | /* Enable power well for DP and Audio */ |
| 234 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x45400, (1 << 31)), |
| 235 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x45400, |
| 236 | (1 << 30), (1 << 30), GT_RETRY), |
| 237 | |
| 238 | REG_SCRIPT_END |
| 239 | }; |
| 240 | |
| 241 | u32 map_oprom_vendev(u32 vendev) |
| 242 | { |
| 243 | return SA_IGD_OPROM_VENDEV; |
| 244 | } |
| 245 | |
| 246 | static struct resource *gtt_res = NULL; |
| 247 | |
Matt DeVillier | 53e2446 | 2016-08-05 02:20:15 -0500 | [diff] [blame] | 248 | u32 gtt_read(u32 reg) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 249 | { |
| 250 | u32 val; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 251 | val = read32(res2mmio(gtt_res, reg, 0)); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 252 | return val; |
| 253 | |
| 254 | } |
| 255 | |
Matt DeVillier | 53e2446 | 2016-08-05 02:20:15 -0500 | [diff] [blame] | 256 | void gtt_write(u32 reg, u32 data) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 257 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 258 | write32(res2mmio(gtt_res, reg, 0), data); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask) |
| 262 | { |
| 263 | u32 val = gtt_read(reg); |
| 264 | val &= andmask; |
| 265 | val |= ormask; |
| 266 | gtt_write(reg, val); |
| 267 | } |
| 268 | |
Matt DeVillier | 53e2446 | 2016-08-05 02:20:15 -0500 | [diff] [blame] | 269 | int gtt_poll(u32 reg, u32 mask, u32 value) |
| 270 | { unsigned int try = GT_RETRY; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 271 | u32 data; |
| 272 | |
| 273 | while (try--) { |
| 274 | data = gtt_read(reg); |
| 275 | if ((data & mask) == value) |
| 276 | return 1; |
| 277 | udelay(10); |
| 278 | } |
| 279 | |
| 280 | printk(BIOS_ERR, "GT init timeout\n"); |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static void igd_setup_panel(struct device *dev) |
| 285 | { |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame] | 286 | config_t *conf = config_of(dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 287 | u32 reg32; |
| 288 | |
| 289 | /* Setup Digital Port Hotplug */ |
| 290 | reg32 = gtt_read(PCH_PORT_HOTPLUG); |
| 291 | if (!reg32) { |
| 292 | reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 293 | reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 294 | reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
| 295 | gtt_write(PCH_PORT_HOTPLUG, reg32); |
| 296 | } |
| 297 | |
| 298 | /* Setup Panel Power On Delays */ |
| 299 | reg32 = gtt_read(PCH_PP_ON_DELAYS); |
| 300 | if (!reg32) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 301 | reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 302 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
| 303 | gtt_write(PCH_PP_ON_DELAYS, reg32); |
| 304 | } |
| 305 | |
| 306 | /* Setup Panel Power Off Delays */ |
| 307 | reg32 = gtt_read(PCH_PP_OFF_DELAYS); |
| 308 | if (!reg32) { |
| 309 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 310 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
| 311 | gtt_write(PCH_PP_OFF_DELAYS, reg32); |
| 312 | } |
| 313 | |
| 314 | /* Setup Panel Power Cycle Delay */ |
| 315 | if (conf->gpu_panel_power_cycle_delay) { |
| 316 | reg32 = gtt_read(PCH_PP_DIVISOR); |
| 317 | reg32 &= ~0xff; |
| 318 | reg32 |= conf->gpu_panel_power_cycle_delay & 0xff; |
| 319 | gtt_write(PCH_PP_DIVISOR, reg32); |
| 320 | } |
| 321 | |
Nico Huber | 3b57a7c | 2019-10-08 20:24:05 +0200 | [diff] [blame] | 322 | /* So far all devices seem to use the PCH PWM function. |
| 323 | The CPU PWM registers are all zero after reset. */ |
| 324 | if (conf->gpu_pch_backlight_pwm_hz) { |
| 325 | /* For Lynx Point-LP: |
| 326 | Reference clock is 24MHz. We can choose either a 16 |
| 327 | or a 128 step increment. Use 16 if we would have less |
| 328 | than 100 steps otherwise. */ |
| 329 | const unsigned int hz_limit = 24 * 1000 * 1000 / 128 / 100; |
| 330 | unsigned int pwm_increment, pwm_period; |
| 331 | u32 south_chicken2; |
| 332 | |
| 333 | south_chicken2 = gtt_read(SOUTH_CHICKEN2); |
| 334 | if (conf->gpu_pch_backlight_pwm_hz > hz_limit) { |
| 335 | pwm_increment = 16; |
Nico Huber | e47132b | 2020-03-23 01:33:23 +0100 | [diff] [blame] | 336 | south_chicken2 |= 1 << 5; |
Nico Huber | 3b57a7c | 2019-10-08 20:24:05 +0200 | [diff] [blame] | 337 | } else { |
| 338 | pwm_increment = 128; |
Nico Huber | e47132b | 2020-03-23 01:33:23 +0100 | [diff] [blame] | 339 | south_chicken2 &= ~(1 << 5); |
Nico Huber | 3b57a7c | 2019-10-08 20:24:05 +0200 | [diff] [blame] | 340 | } |
| 341 | gtt_write(SOUTH_CHICKEN2, south_chicken2); |
| 342 | |
| 343 | pwm_period = 24 * 1000 * 1000 / pwm_increment / conf->gpu_pch_backlight_pwm_hz; |
| 344 | /* Start with a 50% duty cycle. */ |
| 345 | gtt_write(BLC_PWM_PCH_CTL2, pwm_period << 16 | pwm_period / 2); |
| 346 | |
| 347 | gtt_write(BLC_PWM_PCH_CTL1, |
| 348 | (conf->gpu_pch_backlight_polarity == GPU_BACKLIGHT_POLARITY_LOW) << 29 | |
| 349 | BLM_PCH_OVERRIDE_ENABLE | BLM_PCH_PWM_ENABLE); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 353 | static int igd_get_cdclk_haswell(u32 *const cdsel, int *const inform_pc, |
| 354 | struct device *const dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 355 | { |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame] | 356 | const config_t *const conf = config_of(dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 357 | int cdclk = conf->cdclk; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 358 | |
| 359 | /* Check for ULX GT1 or GT2 */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 360 | const int devid = pci_read_config16(dev, PCI_DEVICE_ID); |
| 361 | const int gpu_is_ulx = devid == IGD_HASWELL_ULX_GT1 || |
| 362 | devid == IGD_HASWELL_ULX_GT2; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 363 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 364 | /* Check for fixed fused clock */ |
| 365 | if (gtt_read(0x42014) & 1 << 24) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 366 | cdclk = GT_CDCLK_450; |
| 367 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 368 | /* |
| 369 | * ULX defaults to 337MHz with possible override for 450MHz |
| 370 | * ULT is fixed at 450MHz |
| 371 | * others default to 540MHz with possible override for 450MHz |
| 372 | */ |
| 373 | if (gpu_is_ulx && cdclk <= GT_CDCLK_337) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 374 | cdclk = GT_CDCLK_337; |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 375 | else if (gpu_is_ulx || cpu_is_ult() || |
| 376 | cdclk == GT_CDCLK_337 || cdclk == GT_CDCLK_450) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 377 | cdclk = GT_CDCLK_450; |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 378 | else |
| 379 | cdclk = GT_CDCLK_540; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 380 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 381 | *cdsel = cdclk != GT_CDCLK_450; |
| 382 | *inform_pc = gpu_is_ulx; |
| 383 | return cdclk; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 386 | static int igd_get_cdclk_broadwell(u32 *const cdsel, int *const inform_pc, |
| 387 | struct device *const dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 388 | { |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 389 | static const u32 cdsel_by_cdclk[] = { 0, 2, 0, 1, 3 }; |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame] | 390 | const config_t *const conf = config_of(dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 391 | int cdclk = conf->cdclk; |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 392 | |
| 393 | /* Check for ULX */ |
| 394 | const int devid = pci_read_config16(dev, PCI_DEVICE_ID); |
| 395 | const int gpu_is_ulx = devid == IGD_BROADWELL_Y_GT2; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 396 | |
| 397 | /* Inform power controller of upcoming frequency change */ |
| 398 | gtt_write(0x138128, 0); |
| 399 | gtt_write(0x13812c, 0); |
| 400 | gtt_write(0x138124, 0x80000018); |
| 401 | |
| 402 | /* Poll GT driver mailbox for run/busy clear */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 403 | if (gtt_poll(0x138124, (1 << 31), (0 << 31))) { |
| 404 | *inform_pc = 1; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 405 | } else { |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 406 | cdclk = GT_CDCLK_450; |
| 407 | *inform_pc = 0; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 410 | /* Check for fixed fused clock */ |
| 411 | if (gtt_read(0x42014) & 1 << 24) |
| 412 | cdclk = GT_CDCLK_450; |
| 413 | |
| 414 | /* |
| 415 | * ULX defaults to 450MHz with possible override up to 540MHz |
| 416 | * ULT defaults to 540MHz with possible override up to 675MHz |
| 417 | * others default to 675MHz with possible override for lower freqs |
| 418 | */ |
| 419 | if (cdclk == GT_CDCLK_337) |
| 420 | cdclk = GT_CDCLK_337; |
| 421 | else if (cdclk == GT_CDCLK_450 || |
| 422 | (gpu_is_ulx && cdclk == GT_CDCLK_DEFAULT)) |
| 423 | cdclk = GT_CDCLK_450; |
| 424 | else if (cdclk == GT_CDCLK_540 || gpu_is_ulx || |
| 425 | (cpu_is_ult() && cdclk == GT_CDCLK_DEFAULT)) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 426 | cdclk = GT_CDCLK_540; |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 427 | else |
| 428 | cdclk = GT_CDCLK_675; |
| 429 | |
| 430 | *cdsel = cdsel_by_cdclk[cdclk]; |
| 431 | return cdclk; |
| 432 | } |
| 433 | |
| 434 | static void igd_cdclk_init(struct device *dev, const int is_broadwell) |
| 435 | { |
| 436 | u32 dpdiv, cdsel, cdval; |
| 437 | int cdclk, inform_pc; |
| 438 | |
| 439 | if (is_broadwell) |
| 440 | cdclk = igd_get_cdclk_broadwell(&cdsel, &inform_pc, dev); |
| 441 | else |
| 442 | cdclk = igd_get_cdclk_haswell(&cdsel, &inform_pc, dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 443 | |
| 444 | /* Set variables based on CD Clock setting */ |
| 445 | switch (cdclk) { |
| 446 | case GT_CDCLK_337: |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 447 | cdval = 337; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 448 | dpdiv = 169; |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 449 | reg_em4 = 16; |
| 450 | reg_em5 = 225; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 451 | break; |
| 452 | case GT_CDCLK_450: |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 453 | cdval = 449; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 454 | dpdiv = 225; |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 455 | reg_em4 = 4; |
| 456 | reg_em5 = 75; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 457 | break; |
| 458 | case GT_CDCLK_540: |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 459 | cdval = 539; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 460 | dpdiv = 270; |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 461 | reg_em4 = 4; |
| 462 | reg_em5 = 90; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 463 | break; |
| 464 | case GT_CDCLK_675: |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 465 | cdval = 674; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 466 | dpdiv = 338; |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 467 | reg_em4 = 8; |
| 468 | reg_em5 = 225; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 469 | default: |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | /* Set LPCLL_CTL CD Clock Frequency Select */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 474 | gtt_rmw(0x130040, 0xf3ffffff, cdsel << 26); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 475 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 476 | if (inform_pc) { |
| 477 | /* Inform power controller of selected frequency */ |
| 478 | gtt_write(0x138128, cdsel); |
| 479 | gtt_write(0x13812c, 0); |
| 480 | gtt_write(0x138124, 0x80000017); |
| 481 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 482 | |
| 483 | /* Program CD Clock Frequency */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 484 | gtt_rmw(0x46200, 0xfffffc00, cdval); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 485 | |
| 486 | /* Set CPU DP AUX 2X bit clock dividers */ |
| 487 | gtt_rmw(0x64010, 0xfffff800, dpdiv); |
| 488 | gtt_rmw(0x64810, 0xfffff800, dpdiv); |
| 489 | } |
| 490 | |
| 491 | static void igd_init(struct device *dev) |
| 492 | { |
| 493 | int is_broadwell = !!(cpu_family_model() == BROADWELL_FAMILY_ULT); |
| 494 | u32 rp1_gfx_freq; |
| 495 | |
Nico Huber | f2a0be2 | 2020-04-26 17:01:25 +0200 | [diff] [blame] | 496 | intel_gma_init_igd_opregion(); |
| 497 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 498 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 499 | if (!gtt_res || !gtt_res->base) |
| 500 | return; |
| 501 | |
Nico Huber | dd59762 | 2020-04-26 19:46:35 +0200 | [diff] [blame] | 502 | if (!CONFIG(NO_GFX_INIT)) |
| 503 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 504 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 505 | /* Wait for any configured pre-graphics delay */ |
Kyösti Mälkki | 1ec23c9 | 2015-05-29 06:18:18 +0300 | [diff] [blame] | 506 | if (!acpi_is_wakeup_s3()) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 507 | #if CONFIG(CHROMEOS) |
Joel Kitching | 807803a | 2019-05-10 12:58:53 +0800 | [diff] [blame] | 508 | if (display_init_required()) |
Duncan Laurie | 1e6b591 | 2015-01-30 16:33:43 -0800 | [diff] [blame] | 509 | mdelay(CONFIG_PRE_GRAPHICS_DELAY); |
Duncan Laurie | b8a7b71 | 2014-11-10 13:00:27 -0800 | [diff] [blame] | 510 | #else |
Duncan Laurie | 1e6b591 | 2015-01-30 16:33:43 -0800 | [diff] [blame] | 511 | mdelay(CONFIG_PRE_GRAPHICS_DELAY); |
Duncan Laurie | b8a7b71 | 2014-11-10 13:00:27 -0800 | [diff] [blame] | 512 | #endif |
Duncan Laurie | 1e6b591 | 2015-01-30 16:33:43 -0800 | [diff] [blame] | 513 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 514 | |
| 515 | /* Early init steps */ |
| 516 | if (is_broadwell) { |
| 517 | reg_script_run_on_dev(dev, broadwell_early_init_script); |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 518 | |
| 519 | /* Set GFXPAUSE based on stepping */ |
| 520 | if (cpu_stepping() <= (CPUID_BROADWELL_E0 & 0xf) && |
| 521 | systemagent_revision() <= 9) { |
| 522 | gtt_write(0xa000, 0x300ff); |
| 523 | } else { |
| 524 | gtt_write(0xa000, 0x30020); |
| 525 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 526 | } else { |
| 527 | reg_script_run_on_dev(dev, haswell_early_init_script); |
| 528 | } |
| 529 | |
| 530 | /* Set RP1 graphics frequency */ |
| 531 | rp1_gfx_freq = (MCHBAR32(0x5998) >> 8) & 0xff; |
| 532 | gtt_write(0xa008, rp1_gfx_freq << 24); |
| 533 | |
| 534 | /* Post VBIOS panel setup */ |
| 535 | igd_setup_panel(dev); |
| 536 | |
| 537 | /* Initialize PCI device, load/execute BIOS Option ROM */ |
| 538 | pci_dev_init(dev); |
| 539 | |
| 540 | /* Late init steps */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 541 | igd_cdclk_init(dev, is_broadwell); |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 542 | if (is_broadwell) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 543 | reg_script_run_on_dev(dev, broadwell_late_init_script); |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 544 | else |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 545 | reg_script_run_on_dev(dev, haswell_late_init_script); |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 546 | |
Duncan Laurie | 49efaf2 | 2014-10-09 16:13:24 -0700 | [diff] [blame] | 547 | if (gfx_get_init_done()) { |
| 548 | /* |
| 549 | * Work around VBIOS issue that is not clearing first 64 |
| 550 | * bytes of the framebuffer during VBE mode set. |
| 551 | */ |
| 552 | struct resource *fb = find_resource(dev, PCI_BASE_ADDRESS_2); |
| 553 | memset((void *)((u32)fb->base), 0, 64); |
| 554 | } |
| 555 | |
Kyösti Mälkki | 1ec23c9 | 2015-05-29 06:18:18 +0300 | [diff] [blame] | 556 | if (!gfx_get_init_done() && !acpi_is_wakeup_s3()) { |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 557 | /* |
| 558 | * Enable DDI-A if the Option ROM did not execute: |
| 559 | * |
| 560 | * bit 0: Display detected (RO) |
| 561 | * bit 4: DDI A supports 4 lanes and DDI E is not used |
| 562 | * bit 7: DDI buffer is idle |
| 563 | */ |
| 564 | gtt_write(DDI_BUF_CTL_A, DDI_BUF_IS_IDLE | DDI_A_4_LANES | |
| 565 | DDI_INIT_DISPLAY_DETECTED); |
| 566 | } |
Matt DeVillier | 773488f | 2017-10-18 12:27:25 -0500 | [diff] [blame] | 567 | |
Nico Huber | a06689c | 2019-10-08 20:56:41 +0200 | [diff] [blame] | 568 | if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) { |
| 569 | int lightup_ok; |
| 570 | gma_gfxinit(&lightup_ok); |
| 571 | gfx_set_init_done(lightup_ok); |
| 572 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 575 | static void gma_generate_ssdt(const struct device *dev) |
Matt DeVillier | 53e2446 | 2016-08-05 02:20:15 -0500 | [diff] [blame] | 576 | { |
| 577 | const struct soc_intel_broadwell_config *chip = dev->chip_info; |
| 578 | |
| 579 | drivers_intel_gma_displays_ssdt_generate(&chip->gfx); |
| 580 | } |
| 581 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 582 | static struct device_operations igd_ops = { |
Marc Jones | a6354a1 | 2014-12-26 22:11:14 -0700 | [diff] [blame] | 583 | .read_resources = &pci_dev_read_resources, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 584 | .set_resources = &pci_dev_set_resources, |
| 585 | .enable_resources = &pci_dev_enable_resources, |
| 586 | .init = &igd_init, |
| 587 | .ops_pci = &broadwell_pci_ops, |
Matt DeVillier | 53e2446 | 2016-08-05 02:20:15 -0500 | [diff] [blame] | 588 | .acpi_fill_ssdt = gma_generate_ssdt, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 589 | }; |
| 590 | |
| 591 | static const unsigned short pci_device_ids[] = { |
| 592 | IGD_HASWELL_ULT_GT1, |
| 593 | IGD_HASWELL_ULT_GT2, |
| 594 | IGD_HASWELL_ULT_GT3, |
| 595 | IGD_BROADWELL_U_GT1, |
| 596 | IGD_BROADWELL_U_GT2, |
| 597 | IGD_BROADWELL_U_GT3_15W, |
| 598 | IGD_BROADWELL_U_GT3_28W, |
| 599 | IGD_BROADWELL_Y_GT2, |
| 600 | IGD_BROADWELL_H_GT2, |
| 601 | IGD_BROADWELL_H_GT3, |
| 602 | 0, |
| 603 | }; |
| 604 | |
| 605 | static const struct pci_driver igd_driver __pci_driver = { |
| 606 | .ops = &igd_ops, |
| 607 | .vendor = PCI_VENDOR_ID_INTEL, |
| 608 | .devices = pci_device_ids, |
| 609 | }; |