From nobody Wed Dec 17 15:34:53 2025 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 7D94D3C00 for ; Wed, 17 Jul 2024 00:51:24 +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=1721177485; cv=none; b=BSYG4wv/n9G4I43spm6P/mcsp/6PtWDNDQoKoP5uWi5VsDuh3XURoLfYQeFZH67bRH6RaExr7JAFOpyYcT6L9CgF7Zlnyn9JGfIdcf9GI4U7bi28wxrrX2gn2QxuPlxMRgWaS1iUDHEOWOn+emKeiRDa3vs7J+dZ5MYkj1gnw5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177485; c=relaxed/simple; bh=rtFrRQ4rFy9iHSqIJgEhQebrOvlDgtJBnPfjcOkYxIU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dPDLjS+wXWTbmumQ6hhYNXVYfk4yHtaLhycu/WbkPnsyPdjhawfYer2eVTYYGMqFrdDvAOn+IFOkvk85bfhqH048jDrvaSGiQczPRQFG+Ei5kqpyL7aDWAcW6dqR+rd7jHMk7jeIuNR5CGYHYEt2M1x0COi7F3Q4u6hzEGiWm8o= 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=b3Iz29rY; 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="b3Iz29rY" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e036150efc6so10734820276.2 for ; Tue, 16 Jul 2024 17:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721177483; x=1721782283; 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=lZfO2IpnB7bc3YW/PTDqptNxNpOawD6JRjU0h2mR8Jg=; b=b3Iz29rYEG1T3ucw5yrRRO3ZZ9BlbBwUaCzS50QP2Ff2OTwc/ljrJShW+bvIPyF5+v Xjz8koT9uQ6VBJzA5zLw/YNQ9GYGT5yStvWrBlu2SQb6xFJPntPTVi8eaOTPgUac5/AC N7p20o3EycGCoYYuGTchdzFBMuzdIV4dldsg+Ib9GFdJuY6VmqiwXN0ABTFmIJ6efpjm PU6ijdOz326eaPNCRbvp2ZVxD58KhQ+1y22N2vod89gr0jrtLuopx/pBM+gzD2Xg/ulF P44wXEz7KYY1NB3KUzkBn9G+HNKDH2Wm0uhH43qWDu/R4Bqyb6A0BydwzyBCpOjD8Bxv BGUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721177483; x=1721782283; 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=lZfO2IpnB7bc3YW/PTDqptNxNpOawD6JRjU0h2mR8Jg=; b=U+8Q5t9RRWboDOJt65CmNdA6ZLUmLZJwKNWBgLC1UI8HW9OIC9lEhRlLQcXBW+DljV 8ZWVFwu+uxhZ0JHaERVKe+NaR9/EE5kKfMxpJ7DQPWf2AUcdSvc1/cOZQsistt0HxZnN UOAdupopkLc3YTVDRBoBjU9Ba40TOh2NHkSUuS++wI4XQPBj4bjA63w4XBxWwRrhYXtu HeCwTalQv7Mr136dRkIFyV7yJq9/NSOGiStb3QOfGxgfe4Y0CqNr62uCWhUPeWzTrFuG 7asIEQy0gZK6F+Fdn9hiQdIi3QaIfYEj8p4ff5ypl5sE/tB+Zr0ZSGk8L4o3TNY4WWKc Q17g== X-Forwarded-Encrypted: i=1; AJvYcCVb/vdLoAm/0gSf6DHstIw0wMvDeamR+LRaH6To7mEwBi9LRZ9mJtNg8hCJe1D5bwZcwJt43xNTWJsmBuKx7ZuIzWcUXWEG+TruFSnd X-Gm-Message-State: AOJu0YzwRIPvL5Wz2vC0lr55AQNCItbj3jiGsdhnRz11pDa+hakadcbA MNbNE5niwgNWQgcInSNhnsIshg/Ic0wFRYtf1WXcI5ypZ4g4Inb+kKO0/d68rWZ1pQm8q1YWElx qEw== X-Google-Smtp-Source: AGHT+IHn69xVfaZrAZa13CCuMoUt0BnnEiwyRbQOQS68ztFEUUQVny+N76Q4ts71rDSaIim5mgpGHu6Hias= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:140a:b0:e03:5312:c053 with SMTP id 3f1490d57ef6-e05ed6fdc1bmr322276.7.1721177483369; Tue, 16 Jul 2024 17:51:23 -0700 (PDT) Date: Wed, 17 Jul 2024 00:49:46 +0000 In-Reply-To: <20240717004949.3638557-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: <20240717004949.3638557-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240717004949.3638557-2-jthies@google.com> Subject: [PATCH v1 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add status to UCSI power supply driver properties based on the port's connection and power direction states. Signed-off-by: Jameson Thies --- 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[] =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,20 @@ 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) +{ + val->intval =3D POWER_SUPPLY_STATUS_NOT_CHARGING; + if (con->status.flags & UCSI_CONSTAT_CONNECTED) { + if ((con->status.flags & UCSI_CONSTAT_PWR_DIR) =3D=3D TYPEC_SINK) + val->intval =3D POWER_SUPPLY_STATUS_CHARGING; + else + val->intval =3D 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; } --=20 2.45.2.1089.g2a221341d9-goog From nobody Wed Dec 17 15:34:53 2025 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 269B18493 for ; Wed, 17 Jul 2024 00:51:27 +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=1721177489; cv=none; b=eHW7O26DzswqLq7ykqo7bS+QCGm3JdaT4CTDVZ3agfABwTtBh8QgQXPh9ciqVhyk23qRwrPhXLQTua2EeEArl5nb8kgakpcB68tWpQ1xXUXEFWtyg5np6M59T2X77IxWSJrCdeE6PrHWNVYpQqOlKCZn5EuMLQnoE9BiAOkTL5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177489; c=relaxed/simple; bh=imrdTBKFl9/ler02ONXWrJRcIjmutDnfzz+XiKEiY3w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HqEJrO05+t0tSWV3akTbGPXehMobyr1MPdxOkHLvRFMOJVsUKGDNrrdRcO/UDNy+iGGP88+caiVkYEQekhdfL6HHOvUKROkqf7n9e7BFIJ2yjjS8j59qqIUFtacTcrjkPOxM9kLf3JkG4DFagA3Gyqiz47uTNDv9QC2tJlizsC8= 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=uyEn5/QS; 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="uyEn5/QS" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-650fccfd1dfso113671767b3.0 for ; Tue, 16 Jul 2024 17:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721177487; x=1721782287; 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=ssDYc+w2ZBOTZEW4SaOXob+zs6JJwedZnb8idSmatOU=; b=uyEn5/QS8n3nHDLDaN/Do694H85t8KqwVDP0WL9KiSf7eUfr8HuGb8GzasWKojQD56 wqIu2tshIeHy5U9x+ass+kgnv2vhwOTbqGxNlUSggrOBi7P+2YmOgLkxU+8nEty/INg/ hZ7rz5G8amu7n4axw51bI6EkslGvSQRHBmlSEO+FlBw0qyBok+nfNTyNZ8NCI1f37IXe qSuJ4b7+GkNCn5FWqgAbGZVBLmSTA62bmFmrdtfr5RSylYInMIrxISoHiGt2JL/+S5pT iey4mQWEFGXWxKnjBaAAxjNJlWfAkGpx0Cyt78cgb2TDleUCVUYXgmOLfciQna+Z6n51 PmNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721177487; x=1721782287; 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=ssDYc+w2ZBOTZEW4SaOXob+zs6JJwedZnb8idSmatOU=; b=tQOaNLrFLTok+lpKY402Ot+iU0VrL7DmIV2D2dm06d6QgXxfpEb2sB7n0VzLw56J21 j4qHIvwV6xU2u1PTIyAmqxUk5tALSDPyhBPEXPiL96FDh4m5IzXz5YPzxG+S2xiBWGli F7L5VU4a9EdQhCyK1ZBO+Tifb4GNKVRNwRun9it3aXDudIP5437gosdJTHzOmyu0YPYB 6//PMwNT2zeCxvNJg9cUyE3RQGBYxB75iErvTEP/koElW/hCt3sI/m8b7LzUvl4TsxB2 YRdDC7Mv/Io/nd5WDOuo9asJJy9xnstcr225D9mxj5mpYrCBawOQqquk6gXt9QROpbWs HuWA== X-Forwarded-Encrypted: i=1; AJvYcCVvVfbmjrRaEGPVGcuJ9U3Cx0/N2U6/czAWW9piRVmaDvIUiuuLWTlqYgit6giOVnW9AbNrN9hJmjhMvLJX3ZDJ4bI4mCPVm4Oy374B X-Gm-Message-State: AOJu0Yxcq0XMEb4fQLI7dna5c4zG0ZpQF+2ghukwFq0bN3xsMs2rmP1J wMMNnkzUDQhiuUlBiGxscVrNNKNZQ8CgOtIsH7xvPBnousn7v8W4RHA8ChGQxsy3wulu1aKiXKi Qhg== X-Google-Smtp-Source: AGHT+IGfziVk8mk/t5qqLgrjh2nAuQB6H4AHqRgQ9isrB7miUbLCHuZyYh4XWKyG4GLGSr/PpOKF+I1vupI= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:660f:b0:62a:2a39:ccd9 with SMTP id 00721157ae682-66500955504mr5567b3.6.1721177487061; Tue, 16 Jul 2024 17:51:27 -0700 (PDT) Date: Wed, 17 Jul 2024 00:49:47 +0000 In-Reply-To: <20240717004949.3638557-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: <20240717004949.3638557-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240717004949.3638557-3-jthies@google.com> Subject: [PATCH v1 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 supports USB PD and offers both source and sink PDOs. Signed-off-by: Jameson Thies --- drivers/usb/typec/ucsi/psy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index d0b52cee41d2..45113e013696 100644 --- a/drivers/usb/typec/ucsi/psy.c +++ b/drivers/usb/typec/ucsi/psy.c @@ -204,8 +204,12 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector= *con, =20 val->intval =3D POWER_SUPPLY_USB_TYPE_C; if (flags & UCSI_CONSTAT_CONNECTED && - UCSI_CONSTAT_PWR_OPMODE(flags) =3D=3D UCSI_CONSTAT_PWR_OPMODE_PD) - val->intval =3D POWER_SUPPLY_USB_TYPE_PD; + UCSI_CONSTAT_PWR_OPMODE(flags) =3D=3D UCSI_CONSTAT_PWR_OPMODE_PD) { + if (!con->partner_source_caps || !con->partner_sink_caps) + val->intval =3D POWER_SUPPLY_USB_TYPE_PD; + else + val->intval =3D POWER_SUPPLY_USB_TYPE_PD_DRP; + } =20 return 0; } @@ -275,6 +279,7 @@ static enum power_supply_usb_type ucsi_psy_usb_types[] = =3D { POWER_SUPPLY_USB_TYPE_C, POWER_SUPPLY_USB_TYPE_PD, POWER_SUPPLY_USB_TYPE_PD_PPS, + POWER_SUPPLY_USB_TYPE_PD_DRP, }; =20 int ucsi_register_port_psy(struct ucsi_connector *con) --=20 2.45.2.1089.g2a221341d9-goog From nobody Wed Dec 17 15:34:53 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 C9548BA4B for ; Wed, 17 Jul 2024 00:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177495; cv=none; b=bYa69w+B0ogF3Zd/l831iiawL88/eNQR9WtYPDY5HjXUdxdaPi49kQpKTNq6ags9Gq9yc2VueaJO47lTn/g6QBKbea2XWY56xVOkOFHMKonQCxUqsaRrZqXLNeDVSf3WuiPaCtQr81r8WNzbVfXUy9ZDUH0A6qjczQAAfIJauz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177495; c=relaxed/simple; bh=wj9RriCI5ML0LRKiteJKsLnz30K8rwhCkEtXmY/ViPY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GGjaAOgLwwU34VpoFx3Uy5HZZuavPxXdFIskqpUH3v/idXlIQAQeeeEEOcHMSJYtrfFyYf7U5hxjDgB9iaWx90ihhyTOWqMbaLCcnYs1QeIxcInFel66+HhLgogT8C2We4z9h0mlH5wP4zXLDeOs14QZNO80JSgAmA5ECDYYlwg= 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=yPxj65C2; arc=none smtp.client-ip=209.85.128.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="yPxj65C2" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-650b621f4cdso110020317b3.1 for ; Tue, 16 Jul 2024 17:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721177493; x=1721782293; 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=KQ9sG390GoUWxGLhfPgzLiAx3nRxfoIGsKOr9STNfgY=; b=yPxj65C2aErZD54SikuxNB2HNoHY6vG1zf9wy+xZgQVTOennpZv2FIzSOYiuePBQwY CjeRpBLat6DBOF8SiSuuqJgSwX48SvfNlUQNsnQrmFTULj8Sa9i93hxJbzft5UBqSeiZ qZ8nTVBMjhTs2pz7rnWctwoZCvh5rifHvt/97ogpclYM0EBxSUeEcr+mpyM+wgal7LpI J4k3PyKl2E12dWZaB1cM8tDcR82QFGFqtoFfqYiG1DpoPqyyxnN42d1wnwhh/B0dWDNZ h6nbJBKrhsdRmIbaQf7dFs4cRcZwl38NFlgCZmC87HSSCglAg9I2m4sqrRYdevGHBMoQ 8ThA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721177493; x=1721782293; 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=KQ9sG390GoUWxGLhfPgzLiAx3nRxfoIGsKOr9STNfgY=; b=TzTiAhdeXCk/UiTTCVt1CjjmxAJ8VSZdRXPZYv9Co7QtxVKdu8mGv07DHEMh30BBQP edHD5sogWoOovIaIUDiOjzmZt72kJRhRU0MLxgdF26KsvTbe/+8DoqEfcmEGgM0DT/T7 dQTsO2mllshrkhPL9NvK/015zvaL3hrAUwL45vPOnkfKVBq2olv5rPXUgwOr98pZbRk8 1Vogv7fLxaG7cYOvTkuLiXJ/oUbdlHYzCE+rqUlAzS5ae9vcpPnf4h9v83GIdc6H38VL eLGNH/P5qe+Xk2OWJxtRP4jrxoOQ+u7wic4x8L6YrA2kItU9YL4Kyndhu2nXwbawf6Mt bJ2g== X-Forwarded-Encrypted: i=1; AJvYcCXl661HyzhKi8lFXaz3/THaWer2/2ORD9nRaxkML0mbegN+CC4Sy/tpnBVNA2oVQgcCl+ITWp4CXxyG8+2FCwqAtjRoApVO91c7TURb X-Gm-Message-State: AOJu0Yyd4bkcCJcasE1T9cJd7I3ENL3UHnQlJ3VEHIai3WzNvSF9V5KB T4SKUQ3s4SwT3Go4JDVdc9o7zQyKlV5sx5ABgmC878jiEtwgOCVCS28TvYemkv1x8BMtUbciGNp +FQ== X-Google-Smtp-Source: AGHT+IGs8b8XsKNxd1HsfadHottnqrJ+jqGljW+4HqL2Fv8S5g+1p7Dy4x97Rn7ZN/+IhNZ+4wWiwJpUb7o= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:4:b0:648:3f93:68e0 with SMTP id 00721157ae682-6650066ad75mr9087b3.6.1721177492971; Tue, 16 Jul 2024 17:51:32 -0700 (PDT) Date: Wed, 17 Jul 2024 00:49:48 +0000 In-Reply-To: <20240717004949.3638557-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: <20240717004949.3638557-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240717004949.3638557-4-jthies@google.com> Subject: [PATCH v1 3/4] usb: typec: ucsi: Set power role 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX as a property to the UCSI power supply driver. When set to a negative value, set power role to TYPEC_SOURCE, otherwise set the power role to TYPEC_SINK. Signed-off-by: Jameson Thies --- drivers/usb/typec/ucsi/psy.c | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c index 45113e013696..feb344cb7ac8 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[] =3D { POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, }; =20 static int ucsi_psy_get_scope(struct ucsi_connector *con, @@ -270,11 +271,54 @@ 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 =3D 0; + return 0; + default: + return -EINVAL; + } +} + +static int ucsi_psy_set_charge_control_limit_max(struct ucsi_connector *co= n, + const union power_supply_propval *val) +{ + enum typec_role role; + /* + * Writing a negative value to the charge control limit max implies the + * port should not accept charge. Set the power role to source for a + * negative charge control limit, and sink otherwise. + */ + if (val->intval < 0) + role =3D TYPEC_SOURCE; + else + role =3D TYPEC_SINK; + + if (!con->typec_cap.ops || !con->typec_cap.ops->pr_set) + return -EINVAL; + + return con->typec_cap.ops->pr_set(con->port, role); +} + +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 =3D 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; } } =20 +static int ucsi_psy_prop_is_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + return psp =3D=3D POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX; +} + static enum power_supply_usb_type ucsi_psy_usb_types[] =3D { POWER_SUPPLY_USB_TYPE_C, POWER_SUPPLY_USB_TYPE_PD, @@ -303,6 +347,8 @@ int ucsi_register_port_psy(struct ucsi_connector *con) con->psy_desc.properties =3D ucsi_psy_props; con->psy_desc.num_properties =3D ARRAY_SIZE(ucsi_psy_props); con->psy_desc.get_property =3D ucsi_psy_get_prop; + con->psy_desc.set_property =3D ucsi_psy_set_prop; + con->psy_desc.property_is_writeable =3D ucsi_psy_prop_is_writeable; =20 con->psy =3D power_supply_register(dev, &con->psy_desc, &psy_cfg); =20 --=20 2.45.2.1089.g2a221341d9-goog From nobody Wed Dec 17 15:34:53 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 69D91AD21 for ; Wed, 17 Jul 2024 00:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177497; cv=none; b=S7qbdEusi/k2DmJIXlx1f9fi5g390I8+RnHR+b6lUWuhyDuKGzbxLQljVunb4GxDaxiRUja/GMOpNP7U5HBX6bJkjXOGRCq2qeCiyOjHMu7hSZkY9Ebmc6H9WMIC0FXPCmapUsBKZuxUkAKmptAtov2W83Gw/VgINkwXWR1pXW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721177497; c=relaxed/simple; bh=TxBuHJK85vkREbw0WLP5ADupaB4b16I7uMojTYknRa8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=V9YJX2g8nYnrkcEp4+gIp1NqUzqG/VXfczfHuBAG9EL3MMv/IqnAN2edSLcvoR5heNYSuvqbu1Cb+2UqRTgFkKu3aVE+pldzcXLVMomqAfNc9ZYnhcM6q9dZNERPVSVb2omjQyQVbzyo+E7zceyRUJI3gioXyrJcGmWGGGnTuXU= 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=IQEtIZwq; arc=none smtp.client-ip=209.85.128.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="IQEtIZwq" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-664aa55c690so11263097b3.2 for ; Tue, 16 Jul 2024 17:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721177495; x=1721782295; 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=HTO1tsJpanrsIXuREfXU+lZcoE2mxE9RW1fzcKxRuPY=; b=IQEtIZwqThfL2tkpbppOAJIWrEBFeGp3JwQsUjLtFGvkKsUrCT2pEDg7MyBBoxyUGt ZxUx4caN1wQfl7C4IqBbD0err8tciyYKAN+fRjlQ0V/0ez+9/DnETUu1YAOkrXOXH/jn 8Fg/+yy7AAraMqKS8laXtfRbjiMdBgWsZFn2+DHpJwlmnc74Uav7A8q5+WLs2m4RAkl3 88+Y5ECH4bCBGSqBtID+FiQsBaAyskBiKCFBst4Gxzw4Rds1vSrfTNk89/5aUCg0q0eR EX4d0r7RJkPtjJH+KAZNbiq2sN/C6DjhZ1HCSjTmKSkzSlxirdTo/f/gihcOZOuDeMHf M//w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721177495; x=1721782295; 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=HTO1tsJpanrsIXuREfXU+lZcoE2mxE9RW1fzcKxRuPY=; b=dIlCFjD7eOF7m64RDDB4GnHRMtVMMNj30nZup3if/5NMb9cM/1qIn374q4kFScEY7G mPxlVJVCzhYpNefYNH8Px4ZlygQ2eO4UU0YPV3P0J/X2koSzVkWBtUT9jYlLzlUO/d4c 3p5sx1bRM1PfTUbF+bazHFTMhrwemE7YVd2Bdow+QQMTPjHPR3HeR4p5ykczV01iRDpp Hag3qs0vKZtFgPshUbpX+2q4X6cBu9Hvall5fiElblpNE6ohD81vkRjfQv9BAcn2yQxW +y4maubpaXViKoWnRWVQYOuCvFSXM0TEQPeRjzuBGeOK0u1Req1L6n0XqAq4gxVaoCGo c0rQ== X-Forwarded-Encrypted: i=1; AJvYcCUsIOY0siUTyHvxseQVyjtzT9Im4ncDZ2Qc/wGDqucbSZPAEYkL3BGAy0kdXM2uNrwIocxtzJwc5c/1Wz6PLJQfZBxYOEgje55AgWRB X-Gm-Message-State: AOJu0Yyhi52z0SAy+5UiFWjSByKhTmQ37il81Jcdpr9wBggoRdXOaXzG P03ULNC7XCxFcSMrJEwtcwnC2teQB/uWUGAr32snzb064Lg2hmlbrIhibpak4WbTKUbVDy43COj NvQ== X-Google-Smtp-Source: AGHT+IGg09Ayrrw6aRkughQryryAOlXFSVSJLvjMGLhBlG76jIsoZGI0TJ101PkcfAxrh48DyXAxTN6wUSc= X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:690c:289:b0:65c:4528:d8ee with SMTP id 00721157ae682-664ff0079f7mr6537b3.4.1721177495402; Tue, 16 Jul 2024 17:51:35 -0700 (PDT) Date: Wed, 17 Jul 2024 00:49:49 +0000 In-Reply-To: <20240717004949.3638557-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: <20240717004949.3638557-1-jthies@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240717004949.3638557-5-jthies@google.com> Subject: [PATCH v1 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix SET_PDR typo in UCSI header file. Signed-off-by: Jameson Thies Reviewed-by: Neil Armstrong --- 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 57129f3c0814..375f1881c1e2 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -152,7 +152,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num); #define UCSI_SET_UOR_ROLE(_r_) (((_r_) =3D=3D TYPEC_HOST ? 1 : 2) << 23) #define UCSI_SET_UOR_ACCEPT_ROLE_SWAPS BIT(25) =20 -/* SET_PDF command bits */ +/* SET_PDR command bits */ #define UCSI_SET_PDR_ROLE(_r_) (((_r_) =3D=3D TYPEC_SOURCE ? 1 : 2) << 23) #define UCSI_SET_PDR_ACCEPT_ROLE_SWAPS BIT(25) =20 --=20 2.45.2.1089.g2a221341d9-goog