From nobody Thu Dec 18 01:35:45 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