usb: typec: tcpci: set local CC to Rd only when cc1/cc2 status is Rp
authorXu Yang <xu.yang_2@nxp.com>
Wed, 11 Dec 2024 10:57:53 +0000 (18:57 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 23 Dec 2024 17:40:46 +0000 (18:40 +0100)
The cc1 and cc2 status returned by tcpci_get_cc() may be TYPEC_CC_OPEN
or TYPEC_CC_RA. So don't assume it's just TYPEC_CC_RD or TYPEC_CC_RP_*.
This will let local port present Rd on CC only when cc1/cc2 status is
TYPEC_CC_RP_*.

Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20241211105753.1205312-1-xu.yang_2@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tcpm/tcpci.c

index ed32583829bec21ffa1e907aa7757e0d59795f4e..2f15734a5043b4a342c81e3d19465456a850839e 100644 (file)
@@ -282,7 +282,7 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc,
                        if (cc2 == TYPEC_CC_RD)
                                /* Role control would have the Rp setting when DRP was enabled */
                                reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP);
-                       else
+                       else if (cc2 >= TYPEC_CC_RP_DEF)
                                reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD);
                } else {
                        reg &= ~TCPC_ROLE_CTRL_CC1;
@@ -290,7 +290,7 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc,
                        if (cc1 == TYPEC_CC_RD)
                                /* Role control would have the Rp setting when DRP was enabled */
                                reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP);
-                       else
+                       else if (cc1 >= TYPEC_CC_RP_DEF)
                                reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD);
                }
        }