From patchwork Fri Feb 9 22:37:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 199154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1182551dyd; Fri, 9 Feb 2024 15:07:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDcinlITSEfYldRSpltbZdEiT4CezzIcXKuQm+GtkP4pQd8T4WuSQqNZ4SBY4gJUCzyIwD X-Received: by 2002:a05:6a21:9103:b0:19e:4c37:8737 with SMTP id tn3-20020a056a21910300b0019e4c378737mr597481pzb.5.1707520035078; Fri, 09 Feb 2024 15:07:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707520035; cv=pass; d=google.com; s=arc-20160816; b=Onk3L3S26OufFoccDkuXHOUc99Nm1U4HYOPuHxQyX3nxwEO/bw8RhErpTNMwCQ1hwP RlXbfyrzDVvBwGML4DsCrQ3VswudwBCAQVvHZry0YgsCDF92hkWwn/8IuMEZr99hYCU4 Qi4+vrGMKsiYI/JaEaFZTgVmqFbdfjc79ylf3jsrMYte1NFD+XbPkc64tvpk30flH6St YIwt2ziVi/WgWpLB1UXx9X0u/ZPFvivoyoMnz2aKqKInQCijqMdSH1CnSh9O/EcDa+4R M5SFYmP1f6bN0EsLfx/ZKsBO5SrNMvfSVtOM71qTQnfojT+TOTCzdQYYMhTV1ob3lpW3 zEyw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=q3v1P72CYS7nnHVJlklt4iy31XMKI0yvALu5tUoK9M4=; fh=uT/M6FoZfqMnURTt+0VM2aCUDmDlBSSnVh+b6m+oPAA=; b=AhJdstguCf2fnEz2qHeYGUjhzuyuyuodA4ifqj8PiO9KCIeVlLO+Qohl1iUV6ElHar f9QVaikgAxP76vJ4tSokTcBJqCFLVxTWv3ILNxyBmf2OGAw8a0f1D/TlPl6NdRiF2MPx aJJYVFKet+/wQWNSf8Y/OKSUlssT8xStc3UIDnU6pDD4+bZse7VQZVA2NBowKxcNcy89 Fe2RoTF2+wRd6gLj3R+WgUZEHncUQ+L2XHCRLR9r/eOK2hmMrwwX95g45OwV/oIli4hj 4IyWARkCki321nGDy2SEhgH5xWgRcXY2zpGLMzLI9PBPps9zc8IVmts2yJJ+uJgNWQOQ OW5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Nz/3JUvt"; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60122-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60122-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCUkM6V3znMspWIXIp11a+r9euX9NvKC2jgPduyc1Ld0qWoQQpJeN0P4YApA83DiBGD3wQWjAG3ghmmUOwAs6Y0VQgMKAg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ka30-20020a056a00939e00b006e0901330e8si1065835pfb.368.2024.02.09.15.07.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 15:07:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60122-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=@chromium.org header.s=google header.b="Nz/3JUvt"; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60122-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60122-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 DF443B2DCA3 for ; Fri, 9 Feb 2024 22:39:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86FD639AEC; Fri, 9 Feb 2024 22:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Nz/3JUvt" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 80E7528370 for ; Fri, 9 Feb 2024 22:38:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707518309; cv=none; b=CLBXK7QxutYuqL+mFtyH78DI2T//p17QYvb6rL+o2ARjZKS78TP7Fv8gzIrvdBL3tv/zfsiHxZObOOs3WNF4mx3rUH230iPuybgdT4psIIuhqPT9DOYzfBGiieKVmU9rkdGl9t6/ZspUmsPkkwCwlh6sgRs6zdXzHvMef/7DEl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707518309; c=relaxed/simple; bh=D0wMQBAP5bomV1qNyDC9+FF9TaUQoAw2/pwkBCGCI5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hzpeKIIzS68JN0Hd+p08U1FQNLt2UJj4477bHjXridUknKMlId56y2A6888dQTK8mIoCNgTE/Wweg3+QgSSRtKPIO28fYzagdiWmlmvQ8/bzwM1s9mpD3OLWq7QzDFMULKX/84XrvjJNKYm0M6aeksieyQeGSV9bnmxlEsWvcwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Nz/3JUvt; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e08dd0fa0bso768396b3a.1 for ; Fri, 09 Feb 2024 14:38:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707518307; x=1708123107; darn=vger.kernel.org; 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=q3v1P72CYS7nnHVJlklt4iy31XMKI0yvALu5tUoK9M4=; b=Nz/3JUvtiCPfQ8ItkKpt/iSN6qvkeSlw/JK5WeRY2MZ8PfIY4lXy99WVZcUM6QSRuZ ZZKf+D9vwdnEzjKVKOlTZEor/4viFAbRlpO4K0rGiCYOtnQirakM2hOnGIakdASQwpkw uuQbfAGpFdX/mjqKagCDqTzNiGQoTHL9memHY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707518307; x=1708123107; 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=q3v1P72CYS7nnHVJlklt4iy31XMKI0yvALu5tUoK9M4=; b=ThB5e5ZNesqLE8l2NT9Zg/iM6bNtjYOm3cAqMFn3fq75gDyXIUJNce4tBRBZv/XdJM DS9ed6mr52i2j0zujFSUDMgfBXtg2iaHf+jGN24vVC2C3pFffzqDW5xweblZ1MoMOyMv BU33aQyz+lHP1SxN/cV7BU3V8N5jHwLjPNNWZEM+ShXjaA1XyssRTnrcUcTy06WCRsgT Pv8XM551GJtcqs9aphi8Khc/ncnJYjnFYOeT750xYFWkcyKfB0bQtKqv9+yiMYFZqRdT S3QWIWfmHU5VUJd6Fhsvnbk2aoIJWBWULvfgzjcTyuhostbOjwlW5SbO+d9rkGJQ+Gk8 g0yA== X-Gm-Message-State: AOJu0YxbKVv+YgupkmkO7hQ7XB34kY6yJXJLFx5PUzADb+Tqj9meGgqw 7xtOjOP0PkmVMsktW/COIWwbz/gwHnswT5JXqn34IGTvtgCC3TKZD/akJ5qZ0Q== X-Received: by 2002:a62:c183:0:b0:6e0:53dc:5a86 with SMTP id i125-20020a62c183000000b006e053dc5a86mr673591pfg.4.1707518306813; Fri, 09 Feb 2024 14:38:26 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUqQ0d0lW0rhZY8bknQp4cJi9bKRhqRDz5Opza4sRwyH2vkoInyMSbkBFBsHs48chy8gIgewB8tCutSbEFiageui8r9AzSwMqgoIT/cvlnq08h4ZcQ3rGfaujzQ85CqDIywRKLmxGWGtFekRGbVv8a6FQ91PhTpFiLMW1CdT8SbHNj86eKNg3aeiOleVveeqUs1mmjEMFnDY0Xq+lx0r0hgngfxEdaFsZMg/xg0gPSSThO8G0n3vVc83dzVpZEGhIIXg+pNzBhf2tpCp5Rns24LeSaWqqDc/zt+01MBAGEji12Jg/2UckSX/q654MCh625c60UfgzC2Z3Tg+4Y+cq5BiKehz8t4Ar941fQXCFjYmA3ZpY2MTfpuG/uZfNFCSj5vRumf0SA5tVjeFdT4IJQwM1Z54GoS Received: from localhost (209.148.168.34.bc.googleusercontent.com. [34.168.148.209]) by smtp.gmail.com with UTF8SMTPSA id hq26-20020a056a00681a00b006e040d4d251sm1058929pfb.155.2024.02.09.14.38.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 14:38:26 -0800 (PST) From: Abhishek Pandit-Subedi To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: pmalani@chromium.org, jthies@google.com, Abhishek Pandit-Subedi , Neil Armstrong , Dmitry Baryshkov , Fabrice Gasnier , Greg Kroah-Hartman , Hans de Goede , Saranya Gopal , linux-kernel@vger.kernel.org Subject: [PATCH v5 1/3] usb: typec: ucsi: Limit read size on v1.2 Date: Fri, 9 Feb 2024 14:37:30 -0800 Message-ID: <20240209143723.v5.1.Iacf5570a66b82b73ef03daa6557e2fc0db10266a@changeid> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240209223824.622869-1-abhishekpandit@chromium.org> References: <20240209223824.622869-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790464528164336635 X-GMAIL-MSGID: 1790464528164336635 Between UCSI 1.2 and UCSI 2.0, the size of the MESSAGE_IN region was increased from 16 to 256. In order to avoid overflowing reads for older systems, add a mechanism to use the read UCSI version to truncate read sizes on UCSI v1.2. Tested-by: Neil Armstrong Reviewed-by: Prashant Malani Reviewed-by: Heikki Krogerus Signed-off-by: Abhishek Pandit-Subedi --- Tested on 6.6 kernel. Dmesg output from this change: [ 105.058162] ucsi_um_test ucsi_um_test_device.0: Registered UCSI interface with version 3.0.0 Changes in v5: - Change min_t to clamp Changes in v4: - Added missing Tested-By tags from v1 and reviewed-by tags. Changes in v2: - Changed log message to DEBUG drivers/usb/typec/ucsi/ucsi.c | 26 ++++++++++++++++++++++++-- drivers/usb/typec/ucsi/ucsi.h | 11 +++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 14f5a7bfae2e..7c5cecdd93d6 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -36,6 +36,19 @@ */ #define UCSI_SWAP_TIMEOUT_MS 5000 +static int ucsi_read_message_in(struct ucsi *ucsi, void *buf, + size_t buf_size) +{ + /* + * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the + * reads here. + */ + if (ucsi->version <= UCSI_VERSION_1_2) + buf_size = clamp(buf_size, 0, 16); + + return ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, buf, buf_size); +} + static int ucsi_acknowledge_command(struct ucsi *ucsi) { u64 ctrl; @@ -72,7 +85,7 @@ static int ucsi_read_error(struct ucsi *ucsi) if (ret < 0) return ret; - ret = ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, &error, sizeof(error)); + ret = ucsi_read_message_in(ucsi, &error, sizeof(error)); if (ret) return ret; @@ -170,7 +183,7 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command, length = ret; if (data) { - ret = ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, data, size); + ret = ucsi_read_message_in(ucsi, data, size); if (ret) goto out; } @@ -1558,6 +1571,15 @@ int ucsi_register(struct ucsi *ucsi) if (!ucsi->version) return -ENODEV; + /* + * Version format is JJ.M.N (JJ = Major version, M = Minor version, + * N = sub-minor version). + */ + dev_dbg(ucsi->dev, "Registered UCSI interface with version %x.%x.%x", + UCSI_BCD_GET_MAJOR(ucsi->version), + UCSI_BCD_GET_MINOR(ucsi->version), + UCSI_BCD_GET_SUBMINOR(ucsi->version)); + queue_delayed_work(system_long_wq, &ucsi->work, 0); ucsi_debugfs_register(ucsi); diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 6478016d5cb8..bec920fa6b8a 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -23,6 +23,17 @@ struct dentry; #define UCSI_CONTROL 8 #define UCSI_MESSAGE_IN 16 #define UCSI_MESSAGE_OUT 32 +#define UCSIv2_MESSAGE_OUT 272 + +/* UCSI versions */ +#define UCSI_VERSION_1_2 0x0120 +#define UCSI_VERSION_2_0 0x0200 +#define UCSI_VERSION_2_1 0x0210 +#define UCSI_VERSION_3_0 0x0300 + +#define UCSI_BCD_GET_MAJOR(_v_) (((_v_) >> 8) & 0xFF) +#define UCSI_BCD_GET_MINOR(_v_) (((_v_) >> 4) & 0x0F) +#define UCSI_BCD_GET_SUBMINOR(_v_) ((_v_) & 0x0F) /* Command Status and Connector Change Indication (CCI) bits */ #define UCSI_CCI_CONNECTOR(_c_) (((_c_) & GENMASK(7, 1)) >> 1) From patchwork Fri Feb 9 22:37:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 199150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1170796dyd; Fri, 9 Feb 2024 14:39:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX8ublxmcBFAIevBXEs0qrkzyD47FHiOKjLZ8ZU10xNxLqXq9qIIkuolZDegj1/FRzNOLazEP4kNHjFgKraV+sXYBpRkw== X-Google-Smtp-Source: AGHT+IGDBJIaMAriyPt66FlLYASwRotQ5sbO7yhJ+/YY7liV/xzpXwdVlK/ZdEYFvEVYHu8Np+5b X-Received: by 2002:a9d:6288:0:b0:6e1:12a3:f291 with SMTP id x8-20020a9d6288000000b006e112a3f291mr453074otk.12.1707518392812; Fri, 09 Feb 2024 14:39:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707518392; cv=pass; d=google.com; s=arc-20160816; b=LYmRxypeQssu6GS3nNSVahppmBWhEwwVmejvqnMno4ZtwH4VvTrnbvkCcnht1F7cKM L/T+80vpJ7Rn10v3JpFxpIwjkyE2KAiMCwt56tzLfGgrwOFmFsiIpymzGKLveOHlyZ5D 9qnQ5OVqtNGwxWSO8KpUsxeo5rZSve1fvMmAfQFnxfCTflbXPNmZeDcNKc9fadNQrSfB hIdCNadKNz/3UuhsTSiUCMpQ+zmfojhyItuANhNaM6XitNLkYIVeJQB7oHZgXdPHbhjZ KZCrqEHMgj1t7K/nP6gY85s0rpXapBCJ9YGmFv7Xsg5Md+NJkVBsozwM0ji5GKzpsQtD F5Dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=V6t8uVjqfKj+e3cGps0LaAFzQjViggK8EPU4tBP7N9o=; fh=O4PbhItJNwMx3WkDmq660wtNp9O//t55AaoFlf5XY/M=; b=TJBwljbK3y2naB/bl/zoI5Ye13fafzo9CUy23TZash1+I5nTow0qWUcNmNDlyxklNr W5+CestfyQPztE7OHpXgnMlsMERbnCLEcyZ5jqsmAIKMhJy88md9cBC78sYFnokSWLY9 /SRTxkxv4+H1j2sOgP7RrPJdbyKlNEHfOAvlTl0z3rUJ+7RcoCD39Xf0z+oaktXbUIOR G8fVcxe3IxBqjTNSYh03XstFiAZnnAskq0L+agKhkbTCuaFVjKugPaFreoBrqPV9DyyG XfUaBV91KwwkLN3RCgVHHpg6sUXMGZJw8JIoZLMHMuOb8EaKx30O6BHp1CVf5uLNPCcD MUXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lto0lsIf; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60123-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60123-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCUFAIp02y/6KqmdpkS7HRb2x2soF170zl9Fef6g6QifuBzeDB9XCdvIAmksF1MsUec7ZPEXPhHsJwGBmBbCozWaBuZ6rA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d6-20020ac851c6000000b0042c63f081b6si525264qtn.84.2024.02.09.14.39.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:39:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60123-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lto0lsIf; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60123-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60123-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 824C01C23504 for ; Fri, 9 Feb 2024 22:39:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4FD139FE2; Fri, 9 Feb 2024 22:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="lto0lsIf" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 605AF2AD39 for ; Fri, 9 Feb 2024 22:38:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707518310; cv=none; b=EU43PWo+uCJPL1t2cOaemukEqpuZfry0GPrkujMJjAnzLIb6xYhyRd5iDcsEkalEfj4tYorAvvhadVI5GBl74D6AFucvESLjo1qov1eLZQWOLWCU37z9yppi6Q+F0whrOhPudhFsx6rn5WXTQVbvBweFo6/Zk5s6HqCjBS5z2kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707518310; c=relaxed/simple; bh=Cc9hBfVDEI9Fq6JPOFe/l1+gX3OamRL9BW5+Efsqr2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e0I4VkJRWA/9D21bwpLoacSTbo/IUiEU1I6Rq8Bu+M5R04fg3sBPSaPXQo0cxI9W4y3bHVHrahj1fzSpji5x46rghTjjSpKuA4cghprW6FKU/Q9MpBi6BfY+MynbJJTnigBy43hFUQh6OYVo+Pj/0cfc6vrkGTqqJw8mu9ifsNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=lto0lsIf; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d76671e5a4so12102375ad.0 for ; Fri, 09 Feb 2024 14:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707518308; x=1708123108; darn=vger.kernel.org; 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=V6t8uVjqfKj+e3cGps0LaAFzQjViggK8EPU4tBP7N9o=; b=lto0lsIf//GA22D8769iFnDeGCnOzmprRL1OWUuO4vsUmTT1gdS96Xq0CzEhwRosS8 ewsHzq2hlevgJ6hwVcF8S3nG2Vq5WUoiFw0aeN4GiMNLrUaLotfGHfhwG36w8lVUSGBP 38qxsRGdVvs+rU7dyh27jiSZXUlKu4PuQVyjk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707518308; x=1708123108; 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=V6t8uVjqfKj+e3cGps0LaAFzQjViggK8EPU4tBP7N9o=; b=V13TM1hrOMXxAnBI1HMSJhRugN04ACHZvwNaVuIV8p8hKKvTGsp0ilysAOgTwE9W6S 6AJp2PI2aHuXS5sD1wRTEY5YAQm7ZCRwYTyGuZBKm7Xn51qzY126MUSLQHd1fg6UZU/j LHxXN1639devqHqaaGLaTpt9FHJMEq8UuKyhUazVVRlPAHf8fAYkdJq17JfHfBUqAhi5 7C5DS0Gl39S7ABKRMzuTi0+bvyVSD/8nr8TpZKpd0cnJdji3BPNq4CUDfwKtjNxVMbFX 82+50G7l2/olHTPdjDqQBtxx1jt9hL7lVM8i14IJViBVA7nubLYEklemSqtAoAMZDRb4 JXig== X-Forwarded-Encrypted: i=1; AJvYcCUqIFRmtXSH3KFtX4A32Urs5Xg1W6+zfYWNmkgSjvwmqOZecANoaiF3sVh3oepS3PeCJWGwn5BHF1w+vyzk0OenuTXN/yTOLPp1Y/P0 X-Gm-Message-State: AOJu0YzIZm8KiYv1xgPu648Pb4195asEjpB+VYWC3u9a5CPOf7m9L8kl FO1ER10t9/uV2XEgjVZv9ERODX8RMJ58xfNlB6H1EXEPpNPNBEDDM+XXd0759g== X-Received: by 2002:a17:902:fc50:b0:1d7:7edb:e9b9 with SMTP id me16-20020a170902fc5000b001d77edbe9b9mr737372plb.37.1707518307760; Fri, 09 Feb 2024 14:38:27 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXXkAyYIf/gyptbxo35GZBi2zFh6q5MA2hBk8+tFFeMl6Ynu0eX3gNs43873+gh09D2GTJqakgvMCSVvIJpb2wpNLdV/MbVWlkZWckABc+q/SkSkWyUNhXGsZwaJYSg8AtCQi1THbkaAV0G+ErCQPo4Yvd09wzir0JbwCwuUEfFnE68QMxVqhspVjUIMmodycitHvl+T2dJhqDGcot1+/51ba3Herr3M7JTKueaKHAYcmHcUdWnEpDGIc1NXnCtf8OyuZiFPB+oho0cZaotNupuQIg72vy7qmjPaF/GVkYBlbDBJcZEzwhgiuvPeOctdxdzflbKVo4DTCF/luDodCjqEn2rWYmb Received: from localhost (209.148.168.34.bc.googleusercontent.com. [34.168.148.209]) by smtp.gmail.com with UTF8SMTPSA id v2-20020a170903238200b001d54b763995sm1976154plh.129.2024.02.09.14.38.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 14:38:27 -0800 (PST) From: Abhishek Pandit-Subedi To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: pmalani@chromium.org, jthies@google.com, Abhishek Pandit-Subedi , Dmitry Baryshkov , Greg Kroah-Hartman , Rajaram Regupathy , Saranya Gopal , linux-kernel@vger.kernel.org Subject: [PATCH v5 2/3] usb: typec: ucsi: Update connector cap and status Date: Fri, 9 Feb 2024 14:37:31 -0800 Message-ID: <20240209143723.v5.2.I3d909e3c9a200621e3034686f068a3307945fd87@changeid> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240209223824.622869-1-abhishekpandit@chromium.org> References: <20240209223824.622869-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790462805750935913 X-GMAIL-MSGID: 1790462805750935913 Update the data structures for ucsi_connector_capability and ucsi_connector_status to UCSIv3. Reviewed-by: Prashant Malani Reviewed-by: Heikki Krogerus Signed-off-by: Abhishek Pandit-Subedi --- (no changes since v4) Changes in v4: - Fix BCD translation of PD Major Rev Changes in v3: - Change include to asm/unaligned.h and reorder include. drivers/usb/typec/ucsi/ucsi.h | 56 ++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index bec920fa6b8a..7e35ffbe0a6f 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -10,6 +10,7 @@ #include #include #include +#include /* -------------------------------------------------------------------------- */ @@ -35,6 +36,12 @@ struct dentry; #define UCSI_BCD_GET_MINOR(_v_) (((_v_) >> 4) & 0x0F) #define UCSI_BCD_GET_SUBMINOR(_v_) ((_v_) & 0x0F) +/* + * Per USB PD 3.2, Section 6.2.1.1.5, the spec revision is represented by 2 bits + * 0b00 = 1.0, 0b01 = 2.0, 0b10 = 3.0, 0b11 = Reserved, Shall NOT be used. + */ +#define UCSI_SPEC_REVISION_TO_BCD(_v_) (((_v_) + 1) << 8) + /* Command Status and Connector Change Indication (CCI) bits */ #define UCSI_CCI_CONNECTOR(_c_) (((_c_) & GENMASK(7, 1)) >> 1) #define UCSI_CCI_LENGTH(_c_) (((_c_) & GENMASK(15, 8)) >> 8) @@ -214,9 +221,29 @@ struct ucsi_connector_capability { #define UCSI_CONCAP_OPMODE_USB2 BIT(5) #define UCSI_CONCAP_OPMODE_USB3 BIT(6) #define UCSI_CONCAP_OPMODE_ALT_MODE BIT(7) - u8 flags; + u32 flags; #define UCSI_CONCAP_FLAG_PROVIDER BIT(0) #define UCSI_CONCAP_FLAG_CONSUMER BIT(1) +#define UCSI_CONCAP_FLAG_SWAP_TO_DFP BIT(2) +#define UCSI_CONCAP_FLAG_SWAP_TO_UFP BIT(3) +#define UCSI_CONCAP_FLAG_SWAP_TO_SRC BIT(4) +#define UCSI_CONCAP_FLAG_SWAP_TO_SINK BIT(5) +#define UCSI_CONCAP_FLAG_EX_OP_MODE(_f_) \ + (((_f_) & GENMASK(13, 6)) >> 6) +#define UCSI_CONCAP_EX_OP_MODE_USB4_GEN2 BIT(0) +#define UCSI_CONCAP_EX_OP_MODE_EPR_SRC BIT(1) +#define UCSI_CONCAP_EX_OP_MODE_EPR_SINK BIT(2) +#define UCSI_CONCAP_EX_OP_MODE_USB4_GEN3 BIT(3) +#define UCSI_CONCAP_EX_OP_MODE_USB4_GEN4 BIT(4) +#define UCSI_CONCAP_FLAG_MISC_CAPS(_f_) \ + (((_f_) & GENMASK(17, 14)) >> 14) +#define UCSI_CONCAP_MISC_CAP_FW_UPDATE BIT(0) +#define UCSI_CONCAP_MISC_CAP_SECURITY BIT(1) +#define UCSI_CONCAP_FLAG_REV_CURR_PROT_SUPPORT BIT(18) +#define UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_) \ + (((_f_) & GENMASK(20, 19)) >> 19) +#define UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(_f_) \ + UCSI_SPEC_REVISION_TO_BCD(UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_)) } __packed; struct ucsi_altmode { @@ -276,15 +303,36 @@ struct ucsi_connector_status { #define UCSI_CONSTAT_PARTNER_TYPE_DEBUG 5 #define UCSI_CONSTAT_PARTNER_TYPE_AUDIO 6 u32 request_data_obj; - u8 pwr_status; -#define UCSI_CONSTAT_BC_STATUS(_p_) ((_p_) & GENMASK(2, 0)) + + u8 pwr_status[3]; +#define UCSI_CONSTAT_BC_STATUS(_p_) ((_p_[0]) & GENMASK(1, 0)) #define UCSI_CONSTAT_BC_NOT_CHARGING 0 #define UCSI_CONSTAT_BC_NOMINAL_CHARGING 1 #define UCSI_CONSTAT_BC_SLOW_CHARGING 2 #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3 -#define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_) (((_p_) & GENMASK(6, 3)) >> 3) +#define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_) (((_p_[0]) & GENMASK(5, 2)) >> 2) #define UCSI_CONSTAT_CAP_PWR_LOWERED 0 #define UCSI_CONSTAT_CAP_PWR_BUDGET_LIMIT 1 +#define UCSI_CONSTAT_PROVIDER_PD_VERSION_OPER_MODE(_p_) \ + ((get_unaligned_le32(_p_) & GENMASK(21, 6)) >> 6) +#define UCSI_CONSTAT_ORIENTATION(_p_) (((_p_[2]) & GENMASK(6, 6)) >> 6) +#define UCSI_CONSTAT_ORIENTATION_DIRECT 0 +#define UCSI_CONSTAT_ORIENTATION_FLIPPED 1 +#define UCSI_CONSTAT_SINK_PATH_STATUS(_p_) (((_p_[2]) & GENMASK(7, 7)) >> 7) +#define UCSI_CONSTAT_SINK_PATH_DISABLED 0 +#define UCSI_CONSTAT_SINK_PATH_ENABLED 1 + u8 pwr_readings[9]; +#define UCSI_CONSTAT_REV_CURR_PROT_STATUS(_p_) ((_p_[0]) & 0x1) +#define UCSI_CONSTAT_PWR_READING_VALID(_p_) (((_p_[0]) & GENMASK(1, 1)) >> 1) +#define UCSI_CONSTAT_CURRENT_SCALE(_p_) (((_p_[0]) & GENMASK(4, 2)) >> 2) +#define UCSI_CONSTAT_PEAK_CURRENT(_p_) \ + ((get_unaligned_le32(_p_) & GENMASK(20, 5)) >> 5) +#define UCSI_CONSTAT_AVG_CURRENT(_p_) \ + ((get_unaligned_le32(&(_p_)[2]) & GENMASK(20, 5)) >> 5) +#define UCSI_CONSTAT_VOLTAGE_SCALE(_p_) \ + ((get_unaligned_le16(&(_p_)[4]) & GENMASK(8, 5)) >> 5) +#define UCSI_CONSTAT_VOLTAGE_READING(_p_) \ + ((get_unaligned_le32(&(_p_)[5]) & GENMASK(16, 1)) >> 1) } __packed; /* -------------------------------------------------------------------------- */ From patchwork Fri Feb 9 22:37:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 199151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1170828dyd; Fri, 9 Feb 2024 14:39:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU30ZTgKO3cJoQlvFiIn3m7JttT+bqEU0Fxvhr5fan/nTcK2U94CIpZy4Vj+D5TDPRNBZ5MZQXYumNbGRoPLlkByZEqSg== X-Google-Smtp-Source: AGHT+IFkrKOSV9zRv7XXvwui+YqE5ptlfgLGhM/y4gBcAVAW8vV4+L9kV/KfOvsCKClf5D1B08nR X-Received: by 2002:a05:620a:134d:b0:785:b87f:924 with SMTP id c13-20020a05620a134d00b00785b87f0924mr550861qkl.27.1707518396800; Fri, 09 Feb 2024 14:39:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707518396; cv=pass; d=google.com; s=arc-20160816; b=S/pqWK2apXA/N1wPctyNXXXkTNaM5TCcnHU8IybV2ld6da9E6J++h+3cb0RXqSf2ju lBxS/nLm4aCGTdj0rbQZDszLxCXiczvDrq1ZrcPVqwORf3CpgaZkyK79SP7ErQHcrCBW jd+bMmn8nilWQRUwcjmk4RzBWcGVGVCJxC7IyfKBUfVKQG7BtICdidszSpHj8uAlOw9w S0U6LIjOgPWAHbcjSgCqpw1nhEUfsUDgX8P3AzVR6+Cz3Iuax/JnAAwZJlwLaO9aeh9k pE033Ywwd0B467G2PyYg6rkXUc0u0gIbME7kdzQk9SMV5jPYQPI42mwVFhJsi1qAVyXK RmiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qBapnpxnnvVPFmrxNQOjLuxZFVASUjEQpu3IWq7x3K8=; fh=zCKM7tjRbbD/lPVLTFaIvGIY+C9H1GZ0ZkfSTvfYdPE=; b=JHRrAWcR+LGl7pkZDKAzF33ia+ETStiYDuBDc2RGzFAp+DTVrxCnwtik7o88k601Uf altXYR6SPio4mRhkdtsV+n2NY0cZq7JcKsUnIaqQiToicIvVaPRp535hgE/+LzljZjdD WpCFNUsOVObQPePWd6cMwNliR910vbMpY4pBmUah0WxB3NVshCBgEwTDUNGndFRmqbeF hiyGxks6Jwots/r/z3pbr/eraSwjveueHEIqJ339Iv8iTwFb/TvHttbMHK0m3Z6ox15j 1YIaWWFiDabGbqqgMWV6PaP533yhTvGAWfHW0jusLUpouAJsP5U7Skf8qfOTutQG0xj9 +FhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=inmdu0UY; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60124-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60124-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCUTzPFEqaaFnKhUyPKOvod8fPx8+ngwYfzq4VKr3NSEfaLtGawFIw+jqMG+aF7KddQ7lAIJTf+IQDjBAn95DtvFiWs+6A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dv16-20020a05620a1b9000b0078153cbf56fsi511951qkb.607.2024.02.09.14.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:39:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60124-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=inmdu0UY; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-60124-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60124-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 843B21C23501 for ; Fri, 9 Feb 2024 22:39:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 317B939FEB; Fri, 9 Feb 2024 22:38:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="inmdu0UY" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 60BB536AE3 for ; Fri, 9 Feb 2024 22:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707518310; cv=none; b=sQ4I35NA8MzW3cpZiw2MtjHP51W1cOqdwKqsa+0Q2cjVQGGkwNYpTJ7EZU2wSgG7j8wlN6+cOpMwcvpxv49YyxYozIMseTIfYfogmg0PfkqOdH11F4q+2PDTycvesthYInn50lfYll6VFXO/VaOclhS6Hz7inBti4jPh982aHH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707518310; c=relaxed/simple; bh=DzKLDci93ApF7vfkyDoGWiESzva00+zLX2rytI+hW08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XQY530bgw9+9shpDsFvLtmln/+WLOP3F2R9a2/v7MZ+Nv4a7HoiN7fEM6W77T59L+A89LDeOCqJeU/eg4A5OHX6KTvk++Mmz8MVDeHEek6UzJxv/B251TVp9WpJxRKRD71ty87VRGK3loYF2M57OvCck8M3YDFesSesqsUPnRTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=inmdu0UY; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e08c16715fso686961b3a.0 for ; Fri, 09 Feb 2024 14:38:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707518308; x=1708123108; darn=vger.kernel.org; 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=qBapnpxnnvVPFmrxNQOjLuxZFVASUjEQpu3IWq7x3K8=; b=inmdu0UYc2xhgSdtkb+SZ4gGIjT19U9GfZe4aplGwj39RljB4+Bau45a+cKvAkPsoZ dtDGJllBU6i+Fm2EdH8V3Y2n3L1rbX1IqtZ2Y4l8oFL/vJvEd9hTg50ee9kmdA7BpP/L Crya4Mt/pVUrFmjwNoxHopv3mFy6q0QdEQ1Kk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707518308; x=1708123108; 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=qBapnpxnnvVPFmrxNQOjLuxZFVASUjEQpu3IWq7x3K8=; b=pFhqTVCdg8ksoNj/Fj3Fg4YskANoA4/IdAAzeOQsO9OYEwo6cujTi8A8rDVurLEG4d P/1ySXu4fAgnaEzs+J8IXZ2mlOuhocHp/BDbHaTzh4izF+Wy+nRNKkiuPEpufzjhDcQh wa6hF4wI7kQ2IGcLfXEyNDssLmKgM3Hl8hRUh2EoUNAOYl/0tzEvgJKS2quGuKy2Gomq C/95tHlrgeY1civPi8+QX2IDvAS5xjGbzgM7LBlt18U4W9cvqDVvh4oHwRIpQi3JC4Hs AOt9XdJTF6PP9CtvROsCDDhomPmxsTcQWnXvnY1oHkIovvtxJZ9JkyO40sFIElKbAZKB b5EA== X-Forwarded-Encrypted: i=1; AJvYcCWZlZFpQYvbo9xnpo6DZMtoMP8KPCJxMHKc9kvjSqBnqTzTlm5YANF9sBiWsoqjOF0ktp0vfyecBMq4JqSmuI5ZByWLPO9fyj89Hl53 X-Gm-Message-State: AOJu0Yxwo1PXvN5RdsmO5o30qX8YZlK0Rhci2IINM8EM26XL8gVL6NNh SglcFAhKZQEVPqWxut3w3VynnyvNB1y7u7Z3cxz3q+e4s/bi4f1POetqIPocYQ== X-Received: by 2002:a05:6a00:26ec:b0:6e0:4697:a8f1 with SMTP id p44-20020a056a0026ec00b006e04697a8f1mr712031pfw.11.1707518308710; Fri, 09 Feb 2024 14:38:28 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVp9Dz1zelnFPdV/3pwulYB9UFPGcc96Gc4BNeYpmdH5uHNF11FIH76+41mlIstjpF26M0Kpx//LQPmVs+9d2RXfydqmdpVJOTPTqwsIuMcrlur6AMbmbEUubjEozx/1VfPV6VnTTO57vCdqjkGtbYQFYYodVPE1SX3PeivEsb5dQ5e8ABs7ILsvNw/Aluql5hKw/3f3aWDGdVAF2VIWgvrdHDA0rzOymduuRtBvPqTFt4gCv4puP1SiFsNjz2qwFIZpTQ8vN9BZULIv6G0C7nVW/B9vhdlWYmhLmyh87YhE1qaZzFLxdHu/OjaSapHaad1Gf70nLofL8tZVZHNac08uMglP2N41eHlVfeGfTroRA2Lh+3DpF8uE1g7eyuLm024wXU+0g== Received: from localhost (209.148.168.34.bc.googleusercontent.com. [34.168.148.209]) by smtp.gmail.com with UTF8SMTPSA id z3-20020a62d103000000b006e03a64000esm1092546pfg.150.2024.02.09.14.38.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 14:38:28 -0800 (PST) From: Abhishek Pandit-Subedi To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: pmalani@chromium.org, jthies@google.com, Abhishek Pandit-Subedi , "Christian A. Ehrhardt" , Fabrice Gasnier , Greg Kroah-Hartman , Hans de Goede , Neil Armstrong , Saranya Gopal , linux-kernel@vger.kernel.org Subject: [PATCH v5 3/3] usb: typec: ucsi: Get PD revision for partner Date: Fri, 9 Feb 2024 14:37:32 -0800 Message-ID: <20240209143723.v5.3.Idf7d373c3cbb54058403cb951d644f1f09973d15@changeid> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240209223824.622869-1-abhishekpandit@chromium.org> References: <20240209223824.622869-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790462810499519990 X-GMAIL-MSGID: 1790462810499519990 PD major revision for the port partner is described in GET_CONNECTOR_CAPABILITY and is only valid on UCSI 2.0 and newer. Update the pd_revision on the partner if the UCSI version is 2.0 or newer. Reviewed-by: Heikki Krogerus Reviewed-by: Prashant Malani Signed-off-by: Abhishek Pandit-Subedi --- $ cat /sys/class/typec/port2-partner/usb_power_delivery_revision 3.0 (no changes since v4) Changes in v4: - Replace IS_MIN_VERSION macro and just compare version directly. Changes in v2: - Formatting changes and update macro to use brackets. - Fix incorrect guard condition when checking connector capability. drivers/usb/typec/ucsi/ucsi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 7c5cecdd93d6..ae105383e69e 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -782,6 +782,7 @@ static int ucsi_register_partner(struct ucsi_connector *con) } 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); partner = typec_register_partner(con->port, &desc); if (IS_ERR(partner)) { @@ -856,6 +857,27 @@ static void ucsi_partner_change(struct ucsi_connector *con) con->num, u_role); } +static int ucsi_check_connector_capability(struct ucsi_connector *con) +{ + u64 command; + int ret; + + if (!con->partner || con->ucsi->version < UCSI_VERSION_2_0) + return 0; + + command = UCSI_GET_CONNECTOR_CAPABILITY | UCSI_CONNECTOR_NUMBER(con->num); + ret = ucsi_send_command(con->ucsi, command, &con->cap, sizeof(con->cap)); + if (ret < 0) { + dev_err(con->ucsi->dev, "GET_CONNECTOR_CAPABILITY failed (%d)\n", ret); + return ret; + } + + typec_partner_set_pd_revision(con->partner, + UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags)); + + return ret; +} + static int ucsi_check_connection(struct ucsi_connector *con) { u8 prev_flags = con->status.flags; @@ -925,6 +947,7 @@ static void ucsi_handle_connector_change(struct work_struct *work) if (con->status.flags & UCSI_CONSTAT_CONNECTED) { ucsi_register_partner(con); ucsi_partner_task(con, ucsi_check_connection, 1, HZ); + ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == UCSI_CONSTAT_PWR_OPMODE_PD)