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

usb: typec: altmodes/displayport: Add pin assignment helper

The code to extract a peripheral's currently supported Pin Assignments
is repeated in a couple of locations. Factor it out into a separate
function.

This will also make it easier to add fixes (we only need to update 1
location instead of 2).

Fixes: c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles")
Cc: stable@vger.kernel.org
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20230111020546.3384569-1-pmalani@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Prashant Malani and committed by
Greg Kroah-Hartman
582836e3 ce405d56

+14 -8
+14 -8
drivers/usb/typec/altmodes/displayport.c
··· 419 419 [DP_PIN_ASSIGN_F] = "F", 420 420 }; 421 421 422 + /* 423 + * Helper function to extract a peripheral's currently supported 424 + * Pin Assignments from its DisplayPort alternate mode state. 425 + */ 426 + static u8 get_current_pin_assignments(struct dp_altmode *dp) 427 + { 428 + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) 429 + return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); 430 + else 431 + return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); 432 + } 433 + 422 434 static ssize_t 423 435 pin_assignment_store(struct device *dev, struct device_attribute *attr, 424 436 const char *buf, size_t size) ··· 457 445 goto out_unlock; 458 446 } 459 447 460 - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) 461 - assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); 462 - else 463 - assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); 448 + assignments = get_current_pin_assignments(dp); 464 449 465 450 if (!(DP_CONF_GET_PIN_ASSIGN(conf) & assignments)) { 466 451 ret = -EINVAL; ··· 494 485 495 486 cur = get_count_order(DP_CONF_GET_PIN_ASSIGN(dp->data.conf)); 496 487 497 - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) 498 - assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); 499 - else 500 - assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); 488 + assignments = get_current_pin_assignments(dp); 501 489 502 490 for (i = 0; assignments; assignments >>= 1, i++) { 503 491 if (assignments & 1) {