All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Brunner <mibru@gmx.de>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Kevin Strasser <kevin.strasser@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Michael Brunner <michael.brunner@kontron.com>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Wolfram Sang <wsa@the-dreams.de>, Ben Dooks <ben-linux@fluff.org>,
	"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
	Grant Likely <grant.likely@secretlab.ca>,
	Wim Van Sebroeck <wim@iguana.be>,
	linux-watchdog@vger.kernel.org,
	Darren Hart <dvhart@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 3/4] gpio: Kontron PLD gpio driver
Date: Fri, 12 Apr 2013 13:09:35 +0200	[thread overview]
Message-ID: <20130412130936.3f428cc9@hyperion> (raw)
In-Reply-To: <CACRpkdaU-QT-VBiG8i5XreEP-DvTosHeptUo+5vdmSyi0=uWTw@mail.gmail.com>

Hi Linus,

As this code is from me I will comment on your review.

On Wed, 10 Apr 2013 22:45:51 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:
(...)
> Trying to do some real review...
> 
> (...)  
> > +++ b/drivers/gpio/gpio-kempld.c
> > +#include <linux/acpi.h>  
> 
> Is this used?  

Actually not, this can be removed.

> > +#include <linux/platform_device.h>
> > +#include <linux/gpio.h>
> > +#include <linux/mfd/kempld.h>
> > +#include <linux/seq_file.h>
> > +
> > +#include "gpio-kempld.h"
> > +
> > +static int gpiobase = -1;
> > +static int gpioien = 0x00;
> > +static int gpioevt_lvl_edge = -1;
> > +static int gpioevt_low_high = -1;
> > +static int gpionmien = 0x00;  
> 
> (...)
> 
> +static int kempld_gpio_to_irq(struct gpio_chip *chip, unsigned
> offset) +{
> +       struct kempld_gpio_data *gpio
> +               = container_of(chip, struct kempld_gpio_data, chip);
> +       return gpio->irq;
> +}
> 
> I don't understand this *at all* so help me out here.
> 
> .gpio_to_irq() should return a *Linux* IRQ number, usually we take
> the event offset (in this case) and map to a Linux IRQ using the
> irqdomain helper library. Can you explain how we can be sure that
> this number (apparently just a read from a register on the device)
> can be made to correspond to a Linux IRQ?
> 
> Also if this thing can generate IRQs, are these one line to the CPU
> per IRQ really? Don't you need to demux the status register and
> create a cascades irqchip?
> 
> Maybe it's just me not understanding x86 & ACPI so bear with me...  

The chip is connected to the CPU through a serial IRQ line and IRQs
are managed through the (A)PIC which is configured by the
firmware. I never saw a difference between Linux and HW IRQ numbers
for the legacy IRQs (0-15) this chip generates. But I will take
another look at the IRQ handling of this driver.

> > +static int kempld_gpio_setup_event(struct kempld_gpio_data *gpio)
> > +{
> > +       struct kempld_device_data *pld = gpio->pld;
> > +       struct gpio_chip *chip = &gpio->chip;
> > +       int irq;
> > +
> > +       irq = gpio->irq;
> > +
> > +       kempld_get_mutex_set_index(pld, KEMPLD_IRQ_GPIO);
> > +       irq = kempld_read8(pld, KEMPLD_IRQ_GPIO);
> > +
> > +       /* Leave if interrupts are not supported by the GPIO core */
> > +       if ((irq & 0xf0) == 0xf0)
> > +               return 0;
> > +
> > +       gpio->irq = irq & 0x0f;  
> 
> So you read the IRQ from some plug-n-play here, and it's some
> system-wide IRQ number?  

Correct.

> (...)  
> > +       if (gpio->irq)
> > +               chip->to_irq =          kempld_gpio_to_irq;  
> 
> So that is this mystery with the IRQs and how they turn into
> Linux IRQs.
>   
> > +module_param(gpiobase, int, 0444);  
> 
> Why do you need to be able to configure this?
> It must be a real usecase, debugging can be done by patching
> the code.  

This was intended to help developing userspace applications or scripts.
For this parameter I had in mind that one configures a static
GPIO base and then maps the GPIOs with the help of the sysfs interface
without the need to first find out which is the actual GPIO base. If you think this shouldn't be done this way I won't insist
to keep this parameter.

> > +module_param(gpioien, int, 0444);
> > +module_param(gpioevt_lvl_edge, int, 0444);
> > +module_param(gpioevt_low_high, int, 0444);
> > +module_param(gpionmien, int, 0444);  
> 
> Argh how can anyone possibly make this out ... do you really
> need them or can we get rid of some and rely on autodetect?  

As the chip sits on a computer module that is usually only configured
generically, it is not possible to auto detect the needed configuration.
Those parameters are intended to let the developer configure the chip
without having to touch the driver code.
You are right anyway, doing it this way might not be the best way. So if
there is a good way to configure this stuff at runtime by using a
generic interface I would also prefer this.

> > +MODULE_DESCRIPTION("KEM PLD GPIO Driver");
> > +MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>");
> > +MODULE_LICENSE("GPL");
> > +MODULE_ALIAS("platform:kempld_gpio");
> > +MODULE_PARM_DESC(gpiobase, "Set GPIO base (default -1=dynamic)");
> > +MODULE_PARM_DESC(gpioien, "Set GPIO IEN register (default 0x00)");
> > +MODULE_PARM_DESC(gpioevt_lvl_edge,
> > +                       "Set GPIO EVT_LVL_EDGE register (default
> > -1=no change)"); +MODULE_PARM_DESC(gpioevt_low_high,
> > +                       "Set GPIO EVT_LOW_HIGH register (default
> > -1=no change)"); +MODULE_PARM_DESC(gpionmien, "Set GPIO NMIEN
> > register (default 0x00)");  
> 
> 
> So I don't really like that interrupt enablement and edge and low/high
> is done with module parameters instead of just creating an irqchip and
> have it implement the operations to do exactly these things at runtime
> instead.
> 
> Again maybe some x86 thing I don't get...  

Possibly not. I am not very familiar with irqchip so far, therefore I
will have a look at it and check if the whole IRQ handling can be
ported to this framework.

> > diff --git a/drivers/gpio/gpio-kempld.h
> > b/drivers/gpio/gpio-kempld.h  
> (...)  
> > +struct kempld_gpio_data {
> > +       struct gpio_chip                chip;
> > +       int                             irq;
> > +       struct kempld_device_data       *pld;
> > +       uint16_t                        mask;  
> 
> Just u16?  

The specification allows 16 GPIOs for this device, therefore this seems
to be the right size. Would it be better to use another type instead?

> > +};  
> 
> (...)  
> > diff --git a/drivers/gpio/gpio-kempld_now1.c
> > b/drivers/gpio/gpio-kempld_now1.c +#include <linux/io.h>  
> 
> Do you use this?  

This can be removed.

> > +#include <linux/slab.h>
> > +#include <linux/errno.h>
> > +#include <linux/acpi.h>  
> 
> And this?  

linux/slab.h is necessary for kzalloc, but the rest can be removed.

> > +#include <linux/platform_device.h>
> > +#include <linux/gpio.h>
> > +#include <linux/mfd/kempld.h>
> > +#include <linux/seq_file.h>
> > +
> > +#include "gpio-kempld.h"  
> (...)  
> > +  
> 
> Most comments concern the other driver too.
> 
> Yours,
> Linus Walleij  

Thank you for the review!

Best regards,
  Michael

WARNING: multiple messages have this Message-ID (diff)
From: Michael Brunner <mibru-Mmb7MZpHnFY@public.gmane.org>
To: Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Kevin Strasser
	<kevin.strasser-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Michael Brunner
	<michael.brunner-2UyDCMiLNfhBDgjK7y7TUQ@public.gmane.org>,
	Samuel Ortiz <sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
	Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
	"linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Grant Likely
	<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>,
	Wim Van Sebroeck <wim-IQzOog9fTRqzQB+pC5nmwQ@public.gmane.org>,
	linux-watchdog-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Darren Hart <dvhart-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Subject: Re: [PATCH 3/4] gpio: Kontron PLD gpio driver
Date: Fri, 12 Apr 2013 13:09:35 +0200	[thread overview]
Message-ID: <20130412130936.3f428cc9@hyperion> (raw)
In-Reply-To: <CACRpkdaU-QT-VBiG8i5XreEP-DvTosHeptUo+5vdmSyi0=uWTw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Hi Linus,

As this code is from me I will comment on your review.

On Wed, 10 Apr 2013 22:45:51 +0200
Linus Walleij <linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> wrote:
(...)
> Trying to do some real review...
> 
> (...)  
> > +++ b/drivers/gpio/gpio-kempld.c
> > +#include <linux/acpi.h>  
> 
> Is this used?  

Actually not, this can be removed.

> > +#include <linux/platform_device.h>
> > +#include <linux/gpio.h>
> > +#include <linux/mfd/kempld.h>
> > +#include <linux/seq_file.h>
> > +
> > +#include "gpio-kempld.h"
> > +
> > +static int gpiobase = -1;
> > +static int gpioien = 0x00;
> > +static int gpioevt_lvl_edge = -1;
> > +static int gpioevt_low_high = -1;
> > +static int gpionmien = 0x00;  
> 
> (...)
> 
> +static int kempld_gpio_to_irq(struct gpio_chip *chip, unsigned
> offset) +{
> +       struct kempld_gpio_data *gpio
> +               = container_of(chip, struct kempld_gpio_data, chip);
> +       return gpio->irq;
> +}
> 
> I don't understand this *at all* so help me out here.
> 
> .gpio_to_irq() should return a *Linux* IRQ number, usually we take
> the event offset (in this case) and map to a Linux IRQ using the
> irqdomain helper library. Can you explain how we can be sure that
> this number (apparently just a read from a register on the device)
> can be made to correspond to a Linux IRQ?
> 
> Also if this thing can generate IRQs, are these one line to the CPU
> per IRQ really? Don't you need to demux the status register and
> create a cascades irqchip?
> 
> Maybe it's just me not understanding x86 & ACPI so bear with me...  

The chip is connected to the CPU through a serial IRQ line and IRQs
are managed through the (A)PIC which is configured by the
firmware. I never saw a difference between Linux and HW IRQ numbers
for the legacy IRQs (0-15) this chip generates. But I will take
another look at the IRQ handling of this driver.

> > +static int kempld_gpio_setup_event(struct kempld_gpio_data *gpio)
> > +{
> > +       struct kempld_device_data *pld = gpio->pld;
> > +       struct gpio_chip *chip = &gpio->chip;
> > +       int irq;
> > +
> > +       irq = gpio->irq;
> > +
> > +       kempld_get_mutex_set_index(pld, KEMPLD_IRQ_GPIO);
> > +       irq = kempld_read8(pld, KEMPLD_IRQ_GPIO);
> > +
> > +       /* Leave if interrupts are not supported by the GPIO core */
> > +       if ((irq & 0xf0) == 0xf0)
> > +               return 0;
> > +
> > +       gpio->irq = irq & 0x0f;  
> 
> So you read the IRQ from some plug-n-play here, and it's some
> system-wide IRQ number?  

Correct.

> (...)  
> > +       if (gpio->irq)
> > +               chip->to_irq =          kempld_gpio_to_irq;  
> 
> So that is this mystery with the IRQs and how they turn into
> Linux IRQs.
>   
> > +module_param(gpiobase, int, 0444);  
> 
> Why do you need to be able to configure this?
> It must be a real usecase, debugging can be done by patching
> the code.  

This was intended to help developing userspace applications or scripts.
For this parameter I had in mind that one configures a static
GPIO base and then maps the GPIOs with the help of the sysfs interface
without the need to first find out which is the actual GPIO base. If you think this shouldn't be done this way I won't insist
to keep this parameter.

> > +module_param(gpioien, int, 0444);
> > +module_param(gpioevt_lvl_edge, int, 0444);
> > +module_param(gpioevt_low_high, int, 0444);
> > +module_param(gpionmien, int, 0444);  
> 
> Argh how can anyone possibly make this out ... do you really
> need them or can we get rid of some and rely on autodetect?  

As the chip sits on a computer module that is usually only configured
generically, it is not possible to auto detect the needed configuration.
Those parameters are intended to let the developer configure the chip
without having to touch the driver code.
You are right anyway, doing it this way might not be the best way. So if
there is a good way to configure this stuff at runtime by using a
generic interface I would also prefer this.

> > +MODULE_DESCRIPTION("KEM PLD GPIO Driver");
> > +MODULE_AUTHOR("Michael Brunner <michael.brunner-2UyDCMiLNfhBDgjK7y7TUQ@public.gmane.org>");
> > +MODULE_LICENSE("GPL");
> > +MODULE_ALIAS("platform:kempld_gpio");
> > +MODULE_PARM_DESC(gpiobase, "Set GPIO base (default -1=dynamic)");
> > +MODULE_PARM_DESC(gpioien, "Set GPIO IEN register (default 0x00)");
> > +MODULE_PARM_DESC(gpioevt_lvl_edge,
> > +                       "Set GPIO EVT_LVL_EDGE register (default
> > -1=no change)"); +MODULE_PARM_DESC(gpioevt_low_high,
> > +                       "Set GPIO EVT_LOW_HIGH register (default
> > -1=no change)"); +MODULE_PARM_DESC(gpionmien, "Set GPIO NMIEN
> > register (default 0x00)");  
> 
> 
> So I don't really like that interrupt enablement and edge and low/high
> is done with module parameters instead of just creating an irqchip and
> have it implement the operations to do exactly these things at runtime
> instead.
> 
> Again maybe some x86 thing I don't get...  

Possibly not. I am not very familiar with irqchip so far, therefore I
will have a look at it and check if the whole IRQ handling can be
ported to this framework.

> > diff --git a/drivers/gpio/gpio-kempld.h
> > b/drivers/gpio/gpio-kempld.h  
> (...)  
> > +struct kempld_gpio_data {
> > +       struct gpio_chip                chip;
> > +       int                             irq;
> > +       struct kempld_device_data       *pld;
> > +       uint16_t                        mask;  
> 
> Just u16?  

The specification allows 16 GPIOs for this device, therefore this seems
to be the right size. Would it be better to use another type instead?

> > +};  
> 
> (...)  
> > diff --git a/drivers/gpio/gpio-kempld_now1.c
> > b/drivers/gpio/gpio-kempld_now1.c +#include <linux/io.h>  
> 
> Do you use this?  

This can be removed.

> > +#include <linux/slab.h>
> > +#include <linux/errno.h>
> > +#include <linux/acpi.h>  
> 
> And this?  

linux/slab.h is necessary for kzalloc, but the rest can be removed.

> > +#include <linux/platform_device.h>
> > +#include <linux/gpio.h>
> > +#include <linux/mfd/kempld.h>
> > +#include <linux/seq_file.h>
> > +
> > +#include "gpio-kempld.h"  
> (...)  
> > +  
> 
> Most comments concern the other driver too.
> 
> Yours,
> Linus Walleij  

Thank you for the review!

Best regards,
  Michael

  reply	other threads:[~2013-04-12 11:08 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08 17:15 [PATCH 1/4] mfd: Kontron PLD mfd driver Kevin Strasser
2013-04-08 17:15 ` [PATCH 2/4] i2c: Kontron PLD i2c bus driver Kevin Strasser
2013-04-08 17:15   ` Kevin Strasser
2013-04-10 17:02   ` Guenter Roeck
2013-04-10 17:02     ` Guenter Roeck
2013-04-16  9:53     ` Wolfram Sang
2013-04-16  9:53       ` Wolfram Sang
2013-04-08 17:15 ` [PATCH 3/4] gpio: Kontron PLD gpio driver Kevin Strasser
2013-04-08 17:15   ` Kevin Strasser
2013-04-09  8:46   ` Linus Walleij
2013-04-09 16:41     ` Guenter Roeck
2013-04-09 16:41       ` Guenter Roeck
2013-04-10 20:06       ` Linus Walleij
2013-04-10 20:45   ` Linus Walleij
2013-04-12 11:09     ` Michael Brunner [this message]
2013-04-12 11:09       ` Michael Brunner
2013-04-12 22:05       ` Linus Walleij
2013-04-08 17:15 ` [PATCH 4/4] watchdog: Kontron PLD watchdog timer Kevin Strasser
2013-04-08 17:15   ` Kevin Strasser
2013-04-10 16:47   ` Guenter Roeck
2013-04-10 16:57     ` Kevin Strasser
2013-04-10 16:57       ` Kevin Strasser
2013-05-26 14:38       ` Wim Van Sebroeck
2013-04-13 20:38 ` [PATCH 1/4] mfd: Kontron PLD mfd driver Thomas Gleixner
2013-04-18  4:19   ` Guenter Roeck
2013-04-18  4:40     ` Joe Perches
2013-04-18  4:40       ` Joe Perches
2013-04-18 13:35       ` Guenter Roeck
2013-04-18 13:35         ` Guenter Roeck
2013-04-18 16:42         ` Joe Perches
2013-04-18 18:40           ` Guenter Roeck
2013-06-18 21:04 ` [PATCH v2 0/4] Kontron PLD drivers Kevin Strasser
2013-06-18 21:04   ` Kevin Strasser
2013-06-18 21:04   ` [PATCH v2 1/4] mfd: Kontron PLD mfd driver Kevin Strasser
2013-06-19  8:40     ` Linus Walleij
2013-06-19  9:11       ` Samuel Ortiz
2013-06-19  9:48         ` Mark Brown
2013-06-19  9:12     ` Thomas Gleixner
2013-06-19 18:03       ` Kevin Strasser
2013-06-19 20:35         ` Guenter Roeck
2013-06-18 21:04   ` [PATCH v2 2/4] i2c: Kontron PLD i2c bus driver Kevin Strasser
2013-06-18 21:04   ` [PATCH v2 3/4] gpio: Kontron PLD gpio driver Kevin Strasser
2013-06-19  8:36     ` Linus Walleij
2013-06-27 22:14       ` Kevin Strasser
2013-06-18 21:04   ` [PATCH v2 4/4] watchdog: Kontron PLD watchdog timer driver Kevin Strasser
2013-06-24  4:00 ` [PATCH v3 0/4] Kontron PLD drivers Kevin Strasser
2013-06-24  4:00   ` Kevin Strasser
2013-06-24  4:00   ` [PATCH v3 1/4] mfd: Kontron PLD mfd driver Kevin Strasser
2013-06-24  4:00   ` [PATCH v3 2/4] i2c: Kontron PLD i2c bus driver Kevin Strasser
2013-07-01  6:40     ` Wolfram Sang
2013-07-01  6:40       ` Wolfram Sang
2013-06-24  4:00   ` [PATCH v3 3/4] gpio: Kontron PLD gpio driver Kevin Strasser
2013-07-21 14:31     ` Linus Walleij
2013-06-24  4:00   ` [PATCH v3 4/4] watchdog: Kontron PLD watchdog timer driver Kevin Strasser
2013-06-27 18:23     ` Kevin Strasser
2013-06-27 21:47       ` Samuel Ortiz
2013-06-27 21:47         ` Samuel Ortiz
2013-06-27 22:05         ` Kevin Strasser
2013-06-27 22:05           ` Kevin Strasser
2013-06-24 12:06   ` [PATCH v3 0/4] Kontron PLD drivers Samuel Ortiz
2013-06-24 12:06     ` Samuel Ortiz
2013-06-24 16:09     ` Wolfram Sang
2013-06-24 16:09       ` Wolfram Sang
2013-06-27 20:34     ` Wim Van Sebroeck
2013-06-27 20:34       ` Wim Van Sebroeck
2013-06-27 21:48       ` Samuel Ortiz
2013-06-27 21:48         ` Samuel Ortiz

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=20130412130936.3f428cc9@hyperion \
    --to=mibru@gmx.de \
    --cc=ben-linux@fluff.org \
    --cc=dvhart@linux.intel.com \
    --cc=grant.likely@secretlab.ca \
    --cc=gregkh@linuxfoundation.org \
    --cc=kevin.strasser@linux.intel.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=michael.brunner@kontron.com \
    --cc=sameo@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=wim@iguana.be \
    --cc=wsa@the-dreams.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.