From: Frank Wang <frank.wang@rock-chips.com>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: linux@roeck-us.net, heikki.krogerus@linux.intel.com,
gregkh@linuxfoundation.org, heiko@sntech.de,
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: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
Date: Tue, 21 Mar 2023 09:32:53 +0800 [thread overview]
Message-ID: <19b39d82-8510-2717-cf3b-71cb955373d0@rock-chips.com> (raw)
In-Reply-To: <20230320203139.quld3gmoo6esu56i@mercury.elektranox.org>
Hi Sebastian,
On 2023/3/21 4:31, Sebastian Reichel wrote:
> Hi,
>
> On Mon, Mar 20, 2023 at 06:07:11PM +0800, 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>
>> ---
>> 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 13830b5e2d09f..d6ad3cdf9e4af 100644
>> --- a/drivers/usb/typec/tcpm/tcpm.c
>> +++ b/drivers/usb/typec/tcpm/tcpm.c
>> @@ -6320,6 +6320,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;
> The power-supply subsystem expects Microwatts and not Milliwatts.
Yes, but I see the 'power_supply_propval' member 'intval' is an integer
type, I worry about it may be overflowed that uses Microwatts.
BR.
Frank
> -- Sebastian
>
>> + return 0;
>> +}
>> +
>> static int tcpm_psy_get_prop(struct power_supply *psy,
>> enum power_supply_property psp,
>> union power_supply_propval *val)
>> @@ -6349,6 +6370,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-21 1:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-20 10:07 [PATCH v2 0/3] Fix some defects related Type-C TCPM Frank Wang
2023-03-20 10:07 ` [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset Frank Wang
2023-04-25 3:01 ` Frank Wang
2023-03-20 10:07 ` [RESEND PATCH v2 2/3] usb: typec: tcpm: fix multiple times discover svids error Frank Wang
2023-03-20 10:07 ` [PATCH v2 3/3] usb: typec: tcpm: add get max power support Frank Wang
2023-03-20 20:31 ` Sebastian Reichel
2023-03-21 1:32 ` Frank Wang [this message]
2023-03-21 5:00 ` Sebastian Reichel
2023-03-21 9:54 ` 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=19b39d82-8510-2717-cf3b-71cb955373d0@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=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
all inboxes | Powered by JetHome®