linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memory: renesas-rpc-if: Simplify single/double data register access
@ 2022-04-11 12:55 Geert Uytterhoeven
  2022-04-12  9:42 ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-04-11 12:55 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Wolfram Sang, Sergey Shtylyov, Duc Nguyen, Lad Prabhakar,
	Andrew Gabbasov, linux-renesas-soc, linux-mtd, linux-kernel,
	Geert Uytterhoeven

For manual write and read, factor out the common access to the first
data register by keeping track of the current data pointer.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/memory/renesas-rpc-if.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-if.c
index 019a0822bde0e413..fb2a507ca2badc70 100644
--- a/drivers/memory/renesas-rpc-if.c
+++ b/drivers/memory/renesas-rpc-if.c
@@ -488,7 +488,7 @@ int rpcif_manual_xfer(struct rpcif *rpc)
 	case RPCIF_DATA_OUT:
 		while (pos < rpc->xferlen) {
 			u32 bytes_left = rpc->xferlen - pos;
-			u32 nbytes, data[2];
+			u32 nbytes, data[2], *p = data;
 
 			smcr = rpc->smcr | RPCIF_SMCR_SPIE;
 
@@ -502,15 +502,9 @@ int rpcif_manual_xfer(struct rpcif *rpc)
 			rpc->xfer_size = nbytes;
 
 			memcpy(data, rpc->buffer + pos, nbytes);
-			if (nbytes == 8) {
-				regmap_write(rpc->regmap, RPCIF_SMWDR1,
-					     data[0]);
-				regmap_write(rpc->regmap, RPCIF_SMWDR0,
-					     data[1]);
-			} else {
-				regmap_write(rpc->regmap, RPCIF_SMWDR0,
-					     data[0]);
-			}
+			if (nbytes == 8)
+				regmap_write(rpc->regmap, RPCIF_SMWDR1, *p++);
+			regmap_write(rpc->regmap, RPCIF_SMWDR0, *p++);
 
 			regmap_write(rpc->regmap, RPCIF_SMCR, smcr);
 			ret = wait_msg_xfer_end(rpc);
@@ -552,7 +546,7 @@ int rpcif_manual_xfer(struct rpcif *rpc)
 		}
 		while (pos < rpc->xferlen) {
 			u32 bytes_left = rpc->xferlen - pos;
-			u32 nbytes, data[2];
+			u32 nbytes, data[2], *p = data;
 
 			/* nbytes may only be 1, 2, 4, or 8 */
 			nbytes = bytes_left >= max ? max : (1 << ilog2(bytes_left));
@@ -569,15 +563,9 @@ int rpcif_manual_xfer(struct rpcif *rpc)
 			if (ret)
 				goto err_out;
 
-			if (nbytes == 8) {
-				regmap_read(rpc->regmap, RPCIF_SMRDR1,
-					    &data[0]);
-				regmap_read(rpc->regmap, RPCIF_SMRDR0,
-					    &data[1]);
-			} else {
-				regmap_read(rpc->regmap, RPCIF_SMRDR0,
-					    &data[0]);
-			}
+			if (nbytes == 8)
+				regmap_read(rpc->regmap, RPCIF_SMRDR1, p++);
+			regmap_read(rpc->regmap, RPCIF_SMRDR0, p++);
 			memcpy(rpc->buffer + pos, data, nbytes);
 
 			pos += nbytes;
-- 
2.25.1


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

* Re: [PATCH] memory: renesas-rpc-if: Simplify single/double data register access
  2022-04-11 12:55 [PATCH] memory: renesas-rpc-if: Simplify single/double data register access Geert Uytterhoeven
@ 2022-04-12  9:42 ` Wolfram Sang
  2022-04-12  9:45   ` Geert Uytterhoeven
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2022-04-12  9:42 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Krzysztof Kozlowski, Sergey Shtylyov, Duc Nguyen, Lad Prabhakar,
	Andrew Gabbasov, linux-renesas-soc, linux-mtd, linux-kernel

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

On Mon, Apr 11, 2022 at 02:55:29PM +0200, Geert Uytterhoeven wrote:
> For manual write and read, factor out the common access to the first
> data register by keeping track of the current data pointer.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Works fine with reading/writing on a V3U, so:

Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

I agree the code is more concise. I am not sure, though, if it is really
more readable. But I don't mind very much, so except for a small nit:

Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

> +			if (nbytes == 8)
> +				regmap_write(rpc->regmap, RPCIF_SMWDR1, *p++);
> +			regmap_write(rpc->regmap, RPCIF_SMWDR0, *p++);

Last '++' can be omitted?


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

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

* Re: [PATCH] memory: renesas-rpc-if: Simplify single/double data register access
  2022-04-12  9:42 ` Wolfram Sang
@ 2022-04-12  9:45   ` Geert Uytterhoeven
  2022-04-12  9:49     ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-04-12  9:45 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Krzysztof Kozlowski, Sergey Shtylyov, Duc Nguyen, Lad Prabhakar,
	Andrew Gabbasov, Linux-Renesas, MTD Maling List,
	Linux Kernel Mailing List

Hi Wolfram,

On Tue, Apr 12, 2022 at 11:42 AM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> On Mon, Apr 11, 2022 at 02:55:29PM +0200, Geert Uytterhoeven wrote:
> > For manual write and read, factor out the common access to the first
> > data register by keeping track of the current data pointer.
> >
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> Works fine with reading/writing on a V3U, so:
>
> Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
>
> I agree the code is more concise. I am not sure, though, if it is really
> more readable. But I don't mind very much, so except for a small nit:
>
> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Thanks!

> > +                     if (nbytes == 8)
> > +                             regmap_write(rpc->regmap, RPCIF_SMWDR1, *p++);
> > +                     regmap_write(rpc->regmap, RPCIF_SMWDR0, *p++);
>
> Last '++' can be omitted?

I know. But I think it looks nicer this way ;-)
The compiler doesn't care anyway.

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] 7+ messages in thread

* Re: [PATCH] memory: renesas-rpc-if: Simplify single/double data register access
  2022-04-12  9:45   ` Geert Uytterhoeven
@ 2022-04-12  9:49     ` Wolfram Sang
  2022-04-12 10:04       ` Geert Uytterhoeven
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2022-04-12  9:49 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Krzysztof Kozlowski, Sergey Shtylyov, Duc Nguyen, Lad Prabhakar,
	Andrew Gabbasov, Linux-Renesas, MTD Maling List,
	Linux Kernel Mailing List

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


> > > +                     regmap_write(rpc->regmap, RPCIF_SMWDR0, *p++);
> >
> > Last '++' can be omitted?
> 
> I know. But I think it looks nicer this way ;-)

I have to admit it looks a little like "I copy&pasted without thinking"
to me :)


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

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

* Re: [PATCH] memory: renesas-rpc-if: Simplify single/double data register access
  2022-04-12  9:49     ` Wolfram Sang
@ 2022-04-12 10:04       ` Geert Uytterhoeven
  2022-04-12 10:17         ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-04-12 10:04 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Krzysztof Kozlowski, Sergey Shtylyov, Duc Nguyen, Lad Prabhakar,
	Andrew Gabbasov, Linux-Renesas, MTD Maling List,
	Linux Kernel Mailing List

Hi Wolfram,

On Tue, Apr 12, 2022 at 11:49 AM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> > > > +                     regmap_write(rpc->regmap, RPCIF_SMWDR0, *p++);
> > >
> > > Last '++' can be omitted?
> >
> > I know. But I think it looks nicer this way ;-)
>
> I have to admit it looks a little like "I copy&pasted without thinking"
> to me :)

But that's not what happened. I even compared the assembler output of
various solutions.

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] 7+ messages in thread

* Re: [PATCH] memory: renesas-rpc-if: Simplify single/double data register access
  2022-04-12 10:04       ` Geert Uytterhoeven
@ 2022-04-12 10:17         ` Wolfram Sang
  2022-04-12 12:19           ` Krzysztof Kozlowski
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2022-04-12 10:17 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Krzysztof Kozlowski, Sergey Shtylyov, Duc Nguyen, Lad Prabhakar,
	Andrew Gabbasov, Linux-Renesas, MTD Maling List,
	Linux Kernel Mailing List

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


> But that's not what happened. I even compared the assembler output of
> various solutions.

I am sure you did. I just said "it looks like..." to state a reason why
I don't think it looks prettier. But this turns to bike-shedding for me,
just keep it if everyone else is happy.


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

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

* Re: [PATCH] memory: renesas-rpc-if: Simplify single/double data register access
  2022-04-12 10:17         ` Wolfram Sang
@ 2022-04-12 12:19           ` Krzysztof Kozlowski
  0 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-12 12:19 UTC (permalink / raw)
  To: Wolfram Sang, Geert Uytterhoeven, Sergey Shtylyov, Duc Nguyen,
	Lad Prabhakar, Andrew Gabbasov, Linux-Renesas, MTD Maling List,
	Linux Kernel Mailing List

On 12/04/2022 12:17, Wolfram Sang wrote:
> 
>> But that's not what happened. I even compared the assembler output of
>> various solutions.
> 
> I am sure you did. I just said "it looks like..." to state a reason why
> I don't think it looks prettier. But this turns to bike-shedding for me,
> just keep it if everyone else is happy.

I vote for removal of ++, because later someone might wonder why it was
incremented even if not used.

Best regards,
Krzysztof

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

end of thread, other threads:[~2022-04-12 12:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-11 12:55 [PATCH] memory: renesas-rpc-if: Simplify single/double data register access Geert Uytterhoeven
2022-04-12  9:42 ` Wolfram Sang
2022-04-12  9:45   ` Geert Uytterhoeven
2022-04-12  9:49     ` Wolfram Sang
2022-04-12 10:04       ` Geert Uytterhoeven
2022-04-12 10:17         ` Wolfram Sang
2022-04-12 12:19           ` Krzysztof Kozlowski

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