From: Frank Wang <frank.wang@rock-chips.com>
To: linux@roeck-us.net, heikki.krogerus@linux.intel.com,
gregkh@linuxfoundation.org, heiko@sntech.de
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rockchip@lists.infradead.org, huangtao@rock-chips.com,
william.wu@rock-chips.com, jianwei.zheng@rock-chips.com,
yubing.zhang@rock-chips.com, wmc@rock-chips.com,
Frank Wang <frank.wang@rock-chips.com>
Subject: [PATCH 3/4] usb: typec: tcpm: add get max power support
Date: Mon, 13 Mar 2023 10:58:42 +0800 [thread overview]
Message-ID: <20230313025843.17162-4-frank.wang@rock-chips.com> (raw)
In-Reply-To: <20230313025843.17162-1-frank.wang@rock-chips.com>
Traverse fixed pdos to calculate the maximum power that the charger
can provide, and it can be get by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
property.
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
---
drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 2962f7c261976..9e583060e64fc 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -6319,6 +6319,27 @@ static int tcpm_psy_get_current_now(struct tcpm_port *port,
return 0;
}
+static int tcpm_psy_get_input_power_limit(struct tcpm_port *port,
+ union power_supply_propval *val)
+{
+ unsigned int src_mv, src_ma, max_src_mw = 0;
+ unsigned int i, tmp;
+
+ for (i = 0; i < port->nr_source_caps; i++) {
+ u32 pdo = port->source_caps[i];
+
+ if (pdo_type(pdo) == PDO_TYPE_FIXED) {
+ src_mv = pdo_fixed_voltage(pdo);
+ src_ma = pdo_max_current(pdo);
+ tmp = src_mv * src_ma / 1000;
+ max_src_mw = tmp > max_src_mw ? tmp : max_src_mw;
+ }
+ }
+
+ val->intval = max_src_mw;
+ return 0;
+}
+
static int tcpm_psy_get_prop(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
@@ -6348,6 +6369,9 @@ static int tcpm_psy_get_prop(struct power_supply *psy,
case POWER_SUPPLY_PROP_CURRENT_NOW:
ret = tcpm_psy_get_current_now(port, val);
break;
+ case POWER_SUPPLY_PROP_INPUT_POWER_LIMIT:
+ tcpm_psy_get_input_power_limit(port, val);
+ break;
default:
ret = -EINVAL;
break;
--
2.17.1
next prev parent reply other threads:[~2023-03-13 3:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 2:58 [PATCH 0/4] Fix some defects related Type-C TCPM Frank Wang
2023-03-13 2:58 ` [PATCH 1/4] usb: typec: tcpm: fix cc role at port reset Frank Wang
2023-03-14 9:20 ` Heikki Krogerus
2023-03-15 2:55 ` Frank Wang
2023-03-17 11:24 ` Heikki Krogerus
2023-03-17 12:47 ` Guenter Roeck
2023-03-20 2:28 ` Frank Wang
2023-03-13 2:58 ` [PATCH 2/4] usb: typec: tcpm: fix multiple times discover svids error Frank Wang
2023-03-14 9:22 ` Heikki Krogerus
2023-03-15 2:57 ` Frank Wang
2023-03-13 2:58 ` Frank Wang [this message]
2023-03-13 2:58 ` [PATCH 4/4] usb: typec: tcpm: fix source caps may lost after soft reset Frank Wang
2023-03-17 12:58 ` Guenter Roeck
2023-03-20 2:38 ` Frank Wang
2023-03-20 3:35 ` Guenter Roeck
2023-03-20 6:28 ` Frank Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230313025843.17162-4-frank.wang@rock-chips.com \
--to=frank.wang@rock-chips.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=heiko@sntech.de \
--cc=huangtao@rock-chips.com \
--cc=jianwei.zheng@rock-chips.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=william.wu@rock-chips.com \
--cc=wmc@rock-chips.com \
--cc=yubing.zhang@rock-chips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).