2022-05-24 20:03:20

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCHv2 1/2] i2c: designware: introduce a custom scl recovery for SoCFPGA platforms

On Tue, May 24, 2022 at 08:54:40AM -0500, Dinh Nguyen wrote:
> The I2C pins on the SoCFPGA platforms do not go through a GPIO module,
> thus cannot be recovered by the default method of by doing a GPIO access.
> Only a reset of the I2C IP block can a recovery be successful.

Better now, but see my additional comments.

...

> + switch (dev->flags & MODEL_MASK) {
> + case MODEL_SOCFPGA:
> + rinfo->recover_bus = i2c_socfpga_scl_recovery;
> + break;
> + default:
> + rinfo->recover_bus = i2c_generic_scl_recovery;
> + break;
> + }

> + adap->bus_recovery_info = rinfo;

Usually we do not assign the pointer while data structure is incomplete.
That's said, please leave this line as it was.

On top of that, why you can't move the above switch to the place where old
function was assigned?

--
With Best Regards,
Andy Shevchenko




2022-05-28 20:25:23

by Dinh Nguyen

[permalink] [raw]
Subject: Re: [PATCHv2 1/2] i2c: designware: introduce a custom scl recovery for SoCFPGA platforms



On 5/24/22 11:43, Andy Shevchenko wrote:
> On Tue, May 24, 2022 at 08:54:40AM -0500, Dinh Nguyen wrote:
>> The I2C pins on the SoCFPGA platforms do not go through a GPIO module,
>> thus cannot be recovered by the default method of by doing a GPIO access.
>> Only a reset of the I2C IP block can a recovery be successful.
>
> Better now, but see my additional comments.
>
> ...
>
>> + switch (dev->flags & MODEL_MASK) {
>> + case MODEL_SOCFPGA:
>> + rinfo->recover_bus = i2c_socfpga_scl_recovery;
>> + break;
>> + default:
>> + rinfo->recover_bus = i2c_generic_scl_recovery;
>> + break;
>> + }
>
>> + adap->bus_recovery_info = rinfo;
>
> Usually we do not assign the pointer while data structure is incomplete.
> That's said, please leave this line as it was.
>
> On top of that, why you can't move the above switch to the place where old
> function was assigned?
>

I have to put the switch statement before the call to
devm_gpiod_get_optional(), otherwise the recover_bus function pointer
will not get set.

Dinh

2022-06-01 21:17:45

by Dinh Nguyen

[permalink] [raw]
Subject: Re: [PATCHv2 1/2] i2c: designware: introduce a custom scl recovery for SoCFPGA platforms



On 5/24/22 11:43, Andy Shevchenko wrote:
> On Tue, May 24, 2022 at 08:54:40AM -0500, Dinh Nguyen wrote:
>> The I2C pins on the SoCFPGA platforms do not go through a GPIO module,
>> thus cannot be recovered by the default method of by doing a GPIO access.
>> Only a reset of the I2C IP block can a recovery be successful.
>
> Better now, but see my additional comments.
>
> ...
>
>> + switch (dev->flags & MODEL_MASK) {
>> + case MODEL_SOCFPGA:
>> + rinfo->recover_bus = i2c_socfpga_scl_recovery;
>> + break;
>> + default:
>> + rinfo->recover_bus = i2c_generic_scl_recovery;
>> + break;
>> + }
>
>> + adap->bus_recovery_info = rinfo;
>
> Usually we do not assign the pointer while data structure is incomplete.
> That's said, please leave this line as it was.
>
> On top of that, why you can't move the above switch to the place where old
> function was assigned?
>

The reason is the assignment of the recover_bus needs to get done before
the call to devm_gpiod_get_optional(), otherwise, the assignment is not
taking place because of an error after returning from
devm_gpiod_get_optional().

Dinh

2022-06-10 11:40:18

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCHv2 1/2] i2c: designware: introduce a custom scl recovery for SoCFPGA platforms

On Wed, Jun 01, 2022 at 08:48:07AM -0500, Dinh Nguyen wrote:
> On 5/24/22 11:43, Andy Shevchenko wrote:
> > On Tue, May 24, 2022 at 08:54:40AM -0500, Dinh Nguyen wrote:

...

> > > + switch (dev->flags & MODEL_MASK) {
> > > + case MODEL_SOCFPGA:
> > > + rinfo->recover_bus = i2c_socfpga_scl_recovery;
> > > + break;
> > > + default:
> > > + rinfo->recover_bus = i2c_generic_scl_recovery;
> > > + break;
> > > + }
> >
> > > + adap->bus_recovery_info = rinfo;
> >
> > Usually we do not assign the pointer while data structure is incomplete.
> > That's said, please leave this line as it was.
> >
> > On top of that, why you can't move the above switch to the place where old
> > function was assigned?
>
> The reason is the assignment of the recover_bus needs to get done before the
> call to devm_gpiod_get_optional(), otherwise, the assignment is not taking
> place because of an error after returning from devm_gpiod_get_optional().

Update commit message accordingly then.

Also consider moving GPIO request part in the code, maybe it will bring better
looking / grouped code. Try and see, then choose the best one.

--
With Best Regards,
Andy Shevchenko