[PATCH] PINCTRL: SiRF: add CSR SiRFprimaII GPIO driver depending on pinmux APIs
Grant Likely
grant.likely at secretlab.ca
Fri May 25 20:33:20 EDT 2012
On Thu, 24 May 2012 16:48:25 +0200, Linus Walleij <linus.walleij at linaro.org> wrote:
> On Tue, May 22, 2012 at 9:14 AM, Barry Song <Barry.Song at csr.com> wrote:
>
> > From: Barry Song <Baohua.Song at csr.com>
> >
> > In SiRFprimaII, Each GPIO pin can be configured as input or output
> > independently. If a GPIO is configured as input, it can also be
> > enabled as an interrupt source (either edge or level triggered).
> >
> > These pins must be either MUXed as GPIO or other function pads. So
> > this drivers depend on pinctrl_request_gpio() API pinctrl-sirf.c
> > implements.
> >
> > Signed-off-by: Yuping Luo <yuping.luo at csr.com>
> > Signed-off-by: Barry Song <Baohua.Song at csr.com>
>
> This is actually such a nice and clean cut that it can be put into
> drivers/gpio, it's just using pinctrl, not sharing code or hardware
> registers with it. (If I understand correctly.)
>
> Let's check with Grant how he wants these things.
If it is a gpio controller, then it really should be in drivers/gpio.
If it is a memory mapped gpio controller, then it really should use
gpio-generic.c
>
> > +#define SIRFSOC_GPIO_IRQ_START Â Â (SIRFSOC_INTENAL_IRQ_END + 1)
>
> This is spelled wrong (inteRnal) but where is that #define coming from
> anyway? And is this really used? I think this line can be simply deleted.
>
> > +static inline struct sirfsoc_gpio_bank *sirfsoc_irq_to_bank(unsigned int irq)
> > +{
> > + Â Â Â return &sgpio_bank[(irq - SIRFSOC_GPIO_IRQ_START) / SIRFSOC_GPIO_BANK_SIZE];
> > +}
> > +
> > +static inline int sirfsoc_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
> > +{
> > + Â Â Â return SIRFSOC_GPIO_IRQ_START + (chip->base + offset);
> > +}
>
> Ick! Can you please use irqdomain for this?
Yes.
> > +static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type)
> > +{
> > + Â Â Â struct sirfsoc_gpio_bank *bank = sirfsoc_irq_to_bank(d->irq);
> > + Â Â Â int idx = sirfsoc_irq_to_offset(d->irq);
> > + Â Â Â u32 status, offset;
>
> "status" is a real bad name for this variable since you're not
> checking or changing any status by it. Use "val" or something.
>
> > + Â Â Â unsigned long flags;
> > +
> > + Â Â Â offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
> > +
> > + Â Â Â spin_lock_irqsave(&sgpio_lock, flags);
> > +
> > + Â Â Â status = readl(bank->chip.regs + offset);
> > + Â Â Â status &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK;
> > +
> > + Â Â Â switch (type) {
> > + Â Â Â case IRQ_TYPE_NONE:
> > + Â Â Â Â Â Â Â break;
> > + Â Â Â case IRQ_TYPE_EDGE_RISING:
> > + Â Â Â Â Â Â Â status |= (SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
> > + Â Â Â Â Â Â Â status &= ~SIRFSOC_GPIO_CTL_INTR_LOW_MASK;
> > + Â Â Â Â Â Â Â break;
> > + Â Â Â case IRQ_TYPE_EDGE_FALLING:
> > + Â Â Â Â Â Â Â status &= ~SIRFSOC_GPIO_CTL_INTR_HIGH_MASK;
> > + Â Â Â Â Â Â Â status |= (SIRFSOC_GPIO_CTL_INTR_LOW_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
> > + Â Â Â Â Â Â Â break;
> > + Â Â Â case IRQ_TYPE_EDGE_BOTH:
> > + Â Â Â Â Â Â Â status |=
> > + Â Â Â Â Â Â Â Â Â Â Â (SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_LOW_MASK |
> > + Â Â Â Â Â Â Â Â Â Â Â Â SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
> > + Â Â Â Â Â Â Â break;
> > + Â Â Â case IRQ_TYPE_LEVEL_LOW:
> > + Â Â Â Â Â Â Â status &= ~(SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
> > + Â Â Â Â Â Â Â status |= SIRFSOC_GPIO_CTL_INTR_LOW_MASK;
> > + Â Â Â Â Â Â Â break;
> > + Â Â Â case IRQ_TYPE_LEVEL_HIGH:
> > + Â Â Â Â Â Â Â status |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK;
> > + Â Â Â Â Â Â Â status &= ~(SIRFSOC_GPIO_CTL_INTR_LOW_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
> > + Â Â Â Â Â Â Â break;
> > + Â Â Â }
> > +
> > + Â Â Â writel(status, bank->chip.regs + offset);
> > +
> > + Â Â Â spin_unlock_irqrestore(&sgpio_lock, flags);
> > +
> > + Â Â Â return 0;
> > +}
> (...)
> > + Â Â Â Â Â Â Â /*
> > + Â Â Â Â Â Â Â Â * Here we must check whether the corresponding GPIO's interrupt
> > + Â Â Â Â Â Â Â Â * has been enabled, otherwise just skip it
> > + Â Â Â Â Â Â Â Â */
> > + Â Â Â Â Â Â Â if ((status & 0x1) && (ctrl & SIRFSOC_GPIO_CTL_INTR_EN_MASK)) {
> > + Â Â Â Â Â Â Â Â Â Â Â pr_debug("%s: gpio id %d idx %d happens\n",
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__, bank->id, idx);
> > + Â Â Â Â Â Â Â Â Â Â Â irq =
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (SIRFSOC_GPIO_IRQ_START +
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (bank->id * SIRFSOC_GPIO_BANK_SIZE)) + idx;
>
> So this is where irqdomain makes things simpler.
>
> > + Â Â Â Â Â Â Â Â Â Â Â generic_handle_irq(irq);
> > + Â Â Â Â Â Â Â }
> > +
> > + Â Â Â Â Â Â Â idx++;
> > + Â Â Â Â Â Â Â status = status >> 1;
> > + Â Â Â }
> > +}
>
> > +static inline void sirfsoc_gpio_set_output(struct sirfsoc_gpio_bank *bank, unsigned offset,
> > + Â Â Â int value)
> > +{
> > + Â Â Â u32 status;
>
> Again what does this has to do with any status...
>
> > +static void sirfsoc_gpio_set_value(struct gpio_chip *chip, unsigned offset,
> > + Â Â Â int value)
> > +{
> > + Â Â Â struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
> > + Â Â Â u32 status;
>
> Neither this.
>
> Apart from that it looks good.
>
> Yours,
> Linus Walleij
--
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.
More information about the linux-arm-kernel
mailing list