linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Romain Baeriswyl <Romain.Baeriswyl@abilis.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: rmallon@gmail.com, mika.westerberg@linux.intel.com,
	rob.herring@calxeda.com, pawel.moll@arm.com,
	mark.rutland@arm.com, swarren@wwwdotorg.org,
	ijc+devicetree@hellion.org.uk, rob@landley.net,
	pierrick.hascoet@abilis.com, vgupta@synopsys.com,
	christian.ruppert@abilis.com, chiau.ee.chew@intel.com,
	khali@linux-fr.org, rafael.j.wysocki@intel.com,
	devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	romainba@abilis.com
Subject: [PATCH v2 1/2] i2c designware make SCL and SDA falling time configurable
Date: Mon, 20 Jan 2014 17:43:43 +0100	[thread overview]
Message-ID: <1390236223-22584-1-git-send-email-romainba@abilis.com> (raw)
In-Reply-To: <20140116194303.GC4127@katana>

This patch allows to set independantly SCL and SDA falling times.
The tLOW period is computed by taking into account the SCL falling time.
The tHIGH period is computed by taking into account the SDA falling time.

For instance in case the margin on tLOW is considered too small, it can
be increased by increasing the SCL falling time which is by default set
at 300ns.

The same applies for tHIGH period with the help of SDA falling time.

Signed-off-by: Romain Baeriswyl <romainba@abilis.com>
Reviewed-by: Christian Ruppert <christian.ruppert@abilis.com>
---
 .../devicetree/bindings/i2c/i2c-designware.txt     |    8 ++++++
 drivers/i2c/busses/i2c-designware-core.c           |   27 +++++++++++--------
 drivers/i2c/busses/i2c-designware-core.h           |    2 +
 drivers/i2c/busses/i2c-designware-platdrv.c        |    7 +++++
 4 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
index 7fd7fa2..5199b0c 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
@@ -14,6 +14,12 @@ Optional properties :
  - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds.
    This option is only supported in hardware blocks version 1.11a or newer.
 
+ - i2c-scl-falling-time : should contain the SCL falling time in nanoseconds.
+   This value which is by default 300ns is used to compute the tLOW period.
+
+ - i2c-sda-falling-time : should contain the SDA falling time in nanoseconds.
+   This value which is by default 300ns is used to compute the tHIGH period.
+
 Example :
 
 	i2c@f0000 {
@@ -34,4 +40,6 @@ Example :
 		interrupts = <12 1>;
 		clock-frequency = <400000>;
 		i2c-sda-hold-time-ns = <300>;
+		i2c-sda-falling-time-ns = <300>;
+		i2c-scl-falling-time-ns = <300>;
 	};
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index e89e3e2..3bcdebf 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -219,7 +219,7 @@ i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
 		 *
 		 * If your hardware is free from tHD;STA issue, try this one.
 		 */
-		return (ic_clk * tSYMBOL + 5000) / 10000 - 8 + offset;
+		return (ic_clk * tSYMBOL + 500000) / 1000000 - 8 + offset;
 	else
 		/*
 		 * Conditional expression:
@@ -235,7 +235,8 @@ i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
 		 * The reason why we need to take into account "tf" here,
 		 * is the same as described in i2c_dw_scl_lcnt().
 		 */
-		return (ic_clk * (tSYMBOL + tf) + 5000) / 10000 - 3 + offset;
+		return (ic_clk * (tSYMBOL + tf) + 500000) / 1000000
+			- 3 + offset;
 }
 
 static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
@@ -251,7 +252,7 @@ static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
 	 * account the fall time of SCL signal (tf).  Default tf value
 	 * should be 0.3 us, for safety.
 	 */
-	return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset;
+	return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset;
 }
 
 static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable)
@@ -288,6 +289,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 	u32 input_clock_khz;
 	u32 hcnt, lcnt;
 	u32 reg;
+	u32 sda_falling_time, scl_falling_time;
 
 	input_clock_khz = dev->get_clk_rate_khz(dev);
 
@@ -309,15 +311,18 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 	/* set standard and fast speed deviders for high/low periods */
 
+	sda_falling_time = dev->sda_falling_time ?: 300; /* ns */
+	scl_falling_time = dev->scl_falling_time ?: 300; /* ns */
+
 	/* Standard-mode */
 	hcnt = i2c_dw_scl_hcnt(input_clock_khz,
-				40,	/* tHD;STA = tHIGH = 4.0 us */
-				3,	/* tf = 0.3 us */
+				4000,	/* tHD;STA = tHIGH = 4.0 us */
+				sda_falling_time,
 				0,	/* 0: DW default, 1: Ideal */
 				0);	/* No offset */
 	lcnt = i2c_dw_scl_lcnt(input_clock_khz,
-				47,	/* tLOW = 4.7 us */
-				3,	/* tf = 0.3 us */
+				4700,	/* tLOW = 4.7 us */
+				scl_falling_time,
 				0);	/* No offset */
 
 	/* Allow platforms to specify the ideal HCNT and LCNT values */
@@ -331,13 +336,13 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 
 	/* Fast-mode */
 	hcnt = i2c_dw_scl_hcnt(input_clock_khz,
-				6,	/* tHD;STA = tHIGH = 0.6 us */
-				3,	/* tf = 0.3 us */
+				600,	/* tHD;STA = tHIGH = 0.6 us */
+				sda_falling_time,
 				0,	/* 0: DW default, 1: Ideal */
 				0);	/* No offset */
 	lcnt = i2c_dw_scl_lcnt(input_clock_khz,
-				13,	/* tLOW = 1.3 us */
-				3,	/* tf = 0.3 us */
+				1300,	/* tLOW = 1.3 us */
+				scl_falling_time,
 				0);	/* No offset */
 
 	if (dev->fs_hcnt && dev->fs_lcnt) {
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index e8a7565..d66b6cb 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -99,6 +99,8 @@ struct dw_i2c_dev {
 	unsigned int		rx_fifo_depth;
 	int			rx_outstanding;
 	u32			sda_hold_time;
+	u32			sda_falling_time;
+	u32			scl_falling_time;
 	u16			ss_hcnt;
 	u16			ss_lcnt;
 	u16			fs_hcnt;
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index d0bdac0..fc24399 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -159,6 +159,13 @@ static int dw_i2c_probe(struct platform_device *pdev)
 					"i2c-sda-hold-time-ns", &ht);
 		dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000,
 					     1000000);
+
+		of_property_read_u32(pdev->dev.of_node,
+				     "i2c-sda-falling-time-ns",
+				     &dev->sda_falling_time);
+		of_property_read_u32(pdev->dev.of_node,
+				     "i2c-scl-falling-time-ns",
+				     &dev->scl_falling_time);
 	}
 
 	dev->functionality =
-- 
1.7.1

  reply	other threads:[~2014-01-20 16:43 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-08 11:45 [PATCH 1/2] i2c-designware: make *CNT values configurable Mika Westerberg
     [not found] ` <1373283927-21677-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-07-08 11:45   ` [PATCH 2/2] i2c-designware: configure *CNT values from ACPI Mika Westerberg
     [not found]     ` <1373283927-21677-2-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-07-10 13:01       ` Mika Westerberg
2013-07-08 13:42   ` [PATCH 1/2] i2c-designware: make *CNT values configurable Christian Ruppert
     [not found]     ` <20130708134216.GB6402-7oYq3qWSd+k@public.gmane.org>
2013-07-09  8:44       ` Mika Westerberg
     [not found]         ` <20130709084402.GF4898-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-07-09 16:19           ` Christian Ruppert
     [not found]             ` <20130709161927.GC30236-7oYq3qWSd+k@public.gmane.org>
2013-07-10 10:52               ` Mika Westerberg
     [not found]                 ` <20130710105215.GY4898-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-07-10 16:56                   ` Christian Ruppert
     [not found]                     ` <20130710165634.GA30693-7oYq3qWSd+k@public.gmane.org>
2013-07-11  7:36                       ` Mika Westerberg
2013-07-11 10:13                         ` Mika Westerberg
     [not found]                           ` <20130711101330.GP4898-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-07-12  7:56                             ` Shinya Kuribayashi
     [not found]                               ` <51DFB6C1.4040001-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
2013-07-12  8:51                                 ` Mika Westerberg
     [not found]                                   ` <20130712085140.GY4898-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-07-13  5:36                                     ` Shinya Kuribayashi
     [not found]                                       ` <51E0E76B.1040304-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
2013-07-16 11:16                                         ` Christian Ruppert
     [not found]                                           ` <20130716111616.GA25835-7oYq3qWSd+k@public.gmane.org>
2013-07-17 14:39                                             ` Shinya Kuribayashi
     [not found]                                               ` <51E6ACBE.7000509-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
2013-07-22 13:17                                                 ` Christian Ruppert
     [not found]                                                   ` <20130722131706.GA24081-7oYq3qWSd+k@public.gmane.org>
2013-07-24 14:31                                                     ` Shinya Kuribayashi
     [not found]                                                       ` <51EFE550.1000507-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
2013-08-05  9:31                                                         ` Christian Ruppert
     [not found]                                                           ` <20130805093126.GE20936-7oYq3qWSd+k@public.gmane.org>
2013-08-05 10:02                                                             ` Wolfram Sang
2013-08-12  7:48                                                               ` Christian Ruppert
     [not found]                                                                 ` <20130812074800.GA23792-7oYq3qWSd+k@public.gmane.org>
2013-08-12 11:09                                                                   ` Wolfram Sang
2013-08-16  2:15                                                             ` Shinya Kuribayashi
2013-08-19 11:36                                                               ` Mika Westerberg
     [not found]                                                                 ` <20130819113604.GN4898-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-08-19 12:22                                                                   ` Shinya Kuribayashi
2013-08-21 14:39                                                               ` Christian Ruppert
     [not found]                                                                 ` <20130821143915.GA3046-7oYq3qWSd+k@public.gmane.org>
2013-08-24  4:58                                                                   ` Shinya Kuribayashi
     [not found]                                                                     ` <52183D87.40703-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
2013-08-28 15:34                                                                       ` Christian Ruppert
2013-10-08 15:00                                                                         ` [PATCH 1/2] i2c designware make SCL and SDA falling time configurable Romain Baeriswyl
2013-10-09  7:55                                                                           ` Mika Westerberg
2013-10-10  0:54                                                                             ` Ryan Mallon
     [not found]                                                                               ` <5255FAB5.7080803-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-10-13 11:36                                                                                 ` Shinya Kuribayashi
     [not found]                                                                                   ` <525A85D6.3090608-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
2014-01-16 19:43                                                                                     ` Wolfram Sang
2014-01-20 16:43                                                                                       ` Romain Baeriswyl [this message]
     [not found]                                                                                         ` <1390236223-22584-1-git-send-email-romainba-ux6zf3SgZrrQT0dZR+AlfA@public.gmane.org>
2014-03-09  8:20                                                                                           ` [PATCH v2 " Wolfram Sang
     [not found]                                                                         ` <20130828153429.GB7066-7oYq3qWSd+k@public.gmane.org>
2013-10-08 15:00                                                                           ` [PATCH 2/2] i2c designware add support of I2C standard mode Romain Baeriswyl
2013-10-09  7:56                                                                             ` Mika Westerberg
     [not found]                                                                               ` <20131009075632.GR3521-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-10-13 11:46                                                                                 ` Shinya Kuribayashi
2014-01-16 19:33                                                                             ` Wolfram Sang
2014-01-20 16:45                                                                               ` [PATCH v2 " Romain Baeriswyl
     [not found]                                                                                 ` <1390236338-21407-1-git-send-email-romainba-ux6zf3SgZrrQT0dZR+AlfA@public.gmane.org>
2014-03-09  8:07                                                                                   ` Wolfram Sang
2013-08-19  6:39                                             ` [PATCH 1/2] i2c-designware: make *CNT values configurable 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=1390236223-22584-1-git-send-email-romainba@abilis.com \
    --to=romain.baeriswyl@abilis.com \
    --cc=chiau.ee.chew@intel.com \
    --cc=christian.ruppert@abilis.com \
    --cc=devicetree@vger.kernel.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=khali@linux-fr.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=pawel.moll@arm.com \
    --cc=pierrick.hascoet@abilis.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rmallon@gmail.com \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=romainba@abilis.com \
    --cc=swarren@wwwdotorg.org \
    --cc=vgupta@synopsys.com \
    --cc=wsa@the-dreams.de \
    /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;
as well as URLs for NNTP newsgroup(s).