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: 13550885 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (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 8E7D857315 for ; Fri, 9 Feb 2024 06:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707458748; cv=none; b=qHvhZzRGyyQhyjwRyrBBDtjM2JC3QEuqi3i/ngUJ6LClm3yN4h9LvcZ+ZaEqH8czgH7G+/or70bPsqKjHm5Zqviy+B9H65dOubvKPfLnX3hH0VpTz8V9dJuJuLmdHRV+t9PT56q+tkP5behLbDeIXstHtVv1O4zI4A2+YigJ6D4= 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.52 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AmuTqN5i" Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-59a8b9b327aso235559eaf.2 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=GcsPGCgeQHiSBcITZ4RZlLYUVzQO5aFgioPoLwR6XzqafK0BnlF9Y3w8wICCnqSTpM zIxz9GjD9TPYe/UW1jAoSUl4xZ7LXp9zXEcbReip/GcnOaakqVMaGMT5hul2mnU67tvi t5RngV0AP7VzBu9DVsxyYqww80NhvFdDU9YRzohtt6+mMvXNbS3iXHGyocK/d3gT4hTV Ut7beTxKaw4nLZywOBi5dPRZ9ofJK9HtJn9Dq2/cgwW7LdNdBiqq9K79+Cv+PAfSGScA z5JzteqbpaEvvvGudHpQUHfaQgkzuHsa9IEH/ncISRdBQuqQfz1Mt8WtwX+ON6f7GNbr 6DQQ== X-Gm-Message-State: AOJu0YyU6NpubCs6u76an904wleuvUqvoOAzHSYZUdA8x4+01Vb/QAL7 YNdqRuieZpASkgxcuT/esOcAqQhesl4aJQNwyDGZu0VmB8iKcSXZcc2+zY+cFQ== X-Google-Smtp-Source: AGHT+IF5CxCAWG/VNUGG1iIqxZegtuuT7f9cQSMghIVVa/CJhs4425T6h5CS/gS9J4mn1A8U87CbXw== 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-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; /* -------------------------------------------------------------------------- */