linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Linux-sh list <linux-sh@vger.kernel.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: Re: [PATCH v2][RFC] pinctrl: sh-pfc: share/reuse same PORT_GP_x() macros
Date: Thu, 12 Nov 2015 13:17:47 +0100	[thread overview]
Message-ID: <CAMuHMdXoAd4TFZNzcycisXSg0gd9nWKLRK0UQyAog4HWHJr5yg@mail.gmail.com> (raw)
In-Reply-To: <87ziyldrxk.wl%kuninori.morimoto.gx@renesas.com>

Hi Morimoto-san,

On Wed, Nov 11, 2015 at 6:29 AM, Kuninori Morimoto
<kuninori.morimoto.gx@renesas.com> wrote:
> Many SoC needs each PORT_GP_x() macros, but we can share/reuse
> same one.
>
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Thanks!

I think this still can be improved upon...

ideally you just need log2(32) defines.

> --- a/drivers/pinctrl/sh-pfc/sh_pfc.h
> +++ b/drivers/pinctrl/sh-pfc/sh_pfc.h
> @@ -205,22 +205,68 @@ struct sh_pfc_soc_info {
>  #define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg) fn(bank, pin, GP_##bank##_##pin, sfx, cfg)
>  #define PORT_GP_1(bank, pin, fn, sfx)  PORT_GP_CFG_1(bank, pin, fn, sfx, 0)

"PORT_GP_1()" takes a "pin" parameter...

> -#define PORT_GP_CFG_32(bank, fn, sfx, cfg)                             \
> +#define PORT_GP_CFG_4(bank, fn, sfx, cfg)                                              \

... while "PORT_GP_CFG_X()" (with "X" > 1) don't.

>         PORT_GP_CFG_1(bank, 0,  fn, sfx, cfg), PORT_GP_CFG_1(bank, 1,  fn, sfx, cfg),   \
> -       PORT_GP_CFG_1(bank, 2,  fn, sfx, cfg), PORT_GP_CFG_1(bank, 3,  fn, sfx, cfg),   \
> +       PORT_GP_CFG_1(bank, 2,  fn, sfx, cfg), PORT_GP_CFG_1(bank, 3,  fn, sfx, cfg)
> +#define PORT_GP_4(bank, fn, sfx)       PORT_GP_CFG_4(bank, fn, sfx, 0)
> +
> +#define PORT_GP_CFG_8(bank, fn, sfx, cfg)                                              \
> +       PORT_GP_CFG_4(bank, fn, sfx, cfg),                                              \
>         PORT_GP_CFG_1(bank, 4,  fn, sfx, cfg), PORT_GP_CFG_1(bank, 5,  fn, sfx, cfg),   \
> -       PORT_GP_CFG_1(bank, 6,  fn, sfx, cfg), PORT_GP_CFG_1(bank, 7,  fn, sfx, cfg),   \
> +       PORT_GP_CFG_1(bank, 6,  fn, sfx, cfg), PORT_GP_CFG_1(bank, 7,  fn, sfx, cfg)
> +#define PORT_GP_8(bank, fn, sfx)       PORT_GP_CFG_8(bank, fn, sfx, 0)

Hence you can't simply define PORT_GP_8() in terms of PORT_GP_CFG_4().

So what about:

#define _PORT_GP_CFG_1(bank, pin, fn, sfx, cfg) fn(bank, pin,
GP_##bank##_##pin, sfx, cfg)
#define _PORT_GP_CFG_2(bank, pin, fn, sfx, cfg) \
        _PORT_GP_CFG_1(bank, 0, fn, sfx, cfg) _PORT_GP_CFG_1(bank, 1,
fn, sfx, cfg)
#define _PORT_GP_CFG_4(bank, pin, fn, sfx, cfg) \
        _PORT_GP_CFG_2(bank, 0, fn, sfx, cfg) _PORT_GP_CFG_2(bank, 2,
fn, sfx, cfg)
...
#define _PORT_GP_CFG_32(bank, pin, fn, sfx, cfg) \
        _PORT_GP_CFG_16(bank, 0, fn, sfx, cfg) _PORT_GP_CFG_16(bank,
16, fn, sfx, cfg)

All the rest (only the ones we really need) can be defined in terms of
the above.
E.g.

 #define PORT_GP_CFG_1(bank, fn, sfx, cfg) _PORT_GP_CFG_1(bank, 0, fn, sfx, cfg)
 #define PORT_GP_CFG_2(bank, fn, sfx, cfg) _PORT_GP_CFG_2(bank, 0, fn, sfx, cfg)
 #define PORT_GP_CFG_4(bank, pin, fn, sfx, cfg) _PORT_GP_CFG_4(bank,
0, fn, sfx, cfg)
...
 #define PORT_GP_CFG_32(bank, fn, sfx, cfg) _PORT_GP_CFG_32(bank, 0,
fn, sfx, cfg)

and

 #define PORT_GP_1(bank, fn, sfx) _PORT_GP_CFG_1(bank, 0, fn, sfx, 0)
 #define PORT_GP_2(bank, fn, sfx) _PORT_GP_CFG_2(bank, 0, fn, sfx, 0)
 #define PORT_GP_4(bank, fn, sfx) _PORT_GP_CFG_4(bank, 0, fn, sfx, 0)
...
 #define PORT_GP_32(bank, fn, sfx) _PORT_GP_CFG_32(bank, 0, fn, sfx, 0)

and for the special (non-power-of-two) numbers e.g.

#define PORT_GP_12(bank, fn, sfx) \
        _PORT_GP_CFG_8(bank, 0, fn, sfx, 0) _PORT_GP_CFG_4(bank, 8, fn, sfx, 0)

What do you think?

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

  reply	other threads:[~2015-11-12 12:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-10  8:56 [PATCH][RFC] pinctrl: sh-pfc: share/reuse same PORT_GP_x() macros Kuninori Morimoto
2015-11-11  3:28 ` Kuninori Morimoto
2015-11-11  5:29   ` [PATCH v2][RFC] " Kuninori Morimoto
2015-11-12 12:17     ` Geert Uytterhoeven [this message]
2015-11-13  0:30       ` Kuninori Morimoto
2015-11-13  4:02         ` Kuninori Morimoto
2015-11-13  7:44           ` Geert Uytterhoeven
2015-11-13  8:47             ` Kuninori Morimoto
2015-11-25  0:18               ` Laurent Pinchart
2015-11-25  6:45                 ` Kuninori Morimoto
2015-11-25  9:31                   ` Geert Uytterhoeven
2015-11-24  8:57     ` Geert Uytterhoeven
2015-11-24  9:09       ` Kuninori Morimoto
2015-11-24  9:35         ` Geert Uytterhoeven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMuHMdXoAd4TFZNzcycisXSg0gd9nWKLRK0UQyAog4HWHJr5yg@mail.gmail.com \
    --to=geert@linux-m68k.org \
    --cc=geert+renesas@glider.be \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).