linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] i2c: at91: Add support for programmable clock source
@ 2021-10-12 14:07 Horatiu Vultur
  2021-10-12 14:07 ` [PATCH 1/2] dt-bindings: i2c: at91: Extend compatible list for lan966x Horatiu Vultur
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Horatiu Vultur @ 2021-10-12 14:07 UTC (permalink / raw)
  To: robh+dt, nicolas.ferre, alexandre.belloni, ludovic.desroches,
	codrin.ciubotariu, linux-i2c, devicetree, linux-arm-kernel,
	linux-kernel
  Cc: Horatiu Vultur

Add support to be able to set BRSRCCLK. This feature is support on lan966x

Horatiu Vultur (2):
  dt-bindings: i2c: at91: Extend compatible list for lan966x
  i2c: at91: add support for brsrcclk

 .../devicetree/bindings/i2c/i2c-at91.txt      |  6 +++--
 drivers/i2c/busses/i2c-at91-core.c            | 16 +++++++++++++
 drivers/i2c/busses/i2c-at91-master.c          | 23 +++++++++++++++++--
 drivers/i2c/busses/i2c-at91.h                 |  1 +
 4 files changed, 42 insertions(+), 4 deletions(-)

-- 
2.33.0


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

* [PATCH 1/2] dt-bindings: i2c: at91: Extend compatible list for lan966x
  2021-10-12 14:07 [PATCH 0/2] i2c: at91: Add support for programmable clock source Horatiu Vultur
@ 2021-10-12 14:07 ` Horatiu Vultur
  2021-10-22 23:37   ` Rob Herring
  2021-10-12 14:07 ` [PATCH 2/2] i2c: at91: add support for brsrcclk Horatiu Vultur
  2021-10-13  8:49 ` [PATCH 0/2] i2c: at91: Add support for programmable clock source Codrin.Ciubotariu
  2 siblings, 1 reply; 11+ messages in thread
From: Horatiu Vultur @ 2021-10-12 14:07 UTC (permalink / raw)
  To: robh+dt, nicolas.ferre, alexandre.belloni, ludovic.desroches,
	codrin.ciubotariu, linux-i2c, devicetree, linux-arm-kernel,
	linux-kernel
  Cc: Horatiu Vultur

Extend compatible list and the i2c-sda-hold-time-ns property
with 'microchip,lan966x-i2c'

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 Documentation/devicetree/bindings/i2c/i2c-at91.txt | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
index 2015f50aed0f..d3b5ed081597 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
@@ -10,7 +10,8 @@ Required properties :
 	"atmel,at91sam9x5-i2c",
 	"atmel,sama5d4-i2c",
 	"atmel,sama5d2-i2c",
-	"microchip,sam9x60-i2c".
+	"microchip,sam9x60-i2c",
+	"microchip,lan966x-i2c".
 - reg: physical base address of the controller and length of memory mapped
      region.
 - interrupts: interrupt number to the cpu.
@@ -27,7 +28,8 @@ Optional properties:
 - i2c-sda-hold-time-ns: TWD hold time, only available for:
 	"atmel,sama5d4-i2c",
 	"atmel,sama5d2-i2c",
-	"microchip,sam9x60-i2c".
+	"microchip,sam9x60-i2c",
+	"microchip,lan966x-i2c".
 - scl-gpios: specify the gpio related to SCL pin
 - sda-gpios: specify the gpio related to SDA pin
 - pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
-- 
2.33.0


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

* [PATCH 2/2] i2c: at91: add support for brsrcclk
  2021-10-12 14:07 [PATCH 0/2] i2c: at91: Add support for programmable clock source Horatiu Vultur
  2021-10-12 14:07 ` [PATCH 1/2] dt-bindings: i2c: at91: Extend compatible list for lan966x Horatiu Vultur
@ 2021-10-12 14:07 ` Horatiu Vultur
  2021-10-13  8:49 ` [PATCH 0/2] i2c: at91: Add support for programmable clock source Codrin.Ciubotariu
  2 siblings, 0 replies; 11+ messages in thread
From: Horatiu Vultur @ 2021-10-12 14:07 UTC (permalink / raw)
  To: robh+dt, nicolas.ferre, alexandre.belloni, ludovic.desroches,
	codrin.ciubotariu, linux-i2c, devicetree, linux-arm-kernel,
	linux-kernel
  Cc: Horatiu Vultur

This allows to set the TWI bite rate based on a programmable clock source.
The lan966x supports this feature.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 drivers/i2c/busses/i2c-at91-core.c   | 16 ++++++++++++++++
 drivers/i2c/busses/i2c-at91-master.c | 23 +++++++++++++++++++++--
 drivers/i2c/busses/i2c-at91.h        |  1 +
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-at91-core.c b/drivers/i2c/busses/i2c-at91-core.c
index 2df9df585131..d98b437e5775 100644
--- a/drivers/i2c/busses/i2c-at91-core.c
+++ b/drivers/i2c/busses/i2c-at91-core.c
@@ -146,6 +146,19 @@ static struct at91_twi_pdata sam9x60_config = {
 	.has_clear_cmd = true,
 };
 
+static struct at91_twi_pdata lan966x_config = {
+	.clk_max_div = 7,
+	.clk_offset = 0,
+	.clk_brsrcclk = true,
+	.has_unre_flag = true,
+	.has_alt_cmd = true,
+	.has_hold_field = true,
+	.has_dig_filtr = true,
+	.has_adv_dig_filtr = true,
+	.has_ana_filtr = true,
+	.has_clear_cmd = true,
+};
+
 static const struct of_device_id atmel_twi_dt_ids[] = {
 	{
 		.compatible = "atmel,at91rm9200-i2c",
@@ -174,6 +187,9 @@ static const struct of_device_id atmel_twi_dt_ids[] = {
 	}, {
 		.compatible = "microchip,sam9x60-i2c",
 		.data = &sam9x60_config,
+	}, {
+		.compatible = "microchip,lan966x-i2c",
+		.data = &lan966x_config,
 	}, {
 		/* sentinel */
 	}
diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
index b0eae94909f4..f504af30adbe 100644
--- a/drivers/i2c/busses/i2c-at91-master.c
+++ b/drivers/i2c/busses/i2c-at91-master.c
@@ -120,8 +120,27 @@ static void at91_calc_twi_clock(struct at91_twi_dev *dev)
 		}
 	}
 
-	dev->twi_cwgr_reg = (ckdiv << 16) | (cdiv << 8) | cdiv
-			    | AT91_TWI_CWGR_HOLD(hold);
+	if (pdata->clk_brsrcclk) {
+		u8 chdiv, cldiv, gck_pr;
+
+		gck_pr = 1000000000 / clk_get_rate(dev->clk);
+
+		/* thigh = bus_freq_hz in ns * 0.4
+		 * tlow = bus_freq_hz in ns * 0.6
+		 * chdiv = (thigh / GCK_PR)/2 ^ CKDIV
+		 * cldiv = (tlow / GCK_PR)/2 ^ CKDIV
+		 * where ckdiv = 0;
+		 */
+		cldiv = (1000000000 / t->bus_freq_hz * 6 / 10) / gck_pr;
+		chdiv = (1000000000 / t->bus_freq_hz * 4 / 10) / gck_pr;
+
+		dev->twi_cwgr_reg = (chdiv << 8) | cldiv
+			| AT91_TWI_CWGR_HOLD(hold)
+			| pdata->clk_brsrcclk << 20;
+	} else {
+		dev->twi_cwgr_reg = (ckdiv << 16) | (cdiv << 8) | cdiv
+			| AT91_TWI_CWGR_HOLD(hold);
+	}
 
 	dev->filter_width = filter_width;
 
diff --git a/drivers/i2c/busses/i2c-at91.h b/drivers/i2c/busses/i2c-at91.h
index 942e9c3973bb..f7328fbe8eb8 100644
--- a/drivers/i2c/busses/i2c-at91.h
+++ b/drivers/i2c/busses/i2c-at91.h
@@ -115,6 +115,7 @@
 struct at91_twi_pdata {
 	unsigned clk_max_div;
 	unsigned clk_offset;
+	bool clk_brsrcclk;
 	bool has_unre_flag;
 	bool has_alt_cmd;
 	bool has_hold_field;
-- 
2.33.0


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

* Re: [PATCH 0/2] i2c: at91: Add support for programmable clock source
  2021-10-12 14:07 [PATCH 0/2] i2c: at91: Add support for programmable clock source Horatiu Vultur
  2021-10-12 14:07 ` [PATCH 1/2] dt-bindings: i2c: at91: Extend compatible list for lan966x Horatiu Vultur
  2021-10-12 14:07 ` [PATCH 2/2] i2c: at91: add support for brsrcclk Horatiu Vultur
@ 2021-10-13  8:49 ` Codrin.Ciubotariu
  2021-10-13 11:41   ` Horatiu Vultur - M31836
  2 siblings, 1 reply; 11+ messages in thread
From: Codrin.Ciubotariu @ 2021-10-13  8:49 UTC (permalink / raw)
  To: Horatiu.Vultur, robh+dt, Nicolas.Ferre, alexandre.belloni,
	Ludovic.Desroches, linux-i2c, devicetree, linux-arm-kernel,
	linux-kernel

On 12.10.2021 17:07, Horatiu Vultur wrote:
> Add support to be able to set BRSRCCLK. This feature is support on lan966x
> 
> Horatiu Vultur (2):
>    dt-bindings: i2c: at91: Extend compatible list for lan966x
>    i2c: at91: add support for brsrcclk
> 
>   .../devicetree/bindings/i2c/i2c-at91.txt      |  6 +++--
>   drivers/i2c/busses/i2c-at91-core.c            | 16 +++++++++++++
>   drivers/i2c/busses/i2c-at91-master.c          | 23 +++++++++++++++++--
>   drivers/i2c/busses/i2c-at91.h                 |  1 +
>   4 files changed, 42 insertions(+), 4 deletions(-)
> 

Hi Horatiu,

 From what I understand, on your DTS, you replaced the peripheral clock 
with the GCLK in the I2C node. This means that you are forcing all the 
variants that support clk_brsrcclk to treat the current clock as GCLK. 
This is not necessarily correct, since this newer variants can also work 
fine with only the peripheral clock and we should keep these option 
available.

I would add an optional GCLK clock binding in the I2C node. This way 
GCLK will be used only if it is present in DT and clk_brsrcclk set.

Best regards,
Codrin

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

* Re: [PATCH 0/2] i2c: at91: Add support for programmable clock source
  2021-10-13  8:49 ` [PATCH 0/2] i2c: at91: Add support for programmable clock source Codrin.Ciubotariu
@ 2021-10-13 11:41   ` Horatiu Vultur - M31836
  2021-10-13 13:10     ` Codrin.Ciubotariu
  2021-11-05 21:47     ` Wolfram Sang
  0 siblings, 2 replies; 11+ messages in thread
From: Horatiu Vultur - M31836 @ 2021-10-13 11:41 UTC (permalink / raw)
  To: Codrin Ciubotariu - M19940
  Cc: robh+dt, Nicolas Ferre - M43238, alexandre.belloni,
	Ludovic Desroches - M43218, linux-i2c, devicetree,
	linux-arm-kernel, linux-kernel

The 10/13/2021 08:49, Codrin Ciubotariu - M19940 wrote:
> On 12.10.2021 17:07, Horatiu Vultur wrote:
> > Add support to be able to set BRSRCCLK. This feature is support on lan966x
> > 
> > Horatiu Vultur (2):
> >    dt-bindings: i2c: at91: Extend compatible list for lan966x
> >    i2c: at91: add support for brsrcclk
> > 
> >   .../devicetree/bindings/i2c/i2c-at91.txt      |  6 +++--
> >   drivers/i2c/busses/i2c-at91-core.c            | 16 +++++++++++++
> >   drivers/i2c/busses/i2c-at91-master.c          | 23 +++++++++++++++++--
> >   drivers/i2c/busses/i2c-at91.h                 |  1 +
> >   4 files changed, 42 insertions(+), 4 deletions(-)
> > 
> 
> Hi Horatiu,

Hi Codrin,

> 
>  From what I understand, on your DTS, you replaced the peripheral clock 
> with the GCLK in the I2C node. This means that you are forcing all the 
> variants that support clk_brsrcclk to treat the current clock as GCLK. 
> This is not necessarily correct, since this newer variants can also work 
> fine with only the peripheral clock and we should keep these option 
> available.
> 
> I would add an optional GCLK clock binding in the I2C node. This way 
> GCLK will be used only if it is present in DT and clk_brsrcclk set.

Thanks for the explanation.

I think actually I will drop this patch series because apparently
lan966x works fine also with the peripheral clock. So then no changes
are required.

If you think is worth it, I can do another version with the proposed
changes.

> 
> Best regards,
> Codrin

-- 
/Horatiu

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

* Re: [PATCH 0/2] i2c: at91: Add support for programmable clock source
  2021-10-13 11:41   ` Horatiu Vultur - M31836
@ 2021-10-13 13:10     ` Codrin.Ciubotariu
  2021-11-05 21:47     ` Wolfram Sang
  1 sibling, 0 replies; 11+ messages in thread
From: Codrin.Ciubotariu @ 2021-10-13 13:10 UTC (permalink / raw)
  To: Horatiu.Vultur
  Cc: robh+dt, Nicolas.Ferre, alexandre.belloni, Ludovic.Desroches,
	linux-i2c, devicetree, linux-arm-kernel, linux-kernel

> I think actually I will drop this patch series because apparently
> lan966x works fine also with the peripheral clock. So then no changes
> are required.
> 
> If you think is worth it, I can do another version with the proposed
> changes.

Probably not until we have an implemented good reason to use GCLK.

Best regards,
Codrin

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

* Re: [PATCH 1/2] dt-bindings: i2c: at91: Extend compatible list for lan966x
  2021-10-12 14:07 ` [PATCH 1/2] dt-bindings: i2c: at91: Extend compatible list for lan966x Horatiu Vultur
@ 2021-10-22 23:37   ` Rob Herring
  0 siblings, 0 replies; 11+ messages in thread
From: Rob Herring @ 2021-10-22 23:37 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: alexandre.belloni, linux-kernel, codrin.ciubotariu,
	ludovic.desroches, linux-i2c, robh+dt, linux-arm-kernel,
	nicolas.ferre, devicetree

On Tue, 12 Oct 2021 16:07:17 +0200, Horatiu Vultur wrote:
> Extend compatible list and the i2c-sda-hold-time-ns property
> with 'microchip,lan966x-i2c'
> 
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-at91.txt | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH 0/2] i2c: at91: Add support for programmable clock source
  2021-10-13 11:41   ` Horatiu Vultur - M31836
  2021-10-13 13:10     ` Codrin.Ciubotariu
@ 2021-11-05 21:47     ` Wolfram Sang
  2021-11-08  8:35       ` Codrin.Ciubotariu
  1 sibling, 1 reply; 11+ messages in thread
From: Wolfram Sang @ 2021-11-05 21:47 UTC (permalink / raw)
  To: Horatiu Vultur - M31836
  Cc: Codrin Ciubotariu - M19940, robh+dt, Nicolas Ferre - M43238,
	alexandre.belloni, Ludovic Desroches - M43218, linux-i2c,
	devicetree, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 179 bytes --]


> I think actually I will drop this patch series because apparently
> lan966x works fine also with the peripheral clock. So then no changes
> are required.

Not even patch 1/2?


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

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

* Re: [PATCH 0/2] i2c: at91: Add support for programmable clock source
  2021-11-05 21:47     ` Wolfram Sang
@ 2021-11-08  8:35       ` Codrin.Ciubotariu
  2021-11-08  9:29         ` Horatiu Vultur - M31836
  0 siblings, 1 reply; 11+ messages in thread
From: Codrin.Ciubotariu @ 2021-11-08  8:35 UTC (permalink / raw)
  To: wsa, Horatiu.Vultur, robh+dt, Nicolas.Ferre, alexandre.belloni,
	Ludovic.Desroches, linux-i2c, devicetree, linux-arm-kernel,
	linux-kernel

On 05.11.2021 23:47, Wolfram Sang wrote:
> 
>> I think actually I will drop this patch series because apparently
>> lan966x works fine also with the peripheral clock. So then no changes
>> are required.
> 
> Not even patch 1/2?
> 

we can keep the new compatible, but patch 2/2 needs to be split.

Best regards,
Codrin

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

* Re: [PATCH 0/2] i2c: at91: Add support for programmable clock source
  2021-11-08  8:35       ` Codrin.Ciubotariu
@ 2021-11-08  9:29         ` Horatiu Vultur - M31836
  2021-11-29 10:06           ` Wolfram Sang
  0 siblings, 1 reply; 11+ messages in thread
From: Horatiu Vultur - M31836 @ 2021-11-08  9:29 UTC (permalink / raw)
  To: Codrin Ciubotariu - M19940
  Cc: Wolfram Sang, robh+dt, Nicolas Ferre - M43238, alexandre.belloni,
	Ludovic Desroches - M43218, linux-i2c, devicetree,
	linux-arm-kernel, linux-kernel

The 11/08/2021 08:35, Codrin Ciubotariu - M19940 wrote:
> On 05.11.2021 23:47, Wolfram Sang wrote:
> > 
> >> I think actually I will drop this patch series because apparently
> >> lan966x works fine also with the peripheral clock. So then no changes
> >> are required.
> > 
> > Not even patch 1/2?
> > 
> 
> we can keep the new compatible, but patch 2/2 needs to be split.

For me it is OK to use the compatible string 'microchip,sam9x60-i2c'

> 
> Best regards,
> Codrin

-- 
/Horatiu

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

* Re: [PATCH 0/2] i2c: at91: Add support for programmable clock source
  2021-11-08  9:29         ` Horatiu Vultur - M31836
@ 2021-11-29 10:06           ` Wolfram Sang
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfram Sang @ 2021-11-29 10:06 UTC (permalink / raw)
  To: Horatiu Vultur - M31836
  Cc: Codrin Ciubotariu - M19940, robh+dt, Nicolas Ferre - M43238,
	alexandre.belloni, Ludovic Desroches - M43218, linux-i2c,
	devicetree, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 269 bytes --]


> > > Not even patch 1/2?
> > 
> > we can keep the new compatible, but patch 2/2 needs to be split.
> 
> For me it is OK to use the compatible string 'microchip,sam9x60-i2c'

I'll drop this patch for now. If anyone is still interested in it,
please resend.


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

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

end of thread, other threads:[~2021-11-29 10:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 14:07 [PATCH 0/2] i2c: at91: Add support for programmable clock source Horatiu Vultur
2021-10-12 14:07 ` [PATCH 1/2] dt-bindings: i2c: at91: Extend compatible list for lan966x Horatiu Vultur
2021-10-22 23:37   ` Rob Herring
2021-10-12 14:07 ` [PATCH 2/2] i2c: at91: add support for brsrcclk Horatiu Vultur
2021-10-13  8:49 ` [PATCH 0/2] i2c: at91: Add support for programmable clock source Codrin.Ciubotariu
2021-10-13 11:41   ` Horatiu Vultur - M31836
2021-10-13 13:10     ` Codrin.Ciubotariu
2021-11-05 21:47     ` Wolfram Sang
2021-11-08  8:35       ` Codrin.Ciubotariu
2021-11-08  9:29         ` Horatiu Vultur - M31836
2021-11-29 10:06           ` Wolfram Sang

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