lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
 <TYCPR01MB1209372C80BA19EA179383726C2822@TYCPR01MB12093.jpnprd01.prod.outlook.com>
Date: Thu, 1 May 2025 14:16:44 +0000
From: Fabrizio Castro <fabrizio.castro.jz@...esas.com>
To: Prabhakar <prabhakar.csengg@...il.com>, Chris Brandt
	<Chris.Brandt@...esas.com>, Andi Shyti <andi.shyti@...nel.org>, Wolfram Sang
	<wsa+renesas@...g-engineering.com>, Geert Uytterhoeven
	<geert+renesas@...der.be>, Andy Shevchenko <andy@...nel.org>
CC: "linux-renesas-soc@...r.kernel.org" <linux-renesas-soc@...r.kernel.org>,
	"linux-i2c@...r.kernel.org" <linux-i2c@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, Biju Das
	<biju.das.jz@...renesas.com>, Prabhakar Mahadev Lad
	<prabhakar.mahadev-lad.rj@...renesas.com>
Subject: RE: [PATCH v9 1/2] i2c: riic: Implement bus recovery

> From: Prabhakar <prabhakar.csengg@...il.com>
> Sent: 30 April 2025 20:47
> Subject: [PATCH v9 1/2] i2c: riic: Implement bus recovery
> 
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@...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@...renesas.com>

Reviewed-by: Fabrizio Castro <fabrizio.castro.jz@...esas.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ