linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices
@ 2023-12-14  7:43 Wolfram Sang
  2023-12-14  7:43 ` [PATCH v2 1/2] i2c: rcar: introduce " Wolfram Sang
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Wolfram Sang @ 2023-12-14  7:43 UTC (permalink / raw)
  To: linux-renesas-soc; +Cc: Wolfram Sang, linux-i2c, linux-kernel

The newest generation of Renesas R-Car SoCs support FastMode+. This
series enables the driver to use it. Changes since v1 are annotated in
the patches.

Looking forward to comments and test reports etc.

Happy hacking!


Wolfram Sang (2):
  i2c: rcar: introduce Gen4 devices
  i2c: rcar: add FastMode+ support for Gen4

 drivers/i2c/busses/i2c-rcar.c | 51 +++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 17 deletions(-)

-- 
2.35.1


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

* [PATCH v2 1/2] i2c: rcar: introduce Gen4 devices
  2023-12-14  7:43 [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices Wolfram Sang
@ 2023-12-14  7:43 ` Wolfram Sang
  2023-12-14  8:03   ` Geert Uytterhoeven
  2023-12-14 20:47   ` Andi Shyti
  2023-12-14  7:43 ` [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4 Wolfram Sang
  2023-12-19 12:42 ` [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices Wolfram Sang
  2 siblings, 2 replies; 9+ messages in thread
From: Wolfram Sang @ 2023-12-14  7:43 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: Wolfram Sang, Andi Shyti, Geert Uytterhoeven, Magnus Damm,
	linux-i2c, linux-kernel

So far, we treated Gen4 as Gen3. But we are soon adding FM+ as a Gen4
specific feature, so prepare the code for the new devtype.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Changes since v1:

* rebased to 6.7-rc4
* moved S4 specific handling to patch 2

 drivers/i2c/busses/i2c-rcar.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 829ac053bbb7..973811a6c27b 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -132,6 +132,7 @@ enum rcar_i2c_type {
 	I2C_RCAR_GEN1,
 	I2C_RCAR_GEN2,
 	I2C_RCAR_GEN3,
+	I2C_RCAR_GEN4,
 };
 
 struct rcar_i2c_priv {
@@ -431,8 +432,8 @@ static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv, bool terminate)
 	dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg),
 			 sg_dma_len(&priv->sg), priv->dma_direction);
 
-	/* Gen3 can only do one RXDMA per transfer and we just completed it */
-	if (priv->devtype == I2C_RCAR_GEN3 &&
+	/* Gen3+ can only do one RXDMA per transfer and we just completed it */
+	if (priv->devtype >= I2C_RCAR_GEN3 &&
 	    priv->dma_direction == DMA_FROM_DEVICE)
 		priv->flags |= ID_P_NO_RXDMA;
 
@@ -886,8 +887,8 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
 	if (ret < 0)
 		goto out;
 
-	/* Gen3 needs a reset before allowing RXDMA once */
-	if (priv->devtype == I2C_RCAR_GEN3) {
+	/* Gen3+ needs a reset. That also allows RXDMA once */
+	if (priv->devtype >= I2C_RCAR_GEN3) {
 		priv->flags &= ~ID_P_NO_RXDMA;
 		ret = rcar_i2c_do_reset(priv);
 		if (ret)
@@ -1075,7 +1076,7 @@ static const struct of_device_id rcar_i2c_dt_ids[] = {
 	{ .compatible = "renesas,rcar-gen1-i2c", .data = (void *)I2C_RCAR_GEN1 },
 	{ .compatible = "renesas,rcar-gen2-i2c", .data = (void *)I2C_RCAR_GEN2 },
 	{ .compatible = "renesas,rcar-gen3-i2c", .data = (void *)I2C_RCAR_GEN3 },
-	{ .compatible = "renesas,rcar-gen4-i2c", .data = (void *)I2C_RCAR_GEN3 },
+	{ .compatible = "renesas,rcar-gen4-i2c", .data = (void *)I2C_RCAR_GEN4 },
 	{},
 };
 MODULE_DEVICE_TABLE(of, rcar_i2c_dt_ids);
@@ -1151,7 +1152,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
 	if (of_property_read_bool(dev->of_node, "smbus"))
 		priv->flags |= ID_P_HOST_NOTIFY;
 
-	if (priv->devtype == I2C_RCAR_GEN3) {
+	if (priv->devtype >= I2C_RCAR_GEN3) {
 		priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
 		if (IS_ERR(priv->rstc)) {
 			ret = PTR_ERR(priv->rstc);
-- 
2.35.1


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

* [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4
  2023-12-14  7:43 [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices Wolfram Sang
  2023-12-14  7:43 ` [PATCH v2 1/2] i2c: rcar: introduce " Wolfram Sang
@ 2023-12-14  7:43 ` Wolfram Sang
  2023-12-14  8:19   ` Geert Uytterhoeven
  2023-12-14 20:54   ` Andi Shyti
  2023-12-19 12:42 ` [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices Wolfram Sang
  2 siblings, 2 replies; 9+ messages in thread
From: Wolfram Sang @ 2023-12-14  7:43 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: Wolfram Sang, Andi Shyti, Geert Uytterhoeven, Magnus Damm,
	linux-i2c, linux-kernel

To support FM+, we mainly need to turn the SMD constant into a parameter
and set it accordingly. That also means we can finally fix SMD to our
needs instead of bailing out. A sanity check for SMD then becomes a
sanity check for 'x == 0'. After all that, activating the enable bit for
FM+ is all we need to do. Tested with a Renesas Falcon board using R-Car
V3U.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Changes since v1:

* rebased to 6.7-rc4
* gained S4 specific handling from patch 1
* keep SCL filters active for FM+ by still writing to CDF
* if default SMD is too large, fix it instead of bailing out

 drivers/i2c/busses/i2c-rcar.c | 38 +++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 973811a6c27b..828aa2ea0fe4 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -89,6 +89,7 @@
 #define TMDMAE	BIT(0)	/* DMA Master Transmitted Enable */
 
 /* ICCCR2 */
+#define FMPE	BIT(7)	/* Fast Mode Plus Enable */
 #define CDFD	BIT(2)	/* CDF Disable */
 #define HLSE	BIT(1)	/* HIGH/LOW Separate Control Enable */
 #define SME	BIT(0)	/* SCL Mask Enable */
@@ -122,11 +123,12 @@
 #define ID_NACK			BIT(4)
 #define ID_EPROTO		BIT(5)
 /* persistent flags */
+#define ID_P_FMPLUS		BIT(27)
 #define ID_P_NOT_ATOMIC		BIT(28)
 #define ID_P_HOST_NOTIFY	BIT(29)
 #define ID_P_NO_RXDMA		BIT(30) /* HW forbids RXDMA sometimes */
 #define ID_P_PM_BLOCKED		BIT(31)
-#define ID_P_MASK		GENMASK(31, 28)
+#define ID_P_MASK		GENMASK(31, 27)
 
 enum rcar_i2c_type {
 	I2C_RCAR_GEN1,
@@ -149,6 +151,7 @@ struct rcar_i2c_priv {
 	u32 icccr;
 	u16 schd;
 	u16 scld;
+	u8 smd;
 	u8 recovery_icmcr;	/* protected by adapter lock */
 	enum rcar_i2c_type devtype;
 	struct i2c_client *slave;
@@ -240,9 +243,14 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv)
 	if (priv->devtype < I2C_RCAR_GEN3) {
 		rcar_i2c_write(priv, ICCCR, priv->icccr);
 	} else {
-		rcar_i2c_write(priv, ICCCR2, CDFD | HLSE | SME);
+		u32 icccr2 = CDFD | HLSE | SME;
+
+		if (priv->flags & ID_P_FMPLUS)
+			icccr2 |= FMPE;
+
+		rcar_i2c_write(priv, ICCCR2, icccr2);
 		rcar_i2c_write(priv, ICCCR, priv->icccr);
-		rcar_i2c_write(priv, ICMPR, RCAR_DEFAULT_SMD);
+		rcar_i2c_write(priv, ICMPR, priv->smd);
 		rcar_i2c_write(priv, ICHPR, priv->schd);
 		rcar_i2c_write(priv, ICLPR, priv->scld);
 		rcar_i2c_write(priv, ICFBSCR, TCYC17);
@@ -279,6 +287,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv)
 
 	/* Fall back to previously used values if not supplied */
 	i2c_parse_fw_timings(dev, &t, false);
+	priv->smd = RCAR_DEFAULT_SMD;
 
 	/*
 	 * calculate SCL clock
@@ -304,6 +313,11 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv)
 	if (cdf >= 1U << cdf_width)
 		goto err_no_val;
 
+	if (t.bus_freq_hz > I2C_MAX_FAST_MODE_FREQ && priv->devtype >= I2C_RCAR_GEN4)
+		priv->flags |= ID_P_FMPLUS;
+	else
+		priv->flags &= ~ID_P_FMPLUS;
+
 	/* On Gen3+, we use cdf only for the filters, not as a SCL divider */
 	ick = rate / (priv->devtype < I2C_RCAR_GEN3 ? (cdf + 1) : 1);
 
@@ -345,30 +359,30 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv)
 		 * x as a base value for the SCLD/SCHD ratio:
 		 *
 		 * SCL = clkp / (8 + 2 * SMD + SCLD + SCHD + F[(ticf + tr + intd) * clkp])
-		 * SCL = clkp / (8 + 2 * RCAR_DEFAULT_SMD + RCAR_SCLD_RATIO * x
+		 * SCL = clkp / (8 + 2 * SMD + RCAR_SCLD_RATIO * x
 		 *		 + RCAR_SCHD_RATIO * x + F[...])
 		 *
 		 * with: sum_ratio = RCAR_SCLD_RATIO + RCAR_SCHD_RATIO
-		 * and:  smd = RCAR_DEFAULT_SMD
 		 *
 		 * SCL = clkp / (8 + 2 * smd + sum_ratio * x + F[...])
 		 * 8 + 2 * smd + sum_ratio * x + F[...] = clkp / SCL
 		 * x = ((clkp / SCL) - 8 - 2 * smd - F[...]) / sum_ratio
 		 */
 		x = DIV_ROUND_UP(rate, t.bus_freq_hz ?: 1);
-		x = DIV_ROUND_UP(x - 8 - 2 * RCAR_DEFAULT_SMD - round, sum_ratio);
-		scl = rate / (8 + 2 * RCAR_DEFAULT_SMD + sum_ratio * x + round);
+		x = DIV_ROUND_UP(x - 8 - 2 * priv->smd - round, sum_ratio);
+		scl = rate / (8 + 2 * priv->smd + sum_ratio * x + round);
 
-		/* Bail out if values don't fit into 16 bit or SMD became too large */
-		if (x * RCAR_SCLD_RATIO > 0xffff || RCAR_DEFAULT_SMD > x * RCAR_SCHD_RATIO)
+		if (x == 0 || x * RCAR_SCLD_RATIO > 0xffff)
 			goto err_no_val;
 
 		priv->icccr = cdf;
 		priv->schd = RCAR_SCHD_RATIO * x;
 		priv->scld = RCAR_SCLD_RATIO * x;
+		if (priv->smd >= priv->schd)
+			priv->smd = priv->schd - 1;
 
-		dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u SCHD %u SCLD %u\n",
-			scl, t.bus_freq_hz, rate, round, cdf, priv->schd, priv->scld);
+		dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u SCHD %u SCLD %u SMD %u\n",
+			scl, t.bus_freq_hz, rate, round, cdf, priv->schd, priv->scld, priv->smd);
 	}
 
 	return 0;
@@ -1073,6 +1087,8 @@ static const struct of_device_id rcar_i2c_dt_ids[] = {
 	{ .compatible = "renesas,i2c-r8a7794", .data = (void *)I2C_RCAR_GEN2 },
 	{ .compatible = "renesas,i2c-r8a7795", .data = (void *)I2C_RCAR_GEN3 },
 	{ .compatible = "renesas,i2c-r8a7796", .data = (void *)I2C_RCAR_GEN3 },
+	/* S4 has no FM+ bit */
+	{ .compatible = "renesas,i2c-r8a779f0", .data = (void *)I2C_RCAR_GEN3 },
 	{ .compatible = "renesas,rcar-gen1-i2c", .data = (void *)I2C_RCAR_GEN1 },
 	{ .compatible = "renesas,rcar-gen2-i2c", .data = (void *)I2C_RCAR_GEN2 },
 	{ .compatible = "renesas,rcar-gen3-i2c", .data = (void *)I2C_RCAR_GEN3 },
-- 
2.35.1


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

* Re: [PATCH v2 1/2] i2c: rcar: introduce Gen4 devices
  2023-12-14  7:43 ` [PATCH v2 1/2] i2c: rcar: introduce " Wolfram Sang
@ 2023-12-14  8:03   ` Geert Uytterhoeven
  2023-12-14 20:47   ` Andi Shyti
  1 sibling, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-12-14  8:03 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-renesas-soc, Andi Shyti, Magnus Damm, linux-i2c, linux-kernel

On Thu, Dec 14, 2023 at 8:44 AM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> So far, we treated Gen4 as Gen3. But we are soon adding FM+ as a Gen4
> specific feature, so prepare the code for the new devtype.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> Changes since v1:
>
> * rebased to 6.7-rc4
> * moved S4 specific handling to patch 2

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4
  2023-12-14  7:43 ` [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4 Wolfram Sang
@ 2023-12-14  8:19   ` Geert Uytterhoeven
  2023-12-14 20:54   ` Andi Shyti
  1 sibling, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2023-12-14  8:19 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-renesas-soc, Andi Shyti, Magnus Damm, linux-i2c, linux-kernel

On Thu, Dec 14, 2023 at 8:44 AM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> To support FM+, we mainly need to turn the SMD constant into a parameter
> and set it accordingly. That also means we can finally fix SMD to our
> needs instead of bailing out. A sanity check for SMD then becomes a
> sanity check for 'x == 0'. After all that, activating the enable bit for
> FM+ is all we need to do. Tested with a Renesas Falcon board using R-Car
> V3U.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> Changes since v1:
>
> * rebased to 6.7-rc4
> * gained S4 specific handling from patch 1
> * keep SCL filters active for FM+ by still writing to CDF
> * if default SMD is too large, fix it instead of bailing out

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v2 1/2] i2c: rcar: introduce Gen4 devices
  2023-12-14  7:43 ` [PATCH v2 1/2] i2c: rcar: introduce " Wolfram Sang
  2023-12-14  8:03   ` Geert Uytterhoeven
@ 2023-12-14 20:47   ` Andi Shyti
  1 sibling, 0 replies; 9+ messages in thread
From: Andi Shyti @ 2023-12-14 20:47 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-renesas-soc, Geert Uytterhoeven, Magnus Damm, linux-i2c,
	linux-kernel

Hi Wolfram,

On Thu, Dec 14, 2023 at 08:43:57AM +0100, Wolfram Sang wrote:
> So far, we treated Gen4 as Gen3. But we are soon adding FM+ as a Gen4
> specific feature, so prepare the code for the new devtype.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Andi Shyti <andi.shyti@kernel.org>

Thanks,
Andi

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

* Re: [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4
  2023-12-14  7:43 ` [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4 Wolfram Sang
  2023-12-14  8:19   ` Geert Uytterhoeven
@ 2023-12-14 20:54   ` Andi Shyti
  2023-12-15  2:10     ` Wolfram Sang
  1 sibling, 1 reply; 9+ messages in thread
From: Andi Shyti @ 2023-12-14 20:54 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-renesas-soc, Geert Uytterhoeven, Magnus Damm, linux-i2c,
	linux-kernel

Hi Wolfram,

[...]

> -		dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u SCHD %u SCLD %u\n",
> -			scl, t.bus_freq_hz, rate, round, cdf, priv->schd, priv->scld);
> +		dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u SCHD %u SCLD %u SMD %u\n",
> +			scl, t.bus_freq_hz, rate, round, cdf, priv->schd, priv->scld, priv->smd);

as we were here we could have written the register values as
0x%x, but it's also OK to keep the change with a minimal impact.

Reviewed-by: Andi Shyti <andi.shyti@kernel.org>

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

* Re: [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4
  2023-12-14 20:54   ` Andi Shyti
@ 2023-12-15  2:10     ` Wolfram Sang
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2023-12-15  2:10 UTC (permalink / raw)
  To: Andi Shyti
  Cc: linux-renesas-soc, Geert Uytterhoeven, Magnus Damm, linux-i2c,
	linux-kernel

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

Hi Andi,

> as we were here we could have written the register values as
> 0x%x, but it's also OK to keep the change with a minimal impact.

I think it is OK like it is because the datasheet also uses decimal
values in the formulas.

> Reviewed-by: Andi Shyti <andi.shyti@kernel.org>

Thanks!

   Wolfram


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

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

* Re: [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices
  2023-12-14  7:43 [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices Wolfram Sang
  2023-12-14  7:43 ` [PATCH v2 1/2] i2c: rcar: introduce " Wolfram Sang
  2023-12-14  7:43 ` [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4 Wolfram Sang
@ 2023-12-19 12:42 ` Wolfram Sang
  2 siblings, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2023-12-19 12:42 UTC (permalink / raw)
  To: linux-renesas-soc; +Cc: linux-i2c, linux-kernel

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

On Thu, Dec 14, 2023 at 08:43:56AM +0100, Wolfram Sang wrote:
> The newest generation of Renesas R-Car SoCs support FastMode+. This
> series enables the driver to use it. Changes since v1 are annotated in
> the patches.
> 
> Looking forward to comments and test reports etc.
> 
> Happy hacking!
> 
> 
> Wolfram Sang (2):
>   i2c: rcar: introduce Gen4 devices
>   i2c: rcar: add FastMode+ support for Gen4
> 

Applied to for-next, thanks!


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

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

end of thread, other threads:[~2023-12-19 12:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-14  7:43 [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices Wolfram Sang
2023-12-14  7:43 ` [PATCH v2 1/2] i2c: rcar: introduce " Wolfram Sang
2023-12-14  8:03   ` Geert Uytterhoeven
2023-12-14 20:47   ` Andi Shyti
2023-12-14  7:43 ` [PATCH v2 2/2] i2c: rcar: add FastMode+ support for Gen4 Wolfram Sang
2023-12-14  8:19   ` Geert Uytterhoeven
2023-12-14 20:54   ` Andi Shyti
2023-12-15  2:10     ` Wolfram Sang
2023-12-19 12:42 ` [PATCH v2 0/2] i2c: rcar: add support for Gen4 devices 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).