From patchwork Fri Feb 9 06:02:38 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: 198754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp655976dyd; Thu, 8 Feb 2024 22:06:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRx6QnO0WyU7nQ/ThqaOg7u8Hn/L+ClCHXazfr2KPxJq6hGKGmrBYy71Iq+Lj9QXESq0rH X-Received: by 2002:aa7:d608:0:b0:560:4eb3:bd66 with SMTP id c8-20020aa7d608000000b005604eb3bd66mr548842edr.13.1707458807004; Thu, 08 Feb 2024 22:06:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707458806; cv=pass; d=google.com; s=arc-20160816; b=z3G5D9Hh4UHypeDl506fbi4zJ2mK9r4fnPAQ2ZNpKM/9RmsAFLjGBK8tfnNcEwA9pn sKUbLLPQCQqSR2zFKJ7Anyw8c4z+cPfkpfInFp8qEeTzz7k30YZvJOLHi9ft1MC/x1E9 H/YqOhEqYKPTY3BZwZeXhOIBKS4krv0R18EmqYg77/71I04QKo5BUUxHxm1crdQBJKic SdjhPKjLx6OxSpm63OIayajkQxEc0udZ9uiG6XgJBey6PZUR/bjVloEpHyZJT3Ot4FFM OcQGDkh6HEJWWLHYOzJyLxEO24bWOkkZqaq+C9xp9Ws/Dr5kHeeoL0a2ZyEAYLVrG54W BAGA== 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=80VtU8v4yD1vE6SrhFnN3XZO/F8XU6EPJRSbswzy3Kk=; fh=WIce1J49UvbkOvIfZdKH/O62AxPIK1SjltqJF2YUuaA=; b=nf4Fs6HMcsr+qYJQRfey7cZiGVOI8ekA+N5Zszvj/kuv0ZBvDZ3rsFiP72ddg9C92o oY5/f0FTgFqlcg/nU687cMPK3MVlVrhJVLphvNQjXEK6X749nYcACiqhukbDO2QjhV/2 YXOoUayyflLbLO88p3QH4RfBxPCKOUpkvyoqyr24aF5t6eGUhNZl/BMacYD7+v/wop2B CGeuxFlOgjIEVECp0GbxZrLFCOUadx0tKdhGi0sivib1+KU7uvIjjazLxv99JGUGWOPA mfJ1hUS43Okptxp/Yrn7P5oolF0nF4bIHaI69n+XjNHtR1U7Nj7hC1bvqpZzq29hObXR iWXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=C2Q5HAcv; 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-59031-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59031-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCX3pTvhpU1/4I9lFZYYqUTtUyXoq5m2jSKtT1fwEjGrBcSdT5e4zCqjpUIuFgu7FmOWWof23OikNPNZ7nRX21QgA4gEww== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f21-20020a50ee95000000b00560bf669fc0si505944edr.90.2024.02.08.22.06.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 22:06:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59031-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=@chromium.org header.s=google header.b=C2Q5HAcv; 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-59031-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59031-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C6E931F21E32 for ; Fri, 9 Feb 2024 06:06:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C22558107; Fri, 9 Feb 2024 06:05:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="C2Q5HAcv" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 2739E57308 for ; Fri, 9 Feb 2024 06:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707458746; cv=none; b=kfPH8rScoqsiiEnhyiApl/xDEklTAYc7WvZdHWtUkI9u8HQ15bEacrFgjJ+5b9WlPxobgrmX1uTESBj8N8DGHRWhOCHfo7Gte7kFY+lj8t5YEn/lNCUgZ3hBFWvbmGVg4V98KLRA+6VIlHd3tP7sniZnZeqB9BFf4lG9OaBrvCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707458746; c=relaxed/simple; bh=noXh4QjalWPeIqmk88xgk+MT1Q1CPYJ7IGWY4FLlLYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jvlcFctCmRB4ZbHrvoopI2jQ5FzLrEoS2Gf5lOwnH1pVN8Wyhfpr6toA7mj9oHASSDRP9sDeScd83GRsg4IOhSN54d/vWahJ09QlYIsqDBe9+eMev48aMYa0PqtStzcO8ps+JqAjwXA2bS9/d1BkHs9s9UJi56aQt4bwnWAolbE= 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=C2Q5HAcv; arc=none smtp.client-ip=209.85.214.177 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-f177.google.com with SMTP id d9443c01a7336-1d94323d547so5456695ad.3 for ; Thu, 08 Feb 2024 22:05:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707458744; x=1708063544; 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=80VtU8v4yD1vE6SrhFnN3XZO/F8XU6EPJRSbswzy3Kk=; b=C2Q5HAcvO+drsh2r3n5w4p412q5Cq2KvvZpJIhOo9pLwt9YtmpT5l1istUsiq3WvZr icw6LPO0RXhxyNesgOw1qDD85wqJbdrOI8P5ehJl2L/o2pV9ZMJSV8DDVzM9OYS4cF1h /A1/3rEzEJtrlg9r4kIqfMTbqXVk46l2tVB1E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707458744; x=1708063544; 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=80VtU8v4yD1vE6SrhFnN3XZO/F8XU6EPJRSbswzy3Kk=; b=LZhcr5SLV5ftKpqdYfRCJNRHeR5mYpQVDHIhGgQzVP0dVsRKg2Xf84UEg/qBhIWGT/ gC5951ca/w7rPV6EDv4g2g/B85B6GrSEvYEAwd9PgBOFrh+JfYKnCljjmSEmYVyK0ReW ZB5sd4YqWKbe9mg2IVwm9TxRXX6tj+pZG/N3jMFBRmTF4osgTdphMkM/QVACEHEC2Iud rsTxEMMz6UWyC6jo6dDyx+SVAefqb1/tKbNL3dNMUvLhKAposxpgarLwcpwUKkNaHUN/ R7xQ5MFVXIdqPmXDYyIBpLBIjOpxJ3BUh5Ya7ZLADoEgwyIO9y6Id1D6cxwHNQYx/wxf A2TQ== X-Gm-Message-State: AOJu0YxPcjpvH2ZJTBe6KcPcuSBqFjd4hqESW9JR+aoyeBhHKSLSlute sBvokjgmd83bL0IdRFWAxC/5fcEw7g6YZ8ze8JRzC6y3aXzumN7WX7W3KsoOZQ== X-Received: by 2002:a17:902:650e:b0:1d9:c876:b840 with SMTP id b14-20020a170902650e00b001d9c876b840mr615798plk.2.1707458744421; Thu, 08 Feb 2024 22:05:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWJsf3/BOHYsZ6Prh92L/Pt4yIQ338yOw2jB/FbNQKuPUywOFmyJJ4l3t6jRfQsssyox52TwNvuId11bgMbW25wEgRNmM0QZb1DHuv3OFC0anJjfRs6YcrJin6lGf3Wkg0XiU6fP90ywaBmzsQa/bDP3UrkS6cqk0yLNriWjaoT0s1VWEAC5NmNg4GUnwh+cYYhS5VR3Vdaqjq1MJBWU5sxQKADhgCz7Fq4FVHaUEpG4qScqVD9iOZZTh7Pu3sTzbnpJn29ekKla2zpcUEatZxt9Q+ZF5ublL3tnAibbuMvQWOvXg1t0p6OU+K5o3c5K4NoEK0eIgCTESGg8iPVl8xFUVIwFa+ugSF+P5FUsPeFptk5LNDdVtVBqL9qsRXw9iJ8BDp+ihrI4E8Jo3lUZkqUTN47Ns37fiolQkKa06D5e7gyK6H4oT0bFJ/ml8Ed13m/Hd6lGCVbuGSoNer4JFyQFcrro/4bxjOU0ZJbDhUld9vueQfGR5oBZw== Received: from localhost (209.148.168.34.bc.googleusercontent.com. [34.168.148.209]) by smtp.gmail.com with UTF8SMTPSA id kd5-20020a17090313c500b001d8ffe741basm753922plb.36.2024.02.08.22.05.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Feb 2024 22:05:44 -0800 (PST) From: Abhishek Pandit-Subedi To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Neil Armstrong , Andy Shevchenko , Dmitry Baryshkov , Fabrice Gasnier , Greg Kroah-Hartman , Hans de Goede , Rajaram Regupathy , Saranya Gopal , linux-kernel@vger.kernel.org Subject: [PATCH v4 1/3] usb: typec: ucsi: Limit read size on v1.2 Date: Thu, 8 Feb 2024 22:02:38 -0800 Message-ID: <20240208220230.v4.1.Iacf5570a66b82b73ef03daa6557e2fc0db10266a@changeid> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240209060353.6613-1-abhishekpandit@chromium.org> References: <20240209060353.6613-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: 1790400325910247708 X-GMAIL-MSGID: 1790400325910247708 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 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..d9a345ec62c3 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 = min_t(size_t, 16, buf_size); + + 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 06:02:39 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: 198755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp656038dyd; Thu, 8 Feb 2024 22:06:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXxoWlzzEwyI/lyiQks9qpq/2oid3AhwYYNRaQvp3w/2m78Nu8T6LC7BPKnAATEDL3F7ai X-Received: by 2002:a05:6870:718a:b0:219:2de5:5217 with SMTP id d10-20020a056870718a00b002192de55217mr790367oah.35.1707458816134; Thu, 08 Feb 2024 22:06:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707458816; cv=pass; d=google.com; s=arc-20160816; b=FIJKnxngzdUuiuyIj1gTB0RndkrN4fnerMcWsTtWgBouFV3Tah1UjNOSpF4XWs1anb jGzhVWyYExNwF4fj1L0Cb0UZep/Dd/QF09ci4vNODF9AG0JpEIGFTJP/AdVhBUICUqWw 52JKEdHeOEQpFXZpwFCpkpkjytdktT2r24jY8iKULBR0WqnTeU1mL6wceZ+vHB7vEGzK MmjtIw5ac1WnDYPBpG08dxvzHVJHOEFbCA+vsiUuWZY715Np9jIpcaENBpplUZptJHDs LQgb/CqVt1mAiw0hF5sz06/MTO+h/UldsV810vDTcmVlQ7o9nLtY+3hVKJnxAd08VxJX J8DQ== 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=NXa++egn1I8A9aejMkYJFqgX4tfheQa1aOxxLsKxQ0w=; fh=SqeXE7TBh4pKdO2wEbZeyz3t5c1culVy2+kW1gbwvDA=; b=K/ErjFzzu1+GDvlemmcMrHYqgz20nTqjWx8JXe4GUT0rhmRqo6KzDPJz8XRBPEEmCI EWShpBlcLpPtGmGBdiW9hznl6X0clHUUPl9j9b/aPL95sc9b6Tr1LhppIQvei7r16uuO OrmVqTLvSg78bTAjIAj34ZWsKLOSlL8fF+Zd0kcMuAnQ19zxlcVZXtWVMFhT2aLx0g57 a7uZB95WzQvOwFwgCffBXonbYIEoqY5Qc1sAlJ265ba1cakrVnyUSouV3xmbHmTr/MSg 4W4YLln5i+XTMwcW/wVHYUqvs0+95Tuc/qEwwYVteaVhM+FOdKwSuL6m76MDOsz4SRR+ JVQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AmuTqN5i; 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-59033-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59033-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCXBesuj4GUUrAlPRV+AVECm/wbF0lFbdg3fdprepk04OdmA31JMU+RCTTCcqIFVmwZ106aJO0xdfsGWtm+EItMJS68hfA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m23-20020a637117000000b005d8e12c85d9si1134994pgc.738.2024.02.08.22.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 22:06:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59033-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AmuTqN5i; 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-59033-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59033-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D6F2B2887A4 for ; Fri, 9 Feb 2024 06:06:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC40057308; Fri, 9 Feb 2024 06:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AmuTqN5i" Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 A020457301 for ; Fri, 9 Feb 2024 06:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707458748; cv=none; b=C+AVRDxR0lKODyfxPP64ND6fR1VenyGE0GjAT4aBs1C+6LKuj7W7BZmC4OpPgOPaEwEZZbCvqxNlGaBOqjrvyy7tpA3ajxMlBem84GoIUg4erQTqGkIMjt0beVMRGFdYFH1OPfu4XwdtjhtlUg2Fzd/9SA1TG/+jULHvYzib47U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707458748; c=relaxed/simple; bh=v/nT8b1jYweKH7pv1wyqHS1aqwvFWTRrfh3SnZ5y8ZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SUY/lYe4AHung7OSalo+ABbdFag4vU2xs5jalz5HYvBwfqzqIAjNOpSVXL1iwHAm0NXDOxFXRqQ0OEq+RTIKqESC+z6pA1dytSTW7MjaZp+tBBA9/q3MggMmum/6L9CB5HSyJjAStVdKr2ab1JaRigX55J9ZbxKLeWgvo4IgW/k= 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=AmuTqN5i; arc=none smtp.client-ip=209.85.161.42 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-oo1-f42.google.com with SMTP id 006d021491bc7-59a99ef8c7fso179694eaf.0 for ; Thu, 08 Feb 2024 22:05:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707458745; x=1708063545; 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=NXa++egn1I8A9aejMkYJFqgX4tfheQa1aOxxLsKxQ0w=; b=AmuTqN5im7fkdVxgg2FgKZqXluRiSzWNgJRiNTIP7ZErMbBri+jjf7LBy2sNPLvH1j BoNQ6LGzBYZif8qqOLcHy0IxGCiBR02VTlhoBJODbgimJpNUd61B05DxXm62zkIR11l1 qQQLvV2Wn89j1Kaa0NY39AX3tls45t5w/hDZ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707458745; x=1708063545; 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=NXa++egn1I8A9aejMkYJFqgX4tfheQa1aOxxLsKxQ0w=; b=oBnt2ROPZmIklVusBqelSuHK7zM2YBTIpkZKUHQkp3HeHMdyKXSb+Pi1GynaGGHawu ++jEB0ZIggG4kvREMXBSgZrBACoznyNHoR5PqMsgRX1GZjpn2c09K8D4vzpOzDHHZNFE 98JJEvjqXE4cNpEbxBFsaQnC0bsDxl/Rn3UnKhYDUXKDs2WHeG+eSoKxUhfuYeLzdOO2 s4M81r3bSOTgG7myBaJEoG7s0VdtiovWi7pZmEnfZdpq+lBwgwOwVVgY7U2oGJs6HvzG 45VMLIKAc2+dYYL3cRF2c63EGy5+xkRRH0yrpjYRaNsT2gHtbtdN7qOOUXfhG32VLpN4 SZJQ== X-Gm-Message-State: AOJu0YxUyIB9zWg+b64KQ5x8dk1M4XEiX1BesAd2xD8BDJUqJGG+CCud yyPL6IZ2qGosncBoUhYuvyA8XPnz1KV9AAx9UPXU5bfnuLBhioCAvTfY8cbP+A== X-Received: by 2002:a05:6359:459f:b0:178:70f0:5a47 with SMTP id no31-20020a056359459f00b0017870f05a47mr595965rwb.2.1707458745538; Thu, 08 Feb 2024 22:05:45 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVcoxGYvdJdvOyr87l1IP50EKua3vOXqvYubDDDK/JcY/bGNDfu97x+B1NZ18UL7ruOYfTYjHIzjJ6keroBgdNBAWMSTfH1CD2qXxSulaW4i/zCFDubLqSuuU/D6KWmuQL5q1Pf+dMwAgr20ZCVXmo4NvmBw6FZUGA1FeSpJVo4mQB8Ksat/Mf3AomJwcASKjoatcnZhU6cxXLaK8j7uY+rpoPFwx7OcduA2xH01K1J0HFz1dQhYuWkoQr81UTZGHHyEWFqr2V96fwZDUQotLoGyi1TOXiXcfzihh4ADYS55glOvdn1rc6JpqsLyfaz7XO0jj/kZOnew7wIpNelZ2RkrB6oXYuMCA== Received: from localhost (209.148.168.34.bc.googleusercontent.com. [34.168.148.209]) by smtp.gmail.com with UTF8SMTPSA id v14-20020aa7850e000000b006ddb83e5e47sm827281pfn.90.2024.02.08.22.05.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Feb 2024 22:05:45 -0800 (PST) From: Abhishek Pandit-Subedi To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Dmitry Baryshkov , Greg Kroah-Hartman , Neil Armstrong , Saranya Gopal , linux-kernel@vger.kernel.org Subject: [PATCH v4 2/3] usb: typec: ucsi: Update connector cap and status Date: Thu, 8 Feb 2024 22:02:39 -0800 Message-ID: <20240208220230.v4.2.I3d909e3c9a200621e3034686f068a3307945fd87@changeid> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240209060353.6613-1-abhishekpandit@chromium.org> References: <20240209060353.6613-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: 1790400335688268429 X-GMAIL-MSGID: 1790400335688268429 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 --- 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 06:02:40 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: 198756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp656058dyd; Thu, 8 Feb 2024 22:06:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgzFrGAuWYzGAJYRiFtCM7kwEcjJg1wjqRL5DXUqSDm7KNvSI+ORFvat01oA+IgED4Rx1K X-Received: by 2002:a05:6512:716:b0:511:2e97:add2 with SMTP id b22-20020a056512071600b005112e97add2mr278322lfs.66.1707458818267; Thu, 08 Feb 2024 22:06:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707458818; cv=pass; d=google.com; s=arc-20160816; b=jqpJZ4h1iK6EigHfbV3hMPGzpQJkXR6rqr71ajkpjQ6Pp1hTrX0hre9iGvvyGb3+VL Mo4nCaO3fSpOzmzqqNOfoYcG/Lt3T2cAkPbWqhKh9tKysIIkDZO+XlpoJ9fuSz7UTT5+ aJnSaMZnwrOXiBCKjIU7wWdaWf/UpQFxVS8wf/4mqqhF+D3l/t2yaNvC5LBUYe4uQFtX Ah+/RrJOGhLdbV2dz6waU3aZ8vHq+G/Y6efHCpCkFhaN7e8gW4iCkYtWypRA9OYg1O1l dLanbCcaRNhriM+nlJD5jLJ0Te65b4yufTh6evhs0wKCJg3doeQ0Ktl8wng4lU8K7bfs Tomw== 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=kU3WAfQM9Sfnlpso5o0A7y5vYgNomm9R2kIzE533//Q=; fh=YqVXynzDZMKhb67ekrLT3rzWN3ZN0vdo/skLgaMAEIo=; b=fCJCeMLo6TLNUGDWeHmCLZi7G5Nwby4jMo+6Kml09bPZBOa8G1lgcaK9PkeimauK+Z hsQSCMHCH7hN3Rp0mGjobnKqCGyQGY9bY8dXsY0QsoGSK849eFQH4r2jqRlGpcO99h5X ljz/J4R6Z33aXK4LnpQJhxvtr3FAXV9wTi8ni7r9g3eBdQJaBadJr4+ROzygj6OcUyz6 PPdw/mpuOgHVxBcwENqn82mhRz5iA3rkGZX+xfUYl7zj/Z2NcymtHzrg/l30K5y6B6EQ DZZpKVFlxLyonCvyF/1CD6k4wMBkJ10eNaViCBjbfI655KWbqxatbFnXtXI4pG+3NCqs l4SA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Pt5FX2BL; 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-59034-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59034-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCXMenLHnGVIErwR7vMehzvFysBsA19VSAVyvUfFnzSwJ3ypMzOH/UOq1kG2vSuzwBgPB+DQcvaX2L9BNxTP1gOr1uy0Qw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c19-20020a170906341300b00a3692a5f9bcsi462474ejb.665.2024.02.08.22.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 22:06:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59034-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=@chromium.org header.s=google header.b=Pt5FX2BL; 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-59034-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59034-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B0E961F21CFE for ; Fri, 9 Feb 2024 06:06:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 034CE57310; Fri, 9 Feb 2024 06:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Pt5FX2BL" Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 62CC95732C for ; Fri, 9 Feb 2024 06:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707458748; cv=none; b=eRxaVqGjZjjJVH81eWS45ZnIeqZn3NoJCjmBNlJDshnGTvPk3JuQwq2yqf3Rzpb1JxXKHrTITWJafxzwA53uu0xVsN5e4WK26aGWMc/H/87iMYRuq0aAF+Z9/ruoRGXMo7qru/vrX1az2yyjgDuMb1TImBzkuXHby1Kd4bLpSWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707458748; c=relaxed/simple; bh=CT/55tN9O9NYhHK5DTcn9HOMKpKvx8iNl9/zVWpYct8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CPen20hEskz+plmli9ZA1u4WoLv/RPcYzI+10mU8B6vmlk4wzHNz5hBpPvLNmLo7UB3UCaAMbxo0xpBUB90TCyu3c+GUbch+STjAQIip50xkBUeSA3G8CLcN3975l8bZ/DWXsHHRvOyKdp3hWgAoTHMvGPDFI7Y8N5F6ieIPenY= 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=Pt5FX2BL; arc=none smtp.client-ip=209.85.166.49 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-io1-f49.google.com with SMTP id ca18e2360f4ac-7bff28b2937so21094839f.1 for ; Thu, 08 Feb 2024 22:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707458746; x=1708063546; 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=kU3WAfQM9Sfnlpso5o0A7y5vYgNomm9R2kIzE533//Q=; b=Pt5FX2BL+WdT+X/S1BzX+Drg3p8s3dmM+ARVTt3WafDvhefJD/0m0dLoOyfu1C/JGj L4ISxaDGt2q5WMP3Df+s7DdGMBD1m5d/KIJ+zAD3tKhFapAuepy8CSJtPPDbGnibGnax v4KPN8HuiQzcDj603YFbt89PStwygTEqoccJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707458746; x=1708063546; 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=kU3WAfQM9Sfnlpso5o0A7y5vYgNomm9R2kIzE533//Q=; b=Qqt/5FKUHYxbqk+Catiq5cYM25o1gdwV6Nscgli/HZpqKFRZJel3bH7vvTCJta3D6H H8bcfsBXr+hPhqpZSrgJSKtpDyxzktn3f5J2aAgOoTgn96W5rjZSA1eN//mZLMXGUUB8 Kp7wG3cWdtBynBWJkHy2wvM1TPZGn1PdesQW3cy8IrXlN/TNtBOwQFuMOk1DuxQKusji OANNEZpT8dYCZYA4gxsQnFJOHEuP5iXw6fg2HslpaVPapR9bhuEwF5PURIW7rKFWgj+D hfoDOtmWuPPcAmR9oB9qlUOuIM+2VRsSaL53e2w0PCa4dQoWq16NT4raIo9c9W0W98VE Uw0A== X-Gm-Message-State: AOJu0YxQUbMwycZ1XVzjL+PtbI99ewVvClwN70EMjmdViAxgduwLQER1 WBzrocHTwxEWod/aIatlqoNincoCf85EvjBRUKlUk2l/xCNHbsWLIgeZckXxDA== X-Received: by 2002:a92:cd4c:0:b0:363:ad01:f052 with SMTP id v12-20020a92cd4c000000b00363ad01f052mr896942ilq.24.1707458746569; Thu, 08 Feb 2024 22:05:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWaphZWR2HcRx/d5LRSMw8Ym1cUB+1VtpM/wc17o8hWhUpKC65d6RP5tTdJBwapePscSe+m58FHz4Grp/YuVpQx9LXvn6l7xULE3VtoUJx5SHhC4aX6qb3fhQjmlF7GHfzH0HRMQReywu3u5Jdlcb7oXpkn74YV0JQRfp+/IvlHJ3O6VpoKiTwbT7a9Dh3MHR24KDKA9DkcuLXns12hqJlfGeIsxWQsGD0V4GI5aKf+wMH+A7eYJzPt4LYsFZ5w8OeT9w7WWBMumkaPtggo2xRiphVUOXfKejlNKVU5PkR4N2y1RMZZjRjxTYKLZc4acYiusezGw/3PeSkk0aoWs3U/W+BjbAkzxmP1gc39LY+Jgur1QJNHevBCXNjxanTYQzLOr6WKMG65NVY7COa7Cfw5fvy/k1U= Received: from localhost (209.148.168.34.bc.googleusercontent.com. [34.168.148.209]) by smtp.gmail.com with UTF8SMTPSA id cf11-20020a056a02084b00b005dc26144d96sm753263pgb.75.2024.02.08.22.05.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Feb 2024 22:05:46 -0800 (PST) From: Abhishek Pandit-Subedi To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Fabrice Gasnier , Greg Kroah-Hartman , Hans de Goede , Neil Armstrong , Prashanth K , Saranya Gopal , linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] usb: typec: ucsi: Get PD revision for partner Date: Thu, 8 Feb 2024 22:02:40 -0800 Message-ID: <20240208220230.v4.3.Idf7d373c3cbb54058403cb951d644f1f09973d15@changeid> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240209060353.6613-1-abhishekpandit@chromium.org> References: <20240209060353.6613-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: 1790400337940877287 X-GMAIL-MSGID: 1790400337940877287 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 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 d9a345ec62c3..9d49dbeee9d5 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)