1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * AMD SoC Power Management Controller Driver Quirks 4 * 5 * Copyright (c) 2023, Advanced Micro Devices, Inc. 6 * All Rights Reserved. 7 * 8 * Author: Mario Limonciello <mario.limonciello@amd.com> 9 */ 10 11 #include <linux/dmi.h> 12 #include <linux/io.h> 13 #include <linux/ioport.h> 14 #include <asm/amd/fch.h> 15 16 #include "pmc.h" 17 18 struct quirk_entry { 19 u32 s2idle_bug_mmio; 20 bool spurious_8042; 21 }; 22 23 static struct quirk_entry quirk_s2idle_bug = { 24 .s2idle_bug_mmio = FCH_PM_BASE + FCH_PM_SCRATCH, 25 }; 26 27 static struct quirk_entry quirk_spurious_8042 = { 28 .spurious_8042 = true, 29 }; 30 31 static const struct dmi_system_id fwbug_list[] = { 32 { 33 .ident = "L14 Gen2 AMD", 34 .driver_data = &quirk_s2idle_bug, 35 .matches = { 36 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 37 DMI_MATCH(DMI_PRODUCT_NAME, "20X5"), 38 } 39 }, 40 { 41 .ident = "T14s Gen2 AMD", 42 .driver_data = &quirk_s2idle_bug, 43 .matches = { 44 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 45 DMI_MATCH(DMI_PRODUCT_NAME, "20XF"), 46 } 47 }, 48 { 49 .ident = "X13 Gen2 AMD", 50 .driver_data = &quirk_s2idle_bug, 51 .matches = { 52 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 53 DMI_MATCH(DMI_PRODUCT_NAME, "20XH"), 54 } 55 }, 56 { 57 .ident = "T14 Gen2 AMD", 58 .driver_data = &quirk_s2idle_bug, 59 .matches = { 60 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 61 DMI_MATCH(DMI_PRODUCT_NAME, "20XK"), 62 } 63 }, 64 { 65 .ident = "T14 Gen1 AMD", 66 .driver_data = &quirk_s2idle_bug, 67 .matches = { 68 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 69 DMI_MATCH(DMI_PRODUCT_NAME, "20UD"), 70 } 71 }, 72 { 73 .ident = "T14 Gen1 AMD", 74 .driver_data = &quirk_s2idle_bug, 75 .matches = { 76 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 77 DMI_MATCH(DMI_PRODUCT_NAME, "20UE"), 78 } 79 }, 80 { 81 .ident = "T14s Gen1 AMD", 82 .driver_data = &quirk_s2idle_bug, 83 .matches = { 84 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 85 DMI_MATCH(DMI_PRODUCT_NAME, "20UH"), 86 } 87 }, 88 { 89 .ident = "T14s Gen1 AMD", 90 .driver_data = &quirk_s2idle_bug, 91 .matches = { 92 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 93 DMI_MATCH(DMI_PRODUCT_NAME, "20UJ"), 94 } 95 }, 96 { 97 .ident = "P14s Gen1 AMD", 98 .driver_data = &quirk_s2idle_bug, 99 .matches = { 100 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 101 DMI_MATCH(DMI_PRODUCT_NAME, "20Y1"), 102 } 103 }, 104 { 105 .ident = "P14s Gen2 AMD", 106 .driver_data = &quirk_s2idle_bug, 107 .matches = { 108 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 109 DMI_MATCH(DMI_PRODUCT_NAME, "21A0"), 110 } 111 }, 112 { 113 .ident = "P14s Gen2 AMD", 114 .driver_data = &quirk_s2idle_bug, 115 .matches = { 116 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 117 DMI_MATCH(DMI_PRODUCT_NAME, "21A1"), 118 } 119 }, 120 /* https://bugzilla.kernel.org/show_bug.cgi?id=218024 */ 121 { 122 .ident = "V14 G4 AMN", 123 .driver_data = &quirk_s2idle_bug, 124 .matches = { 125 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 126 DMI_MATCH(DMI_PRODUCT_NAME, "82YT"), 127 } 128 }, 129 { 130 .ident = "V14 G4 AMN", 131 .driver_data = &quirk_s2idle_bug, 132 .matches = { 133 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 134 DMI_MATCH(DMI_PRODUCT_NAME, "83GE"), 135 } 136 }, 137 { 138 .ident = "V15 G4 AMN", 139 .driver_data = &quirk_s2idle_bug, 140 .matches = { 141 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 142 DMI_MATCH(DMI_PRODUCT_NAME, "82YU"), 143 } 144 }, 145 { 146 .ident = "V15 G4 AMN", 147 .driver_data = &quirk_s2idle_bug, 148 .matches = { 149 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 150 DMI_MATCH(DMI_PRODUCT_NAME, "83CQ"), 151 } 152 }, 153 { 154 .ident = "IdeaPad 1 14AMN7", 155 .driver_data = &quirk_s2idle_bug, 156 .matches = { 157 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 158 DMI_MATCH(DMI_PRODUCT_NAME, "82VF"), 159 } 160 }, 161 { 162 .ident = "IdeaPad 1 15AMN7", 163 .driver_data = &quirk_s2idle_bug, 164 .matches = { 165 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 166 DMI_MATCH(DMI_PRODUCT_NAME, "82VG"), 167 } 168 }, 169 { 170 .ident = "IdeaPad 1 15AMN7", 171 .driver_data = &quirk_s2idle_bug, 172 .matches = { 173 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 174 DMI_MATCH(DMI_PRODUCT_NAME, "82X5"), 175 } 176 }, 177 { 178 .ident = "IdeaPad Slim 3 14AMN8", 179 .driver_data = &quirk_s2idle_bug, 180 .matches = { 181 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 182 DMI_MATCH(DMI_PRODUCT_NAME, "82XN"), 183 } 184 }, 185 { 186 .ident = "IdeaPad Slim 3 15AMN8", 187 .driver_data = &quirk_s2idle_bug, 188 .matches = { 189 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), 190 DMI_MATCH(DMI_PRODUCT_NAME, "82XQ"), 191 } 192 }, 193 /* https://gitlab.freedesktop.org/drm/amd/-/issues/2684 */ 194 { 195 .ident = "HP Laptop 15s-eq2xxx", 196 .driver_data = &quirk_s2idle_bug, 197 .matches = { 198 DMI_MATCH(DMI_SYS_VENDOR, "HP"), 199 DMI_MATCH(DMI_PRODUCT_NAME, "HP Laptop 15s-eq2xxx"), 200 } 201 }, 202 /* https://community.frame.work/t/tracking-framework-amd-ryzen-7040-series-lid-wakeup-behavior-feedback/39128 */ 203 { 204 .ident = "Framework Laptop 13 (Phoenix)", 205 .driver_data = &quirk_spurious_8042, 206 .matches = { 207 DMI_MATCH(DMI_SYS_VENDOR, "Framework"), 208 DMI_MATCH(DMI_PRODUCT_NAME, "Laptop 13 (AMD Ryzen 7040Series)"), 209 DMI_MATCH(DMI_BIOS_VERSION, "03.03"), 210 } 211 }, 212 { 213 .ident = "Framework Laptop 13 (Phoenix)", 214 .driver_data = &quirk_spurious_8042, 215 .matches = { 216 DMI_MATCH(DMI_SYS_VENDOR, "Framework"), 217 DMI_MATCH(DMI_PRODUCT_NAME, "Laptop 13 (AMD Ryzen 7040Series)"), 218 DMI_MATCH(DMI_BIOS_VERSION, "03.05"), 219 } 220 }, 221 { 222 .ident = "MECHREVO Wujie 14X (GX4HRXL)", 223 .driver_data = &quirk_spurious_8042, 224 .matches = { 225 DMI_MATCH(DMI_BOARD_NAME, "WUJIE14-GX4HRXL"), 226 } 227 }, 228 /* https://bugzilla.kernel.org/show_bug.cgi?id=220116 */ 229 { 230 .ident = "PCSpecialist Lafite Pro V 14M", 231 .driver_data = &quirk_spurious_8042, 232 .matches = { 233 DMI_MATCH(DMI_SYS_VENDOR, "PCSpecialist"), 234 DMI_MATCH(DMI_PRODUCT_NAME, "Lafite Pro V 14M"), 235 } 236 }, 237 {} 238 }; 239 240 /* 241 * Laptops that run a SMI handler during the D3->D0 transition that occurs 242 * specifically when exiting suspend to idle which can cause 243 * large delays during resume when the IOMMU translation layer is enabled (the default 244 * behavior) for NVME devices: 245 * 246 * To avoid this firmware problem, skip the SMI handler on these machines before the 247 * D0 transition occurs. 248 */ 249 static void amd_pmc_skip_nvme_smi_handler(u32 s2idle_bug_mmio) 250 { 251 void __iomem *addr; 252 u8 val; 253 254 if (!request_mem_region_muxed(s2idle_bug_mmio, 1, "amd_pmc_pm80")) 255 return; 256 257 addr = ioremap(s2idle_bug_mmio, 1); 258 if (!addr) 259 goto cleanup_resource; 260 261 val = ioread8(addr); 262 iowrite8(val & ~BIT(0), addr); 263 264 iounmap(addr); 265 cleanup_resource: 266 release_mem_region(s2idle_bug_mmio, 1); 267 } 268 269 void amd_pmc_process_restore_quirks(struct amd_pmc_dev *dev) 270 { 271 if (dev->quirks && dev->quirks->s2idle_bug_mmio) 272 amd_pmc_skip_nvme_smi_handler(dev->quirks->s2idle_bug_mmio); 273 } 274 275 void amd_pmc_quirks_init(struct amd_pmc_dev *dev) 276 { 277 const struct dmi_system_id *dmi_id; 278 279 if (dev->cpu_id == AMD_CPU_ID_CZN) 280 dev->disable_8042_wakeup = true; 281 282 dmi_id = dmi_first_match(fwbug_list); 283 if (!dmi_id) 284 return; 285 dev->quirks = dmi_id->driver_data; 286 if (dev->quirks->s2idle_bug_mmio) 287 pr_info("Using s2idle quirk to avoid %s platform firmware bug\n", 288 dmi_id->ident); 289 if (dev->quirks->spurious_8042) 290 dev->disable_8042_wakeup = true; 291 } 292