Skip to content

Commit 582836e

Browse files
Prashant Malanigregkh
authored andcommitted
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: c1e5c2f ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles") Cc: [email protected] Cc: Heikki Krogerus <[email protected]> Signed-off-by: Prashant Malani <[email protected]> Reviewed-by: Benson Leung <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ce405d5 commit 582836e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/usb/typec/altmodes/displayport.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,18 @@ static const char * const pin_assignments[] = {
419419
[DP_PIN_ASSIGN_F] = "F",
420420
};
421421

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+
422434
static ssize_t
423435
pin_assignment_store(struct device *dev, struct device_attribute *attr,
424436
const char *buf, size_t size)
@@ -445,10 +457,7 @@ pin_assignment_store(struct device *dev, struct device_attribute *attr,
445457
goto out_unlock;
446458
}
447459

448-
if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
449-
assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
450-
else
451-
assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
460+
assignments = get_current_pin_assignments(dp);
452461

453462
if (!(DP_CONF_GET_PIN_ASSIGN(conf) & assignments)) {
454463
ret = -EINVAL;
@@ -485,10 +494,7 @@ static ssize_t pin_assignment_show(struct device *dev,
485494

486495
cur = get_count_order(DP_CONF_GET_PIN_ASSIGN(dp->data.conf));
487496

488-
if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
489-
assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
490-
else
491-
assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
497+
assignments = get_current_pin_assignments(dp);
492498

493499
for (i = 0; assignments; assignments >>= 1, i++) {
494500
if (assignments & 1) {

0 commit comments

Comments
 (0)