Fix some defects related Type-C TCPM
Subsystems (4)
PATCH v2 1/3 usb: typec: tcpm: fix cc role at port reset
In reply to Frank WangIn the current implementation, the tcpm set CC1/CC2 role to open when it do port reset would cause the VBUS removed by the Type-C partner.
This sets CC1/CC2 according to the default state of port to fix it.
--- drivers/usb/typec/tcpm/tcpm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/typec/tcpm/tcpm.c +2 -1
@@ -4851,7 +4851,8 @@ static void run_state_machine(struct tcpm_port *port)break ;case PORT_RESET :tcpm_reset_port (port); -tcpm_set_cc (port,TYPEC_CC_OPEN ); +tcpm_set_cc (port,tcpm_default_state (port) ==SNK_UNATTACHED ? +TYPEC_CC_RD :tcpm_rp_cc (port));tcpm_set_state (port,PORT_RESET_WAIT_OFF ,PD_T_ERROR_RECOVERY );break ;
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH RESEND v2 2/3 usb: typec: tcpm: fix multiple times discover svids error
In reply to Frank WangPD3.0 Spec 6.4.4.3.2 say that only Responder supports 12 or more SVIDs, the Discover SVIDs Command Shall be executed multiple times until a Discover SVIDs VDO is returned ending either with a SVID value of 0x0000 in the last part of the last VDO or with a VDO containing two SVIDs with values of 0x0000.
In the current implementation, if the last VDO does not find that the Discover SVIDs Command would be executed multiple times even if the Responder SVIDs are less than 12, and we found some odd dockers just meet this case. So fix it.
--- drivers/usb/typec/tcpm/tcpm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/usb/typec/tcpm/tcpm.c +15 -1
@@ -1515,7 +1515,21 @@ static bool svdm_consume_svids(struct tcpm_port *port, const u32 *p, int cnt) pmdata->svids[pmdata->nsvids++] = svid;tcpm_log (port,"SVID %d: 0x%x" , pmdata->nsvids, svid); } -return true; + +/* +* PD3.0 Spec 6.4.4.3.2: The SVIDs are returned 2 per VDO (see Table +* 6-43), and can be returned maximum 6 VDOs per response (see Figure +* 6-19). If the Respondersupports 12 or more SVID then the Discover +* SVIDs Command Shall be executed multiple times until a Discover +* SVIDs VDO is returned ending either with a SVID value of 0x0000 in +* the last part of the last VDO or with a VDO containing two SVIDs +* with values of 0x0000. +* +* However, some odd dockers support SVIDs less than 12 but without +* 0x0000 in the last VDO, so we need to break the Discover SVIDs +* request and return false here. +*/ +return cnt ==7 ; abort:tcpm_log (port,"SVID_DISCOVERY_MAX(%d) too low!" ,SVID_DISCOVERY_MAX );return false;
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH v2 3/3 usb: typec: tcpm: add get max power support
In reply to Frank WangTraverse 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.
--- drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +24 -0
@@ -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; +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 ;
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
v2 cover Fix some defects related Type-C TCPM
This series fix some defects of TCPM like port reset error, SVIDs discover error and etc.
Tested on Rockchip EVB board integrated with FUSB302 or HUSB311 Type-C controller.
Changes in v2:
- Make some tweaking based on Guenter and Heikki's comments for [PATCH 1/3] and [PATCH 2/3].
- Abandon [PATCH 4/4] in v1.
Frank Wang (3):
usb: typec: tcpm: fix cc role at port reset
usb: typec: tcpm: fix multiple times discover svids error
usb: typec: tcpm: add get max power support
drivers/usb/typec/tcpm/tcpm.c | 43 +++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-)
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
In reply to Frank WangHi,
Quoted 25 lines · Frank Wang
Traverse fixed pdos to calculate the maximum power that the charger can provide, and it can be get by
POWER_SUPPLY_PROP_INPUT_POWER_LIMITproperty.Signed-off-by Frank Wang <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)drivers/usb/typec/tcpm/tcpm.c +8
-0@@ -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];
drivers/usb/typec/tcpm/tcpm.c static int tcpm_psy_get_current_now(struct tcpm_port *port, · line 6340
Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +10
-0+ +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.
-- Sebastian
Quoted 19 lines
drivers/usb/typec/tcpm/tcpm.c +6
-0+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 ;Signature · 1 line
2.17.1
Re: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
Hi Sebastian,
Quoted 31 lines · Sebastian Reichel
Hi,
Quoted 28 lines · Frank Wang
Traverse fixed pdos to calculate the maximum power that the charger can provide, and it can be get by
POWER_SUPPLY_PROP_INPUT_POWER_LIMITproperty.Signed-off-by Frank Wang <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)drivers/usb/typec/tcpm/tcpm.c +11
-0@@ -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);
Quoted 8 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_psy_get_current_now(struct tcpm_port *port, · line 6340
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +7
-0+ 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
Quoted 21 lines
-- Sebastian
Quoted 19 lines
drivers/usb/typec/tcpm/tcpm.c +6
-0+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 ;Signature · 1 line
2.17.1
Re: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
Hi,
Quoted 38 lines · Frank Wang
Quoted 28 lines · Sebastian Reichel
Quoted 27 lines · Frank Wang
Traverse fixed pdos to calculate the maximum power that the charger can provide, and it can be get by
POWER_SUPPLY_PROP_INPUT_POWER_LIMITproperty.Signed-off-by Frank Wang <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)drivers/usb/typec/tcpm/tcpm.c +11
-0@@ -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);Quoted 8 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_psy_get_current_now(struct tcpm_port *port, · line 6340
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +7
-0+ 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.
Quoted 2 lines
Yes, but I see the '
power_supply_propval' member 'intval' is an integer type, I worry about it may be overflowed that uses Microwatts.
Data being encoded in Microwatts is part of the ABI. The data you are supplying will be interpreted in µW. If you submit your data in mW it is basically always wrong even without an overflow.
Now regarding the overflow: A signed int can store 2^31 bit, so 2,147,483,648 µW = 2147 W. Looking at your code you effectively calculate Microwatts in an unsigned int and then divide by 1000. Since the intermediate value (before dividing by 1000) needs to be stored you gain only one bit. That raises the question: Why do you expect data to be between 2147 W and 4294 W when the latest released USB PD spec allows 5A@48V = 240W?
-- Sebastian
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
Hi Sebastian,
Quoted 54 lines · Sebastian Reichel
Hi,
Quoted 37 lines · Frank Wang
Quoted 28 lines · Sebastian Reichel
Quoted 27 lines · Frank Wang
Traverse fixed pdos to calculate the maximum power that the charger can provide, and it can be get by
POWER_SUPPLY_PROP_INPUT_POWER_LIMITproperty.Signed-off-by Frank Wang <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)drivers/usb/typec/tcpm/tcpm.c +11
-0@@ -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);Quoted 8 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_psy_get_current_now(struct tcpm_port *port, · line 6340
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +7
-0+ 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.
Quoted 2 lines
Yes, but I see the '
power_supply_propval' member 'intval' is an integer type, I worry about it may be overflowed that uses Microwatts.Data being encoded in Microwatts is part of the ABI. The data you are supplying will be interpreted in µW. If you submit your data in mW it is basically always wrong even without an overflow.
Now regarding the overflow: A signed int can store 2^31 bit, so 2,147,483,648 µW = 2147 W. Looking at your code you effectively calculate Microwatts in an unsigned int and then divide by 1000. Since the intermediate value (before dividing by 1000) needs to be stored you gain only one bit. That raises the question: Why do you expect data to be between 2147 W and 4294 W when the latest released USB PD spec allows 5A@48V = 240W?
Quoted 1 line
-- Sebastian
Okay, got it, I shall delete conversion codes ( divide by 1000 ) in the next version.
BR.
Frank
Re: [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset
In reply to Frank WangHi Guenter and Heikki,
Quoted 15 lines · Frank Wang
In the current implementation, the tcpm set CC1/CC2 role to open when it do port reset would cause the VBUS removed by the Type-C partner.
This sets CC1/CC2 according to the default state of port to fix it.
Signed-off-by Frank Wang <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/usb/typec/tcpm/tcpm.c +0
-0
drivers/usb/typec/tcpm/tcpm.c static void run_state_machine(struct tcpm_port *port) · line 4858
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +2
-1@@ -4851,7 +4851,8 @@ static void run_state_machine(struct tcpm_port *port)break ;case PORT_RESET :tcpm_reset_port (port); -tcpm_set_cc (port,TYPEC_CC_OPEN ); +tcpm_set_cc (port,tcpm_default_state (port) ==SNK_UNATTACHED ? +TYPEC_CC_RD :tcpm_rp_cc (port));tcpm_set_state (port,PORT_RESET_WAIT_OFF ,PD_T_ERROR_RECOVERY );break ;
Can you help to review this patch again?
BR.
Frank