Skip to contentSkip to conversation

usb: typec: fusb302: Fix masking of comparator and bc_lvl interrupts

PATCH In review Ondrej Jirman 3 participants 6 messages Nov 8, 2021 – Nov 15, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: typec: fusb302: Fix masking of comparator and bc_lvl interrupts

The code that enables either BC_LVL or COMP_CHNG interrupt in tcpm_set_cc wrongly assumes that the interrupt is unmasked by writing 1 to the apropriate bit in the mask register. In fact, interrupts are enabled when the mask is 0, so the tcpm_set_cc enables interrupt for COMP_CHNG when it expects BC_LVL interrupt to be enabled.

This causes inability of the driver to recognize cable unplug events in host mode (unplug is recognized only via a COMP_CHNG interrupt).

In device mode this bug was masked by simultaneous triggering of the VBUS change interrupt, because of loss of VBUS when the port peer is providing power.

Fixes 48242e30532b ("usb: typec: fusb302: Revert "Resolve fixed power role contract setup"")
Cc Hans de Goede <[email protected]>
---
 drivers/usb/typec/tcpm/fusb302.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/fusb302.c +4 -2
index 7a2a17866a823..72f9001b07921 100644
@@ -669,25 +669,27 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_COMP_CHNG);
+					     FUSB_REG_MASK_BC_LVL);
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_comp_chng = true;
+		chip->intr_bc_lvl = false;
 		break;
 	case TYPEC_CC_RD:
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_BC_LVL);
+					     FUSB_REG_MASK_COMP_CHNG);
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_bc_lvl = true;
+		chip->intr_comp_chng = false;
 		break;
 	default:
 		break;
Signature · 1 line
2.33.1
Reviewed-by on v2 1/1
#1 lore raw

Hi,

Quoted 9 lines · Ondrej Jirman

The code that enables either BC_LVL or COMP_CHNG interrupt in tcpm_set_cc wrongly assumes that the interrupt is unmasked by writing 1 to the apropriate bit in the mask register. In fact, interrupts are enabled when the mask is 0, so the tcpm_set_cc enables interrupt for COMP_CHNG when it expects BC_LVL interrupt to be enabled.

This causes inability of the driver to recognize cable unplug events in host mode (unplug is recognized only via a COMP_CHNG interrupt).

Quoted 7 lines

In device mode this bug was masked by simultaneous triggering of the VBUS change interrupt, because of loss of VBUS when the port peer is providing power.

Fixes 48242e30532b ("usb: typec: fusb302: Revert "Resolve fixed power role contract setup"")
Cc Hans de Goede <[email protected]>

Thanks, patch looks good to me:

Regards,

Hans

Quoted 13 lines
---
 drivers/usb/typec/tcpm/fusb302.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/fusb302.c +0 -1
index 7a2a17866a823..72f9001b07921 100644
@@ -669,25 +669,27 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_COMP_CHNG);

drivers/usb/typec/tcpm/fusb302.c static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc) · line 681

Quoted 10 lines
drivers/usb/typec/tcpm/fusb302.c +2 -0
+					     FUSB_REG_MASK_BC_LVL);
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_comp_chng = true;
 
 
+		chip->intr_bc_lvl = false;

FWIW this is not necessary because the fusb302_set_toggling(chip, TOGGLING_MODE_OFF) already does this, but it makes the code more clear, so lets keep it.

Quoted 6 lines
drivers/usb/typec/tcpm/fusb302.c +0 -1
 		break;
 	case TYPEC_CC_RD:
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_BC_LVL);

drivers/usb/typec/tcpm/fusb302.c static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc) · line 692

Quoted 10 lines
drivers/usb/typec/tcpm/fusb302.c +2 -0
+					     FUSB_REG_MASK_COMP_CHNG);
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_bc_lvl = true;
 
 
+		chip->intr_comp_chng = false;

Idem.

drivers/usb/typec/tcpm/fusb302.c static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc) · line 695

Quoted 4 lines
drivers/usb/typec/tcpm/fusb302.c +0 -0
 		break;
 	default:
 		break;

Regards,

Hans

maintainer Acked-by Heikki on v2 1/1
#2 lore raw
In reply to Ondrej Jirman
Quoted 9 lines · Ondrej Jirman

The code that enables either BC_LVL or COMP_CHNG interrupt in tcpm_set_cc wrongly assumes that the interrupt is unmasked by writing 1 to the apropriate bit in the mask register. In fact, interrupts are enabled when the mask is 0, so the tcpm_set_cc enables interrupt for COMP_CHNG when it expects BC_LVL interrupt to be enabled.

This causes inability of the driver to recognize cable unplug events in host mode (unplug is recognized only via a COMP_CHNG interrupt).

Quoted 7 lines

In device mode this bug was masked by simultaneous triggering of the VBUS change interrupt, because of loss of VBUS when the port peer is providing power.

Fixes 48242e30532b ("usb: typec: fusb302: Revert "Resolve fixed power role contract setup"")
Cc Hans de Goede <[email protected]>

Should this go to stable?

Quoted 28 lines
---
 drivers/usb/typec/tcpm/fusb302.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/fusb302.c +3 -2
index 7a2a17866a823..72f9001b07921 100644
@@ -669,25 +669,27 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_COMP_CHNG);
+					     FUSB_REG_MASK_BC_LVL);
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_comp_chng = true;
+		chip->intr_bc_lvl = false;
 		break;
 	case TYPEC_CC_RD:
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_BC_LVL);
+					     FUSB_REG_MASK_COMP_CHNG);

drivers/usb/typec/tcpm/fusb302.c static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc) · line 695

Quoted 10 lines
drivers/usb/typec/tcpm/fusb302.c +1 -0
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_bc_lvl = true;
+		chip->intr_comp_chng = false;
 		break;
 	default:
 		break;

thanks,

Signature · 1 line
heikki
maintainer Acked-by
#3 lore raw
Quoted 14 lines · Heikki Krogerus
Quoted 13 lines · Ondrej Jirman

The code that enables either BC_LVL or COMP_CHNG interrupt in tcpm_set_cc wrongly assumes that the interrupt is unmasked by writing 1 to the apropriate bit in the mask register. In fact, interrupts are enabled when the mask is 0, so the tcpm_set_cc enables interrupt for COMP_CHNG when it expects BC_LVL interrupt to be enabled.

This causes inability of the driver to recognize cable unplug events in host mode (unplug is recognized only via a COMP_CHNG interrupt).

In device mode this bug was masked by simultaneous triggering of the VBUS change interrupt, because of loss of VBUS when the port peer is providing power.

Quoted 7 lines
Quoted 3 lines
Fixes 48242e30532b ("usb: typec: fusb302: Revert "Resolve fixed power role contract setup"")
Cc Hans de Goede <[email protected]>

Should this go to stable?

Sorry, that's wrong...

Quoted 40 lines
Quoted 28 lines
---
 drivers/usb/typec/tcpm/fusb302.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/fusb302.c +3 -2
index 7a2a17866a823..72f9001b07921 100644
@@ -669,25 +669,27 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_COMP_CHNG);
+					     FUSB_REG_MASK_BC_LVL);
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_comp_chng = true;
+		chip->intr_bc_lvl = false;
 		break;
 	case TYPEC_CC_RD:
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_BC_LVL);
+					     FUSB_REG_MASK_COMP_CHNG);

drivers/usb/typec/tcpm/fusb302.c static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc) · line 695

Quoted 10 lines
drivers/usb/typec/tcpm/fusb302.c +1 -0
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_bc_lvl = true;
+		chip->intr_comp_chng = false;
 		break;
 	default:
 		break;

thanks,

Signature · 1 line
heikki
#4 lore raw
In reply to Heikki Krogerus
Quoted 14 lines · Heikki Krogerus
Quoted 13 lines · Ondrej Jirman

The code that enables either BC_LVL or COMP_CHNG interrupt in tcpm_set_cc wrongly assumes that the interrupt is unmasked by writing 1 to the apropriate bit in the mask register. In fact, interrupts are enabled when the mask is 0, so the tcpm_set_cc enables interrupt for COMP_CHNG when it expects BC_LVL interrupt to be enabled.

This causes inability of the driver to recognize cable unplug events in host mode (unplug is recognized only via a COMP_CHNG interrupt).

In device mode this bug was masked by simultaneous triggering of the VBUS change interrupt, because of loss of VBUS when the port peer is providing power.

Quoted 5 lines
Quoted 3 lines
Fixes 48242e30532b ("usb: typec: fusb302: Revert "Resolve fixed power role contract setup"")
Cc Hans de Goede <[email protected]>

Should this go to stable?

Without this patch, VBUS is not turned off when I disconnect a hub from the Type-C port (because fusb302 will not notice the disconnect), and it stays on until next plugin of some device, say a normal non PD charger.

So I guess for a brief period you can have both sides provide VBUS (until fusb302/tcpm processes the next plugin). It may be a problem if VBUS was more than 5V (not very likely for devices running this driver, I guess).

regards,

	o.
Quoted 45 lines
Quoted 28 lines
---
 drivers/usb/typec/tcpm/fusb302.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/fusb302.c +3 -2
index 7a2a17866a823..72f9001b07921 100644
@@ -669,25 +669,27 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc)
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_COMP_CHNG);
+					     FUSB_REG_MASK_BC_LVL);
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_comp_chng = true;
+		chip->intr_bc_lvl = false;
 		break;
 	case TYPEC_CC_RD:
 		ret = fusb302_i2c_mask_write(chip, FUSB_REG_MASK,
 					     FUSB_REG_MASK_BC_LVL |
 					     FUSB_REG_MASK_COMP_CHNG,
-					     FUSB_REG_MASK_BC_LVL);
+					     FUSB_REG_MASK_COMP_CHNG);

drivers/usb/typec/tcpm/fusb302.c static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc) · line 695

Quoted 10 lines
drivers/usb/typec/tcpm/fusb302.c +1 -0
 		if (ret < 0) {
 			fusb302_log(chip, "cannot set SRC interrupt, ret=%d",
 				    ret);
 			goto done;
 		}
 		chip->intr_bc_lvl = true;
+		chip->intr_comp_chng = false;
 		break;
 	default:
 		break;

thanks,

Signature · 1 line
heikki
maintainer
#5 lore raw
Quoted 21 lines · Ondřej Jirman
Quoted 14 lines · Heikki Krogerus
Quoted 13 lines · Ondrej Jirman

The code that enables either BC_LVL or COMP_CHNG interrupt in tcpm_set_cc wrongly assumes that the interrupt is unmasked by writing 1 to the apropriate bit in the mask register. In fact, interrupts are enabled when the mask is 0, so the tcpm_set_cc enables interrupt for COMP_CHNG when it expects BC_LVL interrupt to be enabled.

This causes inability of the driver to recognize cable unplug events in host mode (unplug is recognized only via a COMP_CHNG interrupt).

In device mode this bug was masked by simultaneous triggering of the VBUS change interrupt, because of loss of VBUS when the port peer is providing power.

Quoted 5 lines
Quoted 3 lines
Fixes 48242e30532b ("usb: typec: fusb302: Revert "Resolve fixed power role contract setup"")
Cc Hans de Goede <[email protected]>

Should this go to stable?

Quoted 7 lines

Without this patch, VBUS is not turned off when I disconnect a hub from the Type-C port (because fusb302 will not notice the disconnect), and it stays on until next plugin of some device, say a normal non PD charger.

So I guess for a brief period you can have both sides provide VBUS (until fusb302/tcpm processes the next plugin). It may be a problem if VBUS was more than 5V (not very likely for devices running this driver, I guess).

OK. So this should find it's way to the stable kernel releases as well, and it should have the appropriate "Cc: [email protected]" tag:

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#select-the-recipients-for-your-patch

thanks,

Signature · 1 line
heikki