From: liao zenghui <liao.zenghui@xxxxxxxxxx> According to Chapter 5.1.31 of the databook "DesignWare DW_apb_i2c Databook (2.03a)", the bit[19] of the IC_ENABLE register defaults to one when the configuration parameter of the controller is "IC_MULTI_SAR_EN == 1". This bit controls whether the slave send acknowledge signal to the master after an address match. Because setting the IC_ENABLE register using "1" and "0" directly in function "__i2c_dw_enabl" and function "__i2c_dw_disable_nowait", results in the bit[19] of this register being zero, no acknowledge signal is generated when address matched. Therefore, the two functions are modified.Restore the reset value of the IC_ENABLE register in the function "__i2c_dw_disable_nowait". Only bit[0] is set in the function "__i2c_dw_enable" and the other bits remain unchanged. In addition, the code for determining whether the i2c controller is enabled using the value of the IC_ENABLE register is modified. Otherwise, when "C_MULTI_SAR_EN==1" and the bit[19] of the IC_ENABLE register is 1, the determination of the variable "enable" will be not work. Signed-off-by: liao zenghui <liao.zenghui@xxxxxxxxxx> --- drivers/i2c/busses/i2c-designware-core.h | 13 +++++++++++-- drivers/i2c/busses/i2c-designware-master.c | 2 +- drivers/i2c/busses/i2c-designware-slave.c | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index 050d8c63ad3c..49b2f8819952 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -113,6 +113,9 @@ #define DW_IC_STATUS_MASTER_ACTIVITY BIT(5) #define DW_IC_STATUS_SLAVE_ACTIVITY BIT(6) +#define DW_IC_ENABLE_ENABLE BIT(0) +#define DW_IC_ENABLE_SAR_EN BIT(19) + #define DW_IC_SDA_HOLD_RX_SHIFT 16 #define DW_IC_SDA_HOLD_RX_MASK GENMASK(23, 16) @@ -333,13 +336,19 @@ void i2c_dw_disable(struct dw_i2c_dev *dev); static inline void __i2c_dw_enable(struct dw_i2c_dev *dev) { + u32 enabled; + dev->status |= STATUS_ACTIVE; - regmap_write(dev->map, DW_IC_ENABLE, 1); + regmap_read(dev->map, DW_IC_ENABLE, &enabled); + regmap_write(dev->map, DW_IC_ENABLE, enabled | DW_IC_ENABLE_ENABLE); } static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev) { - regmap_write(dev->map, DW_IC_ENABLE, 0); + u32 enabled; + + regmap_read(dev->map, DW_IC_ENABLE, &enabled); + regmap_write(dev->map, DW_IC_ENABLE, enabled & DW_IC_ENABLE_SAR_EN); dev->status &= ~STATUS_ACTIVE; } diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index 55ea91a63382..f2cc25f1c3c7 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -719,7 +719,7 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) regmap_read(dev->map, DW_IC_ENABLE, &enabled); regmap_read(dev->map, DW_IC_RAW_INTR_STAT, &stat); - if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY)) + if (!(enabled & DW_IC_ENABLE_ENABLE) || !(stat & ~DW_IC_INTR_ACTIVITY)) return IRQ_NONE; if (pm_runtime_suspended(dev->dev) || stat == GENMASK(31, 0)) return IRQ_NONE; diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c index cec25054bb24..0da1e0291001 100644 --- a/drivers/i2c/busses/i2c-designware-slave.c +++ b/drivers/i2c/busses/i2c-designware-slave.c @@ -158,7 +158,8 @@ static irqreturn_t i2c_dw_isr_slave(int this_irq, void *dev_id) regmap_read(dev->map, DW_IC_STATUS, &tmp); slave_activity = ((tmp & DW_IC_STATUS_SLAVE_ACTIVITY) >> 6); - if (!enabled || !(raw_stat & ~DW_IC_INTR_ACTIVITY) || !dev->slave) + if (!(enabled & DW_IC_ENABLE_ENABLE) || + !(raw_stat & ~DW_IC_INTR_ACTIVITY) || !dev->slave) return IRQ_NONE; stat = i2c_dw_read_clear_intrbits_slave(dev); -- 2.25.1