From: grinberg@compulab•co.il (Igor Grinberg)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH v2 03/10] gpio: pxa: use platform data for gpio inverted
Date: Thu, 07 Feb 2013 17:17:04 +0200 [thread overview]
Message-ID: <5113C570.6060403@compulab.co.il> (raw)
In-Reply-To: <1359886551-20950-4-git-send-email-haojian.zhuang@linaro.org>
On 02/03/13 12:15, Haojian Zhuang wrote:
> Avoid to judge whether gpio is inverted by identifying cpu in gpio
> driver. Move this into platform data of gpio driver.
>
> Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro•org>
Tested-by: Igor Grinberg <grinberg@compulab•co.il>
> ---
> arch/arm/mach-pxa/pxa25x.c | 3 +++
> drivers/gpio/gpio-pxa.c | 40 +++++++++++++++++++++++++---------------
> include/linux/gpio-pxa.h | 1 +
> 3 files changed, 29 insertions(+), 15 deletions(-)
>
> diff --git a/arch/arm/mach-pxa/pxa25x.c b/arch/arm/mach-pxa/pxa25x.c
> index f4c293a..66dafb7 100644
> --- a/arch/arm/mach-pxa/pxa25x.c
> +++ b/arch/arm/mach-pxa/pxa25x.c
> @@ -340,6 +340,9 @@ void __init pxa25x_map_io(void)
> }
>
> static struct pxa_gpio_platform_data pxa25x_gpio_info __initdata = {
> +#ifdef CONFIG_CPU_PXA26x
> + .inverted = true,
> +#endif
> .gpio_set_wake = gpio_set_wake,
> };
>
> diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
> index 2310665..1f8dfc8 100644
> --- a/drivers/gpio/gpio-pxa.c
> +++ b/drivers/gpio/gpio-pxa.c
> @@ -71,6 +71,7 @@ struct pxa_gpio_chip {
> struct gpio_chip chip;
> void __iomem *regbase;
> unsigned int irq_base;
> + bool inverted;
> char label[10];
>
> unsigned long irq_mask;
> @@ -126,9 +127,9 @@ static inline int gpio_is_mmp_type(int type)
> /* GPIO86/87/88/89 on PXA26x have their direction bits in PXA_GPDR(2 inverted,
> * as well as their Alternate Function value being '1' for GPIO in GAFRx.
> */
> -static inline int __gpio_is_inverted(int gpio)
> +static inline int __gpio_is_inverted(struct pxa_gpio_chip *chip, int gpio)
> {
> - if ((gpio_type == PXA26X_GPIO) && (gpio > 85))
> + if ((chip->inverted) && (gpio > 85))
> return 1;
> return 0;
> }
> @@ -139,15 +140,13 @@ static inline int __gpio_is_inverted(int gpio)
> * is attributed as "occupied" here (I know this terminology isn't
> * accurate, you are welcome to propose a better one :-)
> */
> -static inline int __gpio_is_occupied(unsigned gpio)
> +static inline int __gpio_is_occupied(struct pxa_gpio_chip *chip, unsigned gpio)
> {
> - struct pxa_gpio_chip *pxachip;
> void __iomem *base;
> unsigned long gafr = 0, gpdr = 0;
> int ret, af = 0, dir = 0;
>
> - pxachip = gpio_to_pxachip(gpio);
> - base = gpio_chip_base(&pxachip->chip);
> + base = gpio_chip_base(&chip->chip);
> gpdr = readl_relaxed(base + GPDR_OFFSET);
>
> switch (gpio_type) {
> @@ -158,7 +157,7 @@ static inline int __gpio_is_occupied(unsigned gpio)
> af = (gafr >> ((gpio & 0xf) * 2)) & 0x3;
> dir = gpdr & GPIO_bit(gpio);
>
> - if (__gpio_is_inverted(gpio))
> + if (__gpio_is_inverted(chip, gpio))
> ret = (af != 1) || (dir == 0);
> else
> ret = (af != 0) || (dir != 0);
> @@ -188,16 +187,19 @@ int pxa_irq_to_gpio(struct irq_data *d)
> return gpio;
> }
>
> -static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
> +static int pxa_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
> {
> - void __iomem *base = gpio_chip_base(chip);
> + struct pxa_gpio_chip *chip = NULL;
> + void __iomem *base = gpio_chip_base(gc);
> uint32_t value, mask = 1 << offset;
> unsigned long flags;
>
> + chip = container_of(gc, struct pxa_gpio_chip, chip);
> +
> spin_lock_irqsave(&gpio_lock, flags);
>
> value = readl_relaxed(base + GPDR_OFFSET);
> - if (__gpio_is_inverted(chip->base + offset))
> + if (__gpio_is_inverted(chip, gc->base + offset))
> value |= mask;
> else
> value &= ~mask;
> @@ -207,19 +209,22 @@ static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
> return 0;
> }
>
> -static int pxa_gpio_direction_output(struct gpio_chip *chip,
> +static int pxa_gpio_direction_output(struct gpio_chip *gc,
> unsigned offset, int value)
> {
> - void __iomem *base = gpio_chip_base(chip);
> + struct pxa_gpio_chip *chip = NULL;
> + void __iomem *base = gpio_chip_base(gc);
> uint32_t tmp, mask = 1 << offset;
> unsigned long flags;
>
> + chip = container_of(gc, struct pxa_gpio_chip, chip);
> +
> writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET));
>
> spin_lock_irqsave(&gpio_lock, flags);
>
> tmp = readl_relaxed(base + GPDR_OFFSET);
> - if (__gpio_is_inverted(chip->base + offset))
> + if (__gpio_is_inverted(chip, gc->base + offset))
> tmp &= ~mask;
> else
> tmp |= mask;
> @@ -288,7 +293,7 @@ static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
> if ((c->irq_edge_rise | c->irq_edge_fall) & GPIO_bit(gpio))
> return 0;
>
> - if (__gpio_is_occupied(gpio))
> + if (__gpio_is_occupied(c, gpio))
> return 0;
>
> type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
> @@ -296,7 +301,7 @@ static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
>
> gpdr = readl_relaxed(c->regbase + GPDR_OFFSET);
>
> - if (__gpio_is_inverted(gpio))
> + if (__gpio_is_inverted(c, gpio))
> writel_relaxed(gpdr | mask, c->regbase + GPDR_OFFSET);
> else
> writel_relaxed(gpdr & ~mask, c->regbase + GPDR_OFFSET);
> @@ -474,6 +479,9 @@ static int pxa_gpio_probe_dt(struct platform_device *pdev)
> return -ENOMEM;
> if (of_find_property(np, "marvell,gpio-ed-mask", NULL))
> pdata->ed_mask = true;
> + /* It's only valid for PXA26x */
> + if (of_find_property(np, "marvell,gpio-inverted", NULL))
> + pdata->inverted = true;
> /* set the platform data */
> pdev->dev.platform_data = pdata;
> gpio_type = (int)of_id->data;
> @@ -616,6 +624,8 @@ static int pxa_gpio_probe(struct platform_device *pdev)
> /* unmask GPIO edge detect for AP side */
> if (info->ed_mask)
> writel_relaxed(~0, c->regbase + ED_MASK_OFFSET);
> + /* update for gpio inverted */
> + c->inverted = info->inverted;
> }
>
> if (!use_of) {
> diff --git a/include/linux/gpio-pxa.h b/include/linux/gpio-pxa.h
> index 49120b8..0c212a1 100644
> --- a/include/linux/gpio-pxa.h
> +++ b/include/linux/gpio-pxa.h
> @@ -17,6 +17,7 @@ extern int pxa_irq_to_gpio(struct irq_data *d);
>
> struct pxa_gpio_platform_data {
> bool ed_mask; /* true means that ed_mask reg is available */
> + bool inverted; /* only valid for PXA26x */
> int (*gpio_set_wake)(unsigned int gpio, unsigned int on);
> };
>
>
--
Regards,
Igor.
next prev parent reply other threads:[~2013-02-07 15:17 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-03 10:15 [PATCH v2 00/10] rework pxa gpio driver for pinctrl Haojian Zhuang
2013-02-03 10:15 ` [PATCH v2 01/10] gpio: pxa: identify ed mask reg with platform data Haojian Zhuang
2013-02-03 10:15 ` [PATCH v2 02/10] gpio: pxa: avoid to use global irq base Haojian Zhuang
2013-02-07 15:17 ` Igor Grinberg
2013-02-13 14:18 ` Igor Grinberg
2013-02-13 14:55 ` Haojian Zhuang
2013-02-14 9:27 ` Igor Grinberg
2013-02-14 12:19 ` Linus Walleij
2013-02-14 12:45 ` Igor Grinberg
2013-02-14 15:34 ` Linus Walleij
2013-02-17 14:54 ` Haojian Zhuang
2013-02-03 10:15 ` [PATCH v2 03/10] gpio: pxa: use platform data for gpio inverted Haojian Zhuang
2013-02-07 15:17 ` Igor Grinberg [this message]
2013-02-03 10:15 ` [PATCH v2 04/10] gpio: pxa: remove gpio_type Haojian Zhuang
2013-02-07 15:17 ` Igor Grinberg
2013-02-03 10:15 ` [PATCH v2 05/10] gpio: pxa: define nr gpios in platform data Haojian Zhuang
2013-02-03 13:18 ` Igor Grinberg
2013-02-03 15:00 ` [PATCH v2 05/11] " Haojian Zhuang
2013-02-07 15:17 ` Igor Grinberg
2013-02-03 15:03 ` [PATCH v2 05/10] " Haojian Zhuang
2013-02-03 10:15 ` [PATCH v2 06/10] gpio: pxa: clean code for compatible name Haojian Zhuang
2013-02-07 15:17 ` Igor Grinberg
2013-02-03 10:15 ` [PATCH v2 07/10] gpio: pxa: remove arch related macro Haojian Zhuang
2013-02-07 15:17 ` Igor Grinberg
2013-02-03 10:15 ` [PATCH v2 08/10] gpio: pxa: move gpio properties into child node Haojian Zhuang
2013-02-03 10:15 ` [PATCH v2 09/10] gpio: pxa: bind to pinctrl by request Haojian Zhuang
2013-02-06 14:11 ` Igor Grinberg
2013-02-07 15:17 ` Igor Grinberg
2013-02-03 10:15 ` [PATCH v2 10/10] ARM: dts: support pinmux in pxa910 Haojian Zhuang
2013-02-06 14:12 ` Igor Grinberg
2013-02-05 16:44 ` [PATCH v2 00/10] rework pxa gpio driver for pinctrl Linus Walleij
2013-02-06 2:08 ` Haojian Zhuang
2013-02-07 15:32 ` Igor Grinberg
2013-02-07 15:52 ` 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=5113C570.6060403@compulab.co.il \
--to=grinberg@compulab$(echo .)co.il \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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