diff mbox series

usb: typec: tcpm: add get max power support

Message ID 20230616022157.25877-1-frank.wang@rock-chips.com (mailing list archive)
State Accepted
Commit 8be558dcffe69b078b34b1fa93b82acaf4ce4957
Headers show
Series usb: typec: tcpm: add get max power support | expand

Commit Message

Frank Wang June 16, 2023, 2:21 a.m. UTC
Traverse fixed pdos to calculate the maximum power that the charger
can provide, and it can be got 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(+)

Comments

Guenter Roeck June 16, 2023, 2:26 a.m. UTC | #1
On 6/15/23 19:21, Frank Wang wrote:
> Traverse fixed pdos to calculate the maximum power that the charger
> can provide, and it can be got by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
> property.
> 

Wasn't this already v3 before ? What happened to the version, and the change log ?
Or is this a completely different/new patch ?

Guenter

> 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 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;
Frank Wang June 16, 2023, 3:13 a.m. UTC | #2
Hi Guenter,

On 2023/6/16 10:26, Guenter Roeck wrote:
> On 6/15/23 19:21, Frank Wang wrote:
>> Traverse fixed pdos to calculate the maximum power that the charger
>> can provide, and it can be got by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
>> property.
>>
>
> Wasn't this already v3 before ? What happened to the version, and the 
> change log ?
> Or is this a completely different/new patch ?
>

Yes, it is the v3 patch before which has been hold for a long time, 
Gregkh asked me to rebase it  and resubmit, so should I also add an 
"RESEND" tag in subject?


BR.
Frank


> Guenter
>
>> 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 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;
>
Greg KH June 16, 2023, 6:05 a.m. UTC | #3
On Fri, Jun 16, 2023 at 11:13:08AM +0800, Frank Wang wrote:
> Hi Guenter,
> 
> On 2023/6/16 10:26, Guenter Roeck wrote:
> > On 6/15/23 19:21, Frank Wang wrote:
> > > Traverse fixed pdos to calculate the maximum power that the charger
> > > can provide, and it can be got by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
> > > property.
> > > 
> > 
> > Wasn't this already v3 before ? What happened to the version, and the
> > change log ?
> > Or is this a completely different/new patch ?
> > 
> 
> Yes, it is the v3 patch before which has been hold for a long time, Gregkh
> asked me to rebase it  and resubmit, so should I also add an "RESEND" tag in
> subject?

Yes, please do, otherwise we have no idea what is going on here.

Please resend v4 with all of the change information.

thanks,

greg k-h
diff mbox series

Patch

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;