public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] i2c-designware: make *CNT values configurable
@ 2013-07-08 11:45 Mika Westerberg
  2013-07-08 11:45 ` [PATCH 2/2] i2c-designware: configure *CNT values from ACPI Mika Westerberg
  2013-07-08 13:42 ` [PATCH 1/2] i2c-designware: make *CNT values configurable Christian Ruppert
  0 siblings, 2 replies; 42+ messages in thread
From: Mika Westerberg @ 2013-07-08 11:45 UTC (permalink / raw)
  To: linux-i2c; +Cc: Wolfram Sang, Christian Ruppert, Mika Westerberg, linux-kernel

The DesignWare I2C controller has high count (HCNT) and low count (LCNT)
registers for each of the I2C speed modes (standard and fast). These
registers are programmed based on the input clock speed in the driver.

However, that is not always the most accurate way. For example on Intel
BayTrail we have 100MHz input clock and calculated *CNT values result as
measured by one of our team:

 Standard mode: 100.25kHz
 Fast mode    : 315.41kHZ

The fast mode speed is over 20% lower than what is expected. It might be
that there are things like strenght of the pull-up resistors, bus
capacitance etc. that are very platform specific and have an effect on the
clock signal.

With this patch we let the platform code to specify more accurate, optimal
*CNT values if they are known beforehand.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/i2c/busses/i2c-designware-core.c | 46 +++++++++++++++++++-------------
 drivers/i2c/busses/i2c-designware-core.h | 12 +++++++++
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index ad46616..f31469e 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -308,29 +308,39 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
 	/* set standard and fast speed deviders for high/low periods */
 
 	/* Standard-mode */
-	hcnt = i2c_dw_scl_hcnt(input_clock_khz,
-				40,	/* tHD;STA = tHIGH = 4.0 us */
-				3,	/* tf = 0.3 us */
-				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 */
-				0);	/* No offset */
+	if (dev->ss_hcnt && dev->ss_lcnt) {
+		hcnt = dev->ss_hcnt;
+		lcnt = dev->ss_lcnt;
+	} else {
+		hcnt = i2c_dw_scl_hcnt(input_clock_khz,
+					40,	/* tHD;STA = tHIGH = 4.0 us */
+					3,	/* tf = 0.3 us */
+					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 */
+					0);	/* No offset */
+	}
 	dw_writel(dev, hcnt, DW_IC_SS_SCL_HCNT);
 	dw_writel(dev, lcnt, DW_IC_SS_SCL_LCNT);
 	dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
 
 	/* Fast-mode */
-	hcnt = i2c_dw_scl_hcnt(input_clock_khz,
-				6,	/* tHD;STA = tHIGH = 0.6 us */
-				3,	/* tf = 0.3 us */
-				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 */
-				0);	/* No offset */
+	if (dev->fs_hcnt && dev->fs_lcnt) {
+		hcnt = dev->fs_hcnt;
+		lcnt = dev->fs_lcnt;
+	} else {
+		hcnt = i2c_dw_scl_hcnt(input_clock_khz,
+					6,	/* tHD;STA = tHIGH = 0.6 us */
+					3,	/* tf = 0.3 us */
+					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 */
+					0);	/* No offset */
+	}
 	dw_writel(dev, hcnt, DW_IC_FS_SCL_HCNT);
 	dw_writel(dev, lcnt, DW_IC_FS_SCL_LCNT);
 	dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 912aa22..e8a7565 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -61,6 +61,14 @@
  * @tx_fifo_depth: depth of the hardware tx fifo
  * @rx_fifo_depth: depth of the hardware rx fifo
  * @rx_outstanding: current master-rx elements in tx fifo
+ * @ss_hcnt: standard speed HCNT value
+ * @ss_lcnt: standard speed LCNT value
+ * @fs_hcnt: fast speed HCNT value
+ * @fs_lcnt: fast speed LCNT value
+ *
+ * HCNT and LCNT parameters can be used if the platform knows more accurate
+ * values than the one computed based only on the input clock frequency.
+ * Leave them to be %0 if not used.
  */
 struct dw_i2c_dev {
 	struct device		*dev;
@@ -91,6 +99,10 @@ struct dw_i2c_dev {
 	unsigned int		rx_fifo_depth;
 	int			rx_outstanding;
 	u32			sda_hold_time;
+	u16			ss_hcnt;
+	u16			ss_lcnt;
+	u16			fs_hcnt;
+	u16			fs_lcnt;
 };
 
 #define ACCESS_SWAP		0x00000001
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2014-03-25 10:48 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-08 11:45 [PATCH 1/2] i2c-designware: make *CNT values configurable Mika Westerberg
2013-07-08 11:45 ` [PATCH 2/2] i2c-designware: configure *CNT values from ACPI Mika Westerberg
2013-07-10 13:01   ` Mika Westerberg
2013-07-08 13:42 ` [PATCH 1/2] i2c-designware: make *CNT values configurable Christian Ruppert
2013-07-09  8:44   ` Mika Westerberg
2013-07-09 16:19     ` Christian Ruppert
2013-07-10 10:52       ` Mika Westerberg
2013-07-10 16:56         ` Christian Ruppert
2013-07-11  7:36           ` Mika Westerberg
2013-07-11 10:13             ` Mika Westerberg
2013-07-12  7:56               ` Shinya Kuribayashi
2013-07-12  8:51                 ` Mika Westerberg
2013-07-13  5:36                   ` Shinya Kuribayashi
2013-07-16 11:16                     ` Christian Ruppert
2013-07-17 14:39                       ` Shinya Kuribayashi
2013-07-22 13:17                         ` Christian Ruppert
2013-07-24 14:31                           ` Shinya Kuribayashi
2013-08-05  9:31                             ` Christian Ruppert
2013-08-05 10:02                               ` Wolfram Sang
2013-08-12  7:48                                 ` Christian Ruppert
2013-08-12 11:09                                   ` Wolfram Sang
2013-08-16  2:15                               ` Shinya Kuribayashi
2013-08-19 11:36                                 ` Mika Westerberg
2013-08-19 12:22                                   ` Shinya Kuribayashi
2013-08-21 14:39                                 ` Christian Ruppert
2013-08-24  4:58                                   ` Shinya Kuribayashi
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
2013-10-13 11:36                                             ` Shinya Kuribayashi
2014-01-16 19:43                                               ` Wolfram Sang
2014-01-20 16:43                                                 ` [PATCH v2 " Romain Baeriswyl
2014-03-09  8:20                                                   ` Wolfram Sang
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
2013-10-13 11:46                                           ` Shinya Kuribayashi
2014-01-16 19:33                                         ` Wolfram Sang
2014-01-20 16:45                                           ` [PATCH v2 " Romain Baeriswyl
2014-03-09  8:07                                             ` Wolfram Sang
2014-03-25 10:18                                               ` [PATCH V3 " Romain Baeriswyl
2013-08-19  6:39                       ` [PATCH 1/2] i2c-designware: make *CNT values configurable Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox