Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013, Sony Mobile Communications AB. |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 3 | * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved. |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 and |
| 7 | * only version 2 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 15 | #include <linux/delay.h> |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 16 | #include <linux/err.h> |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 17 | #include <linux/io.h> |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 18 | #include <linux/irq.h> |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/of.h> |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 21 | #include <linux/of_irq.h> |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/pinctrl/machine.h> |
| 24 | #include <linux/pinctrl/pinctrl.h> |
| 25 | #include <linux/pinctrl/pinmux.h> |
| 26 | #include <linux/pinctrl/pinconf.h> |
| 27 | #include <linux/pinctrl/pinconf-generic.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/gpio.h> |
| 30 | #include <linux/interrupt.h> |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 31 | #include <linux/spinlock.h> |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 32 | #include <linux/reboot.h> |
Stephen Boyd | ad64498 | 2015-07-06 18:09:30 -0700 | [diff] [blame] | 33 | #include <linux/pm.h> |
Stephen Boyd | 47a01ee | 2016-06-25 22:21:31 -0700 | [diff] [blame] | 34 | #include <linux/log2.h> |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 35 | #include <linux/irq.h> |
Linus Walleij | 69b78b8 | 2014-07-09 13:55:12 +0200 | [diff] [blame] | 36 | #include "../core.h" |
| 37 | #include "../pinconf.h" |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 38 | #include "pinctrl-msm.h" |
Linus Walleij | 69b78b8 | 2014-07-09 13:55:12 +0200 | [diff] [blame] | 39 | #include "../pinctrl-utils.h" |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 40 | |
Bjorn Andersson | 408e3c6 | 2013-12-14 23:01:53 -0800 | [diff] [blame] | 41 | #define MAX_NR_GPIO 300 |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 42 | #define PS_HOLD_OFFSET 0x820 |
Bjorn Andersson | 408e3c6 | 2013-12-14 23:01:53 -0800 | [diff] [blame] | 43 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 44 | /** |
| 45 | * struct msm_pinctrl - state for a pinctrl-msm device |
| 46 | * @dev: device handle. |
| 47 | * @pctrl: pinctrl handle. |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 48 | * @chip: gpiochip handle. |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 49 | * @restart_nb: restart notifier block. |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 50 | * @irq: parent irq for the TLMM irq_chip. |
| 51 | * @lock: Spinlock to protect register resources as well |
| 52 | * as msm_pinctrl data structures. |
| 53 | * @enabled_irqs: Bitmap of currently enabled irqs. |
| 54 | * @dual_edge_irqs: Bitmap of irqs that need sw emulated dual edge |
| 55 | * detection. |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 56 | * @soc; Reference to soc_data of platform specific data. |
| 57 | * @regs: Base address for the TLMM register map. |
| 58 | */ |
| 59 | struct msm_pinctrl { |
| 60 | struct device *dev; |
| 61 | struct pinctrl_dev *pctrl; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 62 | struct gpio_chip chip; |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 63 | struct notifier_block restart_nb; |
Bjorn Andersson | f393e48 | 2013-12-14 23:01:52 -0800 | [diff] [blame] | 64 | int irq; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 65 | |
| 66 | spinlock_t lock; |
| 67 | |
Bjorn Andersson | 408e3c6 | 2013-12-14 23:01:53 -0800 | [diff] [blame] | 68 | DECLARE_BITMAP(dual_edge_irqs, MAX_NR_GPIO); |
| 69 | DECLARE_BITMAP(enabled_irqs, MAX_NR_GPIO); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 70 | |
| 71 | const struct msm_pinctrl_soc_data *soc; |
| 72 | void __iomem *regs; |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 73 | void __iomem *pdc_regs; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static int msm_get_groups_count(struct pinctrl_dev *pctldev) |
| 77 | { |
| 78 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 79 | |
| 80 | return pctrl->soc->ngroups; |
| 81 | } |
| 82 | |
| 83 | static const char *msm_get_group_name(struct pinctrl_dev *pctldev, |
| 84 | unsigned group) |
| 85 | { |
| 86 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 87 | |
| 88 | return pctrl->soc->groups[group].name; |
| 89 | } |
| 90 | |
| 91 | static int msm_get_group_pins(struct pinctrl_dev *pctldev, |
| 92 | unsigned group, |
| 93 | const unsigned **pins, |
| 94 | unsigned *num_pins) |
| 95 | { |
| 96 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 97 | |
| 98 | *pins = pctrl->soc->groups[group].pins; |
| 99 | *num_pins = pctrl->soc->groups[group].npins; |
| 100 | return 0; |
| 101 | } |
| 102 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 103 | static const struct pinctrl_ops msm_pinctrl_ops = { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 104 | .get_groups_count = msm_get_groups_count, |
| 105 | .get_group_name = msm_get_group_name, |
| 106 | .get_group_pins = msm_get_group_pins, |
| 107 | .dt_node_to_map = pinconf_generic_dt_node_to_map_group, |
Irina Tirdea | d32f7fd | 2016-03-31 14:44:42 +0300 | [diff] [blame] | 108 | .dt_free_map = pinctrl_utils_free_map, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | static int msm_get_functions_count(struct pinctrl_dev *pctldev) |
| 112 | { |
| 113 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 114 | |
| 115 | return pctrl->soc->nfunctions; |
| 116 | } |
| 117 | |
| 118 | static const char *msm_get_function_name(struct pinctrl_dev *pctldev, |
| 119 | unsigned function) |
| 120 | { |
| 121 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 122 | |
| 123 | return pctrl->soc->functions[function].name; |
| 124 | } |
| 125 | |
| 126 | static int msm_get_function_groups(struct pinctrl_dev *pctldev, |
| 127 | unsigned function, |
| 128 | const char * const **groups, |
| 129 | unsigned * const num_groups) |
| 130 | { |
| 131 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 132 | |
| 133 | *groups = pctrl->soc->functions[function].groups; |
| 134 | *num_groups = pctrl->soc->functions[function].ngroups; |
| 135 | return 0; |
| 136 | } |
| 137 | |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 138 | static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev, |
| 139 | unsigned function, |
| 140 | unsigned group) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 141 | { |
| 142 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 143 | const struct msm_pingroup *g; |
| 144 | unsigned long flags; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 145 | u32 val, mask; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 146 | int i; |
| 147 | |
| 148 | g = &pctrl->soc->groups[group]; |
Stephen Boyd | 47a01ee | 2016-06-25 22:21:31 -0700 | [diff] [blame] | 149 | mask = GENMASK(g->mux_bit + order_base_2(g->nfuncs) - 1, g->mux_bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 150 | |
Bjorn Andersson | 3c25381 | 2014-03-31 14:49:55 -0700 | [diff] [blame] | 151 | for (i = 0; i < g->nfuncs; i++) { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 152 | if (g->funcs[i] == function) |
| 153 | break; |
| 154 | } |
| 155 | |
Bjorn Andersson | 3c25381 | 2014-03-31 14:49:55 -0700 | [diff] [blame] | 156 | if (WARN_ON(i == g->nfuncs)) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 157 | return -EINVAL; |
| 158 | |
| 159 | spin_lock_irqsave(&pctrl->lock, flags); |
| 160 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 161 | val = readl(pctrl->regs + g->ctl_reg); |
John Crispin | 6bcf3f6 | 2016-09-12 11:36:55 +0200 | [diff] [blame] | 162 | val &= ~mask; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 163 | val |= i << g->mux_bit; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 164 | writel(val, pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 165 | |
| 166 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 171 | static const struct pinmux_ops msm_pinmux_ops = { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 172 | .get_functions_count = msm_get_functions_count, |
| 173 | .get_function_name = msm_get_function_name, |
| 174 | .get_function_groups = msm_get_function_groups, |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 175 | .set_mux = msm_pinmux_set_mux, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | static int msm_config_reg(struct msm_pinctrl *pctrl, |
| 179 | const struct msm_pingroup *g, |
| 180 | unsigned param, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 181 | unsigned *mask, |
| 182 | unsigned *bit) |
| 183 | { |
| 184 | switch (param) { |
| 185 | case PIN_CONFIG_BIAS_DISABLE: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 186 | case PIN_CONFIG_BIAS_PULL_DOWN: |
Andy Gross | b831a15 | 2014-06-17 23:49:11 -0500 | [diff] [blame] | 187 | case PIN_CONFIG_BIAS_BUS_HOLD: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 188 | case PIN_CONFIG_BIAS_PULL_UP: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 189 | *bit = g->pull_bit; |
| 190 | *mask = 3; |
| 191 | break; |
| 192 | case PIN_CONFIG_DRIVE_STRENGTH: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 193 | *bit = g->drv_bit; |
| 194 | *mask = 7; |
| 195 | break; |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 196 | case PIN_CONFIG_OUTPUT: |
Stanimir Varbanov | 407f5e3 | 2015-03-04 12:41:57 +0200 | [diff] [blame] | 197 | case PIN_CONFIG_INPUT_ENABLE: |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 198 | *bit = g->oe_bit; |
| 199 | *mask = 1; |
| 200 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 201 | default: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 202 | return -ENOTSUPP; |
| 203 | } |
| 204 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 205 | return 0; |
| 206 | } |
| 207 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 208 | #define MSM_NO_PULL 0 |
| 209 | #define MSM_PULL_DOWN 1 |
Andy Gross | b831a15 | 2014-06-17 23:49:11 -0500 | [diff] [blame] | 210 | #define MSM_KEEPER 2 |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 211 | #define MSM_PULL_UP 3 |
| 212 | |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 213 | static unsigned msm_regval_to_drive(u32 val) |
| 214 | { |
| 215 | return (val + 1) * 2; |
| 216 | } |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 217 | |
| 218 | static int msm_config_group_get(struct pinctrl_dev *pctldev, |
| 219 | unsigned int group, |
| 220 | unsigned long *config) |
| 221 | { |
| 222 | const struct msm_pingroup *g; |
| 223 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 224 | unsigned param = pinconf_to_config_param(*config); |
| 225 | unsigned mask; |
| 226 | unsigned arg; |
| 227 | unsigned bit; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 228 | int ret; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 229 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 230 | |
| 231 | g = &pctrl->soc->groups[group]; |
| 232 | |
Stephen Boyd | 051a58b | 2014-03-06 22:44:46 -0800 | [diff] [blame] | 233 | ret = msm_config_reg(pctrl, g, param, &mask, &bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 234 | if (ret < 0) |
| 235 | return ret; |
| 236 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 237 | val = readl(pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 238 | arg = (val >> bit) & mask; |
| 239 | |
| 240 | /* Convert register value to pinconf value */ |
| 241 | switch (param) { |
| 242 | case PIN_CONFIG_BIAS_DISABLE: |
| 243 | arg = arg == MSM_NO_PULL; |
| 244 | break; |
| 245 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 246 | arg = arg == MSM_PULL_DOWN; |
| 247 | break; |
Andy Gross | b831a15 | 2014-06-17 23:49:11 -0500 | [diff] [blame] | 248 | case PIN_CONFIG_BIAS_BUS_HOLD: |
| 249 | arg = arg == MSM_KEEPER; |
| 250 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 251 | case PIN_CONFIG_BIAS_PULL_UP: |
| 252 | arg = arg == MSM_PULL_UP; |
| 253 | break; |
| 254 | case PIN_CONFIG_DRIVE_STRENGTH: |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 255 | arg = msm_regval_to_drive(arg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 256 | break; |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 257 | case PIN_CONFIG_OUTPUT: |
| 258 | /* Pin is not output */ |
| 259 | if (!arg) |
| 260 | return -EINVAL; |
| 261 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 262 | val = readl(pctrl->regs + g->io_reg); |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 263 | arg = !!(val & BIT(g->in_bit)); |
| 264 | break; |
Stanimir Varbanov | 407f5e3 | 2015-03-04 12:41:57 +0200 | [diff] [blame] | 265 | case PIN_CONFIG_INPUT_ENABLE: |
| 266 | /* Pin is output */ |
| 267 | if (arg) |
| 268 | return -EINVAL; |
| 269 | arg = 1; |
| 270 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 271 | default: |
Stanimir Varbanov | 38d756a | 2015-03-04 12:41:56 +0200 | [diff] [blame] | 272 | return -ENOTSUPP; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | *config = pinconf_to_config_packed(param, arg); |
| 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | static int msm_config_group_set(struct pinctrl_dev *pctldev, |
| 281 | unsigned group, |
| 282 | unsigned long *configs, |
| 283 | unsigned num_configs) |
| 284 | { |
| 285 | const struct msm_pingroup *g; |
| 286 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 287 | unsigned long flags; |
| 288 | unsigned param; |
| 289 | unsigned mask; |
| 290 | unsigned arg; |
| 291 | unsigned bit; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 292 | int ret; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 293 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 294 | int i; |
| 295 | |
| 296 | g = &pctrl->soc->groups[group]; |
| 297 | |
| 298 | for (i = 0; i < num_configs; i++) { |
| 299 | param = pinconf_to_config_param(configs[i]); |
| 300 | arg = pinconf_to_config_argument(configs[i]); |
| 301 | |
Stephen Boyd | 051a58b | 2014-03-06 22:44:46 -0800 | [diff] [blame] | 302 | ret = msm_config_reg(pctrl, g, param, &mask, &bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 303 | if (ret < 0) |
| 304 | return ret; |
| 305 | |
| 306 | /* Convert pinconf values to register values */ |
| 307 | switch (param) { |
| 308 | case PIN_CONFIG_BIAS_DISABLE: |
| 309 | arg = MSM_NO_PULL; |
| 310 | break; |
| 311 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 312 | arg = MSM_PULL_DOWN; |
| 313 | break; |
Andy Gross | b831a15 | 2014-06-17 23:49:11 -0500 | [diff] [blame] | 314 | case PIN_CONFIG_BIAS_BUS_HOLD: |
| 315 | arg = MSM_KEEPER; |
| 316 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 317 | case PIN_CONFIG_BIAS_PULL_UP: |
| 318 | arg = MSM_PULL_UP; |
| 319 | break; |
| 320 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 321 | /* Check for invalid values */ |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 322 | if (arg > 16 || arg < 2 || (arg % 2) != 0) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 323 | arg = -1; |
| 324 | else |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 325 | arg = (arg / 2) - 1; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 326 | break; |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 327 | case PIN_CONFIG_OUTPUT: |
| 328 | /* set output value */ |
| 329 | spin_lock_irqsave(&pctrl->lock, flags); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 330 | val = readl(pctrl->regs + g->io_reg); |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 331 | if (arg) |
| 332 | val |= BIT(g->out_bit); |
| 333 | else |
| 334 | val &= ~BIT(g->out_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 335 | writel(val, pctrl->regs + g->io_reg); |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 336 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 337 | |
| 338 | /* enable output */ |
| 339 | arg = 1; |
| 340 | break; |
Stanimir Varbanov | 407f5e3 | 2015-03-04 12:41:57 +0200 | [diff] [blame] | 341 | case PIN_CONFIG_INPUT_ENABLE: |
| 342 | /* disable output */ |
| 343 | arg = 0; |
| 344 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 345 | default: |
| 346 | dev_err(pctrl->dev, "Unsupported config parameter: %x\n", |
| 347 | param); |
| 348 | return -EINVAL; |
| 349 | } |
| 350 | |
| 351 | /* Range-check user-supplied value */ |
| 352 | if (arg & ~mask) { |
| 353 | dev_err(pctrl->dev, "config %x: %x is invalid\n", param, arg); |
| 354 | return -EINVAL; |
| 355 | } |
| 356 | |
| 357 | spin_lock_irqsave(&pctrl->lock, flags); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 358 | val = readl(pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 359 | val &= ~(mask << bit); |
| 360 | val |= arg << bit; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 361 | writel(val, pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 362 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 363 | } |
| 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 368 | static const struct pinconf_ops msm_pinconf_ops = { |
Stanimir Varbanov | 38d756a | 2015-03-04 12:41:56 +0200 | [diff] [blame] | 369 | .is_generic = true, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 370 | .pin_config_group_get = msm_config_group_get, |
| 371 | .pin_config_group_set = msm_config_group_set, |
| 372 | }; |
| 373 | |
| 374 | static struct pinctrl_desc msm_pinctrl_desc = { |
| 375 | .pctlops = &msm_pinctrl_ops, |
| 376 | .pmxops = &msm_pinmux_ops, |
| 377 | .confops = &msm_pinconf_ops, |
| 378 | .owner = THIS_MODULE, |
| 379 | }; |
| 380 | |
| 381 | static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
| 382 | { |
| 383 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 384 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 385 | unsigned long flags; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 386 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 387 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 388 | g = &pctrl->soc->groups[offset]; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 389 | |
| 390 | spin_lock_irqsave(&pctrl->lock, flags); |
| 391 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 392 | val = readl(pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 393 | val &= ~BIT(g->oe_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 394 | writel(val, pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 395 | |
| 396 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static int msm_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) |
| 402 | { |
| 403 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 404 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 405 | unsigned long flags; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 406 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 407 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 408 | g = &pctrl->soc->groups[offset]; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 409 | |
| 410 | spin_lock_irqsave(&pctrl->lock, flags); |
| 411 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 412 | val = readl(pctrl->regs + g->io_reg); |
Axel Lin | e476e77 | 2013-12-13 21:35:55 +0800 | [diff] [blame] | 413 | if (value) |
| 414 | val |= BIT(g->out_bit); |
| 415 | else |
| 416 | val &= ~BIT(g->out_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 417 | writel(val, pctrl->regs + g->io_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 418 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 419 | val = readl(pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 420 | val |= BIT(g->oe_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 421 | writel(val, pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 422 | |
| 423 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | static int msm_gpio_get(struct gpio_chip *chip, unsigned offset) |
| 429 | { |
| 430 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 431 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 432 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 433 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 434 | g = &pctrl->soc->groups[offset]; |
| 435 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 436 | val = readl(pctrl->regs + g->io_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 437 | return !!(val & BIT(g->in_bit)); |
| 438 | } |
| 439 | |
| 440 | static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 441 | { |
| 442 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 443 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 444 | unsigned long flags; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 445 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 446 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 447 | g = &pctrl->soc->groups[offset]; |
| 448 | |
| 449 | spin_lock_irqsave(&pctrl->lock, flags); |
| 450 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 451 | val = readl(pctrl->regs + g->io_reg); |
Axel Lin | e476e77 | 2013-12-13 21:35:55 +0800 | [diff] [blame] | 452 | if (value) |
| 453 | val |= BIT(g->out_bit); |
| 454 | else |
| 455 | val &= ~BIT(g->out_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 456 | writel(val, pctrl->regs + g->io_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 457 | |
| 458 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 459 | } |
| 460 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 461 | #ifdef CONFIG_DEBUG_FS |
| 462 | #include <linux/seq_file.h> |
| 463 | |
| 464 | static void msm_gpio_dbg_show_one(struct seq_file *s, |
| 465 | struct pinctrl_dev *pctldev, |
| 466 | struct gpio_chip *chip, |
| 467 | unsigned offset, |
| 468 | unsigned gpio) |
| 469 | { |
| 470 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 471 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 472 | unsigned func; |
| 473 | int is_out; |
| 474 | int drive; |
| 475 | int pull; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 476 | u32 ctl_reg; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 477 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 478 | static const char * const pulls[] = { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 479 | "no pull", |
| 480 | "pull down", |
| 481 | "keeper", |
| 482 | "pull up" |
| 483 | }; |
| 484 | |
| 485 | g = &pctrl->soc->groups[offset]; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 486 | ctl_reg = readl(pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 487 | |
| 488 | is_out = !!(ctl_reg & BIT(g->oe_bit)); |
| 489 | func = (ctl_reg >> g->mux_bit) & 7; |
| 490 | drive = (ctl_reg >> g->drv_bit) & 7; |
| 491 | pull = (ctl_reg >> g->pull_bit) & 3; |
| 492 | |
| 493 | seq_printf(s, " %-8s: %-3s %d", g->name, is_out ? "out" : "in", func); |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 494 | seq_printf(s, " %dmA", msm_regval_to_drive(drive)); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 495 | seq_printf(s, " %s", pulls[pull]); |
| 496 | } |
| 497 | |
| 498 | static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) |
| 499 | { |
| 500 | unsigned gpio = chip->base; |
| 501 | unsigned i; |
| 502 | |
| 503 | for (i = 0; i < chip->ngpio; i++, gpio++) { |
| 504 | msm_gpio_dbg_show_one(s, NULL, chip, i, gpio); |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 505 | seq_puts(s, "\n"); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
| 509 | #else |
| 510 | #define msm_gpio_dbg_show NULL |
| 511 | #endif |
| 512 | |
| 513 | static struct gpio_chip msm_gpio_template = { |
| 514 | .direction_input = msm_gpio_direction_input, |
| 515 | .direction_output = msm_gpio_direction_output, |
| 516 | .get = msm_gpio_get, |
| 517 | .set = msm_gpio_set, |
Jonas Gorski | 98c85d5 | 2015-10-11 17:34:19 +0200 | [diff] [blame] | 518 | .request = gpiochip_generic_request, |
| 519 | .free = gpiochip_generic_free, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 520 | .dbg_show = msm_gpio_dbg_show, |
| 521 | }; |
| 522 | |
| 523 | /* For dual-edge interrupts in software, since some hardware has no |
| 524 | * such support: |
| 525 | * |
| 526 | * At appropriate moments, this function may be called to flip the polarity |
| 527 | * settings of both-edge irq lines to try and catch the next edge. |
| 528 | * |
| 529 | * The attempt is considered successful if: |
| 530 | * - the status bit goes high, indicating that an edge was caught, or |
| 531 | * - the input value of the gpio doesn't change during the attempt. |
| 532 | * If the value changes twice during the process, that would cause the first |
| 533 | * test to fail but would force the second, as two opposite |
| 534 | * transitions would cause a detection no matter the polarity setting. |
| 535 | * |
| 536 | * The do-loop tries to sledge-hammer closed the timing hole between |
| 537 | * the initial value-read and the polarity-write - if the line value changes |
| 538 | * during that window, an interrupt is lost, the new polarity setting is |
| 539 | * incorrect, and the first success test will fail, causing a retry. |
| 540 | * |
| 541 | * Algorithm comes from Google's msmgpio driver. |
| 542 | */ |
| 543 | static void msm_gpio_update_dual_edge_pos(struct msm_pinctrl *pctrl, |
| 544 | const struct msm_pingroup *g, |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 545 | struct irq_data *d) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 546 | { |
| 547 | int loop_limit = 100; |
| 548 | unsigned val, val2, intstat; |
| 549 | unsigned pol; |
| 550 | |
| 551 | do { |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 552 | val = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 553 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 554 | pol = readl(pctrl->regs + g->intr_cfg_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 555 | pol ^= BIT(g->intr_polarity_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 556 | writel(pol, pctrl->regs + g->intr_cfg_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 557 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 558 | val2 = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit); |
| 559 | intstat = readl(pctrl->regs + g->intr_status_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 560 | if (intstat || (val == val2)) |
| 561 | return; |
| 562 | } while (loop_limit-- > 0); |
| 563 | dev_err(pctrl->dev, "dual-edge irq failed to stabilize, %#08x != %#08x\n", |
| 564 | val, val2); |
| 565 | } |
| 566 | |
| 567 | static void msm_gpio_irq_mask(struct irq_data *d) |
| 568 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 569 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 570 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 571 | const struct msm_pingroup *g; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 572 | unsigned long flags; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 573 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 574 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 575 | g = &pctrl->soc->groups[d->hwirq]; |
| 576 | |
| 577 | spin_lock_irqsave(&pctrl->lock, flags); |
| 578 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 579 | val = readl(pctrl->regs + g->intr_cfg_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 580 | val &= ~BIT(g->intr_enable_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 581 | writel(val, pctrl->regs + g->intr_cfg_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 582 | |
| 583 | clear_bit(d->hwirq, pctrl->enabled_irqs); |
| 584 | |
| 585 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 586 | } |
| 587 | |
Srinivas Ramana | 6952139 | 2017-11-14 11:36:23 +0530 | [diff] [blame] | 588 | static void msm_gpio_irq_enable(struct irq_data *d) |
| 589 | { |
| 590 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 591 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
| 592 | const struct msm_pingroup *g; |
| 593 | unsigned long flags; |
| 594 | u32 val; |
| 595 | |
| 596 | g = &pctrl->soc->groups[d->hwirq]; |
| 597 | |
| 598 | spin_lock_irqsave(&pctrl->lock, flags); |
| 599 | /* clear the interrupt status bit before unmask to avoid |
| 600 | * any erraneous interrupts that would have got latched |
| 601 | * when the intterupt is not in use. |
| 602 | */ |
| 603 | val = readl(pctrl->regs + g->intr_status_reg); |
| 604 | val &= ~BIT(g->intr_status_bit); |
| 605 | writel(val, pctrl->regs + g->intr_status_reg); |
| 606 | |
| 607 | val = readl(pctrl->regs + g->intr_cfg_reg); |
| 608 | val |= BIT(g->intr_enable_bit); |
| 609 | writel(val, pctrl->regs + g->intr_cfg_reg); |
| 610 | |
| 611 | set_bit(d->hwirq, pctrl->enabled_irqs); |
| 612 | |
| 613 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 614 | } |
| 615 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 616 | static void msm_gpio_irq_unmask(struct irq_data *d) |
| 617 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 618 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 619 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 620 | const struct msm_pingroup *g; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 621 | unsigned long flags; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 622 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 623 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 624 | g = &pctrl->soc->groups[d->hwirq]; |
| 625 | |
| 626 | spin_lock_irqsave(&pctrl->lock, flags); |
| 627 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 628 | val = readl(pctrl->regs + g->intr_cfg_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 629 | val |= BIT(g->intr_enable_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 630 | writel(val, pctrl->regs + g->intr_cfg_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 631 | |
| 632 | set_bit(d->hwirq, pctrl->enabled_irqs); |
| 633 | |
| 634 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 635 | } |
| 636 | |
| 637 | static void msm_gpio_irq_ack(struct irq_data *d) |
| 638 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 639 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 640 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 641 | const struct msm_pingroup *g; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 642 | unsigned long flags; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 643 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 644 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 645 | g = &pctrl->soc->groups[d->hwirq]; |
| 646 | |
| 647 | spin_lock_irqsave(&pctrl->lock, flags); |
| 648 | |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 649 | val = readl(pctrl->regs + g->intr_status_reg); |
Bjorn Andersson | 48f15e9 | 2014-03-31 14:49:54 -0700 | [diff] [blame] | 650 | if (g->intr_ack_high) |
| 651 | val |= BIT(g->intr_status_bit); |
| 652 | else |
| 653 | val &= ~BIT(g->intr_status_bit); |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 654 | writel(val, pctrl->regs + g->intr_status_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 655 | |
| 656 | if (test_bit(d->hwirq, pctrl->dual_edge_irqs)) |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 657 | msm_gpio_update_dual_edge_pos(pctrl, g, d); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 658 | |
| 659 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 660 | } |
| 661 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 662 | static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) |
| 663 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 664 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 665 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 666 | const struct msm_pingroup *g; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 667 | unsigned long flags; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 668 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 669 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 670 | g = &pctrl->soc->groups[d->hwirq]; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 671 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 672 | spin_lock_irqsave(&pctrl->lock, flags); |
| 673 | |
| 674 | /* |
| 675 | * For hw without possibility of detecting both edges |
| 676 | */ |
| 677 | if (g->intr_detection_width == 1 && type == IRQ_TYPE_EDGE_BOTH) |
| 678 | set_bit(d->hwirq, pctrl->dual_edge_irqs); |
| 679 | else |
| 680 | clear_bit(d->hwirq, pctrl->dual_edge_irqs); |
| 681 | |
| 682 | /* Route interrupts to application cpu */ |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 683 | val = readl(pctrl->regs + g->intr_target_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 684 | val &= ~(7 << g->intr_target_bit); |
Georgi Djakov | f712c55 | 2014-09-03 19:28:16 +0300 | [diff] [blame] | 685 | val |= g->intr_target_kpss_val << g->intr_target_bit; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 686 | writel(val, pctrl->regs + g->intr_target_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 687 | |
| 688 | /* Update configuration for gpio. |
| 689 | * RAW_STATUS_EN is left on for all gpio irqs. Due to the |
| 690 | * internal circuitry of TLMM, toggling the RAW_STATUS |
| 691 | * could cause the INTR_STATUS to be set for EDGE interrupts. |
| 692 | */ |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 693 | val = readl(pctrl->regs + g->intr_cfg_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 694 | val |= BIT(g->intr_raw_status_bit); |
| 695 | if (g->intr_detection_width == 2) { |
| 696 | val &= ~(3 << g->intr_detection_bit); |
| 697 | val &= ~(1 << g->intr_polarity_bit); |
| 698 | switch (type) { |
| 699 | case IRQ_TYPE_EDGE_RISING: |
| 700 | val |= 1 << g->intr_detection_bit; |
| 701 | val |= BIT(g->intr_polarity_bit); |
| 702 | break; |
| 703 | case IRQ_TYPE_EDGE_FALLING: |
| 704 | val |= 2 << g->intr_detection_bit; |
| 705 | val |= BIT(g->intr_polarity_bit); |
| 706 | break; |
| 707 | case IRQ_TYPE_EDGE_BOTH: |
| 708 | val |= 3 << g->intr_detection_bit; |
| 709 | val |= BIT(g->intr_polarity_bit); |
| 710 | break; |
| 711 | case IRQ_TYPE_LEVEL_LOW: |
| 712 | break; |
| 713 | case IRQ_TYPE_LEVEL_HIGH: |
| 714 | val |= BIT(g->intr_polarity_bit); |
| 715 | break; |
| 716 | } |
| 717 | } else if (g->intr_detection_width == 1) { |
| 718 | val &= ~(1 << g->intr_detection_bit); |
| 719 | val &= ~(1 << g->intr_polarity_bit); |
| 720 | switch (type) { |
| 721 | case IRQ_TYPE_EDGE_RISING: |
| 722 | val |= BIT(g->intr_detection_bit); |
| 723 | val |= BIT(g->intr_polarity_bit); |
| 724 | break; |
| 725 | case IRQ_TYPE_EDGE_FALLING: |
| 726 | val |= BIT(g->intr_detection_bit); |
| 727 | break; |
| 728 | case IRQ_TYPE_EDGE_BOTH: |
| 729 | val |= BIT(g->intr_detection_bit); |
Bjorn Andersson | 48f15e9 | 2014-03-31 14:49:54 -0700 | [diff] [blame] | 730 | val |= BIT(g->intr_polarity_bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 731 | break; |
| 732 | case IRQ_TYPE_LEVEL_LOW: |
| 733 | break; |
| 734 | case IRQ_TYPE_LEVEL_HIGH: |
| 735 | val |= BIT(g->intr_polarity_bit); |
| 736 | break; |
| 737 | } |
| 738 | } else { |
| 739 | BUG(); |
| 740 | } |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 741 | writel(val, pctrl->regs + g->intr_cfg_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 742 | |
| 743 | if (test_bit(d->hwirq, pctrl->dual_edge_irqs)) |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 744 | msm_gpio_update_dual_edge_pos(pctrl, g, d); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 745 | |
| 746 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 747 | |
| 748 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
Thomas Gleixner | 34c0ad8 | 2015-06-23 15:52:51 +0200 | [diff] [blame] | 749 | irq_set_handler_locked(d, handle_level_irq); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 750 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
Thomas Gleixner | 34c0ad8 | 2015-06-23 15:52:51 +0200 | [diff] [blame] | 751 | irq_set_handler_locked(d, handle_edge_irq); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on) |
| 757 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 758 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 759 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 760 | unsigned long flags; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 761 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 762 | spin_lock_irqsave(&pctrl->lock, flags); |
| 763 | |
Josh Cartwright | 6aced33 | 2014-03-05 13:33:08 -0600 | [diff] [blame] | 764 | irq_set_irq_wake(pctrl->irq, on); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 765 | |
| 766 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 771 | static struct irq_chip msm_gpio_irq_chip = { |
| 772 | .name = "msmgpio", |
Srinivas Ramana | 6952139 | 2017-11-14 11:36:23 +0530 | [diff] [blame] | 773 | .irq_enable = msm_gpio_irq_enable, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 774 | .irq_mask = msm_gpio_irq_mask, |
| 775 | .irq_unmask = msm_gpio_irq_unmask, |
| 776 | .irq_ack = msm_gpio_irq_ack, |
| 777 | .irq_set_type = msm_gpio_irq_set_type, |
| 778 | .irq_set_wake = msm_gpio_irq_set_wake, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 779 | }; |
| 780 | |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 781 | static struct irq_chip msm_dirconn_irq_chip; |
| 782 | |
| 783 | static void msm_gpio_dirconn_handler(struct irq_desc *desc) |
| 784 | { |
| 785 | struct irq_data *irqd = irq_desc_get_handler_data(desc); |
| 786 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 787 | |
| 788 | chained_irq_enter(chip, desc); |
| 789 | generic_handle_irq(irqd->irq); |
| 790 | chained_irq_exit(chip, desc); |
| 791 | } |
| 792 | |
| 793 | static void setup_pdc_gpio(struct irq_domain *domain, |
| 794 | unsigned int parent_irq, unsigned int gpio) |
| 795 | { |
| 796 | int irq; |
| 797 | |
| 798 | if (gpio != 0) { |
| 799 | irq = irq_find_mapping(domain, gpio); |
| 800 | irq_set_parent(irq, parent_irq); |
| 801 | irq_set_chip(irq, &msm_dirconn_irq_chip); |
| 802 | irq_set_handler_data(parent_irq, irq_get_irq_data(irq)); |
| 803 | } |
| 804 | |
| 805 | __irq_set_handler(parent_irq, msm_gpio_dirconn_handler, false, NULL); |
| 806 | } |
| 807 | |
| 808 | static void request_dc_interrupt(struct irq_domain *domain, |
| 809 | struct irq_domain *parent, irq_hw_number_t hwirq, |
| 810 | unsigned int gpio) |
| 811 | { |
| 812 | struct irq_fwspec fwspec; |
| 813 | unsigned int parent_irq; |
| 814 | |
| 815 | fwspec.fwnode = parent->fwnode; |
| 816 | fwspec.param[0] = 0; /* SPI */ |
| 817 | fwspec.param[1] = hwirq; |
| 818 | fwspec.param[2] = IRQ_TYPE_NONE; |
| 819 | fwspec.param_count = 3; |
| 820 | |
| 821 | parent_irq = irq_create_fwspec_mapping(&fwspec); |
| 822 | |
| 823 | setup_pdc_gpio(domain, parent_irq, gpio); |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * gpio_muxed_to_pdc: Mux the GPIO to a PDC IRQ |
| 828 | * |
| 829 | * @pdc_domain: the PDC's domain |
| 830 | * @d: the GPIO's IRQ data |
| 831 | * |
| 832 | * Find a free PDC port for the GPIO and map the GPIO's mux information to the |
| 833 | * PDC registers; so the GPIO can be used a wakeup source. |
| 834 | */ |
| 835 | static void gpio_muxed_to_pdc(struct irq_domain *pdc_domain, struct irq_data *d) |
| 836 | { |
| 837 | int i, j; |
| 838 | unsigned int mux; |
| 839 | struct irq_desc *desc = irq_data_to_desc(d); |
| 840 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 841 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 842 | unsigned int gpio = d->hwirq; |
| 843 | struct msm_pinctrl *pctrl; |
| 844 | unsigned int irq; |
| 845 | |
| 846 | if (!gc || !parent_data) |
| 847 | return; |
| 848 | |
| 849 | pctrl = gpiochip_get_data(gc); |
| 850 | |
| 851 | for (i = 0; i < pctrl->soc->n_gpio_mux_in; i++) { |
| 852 | if (gpio != pctrl->soc->gpio_mux_in[i].gpio) |
| 853 | continue; |
| 854 | mux = pctrl->soc->gpio_mux_in[i].mux; |
| 855 | for (j = 0; j < pctrl->soc->n_pdc_mux_out; j++) { |
| 856 | struct msm_pdc_mux_output *pdc_out = |
| 857 | &pctrl->soc->pdc_mux_out[j]; |
| 858 | |
| 859 | if (pdc_out->mux == mux) |
| 860 | break; |
| 861 | if (pdc_out->mux) |
| 862 | continue; |
| 863 | pdc_out->mux = gpio; |
| 864 | irq = irq_find_mapping(pdc_domain, pdc_out->hwirq + 32); |
| 865 | /* setup the IRQ parent for the GPIO */ |
| 866 | setup_pdc_gpio(pctrl->chip.irqdomain, irq, gpio); |
| 867 | /* program pdc select grp register */ |
| 868 | writel_relaxed((mux & 0x3F), pctrl->pdc_regs + |
| 869 | (0x14 * j)); |
| 870 | break; |
| 871 | } |
| 872 | /* We have no more PDC port available */ |
| 873 | WARN_ON(j == pctrl->soc->n_pdc_mux_out); |
| 874 | } |
| 875 | } |
| 876 | |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 877 | static bool is_gpio_dual_edge(struct irq_data *d, irq_hw_number_t *dir_conn_irq) |
| 878 | { |
| 879 | struct irq_desc *desc = irq_data_to_desc(d); |
| 880 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 881 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 882 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
| 883 | int i; |
| 884 | |
| 885 | if (!parent_data) |
| 886 | return false; |
| 887 | |
| 888 | for (i = 0; i < pctrl->soc->n_dir_conns; i++) { |
| 889 | const struct msm_dir_conn *dir_conn = &pctrl->soc->dir_conn[i]; |
| 890 | |
| 891 | if (dir_conn->gpio == d->hwirq && (dir_conn->hwirq + 32) |
| 892 | != parent_data->hwirq) { |
| 893 | *dir_conn_irq = dir_conn->hwirq + 32; |
| 894 | return true; |
| 895 | } |
| 896 | } |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 897 | |
| 898 | for (i = 0; i < pctrl->soc->n_pdc_mux_out; i++) { |
| 899 | struct msm_pdc_mux_output *dir_conn = |
| 900 | &pctrl->soc->pdc_mux_out[i]; |
| 901 | |
| 902 | if (dir_conn->mux == d->hwirq && (dir_conn->hwirq + 32) |
| 903 | != parent_data->hwirq) { |
| 904 | *dir_conn_irq = dir_conn->hwirq + 32; |
| 905 | return true; |
| 906 | } |
| 907 | } |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 908 | return false; |
| 909 | } |
| 910 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 911 | static void msm_dirconn_irq_mask(struct irq_data *d) |
| 912 | { |
| 913 | struct irq_desc *desc = irq_data_to_desc(d); |
| 914 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 915 | irq_hw_number_t dir_conn_irq = 0; |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 916 | |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 917 | if (!parent_data) |
| 918 | return; |
| 919 | |
| 920 | if (is_gpio_dual_edge(d, &dir_conn_irq)) { |
| 921 | struct irq_data *dir_conn_data = |
| 922 | irq_get_irq_data(irq_find_mapping(parent_data->domain, |
| 923 | dir_conn_irq)); |
| 924 | |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 925 | if (!dir_conn_data) |
| 926 | return; |
| 927 | if (dir_conn_data->chip->irq_mask) |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 928 | dir_conn_data->chip->irq_mask(dir_conn_data); |
| 929 | } |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 930 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 931 | if (parent_data->chip->irq_mask) |
| 932 | parent_data->chip->irq_mask(parent_data); |
| 933 | } |
| 934 | |
| 935 | static void msm_dirconn_irq_unmask(struct irq_data *d) |
| 936 | { |
| 937 | struct irq_desc *desc = irq_data_to_desc(d); |
| 938 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 939 | irq_hw_number_t dir_conn_irq = 0; |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 940 | |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 941 | if (!parent_data) |
| 942 | return; |
| 943 | |
| 944 | if (is_gpio_dual_edge(d, &dir_conn_irq)) { |
| 945 | struct irq_data *dir_conn_data = |
| 946 | irq_get_irq_data(irq_find_mapping(parent_data->domain, |
| 947 | dir_conn_irq)); |
| 948 | |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 949 | if (!dir_conn_data) |
| 950 | return; |
| 951 | if (dir_conn_data->chip->irq_unmask) |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 952 | dir_conn_data->chip->irq_unmask(dir_conn_data); |
| 953 | } |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 954 | if (parent_data->chip->irq_unmask) |
| 955 | parent_data->chip->irq_unmask(parent_data); |
| 956 | } |
| 957 | |
| 958 | static void msm_dirconn_irq_ack(struct irq_data *d) |
| 959 | { |
| 960 | struct irq_desc *desc = irq_data_to_desc(d); |
| 961 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 962 | |
Maulik Shah | 9180da2 | 2017-10-31 15:23:17 +0530 | [diff] [blame] | 963 | if (!parent_data) |
| 964 | return; |
| 965 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 966 | if (parent_data->chip->irq_ack) |
| 967 | parent_data->chip->irq_ack(parent_data); |
| 968 | } |
| 969 | |
| 970 | static void msm_dirconn_irq_eoi(struct irq_data *d) |
| 971 | { |
| 972 | struct irq_desc *desc = irq_data_to_desc(d); |
| 973 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 974 | |
Maulik Shah | 9180da2 | 2017-10-31 15:23:17 +0530 | [diff] [blame] | 975 | if (!parent_data) |
| 976 | return; |
| 977 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 978 | if (parent_data->chip->irq_eoi) |
| 979 | parent_data->chip->irq_eoi(parent_data); |
| 980 | } |
| 981 | |
| 982 | static int msm_dirconn_irq_set_affinity(struct irq_data *d, |
| 983 | const struct cpumask *maskval, bool force) |
| 984 | { |
| 985 | struct irq_desc *desc = irq_data_to_desc(d); |
| 986 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 987 | |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 988 | if (!parent_data) |
| 989 | return 0; |
| 990 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 991 | if (parent_data->chip->irq_set_affinity) |
| 992 | return parent_data->chip->irq_set_affinity(parent_data, |
| 993 | maskval, force); |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | static int msm_dirconn_irq_set_vcpu_affinity(struct irq_data *d, |
| 998 | void *vcpu_info) |
| 999 | { |
| 1000 | struct irq_desc *desc = irq_data_to_desc(d); |
| 1001 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 1002 | |
Maulik Shah | 9180da2 | 2017-10-31 15:23:17 +0530 | [diff] [blame] | 1003 | if (!parent_data) |
| 1004 | return 0; |
| 1005 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1006 | if (parent_data->chip->irq_set_vcpu_affinity) |
| 1007 | return parent_data->chip->irq_set_vcpu_affinity(parent_data, |
| 1008 | vcpu_info); |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 1012 | static void msm_dirconn_cfg_reg(struct irq_data *d, u32 offset) |
| 1013 | { |
| 1014 | u32 val = 0; |
| 1015 | const struct msm_pingroup *g; |
| 1016 | unsigned long flags; |
| 1017 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 1018 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
| 1019 | |
| 1020 | spin_lock_irqsave(&pctrl->lock, flags); |
| 1021 | g = &pctrl->soc->groups[d->hwirq]; |
| 1022 | |
| 1023 | val = readl_relaxed(pctrl->regs + g->dir_conn_reg + (offset * 4)); |
| 1024 | val = (d->hwirq) & 0xFF; |
| 1025 | |
| 1026 | writel_relaxed(val, pctrl->regs + g->dir_conn_reg + (offset * 4)); |
| 1027 | |
| 1028 | //write the dir_conn_en bit |
| 1029 | val = readl_relaxed(pctrl->regs + g->intr_cfg_reg); |
| 1030 | val |= BIT(g->dir_conn_en_bit); |
| 1031 | writel_relaxed(val, pctrl->regs + g->intr_cfg_reg); |
| 1032 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 1033 | } |
| 1034 | |
| 1035 | static void msm_dirconn_uncfg_reg(struct irq_data *d, u32 offset) |
| 1036 | { |
| 1037 | const struct msm_pingroup *g; |
| 1038 | unsigned long flags; |
| 1039 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 1040 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
| 1041 | |
| 1042 | spin_lock_irqsave(&pctrl->lock, flags); |
| 1043 | g = &pctrl->soc->groups[d->hwirq]; |
| 1044 | |
| 1045 | writel_relaxed(BIT(8), pctrl->regs + g->dir_conn_reg + (offset * 4)); |
| 1046 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 1047 | } |
| 1048 | |
| 1049 | static int select_dir_conn_mux(struct irq_data *d, irq_hw_number_t *irq) |
| 1050 | { |
| 1051 | struct msm_dir_conn *dc = NULL; |
| 1052 | struct irq_desc *desc = irq_data_to_desc(d); |
| 1053 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 1054 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 1055 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
| 1056 | int i; |
| 1057 | |
| 1058 | if (!parent_data) |
| 1059 | return -EINVAL; |
| 1060 | |
| 1061 | for (i = 0; i < pctrl->soc->n_dir_conns; i++) { |
| 1062 | struct msm_dir_conn *dir_conn = |
| 1063 | (struct msm_dir_conn *)&pctrl->soc->dir_conn[i]; |
| 1064 | |
| 1065 | /* Check if there is already mux assigned for this gpio */ |
| 1066 | if (dir_conn->gpio == d->hwirq && (dir_conn->hwirq + 32) != |
| 1067 | parent_data->hwirq) { |
| 1068 | *irq = dir_conn->hwirq + 32; |
| 1069 | return pctrl->soc->dir_conn_irq_base - dir_conn->hwirq; |
| 1070 | } |
| 1071 | |
| 1072 | if (dir_conn->gpio) |
| 1073 | continue; |
| 1074 | |
| 1075 | /* Use the first unused direct connect available */ |
| 1076 | dc = dir_conn; |
| 1077 | break; |
| 1078 | } |
| 1079 | |
| 1080 | if (dc) { |
| 1081 | *irq = dc->hwirq + 32; |
| 1082 | dc->gpio = (u32)d->hwirq; |
| 1083 | return pctrl->soc->dir_conn_irq_base - (u32)dc->hwirq; |
| 1084 | } |
| 1085 | |
| 1086 | pr_err("%s: No direct connects available for interrupt %lu\n", |
| 1087 | __func__, d->hwirq); |
| 1088 | return -EINVAL; |
| 1089 | } |
| 1090 | |
| 1091 | static void add_dirconn_tlmm(struct irq_data *d, irq_hw_number_t irq) |
| 1092 | { |
| 1093 | struct irq_desc *desc = irq_data_to_desc(d); |
| 1094 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 1095 | struct irq_data *dir_conn_data = NULL; |
| 1096 | int offset = 0; |
| 1097 | unsigned int virt = 0; |
| 1098 | |
| 1099 | offset = select_dir_conn_mux(d, &irq); |
| 1100 | if (offset < 0 || !parent_data) |
| 1101 | return; |
| 1102 | |
| 1103 | virt = irq_find_mapping(parent_data->domain, irq); |
| 1104 | msm_dirconn_cfg_reg(d, offset); |
| 1105 | irq_set_handler_data(virt, d); |
| 1106 | desc = irq_to_desc(virt); |
| 1107 | if (!desc) |
| 1108 | return; |
| 1109 | |
| 1110 | dir_conn_data = &(desc->irq_data); |
| 1111 | |
| 1112 | if (dir_conn_data) { |
| 1113 | if (dir_conn_data->chip && dir_conn_data->chip->irq_set_type) |
| 1114 | dir_conn_data->chip->irq_set_type(dir_conn_data, |
| 1115 | IRQ_TYPE_EDGE_RISING); |
| 1116 | if (dir_conn_data->chip && dir_conn_data->chip->irq_unmask) |
| 1117 | dir_conn_data->chip->irq_unmask(dir_conn_data); |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | static void remove_dirconn_tlmm(struct irq_data *d, irq_hw_number_t irq) |
| 1122 | { |
| 1123 | struct irq_desc *desc = irq_data_to_desc(d); |
| 1124 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 1125 | struct irq_data *dir_conn_data = NULL; |
| 1126 | int offset = 0; |
| 1127 | unsigned int virt = 0; |
| 1128 | |
| 1129 | virt = irq_find_mapping(parent_data->domain, irq); |
| 1130 | msm_dirconn_uncfg_reg(d, offset); |
| 1131 | irq_set_handler_data(virt, NULL); |
| 1132 | desc = irq_to_desc(virt); |
| 1133 | if (!desc) |
| 1134 | return; |
| 1135 | |
| 1136 | dir_conn_data = &(desc->irq_data); |
| 1137 | |
| 1138 | if (dir_conn_data) { |
| 1139 | if (dir_conn_data->chip && dir_conn_data->chip->irq_mask) |
| 1140 | dir_conn_data->chip->irq_mask(dir_conn_data); |
| 1141 | } |
| 1142 | } |
| 1143 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1144 | static int msm_dirconn_irq_set_type(struct irq_data *d, unsigned int type) |
| 1145 | { |
| 1146 | struct irq_desc *desc = irq_data_to_desc(d); |
| 1147 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
Archana Sathyakumar | 8ff3ba6 | 2017-10-06 11:58:46 -0600 | [diff] [blame] | 1148 | irq_hw_number_t irq = 0; |
| 1149 | |
| 1150 | if (!parent_data) |
| 1151 | return 0; |
| 1152 | |
| 1153 | if (type == IRQ_TYPE_EDGE_BOTH) { |
| 1154 | add_dirconn_tlmm(d, irq); |
| 1155 | } else { |
| 1156 | if (is_gpio_dual_edge(d, &irq)) |
| 1157 | remove_dirconn_tlmm(d, irq); |
| 1158 | } |
| 1159 | |
| 1160 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
| 1161 | irq_set_handler_locked(d, handle_level_irq); |
| 1162 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
| 1163 | irq_set_handler_locked(d, handle_edge_irq); |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1164 | |
| 1165 | if (parent_data->chip->irq_set_type) |
| 1166 | return parent_data->chip->irq_set_type(parent_data, type); |
| 1167 | |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | static struct irq_chip msm_dirconn_irq_chip = { |
| 1172 | .name = "msmgpio-dc", |
| 1173 | .irq_mask = msm_dirconn_irq_mask, |
| 1174 | .irq_unmask = msm_dirconn_irq_unmask, |
| 1175 | .irq_eoi = msm_dirconn_irq_eoi, |
| 1176 | .irq_ack = msm_dirconn_irq_ack, |
| 1177 | .irq_set_type = msm_dirconn_irq_set_type, |
| 1178 | .irq_set_affinity = msm_dirconn_irq_set_affinity, |
| 1179 | .irq_set_vcpu_affinity = msm_dirconn_irq_set_vcpu_affinity, |
| 1180 | .flags = IRQCHIP_SKIP_SET_WAKE |
| 1181 | | IRQCHIP_MASK_ON_SUSPEND |
| 1182 | | IRQCHIP_SET_TYPE_MASKED, |
| 1183 | }; |
| 1184 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 1185 | static void msm_gpio_irq_handler(struct irq_desc *desc) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1186 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 1187 | struct gpio_chip *gc = irq_desc_get_handler_data(desc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1188 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 1189 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 1190 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1191 | int irq_pin; |
| 1192 | int handled = 0; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 1193 | u32 val; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1194 | int i; |
| 1195 | |
| 1196 | chained_irq_enter(chip, desc); |
| 1197 | |
| 1198 | /* |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 1199 | * Each pin has it's own IRQ status register, so use |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1200 | * enabled_irq bitmap to limit the number of reads. |
| 1201 | */ |
| 1202 | for_each_set_bit(i, pctrl->enabled_irqs, pctrl->chip.ngpio) { |
| 1203 | g = &pctrl->soc->groups[i]; |
Kyle Yan | 6c2752f | 2017-09-27 16:29:45 -0700 | [diff] [blame] | 1204 | val = readl(pctrl->regs + g->intr_status_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1205 | if (val & BIT(g->intr_status_bit)) { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 1206 | irq_pin = irq_find_mapping(gc->irqdomain, i); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1207 | generic_handle_irq(irq_pin); |
| 1208 | handled++; |
| 1209 | } |
| 1210 | } |
| 1211 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 1212 | /* No interrupts were flagged */ |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1213 | if (handled == 0) |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 1214 | handle_bad_irq(desc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1215 | |
| 1216 | chained_irq_exit(chip, desc); |
| 1217 | } |
| 1218 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1219 | static void msm_gpio_setup_dir_connects(struct msm_pinctrl *pctrl) |
| 1220 | { |
| 1221 | struct device_node *parent_node; |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 1222 | struct irq_domain *pdc_domain; |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1223 | unsigned int i; |
| 1224 | |
| 1225 | parent_node = of_irq_find_parent(pctrl->dev->of_node); |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1226 | if (!parent_node) |
| 1227 | return; |
| 1228 | |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 1229 | pdc_domain = irq_find_host(parent_node); |
| 1230 | if (!pdc_domain) |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1231 | return; |
| 1232 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1233 | for (i = 0; i < pctrl->soc->n_dir_conns; i++) { |
| 1234 | const struct msm_dir_conn *dirconn = &pctrl->soc->dir_conn[i]; |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1235 | |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 1236 | request_dc_interrupt(pctrl->chip.irqdomain, pdc_domain, |
| 1237 | dirconn->hwirq, dirconn->gpio); |
| 1238 | } |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1239 | |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 1240 | for (i = 0; i < pctrl->soc->n_pdc_mux_out; i++) { |
| 1241 | struct msm_pdc_mux_output *pdc_out = |
| 1242 | &pctrl->soc->pdc_mux_out[i]; |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1243 | |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 1244 | request_dc_interrupt(pctrl->chip.irqdomain, pdc_domain, |
| 1245 | pdc_out->hwirq, 0); |
| 1246 | } |
| 1247 | |
| 1248 | /* |
| 1249 | * Statically choose the GPIOs for mapping to PDC. Dynamic mux mapping |
| 1250 | * is very difficult. |
| 1251 | */ |
| 1252 | for (i = 0; i < pctrl->soc->n_pdc_mux_out; i++) { |
| 1253 | unsigned int irq; |
| 1254 | struct irq_data *d; |
| 1255 | struct msm_gpio_mux_input *gpio_in = |
| 1256 | &pctrl->soc->gpio_mux_in[i]; |
| 1257 | if (!gpio_in->init) |
| 1258 | continue; |
| 1259 | |
| 1260 | irq = irq_find_mapping(pctrl->chip.irqdomain, gpio_in->gpio); |
| 1261 | d = irq_get_irq_data(irq); |
| 1262 | if (!d) |
| 1263 | continue; |
| 1264 | |
| 1265 | gpio_muxed_to_pdc(pdc_domain, d); |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1269 | static int msm_gpio_init(struct msm_pinctrl *pctrl) |
| 1270 | { |
| 1271 | struct gpio_chip *chip; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1272 | int ret; |
Stephen Boyd | dcd278b | 2014-03-06 22:44:41 -0800 | [diff] [blame] | 1273 | unsigned ngpio = pctrl->soc->ngpios; |
| 1274 | |
| 1275 | if (WARN_ON(ngpio > MAX_NR_GPIO)) |
| 1276 | return -EINVAL; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1277 | |
| 1278 | chip = &pctrl->chip; |
| 1279 | chip->base = 0; |
Stephen Boyd | dcd278b | 2014-03-06 22:44:41 -0800 | [diff] [blame] | 1280 | chip->ngpio = ngpio; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1281 | chip->label = dev_name(pctrl->dev); |
Linus Walleij | 58383c7 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 1282 | chip->parent = pctrl->dev; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1283 | chip->owner = THIS_MODULE; |
| 1284 | chip->of_node = pctrl->dev->of_node; |
| 1285 | |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 1286 | ret = gpiochip_add_data(&pctrl->chip, pctrl); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1287 | if (ret) { |
| 1288 | dev_err(pctrl->dev, "Failed register gpiochip\n"); |
| 1289 | return ret; |
| 1290 | } |
| 1291 | |
| 1292 | ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 0, 0, chip->ngpio); |
| 1293 | if (ret) { |
| 1294 | dev_err(pctrl->dev, "Failed to add pin range\n"); |
Pramod Gurav | c6e927a | 2014-08-29 13:41:48 +0530 | [diff] [blame] | 1295 | gpiochip_remove(&pctrl->chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1296 | return ret; |
| 1297 | } |
| 1298 | |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 1299 | ret = gpiochip_irqchip_add(chip, |
| 1300 | &msm_gpio_irq_chip, |
| 1301 | 0, |
Archana Sathyakumar | 558f262 | 2017-07-26 07:37:51 -0600 | [diff] [blame] | 1302 | handle_fasteoi_irq, |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 1303 | IRQ_TYPE_NONE); |
| 1304 | if (ret) { |
| 1305 | dev_err(pctrl->dev, "Failed to add irqchip to gpiochip\n"); |
Pramod Gurav | c6e927a | 2014-08-29 13:41:48 +0530 | [diff] [blame] | 1306 | gpiochip_remove(&pctrl->chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1307 | return -ENOSYS; |
| 1308 | } |
| 1309 | |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 1310 | gpiochip_set_chained_irqchip(chip, &msm_gpio_irq_chip, pctrl->irq, |
| 1311 | msm_gpio_irq_handler); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1312 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame] | 1313 | msm_gpio_setup_dir_connects(pctrl); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1314 | return 0; |
| 1315 | } |
| 1316 | |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 1317 | static int msm_ps_hold_restart(struct notifier_block *nb, unsigned long action, |
| 1318 | void *data) |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1319 | { |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 1320 | struct msm_pinctrl *pctrl = container_of(nb, struct msm_pinctrl, restart_nb); |
| 1321 | |
| 1322 | writel(0, pctrl->regs + PS_HOLD_OFFSET); |
| 1323 | mdelay(1000); |
| 1324 | return NOTIFY_DONE; |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1325 | } |
| 1326 | |
Stephen Boyd | ad64498 | 2015-07-06 18:09:30 -0700 | [diff] [blame] | 1327 | static struct msm_pinctrl *poweroff_pctrl; |
| 1328 | |
| 1329 | static void msm_ps_hold_poweroff(void) |
| 1330 | { |
| 1331 | msm_ps_hold_restart(&poweroff_pctrl->restart_nb, 0, NULL); |
| 1332 | } |
| 1333 | |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1334 | static void msm_pinctrl_setup_pm_reset(struct msm_pinctrl *pctrl) |
| 1335 | { |
Stephen Boyd | bcd53f8 | 2015-01-19 11:17:45 +0100 | [diff] [blame] | 1336 | int i; |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1337 | const struct msm_function *func = pctrl->soc->functions; |
| 1338 | |
Stephen Boyd | bcd53f8 | 2015-01-19 11:17:45 +0100 | [diff] [blame] | 1339 | for (i = 0; i < pctrl->soc->nfunctions; i++) |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1340 | if (!strcmp(func[i].name, "ps_hold")) { |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 1341 | pctrl->restart_nb.notifier_call = msm_ps_hold_restart; |
| 1342 | pctrl->restart_nb.priority = 128; |
| 1343 | if (register_restart_handler(&pctrl->restart_nb)) |
| 1344 | dev_err(pctrl->dev, |
| 1345 | "failed to setup restart handler.\n"); |
Stephen Boyd | ad64498 | 2015-07-06 18:09:30 -0700 | [diff] [blame] | 1346 | poweroff_pctrl = pctrl; |
| 1347 | pm_power_off = msm_ps_hold_poweroff; |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 1348 | break; |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1349 | } |
| 1350 | } |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1351 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1352 | int msm_pinctrl_probe(struct platform_device *pdev, |
| 1353 | const struct msm_pinctrl_soc_data *soc_data) |
| 1354 | { |
| 1355 | struct msm_pinctrl *pctrl; |
| 1356 | struct resource *res; |
| 1357 | int ret; |
| 1358 | |
Stephen Boyd | 92f54c9 | 2017-08-14 15:36:48 -0700 | [diff] [blame] | 1359 | pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1360 | if (!pctrl) { |
| 1361 | dev_err(&pdev->dev, "Can't allocate msm_pinctrl\n"); |
| 1362 | return -ENOMEM; |
| 1363 | } |
| 1364 | pctrl->dev = &pdev->dev; |
| 1365 | pctrl->soc = soc_data; |
| 1366 | pctrl->chip = msm_gpio_template; |
| 1367 | |
| 1368 | spin_lock_init(&pctrl->lock); |
| 1369 | |
| 1370 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1371 | pctrl->regs = devm_ioremap_resource(&pdev->dev, res); |
| 1372 | if (IS_ERR(pctrl->regs)) |
| 1373 | return PTR_ERR(pctrl->regs); |
| 1374 | |
Archana Sathyakumar | 892c01c | 2017-10-31 13:47:20 -0600 | [diff] [blame^] | 1375 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 1376 | pctrl->pdc_regs = devm_ioremap_resource(&pdev->dev, res); |
| 1377 | |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1378 | msm_pinctrl_setup_pm_reset(pctrl); |
| 1379 | |
Bjorn Andersson | f393e48 | 2013-12-14 23:01:52 -0800 | [diff] [blame] | 1380 | pctrl->irq = platform_get_irq(pdev, 0); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1381 | if (pctrl->irq < 0) { |
| 1382 | dev_err(&pdev->dev, "No interrupt defined for msmgpio\n"); |
| 1383 | return pctrl->irq; |
| 1384 | } |
| 1385 | |
| 1386 | msm_pinctrl_desc.name = dev_name(&pdev->dev); |
| 1387 | msm_pinctrl_desc.pins = pctrl->soc->pins; |
| 1388 | msm_pinctrl_desc.npins = pctrl->soc->npins; |
Laxman Dewangan | fe0267f | 2016-02-24 14:44:07 +0530 | [diff] [blame] | 1389 | pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &msm_pinctrl_desc, |
| 1390 | pctrl); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1391 | if (IS_ERR(pctrl->pctrl)) { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1392 | dev_err(&pdev->dev, "Couldn't register pinctrl driver\n"); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1393 | return PTR_ERR(pctrl->pctrl); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | ret = msm_gpio_init(pctrl); |
Laxman Dewangan | fe0267f | 2016-02-24 14:44:07 +0530 | [diff] [blame] | 1397 | if (ret) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1398 | return ret; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1399 | |
| 1400 | platform_set_drvdata(pdev, pctrl); |
| 1401 | |
| 1402 | dev_dbg(&pdev->dev, "Probed Qualcomm pinctrl driver\n"); |
| 1403 | |
| 1404 | return 0; |
| 1405 | } |
| 1406 | EXPORT_SYMBOL(msm_pinctrl_probe); |
| 1407 | |
| 1408 | int msm_pinctrl_remove(struct platform_device *pdev) |
| 1409 | { |
| 1410 | struct msm_pinctrl *pctrl = platform_get_drvdata(pdev); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1411 | |
Linus Walleij | 2fcea6c | 2014-09-16 15:05:41 -0700 | [diff] [blame] | 1412 | gpiochip_remove(&pctrl->chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1413 | |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 1414 | unregister_restart_handler(&pctrl->restart_nb); |
| 1415 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1416 | return 0; |
| 1417 | } |
| 1418 | EXPORT_SYMBOL(msm_pinctrl_remove); |
| 1419 | |