Message ID | 20250430194647.332553-1-prabhakar.mahadev-lad.rj@bp.renesas.com |
---|---|
Headers | show |
Series | i2c: riic: Implement bus recovery | expand |
On Wed, Apr 30, 2025 at 08:46:46PM +0100, Prabhakar wrote: > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > Implement I2C bus recovery support for the RIIC controller by making use > of software-controlled SCL and SDA line manipulation. The controller allows > forcing SCL and SDA levels through control bits, which enables generation > of manual clock pulses and a stop condition to free a stuck bus. > > This implementation wires up the bus recovery mechanism using > i2c_generic_scl_recovery and provides get/set operations for SCL and SDA. > > This allows the RIIC driver to recover from bus hang scenarios where SDA > is held low by a slave. > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> From: Prabhakar <prabhakar.csengg@gmail.com> > Sent: 30 April 2025 20:47 > Subject: [PATCH v9 1/2] i2c: riic: Implement bus recovery > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > Implement I2C bus recovery support for the RIIC controller by making use > of software-controlled SCL and SDA line manipulation. The controller allows > forcing SCL and SDA levels through control bits, which enables generation > of manual clock pulses and a stop condition to free a stuck bus. > > This implementation wires up the bus recovery mechanism using > i2c_generic_scl_recovery and provides get/set operations for SCL and SDA. > > This allows the RIIC driver to recover from bus hang scenarios where SDA > is held low by a slave. > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com> > --- > drivers/i2c/busses/i2c-riic.c | 53 +++++++++++++++++++++++++++++++++-- > 1 file changed, 51 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c > index d7dddd6c296a..740e53bdb2a9 100644 > --- a/drivers/i2c/busses/i2c-riic.c > +++ b/drivers/i2c/busses/i2c-riic.c > @@ -53,6 +53,8 @@ > #define ICCR1_IICRST BIT(6) > #define ICCR1_SOWP BIT(4) > #define ICCR1_SCLI BIT(1) > +#define ICCR1_SCLO BIT(3) > +#define ICCR1_SDAO BIT(2) > #define ICCR1_SDAI BIT(0) > > #define ICCR2_BBSY BIT(7) > @@ -151,11 +153,11 @@ static int riic_bus_barrier(struct riic_dev *riic) > ret = readb_poll_timeout(riic->base + riic->info->regs[RIIC_ICCR2], val, > !(val & ICCR2_BBSY), 10, riic->adapter.timeout); > if (ret) > - return ret; > + return i2c_recover_bus(&riic->adapter); > > if ((riic_readb(riic, RIIC_ICCR1) & (ICCR1_SDAI | ICCR1_SCLI)) != > (ICCR1_SDAI | ICCR1_SCLI)) > - return -EBUSY; > + return i2c_recover_bus(&riic->adapter); > > return 0; > } > @@ -439,6 +441,52 @@ static int riic_init_hw(struct riic_dev *riic) > return 0; > } > > +static int riic_get_scl(struct i2c_adapter *adap) > +{ > + struct riic_dev *riic = i2c_get_adapdata(adap); > + > + return !!(riic_readb(riic, RIIC_ICCR1) & ICCR1_SCLI); > +} > + > +static int riic_get_sda(struct i2c_adapter *adap) > +{ > + struct riic_dev *riic = i2c_get_adapdata(adap); > + > + return !!(riic_readb(riic, RIIC_ICCR1) & ICCR1_SDAI); > +} > + > +static void riic_set_scl(struct i2c_adapter *adap, int val) > +{ > + struct riic_dev *riic = i2c_get_adapdata(adap); > + > + if (val) > + riic_clear_set_bit(riic, ICCR1_SOWP, ICCR1_SCLO, RIIC_ICCR1); > + else > + riic_clear_set_bit(riic, ICCR1_SOWP | ICCR1_SCLO, 0, RIIC_ICCR1); > + > + riic_clear_set_bit(riic, 0, ICCR1_SOWP, RIIC_ICCR1); > +} > + > +static void riic_set_sda(struct i2c_adapter *adap, int val) > +{ > + struct riic_dev *riic = i2c_get_adapdata(adap); > + > + if (val) > + riic_clear_set_bit(riic, ICCR1_SOWP, ICCR1_SDAO, RIIC_ICCR1); > + else > + riic_clear_set_bit(riic, ICCR1_SOWP | ICCR1_SDAO, 0, RIIC_ICCR1); > + > + riic_clear_set_bit(riic, 0, ICCR1_SOWP, RIIC_ICCR1); > +} > + > +static struct i2c_bus_recovery_info riic_bri = { > + .recover_bus = i2c_generic_scl_recovery, > + .get_scl = riic_get_scl, > + .set_scl = riic_set_scl, > + .get_sda = riic_get_sda, > + .set_sda = riic_set_sda, > +}; > + > static const struct riic_irq_desc riic_irqs[] = { > { .res_num = 0, .isr = riic_tend_isr, .name = "riic-tend" }, > { .res_num = 1, .isr = riic_rdrf_isr, .name = "riic-rdrf" }, > @@ -495,6 +543,7 @@ static int riic_i2c_probe(struct platform_device *pdev) > adap->algo = &riic_algo; > adap->dev.parent = dev; > adap->dev.of_node = dev->of_node; > + adap->bus_recovery_info = &riic_bri; > > init_completion(&riic->msg_done); > > -- > 2.49.0
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Hi all, This patch series implements bus recovery for the RIIC driver. The first patch implements the bus recovery mechanism, while the second patch handles arbitration loss. v8>->v9: - Dropped Tested-by and Reviewed-by tags from patch 1/2 - Updated commit message for patch 1/2 to include the new approach - New patch 2/2 added to handle arbitration loss v7->v8: - Included Acks from Andy and Fabrizio. v6->v7: - https://lore.kernel.org/all/20250203143511.629140-1-prabhakar.mahadev-lad.rj@bp.renesas.com/ v2->v6: - Included RB and TB from Claudiu. v1->v2: - Used single register read to check SDA/SCL lines Cheers, Prabhakar Lad Prabhakar (2): i2c: riic: Implement bus recovery i2c: riic: Recover from arbitration loss drivers/i2c/busses/i2c-riic.c | 63 +++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-)