Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] Add support for AC timing adjustment
@ 2019-06-11  8:11 Qii Wang
  2019-06-11  8:11 ` [PATCH 1/2] dt-bindings: i2c: Add MediaTek i2c AC timing binding Qii Wang
  2019-06-11  8:11 ` [PATCH 2/2] i2c: mediatek: Add i2c AC timing adjust support Qii Wang
  0 siblings, 2 replies; 6+ messages in thread
From: Qii Wang @ 2019-06-11  8:11 UTC (permalink / raw)
  To: wsa
  Cc: devicetree, qii.wang, srv_heupstream, leilk.liu, linux-kernel,
	robh+dt, linux-mediatek, linux-i2c, matthias.bgg,
	linux-arm-kernel

This series are based on 5.2-rc1, we provide two patches to
support AC timing adjustment.

Qii Wang (2):
  dt-bindings: i2c: Add MediaTek i2c AC timing binding
  i2c: mediatek: Add i2c AC timing adjust support

 .../devicetree/bindings/i2c/i2c-mt65xx.txt         |   11 +++
 drivers/i2c/busses/i2c-mt65xx.c                    |   94 +++++++++++++++++---
 2 files changed, 93 insertions(+), 12 deletions(-)

-- 
1.7.9.5

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 1/2] dt-bindings: i2c: Add MediaTek i2c AC timing binding
  2019-06-11  8:11 [PATCH 0/2] Add support for AC timing adjustment Qii Wang
@ 2019-06-11  8:11 ` Qii Wang
  2019-06-26 13:39   ` Wolfram Sang
  2019-06-11  8:11 ` [PATCH 2/2] i2c: mediatek: Add i2c AC timing adjust support Qii Wang
  1 sibling, 1 reply; 6+ messages in thread
From: Qii Wang @ 2019-06-11  8:11 UTC (permalink / raw)
  To: wsa
  Cc: devicetree, qii.wang, srv_heupstream, leilk.liu, linux-kernel,
	robh+dt, linux-mediatek, linux-i2c, matthias.bgg,
	linux-arm-kernel

Add i2c AC timing binding to binding file. It can give the AC
timing parameters to meet I2C specification at different speed.

Signed-off-by: Qii Wang <qii.wang@mediatek.com>
---
 .../devicetree/bindings/i2c/i2c-mt65xx.txt         |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt b/Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt
index 68f6d73..0f92813 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt
@@ -30,6 +30,7 @@ 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.
+  - ac-timing: give some AC timing parameters to meet i2c spec fully.
 
 Example:
 
@@ -43,5 +44,15 @@ Example:
 			clock-div = <16>;
 			clocks = <&i2c0_ck>, <&ap_dma_ck>;
 			clock-names = "main", "dma";
+			ac-timing =  /bits/ 16 <
+				0x8001	/* 0:ext */
+				0x0005	/* 1:inter_clk_div */
+				0x0102	/* 2:scl_hl_ratio */
+				0x0102	/* 3:hs_scl_hl_ratio */
+				0x0002	/* 4:scl_mis_comp */
+				0x0002	/* 5:sta_stop */
+				0x0002	/* 6:hs_sta_stop */
+				0x0002	/* 7:sda_timing */
+			>;
 	};
 
-- 
1.7.9.5


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 2/2] i2c: mediatek: Add i2c AC timing adjust support
  2019-06-11  8:11 [PATCH 0/2] Add support for AC timing adjustment Qii Wang
  2019-06-11  8:11 ` [PATCH 1/2] dt-bindings: i2c: Add MediaTek i2c AC timing binding Qii Wang
@ 2019-06-11  8:11 ` Qii Wang
  1 sibling, 0 replies; 6+ messages in thread
From: Qii Wang @ 2019-06-11  8:11 UTC (permalink / raw)
  To: wsa
  Cc: devicetree, qii.wang, srv_heupstream, leilk.liu, linux-kernel,
	robh+dt, linux-mediatek, linux-i2c, matthias.bgg,
	linux-arm-kernel

This patch adds some I2C timing registers to meet I2C spec, it
configures these registers according to information passed via DT.

Signed-off-by: Qii Wang <qii.wang@mediatek.com>
---
 drivers/i2c/busses/i2c-mt65xx.c |   94 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 82 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 745b0d0..f4bf753 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -134,6 +134,12 @@ enum I2C_REGS_OFFSET {
 	OFFSET_TRANSFER_LEN_AUX,
 	OFFSET_CLOCK_DIV,
 	OFFSET_LTIMING,
+	OFFSET_SCL_HIGH_LOW_RATIO,
+	OFFSET_HS_SCL_HIGH_LOW_RATIO,
+	OFFSET_SCL_MIS_COMP_POINT,
+	OFFSET_STA_STO_AC_TIMING,
+	OFFSET_HS_STA_STO_AC_TIMING,
+	OFFSET_SDA_TIMING,
 };
 
 static const u16 mt_i2c_regs_v1[] = {
@@ -161,6 +167,12 @@ enum I2C_REGS_OFFSET {
 	[OFFSET_DEBUGCTRL] = 0x68,
 	[OFFSET_TRANSFER_LEN_AUX] = 0x6c,
 	[OFFSET_CLOCK_DIV] = 0x70,
+	[OFFSET_SCL_HIGH_LOW_RATIO] = 0x74,
+	[OFFSET_HS_SCL_HIGH_LOW_RATIO] = 0x78,
+	[OFFSET_SCL_MIS_COMP_POINT] = 0x7C,
+	[OFFSET_STA_STO_AC_TIMING] = 0x80,
+	[OFFSET_HS_STA_STO_AC_TIMING] = 0x84,
+	[OFFSET_SDA_TIMING] = 0x88,
 };
 
 static const u16 mt_i2c_regs_v2[] = {
@@ -179,9 +191,11 @@ enum I2C_REGS_OFFSET {
 	[OFFSET_HS] = 0x30,
 	[OFFSET_IO_CONFIG] = 0x34,
 	[OFFSET_FIFO_ADDR_CLR] = 0x38,
+	[OFFSET_SDA_TIMING] = 0x3c,
 	[OFFSET_TRANSFER_LEN_AUX] = 0x44,
 	[OFFSET_CLOCK_DIV] = 0x48,
 	[OFFSET_SOFTRESET] = 0x50,
+	[OFFSET_SCL_MIS_COMP_POINT] = 0x90,
 	[OFFSET_DEBUGSTAT] = 0xe0,
 	[OFFSET_DEBUGCTRL] = 0xe8,
 	[OFFSET_FIFO_STAT] = 0xf4,
@@ -202,6 +216,17 @@ struct mtk_i2c_compatible {
 	unsigned char ltiming_adjust: 1;
 };
 
+struct mtk_i2c_ac_timing {
+	u16 ext;
+	u16 inter_clk_div;
+	u16 scl_hl_ratio;
+	u16 hs_scl_hl_ratio;
+	u16 scl_mis_comp;
+	u16 sta_stop;
+	u16 hs_sta_stop;
+	u16 sda_timing;
+};
+
 struct mtk_i2c {
 	struct i2c_adapter adap;	/* i2c host adapter */
 	struct device *dev;
@@ -226,6 +251,7 @@ struct mtk_i2c {
 	u16 ltiming_reg;
 	unsigned char auto_restart;
 	bool ignore_restart_irq;
+	struct mtk_i2c_ac_timing ac_timing;
 	const struct mtk_i2c_compatible *dev_comp;
 };
 
@@ -403,13 +429,40 @@ static void mtk_i2c_init_hw(struct mtk_i2c *i2c)
 	if (i2c->dev_comp->dcm)
 		mtk_i2c_writew(i2c, I2C_DCM_DISABLE, OFFSET_DCM_EN);
 
-	if (i2c->dev_comp->timing_adjust)
-		mtk_i2c_writew(i2c, I2C_DEFAULT_CLK_DIV - 1, OFFSET_CLOCK_DIV);
-
 	mtk_i2c_writew(i2c, i2c->timing_reg, OFFSET_TIMING);
 	mtk_i2c_writew(i2c, i2c->high_speed_reg, OFFSET_HS);
-	if (i2c->dev_comp->ltiming_adjust)
-		mtk_i2c_writew(i2c, i2c->ltiming_reg, OFFSET_LTIMING);
+
+	if (i2c->dev_comp->timing_adjust) {
+		mtk_i2c_writew(i2c, i2c->ac_timing.ext, OFFSET_EXT_CONF);
+		mtk_i2c_writew(i2c, i2c->ac_timing.inter_clk_div - 1,
+			       OFFSET_CLOCK_DIV);
+		mtk_i2c_writew(i2c, i2c->ac_timing.scl_mis_comp,
+			       OFFSET_SCL_MIS_COMP_POINT);
+		mtk_i2c_writew(i2c, i2c->ac_timing.sda_timing,
+			       OFFSET_SDA_TIMING);
+
+		if (i2c->dev_comp->ltiming_adjust) {
+			mtk_i2c_writew(i2c, i2c->timing_reg -
+				       i2c->ac_timing.scl_hl_ratio,
+				       OFFSET_TIMING);
+			mtk_i2c_writew(i2c, i2c->high_speed_reg -
+				       ((i2c->ac_timing.hs_scl_hl_ratio) << 8),
+				       OFFSET_HS);
+			mtk_i2c_writew(i2c, i2c->ltiming_reg +
+				       ((i2c->ac_timing.hs_scl_hl_ratio) << 9) +
+				       i2c->ac_timing.scl_hl_ratio,
+				       OFFSET_LTIMING);
+		} else {
+			mtk_i2c_writew(i2c, i2c->ac_timing.scl_hl_ratio,
+				       OFFSET_SCL_HIGH_LOW_RATIO);
+			mtk_i2c_writew(i2c, i2c->ac_timing.hs_scl_hl_ratio,
+				       OFFSET_HS_SCL_HIGH_LOW_RATIO);
+			mtk_i2c_writew(i2c, i2c->ac_timing.sta_stop,
+				       OFFSET_STA_STO_AC_TIMING);
+			mtk_i2c_writew(i2c, i2c->ac_timing.hs_sta_stop,
+				       OFFSET_HS_STA_STO_AC_TIMING);
+		}
+	}
 
 	/* If use i2c pin from PMIC mt6397 side, need set PATH_DIR first */
 	if (i2c->have_pmic)
@@ -592,12 +645,6 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs,
 
 	mtk_i2c_writew(i2c, control_reg, OFFSET_CONTROL);
 
-	/* set start condition */
-	if (i2c->speed_hz <= I2C_DEFAULT_SPEED)
-		mtk_i2c_writew(i2c, I2C_ST_START_CON, OFFSET_EXT_CONF);
-	else
-		mtk_i2c_writew(i2c, I2C_FS_START_CON, OFFSET_EXT_CONF);
-
 	addr_reg = i2c_8bit_addr_from_msg(msgs);
 	mtk_i2c_writew(i2c, addr_reg, OFFSET_SLAVE_ADDR);
 
@@ -889,6 +936,7 @@ static u32 mtk_i2c_functionality(struct i2c_adapter *adap)
 static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c)
 {
 	int ret;
+	u16 ac_timing[8] = {0};
 
 	ret = of_property_read_u32(np, "clock-frequency", &i2c->speed_hz);
 	if (ret < 0)
@@ -901,6 +949,28 @@ static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c)
 	if (i2c->clk_src_div == 0)
 		return -EINVAL;
 
+	if (i2c->dev_comp->timing_adjust) {
+		ret = of_property_read_u16_array(np, "ac-timing", ac_timing,
+						 ARRAY_SIZE(ac_timing));
+		if (ret < 0) {
+			if (i2c->speed_hz <= I2C_DEFAULT_SPEED)
+				i2c->ac_timing.ext = I2C_ST_START_CON;
+			else
+				i2c->ac_timing.ext = I2C_FS_START_CON;
+
+			i2c->ac_timing.inter_clk_div = I2C_DEFAULT_CLK_DIV;
+		} else {
+			i2c->ac_timing.ext = ac_timing[0];
+			i2c->ac_timing.inter_clk_div = ac_timing[1];
+			i2c->ac_timing.scl_hl_ratio = ac_timing[2];
+			i2c->ac_timing.hs_scl_hl_ratio = ac_timing[3];
+			i2c->ac_timing.scl_mis_comp = ac_timing[4];
+			i2c->ac_timing.sta_stop = ac_timing[5];
+			i2c->ac_timing.hs_sta_stop = ac_timing[6];
+			i2c->ac_timing.sda_timing = ac_timing[7];
+		}
+	}
+
 	i2c->have_pmic = of_property_read_bool(np, "mediatek,have-pmic");
 	i2c->use_push_pull =
 		of_property_read_bool(np, "mediatek,use-push-pull");
@@ -951,7 +1021,7 @@ static int mtk_i2c_probe(struct platform_device *pdev)
 		return -EINVAL;
 
 	if (i2c->dev_comp->timing_adjust)
-		i2c->clk_src_div *= I2C_DEFAULT_CLK_DIV;
+		i2c->clk_src_div *= i2c->ac_timing.inter_clk_div;
 
 	if (i2c->have_pmic && !i2c->dev_comp->pmic_i2c)
 		return -EINVAL;
-- 
1.7.9.5


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/2] dt-bindings: i2c: Add MediaTek i2c AC timing binding
  2019-06-11  8:11 ` [PATCH 1/2] dt-bindings: i2c: Add MediaTek i2c AC timing binding Qii Wang
@ 2019-06-26 13:39   ` Wolfram Sang
  2019-07-17 12:55     ` Qii Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2019-06-26 13:39 UTC (permalink / raw)
  To: Qii Wang
  Cc: devicetree, srv_heupstream, leilk.liu, linux-kernel, robh+dt,
	linux-mediatek, linux-i2c, matthias.bgg, linux-arm-kernel

[-- Attachment #1.1: Type: text/plain, Size: 1109 bytes --]

Hi,

On Tue, Jun 11, 2019 at 04:11:54PM +0800, Qii Wang wrote:
> Add i2c AC timing binding to binding file. It can give the AC
> timing parameters to meet I2C specification at different speed.
> 
> Signed-off-by: Qii Wang <qii.wang@mediatek.com>

I think this is a too specific 1:1 mapping of your register set into DT
world. We already have these generic parameters:

- clock-frequency
        frequency of bus clock in Hz.

- i2c-scl-falling-time-ns
        Number of nanoseconds the SCL signal takes to fall; t(f) in the I2C
        specification.

- i2c-scl-internal-delay-ns
        Number of nanoseconds the IP core additionally needs to setup SCL.

- i2c-scl-rising-time-ns
        Number of nanoseconds the SCL signal takes to rise; t(r) in the I2C
        specification.

- i2c-sda-falling-time-ns
        Number of nanoseconds the SDA signal takes to fall; t(f) in the I2C
        specification.

(check Documentation/devicetree/bindings/i2c/i2c.txt)

Can't you use those to derive your values from that? Which ones are you missing
if not?

Regards,

   Wolfram

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/2] dt-bindings: i2c: Add MediaTek i2c AC timing binding
  2019-06-26 13:39   ` Wolfram Sang
@ 2019-07-17 12:55     ` Qii Wang
  2019-07-17 13:29       ` Wolfram Sang
  0 siblings, 1 reply; 6+ messages in thread
From: Qii Wang @ 2019-07-17 12:55 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: devicetree, srv_heupstream, leilk.liu, linux-kernel, robh+dt,
	linux-mediatek, linux-i2c, matthias.bgg, linux-arm-kernel

On Wed, 2019-06-26 at 15:39 +0200, Wolfram Sang wrote:
> Hi,
> 
> On Tue, Jun 11, 2019 at 04:11:54PM +0800, Qii Wang wrote:
> > Add i2c AC timing binding to binding file. It can give the AC
> > timing parameters to meet I2C specification at different speed.
> > 
> > Signed-off-by: Qii Wang <qii.wang@mediatek.com>
> 
> I think this is a too specific 1:1 mapping of your register set into DT
> world. We already have these generic parameters:
> 
> - clock-frequency
>         frequency of bus clock in Hz.
> 
> - i2c-scl-falling-time-ns
>         Number of nanoseconds the SCL signal takes to fall; t(f) in the I2C
>         specification.
> 
> - i2c-scl-internal-delay-ns
>         Number of nanoseconds the IP core additionally needs to setup SCL.
> 
> - i2c-scl-rising-time-ns
>         Number of nanoseconds the SCL signal takes to rise; t(r) in the I2C
>         specification.
> 
> - i2c-sda-falling-time-ns
>         Number of nanoseconds the SDA signal takes to fall; t(f) in the I2C
>         specification.
> 
> (check Documentation/devicetree/bindings/i2c/i2c.txt)
> 
> Can't you use those to derive your values from that? Which ones are you missing
> if not?
> 
> Regards,
> 
>    Wolfram

I have take a little time to develop a new patch which based on your
suggestions, and it tested OK. Thanks for your suggestions, I will
update the patch after I test it fully.



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/2] dt-bindings: i2c: Add MediaTek i2c AC timing binding
  2019-07-17 12:55     ` Qii Wang
@ 2019-07-17 13:29       ` Wolfram Sang
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2019-07-17 13:29 UTC (permalink / raw)
  To: Qii Wang
  Cc: devicetree, srv_heupstream, leilk.liu, linux-kernel, robh+dt,
	linux-mediatek, linux-i2c, matthias.bgg, linux-arm-kernel

[-- Attachment #1.1: Type: text/plain, Size: 314 bytes --]


> > Can't you use those to derive your values from that? Which ones are you missing
> > if not?
> 
> I have take a little time to develop a new patch which based on your
> suggestions, and it tested OK. Thanks for your suggestions, I will
> update the patch after I test it fully.

Great news, thanks!


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-11  8:11 [PATCH 0/2] Add support for AC timing adjustment Qii Wang
2019-06-11  8:11 ` [PATCH 1/2] dt-bindings: i2c: Add MediaTek i2c AC timing binding Qii Wang
2019-06-26 13:39   ` Wolfram Sang
2019-07-17 12:55     ` Qii Wang
2019-07-17 13:29       ` Wolfram Sang
2019-06-11  8:11 ` [PATCH 2/2] i2c: mediatek: Add i2c AC timing adjust support Qii Wang

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org infradead-linux-arm-kernel@archiver.kernel.org
	public-inbox-index linux-arm-kernel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox