Skip to content

Commit fa365e4

Browse files
Javier Martinez Canillaslinusw
authored andcommitted
gpio/omap: maintain GPIO and IRQ usage separately
The GPIO OMAP controller pins can be used as IRQ and GPIO independently so is necessary to keep track GPIO pins and IRQ lines usage separately to make sure that the bank will always be enabled while being used. Also move gpio_is_input() definition in preparation for the next patch that setups the controller's irq_chip driver when a caller requests an interrupt line. Cc: [email protected] Acked-by: Stephen Warren <[email protected]> Tested-by: George Cherian <[email protected]> Tested-by: Aaro Koskinen <[email protected]> Tested-by: Lars Poeschel <[email protected]> Reviewed-by: Kevin Hilman <[email protected]> Tested-by: Kevin Hilman <[email protected]> Acked-by: Santosh Shilimkar <[email protected]> Acked-by: Tony Lindgren <[email protected]> Signed-off-by: Javier Martinez Canillas <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 272b98c commit fa365e4

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

drivers/gpio/gpio-omap.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct gpio_bank {
6363
struct gpio_chip chip;
6464
struct clk *dbck;
6565
u32 mod_usage;
66+
u32 irq_usage;
6667
u32 dbck_enable_mask;
6768
bool dbck_enabled;
6869
struct device *dev;
@@ -86,6 +87,9 @@ struct gpio_bank {
8687
#define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
8788
#define GPIO_MOD_CTRL_BIT BIT(0)
8889

90+
#define BANK_USED(bank) (bank->mod_usage || bank->irq_usage)
91+
#define LINE_USED(line, offset) (line & (1 << offset))
92+
8993
static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq)
9094
{
9195
return bank->chip.base + gpio_irq;
@@ -420,14 +424,21 @@ static int _set_gpio_triggering(struct gpio_bank *bank, int gpio,
420424
return 0;
421425
}
422426

427+
static int gpio_is_input(struct gpio_bank *bank, int mask)
428+
{
429+
void __iomem *reg = bank->base + bank->regs->direction;
430+
431+
return __raw_readl(reg) & mask;
432+
}
433+
423434
static int gpio_irq_type(struct irq_data *d, unsigned type)
424435
{
425436
struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
426437
unsigned gpio = 0;
427438
int retval;
428439
unsigned long flags;
429440

430-
if (WARN_ON(!bank->mod_usage))
441+
if (WARN_ON(!BANK_USED(bank)))
431442
return -EINVAL;
432443

433444
#ifdef CONFIG_ARCH_OMAP1
@@ -447,6 +458,7 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
447458

448459
spin_lock_irqsave(&bank->lock, flags);
449460
retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type);
461+
bank->irq_usage |= 1 << GPIO_INDEX(bank, gpio);
450462
spin_unlock_irqrestore(&bank->lock, flags);
451463

452464
if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
@@ -603,7 +615,7 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
603615
* If this is the first gpio_request for the bank,
604616
* enable the bank module.
605617
*/
606-
if (!bank->mod_usage)
618+
if (!BANK_USED(bank))
607619
pm_runtime_get_sync(bank->dev);
608620

609621
spin_lock_irqsave(&bank->lock, flags);
@@ -619,7 +631,7 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
619631
__raw_writel(__raw_readl(reg) | (1 << offset), reg);
620632
}
621633

622-
if (bank->regs->ctrl && !bank->mod_usage) {
634+
if (bank->regs->ctrl && !BANK_USED(bank)) {
623635
void __iomem *reg = bank->base + bank->regs->ctrl;
624636
u32 ctrl;
625637

@@ -654,7 +666,7 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
654666

655667
bank->mod_usage &= ~(1 << offset);
656668

657-
if (bank->regs->ctrl && !bank->mod_usage) {
669+
if (bank->regs->ctrl && !BANK_USED(bank)) {
658670
void __iomem *reg = bank->base + bank->regs->ctrl;
659671
u32 ctrl;
660672

@@ -672,7 +684,7 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
672684
* If this is the last gpio to be freed in the bank,
673685
* disable the bank module.
674686
*/
675-
if (!bank->mod_usage)
687+
if (!BANK_USED(bank))
676688
pm_runtime_put(bank->dev);
677689
}
678690

@@ -762,8 +774,10 @@ static void gpio_irq_shutdown(struct irq_data *d)
762774
struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
763775
unsigned int gpio = irq_to_gpio(bank, d->hwirq);
764776
unsigned long flags;
777+
unsigned offset = GPIO_INDEX(bank, gpio);
765778

766779
spin_lock_irqsave(&bank->lock, flags);
780+
bank->irq_usage &= ~(1 << offset);
767781
_reset_gpio(bank, gpio);
768782
spin_unlock_irqrestore(&bank->lock, flags);
769783
}
@@ -897,13 +911,6 @@ static int gpio_input(struct gpio_chip *chip, unsigned offset)
897911
return 0;
898912
}
899913

900-
static int gpio_is_input(struct gpio_bank *bank, int mask)
901-
{
902-
void __iomem *reg = bank->base + bank->regs->direction;
903-
904-
return __raw_readl(reg) & mask;
905-
}
906-
907914
static int gpio_get(struct gpio_chip *chip, unsigned offset)
908915
{
909916
struct gpio_bank *bank;
@@ -1400,7 +1407,7 @@ void omap2_gpio_prepare_for_idle(int pwr_mode)
14001407
struct gpio_bank *bank;
14011408

14021409
list_for_each_entry(bank, &omap_gpio_list, node) {
1403-
if (!bank->mod_usage || !bank->loses_context)
1410+
if (!BANK_USED(bank) || !bank->loses_context)
14041411
continue;
14051412

14061413
bank->power_mode = pwr_mode;
@@ -1414,7 +1421,7 @@ void omap2_gpio_resume_after_idle(void)
14141421
struct gpio_bank *bank;
14151422

14161423
list_for_each_entry(bank, &omap_gpio_list, node) {
1417-
if (!bank->mod_usage || !bank->loses_context)
1424+
if (!BANK_USED(bank) || !bank->loses_context)
14181425
continue;
14191426

14201427
pm_runtime_get_sync(bank->dev);

0 commit comments

Comments
 (0)