From patchwork Wed Jul 24 20:11:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13741317 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 0C1D277F15 for ; Wed, 24 Jul 2024 20:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721851941; cv=none; b=GHYO22aO83X3+xCwMzkPUJrv6p/r2sxHxh5WLULJX+P/yyavDRGQRjmPW2jysY3EcwuYQRehQbDgxKdS2xhLUbUR+iOizxgTUKjEMHT0LQ+pJF4wGMo/PaUj3Xn2jNRlCYsYDnlR3YpxfClTosa92aNqRcGwlhAzCVCzhEtEtWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721851941; c=relaxed/simple; bh=bmf032HXnibfYRvqK8uO991qHPAEkYRP9QaQxWdjE6Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZNUiam+KgqwBUWwJDju7HXIDtqpvZFQsbQGxNbQUAz5wSxS+VbITVj2Ott/vATo5HM+6miaFjoxmodZv2c4XXTs4sb1ShmJpjVWNcKdMn/qFD8gnkSflmXbOpnaIWhJANGuvhoNJj5AHAguOtmInemnxUewVOdMvlNUXqO8Kr44= 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=iwkJWOfl; arc=none smtp.client-ip=209.85.128.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="iwkJWOfl" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-64b70c4a269so4667287b3.1 for ; Wed, 24 Jul 2024 13:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721851939; x=1722456739; 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=PF43lGYCTnm27A+1Cps4Zd+/98Emil+YcRWp+KY5vlw=; b=iwkJWOfl+MpiQUT6KRMl/K37aJWxtqhU+wnotdO1cCeYSteDn+eRfjOz4zYwbhaURW ahQ8zwMqKvcTtPno3nv8SchiXclH0qAg+g0J1D0jiZcoe9Ku8as+Zxplcm8g+xDKG3eT xBgkB7YhP1NsRDtkJkHxlgOve0KNmyKEWeG+jV3re9ExyxGg81MxyZPNve8RKehtUjMQ oOd5uetFbjpjwg6zxQ3RQAs/93GMG3vqtWjpagQQeCf9uad5LmSjCdJxG1CM5FUtijjL MUQ5bOvluhvWoGEp/qQZH9BHaB1M4JSWr77rQvfSxzwLJwn0e777U44p9p+EOroDpH+k G0Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721851939; x=1722456739; 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=PF43lGYCTnm27A+1Cps4Zd+/98Emil+YcRWp+KY5vlw=; b=l4YPNluThCUPp9a/EkDmfL1qIbEYeZMvnWUbWd9cTG28xGiHHIwtdMKbPOjY/EXSQk 2nydA7iDQjwqThORU/9VUZ5GGsZZNr5NdkmCEkQ/7BG2EPWa8z4kaXurKLJOq0qfK3cD bymhNAvAJM3NoHNkdruukF3CAsEkV4LWKxHxpfIpkQDuTzdGWp9/6hlsj+MMAL4zZWw6 L5wUsW1VY5cxwFG+MUJFvR8TqISktE4ctHDpboj0pncVkr/jkzgkNH70/GBW6PuzGuey ZW2cNxXnkDddlLwJayzOCVuluta/cA8BdywqHLkplp+RjfRhYAcYgUEzv3Sy99hvIVfu cfzw== X-Forwarded-Encrypted: i=1; AJvYcCXPIyAhnj+9go2vEBZWdErp9ualKqmX6QBvadJsHrZArdqDobV+U0MwJB68TSZcdWK1dODFMWnTVPH38VVmhx/JFbZVZoRnqOmR X-Gm-Message-State: AOJu0Yys6iDK1tdAOt4dGKHh8rDRq2xl80K23j7iaBnbkXCqxaMHIUdb wkwvRH0LAPltjiECWoxclX8xHd1bV/c2Zc0MoHEhkUl5T+sAZRSeGpf7xnKVtlW8bBrzkBwyTUU gKA== X-Google-Smtp-Source: AGHT+IFsAfZQjJbLvYIYnrxSi2i60E8uRxJlJU7Bh6l/GO2NbS00T5qm6h8/oZaj71q/D4vqR77Cxc9u6Yk= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a81:b80e:0:b0:62d:a29:53a0 with SMTP id 00721157ae682-67515030582mr57267b3.7.1721851938956; Wed, 24 Jul 2024 13:12:18 -0700 (PDT) Date: Wed, 24 Jul 2024 20:11:13 +0000 In-Reply-To: <20240724201116.2094059-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240724201116.2094059-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240724201116.2094059-2-jthies@google.com> Subject: [PATCH v2 1/4] usb: typec: ucsi: Add status to UCSI power supply driver From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Add status to UCSI power supply driver properties based on the port's connection and power direction states. Signed-off-by: Jameson Thies --- Changes in V2: - None. drivers/usb/typec/ucsi/psy.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index e623d80e177c..d0b52cee41d2 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[] = { POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_SCOPE, + POWER_SUPPLY_PROP_STATUS, }; static int ucsi_psy_get_scope(struct ucsi_connector *con, @@ -51,6 +52,20 @@ static int ucsi_psy_get_scope(struct ucsi_connector *con, return 0; } +static int ucsi_psy_get_status(struct ucsi_connector *con, + union power_supply_propval *val) +{ + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; + if (con->status.flags & UCSI_CONSTAT_CONNECTED) { + if ((con->status.flags & UCSI_CONSTAT_PWR_DIR) == TYPEC_SINK) + val->intval = POWER_SUPPLY_STATUS_CHARGING; + else + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + } + + return 0; +} + static int ucsi_psy_get_online(struct ucsi_connector *con, union power_supply_propval *val) { @@ -249,6 +264,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; } From patchwork Wed Jul 24 20:11:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13741318 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 2FDE616DC0F for ; Wed, 24 Jul 2024 20:12:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721851943; cv=none; b=Hjtu+LxjLyngoawRpI9yLRZcBn7uqZTfJvYGB3dBXIcx/6qiu/FCcyjWaLbUCiq/yH9oZ0/eAwTbgoM+kPoCyPw4dKOZXxhoWgz+Ha9huFVNQkRCjC0OyKV//Yt59vqHTBHPcgzxx0WZj6nOGRyxc4aOoTsx0JCx7AMFAcm9lpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721851943; c=relaxed/simple; bh=h58HLHCNa0YzrY3VJan8w1y3GHAehkiK7wZWPvDTkMQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oNzab7zK+26OQc8XqV8bwKl3ZZcmnoNGBdHO2ClItSbct5xXPlQLmn1c2wuckERpEqZcBejGRtYAapANgwuCgS/NqHzwoPNWWnUZm3+eAwQnM/Oeynx/5ic9QNKLIZlMCNRcQRN1ynUhiYSaj0/JwXQ3ryO/mmOd6AmPbvcvI10= 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=xhNOSj4d; arc=none smtp.client-ip=209.85.215.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="xhNOSj4d" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-721d20a0807so160686a12.1 for ; Wed, 24 Jul 2024 13:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721851941; x=1722456741; 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=uLze0kadUGbSBXCo4aky2nkQ49F0HsvXX1UCI/WKp1o=; b=xhNOSj4dCcUemx9vY6CORPziQOytusxE3o8zPAUWwMUJRpsLuKijbO7SErJCK2mf3J GidKKkAdOlaNDdgzNV/1SvFtZk9rRzGjajxiwJ2FfQgjsHd5ptLe5Zx0YpKmoKL5Tp8G flPdnGeKAXLFqzdmxHJ1TEypvTpN2PMYm5eOBcQ1tCXvhSxTjp9hcrgZCP8YeXJRTSgL wOyYltN4YOKiBKhh85QVAh8tbxVUZW+vcjGK7DM1fnQD1HI1af5dmU54YpCPz/vaiF5q ewIrD+u8FQGN6EGDZswwD1K7LpCy99MSresZ7U6IcUzxVRjfxqWy54xxdYWjnpEzmfya jszw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721851941; x=1722456741; 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=uLze0kadUGbSBXCo4aky2nkQ49F0HsvXX1UCI/WKp1o=; b=rutqpi+VnMF+JWwWvXRrKh4QkRG6+H/cCLF++10csVnvPGkHNI3FmRd7UD3tNJ5pLQ 4k/piaShmBdwki/H5Gu97VM1cL5XaMNxrngMfsWIzHgJFbdG9PW7Gs8xvhYSApJe3zln VBB34gWUEHByac/tpPmv5vX4UJ4fA+XUGxmR5DWb9t56TUW0DEA6blBg0QVAZw9fkerD FuKZwhZK0I42FGEB6f48fh68+Cdihdye3LeifTsE4i5cTYjDe+b5H7j45TaFoT10HSkK IRgyeBHl/uUVR5U0k2SCjKm6sgmG5ZGhuPLlmLvcIKuTHlMjsWkXlJxByjeKjv+SY9vt S79g== X-Forwarded-Encrypted: i=1; AJvYcCVF0Aih9Hb2+MiJqhA3s7GVYcbVJlm9T34vlAQl00rmupucygYUrYHlQtfNsxQvn2+Kxuxxy9U2rlwKJgDj69MLLLiZekMh0USF X-Gm-Message-State: AOJu0Yyxp7S6Z6Yv1Pa/nIjLj902gb3UqQ6vwnb7hubYC6AD9KsP0MQF Zx3BMXV8b0MkoHmiPoaD3DEC2zKiuxD3bmB4vlDRxICl2ZoiPpC9FU1YuDKVA1AwqM1M2rtsadk 0ew== X-Google-Smtp-Source: AGHT+IGQUzfvNQ0VfRVxY9FJGcd61WeAx5N6cNXLQohbC81lMBoH10RygYZERrbbZNtHojNKZX6YHzJxc9o= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a17:902:f693:b0:1fe:1a92:5b2 with SMTP id d9443c01a7336-1fed3051a17mr16985ad.1.1721851941169; Wed, 24 Jul 2024 13:12:21 -0700 (PDT) Date: Wed, 24 Jul 2024 20:11:14 +0000 In-Reply-To: <20240724201116.2094059-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240724201116.2094059-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240724201116.2094059-3-jthies@google.com> Subject: [PATCH v2 2/4] usb: typec: ucsi: Add USB PD DRP to USB type From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Add POWER_SUPPLY_USB_TYPE_PD_DRP as a USB type in the UCSI power supply driver. The DRP type is set when the partner sets the DRP bit in one of the source PDOs. Signed-off-by: Jameson Thies --- Changes in V2: - Using DRP bit of source PDOs to determine USB type. Updated commit message. drivers/usb/typec/ucsi/psy.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index d0b52cee41d2..d708f9eb1654 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -204,8 +204,17 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector *con, val->intval = POWER_SUPPLY_USB_TYPE_C; if (flags & UCSI_CONSTAT_CONNECTED && - UCSI_CONSTAT_PWR_OPMODE(flags) == UCSI_CONSTAT_PWR_OPMODE_PD) + UCSI_CONSTAT_PWR_OPMODE(flags) == UCSI_CONSTAT_PWR_OPMODE_PD) { + for (int i = 0; i < con->num_pdos; i++) { + if (pdo_type(con->src_pdos[i]) == PDO_TYPE_FIXED && + con->src_pdos[i] & PDO_FIXED_DUAL_ROLE) { + val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP; + return 0; + } + } + val->intval = POWER_SUPPLY_USB_TYPE_PD; + } return 0; } @@ -275,6 +284,7 @@ static enum power_supply_usb_type ucsi_psy_usb_types[] = { POWER_SUPPLY_USB_TYPE_C, POWER_SUPPLY_USB_TYPE_PD, POWER_SUPPLY_USB_TYPE_PD_PPS, + POWER_SUPPLY_USB_TYPE_PD_DRP, }; int ucsi_register_port_psy(struct ucsi_connector *con) From patchwork Wed Jul 24 20:11:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13741319 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 C86AC16CD36 for ; Wed, 24 Jul 2024 20:12:24 +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=1721851946; cv=none; b=UR5l4FMiDfgL/54JyVUs4eQGUvFt74f/7fq8vGagwTaLGVrRRCk7DRWmxVPKyzJGrO16e1oO+Wms595lrGhMsnfmjqSwvhafYlSrcpaMHAnA+lSMx9aptRb4CUK3RpwcWs/w2xTcc6RdMCQQa9GqZIX/b41M9FCHh1GEBQNFrvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721851946; c=relaxed/simple; bh=aFQShb42bii3mGm0qbjwREOyaZHeVjKuehp0xxMT8bw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=g0vIOvy0dRMzgvafJgLnWX6h82PPXtmzX65PGrIv1lg39P7a8vQNVGOytmQCtVif6z9aPrWz0WakEtlz+HXMeDFWDfq8PGtMMM6XAqUm8GwiOc0fEBJFns0rJp3aD+NsJ6rz5hNo6asSXU6YCNaO3xFY4r3Ht7CL/uACUawjTIA= 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=1v0sk6ek; 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="1v0sk6ek" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7a994e332a8so149353a12.3 for ; Wed, 24 Jul 2024 13:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721851944; x=1722456744; 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=b9Pvb4jluH5jBI5txkxQ7mbZedDOA5ya44uq5vX5vPk=; b=1v0sk6eknOAFyKUqpVjAHwibptR4OqYhBoYlyw7X2o1hy/VKAgobPhiaEDOsdncE6a yySsnb55CXRuViTSTEw1exlXZl+rw1sIduPT9jOjzpN5HbnF/IyNxsWgv3r+xWtfUS+y N/2OmDEEK1sHwW2cqk2/o/FTeAKizJo4n6L7Mg78US4EgJB6BRhPgg+531MdthnKrTvd 3gi1OvEbwcSkIIm76mjnOw7+wbbkb43ZrpVoGxbmC9U6jraNqh3ohjspVggPMWTjKPlg 5+cbdMH/RVsp6xRZdOiFJl6DrGcI4LWhB+m6j20ONWHq30fuiQPIDWSiMd2bPe+aD6el kdeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721851944; x=1722456744; 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=b9Pvb4jluH5jBI5txkxQ7mbZedDOA5ya44uq5vX5vPk=; b=o1pjMVv66qqsIbv+f8c4Jlp+KytBvKIE3NRtZnNgDzB3nGnN2HnqSu+MPx2ZOLmkRg bAgv9QQcz/ikKA/fc6d5LZMgxvNQLsxVKxpb+9X8zRLAAfz8M1I/Yju+/xGBrfM1agqA mfv/ey5zX3a/l84DSTbjoZ0mnDyEst4m7shHU+AdMUuo5j7ILtTBGTJJIc3yjUUmbHjP Ll/mH9PeN9F6OoEL4hjwot79s7q53qMa3UbEQmsgOqtFj9vgRxtG9EFBAuigQRqN24g8 9is4taUPf4Gt1Q0asTQMTX88jRS7c6UAg9otnp+K6Gt7R3936T1ZSQ2dj/T3mq/49V5C rLgQ== X-Forwarded-Encrypted: i=1; AJvYcCWe+XPrSwr4eIJWdS+035y4EcgPi44FroZ9emfqH1lqIlSdBIa08swOQrPX9ibKA/iDbl0Zmw8Df0ixgi5TgZcuIRSg0J+knseD X-Gm-Message-State: AOJu0YwekxzXhQ/TGLmg1ZbpE+ZM3bURUbotGQtqiwy4uw5N1cDJg8GC QeqyiwS/BjR0rPqD9w/HnQ+FLjMFBVILylbRAKlSEOkhK9upW/Sk3fmm/D4ls3gCGMNX9YYjvuu D2Q== X-Google-Smtp-Source: AGHT+IG2uh8fFLHM5G69rObhox/F6sVJL7/iLS8kFtx31VwkwYk0HuYXoE4wEWN3ZqM2ESVQPytGnOYuX5I= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a63:da43:0:b0:635:62f6:d5ea with SMTP id 41be03b00d2f7-7a9c7c98e9bmr1234a12.4.1721851943753; Wed, 24 Jul 2024 13:12:23 -0700 (PDT) Date: Wed, 24 Jul 2024 20:11:15 +0000 In-Reply-To: <20240724201116.2094059-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240724201116.2094059-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240724201116.2094059-4-jthies@google.com> Subject: [PATCH v2 3/4] usb: typec: ucsi: Set sink path based on UCSI charge control From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Add POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX as a property to the UCSI power supply driver. When set to a positive value, enable the connector's sink path. When set to a negative value, disable the connector's sink path. Signed-off-by: Jameson Thies --- Changes in V2: - Added SET_SINK_PATH call when handling charge_control_limit_max update. Updated commit message. drivers/usb/typec/ucsi/psy.c | 52 +++++++++++++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.c | 15 ++++++++++ drivers/usb/typec/ucsi/ucsi.h | 5 ++++ 3 files changed, 72 insertions(+) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index d708f9eb1654..28265feb9d13 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -30,6 +30,7 @@ static enum power_supply_property ucsi_psy_props[] = { POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, }; static int ucsi_psy_get_scope(struct ucsi_connector *con, @@ -275,11 +276,60 @@ static int ucsi_psy_get_prop(struct power_supply *psy, return ucsi_psy_get_scope(con, val); case POWER_SUPPLY_PROP_STATUS: return ucsi_psy_get_status(con, val); + case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX: + val->intval = 0; + return 0; + default: + return -EINVAL; + } +} + +static int ucsi_psy_set_charge_control_limit_max(struct ucsi_connector *con, + const union power_supply_propval *val) +{ + /* + * Writing a negative value to the charge control limit max implies the + * port should not accept charge. Disable the sink path for a negative + * charge control limit, and enable the sink path for a positive charge + * control limit. If the requested charge port is a source, update the + * power role. + */ + int ret; + bool sink_path = false; + + if (val->intval >= 0) { + sink_path = true; + if (!con->typec_cap.ops || !con->typec_cap.ops->pr_set) + return -EINVAL; + + ret = con->typec_cap.ops->pr_set(con->port, TYPEC_SINK); + if (ret < 0) + return ret; + } + + return ucsi_set_sink_path(con, sink_path); +} + +static int ucsi_psy_set_prop(struct power_supply *psy, + enum power_supply_property psp, + const union power_supply_propval *val) +{ + struct ucsi_connector *con = power_supply_get_drvdata(psy); + + switch (psp) { + case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX: + return ucsi_psy_set_charge_control_limit_max(con, val); default: return -EINVAL; } } +static int ucsi_psy_prop_is_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + return psp == POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX; +} + static enum power_supply_usb_type ucsi_psy_usb_types[] = { POWER_SUPPLY_USB_TYPE_C, POWER_SUPPLY_USB_TYPE_PD, @@ -308,6 +358,8 @@ int ucsi_register_port_psy(struct ucsi_connector *con) con->psy_desc.properties = ucsi_psy_props; con->psy_desc.num_properties = ARRAY_SIZE(ucsi_psy_props); con->psy_desc.get_property = ucsi_psy_get_prop; + con->psy_desc.set_property = ucsi_psy_set_prop; + con->psy_desc.property_is_writeable = ucsi_psy_prop_is_writeable; con->psy = power_supply_register(dev, &con->psy_desc, &psy_cfg); diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index dcd3765cc1f5..02663fdebdd9 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1545,6 +1545,21 @@ static const struct typec_operations ucsi_ops = { .pr_set = ucsi_pr_swap }; +int ucsi_set_sink_path(struct ucsi_connector *con, bool sink_path) +{ + struct ucsi *ucsi = con->ucsi; + u64 command; + int ret; + + command = UCSI_SET_SINK_PATH | UCSI_CONNECTOR_NUMBER(con->num); + command |= UCSI_SET_SINK_PATH_SINK_PATH(sink_path); + ret = ucsi_send_command(ucsi, command, NULL, 0); + if (ret < 0) + dev_err(con->ucsi->dev, "SET_SINK_PATH failed (%d)\n", ret); + + return ret; +} + /* Caller must call fwnode_handle_put() after use */ static struct fwnode_handle *ucsi_find_fwnode(struct ucsi_connector *con) { diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 57129f3c0814..6a958eac5703 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -114,6 +114,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num); #define UCSI_GET_CONNECTOR_STATUS 0x12 #define UCSI_GET_ERROR_STATUS 0x13 #define UCSI_GET_PD_MESSAGE 0x15 +#define UCSI_SET_SINK_PATH 0x1c #define UCSI_CONNECTOR_NUMBER(_num_) ((u64)(_num_) << 16) #define UCSI_COMMAND(_cmd_) ((_cmd_) & 0xff) @@ -187,6 +188,9 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num); #define UCSI_GET_PD_MESSAGE_TYPE_IDENTITY 4 #define UCSI_GET_PD_MESSAGE_TYPE_REVISION 5 +/* SET_SINK_PATH command bits */ +#define UCSI_SET_SINK_PATH_SINK_PATH(_r_) (((_r_) ? 1 : 0) << 23) + /* -------------------------------------------------------------------------- */ /* Error information returned by PPM in response to GET_ERROR_STATUS command. */ @@ -492,6 +496,7 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command, void ucsi_altmode_update_active(struct ucsi_connector *con); int ucsi_resume(struct ucsi *ucsi); +int ucsi_set_sink_path(struct ucsi_connector *con, bool sink_path); void ucsi_notify_common(struct ucsi *ucsi, u32 cci); int ucsi_sync_control_common(struct ucsi *ucsi, u64 command); From patchwork Wed Jul 24 20:11:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jameson Thies X-Patchwork-Id: 13741320 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 4623716F26D for ; Wed, 24 Jul 2024 20:12:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721851948; cv=none; b=oFAlXaJzPjaByKSena9hvht808UAbzLXntg7zPg9dbz+8+YHR5wuI/slUVv1l91FG7EVSeLf7QjEGRfoyx9lI9cKe408uRXWm1RewWo1RWegi2lEcuGP6WtJXxD7k2FpozKC++DapeRXjhw23cGjVtKj5KFdewTM8OXE1x3Qed4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721851948; c=relaxed/simple; bh=ftKGBViUOgmYn6lD6rKdnKxeD3XcFNArhW8Gz6/ov7g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UO+UfituS9Z/gP/LoOBw9oIzfWrDftlN8h3MR7xiyMSbH1sEEuQ//ldde4WtP06qWWxu6i1v+GKI6RE7Ppx3XJsTS6olw3e849VB2yWtOjkjf+irJsY+P7PWhoElxtcH5ut9LyhY7760AGgir4deAXfUCEuv2mnOCkSR/anqGM4= 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=YLXHRLuW; arc=none smtp.client-ip=209.85.219.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="YLXHRLuW" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e02b5792baaso238530276.2 for ; Wed, 24 Jul 2024 13:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721851946; x=1722456746; 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=x9PT/6cjnR+Gnm6WIJzoVk3JaTZqlTM7UT6q82pMzX8=; b=YLXHRLuWDD0xy6ohmfotgN+90XuBk1tBb7fWP+wEPbP0/LwralxlcJxd62hBFFaSWX svuXaKhfVQogTbbKxk6YCLbAtEUKwXQSwnSfgsMUW0XJtR7hhbW1BnVIjMP7rErNd25J LCVq19pdRyrkXqNPE73bTiGPnutJ0+XJGp4fyLmKk3eaYs4ZDz5gA9WcHhLSdBydJmOR 7ESiJx/OM6ePVqu36PO6rtWw+EV3/ZLReBsb09yWpet+98jqyKWrkn2oguTOntV97Yhe Zw96oJ9Ev2tVzpt/JLJTUE2eC+1DF1W5e2IslWtdWnXAirckIwPe6BDIJiEUhPoueOGT z9fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721851946; x=1722456746; 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=x9PT/6cjnR+Gnm6WIJzoVk3JaTZqlTM7UT6q82pMzX8=; b=sIhXliz2felRS0kU78Ywtts5i8U4NFDM5uRB6yp8T+vyatkBZRMHy58ACjUyRpD9QM XnpRPDo7zApanRwMkyWA0xzxXmJe0YPq7coNbd7SwKRaZ3pX+MOgqDof8t6D/WY7I5ew MUjgTTNAtqw08TIJfgvDqtgDa70OfLYryBAUoi1gjSQITa7rx5256+x/4fkGp4rEA1/3 xzKiJMpF5fZ6Ov/LmZKOJqv//hz8YwUr/Yy1028GYVtgbbEzwYFiqQi6jk9AcrHeJB0K mTUFbhoeWCwpuIY3KoP4QwhpHq/b8jiSBSiGQL7+FB1wUj2BKDToQ/xz5xSpSg7MJHTd mVEQ== X-Forwarded-Encrypted: i=1; AJvYcCXTm4ApGI/VHn0uJ80b/+NcYexVqOfuTjBMhhIjiYOVG+fEYRqRY7BG6xzwOKeJznG7pyuQrsnMsdqSNavVEMzFluZ+bkWHJVPv X-Gm-Message-State: AOJu0YyTU5Mg8zEnVKZDVn5focfrbp0J3Z3+7uhbxl3XIL8kseimUhIf 95pNMWUagxB8vDBNmZQgtB6cj37PZPUYeI+j2t1fmSq1v/d65a8ot93jSOSPSqmWUFUWkPQEWDB 7WQ== X-Google-Smtp-Source: AGHT+IEZtWnLjP/SYhqErAI4vD+nBsv+e3S+tTON9apiX87M2tONY2ATm4vpw94egaaQQU8IqgOAGcYzxBE= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:110e:b0:e05:b006:9e12 with SMTP id 3f1490d57ef6-e0b23239497mr30065276.11.1721851946331; Wed, 24 Jul 2024 13:12:26 -0700 (PDT) Date: Wed, 24 Jul 2024 20:11:16 +0000 In-Reply-To: <20240724201116.2094059-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240724201116.2094059-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240724201116.2094059-5-jthies@google.com> Subject: [PATCH v2 4/4] usb: typec: ucsi: Fix SET_PDR typo in UCSI header file From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Fix SET_PDR typo in UCSI header file. Reviewed-by: Neil Armstrong Signed-off-by: Jameson Thies --- Changes in V2: - None. drivers/usb/typec/ucsi/ucsi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 6a958eac5703..a0e91335da80 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -153,7 +153,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num); #define UCSI_SET_UOR_ROLE(_r_) (((_r_) == TYPEC_HOST ? 1 : 2) << 23) #define UCSI_SET_UOR_ACCEPT_ROLE_SWAPS BIT(25) -/* SET_PDF command bits */ +/* SET_PDR command bits */ #define UCSI_SET_PDR_ROLE(_r_) (((_r_) == TYPEC_SOURCE ? 1 : 2) << 23) #define UCSI_SET_PDR_ACCEPT_ROLE_SWAPS BIT(25)