usb: typec: tipd: fix event checking for tps6598x

commit 409c1cfb5a 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: 0a4c005bd1 ("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>
This commit is contained in:
Javier Carrasco 2024-04-29 15:35:58 +02:00 committed by Greg Kroah-Hartman
parent 2f95dfb647
commit 40b963e45c
2 changed files with 43 additions and 13 deletions

View File

@ -26,6 +26,7 @@
#define TPS_REG_MODE 0x03 #define TPS_REG_MODE 0x03
#define TPS_REG_CMD1 0x08 #define TPS_REG_CMD1 0x08
#define TPS_REG_DATA1 0x09 #define TPS_REG_DATA1 0x09
#define TPS_REG_VERSION 0x0F
#define TPS_REG_INT_EVENT1 0x14 #define TPS_REG_INT_EVENT1 0x14
#define TPS_REG_INT_EVENT2 0x15 #define TPS_REG_INT_EVENT2 0x15
#define TPS_REG_INT_MASK1 0x16 #define TPS_REG_INT_MASK1 0x16
@ -515,49 +516,67 @@ err_unlock:
static irqreturn_t tps6598x_interrupt(int irq, void *data) static irqreturn_t tps6598x_interrupt(int irq, void *data)
{ {
int intev_len = TPS_65981_2_6_INTEVENT_LEN;
struct tps6598x *tps = data; struct tps6598x *tps = data;
u64 event1 = 0; u64 event1[2] = { };
u64 event2 = 0; u64 event2[2] = { };
u32 version;
u32 status; u32 status;
int ret; int ret;
mutex_lock(&tps->lock); mutex_lock(&tps->lock);
ret = tps6598x_read64(tps, TPS_REG_INT_EVENT1, &event1); ret = tps6598x_read32(tps, TPS_REG_VERSION, &version);
ret |= tps6598x_read64(tps, TPS_REG_INT_EVENT2, &event2); if (ret)
dev_warn(tps->dev, "%s: failed to read version (%d)\n",
__func__, ret);
if (TPS_VERSION_HW_VERSION(version) == TPS_VERSION_HW_65987_8_DH ||
TPS_VERSION_HW_VERSION(version) == TPS_VERSION_HW_65987_8_DK)
intev_len = TPS_65987_8_INTEVENT_LEN;
ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT1, event1, intev_len);
ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT1, event1, intev_len);
if (ret) { if (ret) {
dev_err(tps->dev, "%s: failed to read events\n", __func__); dev_err(tps->dev, "%s: failed to read event1\n", __func__);
goto err_unlock; goto err_unlock;
} }
trace_tps6598x_irq(event1, event2); ret = tps6598x_block_read(tps, TPS_REG_INT_EVENT2, event2, intev_len);
if (ret) {
dev_err(tps->dev, "%s: failed to read event2\n", __func__);
goto err_unlock;
}
trace_tps6598x_irq(event1[0], event2[0]);
if (!(event1 | event2)) if (!(event1[0] | event1[1] | event2[0] | event2[1]))
goto err_unlock; goto err_unlock;
if (!tps6598x_read_status(tps, &status)) if (!tps6598x_read_status(tps, &status))
goto err_clear_ints; goto err_clear_ints;
if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE) if ((event1[0] | event2[0]) & TPS_REG_INT_POWER_STATUS_UPDATE)
if (!tps6598x_read_power_status(tps)) if (!tps6598x_read_power_status(tps))
goto err_clear_ints; goto err_clear_ints;
if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) if ((event1[0] | event2[0]) & TPS_REG_INT_DATA_STATUS_UPDATE)
if (!tps6598x_read_data_status(tps)) if (!tps6598x_read_data_status(tps))
goto err_clear_ints; goto err_clear_ints;
/* Handle plug insert or removal */ /* Handle plug insert or removal */
if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) if ((event1[0] | event2[0]) & TPS_REG_INT_PLUG_EVENT)
tps6598x_handle_plug_event(tps, status); tps6598x_handle_plug_event(tps, status);
err_clear_ints: err_clear_ints:
tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1); tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len);
tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event2); tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len);
err_unlock: err_unlock:
mutex_unlock(&tps->lock); mutex_unlock(&tps->lock);
if (event1 | event2) if (event1[0] | event1[1] | event2[0] | event2[1])
return IRQ_HANDLED; return IRQ_HANDLED;
return IRQ_NONE; return IRQ_NONE;
} }

View File

@ -199,4 +199,15 @@
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_A BIT(2) #define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_A BIT(2)
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B (BIT(2) | BIT(1)) #define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B (BIT(2) | BIT(1))
/* Version Register */
#define TPS_VERSION_HW_VERSION_MASK GENMASK(31, 24)
#define TPS_VERSION_HW_VERSION(x) TPS_FIELD_GET(TPS_VERSION_HW_VERSION_MASK, (x))
#define TPS_VERSION_HW_65981_2_6 0x00
#define TPS_VERSION_HW_65987_8_DH 0xF7
#define TPS_VERSION_HW_65987_8_DK 0xF9
/* Int Event Register length */
#define TPS_65981_2_6_INTEVENT_LEN 8
#define TPS_65987_8_INTEVENT_LEN 11
#endif /* __TPS6598X_H__ */ #endif /* __TPS6598X_H__ */