[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1419419050.6157.11.camel@perches.com>
Date: Wed, 24 Dec 2014 03:04:10 -0800
From: Joe Perches <joe@...ches.com>
To: thloh@...era.com
Cc: Pawel Moll <pawel.moll@....com>,
Mark Rutland <mark.rutland@....com>,
Ian Campbell <ijc+devicetree@...lion.org.uk>,
Kumar Gala <galak@...eaurora.org>,
Linus Walleij <linus.walleij@...aro.org>,
Alexandre Courbot <gnurou@...il.com>,
Grant Likely <grant.likely@...aro.org>,
Andrew Morton <akpm@...ux-foundation.org>,
"David S. Miller" <davem@...emloft.net>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Mauro Carvalho Chehab <mchehab@....samsung.com>,
Antti Palosaari <crope@....fi>, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-gpio@...r.kernel.org,
Dinh Nguyen <dinguyen@...era.com>
Subject: Re: [PATCH v8 2/2] drivers/gpio: Altera soft IP GPIO driver
On Wed, 2014-12-24 at 00:22 -0800, thloh@...era.com wrote:
> Adds a new driver for Altera soft GPIO IP. The driver is able to
> do read/write and allows GPIO to be a interrupt controller.
Some trivial comments, some not quite so trivial.
> diff --git a/drivers/gpio/gpio-altera.c b/drivers/gpio/gpio-altera.c
[]
> +static int altera_gpio_irq_set_type(struct irq_data *d,
> + unsigned int type)
> +{
> + struct altera_gpio_chip *altera_gc = irq_data_get_irq_chip_data(d);
> +
> + altera_gc = irq_data_get_irq_chip_data(d);
I presume this multiple initialization of altera_gc
is unnecessary duplication.
> +static void altera_gpio_irq_edge_handler(unsigned int irq,
> + struct irq_desc *desc)
> +{
> + struct altera_gpio_chip *altera_gc;
> + struct irq_chip *chip;
> + struct of_mm_gpio_chip *mm_gc;
> + unsigned long status;
> + int i;
> +
> + altera_gc = irq_desc_get_handler_data(desc);
> + chip = irq_desc_get_chip(desc);
> + mm_gc = &altera_gc->mmchip;
> +
> + chained_irq_enter(chip, desc);
> +
> + while ((status =
> + (readl(mm_gc->regs + ALTERA_GPIO_EDGE_CAP) &
> + readl(mm_gc->regs + ALTERA_GPIO_IRQ_MASK)))) {
> + writel(status, mm_gc->regs + ALTERA_GPIO_EDGE_CAP);
> + for_each_set_bit(i, &status, mm_gc->gc.ngpio) {
> + generic_handle_irq(
> + irq_find_mapping(altera_gc->mmchip.gc.irqdomain
> + , i));
That's kind of unpleasant to read.
It might be better to use a separate these statements
and use a temporary for irq_find_mapping()
> +static void altera_gpio_irq_leveL_high_handler(unsigned int irq,
> + struct irq_desc *desc)
> +{
> + struct altera_gpio_chip *altera_gc;
> + struct irq_chip *chip;
> + struct of_mm_gpio_chip *mm_gc;
> + unsigned long status;
> + int i;
> +
> + altera_gc = irq_desc_get_handler_data(desc);
> + chip = irq_desc_get_chip(desc);
> + mm_gc = &altera_gc->mmchip;
> +
> + chained_irq_enter(chip, desc);
> +
> + status = readl(mm_gc->regs + ALTERA_GPIO_DATA);
> + status &= readl(mm_gc->regs + ALTERA_GPIO_IRQ_MASK);
> +
> + for_each_set_bit(i, &status, mm_gc->gc.ngpio) {
> + generic_handle_irq(
> + irq_find_mapping(altera_gc->mmchip.gc.irqdomain, i));
Maybe a temporary here too
> +int altera_gpio_probe(struct platform_device *pdev)
> +{
> + struct device_node *node = pdev->dev.of_node;
> + int id, reg, ret;
> + struct altera_gpio_chip *altera_gc;
> +
> + altera_gc = devm_kzalloc(&pdev->dev, sizeof(*altera_gc), GFP_KERNEL);
> +
> + if (altera_gc == NULL)
> + return -ENOMEM;
No blank line after the devm_kzalloc please and
if (!altera_gc)
is more common.
> + if (altera_gc->interrupt_trigger == IRQ_TYPE_LEVEL_HIGH) {
> + gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc,
> + &altera_irq_chip,
> + altera_gc->mapped_irq,
> + altera_gpio_irq_leveL_high_handler);
> + } else {
> + gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc,
> + &altera_irq_chip,
> + altera_gc->mapped_irq,
> + altera_gpio_irq_edge_handler);
> + }
Sometimes using a ?: ternary is smaller code
gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc,
&altera_irq_chip,
altera_gc->mapped_irq,
altera_gc->interrupt_trigger == IRQ_TYPE_LEVEL_HIGH ?
altera_gpio_irq_leveL_high_handler :
altera_gpio_irq_edge_handler);
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists