Re: [PATCH v2 1/2] gpio: pxa: change the interrupt management

2015-12-15 Thread Robert Jarzmik
Linus Walleij  writes:

> On Sat, Dec 12, 2015 at 11:55 PM, Robert Jarzmik  
> wrote:
>
>> The interrupt management is changed by this patch to rely on chip data
>> instead of chained interrupts.
>>
>> The main goal is to loosen the dependency on the global pxa chip
>> structure in favor of the passed chip data. The secondary goal is to
>> better show in /proc/interrupts the difference between interrupts for
>> gpio0 and gpio1 (directly wired to interrupt controller), and the other
>> gpios (wired onto a third line in the interrupt controller).
>>
>> The last advantage of this patch is that the interrupt is actually
>> requested, so that another driver cannot steal this line, or overwrite
>> the handler.
>>
>> Signed-off-by: Robert Jarzmik 
>> ---
>> Since v1: moved CONFIG_OF for pxa_irq_domain_ops
>
> I already merged v1 and I don't like to rebase my tree,
> can you send an incremental patch fixing this, based off
> my "devel" branch?
Yeah, sure, I'll just do that.

Cheers.

-- 
Robert
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 1/2] gpio: pxa: change the interrupt management

2015-12-15 Thread Linus Walleij
On Sat, Dec 12, 2015 at 11:55 PM, Robert Jarzmik  wrote:

> The interrupt management is changed by this patch to rely on chip data
> instead of chained interrupts.
>
> The main goal is to loosen the dependency on the global pxa chip
> structure in favor of the passed chip data. The secondary goal is to
> better show in /proc/interrupts the difference between interrupts for
> gpio0 and gpio1 (directly wired to interrupt controller), and the other
> gpios (wired onto a third line in the interrupt controller).
>
> The last advantage of this patch is that the interrupt is actually
> requested, so that another driver cannot steal this line, or overwrite
> the handler.
>
> Signed-off-by: Robert Jarzmik 
> ---
> Since v1: moved CONFIG_OF for pxa_irq_domain_ops

I already merged v1 and I don't like to rebase my tree,
can you send an incremental patch fixing this, based off
my "devel" branch?

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 1/2] gpio: pxa: change the interrupt management

2015-12-15 Thread Robert Jarzmik
Linus Walleij  writes:

> On Sat, Dec 12, 2015 at 11:55 PM, Robert Jarzmik  
> wrote:
>
>> The interrupt management is changed by this patch to rely on chip data
>> instead of chained interrupts.
>>
>> The main goal is to loosen the dependency on the global pxa chip
>> structure in favor of the passed chip data. The secondary goal is to
>> better show in /proc/interrupts the difference between interrupts for
>> gpio0 and gpio1 (directly wired to interrupt controller), and the other
>> gpios (wired onto a third line in the interrupt controller).
>>
>> The last advantage of this patch is that the interrupt is actually
>> requested, so that another driver cannot steal this line, or overwrite
>> the handler.
>>
>> Signed-off-by: Robert Jarzmik 
>> ---
>> Since v1: moved CONFIG_OF for pxa_irq_domain_ops
>
> I already merged v1 and I don't like to rebase my tree,
> can you send an incremental patch fixing this, based off
> my "devel" branch?
Yeah, sure, I'll just do that.

Cheers.

-- 
Robert
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 1/2] gpio: pxa: change the interrupt management

2015-12-15 Thread Linus Walleij
On Sat, Dec 12, 2015 at 11:55 PM, Robert Jarzmik  wrote:

> The interrupt management is changed by this patch to rely on chip data
> instead of chained interrupts.
>
> The main goal is to loosen the dependency on the global pxa chip
> structure in favor of the passed chip data. The secondary goal is to
> better show in /proc/interrupts the difference between interrupts for
> gpio0 and gpio1 (directly wired to interrupt controller), and the other
> gpios (wired onto a third line in the interrupt controller).
>
> The last advantage of this patch is that the interrupt is actually
> requested, so that another driver cannot steal this line, or overwrite
> the handler.
>
> Signed-off-by: Robert Jarzmik 
> ---
> Since v1: moved CONFIG_OF for pxa_irq_domain_ops

I already merged v1 and I don't like to rebase my tree,
can you send an incremental patch fixing this, based off
my "devel" branch?

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/2] gpio: pxa: change the interrupt management

2015-12-12 Thread Robert Jarzmik
The interrupt management is changed by this patch to rely on chip data
instead of chained interrupts.

The main goal is to loosen the dependency on the global pxa chip
structure in favor of the passed chip data. The secondary goal is to
better show in /proc/interrupts the difference between interrupts for
gpio0 and gpio1 (directly wired to interrupt controller), and the other
gpios (wired onto a third line in the interrupt controller).

The last advantage of this patch is that the interrupt is actually
requested, so that another driver cannot steal this line, or overwrite
the handler.

Signed-off-by: Robert Jarzmik 
---
Since v1: moved CONFIG_OF for pxa_irq_domain_ops
---
 drivers/gpio/gpio-pxa.c | 171 +++-
 1 file changed, 95 insertions(+), 76 deletions(-)

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 8558abf98204..c6b572be68c0 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -64,11 +64,6 @@
 int pxa_last_gpio;
 static int irq_base;
 
-#ifdef CONFIG_OF
-static struct irq_domain *domain;
-static struct device_node *pxa_gpio_of_node;
-#endif
-
 struct pxa_gpio_bank {
void __iomem*regbase;
unsigned long   irq_mask;
@@ -87,6 +82,7 @@ struct pxa_gpio_chip {
struct device *dev;
struct gpio_chip chip;
struct pxa_gpio_bank *banks;
+   struct irq_domain *irqdomain;
 
int irq0;
int irq1;
@@ -231,14 +227,23 @@ static inline int __gpio_is_occupied(struct pxa_gpio_chip 
*pchip, unsigned gpio)
return ret;
 }
 
-static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
+int pxa_irq_to_gpio(int irq)
 {
-   return offset + irq_base;
+   struct pxa_gpio_chip *pchip = pxa_gpio_chip;
+   int irq_gpio0;
+
+   irq_gpio0 = irq_find_mapping(pchip->irqdomain, 0);
+   if (irq_gpio0 > 0)
+   return irq - irq_gpio0;
+
+   return irq_gpio0;
 }
 
-int pxa_irq_to_gpio(int irq)
+static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
 {
-   return irq - irq_base;
+   struct pxa_gpio_chip *pchip = chip_to_pxachip(chip);
+
+   return irq_find_mapping(pchip->irqdomain, offset);
 }
 
 static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -314,7 +319,7 @@ static int pxa_gpio_of_xlate(struct gpio_chip *gc,
 #endif
 
 static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio,
- void __iomem *regbase)
+ struct device_node *np, void __iomem *regbase)
 {
int i, gpio, nbanks = DIV_ROUND_UP(ngpio, 32);
struct pxa_gpio_bank *bank;
@@ -332,7 +337,7 @@ static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, 
int ngpio,
pchip->chip.to_irq = pxa_gpio_to_irq;
pchip->chip.ngpio = ngpio;
 #ifdef CONFIG_OF_GPIO
-   pchip->chip.of_node = pxa_gpio_of_node;
+   pchip->chip.of_node = np;
pchip->chip.of_xlate = pxa_gpio_of_xlate;
pchip->chip.of_gpio_n_cells = 2;
 #endif
@@ -362,8 +367,8 @@ static inline void update_edge_detect(struct pxa_gpio_bank 
*c)
 
 static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
 {
-   struct pxa_gpio_chip *pchip = pxa_gpio_chip;
-   int gpio = pxa_irq_to_gpio(d->irq);
+   struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d);
+   unsigned int gpio = irqd_to_hwirq(d);
struct pxa_gpio_bank *c = gpio_to_pxabank(>chip, gpio);
unsigned long gpdr, mask = GPIO_bit(gpio);
 
@@ -405,16 +410,13 @@ static int pxa_gpio_irq_type(struct irq_data *d, unsigned 
int type)
return 0;
 }
 
-static void pxa_gpio_demux_handler(struct irq_desc *desc)
+static irqreturn_t pxa_gpio_demux_handler(int in_irq, void *d)
 {
int loop, gpio, n, handled = 0;
unsigned long gedr;
-   struct irq_chip *chip = irq_desc_get_chip(desc);
-   struct pxa_gpio_chip *pchip = pxa_gpio_chip;
+   struct pxa_gpio_chip *pchip = d;
struct pxa_gpio_bank *c;
 
-   chained_irq_enter(chip, desc);
-
do {
loop = 0;
for_each_gpio_bank(gpio, c, pchip) {
@@ -428,15 +430,31 @@ static void pxa_gpio_demux_handler(struct irq_desc *desc)
generic_handle_irq(gpio_to_irq(gpio + n));
}
}
+   handled += loop;
} while (loop);
 
-   chained_irq_exit(chip, desc);
+   return handled ? IRQ_HANDLED : IRQ_NONE;
+}
+
+static irqreturn_t pxa_gpio_direct_handler(int in_irq, void *d)
+{
+   struct pxa_gpio_chip *pchip = d;
+
+   if (in_irq == pchip->irq0) {
+   generic_handle_irq(gpio_to_irq(0));
+   } else if (in_irq == pchip->irq1) {
+   generic_handle_irq(gpio_to_irq(1));
+   } else {
+   pr_err("%s() unknown irq %d\n", __func__, in_irq);
+   return IRQ_NONE;
+   }
+   return IRQ_HANDLED;
 }
 
 static void 

[PATCH v2 1/2] gpio: pxa: change the interrupt management

2015-12-12 Thread Robert Jarzmik
The interrupt management is changed by this patch to rely on chip data
instead of chained interrupts.

The main goal is to loosen the dependency on the global pxa chip
structure in favor of the passed chip data. The secondary goal is to
better show in /proc/interrupts the difference between interrupts for
gpio0 and gpio1 (directly wired to interrupt controller), and the other
gpios (wired onto a third line in the interrupt controller).

The last advantage of this patch is that the interrupt is actually
requested, so that another driver cannot steal this line, or overwrite
the handler.

Signed-off-by: Robert Jarzmik 
---
Since v1: moved CONFIG_OF for pxa_irq_domain_ops
---
 drivers/gpio/gpio-pxa.c | 171 +++-
 1 file changed, 95 insertions(+), 76 deletions(-)

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 8558abf98204..c6b572be68c0 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -64,11 +64,6 @@
 int pxa_last_gpio;
 static int irq_base;
 
-#ifdef CONFIG_OF
-static struct irq_domain *domain;
-static struct device_node *pxa_gpio_of_node;
-#endif
-
 struct pxa_gpio_bank {
void __iomem*regbase;
unsigned long   irq_mask;
@@ -87,6 +82,7 @@ struct pxa_gpio_chip {
struct device *dev;
struct gpio_chip chip;
struct pxa_gpio_bank *banks;
+   struct irq_domain *irqdomain;
 
int irq0;
int irq1;
@@ -231,14 +227,23 @@ static inline int __gpio_is_occupied(struct pxa_gpio_chip 
*pchip, unsigned gpio)
return ret;
 }
 
-static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
+int pxa_irq_to_gpio(int irq)
 {
-   return offset + irq_base;
+   struct pxa_gpio_chip *pchip = pxa_gpio_chip;
+   int irq_gpio0;
+
+   irq_gpio0 = irq_find_mapping(pchip->irqdomain, 0);
+   if (irq_gpio0 > 0)
+   return irq - irq_gpio0;
+
+   return irq_gpio0;
 }
 
-int pxa_irq_to_gpio(int irq)
+static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
 {
-   return irq - irq_base;
+   struct pxa_gpio_chip *pchip = chip_to_pxachip(chip);
+
+   return irq_find_mapping(pchip->irqdomain, offset);
 }
 
 static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -314,7 +319,7 @@ static int pxa_gpio_of_xlate(struct gpio_chip *gc,
 #endif
 
 static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio,
- void __iomem *regbase)
+ struct device_node *np, void __iomem *regbase)
 {
int i, gpio, nbanks = DIV_ROUND_UP(ngpio, 32);
struct pxa_gpio_bank *bank;
@@ -332,7 +337,7 @@ static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, 
int ngpio,
pchip->chip.to_irq = pxa_gpio_to_irq;
pchip->chip.ngpio = ngpio;
 #ifdef CONFIG_OF_GPIO
-   pchip->chip.of_node = pxa_gpio_of_node;
+   pchip->chip.of_node = np;
pchip->chip.of_xlate = pxa_gpio_of_xlate;
pchip->chip.of_gpio_n_cells = 2;
 #endif
@@ -362,8 +367,8 @@ static inline void update_edge_detect(struct pxa_gpio_bank 
*c)
 
 static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
 {
-   struct pxa_gpio_chip *pchip = pxa_gpio_chip;
-   int gpio = pxa_irq_to_gpio(d->irq);
+   struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d);
+   unsigned int gpio = irqd_to_hwirq(d);
struct pxa_gpio_bank *c = gpio_to_pxabank(>chip, gpio);
unsigned long gpdr, mask = GPIO_bit(gpio);
 
@@ -405,16 +410,13 @@ static int pxa_gpio_irq_type(struct irq_data *d, unsigned 
int type)
return 0;
 }
 
-static void pxa_gpio_demux_handler(struct irq_desc *desc)
+static irqreturn_t pxa_gpio_demux_handler(int in_irq, void *d)
 {
int loop, gpio, n, handled = 0;
unsigned long gedr;
-   struct irq_chip *chip = irq_desc_get_chip(desc);
-   struct pxa_gpio_chip *pchip = pxa_gpio_chip;
+   struct pxa_gpio_chip *pchip = d;
struct pxa_gpio_bank *c;
 
-   chained_irq_enter(chip, desc);
-
do {
loop = 0;
for_each_gpio_bank(gpio, c, pchip) {
@@ -428,15 +430,31 @@ static void pxa_gpio_demux_handler(struct irq_desc *desc)
generic_handle_irq(gpio_to_irq(gpio + n));
}
}
+   handled += loop;
} while (loop);
 
-   chained_irq_exit(chip, desc);
+   return handled ? IRQ_HANDLED : IRQ_NONE;
+}
+
+static irqreturn_t pxa_gpio_direct_handler(int in_irq, void *d)
+{
+   struct pxa_gpio_chip *pchip = d;
+
+   if (in_irq == pchip->irq0) {
+   generic_handle_irq(gpio_to_irq(0));
+   } else if (in_irq == pchip->irq1) {
+   generic_handle_irq(gpio_to_irq(1));
+   } else {
+   pr_err("%s() unknown irq %d\n", __func__, in_irq);
+   return IRQ_NONE;
+   }
+   return IRQ_HANDLED;
 }
 
 static