* [PATCH] i2c: cadence: Add standard bus recovery support
@ 2022-06-30 12:18 Shubhrajyoti Datta
0 siblings, 0 replies; 4+ messages in thread
From: Shubhrajyoti Datta @ 2022-06-30 12:18 UTC (permalink / raw)
To: linux-i2c; +Cc: michal.simek, git, git
From: Robert Hancock <robert.hancock@calian.com>
Hook up the standard GPIO/pinctrl-based recovery support..
In the discurssion
https://patchwork.ozlabs.org/project/linux-i2c/patch/20211129090116.16628-1-shubhrajyoti.datta@xilinx.com/
recovery should be done at the beginning of the transaction.
Here we are doing the recovery at the beginning on a timeout.
Signed-off-by: Robert Hancock <robert.hancock@calian.com>
Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
---
drivers/i2c/busses/i2c-cadence.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index b4c1ad19cdae..cf15eca1f9e4 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -10,6 +10,7 @@
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
@@ -125,6 +126,8 @@
#define CDNS_I2C_DIVB_MAX 64
#define CDNS_I2C_TIMEOUT_MAX 0xFF
+#define CDNS_I2C_POLL_US 100000
+#define CDNS_I2C_TIMEOUT_US 500000
#define CDNS_I2C_BROKEN_HOLD_BIT BIT(0)
@@ -179,6 +182,7 @@ enum cdns_i2c_slave_state {
* @clk_rate_change_nb: Notifier block for clock rate changes
* @quirks: flag for broken hold bit usage in r1p10
* @ctrl_reg: Cached value of the control register.
+ * @rinfo: Structure holding recovery information.
* @ctrl_reg_diva_divb: value of fields DIV_A and DIV_B from CR register
* @slave: Registered slave instance.
* @dev_mode: I2C operating role(master/slave).
@@ -204,6 +208,7 @@ struct cdns_i2c {
struct notifier_block clk_rate_change_nb;
u32 quirks;
u32 ctrl_reg;
+ struct i2c_bus_recovery_info rinfo;
#if IS_ENABLED(CONFIG_I2C_SLAVE)
u16 ctrl_reg_diva_divb;
struct i2c_client *slave;
@@ -796,6 +801,7 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
/* Wait for the signal of completion */
time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout);
if (time_left == 0) {
+ i2c_recover_bus(adap);
cdns_i2c_master_reset(adap);
dev_err(id->adap.dev.parent,
"timeout waiting on completion\n");
@@ -852,8 +858,12 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
#endif
/* Check if the bus is free */
- if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA) {
+ ret = readl_poll_timeout(id->membase + CDNS_I2C_SR_OFFSET, reg,
+ !(reg & CDNS_I2C_SR_BA),
+ CDNS_I2C_POLL_US, CDNS_I2C_TIMEOUT_US);
+ if (ret) {
ret = -EAGAIN;
+ i2c_recover_bus(adap);
goto out;
}
@@ -1278,6 +1288,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
id->adap.retries = 3; /* Default retry value. */
id->adap.algo_data = id;
id->adap.dev.parent = &pdev->dev;
+ id->adap.bus_recovery_info = &id->rinfo;
init_completion(&id->xfer_done);
snprintf(id->adap.name, sizeof(id->adap.name),
"Cadence I2C at %08lx", (unsigned long)r_mem->start);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] i2c: cadence: Add standard bus recovery support
@ 2021-04-15 23:25 Robert Hancock
2021-04-20 13:23 ` Michal Simek
0 siblings, 1 reply; 4+ messages in thread
From: Robert Hancock @ 2021-04-15 23:25 UTC (permalink / raw)
To: michal.simek; +Cc: linux-i2c, Robert Hancock, Chirag Parekh
Hook up the standard GPIO/pinctrl-based recovery support for this
driver.
Based on a patch "i2c: cadence: Recover bus after controller reset" by
Chirag Parekh in the Xilinx kernel Git tree, but simplified to make use
of more common code.
Cc: Chirag Parekh <chiragp@xilinx.com>
Signed-off-by: Robert Hancock <robert.hancock@calian.com>
---
drivers/i2c/busses/i2c-cadence.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index c1bbc4caeb5c..d017bc64e759 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -178,6 +178,7 @@ enum cdns_i2c_slave_state {
* @clk: Pointer to struct clk
* @clk_rate_change_nb: Notifier block for clock rate changes
* @quirks: flag for broken hold bit usage in r1p10
+ * @rinfo: Structure holding recovery information.
* @ctrl_reg_diva_divb: value of fields DIV_A and DIV_B from CR register
* @slave: Registered slave instance.
* @dev_mode: I2C operating role(master/slave).
@@ -202,6 +203,7 @@ struct cdns_i2c {
struct clk *clk;
struct notifier_block clk_rate_change_nb;
u32 quirks;
+ struct i2c_bus_recovery_info rinfo;
#if IS_ENABLED(CONFIG_I2C_SLAVE)
u16 ctrl_reg_diva_divb;
struct i2c_client *slave;
@@ -752,6 +754,7 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
/* Wait for the signal of completion */
time_left = wait_for_completion_timeout(&id->xfer_done, adap->timeout);
if (time_left == 0) {
+ i2c_recover_bus(adap);
cdns_i2c_master_reset(adap);
dev_err(id->adap.dev.parent,
"timeout waiting on completion\n");
@@ -1212,6 +1215,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
id->adap.retries = 3; /* Default retry value. */
id->adap.algo_data = id;
id->adap.dev.parent = &pdev->dev;
+ id->adap.bus_recovery_info = &id->rinfo;
init_completion(&id->xfer_done);
snprintf(id->adap.name, sizeof(id->adap.name),
"Cadence I2C at %08lx", (unsigned long)r_mem->start);
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: cadence: Add standard bus recovery support
2021-04-15 23:25 Robert Hancock
@ 2021-04-20 13:23 ` Michal Simek
2021-06-30 16:40 ` Robert Hancock
0 siblings, 1 reply; 4+ messages in thread
From: Michal Simek @ 2021-04-20 13:23 UTC (permalink / raw)
To: Robert Hancock, michal.simek; +Cc: linux-i2c, Chirag Parekh
Hi,
On 4/16/21 1:25 AM, Robert Hancock wrote:
> Hook up the standard GPIO/pinctrl-based recovery support for this
> driver.
>
> Based on a patch "i2c: cadence: Recover bus after controller reset" by
> Chirag Parekh in the Xilinx kernel Git tree, but simplified to make use
> of more common code.
>
> Cc: Chirag Parekh <chiragp@xilinx.com>
> Signed-off-by: Robert Hancock <robert.hancock@calian.com>
> ---
> drivers/i2c/busses/i2c-cadence.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index c1bbc4caeb5c..d017bc64e759 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -178,6 +178,7 @@ enum cdns_i2c_slave_state {
> * @clk: Pointer to struct clk
> * @clk_rate_change_nb: Notifier block for clock rate changes
> * @quirks: flag for broken hold bit usage in r1p10
> + * @rinfo: Structure holding recovery information.
> * @ctrl_reg_diva_divb: value of fields DIV_A and DIV_B from CR register
> * @slave: Registered slave instance.
> * @dev_mode: I2C operating role(master/slave).
> @@ -202,6 +203,7 @@ struct cdns_i2c {
> struct clk *clk;
> struct notifier_block clk_rate_change_nb;
> u32 quirks;
> + struct i2c_bus_recovery_info rinfo;
> #if IS_ENABLED(CONFIG_I2C_SLAVE)
> u16 ctrl_reg_diva_divb;
> struct i2c_client *slave;
> @@ -752,6 +754,7 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
> /* Wait for the signal of completion */
> time_left = wait_for_completion_timeout(&id->xfer_done, adap->timeout);
> if (time_left == 0) {
> + i2c_recover_bus(adap);
> cdns_i2c_master_reset(adap);
> dev_err(id->adap.dev.parent,
> "timeout waiting on completion\n");
> @@ -1212,6 +1215,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
> id->adap.retries = 3; /* Default retry value. */
> id->adap.algo_data = id;
> id->adap.dev.parent = &pdev->dev;
> + id->adap.bus_recovery_info = &id->rinfo;
> init_completion(&id->xfer_done);
> snprintf(id->adap.name, sizeof(id->adap.name),
> "Cadence I2C at %08lx", (unsigned long)r_mem->start);
>
My colleague sent pinctrl driver for ZynqMP already. This driver can be
used on Zynq where pinctrl driver already exists upstream.
It looks quite nice.
Acked-by: Michal Simek <michal.simek@xilinx.com>
Thanks,
Michal
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: cadence: Add standard bus recovery support
2021-04-20 13:23 ` Michal Simek
@ 2021-06-30 16:40 ` Robert Hancock
0 siblings, 0 replies; 4+ messages in thread
From: Robert Hancock @ 2021-06-30 16:40 UTC (permalink / raw)
To: michal.simek; +Cc: chiragp, linux-i2c
On Tue, 2021-04-20 at 15:23 +0200, Michal Simek wrote:
> Hi,
>
> On 4/16/21 1:25 AM, Robert Hancock wrote:
> > Hook up the standard GPIO/pinctrl-based recovery support for this
> > driver.
> >
> > Based on a patch "i2c: cadence: Recover bus after controller reset" by
> > Chirag Parekh in the Xilinx kernel Git tree, but simplified to make use
> > of more common code.
> >
> > Cc: Chirag Parekh <chiragp@xilinx.com>
> > Signed-off-by: Robert Hancock <robert.hancock@calian.com>
> > ---
> > drivers/i2c/busses/i2c-cadence.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-
> > cadence.c
> > index c1bbc4caeb5c..d017bc64e759 100644
> > --- a/drivers/i2c/busses/i2c-cadence.c
> > +++ b/drivers/i2c/busses/i2c-cadence.c
> > @@ -178,6 +178,7 @@ enum cdns_i2c_slave_state {
> > * @clk: Pointer to struct clk
> > * @clk_rate_change_nb: Notifier block for clock rate changes
> > * @quirks: flag for broken hold bit usage in r1p10
> > + * @rinfo: Structure holding recovery information.
> > * @ctrl_reg_diva_divb: value of fields DIV_A and DIV_B from CR register
> > * @slave: Registered slave instance.
> > * @dev_mode: I2C operating role(master/slave).
> > @@ -202,6 +203,7 @@ struct cdns_i2c {
> > struct clk *clk;
> > struct notifier_block clk_rate_change_nb;
> > u32 quirks;
> > + struct i2c_bus_recovery_info rinfo;
> > #if IS_ENABLED(CONFIG_I2C_SLAVE)
> > u16 ctrl_reg_diva_divb;
> > struct i2c_client *slave;
> > @@ -752,6 +754,7 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id,
> > struct i2c_msg *msg,
> > /* Wait for the signal of completion */
> > time_left = wait_for_completion_timeout(&id->xfer_done, adap->timeout);
> > if (time_left == 0) {
> > + i2c_recover_bus(adap);
> > cdns_i2c_master_reset(adap);
> > dev_err(id->adap.dev.parent,
> > "timeout waiting on completion\n");
> > @@ -1212,6 +1215,7 @@ static int cdns_i2c_probe(struct platform_device
> > *pdev)
> > id->adap.retries = 3; /* Default retry value. */
> > id->adap.algo_data = id;
> > id->adap.dev.parent = &pdev->dev;
> > + id->adap.bus_recovery_info = &id->rinfo;
> > init_completion(&id->xfer_done);
> > snprintf(id->adap.name, sizeof(id->adap.name),
> > "Cadence I2C at %08lx", (unsigned long)r_mem->start);
> >
>
> My colleague sent pinctrl driver for ZynqMP already. This driver can be
> used on Zynq where pinctrl driver already exists upstream.
>
> It looks quite nice.
>
> Acked-by: Michal Simek <michal.simek@xilinx.com>
>
Any other feedback on this patch? I only saw the ack from Michal. The pinctrl
driver which is needed to make this useful on the ZynqMP platform has now been
merged into mainline (commit 8b242ca700f8043be56542efd8360056358a42ed,
"pinctrl: Add Xilinx ZynqMP pinctrl driver support").
> Thanks,
> Michal
--
Robert Hancock
Senior Hardware Designer, Calian Advanced Technologies
www.calian.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-30 12:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 12:18 [PATCH] i2c: cadence: Add standard bus recovery support Shubhrajyoti Datta
-- strict thread matches above, loose matches on Subject: below --
2021-04-15 23:25 Robert Hancock
2021-04-20 13:23 ` Michal Simek
2021-06-30 16:40 ` Robert Hancock
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).