From d521b926aaf141e5dfaf5ddc5d03009ba0cdeda2 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Wed, 19 Feb 2025 17:03:53 +0900 Subject: [PATCH] arch: cxd56xx: Improve i2c reset function During I2C communication between non-Spresense devices is performed, the I2C bus may freeze after initialization of the Spresense I2C. As a workaround, add clock gating process and disable GPIO input to the I2C reset function. Signed-off-by: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> --- arch/arm/src/cxd56xx/cxd56_i2c.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm/src/cxd56xx/cxd56_i2c.c b/arch/arm/src/cxd56xx/cxd56_i2c.c index 582a0643bd..f6b23dd2db 100644 --- a/arch/arm/src/cxd56xx/cxd56_i2c.c +++ b/arch/arm/src/cxd56xx/cxd56_i2c.c @@ -723,6 +723,10 @@ static int cxd56_i2c_reset(struct i2c_master_s *dev) nxmutex_lock(&priv->lock); + /* Disable clock gating (clock enable) */ + + cxd56_i2c_clock_gate_disable(priv->port); + /* Use GPIO configuration to un-wedge the bus */ cxd56_i2c_pincontrol(priv->port, false); @@ -794,6 +798,11 @@ static int cxd56_i2c_reset(struct i2c_master_s *dev) up_udelay(10); } + /* Disable input of SCL and SDA pins */ + + cxd56_gpio_config(scl_gpio, false); + cxd56_gpio_config(sda_gpio, false); + /* Generate a start followed by a stop to reset slave * state machines. */ @@ -820,6 +829,10 @@ out: cxd56_i2c_pincontrol(priv->port, true); + /* Enable clock gating (clock disable) */ + + cxd56_i2c_clock_gate_enable(priv->port); + /* Release the port for re-use by other clients */ nxmutex_unlock(&priv->lock);