From patchwork Wed Feb 28 22:02:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 208059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp227329rwa; Wed, 28 Feb 2024 14:19:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUSBFRrgbgdJaNdK4gDpJez+zOcdyWJ+F1Js8X36NU5comNQ6V47P1daYFgW7farhZxsB1RTF3e/q9IB80cRCA9E+wTew== X-Google-Smtp-Source: AGHT+IE2xMBEiWBSxZEPIwXOccHXSA7uP196H4j0INiz7/7M51O9wc1JmtePlTk49xMZJXkSt8Hk X-Received: by 2002:a9d:7a4a:0:b0:6e4:459e:fdba with SMTP id z10-20020a9d7a4a000000b006e4459efdbamr287173otm.26.1709158752565; Wed, 28 Feb 2024 14:19:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709158752; cv=pass; d=google.com; s=arc-20160816; b=QXc1/Iyr2M1QsNsWYspiCBVV5/IkdObbhq2u3/XWwlI9W2JFRc0fIg9jVU1VKon8w6 7PHcfuhNJU+1DCKpgcK7vmVfvGC9PbEa/3iQPR//zPm+2Vp5sZCaUkLqGK7J/rJKPzXR 9HPG5ZFflqopBYE+r4ZKD1mi40mjdeoUe1iu+n96xOU7GorXOeUca69FaOMQ5sRH+Hsv N76/v0cgBM025nPlBATLobbtzska8vH7EWhy2qcqZ2+N+xgWo4wfB2paU2M22DdAIZ3t PYdWOJhfeJ5Gw9vELPJAHIrUMhHsMfVa9K2M653LuxN5QqPkpzBH0sdczljf0NyMmwdX Jykw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=EOALInjeSh3HTsFKo9WeEXTAmZVBSHgGCLq/ONkSsHE=; fh=idSapr98KOiZ4BfPEqBEBE6RAun/wOeqLKG5WfuJsD0=; b=vpcG9w2mSVUFZUQcLgLk0XzAHqlwvoays2k/Wk8tYszuZW+liaVG/3vtCLhQPab1po 4q1lYlZRB7MQEysVJiCjRzW3bkOJ/kouBgTnjG+6ww3NAHtCnt0GhbHzQ24NknOs0X6m MmXTAq5+4cm4TuZKrG3/pSOrzReSjTcMv4aq4Ywg3B0EIARtYvJ2hPvL8PWCMUMVB7kz XRKKZGP3W5oOq1iN2DbCR5II3GHmrSJkhnjYwv9/NbIgL0eFsSKlhHdD0o9eI+rL6hzm bD/sWU8uKjUUpp5yI7yIqljr2KXjLWyMGdr62qQWArVWexx6TqLTdw5SUaVY/fbKA6u0 30AQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vKQoa0a+; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85767-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85767-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k188-20020a6324c5000000b005dc8f60ce09si398128pgk.7.2024.02.28.14.19.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 14:19:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85767-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vKQoa0a+; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85767-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85767-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 99784B23BD2 for ; Wed, 28 Feb 2024 22:04:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 006C371EC6; Wed, 28 Feb 2024 22:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vKQoa0a+" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83CE71361A0 for ; Wed, 28 Feb 2024 22:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709157790; cv=none; b=r9J5NK+kXBwS8Z9fCh62PTPh2iXmZztGaPXlufjBGjYpRmkRvYMDF4x8MP/MGU666oa0GMfs+50Zl4d8dwlPaBXkXp9iH1Dy6pl4h8zXs2zoonwIc7yG30WbEf8gSXnj1vgfOBxi/lXkVQqsaw/IWTg1F/v8bkj9cWv4MPrHYQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709157790; c=relaxed/simple; bh=Ybd/HW3xor3RSSR0F37+S3Wo7Gc0r4PsvTMb4I8HHCI=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Z2cUuFSoiHateAClnH0XJdC13DhERcx1YoRsLhhqBgileIdwqyETLw/CL9h2WvNwQe+MmgBK4UsbYNgRo5lr1hVeSdVpi/ins1LHNRMUtib8CuJYaWWTxm8NTrxTKmEDPNfBFSlozLUlEVuH2MIzkMrcBQNwKF3wog4aL635DgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vKQoa0a+; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b269686aso445980276.1 for ; Wed, 28 Feb 2024 14:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709157787; x=1709762587; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=EOALInjeSh3HTsFKo9WeEXTAmZVBSHgGCLq/ONkSsHE=; b=vKQoa0a+MuYFP7qu+/L7cVNB6QPL2QiKG6k0ejUKLLGASeEjtHXTizcOx4mHfzvHB4 9VUNIUoBKkJjiLQEse12DknNAVLyLps8yN030mrxeoqt/9cY4caXfiDHrubjIZX1v1gc jRz12nVBlxe3s8WMMf9ZIjDmV1omJegZNDbRMyjBTc3CRjx8OhYMsLBlyELliakCjFQA K8piN8tcsJlLeus+fFhTCupKF+cJdnvCd+wKy7pjAptu8Jvyt8RlFW9sOlHj/Qkmtk0n 7qiWTDOVs7XYRcHxKugbATK1Pq3aaKYSxM77L1x42P0NWTpDUIqQTyD0xoe8qqhq4tab Ytew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709157787; x=1709762587; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EOALInjeSh3HTsFKo9WeEXTAmZVBSHgGCLq/ONkSsHE=; b=B/kTCZMai2yAE98Jvt0FbZSFDrCMe5NLDsmAfFNicLkNjz4Pw5QrhxS12B2SfNFrgO 0Um1uxpBmnDO6xZwLs9xuC0yziRuw0dSBCfv/VowOaNfNAUK1kVArb156uqnSeeJZIY8 T3CN7ugi1auAxFHg3lr7yQ0q7pmyYPHkACgxhqlEiWPa/cjGRWeIG+HFFl2dMelwOToj rq+3g3k0Dy4Qyr5wKhRefmWBGsOdyoTtVgUBia9FEIcJ91cliyaNse2plctAtdoqek8x 2OncOkJ2P7pJN16VORyWifcjaJD1Oikb4olj0XH1oP03kfVlKveEcRengW6IpWn7jswt iOPg== X-Forwarded-Encrypted: i=1; AJvYcCV2mscUOxAEKlhx/YVhyqs1v9NFj3j5THPGoM5Xbz9c65/dKgsDiZlH0hMsuyitomdJl59qRTw6Q0s2anBmYqWPaCPAJ6saO+WYuYVU X-Gm-Message-State: AOJu0Yza4vb4QTYo2+sdhTU8OW41WT+j49b5dtv6GgmNBmtxKqvvghkV 3LmkyvfkCziAxVDn4o0WBkdvNCwqPzNZmd+5+XkqFJRDBILY2uTDBXg1yfDedMlDmm4bURF4Su2 tvQ== X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:1142:b0:dce:5218:c89b with SMTP id p2-20020a056902114200b00dce5218c89bmr31900ybu.5.1709157787604; Wed, 28 Feb 2024 14:03:07 -0800 (PST) Date: Wed, 28 Feb 2024 22:02:51 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228220251.3613424-1-jthies@google.com> Subject: [PATCH v2 1/4] usb: typec: ucsi: Clean up UCSI_CABLE_PROP macros From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Benson Leung X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792182848307269728 X-GMAIL-MSGID: 1792182848307269728 Clean up UCSI_CABLE_PROP macros by fixing a bitmask shifting error for plug type and updating the modal support macro for consistent naming. Fixes: 3cf657f07918 ("usb: typec: ucsi: Remove all bit-fields") Reviewed-by: Benson Leung Reviewed-by: Prashant Malani Reviewed-by: Dmitry Baryshkov Signed-off-by: Jameson Thies --- Changes in v2: - Tested on usb-testing branch merged with chromeOS 6.8-rc2 kernel. drivers/usb/typec/ucsi/ucsi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 7e35ffbe0a6f2..469a2baf472e4 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -259,12 +259,12 @@ struct ucsi_cable_property { #define UCSI_CABLE_PROP_FLAG_VBUS_IN_CABLE BIT(0) #define UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE BIT(1) #define UCSI_CABLE_PROP_FLAG_DIRECTIONALITY BIT(2) -#define UCSI_CABLE_PROP_FLAG_PLUG_TYPE(_f_) ((_f_) & GENMASK(3, 0)) +#define UCSI_CABLE_PROP_FLAG_PLUG_TYPE(_f_) (((_f_) & GENMASK(4, 3)) >> 3) #define UCSI_CABLE_PROPERTY_PLUG_TYPE_A 0 #define UCSI_CABLE_PROPERTY_PLUG_TYPE_B 1 #define UCSI_CABLE_PROPERTY_PLUG_TYPE_C 2 #define UCSI_CABLE_PROPERTY_PLUG_OTHER 3 -#define UCSI_CABLE_PROP_MODE_SUPPORT BIT(5) +#define UCSI_CABLE_PROP_FLAG_MODE_SUPPORT BIT(5) u8 latency; } __packed; From patchwork Wed Feb 28 22:03:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 208049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp220181rwa; Wed, 28 Feb 2024 14:04:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV+sEc9ql7ZYCXL+LmmHPHi9QplGCwOcpf6yvTSqivscYaw5MSahQdRagMujdekB2xxSncOSS5qeq7mlkUT/ExB6MRgRA== X-Google-Smtp-Source: AGHT+IGWimV8hTIiYh5vnygwGyp5sABOn8Or6EVW1/rM5O8WaVqxjLHIbiLO19vj6kVACGASblR2 X-Received: by 2002:a05:6a00:1895:b0:6e5:3dea:bf51 with SMTP id x21-20020a056a00189500b006e53deabf51mr57057pfh.7.1709157881133; Wed, 28 Feb 2024 14:04:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709157881; cv=pass; d=google.com; s=arc-20160816; b=g8h8jA93USuzl9O1UN0nD77pg3sHYX8UIwUUy0Q+aBgCQ2aLA9iBH7J3q8cwQ5Q02a vx8A/qSQb1Sdj1fFyAq2vIwW6mcWkmcO4nMmYqpI2SdZWxv5vintM2vlsfLLD4XYgLfC 0we6mmESlCk9YNd8pXrAibWwVww/WeuLUueuC8DfZZv8b3nXJ5wREDRh32OehGqw018F Gt62lFGXYBPRSsJlOp+QS1gV0BJs9UBqzLJRaIgIyzWlpudufs/qfWe4m4IHREz+Dz+z lCuC/dNDwFz4tpuSlZrW39gh/7Gcksu2YVYi8NH2+iSEbPZ7H3ixTDGgPqEoTVSgSX9r zF8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=yFg4YW/Z3HZfFTzuAYbv+SLduBl2JOv/FXcutS6mDuE=; fh=W2QRcz+sgwvTpr7B9yuMrtmO5AWjsjxwyi3Vi5YvbiM=; b=w7LvgY5yTlfLwXLu6yLbF3X5YMrYL8CUEKypu73aDeD6g/khM7I/x9QzB+69llRntY miQQGiBm3wVlLRs6KuR9IcJqjvToq1HxwP/7Z5t8S7gNP8eIFEjLOv/KQ8xQ6uqw4eMO 3C2lDlwwAIxCMfc8ECF0/h5vnE5FoZSLTAE/aADaulzchP00ydYtogZjK77psifaY/AH c7bkHA2hJhXfVCX01BjVkHSk7+fgZNGWhcz+awyEcQurC07hGjfXHm/SCWkTSI0I+c2a yuvUFkXAe8svlMD76QxACVEgO+rXzGwATSeZJRSCVNdFX3YMwgUqJnMkvsl43phJiuAo zT5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=T0RTPi+U; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85768-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85768-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k187-20020a633dc4000000b005ce04795a98si375315pga.32.2024.02.28.14.04.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 14:04:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85768-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=T0RTPi+U; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85768-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85768-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EFCFD287190 for ; Wed, 28 Feb 2024 22:04:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F275D72925; Wed, 28 Feb 2024 22:03:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="T0RTPi+U" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E32801361B2 for ; Wed, 28 Feb 2024 22:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709157825; cv=none; b=rwPikMHYShohsm2SGUQ5bC0yltNSN60Wn3rCYOTL668E9MHRmKpcaTOP0JlapFGd5kyPBsnFj94/ijgyXxFDrqd6depWwEaKmDl3QhpQJWCUR5mHV0RYubVYotVxBqlMC+CGPNUuqamaf1EA+wWeZFqiY0ZUgYzvS9shUljfck4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709157825; c=relaxed/simple; bh=ryVPktQRnYCrMHD3Ujbd8hCR3CnuJmpQVQb/Vo2KVQE=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=GKL6JYUv0fLQQmnfpQWhowK2iF8KRQ0WGuF/ovWoU2OxhWYZC0YLoLK5bA/Lkx740GxRRv228iJIn8M/rHCtrE5spM7xYFRvYmFpthAx48znPYPeDhbVlEeTmamPDJ6rb3tBxBbAsAr1u+SmqW+HFpK+/YYpIbA2eLf+wP5hnhg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=T0RTPi+U; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60802b0afd2so2670007b3.1 for ; Wed, 28 Feb 2024 14:03:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709157823; x=1709762623; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yFg4YW/Z3HZfFTzuAYbv+SLduBl2JOv/FXcutS6mDuE=; b=T0RTPi+UEGCOI1/7M8mLrEcVq5UTpoilBoa96pK7u50SFnP8a9FQ3pKeV21lW3lq3L T4TIYMRvutkN4M7dxhowx77zS1EY/xytitgVUS0dIJC2jD6peeNJyJdO0arLcv8UNXrQ DyqMhc8BTLQtPZ2u8yA7GnPtZFBHpr87kSedxDVyNQrl0TUz+t/Pd3M4Uvhc+w1XSLSc UYD8fM7gqbdmpuZhxfkjCoRrQZr9kVGFVpM3XBuMLpsOLhaK74hYBWospbf+JRC7pVPH M4YQKSlidhfOjKNcbAhXmUphxf+aW1aaz0vbESoTXQRQUqy7oBfvj3TFwm/dTCa6RhjZ 66lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709157823; x=1709762623; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yFg4YW/Z3HZfFTzuAYbv+SLduBl2JOv/FXcutS6mDuE=; b=L98/lOb5ykBPSBJc2es/O+gUgRgLowrOtFPTP5YS/lTBKfGxso9ebaUDsZZwZ9IAOm 52MzxkpmTQD+xYyQunvcUtf3vs5wxrEvsRvY/WYaUZPlSGLMgnVGKE6/Cm9QY5UGLuIR he4FUsRKb44/TJsR7hpP/YyxvWHY5kBvg6rHq06ip1aLY21BPwiZBkw/iY3IdD3tY1A1 RgEgC/VBrmJwKGUAuS6wJbS5iJA8EIYIdrBUF+7sKrjKWQ+q/YXDN+6YQIcg1FPih3uq 5XzRiajRfHrym4XYH0lYBN5gf7gXTT1LxXXZ7Asg/051r7P9Ej2YPIWPZsKzLjWLkiyM fVbw== X-Forwarded-Encrypted: i=1; AJvYcCV2Qj2G4kwC3tdS5iWX3/ksJZ0iXCu7+vUh+NPane1V+V6jVS2PvGVsBZJlq7UXdtkGlHKKjsog5usnhPXGDr08rXRDGJ+7qa+PF2n1 X-Gm-Message-State: AOJu0YynoanMakNBPuCs23k+hJoSETJ9Tb6sW/y5KV1pn5AcgC3YBz9m VfmJbj/HzXhUdpgM34rsHdqOMFh+wAM7Sw742/2m3A2WxbeH4OyZwGO5Jms8vch3qk6WkO0yFbh fQw== X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:5:b0:609:3a33:bacc with SMTP id bc5-20020a05690c000500b006093a33baccmr2310ywb.5.1709157822956; Wed, 28 Feb 2024 14:03:42 -0800 (PST) Date: Wed, 28 Feb 2024 22:03:39 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228220339.3613870-1-jthies@google.com> Subject: [PATCH v2 2/4] usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792181934195900494 X-GMAIL-MSGID: 1792181934195900494 Register cables with the Type-C Connector Class in the UCSI driver based on the PPM response to GET_CABLE_PROPERTY. Registered cable properties include plug type, cable type and major revision. Reviewed-by: Benson Leung Reviewed-by: Prashant Malani Reviewed-by: Dmitry Baryshkov Reviewed-by: Heikki Krogerus Signed-off-by: Jameson Thies --- Expected cable properties populate the USB Type-C connector class sysfs paths: nospike-rev4 /sys/class/typec # ls port0-cable device identity plug_type port0-plug0 power subsystem type uevent usb_power_delivery_revision Changes in v2: - Shortened lines to within 80 characters. - Tested on usb-testing branch merged with chromeOS 6.8-rc2 kernel. drivers/usb/typec/ucsi/ucsi.c | 73 +++++++++++++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 5 +++ 2 files changed, 78 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index ae105383e69e7..7c84687b5d1a3 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -734,6 +734,52 @@ static void ucsi_unregister_partner_pdos(struct ucsi_connector *con) con->partner_pd = NULL; } +static int ucsi_register_cable(struct ucsi_connector *con) +{ + struct typec_cable *cable; + struct typec_cable_desc desc = {}; + + switch (UCSI_CABLE_PROP_FLAG_PLUG_TYPE(con->cable_prop.flags)) { + case UCSI_CABLE_PROPERTY_PLUG_TYPE_A: + desc.type = USB_PLUG_TYPE_A; + break; + case UCSI_CABLE_PROPERTY_PLUG_TYPE_B: + desc.type = USB_PLUG_TYPE_B; + break; + case UCSI_CABLE_PROPERTY_PLUG_TYPE_C: + desc.type = USB_PLUG_TYPE_C; + break; + default: + desc.type = USB_PLUG_NONE; + break; + } + + desc.active = !!(UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE & + con->cable_prop.flags); + desc.pd_revision = UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD( + con->cable_prop.flags); + + cable = typec_register_cable(con->port, &desc); + if (IS_ERR(cable)) { + dev_err(con->ucsi->dev, + "con%d: failed to register cable (%ld)\n", con->num, + PTR_ERR(cable)); + return PTR_ERR(cable); + } + + con->cable = cable; + return 0; +} + +static void ucsi_unregister_cable(struct ucsi_connector *con) +{ + if (!con->cable) + return; + + typec_unregister_cable(con->cable); + con->cable = NULL; +} + static void ucsi_pwr_opmode_change(struct ucsi_connector *con) { switch (UCSI_CONSTAT_PWR_OPMODE(con->status.flags)) { @@ -807,6 +853,7 @@ static void ucsi_unregister_partner(struct ucsi_connector *con) typec_partner_set_usb_power_delivery(con->partner, NULL); ucsi_unregister_partner_pdos(con); ucsi_unregister_altmodes(con, UCSI_RECIPIENT_SOP); + ucsi_unregister_cable(con); typec_unregister_partner(con->partner); con->partner = NULL; } @@ -907,6 +954,30 @@ static int ucsi_check_connection(struct ucsi_connector *con) return 0; } +static int ucsi_check_cable(struct ucsi_connector *con) +{ + u64 command; + int ret; + + if (con->cable) + return 0; + + command = UCSI_GET_CABLE_PROPERTY | UCSI_CONNECTOR_NUMBER(con->num); + ret = ucsi_send_command(con->ucsi, command, &con->cable_prop, + sizeof(con->cable_prop)); + if (ret < 0) { + dev_err(con->ucsi->dev, "GET_CABLE_PROPERTY failed (%d)\n", + ret); + return ret; + } + + ret = ucsi_register_cable(con); + if (ret < 0) + return ret; + + return 0; +} + static void ucsi_handle_connector_change(struct work_struct *work) { struct ucsi_connector *con = container_of(work, struct ucsi_connector, @@ -948,6 +1019,7 @@ static void ucsi_handle_connector_change(struct work_struct *work) ucsi_register_partner(con); ucsi_partner_task(con, ucsi_check_connection, 1, HZ); ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); + ucsi_partner_task(con, ucsi_check_cable, 1, HZ); if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == UCSI_CONSTAT_PWR_OPMODE_PD) @@ -1346,6 +1418,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) ucsi_register_partner(con); ucsi_pwr_opmode_change(con); ucsi_port_psy_changed(con); + ucsi_check_cable(con); } /* Only notify USB controller if partner supports USB data */ diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 469a2baf472e4..f0aabef0b7c64 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -265,6 +265,9 @@ struct ucsi_cable_property { #define UCSI_CABLE_PROPERTY_PLUG_TYPE_C 2 #define UCSI_CABLE_PROPERTY_PLUG_OTHER 3 #define UCSI_CABLE_PROP_FLAG_MODE_SUPPORT BIT(5) +#define UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV(_f_) (((_f_) & GENMASK(7, 6)) >> 6) +#define UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD(_f_) \ + UCSI_SPEC_REVISION_TO_BCD(UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV(_f_)) u8 latency; } __packed; @@ -400,6 +403,7 @@ struct ucsi_connector { struct typec_port *port; struct typec_partner *partner; + struct typec_cable *cable; struct typec_altmode *port_altmode[UCSI_MAX_ALTMODES]; struct typec_altmode *partner_altmode[UCSI_MAX_ALTMODES]; @@ -408,6 +412,7 @@ struct ucsi_connector { struct ucsi_connector_status status; struct ucsi_connector_capability cap; + struct ucsi_cable_property cable_prop; struct power_supply *psy; struct power_supply_desc psy_desc; u32 rdo; From patchwork Wed Feb 28 22:03:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 208050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp220376rwa; Wed, 28 Feb 2024 14:04:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXBakvZO0icDD9nLaaqLoM8jdHXzydLnoG6fxOKUJVNnrmpqjCM4sAjDjD0iaJPYMnB1dkrVnFn6ZqhDx3UJ5KwVcWqhQ== X-Google-Smtp-Source: AGHT+IHkTk+0E8ExTHKk2a99yflKg0OFpyC2z0TyS1Y5Nm1jtMbh0aOhMXXDgnW6Cbh7+cJQEfTe X-Received: by 2002:a05:6a20:e607:b0:19e:9a75:7851 with SMTP id my7-20020a056a20e60700b0019e9a757851mr677215pzb.3.1709157898675; Wed, 28 Feb 2024 14:04:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709157898; cv=pass; d=google.com; s=arc-20160816; b=eyt4HLwFZXvDZkSNeaPjAECHouMLnwdfKrr9yhdVjOx+1sKH5/w4zt2wiZilvDXwDk wNC7ObmK3VGsPGLmOUJbX/RAZOa94vAJVAQsY9OVDvVCD1bT9aMr8uG1LvzwP573oWvf PiK8ZgHnFHiO5TpiukNNwNN1qKcxZAjgf3EkGwj8iWCXbSDgL3WrFaWAJqMSq4lZ+wbh hVqg8jT5BexirBf1Pnl33XzEsfSdvVAc52oQe8D9Nc/Yv4LhSdDkZgo6kQWfobtmfM1R qePtwi9mWoyEAgaII8rWh9+evrfMere3HR4S9XDeV4ZyZWgMiWI/RegmfgfsDgZwsDd0 eSBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=4CA4tg/c3dgG9UMrMK9e+dv6nPpGjSIEc2b658y+GNA=; fh=fMIHEctLmlBizITNa86vmqPLCQcYyeKeIaBOcCb3Y5c=; b=SQlzA76z74ihAS5AjSKqE5PLK/f/upk2a9oxCFgCMbieFqfhWVscYw+kl/9g55wWAK huFsyGexLYXb6dQzcjsmZq8VHzBVDEI1Nru5dyzg18O1/YRX6MXfedyb/uk1VPV62V5i oIIBGCPqcJ7NGTk70U4Pp4zXXurU4EdqAde/RutZZRfuv9PAgSZwVsrLVdajrdaGRUwr zsi9GmmirLdGpicO8oAmEAkwoF6WcJFSfrsMF6bnvvI/r/eH5mPwYOfepUzHdUPPt9Jk WKR4QEkxihk5ea29L/OIJ5GDoAufyUfNOiM49bImNvD8sPpkI1xw0uLKIlB76JHdXH5A 5FNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zpN+EVC2; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85769-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85769-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p25-20020a639519000000b005e2b0672449si363341pgd.27.2024.02.28.14.04.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 14:04:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85769-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zpN+EVC2; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85769-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85769-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7527A2861C9 for ; Wed, 28 Feb 2024 22:04:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCF471361B1; Wed, 28 Feb 2024 22:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zpN+EVC2" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAEB271ED3 for ; Wed, 28 Feb 2024 22:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709157838; cv=none; b=Sve15wJEfhSw05+mdljYRjd5FoRoBmcP61m0aveXkkbiAIoDaPNiE31UoCvJGbys92+TCym/s6bvk7XcSKdFCDzKQQ/CxoqkscC/v2iTCDW92GKBClFwYXjaeBdt3yh8n8im3etzwzyXJmE/CbPW2JOPvIgoB4rIFcNqQRI0SjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709157838; c=relaxed/simple; bh=Z/DkHcQWucfnp59Rztm+Uc4+DaWNClDgYlOSekDwPTQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=f9WyO/n0D1IgoJl8d7jdloeamBQJ68DSTaQstOqdLHx3lIPPtwF6npe9/pltFLEpJv/sFqpL9Kn3/sqpr6ywqHHG/qTFWSz/ifKxc6geUGywxmQBo5PpvXXHcISrkwPpqHOak7SmCjPzPK2OUJnkuRiLxgl4WL2tmaNInelRtT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zpN+EVC2; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-608852fc324so3685607b3.2 for ; Wed, 28 Feb 2024 14:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709157836; x=1709762636; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4CA4tg/c3dgG9UMrMK9e+dv6nPpGjSIEc2b658y+GNA=; b=zpN+EVC24EQZrjwmgNTLgae8Zkq27I+8j61fASCgvGS7TW4PCCZiFau8qG040J3bzl cvDDD46ZQBXBqPRq/xPMInh7D+4pboET7Rvv6r7w2LIERoWwKb0NTxtSGAyEZ8mgBzIJ s7BQbX/TVm6Mi+3OaZhpY7t9Hn2DCh62PP+/Dkl1C4Eh+D7BavjaHSsZKyq/P6a/aP4H +NR60LYjN6UI/JC3asFVSA2bC2QhB/cVojOeYOIgB8X5NRDfwICvD++C58v4+EdXYsnx KolRw2DlWR/hxOGQZD+f2QOgDGQcMFAWfjke684/6JHLNHfkOm80rCvTsaAlvx05TKiZ Sbug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709157836; x=1709762636; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4CA4tg/c3dgG9UMrMK9e+dv6nPpGjSIEc2b658y+GNA=; b=I6TvXU+kz1E3aXMVBxF7Mv73QibsJCXtxh5RrRbATjitXFUjCei2WdBlabOseTD1Aq m02rRbgNhBCCY58qP3uMiU4caZDIXaGM2RFtG4lCZwag3qq2fSP8DaEC1vtSnZUDzP53 LJ+ptFkjD+pvdjdxNjks1Cts0G+AkY2Q/eJBHisAUbKRurA5Lu17fL1HTIE7CT3N//NS 5bwsN9ave9MdyxA0JAIrMtq3wk5IhKSpCHh7NtSG/TLtSECoFG0UXOh1D0/RfBwcm/Po ONBP3LaQ4OA+5Ebbvv2t90SBr3ZI/nCmdg8V2gWjkA2yTFY6vizI9jBLZjvm7xp6IG3b b1tw== X-Forwarded-Encrypted: i=1; AJvYcCWqnr2H6UfEaRMmnh2Ib2McjmSO/Lx5wKT3KaWdx7mGAdCOCDMxZZYdooIVnXvDBqgCWLZL4JiCyOWrgkLe7ZcffYpgvt2dWOWgSoUf X-Gm-Message-State: AOJu0YzirecTZs3zloStOy4UgNMZNhmBSFhVaSFs6plQoCZYI/OdVYU5 wYoj/QSokqY9a1pkf+xhbkzrNzkSgS7gtxP7+OFqoP5tPAQFcA3itQ/KjXo0jCKTnMUKZcR+2k2 Ukw== X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a81:9858:0:b0:609:2faf:7dca with SMTP id p85-20020a819858000000b006092faf7dcamr71912ywg.8.1709157835923; Wed, 28 Feb 2024 14:03:55 -0800 (PST) Date: Wed, 28 Feb 2024 22:03:52 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228220352.3614262-1-jthies@google.com> Subject: [PATCH v2 3/4] usb: typec: ucsi: Register SOP/SOP' Discover Identity Responses From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792181952600385397 X-GMAIL-MSGID: 1792181952600385397 Register SOP and SOP' Discover Identity responses with the USB Type-C Connector Class as partner and cable identities, respectively. Discover Identity responses are requested from the PPM using the GET_PD_MESSAGE UCSI command. Signed-off-by: Jameson Thies --- GET_PD_MESSAGE responses from the PPM populate partner and cable identity in sysfs: nospike-rev4 /sys/class/typec # ls port0-partner/identity/ cert_stat id_header product product_type_vdo1 product_type_vdo2 product_type_vdo3 nospike-rev4 /sys/class/typec # ls port0-cable/identity/ cert_stat id_header product product_type_vdo1 product_type_vdo2 product_type_vdo3 Changes in v2: - Re-ordered memset call and null assignment when unregistering partners and cables. - Supports registering partner and cable identity with UCSI versions before v2.0. - Shortened lines to within 80 characters with the exception of two error log lines with three indentations. - Tested on usb-testing branch merged with chromeOS 6.8-rc2 kernel. drivers/usb/typec/ucsi/ucsi.c | 125 ++++++++++++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 29 ++++++++ 2 files changed, 154 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 7c84687b5d1a3..4088422b33c74 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -646,6 +646,121 @@ static int ucsi_get_src_pdos(struct ucsi_connector *con) return ret; } +static int ucsi_read_identity(struct ucsi_connector *con, u8 recipient, + struct usb_pd_identity *id) +{ + struct ucsi *ucsi = con->ucsi; + struct ucsi_pd_message_disc_id resp = {}; + u64 command; + int ret; + + if (ucsi->version < UCSI_VERSION_2_0) { + /* + * Before UCSI v2.0, MESSAGE_IN is 16 bytes which cannot fit + * the 28 byte identity response including the VDM header. + * First request the VDM header, ID Header VDO, Cert Stat VDO + * and Product VDO. + */ + command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) | + UCSI_CONNECTOR_NUMBER(con->num); + command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient); + command |= UCSI_GET_PD_MESSAGE_OFFSET(0); + command |= UCSI_GET_PD_MESSAGE_BYTES(0x10); + command |= UCSI_GET_PD_MESSAGE_TYPE( + UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); + + ret = ucsi_send_command(ucsi, command, &resp, 0x10); + if (ret < 0) { + dev_err(ucsi->dev, + "UCSI_GET_PD_MESSAGE v1.2 failed first request (%d)\n", + ret); + return ret; + } + + /* Then request Product Type VDO1 through Product Type VDO3. */ + command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) | + UCSI_CONNECTOR_NUMBER(con->num); + command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient); + command |= UCSI_GET_PD_MESSAGE_OFFSET(0x10); + command |= UCSI_GET_PD_MESSAGE_BYTES(0xc); + command |= UCSI_GET_PD_MESSAGE_TYPE( + UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); + + ret = ucsi_send_command(ucsi, command, &resp.vdo[0], 0xc); + if (ret < 0) { + dev_err(ucsi->dev, + "UCSI_GET_PD_MESSAGE v1.2 failed second request (%d)\n", + ret); + return ret; + } + } else { + /* + * In UCSI v2.0 and after, MESSAGE_IN is large enough to request + * the large enough to request the full Discover Identity + * response at once. + */ + command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) | + UCSI_CONNECTOR_NUMBER(con->num); + command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient); + /* VDM Header + 6 VDOs (0x1c bytes) without an offset */ + command |= UCSI_GET_PD_MESSAGE_OFFSET(0); + command |= UCSI_GET_PD_MESSAGE_BYTES(0x1c); + command |= UCSI_GET_PD_MESSAGE_TYPE( + UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); + + ret = ucsi_send_command(ucsi, command, &resp, sizeof(resp)); + if (ret < 0) { + dev_err(ucsi->dev, "UCSI_GET_PD_MESSAGE failed (%d)\n", + ret); + return ret; + } + } + + id->id_header = resp.id_header; + id->cert_stat = resp.cert_stat; + id->product = resp.product; + id->vdo[0] = resp.vdo[0]; + id->vdo[1] = resp.vdo[1]; + id->vdo[2] = resp.vdo[2]; + return 0; +} + +static int ucsi_get_partner_identity(struct ucsi_connector *con) +{ + int ret; + + ret = ucsi_read_identity(con, UCSI_RECIPIENT_SOP, + &con->partner_identity); + if (ret < 0) + return ret; + + ret = typec_partner_set_identity(con->partner); + if (ret < 0) { + dev_err(con->ucsi->dev, "Failed to set partner identity (%d)\n", + ret); + } + + return ret; +} + +static int ucsi_get_cable_identity(struct ucsi_connector *con) +{ + int ret; + + ret = ucsi_read_identity(con, UCSI_RECIPIENT_SOP_P, + &con->cable_identity); + if (ret < 0) + return ret; + + ret = typec_cable_set_identity(con->cable); + if (ret < 0) { + dev_err(con->ucsi->dev, "Failed to set cable identity (%d)\n", + ret); + } + + return ret; +} + static int ucsi_check_altmodes(struct ucsi_connector *con) { int ret, num_partner_am; @@ -754,6 +869,7 @@ static int ucsi_register_cable(struct ucsi_connector *con) break; } + desc.identity = &con->cable_identity; desc.active = !!(UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE & con->cable_prop.flags); desc.pd_revision = UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD( @@ -777,6 +893,7 @@ static void ucsi_unregister_cable(struct ucsi_connector *con) return; typec_unregister_cable(con->cable); + memset(&con->cable_identity, 0, sizeof(con->cable_identity)); con->cable = NULL; } @@ -827,6 +944,7 @@ static int ucsi_register_partner(struct ucsi_connector *con) break; } + desc.identity = &con->partner_identity; desc.usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD; desc.pd_revision = UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags); @@ -855,6 +973,7 @@ static void ucsi_unregister_partner(struct ucsi_connector *con) ucsi_unregister_altmodes(con, UCSI_RECIPIENT_SOP); ucsi_unregister_cable(con); typec_unregister_partner(con->partner); + memset(&con->partner_identity, 0, sizeof(con->partner_identity)); con->partner = NULL; } @@ -975,6 +1094,10 @@ static int ucsi_check_cable(struct ucsi_connector *con) if (ret < 0) return ret; + ret = ucsi_get_cable_identity(con); + if (ret < 0) + return ret; + return 0; } @@ -1019,6 +1142,7 @@ static void ucsi_handle_connector_change(struct work_struct *work) ucsi_register_partner(con); ucsi_partner_task(con, ucsi_check_connection, 1, HZ); ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ); ucsi_partner_task(con, ucsi_check_cable, 1, HZ); if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == @@ -1418,6 +1542,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) ucsi_register_partner(con); ucsi_pwr_opmode_change(con); ucsi_port_psy_changed(con); + ucsi_get_partner_identity(con); ucsi_check_cable(con); } diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index f0aabef0b7c64..b89fae82e8ce7 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -106,6 +106,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num); #define UCSI_GET_CABLE_PROPERTY 0x11 #define UCSI_GET_CONNECTOR_STATUS 0x12 #define UCSI_GET_ERROR_STATUS 0x13 +#define UCSI_GET_PD_MESSAGE 0x15 #define UCSI_CONNECTOR_NUMBER(_num_) ((u64)(_num_) << 16) #define UCSI_COMMAND(_cmd_) ((_cmd_) & 0xff) @@ -159,6 +160,18 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num); #define UCSI_MAX_PDOS (4) #define UCSI_GET_PDOS_SRC_PDOS ((u64)1 << 34) +/* GET_PD_MESSAGE command bits */ +#define UCSI_GET_PD_MESSAGE_RECIPIENT(_r_) ((u64)(_r_) << 23) +#define UCSI_GET_PD_MESSAGE_OFFSET(_r_) ((u64)(_r_) << 26) +#define UCSI_GET_PD_MESSAGE_BYTES(_r_) ((u64)(_r_) << 34) +#define UCSI_GET_PD_MESSAGE_TYPE(_r_) ((u64)(_r_) << 42) +#define UCSI_GET_PD_MESSAGE_TYPE_SNK_CAP_EXT 0 +#define UCSI_GET_PD_MESSAGE_TYPE_SRC_CAP_EXT 1 +#define UCSI_GET_PD_MESSAGE_TYPE_BAT_CAP 2 +#define UCSI_GET_PD_MESSAGE_TYPE_BAT_STAT 3 +#define UCSI_GET_PD_MESSAGE_TYPE_IDENTITY 4 +#define UCSI_GET_PD_MESSAGE_TYPE_REVISION 5 + /* -------------------------------------------------------------------------- */ /* Error information returned by PPM in response to GET_ERROR_STATUS command. */ @@ -338,6 +351,18 @@ struct ucsi_connector_status { ((get_unaligned_le32(&(_p_)[5]) & GENMASK(16, 1)) >> 1) } __packed; +/* + * Data structure filled by PPM in response to GET_PD_MESSAGE command with the + * Response Message Type set to Discover Identity Response. + */ +struct ucsi_pd_message_disc_id { + u32 vdm_header; + u32 id_header; + u32 cert_stat; + u32 product; + u32 vdo[3]; +} __packed; + /* -------------------------------------------------------------------------- */ struct ucsi_debugfs_entry { @@ -428,6 +453,10 @@ struct ucsi_connector { struct usb_power_delivery_capabilities *partner_sink_caps; struct usb_role_switch *usb_role_sw; + + /* USB PD identity */ + struct usb_pd_identity partner_identity; + struct usb_pd_identity cable_identity; }; int ucsi_send_command(struct ucsi *ucsi, u64 command, From patchwork Wed Feb 28 22:04:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 208051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp220573rwa; Wed, 28 Feb 2024 14:05:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUklguelsMKb+IK24kAipdUgtzjzMmRX/5+QhvidsLRYOH2Kbg0QzHVcwIItDuwOr4kEWVdMAllD2AAcBPTxgGx81t10w== X-Google-Smtp-Source: AGHT+IFY9a4Ffx0dBRiMdnNJmFYBuFPBctFE3KPDzUH2xJvZ3FiG31576r3d8QF5tMx2a/HrVp/6 X-Received: by 2002:a17:906:7189:b0:a43:87a3:3fe8 with SMTP id h9-20020a170906718900b00a4387a33fe8mr123278ejk.72.1709157917273; Wed, 28 Feb 2024 14:05:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709157917; cv=pass; d=google.com; s=arc-20160816; b=Qt6+913yHN4hUzKBWfpWu59EyjcNJs6bKrz9r8LsBHa3F33CUJol2HRuIewVZ9sgFj aVaB/u3TjUaPHoJylKmIjirTTRT5vqmqfyoY7PRAGVW1jaPg1doAxvYksltyATWPIO9O 0jlxQOpgAq9RCKfOAH9XRw+J2j3suWLmUYq+s2ah8ZqtpwMHruEzqUYpcxyubrP2Ly05 vyXU4EheXxoHYmtZGvc0YXStkY47DUVPiIGRoWLQosYNn6765B8PMybSk5l7FQ54Rzy5 dNAhaolfJW73LDxkSQbmIlKMA2JJCls36wrSQPpm/K4FWgmGNtri3vzwKYqCO0plb3Uz 6zmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=jb2gwN6bxiLt3LtO6maFpO1+dlXHorrZhIAqEy+dyf0=; fh=NLUy2ZDck8Bs9mvBh6Sw7WHW+Puqz0Ox7vvck6T+9FI=; b=DtW7NS5TDjagKDL/ARmn5Tk07lrNXQ3QmfY1/19Sw91KBcSVz5v8AmLMcKhiZcuTr2 8UyjnPuX1A1f3WRA75K0tl52seMTRG+9yp0LUponz0nXgWLi417Ac/FgWgTDHbAb1FZC phZrMSrQa/FACQzaBiLy1uuk7n57Aj6Ksn290I14EOfMN+RMZ0eUYH3f2FnYGMBB+LCn OB3+SwsWig0hZOLrdzvlHxzxYJLo3vebpqJyqC6droiI9QKaavoIVBmOIr7UWeZolq0b 7/lyCEtXg3lK6dPldkIPMuGa1PYiAzclDLlsrIxTnqVgvDyETYsgc4sA0yzTYLES2c1S 5MDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=EdIfd3dW; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85770-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85770-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id oz14-20020a1709077d8e00b00a3f51ba0d5esi2161313ejc.297.2024.02.28.14.05.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 14:05:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85770-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=EdIfd3dW; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85770-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85770-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BF4C41F25344 for ; Wed, 28 Feb 2024 22:05:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F0FE1361C9; Wed, 28 Feb 2024 22:04:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EdIfd3dW" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA8421361A9 for ; Wed, 28 Feb 2024 22:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709157849; cv=none; b=Ypdq7+EZd0IUKYYuEGlXOsrKmVlTYHWqQsM1qq/kYV4HlfPptTZ+idO5Q1hUxr7GM1SbTS86NTF3Ss4UD5xtMEij3pr0hYO0D+S+TARZI5fChKnowE/ZwTFi7F6wtUz/HQoPHZRuldzSZSS4A8ddizxY5/6L6JfMOsSwP1rdY9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709157849; c=relaxed/simple; bh=Ck20RD7SWLmT3wN/hjyZSTuoMvNa2KJPDTQ2bpCa8rU=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=IBPNta+yXDz9zmM4x3pe6HtPmuYGmRCKHyl0ukI6srwg1wi2cSQnAahDnzcVPjaYJLkIhUDqsATuo1WRENweDfzrGPEtKzN4JIWmz35QWmcolRqhfYBw5WMAuy5ZwK87bur5Fw+uANNqDbOZ69362l6O8b0o6uBveY/rnvmcJQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EdIfd3dW; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc746178515so373906276.2 for ; Wed, 28 Feb 2024 14:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709157846; x=1709762646; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=jb2gwN6bxiLt3LtO6maFpO1+dlXHorrZhIAqEy+dyf0=; b=EdIfd3dWgZ+phOaF12ToGLCveiEDgRPqBtkW1VAVQpFh+v7MRCW/9e2ePDD6Qi3uZG o8CLvN5p0LP/DBMyyeHKFjkyK45rEhN3k0IJWa0E2IjDaq2U00krCVzAnqUHSG8kN5cD Gisuau13EutHypOu7zGPTYgESX/HWHSoCaiWOdxn6NIvuvncTyn1CoONAfjxnlHiWkDp j6CGfC0jM8dNrV/0TcHwnaH1LtnZEC1TRJMxonedv7ThC95r1PcOrepnbIf83OKWzkgG joS4XMVIYP2Kv52/NoUQ64DpcWhrnElhCxRmi4/oFal5kbwm0jTsAqWqwMkACs2jq6V8 SBtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709157846; x=1709762646; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jb2gwN6bxiLt3LtO6maFpO1+dlXHorrZhIAqEy+dyf0=; b=MEogq077DHrGnJXhKu2gSOUzDioRi1fhghKWEAOw/jh7/jnurQjXzDMY0ftUm7G+2i tB4bIL3lmjYEj1amTRpM584ejTns/ihYb1OS47r9hpDa5e6p3pPnUjaMp4qh86FHe25K 089VGFVIKiLLoauJBe9sFG5gmmIc9BzumRSMjErUu0JTYbmFwdU67snjOV5QjA7fm5ri PiZNcT1cGtPdVDAiIKBBm9SClYe71seeZAE9wg0F1DTPXUnOXvlp6pgcZzkTMqF9DaKo shMdjXMn0GzwGBJ3Xl5LmzjrQHKs8b6m7WYrm5ugLqokjEMaA/Ah0PGlK+zF6Rscd7he C6Vg== X-Forwarded-Encrypted: i=1; AJvYcCXTJzqbKKtxnutdh71uVoqOJfkSo7VsG7KCrjlewdCeW3eEYEU0nt92Yf465AvtvDTulojnKjRhczQ3EiVLHnVDMTkt8IFRhQ9hEs8O X-Gm-Message-State: AOJu0YyJiyM/Rmql4hQe+VoLyMNoADXiAWrIP/eXCF29ptGqdz6MUbqN AeWgCBFEyQcuTNFkfA0TLcb+9IqAMPtboBOYrFAN28Yq9wmStGPvbHK37rSQ9nHP8/ZuoteyIb8 WeA== X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:150f:b0:dc6:207e:e8b1 with SMTP id q15-20020a056902150f00b00dc6207ee8b1mr125822ybu.2.1709157845820; Wed, 28 Feb 2024 14:04:05 -0800 (PST) Date: Wed, 28 Feb 2024 22:04:02 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240228220403.3614604-1-jthies@google.com> Subject: [PATCH v2 4/4] usb: typec: ucsi: Register SOP' alternate modes with cable plug From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792181972173121854 X-GMAIL-MSGID: 1792181972173121854 Register SOP' alternate modes with a Type-C Connector Class cable plug. Alternate modes are queried from the PPM using the GET_ALTERNATE_MODES command with recipient set to SOP'. Reviewed-by: Benson Leung Reviewed-by: Prashant Malani Reviewed-by: Heikki Krogerus Signed-off-by: Jameson Thies --- SOP' GET_ALTERNATE_MODE responses from the PPM are correctly registered to the cable plug. nospike-rev4 /sys/class/typec # ls port0-cable/port0-plug0/ device port0-plug0.0 port0-plug0.1 power subsystem uevent Changes in v2: - Shortened lines to within 80 characters. - Tested on usb-testing branch merged with chromeOS 6.8-rc2 kernel. drivers/usb/typec/ucsi/ucsi.c | 60 +++++++++++++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 2 ++ 2 files changed, 62 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 4088422b33c74..281954fe9d855 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -399,6 +399,27 @@ static int ucsi_register_altmode(struct ucsi_connector *con, con->partner_altmode[i] = alt; break; + case UCSI_RECIPIENT_SOP_P: + i = ucsi_next_altmode(con->plug_altmode); + if (i < 0) { + ret = i; + goto err; + } + + ret = ucsi_altmode_next_mode(con->plug_altmode, desc->svid); + if (ret < 0) + return ret; + + desc->mode = ret; + + alt = typec_plug_register_altmode(con->plug, desc); + if (IS_ERR(alt)) { + ret = PTR_ERR(alt); + goto err; + } + + con->plug_altmode[i] = alt; + break; default: return -EINVAL; } @@ -566,6 +587,9 @@ static void ucsi_unregister_altmodes(struct ucsi_connector *con, u8 recipient) case UCSI_RECIPIENT_SOP: adev = con->partner_altmode; break; + case UCSI_RECIPIENT_SOP_P: + adev = con->plug_altmode; + break; default: return; } @@ -849,6 +873,33 @@ static void ucsi_unregister_partner_pdos(struct ucsi_connector *con) con->partner_pd = NULL; } +static int ucsi_register_plug(struct ucsi_connector *con) +{ + struct typec_plug *plug; + struct typec_plug_desc desc = {.index = TYPEC_PLUG_SOP_P}; + + plug = typec_register_plug(con->cable, &desc); + if (IS_ERR(plug)) { + dev_err(con->ucsi->dev, + "con%d: failed to register plug (%ld)\n", con->num, + PTR_ERR(plug)); + return PTR_ERR(plug); + } + + con->plug = plug; + return 0; +} + +static void ucsi_unregister_plug(struct ucsi_connector *con) +{ + if (!con->plug) + return; + + ucsi_unregister_altmodes(con, UCSI_RECIPIENT_SOP_P); + typec_unregister_plug(con->plug); + con->plug = NULL; +} + static int ucsi_register_cable(struct ucsi_connector *con) { struct typec_cable *cable; @@ -892,6 +943,7 @@ static void ucsi_unregister_cable(struct ucsi_connector *con) if (!con->cable) return; + ucsi_unregister_plug(con); typec_unregister_cable(con->cable); memset(&con->cable_identity, 0, sizeof(con->cable_identity)); con->cable = NULL; @@ -1098,6 +1150,14 @@ static int ucsi_check_cable(struct ucsi_connector *con) if (ret < 0) return ret; + ret = ucsi_register_plug(con); + if (ret < 0) + return ret; + + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P); + if (ret < 0) + return ret; + return 0; } diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index b89fae82e8ce7..32daf5f586505 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -429,9 +429,11 @@ struct ucsi_connector { struct typec_port *port; struct typec_partner *partner; struct typec_cable *cable; + struct typec_plug *plug; struct typec_altmode *port_altmode[UCSI_MAX_ALTMODES]; struct typec_altmode *partner_altmode[UCSI_MAX_ALTMODES]; + struct typec_altmode *plug_altmode[UCSI_MAX_ALTMODES]; struct typec_capability typec_cap;