From: Chris Packham <chris.packham@alliedtelesis.co.nz>
To: gregory.clement@bootlin.com, andi.shyti@kernel.org,
robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, pierre.gondois@arm.com
Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Chris Packham <chris.packham@alliedtelesis.co.nz>
Subject: [PATCH 3/3] i2c: mv64xxx: add support for FSM based recovery
Date: Wed, 27 Sep 2023 12:48:01 +1300 [thread overview]
Message-ID: <20230926234801.4078042-4-chris.packham@alliedtelesis.co.nz> (raw)
In-Reply-To: <20230926234801.4078042-1-chris.packham@alliedtelesis.co.nz>
Some newer Marvell SoCs (AC5 and CN9130, possibly more) support a I2C
unstuck function. This provides a recovery function as part of the FSM
as an alternative to changing pinctrl modes and using the generic GPIO
based recovery. Allow for using this by adding an optional resource to
the platform data which contains the address of the I2C unstuck register
for the I2C controller.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
drivers/i2c/busses/i2c-mv64xxx.c | 71 ++++++++++++++++++++++++++++++--
1 file changed, 67 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index fd8403b07fa6..4345ab19b89c 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -21,6 +21,7 @@
#include <linux/pm_runtime.h>
#include <linux/reset.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_irq.h>
@@ -82,6 +83,13 @@
/* Bridge Status values */
#define MV64XXX_I2C_BRIDGE_STATUS_ERROR BIT(0)
+/* Unstuck Register values */
+#define MV64XXX_I2C_UNSTUCK_TRIGGER BIT(0)
+#define MV64XXX_I2C_UNSTUCK_ON_GOING BIT(1)
+#define MV64XXX_I2C_UNSTUCK_ERROR BIT(2)
+#define MV64XXX_I2C_UNSTUCK_COUNT(val) ((val & 0xf0) >> 4)
+#define MV64XXX_I2C_UNSTUCK_INPROGRESS (MV64XXX_I2C_UNSTUCK_TRIGGER|MV64XXX_I2C_UNSTUCK_ON_GOING)
+
/* Driver states */
enum {
MV64XXX_I2C_STATE_INVALID,
@@ -126,6 +134,7 @@ struct mv64xxx_i2c_data {
u32 aborting;
u32 cntl_bits;
void __iomem *reg_base;
+ void __iomem *unstuck_reg;
struct mv64xxx_i2c_regs reg_offsets;
u32 addr1;
u32 addr2;
@@ -735,6 +744,33 @@ mv64xxx_i2c_can_offload(struct mv64xxx_i2c_data *drv_data)
return false;
}
+static int
+mv64xxx_i2c_recover_bus(struct i2c_adapter *adap)
+{
+ struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap);
+ int ret;
+ u32 val;
+
+ dev_dbg(&adap->dev, "Trying i2c bus recovery\n");
+ writel(MV64XXX_I2C_UNSTUCK_TRIGGER, drv_data->unstuck_reg);
+ ret = readl_poll_timeout_atomic(drv_data->unstuck_reg, val,
+ !(val & MV64XXX_I2C_UNSTUCK_INPROGRESS),
+ 1000, 5000);
+ if (ret) {
+ dev_err(&adap->dev, "recovery timeout\n");
+ return ret;
+ }
+
+ if (val & MV64XXX_I2C_UNSTUCK_ERROR) {
+ dev_err(&adap->dev, "recovery failed\n");
+ return -EBUSY;
+ }
+
+ dev_info(&adap->dev, "recovery complete after %d pulses\n", MV64XXX_I2C_UNSTUCK_COUNT(val));
+
+ return 0;
+}
+
/*
*****************************************************************************
*
@@ -914,7 +950,8 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
drv_data->errata_delay = true;
}
- if (of_device_is_compatible(np, "marvell,mv78230-a0-i2c")) {
+ if (of_device_is_compatible(np, "marvell,mv78230-a0-i2c") ||
+ of_device_is_compatible(np, "marvell,armada-8k-i2c")) {
drv_data->offload_enabled = false;
/* The delay is only needed in standard mode (100kHz) */
if (bus_freq <= I2C_MAX_STANDARD_MODE_FREQ)
@@ -936,8 +973,21 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
}
#endif /* CONFIG_OF */
-static int mv64xxx_i2c_init_recovery_info(struct mv64xxx_i2c_data *drv_data,
- struct device *dev)
+static int mv64xxx_i2c_init_fsm_recovery_info(struct mv64xxx_i2c_data *drv_data,
+ struct device *dev)
+{
+ struct i2c_bus_recovery_info *rinfo = &drv_data->rinfo;
+
+ dev_info(dev, "using FSM for recovery\n");
+ rinfo->recover_bus = mv64xxx_i2c_recover_bus;
+ drv_data->adapter.bus_recovery_info = rinfo;
+
+ return 0;
+
+}
+
+static int mv64xxx_i2c_init_gpio_recovery_info(struct mv64xxx_i2c_data *drv_data,
+ struct device *dev)
{
struct i2c_bus_recovery_info *rinfo = &drv_data->rinfo;
@@ -986,6 +1036,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
{
struct mv64xxx_i2c_data *drv_data;
struct mv64xxx_i2c_pdata *pdata = dev_get_platdata(&pd->dev);
+ struct resource *res;
int rc;
if ((!pdata && !pd->dev.of_node))
@@ -1000,6 +1051,14 @@ mv64xxx_i2c_probe(struct platform_device *pd)
if (IS_ERR(drv_data->reg_base))
return PTR_ERR(drv_data->reg_base);
+ /* optional unstuck support */
+ res = platform_get_resource(pd, IORESOURCE_MEM, 1);
+ if (res) {
+ drv_data->unstuck_reg = devm_ioremap_resource(&pd->dev, res);
+ if (IS_ERR(drv_data->unstuck_reg))
+ return PTR_ERR(drv_data->unstuck_reg);
+ }
+
strscpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter",
sizeof(drv_data->adapter.name));
@@ -1037,7 +1096,11 @@ mv64xxx_i2c_probe(struct platform_device *pd)
return rc;
}
- rc = mv64xxx_i2c_init_recovery_info(drv_data, &pd->dev);
+ if (drv_data->unstuck_reg)
+ rc = mv64xxx_i2c_init_fsm_recovery_info(drv_data, &pd->dev);
+ else
+ rc = mv64xxx_i2c_init_gpio_recovery_info(drv_data, &pd->dev);
+
if (rc == -EPROBE_DEFER)
return rc;
--
2.42.0
next prev parent reply other threads:[~2023-09-26 23:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-26 23:47 [PATCH 0/3] i2c: mv64xxx: Support for I2C unstuck Chris Packham
2023-09-26 23:47 ` [PATCH 1/3] dt-bindings: i2c: mv64xxx: update bindings for unstuck register Chris Packham
2023-09-27 15:05 ` Conor Dooley
2023-09-26 23:48 ` [PATCH 2/3] arm64: dts: marvell: AC5: use I2C unstuck function Chris Packham
2023-09-26 23:48 ` Chris Packham [this message]
2023-10-05 21:58 ` [PATCH 3/3] i2c: mv64xxx: add support for FSM based recovery Andi Shyti
2023-10-05 22:39 ` Chris Packham
2023-10-05 23:07 ` Andi Shyti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230926234801.4078042-4-chris.packham@alliedtelesis.co.nz \
--to=chris.packham@alliedtelesis.co.nz \
--cc=andi.shyti@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregory.clement@bootlin.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pierre.gondois@arm.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).