public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* GPIO: Add generic gpio_to_irq call.
@ 2008-07-17 23:50 Ben Dooks
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Dooks @ 2008-07-17 23:50 UTC (permalink / raw)
  To: linux-kernel, david-b; +Cc: Ben Dooks

[-- Attachment #1: simtec/simtec-gpiolib-add-irqmappings.patch --]
[-- Type: text/plain, Size: 2825 bytes --]

Add gpio_to_irq() implementation allowing the
gpio_chip registration to also specify an function
to map GPIO offsets into IRQs.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.26-quilt3/drivers/gpio/gpiolib.c
===================================================================
--- linux-2.6.26-quilt3.orig/drivers/gpio/gpiolib.c	2008-07-18 00:40:52.000000000 +0100
+++ linux-2.6.26-quilt3/drivers/gpio/gpiolib.c	2008-07-18 00:47:03.000000000 +0100
@@ -339,6 +339,36 @@ const char *gpiochip_is_requested(struct
 }
 EXPORT_SYMBOL_GPL(gpiochip_is_requested);
 
+int gpio_to_irq(unsigned gpio)
+{
+	struct gpio_chip	*chip;
+	struct gpio_desc	*desc = &gpio_desc[gpio];
+	unsigned long		flags;
+	int			status = -EINVAL;
+
+	spin_lock_irqsave(&gpio_lock, flags);
+
+	if (!gpio_is_valid(gpio))
+		goto fail;
+
+	chip = desc->chip;
+	if (!chip || !chip->to_irq)
+		goto fail;
+
+	gpio -= chip->base;
+	if (gpio >= chip->ngpio)
+		goto fail;
+
+	status = chip->to_irq(chip, offset);
+
+ fail:
+	spin_unlock_irqrestore(&gpio_lock, flags);
+	if (status)
+		pr_debug("%s: gpio-%d status %d\n",
+			__func__, gpio, status);
+	return status;
+}
+EXPORT_SYMBOL_GPL(gpio_to_irq);
 
 /* Drivers MUST set GPIO direction before making get/set calls.  In
  * some cases this is done in early boot, before IRQs are enabled.
Index: linux-2.6.26-quilt3/include/asm-generic/gpio.h
===================================================================
--- linux-2.6.26-quilt3.orig/include/asm-generic/gpio.h	2008-07-18 00:40:52.000000000 +0100
+++ linux-2.6.26-quilt3/include/asm-generic/gpio.h	2008-07-18 00:46:32.000000000 +0100
@@ -40,6 +40,7 @@ struct module;
  * @dbg_show: optional routine to show contents in debugfs; default code
  *	will be used when this is omitted, but custom code can show extra
  *	state (such as pullup/pulldown configuration).
+ * @to_irq: convert gpio offset to IRQ number.
  * @base: identifies the first GPIO number handled by this chip; or, if
  *	negative during registration, requests dynamic ID allocation.
  * @ngpio: the number of GPIOs handled by this controller; the last GPIO
@@ -71,6 +72,9 @@ struct gpio_chip {
 						unsigned offset, int value);
 	void			(*dbg_show)(struct seq_file *s,
 						struct gpio_chip *chip);
+	int			(*to_irq)(struct gpio_chip *chip,
+					  unsigned offset);
+
 	int			base;
 	u16			ngpio;
 	unsigned		can_sleep:1;
@@ -97,6 +101,7 @@ extern int gpio_direction_output(unsigne
 extern int gpio_get_value_cansleep(unsigned gpio);
 extern void gpio_set_value_cansleep(unsigned gpio, int value);
 
+extern int gpio_to_irq(unsigned gpio);
 
 /* A platform's <asm/gpio.h> code may want to inline the I/O calls when
  * the GPIO is constant and refers to some always-present controller,

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

^ permalink raw reply	[flat|nested] 6+ messages in thread

* GPIO: Add generic gpio_to_irq call.
@ 2008-07-17 23:52 Ben Dooks
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Dooks @ 2008-07-17 23:52 UTC (permalink / raw)
  To: linux-kernel, david-b; +Cc: Ben Dooks

[-- Attachment #1: simtec/simtec-gpiolib-add-irqmappings.patch --]
[-- Type: text/plain, Size: 2825 bytes --]

Add gpio_to_irq() implementation allowing the
gpio_chip registration to also specify an function
to map GPIO offsets into IRQs.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.26-quilt3/drivers/gpio/gpiolib.c
===================================================================
--- linux-2.6.26-quilt3.orig/drivers/gpio/gpiolib.c	2008-07-18 00:40:52.000000000 +0100
+++ linux-2.6.26-quilt3/drivers/gpio/gpiolib.c	2008-07-18 00:47:03.000000000 +0100
@@ -339,6 +339,36 @@ const char *gpiochip_is_requested(struct
 }
 EXPORT_SYMBOL_GPL(gpiochip_is_requested);
 
+int gpio_to_irq(unsigned gpio)
+{
+	struct gpio_chip	*chip;
+	struct gpio_desc	*desc = &gpio_desc[gpio];
+	unsigned long		flags;
+	int			status = -EINVAL;
+
+	spin_lock_irqsave(&gpio_lock, flags);
+
+	if (!gpio_is_valid(gpio))
+		goto fail;
+
+	chip = desc->chip;
+	if (!chip || !chip->to_irq)
+		goto fail;
+
+	gpio -= chip->base;
+	if (gpio >= chip->ngpio)
+		goto fail;
+
+	status = chip->to_irq(chip, offset);
+
+ fail:
+	spin_unlock_irqrestore(&gpio_lock, flags);
+	if (status)
+		pr_debug("%s: gpio-%d status %d\n",
+			__func__, gpio, status);
+	return status;
+}
+EXPORT_SYMBOL_GPL(gpio_to_irq);
 
 /* Drivers MUST set GPIO direction before making get/set calls.  In
  * some cases this is done in early boot, before IRQs are enabled.
Index: linux-2.6.26-quilt3/include/asm-generic/gpio.h
===================================================================
--- linux-2.6.26-quilt3.orig/include/asm-generic/gpio.h	2008-07-18 00:40:52.000000000 +0100
+++ linux-2.6.26-quilt3/include/asm-generic/gpio.h	2008-07-18 00:46:32.000000000 +0100
@@ -40,6 +40,7 @@ struct module;
  * @dbg_show: optional routine to show contents in debugfs; default code
  *	will be used when this is omitted, but custom code can show extra
  *	state (such as pullup/pulldown configuration).
+ * @to_irq: convert gpio offset to IRQ number.
  * @base: identifies the first GPIO number handled by this chip; or, if
  *	negative during registration, requests dynamic ID allocation.
  * @ngpio: the number of GPIOs handled by this controller; the last GPIO
@@ -71,6 +72,9 @@ struct gpio_chip {
 						unsigned offset, int value);
 	void			(*dbg_show)(struct seq_file *s,
 						struct gpio_chip *chip);
+	int			(*to_irq)(struct gpio_chip *chip,
+					  unsigned offset);
+
 	int			base;
 	u16			ngpio;
 	unsigned		can_sleep:1;
@@ -97,6 +101,7 @@ extern int gpio_direction_output(unsigne
 extern int gpio_get_value_cansleep(unsigned gpio);
 extern void gpio_set_value_cansleep(unsigned gpio, int value);
 
+extern int gpio_to_irq(unsigned gpio);
 
 /* A platform's <asm/gpio.h> code may want to inline the I/O calls when
  * the GPIO is constant and refers to some always-present controller,

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

^ permalink raw reply	[flat|nested] 6+ messages in thread

* GPIO: Add generic gpio_to_irq call.
@ 2008-07-24 11:46 Ben Dooks
  2008-07-24 11:51 ` Ben Dooks
  2008-07-24 12:17 ` Mikael Pettersson
  0 siblings, 2 replies; 6+ messages in thread
From: Ben Dooks @ 2008-07-24 11:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: david-b, Ben Dooks

[-- Attachment #1: simtec/simtec-gpiolib-add-irqmappings.patch --]
[-- Type: text/plain, Size: 4181 bytes --]

Add gpio_to_irq() implementation allowing the
gpio_chip registration to also specify an function
to map GPIO offsets into IRQs.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.26-quilt3/drivers/gpio/gpiolib.c
===================================================================
--- linux-2.6.26-quilt3.orig/drivers/gpio/gpiolib.c	2008-07-18 13:50:32.000000000 +0100
+++ linux-2.6.26-quilt3/drivers/gpio/gpiolib.c	2008-07-22 15:20:26.000000000 +0100
@@ -339,6 +339,36 @@ const char *gpiochip_is_requested(struct
 }
 EXPORT_SYMBOL_GPL(gpiochip_is_requested);
 
+int __gpio_to_irq(unsigned gpio)
+{
+	struct gpio_chip	*chip;
+	struct gpio_desc	*desc = &gpio_desc[gpio];
+	unsigned long		flags;
+	int			status = -EINVAL;
+
+	spin_lock_irqsave(&gpio_lock, flags);
+
+	if (!gpio_is_valid(gpio))
+		goto fail;
+
+	chip = desc->chip;
+	if (!chip || !chip->to_irq)
+		goto fail;
+
+	gpio -= chip->base;
+	if (gpio >= chip->ngpio)
+		goto fail;
+
+	status = chip->to_irq(chip, gpio);
+
+ fail:
+	spin_unlock_irqrestore(&gpio_lock, flags);
+	if (status)
+		pr_debug("%s: gpio-%d status %d\n",
+			__func__, gpio, status);
+	return status;
+}
+EXPORT_SYMBOL_GPL(__gpio_to_irq);
 
 /* Drivers MUST set GPIO direction before making get/set calls.  In
  * some cases this is done in early boot, before IRQs are enabled.
Index: linux-2.6.26-quilt3/include/asm-generic/gpio.h
===================================================================
--- linux-2.6.26-quilt3.orig/include/asm-generic/gpio.h	2008-07-18 13:50:32.000000000 +0100
+++ linux-2.6.26-quilt3/include/asm-generic/gpio.h	2008-07-22 15:21:05.000000000 +0100
@@ -40,6 +40,7 @@ struct module;
  * @dbg_show: optional routine to show contents in debugfs; default code
  *	will be used when this is omitted, but custom code can show extra
  *	state (such as pullup/pulldown configuration).
+ * @to_irq: convert gpio offset to IRQ number.
  * @base: identifies the first GPIO number handled by this chip; or, if
  *	negative during registration, requests dynamic ID allocation.
  * @ngpio: the number of GPIOs handled by this controller; the last GPIO
@@ -71,6 +72,9 @@ struct gpio_chip {
 						unsigned offset, int value);
 	void			(*dbg_show)(struct seq_file *s,
 						struct gpio_chip *chip);
+	int			(*to_irq)(struct gpio_chip *chip,
+					  unsigned offset);
+
 	int			base;
 	u16			ngpio;
 	unsigned		can_sleep:1;
@@ -97,6 +101,7 @@ extern int gpio_direction_output(unsigne
 extern int gpio_get_value_cansleep(unsigned gpio);
 extern void gpio_set_value_cansleep(unsigned gpio, int value);
 
+extern int __gpio_to_irq(unsigned gpio);
 
 /* A platform's <asm/gpio.h> code may want to inline the I/O calls when
  * the GPIO is constant and refers to some always-present controller,
Index: linux-2.6.26-quilt3/Documentation/gpio.txt
===================================================================
--- linux-2.6.26-quilt3.orig/Documentation/gpio.txt	2008-07-22 15:22:08.000000000 +0100
+++ linux-2.6.26-quilt3/Documentation/gpio.txt	2008-07-22 15:27:14.000000000 +0100
@@ -273,8 +273,9 @@ some GPIOs can't be used as IRQs.)  It i
 number that wasn't set up as an input using gpio_direction_input(), or
 to use an IRQ number that didn't originally come from gpio_to_irq().
 
-These two mapping calls are expected to cost on the order of a single
-addition or subtraction.  They're not allowed to sleep.
+These two mapping calls are expected to cost on between the order of a
+single addition or subtraction to obtaining an spinlock and using the
+to_irq method of the relevant gpio chip. They're not allowed to sleep.
 
 Non-error values returned from gpio_to_irq() can be passed to request_irq()
 or free_irq().  They will often be stored into IRQ resources for platform
@@ -400,6 +401,7 @@ They may also want to provide a custom v
 Trivial implementations of those functions can directly use framework
 code, which always dispatches through the gpio_chip:
 
+  #define gpio_to_irq	        __gpio_to_irq
   #define gpio_get_value	__gpio_get_value
   #define gpio_set_value	__gpio_set_value
   #define gpio_cansleep		__gpio_cansleep

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: GPIO: Add generic gpio_to_irq call.
  2008-07-24 11:46 Ben Dooks
@ 2008-07-24 11:51 ` Ben Dooks
  2008-07-24 12:17 ` Mikael Pettersson
  1 sibling, 0 replies; 6+ messages in thread
From: Ben Dooks @ 2008-07-24 11:51 UTC (permalink / raw)
  To: Ben Dooks; +Cc: linux-kernel, david-b

On Thu, Jul 24, 2008 at 12:46:27PM +0100, Ben Dooks wrote:
> Add gpio_to_irq() implementation allowing the
> gpio_chip registration to also specify an function
> to map GPIO offsets into IRQs.
> 
> Signed-off-by: Ben Dooks <ben-linux@fluff.org>
> 
> Index: linux-2.6.26-quilt3/drivers/gpio/gpiolib.c
> ===================================================================
> --- linux-2.6.26-quilt3.orig/drivers/gpio/gpiolib.c	2008-07-18 13:50:32.000000000 +0100
> +++ linux-2.6.26-quilt3/drivers/gpio/gpiolib.c	2008-07-22 15:20:26.000000000 +0100
> @@ -339,6 +339,36 @@ const char *gpiochip_is_requested(struct
>  }
>  EXPORT_SYMBOL_GPL(gpiochip_is_requested);
>  
> +int __gpio_to_irq(unsigned gpio)
> +{
> +	struct gpio_chip	*chip;
> +	struct gpio_desc	*desc = &gpio_desc[gpio];
> +	unsigned long		flags;
> +	int			status = -EINVAL;
> +
> +	spin_lock_irqsave(&gpio_lock, flags);
> +
> +	if (!gpio_is_valid(gpio))
> +		goto fail;
> +
> +	chip = desc->chip;
> +	if (!chip || !chip->to_irq)
> +		goto fail;
> +
> +	gpio -= chip->base;
> +	if (gpio >= chip->ngpio)
> +		goto fail;
> +
> +	status = chip->to_irq(chip, gpio);

hmm, this should have a check for chip->to_irq
being non-null before it.

> +
> + fail:
> +	spin_unlock_irqrestore(&gpio_lock, flags);
> +	if (status)
> +		pr_debug("%s: gpio-%d status %d\n",
> +			__func__, gpio, status);
> +	return status;
> +}
> +EXPORT_SYMBOL_GPL(__gpio_to_irq);
>  
>  /* Drivers MUST set GPIO direction before making get/set calls.  In
>   * some cases this is done in early boot, before IRQs are enabled.
> Index: linux-2.6.26-quilt3/include/asm-generic/gpio.h
> ===================================================================
> --- linux-2.6.26-quilt3.orig/include/asm-generic/gpio.h	2008-07-18 13:50:32.000000000 +0100
> +++ linux-2.6.26-quilt3/include/asm-generic/gpio.h	2008-07-22 15:21:05.000000000 +0100
> @@ -40,6 +40,7 @@ struct module;
>   * @dbg_show: optional routine to show contents in debugfs; default code
>   *	will be used when this is omitted, but custom code can show extra
>   *	state (such as pullup/pulldown configuration).
> + * @to_irq: convert gpio offset to IRQ number.
>   * @base: identifies the first GPIO number handled by this chip; or, if
>   *	negative during registration, requests dynamic ID allocation.
>   * @ngpio: the number of GPIOs handled by this controller; the last GPIO
> @@ -71,6 +72,9 @@ struct gpio_chip {
>  						unsigned offset, int value);
>  	void			(*dbg_show)(struct seq_file *s,
>  						struct gpio_chip *chip);
> +	int			(*to_irq)(struct gpio_chip *chip,
> +					  unsigned offset);
> +
>  	int			base;
>  	u16			ngpio;
>  	unsigned		can_sleep:1;
> @@ -97,6 +101,7 @@ extern int gpio_direction_output(unsigne
>  extern int gpio_get_value_cansleep(unsigned gpio);
>  extern void gpio_set_value_cansleep(unsigned gpio, int value);
>  
> +extern int __gpio_to_irq(unsigned gpio);
>  
>  /* A platform's <asm/gpio.h> code may want to inline the I/O calls when
>   * the GPIO is constant and refers to some always-present controller,
> Index: linux-2.6.26-quilt3/Documentation/gpio.txt
> ===================================================================
> --- linux-2.6.26-quilt3.orig/Documentation/gpio.txt	2008-07-22 15:22:08.000000000 +0100
> +++ linux-2.6.26-quilt3/Documentation/gpio.txt	2008-07-22 15:27:14.000000000 +0100
> @@ -273,8 +273,9 @@ some GPIOs can't be used as IRQs.)  It i
>  number that wasn't set up as an input using gpio_direction_input(), or
>  to use an IRQ number that didn't originally come from gpio_to_irq().
>  
> -These two mapping calls are expected to cost on the order of a single
> -addition or subtraction.  They're not allowed to sleep.
> +These two mapping calls are expected to cost on between the order of a
> +single addition or subtraction to obtaining an spinlock and using the
> +to_irq method of the relevant gpio chip. They're not allowed to sleep.
>  
>  Non-error values returned from gpio_to_irq() can be passed to request_irq()
>  or free_irq().  They will often be stored into IRQ resources for platform
> @@ -400,6 +401,7 @@ They may also want to provide a custom v
>  Trivial implementations of those functions can directly use framework
>  code, which always dispatches through the gpio_chip:
>  
> +  #define gpio_to_irq	        __gpio_to_irq
>    #define gpio_get_value	__gpio_get_value
>    #define gpio_set_value	__gpio_set_value
>    #define gpio_cansleep		__gpio_cansleep
> 
> -- 
> Ben (ben@fluff.org, http://www.fluff.org/)
> 
>   'a smiley only costs 4 bytes'
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: GPIO: Add generic gpio_to_irq call.
  2008-07-24 11:46 Ben Dooks
  2008-07-24 11:51 ` Ben Dooks
@ 2008-07-24 12:17 ` Mikael Pettersson
  1 sibling, 0 replies; 6+ messages in thread
From: Mikael Pettersson @ 2008-07-24 12:17 UTC (permalink / raw)
  To: Ben Dooks; +Cc: linux-kernel, david-b

Ben Dooks writes:
 > Add gpio_to_irq() implementation allowing the
 > gpio_chip registration to also specify an function
 > to map GPIO offsets into IRQs.
 > 
 > Signed-off-by: Ben Dooks <ben-linux@fluff.org>
 > 
 > Index: linux-2.6.26-quilt3/drivers/gpio/gpiolib.c
 > ===================================================================
 > --- linux-2.6.26-quilt3.orig/drivers/gpio/gpiolib.c	2008-07-18 13:50:32.000000000 +0100
 > +++ linux-2.6.26-quilt3/drivers/gpio/gpiolib.c	2008-07-22 15:20:26.000000000 +0100
 > @@ -339,6 +339,36 @@ const char *gpiochip_is_requested(struct
 >  }
 >  EXPORT_SYMBOL_GPL(gpiochip_is_requested);
 >  
 > +int __gpio_to_irq(unsigned gpio)
 > +{
 > +	struct gpio_chip	*chip;
 > +	struct gpio_desc	*desc = &gpio_desc[gpio];
 > +	unsigned long		flags;
 > +	int			status = -EINVAL;
 > +
 > +	spin_lock_irqsave(&gpio_lock, flags);
 > +
 > +	if (!gpio_is_valid(gpio))
 > +		goto fail;

Please move the &gpio_desc[gpio] expression after the gpio_is_valid(gpio)
test. Otherwise you risk violating C's pointer rules if the gpio is invalid.

 > +
 > +	chip = desc->chip;
 > +	if (!chip || !chip->to_irq)
 > +		goto fail;
 > +
 > +	gpio -= chip->base;
 > +	if (gpio >= chip->ngpio)
 > +		goto fail;
 > +
 > +	status = chip->to_irq(chip, gpio);
 > +
 > + fail:
 > +	spin_unlock_irqrestore(&gpio_lock, flags);
 > +	if (status)
 > +		pr_debug("%s: gpio-%d status %d\n",
 > +			__func__, gpio, status);
 > +	return status;
 > +}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* GPIO: Add generic gpio_to_irq call.
@ 2008-09-14 20:57 Ben Dooks
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Dooks @ 2008-09-14 20:57 UTC (permalink / raw)
  To: linux-kernel, david-b; +Cc: Ben Dooks

[-- Attachment #1: simtec/simtec-gpiolib-add-irqmappings.patch --]
[-- Type: text/plain, Size: 4218 bytes --]

Add gpio_to_irq() implementation allowing the
gpio_chip registration to also specify an function
to map GPIO offsets into IRQs.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.27-rc1-quilt1/drivers/gpio/gpiolib.c
===================================================================
--- linux-2.6.27-rc1-quilt1.orig/drivers/gpio/gpiolib.c	2008-07-30 09:20:12.000000000 +0100
+++ linux-2.6.27-rc1-quilt1/drivers/gpio/gpiolib.c	2008-07-30 10:08:05.000000000 +0100
@@ -842,6 +842,36 @@ const char *gpiochip_is_requested(struct
 }
 EXPORT_SYMBOL_GPL(gpiochip_is_requested);
 
+int __gpio_to_irq(unsigned gpio)
+{
+	struct gpio_chip	*chip;
+	struct gpio_desc	*desc = &gpio_desc[gpio];
+	unsigned long		flags;
+	int			status = -EINVAL;
+
+	spin_lock_irqsave(&gpio_lock, flags);
+
+	if (!gpio_is_valid(gpio))
+		goto fail;
+
+	chip = desc->chip;
+	if (!chip || !chip->to_irq)
+		goto fail;
+
+	gpio -= chip->base;
+	if (gpio >= chip->ngpio)
+		goto fail;
+
+	status = chip->to_irq(chip, gpio);
+
+ fail:
+	spin_unlock_irqrestore(&gpio_lock, flags);
+	if (status)
+		pr_debug("%s: gpio-%d status %d\n",
+			__func__, gpio, status);
+	return status;
+}
+EXPORT_SYMBOL_GPL(__gpio_to_irq);
 
 /* Drivers MUST set GPIO direction before making get/set calls.  In
  * some cases this is done in early boot, before IRQs are enabled.
Index: linux-2.6.27-rc1-quilt1/include/asm-generic/gpio.h
===================================================================
--- linux-2.6.27-rc1-quilt1.orig/include/asm-generic/gpio.h	2008-07-30 09:20:16.000000000 +0100
+++ linux-2.6.27-rc1-quilt1/include/asm-generic/gpio.h	2008-07-30 10:08:05.000000000 +0100
@@ -43,6 +43,7 @@ struct module;
  * @dbg_show: optional routine to show contents in debugfs; default code
  *	will be used when this is omitted, but custom code can show extra
  *	state (such as pullup/pulldown configuration).
+ * @to_irq: convert gpio offset to IRQ number.
  * @base: identifies the first GPIO number handled by this chip; or, if
  *	negative during registration, requests dynamic ID allocation.
  * @ngpio: the number of GPIOs handled by this controller; the last GPIO
@@ -75,6 +76,9 @@ struct gpio_chip {
 						unsigned offset, int value);
 	void			(*dbg_show)(struct seq_file *s,
 						struct gpio_chip *chip);
+	int			(*to_irq)(struct gpio_chip *chip,
+					  unsigned offset);
+
 	int			base;
 	u16			ngpio;
 	unsigned		can_sleep:1;
@@ -102,6 +106,7 @@ extern int gpio_direction_output(unsigne
 extern int gpio_get_value_cansleep(unsigned gpio);
 extern void gpio_set_value_cansleep(unsigned gpio, int value);
 
+extern int __gpio_to_irq(unsigned gpio);
 
 /* A platform's <asm/gpio.h> code may want to inline the I/O calls when
  * the GPIO is constant and refers to some always-present controller,
Index: linux-2.6.27-rc1-quilt1/Documentation/gpio.txt
===================================================================
--- linux-2.6.27-rc1-quilt1.orig/Documentation/gpio.txt	2008-07-30 09:20:08.000000000 +0100
+++ linux-2.6.27-rc1-quilt1/Documentation/gpio.txt	2008-07-30 10:08:05.000000000 +0100
@@ -273,8 +273,9 @@ some GPIOs can't be used as IRQs.)  It i
 number that wasn't set up as an input using gpio_direction_input(), or
 to use an IRQ number that didn't originally come from gpio_to_irq().
 
-These two mapping calls are expected to cost on the order of a single
-addition or subtraction.  They're not allowed to sleep.
+These two mapping calls are expected to cost on between the order of a
+single addition or subtraction to obtaining an spinlock and using the
+to_irq method of the relevant gpio chip. They're not allowed to sleep.
 
 Non-error values returned from gpio_to_irq() can be passed to request_irq()
 or free_irq().  They will often be stored into IRQ resources for platform
@@ -407,6 +408,7 @@ GPIOs through GPIO-lib and the code cann
 Trivial implementations of those functions can directly use framework
 code, which always dispatches through the gpio_chip:
 
+  #define gpio_to_irq	        __gpio_to_irq
   #define gpio_get_value	__gpio_get_value
   #define gpio_set_value	__gpio_set_value
   #define gpio_cansleep		__gpio_cansleep

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-09-14 20:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-17 23:52 GPIO: Add generic gpio_to_irq call Ben Dooks
  -- strict thread matches above, loose matches on Subject: below --
2008-09-14 20:57 Ben Dooks
2008-07-24 11:46 Ben Dooks
2008-07-24 11:51 ` Ben Dooks
2008-07-24 12:17 ` Mikael Pettersson
2008-07-17 23:50 Ben Dooks

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox