Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6758339rwn; Tue, 13 Sep 2022 08:38:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR5MPErpPPDzmsMOczbHPJer4r5Vomsq7m/Mh0L4+zrgIKNHPsuKQewGjaWdZBNX14QBK1os X-Received: by 2002:a65:6047:0:b0:42b:313e:d331 with SMTP id a7-20020a656047000000b0042b313ed331mr28585097pgp.179.1663083498883; Tue, 13 Sep 2022 08:38:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663083498; cv=none; d=google.com; s=arc-20160816; b=m2Z/NlHZCgAuCz2QVoS69S37/DzJfnUR/DjgyF7fFEKZNBj9YW5CBYl/7lhcOgbBZr 5zLo3wCFLUH8l8TAdB7W/gXsL3tbVjZLZCDmsJWm8pTVFnVB4ZY03SC+zQWzQwx6UxXY H2PDsz/mUBD071gln9dd86o4RUAAy+JW8DM3Jb1q+Xjh38h8azywBWNXlUo6lHcYG8Qc vNNDKqvtFIby/nc3Px0YA8YIpDr3at4XS4Lsr3s9DiOEIKWS338u/qgI22JCQt6ZCPrj UZke1T1km+RXI9DTLL2P456TohIM4uFu8zDA+vO1xbpMYH0df37XlNQET1Uz62crZcSF VXWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NqEPTOINKuXj8uizkXy4+2A2T/QSW3bTdUdgCUwU62c=; b=H5gDqMmmfxgkGucXt5v+vpb93UulYSbEV9lmZvAoy9aWab7mc3rDMUt1VchKkdM6l9 nknky6p+NdsurLen1tpOZMULKkNOHzikT6O9KhLL2D5lxxct4oSH3Hx6ZTeZcYegYlCE ebMptuJ0y8YdivUK9wEMR/n5RQY4ZxBya65bXFp76UapiWLja3vbd2Yv42p8ESj3uosL T39S19S4Wm6wJeax9zU2Zw2wFA5LA4F382InmJ7fitrLLiVScBhDm++ATbr+TngpFyZ6 UvIMv0cu3DUIsUKVQ0NNnh93NANLuF/OyWjcRY3wBhPnxKSqK3xec8VJ/AoRcvXB+SKZ +eNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ICnSaEiU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n1-20020a17090a9f0100b001f307a7871fsi11464119pjp.45.2022.09.13.08.38.05; Tue, 13 Sep 2022 08:38:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ICnSaEiU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234924AbiIMPCC (ORCPT + 99 others); Tue, 13 Sep 2022 11:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235142AbiIMO7T (ORCPT ); Tue, 13 Sep 2022 10:59:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8719167CA2; Tue, 13 Sep 2022 07:28:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 304CFB80EFE; Tue, 13 Sep 2022 14:26:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9755DC433C1; Tue, 13 Sep 2022 14:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079214; bh=jzp64FOyngmI3Xz4S2MINfXLh+7J/d9J1o6732nJmmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ICnSaEiU42Zf498j9NwEBNG8Uu8G+HZOQL/a+awdOOf3o5TODqJmobH6d0us4hLPz N1XFDPYnJYukeFMw233agl4r+eKyUK2jLMrL+wzQc0tKIVxNwp6HLDX3khGegGh0Hy MZmRC92z9LjAScdZ+e8GSIsY5loa3LUqRCe4+9N0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Ranquet , Heikki Krogerus , Pablo Sun , Macpaul Lin Subject: [PATCH 5.4 047/108] usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles Date: Tue, 13 Sep 2022 16:06:18 +0200 Message-Id: <20220913140355.661619787@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pablo Sun commit c1e5c2f0cb8a22ec2e14af92afc7006491bebabb upstream. 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 Co-developed-by: Macpaul Lin Reviewed-by: Guillaume Ranquet Reviewed-by: Heikki Krogerus Signed-off-by: Pablo Sun Signed-off-by: Macpaul Lin Link: https://lore.kernel.org/r/20220804034803.19486-1-macpaul.lin@mediatek.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/altmodes/displayport.c | 4 ++-- include/linux/usb/typec_dp.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -87,8 +87,8 @@ static int dp_altmode_configure(struct d case DP_STATUS_CON_UFP_D: case DP_STATUS_CON_BOTH: /* NOTE: First acting as DP source */ conf |= DP_CONF_UFP_U_AS_UFP_D; - pin_assign = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo) & - DP_CAP_UFP_D_PIN_ASSIGN(dp->port->vdo); + pin_assign = DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo) & + DP_CAP_PIN_ASSIGN_DFP_D(dp->port->vdo); break; default: break; --- a/include/linux/usb/typec_dp.h +++ b/include/linux/usb/typec_dp.h @@ -73,6 +73,11 @@ enum { #define DP_CAP_USB BIT(7) #define DP_CAP_DFP_D_PIN_ASSIGN(_cap_) (((_cap_) & GENMASK(15, 8)) >> 8) #define DP_CAP_UFP_D_PIN_ASSIGN(_cap_) (((_cap_) & GENMASK(23, 16)) >> 16) +/* Get pin assignment taking plug & receptacle into consideration */ +#define DP_CAP_PIN_ASSIGN_UFP_D(_cap_) ((_cap_ & DP_CAP_RECEPTACLE) ? \ + DP_CAP_UFP_D_PIN_ASSIGN(_cap_) : DP_CAP_DFP_D_PIN_ASSIGN(_cap_)) +#define DP_CAP_PIN_ASSIGN_DFP_D(_cap_) ((_cap_ & DP_CAP_RECEPTACLE) ? \ + DP_CAP_DFP_D_PIN_ASSIGN(_cap_) : DP_CAP_UFP_D_PIN_ASSIGN(_cap_)) /* DisplayPort Status Update VDO bits */ #define DP_STATUS_CONNECTION(_status_) ((_status_) & 3)