Lines Matching +full:edge +full:- +full:offset

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2003-2005 Nokia Corporation
9 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
27 #include <linux/platform_data/gpio-omap.h>
83 #define BANK_USED(bank) (bank->mod_usage || bank->irq_usage)
84 #define LINE_USED(line, offset) (line & (BIT(offset))) argument
111 bank->context.oe = omap_gpio_rmw(bank->base + bank->regs->direction, in omap_set_gpio_direction()
117 static void omap_set_gpio_dataout_reg(struct gpio_bank *bank, unsigned offset, in omap_set_gpio_dataout_reg() argument
120 void __iomem *reg = bank->base; in omap_set_gpio_dataout_reg()
121 u32 l = BIT(offset); in omap_set_gpio_dataout_reg()
124 reg += bank->regs->set_dataout; in omap_set_gpio_dataout_reg()
125 bank->context.dataout |= l; in omap_set_gpio_dataout_reg()
127 reg += bank->regs->clr_dataout; in omap_set_gpio_dataout_reg()
128 bank->context.dataout &= ~l; in omap_set_gpio_dataout_reg()
135 static void omap_set_gpio_dataout_mask(struct gpio_bank *bank, unsigned offset, in omap_set_gpio_dataout_mask() argument
138 bank->context.dataout = omap_gpio_rmw(bank->base + bank->regs->dataout, in omap_set_gpio_dataout_mask()
139 BIT(offset), enable); in omap_set_gpio_dataout_mask()
144 if (bank->dbck_enable_mask && !bank->dbck_enabled) { in omap_gpio_dbck_enable()
145 clk_enable(bank->dbck); in omap_gpio_dbck_enable()
146 bank->dbck_enabled = true; in omap_gpio_dbck_enable()
148 writel_relaxed(bank->dbck_enable_mask, in omap_gpio_dbck_enable()
149 bank->base + bank->regs->debounce_en); in omap_gpio_dbck_enable()
155 if (bank->dbck_enable_mask && bank->dbck_enabled) { in omap_gpio_dbck_disable()
161 writel_relaxed(0, bank->base + bank->regs->debounce_en); in omap_gpio_dbck_disable()
163 clk_disable(bank->dbck); in omap_gpio_dbck_disable()
164 bank->dbck_enabled = false; in omap_gpio_dbck_disable()
169 * omap2_set_gpio_debounce - low level gpio debounce time
171 * @offset: the gpio number on this @bank
180 static int omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, in omap2_set_gpio_debounce() argument
187 if (!bank->dbck_flag) in omap2_set_gpio_debounce()
188 return -ENOTSUPP; in omap2_set_gpio_debounce()
191 debounce = DIV_ROUND_UP(debounce, 31) - 1; in omap2_set_gpio_debounce()
193 return -EINVAL; in omap2_set_gpio_debounce()
196 l = BIT(offset); in omap2_set_gpio_debounce()
198 clk_enable(bank->dbck); in omap2_set_gpio_debounce()
199 writel_relaxed(debounce, bank->base + bank->regs->debounce); in omap2_set_gpio_debounce()
201 val = omap_gpio_rmw(bank->base + bank->regs->debounce_en, l, enable); in omap2_set_gpio_debounce()
202 bank->dbck_enable_mask = val; in omap2_set_gpio_debounce()
204 clk_disable(bank->dbck); in omap2_set_gpio_debounce()
214 if (bank->dbck_enable_mask) { in omap2_set_gpio_debounce()
215 bank->context.debounce = debounce; in omap2_set_gpio_debounce()
216 bank->context.debounce_en = val; in omap2_set_gpio_debounce()
223 * omap_clear_gpio_debounce - clear debounce settings for a gpio
225 * @offset: the gpio number on this @bank
232 static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset) in omap_clear_gpio_debounce() argument
234 u32 gpio_bit = BIT(offset); in omap_clear_gpio_debounce()
236 if (!bank->dbck_flag) in omap_clear_gpio_debounce()
239 if (!(bank->dbck_enable_mask & gpio_bit)) in omap_clear_gpio_debounce()
242 bank->dbck_enable_mask &= ~gpio_bit; in omap_clear_gpio_debounce()
243 bank->context.debounce_en &= ~gpio_bit; in omap_clear_gpio_debounce()
244 writel_relaxed(bank->context.debounce_en, in omap_clear_gpio_debounce()
245 bank->base + bank->regs->debounce_en); in omap_clear_gpio_debounce()
247 if (!bank->dbck_enable_mask) { in omap_clear_gpio_debounce()
248 bank->context.debounce = 0; in omap_clear_gpio_debounce()
249 writel_relaxed(bank->context.debounce, bank->base + in omap_clear_gpio_debounce()
250 bank->regs->debounce); in omap_clear_gpio_debounce()
251 clk_disable(bank->dbck); in omap_clear_gpio_debounce()
252 bank->dbck_enabled = false; in omap_clear_gpio_debounce()
257 * Off mode wake-up capable GPIOs in bank(s) that are in the wakeup domain.
258 * See TRM section for GPIO for "Wake-Up Generation" for the list of GPIOs
259 * in wakeup domain. If bank->non_wakeup_gpios is not configured, assume none
264 u32 no_wake = bank->non_wakeup_gpios; in omap_gpio_is_off_wakeup_capable()
275 void __iomem *base = bank->base; in omap_set_gpio_trigger()
278 omap_gpio_rmw(base + bank->regs->leveldetect0, gpio_bit, in omap_set_gpio_trigger()
280 omap_gpio_rmw(base + bank->regs->leveldetect1, gpio_bit, in omap_set_gpio_trigger()
284 * We need the edge detection enabled for to allow the GPIO block in omap_set_gpio_trigger()
285 * to be woken from idle state. Set the appropriate edge detection in omap_set_gpio_trigger()
288 omap_gpio_rmw(base + bank->regs->risingdetect, gpio_bit, in omap_set_gpio_trigger()
290 omap_gpio_rmw(base + bank->regs->fallingdetect, gpio_bit, in omap_set_gpio_trigger()
293 bank->context.leveldetect0 = in omap_set_gpio_trigger()
294 readl_relaxed(bank->base + bank->regs->leveldetect0); in omap_set_gpio_trigger()
295 bank->context.leveldetect1 = in omap_set_gpio_trigger()
296 readl_relaxed(bank->base + bank->regs->leveldetect1); in omap_set_gpio_trigger()
297 bank->context.risingdetect = in omap_set_gpio_trigger()
298 readl_relaxed(bank->base + bank->regs->risingdetect); in omap_set_gpio_trigger()
299 bank->context.fallingdetect = in omap_set_gpio_trigger()
300 readl_relaxed(bank->base + bank->regs->fallingdetect); in omap_set_gpio_trigger()
302 bank->level_mask = bank->context.leveldetect0 | in omap_set_gpio_trigger()
303 bank->context.leveldetect1; in omap_set_gpio_trigger()
306 if (!bank->regs->irqctrl && !omap_gpio_is_off_wakeup_capable(bank, gpio)) { in omap_set_gpio_trigger()
308 * Log the edge gpio and manually trigger the IRQ in omap_set_gpio_trigger()
311 * Applies for omap2 non-wakeup gpio and all omap3 gpios in omap_set_gpio_trigger()
314 bank->enabled_non_wakeup_gpios |= gpio_bit; in omap_set_gpio_trigger()
316 bank->enabled_non_wakeup_gpios &= ~gpio_bit; in omap_set_gpio_trigger()
321 * This only applies to chips that can't do both rising and falling edge
326 if (IS_ENABLED(CONFIG_ARCH_OMAP1) && bank->regs->irqctrl) { in omap_toggle_gpio_edge_triggering()
327 void __iomem *reg = bank->base + bank->regs->irqctrl; in omap_toggle_gpio_edge_triggering()
336 void __iomem *reg = bank->base; in omap_set_gpio_triggering()
339 if (bank->regs->leveldetect0 && bank->regs->wkup_en) { in omap_set_gpio_triggering()
341 } else if (bank->regs->irqctrl) { in omap_set_gpio_triggering()
342 reg += bank->regs->irqctrl; in omap_set_gpio_triggering()
346 bank->toggle_mask |= BIT(gpio); in omap_set_gpio_triggering()
352 return -EINVAL; in omap_set_gpio_triggering()
355 } else if (bank->regs->edgectrl1) { in omap_set_gpio_triggering()
357 reg += bank->regs->edgectrl2; in omap_set_gpio_triggering()
359 reg += bank->regs->edgectrl1; in omap_set_gpio_triggering()
373 static void omap_enable_gpio_module(struct gpio_bank *bank, unsigned offset) in omap_enable_gpio_module() argument
375 if (bank->regs->pinctrl) { in omap_enable_gpio_module()
376 void __iomem *reg = bank->base + bank->regs->pinctrl; in omap_enable_gpio_module()
379 writel_relaxed(readl_relaxed(reg) | (BIT(offset)), reg); in omap_enable_gpio_module()
382 if (bank->regs->ctrl && !BANK_USED(bank)) { in omap_enable_gpio_module()
383 void __iomem *reg = bank->base + bank->regs->ctrl; in omap_enable_gpio_module()
390 bank->context.ctrl = ctrl; in omap_enable_gpio_module()
394 static void omap_disable_gpio_module(struct gpio_bank *bank, unsigned offset) in omap_disable_gpio_module() argument
396 if (bank->regs->ctrl && !BANK_USED(bank)) { in omap_disable_gpio_module()
397 void __iomem *reg = bank->base + bank->regs->ctrl; in omap_disable_gpio_module()
404 bank->context.ctrl = ctrl; in omap_disable_gpio_module()
408 static int omap_gpio_is_input(struct gpio_bank *bank, unsigned offset) in omap_gpio_is_input() argument
410 void __iomem *reg = bank->base + bank->regs->direction; in omap_gpio_is_input()
412 return readl_relaxed(reg) & BIT(offset); in omap_gpio_is_input()
415 static void omap_gpio_init_irq(struct gpio_bank *bank, unsigned offset) in omap_gpio_init_irq() argument
417 if (!LINE_USED(bank->mod_usage, offset)) { in omap_gpio_init_irq()
418 omap_enable_gpio_module(bank, offset); in omap_gpio_init_irq()
419 omap_set_gpio_direction(bank, offset, 1); in omap_gpio_init_irq()
421 bank->irq_usage |= BIT(offset); in omap_gpio_init_irq()
429 unsigned offset = d->hwirq; in omap_gpio_irq_type() local
432 return -EINVAL; in omap_gpio_irq_type()
434 if (!bank->regs->leveldetect0 && in omap_gpio_irq_type()
436 return -EINVAL; in omap_gpio_irq_type()
438 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_irq_type()
439 retval = omap_set_gpio_triggering(bank, offset, type); in omap_gpio_irq_type()
441 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_irq_type()
444 omap_gpio_init_irq(bank, offset); in omap_gpio_irq_type()
445 if (!omap_gpio_is_input(bank, offset)) { in omap_gpio_irq_type()
446 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_irq_type()
447 retval = -EINVAL; in omap_gpio_irq_type()
450 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_irq_type()
456 * Edge IRQs are already cleared/acked in irq_handler and in omap_gpio_irq_type()
471 void __iomem *reg = bank->base; in omap_clear_gpio_irqbank()
473 reg += bank->regs->irqstatus; in omap_clear_gpio_irqbank()
477 if (bank->regs->irqstatus2) { in omap_clear_gpio_irqbank()
478 reg = bank->base + bank->regs->irqstatus2; in omap_clear_gpio_irqbank()
487 unsigned offset) in omap_clear_gpio_irqstatus() argument
489 omap_clear_gpio_irqbank(bank, BIT(offset)); in omap_clear_gpio_irqstatus()
494 void __iomem *reg = bank->base; in omap_get_gpio_irqbank_mask()
496 u32 mask = (BIT(bank->width)) - 1; in omap_get_gpio_irqbank_mask()
498 reg += bank->regs->irqenable; in omap_get_gpio_irqbank_mask()
500 if (bank->regs->irqenable_inv) in omap_get_gpio_irqbank_mask()
507 unsigned offset, int enable) in omap_set_gpio_irqenable() argument
509 void __iomem *reg = bank->base; in omap_set_gpio_irqenable()
510 u32 gpio_mask = BIT(offset); in omap_set_gpio_irqenable()
512 if (bank->regs->set_irqenable && bank->regs->clr_irqenable) { in omap_set_gpio_irqenable()
514 reg += bank->regs->set_irqenable; in omap_set_gpio_irqenable()
515 bank->context.irqenable1 |= gpio_mask; in omap_set_gpio_irqenable()
517 reg += bank->regs->clr_irqenable; in omap_set_gpio_irqenable()
518 bank->context.irqenable1 &= ~gpio_mask; in omap_set_gpio_irqenable()
522 bank->context.irqenable1 = in omap_set_gpio_irqenable()
523 omap_gpio_rmw(reg + bank->regs->irqenable, gpio_mask, in omap_set_gpio_irqenable()
524 enable ^ bank->regs->irqenable_inv); in omap_set_gpio_irqenable()
533 if (bank->regs->wkup_en && in omap_set_gpio_irqenable()
534 (bank->regs->edgectrl1 || !(bank->non_wakeup_gpios & gpio_mask))) { in omap_set_gpio_irqenable()
535 bank->context.wake_en = in omap_set_gpio_irqenable()
536 omap_gpio_rmw(bank->base + bank->regs->wkup_en, in omap_set_gpio_irqenable()
546 return irq_set_irq_wake(bank->irq, enable); in omap_gpio_wake_enable()
552 * Then we need to mask-read-clear-unmask the triggered GPIO lines
561 u32 enabled, isr, edge; in omap_gpio_irq_handler() local
567 isr_reg = bank->base + bank->regs->irqstatus; in omap_gpio_irq_handler()
571 if (WARN_ONCE(!pm_runtime_active(bank->chip.parent), in omap_gpio_irq_handler()
576 raw_spin_lock_irqsave(&bank->lock, lock_flags); in omap_gpio_irq_handler()
582 * Clear edge sensitive interrupts before calling handler(s) in omap_gpio_irq_handler()
583 * so subsequent edge transitions are not missed while the in omap_gpio_irq_handler()
586 edge = isr & ~bank->level_mask; in omap_gpio_irq_handler()
587 if (edge) in omap_gpio_irq_handler()
588 omap_clear_gpio_irqbank(bank, edge); in omap_gpio_irq_handler()
590 raw_spin_unlock_irqrestore(&bank->lock, lock_flags); in omap_gpio_irq_handler()
599 raw_spin_lock_irqsave(&bank->lock, lock_flags); in omap_gpio_irq_handler()
607 if (bank->toggle_mask & (BIT(bit))) in omap_gpio_irq_handler()
610 raw_spin_unlock_irqrestore(&bank->lock, lock_flags); in omap_gpio_irq_handler()
612 raw_spin_lock_irqsave(&bank->wa_lock, wa_lock_flags); in omap_gpio_irq_handler()
614 generic_handle_domain_irq(bank->chip.irq.domain, bit); in omap_gpio_irq_handler()
616 raw_spin_unlock_irqrestore(&bank->wa_lock, in omap_gpio_irq_handler()
628 unsigned offset = d->hwirq; in omap_gpio_irq_startup() local
630 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_irq_startup()
632 if (!LINE_USED(bank->mod_usage, offset)) in omap_gpio_irq_startup()
633 omap_set_gpio_direction(bank, offset, 1); in omap_gpio_irq_startup()
634 omap_enable_gpio_module(bank, offset); in omap_gpio_irq_startup()
635 bank->irq_usage |= BIT(offset); in omap_gpio_irq_startup()
637 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_irq_startup()
647 unsigned offset = d->hwirq; in omap_gpio_irq_shutdown() local
649 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_irq_shutdown()
650 bank->irq_usage &= ~(BIT(offset)); in omap_gpio_irq_shutdown()
651 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); in omap_gpio_irq_shutdown()
652 omap_clear_gpio_irqstatus(bank, offset); in omap_gpio_irq_shutdown()
653 omap_set_gpio_irqenable(bank, offset, 0); in omap_gpio_irq_shutdown()
654 if (!LINE_USED(bank->mod_usage, offset)) in omap_gpio_irq_shutdown()
655 omap_clear_gpio_debounce(bank, offset); in omap_gpio_irq_shutdown()
656 omap_disable_gpio_module(bank, offset); in omap_gpio_irq_shutdown()
657 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_irq_shutdown()
664 pm_runtime_get_sync(bank->chip.parent); in omap_gpio_irq_bus_lock()
671 pm_runtime_put(bank->chip.parent); in gpio_irq_bus_sync_unlock()
677 unsigned offset = d->hwirq; in omap_gpio_mask_irq() local
680 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_mask_irq()
681 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); in omap_gpio_mask_irq()
682 omap_set_gpio_irqenable(bank, offset, 0); in omap_gpio_mask_irq()
683 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_mask_irq()
689 unsigned offset = d->hwirq; in omap_gpio_unmask_irq() local
693 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_unmask_irq()
694 omap_set_gpio_irqenable(bank, offset, 1); in omap_gpio_unmask_irq()
697 * For level-triggered GPIOs, clearing must be done after the source in omap_gpio_unmask_irq()
701 if (bank->regs->leveldetect0 && bank->regs->wkup_en && in omap_gpio_unmask_irq()
703 omap_clear_gpio_irqstatus(bank, offset); in omap_gpio_unmask_irq()
706 omap_set_gpio_triggering(bank, offset, trigger); in omap_gpio_unmask_irq()
708 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_unmask_irq()
711 /*---------------------------------------------------------------------*/
716 void __iomem *mask_reg = bank->base + in omap_mpuio_suspend_noirq()
717 OMAP_MPUIO_GPIO_MASKIT / bank->stride; in omap_mpuio_suspend_noirq()
720 raw_spin_lock_irqsave(&bank->lock, flags); in omap_mpuio_suspend_noirq()
721 writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg); in omap_mpuio_suspend_noirq()
722 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_mpuio_suspend_noirq()
730 void __iomem *mask_reg = bank->base + in omap_mpuio_resume_noirq()
731 OMAP_MPUIO_GPIO_MASKIT / bank->stride; in omap_mpuio_resume_noirq()
734 raw_spin_lock_irqsave(&bank->lock, flags); in omap_mpuio_resume_noirq()
735 writel_relaxed(bank->context.wake_en, mask_reg); in omap_mpuio_resume_noirq()
736 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_mpuio_resume_noirq()
756 .id = -1,
771 /*---------------------------------------------------------------------*/
773 static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) in omap_gpio_request() argument
778 pm_runtime_get_sync(chip->parent); in omap_gpio_request()
780 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_request()
781 omap_enable_gpio_module(bank, offset); in omap_gpio_request()
782 bank->mod_usage |= BIT(offset); in omap_gpio_request()
783 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_request()
788 static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) in omap_gpio_free() argument
793 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_free()
794 bank->mod_usage &= ~(BIT(offset)); in omap_gpio_free()
795 if (!LINE_USED(bank->irq_usage, offset)) { in omap_gpio_free()
796 omap_set_gpio_direction(bank, offset, 1); in omap_gpio_free()
797 omap_clear_gpio_debounce(bank, offset); in omap_gpio_free()
799 omap_disable_gpio_module(bank, offset); in omap_gpio_free()
800 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_free()
802 pm_runtime_put(chip->parent); in omap_gpio_free()
805 static int omap_gpio_get_direction(struct gpio_chip *chip, unsigned offset) in omap_gpio_get_direction() argument
809 if (readl_relaxed(bank->base + bank->regs->direction) & BIT(offset)) in omap_gpio_get_direction()
815 static int omap_gpio_input(struct gpio_chip *chip, unsigned offset) in omap_gpio_input() argument
821 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_input()
822 omap_set_gpio_direction(bank, offset, 1); in omap_gpio_input()
823 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_input()
827 static int omap_gpio_get(struct gpio_chip *chip, unsigned offset) in omap_gpio_get() argument
832 if (omap_gpio_is_input(bank, offset)) in omap_gpio_get()
833 reg = bank->base + bank->regs->datain; in omap_gpio_get()
835 reg = bank->base + bank->regs->dataout; in omap_gpio_get()
837 return (readl_relaxed(reg) & BIT(offset)) != 0; in omap_gpio_get()
840 static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value) in omap_gpio_output() argument
846 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_output()
847 bank->set_dataout(bank, offset, value); in omap_gpio_output()
848 omap_set_gpio_direction(bank, offset, 0); in omap_gpio_output()
849 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_output()
857 void __iomem *base = bank->base; in omap_gpio_get_multiple()
860 direction = readl_relaxed(base + bank->regs->direction); in omap_gpio_get_multiple()
864 val |= readl_relaxed(base + bank->regs->datain) & m; in omap_gpio_get_multiple()
868 val |= readl_relaxed(base + bank->regs->dataout) & m; in omap_gpio_get_multiple()
875 static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset, in omap_gpio_debounce() argument
884 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_debounce()
885 ret = omap2_set_gpio_debounce(bank, offset, debounce); in omap_gpio_debounce()
886 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_debounce()
889 dev_info(chip->parent, in omap_gpio_debounce()
891 offset, debounce, ret); in omap_gpio_debounce()
896 static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, in omap_gpio_set_config() argument
900 int ret = -ENOTSUPP; in omap_gpio_set_config()
906 ret = gpiochip_generic_config(chip, offset, config); in omap_gpio_set_config()
910 ret = omap_gpio_debounce(chip, offset, debounce); in omap_gpio_set_config()
919 static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value) in omap_gpio_set() argument
925 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_set()
926 bank->set_dataout(bank, offset, value); in omap_gpio_set()
927 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_set()
934 void __iomem *reg = bank->base + bank->regs->dataout; in omap_gpio_set_multiple()
938 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_set_multiple()
941 bank->context.dataout = l; in omap_gpio_set_multiple()
942 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_set_multiple()
945 /*---------------------------------------------------------------------*/
952 if (called || bank->regs->revision == USHRT_MAX) in omap_gpio_show_rev()
955 rev = readw_relaxed(bank->base + bank->regs->revision); in omap_gpio_show_rev()
964 void __iomem *base = bank->base; in omap_gpio_mod_init()
967 if (bank->width == 16) in omap_gpio_mod_init()
970 if (bank->is_mpuio) { in omap_gpio_mod_init()
971 writel_relaxed(l, bank->base + bank->regs->irqenable); in omap_gpio_mod_init()
975 omap_gpio_rmw(base + bank->regs->irqenable, l, in omap_gpio_mod_init()
976 bank->regs->irqenable_inv); in omap_gpio_mod_init()
977 omap_gpio_rmw(base + bank->regs->irqstatus, l, in omap_gpio_mod_init()
978 !bank->regs->irqenable_inv); in omap_gpio_mod_init()
979 if (bank->regs->debounce_en) in omap_gpio_mod_init()
980 writel_relaxed(0, base + bank->regs->debounce_en); in omap_gpio_mod_init()
983 bank->context.oe = readl_relaxed(bank->base + bank->regs->direction); in omap_gpio_mod_init()
985 if (bank->regs->ctrl) in omap_gpio_mod_init()
986 writel_relaxed(0, base + bank->regs->ctrl); in omap_gpio_mod_init()
999 * REVISIT eventually switch from OMAP-specific gpio structs in omap_gpio_chip_init()
1002 bank->chip.request = omap_gpio_request; in omap_gpio_chip_init()
1003 bank->chip.free = omap_gpio_free; in omap_gpio_chip_init()
1004 bank->chip.get_direction = omap_gpio_get_direction; in omap_gpio_chip_init()
1005 bank->chip.direction_input = omap_gpio_input; in omap_gpio_chip_init()
1006 bank->chip.get = omap_gpio_get; in omap_gpio_chip_init()
1007 bank->chip.get_multiple = omap_gpio_get_multiple; in omap_gpio_chip_init()
1008 bank->chip.direction_output = omap_gpio_output; in omap_gpio_chip_init()
1009 bank->chip.set_config = omap_gpio_set_config; in omap_gpio_chip_init()
1010 bank->chip.set = omap_gpio_set; in omap_gpio_chip_init()
1011 bank->chip.set_multiple = omap_gpio_set_multiple; in omap_gpio_chip_init()
1012 if (bank->is_mpuio) { in omap_gpio_chip_init()
1013 bank->chip.label = "mpuio"; in omap_gpio_chip_init()
1014 if (bank->regs->wkup_en) in omap_gpio_chip_init()
1015 bank->chip.parent = &omap_mpuio_device.dev; in omap_gpio_chip_init()
1016 bank->chip.base = OMAP_MPUIO(0); in omap_gpio_chip_init()
1018 label = devm_kasprintf(bank->chip.parent, GFP_KERNEL, "gpio-%d-%d", in omap_gpio_chip_init()
1019 gpio, gpio + bank->width - 1); in omap_gpio_chip_init()
1021 return -ENOMEM; in omap_gpio_chip_init()
1022 bank->chip.label = label; in omap_gpio_chip_init()
1023 bank->chip.base = gpio; in omap_gpio_chip_init()
1025 bank->chip.ngpio = bank->width; in omap_gpio_chip_init()
1030 * irq_alloc_descs() since a base IRQ offset will no longer be needed. in omap_gpio_chip_init()
1032 irq_base = devm_irq_alloc_descs(bank->chip.parent, in omap_gpio_chip_init()
1033 -1, 0, bank->width, 0); in omap_gpio_chip_init()
1035 dev_err(bank->chip.parent, "Couldn't allocate IRQ numbers\n"); in omap_gpio_chip_init()
1036 return -ENODEV; in omap_gpio_chip_init()
1041 if (bank->is_mpuio && !bank->regs->wkup_en) in omap_gpio_chip_init()
1042 irqc->irq_set_wake = NULL; in omap_gpio_chip_init()
1044 irq = &bank->chip.irq; in omap_gpio_chip_init()
1045 irq->chip = irqc; in omap_gpio_chip_init()
1046 irq->handler = handle_bad_irq; in omap_gpio_chip_init()
1047 irq->default_type = IRQ_TYPE_NONE; in omap_gpio_chip_init()
1048 irq->num_parents = 1; in omap_gpio_chip_init()
1049 irq->parents = &bank->irq; in omap_gpio_chip_init()
1050 irq->first = irq_base; in omap_gpio_chip_init()
1052 ret = gpiochip_add_data(&bank->chip, bank); in omap_gpio_chip_init()
1054 return dev_err_probe(bank->chip.parent, ret, "Could not register gpio chip\n"); in omap_gpio_chip_init()
1056 irq_domain_set_pm_device(bank->chip.irq.domain, pm_dev); in omap_gpio_chip_init()
1057 ret = devm_request_irq(bank->chip.parent, bank->irq, in omap_gpio_chip_init()
1059 0, dev_name(bank->chip.parent), bank); in omap_gpio_chip_init()
1061 gpiochip_remove(&bank->chip); in omap_gpio_chip_init()
1063 if (!bank->is_mpuio) in omap_gpio_chip_init()
1064 gpio += bank->width; in omap_gpio_chip_init()
1071 const struct omap_gpio_reg_offs *regs = p->regs; in omap_gpio_init_context()
1072 void __iomem *base = p->base; in omap_gpio_init_context()
1074 p->context.sysconfig = readl_relaxed(base + regs->sysconfig); in omap_gpio_init_context()
1075 p->context.ctrl = readl_relaxed(base + regs->ctrl); in omap_gpio_init_context()
1076 p->context.oe = readl_relaxed(base + regs->direction); in omap_gpio_init_context()
1077 p->context.wake_en = readl_relaxed(base + regs->wkup_en); in omap_gpio_init_context()
1078 p->context.leveldetect0 = readl_relaxed(base + regs->leveldetect0); in omap_gpio_init_context()
1079 p->context.leveldetect1 = readl_relaxed(base + regs->leveldetect1); in omap_gpio_init_context()
1080 p->context.risingdetect = readl_relaxed(base + regs->risingdetect); in omap_gpio_init_context()
1081 p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect); in omap_gpio_init_context()
1082 p->context.irqenable1 = readl_relaxed(base + regs->irqenable); in omap_gpio_init_context()
1083 p->context.irqenable2 = readl_relaxed(base + regs->irqenable2); in omap_gpio_init_context()
1084 p->context.dataout = readl_relaxed(base + regs->dataout); in omap_gpio_init_context()
1086 p->context_valid = true; in omap_gpio_init_context()
1091 const struct omap_gpio_reg_offs *regs = bank->regs; in omap_gpio_restore_context()
1092 void __iomem *base = bank->base; in omap_gpio_restore_context()
1094 writel_relaxed(bank->context.sysconfig, base + regs->sysconfig); in omap_gpio_restore_context()
1095 writel_relaxed(bank->context.wake_en, base + regs->wkup_en); in omap_gpio_restore_context()
1096 writel_relaxed(bank->context.ctrl, base + regs->ctrl); in omap_gpio_restore_context()
1097 writel_relaxed(bank->context.leveldetect0, base + regs->leveldetect0); in omap_gpio_restore_context()
1098 writel_relaxed(bank->context.leveldetect1, base + regs->leveldetect1); in omap_gpio_restore_context()
1099 writel_relaxed(bank->context.risingdetect, base + regs->risingdetect); in omap_gpio_restore_context()
1100 writel_relaxed(bank->context.fallingdetect, base + regs->fallingdetect); in omap_gpio_restore_context()
1101 writel_relaxed(bank->context.dataout, base + regs->dataout); in omap_gpio_restore_context()
1102 writel_relaxed(bank->context.oe, base + regs->direction); in omap_gpio_restore_context()
1104 if (bank->dbck_enable_mask) { in omap_gpio_restore_context()
1105 writel_relaxed(bank->context.debounce, base + regs->debounce); in omap_gpio_restore_context()
1106 writel_relaxed(bank->context.debounce_en, in omap_gpio_restore_context()
1107 base + regs->debounce_en); in omap_gpio_restore_context()
1110 writel_relaxed(bank->context.irqenable1, base + regs->irqenable); in omap_gpio_restore_context()
1111 writel_relaxed(bank->context.irqenable2, base + regs->irqenable2); in omap_gpio_restore_context()
1116 struct device *dev = bank->chip.parent; in omap_gpio_idle()
1117 void __iomem *base = bank->base; in omap_gpio_idle()
1120 bank->saved_datain = readl_relaxed(base + bank->regs->datain); in omap_gpio_idle()
1123 if (bank->loses_context) in omap_gpio_idle()
1124 bank->context.sysconfig = readl_relaxed(base + bank->regs->sysconfig); in omap_gpio_idle()
1126 if (!bank->enabled_non_wakeup_gpios) in omap_gpio_idle()
1130 mask = bank->enabled_non_wakeup_gpios & bank->context.fallingdetect; in omap_gpio_idle()
1131 mask &= ~bank->context.risingdetect; in omap_gpio_idle()
1132 bank->saved_datain |= mask; in omap_gpio_idle()
1135 mask = bank->enabled_non_wakeup_gpios & bank->context.risingdetect; in omap_gpio_idle()
1136 mask &= ~bank->context.fallingdetect; in omap_gpio_idle()
1137 bank->saved_datain &= ~mask; in omap_gpio_idle()
1144 * non-wakeup GPIOs. Otherwise spurious IRQs will be in omap_gpio_idle()
1147 if (!bank->loses_context && bank->enabled_non_wakeup_gpios) { in omap_gpio_idle()
1148 nowake = bank->enabled_non_wakeup_gpios; in omap_gpio_idle()
1149 omap_gpio_rmw(base + bank->regs->fallingdetect, nowake, ~nowake); in omap_gpio_idle()
1150 omap_gpio_rmw(base + bank->regs->risingdetect, nowake, ~nowake); in omap_gpio_idle()
1154 if (bank->get_context_loss_count) in omap_gpio_idle()
1155 bank->context_loss_count = in omap_gpio_idle()
1156 bank->get_context_loss_count(dev); in omap_gpio_idle()
1163 struct device *dev = bank->chip.parent; in omap_gpio_unidle()
1172 if (bank->loses_context && !bank->context_valid) { in omap_gpio_unidle()
1175 if (bank->get_context_loss_count) in omap_gpio_unidle()
1176 bank->context_loss_count = in omap_gpio_unidle()
1177 bank->get_context_loss_count(dev); in omap_gpio_unidle()
1182 if (bank->loses_context) { in omap_gpio_unidle()
1183 if (!bank->get_context_loss_count) { in omap_gpio_unidle()
1186 c = bank->get_context_loss_count(dev); in omap_gpio_unidle()
1187 if (c != bank->context_loss_count) { in omap_gpio_unidle()
1195 writel_relaxed(bank->context.fallingdetect, in omap_gpio_unidle()
1196 bank->base + bank->regs->fallingdetect); in omap_gpio_unidle()
1197 writel_relaxed(bank->context.risingdetect, in omap_gpio_unidle()
1198 bank->base + bank->regs->risingdetect); in omap_gpio_unidle()
1201 l = readl_relaxed(bank->base + bank->regs->datain); in omap_gpio_unidle()
1204 * Check if any of the non-wakeup interrupt GPIOs have changed in omap_gpio_unidle()
1209 l ^= bank->saved_datain; in omap_gpio_unidle()
1210 l &= bank->enabled_non_wakeup_gpios; in omap_gpio_unidle()
1213 * No need to generate IRQs for the rising edge for gpio IRQs in omap_gpio_unidle()
1214 * configured with falling edge only; and vice versa. in omap_gpio_unidle()
1216 gen0 = l & bank->context.fallingdetect; in omap_gpio_unidle()
1217 gen0 &= bank->saved_datain; in omap_gpio_unidle()
1219 gen1 = l & bank->context.risingdetect; in omap_gpio_unidle()
1220 gen1 &= ~(bank->saved_datain); in omap_gpio_unidle()
1223 gen = l & (~(bank->context.fallingdetect) & in omap_gpio_unidle()
1224 ~(bank->context.risingdetect)); in omap_gpio_unidle()
1231 old0 = readl_relaxed(bank->base + bank->regs->leveldetect0); in omap_gpio_unidle()
1232 old1 = readl_relaxed(bank->base + bank->regs->leveldetect1); in omap_gpio_unidle()
1234 if (!bank->regs->irqstatus_raw0) { in omap_gpio_unidle()
1235 writel_relaxed(old0 | gen, bank->base + in omap_gpio_unidle()
1236 bank->regs->leveldetect0); in omap_gpio_unidle()
1237 writel_relaxed(old1 | gen, bank->base + in omap_gpio_unidle()
1238 bank->regs->leveldetect1); in omap_gpio_unidle()
1241 if (bank->regs->irqstatus_raw0) { in omap_gpio_unidle()
1242 writel_relaxed(old0 | l, bank->base + in omap_gpio_unidle()
1243 bank->regs->leveldetect0); in omap_gpio_unidle()
1244 writel_relaxed(old1 | l, bank->base + in omap_gpio_unidle()
1245 bank->regs->leveldetect1); in omap_gpio_unidle()
1247 writel_relaxed(old0, bank->base + bank->regs->leveldetect0); in omap_gpio_unidle()
1248 writel_relaxed(old1, bank->base + bank->regs->leveldetect1); in omap_gpio_unidle()
1262 raw_spin_lock_irqsave(&bank->lock, flags); in gpio_omap_cpu_notifier()
1263 if (bank->is_suspended) in gpio_omap_cpu_notifier()
1269 isr = readl_relaxed(bank->base + bank->regs->irqstatus) & mask; in gpio_omap_cpu_notifier()
1283 raw_spin_unlock_irqrestore(&bank->lock, flags); in gpio_omap_cpu_notifier()
1358 .compatible = "ti,omap4-gpio",
1362 .compatible = "ti,omap3-gpio",
1366 .compatible = "ti,omap2-gpio",
1375 struct device *dev = &pdev->dev; in omap_gpio_probe()
1376 struct device_node *node = dev->of_node; in omap_gpio_probe()
1386 return -EINVAL; in omap_gpio_probe()
1390 return -ENOMEM; in omap_gpio_probe()
1394 return -ENOMEM; in omap_gpio_probe()
1396 irqc->irq_startup = omap_gpio_irq_startup, in omap_gpio_probe()
1397 irqc->irq_shutdown = omap_gpio_irq_shutdown, in omap_gpio_probe()
1398 irqc->irq_ack = dummy_irq_chip.irq_ack, in omap_gpio_probe()
1399 irqc->irq_mask = omap_gpio_mask_irq, in omap_gpio_probe()
1400 irqc->irq_unmask = omap_gpio_unmask_irq, in omap_gpio_probe()
1401 irqc->irq_set_type = omap_gpio_irq_type, in omap_gpio_probe()
1402 irqc->irq_set_wake = omap_gpio_wake_enable, in omap_gpio_probe()
1403 irqc->irq_bus_lock = omap_gpio_irq_bus_lock, in omap_gpio_probe()
1404 irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock, in omap_gpio_probe()
1405 irqc->name = dev_name(&pdev->dev); in omap_gpio_probe()
1406 irqc->flags = IRQCHIP_MASK_ON_SUSPEND; in omap_gpio_probe()
1408 bank->irq = platform_get_irq(pdev, 0); in omap_gpio_probe()
1409 if (bank->irq <= 0) { in omap_gpio_probe()
1410 if (!bank->irq) in omap_gpio_probe()
1411 bank->irq = -ENXIO; in omap_gpio_probe()
1412 return dev_err_probe(dev, bank->irq, "can't get irq resource\n"); in omap_gpio_probe()
1415 bank->chip.parent = dev; in omap_gpio_probe()
1416 bank->chip.owner = THIS_MODULE; in omap_gpio_probe()
1417 bank->dbck_flag = pdata->dbck_flag; in omap_gpio_probe()
1418 bank->stride = pdata->bank_stride; in omap_gpio_probe()
1419 bank->width = pdata->bank_width; in omap_gpio_probe()
1420 bank->is_mpuio = pdata->is_mpuio; in omap_gpio_probe()
1421 bank->non_wakeup_gpios = pdata->non_wakeup_gpios; in omap_gpio_probe()
1422 bank->regs = pdata->regs; in omap_gpio_probe()
1425 if (!of_property_read_bool(node, "ti,gpio-always-on")) in omap_gpio_probe()
1426 bank->loses_context = true; in omap_gpio_probe()
1428 bank->loses_context = pdata->loses_context; in omap_gpio_probe()
1430 if (bank->loses_context) in omap_gpio_probe()
1431 bank->get_context_loss_count = in omap_gpio_probe()
1432 pdata->get_context_loss_count; in omap_gpio_probe()
1435 if (bank->regs->set_dataout && bank->regs->clr_dataout) in omap_gpio_probe()
1436 bank->set_dataout = omap_set_gpio_dataout_reg; in omap_gpio_probe()
1438 bank->set_dataout = omap_set_gpio_dataout_mask; in omap_gpio_probe()
1440 raw_spin_lock_init(&bank->lock); in omap_gpio_probe()
1441 raw_spin_lock_init(&bank->wa_lock); in omap_gpio_probe()
1444 bank->base = devm_platform_ioremap_resource(pdev, 0); in omap_gpio_probe()
1445 if (IS_ERR(bank->base)) { in omap_gpio_probe()
1446 return PTR_ERR(bank->base); in omap_gpio_probe()
1449 if (bank->dbck_flag) { in omap_gpio_probe()
1450 bank->dbck = devm_clk_get(dev, "dbclk"); in omap_gpio_probe()
1451 if (IS_ERR(bank->dbck)) { in omap_gpio_probe()
1454 bank->dbck_flag = false; in omap_gpio_probe()
1456 clk_prepare(bank->dbck); in omap_gpio_probe()
1465 if (bank->is_mpuio) in omap_gpio_probe()
1474 if (bank->dbck_flag) in omap_gpio_probe()
1475 clk_unprepare(bank->dbck); in omap_gpio_probe()
1481 bank->nb.notifier_call = gpio_omap_cpu_notifier; in omap_gpio_probe()
1482 cpu_pm_register_notifier(&bank->nb); in omap_gpio_probe()
1493 cpu_pm_unregister_notifier(&bank->nb); in omap_gpio_remove()
1494 gpiochip_remove(&bank->chip); in omap_gpio_remove()
1495 pm_runtime_disable(&pdev->dev); in omap_gpio_remove()
1496 if (bank->dbck_flag) in omap_gpio_remove()
1497 clk_unprepare(bank->dbck); in omap_gpio_remove()
1507 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_runtime_suspend()
1509 bank->is_suspended = true; in omap_gpio_runtime_suspend()
1510 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_runtime_suspend()
1520 raw_spin_lock_irqsave(&bank->lock, flags); in omap_gpio_runtime_resume()
1522 bank->is_suspended = false; in omap_gpio_runtime_resume()
1523 raw_spin_unlock_irqrestore(&bank->lock, flags); in omap_gpio_runtime_resume()
1532 if (bank->is_suspended) in omap_gpio_suspend()
1535 bank->needs_resume = 1; in omap_gpio_suspend()
1544 if (!bank->needs_resume) in omap_gpio_resume()
1547 bank->needs_resume = 0; in omap_gpio_resume()
1586 MODULE_ALIAS("platform:gpio-omap");