i2c: designware: fix slave not acknowledge when address matched
Subsystems (3)
PATCH 1/1 i2c: designware: fix slave not acknowledge when address matched
From: liao zenghui <[email protected]>
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.
---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(-)
drivers/i2c/busses/i2c-designware-core.h +0 -0
@@ -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;
}
drivers/i2c/busses/i2c-designware-master.c +0 -0
@@ -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;
drivers/i2c/busses/i2c-designware-slave.c +0 -0
@@ -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
Mika Westerberg
maintainerHi,
Quoted 8 lines · On Fri, Mar 10, 2023 at 03:10:46PM +0800, [email protected] wrote:
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);
Looks like this patch has some whitespace damage. Probably good to use git send-email or so to make sure the formatting stays intact.