Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1 | /* |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2 | * Support functions for OMAP GPIO |
| 3 | * |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 4 | * Copyright (C) 2003-2005 Nokia Corporation |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 5 | * Written by Juha Yrjölä <juha.yrjola@nokia.com> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 6 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 7 | * Copyright (C) 2009 Texas Instruments |
| 8 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
| 9 | * |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 18 | #include <linux/syscore_ops.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 19 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 20 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 22 | #include <linux/cpu_pm.h> |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame] | 23 | #include <linux/device.h> |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 24 | #include <linux/pm_runtime.h> |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 25 | #include <linux/pm.h> |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 26 | #include <linux/of.h> |
| 27 | #include <linux/of_device.h> |
Linus Walleij | b7351b0 | 2018-05-24 14:24:00 +0200 | [diff] [blame] | 28 | #include <linux/gpio/driver.h> |
Yegor Yefremov | 9370084 | 2014-04-24 08:57:39 +0200 | [diff] [blame] | 29 | #include <linux/bitops.h> |
Tony Lindgren | 4b25408 | 2012-08-30 15:37:24 -0700 | [diff] [blame] | 30 | #include <linux/platform_data/gpio-omap.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 31 | |
Grygorii Strashko | e85ec6c | 2015-08-18 14:10:54 +0300 | [diff] [blame] | 32 | #define OMAP4_GPIO_DEBOUNCINGTIME_MASK 0xFF |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 33 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 34 | #define OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER BIT(2) |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 35 | |
Charulatha V | 6d62e21 | 2011-04-18 15:06:51 +0000 | [diff] [blame] | 36 | struct gpio_regs { |
| 37 | u32 irqenable1; |
| 38 | u32 irqenable2; |
| 39 | u32 wake_en; |
| 40 | u32 ctrl; |
| 41 | u32 oe; |
| 42 | u32 leveldetect0; |
| 43 | u32 leveldetect1; |
| 44 | u32 risingdetect; |
| 45 | u32 fallingdetect; |
| 46 | u32 dataout; |
Nishanth Menon | ae54735 | 2011-09-09 19:08:58 +0530 | [diff] [blame] | 47 | u32 debounce; |
| 48 | u32 debounce_en; |
Charulatha V | 6d62e21 | 2011-04-18 15:06:51 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 51 | struct gpio_bank; |
| 52 | |
| 53 | struct gpio_omap_funcs { |
| 54 | void (*idle_enable_level_quirk)(struct gpio_bank *bank); |
| 55 | void (*idle_disable_level_quirk)(struct gpio_bank *bank); |
| 56 | }; |
| 57 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 58 | struct gpio_bank { |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 59 | struct list_head node; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 60 | void __iomem *base; |
Grygorii Strashko | 30cefea | 2015-09-25 12:06:02 -0700 | [diff] [blame] | 61 | int irq; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 62 | u32 non_wakeup_gpios; |
| 63 | u32 enabled_non_wakeup_gpios; |
Charulatha V | 6d62e21 | 2011-04-18 15:06:51 +0000 | [diff] [blame] | 64 | struct gpio_regs context; |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 65 | struct gpio_omap_funcs funcs; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 66 | u32 saved_datain; |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 67 | u32 level_mask; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 68 | u32 toggle_mask; |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 69 | raw_spinlock_t lock; |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 70 | raw_spinlock_t wa_lock; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 71 | struct gpio_chip chip; |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 72 | struct clk *dbck; |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 73 | struct notifier_block nb; |
| 74 | unsigned int is_suspended:1; |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 75 | u32 mod_usage; |
Javier Martinez Canillas | fa365e4 | 2013-09-25 02:36:52 +0200 | [diff] [blame] | 76 | u32 irq_usage; |
Kevin Hilman | 8865b9b | 2009-01-27 11:15:34 -0800 | [diff] [blame] | 77 | u32 dbck_enable_mask; |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 78 | bool dbck_enabled; |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 79 | bool is_mpuio; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 80 | bool dbck_flag; |
Charulatha V | 0cde8d0 | 2011-05-05 20:15:16 +0530 | [diff] [blame] | 81 | bool loses_context; |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 82 | bool context_valid; |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 83 | int stride; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 84 | u32 width; |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 85 | int context_loss_count; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 86 | bool workaround_enabled; |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 87 | u32 quirks; |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 88 | |
Grygorii Strashko | 04ebcbd | 2015-03-23 14:18:24 +0200 | [diff] [blame] | 89 | void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable); |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 90 | void (*set_dataout_multiple)(struct gpio_bank *bank, |
| 91 | unsigned long *mask, unsigned long *bits); |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 92 | int (*get_context_loss_count)(struct device *dev); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 93 | |
| 94 | struct omap_gpio_reg_offs *regs; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
Charulatha V | c8eef65 | 2011-05-02 15:21:42 +0530 | [diff] [blame] | 97 | #define GPIO_MOD_CTRL_BIT BIT(0) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 98 | |
Javier Martinez Canillas | fa365e4 | 2013-09-25 02:36:52 +0200 | [diff] [blame] | 99 | #define BANK_USED(bank) (bank->mod_usage || bank->irq_usage) |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 100 | #define LINE_USED(line, offset) (line & (BIT(offset))) |
Javier Martinez Canillas | fa365e4 | 2013-09-25 02:36:52 +0200 | [diff] [blame] | 101 | |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 102 | static void omap_gpio_unmask_irq(struct irq_data *d); |
| 103 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 104 | static inline struct gpio_bank *omap_irq_data_get_bank(struct irq_data *d) |
Jon Hunter | ede4d7a | 2013-03-01 11:22:47 -0600 | [diff] [blame] | 105 | { |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 106 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 107 | return gpiochip_get_data(chip); |
Benoit Cousson | 25db711 | 2012-02-23 21:50:10 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 110 | static void omap_set_gpio_direction(struct gpio_bank *bank, int gpio, |
| 111 | int is_input) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 112 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 113 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 114 | u32 l; |
| 115 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 116 | reg += bank->regs->direction; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 117 | l = readl_relaxed(reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 118 | if (is_input) |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 119 | l |= BIT(gpio); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 120 | else |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 121 | l &= ~(BIT(gpio)); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 122 | writel_relaxed(l, reg); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 123 | bank->context.oe = l; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 126 | |
| 127 | /* set data out value using dedicate set/clear register */ |
Grygorii Strashko | 04ebcbd | 2015-03-23 14:18:24 +0200 | [diff] [blame] | 128 | static void omap_set_gpio_dataout_reg(struct gpio_bank *bank, unsigned offset, |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 129 | int enable) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 130 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 131 | void __iomem *reg = bank->base; |
Grygorii Strashko | 04ebcbd | 2015-03-23 14:18:24 +0200 | [diff] [blame] | 132 | u32 l = BIT(offset); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 133 | |
Tarun Kanti DebBarma | 2c836f7 | 2012-03-02 12:52:52 +0530 | [diff] [blame] | 134 | if (enable) { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 135 | reg += bank->regs->set_dataout; |
Tarun Kanti DebBarma | 2c836f7 | 2012-03-02 12:52:52 +0530 | [diff] [blame] | 136 | bank->context.dataout |= l; |
| 137 | } else { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 138 | reg += bank->regs->clr_dataout; |
Tarun Kanti DebBarma | 2c836f7 | 2012-03-02 12:52:52 +0530 | [diff] [blame] | 139 | bank->context.dataout &= ~l; |
| 140 | } |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 141 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 142 | writel_relaxed(l, reg); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* set data out value using mask register */ |
Grygorii Strashko | 04ebcbd | 2015-03-23 14:18:24 +0200 | [diff] [blame] | 146 | static void omap_set_gpio_dataout_mask(struct gpio_bank *bank, unsigned offset, |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 147 | int enable) |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 148 | { |
| 149 | void __iomem *reg = bank->base + bank->regs->dataout; |
Grygorii Strashko | 04ebcbd | 2015-03-23 14:18:24 +0200 | [diff] [blame] | 150 | u32 gpio_bit = BIT(offset); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 151 | u32 l; |
| 152 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 153 | l = readl_relaxed(reg); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 154 | if (enable) |
| 155 | l |= gpio_bit; |
| 156 | else |
| 157 | l &= ~gpio_bit; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 158 | writel_relaxed(l, reg); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 159 | bank->context.dataout = l; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 160 | } |
| 161 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 162 | static int omap_get_gpio_datain(struct gpio_bank *bank, int offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 163 | { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 164 | void __iomem *reg = bank->base + bank->regs->datain; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 165 | |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 166 | return (readl_relaxed(reg) & (BIT(offset))) != 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 169 | static int omap_get_gpio_dataout(struct gpio_bank *bank, int offset) |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 170 | { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 171 | void __iomem *reg = bank->base + bank->regs->dataout; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 172 | |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 173 | return (readl_relaxed(reg) & (BIT(offset))) != 0; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 174 | } |
| 175 | |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 176 | /* set multiple data out values using dedicate set/clear register */ |
| 177 | static void omap_set_gpio_dataout_reg_multiple(struct gpio_bank *bank, |
| 178 | unsigned long *mask, |
| 179 | unsigned long *bits) |
| 180 | { |
| 181 | void __iomem *reg = bank->base; |
| 182 | u32 l; |
| 183 | |
| 184 | l = *bits & *mask; |
| 185 | writel_relaxed(l, reg + bank->regs->set_dataout); |
| 186 | bank->context.dataout |= l; |
| 187 | |
| 188 | l = ~*bits & *mask; |
| 189 | writel_relaxed(l, reg + bank->regs->clr_dataout); |
| 190 | bank->context.dataout &= ~l; |
| 191 | } |
| 192 | |
| 193 | /* set multiple data out values using mask register */ |
| 194 | static void omap_set_gpio_dataout_mask_multiple(struct gpio_bank *bank, |
| 195 | unsigned long *mask, |
| 196 | unsigned long *bits) |
| 197 | { |
| 198 | void __iomem *reg = bank->base + bank->regs->dataout; |
| 199 | u32 l = (readl_relaxed(reg) & ~*mask) | (*bits & *mask); |
| 200 | |
| 201 | writel_relaxed(l, reg); |
| 202 | bank->context.dataout = l; |
| 203 | } |
| 204 | |
| 205 | static unsigned long omap_get_gpio_datain_multiple(struct gpio_bank *bank, |
| 206 | unsigned long *mask) |
| 207 | { |
| 208 | void __iomem *reg = bank->base + bank->regs->datain; |
| 209 | |
| 210 | return readl_relaxed(reg) & *mask; |
| 211 | } |
| 212 | |
| 213 | static unsigned long omap_get_gpio_dataout_multiple(struct gpio_bank *bank, |
| 214 | unsigned long *mask) |
| 215 | { |
| 216 | void __iomem *reg = bank->base + bank->regs->dataout; |
| 217 | |
| 218 | return readl_relaxed(reg) & *mask; |
| 219 | } |
| 220 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 221 | static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 222 | { |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 223 | int l = readl_relaxed(base + reg); |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 224 | |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 225 | if (set) |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 226 | l |= mask; |
| 227 | else |
| 228 | l &= ~mask; |
| 229 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 230 | writel_relaxed(l, base + reg); |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 231 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 232 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 233 | static inline void omap_gpio_dbck_enable(struct gpio_bank *bank) |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 234 | { |
| 235 | if (bank->dbck_enable_mask && !bank->dbck_enabled) { |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 236 | clk_enable(bank->dbck); |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 237 | bank->dbck_enabled = true; |
Grazvydas Ignotas | 9e303f2 | 2012-06-16 22:01:25 +0300 | [diff] [blame] | 238 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 239 | writel_relaxed(bank->dbck_enable_mask, |
Grazvydas Ignotas | 9e303f2 | 2012-06-16 22:01:25 +0300 | [diff] [blame] | 240 | bank->base + bank->regs->debounce_en); |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 244 | static inline void omap_gpio_dbck_disable(struct gpio_bank *bank) |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 245 | { |
| 246 | if (bank->dbck_enable_mask && bank->dbck_enabled) { |
Grazvydas Ignotas | 9e303f2 | 2012-06-16 22:01:25 +0300 | [diff] [blame] | 247 | /* |
| 248 | * Disable debounce before cutting it's clock. If debounce is |
| 249 | * enabled but the clock is not, GPIO module seems to be unable |
| 250 | * to detect events and generate interrupts at least on OMAP3. |
| 251 | */ |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 252 | writel_relaxed(0, bank->base + bank->regs->debounce_en); |
Grazvydas Ignotas | 9e303f2 | 2012-06-16 22:01:25 +0300 | [diff] [blame] | 253 | |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 254 | clk_disable(bank->dbck); |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 255 | bank->dbck_enabled = false; |
| 256 | } |
| 257 | } |
| 258 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 259 | /** |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 260 | * omap2_set_gpio_debounce - low level gpio debounce time |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 261 | * @bank: the gpio bank we're acting upon |
Grygorii Strashko | 4a58d22 | 2015-03-23 14:18:25 +0200 | [diff] [blame] | 262 | * @offset: the gpio number on this @bank |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 263 | * @debounce: debounce time to use |
| 264 | * |
Grygorii Strashko | e85ec6c | 2015-08-18 14:10:54 +0300 | [diff] [blame] | 265 | * OMAP's debounce time is in 31us steps |
| 266 | * <debounce time> = (GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME + 1) x 31 |
| 267 | * so we need to convert and round up to the closest unit. |
David Rivshin | 8397744 | 2017-04-24 18:56:50 -0400 | [diff] [blame] | 268 | * |
| 269 | * Return: 0 on success, negative error otherwise. |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 270 | */ |
David Rivshin | 8397744 | 2017-04-24 18:56:50 -0400 | [diff] [blame] | 271 | static int omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset, |
| 272 | unsigned debounce) |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 273 | { |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 274 | void __iomem *reg; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 275 | u32 val; |
| 276 | u32 l; |
Grygorii Strashko | e85ec6c | 2015-08-18 14:10:54 +0300 | [diff] [blame] | 277 | bool enable = !!debounce; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 278 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 279 | if (!bank->dbck_flag) |
David Rivshin | 8397744 | 2017-04-24 18:56:50 -0400 | [diff] [blame] | 280 | return -ENOTSUPP; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 281 | |
Grygorii Strashko | e85ec6c | 2015-08-18 14:10:54 +0300 | [diff] [blame] | 282 | if (enable) { |
| 283 | debounce = DIV_ROUND_UP(debounce, 31) - 1; |
David Rivshin | 8397744 | 2017-04-24 18:56:50 -0400 | [diff] [blame] | 284 | if ((debounce & OMAP4_GPIO_DEBOUNCINGTIME_MASK) != debounce) |
| 285 | return -EINVAL; |
Grygorii Strashko | e85ec6c | 2015-08-18 14:10:54 +0300 | [diff] [blame] | 286 | } |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 287 | |
Grygorii Strashko | 4a58d22 | 2015-03-23 14:18:25 +0200 | [diff] [blame] | 288 | l = BIT(offset); |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 289 | |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 290 | clk_enable(bank->dbck); |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 291 | reg = bank->base + bank->regs->debounce; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 292 | writel_relaxed(debounce, reg); |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 293 | |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 294 | reg = bank->base + bank->regs->debounce_en; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 295 | val = readl_relaxed(reg); |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 296 | |
Grygorii Strashko | e85ec6c | 2015-08-18 14:10:54 +0300 | [diff] [blame] | 297 | if (enable) |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 298 | val |= l; |
Tarun Kanti DebBarma | 6fd9c42 | 2011-11-24 03:58:54 +0530 | [diff] [blame] | 299 | else |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 300 | val &= ~l; |
Kevin Hilman | f7ec0b0 | 2010-06-09 13:53:07 +0300 | [diff] [blame] | 301 | bank->dbck_enable_mask = val; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 302 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 303 | writel_relaxed(val, reg); |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 304 | clk_disable(bank->dbck); |
Tarun Kanti DebBarma | 6fd9c42 | 2011-11-24 03:58:54 +0530 | [diff] [blame] | 305 | /* |
| 306 | * Enable debounce clock per module. |
| 307 | * This call is mandatory because in omap_gpio_request() when |
| 308 | * *_runtime_get_sync() is called, _gpio_dbck_enable() within |
| 309 | * runtime callbck fails to turn on dbck because dbck_enable_mask |
| 310 | * used within _gpio_dbck_enable() is still not initialized at |
| 311 | * that point. Therefore we have to enable dbck here. |
| 312 | */ |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 313 | omap_gpio_dbck_enable(bank); |
Nishanth Menon | ae54735 | 2011-09-09 19:08:58 +0530 | [diff] [blame] | 314 | if (bank->dbck_enable_mask) { |
| 315 | bank->context.debounce = debounce; |
| 316 | bank->context.debounce_en = val; |
| 317 | } |
David Rivshin | 8397744 | 2017-04-24 18:56:50 -0400 | [diff] [blame] | 318 | |
| 319 | return 0; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Jon Hunter | c9c55d9 | 2012-10-26 14:26:04 -0500 | [diff] [blame] | 322 | /** |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 323 | * omap_clear_gpio_debounce - clear debounce settings for a gpio |
Jon Hunter | c9c55d9 | 2012-10-26 14:26:04 -0500 | [diff] [blame] | 324 | * @bank: the gpio bank we're acting upon |
Grygorii Strashko | 4a58d22 | 2015-03-23 14:18:25 +0200 | [diff] [blame] | 325 | * @offset: the gpio number on this @bank |
Jon Hunter | c9c55d9 | 2012-10-26 14:26:04 -0500 | [diff] [blame] | 326 | * |
| 327 | * If a gpio is using debounce, then clear the debounce enable bit and if |
| 328 | * this is the only gpio in this bank using debounce, then clear the debounce |
| 329 | * time too. The debounce clock will also be disabled when calling this function |
| 330 | * if this is the only gpio in the bank using debounce. |
| 331 | */ |
Grygorii Strashko | 4a58d22 | 2015-03-23 14:18:25 +0200 | [diff] [blame] | 332 | static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset) |
Jon Hunter | c9c55d9 | 2012-10-26 14:26:04 -0500 | [diff] [blame] | 333 | { |
Grygorii Strashko | 4a58d22 | 2015-03-23 14:18:25 +0200 | [diff] [blame] | 334 | u32 gpio_bit = BIT(offset); |
Jon Hunter | c9c55d9 | 2012-10-26 14:26:04 -0500 | [diff] [blame] | 335 | |
| 336 | if (!bank->dbck_flag) |
| 337 | return; |
| 338 | |
| 339 | if (!(bank->dbck_enable_mask & gpio_bit)) |
| 340 | return; |
| 341 | |
| 342 | bank->dbck_enable_mask &= ~gpio_bit; |
| 343 | bank->context.debounce_en &= ~gpio_bit; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 344 | writel_relaxed(bank->context.debounce_en, |
Jon Hunter | c9c55d9 | 2012-10-26 14:26:04 -0500 | [diff] [blame] | 345 | bank->base + bank->regs->debounce_en); |
| 346 | |
| 347 | if (!bank->dbck_enable_mask) { |
| 348 | bank->context.debounce = 0; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 349 | writel_relaxed(bank->context.debounce, bank->base + |
Jon Hunter | c9c55d9 | 2012-10-26 14:26:04 -0500 | [diff] [blame] | 350 | bank->regs->debounce); |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 351 | clk_disable(bank->dbck); |
Jon Hunter | c9c55d9 | 2012-10-26 14:26:04 -0500 | [diff] [blame] | 352 | bank->dbck_enabled = false; |
| 353 | } |
| 354 | } |
| 355 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 356 | static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio, |
Tarun Kanti DebBarma | 00ece7e | 2011-11-25 15:41:06 +0530 | [diff] [blame] | 357 | unsigned trigger) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 358 | { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 359 | void __iomem *base = bank->base; |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 360 | u32 gpio_bit = BIT(gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 361 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 362 | omap_gpio_rmw(base, bank->regs->leveldetect0, gpio_bit, |
| 363 | trigger & IRQ_TYPE_LEVEL_LOW); |
| 364 | omap_gpio_rmw(base, bank->regs->leveldetect1, gpio_bit, |
| 365 | trigger & IRQ_TYPE_LEVEL_HIGH); |
| 366 | omap_gpio_rmw(base, bank->regs->risingdetect, gpio_bit, |
| 367 | trigger & IRQ_TYPE_EDGE_RISING); |
| 368 | omap_gpio_rmw(base, bank->regs->fallingdetect, gpio_bit, |
| 369 | trigger & IRQ_TYPE_EDGE_FALLING); |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 370 | |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 371 | bank->context.leveldetect0 = |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 372 | readl_relaxed(bank->base + bank->regs->leveldetect0); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 373 | bank->context.leveldetect1 = |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 374 | readl_relaxed(bank->base + bank->regs->leveldetect1); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 375 | bank->context.risingdetect = |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 376 | readl_relaxed(bank->base + bank->regs->risingdetect); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 377 | bank->context.fallingdetect = |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 378 | readl_relaxed(bank->base + bank->regs->fallingdetect); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 379 | |
| 380 | if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { |
Tony Lindgren | 00ded24 | 2018-12-07 11:08:29 -0800 | [diff] [blame] | 381 | omap_gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0); |
| 382 | bank->context.wake_en = |
| 383 | readl_relaxed(bank->base + bank->regs->wkup_en); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 384 | } |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 385 | |
Ambresh K | 55b220c | 2011-06-15 13:40:45 -0700 | [diff] [blame] | 386 | /* This part needs to be executed always for OMAP{34xx, 44xx} */ |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 387 | if (!bank->regs->irqctrl) { |
| 388 | /* On omap24xx proceed only when valid GPIO bit is set */ |
| 389 | if (bank->non_wakeup_gpios) { |
| 390 | if (!(bank->non_wakeup_gpios & gpio_bit)) |
| 391 | goto exit; |
| 392 | } |
| 393 | |
Chunqiu Wang | 699117a6 | 2009-06-24 17:13:39 +0000 | [diff] [blame] | 394 | /* |
| 395 | * Log the edge gpio and manually trigger the IRQ |
| 396 | * after resume if the input level changes |
| 397 | * to avoid irq lost during PER RET/OFF mode |
| 398 | * Applies for omap2 non-wakeup gpio and all omap3 gpios |
| 399 | */ |
| 400 | if (trigger & IRQ_TYPE_EDGE_BOTH) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 401 | bank->enabled_non_wakeup_gpios |= gpio_bit; |
| 402 | else |
| 403 | bank->enabled_non_wakeup_gpios &= ~gpio_bit; |
| 404 | } |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 405 | |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 406 | exit: |
Tarun Kanti DebBarma | 9ea14d8 | 2011-08-30 15:05:44 +0530 | [diff] [blame] | 407 | bank->level_mask = |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 408 | readl_relaxed(bank->base + bank->regs->leveldetect0) | |
| 409 | readl_relaxed(bank->base + bank->regs->leveldetect1); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 410 | } |
| 411 | |
Uwe Kleine-König | 9198bcd | 2010-01-29 14:20:05 -0800 | [diff] [blame] | 412 | #ifdef CONFIG_ARCH_OMAP1 |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 413 | /* |
| 414 | * This only applies to chips that can't do both rising and falling edge |
| 415 | * detection at once. For all other chips, this function is a noop. |
| 416 | */ |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 417 | static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 418 | { |
| 419 | void __iomem *reg = bank->base; |
| 420 | u32 l = 0; |
| 421 | |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 422 | if (!bank->regs->irqctrl) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 423 | return; |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 424 | |
| 425 | reg += bank->regs->irqctrl; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 426 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 427 | l = readl_relaxed(reg); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 428 | if ((l >> gpio) & 1) |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 429 | l &= ~(BIT(gpio)); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 430 | else |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 431 | l |= BIT(gpio); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 432 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 433 | writel_relaxed(l, reg); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 434 | } |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 435 | #else |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 436 | static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {} |
Uwe Kleine-König | 9198bcd | 2010-01-29 14:20:05 -0800 | [diff] [blame] | 437 | #endif |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 438 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 439 | static int omap_set_gpio_triggering(struct gpio_bank *bank, int gpio, |
| 440 | unsigned trigger) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 441 | { |
| 442 | void __iomem *reg = bank->base; |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 443 | void __iomem *base = bank->base; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 444 | u32 l = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 445 | |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 446 | if (bank->regs->leveldetect0 && bank->regs->wkup_en) { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 447 | omap_set_gpio_trigger(bank, gpio, trigger); |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 448 | } else if (bank->regs->irqctrl) { |
| 449 | reg += bank->regs->irqctrl; |
| 450 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 451 | l = readl_relaxed(reg); |
Janusz Krzysztofik | 2950157 | 2010-04-05 11:38:06 +0000 | [diff] [blame] | 452 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 453 | bank->toggle_mask |= BIT(gpio); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 454 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 455 | l |= BIT(gpio); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 456 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 457 | l &= ~(BIT(gpio)); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 458 | else |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 459 | return -EINVAL; |
| 460 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 461 | writel_relaxed(l, reg); |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 462 | } else if (bank->regs->edgectrl1) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 463 | if (gpio & 0x08) |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 464 | reg += bank->regs->edgectrl2; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 465 | else |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 466 | reg += bank->regs->edgectrl1; |
| 467 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 468 | gpio &= 0x07; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 469 | l = readl_relaxed(reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 470 | l &= ~(3 << (gpio << 1)); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 471 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 472 | l |= 2 << (gpio << 1); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 473 | if (trigger & IRQ_TYPE_EDGE_FALLING) |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 474 | l |= BIT(gpio << 1); |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 475 | |
| 476 | /* Enable wake-up during idle for dynamic tick */ |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 477 | omap_gpio_rmw(base, bank->regs->wkup_en, BIT(gpio), trigger); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 478 | bank->context.wake_en = |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 479 | readl_relaxed(bank->base + bank->regs->wkup_en); |
| 480 | writel_relaxed(l, reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 481 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 482 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 483 | } |
| 484 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 485 | static void omap_enable_gpio_module(struct gpio_bank *bank, unsigned offset) |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 486 | { |
| 487 | if (bank->regs->pinctrl) { |
| 488 | void __iomem *reg = bank->base + bank->regs->pinctrl; |
| 489 | |
| 490 | /* Claim the pin for MPU */ |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 491 | writel_relaxed(readl_relaxed(reg) | (BIT(offset)), reg); |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | if (bank->regs->ctrl && !BANK_USED(bank)) { |
| 495 | void __iomem *reg = bank->base + bank->regs->ctrl; |
| 496 | u32 ctrl; |
| 497 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 498 | ctrl = readl_relaxed(reg); |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 499 | /* Module is enabled, clocks are not gated */ |
| 500 | ctrl &= ~GPIO_MOD_CTRL_BIT; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 501 | writel_relaxed(ctrl, reg); |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 502 | bank->context.ctrl = ctrl; |
| 503 | } |
| 504 | } |
| 505 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 506 | static void omap_disable_gpio_module(struct gpio_bank *bank, unsigned offset) |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 507 | { |
| 508 | void __iomem *base = bank->base; |
| 509 | |
| 510 | if (bank->regs->wkup_en && |
| 511 | !LINE_USED(bank->mod_usage, offset) && |
| 512 | !LINE_USED(bank->irq_usage, offset)) { |
| 513 | /* Disable wake-up during idle for dynamic tick */ |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 514 | omap_gpio_rmw(base, bank->regs->wkup_en, BIT(offset), 0); |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 515 | bank->context.wake_en = |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 516 | readl_relaxed(bank->base + bank->regs->wkup_en); |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | if (bank->regs->ctrl && !BANK_USED(bank)) { |
| 520 | void __iomem *reg = bank->base + bank->regs->ctrl; |
| 521 | u32 ctrl; |
| 522 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 523 | ctrl = readl_relaxed(reg); |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 524 | /* Module is disabled, clocks are gated */ |
| 525 | ctrl |= GPIO_MOD_CTRL_BIT; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 526 | writel_relaxed(ctrl, reg); |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 527 | bank->context.ctrl = ctrl; |
| 528 | } |
| 529 | } |
| 530 | |
Grygorii Strashko | b2b2004 | 2015-03-23 14:18:23 +0200 | [diff] [blame] | 531 | static int omap_gpio_is_input(struct gpio_bank *bank, unsigned offset) |
Javier Martinez Canillas | fa365e4 | 2013-09-25 02:36:52 +0200 | [diff] [blame] | 532 | { |
| 533 | void __iomem *reg = bank->base + bank->regs->direction; |
| 534 | |
Grygorii Strashko | b2b2004 | 2015-03-23 14:18:23 +0200 | [diff] [blame] | 535 | return readl_relaxed(reg) & BIT(offset); |
Javier Martinez Canillas | fa365e4 | 2013-09-25 02:36:52 +0200 | [diff] [blame] | 536 | } |
| 537 | |
Grygorii Strashko | 37e14ec | 2015-03-23 14:18:26 +0200 | [diff] [blame] | 538 | static void omap_gpio_init_irq(struct gpio_bank *bank, unsigned offset) |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 539 | { |
| 540 | if (!LINE_USED(bank->mod_usage, offset)) { |
| 541 | omap_enable_gpio_module(bank, offset); |
| 542 | omap_set_gpio_direction(bank, offset, 1); |
| 543 | } |
Grygorii Strashko | 37e14ec | 2015-03-23 14:18:26 +0200 | [diff] [blame] | 544 | bank->irq_usage |= BIT(offset); |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 547 | static int omap_gpio_irq_type(struct irq_data *d, unsigned type) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 548 | { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 549 | struct gpio_bank *bank = omap_irq_data_get_bank(d); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 550 | int retval; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 551 | unsigned long flags; |
Grygorii Strashko | ea5fbe8 | 2015-03-23 14:18:29 +0200 | [diff] [blame] | 552 | unsigned offset = d->hwirq; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 553 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 554 | if (type & ~IRQ_TYPE_SENSE_MASK) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 555 | return -EINVAL; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 556 | |
Tarun Kanti DebBarma | 9ea14d8 | 2011-08-30 15:05:44 +0530 | [diff] [blame] | 557 | if (!bank->regs->leveldetect0 && |
| 558 | (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 559 | return -EINVAL; |
| 560 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 561 | raw_spin_lock_irqsave(&bank->lock, flags); |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 562 | retval = omap_set_gpio_triggering(bank, offset, type); |
Grygorii Strashko | 977bd8a | 2015-06-24 17:54:17 +0300 | [diff] [blame] | 563 | if (retval) { |
Axel Lin | 627c89b | 2015-08-05 22:37:41 +0800 | [diff] [blame] | 564 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Grygorii Strashko | 1562e46 | 2015-05-22 17:35:49 +0300 | [diff] [blame] | 565 | goto error; |
Grygorii Strashko | 977bd8a | 2015-06-24 17:54:17 +0300 | [diff] [blame] | 566 | } |
Grygorii Strashko | 37e14ec | 2015-03-23 14:18:26 +0200 | [diff] [blame] | 567 | omap_gpio_init_irq(bank, offset); |
Grygorii Strashko | b2b2004 | 2015-03-23 14:18:23 +0200 | [diff] [blame] | 568 | if (!omap_gpio_is_input(bank, offset)) { |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 569 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Grygorii Strashko | 1562e46 | 2015-05-22 17:35:49 +0300 | [diff] [blame] | 570 | retval = -EINVAL; |
| 571 | goto error; |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 572 | } |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 573 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 574 | |
| 575 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
Thomas Gleixner | 43ec2e4 | 2015-06-23 15:52:39 +0200 | [diff] [blame] | 576 | irq_set_handler_locked(d, handle_level_irq); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 577 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
Grygorii Strashko | 80ac93c | 2017-10-03 11:17:05 -0500 | [diff] [blame] | 578 | /* |
| 579 | * Edge IRQs are already cleared/acked in irq_handler and |
| 580 | * not need to be masked, as result handle_edge_irq() |
| 581 | * logic is excessed here and may cause lose of interrupts. |
| 582 | * So just use handle_simple_irq. |
| 583 | */ |
| 584 | irq_set_handler_locked(d, handle_simple_irq); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 585 | |
Grygorii Strashko | 1562e46 | 2015-05-22 17:35:49 +0300 | [diff] [blame] | 586 | return 0; |
| 587 | |
| 588 | error: |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 589 | return retval; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 590 | } |
| 591 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 592 | static void omap_clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 593 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 594 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 595 | |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 596 | reg += bank->regs->irqstatus; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 597 | writel_relaxed(gpio_mask, reg); |
Hiroshi DOYU | bee7930 | 2006-09-25 12:41:46 +0300 | [diff] [blame] | 598 | |
| 599 | /* Workaround for clearing DSP GPIO interrupts to allow retention */ |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 600 | if (bank->regs->irqstatus2) { |
| 601 | reg = bank->base + bank->regs->irqstatus2; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 602 | writel_relaxed(gpio_mask, reg); |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 603 | } |
Roger Quadros | bedfd15 | 2009-04-23 11:10:50 -0700 | [diff] [blame] | 604 | |
| 605 | /* Flush posted write for the irq status to avoid spurious interrupts */ |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 606 | readl_relaxed(reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 607 | } |
| 608 | |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 609 | static inline void omap_clear_gpio_irqstatus(struct gpio_bank *bank, |
| 610 | unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 611 | { |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 612 | omap_clear_gpio_irqbank(bank, BIT(offset)); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 613 | } |
| 614 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 615 | static u32 omap_get_gpio_irqbank_mask(struct gpio_bank *bank) |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 616 | { |
| 617 | void __iomem *reg = bank->base; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 618 | u32 l; |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 619 | u32 mask = (BIT(bank->width)) - 1; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 620 | |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 621 | reg += bank->regs->irqenable; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 622 | l = readl_relaxed(reg); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 623 | if (bank->regs->irqenable_inv) |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 624 | l = ~l; |
| 625 | l &= mask; |
| 626 | return l; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 629 | static void omap_enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 630 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 631 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 632 | u32 l; |
| 633 | |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 634 | if (bank->regs->set_irqenable) { |
| 635 | reg += bank->regs->set_irqenable; |
| 636 | l = gpio_mask; |
Tarun Kanti DebBarma | 2a900eb | 2012-03-06 12:08:16 +0530 | [diff] [blame] | 637 | bank->context.irqenable1 |= gpio_mask; |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 638 | } else { |
| 639 | reg += bank->regs->irqenable; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 640 | l = readl_relaxed(reg); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 641 | if (bank->regs->irqenable_inv) |
| 642 | l &= ~gpio_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 643 | else |
| 644 | l |= gpio_mask; |
Tarun Kanti DebBarma | 2a900eb | 2012-03-06 12:08:16 +0530 | [diff] [blame] | 645 | bank->context.irqenable1 = l; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 646 | } |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 647 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 648 | writel_relaxed(l, reg); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 651 | static void omap_disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 652 | { |
| 653 | void __iomem *reg = bank->base; |
| 654 | u32 l; |
| 655 | |
| 656 | if (bank->regs->clr_irqenable) { |
| 657 | reg += bank->regs->clr_irqenable; |
| 658 | l = gpio_mask; |
Tarun Kanti DebBarma | 2a900eb | 2012-03-06 12:08:16 +0530 | [diff] [blame] | 659 | bank->context.irqenable1 &= ~gpio_mask; |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 660 | } else { |
| 661 | reg += bank->regs->irqenable; |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 662 | l = readl_relaxed(reg); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 663 | if (bank->regs->irqenable_inv) |
| 664 | l |= gpio_mask; |
| 665 | else |
| 666 | l &= ~gpio_mask; |
Tarun Kanti DebBarma | 2a900eb | 2012-03-06 12:08:16 +0530 | [diff] [blame] | 667 | bank->context.irqenable1 = l; |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 670 | writel_relaxed(l, reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 671 | } |
| 672 | |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 673 | static inline void omap_set_gpio_irqenable(struct gpio_bank *bank, |
| 674 | unsigned offset, int enable) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 675 | { |
Tarun Kanti DebBarma | 8276536c | 2011-11-25 15:27:37 +0530 | [diff] [blame] | 676 | if (enable) |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 677 | omap_enable_gpio_irqbank(bank, BIT(offset)); |
Tarun Kanti DebBarma | 8276536c | 2011-11-25 15:27:37 +0530 | [diff] [blame] | 678 | else |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 679 | omap_disable_gpio_irqbank(bank, BIT(offset)); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 680 | } |
| 681 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 682 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 683 | static int omap_gpio_wake_enable(struct irq_data *d, unsigned int enable) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 684 | { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 685 | struct gpio_bank *bank = omap_irq_data_get_bank(d); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 686 | |
Grygorii Strashko | 0c0451e | 2016-04-12 13:52:31 +0300 | [diff] [blame] | 687 | return irq_set_irq_wake(bank->irq, enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 688 | } |
| 689 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 690 | static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 691 | { |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 692 | struct gpio_bank *bank = gpiochip_get_data(chip); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 693 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 694 | |
Grygorii Strashko | 4674807 | 2018-09-28 16:39:50 -0500 | [diff] [blame] | 695 | pm_runtime_get_sync(chip->parent); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 696 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 697 | raw_spin_lock_irqsave(&bank->lock, flags); |
Grygorii Strashko | c351817 | 2015-05-22 17:35:51 +0300 | [diff] [blame] | 698 | omap_enable_gpio_module(bank, offset); |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 699 | bank->mod_usage |= BIT(offset); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 700 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 705 | static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 706 | { |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 707 | struct gpio_bank *bank = gpiochip_get_data(chip); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 708 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 709 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 710 | raw_spin_lock_irqsave(&bank->lock, flags); |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 711 | bank->mod_usage &= ~(BIT(offset)); |
Grygorii Strashko | 5f982c7 | 2015-05-22 17:35:48 +0300 | [diff] [blame] | 712 | if (!LINE_USED(bank->irq_usage, offset)) { |
| 713 | omap_set_gpio_direction(bank, offset, 1); |
| 714 | omap_clear_gpio_debounce(bank, offset); |
| 715 | } |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 716 | omap_disable_gpio_module(bank, offset); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 717 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 718 | |
Grygorii Strashko | 4674807 | 2018-09-28 16:39:50 -0500 | [diff] [blame] | 719 | pm_runtime_put(chip->parent); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /* |
| 723 | * We need to unmask the GPIO bank interrupt as soon as possible to |
| 724 | * avoid missing GPIO interrupts for other lines in the bank. |
| 725 | * Then we need to mask-read-clear-unmask the triggered GPIO lines |
| 726 | * in the bank to avoid missing nested interrupts for a GPIO line. |
| 727 | * If we wait to unmask individual GPIO lines in the bank after the |
| 728 | * line's interrupt handler has been run, we may miss some nested |
| 729 | * interrupts. |
| 730 | */ |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 731 | static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 732 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 733 | void __iomem *isr_reg = NULL; |
Grygorii Strashko | 80ac93c | 2017-10-03 11:17:05 -0500 | [diff] [blame] | 734 | u32 enabled, isr, level_mask; |
Jon Hunter | 3513cde | 2013-04-04 15:16:14 -0500 | [diff] [blame] | 735 | unsigned int bit; |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 736 | struct gpio_bank *bank = gpiobank; |
| 737 | unsigned long wa_lock_flags; |
Grygorii Strashko | 235f1eb | 2015-08-18 14:10:55 +0300 | [diff] [blame] | 738 | unsigned long lock_flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 739 | |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 740 | isr_reg = bank->base + bank->regs->irqstatus; |
Evgeny Kuznetsov | b1cc4c5 | 2010-12-07 16:25:40 -0800 | [diff] [blame] | 741 | if (WARN_ON(!isr_reg)) |
| 742 | goto exit; |
| 743 | |
Tony Lindgren | 5284521 | 2018-09-20 12:35:32 -0700 | [diff] [blame] | 744 | if (WARN_ONCE(!pm_runtime_active(bank->chip.parent), |
| 745 | "gpio irq%i while runtime suspended?\n", irq)) |
| 746 | return IRQ_NONE; |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 747 | |
Laurent Navet | e83507b | 2013-03-20 13:15:57 +0100 | [diff] [blame] | 748 | while (1) { |
Grygorii Strashko | 235f1eb | 2015-08-18 14:10:55 +0300 | [diff] [blame] | 749 | raw_spin_lock_irqsave(&bank->lock, lock_flags); |
| 750 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 751 | enabled = omap_get_gpio_irqbank_mask(bank); |
Grygorii Strashko | 80ac93c | 2017-10-03 11:17:05 -0500 | [diff] [blame] | 752 | isr = readl_relaxed(isr_reg) & enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 753 | |
Tarun Kanti DebBarma | 9ea14d8 | 2011-08-30 15:05:44 +0530 | [diff] [blame] | 754 | if (bank->level_mask) |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 755 | level_mask = bank->level_mask & enabled; |
Grygorii Strashko | 80ac93c | 2017-10-03 11:17:05 -0500 | [diff] [blame] | 756 | else |
| 757 | level_mask = 0; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 758 | |
| 759 | /* clear edge sensitive interrupts before handler(s) are |
| 760 | called so that we don't miss any interrupt occurred while |
| 761 | executing them */ |
Grygorii Strashko | 80ac93c | 2017-10-03 11:17:05 -0500 | [diff] [blame] | 762 | if (isr & ~level_mask) |
| 763 | omap_clear_gpio_irqbank(bank, isr & ~level_mask); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 764 | |
Grygorii Strashko | 235f1eb | 2015-08-18 14:10:55 +0300 | [diff] [blame] | 765 | raw_spin_unlock_irqrestore(&bank->lock, lock_flags); |
| 766 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 767 | if (!isr) |
| 768 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 769 | |
Jon Hunter | 3513cde | 2013-04-04 15:16:14 -0500 | [diff] [blame] | 770 | while (isr) { |
| 771 | bit = __ffs(isr); |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 772 | isr &= ~(BIT(bit)); |
Benoit Cousson | 25db711 | 2012-02-23 21:50:10 +0100 | [diff] [blame] | 773 | |
Grygorii Strashko | 235f1eb | 2015-08-18 14:10:55 +0300 | [diff] [blame] | 774 | raw_spin_lock_irqsave(&bank->lock, lock_flags); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 775 | /* |
| 776 | * Some chips can't respond to both rising and falling |
| 777 | * at the same time. If this irq was requested with |
| 778 | * both flags, we need to flip the ICR data for the IRQ |
| 779 | * to respond to the IRQ for the opposite direction. |
| 780 | * This will be indicated in the bank toggle_mask. |
| 781 | */ |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 782 | if (bank->toggle_mask & (BIT(bit))) |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 783 | omap_toggle_gpio_edge_triggering(bank, bit); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 784 | |
Grygorii Strashko | 235f1eb | 2015-08-18 14:10:55 +0300 | [diff] [blame] | 785 | raw_spin_unlock_irqrestore(&bank->lock, lock_flags); |
| 786 | |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 787 | raw_spin_lock_irqsave(&bank->wa_lock, wa_lock_flags); |
| 788 | |
Thierry Reding | f0fbe7b | 2017-11-07 19:15:47 +0100 | [diff] [blame] | 789 | generic_handle_irq(irq_find_mapping(bank->chip.irq.domain, |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 790 | bit)); |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 791 | |
| 792 | raw_spin_unlock_irqrestore(&bank->wa_lock, |
| 793 | wa_lock_flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 794 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 795 | } |
Evgeny Kuznetsov | b1cc4c5 | 2010-12-07 16:25:40 -0800 | [diff] [blame] | 796 | exit: |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 797 | return IRQ_HANDLED; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 798 | } |
| 799 | |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 800 | static unsigned int omap_gpio_irq_startup(struct irq_data *d) |
| 801 | { |
| 802 | struct gpio_bank *bank = omap_irq_data_get_bank(d); |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 803 | unsigned long flags; |
Grygorii Strashko | 37e14ec | 2015-03-23 14:18:26 +0200 | [diff] [blame] | 804 | unsigned offset = d->hwirq; |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 805 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 806 | raw_spin_lock_irqsave(&bank->lock, flags); |
Grygorii Strashko | 121dcb7 | 2015-05-22 17:35:52 +0300 | [diff] [blame] | 807 | |
| 808 | if (!LINE_USED(bank->mod_usage, offset)) |
| 809 | omap_set_gpio_direction(bank, offset, 1); |
| 810 | else if (!omap_gpio_is_input(bank, offset)) |
| 811 | goto err; |
| 812 | omap_enable_gpio_module(bank, offset); |
| 813 | bank->irq_usage |= BIT(offset); |
| 814 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 815 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 816 | omap_gpio_unmask_irq(d); |
| 817 | |
| 818 | return 0; |
Grygorii Strashko | 121dcb7 | 2015-05-22 17:35:52 +0300 | [diff] [blame] | 819 | err: |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 820 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Grygorii Strashko | 121dcb7 | 2015-05-22 17:35:52 +0300 | [diff] [blame] | 821 | return -EINVAL; |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 822 | } |
| 823 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 824 | static void omap_gpio_irq_shutdown(struct irq_data *d) |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 825 | { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 826 | struct gpio_bank *bank = omap_irq_data_get_bank(d); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 827 | unsigned long flags; |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 828 | unsigned offset = d->hwirq; |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 829 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 830 | raw_spin_lock_irqsave(&bank->lock, flags); |
Javier Martinez Canillas | b1e9fec | 2014-04-27 02:00:49 +0200 | [diff] [blame] | 831 | bank->irq_usage &= ~(BIT(offset)); |
Grygorii Strashko | 6e96c1b | 2015-05-22 17:35:50 +0300 | [diff] [blame] | 832 | omap_set_gpio_irqenable(bank, offset, 0); |
| 833 | omap_clear_gpio_irqstatus(bank, offset); |
| 834 | omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); |
| 835 | if (!LINE_USED(bank->mod_usage, offset)) |
| 836 | omap_clear_gpio_debounce(bank, offset); |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 837 | omap_disable_gpio_module(bank, offset); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 838 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Grygorii Strashko | aca82d1 | 2015-09-25 12:28:02 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | static void omap_gpio_irq_bus_lock(struct irq_data *data) |
| 842 | { |
| 843 | struct gpio_bank *bank = omap_irq_data_get_bank(data); |
| 844 | |
Grygorii Strashko | 4674807 | 2018-09-28 16:39:50 -0500 | [diff] [blame] | 845 | pm_runtime_get_sync(bank->chip.parent); |
Grygorii Strashko | aca82d1 | 2015-09-25 12:28:02 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | static void gpio_irq_bus_sync_unlock(struct irq_data *data) |
| 849 | { |
| 850 | struct gpio_bank *bank = omap_irq_data_get_bank(data); |
Javier Martinez Canillas | fac7fa1 | 2013-09-25 02:36:54 +0200 | [diff] [blame] | 851 | |
Grygorii Strashko | 4674807 | 2018-09-28 16:39:50 -0500 | [diff] [blame] | 852 | pm_runtime_put(bank->chip.parent); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 853 | } |
| 854 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 855 | static void omap_gpio_ack_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 856 | { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 857 | struct gpio_bank *bank = omap_irq_data_get_bank(d); |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 858 | unsigned offset = d->hwirq; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 859 | |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 860 | omap_clear_gpio_irqstatus(bank, offset); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 861 | } |
| 862 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 863 | static void omap_gpio_mask_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 864 | { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 865 | struct gpio_bank *bank = omap_irq_data_get_bank(d); |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 866 | unsigned offset = d->hwirq; |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 867 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 868 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 869 | raw_spin_lock_irqsave(&bank->lock, flags); |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 870 | omap_set_gpio_irqenable(bank, offset, 0); |
| 871 | omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 872 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 873 | } |
| 874 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 875 | static void omap_gpio_unmask_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 876 | { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 877 | struct gpio_bank *bank = omap_irq_data_get_bank(d); |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 878 | unsigned offset = d->hwirq; |
Thomas Gleixner | 8c04a17 | 2011-03-24 12:40:15 +0100 | [diff] [blame] | 879 | u32 trigger = irqd_get_trigger_type(d); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 880 | unsigned long flags; |
Kevin Hilman | 55b6019 | 2009-06-04 15:57:10 -0700 | [diff] [blame] | 881 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 882 | raw_spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | 55b6019 | 2009-06-04 15:57:10 -0700 | [diff] [blame] | 883 | if (trigger) |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 884 | omap_set_gpio_triggering(bank, offset, trigger); |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 885 | |
| 886 | /* For level-triggered GPIOs, the clearing must be done after |
| 887 | * the HW source is cleared, thus after the handler has run */ |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 888 | if (bank->level_mask & BIT(offset)) { |
| 889 | omap_set_gpio_irqenable(bank, offset, 0); |
| 890 | omap_clear_gpio_irqstatus(bank, offset); |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 891 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 892 | |
Grygorii Strashko | 9943f26 | 2015-03-23 14:18:27 +0200 | [diff] [blame] | 893 | omap_set_gpio_irqenable(bank, offset, 1); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 894 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 895 | } |
| 896 | |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 897 | /* |
| 898 | * Only edges can generate a wakeup event to the PRCM. |
| 899 | * |
| 900 | * Therefore, ensure any wake-up capable GPIOs have |
| 901 | * edge-detection enabled before going idle to ensure a wakeup |
| 902 | * to the PRCM is generated on a GPIO transition. (c.f. 34xx |
| 903 | * NDA TRM 25.5.3.1) |
| 904 | * |
| 905 | * The normal values will be restored upon ->runtime_resume() |
| 906 | * by writing back the values saved in bank->context. |
| 907 | */ |
| 908 | static void __maybe_unused |
| 909 | omap2_gpio_enable_level_quirk(struct gpio_bank *bank) |
| 910 | { |
| 911 | u32 wake_low, wake_hi; |
| 912 | |
| 913 | /* Enable additional edge detection for level gpios for idle */ |
| 914 | wake_low = bank->context.leveldetect0 & bank->context.wake_en; |
| 915 | if (wake_low) |
| 916 | writel_relaxed(wake_low | bank->context.fallingdetect, |
| 917 | bank->base + bank->regs->fallingdetect); |
| 918 | |
| 919 | wake_hi = bank->context.leveldetect1 & bank->context.wake_en; |
| 920 | if (wake_hi) |
| 921 | writel_relaxed(wake_hi | bank->context.risingdetect, |
| 922 | bank->base + bank->regs->risingdetect); |
| 923 | } |
| 924 | |
| 925 | static void __maybe_unused |
| 926 | omap2_gpio_disable_level_quirk(struct gpio_bank *bank) |
| 927 | { |
| 928 | /* Disable edge detection for level gpios after idle */ |
| 929 | writel_relaxed(bank->context.fallingdetect, |
| 930 | bank->base + bank->regs->fallingdetect); |
| 931 | writel_relaxed(bank->context.risingdetect, |
| 932 | bank->base + bank->regs->risingdetect); |
| 933 | } |
| 934 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 935 | /*---------------------------------------------------------------------*/ |
| 936 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 937 | static int omap_mpuio_suspend_noirq(struct device *dev) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 938 | { |
Wolfram Sang | a3f4f72 | 2018-10-21 21:59:59 +0200 | [diff] [blame] | 939 | struct gpio_bank *bank = dev_get_drvdata(dev); |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 940 | void __iomem *mask_reg = bank->base + |
| 941 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 942 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 943 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 944 | raw_spin_lock_irqsave(&bank->lock, flags); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 945 | writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 946 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 947 | |
| 948 | return 0; |
| 949 | } |
| 950 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 951 | static int omap_mpuio_resume_noirq(struct device *dev) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 952 | { |
Wolfram Sang | a3f4f72 | 2018-10-21 21:59:59 +0200 | [diff] [blame] | 953 | struct gpio_bank *bank = dev_get_drvdata(dev); |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 954 | void __iomem *mask_reg = bank->base + |
| 955 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 956 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 957 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 958 | raw_spin_lock_irqsave(&bank->lock, flags); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 959 | writel_relaxed(bank->context.wake_en, mask_reg); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 960 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 961 | |
| 962 | return 0; |
| 963 | } |
| 964 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 965 | static const struct dev_pm_ops omap_mpuio_dev_pm_ops = { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 966 | .suspend_noirq = omap_mpuio_suspend_noirq, |
| 967 | .resume_noirq = omap_mpuio_resume_noirq, |
| 968 | }; |
| 969 | |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 970 | /* use platform_driver for this. */ |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 971 | static struct platform_driver omap_mpuio_driver = { |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 972 | .driver = { |
| 973 | .name = "mpuio", |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 974 | .pm = &omap_mpuio_dev_pm_ops, |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 975 | }, |
| 976 | }; |
| 977 | |
| 978 | static struct platform_device omap_mpuio_device = { |
| 979 | .name = "mpuio", |
| 980 | .id = -1, |
| 981 | .dev = { |
| 982 | .driver = &omap_mpuio_driver.driver, |
| 983 | } |
| 984 | /* could list the /proc/iomem resources */ |
| 985 | }; |
| 986 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 987 | static inline void omap_mpuio_init(struct gpio_bank *bank) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 988 | { |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 989 | platform_set_drvdata(&omap_mpuio_device, bank); |
David Brownell | fcf126d | 2007-04-02 12:46:47 -0700 | [diff] [blame] | 990 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 991 | if (platform_driver_register(&omap_mpuio_driver) == 0) |
| 992 | (void) platform_device_register(&omap_mpuio_device); |
| 993 | } |
| 994 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 995 | /*---------------------------------------------------------------------*/ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 996 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 997 | static int omap_gpio_get_direction(struct gpio_chip *chip, unsigned offset) |
Yegor Yefremov | 9370084 | 2014-04-24 08:57:39 +0200 | [diff] [blame] | 998 | { |
| 999 | struct gpio_bank *bank; |
| 1000 | unsigned long flags; |
| 1001 | void __iomem *reg; |
| 1002 | int dir; |
| 1003 | |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 1004 | bank = gpiochip_get_data(chip); |
Yegor Yefremov | 9370084 | 2014-04-24 08:57:39 +0200 | [diff] [blame] | 1005 | reg = bank->base + bank->regs->direction; |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1006 | raw_spin_lock_irqsave(&bank->lock, flags); |
Yegor Yefremov | 9370084 | 2014-04-24 08:57:39 +0200 | [diff] [blame] | 1007 | dir = !!(readl_relaxed(reg) & BIT(offset)); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1008 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Yegor Yefremov | 9370084 | 2014-04-24 08:57:39 +0200 | [diff] [blame] | 1009 | return dir; |
| 1010 | } |
| 1011 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1012 | static int omap_gpio_input(struct gpio_chip *chip, unsigned offset) |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1013 | { |
| 1014 | struct gpio_bank *bank; |
| 1015 | unsigned long flags; |
| 1016 | |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 1017 | bank = gpiochip_get_data(chip); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1018 | raw_spin_lock_irqsave(&bank->lock, flags); |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1019 | omap_set_gpio_direction(bank, offset, 1); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1020 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1021 | return 0; |
| 1022 | } |
| 1023 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1024 | static int omap_gpio_get(struct gpio_chip *chip, unsigned offset) |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1025 | { |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 1026 | struct gpio_bank *bank; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 1027 | |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 1028 | bank = gpiochip_get_data(chip); |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 1029 | |
Grygorii Strashko | b2b2004 | 2015-03-23 14:18:23 +0200 | [diff] [blame] | 1030 | if (omap_gpio_is_input(bank, offset)) |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1031 | return omap_get_gpio_datain(bank, offset); |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 1032 | else |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1033 | return omap_get_gpio_dataout(bank, offset); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1036 | static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value) |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1037 | { |
| 1038 | struct gpio_bank *bank; |
| 1039 | unsigned long flags; |
| 1040 | |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 1041 | bank = gpiochip_get_data(chip); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1042 | raw_spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 1043 | bank->set_dataout(bank, offset, value); |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1044 | omap_set_gpio_direction(bank, offset, 0); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1045 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Javier Martinez Canillas | 2f56e0a | 2013-10-16 02:47:30 +0200 | [diff] [blame] | 1046 | return 0; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 1049 | static int omap_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, |
| 1050 | unsigned long *bits) |
| 1051 | { |
| 1052 | struct gpio_bank *bank = gpiochip_get_data(chip); |
| 1053 | void __iomem *reg = bank->base + bank->regs->direction; |
| 1054 | unsigned long in = readl_relaxed(reg), l; |
| 1055 | |
| 1056 | *bits = 0; |
| 1057 | |
| 1058 | l = in & *mask; |
| 1059 | if (l) |
| 1060 | *bits |= omap_get_gpio_datain_multiple(bank, &l); |
| 1061 | |
| 1062 | l = ~in & *mask; |
| 1063 | if (l) |
| 1064 | *bits |= omap_get_gpio_dataout_multiple(bank, &l); |
| 1065 | |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1069 | static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset, |
| 1070 | unsigned debounce) |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 1071 | { |
| 1072 | struct gpio_bank *bank; |
| 1073 | unsigned long flags; |
David Rivshin | 8397744 | 2017-04-24 18:56:50 -0400 | [diff] [blame] | 1074 | int ret; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 1075 | |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 1076 | bank = gpiochip_get_data(chip); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1077 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1078 | raw_spin_lock_irqsave(&bank->lock, flags); |
David Rivshin | 8397744 | 2017-04-24 18:56:50 -0400 | [diff] [blame] | 1079 | ret = omap2_set_gpio_debounce(bank, offset, debounce); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1080 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 1081 | |
David Rivshin | 8397744 | 2017-04-24 18:56:50 -0400 | [diff] [blame] | 1082 | if (ret) |
| 1083 | dev_info(chip->parent, |
| 1084 | "Could not set line %u debounce to %u microseconds (%d)", |
| 1085 | offset, debounce, ret); |
| 1086 | |
| 1087 | return ret; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Mika Westerberg | 2956b5d | 2017-01-23 15:34:34 +0300 | [diff] [blame] | 1090 | static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, |
| 1091 | unsigned long config) |
| 1092 | { |
| 1093 | u32 debounce; |
| 1094 | |
| 1095 | if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE) |
| 1096 | return -ENOTSUPP; |
| 1097 | |
| 1098 | debounce = pinconf_to_config_argument(config); |
| 1099 | return omap_gpio_debounce(chip, offset, debounce); |
| 1100 | } |
| 1101 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1102 | static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1103 | { |
| 1104 | struct gpio_bank *bank; |
| 1105 | unsigned long flags; |
| 1106 | |
Linus Walleij | d99f7ae | 2015-12-07 11:16:00 +0100 | [diff] [blame] | 1107 | bank = gpiochip_get_data(chip); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1108 | raw_spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 1109 | bank->set_dataout(bank, offset, value); |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1110 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 1113 | static void omap_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask, |
| 1114 | unsigned long *bits) |
| 1115 | { |
| 1116 | struct gpio_bank *bank = gpiochip_get_data(chip); |
| 1117 | unsigned long flags; |
| 1118 | |
| 1119 | raw_spin_lock_irqsave(&bank->lock, flags); |
| 1120 | bank->set_dataout_multiple(bank, mask, bits); |
| 1121 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
| 1122 | } |
| 1123 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1124 | /*---------------------------------------------------------------------*/ |
| 1125 | |
Arnd Bergmann | e4b2ae7 | 2017-09-16 22:42:21 +0200 | [diff] [blame] | 1126 | static void omap_gpio_show_rev(struct gpio_bank *bank) |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1127 | { |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 1128 | static bool called; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1129 | u32 rev; |
| 1130 | |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 1131 | if (called || bank->regs->revision == USHRT_MAX) |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1132 | return; |
| 1133 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1134 | rev = readw_relaxed(bank->base + bank->regs->revision); |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 1135 | pr_info("OMAP GPIO hardware version %d.%d\n", |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1136 | (rev >> 4) & 0x0f, rev & 0x0f); |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 1137 | |
| 1138 | called = true; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1141 | static void omap_gpio_mod_init(struct gpio_bank *bank) |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1142 | { |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1143 | void __iomem *base = bank->base; |
| 1144 | u32 l = 0xffffffff; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1145 | |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1146 | if (bank->width == 16) |
| 1147 | l = 0xffff; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1148 | |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 1149 | if (bank->is_mpuio) { |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1150 | writel_relaxed(l, bank->base + bank->regs->irqenable); |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1151 | return; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1152 | } |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1153 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1154 | omap_gpio_rmw(base, bank->regs->irqenable, l, |
| 1155 | bank->regs->irqenable_inv); |
| 1156 | omap_gpio_rmw(base, bank->regs->irqstatus, l, |
| 1157 | !bank->regs->irqenable_inv); |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1158 | if (bank->regs->debounce_en) |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1159 | writel_relaxed(0, base + bank->regs->debounce_en); |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1160 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1161 | /* Save OE default value (0xffffffff) in the context */ |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1162 | bank->context.oe = readl_relaxed(bank->base + bank->regs->direction); |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1163 | /* Initialize interface clk ungated, module enabled */ |
| 1164 | if (bank->regs->ctrl) |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1165 | writel_relaxed(0, base + bank->regs->ctrl); |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1166 | } |
| 1167 | |
Nishanth Menon | 46824e22 | 2014-09-05 14:52:55 -0500 | [diff] [blame] | 1168 | static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1169 | { |
Grygorii Strashko | 8193032 | 2017-11-15 12:36:33 -0600 | [diff] [blame] | 1170 | struct gpio_irq_chip *irq; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1171 | static int gpio; |
Linus Walleij | 088413b | 2017-12-29 13:22:58 +0100 | [diff] [blame] | 1172 | const char *label; |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 1173 | int irq_base = 0; |
Javier Martinez Canillas | 6ef7f38 | 2014-04-06 16:58:14 +0200 | [diff] [blame] | 1174 | int ret; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1175 | |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1176 | /* |
| 1177 | * REVISIT eventually switch from OMAP-specific gpio structs |
| 1178 | * over to the generic ones |
| 1179 | */ |
| 1180 | bank->chip.request = omap_gpio_request; |
| 1181 | bank->chip.free = omap_gpio_free; |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1182 | bank->chip.get_direction = omap_gpio_get_direction; |
| 1183 | bank->chip.direction_input = omap_gpio_input; |
| 1184 | bank->chip.get = omap_gpio_get; |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 1185 | bank->chip.get_multiple = omap_gpio_get_multiple; |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1186 | bank->chip.direction_output = omap_gpio_output; |
Mika Westerberg | 2956b5d | 2017-01-23 15:34:34 +0300 | [diff] [blame] | 1187 | bank->chip.set_config = omap_gpio_set_config; |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1188 | bank->chip.set = omap_gpio_set; |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 1189 | bank->chip.set_multiple = omap_gpio_set_multiple; |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 1190 | if (bank->is_mpuio) { |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1191 | bank->chip.label = "mpuio"; |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 1192 | if (bank->regs->wkup_en) |
Linus Walleij | 58383c78 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 1193 | bank->chip.parent = &omap_mpuio_device.dev; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1194 | bank->chip.base = OMAP_MPUIO(0); |
| 1195 | } else { |
Linus Walleij | 088413b | 2017-12-29 13:22:58 +0100 | [diff] [blame] | 1196 | label = devm_kasprintf(bank->chip.parent, GFP_KERNEL, "gpio-%d-%d", |
| 1197 | gpio, gpio + bank->width - 1); |
| 1198 | if (!label) |
| 1199 | return -ENOMEM; |
| 1200 | bank->chip.label = label; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1201 | bank->chip.base = gpio; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1202 | } |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1203 | bank->chip.ngpio = bank->width; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1204 | |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 1205 | #ifdef CONFIG_ARCH_OMAP1 |
| 1206 | /* |
| 1207 | * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop |
| 1208 | * irq_alloc_descs() since a base IRQ offset will no longer be needed. |
| 1209 | */ |
Bartosz Golaszewski | 2ed36f3 | 2017-03-04 17:23:31 +0100 | [diff] [blame] | 1210 | irq_base = devm_irq_alloc_descs(bank->chip.parent, |
| 1211 | -1, 0, bank->width, 0); |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 1212 | if (irq_base < 0) { |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1213 | dev_err(bank->chip.parent, "Couldn't allocate IRQ numbers\n"); |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 1214 | return -ENODEV; |
| 1215 | } |
| 1216 | #endif |
| 1217 | |
Tony Lindgren | d2d05c6 | 2015-04-23 16:54:17 -0700 | [diff] [blame] | 1218 | /* MPUIO is a bit different, reading IRQ status clears it */ |
| 1219 | if (bank->is_mpuio) { |
| 1220 | irqc->irq_ack = dummy_irq_chip.irq_ack; |
Tony Lindgren | d2d05c6 | 2015-04-23 16:54:17 -0700 | [diff] [blame] | 1221 | if (!bank->regs->wkup_en) |
| 1222 | irqc->irq_set_wake = NULL; |
| 1223 | } |
| 1224 | |
Grygorii Strashko | 8193032 | 2017-11-15 12:36:33 -0600 | [diff] [blame] | 1225 | irq = &bank->chip.irq; |
| 1226 | irq->chip = irqc; |
| 1227 | irq->handler = handle_bad_irq; |
| 1228 | irq->default_type = IRQ_TYPE_NONE; |
| 1229 | irq->num_parents = 1; |
| 1230 | irq->parents = &bank->irq; |
| 1231 | irq->first = irq_base; |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 1232 | |
Grygorii Strashko | 8193032 | 2017-11-15 12:36:33 -0600 | [diff] [blame] | 1233 | ret = gpiochip_add_data(&bank->chip, bank); |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 1234 | if (ret) { |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1235 | dev_err(bank->chip.parent, |
Grygorii Strashko | 8193032 | 2017-11-15 12:36:33 -0600 | [diff] [blame] | 1236 | "Could not register gpio chip %d\n", ret); |
| 1237 | return ret; |
Javier Martinez Canillas | fb655f5 | 2014-04-06 16:58:16 +0200 | [diff] [blame] | 1238 | } |
| 1239 | |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1240 | ret = devm_request_irq(bank->chip.parent, bank->irq, |
| 1241 | omap_gpio_irq_handler, |
| 1242 | 0, dev_name(bank->chip.parent), bank); |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 1243 | if (ret) |
| 1244 | gpiochip_remove(&bank->chip); |
| 1245 | |
Grygorii Strashko | 8193032 | 2017-11-15 12:36:33 -0600 | [diff] [blame] | 1246 | if (!bank->is_mpuio) |
| 1247 | gpio += bank->width; |
| 1248 | |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 1249 | return ret; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1252 | static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context); |
| 1253 | static void omap_gpio_unidle(struct gpio_bank *bank); |
| 1254 | |
| 1255 | static int gpio_omap_cpu_notifier(struct notifier_block *nb, |
| 1256 | unsigned long cmd, void *v) |
| 1257 | { |
| 1258 | struct gpio_bank *bank; |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1259 | unsigned long flags; |
| 1260 | |
| 1261 | bank = container_of(nb, struct gpio_bank, nb); |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1262 | |
| 1263 | raw_spin_lock_irqsave(&bank->lock, flags); |
| 1264 | switch (cmd) { |
| 1265 | case CPU_CLUSTER_PM_ENTER: |
| 1266 | if (bank->is_suspended) |
| 1267 | break; |
| 1268 | omap_gpio_idle(bank, true); |
| 1269 | break; |
| 1270 | case CPU_CLUSTER_PM_ENTER_FAILED: |
| 1271 | case CPU_CLUSTER_PM_EXIT: |
| 1272 | if (bank->is_suspended) |
| 1273 | break; |
| 1274 | omap_gpio_unidle(bank); |
| 1275 | break; |
| 1276 | } |
| 1277 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
| 1278 | |
| 1279 | return NOTIFY_OK; |
| 1280 | } |
| 1281 | |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1282 | static const struct of_device_id omap_gpio_match[]; |
| 1283 | |
Bill Pemberton | 3836309 | 2012-11-19 13:22:34 -0500 | [diff] [blame] | 1284 | static int omap_gpio_probe(struct platform_device *pdev) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1285 | { |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 1286 | struct device *dev = &pdev->dev; |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1287 | struct device_node *node = dev->of_node; |
| 1288 | const struct of_device_id *match; |
Uwe Kleine-König | f6817a2 | 2012-05-21 21:57:39 +0200 | [diff] [blame] | 1289 | const struct omap_gpio_platform_data *pdata; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1290 | struct resource *res; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1291 | struct gpio_bank *bank; |
Nishanth Menon | 46824e22 | 2014-09-05 14:52:55 -0500 | [diff] [blame] | 1292 | struct irq_chip *irqc; |
Javier Martinez Canillas | 6ef7f38 | 2014-04-06 16:58:14 +0200 | [diff] [blame] | 1293 | int ret; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1294 | |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1295 | match = of_match_device(of_match_ptr(omap_gpio_match), dev); |
| 1296 | |
Jingoo Han | e56aee1 | 2013-07-30 17:08:05 +0900 | [diff] [blame] | 1297 | pdata = match ? match->data : dev_get_platdata(dev); |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1298 | if (!pdata) |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame] | 1299 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1300 | |
Markus Elfring | f97364c | 2018-02-10 21:49:22 +0100 | [diff] [blame] | 1301 | bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL); |
Markus Elfring | 9117d40 | 2018-02-10 21:46:30 +0100 | [diff] [blame] | 1302 | if (!bank) |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame] | 1303 | return -ENOMEM; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1304 | |
Nishanth Menon | 46824e22 | 2014-09-05 14:52:55 -0500 | [diff] [blame] | 1305 | irqc = devm_kzalloc(dev, sizeof(*irqc), GFP_KERNEL); |
| 1306 | if (!irqc) |
| 1307 | return -ENOMEM; |
| 1308 | |
Tony Lindgren | 3d009c8 | 2015-01-16 14:50:50 -0800 | [diff] [blame] | 1309 | irqc->irq_startup = omap_gpio_irq_startup, |
Nishanth Menon | 46824e22 | 2014-09-05 14:52:55 -0500 | [diff] [blame] | 1310 | irqc->irq_shutdown = omap_gpio_irq_shutdown, |
| 1311 | irqc->irq_ack = omap_gpio_ack_irq, |
| 1312 | irqc->irq_mask = omap_gpio_mask_irq, |
| 1313 | irqc->irq_unmask = omap_gpio_unmask_irq, |
| 1314 | irqc->irq_set_type = omap_gpio_irq_type, |
| 1315 | irqc->irq_set_wake = omap_gpio_wake_enable, |
Grygorii Strashko | aca82d1 | 2015-09-25 12:28:02 -0700 | [diff] [blame] | 1316 | irqc->irq_bus_lock = omap_gpio_irq_bus_lock, |
| 1317 | irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock, |
Nishanth Menon | 46824e22 | 2014-09-05 14:52:55 -0500 | [diff] [blame] | 1318 | irqc->name = dev_name(&pdev->dev); |
Grygorii Strashko | 0c0451e | 2016-04-12 13:52:31 +0300 | [diff] [blame] | 1319 | irqc->flags = IRQCHIP_MASK_ON_SUSPEND; |
Grygorii Strashko | 4674807 | 2018-09-28 16:39:50 -0500 | [diff] [blame] | 1320 | irqc->parent_device = dev; |
Nishanth Menon | 46824e22 | 2014-09-05 14:52:55 -0500 | [diff] [blame] | 1321 | |
Grygorii Strashko | 89d18e3 | 2015-08-18 14:10:53 +0300 | [diff] [blame] | 1322 | bank->irq = platform_get_irq(pdev, 0); |
| 1323 | if (bank->irq <= 0) { |
| 1324 | if (!bank->irq) |
| 1325 | bank->irq = -ENXIO; |
| 1326 | if (bank->irq != -EPROBE_DEFER) |
| 1327 | dev_err(dev, |
| 1328 | "can't get irq resource ret=%d\n", bank->irq); |
| 1329 | return bank->irq; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1330 | } |
| 1331 | |
Linus Walleij | 58383c78 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 1332 | bank->chip.parent = dev; |
Grygorii Strashko | c23837c | 2015-06-25 18:13:33 +0300 | [diff] [blame] | 1333 | bank->chip.owner = THIS_MODULE; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1334 | bank->dbck_flag = pdata->dbck_flag; |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 1335 | bank->quirks = pdata->quirks; |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 1336 | bank->stride = pdata->bank_stride; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1337 | bank->width = pdata->bank_width; |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 1338 | bank->is_mpuio = pdata->is_mpuio; |
Charulatha V | 803a243 | 2011-05-05 17:04:12 +0530 | [diff] [blame] | 1339 | bank->non_wakeup_gpios = pdata->non_wakeup_gpios; |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 1340 | bank->regs = pdata->regs; |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1341 | #ifdef CONFIG_OF_GPIO |
| 1342 | bank->chip.of_node = of_node_get(node); |
| 1343 | #endif |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 1344 | |
Jon Hunter | a2797be | 2013-04-04 15:16:15 -0500 | [diff] [blame] | 1345 | if (node) { |
| 1346 | if (!of_property_read_bool(node, "ti,gpio-always-on")) |
| 1347 | bank->loses_context = true; |
| 1348 | } else { |
| 1349 | bank->loses_context = pdata->loses_context; |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 1350 | |
| 1351 | if (bank->loses_context) |
| 1352 | bank->get_context_loss_count = |
| 1353 | pdata->get_context_loss_count; |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1354 | } |
| 1355 | |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 1356 | if (bank->regs->set_dataout && bank->regs->clr_dataout) { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1357 | bank->set_dataout = omap_set_gpio_dataout_reg; |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 1358 | bank->set_dataout_multiple = omap_set_gpio_dataout_reg_multiple; |
| 1359 | } else { |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1360 | bank->set_dataout = omap_set_gpio_dataout_mask; |
Janusz Krzysztofik | 442af14 | 2018-07-19 01:57:08 +0200 | [diff] [blame] | 1361 | bank->set_dataout_multiple = |
| 1362 | omap_set_gpio_dataout_mask_multiple; |
| 1363 | } |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1364 | |
Tony Lindgren | 00ded24 | 2018-12-07 11:08:29 -0800 | [diff] [blame] | 1365 | if (bank->quirks & OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER) { |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 1366 | bank->funcs.idle_enable_level_quirk = |
| 1367 | omap2_gpio_enable_level_quirk; |
| 1368 | bank->funcs.idle_disable_level_quirk = |
| 1369 | omap2_gpio_disable_level_quirk; |
| 1370 | } |
| 1371 | |
Sebastian Andrzej Siewior | 4dbada2 | 2015-07-21 18:26:51 +0200 | [diff] [blame] | 1372 | raw_spin_lock_init(&bank->lock); |
Grygorii Strashko | 450fa54 | 2015-09-25 12:28:03 -0700 | [diff] [blame] | 1373 | raw_spin_lock_init(&bank->wa_lock); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1374 | |
| 1375 | /* Static mapping, never released */ |
| 1376 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Jingoo Han | 717f70e | 2014-02-12 11:51:38 +0900 | [diff] [blame] | 1377 | bank->base = devm_ioremap_resource(dev, res); |
| 1378 | if (IS_ERR(bank->base)) { |
Jingoo Han | 717f70e | 2014-02-12 11:51:38 +0900 | [diff] [blame] | 1379 | return PTR_ERR(bank->base); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1380 | } |
| 1381 | |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 1382 | if (bank->dbck_flag) { |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1383 | bank->dbck = devm_clk_get(dev, "dbclk"); |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 1384 | if (IS_ERR(bank->dbck)) { |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1385 | dev_err(dev, |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 1386 | "Could not get gpio dbck. Disable debounce\n"); |
| 1387 | bank->dbck_flag = false; |
| 1388 | } else { |
| 1389 | clk_prepare(bank->dbck); |
| 1390 | } |
| 1391 | } |
| 1392 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1393 | platform_set_drvdata(pdev, bank); |
| 1394 | |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1395 | pm_runtime_enable(dev); |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1396 | pm_runtime_get_sync(dev); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1397 | |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 1398 | if (bank->is_mpuio) |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1399 | omap_mpuio_init(bank); |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1400 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1401 | omap_gpio_mod_init(bank); |
Javier Martinez Canillas | 6ef7f38 | 2014-04-06 16:58:14 +0200 | [diff] [blame] | 1402 | |
Nishanth Menon | 46824e22 | 2014-09-05 14:52:55 -0500 | [diff] [blame] | 1403 | ret = omap_gpio_chip_init(bank, irqc); |
Tony Lindgren | 5e606ab | 2015-08-28 11:44:49 -0700 | [diff] [blame] | 1404 | if (ret) { |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1405 | pm_runtime_put_sync(dev); |
| 1406 | pm_runtime_disable(dev); |
Arvind Yadav | e2c3c19 | 2017-08-01 12:14:31 +0530 | [diff] [blame] | 1407 | if (bank->dbck_flag) |
| 1408 | clk_unprepare(bank->dbck); |
Javier Martinez Canillas | 6ef7f38 | 2014-04-06 16:58:14 +0200 | [diff] [blame] | 1409 | return ret; |
Tony Lindgren | 5e606ab | 2015-08-28 11:44:49 -0700 | [diff] [blame] | 1410 | } |
Javier Martinez Canillas | 6ef7f38 | 2014-04-06 16:58:14 +0200 | [diff] [blame] | 1411 | |
Tony Lindgren | 9a74805 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 1412 | omap_gpio_show_rev(bank); |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1413 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1414 | if (bank->funcs.idle_enable_level_quirk && |
| 1415 | bank->funcs.idle_disable_level_quirk) { |
| 1416 | bank->nb.notifier_call = gpio_omap_cpu_notifier; |
| 1417 | cpu_pm_register_notifier(&bank->nb); |
| 1418 | } |
| 1419 | |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1420 | pm_runtime_put(dev); |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1421 | |
Jon Hunter | 879fe32 | 2013-04-04 15:16:12 -0500 | [diff] [blame] | 1422 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1423 | } |
| 1424 | |
Tony Lindgren | cac089f | 2015-04-23 16:56:22 -0700 | [diff] [blame] | 1425 | static int omap_gpio_remove(struct platform_device *pdev) |
| 1426 | { |
| 1427 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1428 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1429 | if (bank->nb.notifier_call) |
| 1430 | cpu_pm_unregister_notifier(&bank->nb); |
Tony Lindgren | cac089f | 2015-04-23 16:56:22 -0700 | [diff] [blame] | 1431 | list_del(&bank->node); |
| 1432 | gpiochip_remove(&bank->chip); |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1433 | pm_runtime_disable(&pdev->dev); |
Grygorii Strashko | 5d9452e | 2015-08-18 14:10:56 +0300 | [diff] [blame] | 1434 | if (bank->dbck_flag) |
| 1435 | clk_unprepare(bank->dbck); |
Tony Lindgren | cac089f | 2015-04-23 16:56:22 -0700 | [diff] [blame] | 1436 | |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1440 | static void omap_gpio_restore_context(struct gpio_bank *bank); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1441 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1442 | static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1443 | { |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1444 | struct device *dev = bank->chip.parent; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1445 | u32 l1 = 0, l2 = 0; |
Kevin Hilman | 68942ed | 2012-03-05 15:10:04 -0800 | [diff] [blame] | 1446 | |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 1447 | if (bank->funcs.idle_enable_level_quirk) |
| 1448 | bank->funcs.idle_enable_level_quirk(bank); |
Kevin Hilman | 68942ed | 2012-03-05 15:10:04 -0800 | [diff] [blame] | 1449 | |
Kevin Hilman | b3c64bc | 2012-05-17 16:42:16 -0700 | [diff] [blame] | 1450 | if (!bank->enabled_non_wakeup_gpios) |
| 1451 | goto update_gpio_context_count; |
| 1452 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1453 | if (!may_lose_context) |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 1454 | goto update_gpio_context_count; |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1455 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1456 | /* |
| 1457 | * If going to OFF, remove triggering for all |
| 1458 | * non-wakeup GPIOs. Otherwise spurious IRQs will be |
| 1459 | * generated. See OMAP2420 Errata item 1.101. |
| 1460 | */ |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1461 | bank->saved_datain = readl_relaxed(bank->base + |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1462 | bank->regs->datain); |
Tarun Kanti DebBarma | c6f31c9 | 2012-04-27 19:43:32 +0530 | [diff] [blame] | 1463 | l1 = bank->context.fallingdetect; |
| 1464 | l2 = bank->context.risingdetect; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1465 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1466 | l1 &= ~bank->enabled_non_wakeup_gpios; |
| 1467 | l2 &= ~bank->enabled_non_wakeup_gpios; |
| 1468 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1469 | writel_relaxed(l1, bank->base + bank->regs->fallingdetect); |
| 1470 | writel_relaxed(l2, bank->base + bank->regs->risingdetect); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1471 | |
| 1472 | bank->workaround_enabled = true; |
| 1473 | |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 1474 | update_gpio_context_count: |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1475 | if (bank->get_context_loss_count) |
| 1476 | bank->context_loss_count = |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1477 | bank->get_context_loss_count(dev); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1478 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1479 | omap_gpio_dbck_disable(bank); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1480 | } |
| 1481 | |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 1482 | static void omap_gpio_init_context(struct gpio_bank *p); |
| 1483 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1484 | static void omap_gpio_unidle(struct gpio_bank *bank) |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1485 | { |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1486 | struct device *dev = bank->chip.parent; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1487 | u32 l = 0, gen, gen0, gen1; |
Jon Hunter | a2797be | 2013-04-04 15:16:15 -0500 | [diff] [blame] | 1488 | int c; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1489 | |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 1490 | /* |
| 1491 | * On the first resume during the probe, the context has not |
| 1492 | * been initialised and so initialise it now. Also initialise |
| 1493 | * the context loss count. |
| 1494 | */ |
| 1495 | if (bank->loses_context && !bank->context_valid) { |
| 1496 | omap_gpio_init_context(bank); |
| 1497 | |
| 1498 | if (bank->get_context_loss_count) |
| 1499 | bank->context_loss_count = |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1500 | bank->get_context_loss_count(dev); |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 1501 | } |
| 1502 | |
Javier Martinez Canillas | a0e827c | 2014-06-27 22:17:37 +0200 | [diff] [blame] | 1503 | omap_gpio_dbck_enable(bank); |
Kevin Hilman | 68942ed | 2012-03-05 15:10:04 -0800 | [diff] [blame] | 1504 | |
Tony Lindgren | ec0daae | 2018-09-20 12:35:30 -0700 | [diff] [blame] | 1505 | if (bank->funcs.idle_disable_level_quirk) |
| 1506 | bank->funcs.idle_disable_level_quirk(bank); |
Kevin Hilman | 68942ed | 2012-03-05 15:10:04 -0800 | [diff] [blame] | 1507 | |
Jon Hunter | a2797be | 2013-04-04 15:16:15 -0500 | [diff] [blame] | 1508 | if (bank->loses_context) { |
| 1509 | if (!bank->get_context_loss_count) { |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1510 | omap_gpio_restore_context(bank); |
| 1511 | } else { |
Grygorii Strashko | 7b1e5dc | 2016-03-04 17:25:35 +0200 | [diff] [blame] | 1512 | c = bank->get_context_loss_count(dev); |
Jon Hunter | a2797be | 2013-04-04 15:16:15 -0500 | [diff] [blame] | 1513 | if (c != bank->context_loss_count) { |
| 1514 | omap_gpio_restore_context(bank); |
| 1515 | } else { |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1516 | return; |
Jon Hunter | a2797be | 2013-04-04 15:16:15 -0500 | [diff] [blame] | 1517 | } |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1518 | } |
| 1519 | } |
| 1520 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1521 | if (!bank->workaround_enabled) |
| 1522 | return; |
Tarun Kanti DebBarma | 1b128703 | 2012-04-27 19:43:38 +0530 | [diff] [blame] | 1523 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1524 | l = readl_relaxed(bank->base + bank->regs->datain); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1525 | |
| 1526 | /* |
| 1527 | * Check if any of the non-wakeup interrupt GPIOs have changed |
| 1528 | * state. If so, generate an IRQ by software. This is |
| 1529 | * horribly racy, but it's the best we can do to work around |
| 1530 | * this silicon bug. |
| 1531 | */ |
| 1532 | l ^= bank->saved_datain; |
| 1533 | l &= bank->enabled_non_wakeup_gpios; |
| 1534 | |
| 1535 | /* |
| 1536 | * No need to generate IRQs for the rising edge for gpio IRQs |
| 1537 | * configured with falling edge only; and vice versa. |
| 1538 | */ |
Tarun Kanti DebBarma | c6f31c9 | 2012-04-27 19:43:32 +0530 | [diff] [blame] | 1539 | gen0 = l & bank->context.fallingdetect; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1540 | gen0 &= bank->saved_datain; |
| 1541 | |
Tarun Kanti DebBarma | c6f31c9 | 2012-04-27 19:43:32 +0530 | [diff] [blame] | 1542 | gen1 = l & bank->context.risingdetect; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1543 | gen1 &= ~(bank->saved_datain); |
| 1544 | |
| 1545 | /* FIXME: Consider GPIO IRQs with level detections properly! */ |
Tarun Kanti DebBarma | c6f31c9 | 2012-04-27 19:43:32 +0530 | [diff] [blame] | 1546 | gen = l & (~(bank->context.fallingdetect) & |
| 1547 | ~(bank->context.risingdetect)); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1548 | /* Consider all GPIO IRQs needed to be updated */ |
| 1549 | gen |= gen0 | gen1; |
| 1550 | |
| 1551 | if (gen) { |
| 1552 | u32 old0, old1; |
| 1553 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1554 | old0 = readl_relaxed(bank->base + bank->regs->leveldetect0); |
| 1555 | old1 = readl_relaxed(bank->base + bank->regs->leveldetect1); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1556 | |
Tarun Kanti DebBarma | 4e962e8 | 2012-04-27 19:43:37 +0530 | [diff] [blame] | 1557 | if (!bank->regs->irqstatus_raw0) { |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1558 | writel_relaxed(old0 | gen, bank->base + |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1559 | bank->regs->leveldetect0); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1560 | writel_relaxed(old1 | gen, bank->base + |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1561 | bank->regs->leveldetect1); |
| 1562 | } |
| 1563 | |
Tarun Kanti DebBarma | 4e962e8 | 2012-04-27 19:43:37 +0530 | [diff] [blame] | 1564 | if (bank->regs->irqstatus_raw0) { |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1565 | writel_relaxed(old0 | l, bank->base + |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1566 | bank->regs->leveldetect0); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1567 | writel_relaxed(old1 | l, bank->base + |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1568 | bank->regs->leveldetect1); |
| 1569 | } |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1570 | writel_relaxed(old0, bank->base + bank->regs->leveldetect0); |
| 1571 | writel_relaxed(old1, bank->base + bank->regs->leveldetect1); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | bank->workaround_enabled = false; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 1577 | static void omap_gpio_init_context(struct gpio_bank *p) |
| 1578 | { |
| 1579 | struct omap_gpio_reg_offs *regs = p->regs; |
| 1580 | void __iomem *base = p->base; |
| 1581 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1582 | p->context.ctrl = readl_relaxed(base + regs->ctrl); |
| 1583 | p->context.oe = readl_relaxed(base + regs->direction); |
| 1584 | p->context.wake_en = readl_relaxed(base + regs->wkup_en); |
| 1585 | p->context.leveldetect0 = readl_relaxed(base + regs->leveldetect0); |
| 1586 | p->context.leveldetect1 = readl_relaxed(base + regs->leveldetect1); |
| 1587 | p->context.risingdetect = readl_relaxed(base + regs->risingdetect); |
| 1588 | p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect); |
| 1589 | p->context.irqenable1 = readl_relaxed(base + regs->irqenable); |
| 1590 | p->context.irqenable2 = readl_relaxed(base + regs->irqenable2); |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 1591 | |
| 1592 | if (regs->set_dataout && p->regs->clr_dataout) |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1593 | p->context.dataout = readl_relaxed(base + regs->set_dataout); |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 1594 | else |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1595 | p->context.dataout = readl_relaxed(base + regs->dataout); |
Jon Hunter | 352a2d5 | 2013-04-15 13:06:54 -0500 | [diff] [blame] | 1596 | |
| 1597 | p->context_valid = true; |
| 1598 | } |
| 1599 | |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1600 | static void omap_gpio_restore_context(struct gpio_bank *bank) |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1601 | { |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1602 | writel_relaxed(bank->context.wake_en, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1603 | bank->base + bank->regs->wkup_en); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1604 | writel_relaxed(bank->context.ctrl, bank->base + bank->regs->ctrl); |
| 1605 | writel_relaxed(bank->context.leveldetect0, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1606 | bank->base + bank->regs->leveldetect0); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1607 | writel_relaxed(bank->context.leveldetect1, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1608 | bank->base + bank->regs->leveldetect1); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1609 | writel_relaxed(bank->context.risingdetect, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1610 | bank->base + bank->regs->risingdetect); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1611 | writel_relaxed(bank->context.fallingdetect, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1612 | bank->base + bank->regs->fallingdetect); |
Nishanth Menon | f86bcc3 | 2011-09-09 19:14:08 +0530 | [diff] [blame] | 1613 | if (bank->regs->set_dataout && bank->regs->clr_dataout) |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1614 | writel_relaxed(bank->context.dataout, |
Nishanth Menon | f86bcc3 | 2011-09-09 19:14:08 +0530 | [diff] [blame] | 1615 | bank->base + bank->regs->set_dataout); |
| 1616 | else |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1617 | writel_relaxed(bank->context.dataout, |
Nishanth Menon | f86bcc3 | 2011-09-09 19:14:08 +0530 | [diff] [blame] | 1618 | bank->base + bank->regs->dataout); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1619 | writel_relaxed(bank->context.oe, bank->base + bank->regs->direction); |
Nishanth Menon | 6d13eaa | 2011-08-29 18:54:50 +0530 | [diff] [blame] | 1620 | |
Nishanth Menon | ae54735 | 2011-09-09 19:08:58 +0530 | [diff] [blame] | 1621 | if (bank->dbck_enable_mask) { |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1622 | writel_relaxed(bank->context.debounce, bank->base + |
Nishanth Menon | ae54735 | 2011-09-09 19:08:58 +0530 | [diff] [blame] | 1623 | bank->regs->debounce); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1624 | writel_relaxed(bank->context.debounce_en, |
Nishanth Menon | ae54735 | 2011-09-09 19:08:58 +0530 | [diff] [blame] | 1625 | bank->base + bank->regs->debounce_en); |
| 1626 | } |
Nishanth Menon | ba805be | 2011-08-29 18:41:08 +0530 | [diff] [blame] | 1627 | |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1628 | writel_relaxed(bank->context.irqenable1, |
Nishanth Menon | ba805be | 2011-08-29 18:41:08 +0530 | [diff] [blame] | 1629 | bank->base + bank->regs->irqenable); |
Victor Kamensky | 661553b | 2013-11-16 02:01:04 +0200 | [diff] [blame] | 1630 | writel_relaxed(bank->context.irqenable2, |
Nishanth Menon | ba805be | 2011-08-29 18:41:08 +0530 | [diff] [blame] | 1631 | bank->base + bank->regs->irqenable2); |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1632 | } |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1633 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1634 | static int __maybe_unused omap_gpio_runtime_suspend(struct device *dev) |
| 1635 | { |
Wolfram Sang | a3f4f72 | 2018-10-21 21:59:59 +0200 | [diff] [blame] | 1636 | struct gpio_bank *bank = dev_get_drvdata(dev); |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1637 | unsigned long flags; |
| 1638 | int error = 0; |
| 1639 | |
| 1640 | raw_spin_lock_irqsave(&bank->lock, flags); |
| 1641 | /* Must be idled only by CPU_CLUSTER_PM_ENTER? */ |
| 1642 | if (bank->irq_usage) { |
| 1643 | error = -EBUSY; |
| 1644 | goto unlock; |
| 1645 | } |
| 1646 | omap_gpio_idle(bank, true); |
| 1647 | bank->is_suspended = true; |
| 1648 | unlock: |
| 1649 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
| 1650 | |
| 1651 | return error; |
| 1652 | } |
| 1653 | |
| 1654 | static int __maybe_unused omap_gpio_runtime_resume(struct device *dev) |
| 1655 | { |
Wolfram Sang | a3f4f72 | 2018-10-21 21:59:59 +0200 | [diff] [blame] | 1656 | struct gpio_bank *bank = dev_get_drvdata(dev); |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1657 | unsigned long flags; |
| 1658 | int error = 0; |
| 1659 | |
| 1660 | raw_spin_lock_irqsave(&bank->lock, flags); |
| 1661 | /* Must be unidled only by CPU_CLUSTER_PM_ENTER? */ |
| 1662 | if (bank->irq_usage) { |
| 1663 | error = -EBUSY; |
| 1664 | goto unlock; |
| 1665 | } |
| 1666 | omap_gpio_unidle(bank); |
| 1667 | bank->is_suspended = false; |
| 1668 | unlock: |
| 1669 | raw_spin_unlock_irqrestore(&bank->lock, flags); |
| 1670 | |
| 1671 | return error; |
| 1672 | } |
| 1673 | |
| 1674 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1675 | static const struct dev_pm_ops gpio_pm_ops = { |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1676 | SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume, |
| 1677 | NULL) |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1678 | }; |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1679 | #else |
| 1680 | static const struct dev_pm_ops gpio_pm_ops; |
| 1681 | #endif /* CONFIG_ARCH_OMAP2PLUS */ |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1682 | |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1683 | #if defined(CONFIG_OF) |
| 1684 | static struct omap_gpio_reg_offs omap2_gpio_regs = { |
| 1685 | .revision = OMAP24XX_GPIO_REVISION, |
| 1686 | .direction = OMAP24XX_GPIO_OE, |
| 1687 | .datain = OMAP24XX_GPIO_DATAIN, |
| 1688 | .dataout = OMAP24XX_GPIO_DATAOUT, |
| 1689 | .set_dataout = OMAP24XX_GPIO_SETDATAOUT, |
| 1690 | .clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT, |
| 1691 | .irqstatus = OMAP24XX_GPIO_IRQSTATUS1, |
| 1692 | .irqstatus2 = OMAP24XX_GPIO_IRQSTATUS2, |
| 1693 | .irqenable = OMAP24XX_GPIO_IRQENABLE1, |
| 1694 | .irqenable2 = OMAP24XX_GPIO_IRQENABLE2, |
| 1695 | .set_irqenable = OMAP24XX_GPIO_SETIRQENABLE1, |
| 1696 | .clr_irqenable = OMAP24XX_GPIO_CLEARIRQENABLE1, |
| 1697 | .debounce = OMAP24XX_GPIO_DEBOUNCE_VAL, |
| 1698 | .debounce_en = OMAP24XX_GPIO_DEBOUNCE_EN, |
| 1699 | .ctrl = OMAP24XX_GPIO_CTRL, |
| 1700 | .wkup_en = OMAP24XX_GPIO_WAKE_EN, |
| 1701 | .leveldetect0 = OMAP24XX_GPIO_LEVELDETECT0, |
| 1702 | .leveldetect1 = OMAP24XX_GPIO_LEVELDETECT1, |
| 1703 | .risingdetect = OMAP24XX_GPIO_RISINGDETECT, |
| 1704 | .fallingdetect = OMAP24XX_GPIO_FALLINGDETECT, |
| 1705 | }; |
| 1706 | |
| 1707 | static struct omap_gpio_reg_offs omap4_gpio_regs = { |
| 1708 | .revision = OMAP4_GPIO_REVISION, |
| 1709 | .direction = OMAP4_GPIO_OE, |
| 1710 | .datain = OMAP4_GPIO_DATAIN, |
| 1711 | .dataout = OMAP4_GPIO_DATAOUT, |
| 1712 | .set_dataout = OMAP4_GPIO_SETDATAOUT, |
| 1713 | .clr_dataout = OMAP4_GPIO_CLEARDATAOUT, |
| 1714 | .irqstatus = OMAP4_GPIO_IRQSTATUS0, |
| 1715 | .irqstatus2 = OMAP4_GPIO_IRQSTATUS1, |
| 1716 | .irqenable = OMAP4_GPIO_IRQSTATUSSET0, |
| 1717 | .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1, |
| 1718 | .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0, |
| 1719 | .clr_irqenable = OMAP4_GPIO_IRQSTATUSCLR0, |
| 1720 | .debounce = OMAP4_GPIO_DEBOUNCINGTIME, |
| 1721 | .debounce_en = OMAP4_GPIO_DEBOUNCENABLE, |
| 1722 | .ctrl = OMAP4_GPIO_CTRL, |
| 1723 | .wkup_en = OMAP4_GPIO_IRQWAKEN0, |
| 1724 | .leveldetect0 = OMAP4_GPIO_LEVELDETECT0, |
| 1725 | .leveldetect1 = OMAP4_GPIO_LEVELDETECT1, |
| 1726 | .risingdetect = OMAP4_GPIO_RISINGDETECT, |
| 1727 | .fallingdetect = OMAP4_GPIO_FALLINGDETECT, |
| 1728 | }; |
| 1729 | |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1730 | /* |
| 1731 | * Note that omap2 does not currently support idle modes with context loss so |
| 1732 | * no need to add OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER quirk flag to save |
| 1733 | * and restore context. |
| 1734 | */ |
Chen Gang | e9a65bb | 2013-02-06 18:44:32 +0800 | [diff] [blame] | 1735 | static const struct omap_gpio_platform_data omap2_pdata = { |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1736 | .regs = &omap2_gpio_regs, |
| 1737 | .bank_width = 32, |
| 1738 | .dbck_flag = false, |
| 1739 | }; |
| 1740 | |
Chen Gang | e9a65bb | 2013-02-06 18:44:32 +0800 | [diff] [blame] | 1741 | static const struct omap_gpio_platform_data omap3_pdata = { |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1742 | .regs = &omap2_gpio_regs, |
| 1743 | .bank_width = 32, |
| 1744 | .dbck_flag = true, |
Tony Lindgren | b764a58 | 2018-09-20 12:35:31 -0700 | [diff] [blame] | 1745 | .quirks = OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER, |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1746 | }; |
| 1747 | |
Chen Gang | e9a65bb | 2013-02-06 18:44:32 +0800 | [diff] [blame] | 1748 | static const struct omap_gpio_platform_data omap4_pdata = { |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1749 | .regs = &omap4_gpio_regs, |
| 1750 | .bank_width = 32, |
| 1751 | .dbck_flag = true, |
Tony Lindgren | 00ded24 | 2018-12-07 11:08:29 -0800 | [diff] [blame] | 1752 | .quirks = OMAP_GPIO_QUIRK_IDLE_REMOVE_TRIGGER, |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1753 | }; |
| 1754 | |
| 1755 | static const struct of_device_id omap_gpio_match[] = { |
| 1756 | { |
| 1757 | .compatible = "ti,omap4-gpio", |
| 1758 | .data = &omap4_pdata, |
| 1759 | }, |
| 1760 | { |
| 1761 | .compatible = "ti,omap3-gpio", |
| 1762 | .data = &omap3_pdata, |
| 1763 | }, |
| 1764 | { |
| 1765 | .compatible = "ti,omap2-gpio", |
| 1766 | .data = &omap2_pdata, |
| 1767 | }, |
| 1768 | { }, |
| 1769 | }; |
| 1770 | MODULE_DEVICE_TABLE(of, omap_gpio_match); |
| 1771 | #endif |
| 1772 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1773 | static struct platform_driver omap_gpio_driver = { |
| 1774 | .probe = omap_gpio_probe, |
Tony Lindgren | cac089f | 2015-04-23 16:56:22 -0700 | [diff] [blame] | 1775 | .remove = omap_gpio_remove, |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1776 | .driver = { |
| 1777 | .name = "omap_gpio", |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1778 | .pm = &gpio_pm_ops, |
Benoit Cousson | 384ebe1 | 2011-08-16 11:53:02 +0200 | [diff] [blame] | 1779 | .of_match_table = of_match_ptr(omap_gpio_match), |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1780 | }, |
| 1781 | }; |
| 1782 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1783 | /* |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1784 | * gpio driver register needs to be done before |
| 1785 | * machine_init functions access gpio APIs. |
| 1786 | * Hence omap_gpio_drv_reg() is a postcore_initcall. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1787 | */ |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1788 | static int __init omap_gpio_drv_reg(void) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1789 | { |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1790 | return platform_driver_register(&omap_gpio_driver); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1791 | } |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1792 | postcore_initcall(omap_gpio_drv_reg); |
Tony Lindgren | cac089f | 2015-04-23 16:56:22 -0700 | [diff] [blame] | 1793 | |
| 1794 | static void __exit omap_gpio_exit(void) |
| 1795 | { |
| 1796 | platform_driver_unregister(&omap_gpio_driver); |
| 1797 | } |
| 1798 | module_exit(omap_gpio_exit); |
| 1799 | |
| 1800 | MODULE_DESCRIPTION("omap gpio driver"); |
| 1801 | MODULE_ALIAS("platform:gpio-omap"); |
| 1802 | MODULE_LICENSE("GPL v2"); |