Commit 25db711d authored by Benoit Cousson's avatar Benoit Cousson

gpio/omap: Fix IRQ handling for SPARSE_IRQ

The driver is still relying on internal OMAP IRQ defines that
are not relevant anymore if OMAP is built with SPARSE_IRQ.

Replace the defines with the proper IRQ base number.
Clean some comment style issue.
Remove some hidden and ugly cpu_class_is_omap1() inside the
gpio header.
Signed-off-by: default avatarBenoit Cousson <b-cousson@ti.com>
Tested-by: default avatarTarun Kanti DebBarma <tarun.kanti@ti.com>
parent 384ebe1c
...@@ -218,30 +218,14 @@ extern void omap_set_gpio_debounce(int gpio, int enable); ...@@ -218,30 +218,14 @@ extern void omap_set_gpio_debounce(int gpio, int enable);
extern void omap_set_gpio_debounce_time(int gpio, int enable); extern void omap_set_gpio_debounce_time(int gpio, int enable);
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* Wrappers for "new style" GPIO calls, using the new infrastructure /*
* Wrappers for "new style" GPIO calls, using the new infrastructure
* which lets us plug in FPGA, I2C, and other implementations. * which lets us plug in FPGA, I2C, and other implementations.
* * *
* The original OMAP-specific calls should eventually be removed. * The original OMAP-specific calls should eventually be removed.
*/ */
#include <linux/errno.h> #include <linux/errno.h>
#include <asm-generic/gpio.h> #include <asm-generic/gpio.h>
static inline int irq_to_gpio(unsigned irq)
{
int tmp;
/* omap1 SOC mpuio */
if (cpu_class_is_omap1() && (irq < (IH_MPUIO_BASE + 16)))
return (irq - IH_MPUIO_BASE) + OMAP_MAX_GPIO_LINES;
/* SOC gpio */
tmp = irq - IH_GPIO_BASE;
if (tmp < OMAP_MAX_GPIO_LINES)
return tmp;
/* we don't supply reverse mappings for non-SOC gpios */
return -EIO;
}
#endif #endif
...@@ -93,6 +93,11 @@ struct gpio_bank { ...@@ -93,6 +93,11 @@ struct gpio_bank {
#define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio)) #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
#define GPIO_MOD_CTRL_BIT BIT(0) #define GPIO_MOD_CTRL_BIT BIT(0)
static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq)
{
return gpio_irq - bank->irq_base + bank->chip.base;
}
static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
{ {
void __iomem *reg = bank->base; void __iomem *reg = bank->base;
...@@ -369,7 +374,7 @@ static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger) ...@@ -369,7 +374,7 @@ static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
static int gpio_irq_type(struct irq_data *d, unsigned type) static int gpio_irq_type(struct irq_data *d, unsigned type)
{ {
struct gpio_bank *bank; struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
unsigned gpio; unsigned gpio;
int retval; int retval;
unsigned long flags; unsigned long flags;
...@@ -377,13 +382,11 @@ static int gpio_irq_type(struct irq_data *d, unsigned type) ...@@ -377,13 +382,11 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
if (!cpu_class_is_omap2() && d->irq > IH_MPUIO_BASE) if (!cpu_class_is_omap2() && d->irq > IH_MPUIO_BASE)
gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE); gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
else else
gpio = d->irq - IH_GPIO_BASE; gpio = irq_to_gpio(bank, d->irq);
if (type & ~IRQ_TYPE_SENSE_MASK) if (type & ~IRQ_TYPE_SENSE_MASK)
return -EINVAL; return -EINVAL;
bank = irq_data_get_irq_chip_data(d);
if (!bank->regs->leveldetect0 && if (!bank->regs->leveldetect0 &&
(type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
return -EINVAL; return -EINVAL;
...@@ -524,14 +527,10 @@ static void _reset_gpio(struct gpio_bank *bank, int gpio) ...@@ -524,14 +527,10 @@ static void _reset_gpio(struct gpio_bank *bank, int gpio)
/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
static int gpio_wake_enable(struct irq_data *d, unsigned int enable) static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
{ {
unsigned int gpio = d->irq - IH_GPIO_BASE; struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
struct gpio_bank *bank; unsigned int gpio = irq_to_gpio(bank, d->irq);
int retval;
bank = irq_data_get_irq_chip_data(d);
retval = _set_gpio_wakeup(bank, gpio, enable);
return retval; return _set_gpio_wakeup(bank, gpio, enable);
} }
static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
...@@ -675,11 +674,13 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) ...@@ -675,11 +674,13 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
gpio_irq = bank->irq_base; gpio_irq = bank->irq_base;
for (; isr != 0; isr >>= 1, gpio_irq++) { for (; isr != 0; isr >>= 1, gpio_irq++) {
gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq)); int gpio = irq_to_gpio(bank, gpio_irq);
if (!(isr & 1)) if (!(isr & 1))
continue; continue;
gpio_index = GPIO_INDEX(bank, gpio);
/* /*
* Some chips can't respond to both rising and falling * Some chips can't respond to both rising and falling
* at the same time. If this irq was requested with * at the same time. If this irq was requested with
...@@ -705,8 +706,8 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) ...@@ -705,8 +706,8 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
static void gpio_irq_shutdown(struct irq_data *d) static void gpio_irq_shutdown(struct irq_data *d)
{ {
unsigned int gpio = d->irq - IH_GPIO_BASE;
struct gpio_bank *bank = irq_data_get_irq_chip_data(d); struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
unsigned int gpio = irq_to_gpio(bank, d->irq);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&bank->lock, flags); spin_lock_irqsave(&bank->lock, flags);
...@@ -716,16 +717,16 @@ static void gpio_irq_shutdown(struct irq_data *d) ...@@ -716,16 +717,16 @@ static void gpio_irq_shutdown(struct irq_data *d)
static void gpio_ack_irq(struct irq_data *d) static void gpio_ack_irq(struct irq_data *d)
{ {
unsigned int gpio = d->irq - IH_GPIO_BASE;
struct gpio_bank *bank = irq_data_get_irq_chip_data(d); struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
unsigned int gpio = irq_to_gpio(bank, d->irq);
_clear_gpio_irqstatus(bank, gpio); _clear_gpio_irqstatus(bank, gpio);
} }
static void gpio_mask_irq(struct irq_data *d) static void gpio_mask_irq(struct irq_data *d)
{ {
unsigned int gpio = d->irq - IH_GPIO_BASE;
struct gpio_bank *bank = irq_data_get_irq_chip_data(d); struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
unsigned int gpio = irq_to_gpio(bank, d->irq);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&bank->lock, flags); spin_lock_irqsave(&bank->lock, flags);
...@@ -736,8 +737,8 @@ static void gpio_mask_irq(struct irq_data *d) ...@@ -736,8 +737,8 @@ static void gpio_mask_irq(struct irq_data *d)
static void gpio_unmask_irq(struct irq_data *d) static void gpio_unmask_irq(struct irq_data *d)
{ {
unsigned int gpio = d->irq - IH_GPIO_BASE;
struct gpio_bank *bank = irq_data_get_irq_chip_data(d); struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
unsigned int gpio = irq_to_gpio(bank, d->irq);
unsigned int irq_mask = GPIO_BIT(bank, gpio); unsigned int irq_mask = GPIO_BIT(bank, gpio);
u32 trigger = irqd_get_trigger_type(d); u32 trigger = irqd_get_trigger_type(d);
unsigned long flags; unsigned long flags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment