From: Horatiu Vultur <horatiu.vultur@microchip.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
<kavyasree.kotagiri@microchip.com>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
Colin Foster <colin.foster@in-advantage.com>,
Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Michael Walle <michael@walle.cc>
Subject: Re: [PATCH v2 1/2] pinctrl: ocelot: Fix pincfg for lan966x
Date: Mon, 11 Jul 2022 08:49:50 +0200 [thread overview]
Message-ID: <20220711064950.3fqhuat3b23uabkj@soft-dev3-1.localhost> (raw)
In-Reply-To: <CAHp75VdPi8rT_EJd8L8-waAkH_Lm947WVKMLHjjW5MpFW9A06Q@mail.gmail.com>
The 07/08/2022 23:58, Andy Shevchenko wrote:
Hi Andy,
>
> On Fri, Jul 8, 2022 at 10:10 PM Horatiu Vultur
> <horatiu.vultur@microchip.com> wrote:
> >
> > The blamed commit introduce support for lan966x which use the same
> > pinconf_ops as sparx5. The problem is that pinconf_ops is specific to
> > sparx5. More precisely the offset of the bits in the pincfg register are
> > different and also lan966x doesn't have support for
> > PIN_CONFIG_INPUT_SCHMITT_ENABLE.
> >
> > Fix this by making pinconf_ops more generic such that it can be also
> > used by lan966x. This is done by introducing 'ocelot_pincfg_data' which
> > contains the offset and what is supported for each SOC.
>
> ...
>
> > +struct ocelot_pincfg_data {
> > + bool has_schmitt;
> > + u8 schmitt_bit;
> > + u8 pd_bit;
> > + u8 pu_bit;
> > + u8 drive_bits;
>
> I would go with mandatory fields first and leave optional (that is
> with boolean flag) at last.
>
> > +};
>
> ...
>
> > struct ocelot_pinctrl {
> > struct device *dev;
> > struct pinctrl_dev *pctl;
> > @@ -330,6 +331,12 @@ struct ocelot_pinctrl {
> > struct pinctrl_desc *desc;
> > struct ocelot_pmx_func func[FUNC_MAX];
> > u8 stride;
> > + struct ocelot_pincfg_data *pincfg_data;
>
> It might waste too many bytes in some cases. I would recommend moving
> it somewhere above, definitely before the u8 member.
>
> > +};
>
> Yes, I understand that for a certain architecture it might be the same
> result in sizeof(), the rationale is to make code better in case
> somebody copies'n'pastes pieces or ideas from it.
>
> ...
>
> > if (param == PIN_CONFIG_BIAS_DISABLE)> val = (val == 0);
> > else if (param == PIN_CONFIG_BIAS_PULL_DOWN)
> > - val = (val & BIAS_PD_BIT ? true : false);
> > + val = (val & info->pincfg_data->pd_bit ? true : false);
> > else /* PIN_CONFIG_BIAS_PULL_UP */
> > - val = (val & BIAS_PU_BIT ? true : false);
> > + val = (val & info->pincfg_data->pu_bit ? true : false);
> > break;
>
> > + val = (val & info->pincfg_data->schmitt_bit ? true : false);
>
>
> !!(val & ...) will be a much shorter equivalent to ternary.
>
> > break;
>
> ...
>
> > +static struct ocelot_match_data ocelot_desc = {
> > + .desc = {
> > + .name = "ocelot-pinctrl",
> > + .pins = ocelot_pins,
> > + .npins = ARRAY_SIZE(ocelot_pins),
> > + .pctlops = &ocelot_pctl_ops,
> > + .pmxops = &ocelot_pmx_ops,
> > + .owner = THIS_MODULE,
> > + }
>
> Please, keep a comma here. It's definitely not a terminating entry, so
> it might help in the future.
>
> Ditto for all cases like this.
>
> > };
>
> ...
>
> > + struct ocelot_match_data *data;
>
> Any specific reason why this is not const?
>
> ...
>
> > + data = (struct ocelot_match_data *)device_get_match_data(dev);
>
> And here you drop the qualifier...
>
> I would recommend making it const and dropping the cast completely.
If I make this const, but then few lines after I will get the following
warnings:
drivers/pinctrl/pinctrl-ocelot.c:1983:13: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1983 | info->desc = &data->desc;
| ^
drivers/pinctrl/pinctrl-ocelot.c:1984:20: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1984 | info->pincfg_data = &data->pincfg_data;
| ^
Of course I can make also info->desc and info->pincfg_data const but
then I will get the following warning:
drivers/pinctrl/pinctrl-ocelot.c: In function ‘ocelot_pinctrl_register’:
drivers/pinctrl/pinctrl-ocelot.c:1723:53: warning: passing argument 2 of ‘devm_pinctrl_register’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1723 | info->pctl = devm_pinctrl_register(&pdev->dev, info->desc, info);
| ~~~~^~~~~~
In file included from include/linux/gpio/driver.h:10,
from drivers/pinctrl/pinctrl-ocelot.c:10:
include/linux/pinctrl/pinctrl.h:166:26: note: expected ‘struct pinctrl_desc *’ but argument is of type ‘const struct pinctrl_desc *’
166 | struct pinctrl_desc *pctldesc,
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
>
> > + if (!data)
> > + return -EINVAL;
>
> --
> With Best Regards,
> Andy Shevchenko
--
/Horatiu
next prev parent reply other threads:[~2022-07-11 6:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-08 19:55 [PATCH v2 0/2] pinctrl: ocelot: Add fixes for ocelot driver Horatiu Vultur
2022-07-08 19:55 ` [PATCH v2 1/2] pinctrl: ocelot: Fix pincfg for lan966x Horatiu Vultur
2022-07-08 21:58 ` Andy Shevchenko
2022-07-11 6:49 ` Horatiu Vultur [this message]
2022-07-11 8:31 ` Andy Shevchenko
2022-07-08 19:55 ` [PATCH v2 2/2] pinctrl: ocelot: Fix pincfg Horatiu Vultur
2022-07-08 20:16 ` Colin Foster
2022-07-08 22:02 ` Andy Shevchenko
2022-07-11 6:55 ` Horatiu Vultur
2022-07-11 8:35 ` Andy Shevchenko
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=20220711064950.3fqhuat3b23uabkj@soft-dev3-1.localhost \
--to=horatiu.vultur@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andy.shevchenko@gmail.com \
--cc=colin.foster@in-advantage.com \
--cc=kavyasree.kotagiri@microchip.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=michael@walle.cc \
/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