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