From: Guenter Roeck <linux@roeck-us.net>
To: Frank Wang <frank.wang@rock-chips.com>,
heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org,
sebastian.reichel@collabora.com, 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
Subject: Re: [v4,2/2] usb: typec: tcpm: add get max power support
Date: Fri, 16 Jun 2023 01:36:54 -0700 [thread overview]
Message-ID: <df28b348-28c4-a1ef-1d7e-46a60911ebc4@roeck-us.net> (raw)
In-Reply-To: <20230616075241.27690-2-frank.wang@rock-chips.com>
On 6/16/23 00:52, Frank Wang wrote:
> 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>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> Changelog:
> v4:
> - No change
>
> v3:
> - Use Microwatts instead of Milliwatts to follow the ABI, commented by Sebastian Reichel.
>
> v2:
> - No change
>
> v1:
> - https://patchwork.kernel.org/project/linux-usb/patch/20230313025843.17162-4-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 9f6aaa3e70ca8..829d75ebab422 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -6340,6 +6340,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_uw = 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;
> + max_src_uw = tmp > max_src_uw ? tmp : max_src_uw;
> + }
> + }
> +
> + val->intval = max_src_uw;
> + return 0;
> +}
> +
> static int tcpm_psy_get_prop(struct power_supply *psy,
> enum power_supply_property psp,
> union power_supply_propval *val)
> @@ -6369,6 +6390,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;
next prev parent reply other threads:[~2023-06-16 8:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 7:52 [v4,1/2] usb: typec: tcpm: fix cc role at port reset Frank Wang
2023-06-16 7:52 ` [v4,2/2] usb: typec: tcpm: add get max power support Frank Wang
2023-06-16 8:36 ` Guenter Roeck [this message]
2023-06-26 8:39 ` Heikki Krogerus
2023-06-16 8:33 ` [v4,1/2] usb: typec: tcpm: fix cc role at port reset Guenter Roeck
2023-06-26 8:35 ` Heikki Krogerus
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=df28b348-28c4-a1ef-1d7e-46a60911ebc4@roeck-us.net \
--to=linux@roeck-us.net \
--cc=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=sebastian.reichel@collabora.com \
--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