Re: [PATCH V3 2/2] gpio: add STA2X11 GPIO block

From: Linus Walleij
Date: Thu Apr 12 2012 - 11:05:41 EST


On Thu, Apr 12, 2012 at 10:48 AM, Alessandro Rubini <rubini@xxxxxxxxx> wrote:

> +/*
> + * Special method: alternate functions and pullup/pulldown. This is only
> + * invoked on startup to configure gpio's according to platform data.
> + * FIXME : this functionality shall be managed (and exported to other drivers)
> + * via the pin control subsystem.
> + */
> +static void gsta_set_config(struct gsta_gpio *chip, int nr, unsigned cfg)
> +{
> +       struct gsta_regs __iomem *regs = __regs(chip, nr);
> +       unsigned long flags;
> +       u32 bit = __bit(nr);
> +       u32 val;
> +       int err = 0;
> +
> +       pr_info("%s: %p %i %i\n", __func__, chip, nr, cfg);
> +
> +       if (cfg == PINMUX_TYPE_NONE)
> +               return;
> +
> +       /* Alternate function or not? */
> +       spin_lock_irqsave(&chip->lock, flags);
> +       val = readl(&regs->afsela);
> +       if (cfg == PINMUX_TYPE_FUNCTION)
> +               val |= bit;
> +       else
> +               val &= ~bit;
> +       writel(val | bit, &regs->afsela);
> +       if (cfg == PINMUX_TYPE_FUNCTION) {
> +               spin_unlock_irqrestore(&chip->lock, flags);
> +               return;
> +       }
> +
> +       /* not alternate function: set details */
> +       switch (cfg) {
> +       case PINMUX_TYPE_OUTPUT_LOW:
> +               writel(bit, &regs->dirs);
> +               writel(bit, &regs->datc);
> +               break;
> +       case PINMUX_TYPE_OUTPUT_HIGH:
> +               writel(bit, &regs->dirs);
> +               writel(bit, &regs->dats);
> +               break;
> +       case PINMUX_TYPE_INPUT:
> +               writel(bit, &regs->dirc);
> +               val = readl(&regs->pdis) | bit;
> +               writel(val, &regs->pdis);
> +               break;
> +       case PINMUX_TYPE_INPUT_PULLUP:
> +               writel(bit, &regs->dirc);
> +               val = readl(&regs->pdis) & ~bit;
> +               writel(val, &regs->pdis);
> +               writel(bit, &regs->dats);
> +               break;
> +       case PINMUX_TYPE_INPUT_PULLDOWN:
> +               writel(bit, &regs->dirc);
> +               val = readl(&regs->pdis) & ~bit;
> +               writel(val, &regs->pdis);
> +               writel(bit, &regs->datc);
> +               break;
> +       default:
> +               err = 1;
> +       }
> +       spin_unlock_irqrestore(&chip->lock, flags);
> +       if (err)
> +               pr_err("%s: chip %p, pin %i, cfg %i is invalid\n",
> +                      __func__, chip, nr, cfg);
> +}

I would still prefer to use the pinctrl subsystem for this from day 1 instead of
adding more custom stuff for later refactoring...

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/