From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-sh@vger.kernel.org
Subject: Re: [PATCH/RFC 06/12] sh-pfc: Skip gpiochip registration when no GPIO resource is found
Date: Wed, 13 Mar 2013 20:51:03 +0000 [thread overview]
Message-ID: <1864724.bK3OTDP1CF@avalon> (raw)
In-Reply-To: <1362941928-18115-7-git-send-email-laurent.pinchart+renesas@ideasonboard.com>
Hi Linus,
On Wednesday 13 March 2013 18:37:03 Linus Walleij wrote:
> On Sun, Mar 10, 2013 at 7:58 PM, Laurent Pinchart wrote:
> > Boards/platforms that register dedicated GPIO devices will not supply a
> > memory resource for GPIOs. Try to locate the GPIO memory resource at
> > initialization time, and skip registration of the gpiochip if the
> > resource can't be found.
>
> Isn't this a bit misleading? By memory resource we usually understand
> something that will pass a struct resource connected to e.g. a
> platform_device,
Yes, that's exactly what this patch is about.
> whereas...
>
> (...)
>
> > @@ -328,6 +314,7 @@ sh_pfc_add_gpiochip(struct sh_pfc *pfc,
> > int(*setup)(struct sh_pfc_chip *))>
> > if (unlikely(!chip))
> > return ERR_PTR(-ENOMEM);
> >
> > + chip->mem = mem;
> > chip->pfc = pfc;
> >
> > ret = setup(chip);
> > @@ -357,8 +344,24 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
> > if (pfc->info->data_regs = NULL)
> > return 0;
> >
> > + /* Find the memory window that contain the GPIO registers. Boards that
> > + * register a separate GPIO device will not supply a memory resource
> > + * that covers the data registers. In that case don't try to handle
> > + * GPIOs.
> > + */
> > + for (i = 0; i < pfc->num_windows; ++i) {
> > + struct sh_pfc_window *window = &pfc->window[i];
> > +
> > + if (pfc->info->data_regs[0].reg >= window->phys &&
> > + pfc->info->data_regs[0].reg < window->phys +
> > window->size)
> > + break;
> > + }
>
> This "pfc" isn't quite a "resource". I would call that platform data or
> something.
>
> But maybe this could be refactored to actually be a number of
> IOMEM resources?
pfc->info->data_regs is a list of SoC-specific information about GPIO
registers. It contains, among other information, the register physical address
in the reg field. pfc->window is a list of ioremapped IOMEM resources.
The above code thus tries to locate the IOMEM resource that contains the first
GPIO data register. If no such resource is found then this patch assumes that
GPIO will be handled externally.
The main purpose of this code is to allow an atomic transition from GPIO
handling inside the PFC driver to GPIO handling by a separate driver without
requiring a patch to touch both arch/arm/mach-shmobile/ and
drivers/pinctrl/sh-pfc/. Such a transition only requires adding the GPIO
platform device and removing the GPIO IOMEM resource from the PFC device. A
later patch can then remove the pfc->info->data_regs completely from SoC data
in drivers/pinctrl/sh-pfc/pfc-*.c.
> > + if (i = pfc->num_windows)
> > + return 0;
>
> The ++i and this thing make the code pretty hard for me to grasp. But maybe
> I'm just dumb? Could you explain here what is happening, like with some
> small comment or so....
++i and i++ would be totally equivalent in the for loop above. I took the
habit of using the pre-increment style in for loops from my C++ programming
days (http://forums.codeguru.com/showthread.php?231052-C-Operator-Why-should-I-use-i-instead-of-i).
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2013-03-13 20:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-10 18:58 [PATCH/RFC 06/12] sh-pfc: Skip gpiochip registration when no GPIO resource is found Laurent Pinchart
2013-03-13 17:37 ` Linus Walleij
2013-03-13 20:51 ` Laurent Pinchart [this message]
2013-03-14 8:08 ` Linus Walleij
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=1864724.bK3OTDP1CF@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=linux-sh@vger.kernel.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 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.