From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Trent Piepho <tpiepho@freescale.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>,
linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org,
Richard Purdie <rpurdie@rpsys.net>
Subject: Re: [PATCH v3] leds: implement OpenFirmare GPIO LED driver
Date: Fri, 18 Jul 2008 14:05:49 +0400 [thread overview]
Message-ID: <20080718100549.GA28741@polina.dev.rtsoft.ru> (raw)
In-Reply-To: <Pine.LNX.4.64.0807171807420.29856@t2.domain.actdsltmp>
On Fri, Jul 18, 2008 at 02:20:42AM -0700, Trent Piepho wrote:
> On Fri, 18 Jul 2008, Anton Vorontsov wrote:
> > On Thu, Jul 17, 2008 at 01:18:18PM -0700, Trent Piepho wrote:
> >> Basically what I did then in my patch then, refactor leds-gpio so most of
> >> it is shared and there is a block of code that does platform binding and
> >> another block that does of_platform binding.
> >
> > Ok. I must admit I'm quite burned out with OF gpio-leds. I was posting the
> > bindings since April, probably four or five times. Last time a week ago,
> > IIRC.
> >
> > During the months I received just a few replies, one from Grant ("Looks
> > good to me."), few from Segher (with a lot of criticism, that I much
> > appreciated and tried to fix all spotted issues), and one from Laurent
> > (about active-low LEDs).
>
> I'm sorry, I never saw those emails. Were they all to linuxppc-dev? I hate
> reading that list, gmane, marc, and lkml.org don't archive it and
> mail-archive.com isn't nearly as nice.
Usually I use this archive: http://ozlabs.org/pipermail/linuxppc-dev/
> Is this the last version?
> http://www.mail-archive.com/linuxppc-dev@ozlabs.org/msg18355.html
No, this is v2 or something. The last version is the same as the current
one:
http://ozlabs.org/pipermail/linuxppc-dev/2008-July/059156.html
> Why did you get rid of "linux,default-trigger"
Nobody liked it, even I myself. ;-)
http://ozlabs.org/pipermail/linuxppc-dev/2008-May/056943.html
Later I tried to use aliases for default-trigger.
http://ozlabs.org/pipermail/linuxppc-dev/2008-June/057244.html
But after "i2c vs. cell-index vs. aliases" discussion I decided to
remove this stuff completely until I find something better (or
somebody will purpose).
As for linux,default-brightness... we don't need this since now we
have default-on trigger.
> and the active-low property?
Active-low can be coded inside the gpios = <>, via flags cell. And GPIO
controller can transparently support active-low GPIO states (i.e. just
like IRQ controllers automatically setting up IRQ trigger types based
on information from the device tree).
I implemented active-low flags for pixis gpio controller, but it is easy
to do this for any controller, when needed. Here is example:
diff --git a/arch/powerpc/platforms/86xx/pixis_gpio.c b/arch/powerpc/platforms/86xx/pixis_gpio.c
new file mode 100644
index 0000000..85254f9
--- /dev/null
+++ b/arch/powerpc/platforms/86xx/pixis_gpio.c
@@ -0,0 +1,141 @@
+/*
+ * PIXIS GPIOs
+ *
+ * Copyright (c) MontaVista Software, Inc. 2008.
+ *
+ * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/spinlock.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/gpio.h>
+
+#define PIXIS_GPIO_PINS 8
+
+struct px_gpio_chip {
+ struct of_mm_gpio_chip mm_gc;
+ spinlock_t lock;
+
+ /* mask for active-low pins */
+ u8 active_low;
+};
+
+static inline struct px_gpio_chip *
+to_px_gpio_chip(struct of_mm_gpio_chip *mm_gc)
+{
+ return container_of(mm_gc, struct px_gpio_chip, mm_gc);
+}
+
+static inline u8 pin2mask(unsigned int pin)
+{
+ return 1 << (PIXIS_GPIO_PINS - 1 - pin);
+}
+
+static int px_gpio_get(struct gpio_chip *gc, unsigned int gpio)
+{
+ struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+ struct px_gpio_chip *px_gc = to_px_gpio_chip(mm_gc);
+ u8 __iomem *regs = mm_gc->regs;
+
+ return (in_8(regs) ^ px_gc->active_low) & pin2mask(gpio);
+}
+
+static void px_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+ struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+ struct px_gpio_chip *px_gc = to_px_gpio_chip(mm_gc);
+ u8 __iomem *regs = mm_gc->regs;
+ unsigned long flags;
+ u8 val_mask = val ? pin2mask(gpio) : 0;
+
+ spin_lock_irqsave(&px_gc->lock, flags);
+
+ if ((val_mask ^ px_gc->active_low) & pin2mask(gpio))
+ setbits8(regs, pin2mask(gpio));
+ else
+ clrbits8(regs, pin2mask(gpio));
+
+ spin_unlock_irqrestore(&px_gc->lock, flags);
+}
+
+static int px_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
+{
+ return 0;
+}
+
+static int px_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+ px_gpio_set(gc, gpio, val);
+ return 0;
+}
+
+#define PX_GPIO_FLAG_ACTIVE_LOW (1 << 0)
+
+int px_gpio_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
+ const void *gpio_spec)
+{
+ struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(&of_gc->gc);
+ struct px_gpio_chip *px_gc = to_px_gpio_chip(mm_gc);
+ const u32 *gpio = gpio_spec;
+
+ if (*gpio > of_gc->gc.ngpio)
+ return -EINVAL;
+
+ if (gpio[1] & PX_GPIO_FLAG_ACTIVE_LOW)
+ px_gc->active_low |= pin2mask(*gpio);
+
+ return *gpio;
+}
+
+static int __init pixis_gpio_init(void)
+{
+ struct device_node *np;
+
+ for_each_compatible_node(np, NULL, "fsl,fpga-pixis-gpio-bank") {
+ int ret;
+ struct px_gpio_chip *px_gc;
+ struct of_mm_gpio_chip *mm_gc;
+ struct of_gpio_chip *of_gc;
+ struct gpio_chip *gc;
+
+ px_gc = kzalloc(sizeof(*px_gc), GFP_KERNEL);
+ if (!px_gc) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ spin_lock_init(&px_gc->lock);
+
+ mm_gc = &px_gc->mm_gc;
+ of_gc = &mm_gc->of_gc;
+ gc = &of_gc->gc;
+
+ of_gc->gpio_cells = 2;
+ of_gc->xlate = px_gpio_xlate;
+ gc->ngpio = PIXIS_GPIO_PINS;
+ gc->direction_input = px_gpio_dir_in;
+ gc->direction_output = px_gpio_dir_out;
+ gc->get = px_gpio_get;
+ gc->set = px_gpio_set;
+
+ ret = of_mm_gpiochip_add(np, mm_gc);
+ if (ret)
+ goto err;
+ continue;
+err:
+ pr_err("%s: registration failed with status %d\n",
+ np->full_name, ret);
+ kfree(px_gc);
+ /* try others anyway */
+ }
+ return 0;
+}
+arch_initcall(pixis_gpio_init);
WARNING: multiple messages have this Message-ID (diff)
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Trent Piepho <tpiepho@freescale.com>
Cc: Grant Likely <grant.likely@secretlab.ca>,
Richard Purdie <rpurdie@rpsys.net>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Kumar Gala <galak@kernel.crashing.org>,
linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org
Subject: Re: [PATCH v3] leds: implement OpenFirmare GPIO LED driver
Date: Fri, 18 Jul 2008 14:05:49 +0400 [thread overview]
Message-ID: <20080718100549.GA28741@polina.dev.rtsoft.ru> (raw)
In-Reply-To: <Pine.LNX.4.64.0807171807420.29856@t2.domain.actdsltmp>
On Fri, Jul 18, 2008 at 02:20:42AM -0700, Trent Piepho wrote:
> On Fri, 18 Jul 2008, Anton Vorontsov wrote:
> > On Thu, Jul 17, 2008 at 01:18:18PM -0700, Trent Piepho wrote:
> >> Basically what I did then in my patch then, refactor leds-gpio so most of
> >> it is shared and there is a block of code that does platform binding and
> >> another block that does of_platform binding.
> >
> > Ok. I must admit I'm quite burned out with OF gpio-leds. I was posting the
> > bindings since April, probably four or five times. Last time a week ago,
> > IIRC.
> >
> > During the months I received just a few replies, one from Grant ("Looks
> > good to me."), few from Segher (with a lot of criticism, that I much
> > appreciated and tried to fix all spotted issues), and one from Laurent
> > (about active-low LEDs).
>
> I'm sorry, I never saw those emails. Were they all to linuxppc-dev? I hate
> reading that list, gmane, marc, and lkml.org don't archive it and
> mail-archive.com isn't nearly as nice.
Usually I use this archive: http://ozlabs.org/pipermail/linuxppc-dev/
> Is this the last version?
> http://www.mail-archive.com/linuxppc-dev@ozlabs.org/msg18355.html
No, this is v2 or something. The last version is the same as the current
one:
http://ozlabs.org/pipermail/linuxppc-dev/2008-July/059156.html
> Why did you get rid of "linux,default-trigger"
Nobody liked it, even I myself. ;-)
http://ozlabs.org/pipermail/linuxppc-dev/2008-May/056943.html
Later I tried to use aliases for default-trigger.
http://ozlabs.org/pipermail/linuxppc-dev/2008-June/057244.html
But after "i2c vs. cell-index vs. aliases" discussion I decided to
remove this stuff completely until I find something better (or
somebody will purpose).
As for linux,default-brightness... we don't need this since now we
have default-on trigger.
> and the active-low property?
Active-low can be coded inside the gpios = <>, via flags cell. And GPIO
controller can transparently support active-low GPIO states (i.e. just
like IRQ controllers automatically setting up IRQ trigger types based
on information from the device tree).
I implemented active-low flags for pixis gpio controller, but it is easy
to do this for any controller, when needed. Here is example:
diff --git a/arch/powerpc/platforms/86xx/pixis_gpio.c b/arch/powerpc/platforms/86xx/pixis_gpio.c
new file mode 100644
index 0000000..85254f9
--- /dev/null
+++ b/arch/powerpc/platforms/86xx/pixis_gpio.c
@@ -0,0 +1,141 @@
+/*
+ * PIXIS GPIOs
+ *
+ * Copyright (c) MontaVista Software, Inc. 2008.
+ *
+ * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/spinlock.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/gpio.h>
+
+#define PIXIS_GPIO_PINS 8
+
+struct px_gpio_chip {
+ struct of_mm_gpio_chip mm_gc;
+ spinlock_t lock;
+
+ /* mask for active-low pins */
+ u8 active_low;
+};
+
+static inline struct px_gpio_chip *
+to_px_gpio_chip(struct of_mm_gpio_chip *mm_gc)
+{
+ return container_of(mm_gc, struct px_gpio_chip, mm_gc);
+}
+
+static inline u8 pin2mask(unsigned int pin)
+{
+ return 1 << (PIXIS_GPIO_PINS - 1 - pin);
+}
+
+static int px_gpio_get(struct gpio_chip *gc, unsigned int gpio)
+{
+ struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+ struct px_gpio_chip *px_gc = to_px_gpio_chip(mm_gc);
+ u8 __iomem *regs = mm_gc->regs;
+
+ return (in_8(regs) ^ px_gc->active_low) & pin2mask(gpio);
+}
+
+static void px_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+ struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+ struct px_gpio_chip *px_gc = to_px_gpio_chip(mm_gc);
+ u8 __iomem *regs = mm_gc->regs;
+ unsigned long flags;
+ u8 val_mask = val ? pin2mask(gpio) : 0;
+
+ spin_lock_irqsave(&px_gc->lock, flags);
+
+ if ((val_mask ^ px_gc->active_low) & pin2mask(gpio))
+ setbits8(regs, pin2mask(gpio));
+ else
+ clrbits8(regs, pin2mask(gpio));
+
+ spin_unlock_irqrestore(&px_gc->lock, flags);
+}
+
+static int px_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
+{
+ return 0;
+}
+
+static int px_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+ px_gpio_set(gc, gpio, val);
+ return 0;
+}
+
+#define PX_GPIO_FLAG_ACTIVE_LOW (1 << 0)
+
+int px_gpio_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
+ const void *gpio_spec)
+{
+ struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(&of_gc->gc);
+ struct px_gpio_chip *px_gc = to_px_gpio_chip(mm_gc);
+ const u32 *gpio = gpio_spec;
+
+ if (*gpio > of_gc->gc.ngpio)
+ return -EINVAL;
+
+ if (gpio[1] & PX_GPIO_FLAG_ACTIVE_LOW)
+ px_gc->active_low |= pin2mask(*gpio);
+
+ return *gpio;
+}
+
+static int __init pixis_gpio_init(void)
+{
+ struct device_node *np;
+
+ for_each_compatible_node(np, NULL, "fsl,fpga-pixis-gpio-bank") {
+ int ret;
+ struct px_gpio_chip *px_gc;
+ struct of_mm_gpio_chip *mm_gc;
+ struct of_gpio_chip *of_gc;
+ struct gpio_chip *gc;
+
+ px_gc = kzalloc(sizeof(*px_gc), GFP_KERNEL);
+ if (!px_gc) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ spin_lock_init(&px_gc->lock);
+
+ mm_gc = &px_gc->mm_gc;
+ of_gc = &mm_gc->of_gc;
+ gc = &of_gc->gc;
+
+ of_gc->gpio_cells = 2;
+ of_gc->xlate = px_gpio_xlate;
+ gc->ngpio = PIXIS_GPIO_PINS;
+ gc->direction_input = px_gpio_dir_in;
+ gc->direction_output = px_gpio_dir_out;
+ gc->get = px_gpio_get;
+ gc->set = px_gpio_set;
+
+ ret = of_mm_gpiochip_add(np, mm_gc);
+ if (ret)
+ goto err;
+ continue;
+err:
+ pr_err("%s: registration failed with status %d\n",
+ np->full_name, ret);
+ kfree(px_gc);
+ /* try others anyway */
+ }
+ return 0;
+}
+arch_initcall(pixis_gpio_init);
next prev parent reply other threads:[~2008-07-18 10:05 UTC|newest]
Thread overview: 117+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-14 16:41 [PATCH] leds: implement OpenFirmare GPIO LED driver Anton Vorontsov
2008-07-14 16:41 ` Anton Vorontsov
2008-07-15 3:10 ` Stephen Rothwell
2008-07-15 3:10 ` Stephen Rothwell
2008-07-15 12:38 ` Anton Vorontsov
2008-07-15 12:38 ` Anton Vorontsov
2008-07-15 12:40 ` [PATCH v2] " Anton Vorontsov
2008-07-15 12:40 ` Anton Vorontsov
2008-07-15 12:54 ` Richard Purdie
2008-07-15 12:54 ` Richard Purdie
2008-07-15 13:24 ` Anton Vorontsov
2008-07-15 13:24 ` Anton Vorontsov
2008-07-15 13:31 ` Richard Purdie
2008-07-15 13:31 ` Richard Purdie
2008-07-15 14:23 ` Anton Vorontsov
2008-07-15 14:23 ` Anton Vorontsov
2008-07-15 14:43 ` Richard Purdie
2008-07-15 14:43 ` Richard Purdie
2008-07-15 15:19 ` [PATCH v3] " Anton Vorontsov
2008-07-15 15:19 ` Anton Vorontsov
2008-07-16 23:18 ` Trent Piepho
2008-07-16 23:18 ` Trent Piepho
2008-07-17 4:15 ` Grant Likely
2008-07-17 4:15 ` Grant Likely
2008-07-17 5:13 ` Trent Piepho
2008-07-17 5:13 ` Trent Piepho
2008-07-17 13:55 ` Anton Vorontsov
2008-07-17 13:55 ` Anton Vorontsov
2008-07-17 20:01 ` Trent Piepho
2008-07-17 20:01 ` Trent Piepho
2008-07-17 14:05 ` Anton Vorontsov
2008-07-17 14:05 ` Anton Vorontsov
2008-07-17 14:13 ` Anton Vorontsov
2008-07-17 14:13 ` Anton Vorontsov
2008-07-17 15:04 ` Grant Likely
2008-07-17 15:04 ` Grant Likely
2008-07-17 15:20 ` Anton Vorontsov
2008-07-17 15:20 ` Anton Vorontsov
2008-07-17 18:05 ` Grant Likely
2008-07-17 18:05 ` Grant Likely
2008-07-17 20:18 ` Trent Piepho
2008-07-17 20:18 ` Trent Piepho
2008-07-17 20:49 ` Grant Likely
2008-07-17 20:49 ` Grant Likely
2008-07-17 23:42 ` Anton Vorontsov
2008-07-17 23:42 ` Anton Vorontsov
2008-07-18 5:09 ` Grant Likely
2008-07-18 5:09 ` Grant Likely
2008-07-18 9:20 ` Trent Piepho
2008-07-18 9:20 ` Trent Piepho
2008-07-18 10:05 ` Anton Vorontsov [this message]
2008-07-18 10:05 ` Anton Vorontsov
2008-07-19 21:08 ` PIXIS gpio controller and gpio flags Trent Piepho
2008-07-19 21:08 ` Trent Piepho
2008-07-21 17:53 ` Anton Vorontsov
2008-07-21 17:53 ` Anton Vorontsov
2008-07-21 21:12 ` Trent Piepho
2008-07-21 21:12 ` Trent Piepho
2008-07-23 14:56 ` Anton Vorontsov
2008-07-23 14:56 ` Anton Vorontsov
2008-07-23 23:42 ` Trent Piepho
2008-07-23 23:42 ` Trent Piepho
2008-07-25 16:48 ` [RFC PATCH] of_gpio: implement of_get_gpio_flags() Anton Vorontsov
2008-07-25 16:48 ` Anton Vorontsov
2008-07-26 8:26 ` Trent Piepho
2008-07-26 8:26 ` Trent Piepho
2008-07-25 20:38 ` [PATCH v3] leds: implement OpenFirmare GPIO LED driver Trent Piepho
2008-07-25 20:38 ` Trent Piepho
2008-07-25 21:01 ` [PATCH 1/2] leds: make the default trigger name const Trent Piepho
2008-07-25 21:01 ` Trent Piepho
2008-07-27 2:08 ` Grant Likely
2008-07-27 2:08 ` Grant Likely
2008-07-27 13:11 ` Stephen Rothwell
2008-07-27 13:11 ` Stephen Rothwell
2008-07-28 1:56 ` Trent Piepho
2008-07-28 1:56 ` Trent Piepho
2008-07-28 2:02 ` [PATCH v2] " Trent Piepho
2008-07-28 2:02 ` Trent Piepho
2008-07-28 9:53 ` [PATCH 1/2] " Anton Vorontsov
2008-07-28 9:53 ` Anton Vorontsov
2008-08-29 1:22 ` Trent Piepho
2008-08-29 1:22 ` Trent Piepho
2008-07-25 21:01 ` [PATCH 2/2] leds: Support OpenFirmware led bindings Trent Piepho
2008-07-25 21:01 ` Trent Piepho
2008-07-27 2:21 ` Grant Likely
2008-07-27 2:21 ` Grant Likely
2008-07-28 8:31 ` Trent Piepho
2008-07-28 8:31 ` Trent Piepho
2008-07-28 17:09 ` Grant Likely
2008-07-28 17:09 ` Grant Likely
2008-07-28 18:02 ` Anton Vorontsov
2008-07-28 18:02 ` Anton Vorontsov
2008-07-28 18:06 ` Grant Likely
2008-07-28 18:06 ` Grant Likely
2008-07-28 18:26 ` Trent Piepho
2008-07-28 18:26 ` Trent Piepho
2008-07-28 18:49 ` Grant Likely
2008-07-28 18:49 ` Grant Likely
2008-07-28 18:51 ` Anton Vorontsov
2008-07-28 18:51 ` Anton Vorontsov
2008-07-28 19:11 ` Trent Piepho
2008-07-28 19:11 ` Trent Piepho
2008-07-17 21:29 ` [PATCH v3] leds: implement OpenFirmare GPIO LED driver Nate Case
2008-07-17 21:29 ` Nate Case
2008-07-16 23:22 ` [PATCH v2] " Trent Piepho
2008-07-16 23:22 ` Trent Piepho
2008-07-17 5:59 ` [PATCH] " Segher Boessenkool
2008-07-17 5:59 ` Segher Boessenkool
2008-07-17 11:07 ` Anton Vorontsov
2008-07-17 11:07 ` Anton Vorontsov
2008-07-17 14:58 ` Sean MacLennan
2008-07-17 14:58 ` Sean MacLennan
2008-07-17 15:07 ` Grant Likely
2008-07-17 15:07 ` Grant Likely
2008-07-18 3:35 ` David Gibson
2008-07-18 3:35 ` David Gibson
2008-07-18 4:44 ` Grant Likely
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=20080718100549.GA28741@polina.dev.rtsoft.ru \
--to=avorontsov@ru.mvista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=rpurdie@rpsys.net \
--cc=sfr@canb.auug.org.au \
--cc=tpiepho@freescale.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.