All of lore.kernel.org
 help / color / mirror / Atom feed
* gpio-ep93xx: Add helper function to convert irq to gpio, port, and mask.
@ 2011-08-09 18:04 H Hartley Sweeten
  2011-08-09 21:48 ` Ryan Mallon
  0 siblings, 1 reply; 3+ messages in thread
From: H Hartley Sweeten @ 2011-08-09 18:04 UTC (permalink / raw)
  To: Linux Kernel; +Cc: rmallon, grant.likely

This consolidates the irq_to_gpio() call and the shift magic used to convert
a GPIO irq into it's relevant GPIO, port, and mask values.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Grant Likely <grant.likely@secretlab.ca>

---

diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
index 468b27d..788c7c4 100644
--- a/drivers/gpio/gpio-ep93xx.c
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -46,6 +46,20 @@ static const u8 eoi_register_offset[3]		= { 0x98, 0xb4, 0x54 };
 static const u8 int_en_register_offset[3]	= { 0x9c, 0xb8, 0x58 };
 static const u8 int_debounce_register_offset[3]	= { 0xa8, 0xc4, 0x64 };
 
+/*
+ * Map a sw irq to it's GPIO port and mask.
+ */
+static int ep93xx_gpio_irq_to_gpio_port_mask(unsigned int irq,
+			int *port, int *port_mask)
+{
+	int gpio = irq_to_gpio(irq);
+
+	*port = gpio >> 3;
+	*port_mask = 1 << (gpio & 7);
+
+	return gpio;
+}
+
 static void ep93xx_gpio_update_int_params(unsigned port)
 {
 	BUG_ON(port > 2);
@@ -69,9 +83,9 @@ static inline void ep93xx_gpio_int_mask(unsigned line)
 
 static void ep93xx_gpio_int_debounce(unsigned int irq, bool enable)
 {
-	int line = irq_to_gpio(irq);
-	int port = line >> 3;
-	int port_mask = 1 << (line & 7);
+	int port, port_mask;
+
+	ep93xx_gpio_irq_to_gpio_port_mask(irq, &port, &port_mask);
 
 	if (enable)
 		gpio_int_debounce[port] |= port_mask;
@@ -119,9 +133,9 @@ static void ep93xx_gpio_f_irq_handler(unsigned int irq, struct irq_desc *desc)
 
 static void ep93xx_gpio_irq_ack(struct irq_data *d)
 {
-	int line = irq_to_gpio(d->irq);
-	int port = line >> 3;
-	int port_mask = 1 << (line & 7);
+	int port, port_mask;
+
+	ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
 
 	if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
 		gpio_int_type2[port] ^= port_mask; /* switch edge direction */
@@ -133,9 +147,9 @@ static void ep93xx_gpio_irq_ack(struct irq_data *d)
 
 static void ep93xx_gpio_irq_mask_ack(struct irq_data *d)
 {
-	int line = irq_to_gpio(d->irq);
-	int port = line >> 3;
-	int port_mask = 1 << (line & 7);
+	int port, port_mask;
+
+	ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
 
 	if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH)
 		gpio_int_type2[port] ^= port_mask; /* switch edge direction */
@@ -148,19 +162,21 @@ static void ep93xx_gpio_irq_mask_ack(struct irq_data *d)
 
 static void ep93xx_gpio_irq_mask(struct irq_data *d)
 {
-	int line = irq_to_gpio(d->irq);
-	int port = line >> 3;
+	int port, port_mask;
+
+	ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
 
-	gpio_int_unmasked[port] &= ~(1 << (line & 7));
+	gpio_int_unmasked[port] &= ~port_mask;
 	ep93xx_gpio_update_int_params(port);
 }
 
 static void ep93xx_gpio_irq_unmask(struct irq_data *d)
 {
-	int line = irq_to_gpio(d->irq);
-	int port = line >> 3;
+	int port, port_mask;
+
+	ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
 
-	gpio_int_unmasked[port] |= 1 << (line & 7);
+	gpio_int_unmasked[port] |= port_mask;
 	ep93xx_gpio_update_int_params(port);
 }
 
@@ -171,11 +187,11 @@ static void ep93xx_gpio_irq_unmask(struct irq_data *d)
  */
 static int ep93xx_gpio_irq_type(struct irq_data *d, unsigned int type)
 {
-	const int gpio = irq_to_gpio(d->irq);
-	const int port = gpio >> 3;
-	const int port_mask = 1 << (gpio & 7);
+	int gpio, port, port_mask;
 	irq_flow_handler_t handler;
 
+	gpio = ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
+
 	gpio_direction_input(gpio);
 
 	switch (type) {

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

* Re: gpio-ep93xx: Add helper function to convert irq to gpio, port, and mask.
  2011-08-09 18:04 gpio-ep93xx: Add helper function to convert irq to gpio, port, and mask H Hartley Sweeten
@ 2011-08-09 21:48 ` Ryan Mallon
  2011-08-09 22:00   ` H Hartley Sweeten
  0 siblings, 1 reply; 3+ messages in thread
From: Ryan Mallon @ 2011-08-09 21:48 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, grant.likely

On 10/08/11 04:04, H Hartley Sweeten wrote:
> This consolidates the irq_to_gpio() call and the shift magic used to convert
> a GPIO irq into it's relevant GPIO, port, and mask values.
>
> Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
> Cc: Ryan Mallon <rmallon@gmail.com>

I think this should have my:

Signed-off-by: Ryan Mallon <rmallon@gmail.com>

Since I wrote the original patch.

Thanks,
~Ryan

> Cc: Grant Likely <grant.likely@secretlab.ca>
>
> ---
>
> diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
> index 468b27d..788c7c4 100644
> --- a/drivers/gpio/gpio-ep93xx.c
> +++ b/drivers/gpio/gpio-ep93xx.c
> @@ -46,6 +46,20 @@ static const u8 eoi_register_offset[3]		= { 0x98, 0xb4, 0x54 };
>  static const u8 int_en_register_offset[3]	= { 0x9c, 0xb8, 0x58 };
>  static const u8 int_debounce_register_offset[3]	= { 0xa8, 0xc4, 0x64 };
>  
> +/*
> + * Map a sw irq to it's GPIO port and mask.
> + */
> +static int ep93xx_gpio_irq_to_gpio_port_mask(unsigned int irq,
> +			int *port, int *port_mask)
> +{
> +	int gpio = irq_to_gpio(irq);
> +
> +	*port = gpio >> 3;
> +	*port_mask = 1 << (gpio & 7);
> +
> +	return gpio;
> +}
> +
>  static void ep93xx_gpio_update_int_params(unsigned port)
>  {
>  	BUG_ON(port > 2);
> @@ -69,9 +83,9 @@ static inline void ep93xx_gpio_int_mask(unsigned line)
>  
>  static void ep93xx_gpio_int_debounce(unsigned int irq, bool enable)
>  {
> -	int line = irq_to_gpio(irq);
> -	int port = line >> 3;
> -	int port_mask = 1 << (line & 7);
> +	int port, port_mask;
> +
> +	ep93xx_gpio_irq_to_gpio_port_mask(irq, &port, &port_mask);
>  
>  	if (enable)
>  		gpio_int_debounce[port] |= port_mask;
> @@ -119,9 +133,9 @@ static void ep93xx_gpio_f_irq_handler(unsigned int irq, struct irq_desc *desc)
>  
>  static void ep93xx_gpio_irq_ack(struct irq_data *d)
>  {
> -	int line = irq_to_gpio(d->irq);
> -	int port = line >> 3;
> -	int port_mask = 1 << (line & 7);
> +	int port, port_mask;
> +
> +	ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
>  
>  	if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
>  		gpio_int_type2[port] ^= port_mask; /* switch edge direction */
> @@ -133,9 +147,9 @@ static void ep93xx_gpio_irq_ack(struct irq_data *d)
>  
>  static void ep93xx_gpio_irq_mask_ack(struct irq_data *d)
>  {
> -	int line = irq_to_gpio(d->irq);
> -	int port = line >> 3;
> -	int port_mask = 1 << (line & 7);
> +	int port, port_mask;
> +
> +	ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
>  
>  	if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH)
>  		gpio_int_type2[port] ^= port_mask; /* switch edge direction */
> @@ -148,19 +162,21 @@ static void ep93xx_gpio_irq_mask_ack(struct irq_data *d)
>  
>  static void ep93xx_gpio_irq_mask(struct irq_data *d)
>  {
> -	int line = irq_to_gpio(d->irq);
> -	int port = line >> 3;
> +	int port, port_mask;
> +
> +	ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
>  
> -	gpio_int_unmasked[port] &= ~(1 << (line & 7));
> +	gpio_int_unmasked[port] &= ~port_mask;
>  	ep93xx_gpio_update_int_params(port);
>  }
>  
>  static void ep93xx_gpio_irq_unmask(struct irq_data *d)
>  {
> -	int line = irq_to_gpio(d->irq);
> -	int port = line >> 3;
> +	int port, port_mask;
> +
> +	ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
>  
> -	gpio_int_unmasked[port] |= 1 << (line & 7);
> +	gpio_int_unmasked[port] |= port_mask;
>  	ep93xx_gpio_update_int_params(port);
>  }
>  
> @@ -171,11 +187,11 @@ static void ep93xx_gpio_irq_unmask(struct irq_data *d)
>   */
>  static int ep93xx_gpio_irq_type(struct irq_data *d, unsigned int type)
>  {
> -	const int gpio = irq_to_gpio(d->irq);
> -	const int port = gpio >> 3;
> -	const int port_mask = 1 << (gpio & 7);
> +	int gpio, port, port_mask;
>  	irq_flow_handler_t handler;
>  
> +	gpio = ep93xx_gpio_irq_to_gpio_port_mask(d->irq, &port, &port_mask);
> +
>  	gpio_direction_input(gpio);
>  
>  	switch (type) {
> --
> 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/


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

* RE: gpio-ep93xx: Add helper function to convert irq to gpio, port, and mask.
  2011-08-09 21:48 ` Ryan Mallon
@ 2011-08-09 22:00   ` H Hartley Sweeten
  0 siblings, 0 replies; 3+ messages in thread
From: H Hartley Sweeten @ 2011-08-09 22:00 UTC (permalink / raw)
  To: Ryan Mallon; +Cc: Linux Kernel, grant.likely@secretlab.ca

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 924 bytes --]

On Tuesday, August 09, 2011 2:48 PM, Ryan Mallon wrote:
> On 10/08/11 04:04, H Hartley Sweeten wrote:
>> This consolidates the irq_to_gpio() call and the shift magic used to convert
>> a GPIO irq into it's relevant GPIO, port, and mask values.
>>
>> Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
>> Cc: Ryan Mallon <rmallon@gmail.com>
>
> I think this should have my:
>
> Signed-off-by: Ryan Mallon <rmallon@gmail.com>
>
> Since I wrote the original patch.

Sorry, misunderstood your previous email.

I re-coded this patch based on my one helper function instead of your two
functions.  Regardless, the idea was yours and I have no problem with it
having your Signed-off-by.

I'll re-post it with the modified sign offs shortly.

Thanks,
Hartley
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

end of thread, other threads:[~2011-08-09 22:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-09 18:04 gpio-ep93xx: Add helper function to convert irq to gpio, port, and mask H Hartley Sweeten
2011-08-09 21:48 ` Ryan Mallon
2011-08-09 22:00   ` H Hartley Sweeten

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.