mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jaya Kumar" <jayakumar.lkml@gmail.com>
To: "Eric Miao" <eric.y.miao@gmail.com>
Cc: "David Brownell" <dbrownell@users.sourceforge.net>,
	"Eric Miao" <eric.miao@marvell.com>,
	"Paulius Zaleckas" <paulius.zaleckas@teltonika.lt>,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	"David Brownell" <david-b@pacbell.net>,
	"Sam Ravnborg" <sam@ravnborg.org>,
	"Haavard Skinnemoen" <hskinnemoen@atmel.com>,
	"Philipp Zabel" <philipp.zabel@gmail.com>,
	"Russell King" <rmk@arm.linux.org.uk>,
	"Ben Gardner" <bgardner@wabtec.com>, "Greg KH" <greg@kroah.com>,
	linux-arm-kernel@lists.arm.linux.org.uk,
	linux-fbdev-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC 2.6.27 1/1] gpiolib: add batch set/get
Date: Sun, 28 Dec 2008 23:12:04 -0500	[thread overview]
Message-ID: <45a44e480812282012m6ebcc648h9eaaa6a6973fd27c@mail.gmail.com> (raw)
In-Reply-To: <f17812d70812281938h1b8ad9ecq49a460ac7786ae76@mail.gmail.com>

On Sun, Dec 28, 2008 at 10:38 PM, Eric Miao <eric.y.miao@gmail.com> wrote:
> On Sun, Dec 28, 2008 at 12:24 AM, Jaya Kumar <jayakumar.lkml@gmail.com> wrote:
>> +#ifdef CONFIG_GPIOLIB_BATCH
>> +       gpio_set_batch(DB0_GPIO_PIN, data, 0xFFFF, 16);
>> +#else
>>        for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
>>                gpio_set_value(DB0_GPIO_PIN + i, (data >> i) & 0x01);
>> +#endif
>
> Well, if AM300 selects GPIOLIB_BATCH, I don't think we need the
> gpio_set_value() stuffs, and get rid of this #ifdef completely.

Good point. Will do.

>> +       /* shift the bits into our register specific position */
>> +       values <<= offset;
>> +       bitmask <<= offset;
>> +
>> +       values &= bitmask;
>
> or a single 'values = (values & bitmask) << offset' ?

Yup, good point. Will do.

>
>> +       if (values)
>> +               __raw_writel(values, pxa->regbase + GPSR_OFFSET);
>> +
>> +       values = ~values;
>> +       values &= bitmask;
>
> ditto

Will do.

>
>> +       if (values)
>> +               __raw_writel(values, pxa->regbase + GPCR_OFFSET);
>> +}
>> +
>> +/*
>> + * Get output GPIO level in batches
>> + */
>> +static u32 pxa_gpio_get_batch(struct gpio_chip *chip, unsigned offset,
>> +                               u32 bitmask)
>> +{
>> +       u32 values;
>> +       struct pxa_gpio_chip *pxa;
>> +
>> +       /* we're guaranteed by the caller that offset + bitmask remains
>> +        * in this chip.
>> +        */
>> +       pxa = container_of(chip, struct pxa_gpio_chip, chip);
>> +
>> +       values = __raw_readl(pxa->regbase + GPLR_OFFSET);
>> +
>> +       /* shift the result back into original position */
>> +       values >>= offset;
>> +       /* no need to shift bitmask since we've already shifted values */
>> +       values &= bitmask;
>> +
>> +       return values;
>
> or a single 'return (values >> offset) & bitmask;' should be enough.

Agreed.

>
>> +}
>> +#endif
>> +
>> +#ifdef CONFIG_GPIOLIB_BATCH
>> +#define GPIO_CHIP(_n)                                                  \
>> +       [_n] = {                                                        \
>> +               .regbase = GPIO##_n##_BASE,                             \
>> +               .chip = {                                               \
>> +                       .label            = "gpio-" #_n,                \
>> +                       .direction_input  = pxa_gpio_direction_input,   \
>> +                       .direction_output = pxa_gpio_direction_output,  \
>> +                       .get              = pxa_gpio_get,               \
>> +                       .set              = pxa_gpio_set,               \
>> +                       .base             = (_n) * 32,                  \
>> +                       .ngpio            = 32,                         \
>> +                       .set_batch        = pxa_gpio_set_batch,         \
>> +                       .get_batch        = pxa_gpio_get_batch,         \
>
> This is a bit ugly, define pxa_gpio_set_batch to NULL #ifndef GPIOLIB_BATCH
> in the above code, and force .{set,get}_batch assignment anyway, this will
> look a bit better, the same way as PM. However, this requires a modification
> to gpio_chip to always allow these two pointers, which might be a concern.

I think I tried that but then encountered the problem that I can't put
ifdefs within the define GPIO_CHIP macro. Will try to find a different
way. How about if I do:
#ifdef GPIOLIB_BATCH
#define SET_BATCH_MACRO .set_batch = pxa_gpio_set_batch \
#else
#define SET_BATCH_MACRO
#endif

then leave SET_BATCH_MACRO in the GPIO_CHIP macro. I think that would work.

>> +               if (!chip->set_batch) {
>> +                       while (((gpio + i) < (chip->base + chip->ngpio))
>> +                               && bitwidth) {
>> +                               mask = 1 << i;
>> +                               value = values & mask;
>> +                               if (bitmask & mask)
>> +                                       chip->set(chip, gpio + i - chip->base,
>> +                                                       value);
>> +                               i++;
>> +                               bitwidth--;
>
> I recommend this being put into something like 'default_gpio_set_batch', and
> assign this to 'chip->set_batch' when the gpio chip is being registered and
> found 'chip->set_batch == NULL', so to keep this block consistent.
>
> Same comment to the 'get_batch' implementation below.

Ok, that should also make the code nicer, will do.

Thanks,
jaya

  reply	other threads:[~2008-12-29  4:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-27 16:24 Jaya Kumar
2008-12-29  3:38 ` Eric Miao
2008-12-29  4:12   ` Jaya Kumar [this message]
2008-12-29 20:33   ` David Brownell

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=45a44e480812282012m6ebcc648h9eaaa6a6973fd27c@mail.gmail.com \
    --to=jayakumar.lkml@gmail.com \
    --cc=bgardner@wabtec.com \
    --cc=david-b@pacbell.net \
    --cc=dbrownell@users.sourceforge.net \
    --cc=eric.miao@marvell.com \
    --cc=eric.y.miao@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=greg@kroah.com \
    --cc=hskinnemoen@atmel.com \
    --cc=linux-arm-kernel@lists.arm.linux.org.uk \
    --cc=linux-fbdev-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulius.zaleckas@teltonika.lt \
    --cc=philipp.zabel@gmail.com \
    --cc=rmk@arm.linux.org.uk \
    --cc=sam@ravnborg.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

Powered by JetHome