mbox series

[v2,0/3] P2040/P2041 i2c recovery erratum

Message ID 20210507004047.4454-1-chris.packham@alliedtelesis.co.nz
Headers show
Series P2040/P2041 i2c recovery erratum | expand

Message

Chris Packham May 7, 2021, 12:40 a.m. UTC
The P2040/P2041 has an erratum where the i2c recovery scheme
documented in the reference manual (and currently implemented
in the i2c-mpc.c driver) does not work. The errata document
provides an alternative that does work. This series implements
that alternative and uses a property in the devicetree to
decide when the alternative mechanism is needed.

Chris Packham (3):
  dt-bindings: i2c: mpc: Add fsl,i2c-erratum-a004447 flag
  powerpc/fsl: set fsl,i2c-erratum-a004447 flag for P2041 i2c
    controllers
  i2c: mpc: implement erratum A-004447 workaround

 .../devicetree/bindings/i2c/i2c-mpc.yaml      |  7 ++
 arch/powerpc/boot/dts/fsl/p2041si-post.dtsi   | 16 ++++
 drivers/i2c/busses/i2c-mpc.c                  | 84 ++++++++++++++++++-
 3 files changed, 105 insertions(+), 2 deletions(-)

Comments

Andy Shevchenko May 7, 2021, 11:46 a.m. UTC | #1
On Fri, May 7, 2021 at 3:40 AM Chris Packham
<chris.packham@alliedtelesis.co.nz> wrote:
>
> The P2040/P2041 has an erratum where the normal i2c recovery mechanism
> does not work. Implement the alternative recovery mechanism documented
> in the P2040 Chip Errata Rev Q.

Thanks.

> +static int i2c_mpc_wait_sr(struct mpc_i2c *i2c, int mask)
> +{
> +       int ret;
> +       u8 val;
> +
> +       ret = readb_poll_timeout(i2c->base + MPC_I2C_SR, val,
> +                                val & mask, 0, 100);
> +
> +       return ret;
> +}

So, now you may shrink it even further, i.e.

       void __iomem *sr = i2c->base + MPC_I2C_SR;
       u8 val;

       return readb_poll_timeout(sr, val, val & mask, 0, 100);
Andy Shevchenko May 7, 2021, 3:36 p.m. UTC | #2
On Fri, May 7, 2021 at 5:52 PM Joakim Tjernlund
<Joakim.Tjernlund@infinera.com> wrote:
> On Fri, 2021-05-07 at 14:46 +0300, Andy Shevchenko wrote:
> > On Fri, May 7, 2021 at 3:40 AM Chris Packham
> > <chris.packham@alliedtelesis.co.nz> wrote:

...

> > So, now you may shrink it even further, i.e.
> >
> >        void __iomem *sr = i2c->base + MPC_I2C_SR;
> >        u8 val;
> >
> >        return readb_poll_timeout(sr, val, val & mask, 0, 100);
> >
>
> val looks uninitialised before use?

Nope.

Thinking about naming, perhaps

        void __iomem *addr = i2c->base + MPC_I2C_SR;
        u8 sr; // or leave as val?

        return readb_poll_timeout(addr, sr, sr & mask, 0, 100);

would be more clear.
Rob Herring (Arm) May 11, 2021, 3:33 p.m. UTC | #3
On Sun, May 9, 2021 at 4:08 PM Chris Packham
<Chris.Packham@alliedtelesis.co.nz> wrote:
>
>
> On 8/05/21 9:49 am, Rob Herring wrote:
> > On Fri, May 07, 2021 at 12:40:45PM +1200, Chris Packham wrote:
> >> Document the fsl,i2c-erratum-a004447 flag which indicates the presence
> >> of an i2c erratum on some QorIQ SoCs.
> >>
> >> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> >> ---
> >>   Documentation/devicetree/bindings/i2c/i2c-mpc.yaml | 7 +++++++
> >>   1 file changed, 7 insertions(+)
> >>
> >> diff --git a/Documentation/devicetree/bindings/i2c/i2c-mpc.yaml b/Documentation/devicetree/bindings/i2c/i2c-mpc.yaml
> >> index 7b553d559c83..98c6fcf7bf26 100644
> >> --- a/Documentation/devicetree/bindings/i2c/i2c-mpc.yaml
> >> +++ b/Documentation/devicetree/bindings/i2c/i2c-mpc.yaml
> >> @@ -46,6 +46,13 @@ properties:
> >>       description: |
> >>         I2C bus timeout in microseconds
> >>
> >> +  fsl,i2c-erratum-a004447:
> >> +    $ref: /schemas/types.yaml#/definitions/flag
> >> +    description: |
> >> +      Indicates the presence of QorIQ erratum A-004447, which
> >> +      says that the standard i2c recovery scheme mechanism does
> >> +      not work and an alternate implementation is needed.
> > The problem with adding a property for an errata is you have to update
> > the dtb. If you use the compatible string, then only an OS update is
> > needed. That assumes you have specific enough compatible strings.
>
> I was following the style of the existing fsl,usb-erratum-a007792 or
> fsl,erratum-a008585 properties. But that's not really a compelling reason.
>
> The existing compatible string is "fsl-i2c" and it's used by pretty much
> every powerpc QorIQ SoC. There are some specific compatible strings in
> the driver for some of the older mpc SoCs. A more specific compatible
> string will work although determining which ones are affected might be a
> bit troublesome. That we know of the P2041 and P1010 are affected but I
> suspect there may be more. One disadvantage of using the compatible
> string is that as affected SoCs are identified we'll have to update the
> driver to know that SoC is affected and update the dtb to use it. With
> the property we'd just have to update the dtb.

If you don't have specific compatibles in the dtb already, then it's
mute as the point was to avoid the dtb update.

> I'm not too fussed either way so if that's a hard NACK on the property I
> can send a version that uses compatible strings instead.

Acked-by: Rob Herring <robh@kernel.org>

You could still add compatibles for the next time...