Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 313737
b: refs/heads/master
c: b98b358
h: refs/heads/master
i:
  313735: b0d2c0a
v: v3
  • Loading branch information
Paul Mundt committed May 24, 2012
1 parent 803d22c commit 22baa46
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3b1267b90f6b7c080024101696c0454f455761f4
refs/heads/master: b98b35815f40f01337e25e3f0d10d57b7cec5126
1 change: 1 addition & 0 deletions trunk/arch/sh/boards/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ config SH_X3PROTO
bool "SH-X3 Prototype board"
depends on CPU_SUBTYPE_SHX3
select NO_IOPORT if !PCI
select IRQ_DOMAIN

config SH_MAGIC_PANEL_R2
bool "Magic Panel R2"
Expand Down
57 changes: 31 additions & 26 deletions trunk/arch/sh/boards/mach-x3proto/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Renesas SH-X3 Prototype Baseboard GPIO Support.
*
* Copyright (C) 2010 Paul Mundt
* Copyright (C) 2010 - 2012 Paul Mundt
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
Expand All @@ -17,6 +17,7 @@
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/spinlock.h>
#include <linux/irqdomain.h>
#include <linux/io.h>
#include <mach/ilsel.h>
#include <mach/hardware.h>
Expand All @@ -26,7 +27,7 @@
#define KEYDETR 0xb81c0004

static DEFINE_SPINLOCK(x3proto_gpio_lock);
static unsigned int x3proto_gpio_irq_map[NR_BASEBOARD_GPIOS] = { 0, };
static struct irq_domain *x3proto_irq_domain;

static int x3proto_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
{
Expand All @@ -49,7 +50,14 @@ static int x3proto_gpio_get(struct gpio_chip *chip, unsigned gpio)

static int x3proto_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
{
return x3proto_gpio_irq_map[gpio];
int virq;

if (gpio < chip->ngpio)
virq = irq_create_mapping(x3proto_irq_domain, gpio);
else
virq = -ENXIO;

return virq;
}

static void x3proto_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Expand All @@ -62,9 +70,8 @@ static void x3proto_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
chip->irq_mask_ack(data);

mask = __raw_readw(KEYDETR);

for_each_set_bit(pin, &mask, NR_BASEBOARD_GPIOS)
generic_handle_irq(x3proto_gpio_to_irq(NULL, pin));
generic_handle_irq(irq_linear_revmap(x3proto_irq_domain, pin));

chip->irq_unmask(data);
}
Expand All @@ -78,10 +85,23 @@ struct gpio_chip x3proto_gpio_chip = {
.ngpio = NR_BASEBOARD_GPIOS,
};

static int x3proto_gpio_irq_map(struct irq_domain *domain, unsigned int virq,
irq_hw_number_t hwirq)
{
irq_set_chip_and_handler_name(virq, &dummy_irq_chip, handle_simple_irq,
"gpio");

return 0;
}

static struct irq_domain_ops x3proto_gpio_irq_ops = {
.map = x3proto_gpio_irq_map,
.xlate = irq_domain_xlate_twocell,
};

int __init x3proto_gpio_setup(void)
{
int ilsel;
int ret, i;
int ilsel, ret;

ilsel = ilsel_enable(ILSEL_KEY);
if (unlikely(ilsel < 0))
Expand All @@ -91,21 +111,10 @@ int __init x3proto_gpio_setup(void)
if (unlikely(ret))
goto err_gpio;

for (i = 0; i < NR_BASEBOARD_GPIOS; i++) {
unsigned long flags;
int irq = create_irq();

if (unlikely(irq < 0)) {
ret = -EINVAL;
goto err_irq;
}

spin_lock_irqsave(&x3proto_gpio_lock, flags);
x3proto_gpio_irq_map[i] = irq;
irq_set_chip_and_handler_name(irq, &dummy_irq_chip,
handle_simple_irq, "gpio");
spin_unlock_irqrestore(&x3proto_gpio_lock, flags);
}
x3proto_irq_domain = irq_domain_add_linear(NULL, NR_BASEBOARD_GPIOS,
&x3proto_gpio_irq_ops, NULL);
if (unlikely(!x3proto_irq_domain))
goto err_irq;

pr_info("registering '%s' support, handling GPIOs %u -> %u, "
"bound to IRQ %u\n",
Expand All @@ -119,10 +128,6 @@ int __init x3proto_gpio_setup(void)
return 0;

err_irq:
for (; i >= 0; --i)
if (x3proto_gpio_irq_map[i])
destroy_irq(x3proto_gpio_irq_map[i]);

ret = gpiochip_remove(&x3proto_gpio_chip);
if (unlikely(ret))
pr_err("Failed deregistering GPIO\n");
Expand Down

0 comments on commit 22baa46

Please sign in to comment.