Skip to content

Commit 7fb1322

Browse files
Prashant Malanigregkh
authored andcommitted
usb: typec: altmodes/displayport: Add pin assignment helper
commit 582836e upstream. 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 59f9ee3 commit 7fb1322

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
@@ -418,6 +418,18 @@ static const char * const pin_assignments[] = {
418418
[DP_PIN_ASSIGN_F] = "F",
419419
};
420420

421+
/*
422+
* Helper function to extract a peripheral's currently supported
423+
* Pin Assignments from its DisplayPort alternate mode state.
424+
*/
425+
static u8 get_current_pin_assignments(struct dp_altmode *dp)
426+
{
427+
if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D)
428+
return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo);
429+
else
430+
return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo);
431+
}
432+
421433
static ssize_t
422434
pin_assignment_store(struct device *dev, struct device_attribute *attr,
423435
const char *buf, size_t size)
@@ -444,10 +456,7 @@ pin_assignment_store(struct device *dev, struct device_attribute *attr,
444456
goto out_unlock;
445457
}
446458

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

452461
if (!(DP_CONF_GET_PIN_ASSIGN(conf) & assignments)) {
453462
ret = -EINVAL;
@@ -484,10 +493,7 @@ static ssize_t pin_assignment_show(struct device *dev,
484493

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

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

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

0 commit comments

Comments
 (0)