From 00866aebd691ad03906613eeac3ab544f6573ac3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Jirman?= <megi@xff.cz>
Date: Sat, 20 Nov 2021 14:35:10 +0100
Subject: [PATCH 317/463] usb: typec: fusb302: Clear interrupts before we start
 toggling

This is recommended by the datasheet.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 drivers/usb/typec/tcpm/fusb302.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
index 5288e0e04343d..1013cba730b12 100644
--- a/drivers/usb/typec/tcpm/fusb302.c
+++ b/drivers/usb/typec/tcpm/fusb302.c
@@ -586,6 +586,7 @@ static int fusb302_set_toggling(struct fusb302_chip *chip,
 				enum toggling_mode mode)
 {
 	int ret = 0;
+	u8 reg;
 
 	/* first disable toggling */
 	ret = fusb302_i2c_clear_bits(chip, FUSB_REG_CONTROL2,
@@ -644,6 +645,12 @@ static int fusb302_set_toggling(struct fusb302_chip *chip,
 	} else {
 		/* Datasheet says vconn MUST be off when toggling */
 		WARN(chip->vconn_on, "Vconn is on during toggle start");
+
+		/* clear interrupts */
+                ret = fusb302_i2c_read(chip, FUSB_REG_INTERRUPT, &reg);
+		if (ret < 0)
+			return ret;
+
 		/* unmask TOGDONE interrupt */
 		ret = fusb302_i2c_clear_bits(chip, FUSB_REG_MASKA,
 					     FUSB_REG_MASKA_TOGDONE);
-- 
2.46.0

