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

usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles

Fix incorrect pin assignment values when connecting to a monitor with
Type-C receptacle instead of a plug.

According to specification, an UFP_D receptacle's pin assignment
should came from the UFP_D pin assignments field (bit 23:16), while
an UFP_D plug's assignments are described in the DFP_D pin assignments
(bit 15:8) during Mode Discovery.

For example the LG 27 UL850-W is a monitor with Type-C receptacle.
The monitor responds to MODE DISCOVERY command with following
DisplayPort Capability flag:

dp->alt->vdo=0x140045

The existing logic only take cares of UPF_D plug case,
and would take the bit 15:8 for this 0x140045 case.

This results in an non-existing pin assignment 0x0 in
dp_altmode_configure.

To fix this problem a new set of macros are introduced
to take plug/receptacle differences into consideration.

Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
Cc: stable@vger.kernel.org
Co-developed-by: Pablo Sun <pablo.sun@mediatek.com>
Co-developed-by: Macpaul Lin <macpaul.lin@mediatek.com>
Reviewed-by: Guillaume Ranquet <granquet@baylibre.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Pablo Sun <pablo.sun@mediatek.com>
Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
Link: https://lore.kernel.org/r/20220804034803.19486-1-macpaul.lin@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Pablo Sun and committed by
Greg Kroah-Hartman
c1e5c2f0 1bcafc04

+7 -2
+2 -2
drivers/usb/typec/altmodes/displayport.c
··· 99 99 case DP_STATUS_CON_UFP_D: 100 100 case DP_STATUS_CON_BOTH: /* NOTE: First acting as DP source */ 101 101 conf |= DP_CONF_UFP_U_AS_UFP_D; 102 - pin_assign = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo) & 103 - DP_CAP_UFP_D_PIN_ASSIGN(dp->port->vdo); 102 + pin_assign = DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo) & 103 + DP_CAP_PIN_ASSIGN_DFP_D(dp->port->vdo); 104 104 break; 105 105 default: 106 106 break;
+5
include/linux/usb/typec_dp.h
··· 73 73 #define DP_CAP_USB BIT(7) 74 74 #define DP_CAP_DFP_D_PIN_ASSIGN(_cap_) (((_cap_) & GENMASK(15, 8)) >> 8) 75 75 #define DP_CAP_UFP_D_PIN_ASSIGN(_cap_) (((_cap_) & GENMASK(23, 16)) >> 16) 76 + /* Get pin assignment taking plug & receptacle into consideration */ 77 + #define DP_CAP_PIN_ASSIGN_UFP_D(_cap_) ((_cap_ & DP_CAP_RECEPTACLE) ? \ 78 + DP_CAP_UFP_D_PIN_ASSIGN(_cap_) : DP_CAP_DFP_D_PIN_ASSIGN(_cap_)) 79 + #define DP_CAP_PIN_ASSIGN_DFP_D(_cap_) ((_cap_ & DP_CAP_RECEPTACLE) ? \ 80 + DP_CAP_DFP_D_PIN_ASSIGN(_cap_) : DP_CAP_UFP_D_PIN_ASSIGN(_cap_)) 76 81 77 82 /* DisplayPort Status Update VDO bits */ 78 83 #define DP_STATUS_CONNECTION(_status_) ((_status_) & 3)