devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Yinbo Zhu <zhuyinbo@loongson.cn>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, Jianmin Lv <lvjianmin@loongson.cn>,
	wanghongliang@loongson.cn, loongson-kernel@lists.loongnix.cn
Subject: Re: [PATCH v4 2/2] gpio: loongson: add more gpio chip support
Date: Wed, 23 Aug 2023 14:29:25 +0200	[thread overview]
Message-ID: <CACRpkdZJVjwOCGYhmzaPLWbcX0rgrDD-d2OX=TnmYs0F56fGug@mail.gmail.com> (raw)
In-Reply-To: <20230823033427.23072-3-zhuyinbo@loongson.cn>

Hi Yinbo,

thanks for the new patch, it's starting to look really good!
The main point with offsets in the match data is very nice.

On Wed, Aug 23, 2023 at 5:34 AM Yinbo Zhu <zhuyinbo@loongson.cn> wrote:

> This patch was to add loongson 2k0500, 2k2000 and 3a5000 gpio chip
> driver support.
>
> Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
(...)


>  static int loongson_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
>  {
> +       unsigned int u;
>         struct platform_device *pdev = to_platform_device(chip->parent);
> +       struct loongson_gpio_chip *lgpio = to_loongson_gpio_chip(chip);
> +
> +       if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
> +               u = readl(lgpio->reg_base + lgpio->chip_data->inten_offset + offset / 32 * 4);
> +               u |= BIT(offset % 32);
> +               writel(u, lgpio->reg_base + lgpio->chip_data->inten_offset + offset / 32 * 4);

This offset / 32 * 4 is really hard to read.
What about

/* Get the register index from offset then multiply by bytes per register */
(offset / 32) * 4

>         lgpio->reg_base = reg_base;
> +       if (device_property_read_u32(dev, "ngpios", &ngpios) || !ngpios)
> +               return -EINVAL;
> +
> +       ret = DIV_ROUND_UP(ngpios, 8);
> +       switch (ret) {
> +       case 1 ... 2:
> +               io_width = ret;
> +               break;
> +       case 3 ... 4:
> +               io_width = 0x4;
> +               break;
> +       case 5 ... 8:
> +               io_width = 0x8;
> +               break;
> +       default:
> +               dev_err(dev, "unsupported io width\n");
> +               return -EINVAL;
> +       }

Is it really a good idea to infer the register width from ngpios?

What about just putting this into the struct loongson_gpio_chip_data
as well? Certainly it will be fixed for a certain device.

Yours,
Linus Walleij

  reply	other threads:[~2023-08-23 12:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23  3:34 [PATCH v4 0/2] gpio: loongson: add more gpio chip support Yinbo Zhu
2023-08-23  3:34 ` [PATCH v4 1/2] gpio: dt-bindings: add more loongson " Yinbo Zhu
2023-08-23 12:17   ` Linus Walleij
2023-08-23 15:08   ` Conor Dooley
2023-08-29 12:12     ` Yinbo Zhu
2023-08-23  3:34 ` [PATCH v4 2/2] gpio: loongson: add more " Yinbo Zhu
2023-08-23 12:29   ` Linus Walleij [this message]
2023-08-29 11:27     ` Yinbo Zhu

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='CACRpkdZJVjwOCGYhmzaPLWbcX0rgrDD-d2OX=TnmYs0F56fGug@mail.gmail.com' \
    --to=linus.walleij@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongson-kernel@lists.loongnix.cn \
    --cc=lvjianmin@loongson.cn \
    --cc=robh+dt@kernel.org \
    --cc=wanghongliang@loongson.cn \
    --cc=zhuyinbo@loongson.cn \
    /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).