From: Abdel Alkuor <[email protected]>
TPS25750 USB type-C PD controller has the same register offsets as
tps6598x. The following is a summary of incorporating TPS25750 into
TPS6598x driver:
- Only Check VID register (0x00) for TPS6598x and cd321x, as TPS25750 doesn't
have VID register.
- TypeC port registration will be registered differently for each PD
controller. TPS6598x uses system configuration register (0x28) to get
pr/dr capabilities. On the other hand, TPS25750 will use data role property
and PD status register (0x40) to get pr/dr capabilities as TPS25750 doesn't
have register 0x28 supported.
- TPS25750 requires writing a binary configuration to switch PD
controller from PTCH mode to APP mode which needs the following changes:
- Add PTCH mode to the modes list.
- Add an argument to tps6598x_check_mode to return the current mode.
- Currently, tps6598x_exec_cmd has cmd timeout hardcoded to 1 second,
and doesn't wait before checking DATA_OUT response. In TPS25750, patch 4CCs
take longer than 1 second to execute and some requires a delay before
checking DATA_OUT. To accommodate that, cmd_timeout and response_delay will
be added as arguments to tps6598x_exec_cmd.
- Implement applying patch sequence for TPS25750.
- In pm suspend callback, patch mode needs to be checked and the binary
configuration should be applied if needed.
- For interrupt, TPS25750 has only one event register (0x14) and one mask
register (0x16) of 11 bytes each, where TPS6598x has two event
and two mask registers of 8 bytes each. Both TPS25750 and TPS65986x
shares the same bit field offsets for events/masks/clear but many of
there fields are reserved in TPS25750, the following needs to be done in
tps6598x_interrupt:
- Read EVENT1 register as a block of 11 bytes when tps25750 is present
- Write CLEAR1 register as a block of 11 bytes when tps25750 is present
- Add trace_tps25750_irq
- During testing, I noticed that when a cable is plugged into the PD
controller and before PD controller switches to APP mode, there is a
lag between dr/pr updates and PlugInsertOrRemoval Event, so a check
for dr/pr change needs to be added along TPS_REG_INT_PLUG_EVENT check
- Add TPS25750 traces for status and power status registers. Trace for
data register won't be added as it doesn't exist in the device.
- Configure sleep mode for TPS25750.
v6:
- PATCH 1: Use reg property for patch address
- PATCH 2: Use tps6598x_exec_cmd as a wrapper
- PATCH 3: Return current mode and check it directly
- PATCH 4:
- Don't check VID for tps25750 as the VID register doesn't exist
- Remove is_tps25750 flag from tps6598x struct
- Get patch address from reg property
- PATCH 5: Update eeprom macro to use TPS instead
- PATCH 6: No changes
- PATCH 7: Check tps25750 using is_compatiable device node
- PATCH 8: Create tipd callbacks factory
- PATCH 9: No changes
- PATCH 10: Add port registration to tipd data factory
- PATCH 11: Use tps25750_init instead of tps25750_apply_patch in resume
as it initializes sleep mode
- PATCH 12: Add trace irq to tipd callbacks factory
- PATCH 13: Add trace power status to tipd data factory
- PATCH 14: Add trace status to tipd data factory
v5:
- PATCH 1: Add tps25750 bindings to tps6598x
- PATCH 2: Remove tps25750 driver and incorperate tps25750
into tps6598x driver
- PATCH [3..15]: Incorporating tps25750 into tps6598x driver
v4:
- PATCH 1: No change
- PATCH 2: Fix comments style and drop of_match_ptr
v3:
- PATCH 1: Fix node name
- PATCH 2: Upload tps25750 driver patch
v2:
- PATCH 1: General properties clean up
Abdel Alkuor (14):
dt-bindings: usb: tps6598x: Add tps25750
USB: typec: Add cmd timeout and response delay
USB: typec: Add patch mode to tps6598x
USB: typec: Load TPS25750 patch bundle
USB: typec: Check for EEPROM present
USB: typec: Clear dead battery flag
USB: typec: Apply patch again after power resume
USB: typec: Add interrupt support for TPS25750
USB: typec: Refactor tps6598x port registration
USB: typec: Add port registration for tps25750
USB: typec: Enable sleep mode for tps25750
USB: typec: Add trace for tps25750 irq
USB: typec: Add power status trace for tps25750
USB: typec: Add status trace for tps25750
.../devicetree/bindings/usb/ti,tps6598x.yaml | 70 ++
drivers/usb/typec/tipd/core.c | 632 +++++++++++++++---
drivers/usb/typec/tipd/tps6598x.h | 36 +
drivers/usb/typec/tipd/trace.h | 92 +++
4 files changed, 749 insertions(+), 81 deletions(-)
--
2.34.1
From: Abdel Alkuor <[email protected]>
When an EEPROM is present, tps25750 loads the binary configuration from
EEPROM. Hence, all we need to do is wait for the device to switch to APP
mode
Signed-off-by: Abdel Alkuor <[email protected]>
---
Changes in v6:
- Update eeprom macro to use TPS instead
Changes in v5:
- Incorporating tps25750 into tps6598x driver
drivers/usb/typec/tipd/core.c | 13 +++++++++++++
drivers/usb/typec/tipd/tps6598x.h | 3 +++
2 files changed, 16 insertions(+)
diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index d2f82f191e4a..7c08669400a8 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -37,6 +37,7 @@
#define TPS_REG_STATUS 0x1a
#define TPS_REG_SYSTEM_CONF 0x28
#define TPS_REG_CTRL_CONF 0x29
+#define TPS_REG_BOOT_STATUS 0x2D
#define TPS_REG_POWER_STATUS 0x3f
#define TPS_REG_RX_IDENTITY_SOP 0x48
#define TPS_REG_DATA_STATUS 0x5f
@@ -898,6 +899,17 @@ static int tps25750_apply_patch(struct tps6598x *tps)
{
int ret;
unsigned long timeout;
+ u64 status = 0;
+
+ ret = tps6598x_block_read(tps, TPS_REG_BOOT_STATUS, &status, 5);
+ if (ret)
+ return ret;
+ /*
+ * Nothing to be done if the configuration
+ * is being loaded from EERPOM
+ */
+ if (status & TPS_BOOT_STATUS_I2C_EEPROM_PRESENT)
+ goto wait_for_app;
ret = tps25750_start_patch_burst_mode(tps);
if (ret) {
@@ -909,6 +921,7 @@ static int tps25750_apply_patch(struct tps6598x *tps)
if (ret)
return ret;
+wait_for_app:
timeout = jiffies + msecs_to_jiffies(1000);
do {
diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h
index 527857549d69..a80d0929f3ee 100644
--- a/drivers/usb/typec/tipd/tps6598x.h
+++ b/drivers/usb/typec/tipd/tps6598x.h
@@ -199,4 +199,7 @@
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_A BIT(2)
#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B (BIT(2) | BIT(1))
+/* BOOT STATUS REG*/
+#define TPS_BOOT_STATUS_I2C_EEPROM_PRESENT BIT(3)
+
#endif /* __TPS6598X_H__ */
--
2.34.1
From: Abdel Alkuor <[email protected]>
tps25750 event registers structure is different than tps6598x's,
tps25750 has 11 bytes of events which are read at once where
tps6598x has two event registers of 8 bytes each which are read
separately. Likewise MASK event registers. Also, not all events
are supported in both devices.
Update tps6598x interrupt handler to accommodate tps25750 interrupt
Signed-off-by: Abdel Alkuor <[email protected]>
---
Changes in v6:
- Create tipd callbacks factory
Changes in v5:
- Incorporating tps25750 into tps6598x driver
drivers/usb/typec/tipd/core.c | 102 +++++++++++++++++++++++++++-------
1 file changed, 83 insertions(+), 19 deletions(-)
diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 56ffffe225f2..cde52afe5097 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -101,6 +101,14 @@ static const char *const modes[] = {
/* Unrecognized commands will be replaced with "!CMD" */
#define INVALID_CMD(_cmd_) (_cmd_ == 0x444d4321)
+struct tps6598x;
+
+struct tipd_data {
+ irq_handler_t irq_handler;
+ int (*read_events)(struct tps6598x *tps, void *events);
+ int (*clear_events)(struct tps6598x *tps, void *events);
+};
+
struct tps6598x {
struct device *dev;
struct regmap *regmap;
@@ -118,9 +126,11 @@ 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;
+
+ struct tipd_data cb;
};
static enum power_supply_property tps6598x_psy_props[] = {
@@ -500,6 +510,32 @@ static void tps6598x_handle_plug_event(struct tps6598x *tps, u32 status)
}
}
+static int tps6598x_read_events(struct tps6598x *tps, void *events)
+{
+ uint64_t *e = events;
+
+ return tps6598x_read64(tps, TPS_REG_INT_EVENT1, &e[0]) |
+ tps6598x_read64(tps, TPS_REG_INT_EVENT2, &e[1]);
+}
+
+static int tps6598x_clear_events(struct tps6598x *tps, void *events)
+{
+ uint64_t *e = events;
+
+ return tps6598x_write64(tps, TPS_REG_INT_CLEAR1, e[0]) |
+ tps6598x_write64(tps, TPS_REG_INT_CLEAR2, e[1]);
+}
+
+static int tps25750_read_events(struct tps6598x *tps, void *events)
+{
+ return tps6598x_block_read(tps, TPS_REG_INT_EVENT1, events, 11);
+}
+
+static int tps25750_clear_events(struct tps6598x *tps, void *events)
+{
+ return tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, events, 11);
+}
+
static irqreturn_t cd321x_interrupt(int irq, void *data)
{
struct tps6598x *tps = data;
@@ -545,50 +581,60 @@ 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);
+ ret = tps->cb.read_events(tps, event);
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);
+ tps->cb.clear_events(tps, event);
err_unlock:
mutex_unlock(&tps->lock);
- if (event1 | event2)
+ if (event[0] | event[1])
return IRQ_HANDLED;
return IRQ_NONE;
}
@@ -600,7 +646,7 @@ static void tps6598x_poll_work(struct work_struct *work)
struct tps6598x *tps = container_of(to_delayed_work(work),
struct tps6598x, wq_poll);
- tps->irq_handler(0, tps);
+ tps->cb.irq_handler(0, tps);
queue_delayed_work(system_power_efficient_wq,
&tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL));
}
@@ -967,9 +1013,24 @@ static int tps25750_apply_patch(struct tps6598x *tps)
return 0;
};
+static const struct tipd_data cd321x_data = {
+ .irq_handler = cd321x_interrupt,
+};
+
+static const struct tipd_data tps6598x_data = {
+ .irq_handler = tps6598x_interrupt,
+ .read_events = tps6598x_read_events,
+ .clear_events = tps6598x_clear_events,
+};
+
+static const struct tipd_data tps25750_data = {
+ .irq_handler = tps6598x_interrupt,
+ .read_events = tps25750_read_events,
+ .clear_events = tps25750_clear_events,
+};
+
static int tps6598x_probe(struct i2c_client *client)
{
- irq_handler_t irq_handler = tps6598x_interrupt;
struct device_node *np = client->dev.of_node;
struct typec_capability typec_cap = { };
struct tps6598x *tps;
@@ -1017,15 +1078,18 @@ static int tps6598x_probe(struct i2c_client *client)
APPLE_CD_REG_INT_DATA_STATUS_UPDATE |
APPLE_CD_REG_INT_PLUG_EVENT;
- irq_handler = cd321x_interrupt;
+ tps->cb = cd321x_data;
} else {
+ if (is_tps25750)
+ tps->cb = tps25750_data;
+ else
+ tps->cb = tps6598x_data;
/* Enable power status, data status and plug event interrupts */
mask1 = TPS_REG_INT_POWER_STATUS_UPDATE |
TPS_REG_INT_DATA_STATUS_UPDATE |
TPS_REG_INT_PLUG_EVENT;
}
- tps->irq_handler = irq_handler;
/* Make sure the controller has application firmware running */
ret = tps6598x_check_mode(tps);
if (ret < 0)
@@ -1125,7 +1189,7 @@ static int tps6598x_probe(struct i2c_client *client)
if (client->irq) {
ret = devm_request_threaded_irq(&client->dev, client->irq, NULL,
- irq_handler,
+ tps->cb.irq_handler,
IRQF_SHARED | IRQF_ONESHOT,
dev_name(&client->dev), tps);
} else {
--
2.34.1