linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 11/27] clocksource: sh_cmt: Add support for multiple channels per device
Date: Mon, 17 Feb 2014 09:58:06 +0000	[thread overview]
Message-ID: <3050110.8B4nKkQ5Sd@avalon> (raw)
In-Reply-To: <CANqRtoQ=QJ0YVjp+8y+H9OTk=iRf6Jdeg_J9PMyYa-9WbgfXyA@mail.gmail.com>

Hi Magnus,

On Monday 17 February 2014 11:07:06 Magnus Damm wrote:
> On Mon, Feb 17, 2014 at 10:48 AM, Laurent Pinchart wrote:
> > On Monday 17 February 2014 10:41:31 Magnus Damm wrote:
> >> On Mon, Feb 17, 2014 at 3:18 AM, Laurent Pinchart wrote:
> >> > On Saturday 15 February 2014 13:46:54 Thomas Gleixner wrote:
> >> >> On Fri, 14 Feb 2014, Laurent Pinchart wrote:
> >> >> > CMT hardware devices can support multiple channels, with global
> >> >> > registers and per-channel registers. The sh_cmt driver currently
> >> >> > models the hardware with one Linux device per channel. This model
> >> >> > makes it difficult to handle global registers in a clean way.
> >> >> > 
> >> >> > Add support for a new model that uses one Linux device per timer
> >> >> > with multiple channels per device. This requires changes to platform
> >> >> > data, add new channel configuration fields.
> >> >> > 
> >> >> > Support for the legacy model is kept and will be removed after all
> >> >> > platforms switch to the new model.
> >> >> > 
> >> >> > Signed-off-by: Laurent Pinchart
> >> >> > <laurent.pinchart+renesas@ideasonboard.com>
> >> >> > ---
> >> >> > 
> >> >> >  drivers/clocksource/sh_cmt.c | 299 ++++++++++++++++++++++++--------
> >> >> >  include/linux/sh_timer.h     |   9 ++
> >> >> >  2 files changed, 239 insertions(+), 69 deletions(-)
> >> >> > 
> >> >> > diff --git a/drivers/clocksource/sh_cmt.c
> >> >> > b/drivers/clocksource/sh_cmt.c
> >> >> > index 5280231..8390f0f 100644
> >> >> > --- a/drivers/clocksource/sh_cmt.c
> >> >> > +++ b/drivers/clocksource/sh_cmt.c
> > 
> > [snip]
> > 
> >> >> > @@ -85,11 +94,15 @@ struct sh_cmt_info {
> >> >> > 
> >> >> >  struct sh_cmt_channel {
> >> >> >     struct sh_cmt_device *cmt;
> >> >> > 
> >> >> > -   unsigned int index;
> >> >> > -   void __iomem *base;
> >> >> > +   unsigned int index;     /* Index in the documentation */
> >> >> > +   unsigned int hwidx;     /* Real hardware index */
> >> >> > +
> >> >> > +   void __iomem *iostart;
> >> >> > +   void __iomem *ioctrl;
> >> >> > 
> >> >> >     struct irqaction irqaction;
> >> >> 
> >> >> While you are at it, can you please get rid of that irqaction and use
> >> >> request_irq() ?
> >> > 
> >> > The driver claims it can't use request_irq() because the function is
> >> > not available for early platform devices. If the situation has changed
> >> > I'd gladly get rid of irqaction.
> >> 
> >> With the risk of stating the obvious, this depends on how early the
> >> early platform device stuff is being run. The actual location may not
> >> be the same on SH and ARM for instance.
> >> 
> >> On ARM we are doing all we can to initialize these devices as late as
> >> ever possible in the MULTIPLAFORM (DT reference) case. Once we manage
> >> to remove the legacy ARM case then there is one less user of early
> >> platform timers.
> >> 
> >> One perhaps reasonable way forward could be to use request_irq() in
> >> case of DT and leave the legacy platform data case to rely on
> >> irqaction.
> > 
> > The whole point of switching from setup_irq() to request_irq() is to
> > simplify the code. Adding request_irq() as an option would go in the
> > opposite direction.
> 
> The point of switching to setup_irq() was not very clear to me. I
> think it is fine to switch to using it over time, and I'm open to any
> alternative ways forward. Usually moving in incremental steps means
> more crap in the short term, but if someone could come up with a way
> that involves little crap then I'm all for that! =)

I've had a quick look at request_irq(). The function is defined as a static 
inline in include/linux/interrupt.h:

static inline int __must_check
request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
            const char *name, void *dev)
{
        return request_threaded_irq(irq, handler, NULL, flags, name, dev);
}

request_threaded_irq() is implemented in kernel/irq/manage.c. I've removed the 
code paths that would never be taken when called by the sh_cmt driver, due to

- handler not being NULL
- thread_fn being NULL
- CONFIG_DEBUG_SHIRQ_FIXME not being set
- IRQF_SHARED not being set

int request_threaded_irq(unsigned int irq, irq_handler_t handler,
                         irq_handler_t thread_fn, unsigned long irqflags,
                         const char *devname, void *dev_id)
{
        struct irqaction *action;
        struct irq_desc *desc;
        int retval;

        desc = irq_to_desc(irq);
        if (!desc)
                return -EINVAL;

        if (!irq_settings_can_request(desc) ||
            WARN_ON(irq_settings_is_per_cpu_devid(desc)))
                return -EINVAL;

        action = kzalloc(sizeof(struct irqaction), GFP_KERNEL);
        if (!action)
                return -ENOMEM;

        action->handler = handler;
        action->thread_fn = thread_fn;
        action->flags = irqflags;
        action->name = devname;
        action->dev_id = dev_id;

        chip_bus_lock(desc);
        retval = __setup_irq(irq, desc, action);
        chip_bus_sync_unlock(desc);

        if (retval)
                kfree(action);

        return retval;
}

setup_irq() is implemented in the same file as

int setup_irq(unsigned int irq, struct irqaction *act)
{
        int retval;
        struct irq_desc *desc = irq_to_desc(irq);

        if (WARN_ON(irq_settings_is_per_cpu_devid(desc)))
                return -EINVAL;
        chip_bus_lock(desc);
        retval = __setup_irq(irq, desc, act);
        chip_bus_sync_unlock(desc);

        return retval;
}

The only two differences between request_irq() and setup_irq() would thus be

- the extra !irq_settings_can_request(desc) check
- the extra kzalloc() call

The former should only be true for chained IRQ handlers, which isn't the case 
here. The latter is just a kmalloc + kmap_atomic + memset as far as I can 
tell.

It thus seems safe to replace setup_irq() with request_irq().

-- 
Regards,

Laurent Pinchart


  reply	other threads:[~2014-02-17  9:58 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14  0:59 [PATCH 00/27] Renesas CMT (Compare Match Timer) DT bindings Laurent Pinchart
2014-02-14  0:59 ` [PATCH 01/27] clocksource: sh_cmt: Split channel fields from sh_cmt_priv Laurent Pinchart
2014-02-14  0:59 ` [PATCH 02/27] clocksource: sh_cmt: Rename struct sh_cmt_priv to sh_cmt_device Laurent Pinchart
2014-02-14  0:59 ` [PATCH 03/27] clocksource: sh_cmt: Split channel setup to separate function Laurent Pinchart
2014-02-14  0:59 ` [PATCH 04/27] clocksource: sh_cmt: Rename mapbase/mapbase_str to mapbase_ch/mapbase Laurent Pinchart
2014-02-14  0:59 ` [PATCH 05/27] clocksource: sh_cmt: Add memory base to sh_cmt_channel structure Laurent Pinchart
2014-02-14  0:59 ` [PATCH 06/27] clocksource: sh_cmt: Add index to struct sh_cmt_channel Laurent Pinchart
2014-02-14  0:59 ` [PATCH 07/27] clocksource: sh_cmt: Replace kmalloc + memset with kzalloc Laurent Pinchart
2014-02-14  0:59 ` [PATCH 08/27] clocksource: sh_cmt: Allocate channels dynamically Laurent Pinchart
2014-02-14  0:59 ` [PATCH 09/27] clocksource: sh_cmt: Split static information from sh_cmt_device Laurent Pinchart
2014-02-14  0:59 ` [PATCH 10/27] clocksource: sh_cmt: Replace hardcoded register values with macros Laurent Pinchart
2014-02-14  0:59 ` [PATCH 11/27] clocksource: sh_cmt: Add support for multiple channels per device Laurent Pinchart
2014-02-15 12:46   ` Thomas Gleixner
2014-02-16 18:18     ` Laurent Pinchart
2014-02-17  1:41       ` Magnus Damm
2014-02-17  1:48         ` Laurent Pinchart
2014-02-17  2:07           ` Magnus Damm
2014-02-17  9:58             ` Laurent Pinchart [this message]
2014-02-14  0:59 ` [PATCH 12/27] clocksource: sh_cmt: Acquire default clock in the non-legacy case Laurent Pinchart
2014-02-14  0:59 ` [PATCH 13/27] clocksource: sh_cmt: Remove FSF mail address from GPL notice Laurent Pinchart
2014-02-14  0:59 ` [PATCH 14/27] clocksource: sh_cmt: Sort headers alphabetically Laurent Pinchart
2014-02-14  0:59 ` [PATCH 15/27] sh: Switch to new style CMT device Laurent Pinchart
2014-02-14  0:59 ` [PATCH 16/27] ARM: shmobile: sh7372: " Laurent Pinchart
2014-02-14  0:59 ` [PATCH 17/27] ARM: shmobile: sh73a0: " Laurent Pinchart
2014-02-14  0:59 ` [PATCH 18/27] ARM: shmobile: r8a73a4: " Laurent Pinchart
2014-02-14  0:59 ` [PATCH 19/27] ARM: shmobile: r8a7740: " Laurent Pinchart
2014-02-14  0:59 ` [PATCH 20/27] ARM: shmobile: r8a7790: " Laurent Pinchart
2014-02-14  0:59 ` [PATCH 21/27] ARM: shmobile: r8a7791: " Laurent Pinchart
2014-02-14  1:00 ` [PATCH 22/27] clocksource: sh_cmt: Drop support for legacy platform data Laurent Pinchart
2014-02-14  1:00 ` [PATCH 23/27] clocksource: sh_cmt: Add DT support Laurent Pinchart
2014-02-14  9:18   ` Geert Uytterhoeven
2014-02-14 14:35     ` Laurent Pinchart
2014-02-14 10:58   ` Mark Rutland
2014-02-14 15:53     ` Laurent Pinchart
2014-02-14 15:59       ` Josh Cartwright
2014-02-14 16:15         ` Laurent Pinchart
2014-02-14 16:01       ` Magnus Damm
2014-02-14 16:12         ` Laurent Pinchart
2014-02-14 17:22           ` Magnus Damm
2014-02-17  1:45             ` Laurent Pinchart
2014-02-17  1:48               ` Magnus Damm
2014-02-17 21:43                 ` Laurent Pinchart
2014-02-18  0:51                   ` Magnus Damm
2014-02-18 11:45                     ` Laurent Pinchart
2014-02-14  1:00 ` [PATCH 24/27] ARM: shmobile: r8a7790: Add CMT devices to DT Laurent Pinchart
2014-02-14  1:00 ` [PATCH 25/27] ARM: shmobile: r8a7791: " Laurent Pinchart
2014-02-14  1:00 ` [PATCH 26/27] ARM: shmobile: lager-reference: Enable CMT0 in device tree Laurent Pinchart
2014-02-14 13:45   ` Sergei Shtylyov
2014-02-14 13:48     ` Laurent Pinchart
2014-02-14 14:13       ` Sergei Shtylyov
2014-02-14 14:22         ` Laurent Pinchart
2014-02-14 14:36           ` Sergei Shtylyov
2014-02-14 16:26             ` Laurent Pinchart
2014-02-14 18:56               ` Sergei Shtylyov
2014-02-14  1:00 ` [PATCH 27/27] ARM: shmobile: koelsch-reference: " Laurent Pinchart
2014-02-14 13:47   ` Sergei Shtylyov

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=3050110.8B4nKkQ5Sd@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).