diff mbox series

[5/5] i3c: ast2600: enable IBI support

Message ID ba923b96d6d129024c975e8a0472c5b2fcb3af32.1680161823.git.jk@codeconstruct.com.au (mailing list archive)
State Changes Requested
Headers show
Series i3c: dw,ast2600: Add In-Band Interrupt support | expand

Commit Message

Jeremy Kerr March 30, 2023, 7:50 a.m. UTC
The ast2600 i3c hardware is capable of IBIs, but we need a workaround
for a hardware issue with the I3C state machine handling IBI payloads
of specific lengths when PEC is not enabled. To avoid this, we need to
unconditionally enable PECs, at the consquence of losing a byte of data
when the device does not send a PEC.

Enable IBIs on the ast2600 platform, including an implementation of the
PEC workaround, which prints a warning when triggered.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
---
 drivers/i3c/master/ast2600-i3c-master.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/drivers/i3c/master/ast2600-i3c-master.c b/drivers/i3c/master/ast2600-i3c-master.c
index d3d7b7d19f22..52d9474a7651 100644
--- a/drivers/i3c/master/ast2600-i3c-master.c
+++ b/drivers/i3c/master/ast2600-i3c-master.c
@@ -36,6 +36,8 @@ 
 
 #define AST2600_DEFAULT_SDA_PULLUP_OHMS		2000
 
+#define DEV_ADDR_TABLE_IBI_PEC			BIT(11)
+
 struct ast2600_i3c_platform_data {
 	struct regmap *global_regs;
 	unsigned int global_idx;
@@ -93,8 +95,26 @@  static int ast2600_i3c_init(struct dw_i3c_master *master)
 	return rc;
 }
 
+static void ast2600_i3c_set_dat_ibi(struct dw_i3c_master *i3c,
+				    struct i3c_dev_desc *dev,
+				    bool enable, u32 *dat)
+{
+	/*
+	 * The ast2600 i3c controller will lock up on receiving 4n+1-byte IBIs
+	 * if the PEC is disabled. We have no way to restrict the length of
+	 * IBIs sent to the controller, so we need to unconditionally enable
+	 * PEC checking, which means we drop a byte of payload data
+	 */
+	if (enable && dev->info.bcr & I3C_BCR_IBI_PAYLOAD) {
+		dev_warn_once(&i3c->base.dev,
+		      "Enabling PEC workaround. IBI payloads will be truncated\n");
+		*dat |= DEV_ADDR_TABLE_IBI_PEC;
+	}
+}
+
 const struct dw_i3c_platform_ops ast2600_i3c_ops = {
 	.init = ast2600_i3c_init,
+	.set_dat_ibi = ast2600_i3c_set_dat_ibi,
 };
 
 static int ast2600_i3c_probe(struct platform_device *pdev)
@@ -136,6 +156,7 @@  static int ast2600_i3c_probe(struct platform_device *pdev)
 
 	dw_i3c->platform_ops = &ast2600_i3c_ops;
 	dw_i3c->platform_data = pdata;
+	dw_i3c->ibi_capable = true;
 	rc = dw_i3c_common_probe(dw_i3c, pdev);
 
 	return rc;