diff mbox

i2c: st: Implement i2c_bus_recovery_info callbacks

Message ID 20160424211044.GD4317@katana (mailing list archive)
State New, archived
Headers show

Commit Message

Wolfram Sang April 24, 2016, 9:10 p.m. UTC
> +/*
> + * i2c bus recovery routines
> + * get_scl and set_scl must be defined to avoid the recover_bus field of
> + * i2c_bus_recovery_info to be overriden with NULL during the
> + * i2c_add_adapter call
> + */

Oh, that shouldn't be like this. Can you try this patch and remove the
empty functions please?


> +static int st_i2c_recover_bus(struct i2c_adapter *i2c_adap)
> +{

Can you describe what the function does? It is not clear to me that it
generates 9 scl pulses.

> +	struct st_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap);
> +	u32 ctl;
> +
> +	dev_err(i2c_dev->dev, "Trying to recover bus\n");

This is not an error. Either dev_dbg or drop it, I'd say.

> +
> +	/* Disable interrupts */
> +	writel_relaxed(0, i2c_dev->base + SSC_IEN);
> +
> +	st_i2c_hw_config(i2c_dev);
> +
> +	ctl = SSC_CTL_EN | SSC_CTL_MS |	SSC_CTL_EN_RX_FIFO | SSC_CTL_EN_TX_FIFO;
> +	st_i2c_set_bits(i2c_dev->base + SSC_CTL, ctl);
> +
> +	st_i2c_clr_bits(i2c_dev->base + SSC_I2C, SSC_I2C_I2CM);
> +	usleep_range(8000, 10000);
> +
> +	writel_relaxed(0, i2c_dev->base + SSC_TBUF);
> +	usleep_range(2000, 4000);
> +	st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_I2CM);
> +
> +	return 0;
> +}

Thanks,

   Wolfram

Comments

Maxime Coquelin April 28, 2016, 1:30 p.m. UTC | #1
Hi Wolfram,

On 04/24/2016 11:10 PM, Wolfram Sang wrote:
>> +/*
>> + * i2c bus recovery routines
>> + * get_scl and set_scl must be defined to avoid the recover_bus field of
>> + * i2c_bus_recovery_info to be overriden with NULL during the
>> + * i2c_add_adapter call
>> + */
> Oh, that shouldn't be like this. Can you try this patch and remove the
> empty functions please?
>
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 4979728f7fb2de..604936955807e5 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -1595,10 +1595,12 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
>   
>   			bri->get_scl = get_scl_gpio_value;
>   			bri->set_scl = set_scl_gpio_value;
> -		} else if (!bri->set_scl || !bri->get_scl) {
> +		} else if (bri->recover_bus == i2c_generic_scl_recovery) {
>   			/* Generic SCL recovery */
> -			dev_err(&adap->dev, "No {get|set}_gpio() found, not using recovery\n");
> -			adap->bus_recovery_info = NULL;
> +			if (!bri->set_scl || !bri->get_scl) {
> +				dev_err(&adap->dev, "No {get|set}_scl() found, not using recovery\n");
> +				adap->bus_recovery_info = NULL;
> +			}
>   		}
>   	}
>   
>
>> +static int st_i2c_recover_bus(struct i2c_adapter *i2c_adap)
>> +{
> Can you describe what the function does? It is not clear to me that it
> generates 9 scl pulses.
I agree, it would need some comments.
This IP is dual-role, it can do either SPI or I2C.
The trick is to switch to SPI mode, 9 bits words and write a 0,
so that 9 clock pulses are generated.

This is easier to manage than switching to GPIO mode,
as we don't need to provide the gpio handles in DT, and no need to 
put/get the pinctrl handle.

Regards,
Maxime
Wolfram Sang April 28, 2016, 2:57 p.m. UTC | #2
> The trick is to switch to SPI mode, 9 bits words and write a 0,
> so that 9 clock pulses are generated.

Heh. As long as it works :) But as you said, it really needs a comment.
Maxime Coquelin April 29, 2016, 11:26 a.m. UTC | #3
On 04/28/2016 04:57 PM, Wolfram Sang wrote:
>> The trick is to switch to SPI mode, 9 bits words and write a 0,
>> so that 9 clock pulses are generated.
> Heh. As long as it works :) But as you said, it really needs a comment.
>
:)
I didn't faced the problem myself, but it looks good with an oscilloscope,
and a customer reported it to work.

Peter, will you resend with adding the explanations I provided as comment?

Thanks in advance,
Maxime
Peter Griffin April 29, 2016, 2:03 p.m. UTC | #4
Hi Maxime,

On Fri, 29 Apr 2016, Maxime Coquelin wrote:

> 
> 
> On 04/28/2016 04:57 PM, Wolfram Sang wrote:
> >>The trick is to switch to SPI mode, 9 bits words and write a 0,
> >>so that 9 clock pulses are generated.
> >Heh. As long as it works :) But as you said, it really needs a comment.
> >
> :)
> I didn't faced the problem myself, but it looks good with an oscilloscope,
> and a customer reported it to work.
> 
> Peter, will you resend with adding the explanations I provided as comment?
>
Yes I'll send a v2 with your comment added.

Peter
Wolfram Sang May 11, 2016, 3:01 p.m. UTC | #5
> Yes I'll send a v2 with your comment added.

Any news?
Peter Griffin May 11, 2016, 3:26 p.m. UTC | #6
Hi Wolfram,

On Wed, 11 May 2016, Wolfram Sang wrote:

> > Yes I'll send a v2 with your comment added.
> 
> Any news?
>
Sorry, I will re-send it in a few minutes.

Peter.
Peter Griffin May 11, 2016, 4:22 p.m. UTC | #7
Hi Wolfram,

On Sun, 24 Apr 2016, Wolfram Sang wrote:

> > +/*
> > + * i2c bus recovery routines
> > + * get_scl and set_scl must be defined to avoid the recover_bus field of
> > + * i2c_bus_recovery_info to be overriden with NULL during the
> > + * i2c_add_adapter call
> > + */
> 
> Oh, that shouldn't be like this. Can you try this patch and remove the
> empty functions please?

That works, so will need to be applied along with my v2 which I just sent.

regards,

Peter.
diff mbox

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 4979728f7fb2de..604936955807e5 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1595,10 +1595,12 @@  static int i2c_register_adapter(struct i2c_adapter *adap)
 
 			bri->get_scl = get_scl_gpio_value;
 			bri->set_scl = set_scl_gpio_value;
-		} else if (!bri->set_scl || !bri->get_scl) {
+		} else if (bri->recover_bus == i2c_generic_scl_recovery) {
 			/* Generic SCL recovery */
-			dev_err(&adap->dev, "No {get|set}_gpio() found, not using recovery\n");
-			adap->bus_recovery_info = NULL;
+			if (!bri->set_scl || !bri->get_scl) {
+				dev_err(&adap->dev, "No {get|set}_scl() found, not using recovery\n");
+				adap->bus_recovery_info = NULL;
+			}
 		}
 	}