Skip to content

Commit 409c1cf

Browse files
JC-WVgregkh
authored andcommitted
usb: typec: tipd: fix event checking for tps6598x
The current interrupt service routine of the tps6598x only reads the first 64 bits of the INT_EVENT1 and INT_EVENT2 registers, which means that any event above that range will be ignored, leaving interrupts unattended. Moreover, those events will not be cleared, and the device will keep the interrupt enabled. This issue has been observed while attempting to load patches, and the 'ReadyForPatch' field (bit 81) of INT_EVENT1 was set. Given that older versions of the tps6598x (1, 2 and 6) provide 8-byte registers, a mechanism based on the upper byte of the version register (0x0F) has been included. The manufacturer has confirmed [1] that this byte is always 0 for older versions, and either 0xF7 (DH parts) or 0xF9 (DK parts) is returned in newer versions (7 and 8). Read the complete INT_EVENT registers to handle all interrupts generated by the device and account for the hardware version to select the register size. Link: https://e2e.ti.com/support/power-management-group/power-management/f/power-management-forum/1346521/tps65987d-register-command-to-distinguish-between-tps6591-2-6-and-tps65987-8 [1] Fixes: 0a4c005 ("usb: typec: driver for TI TPS6598x USB Power Delivery controllers") Cc: stable@vger.kernel.org Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net> Link: https://lore.kernel.org/r/20240429-tps6598x_fix_event_handling-v3-2-4e8e58dce489@wolfvision.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d64adb0 commit 409c1cf

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

drivers/usb/typec/tipd/core.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define TPS_REG_MODE 0x03
2929
#define TPS_REG_CMD1 0x08
3030
#define TPS_REG_DATA1 0x09
31+
#define TPS_REG_VERSION 0x0F
3132
#define TPS_REG_INT_EVENT1 0x14
3233
#define TPS_REG_INT_EVENT2 0x15
3334
#define TPS_REG_INT_MASK1 0x16
@@ -636,49 +637,67 @@ static irqreturn_t tps25750_interrupt(int irq, void *data)
636637

637638
static irqreturn_t tps6598x_interrupt(int irq, void *data)
638639
{
640+
int intev_len = TPS_65981_2_6_INTEVENT_LEN;
639641
struct tps6598x *tps = data;
640-
u64 event1 = 0;
641-
u64 event2 = 0;
642+
u64 event1[2] = { };
643+
u64 event2[2] = { };
644+
u32 version;
642645
u32 status;
643646
int ret;
644647

645648
mutex_lock(&tps->lock);
646649

647-
ret = tps6598x_read64(tps, TPS_REG_INT_EVENT1, &event1);
648-
ret |= tps6598x_read64(tps, TPS_REG_INT_EVENT2, &event2);
650+
ret = tps6598x_read32(tps, TPS_REG_VERSION, &version);
651+
if (ret)
652+
dev_warn(tps->dev, "%s: failed to read version (%d)\n",
653+
__func__, ret);
654+
655+
if (TPS_VERSION_HW_VERSION(version) == TPS_VERSION_HW_65987_8_DH ||
656+
TPS_VERSION_HW_VERSION(version) == TPS_VERSION_HW_65987_8_DK)
657+
intev_len = TPS_65987_8_INTEVENT_LEN;
658+
659+
ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT1, event1, intev_len);
660+
661+
ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT1, event1, intev_len);
649662
if (ret) {
650-
dev_err(tps->dev, "%s: failed to read events\n", __func__);
663+
dev_err(tps->dev, "%s: failed to read event1\n", __func__);
651664
goto err_unlock;
652665
}
653-
trace_tps6598x_irq(event1, event2);
666+
ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT2, event2, intev_len);
667+
if (ret) {
668+
dev_err(tps->dev, "%s: failed to read event2\n", __func__);
669+
goto err_unlock;
670+
}
671+
trace_tps6598x_irq(event1[0], event2[0]);
654672

655-
if (!(event1 | event2))
673+
if (!(event1[0] | event1[1] | event2[0] | event2[1]))
656674
goto err_unlock;
657675

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

661-
if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE)
679+
if ((event1[0] | event2[0]) & TPS_REG_INT_POWER_STATUS_UPDATE)
662680
if (!tps6598x_read_power_status(tps))
663681
goto err_clear_ints;
664682

665-
if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE)
683+
if ((event1[0] | event2[0]) & TPS_REG_INT_DATA_STATUS_UPDATE)
666684
if (!tps6598x_read_data_status(tps))
667685
goto err_clear_ints;
668686

669687
/* Handle plug insert or removal */
670-
if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT)
688+
if ((event1[0] | event2[0]) & TPS_REG_INT_PLUG_EVENT)
671689
tps6598x_handle_plug_event(tps, status);
672690

673691
err_clear_ints:
674-
tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1);
675-
tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event2);
692+
tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len);
693+
tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len);
676694

677695
err_unlock:
678696
mutex_unlock(&tps->lock);
679697

680-
if (event1 | event2)
698+
if (event1[0] | event1[1] | event2[0] | event2[1])
681699
return IRQ_HANDLED;
700+
682701
return IRQ_NONE;
683702
}
684703

drivers/usb/typec/tipd/tps6598x.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,15 @@
253253
#define TPS_PTCC_DEV 2
254254
#define TPS_PTCC_APP 3
255255

256+
/* Version Register */
257+
#define TPS_VERSION_HW_VERSION_MASK GENMASK(31, 24)
258+
#define TPS_VERSION_HW_VERSION(x) TPS_FIELD_GET(TPS_VERSION_HW_VERSION_MASK, (x))
259+
#define TPS_VERSION_HW_65981_2_6 0x00
260+
#define TPS_VERSION_HW_65987_8_DH 0xF7
261+
#define TPS_VERSION_HW_65987_8_DK 0xF9
262+
263+
/* Int Event Register length */
264+
#define TPS_65981_2_6_INTEVENT_LEN 8
265+
#define TPS_65987_8_INTEVENT_LEN 11
266+
256267
#endif /* __TPS6598X_H__ */

0 commit comments

Comments
 (0)