From: <liao.zenghui@zte.com.cn>
To: <jarkko.nikula@linux.intel.com>
Cc: <andriy.shevchenko@linux.intel.com>,
<mika.westerberg@linux.intel.com>, <jsd@semihalf.com>,
<linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] i2c: designware: fix slave not acknowledge when address matched
Date: Fri, 10 Mar 2023 15:10:46 +0800 (CST) [thread overview]
Message-ID: <202303101510464477898@zte.com.cn> (raw)
From: liao zenghui <liao.zenghui@zte.com.cn>
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@zte.com.cn>
---
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
next reply other threads:[~2023-03-10 7:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 7:10 liao.zenghui [this message]
2023-03-10 7:19 ` [PATCH] i2c: designware: fix slave not acknowledge when address matched Mika Westerberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202303101510464477898@zte.com.cn \
--to=liao.zenghui@zte.com.cn \
--cc=andriy.shevchenko@linux.intel.com \
--cc=jarkko.nikula@linux.intel.com \
--cc=jsd@semihalf.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox