public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Richard <thomas.richard@bootlin.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	thomas.petazzoni@bootlin.com, DanieleCleri@aaeon.eu,
	GaryWang@aaeon.com.tw, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v5 12/12] pinctrl: Add pin controller driver for AAEON UP boards
Date: Wed, 7 May 2025 15:34:12 +0200	[thread overview]
Message-ID: <0af29bac-ebe2-4448-b708-f0b9258544e7@bootlin.com> (raw)
In-Reply-To: <CAHp75VfFnd616FiG8XP_oW4MeMBrqj_nmi0xCOGUj-LG1ru-qw@mail.gmail.com>

On 5/7/25 08:57, Andy Shevchenko wrote:
> 
>> +#define UPBOARD_UP_PIN_MUX(bit, data)                          \
>> +       {                                                       \
>> +               .number = UPBOARD_UP_BIT_##bit,                 \
>> +               .name = "PINMUX_"#bit,                          \
>> +               .drv_data = (void *)(data),                     \
> 
> Wondering why we need to cast here and there if currently we all use
> constant driver data. Perhaps enable const for now and if we ever need
> that to be modified by the consumer we add that.

We need to cast as drv_data is not const, so the compiler complains.
Or I can remove const.
I looked at other drivers, some do a cast, others have not const driver
data.

> 
>> +       }
>> +
>> +#define UPBOARD_UP_PIN_FUNC(id, data)                          \
>> +       {                                                       \
>> +               .number = UPBOARD_UP_BIT_##id,                  \
>> +               .name = #id,                                    \
>> +               .drv_data = (void *)(data),                     \
> 
> Ditto.
> 
>> +       }
> 
> ...
> 
>> +static int upboard_pinctrl_register_groups(struct upboard_pinctrl *pctrl)
>> +{
>> +       const struct upboard_pingroup *groups = pctrl->pctrl_data->groups;
>> +       size_t ngroups = pctrl->pctrl_data->ngroups;
>> +       unsigned int i;
>> +       int ret;
>> +
>> +       for (i = 0; i < ngroups; i++) {
>> +               ret = pinctrl_generic_add_group(pctrl->pctldev, groups[i].grp.name,
>> +                                               groups[i].grp.pins, groups[i].grp.npins, pctrl);
> 
>> +               if (ret < 0)
> 
> Why ' < 0' ?

pinctrl_generic_add_group() returns the group selector which can be >=
0. So all values >= 0 are valid. [1]

[1]
https://elixir.bootlin.com/linux/v6.15-rc5/source/drivers/pinctrl/core.c#L658-L676

> 
>> +                       return ret;
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>> +static int upboard_pinctrl_register_functions(struct upboard_pinctrl *pctrl)
>> +{
>> +       const struct pinfunction *funcs = pctrl->pctrl_data->funcs;
>> +       size_t nfuncs = pctrl->pctrl_data->nfuncs;
>> +       unsigned int i;
>> +       int ret;
>> +
>> +       for (i = 0; i < nfuncs ; i++) {
>> +               ret = pinmux_generic_add_function(pctrl->pctldev, funcs[i].name,
>> +                                                 funcs[i].groups, funcs[i].ngroups, NULL);
>> +               if (ret < 0)
> 
> Ditto.
> 
>> +                       return ret;
>> +       }
>> +
>> +       return 0;
>> +}
> 
> ...
> 
>> +       board_id = (enum upboard_board_id)(unsigned long)dmi_id->driver_data;
>> +
> 
> Unneeded blank line.
> 
>> +       switch (board_id) {
>> +       case UPBOARD_APL01:
>> +               pctrl->maps = upboard_pinctrl_mapping_apl01;
>> +               pctrl->nmaps = ARRAY_SIZE(upboard_pinctrl_mapping_apl01);
>> +               break;
>> +       default:
>> +               return dev_err_probe(dev, -ENODEV, "Unsupported board\n");
>> +       }
> 
> And actually we can get rid of that train of castings by switching to
> use the info type of the structure
> 
> (namings are just constructed without checking for the better or
> existing ones, choose another if you think they fit)
> 
> struct upboard_pinctrl_map {
>   ... *maps;
>   ... nmaps;
> };
> 
> static const struct upboard_pinctrl_map apl01 = {
>   ...
> };
> 
> ...dmi... = {
>   ...
>   .data = (void *)&apl01,
>   ...
> };
> 
> board_map = (const ...) dmi_id->driver_data;
> 
> ...
> 
> But since DMI will require castings, it's up to you as I don't like
> the idea of having that driver data not to be const in the first
> place.

I definitely prefer your proposal, so we can remove the switch case and
the enum.
I will just split the definition to compute automatically nmaps like this:

static const struct pinctrl_map pinctrl_map_apl01[] = {
        ...
};

static const struct upboard_pinctrl_map upboard_pinctrl_map_apl01 = {
	.maps = &pinctrl_map_apl01[0],
	.nmaps = ARRAY_SIZE(pinctrl_map_apl01),
};

Regards,

Thomas

  reply	other threads:[~2025-05-07 13:34 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06 15:21 [PATCH v5 00/12] Add pinctrl support for the AAEON UP board FPGA Thomas Richard
2025-05-06 15:21 ` [PATCH v5 01/12] gpiolib: add support to register sparse pin range Thomas Richard
2025-05-07 17:49   ` kernel test robot
2025-05-06 15:21 ` [PATCH v5 02/12] pinctrl: remove extern specifier for functions in machine.h Thomas Richard
2025-05-13 12:59   ` Linus Walleij
2025-05-06 15:21 ` [PATCH v5 03/12] pinctrl: core: add devm_pinctrl_register_mappings() Thomas Richard
2025-05-06 15:21 ` [PATCH v5 04/12] gpio: aggregator: move GPIO forwarder allocation in a dedicated function Thomas Richard
2025-05-09  8:05   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 05/12] gpio: aggregator: refactor the code to add GPIO desc in the forwarder Thomas Richard
2025-05-07  6:22   ` Andy Shevchenko
2025-05-09  8:38   ` Geert Uytterhoeven
2025-05-09  8:43     ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 06/12] gpio: aggregator: refactor the forwarder registration part Thomas Richard
2025-05-09  8:50   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 07/12] gpio: aggregator: update gpiochip_fwd_setup_delay_line() parameters Thomas Richard
2025-05-09  8:53   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 08/12] gpio: aggregator: export symbols of the GPIO forwarder library Thomas Richard
2025-05-07  6:29   ` Andy Shevchenko
2025-05-07 14:53     ` Thomas Richard
2025-05-07 15:21       ` Andy Shevchenko
2025-05-07 15:23         ` Andy Shevchenko
2025-05-07 15:29           ` Thomas Richard
2025-05-08  7:23           ` Geert Uytterhoeven
2025-05-09  9:07   ` Geert Uytterhoeven
2025-05-12 14:08     ` Thomas Richard
2025-05-12 14:11       ` Andy Shevchenko
2025-05-12 14:30         ` Thomas Richard
2025-05-12 14:42           ` Geert Uytterhoeven
2025-05-12 14:39       ` Geert Uytterhoeven
2025-05-12 15:00         ` Thomas Richard
2025-05-12 15:14           ` Geert Uytterhoeven
2025-05-12 15:33             ` Thomas Richard
2025-05-06 15:21 ` [PATCH v5 09/12] gpio: aggregator: handle runtime registration of gpio_desc in gpiochip_fwd Thomas Richard
2025-05-07  6:34   ` Andy Shevchenko
2025-05-07 10:10     ` Thomas Richard
2025-05-07 13:24       ` Andy Shevchenko
2025-05-07 13:54         ` Thomas Richard
2025-05-07 15:24           ` Andy Shevchenko
2025-05-09 13:33             ` Bartosz Golaszewski
2025-05-09  9:29   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 10/12] gpio: aggregator: add possibility to attach data to the forwarder Thomas Richard
2025-05-09  9:32   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 11/12] lib/string_choices: Add str_input_output() helper Thomas Richard
2025-05-06 15:21 ` [PATCH v5 12/12] pinctrl: Add pin controller driver for AAEON UP boards Thomas Richard
2025-05-07  6:57   ` Andy Shevchenko
2025-05-07 13:34     ` Thomas Richard [this message]
2025-05-07  6:59 ` [PATCH v5 00/12] Add pinctrl support for the AAEON UP board FPGA Andy Shevchenko
2025-05-13 13:02 ` Linus Walleij

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=0af29bac-ebe2-4448-b708-f0b9258544e7@bootlin.com \
    --to=thomas.richard@bootlin.com \
    --cc=DanieleCleri@aaeon.eu \
    --cc=GaryWang@aaeon.com.tw \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=geert+renesas@glider.be \
    --cc=kees@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    /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