All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sander Vanheule <sander@svanheule.net>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Rob Herring <robh+dt@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Marc Zyngier <maz@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Bert Vermeulen <bert@biot.com>
Subject: Re: [PATCH v2 2/2] gpio: Add Realtek Otto GPIO support
Date: Fri, 19 Mar 2021 16:51:31 +0100	[thread overview]
Message-ID: <a7d410216d35ed2b3015bfdd8e21dafd9c42d9d4.camel@svanheule.net> (raw)
In-Reply-To: <CAHp75Vc6aaDhVN7LzvLNQjuOPguz+nbfmfpZ7TZHK=fNjCRz8w@mail.gmail.com>

Hi Andy,

Thanks for the review. I'll address the style comments in a v3. Some
further comments and discussion below.


On Wed, 2021-03-17 at 15:08 +0200, Andy Shevchenko wrote:
> On Mon, Mar 15, 2021 at 11:11 PM Sander Vanheule < 
> sander@svanheule.net> wrote:
> > +       depends on OF_GPIO
> 
> Don't see how it's used.

It isn't, so I'll remove it.


> > +#include <linux/of_irq.h>
> 
> Why?
> Perhaps what you need is property.h and mod_devicetable.h. See below.

With you suggestions, I was able to drop most explicit OF references.
Only of_device_id remains, for which I'll include mod_devicetable.h.


> > +#include <linux/swab.h>
> 
> Not sure why you need this? See below.

[snip]

> 
> > +
> > +static inline u32 realtek_gpio_isr_read(struct realtek_gpio_ctrl
> > *ctrl)
> > +{
> > +       return swab32(readl(ctrl->base + REALTEK_GPIO_REG_ISR));
> 
> Why swab?! How is this supposed to work on BE CPUs?
> Ditto for all swabXX() usage.

My use of swab32/swahw32 has little to do with the CPU being BE or LE,
but more with the register packing in the GPIO peripheral.

The supported SoCs have port layout A-B-C-D in the registers, where
firmware built with Realtek's SDK always denotes A0 as the first GPIO
line. So bit 24 in a register has the value for A0 (with the exception
of the IMR register).

I wrote these wrapper functions to be able to use the BIT() macro with
the GPIO line number, similar to how gpio-mmio uses ioread32be() when
the BGPIOF_BIG_ENDIAN_BYTE_ORDER flag is used.

For the IMR register, port A again comes first, but is now 16 bits wide
instead of 8, with A0 at bits 16:17. That's why swahw32 is used for
this register.

On the currently unsupported RTL9300-series, the port layout is
reversed: D-C-B-A. GPIO line A0 is then at bit 0, so the swapping
functions won't be required. When support for this alternate port
layout is added, some code will need to be added to differentiate
between the two cases.


> > +}
> > +
> > +static inline void realtek_gpio_isr_clear(struct realtek_gpio_ctrl
> > *ctrl,
> > +       unsigned int pin_mask)
> > +{
> > +       writel(swab32(pin_mask), ctrl->base +
> > REALTEK_GPIO_REG_ISR);
> > +}
> > +
> > +static inline void realtek_gpio_update_imr(struct
> > realtek_gpio_ctrl *ctrl,
> > +       unsigned int imr_offset, u32 type, u32 mask)
> > +{
> > +       unsigned int reg;
> > +
> > +       if (imr_offset == 0)
> > +               reg = REALTEK_GPIO_REG_IMR_AB;
> > +       else
> > +               reg = REALTEK_GPIO_REG_IMR_CD;
> > +       writel(swahw32(type & mask), ctrl->base + reg);
> > +}

[snip]

> > +       switch (flow_type & IRQ_TYPE_SENSE_MASK) {
> 
> > +       case IRQ_TYPE_NONE:
> > +               type = 0;
> > +               handler = handle_bad_irq;
> > +               break;
> 
> Why is it here? Make it default like many other GPIO drivers do.
> 
> > +       case IRQ_TYPE_EDGE_FALLING:
> > +               type = REALTEK_GPIO_IRQ_EDGE_FALLING;
> > +               handler = handle_edge_irq;
> > +               break;
> > +       case IRQ_TYPE_EDGE_RISING:
> > +               type = REALTEK_GPIO_IRQ_EDGE_RISING;
> > +               handler = handle_edge_irq;
> > +               break;
> > +       case IRQ_TYPE_EDGE_BOTH:
> > +               type = REALTEK_GPIO_IRQ_EDGE_BOTH;
> > +               handler = handle_edge_irq;
> > +               break;
> > +       default:
> > +               return -EINVAL;
> > +       }
> > +
> > +       irq_set_handler_locked(data, handler);
> 
> handler is always the same. Use it directly here.

I'll drop the IRQ_TYPE_NONE case. Do I understand it correctly, that
IRQ_TYPE_NONE should never be used as the new value, but only as the
default initial value?


Best,
Sander





  reply	other threads:[~2021-03-19 15:52 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15  8:23 [PATCH 0/2] Add Realtek Otto GPIO support Sander Vanheule
2021-03-15  8:23 ` [PATCH 1/2] dt-bindings: gpio: Binding for Realtek Otto GPIO Sander Vanheule
2021-03-15 15:01   ` Linus Walleij
2021-03-15  8:23 ` [PATCH 2/2] gpio: Add Realtek Otto GPIO support Sander Vanheule
2021-03-15 15:10   ` Linus Walleij
2021-03-15 19:09     ` Sander Vanheule
2021-03-15 19:08 ` [PATCH v2 0/2] " Sander Vanheule
2021-03-15 19:08   ` [PATCH v2 1/2] dt-bindings: gpio: Binding for Realtek Otto GPIO Sander Vanheule
2021-03-24 18:29     ` Rob Herring
2021-03-15 19:08   ` [PATCH v2 2/2] gpio: Add Realtek Otto GPIO support Sander Vanheule
2021-03-17 13:08     ` Andy Shevchenko
2021-03-19 15:51       ` Sander Vanheule [this message]
2021-03-19 17:57         ` Andy Shevchenko
2021-03-19 21:20           ` Sander Vanheule
2021-03-19 21:24             ` Andy Shevchenko
2021-03-19 21:48               ` Sander Vanheule
2021-03-22 13:16                 ` Andy Shevchenko
2021-03-24 21:22 ` [PATCH v3 0/2] " Sander Vanheule
2021-03-24 21:22   ` [PATCH v3 1/2] dt-bindings: gpio: Binding for Realtek Otto GPIO Sander Vanheule
2021-03-24 21:22   ` [PATCH v3 2/2] gpio: Add Realtek Otto GPIO support Sander Vanheule
2021-03-24 21:29     ` Sander Vanheule
2021-03-26 12:03 ` [PATCH v4 0/2] " Sander Vanheule
2021-03-26 12:03   ` [PATCH v4 1/2] dt-bindings: gpio: Binding for Realtek Otto GPIO Sander Vanheule
2021-03-27 18:16     ` Rob Herring
2021-03-26 12:03   ` [PATCH v4 2/2] gpio: Add Realtek Otto GPIO support Sander Vanheule
2021-03-26 18:19     ` Andy Shevchenko
2021-03-26 21:11       ` Sander Vanheule
2021-03-29 10:26         ` Andy Shevchenko
2021-03-29 17:28           ` Sander Vanheule
2021-03-30 10:14             ` Andy Shevchenko
2021-03-30 15:26 ` [PATCH v5 0/2] " Sander Vanheule
2021-03-30 15:26   ` [PATCH v5 1/2] dt-bindings: gpio: Binding for Realtek Otto GPIO Sander Vanheule
2021-03-30 15:26   ` [PATCH v5 2/2] gpio: Add Realtek Otto GPIO support Sander Vanheule
2021-03-30 16:43     ` Andy Shevchenko
2021-03-30 17:48 ` [PATCH v6 0/2] " Sander Vanheule
2021-03-30 17:48   ` [PATCH v6 1/2] dt-bindings: gpio: Binding for Realtek Otto GPIO Sander Vanheule
2021-03-30 17:48   ` [PATCH v6 2/2] gpio: Add Realtek Otto GPIO support Sander Vanheule
2021-03-31  7:49   ` [PATCH v6 0/2] " Bartosz Golaszewski
2021-03-31  8:11     ` Sander Vanheule

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=a7d410216d35ed2b3015bfdd8e21dafd9c42d9d4.camel@svanheule.net \
    --to=sander@svanheule.net \
    --cc=andy.shevchenko@gmail.com \
    --cc=bert@biot.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.