Skip to contentSkip to conversation

i2c: designware: fix master is holding SCL low while ENABLE bit is disabled

PATCH In review kimriver liu 4 participants 6 messages Sep 5, 2024 – Sep 9, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: designware: fix master is holding SCL low while ENABLE bit is disabled

From: "kimriver.liu" <[email protected]>

Failure in normal Stop operational path

This failure happens rarely and is hard to reproduce. Debug trace showed that IC_STATUS had value of 0x23 when STOP_DET occurred, immediately disable ENABLE bit that can result in IC_RAW_INTR_STAT.MASTER_ON_HOLD holding SCL low.

Failure in ENABLE bit is disabled path

It was observed that master is holding SCL low and the IC_ENABLE is already disabled, Enable ABORT bit and ENABLE bit simultaneously cannot take effect.

Check if the master is holding SCL low after ENABLE bit is already disabled. If SCL is held low, The software can set this ABORT bit only when ENABLE is already set,otherwise,
the controller ignores any write to ABORT bit. When the abort is done, then proceed with disabling the controller.

These kernel logs show up whenever an I2C transaction is attempted after this failure.
i2c_designware e95e0000.i2c: timeout in disabling adapter i2c_designware e95e0000.i2c: timeout waiting for bus ready

The patch can be fix the controller cannot be disabled while SCL is held low in ENABLE bit is already disabled.

---
 drivers/i2c/busses/i2c-designware-common.c | 12 +++++++++++
 drivers/i2c/busses/i2c-designware-master.c | 23 +++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-common.c +12 -0
index e8a688d04aee..54acf8554582 100644
@@ -453,6 +453,18 @@ void __i2c_dw_disable(struct dw_i2c_dev *dev)
 
 	abort_needed = raw_intr_stats & DW_IC_INTR_MST_ON_HOLD;
 	if (abort_needed) {
+		if (!(enable & DW_IC_ENABLE_ENABLE)) {
+			regmap_write(dev->map, DW_IC_ENABLE, DW_IC_ENABLE_ENABLE);
+			enable |= DW_IC_ENABLE_ENABLE;
+
+			/*
+			 * Wait two ic_clk delay when enabling the i2c to ensure ENABLE bit
+			 * is already set by the driver (for 400KHz this is 25us)
+			 * as described in the DesignWare I2C databook.
+			 */
+			fsleep(25);
+		}
+
 		regmap_write(dev->map, DW_IC_ENABLE, enable | DW_IC_ENABLE_ABORT);
 		ret = regmap_read_poll_timeout(dev->map, DW_IC_ENABLE, enable,
 					       !(enable & DW_IC_ENABLE_ABORT), 10,
drivers/i2c/busses/i2c-designware-master.c +22 -1
index c7e56002809a..aba0b8fdfe9a 100644
@@ -253,6 +253,26 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
 	__i2c_dw_write_intr_mask(dev, DW_IC_INTR_MASTER_MASK);
 }
 
+static bool i2c_dw_is_master_idling(struct dw_i2c_dev *dev)
+{
+	u32 status;
+	int ret;
+
+	regmap_read(dev->map, DW_IC_STATUS, &status);
+	if (!(status & DW_IC_STATUS_MASTER_ACTIVITY))
+		return true;
+
+	ret = regmap_read_poll_timeout(dev->map, DW_IC_STATUS, status,
+			!(status & DW_IC_STATUS_MASTER_ACTIVITY),
+			1100, 20000);
+	if (ret) {
+		dev_err(dev->dev, "i2c master controller not idle %d\n", ret);
+		return false;
+	}
+
+	return true;
+}
+
 static int i2c_dw_check_stopbit(struct dw_i2c_dev *dev)
 {
 	u32 val;
@@ -796,7 +816,8 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 	 * additional interrupts are a hardware bug or this driver doesn't
 	 * handle them correctly yet.
 	 */
-	__i2c_dw_disable_nowait(dev);
+	if (i2c_dw_is_master_idling(dev))
+		__i2c_dw_disable_nowait(dev);
 
 	if (dev->msg_err) {
 		ret = dev->msg_err;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 1 line · kimriver liu

From: "kimriver.liu" <[email protected]>

You forgot bumping patch version in the Subject and now it's quite confusing.

Quoted 1 line

Failure in normal Stop operational path

Is this a subsection?
Make it more clear, by using additional formatting, like

Failure in normal Stop operational path
---------------------------------------

Quoted 6 lines

This failure happens rarely and is hard to reproduce. Debug trace showed that IC_STATUS had value of 0x23 when STOP_DET occurred, immediately disable ENABLE bit that can result in IC_RAW_INTR_STAT.MASTER_ON_HOLD holding SCL low.

Failure in ENABLE bit is disabled path

Ditto.

Quoted 15 lines

It was observed that master is holding SCL low and the IC_ENABLE is already disabled, Enable ABORT bit and ENABLE bit simultaneously cannot take effect.

Check if the master is holding SCL low after ENABLE bit is already disabled. If SCL is held low, The software can set this ABORT bit only when ENABLE is already set,otherwise,
the controller ignores any write to ABORT bit. When the abort is done, then proceed with disabling the controller.

These kernel logs show up whenever an I2C transaction is attempted after this failure.
i2c_designware e95e0000.i2c: timeout in disabling adapter i2c_designware e95e0000.i2c: timeout waiting for bus ready

Quoted 5 lines

The patch can be fix the controller cannot be disabled while SCL is held low in ENABLE bit is already disabled.

---

Here is the place for comments and changelog.
Since it's not the first version of the patch, changelog is a must.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#2 lore raw

Re: [PATCH] i2c: designware: fix master is holding SCL low while ENABLE bit is disabledg

In reply to kimriver liu

Hi Kimriver,

Quoted 1 line · kimriver liu

From: "kimriver.liu" <[email protected]>

Is there any reason to have "kimriver.liu" instead of "Kimriver Liu"?

Quoted 19 lines

Failure in normal Stop operational path

This failure happens rarely and is hard to reproduce. Debug trace showed that IC_STATUS had value of 0x23 when STOP_DET occurred, immediately disable ENABLE bit that can result in IC_RAW_INTR_STAT.MASTER_ON_HOLD holding SCL low.

Failure in ENABLE bit is disabled path

It was observed that master is holding SCL low and the IC_ENABLE is already disabled, Enable ABORT bit and ENABLE bit simultaneously cannot take effect.

Check if the master is holding SCL low after ENABLE bit is already disabled. If SCL is held low, The software can set this ABORT bit only when ENABLE is already set,otherwise,
the controller ignores any write to ABORT bit. When the abort is done, then proceed with disabling the controller.

Quoted 7 lines

These kernel logs show up whenever an I2C transaction is attempted after this failure.
i2c_designware e95e0000.i2c: timeout in disabling adapter i2c_designware e95e0000.i2c: timeout waiting for bus ready

The patch can be fix the controller cannot be disabled while SCL is held low in ENABLE bit is already disabled.

I'm sorry, but this commit log is difficult to understand. Could you please polish it, fix the grammar and the punctuation and make it more understandable?

Quoted 1 line

As I said above, would be nicer to have "Kimriver Liu" rather than "kimriver.liu".

I'm wondering if we need the Fixes: tag here. If this is not a frequent issue then we can probably omit it.

Quoted 1 line

---

Andy already pointed out that you are missing versioning (is this v2? v3?) and changelog.

Quoted 39 lines
 drivers/i2c/busses/i2c-designware-common.c | 12 +++++++++++
 drivers/i2c/busses/i2c-designware-master.c | 23 +++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-common.c +12 -0
index e8a688d04aee..54acf8554582 100644
@@ -453,6 +453,18 @@ void __i2c_dw_disable(struct dw_i2c_dev *dev)
 
 	abort_needed = raw_intr_stats & DW_IC_INTR_MST_ON_HOLD;
 	if (abort_needed) {
+		if (!(enable & DW_IC_ENABLE_ENABLE)) {
+			regmap_write(dev->map, DW_IC_ENABLE, DW_IC_ENABLE_ENABLE);
+			enable |= DW_IC_ENABLE_ENABLE;
+
+			/*
+			 * Wait two ic_clk delay when enabling the i2c to ensure ENABLE bit
+			 * is already set by the driver (for 400KHz this is 25us)
+			 * as described in the DesignWare I2C databook.
+			 */
+			fsleep(25);
+		}
+
 		regmap_write(dev->map, DW_IC_ENABLE, enable | DW_IC_ENABLE_ABORT);
 		ret = regmap_read_poll_timeout(dev->map, DW_IC_ENABLE, enable,
 					       !(enable & DW_IC_ENABLE_ABORT), 10,
drivers/i2c/busses/i2c-designware-master.c +4 -0
index c7e56002809a..aba0b8fdfe9a 100644
@@ -253,6 +253,26 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
 	__i2c_dw_write_intr_mask(dev, DW_IC_INTR_MASTER_MASK);
 }
 
+static bool i2c_dw_is_master_idling(struct dw_i2c_dev *dev)
+{
+	u32 status;
+	int ret;

drivers/i2c/busses/i2c-designware-master.c static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) · line 269

Quoted 10 lines
drivers/i2c/busses/i2c-designware-master.c +10 -0
+
+	regmap_read(dev->map, DW_IC_STATUS, &status);
+	if (!(status & DW_IC_STATUS_MASTER_ACTIVITY))
+		return true;
+
+	ret = regmap_read_poll_timeout(dev->map, DW_IC_STATUS, status,
+			!(status & DW_IC_STATUS_MASTER_ACTIVITY),
+			1100, 20000);
+	if (ret) {
+		dev_err(dev->dev, "i2c master controller not idle %d\n", ret);

Please be a bit more descriptive. It's not an error for the i2c master not to be idle, it is if you try to disable the adapter.

Besides, it makes sense to me that this print is done in the i2c_dw_xfer function rather than here. The task of this function is only to check whether the controller is idling or active.

drivers/i2c/busses/i2c-designware-master.c i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · line 818

Quoted 13 lines
drivers/i2c/busses/i2c-designware-master.c +6 -0
+		return false;
+	}
+
+	return true;
+}
+
 static int i2c_dw_check_stopbit(struct dw_i2c_dev *dev)
 {
 	u32 val;
@@ -796,7 +816,8 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 	 * additional interrupts are a hardware bug or this driver doesn't
 	 * handle them correctly yet.
 	 */

Please update the comment according to your change.

drivers/i2c/busses/i2c-designware-master.c i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · line 819

Quoted 2 lines
drivers/i2c/busses/i2c-designware-master.c +1 -1
-	__i2c_dw_disable_nowait(dev);
+	if (i2c_dw_is_master_idling(dev))

Please print the error message here.

Thanks for your patch,
Andi

Quoted 7 lines
drivers/i2c/busses/i2c-designware-master.c +1 -0
+		__i2c_dw_disable_nowait(dev);
 
 	if (dev->msg_err) {
 		ret = dev->msg_err;
Signature · 1 line
2.17.1
#3 lore raw
In reply to kimriver liu
kernel test robot noticed the following build errors:

Hi kimriver,

kernel test robot noticed the following build errors:

[auto build test ERROR on andi-shyti/i2c/i2c-host]
[also build test ERROR on linus/master v6.11-rc6 next-20240906] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/kimriver-liu/i2c-designware-fix-master-is-holding-SCL-low-while-ENABLE-bit-is-disabled/20240905-154711
base:   https://git.kernel.org/pub/scm/linux/kernel/git/andi.shyti/linux.git i2c/i2c-host
patch link:    https://lore.kernel.org/r/20240905074211.2278-1-kimriver.liu%40siengine.com
patch subject: [PATCH] i2c: designware: fix master is holding SCL low while ENABLE bit is disabled
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20240908/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240908/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/i2c/busses/i2c-designware-common.c: In function '__i2c_dw_disable':

>> drivers/i2c/busses/i2c-designware-common.c:538:32: error: 'DW_IC_ENABLE_ENABLE' undeclared (first use in this function); did you mean 'DW_IC_ENABLE_STATUS'?
     538 |                 if (!(enable & DW_IC_ENABLE_ENABLE)) {
         |                                ^~~~~~~~~~~~~~~~~~~
         |                                DW_IC_ENABLE_STATUS

drivers/i2c/busses/i2c-designware-common.c:538:32: note: each undeclared identifier is reported only once for each function it appears in

vim +538 drivers/i2c/busses/i2c-designware-common.c

523
524 void __i2c_dw_disable(struct dw_i2c_dev *dev)
525 {
526 unsigned int raw_intr_stats;
527 unsigned int enable;
528 int timeout = 100;
529 bool abort_needed;
530 unsigned int status;
531 int ret;
532
533 regmap_read(dev->map, DW_IC_RAW_INTR_STAT, &raw_intr_stats);
534 regmap_read(dev->map, DW_IC_ENABLE, &enable);
535
536 abort_needed = raw_intr_stats & DW_IC_INTR_MST_ON_HOLD;
537 if (abort_needed) {

 > 538			if (!(enable & DW_IC_ENABLE_ENABLE)) {

539 regmap_write(dev->map, DW_IC_ENABLE, DW_IC_ENABLE_ENABLE);
540 enable |= DW_IC_ENABLE_ENABLE;
541
542 /*
543 * Wait two ic_clk delay when enabling the i2c to ensure ENABLE bit
544 * is already set by the driver (for 400KHz this is 25us)
545 * as described in the DesignWare I2C databook.
546 */
547 fsleep(25);
548 }
549
550 regmap_write(dev->map, DW_IC_ENABLE, enable | DW_IC_ENABLE_ABORT);
551 ret = regmap_read_poll_timeout(dev->map, DW_IC_ENABLE, enable,
552 !(enable & DW_IC_ENABLE_ABORT), 10,
553 100);
554 if (ret)
555 dev_err(dev->dev, "timeout while trying to abort current transfer\n");
556 }
557
558 do {
559 __i2c_dw_disable_nowait(dev);
560 /*
561 * The enable status register may be unimplemented, but
562 * in that case this test reads zero and exits the loop.
563 */
564 regmap_read(dev->map, DW_IC_ENABLE_STATUS, &status);
565 if ((status & 1) == 0)
566 return;
567
568 /*
569 * Wait 10 times the signaling period of the highest I2C
570 * transfer supported by the driver (for 400KHz this is
571 * 25us) as described in the DesignWare I2C databook.
572 */
573 usleep_range(25, 250);
574 } while (timeout--);
575
576 dev_warn(dev->dev, "timeout in disabling adapter\n");
577 }
578

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

HI,robot,
Today I will resend a version v7 patch([PATCH V7] i2c: designware: fix master is holding SCL low while ENABLE bit is disabled) based on the latest Linux master branch to resolve compile errors.

-------------
Best Regards,
Kimriver Liu

-----Original Message-----
From: kernel test robot <[email protected]>
Sent: 2024年9月8日 21:32
To: Liu Kimriver/刘金河 <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Liu Kimriver/刘金河 <[email protected]>
Subject: Re: [PATCH] i2c: designware: fix master is holding SCL low while ENABLE bit is disabled

Hi kimriver,

kernel test robot noticed the following build errors:

[auto build test ERROR on andi-shyti/i2c/i2c-host]
[also build test ERROR on linus/master v6.11-rc6 next-20240906] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/kimriver-liu/i2c-designware-fix-master-is-holding-SCL-low-while-ENABLE-bit-is-disabled/20240905-154711
base:   https://git.kernel.org/pub/scm/linux/kernel/git/andi.shyti/linux.git i2c/i2c-host
patch link:    https://lore.kernel.org/r/20240905074211.2278-1-kimriver.liu%40siengine.com
patch subject: [PATCH] i2c: designware: fix master is holding SCL low while ENABLE bit is disabled
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20240908/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240908/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/i2c/busses/i2c-designware-common.c: In function '__i2c_dw_disable':

Quoted 1 line
Quoted 1 line

drivers/i2c/busses/i2c-designware-common.c:538:32: error: 'DW_IC_ENABLE_ENABLE' undeclared (first use in this function); did you mean 'DW_IC_ENABLE_STATUS'?

     538 |                 if (!(enable & DW_IC_ENABLE_ENABLE)) {
         |                                ^~~~~~~~~~~~~~~~~~~
         |                                DW_IC_ENABLE_STATUS

drivers/i2c/busses/i2c-designware-common.c:538:32: note: each undeclared identifier is reported only once for each function it appears in

vim +538 drivers/i2c/busses/i2c-designware-common.c

523
524 void __i2c_dw_disable(struct dw_i2c_dev *dev)
525 {
526 unsigned int raw_intr_stats;
527 unsigned int enable;
528 int timeout = 100;
529 bool abort_needed;
530 unsigned int status;
531 int ret;
532
533 regmap_read(dev->map, DW_IC_RAW_INTR_STAT, &raw_intr_stats);
534 regmap_read(dev->map, DW_IC_ENABLE, &enable);
535
536 abort_needed = raw_intr_stats & DW_IC_INTR_MST_ON_HOLD;
537 if (abort_needed) {

Quoted 1 line

538 if (!(enable & DW_IC_ENABLE_ENABLE)) {

539 regmap_write(dev->map, DW_IC_ENABLE, DW_IC_ENABLE_ENABLE);
540 enable |= DW_IC_ENABLE_ENABLE;
541
542 /*
543 * Wait two ic_clk delay when enabling the i2c to ensure ENABLE bit
544 * is already set by the driver (for 400KHz this is 25us)
545 * as described in the DesignWare I2C databook.
546 */
547 fsleep(25);
548 }
549
550 regmap_write(dev->map, DW_IC_ENABLE, enable | DW_IC_ENABLE_ABORT);
551 ret = regmap_read_poll_timeout(dev->map, DW_IC_ENABLE, enable,
552 !(enable & DW_IC_ENABLE_ABORT), 10,
553 100);
554 if (ret)
555 dev_err(dev->dev, "timeout while trying to abort current transfer\n");
556 }
557
558 do {
559 __i2c_dw_disable_nowait(dev);
560 /*
561 * The enable status register may be unimplemented, but
562 * in that case this test reads zero and exits the loop.
563 */
564 regmap_read(dev->map, DW_IC_ENABLE_STATUS, &status);
565 if ((status & 1) == 0)
566 return;
567
568 /*
569 * Wait 10 times the signaling period of the highest I2C
570 * transfer supported by the driver (for 400KHz this is
571 * 25us) as described in the DesignWare I2C databook.
572 */
573 usleep_range(25, 250);
574 } while (timeout--);
575
576 dev_warn(dev->dev, "timeout in disabling adapter\n");
577 }
578

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw
In reply to kernel test robot

Hi jarkko

-----Original Message-----
From: kernel test robot <[email protected]>
Sent: 2024年9月8日 21:32
To: Liu Kimriver/刘金河 <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Liu Kimriver/刘金河 <[email protected]>
Subject: Re: [PATCH] i2c: designware: fix master is holding SCL low while ENABLE bit is disabled

Quoted 9 lines
Quoted 9 lines

Hi kimriver,

kernel test robot noticed the following build errors:

[auto build test ERROR on andi-shyti/i2c/i2c-host]
[also build test ERROR on linus/master v6.11-rc6 next-20240906] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

I applied patch to the wrong git tree last week , I had resent V7 patch To resolve build test ERROR. patch Subject: [PATCH v7] i2c: designware: fix master is holding SCL low while ENABLE bit is disabled New patch link:
https://lore.kernel.org/all/[email protected]/
The patch rebase on the latest Linux v6.11.0-rc6 (89f5e14d05b) branch (the latest linux master branch)

Quoted 13 lines
Quoted 12 lines
url:    https://github.com/intel-lab-lkp/linux/commits/kimriver-liu/i2c-designware-fix-master-is-holding-SCL-low-while-ENABLE-bit-is-disabled/20240905-154711
base:   https://git.kernel.org/pub/scm/linux/kernel/git/andi.shyti/linux.git i2c/i2c-host
patch link:    https://lore.kernel.org/r/20240905074211.2278-1-kimriver.liu%40siengine.com
patch subject: [PATCH] i2c: designware: fix master is holding SCL low while ENABLE bit is disabled
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20240908/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240908/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 8 lines
Quoted 8 lines

All errors (new ones prefixed by >>):

drivers/i2c/busses/i2c-designware-common.c: In function '__i2c_dw_disable':

Quoted 1 line
Quoted 1 line

drivers/i2c/busses/i2c-designware-common.c:538:32: error: 'DW_IC_ENABLE_ENABLE' undeclared (first use in this function); did you mean 'DW_IC_ENABLE_STATUS'?

    538 |                 if (!(enable & DW_IC_ENABLE_ENABLE)) {
        |                                ^~~~~~~~~~~~~~~~~~~
        |                                DW_IC_ENABLE_STATUS

drivers/i2c/busses/i2c-designware-common.c:538:32: note: each undeclared identifier is reported only once for each function it appears in

I fixexd the issue at the same commit as In V7 version patch link:
https://lore.kernel.org/all/[email protected]/
patch Subject: [PATCH v7] i2c: designware: fix master is holding SCL low while ENABLE bit is disabled Declaration DW_IC_ENABLE_ENABLE as follow:

drivers/i2c/busses/i2c-designware-core.h +1 -0
index e9606c00b8d1..e45daedad967 100644
@@ -109,6 +109,7 @@
 						 DW_IC_INTR_RX_UNDER | \
 						 DW_IC_INTR_RD_REQ)
 
+#define DW_IC_ENABLE_ENABLE			BIT(0)
 #define DW_IC_ENABLE_ABORT			BIT(1)
 
 #define DW_IC_STATUS_ACTIVITY			BIT(0)
Quoted 50 lines
Quoted 50 lines

vim +538 drivers/i2c/busses/i2c-designware-common.c

523
524 void __i2c_dw_disable(struct dw_i2c_dev *dev)
525 {
526 unsigned int raw_intr_stats;
527 unsigned int enable;
528 int timeout = 100;
529 bool abort_needed;
530 unsigned int status;
531 int ret;
532
533 regmap_read(dev->map, DW_IC_RAW_INTR_STAT, &raw_intr_stats);
534 regmap_read(dev->map, DW_IC_ENABLE, &enable);
535
536 abort_needed = raw_intr_stats & DW_IC_INTR_MST_ON_HOLD;
537 if (abort_needed) {

Quoted 1 line

538 if (!(enable & DW_IC_ENABLE_ENABLE)) {

539 regmap_write(dev->map, DW_IC_ENABLE, DW_IC_ENABLE_ENABLE);
540 enable |= DW_IC_ENABLE_ENABLE;
541
542 /*
543 * Wait two ic_clk delay when enabling the i2c to ensure ENABLE bit
544 * is already set by the driver (for 400KHz this is 25us)
545 * as described in the DesignWare I2C databook.
546 */
547 fsleep(25);
548 }
549
550 regmap_write(dev->map, DW_IC_ENABLE, enable | DW_IC_ENABLE_ABORT);
551 ret = regmap_read_poll_timeout(dev->map, DW_IC_ENABLE, enable,
552 !(enable & DW_IC_ENABLE_ABORT), 10,
553 100);
554 if (ret)
555 dev_err(dev->dev, "timeout while trying to abort current transfer\n");
556 }
557
558 do {
559 __i2c_dw_disable_nowait(dev);
560 /*
561 * The enable status register may be unimplemented, but
562 * in that case this test reads zero and exits the loop.
563 */
564 regmap_read(dev->map, DW_IC_ENABLE_STATUS, &status);
565 if ((status & 1) == 0)
566 return;
567
568 /*
569 * Wait 10 times the signaling period of the highest I2C
570 * transfer supported by the driver (for 400KHz this is

Quoted 8 lines
Quoted 8 lines
  571			 * 25us) as described in the DesignWare I2C databook.
  572			 */
  573			usleep_range(25, 250);
  574		} while (timeout--);
  575	
  576		dev_warn(dev->dev, "timeout in disabling adapter\n");
  577	}
  578	

------------------------------------------
Best Regards
Kimriver Liu