linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* OMAP gpio handling
@ 2012-02-25 13:04 Russell King - ARM Linux
  2012-02-27  7:11 ` DebBarma, Tarun Kanti
  0 siblings, 1 reply; 4+ messages in thread
From: Russell King - ARM Linux @ 2012-02-25 13:04 UTC (permalink / raw)
  To: linux-omap

Can someone explain to me this:

#define GPIO_INDEX(bank, gpio) (gpio % bank->width)
#define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))

static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
{
        void __iomem *reg = bank->base + bank->regs->datain;

        return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
}

static int gpio_get(struct gpio_chip *chip, unsigned offset)
{
        struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
        void __iomem *reg = bank->base;
        int gpio = chip->base + offset;
        u32 mask = GPIO_BIT(bank, gpio);

        if (gpio_is_input(bank, mask))
                return _get_gpio_datain(bank, gpio);
        else
                return _get_gpio_dataout(bank, gpio);
}

Given that bank->width on OMAP is either 32 or 16, and GPIO numbers for
any GPIO chip are always aligned to 32 or 16, why does this code bother
adding the chips base gpio number and then modulo the width?

Surely this means if - for argument sake - you registered a GPIO chip
with 8 lines followed by one with 16 lines, GPIO0..7 would be chip 0
bit 0..7, GPIO8..15 would be chip 1 bit 8..15, GPIO16..23 would be
chip 1 bit 0..7.

However, if you registered a GPIO chip with 16 lines first, it would
mean GPIO0..15 would be chip 0 bit 0..15, and GPIO16..31 would be
chip 1 bit 0..15.

Surely this kind of behaviour is not intended?

Is there a reason why the bitmask can't just be (1 << offset) where
offset is passed into these functions as GPIO number - chip->base ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-29  3:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-25 13:04 OMAP gpio handling Russell King - ARM Linux
2012-02-27  7:11 ` DebBarma, Tarun Kanti
2012-02-28 20:29   ` Cousson, Benoit
2012-02-29  3:32     ` DebBarma, Tarun Kanti

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).