From patchwork Wed Jan 11 02:05:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13095887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A90B4C61DB3 for ; Wed, 11 Jan 2023 02:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230235AbjAKCGC (ORCPT ); Tue, 10 Jan 2023 21:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234958AbjAKCF7 (ORCPT ); Tue, 10 Jan 2023 21:05:59 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB528234 for ; Tue, 10 Jan 2023 18:05:57 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id w3so15229140ply.3 for ; Tue, 10 Jan 2023 18:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qS19MD5Zbe+eJ9gIfmAabpV1LfKfinJzSfEen8dZJOE=; b=DNcVUKHG9cU/nPJHm64CxJPtzm3cG4CMsD19HXOfPf6VjsbcFZnaoqYOZ+nHs/NP93 y2GJkNOxJTCkAPkNNDR4lVP7I3Nf8tab5XzO+kRDMz82tjk7XHPGLgBgSXB4NHfJTo+N v7BVDc0FjZCBuC3I21/210GDz60MgYQOKQxQI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qS19MD5Zbe+eJ9gIfmAabpV1LfKfinJzSfEen8dZJOE=; b=tCHXwn1HxdpaHMTIobsavb0xd1lIpAnuHSml6QUnti65eAEJQlEi9dmjAziB94R5gh TH8Un4wIFcdXK1BF7vt9blxOlEvBUgIDCqgt9M9map41TEk0JlsDC6WpGAaQM2AY/Vec qjaFYAvVOWnaX/h5bhQu2k4kG+2J81YGbo58qrgmnRXXgtRNoRPrxboS7wA8Y6Blyyz3 nK/5Oo5kFM11cuKlyARq4GUnj3PKJriAtnc/hWn/IcGdJN0nfkplksqqWK3gxQYfIo5L CcPSKnT7RrBNyAhBi3EE05QeEo/HTfz7ScjDIFT5ONOW3YQpibMrR/P8p+lodLjY1PiX rRVg== X-Gm-Message-State: AFqh2kobWJa9luGLusrUHtvv6OVn2aFjpYBP6XF/3y6SEBtcFJVROvBw 9f1sYWhVsL+9tIJVHoKO6HCGYlLAWLlP8X5M X-Google-Smtp-Source: AMrXdXtzQT/6JuKQRYC+X8VwEUExfNrNm6jJEbBiSP8e0f2jsH+npBB6a3KqCJILpvKBoHa+rV6uEw== X-Received: by 2002:a05:6a20:9588:b0:b2:549c:b0eb with SMTP id iu8-20020a056a20958800b000b2549cb0ebmr89906325pzb.36.1673402757139; Tue, 10 Jan 2023 18:05:57 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id z6-20020a656646000000b00477a442d450sm7336738pgv.16.2023.01.10.18.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 18:05:56 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: bleung@chromium.org, Prashant Malani , stable@vger.kernel.org, Heikki Krogerus , Greg Kroah-Hartman , Guillaume Ranquet , Macpaul Lin , Pablo Sun Subject: [PATCH 1/3] usb: typec: altmodes/displayport: Add pin assignment helper Date: Wed, 11 Jan 2023 02:05:41 +0000 Message-Id: <20230111020546.3384569-1-pmalani@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 Signed-off-by: Prashant Malani Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- While this patch doesn't fix anything, it is required by the actual fix (which is Patch 2/3 in this series). So, I've add the "Fixes" tag and "Cc stable" tag to ensure that both patches are picked. If this is the incorrect approach and there is a better way, my apologies, and please let me know the appropriate process. drivers/usb/typec/altmodes/displayport.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index 06fb4732f8cd..f9d4a7648bc9 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -420,6 +420,18 @@ static const char * const pin_assignments[] = { [DP_PIN_ASSIGN_F] = "F", }; +/* + * Helper function to extract a peripheral's currently supported + * Pin Assignments from its DisplayPort alternate mode state. + */ +static u8 get_current_pin_assignments(struct dp_altmode *dp) +{ + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) + return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); + else + return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); +} + static ssize_t pin_assignment_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) @@ -446,10 +458,7 @@ pin_assignment_store(struct device *dev, struct device_attribute *attr, goto out_unlock; } - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) - assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); - else - assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); + assignments = get_current_pin_assignments(dp); if (!(DP_CONF_GET_PIN_ASSIGN(conf) & assignments)) { ret = -EINVAL; @@ -486,10 +495,7 @@ static ssize_t pin_assignment_show(struct device *dev, cur = get_count_order(DP_CONF_GET_PIN_ASSIGN(dp->data.conf)); - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) - assignments = DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); - else - assignments = DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); + assignments = get_current_pin_assignments(dp); for (i = 0; assignments; assignments >>= 1, i++) { if (assignments & 1) { From patchwork Wed Jan 11 02:05:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13095888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F25A5C61DB3 for ; Wed, 11 Jan 2023 02:06:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234634AbjAKCGG (ORCPT ); Tue, 10 Jan 2023 21:06:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234935AbjAKCGE (ORCPT ); Tue, 10 Jan 2023 21:06:04 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF4DB256 for ; Tue, 10 Jan 2023 18:06:02 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id d9so15200985pll.9 for ; Tue, 10 Jan 2023 18:06:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fOOH1h4KChlf2EGy6Niqg+gxYFOWhvY7/46pTYzOve8=; b=lzq1c4GT3OSKqRRDQNDqpsLFknvNebMBft69ALfIwBu8YiwtWVX6NYPre1ahsuWnIu gvRq7RNluMHnz6cheKyvzuZQItjdS3hGJXYGycUpQ2gxzvFppDugHewMKIIZVlPR9H67 5FXAlAsPd9Zu3U7x3U5ILvewmBFIXkdGV6xz8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fOOH1h4KChlf2EGy6Niqg+gxYFOWhvY7/46pTYzOve8=; b=V0xS01XAj8a82LwVwRn/yGfugvcV1nIpTPPf1QKM5vok3tqwgBWTOPptfsCnFkXuyW xSXlXyGmONMpm3CdJJ3nDXgwndqN1TsZLcA84j5Th2RMMrjtxIx4g/EJWVh1CFjwK+c4 6Yk5d7ji/+1+YEDmtSlBZxsCDzcoomxfZXJ0uLIdNJrzZXnqbNGUoL91jfNOtTMpoIuR JSRLX+7asePZ/ge8XmDdLQL+YqnF9AchswFx9+kIZNcYnyw/wdw4YuliCkzqqC+ZV/Pv MqpfXP5MgLFb3KBBq0KiGFVl8OS1WoULmeeTy5sCUhwl/mKhVcoNbfU9WH8Qu3bWAk8g Rvrw== X-Gm-Message-State: AFqh2ko9EprQDoqZOe6C2KlYDWlH4J9ss22XfqZa2jdYQcVxhLZRhCaB k7Xkhm/B60Na5lWzFiuXeoUMCA== X-Google-Smtp-Source: AMrXdXsm14meHXsg+0HKJ6VPqdWpetpoVPSQGqXYbRHaS7Fafz1lvKtFbgdIeGQdS7BKaCo8z4vnag== X-Received: by 2002:a05:6a20:c26:b0:9d:efbf:816d with SMTP id bw38-20020a056a200c2600b0009defbf816dmr544549pzb.54.1673402762422; Tue, 10 Jan 2023 18:06:02 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id z6-20020a656646000000b00477a442d450sm7336738pgv.16.2023.01.10.18.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 18:06:01 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: bleung@chromium.org, Prashant Malani , stable@vger.kernel.org, Heikki Krogerus , Greg Kroah-Hartman , Guillaume Ranquet , Macpaul Lin , Pablo Sun Subject: [PATCH 2/3] usb: typec: altmodes/displayport: Fix pin assignment calculation Date: Wed, 11 Jan 2023 02:05:42 +0000 Message-Id: <20230111020546.3384569-2-pmalani@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230111020546.3384569-1-pmalani@chromium.org> References: <20230111020546.3384569-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Commit c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles") fixed the pin assignment calculation to take into account whether the peripheral was a plug or a receptacle. But the "pin_assignments" sysfs logic was not updated. Address this by using the macros introduced in the aforementioned commit in the sysfs logic too. Fixes: c1e5c2f0cb8a ("usb: typec: altmodes/displayport: correct pin assignment for UFP receptacles") Cc: stable@vger.kernel.org Cc: Heikki Krogerus Signed-off-by: Prashant Malani Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- drivers/usb/typec/altmodes/displayport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index f9d4a7648bc9..c0d65c93cefe 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -427,9 +427,9 @@ static const char * const pin_assignments[] = { static u8 get_current_pin_assignments(struct dp_altmode *dp) { if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) - return DP_CAP_UFP_D_PIN_ASSIGN(dp->alt->vdo); + return DP_CAP_PIN_ASSIGN_DFP_D(dp->alt->vdo); else - return DP_CAP_DFP_D_PIN_ASSIGN(dp->alt->vdo); + return DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo); } static ssize_t From patchwork Wed Jan 11 02:05:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13095889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E4DBC54EBC for ; Wed, 11 Jan 2023 02:06:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235409AbjAKCGU (ORCPT ); Tue, 10 Jan 2023 21:06:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235003AbjAKCGH (ORCPT ); Tue, 10 Jan 2023 21:06:07 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54391200F for ; Tue, 10 Jan 2023 18:06:07 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id q64so14351602pjq.4 for ; Tue, 10 Jan 2023 18:06:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aBFAbmggijOhKjLzf9il6pua2012DvMDyGgeIBZj5ls=; b=m2MFXy1xICKP7wXEyoTOm7zW0ptblveblZ8XnwBpeo2AKBwPeFD5jmjnjHS6MtgLnx KyKFP2HmIFuQmtQYccuYE92XM+qfF/VMEIgI4zwELU1woAYUZ7poA9Qb1r92ssWmC6wV ur7+Sh2GggjJFj+4LcSt6TetHYyIJ8lb2nBSQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aBFAbmggijOhKjLzf9il6pua2012DvMDyGgeIBZj5ls=; b=QZp+P8FhpKC2PzV7z+YmyE5D4KZglNWHSgyXYGYJFhMsk6kgEtwUUX9p1BUVF12zAd bXcYBtNA+2mEMUEjUW7UMvHV3KdC8eFUiXc7PSK1UjL1LJWxWPpblq/hm4Eb7eM+gBhG zY9L8txrkPeWX8/N0jPGdhheQPs3ocpKuXjdDfPaZrfQfyB8nLoHaCg5Ge0LWMfJiMO3 w6VnIQh2vIksLC6ZX+24O2DHNoCN+jx+ORALJsjJLiOEalqFjjNfCj0fR2T45/jH3wFK hQZatvXsZ+POhrb3fsV5A9DoQTk6L0JlHGVhoxRHcjngFwuV91TjGMgKU2GUATJhUT/C O9aw== X-Gm-Message-State: AFqh2krmz1Ps4W1UzCWQiAqJTqV2qF9EOZWRkcHvAnOJHd5kLIzqPwEi wGFsLfC4Eg5CFBa0lTGxWW1QVA== X-Google-Smtp-Source: AMrXdXuCj84I+jhx/wOedwvaeYXtbs0dOplLvj21ewxSfXqBwZfxqQmziQeUa4iUXnqxygc9yO9fOQ== X-Received: by 2002:a05:6a20:b285:b0:af:ec0f:f6b5 with SMTP id ei5-20020a056a20b28500b000afec0ff6b5mr72803915pzb.11.1673402766884; Tue, 10 Jan 2023 18:06:06 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id z6-20020a656646000000b00477a442d450sm7336738pgv.16.2023.01.10.18.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 18:06:06 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: bleung@chromium.org, Prashant Malani , Heikki Krogerus , Greg Kroah-Hartman , Guillaume Ranquet , Macpaul Lin , Pablo Sun Subject: [PATCH 3/3] usb: typec: altmodes/displayport: Use proper macro for pin assignment check Date: Wed, 11 Jan 2023 02:05:43 +0000 Message-Id: <20230111020546.3384569-3-pmalani@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230111020546.3384569-1-pmalani@chromium.org> References: <20230111020546.3384569-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org While looking at the DP configuration VDO to determine the peripheral configuration, the spec (Table 8-5: DisplayPort Configurations, VESA DisplayPort Alt Mode Standard v2.0) lists the options as "UFP_U as a DP Source/Sink Device". So, use the correct macro while performing this check. Effectively it's the same as the existing code, but the proposed macro describes the state a little better. No functional changes introduced. Cc: Heikki Krogerus Signed-off-by: Prashant Malani Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- drivers/usb/typec/altmodes/displayport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index c0d65c93cefe..746bfbf3d557 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -426,7 +426,7 @@ static const char * const pin_assignments[] = { */ static u8 get_current_pin_assignments(struct dp_altmode *dp) { - if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_DFP_D) + if (DP_CONF_CURRENTLY(dp->data.conf) == DP_CONF_UFP_U_AS_DFP_D) return DP_CAP_PIN_ASSIGN_DFP_D(dp->alt->vdo); else return DP_CAP_PIN_ASSIGN_UFP_D(dp->alt->vdo);