From: Sander Vanheule <sander@svanheule.net>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: devicetree <devicetree@vger.kernel.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Bert Vermeulen <bert@biot.com>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Linus Walleij <linus.walleij@linaro.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Marc Zyngier <maz@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH v4 2/2] gpio: Add Realtek Otto GPIO support
Date: Fri, 26 Mar 2021 22:11:36 +0100 [thread overview]
Message-ID: <f5059092c1d4f3a23683a2eebfa37cb739881a8a.camel@svanheule.net> (raw)
In-Reply-To: <CAHp75Vdi06dLxJNCo4f1CA=cS1MuPwG0nEAnVqt8BRrz9bnOtw@mail.gmail.com>
Hi Andy,
Replies inline below.
On Fri, 2021-03-26 at 20:19 +0200, Andy Shevchenko wrote:
> On Fri, Mar 26, 2021 at 2:05 PM Sander Vanheule <sander@svanheule.net>
> wrote:
>
> > +config GPIO_REALTEK_OTTO
> > + bool "Realtek Otto GPIO support"
>
> Why not module?
This driver is only useful on a few specific MIPS SoCs, where this GPIO
peripheral is a part of that SoC. What would be the point of providing
this driver as a module?
>
> > + depends on MACH_REALTEK_RTL
> > + default MACH_REALTEK_RTL
> > + select GPIO_GENERIC
> > + select GPIOLIB_IRQCHIP
>
> > + help
> > + The GPIO controller on the Otto MIPS platform supports up
> > to two
> > + banks of 32 GPIOs, with edge triggered interrupts. The 32
> > GPIOs
> > + are grouped in four 8-bit wide ports.
>
> When allowing module build, here you may add what will be the name of
> it.
>
> ...
>
> > +/*
> > + * Total register block size is 0x1C for four ports.
> > + * On the RTL8380/RLT8390 platforms port A, B, and C are
> > implemented.
>
> D?
No port D on 8380/8390. Only 24 GPIO lines are present on these
platforms. I'll rephrase this comment.
>
> > + * RTL8389 and RTL8328 implement a second bank with ports E, F, G,
> > and H.
> > + *
> > + * Port information is stored with the first port at offset 0,
> > followed by the
> > + * second, etc. Most registers store one bit per GPIO and should be
> > read out in
> > + * reversed endian order. The two interrupt mask registers store two
> > bits per
> > + * GPIO, and should be manipulated with swahw32, if required.
> > + */
This reference to swahw32 and the include of linux/swab.h will be
dropped.
>
> > +/*
>
> Seems like kernel doc format with missed ** header and properly formed
> summary and description.
I'll reformat.
>
> > + * Realtek GPIO driver data
> > + * Because the interrupt mask register (IMR) combines the function
> > of
> > + * IRQ type selection and masking, two extra values are stored.
> > + * intr_mask is used to mask/unmask the interrupts for certain
> > GPIO,
> > + * and intr_type is used to store the selected interrupt types.
> > The
> > + * logical AND of these values is written to IMR on changes.
> > + *
> > + * @gc Associated gpio_chip instance
> > + * @base Base address of the register block
> > + * @lock Lock for accessing the IRQ registers and values
> > + * @intr_mask Mask for GPIO interrupts
> > + * @intr_type GPIO interrupt type selection
> > + */
> > +struct realtek_gpio_ctrl {
> > + struct gpio_chip gc;
> > + void __iomem *base;
> > + raw_spinlock_t lock;
> > + u16 intr_mask[REALTEK_GPIO_PORTS_PER_BANK];
> > + u16 intr_type[REALTEK_GPIO_PORTS_PER_BANK];
> > +};
> > +
> > +enum realtek_gpio_flags {
> > + GPIO_INTERRUPTS = BIT(0),
> > +};
>
> ...
See below. I'll add a comment.
>
> > +static struct realtek_gpio_ctrl *irq_data_to_ctrl(struct irq_data
> > *data)
> > +{
> > + struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
> > +
> > + return container_of(gc, struct realtek_gpio_ctrl, gc);
> > +}
>
> > +static unsigned int line_to_port(unsigned int line)
> > +{
> > + return line / 8;
> > +}
> > +
> > +static unsigned int line_to_port_pin(unsigned int line)
> > +{
> > + return line % 8;
> > +}
>
> These are useless. Just use them inline.
I added these as the alternative of the /16 and %16 I had for the IMR
offsets in v2. The function names tell the reader _why_ I'm doing the
division and modulo operations, but I guess a properly named variable
would do the same.
>
> > +static u8 read_u8_reg(void __iomem *reg, unsigned int port)
> > +{
> > + return ioread8(reg + port);
> > +}
> > +
> > +static void write_u8_reg(void __iomem *reg, unsigned int port, u8
> > value)
> > +{
> > + iowrite8(value, reg + port);
> > +}
> > +
> > +static void write_u16_reg(void __iomem *reg, unsigned int port, u16
> > value)
> > +{
> > + iowrite16(value, reg + 2 * port);
> > +}
>
> What's the point? You better provide a controller structure as a
> parameter. Look into other drivers. There are plenty of examples how
> to provide IO accessors in smarter way.
Since these are currently only really used for IMR and ISR, I'll fold
them into their accessor functions for v5.
>
> > +static void realtek_gpio_write_imr(struct realtek_gpio_ctrl *ctrl,
> > + unsigned int port, u16 irq_type, u16 irq_mask)
> > +{
> > + write_u16_reg(ctrl->base + REALTEK_GPIO_REG_IMR, port,
> > + irq_type & irq_mask);
>
> Can be one line.
>
> > +}
>
> ...
>
> > +static int realtek_gpio_irq_set_type(struct irq_data *data,
> > + unsigned int flow_type)
>
> One line?
I thought checkpatch.pl would complain, but it doesn't. Folded onto one
line.
> > + chained_irq_enter(irq_chip, desc);
> > +
> > + for (lines_done = 0; lines_done < gc->ngpio; lines_done += 8)
> > {
> > + port = line_to_port(lines_done);
> > + status = read_u8_reg(reg_isr, port);
> > + port_pin_count = min(gc->ngpio - lines_done, 8U);
> > + for_each_set_bit(offset, &status, port_pin_count) {
> > + irq = irq_find_mapping(gc->irq.domain,
> > offset);
> > + generic_handle_irq(irq);
>
> > + write_u8_reg(reg_isr, port, BIT(offset));
>
> Shouldn't it be in the ->irq_ack() callback?
I think I added this line to deal with handle_bad_irq during
development. Like you say, handle_edge_irq() has it's specific ACK
logic, so this is probably even a bug. Will be removed.
>
> > + }
> > + }
>
> ...
>
> > +static const struct of_device_id realtek_gpio_of_match[] = {
> > + { .compatible = "realtek,otto-gpio" },
> > + {
> > + .compatible = "realtek,rtl8380-gpio",
> > + .data = (void *)GPIO_INTERRUPTS
>
> Not sure why this flag is needed right now. Drop it completely for
> good.
> > + },
> > + {
> > + .compatible = "realtek,rtl8390-gpio",
> > + .data = (void *)GPIO_INTERRUPTS
>
> Ditto
Linus Walleij asked this question too after v1:
https://lore.kernel.org/linux-gpio/e9f0651e5fb52b7d56361ceb30b41759b6f2ec13.camel@svanheule.net/
Note that the fall-back compatible doesn't have this flag set.
> .
>
> > + },
> > + {}
> > +};
>
> > +
>
> Extra blank line.
Add or drop? I see other drivers using no empty line between the
of_match table and the MODULE_DEVICE_TABLE macro.
>
> > +MODULE_DEVICE_TABLE(of, realtek_gpio_of_match);
>
>
> ...
>
> > + iowrite32(GENMASK(31, 0), ctrl->base +
> > REALTEK_GPIO_REG_ISR);
>
> This one perhaps needs a comment like "cleaning all IRQ states".
> Note, we have a proper callback for this, i.e. hw_init. Consider to use
> it.
Which "hw_init" are you referring too? I can't really find much, aside
from drivers implementing it themselves to differentiate between driver
and hardware set-up.
Since this is normally only called once, I can turn it into the more
readable:
for (port = 0; (port * 8) < ngpios; port++) {
realtek_gpio_write_imr(ctrl, port, 0, 0);
realtek_gpio_clear_isr(ctrl, port, GENMASK(7, 0));
}
>
> > +};
>
> > +
>
> Extra blank line.
I see the same use of one blank line in other drivers.
> > +builtin_platform_driver(realtek_gpio_driver);
>
> ...
>
> So, looking into the code, I think you may easily get rid of 30-50
> LOCs.
> So, expecting <= 300 LOCs in v5.
After trimming the file, sloccount puts me at 224, but the total line
count is still 310. :-)
Best,
Sander
next prev parent reply other threads:[~2021-03-26 21:12 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-15 8:23 [PATCH 0/2] " 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
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 [this message]
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=f5059092c1d4f3a23683a2eebfa37cb739881a8a.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®