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