[PATCH v5 08/15] USB: typec: Add interrupt support for TPS25750

From: Abdel Alkuor
Date: Sun Sep 17 2023 - 11:33:06 EST


From: Abdel Alkuor <abdelalkuor@xxxxxxxxxx>

Update tps6598x interrupt handler to accommodate tps25750 interrupt

Signed-off-by: Abdel Alkuor <abdelalkuor@xxxxxxxxxx>
---
drivers/usb/typec/tipd/core.c | 49 +++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index bd5436fd88fd..17b3bc480f97 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -120,6 +120,7 @@ struct tps6598x {
enum power_supply_usb_type usb_type;

int wakeup;
+ u32 status; /* status reg */
u16 pwr_status;
struct delayed_work wq_poll;
irq_handler_t irq_handler;
@@ -539,50 +540,71 @@ static irqreturn_t cd321x_interrupt(int irq, void *data)
return IRQ_NONE;
}

+static bool tps6598x_has_role_changed(struct tps6598x *tps, u32 status)
+{
+ status ^= tps->status;
+
+ return status & (TPS_STATUS_PORTROLE | TPS_STATUS_DATAROLE);
+}
+
static irqreturn_t tps6598x_interrupt(int irq, void *data)
{
struct tps6598x *tps = data;
- u64 event1 = 0;
- u64 event2 = 0;
+ u64 event[2] = { };
u32 status;
int ret;

mutex_lock(&tps->lock);

- ret = tps6598x_read64(tps, TPS_REG_INT_EVENT1, &event1);
- ret |= tps6598x_read64(tps, TPS_REG_INT_EVENT2, &event2);
+ if (tps->is_tps25750) {
+ ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT1, event, 11);
+ } else {
+ ret = tps6598x_read64(tps, TPS_REG_INT_EVENT1, &event[0]);
+ ret |= tps6598x_read64(tps, TPS_REG_INT_EVENT2, &event[1]);
+ }
+
if (ret) {
dev_err(tps->dev, "%s: failed to read events\n", __func__);
goto err_unlock;
}
- trace_tps6598x_irq(event1, event2);
+ trace_tps6598x_irq(event[0], event[1]);

- if (!(event1 | event2))
+ if (!(event[0] | event[1]))
goto err_unlock;

if (!tps6598x_read_status(tps, &status))
goto err_clear_ints;

- if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE)
+ if ((event[0] | event[1]) & TPS_REG_INT_POWER_STATUS_UPDATE)
if (!tps6598x_read_power_status(tps))
goto err_clear_ints;

- if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE)
+ if ((event[0] | event[1]) & TPS_REG_INT_DATA_STATUS_UPDATE)
if (!tps6598x_read_data_status(tps))
goto err_clear_ints;

- /* Handle plug insert or removal */
- if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT)
+ /*
+ * data/port roles could be updated independently after
+ * a plug event. Therefore, we need to check
+ * for pr/dr status change to set TypeC dr/pr accordingly.
+ */
+ if ((event[0] | event[1]) & TPS_REG_INT_PLUG_EVENT ||
+ tps6598x_has_role_changed(tps, status))
tps6598x_handle_plug_event(tps, status);

+ tps->status = status;
err_clear_ints:
- tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1);
- tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event2);
+ if (tps->is_tps25750) {
+ tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event, 11);
+ } else {
+ tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event[0]);
+ tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event[1]);
+ }

err_unlock:
mutex_unlock(&tps->lock);

- if (event1 | event2)
+ if (event[0] | event[1])
return IRQ_HANDLED;
return IRQ_NONE;
}
@@ -1003,7 +1025,6 @@ static int tps6598x_probe(struct i2c_client *client)

irq_handler = cd321x_interrupt;
} else {
-
tps->is_tps25750 = of_device_is_compatible(np, "ti,tps25750");
/* Enable power status, data status and plug event interrupts */
mask1 = TPS_REG_INT_POWER_STATUS_UPDATE |
--
2.34.1