Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

platform/x86: alienware-wmi-wmax: Simplify FW profile to pprof matching

Drop profile matching micro-optimizations to improve readability and
long-term maintainability.

Additionally, is_awcc_thermal_profile_id is implicitly ignoring the
AWCC_PROFILE_SPECIAL_GMODE ID. State this explicitly with code and a
comment.

Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Link: https://patch.msgid.link/20251103-aw-gmode-v1-1-eba7b7be0a9c@gmail.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Kurt Borja and committed by
Ilpo Järvinen
ff49362e cec551ec

+57 -67
+57 -67
drivers/platform/x86/dell/alienware-wmi-wmax.c
··· 283 283 AWCC_THERMAL_TABLE_USTT = 0xA, 284 284 }; 285 285 286 - enum AWCC_SPECIAL_THERMAL_CODES { 287 - AWCC_SPECIAL_PROFILE_CUSTOM = 0x00, 288 - AWCC_SPECIAL_PROFILE_GMODE = 0xAB, 289 - }; 290 - 291 286 enum AWCC_TEMP_SENSOR_TYPES { 292 287 AWCC_TEMP_SENSOR_CPU = 0x01, 293 288 AWCC_TEMP_SENSOR_FRONT = 0x03, ··· 309 314 }; 310 315 311 316 enum awcc_thermal_profile { 312 - AWCC_PROFILE_USTT_BALANCED, 313 - AWCC_PROFILE_USTT_BALANCED_PERFORMANCE, 314 - AWCC_PROFILE_USTT_COOL, 315 - AWCC_PROFILE_USTT_QUIET, 316 - AWCC_PROFILE_USTT_PERFORMANCE, 317 - AWCC_PROFILE_USTT_LOW_POWER, 318 - AWCC_PROFILE_LEGACY_QUIET, 319 - AWCC_PROFILE_LEGACY_BALANCED, 320 - AWCC_PROFILE_LEGACY_BALANCED_PERFORMANCE, 321 - AWCC_PROFILE_LEGACY_PERFORMANCE, 322 - AWCC_PROFILE_LAST, 317 + AWCC_PROFILE_SPECIAL_CUSTOM = 0x00, 318 + AWCC_PROFILE_LEGACY_QUIET = 0x96, 319 + AWCC_PROFILE_LEGACY_BALANCED = 0x97, 320 + AWCC_PROFILE_LEGACY_BALANCED_PERFORMANCE = 0x98, 321 + AWCC_PROFILE_LEGACY_PERFORMANCE = 0x99, 322 + AWCC_PROFILE_USTT_BALANCED = 0xA0, 323 + AWCC_PROFILE_USTT_BALANCED_PERFORMANCE = 0xA1, 324 + AWCC_PROFILE_USTT_COOL = 0xA2, 325 + AWCC_PROFILE_USTT_QUIET = 0xA3, 326 + AWCC_PROFILE_USTT_PERFORMANCE = 0xA4, 327 + AWCC_PROFILE_USTT_LOW_POWER = 0xA5, 328 + AWCC_PROFILE_SPECIAL_GMODE = 0xAB, 323 329 }; 324 330 325 331 struct wmax_led_args { ··· 374 378 unsigned long temp_sensors[AWCC_ID_BITMAP_LONGS]; 375 379 376 380 u32 gpio_count; 377 - }; 378 - 379 - static const enum platform_profile_option awcc_mode_to_platform_profile[AWCC_PROFILE_LAST] = { 380 - [AWCC_PROFILE_USTT_BALANCED] = PLATFORM_PROFILE_BALANCED, 381 - [AWCC_PROFILE_USTT_BALANCED_PERFORMANCE] = PLATFORM_PROFILE_BALANCED_PERFORMANCE, 382 - [AWCC_PROFILE_USTT_COOL] = PLATFORM_PROFILE_COOL, 383 - [AWCC_PROFILE_USTT_QUIET] = PLATFORM_PROFILE_QUIET, 384 - [AWCC_PROFILE_USTT_PERFORMANCE] = PLATFORM_PROFILE_PERFORMANCE, 385 - [AWCC_PROFILE_USTT_LOW_POWER] = PLATFORM_PROFILE_LOW_POWER, 386 - [AWCC_PROFILE_LEGACY_QUIET] = PLATFORM_PROFILE_QUIET, 387 - [AWCC_PROFILE_LEGACY_BALANCED] = PLATFORM_PROFILE_BALANCED, 388 - [AWCC_PROFILE_LEGACY_BALANCED_PERFORMANCE] = PLATFORM_PROFILE_BALANCED_PERFORMANCE, 389 - [AWCC_PROFILE_LEGACY_PERFORMANCE] = PLATFORM_PROFILE_PERFORMANCE, 390 381 }; 391 382 392 383 static struct awcc_quirks *awcc; ··· 593 610 /* 594 611 * AWCC Helpers 595 612 */ 596 - static bool is_awcc_thermal_profile_id(u8 code) 613 + static int awcc_profile_to_pprof(enum awcc_thermal_profile profile, 614 + enum platform_profile_option *pprof) 597 615 { 598 - u8 table = FIELD_GET(AWCC_THERMAL_TABLE_MASK, code); 599 - u8 mode = FIELD_GET(AWCC_THERMAL_MODE_MASK, code); 616 + switch (profile) { 617 + case AWCC_PROFILE_SPECIAL_CUSTOM: 618 + *pprof = PLATFORM_PROFILE_CUSTOM; 619 + break; 620 + case AWCC_PROFILE_LEGACY_QUIET: 621 + case AWCC_PROFILE_USTT_QUIET: 622 + *pprof = PLATFORM_PROFILE_QUIET; 623 + break; 624 + case AWCC_PROFILE_LEGACY_BALANCED: 625 + case AWCC_PROFILE_USTT_BALANCED: 626 + *pprof = PLATFORM_PROFILE_BALANCED; 627 + break; 628 + case AWCC_PROFILE_LEGACY_BALANCED_PERFORMANCE: 629 + case AWCC_PROFILE_USTT_BALANCED_PERFORMANCE: 630 + *pprof = PLATFORM_PROFILE_BALANCED_PERFORMANCE; 631 + break; 632 + case AWCC_PROFILE_LEGACY_PERFORMANCE: 633 + case AWCC_PROFILE_USTT_PERFORMANCE: 634 + case AWCC_PROFILE_SPECIAL_GMODE: 635 + *pprof = PLATFORM_PROFILE_PERFORMANCE; 636 + break; 637 + case AWCC_PROFILE_USTT_COOL: 638 + *pprof = PLATFORM_PROFILE_COOL; 639 + break; 640 + case AWCC_PROFILE_USTT_LOW_POWER: 641 + *pprof = PLATFORM_PROFILE_LOW_POWER; 642 + break; 643 + default: 644 + return -EINVAL; 645 + } 600 646 601 - if (mode >= AWCC_PROFILE_LAST) 602 - return false; 603 - 604 - if (table == AWCC_THERMAL_TABLE_LEGACY && mode >= AWCC_PROFILE_LEGACY_QUIET) 605 - return true; 606 - 607 - if (table == AWCC_THERMAL_TABLE_USTT && mode <= AWCC_PROFILE_USTT_LOW_POWER) 608 - return true; 609 - 610 - return false; 647 + return 0; 611 648 } 612 649 613 650 static int awcc_wmi_command(struct wmi_device *wdev, u32 method_id, ··· 1276 1273 if (ret) 1277 1274 return ret; 1278 1275 1279 - switch (out_data) { 1280 - case AWCC_SPECIAL_PROFILE_CUSTOM: 1281 - *profile = PLATFORM_PROFILE_CUSTOM; 1282 - return 0; 1283 - case AWCC_SPECIAL_PROFILE_GMODE: 1284 - *profile = PLATFORM_PROFILE_PERFORMANCE; 1285 - return 0; 1286 - default: 1287 - break; 1288 - } 1289 - 1290 - if (!is_awcc_thermal_profile_id(out_data)) 1291 - return -ENODATA; 1292 - 1293 - out_data = FIELD_GET(AWCC_THERMAL_MODE_MASK, out_data); 1294 - *profile = awcc_mode_to_platform_profile[out_data]; 1295 - 1296 - return 0; 1276 + return awcc_profile_to_pprof(out_data, profile); 1297 1277 } 1298 1278 1299 1279 static int awcc_platform_profile_set(struct device *dev, ··· 1313 1327 { 1314 1328 enum platform_profile_option profile; 1315 1329 struct awcc_priv *priv = drvdata; 1316 - enum awcc_thermal_profile mode; 1317 1330 u8 id, offset = 0; 1318 1331 int ret; 1319 1332 ··· 1334 1349 if (ret) 1335 1350 return ret; 1336 1351 1337 - if (!is_awcc_thermal_profile_id(id)) { 1352 + /* 1353 + * G-Mode profile ID is not listed consistently across modeles 1354 + * that support it, therefore we handle it through quirks. 1355 + */ 1356 + if (id == AWCC_PROFILE_SPECIAL_GMODE) 1357 + continue; 1358 + 1359 + ret = awcc_profile_to_pprof(id, &profile); 1360 + if (ret) { 1338 1361 dev_dbg(&priv->wdev->dev, "Unmapped thermal profile ID 0x%02x\n", id); 1339 1362 continue; 1340 1363 } 1341 1364 1342 - mode = FIELD_GET(AWCC_THERMAL_MODE_MASK, id); 1343 - profile = awcc_mode_to_platform_profile[mode]; 1344 1365 priv->supported_profiles[profile] = id; 1345 - 1346 1366 __set_bit(profile, choices); 1347 1367 } 1348 1368 ··· 1356 1366 1357 1367 if (awcc->gmode) { 1358 1368 priv->supported_profiles[PLATFORM_PROFILE_PERFORMANCE] = 1359 - AWCC_SPECIAL_PROFILE_GMODE; 1369 + AWCC_PROFILE_SPECIAL_GMODE; 1360 1370 1361 1371 __set_bit(PLATFORM_PROFILE_PERFORMANCE, choices); 1362 1372 } 1363 1373 1364 1374 /* Every model supports the "custom" profile */ 1365 1375 priv->supported_profiles[PLATFORM_PROFILE_CUSTOM] = 1366 - AWCC_SPECIAL_PROFILE_CUSTOM; 1376 + AWCC_PROFILE_SPECIAL_CUSTOM; 1367 1377 1368 1378 __set_bit(PLATFORM_PROFILE_CUSTOM, choices); 1369 1379