Skip to content

Commit 40b963e

Browse files
JC-WVgregkh
authored andcommitted
usb: typec: tipd: fix event checking for tps6598x
commit 409c1cf upstream. 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 2f95dfb commit 40b963e

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
@@ -26,6 +26,7 @@
2626
#define TPS_REG_MODE 0x03
2727
#define TPS_REG_CMD1 0x08
2828
#define TPS_REG_DATA1 0x09
29+
#define TPS_REG_VERSION 0x0F
2930
#define TPS_REG_INT_EVENT1 0x14
3031
#define TPS_REG_INT_EVENT2 0x15
3132
#define TPS_REG_INT_MASK1 0x16
@@ -515,49 +516,67 @@ static irqreturn_t cd321x_interrupt(int irq, void *data)
515516

516517
static irqreturn_t tps6598x_interrupt(int irq, void *data)
517518
{
519+
int intev_len = TPS_65981_2_6_INTEVENT_LEN;
518520
struct tps6598x *tps = data;
519-
u64 event1 = 0;
520-
u64 event2 = 0;
521+
u64 event1[2] = { };
522+
u64 event2[2] = { };
523+
u32 version;
521524
u32 status;
522525
int ret;
523526

524527
mutex_lock(&tps->lock);
525528

526-
ret = tps6598x_read64(tps, TPS_REG_INT_EVENT1, &event1);
527-
ret |= tps6598x_read64(tps, TPS_REG_INT_EVENT2, &event2);
529+
ret = tps6598x_read32(tps, TPS_REG_VERSION, &version);
530+
if (ret)
531+
dev_warn(tps->dev, "%s: failed to read version (%d)\n",
532+
__func__, ret);
533+
534+
if (TPS_VERSION_HW_VERSION(version) == TPS_VERSION_HW_65987_8_DH ||
535+
TPS_VERSION_HW_VERSION(version) == TPS_VERSION_HW_65987_8_DK)
536+
intev_len = TPS_65987_8_INTEVENT_LEN;
537+
538+
ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT1, event1, intev_len);
539+
540+
ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT1, event1, intev_len);
528541
if (ret) {
529-
dev_err(tps->dev, "%s: failed to read events\n", __func__);
542+
dev_err(tps->dev, "%s: failed to read event1\n", __func__);
530543
goto err_unlock;
531544
}
532-
trace_tps6598x_irq(event1, event2);
545+
ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT2, event2, intev_len);
546+
if (ret) {
547+
dev_err(tps->dev, "%s: failed to read event2\n", __func__);
548+
goto err_unlock;
549+
}
550+
trace_tps6598x_irq(event1[0], event2[0]);
533551

534-
if (!(event1 | event2))
552+
if (!(event1[0] | event1[1] | event2[0] | event2[1]))
535553
goto err_unlock;
536554

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

540-
if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE)
558+
if ((event1[0] | event2[0]) & TPS_REG_INT_POWER_STATUS_UPDATE)
541559
if (!tps6598x_read_power_status(tps))
542560
goto err_clear_ints;
543561

544-
if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE)
562+
if ((event1[0] | event2[0]) & TPS_REG_INT_DATA_STATUS_UPDATE)
545563
if (!tps6598x_read_data_status(tps))
546564
goto err_clear_ints;
547565

548566
/* Handle plug insert or removal */
549-
if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT)
567+
if ((event1[0] | event2[0]) & TPS_REG_INT_PLUG_EVENT)
550568
tps6598x_handle_plug_event(tps, status);
551569

552570
err_clear_ints:
553-
tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1);
554-
tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event2);
571+
tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len);
572+
tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len);
555573

556574
err_unlock:
557575
mutex_unlock(&tps->lock);
558576

559-
if (event1 | event2)
577+
if (event1[0] | event1[1] | event2[0] | event2[1])
560578
return IRQ_HANDLED;
579+
561580
return IRQ_NONE;
562581
}
563582

drivers/usb/typec/tipd/tps6598x.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,15 @@
199199
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_A BIT(2)
200200
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B (BIT(2) | BIT(1))
201201

202+
/* Version Register */
203+
#define TPS_VERSION_HW_VERSION_MASK GENMASK(31, 24)
204+
#define TPS_VERSION_HW_VERSION(x) TPS_FIELD_GET(TPS_VERSION_HW_VERSION_MASK, (x))
205+
#define TPS_VERSION_HW_65981_2_6 0x00
206+
#define TPS_VERSION_HW_65987_8_DH 0xF7
207+
#define TPS_VERSION_HW_65987_8_DK 0xF9
208+
209+
/* Int Event Register length */
210+
#define TPS_65981_2_6_INTEVENT_LEN 8
211+
#define TPS_65987_8_INTEVENT_LEN 11
212+
202213
#endif /* __TPS6598X_H__ */

0 commit comments

Comments
 (0)