linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@amd.com>
To: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>,
	<linux-i2c@vger.kernel.org>
Cc: <michal.simek@xilinx.com>,
	Robert Hancock <robert.hancock@calian.com>,
	Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
Subject: Re: [PATCH v2] i2c: cadence: Add standard bus recovery support
Date: Mon, 4 Jul 2022 13:30:07 +0200	[thread overview]
Message-ID: <b5cf2f85-37a5-07ab-9ce6-a4cfab60b7fe@amd.com> (raw)
In-Reply-To: <1656914060-24445-1-git-send-email-shubhrajyoti.datta@xilinx.com>



On 7/4/22 07:54, Shubhrajyoti Datta wrote:
> From: Robert Hancock <robert.hancock@calian.com>
> 
> Hook up the standard GPIO/pinctrl-based recovery support..
> In the discurssion

typo

> 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>
> ---
> v2:
> Updated the busbusy check on a timeout
> 
>   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);

I have no problem with it. I expect you have tested it on the real HW.

Acked-by: Michal Simek <michal.simek@amd.com>

Thanks,
Michal


  reply	other threads:[~2022-07-04 11:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04  5:54 [PATCH v2] i2c: cadence: Add standard bus recovery support Shubhrajyoti Datta
2022-07-04 11:30 ` Michal Simek [this message]
2022-07-07 21:03 ` Wolfram Sang
2022-07-07 22:14   ` Robert Hancock
2022-07-14  7:22     ` Datta, Shubhrajyoti
  -- strict thread matches above, loose matches on Subject: below --
2021-11-29  9:01 Shubhrajyoti Datta
2021-11-29 12:00 ` Wolfram Sang
2022-01-07 22:24   ` Robert Hancock
2022-02-23 16:51     ` Shubhrajyoti Datta
2022-04-12 10:16       ` Shubhrajyoti Datta

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=b5cf2f85-37a5-07ab-9ce6-a4cfab60b7fe@amd.com \
    --to=michal.simek@amd.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=robert.hancock@calian.com \
    --cc=shubhrajyoti.datta@amd.com \
    --cc=shubhrajyoti.datta@xilinx.com \
    /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).