linux-i3c.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 0/3] Introduce an attribute to choose timing setting
@ 2021-06-21  9:01 kewei.xu
  2021-06-21  9:01 ` [PATCH V2 1/3] i2c: mediatek: Add OFFSET_EXT_CONF setting back kewei.xu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: kewei.xu @ 2021-06-21  9:01 UTC (permalink / raw)
  To: bbrezillon
  Cc: matthias.bgg, robh+dt, mark.rutland, linux-i3c, devicetree,
	linux-arm-kernel, linux-kernel, linux-mediatek, srv_heupstream,
	leilk.liu, qii.wang, liguo.zhang, xinping.qian

From 7f9f31c3e49e67e915a5137259a3f5bd62818339 Mon Sep 17 00:00:00 2001
From: Kewei Xu <kewei.xu@mediatek.com>
Date: Mon, 21 Jun 2021 16:36:09 +0800
Subject: [PATCH V2 0/3] Introduce an attribute to choose timing setting

Main changes compared to V1:
--split OFFSET_EXT_CONF into another patch.
--add attribute default-timing-adjust into dt-binding. 

Kewei Xu (3):
  i2c: mediatek: Add OFFSET_EXT_CONF setting back
  dt-bindings: i2c: add attribute default-timing-adjust
  i2c: mediatek: Isolate speed setting via dts for special devices

 .../devicetree/bindings/i2c/i2c-mt65xx.txt         |  2 +
 drivers/i2c/busses/i2c-mt65xx.c                    | 88 ++++++++++++++++++++--
 2 files changed, 83 insertions(+), 7 deletions(-)

-- 
1.9.1
 
-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH V2 1/3] i2c: mediatek: Add OFFSET_EXT_CONF setting back
  2021-06-21  9:01 [PATCH V2 0/3] Introduce an attribute to choose timing setting kewei.xu
@ 2021-06-21  9:01 ` kewei.xu
  2021-06-21  9:01 ` [PATCH V2 2/3] dt-bindings: i2c: add attribute default-timing-adjust kewei.xu
  2021-06-21  9:01 ` [PATCH V2 3/3] i2c: mediatek: Isolate speed setting via dts for special devices kewei.xu
  2 siblings, 0 replies; 5+ messages in thread
From: kewei.xu @ 2021-06-21  9:01 UTC (permalink / raw)
  To: bbrezillon
  Cc: matthias.bgg, robh+dt, mark.rutland, linux-i3c, devicetree,
	linux-arm-kernel, linux-kernel, linux-mediatek, srv_heupstream,
	leilk.liu, qii.wang, liguo.zhang, xinping.qian, Kewei Xu

From: Kewei Xu <kewei.xu@mediatek.com>

In the commit be5ce0e97cc7 ("i2c: mediatek: Add i2c ac-timing adjust
support"), we miss setting OFFSET_EXT_CONF register if
i2c->dev_comp->timing_adjust is false, now add it back.

Fixes: be5ce0e97cc7 ("i2c: mediatek: Add i2c ac-timing adjust support")
Signed-off-by: Kewei Xu <kewei.xu@mediatek.com>
---
 drivers/i2c/busses/i2c-mt65xx.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index ded94f9..fe3cea7 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -41,6 +41,8 @@
 #define I2C_HANDSHAKE_RST		0x0020
 #define I2C_FIFO_ADDR_CLR		0x0001
 #define I2C_DELAY_LEN			0x0002
+#define I2C_ST_START_CON		0x8001
+#define I2C_FS_START_CON		0x1800
 #define I2C_TIME_CLR_VALUE		0x0000
 #define I2C_TIME_DEFAULT_VALUE		0x0003
 #define I2C_WRRD_TRANAC_VALUE		0x0002
@@ -484,6 +486,7 @@ static void mtk_i2c_clock_disable(struct mtk_i2c *i2c)
 static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
 {
 	u16 control_reg;
+	u16 ext_conf_val;
 
 	if (i2c->dev_comp->apdma_sync) {
 		writel(I2C_DMA_WARM_RST, i2c->pdmabase + OFFSET_RST);
@@ -518,8 +521,13 @@ static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
 	if (i2c->dev_comp->ltiming_adjust)
 		mtk_i2c_writew(i2c, i2c->ltiming_reg, OFFSET_LTIMING);
 
+	if (i2c->speed_hz <= I2C_MAX_STANDARD_MODE_FREQ)
+		ext_conf_val = I2C_ST_START_CON;
+	else
+		ext_conf_val = I2C_FS_START_CON;
+
 	if (i2c->dev_comp->timing_adjust) {
-		mtk_i2c_writew(i2c, i2c->ac_timing.ext, OFFSET_EXT_CONF);
+		ext_conf_val = i2c->ac_timing.ext;
 		mtk_i2c_writew(i2c, i2c->ac_timing.inter_clk_div,
 			       OFFSET_CLOCK_DIV);
 		mtk_i2c_writew(i2c, I2C_SCL_MIS_COMP_VALUE,
@@ -544,6 +552,7 @@ static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
 				       OFFSET_HS_STA_STO_AC_TIMING);
 		}
 	}
+	mtk_i2c_writew(i2c, ext_conf_val, OFFSET_EXT_CONF);
 
 	/* If use i2c pin from PMIC mt6397 side, need set PATH_DIR first */
 	if (i2c->have_pmic)
-- 
1.9.1
-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH V2 2/3] dt-bindings: i2c: add attribute default-timing-adjust
  2021-06-21  9:01 [PATCH V2 0/3] Introduce an attribute to choose timing setting kewei.xu
  2021-06-21  9:01 ` [PATCH V2 1/3] i2c: mediatek: Add OFFSET_EXT_CONF setting back kewei.xu
@ 2021-06-21  9:01 ` kewei.xu
  2021-06-21  9:01 ` [PATCH V2 3/3] i2c: mediatek: Isolate speed setting via dts for special devices kewei.xu
  2 siblings, 0 replies; 5+ messages in thread
From: kewei.xu @ 2021-06-21  9:01 UTC (permalink / raw)
  To: bbrezillon
  Cc: matthias.bgg, robh+dt, mark.rutland, linux-i3c, devicetree,
	linux-arm-kernel, linux-kernel, linux-mediatek, srv_heupstream,
	leilk.liu, qii.wang, liguo.zhang, xinping.qian, Kewei Xu

From: Kewei Xu <kewei.xu@mediatek.com>

Add attribute default-timing-adjust for DT-binding document.

Fixes: be5ce0e97cc7 ("i2c: mediatek: Add i2c ac-timing adjust support")
Signed-off-by: Kewei Xu <kewei.xu@mediatek.com>
---
 Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt b/Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt
index 7c4915bc..7b80a11 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt
@@ -33,6 +33,8 @@ Optional properties:
   - mediatek,have-pmic: platform can control i2c form special pmic side.
     Only mt6589 and mt8135 support this feature.
   - mediatek,use-push-pull: IO config use push-pull mode.
+  - mediatek,default-timing-adjust: use default timing calculation, no timing
+    adjustment.
 
 Example:
 
-- 
1.9.1
-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [PATCH V2 3/3] i2c: mediatek: Isolate speed setting via dts for special devices
  2021-06-21  9:01 [PATCH V2 0/3] Introduce an attribute to choose timing setting kewei.xu
  2021-06-21  9:01 ` [PATCH V2 1/3] i2c: mediatek: Add OFFSET_EXT_CONF setting back kewei.xu
  2021-06-21  9:01 ` [PATCH V2 2/3] dt-bindings: i2c: add attribute default-timing-adjust kewei.xu
@ 2021-06-21  9:01 ` kewei.xu
  2021-06-21  9:44   ` Tzung-Bi Shih
  2 siblings, 1 reply; 5+ messages in thread
From: kewei.xu @ 2021-06-21  9:01 UTC (permalink / raw)
  To: bbrezillon
  Cc: matthias.bgg, robh+dt, mark.rutland, linux-i3c, devicetree,
	linux-arm-kernel, linux-kernel, linux-mediatek, srv_heupstream,
	leilk.liu, qii.wang, liguo.zhang, xinping.qian, Kewei Xu

From: Kewei Xu <kewei.xu@mediatek.com>

In the commit be5ce0e97cc7 ("i2c: mediatek: Add i2c ac-timing adjust
support"), the I2C timing calculation has been revised to support
ac-timing adjustment, however that will break on some I2C components.
As a result we want to introduce a new setting "default-adjust-timing"
so those components can choose to use the old (default) timing algorithm.

Fixes: be5ce0e97cc7 ("i2c: mediatek: Add i2c ac-timing adjust support")
Signed-off-by: Kewei Xu <kewei.xu@mediatek.com>
---
 drivers/i2c/busses/i2c-mt65xx.c | 77 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 71 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index fe3cea7..88dc462 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -65,6 +65,7 @@
 #define I2C_DMA_HARD_RST		0x0002
 #define I2C_DMA_HANDSHAKE_RST		0x0004
 
+#define I2C_DEFAULT_CLK_DIV		5
 #define MAX_SAMPLE_CNT_DIV		8
 #define MAX_STEP_CNT_DIV		64
 #define MAX_CLOCK_DIV			256
@@ -249,6 +250,7 @@ struct mtk_i2c {
 	struct clk *clk_arb;		/* Arbitrator clock for i2c */
 	bool have_pmic;			/* can use i2c pins from PMIC */
 	bool use_push_pull;		/* IO config push-pull mode */
+	bool default_timing_adjust;	/* no timing adjust mode */
 
 	u16 irq_stat;			/* interrupt status */
 	unsigned int clk_src_div;
@@ -526,7 +528,11 @@ static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
 	else
 		ext_conf_val = I2C_FS_START_CON;
 
-	if (i2c->dev_comp->timing_adjust) {
+	if (i2c->default_timing_adjust) {
+		if (i2c->dev_comp->timing_adjust)
+			mtk_i2c_writew(i2c, I2C_DEFAULT_CLK_DIV - 1,
+				       OFFSET_CLOCK_DIV);
+	} else if (i2c->dev_comp->timing_adjust) {
 		ext_conf_val = i2c->ac_timing.ext;
 		mtk_i2c_writew(i2c, i2c->ac_timing.inter_clk_div,
 			       OFFSET_CLOCK_DIV);
@@ -609,7 +615,7 @@ static int mtk_i2c_check_ac_timing(struct mtk_i2c *i2c,
 	unsigned int sample_ns = div_u64(1000000000ULL * (sample_cnt + 1),
 					 clk_src);
 
-	if (!i2c->dev_comp->timing_adjust)
+	if (i2c->default_timing_adjust || !i2c->dev_comp->timing_adjust)
 		return 0;
 
 	if (i2c->dev_comp->ltiming_adjust)
@@ -769,7 +775,63 @@ static int mtk_i2c_calculate_speed(struct mtk_i2c *i2c, unsigned int clk_src,
 	return 0;
 }
 
-static int mtk_i2c_set_speed(struct mtk_i2c *i2c, unsigned int parent_clk)
+static int mtk_i2c_set_speed_default_timing(struct mtk_i2c *i2c, unsigned int parent_clk)
+{
+	unsigned int clk_src;
+	unsigned int step_cnt;
+	unsigned int sample_cnt;
+	unsigned int l_step_cnt;
+	unsigned int l_sample_cnt;
+	unsigned int target_speed;
+	int ret;
+
+	if (i2c->dev_comp->timing_adjust)
+		i2c->clk_src_div *= I2C_DEFAULT_CLK_DIV;
+
+	clk_src = parent_clk / i2c->clk_src_div;
+	target_speed = i2c->speed_hz;
+
+	if (target_speed > I2C_MAX_FAST_MODE_PLUS_FREQ) {
+		/* Set master code speed register */
+		ret = mtk_i2c_calculate_speed(i2c, clk_src, I2C_MAX_FAST_MODE_FREQ,
+					      &l_step_cnt, &l_sample_cnt);
+		if (ret < 0)
+			return ret;
+
+		i2c->timing_reg = (l_sample_cnt << 8) | l_step_cnt;
+
+		/* Set the high speed mode register */
+		ret = mtk_i2c_calculate_speed(i2c, clk_src, target_speed,
+					      &step_cnt, &sample_cnt);
+		if (ret < 0)
+			return ret;
+
+		i2c->high_speed_reg = I2C_TIME_DEFAULT_VALUE |
+			(sample_cnt << 12) | (step_cnt << 8);
+
+		if (i2c->dev_comp->ltiming_adjust)
+			i2c->ltiming_reg = (l_sample_cnt << 6) | l_step_cnt |
+					   (sample_cnt << 12) | (step_cnt << 9);
+	} else {
+		ret = mtk_i2c_calculate_speed(i2c, clk_src, target_speed,
+					      &step_cnt, &sample_cnt);
+		if (ret < 0)
+			return ret;
+
+		i2c->timing_reg = (sample_cnt << 8) | step_cnt;
+
+		/* Disable the high speed transaction */
+		i2c->high_speed_reg = I2C_TIME_CLR_VALUE;
+
+		if (i2c->dev_comp->ltiming_adjust)
+			i2c->ltiming_reg = (sample_cnt << 6) | step_cnt;
+	}
+
+	return 0;
+}
+
+static int mtk_i2c_set_speed_adjust_timing(struct mtk_i2c *i2c,
+					   unsigned int parent_clk)
 {
 	unsigned int clk_src;
 	unsigned int step_cnt;
@@ -1293,8 +1355,8 @@ static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c)
 	i2c->have_pmic = of_property_read_bool(np, "mediatek,have-pmic");
 	i2c->use_push_pull =
 		of_property_read_bool(np, "mediatek,use-push-pull");
-
-	i2c_parse_fw_timings(i2c->dev, &i2c->timing_info, true);
+	i2c->default_timing_adjust =
+		of_property_read_bool(np, "mediatek,default-timing-adjust");
 
 	return 0;
 }
@@ -1372,7 +1434,10 @@ static int mtk_i2c_probe(struct platform_device *pdev)
 
 	strlcpy(i2c->adap.name, I2C_DRV_NAME, sizeof(i2c->adap.name));
 
-	ret = mtk_i2c_set_speed(i2c, clk_get_rate(clk));
+	if (i2c->default_timing_adjust)
+		ret = mtk_i2c_set_speed_default_timing(i2c, clk_get_rate(clk));
+	else
+		ret = mtk_i2c_set_speed_adjust_timing(i2c, clk_get_rate(clk));
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to set the speed.\n");
 		return -EINVAL;
-- 
1.9.1
-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [PATCH V2 3/3] i2c: mediatek: Isolate speed setting via dts for special devices
  2021-06-21  9:01 ` [PATCH V2 3/3] i2c: mediatek: Isolate speed setting via dts for special devices kewei.xu
@ 2021-06-21  9:44   ` Tzung-Bi Shih
  0 siblings, 0 replies; 5+ messages in thread
From: Tzung-Bi Shih @ 2021-06-21  9:44 UTC (permalink / raw)
  To: kewei.xu
  Cc: bbrezillon, matthias.bgg, robh+dt, mark.rutland, linux-i3c,
	devicetree, linux-arm-kernel, linux-kernel, linux-mediatek,
	srv_heupstream, leilk.liu, qii.wang, liguo.zhang, xinping.qian

On Mon, Jun 21, 2021 at 5:03 PM <kewei.xu@mediatek.com> wrote:
> @@ -1293,8 +1355,8 @@ static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c)
>         i2c->have_pmic = of_property_read_bool(np, "mediatek,have-pmic");
>         i2c->use_push_pull =
>                 of_property_read_bool(np, "mediatek,use-push-pull");
> -
> -       i2c_parse_fw_timings(i2c->dev, &i2c->timing_info, true);
Looks like the patch removes the line accidentally.

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

end of thread, other threads:[~2021-06-22 15:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21  9:01 [PATCH V2 0/3] Introduce an attribute to choose timing setting kewei.xu
2021-06-21  9:01 ` [PATCH V2 1/3] i2c: mediatek: Add OFFSET_EXT_CONF setting back kewei.xu
2021-06-21  9:01 ` [PATCH V2 2/3] dt-bindings: i2c: add attribute default-timing-adjust kewei.xu
2021-06-21  9:01 ` [PATCH V2 3/3] i2c: mediatek: Isolate speed setting via dts for special devices kewei.xu
2021-06-21  9:44   ` Tzung-Bi Shih

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).