From nobody Wed Dec 17 21:27:10 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 57A23218EA8 for ; Tue, 7 Oct 2025 00:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795222; cv=none; b=tFDQFNNsOHc0IW4hNJj9xg2NnrBtxcq43hNdR5Bbpnj0F2Y0RhACpeYUiF6el/COARW264+ZIJPkVaC7qUF6a8C3GmuX8z6MaDcr6q4eIMZT1QgHIthzPBEu/RZ15BZEe5znHolwD6kdKBz7kGpRgxdC8tOVGS7EtxJoCaaN0Nc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795222; c=relaxed/simple; bh=Str9fH8hydrNHWjtKguZVPS+zITiFbgB/SOHaQ7ym60=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nHeZk0UDfj88ysFwiv8YmHw6HhkL5sAI/z8kgIP78E72KrstbB/vKdCG8IZMVGv2Rny7B5ycjsqo5Btsjt5Ah19eyd2MmBAtBAfCz6QeUTEFw4xmO7dffcwcWLJKqkjsxujv9Te7oDdP10OCNHB419zVR+5HiIjeJB+vSemEj50= 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=eUI/xleg; arc=none smtp.client-ip=209.85.214.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eUI/xleg" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-28c58e009d1so94609245ad.3 for ; Mon, 06 Oct 2025 17:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759795220; x=1760400020; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=n/Ntr7wFteVMdK8qe86TO1gtoCOtxfr/CBl4A1p6Hm4=; b=eUI/xlegB2JXM9JWFGmDeRla2Ixt/2WrSKCQOBblp3R0vf8vPV3giV2NFSk3w+1a+F lVRurb8rlAc5/xkzHYfCPoqtq1xkUK/0Ex+PPhYDa+reSSL7OfBLWHLyP9mLOeLFeggm Np6Yj1smpoA1cxTU8HQ90lrzQddbVIZHuGdt7ReFZFpPr+NZk0rwON44IUpy8xcjJInH AwQQgtn4JsLP6jkz61aIp6GjU5X5BjAlRIX+ySuTqRC/HuNsehqKkxBnUoAYjxxrylZX Zhd6kq5EWzTwEJhhPWWP80yS3RU47roWkbEkInrRgtE/W2xo0JYpoWJq2aOLViemiRp6 ZLDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759795220; x=1760400020; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n/Ntr7wFteVMdK8qe86TO1gtoCOtxfr/CBl4A1p6Hm4=; b=g5lMoRJGcuOAu+Eiwy+GgDKqU6FO/JXWFg4Fvn+VsmGnR8jYRYWbKhJmqGo0nsk318 9eGQYLtKAPtSFNtLaSVHTgQqWRfEoepj1dZTrVb7bniLpAoQvt09Isg4KGZYXWKWkLQg OwvYwqkA4SWshOu7JD9E27mAXa3SdjcXLOumMaklSMmh50rfQc6Nlsu98+gvXrBntGeX bvL0jBAm23QLCMpqv0iecBgs6N4EfMz+wn/IcjVrbJu6A6PF3hoB64/lshTsIxb8+RJ5 rqRrGx/xq4gAvLt3lPWkREDoJ6S75fFiq5B9h6I2gY79MagEYA1OPrbca+r7wdN22S+x 4MLw== X-Forwarded-Encrypted: i=1; AJvYcCXlYb34SpHUDTLjNHX/ZcF0dSJ2KVWCMYxR5DvGbgvx4TRtH1bzZdGdjupKP6OTRhvo2+PTXsFu34O/G3E=@vger.kernel.org X-Gm-Message-State: AOJu0YwWWiCVNYA62zZgv7aC17lWIlrzzF+Tl9pUu56hyTxySFxQAv45 J2RxuLA2IM2ZQn/4F538WvENYY0rgAK043QSRdmRtQtRkwX6rqSjljV73l4uK2Pp1Kz9smCT+WW L8nqc5Q== X-Google-Smtp-Source: AGHT+IGtj1LUUjLYbsIMAV2GwYOXjjJ8onhXCjB5EWGPd6ipgp/twyTqetktTXVYLm7pESak4E3PvR4IS0U= X-Received: from plcs4.prod.google.com ([2002:a17:903:30c4:b0:28e:cc8d:f602]) (user=jthies job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1b63:b0:281:613:844b with SMTP id d9443c01a7336-28e9a6b1988mr189582965ad.52.1759795219487; Mon, 06 Oct 2025 17:00:19 -0700 (PDT) Date: Tue, 7 Oct 2025 00:00:02 +0000 In-Reply-To: <20251007000007.3724229-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251007000007.3724229-1-jthies@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251007000007.3724229-2-jthies@google.com> Subject: [PATCH 1/6] usb: typec: ucsi: psy: Add power supply status From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jthies@google.com, dmitry.baryshkov@oss.qualcomm.com, bleung@chromium.org, gregkh@linuxfoundation.org, akuchynski@chromium.org, abhishekpandit@chromium.org, sebastian.reichel@collabora.com, linux-pm@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for power supply status. If a port is acting as a sink with the sink path enabled, report it is charging. If a port is source, report it is discharging. If there is no connection or the port hasn't enabled the sink path, report not charging. Signed-off-by: Jameson Thies Reviewed-by: Heikki Krogerus --- drivers/usb/typec/ucsi/psy.c | 26 ++++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index 62a9d68bb66d..2b0225821502 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -29,6 +29,7 @@ static enum power_supply_property ucsi_psy_props[] =3D { POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_SCOPE, + POWER_SUPPLY_PROP_STATUS, }; =20 static int ucsi_psy_get_scope(struct ucsi_connector *con, @@ -51,6 +52,29 @@ static int ucsi_psy_get_scope(struct ucsi_connector *con, return 0; } =20 +static int ucsi_psy_get_status(struct ucsi_connector *con, + union power_supply_propval *val) +{ + bool is_sink =3D UCSI_CONSTAT(con, PWR_DIR) =3D=3D TYPEC_SINK; + bool sink_path_enabled =3D true; + + val->intval =3D POWER_SUPPLY_STATUS_NOT_CHARGING; + + if (con->ucsi->version >=3D UCSI_VERSION_2_0) + sink_path_enabled =3D + UCSI_CONSTAT(con, SINK_PATH_STATUS_V2_0) =3D=3D + UCSI_CONSTAT_SINK_PATH_ENABLED; + + if (UCSI_CONSTAT(con, CONNECTED)) { + if (is_sink && sink_path_enabled) + val->intval =3D POWER_SUPPLY_STATUS_CHARGING; + else if (!is_sink) + val->intval =3D POWER_SUPPLY_STATUS_DISCHARGING; + } + + return 0; +} + static int ucsi_psy_get_online(struct ucsi_connector *con, union power_supply_propval *val) { @@ -245,6 +269,8 @@ static int ucsi_psy_get_prop(struct power_supply *psy, return ucsi_psy_get_current_now(con, val); case POWER_SUPPLY_PROP_SCOPE: return ucsi_psy_get_scope(con, val); + case POWER_SUPPLY_PROP_STATUS: + return ucsi_psy_get_status(con, val); default: return -EINVAL; } diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index e301d9012936..cce93af7461b 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -360,6 +360,9 @@ struct ucsi_cable_property { #define UCSI_CONSTAT_BC_SLOW_CHARGING 2 #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3 #define UCSI_CONSTAT_PD_VERSION_V1_2 UCSI_DECLARE_BITFIELD_V1_2(70, 16) +#define UCSI_CONSTAT_SINK_PATH_STATUS_V2_0 UCSI_DECLARE_BITFIELD_V2_0(87, = 1) +#define UCSI_CONSTAT_SINK_PATH_DISABLED 0 +#define UCSI_CONSTAT_SINK_PATH_ENABLED 1 #define UCSI_CONSTAT_PWR_READING_READY_V2_1 UCSI_DECLARE_BITFIELD_V2_1(89,= 1) #define UCSI_CONSTAT_CURRENT_SCALE_V2_1 UCSI_DECLARE_BITFIELD_V2_1(90, 3) #define UCSI_CONSTAT_PEAK_CURRENT_V2_1 UCSI_DECLARE_BITFIELD_V2_1(93, 16) --=20 2.51.0.618.g983fd99d29-goog From nobody Wed Dec 17 21:27:10 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 3A71F21765B for ; Tue, 7 Oct 2025 00:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795225; cv=none; b=AQ7ymQEH9Vo/kRZ+y4Dif5RlzGVHAO1gpuS5evTGLxyhKuyQC+967JuQ61efu72unHCQy2tHsGFV//Igz0JVSqDNGTebVOgph2kh/mZQiyMIHdrS77UarNPNg0aWZ8xUD2Vy2kgmBY0o0VnVYRPhJAyrwtD7LKq/sDvu3Mgu+kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795225; c=relaxed/simple; bh=McZ/Cz+3YMUncfglY4ZLNaseNHW944rk9LCxaUVXOoQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iMXMiA6LKXKfailSgT/CIGPzAeuCH5m9GKyFMME9Sp9TTLPuB2btdd37DM+yRS1qo3E3cd/npMVuE+FDBIg4EXh6Mt6gUzUjisJonPksbcG7p6qtGmDget/oKcGHb8t5w9N6z8FDzr+yJqTfgwMvvfzYmIblzieuClPQMiWoDcI= 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=tiEbFGw8; arc=none smtp.client-ip=209.85.216.73 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tiEbFGw8" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-339d5dbf58aso5528275a91.3 for ; Mon, 06 Oct 2025 17:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759795223; x=1760400023; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aX+L3x30EvRej5n6vrQ0kCgHgreWzDds4tYuLwFNAIQ=; b=tiEbFGw8jxGtb0582Md0VDdU6aN19MB4oK37nvt77RBTPSTQJB2JrAf/QNh40nyUzk MPjEPwyzR5+RHRJqi6ZVvf0ZfOuP834Jfw5Zh7EpeRHrFkt/ta6fmJTAWpslMf0RMg+G CEH87NjOiUQ/i6+OqOpRr68AEybw4YH1D1U14kaU2JqanjbemTuCdgq4wuq0S81POwUc 1BF/hgNr8uQrAljCwEdwLXPMSy5fnYlJ9aKpgS/XSGDUaBSKEL4m/d9A/4EEIeFbvhlG 8LCMVmD+CbmoBAgvTnpbuCc9Y8w3/r9xCNxDaHRDmgCwE2fP0xo1j7u7m8ukNFmlzFvm OTQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759795223; x=1760400023; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aX+L3x30EvRej5n6vrQ0kCgHgreWzDds4tYuLwFNAIQ=; b=OpgWuvtznmwqoY1gsY+PuigaHu/c7VrFiU0wEXfmHjXruFJr29RKjedNe18yN6M0Gv zM903RLgD7lt8ccAuyoMpeC5fXlDL4VN5nMo/jxHopiabqCXmyXlf3S9Echuf4DbXkU6 /ht8/GvpJPgjsVklQtM95BPw0Il92qwhozJGPRTUYrwdhe0rRD9qt1yWXDk9aIVC+YUM qx2ojAt2mR96HXSp+Jf3X81blAJ7X5wSDOoZ5Ikap6A3fsfEa8tGydJz/ioLSVWJXj2E dWpSLAw7k5fLr8ohQJDWAVGbu8KvinqWR0VdFuYtlZvOGeCWy47YQmjYIInTX1X8d433 547A== X-Forwarded-Encrypted: i=1; AJvYcCWK42x3ng63rDZ4xfVyMi5UZfTszaZUtJVArV3/b7Ua+8jV20fvYCJu/Eb2q4y5pajJLhJdeSrgm1JNp8c=@vger.kernel.org X-Gm-Message-State: AOJu0Yxg32KUK4i0JiibY2sIMMo9E80JZ1sIPnGOQyRlpnBRHjWSopdv 7jOGRW8LEttKcpQGfsAY/rEVtY/VYwk8g6aY5kUf6257HP9gnStj80UW+YioAPSoJvkngt4rfx7 k3QX1+g== X-Google-Smtp-Source: AGHT+IGDoEP/SfOiBAkMPYdIPL/5i5TrNtJtl0UOJt+bU99REJjTTBrtPSg8geiVHRKHdH7VyXGDm4KMtPM= X-Received: from pjzi16.prod.google.com ([2002:a17:90a:ee90:b0:32b:8eda:24e8]) (user=jthies job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1c04:b0:329:ca48:7090 with SMTP id 98e67ed59e1d1-339c27d2763mr19089364a91.37.1759795223265; Mon, 06 Oct 2025 17:00:23 -0700 (PDT) Date: Tue, 7 Oct 2025 00:00:03 +0000 In-Reply-To: <20251007000007.3724229-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251007000007.3724229-1-jthies@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251007000007.3724229-3-jthies@google.com> Subject: [PATCH 2/6] usb: typec: ucsi: psy: Add support for DRP USB type From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jthies@google.com, dmitry.baryshkov@oss.qualcomm.com, bleung@chromium.org, gregkh@linuxfoundation.org, akuchynski@chromium.org, abhishekpandit@chromium.org, sebastian.reichel@collabora.com, linux-pm@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The USB Type registered with the power supply class is based on the current power operation mode of the port. When the port is using USB PD and is connected to a DRP partner, report that the power supply's USB type is USB PD DRP. Signed-off-by: Jameson Thies Reviewed-by: Heikki Krogerus --- drivers/usb/typec/ucsi/psy.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index 2b0225821502..985a90d3f898 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -209,8 +209,16 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector= *con, { val->intval =3D POWER_SUPPLY_USB_TYPE_C; if (UCSI_CONSTAT(con, CONNECTED) && - UCSI_CONSTAT(con, PWR_OPMODE) =3D=3D UCSI_CONSTAT_PWR_OPMODE_PD) + UCSI_CONSTAT(con, PWR_OPMODE) =3D=3D UCSI_CONSTAT_PWR_OPMODE_PD) { + for (int i =3D 0; i < con->num_pdos; i++) { + if (pdo_type(con->src_pdos[i]) =3D=3D PDO_TYPE_FIXED && + con->src_pdos[i] & PDO_FIXED_DUAL_ROLE) { + val->intval =3D POWER_SUPPLY_USB_TYPE_PD_DRP; + return 0; + } + } val->intval =3D POWER_SUPPLY_USB_TYPE_PD; + } =20 return 0; } --=20 2.51.0.618.g983fd99d29-goog From nobody Wed Dec 17 21:27:10 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 B84E621883F for ; Tue, 7 Oct 2025 00:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795229; cv=none; b=XhGw1njx06+K06ntc+kk23DEyiJ4Hv3ndPXUf6tNU4rCnYH5/pE2GQYQ1pKbY9T583uXbIu81ELjX8be9x/AeEGBT4z3gusNWMFpxTP+qynt7ngkVfbTb3OlEXLxB90IXa7WmnyrySWoQHOrb6hIih5euVjShpZyEa19VDxU0dA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795229; c=relaxed/simple; bh=pENwmsAAjmiNkgco4RnTpMkJCARZFCefDJIaJ08Ov5c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=S+DOnDEhXp5P5hZfXMFW54jfZ0S66s8Es25HrbUaz10pRZnokb4fkRsIPXIu2oUDGYHPIx1i7GTBNJA8WrL0qBtKbgdEDqzRsCRmgf1Em+KonbGob28eWLKejbugFQr+KQla51t+Yq1Z7bStJxP9mHBjb+qUMfPa4fbHLSY3JDM= 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=dFojNvCA; arc=none smtp.client-ip=209.85.215.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dFojNvCA" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b62da9810eeso3134312a12.2 for ; Mon, 06 Oct 2025 17:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759795227; x=1760400027; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=veFXfjRDf0dsvd44VAIZ/d1llsST7JCD9aXA/FPz96g=; b=dFojNvCA8fpNQss7mCwGj7h3gilGHWx4j8omrm0sTp8KdF7mryYhhC1Emj/BiIYBMI uek5x1JYUxgh8QYVN8hy3/2+PH5fqwgmzSglGzmArPysvAar9GQBR1wmhXyMHhGGtNaI vUKLLH6qSc3KCMrG/A/IqKEVuo3U8qUNvSoczFv5qjgF4uTHu29aNPlIeFDuvkEVZjgE 6OSQqxNSQ2TSoT+YBNINFdX3T5uNM3F73X8oyKlqQlxY4V1iPuYjK8T5X50flsyWfeQW aPjiur3LkQhpWOu2F1wFOVY1LTVsr1N2KffpHm4MYtNGcjzoTwiNmCQ3JkNIPztw9rqW 8wWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759795227; x=1760400027; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=veFXfjRDf0dsvd44VAIZ/d1llsST7JCD9aXA/FPz96g=; b=MntegNNbRRSO0aOTspPchfY1JKACEi+zGUOFmO6LCqNOdP+2VSflIbbnTgYGksLsN6 8lbxVoeKDhGwORyBytwK7Q4Ba0srY79zOpYG1HvWtygFAHIIs9h67czVoihSPCTAk+Ch UVOr2v0GSEL3OLWxbMmfPfMyOd5hpO42GI6emc14fCYhkELDGlelJxn5eW/td/A3n6jT 3lliwU0pZhT7dj4TKrRU90WrjO/uh9lsqL81Ldq+VRqrWDddKfJA4T7zMSz1xTQOenvN HJehjcxUZMN2Fm8Eq2h7YIEFc34lzI4RizXz8IslHZsvpi215jVgbIsXNvCbvUusIZ9M JVtg== X-Forwarded-Encrypted: i=1; AJvYcCXdhd49LJFKNafR2Jny+uYIs/Jq8hP7GBCZtbxiuj/i+bSouQvekE4p0r7kaHNMVxOS0Uw+kj1+Hx5tyCA=@vger.kernel.org X-Gm-Message-State: AOJu0YzyAsX0MsjWTXtVlKnehmvHzfR6RYzATLKRp4SFJquhSk7DS4xf bIlQNppTuyUeSGBzTphndPXC4o/tLrT1Yyp30HQxET+WgfRpC3fClP0FnTrTCRdLi/uln085pEc gXIjHLQ== X-Google-Smtp-Source: AGHT+IEOR6Wj27pRpKv0k/qoUxQHhzFwXh906JQ8G1YD/rp0fjukZfK5N0y7vLEm9X9EgoopeHdAosKdGtE= X-Received: from ploh14.prod.google.com ([2002:a17:902:f70e:b0:269:4741:6d3f]) (user=jthies job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:db05:b0:267:a5df:9b07 with SMTP id d9443c01a7336-28e9a513217mr199147135ad.12.1759795227083; Mon, 06 Oct 2025 17:00:27 -0700 (PDT) Date: Tue, 7 Oct 2025 00:00:04 +0000 In-Reply-To: <20251007000007.3724229-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251007000007.3724229-1-jthies@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251007000007.3724229-4-jthies@google.com> Subject: [PATCH 3/6] usb: typec: ucsi: Report power supply changes on power opmode changes From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jthies@google.com, dmitry.baryshkov@oss.qualcomm.com, bleung@chromium.org, gregkh@linuxfoundation.org, akuchynski@chromium.org, abhishekpandit@chromium.org, sebastian.reichel@collabora.com, linux-pm@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Report opmode changes from the PPM to the power supply class by calling ucsi_port_psy_changed(). If the current opmode is USB PD, do not call ucsi_port_psy_changed(). The power supply class will be updated after requesting partner source PDOs. Signed-off-by: Jameson Thies Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- drivers/usb/typec/ucsi/ucsi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 3f568f790f39..7b718049d0d1 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1022,14 +1022,17 @@ static void ucsi_pwr_opmode_change(struct ucsi_conn= ector *con) case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5: con->rdo =3D 0; typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_1_5A); + ucsi_port_psy_changed(con); break; case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0: con->rdo =3D 0; typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_3_0A); + ucsi_port_psy_changed(con); break; default: con->rdo =3D 0; typec_set_pwr_opmode(con->port, TYPEC_PWR_MODE_USB); + ucsi_port_psy_changed(con); break; } } --=20 2.51.0.618.g983fd99d29-goog From nobody Wed Dec 17 21:27:10 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 05C832192FA for ; Tue, 7 Oct 2025 00:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795232; cv=none; b=W7DzxsMnYUAV+/AvwB9fbPMER6ZckVl1Wx6CDEkz55kUNRF1ARxcsUU2wD1e6VP6ei9lS0gmXdkovDBt43krgG9HOK22bKruu0nIu9Ymwap/E/CY/lHXpnydGpGmKM+C9ROeQLBUOdxikD0nu3i7ir0Ygwwq3lwLgnXKdlJy5a8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795232; c=relaxed/simple; bh=D+MRKxpRY+FzYsdPeIj4rxTE/97xCVi92Ne0tdfRG9w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=amc73b8EiAO7zv0J59/7TsZ05FwNFQONmZZFFaBaSfODiSY5ZZANzyQXiqlCqsp4PZJm8HihGxPEmEiy7bypKr/lbyeGXRLUCgkIR2abocaexGDgIq0PIai/c58Zy3WD04+4DDdDRZMqM3VmiALHhHJkdCZJplzWhMOBdrbGlyA= 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=Q03rbH0Z; arc=none smtp.client-ip=209.85.216.73 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q03rbH0Z" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33428befb83so5853995a91.1 for ; Mon, 06 Oct 2025 17:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759795230; x=1760400030; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=HBzYAbkVeiCWYgmKOO6DMAiS3ySiT/Utkjit0D80cV8=; b=Q03rbH0ZOciiKXEGIka8M5SIgkmvzw6ZHsDsOkSYyUmLRCd8v3zg1PCTWsjgf205cE fju8msKsEasSW/0kkBl6H10HqfnMZm4EgbfVOvofsXBgSWUacfO4/3ZUHCeyqPwoLs3o nIsHdRVAqLeBDmEyt3nHaAAjywJdKopVZ3J4A/nYfXQPISH5PH7d1/oOWzBJ592wkSgH m1SAQEkRXRW0CSkcAD2PNVa6uOgy0xfcj1sV/HquWem0LmSUERRwbzcY3Wlmp+bBTDtL BMk32ivDpxNgdFKmcAAIG+Jw47DFOQCdpSYvns7wogtXrvL2kE6hgLgyfiY5lga0U23m Pn4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759795230; x=1760400030; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HBzYAbkVeiCWYgmKOO6DMAiS3ySiT/Utkjit0D80cV8=; b=Lz99n72r23PDd+xadlroq8hfN1ZJpPNx9bRlgHABfWYaZLB5Tc0XBVpSEFr1Wb23lj 9xSio9S/T+XXeQNWXmVlKoEglz/pGOr8t9mnskzl9ValmggM4le6ukSc1KWraIs9BSU4 ZHc+OlHDYs88XFM8Rpb3wGMNNO8q7dDa7LKPvyxPqQmhZEp0v/5logPQbQsU6NonVl+c JNVT1cOBk9437ASvMd4mQbIxOmIPSvUQvlDhwjdobGKXBwWJHDI94QIFeytUp/X+XbnH 2iGUM7IoTe7BOGEOkmRvbC/nFWTcaVe7izS60O578VBr5fBkagdzydvX/YpZk3JiVe4Z yQ4g== X-Forwarded-Encrypted: i=1; AJvYcCUHD/ekczHx8pVui4JNdT5jEG4Z14AuqtjBF5sUtBL2yUQXloI+/npmc0zDAxvZ7GFsLzEQQkfEdGmGvz4=@vger.kernel.org X-Gm-Message-State: AOJu0YyPq1bT5A+TonjuNS2WrTTZxOTSX2QTaCzg7rFrs/rcb2kdadAZ Y2P213Q6/kTGTNnWYFVdAj7JW+30hLi+dkDDGMj2avTfM2aqh+zJwMzZLKURJI70IyHhFTab0IW UunLPnA== X-Google-Smtp-Source: AGHT+IFxQ/0APQQH/w8k8aOg6BAF8kp00klr4bjh7buOd+uTq0PuqSjd8xU2TYekqWlGFdbE0f7oM3ZZQgc= X-Received: from plek20.prod.google.com ([2002:a17:903:4514:b0:274:e523:6f5a]) (user=jthies job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2f04:b0:269:8d85:2249 with SMTP id d9443c01a7336-28e9a5689f6mr144152565ad.22.1759795230224; Mon, 06 Oct 2025 17:00:30 -0700 (PDT) Date: Tue, 7 Oct 2025 00:00:05 +0000 In-Reply-To: <20251007000007.3724229-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251007000007.3724229-1-jthies@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251007000007.3724229-5-jthies@google.com> Subject: [PATCH 4/6] usb: typec: ucsi: Report power supply change on sink path change From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jthies@google.com, dmitry.baryshkov@oss.qualcomm.com, bleung@chromium.org, gregkh@linuxfoundation.org, akuchynski@chromium.org, abhishekpandit@chromium.org, sebastian.reichel@collabora.com, linux-pm@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update the UCSI interface driver to report a power supply change when the PPM sets the Sink Path Change bit. Signed-off-by: Jameson Thies Reviewed-by: Benson Leung --- drivers/usb/typec/ucsi/ucsi.c | 2 +- drivers/usb/typec/ucsi/ucsi.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 7b718049d0d1..1a7d850b11ea 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1293,7 +1293,7 @@ static void ucsi_handle_connector_change(struct work_= struct *work) if (change & UCSI_CONSTAT_CAM_CHANGE) ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ); =20 - if (change & UCSI_CONSTAT_BC_CHANGE) + if (change & UCSI_CONSTAT_BC_CHANGE || change & UCSI_CONSTAT_SINK_PATH_CH= ANGE) ucsi_port_psy_changed(con); =20 if (con->ucsi->version >=3D UCSI_VERSION_2_1 && diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index cce93af7461b..35993bc34d4d 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -382,6 +382,7 @@ struct ucsi_cable_property { #define UCSI_CONSTAT_BC_CHANGE BIT(9) #define UCSI_CONSTAT_PARTNER_CHANGE BIT(11) #define UCSI_CONSTAT_POWER_DIR_CHANGE BIT(12) +#define UCSI_CONSTAT_SINK_PATH_CHANGE BIT(13) #define UCSI_CONSTAT_CONNECT_CHANGE BIT(14) #define UCSI_CONSTAT_ERROR BIT(15) =20 --=20 2.51.0.618.g983fd99d29-goog From nobody Wed Dec 17 21:27:10 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 3075022F386 for ; Tue, 7 Oct 2025 00:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795235; cv=none; b=pWFTjv+wyxbPNq67b5oPnPBdyYBlOjRzdX4P4zEs4RFd4PU1hkbzgi5oa0IJbSkNZYxMpU21tcZZLclu5Qiy0vVK2230Y4TnDl/Qkx5JM3X7GfnXqlNmGvGf4W/bfSclA+DJRs05pDRZtqm8f7V/1oKnhtm1QoDNFyr1B59c5CU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795235; c=relaxed/simple; bh=3SrGK00c6kBpKdfA0G1voXW98D3SN4/08oAWZGvB06s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l3djnkT9ZHzIDOZciiLJfb1F4ebV3iXO5tkGLGFmtG0/VMB+HerhRL3x3XICNQOTIl7i2kUpo2FILREPjgOpBTal3otgmRGlwlnR6b2pwlZWxuDopSDwhyxjIwCd00fWhKbr3H+VH14/BIO88kcZ0l1P9hrYbNMUvmu/ZTslZHY= 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=aBHPjJGx; arc=none smtp.client-ip=209.85.216.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aBHPjJGx" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3307af9b55eso4557975a91.2 for ; Mon, 06 Oct 2025 17:00:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759795233; x=1760400033; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bNxgxN8i4WKNF9gjsgYvNaV1dKsUpnqQpccRNq6XLzk=; b=aBHPjJGxffZAo8gagTuh1Mkcbw6ke0uy17r0vs+k3Y9Cg79uPIyw+MNa2iZe/s1ZKC Xt9e0M5WWf+xdDuqktM7xH6KHrxOhT5ucIQCHNYAENlmejhA3jNsQdjzRILt7y13Kdjf bu7SeWxzKdLOGRluoRRmy3g3TFSlgEKsaQhIN8w83ysB2e8FRDD5PbAdOj703wiLR7XH xNH54IRQL/I7jJLUNedthCgtPD0F8Z0xHzrZpuc6LJxGXQ/Ia7fSVLWq2x7bZdmlllar 0/HBsbW5Xddg9BhWOLjiAunsb4tRRAfvHlJ5W/6oD9cRMCCP6XLQumZzNQvChO+z3THI Ad+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759795233; x=1760400033; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bNxgxN8i4WKNF9gjsgYvNaV1dKsUpnqQpccRNq6XLzk=; b=tHQasmbI8jzqGhcJh3ixuriJsccCxuzKfLaD978KuZJHd7VCQsECJBDkEZ5RFaY6uY EDyvp45MWZCId2HyqxJjpqnMOppEMI59yWXHfcQ1kOu2djrNDDKiH39rpXnd7xpwcJNs KKaVNvESgX0G93dAAv5CI8hhaAnyz+0n61pEHsfHaXXRoWcJ72zOFGk/+vUKeenEkZi+ VC/cPW73upfgtbsXUTmQzoOfY8ejBF9LeWCceJ7JvKsW6OFoSTedkRQ6QfGj1A97MtH+ VmB3jDDYv+JqUjQPNtztf+l0uX77V52ZpJnO90G2F0HMSfd51VrY5Kg7ONc+sD3QeUst mdMQ== X-Forwarded-Encrypted: i=1; AJvYcCXKykRnTkAFkN1efDv8cwWLoqhqmjukk8JvKdJvwxOz6+7vLsryMR1DY5XbfpMWuu4uPetCITBfJF5RixE=@vger.kernel.org X-Gm-Message-State: AOJu0YxIniPbtyHXCixj9ZL5BnKoriavw/wc+EGvDS3R7NkyH3SKls5b 2WgsxvA/DxTUaBy4BHjXoQQYucKz7WU9Pitl0anqTej7ZwOa1DfACoIpSZbeMb7oL2fKXmK1EQB JY9DzTg== X-Google-Smtp-Source: AGHT+IHFgZJ+HkrSiYXPJMMiNLQI1F1cnVHsmDy7sKcZjdwP5IwvuIVt3bnCbD90DcU72hET3y58ZFjpk3E= X-Received: from pjbbx13.prod.google.com ([2002:a17:90a:f48d:b0:330:72b8:fcc0]) (user=jthies job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1b0e:b0:330:6d5e:f17e with SMTP id 98e67ed59e1d1-339c278eb63mr16986089a91.24.1759795233450; Mon, 06 Oct 2025 17:00:33 -0700 (PDT) Date: Tue, 7 Oct 2025 00:00:06 +0000 In-Reply-To: <20251007000007.3724229-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251007000007.3724229-1-jthies@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251007000007.3724229-6-jthies@google.com> Subject: [PATCH 5/6] usb: typec: ucsi: psy: Set max current to zero when disconnected From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jthies@google.com, dmitry.baryshkov@oss.qualcomm.com, bleung@chromium.org, gregkh@linuxfoundation.org, akuchynski@chromium.org, abhishekpandit@chromium.org, sebastian.reichel@collabora.com, linux-pm@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The ucsi_psy_get_current_max function defaults to 0.1A when it is not clear how much current the partner device can support. But this does not check the port is connected, and will report 0.1A max current when nothing is connected. Update ucsi_psy_get_current_max to report 0A when there is no connection. Signed-off-by: Jameson Thies Reviewed-by: Benson Leung Reviewed-by: Heikki Krogerus --- drivers/usb/typec/ucsi/psy.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index 985a90d3f898..3a209de55c14 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -169,6 +169,11 @@ static int ucsi_psy_get_current_max(struct ucsi_connec= tor *con, { u32 pdo; =20 + if (!UCSI_CONSTAT(con, CONNECTED)) { + val->intval =3D 0; + return 0; + } + switch (UCSI_CONSTAT(con, PWR_OPMODE)) { case UCSI_CONSTAT_PWR_OPMODE_PD: if (con->num_pdos > 0) { --=20 2.51.0.618.g983fd99d29-goog From nobody Wed Dec 17 21:27:10 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 7302C239E67 for ; Tue, 7 Oct 2025 00:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795239; cv=none; b=R+d+mUs1uko5jSR1mvAN80jLlj/UgeiABYmF4ytZraJMWYcsvbtim7Urvpb4VD/EMMc+ZCk67si/q3vakC1A1+7uUSgd2Dt2n7ztu0hdR4rYfpY5zlx+WfVmsAN4C+5bJXTnI8+OBDx0pXclohDBBxzzlYPYrsWEJGhumbsEyEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759795239; c=relaxed/simple; bh=GBPMFxcyATcinHz2L3AJDSb/kMMMuAbd+drLtO73/sI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aD+B9oZUB9A4D3pdK/lbZzuv7FbTKPm24VEdQc/h7ouBk9MSqHpAHoXqpTTzRdFteCSGSo52Eq3fPvd/7cfBRfppY1KJS2woOWDLh56Wd+6ViHpYbIlL9n2EZuMk3G23bracvVgpWfvD4APwdoM8XCBahF9PgdfigQooUiVgm/A= 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=HT+zeqD2; arc=none smtp.client-ip=209.85.214.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HT+zeqD2" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-28e8d1d9b13so58515085ad.0 for ; Mon, 06 Oct 2025 17:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759795237; x=1760400037; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qGKXpJpqBqzMfm+XRzJ9DqWA3n0QzysPqL8GwN0dGls=; b=HT+zeqD2rdthnBqRYpixPYr8EzjEQNI2/jO8dIvrS58zyEZXPUwivmtC0mDC9Qx2S9 qEzkKjVmeVxmqFOggjk7hbP+d6zfm8LcOwWpLc6mBLntt81JGJoiAOVbTpuXBVahl34u dibtdK1P3Rojike8Es+TxmrtLD6k7jEmhfVIzBcX5x08FFjwny73QZRkerrZn+QNXh4l JVIYKm3MK5WuLdSwLc8Qwwj9PwUB0TX7KSH45wriOme+A21t1WSpnvPctHpWZfwHK/MK 7ugAxhtpmuslUH9Z2puiGENceKTP/3tkDvsjelpmk2wYKM2RLuBKzO9dQUyZ6adZmjzq WSVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759795237; x=1760400037; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qGKXpJpqBqzMfm+XRzJ9DqWA3n0QzysPqL8GwN0dGls=; b=AWxPScqm2I71zzuRA5yOiOPY6+h/7fz9FMT1DbPOpbpo2vdjFSGK2B6/xoc6IdXpVb ploqeCffeoR6Rvol4C56paOBcjBO2pKTlMzGWEJYrcIRIVnnQ04Ry7rX3xARatpxKpAX 6GsAt6GH9sNbQf9UjebNCql3GK8cNoa4VGNAAgBwSppFpSYEaRrv1MiKm2RvQawqNnu3 fCw+MC3JmmRbm024gw3KOFLwKFLmbzSd4JOwS9NBkqUjkt42f4c4p8j8CnBB4cif29XW W63JIo0mZ5z2YN4vuetipDrEUpEfJiYu8Vrcq7Yr0MeBaJyWGwgq2bf+ZsWDE0dY1hZM wi3Q== X-Forwarded-Encrypted: i=1; AJvYcCVRo7Dxhtp/+amdNqK3AHCacoMpqZku2/3pCMrq59exVyPSZbw+PdCmxggoMUlkjvk9TSpiZIVoyblYT2E=@vger.kernel.org X-Gm-Message-State: AOJu0Yw541RLO0/w+8gZLSXjXw8IaF/l7eQqMsTHDzUJirMeENkjact7 xdzSbDGI4G+lBA8SmJM07xdoffnNI5zKFXaDiw5W9RxF5dP/8OZ8si80Xhw1RCGasERQcNnWxF/ J2EO6iw== X-Google-Smtp-Source: AGHT+IF8hGVIlChbtIhMjhLw3aZZeNeEt0jbndtu/J7HYN5bXvwyE+kZ9qVypMx6ixiiCHlMmAe0pYoqYCs= X-Received: from plhi5.prod.google.com ([2002:a17:903:2ec5:b0:24a:b588:eefd]) (user=jthies job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:ac3:b0:267:f121:6a88 with SMTP id d9443c01a7336-28e9a6dc287mr175381245ad.42.1759795236620; Mon, 06 Oct 2025 17:00:36 -0700 (PDT) Date: Tue, 7 Oct 2025 00:00:07 +0000 In-Reply-To: <20251007000007.3724229-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251007000007.3724229-1-jthies@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251007000007.3724229-7-jthies@google.com> Subject: [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jthies@google.com, dmitry.baryshkov@oss.qualcomm.com, bleung@chromium.org, gregkh@linuxfoundation.org, akuchynski@chromium.org, abhishekpandit@chromium.org, sebastian.reichel@collabora.com, linux-pm@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Abhishek Pandit-Subedi Power role swaps initiated by the host system doesn't generate connection status change notifications. From UCSIv3.0 spec, section 6.5.10 Set Power Direction Role: The execution of this command might require PPM to initiate a power role swap. If the power role swap fails for any reason, the command returns, and error and the power direction should remain unchanged. Note that if the execution of the command resulted in a successful power role swap, it should not result in a connector status change notification. Signed-off-by: Abhishek Pandit-Subedi Signed-off-by: Jameson Thies Reviewed-by: Benson Leung --- drivers/usb/typec/ucsi/ucsi.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 1a7d850b11ea..6e3797d7a144 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1526,20 +1526,40 @@ static int ucsi_pr_swap(struct typec_port *port, en= um typec_role role) if (ret < 0) goto out_unlock; =20 - mutex_unlock(&con->lock); + command =3D UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num); + ret =3D ucsi_send_command(con->ucsi, command, &con->status, sizeof(con->s= tatus)); + if (ret < 0) + goto out_unlock; =20 - if (!wait_for_completion_timeout(&con->complete, - msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS))) - return -ETIMEDOUT; + cur_role =3D !!UCSI_CONSTAT(con, PWR_DIR); =20 - mutex_lock(&con->lock); + /* Execution of SET_PDR should not result in connector status + * notifications. However, some legacy implementations may still defer + * the actual role swap and return immediately. Thus, check the + * connector status in case it immediately succeeded or wait for a later + * connector status change. + */ + if (cur_role !=3D role) { + mutex_unlock(&con->lock); + + if (!wait_for_completion_timeout( + &con->complete, + msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS))) + return -ETIMEDOUT; + + mutex_lock(&con->lock); + } =20 /* Something has gone wrong while swapping the role */ if (UCSI_CONSTAT(con, PWR_OPMODE) !=3D UCSI_CONSTAT_PWR_OPMODE_PD) { ucsi_reset_connector(con, true); ret =3D -EPROTO; + goto out_unlock; } =20 + /* Indicate successful power role swap */ + typec_set_pwr_role(con->port, role); + out_unlock: mutex_unlock(&con->lock); =20 --=20 2.51.0.618.g983fd99d29-goog