diff mbox series

[2/4] i2c: designware_i2c: check is high speed possible support

Message ID 1583139537-65602-3-git-send-email-ptchentw@gmail.com
State Accepted
Commit 565e328b959b58c181fdec33b2e161ada90dd521
Delegated to: Heiko Schocher
Headers show
Series i2c: designware_i2c: Improvements for high speed mode | expand

Commit Message

Jun Chen March 2, 2020, 8:58 a.m. UTC
From: Jun Chen <jun.chen@vatics.com>

To read IC_COMP_PARAM_1[3:2] to check is high speed possible,
and fall back to fast mode if not.

Signed-off-by: Jun Chen <ptchentw@gmail.com>
Signed-off-by: Jun Chen <jun.chen@vatics.com>
---

 drivers/i2c/designware_i2c.c | 10 ++++++++++
 drivers/i2c/designware_i2c.h |  3 +++
 2 files changed, 13 insertions(+)

Comments

Heiko Schocher March 17, 2020, 5:14 a.m. UTC | #1
Hello Jun Chen,

Am 02.03.2020 um 09:58 schrieb Jun Chen:
> From: Jun Chen <jun.chen@vatics.com>
> 
> To read IC_COMP_PARAM_1[3:2] to check is high speed possible,
> and fall back to fast mode if not.
> 
> Signed-off-by: Jun Chen <ptchentw@gmail.com>
> Signed-off-by: Jun Chen <jun.chen@vatics.com>
> ---
> 
>   drivers/i2c/designware_i2c.c | 10 ++++++++++
>   drivers/i2c/designware_i2c.h |  3 +++
>   2 files changed, 13 insertions(+)

Applied to u-boot-i2c next, thanks!

bye,
Heiko
diff mbox series

Patch

diff --git a/drivers/i2c/designware_i2c.c b/drivers/i2c/designware_i2c.c
index 9186fcb..f4fbf3b 100644
--- a/drivers/i2c/designware_i2c.c
+++ b/drivers/i2c/designware_i2c.c
@@ -203,9 +203,12 @@  static int calc_bus_speed(struct dw_i2c *priv, int speed, ulong bus_clk,
 	const struct dw_scl_sda_cfg *scl_sda_cfg = NULL;
 	struct i2c_regs *regs = priv->regs;
 	enum i2c_speed_mode i2c_spd;
+	u32 comp_param1;
 	int spk_cnt;
 	int ret;
 
+	comp_param1 = readl(&regs->comp_param1);
+
 	if (priv)
 		scl_sda_cfg = priv->scl_sda_cfg;
 	/* Allow high speed if there is no config, or the config allows it */
@@ -219,6 +222,13 @@  static int calc_bus_speed(struct dw_i2c *priv, int speed, ulong bus_clk,
 	else
 		i2c_spd = IC_SPEED_MODE_STANDARD;
 
+	/* Check is high speed possible and fall back to fast mode if not */
+	if (i2c_spd == IC_SPEED_MODE_HIGH) {
+		if ((comp_param1 & DW_IC_COMP_PARAM_1_SPEED_MODE_MASK)
+				!= DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH)
+			i2c_spd = IC_SPEED_MODE_FAST;
+	}
+
 	/* Get the proper spike-suppression count based on target speed */
 	if (!priv || !priv->has_spk_cnt)
 		spk_cnt = 0;
diff --git a/drivers/i2c/designware_i2c.h b/drivers/i2c/designware_i2c.h
index 61a882c..23f311b 100644
--- a/drivers/i2c/designware_i2c.h
+++ b/drivers/i2c/designware_i2c.h
@@ -138,6 +138,9 @@  struct i2c_regs {
 #define IC_STATUS_TFNF		0x0002
 #define IC_STATUS_ACT		0x0001
 
+#define DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH      (BIT(2) | BIT(3))
+#define DW_IC_COMP_PARAM_1_SPEED_MODE_MASK      (BIT(2) | BIT(3))
+
 /**
  * struct dw_scl_sda_cfg - I2C timing configuration
  *