All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Grant Likely <grant.likely@secretlab.ca>,
	David Brownell <dbrownell@users.sourceforge.net>
Cc: Bill Gatliff <bgat@billgatliff.com>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 2/4] of/gpio: Add support for two-stage registration for the of_gpio_chips
Date: Fri, 5 Feb 2010 23:32:34 +0300	[thread overview]
Message-ID: <20100205203234.GB1475@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <20100205203201.GA32281@oksana.dev.rtsoft.ru>

I2C/SPI drivers allocate gpio_chip structure already, so we don't need
'struct gpio_chip gc' in the OF GPIO subsystem, instead we need to store
just a pointer, and then attach the already allocated gpio_chip to the
of_gpio_chip structure.

With this patch there are two ways to register OF GPIO controllers:

1. Allocating the of_gpio_chip structure and passing the
   &of_gc->gc pointer to the gpiochip_add. (Can use container_of
   to convert the gpio_chip to the of_gpio_chip.)

2. Allocating and registering the gpio_chip structure separately
   from the of_gpio_chip. (Since two allocations are separate,
   container_of won't work.)

As time goes by we'll kill the first option.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
---
 arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c |    1 +
 drivers/of/gpio.c                              |   23 +++++++++++++++++++++--
 include/linux/of_gpio.h                        |    3 ++-
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
index 82a9bcb..73c7e6b 100644
--- a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
+++ b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
@@ -93,6 +93,7 @@ static int mcu_gpiochip_add(struct mcu *mcu)
 	gc->base = -1;
 	gc->set = mcu_gpio_set;
 	gc->direction_output = mcu_gpio_dir_out;
+	of_gc->chip = gc;
 	of_gc->gpio_cells = 2;
 	of_gc->xlate = of_gpio_simple_xlate;
 
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 6eea601..12c4af0 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -70,7 +70,7 @@ int of_get_gpio_flags(struct device_node *np, int index,
 	if (ret < 0)
 		goto err1;
 
-	ret += of_gc->gc.base;
+	ret += of_gc->chip->base;
 err1:
 	of_node_put(gc);
 err0:
@@ -140,7 +140,7 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
 		return -EINVAL;
 	}
 
-	if (*gpio > of_gc->gc.ngpio)
+	if (*gpio > of_gc->chip->ngpio)
 		return -EINVAL;
 
 	if (flags)
@@ -178,6 +178,25 @@ int of_mm_gpiochip_add(struct device_node *np,
 	struct of_gpio_chip *of_gc = &mm_gc->of_gc;
 	struct gpio_chip *gc = &of_gc->gc;
 
+	/*
+	 * Currently there are two ways to register OF GPIO controllers:
+	 *
+	 * 1. Allocating the of_gpio_chip structure and passing the
+	 *    &of_gc->gc pointer to the gpiochip_add. (Can use container_of
+	 *    to convert the gpio_chip to the of_gpio_chip.)
+	 *
+	 * 2. Allocating and registering the gpio_chip structure separately
+	 *    from the of_gpio_chip. (Since two allocations are separate,
+	 *    container_of won't work.)
+	 *
+	 * As time goes by we'll kill the first option. For now just check
+	 * if it's the new-style registration or the old-style.
+	 */
+	if (!of_gc->chip)
+		of_gc->chip = gc;
+	else
+		gc = of_gc->chip;
+
 	gc->label = kstrdup(np->full_name, GFP_KERNEL);
 	if (!gc->label)
 		goto err0;
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index fc2472c..c74cb37 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -36,7 +36,8 @@ enum of_gpio_flags {
  * Generic OF GPIO chip
  */
 struct of_gpio_chip {
-	struct gpio_chip gc;
+	struct gpio_chip gc; /* legacy, don't use for a new code */
+	struct gpio_chip *chip;
 	int gpio_cells;
 	int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np,
 		     const void *gpio_spec, enum of_gpio_flags *flags);
-- 
1.6.5.7

WARNING: multiple messages have this Message-ID (diff)
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Grant Likely <grant.likely@secretlab.ca>,
	David Brownell <dbrownell@users.sourceforge.net>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Bill Gatliff <bgat@billgatliff.com>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	linuxppc-dev@ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] of/gpio: Add support for two-stage registration for the of_gpio_chips
Date: Fri, 5 Feb 2010 23:32:34 +0300	[thread overview]
Message-ID: <20100205203234.GB1475@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <20100205203201.GA32281@oksana.dev.rtsoft.ru>

I2C/SPI drivers allocate gpio_chip structure already, so we don't need
'struct gpio_chip gc' in the OF GPIO subsystem, instead we need to store
just a pointer, and then attach the already allocated gpio_chip to the
of_gpio_chip structure.

With this patch there are two ways to register OF GPIO controllers:

1. Allocating the of_gpio_chip structure and passing the
   &of_gc->gc pointer to the gpiochip_add. (Can use container_of
   to convert the gpio_chip to the of_gpio_chip.)

2. Allocating and registering the gpio_chip structure separately
   from the of_gpio_chip. (Since two allocations are separate,
   container_of won't work.)

As time goes by we'll kill the first option.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
---
 arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c |    1 +
 drivers/of/gpio.c                              |   23 +++++++++++++++++++++--
 include/linux/of_gpio.h                        |    3 ++-
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
index 82a9bcb..73c7e6b 100644
--- a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
+++ b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
@@ -93,6 +93,7 @@ static int mcu_gpiochip_add(struct mcu *mcu)
 	gc->base = -1;
 	gc->set = mcu_gpio_set;
 	gc->direction_output = mcu_gpio_dir_out;
+	of_gc->chip = gc;
 	of_gc->gpio_cells = 2;
 	of_gc->xlate = of_gpio_simple_xlate;
 
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 6eea601..12c4af0 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -70,7 +70,7 @@ int of_get_gpio_flags(struct device_node *np, int index,
 	if (ret < 0)
 		goto err1;
 
-	ret += of_gc->gc.base;
+	ret += of_gc->chip->base;
 err1:
 	of_node_put(gc);
 err0:
@@ -140,7 +140,7 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
 		return -EINVAL;
 	}
 
-	if (*gpio > of_gc->gc.ngpio)
+	if (*gpio > of_gc->chip->ngpio)
 		return -EINVAL;
 
 	if (flags)
@@ -178,6 +178,25 @@ int of_mm_gpiochip_add(struct device_node *np,
 	struct of_gpio_chip *of_gc = &mm_gc->of_gc;
 	struct gpio_chip *gc = &of_gc->gc;
 
+	/*
+	 * Currently there are two ways to register OF GPIO controllers:
+	 *
+	 * 1. Allocating the of_gpio_chip structure and passing the
+	 *    &of_gc->gc pointer to the gpiochip_add. (Can use container_of
+	 *    to convert the gpio_chip to the of_gpio_chip.)
+	 *
+	 * 2. Allocating and registering the gpio_chip structure separately
+	 *    from the of_gpio_chip. (Since two allocations are separate,
+	 *    container_of won't work.)
+	 *
+	 * As time goes by we'll kill the first option. For now just check
+	 * if it's the new-style registration or the old-style.
+	 */
+	if (!of_gc->chip)
+		of_gc->chip = gc;
+	else
+		gc = of_gc->chip;
+
 	gc->label = kstrdup(np->full_name, GFP_KERNEL);
 	if (!gc->label)
 		goto err0;
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index fc2472c..c74cb37 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -36,7 +36,8 @@ enum of_gpio_flags {
  * Generic OF GPIO chip
  */
 struct of_gpio_chip {
-	struct gpio_chip gc;
+	struct gpio_chip gc; /* legacy, don't use for a new code */
+	struct gpio_chip *chip;
 	int gpio_cells;
 	int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np,
 		     const void *gpio_spec, enum of_gpio_flags *flags);
-- 
1.6.5.7


  parent reply	other threads:[~2010-02-05 20:32 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-05 20:32 [PATCH v2 0/4] OF GPIO integration for I2C/SPI GPIO chips Anton Vorontsov
2010-02-05 20:32 ` Anton Vorontsov
2010-02-05 20:32 ` [PATCH 1/4] gpiolib: Introduce chip addition/removal notifier Anton Vorontsov
2010-02-05 20:32   ` Anton Vorontsov
2010-02-09 17:16   ` Grant Likely
2010-02-09 17:16     ` Grant Likely
2010-03-05 19:59     ` Andrew Morton
2010-03-05 19:59       ` Andrew Morton
2010-03-05 20:30       ` Anton Vorontsov
2010-03-05 20:30         ` Anton Vorontsov
2010-02-05 20:32 ` Anton Vorontsov [this message]
2010-02-05 20:32   ` [PATCH 2/4] of/gpio: Add support for two-stage registration for the of_gpio_chips Anton Vorontsov
2010-02-05 20:32 ` [PATCH 3/4] of/gpio: Implement GPIOLIB notifier hooks Anton Vorontsov
2010-02-05 20:32   ` Anton Vorontsov
2010-02-08 21:02   ` Andrew Morton
2010-02-08 21:02     ` Andrew Morton
2010-02-09 17:08   ` Grant Likely
2010-02-09 17:08     ` Grant Likely
2010-02-09 19:06     ` Anton Vorontsov
2010-02-09 19:06       ` Anton Vorontsov
2010-02-09 17:13   ` Grant Likely
2010-02-09 17:13     ` Grant Likely
2010-02-09 19:16     ` Anton Vorontsov
2010-02-09 19:16       ` Anton Vorontsov
     [not found]       ` <20100305120015.a2008f46.akpm@linux-foundation.org>
     [not found]         ` <fa686aa41003051228w38579483yd4e95bb8eacf40f7@mail.gmail.com>
     [not found]           ` <20100305123527.d6d68e56.akpm@linux-foundation.org>
2010-03-05 23:47             ` Grant Likely
2010-03-05 23:47               ` Grant Likely
2010-03-06  0:28               ` Anton Vorontsov
2010-03-06  0:28                 ` Anton Vorontsov
2010-03-06  3:54                 ` Grant Likely
2010-03-06  3:54                   ` Grant Likely
2010-03-06  5:05                   ` Anton Vorontsov
2010-03-06  5:05                     ` Anton Vorontsov
2010-03-06 16:43                     ` Grant Likely
2010-03-06 16:43                       ` Grant Likely
2010-03-07  1:47                       ` Anton Vorontsov
2010-03-07  1:47                         ` Anton Vorontsov
2010-03-07  6:11                         ` Grant Likely
2010-03-07  6:11                           ` Grant Likely
2010-03-12 21:07   ` Andrew Morton
2010-03-12 21:07     ` Andrew Morton
2010-03-12 21:38     ` Grant Likely
2010-03-12 21:38       ` Grant Likely
2010-04-30 17:45       ` Anton Vorontsov
2010-04-30 17:45         ` Anton Vorontsov
2010-02-05 20:32 ` [PATCH 4/4] powerpc/mcu_mpc8349emitx: Remove OF GPIO handling stuff Anton Vorontsov
2010-02-05 20:32   ` Anton Vorontsov
  -- strict thread matches above, loose matches on Subject: below --
2010-01-25 18:09 [PATCH 0/4] OF GPIO integration for I2C/SPI GPIO chips Anton Vorontsov
2010-01-25 18:11 ` [PATCH 2/4] of/gpio: Add support for two-stage registration for the of_gpio_chips Anton Vorontsov
2010-01-25 18:11   ` Anton Vorontsov
2010-01-26  6:36   ` David Brownell
2010-01-26  6:36     ` David Brownell
2010-01-26 17:43     ` Anton Vorontsov
2010-01-26 17:43       ` Anton Vorontsov
2010-01-26 21:02       ` David Brownell
2010-01-26 21:02         ` David Brownell

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=20100205203234.GB1475@oksana.dev.rtsoft.ru \
    --to=avorontsov@ru.mvista.com \
    --cc=akpm@linux-foundation.org \
    --cc=bgat@billgatliff.com \
    --cc=dbaryshkov@gmail.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    /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.