@@ -65,6 +65,27 @@ static inline void i2c_smartbond_pm_policy_state_lock_put(struct i2c_smartbond_d
6565#endif
6666}
6767
68+ static inline bool i2c_smartbond_is_idle (const struct device * dev )
69+ {
70+ const struct i2c_smartbond_cfg * config = dev -> config ;
71+ uint32_t mask = I2C_I2C_STATUS_REG_I2C_ACTIVITY_Msk |
72+ I2C_I2C_STATUS_REG_RFNE_Msk |
73+ I2C_I2C_STATUS_REG_TFE_Msk ;
74+
75+ return ((config -> regs -> I2C_STATUS_REG & mask ) == I2C_I2C_STATUS_REG_TFE_Msk );
76+ }
77+
78+ static void i2c_smartbond_disable_when_inactive (const struct device * dev )
79+ {
80+ const struct i2c_smartbond_cfg * config = dev -> config ;
81+
82+ if ((config -> regs -> I2C_ENABLE_REG & I2C_I2C_ENABLE_REG_I2C_EN_Msk )) {
83+ while (!i2c_smartbond_is_idle (dev )) {
84+ };
85+ config -> regs -> I2C_ENABLE_REG &= ~I2C_I2C_ENABLE_REG_I2C_EN_Msk ;
86+ }
87+ }
88+
6889static int i2c_smartbond_configure (const struct device * dev , uint32_t dev_config )
6990{
7091 const struct i2c_smartbond_cfg * config = dev -> config ;
@@ -105,11 +126,7 @@ static int i2c_smartbond_configure(const struct device *dev, uint32_t dev_config
105126
106127 key = k_spin_lock (& data -> lock );
107128
108- if (!!(config -> regs -> I2C_ENABLE_REG & I2C_I2C_ENABLE_REG_I2C_EN_Msk )) {
109- while (!!(config -> regs -> I2C_STATUS_REG & I2C_I2C_STATUS_REG_I2C_ACTIVITY_Msk )) {
110- };
111- config -> regs -> I2C_ENABLE_REG &= ~I2C_I2C_ENABLE_REG_I2C_EN_Msk ;
112- }
129+ i2c_smartbond_disable_when_inactive (dev );
113130
114131 /* Write control register*/
115132 config -> regs -> I2C_CON_REG = con_reg ;
@@ -319,7 +336,7 @@ static int i2c_smartbond_transfer(const struct device *dev, struct i2c_msg *msgs
319336 struct i2c_smartbond_data * data = dev -> data ;
320337 int ret = 0 ;
321338
322- while (!!( config -> regs -> I2C_STATUS_REG & I2C_I2C_STATUS_REG_I2C_ACTIVITY_Msk )) {
339+ while (!i2c_smartbond_is_idle ( dev )) {
323340 };
324341
325342 ret = i2c_smartbond_prep_transfer (dev , msgs , num_msgs , addr );
0 commit comments