Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013, Sony Mobile Communications AB. |
Prasad Sodagudi | d045185 | 2016-07-01 14:12:20 +0530 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, 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> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/of.h> |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame^] | 20 | #include <linux/of_irq.h> |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/pinctrl/machine.h> |
| 23 | #include <linux/pinctrl/pinctrl.h> |
| 24 | #include <linux/pinctrl/pinmux.h> |
| 25 | #include <linux/pinctrl/pinconf.h> |
| 26 | #include <linux/pinctrl/pinconf-generic.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/gpio.h> |
| 29 | #include <linux/interrupt.h> |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 30 | #include <linux/spinlock.h> |
Prasad Sodagudi | d045185 | 2016-07-01 14:12:20 +0530 | [diff] [blame] | 31 | #include <linux/syscore_ops.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; |
| 73 | }; |
| 74 | |
Prasad Sodagudi | d045185 | 2016-07-01 14:12:20 +0530 | [diff] [blame] | 75 | static struct msm_pinctrl *msm_pinctrl_data; |
| 76 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 77 | static int msm_get_groups_count(struct pinctrl_dev *pctldev) |
| 78 | { |
| 79 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 80 | |
| 81 | return pctrl->soc->ngroups; |
| 82 | } |
| 83 | |
| 84 | static const char *msm_get_group_name(struct pinctrl_dev *pctldev, |
| 85 | unsigned group) |
| 86 | { |
| 87 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 88 | |
| 89 | return pctrl->soc->groups[group].name; |
| 90 | } |
| 91 | |
| 92 | static int msm_get_group_pins(struct pinctrl_dev *pctldev, |
| 93 | unsigned group, |
| 94 | const unsigned **pins, |
| 95 | unsigned *num_pins) |
| 96 | { |
| 97 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 98 | |
| 99 | *pins = pctrl->soc->groups[group].pins; |
| 100 | *num_pins = pctrl->soc->groups[group].npins; |
| 101 | return 0; |
| 102 | } |
| 103 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 104 | static const struct pinctrl_ops msm_pinctrl_ops = { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 105 | .get_groups_count = msm_get_groups_count, |
| 106 | .get_group_name = msm_get_group_name, |
| 107 | .get_group_pins = msm_get_group_pins, |
| 108 | .dt_node_to_map = pinconf_generic_dt_node_to_map_group, |
Irina Tirdea | d32f7fd | 2016-03-31 14:44:42 +0300 | [diff] [blame] | 109 | .dt_free_map = pinctrl_utils_free_map, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | static int msm_get_functions_count(struct pinctrl_dev *pctldev) |
| 113 | { |
| 114 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 115 | |
| 116 | return pctrl->soc->nfunctions; |
| 117 | } |
| 118 | |
| 119 | static const char *msm_get_function_name(struct pinctrl_dev *pctldev, |
| 120 | unsigned function) |
| 121 | { |
| 122 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 123 | |
| 124 | return pctrl->soc->functions[function].name; |
| 125 | } |
| 126 | |
| 127 | static int msm_get_function_groups(struct pinctrl_dev *pctldev, |
| 128 | unsigned function, |
| 129 | const char * const **groups, |
| 130 | unsigned * const num_groups) |
| 131 | { |
| 132 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 133 | |
| 134 | *groups = pctrl->soc->functions[function].groups; |
| 135 | *num_groups = pctrl->soc->functions[function].ngroups; |
| 136 | return 0; |
| 137 | } |
| 138 | |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 139 | static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev, |
| 140 | unsigned function, |
| 141 | unsigned group) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 142 | { |
| 143 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 144 | const struct msm_pingroup *g; |
| 145 | unsigned long flags; |
Stephen Boyd | 47a01ee | 2016-06-25 22:21:31 -0700 | [diff] [blame] | 146 | u32 val, mask; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 147 | int i; |
| 148 | |
| 149 | g = &pctrl->soc->groups[group]; |
Stephen Boyd | 47a01ee | 2016-06-25 22:21:31 -0700 | [diff] [blame] | 150 | 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] | 151 | |
Bjorn Andersson | 3c25381 | 2014-03-31 14:49:55 -0700 | [diff] [blame] | 152 | for (i = 0; i < g->nfuncs; i++) { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 153 | if (g->funcs[i] == function) |
| 154 | break; |
| 155 | } |
| 156 | |
Bjorn Andersson | 3c25381 | 2014-03-31 14:49:55 -0700 | [diff] [blame] | 157 | if (WARN_ON(i == g->nfuncs)) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 158 | return -EINVAL; |
| 159 | |
| 160 | spin_lock_irqsave(&pctrl->lock, flags); |
| 161 | |
| 162 | val = readl(pctrl->regs + g->ctl_reg); |
John Crispin | 6bcf3f6 | 2016-09-12 11:36:55 +0200 | [diff] [blame] | 163 | val &= ~mask; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 164 | val |= i << g->mux_bit; |
| 165 | writel(val, pctrl->regs + g->ctl_reg); |
| 166 | |
| 167 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 172 | static const struct pinmux_ops msm_pinmux_ops = { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 173 | .get_functions_count = msm_get_functions_count, |
| 174 | .get_function_name = msm_get_function_name, |
| 175 | .get_function_groups = msm_get_function_groups, |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 176 | .set_mux = msm_pinmux_set_mux, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | static int msm_config_reg(struct msm_pinctrl *pctrl, |
| 180 | const struct msm_pingroup *g, |
| 181 | unsigned param, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 182 | unsigned *mask, |
| 183 | unsigned *bit) |
| 184 | { |
| 185 | switch (param) { |
| 186 | case PIN_CONFIG_BIAS_DISABLE: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 187 | case PIN_CONFIG_BIAS_PULL_DOWN: |
Andy Gross | b831a15 | 2014-06-17 23:49:11 -0500 | [diff] [blame] | 188 | case PIN_CONFIG_BIAS_BUS_HOLD: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 189 | case PIN_CONFIG_BIAS_PULL_UP: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 190 | *bit = g->pull_bit; |
| 191 | *mask = 3; |
| 192 | break; |
| 193 | case PIN_CONFIG_DRIVE_STRENGTH: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 194 | *bit = g->drv_bit; |
| 195 | *mask = 7; |
| 196 | break; |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 197 | case PIN_CONFIG_OUTPUT: |
Stanimir Varbanov | 407f5e3 | 2015-03-04 12:41:57 +0200 | [diff] [blame] | 198 | case PIN_CONFIG_INPUT_ENABLE: |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 199 | *bit = g->oe_bit; |
| 200 | *mask = 1; |
| 201 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 202 | default: |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 203 | return -ENOTSUPP; |
| 204 | } |
| 205 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 209 | #define MSM_NO_PULL 0 |
| 210 | #define MSM_PULL_DOWN 1 |
Andy Gross | b831a15 | 2014-06-17 23:49:11 -0500 | [diff] [blame] | 211 | #define MSM_KEEPER 2 |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 212 | #define MSM_PULL_UP 3 |
| 213 | |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 214 | static unsigned msm_regval_to_drive(u32 val) |
| 215 | { |
| 216 | return (val + 1) * 2; |
| 217 | } |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 218 | |
| 219 | static int msm_config_group_get(struct pinctrl_dev *pctldev, |
| 220 | unsigned int group, |
| 221 | unsigned long *config) |
| 222 | { |
| 223 | const struct msm_pingroup *g; |
| 224 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 225 | unsigned param = pinconf_to_config_param(*config); |
| 226 | unsigned mask; |
| 227 | unsigned arg; |
| 228 | unsigned bit; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 229 | int ret; |
| 230 | u32 val; |
| 231 | |
| 232 | g = &pctrl->soc->groups[group]; |
| 233 | |
Stephen Boyd | 051a58b | 2014-03-06 22:44:46 -0800 | [diff] [blame] | 234 | ret = msm_config_reg(pctrl, g, param, &mask, &bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 235 | if (ret < 0) |
| 236 | return ret; |
| 237 | |
Stephen Boyd | 051a58b | 2014-03-06 22:44:46 -0800 | [diff] [blame] | 238 | val = readl(pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 239 | arg = (val >> bit) & mask; |
| 240 | |
| 241 | /* Convert register value to pinconf value */ |
| 242 | switch (param) { |
| 243 | case PIN_CONFIG_BIAS_DISABLE: |
| 244 | arg = arg == MSM_NO_PULL; |
| 245 | break; |
| 246 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 247 | arg = arg == MSM_PULL_DOWN; |
| 248 | break; |
Andy Gross | b831a15 | 2014-06-17 23:49:11 -0500 | [diff] [blame] | 249 | case PIN_CONFIG_BIAS_BUS_HOLD: |
| 250 | arg = arg == MSM_KEEPER; |
| 251 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 252 | case PIN_CONFIG_BIAS_PULL_UP: |
| 253 | arg = arg == MSM_PULL_UP; |
| 254 | break; |
| 255 | case PIN_CONFIG_DRIVE_STRENGTH: |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 256 | arg = msm_regval_to_drive(arg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 257 | break; |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 258 | case PIN_CONFIG_OUTPUT: |
| 259 | /* Pin is not output */ |
| 260 | if (!arg) |
| 261 | return -EINVAL; |
| 262 | |
| 263 | val = readl(pctrl->regs + g->io_reg); |
| 264 | arg = !!(val & BIT(g->in_bit)); |
| 265 | break; |
Stanimir Varbanov | 407f5e3 | 2015-03-04 12:41:57 +0200 | [diff] [blame] | 266 | case PIN_CONFIG_INPUT_ENABLE: |
| 267 | /* Pin is output */ |
| 268 | if (arg) |
| 269 | return -EINVAL; |
| 270 | arg = 1; |
| 271 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 272 | default: |
Stanimir Varbanov | 38d756a | 2015-03-04 12:41:56 +0200 | [diff] [blame] | 273 | return -ENOTSUPP; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | *config = pinconf_to_config_packed(param, arg); |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | static int msm_config_group_set(struct pinctrl_dev *pctldev, |
| 282 | unsigned group, |
| 283 | unsigned long *configs, |
| 284 | unsigned num_configs) |
| 285 | { |
| 286 | const struct msm_pingroup *g; |
| 287 | struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 288 | unsigned long flags; |
| 289 | unsigned param; |
| 290 | unsigned mask; |
| 291 | unsigned arg; |
| 292 | unsigned bit; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 293 | int ret; |
| 294 | u32 val; |
| 295 | int i; |
| 296 | |
| 297 | g = &pctrl->soc->groups[group]; |
| 298 | |
| 299 | for (i = 0; i < num_configs; i++) { |
| 300 | param = pinconf_to_config_param(configs[i]); |
| 301 | arg = pinconf_to_config_argument(configs[i]); |
| 302 | |
Stephen Boyd | 051a58b | 2014-03-06 22:44:46 -0800 | [diff] [blame] | 303 | ret = msm_config_reg(pctrl, g, param, &mask, &bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 304 | if (ret < 0) |
| 305 | return ret; |
| 306 | |
| 307 | /* Convert pinconf values to register values */ |
| 308 | switch (param) { |
| 309 | case PIN_CONFIG_BIAS_DISABLE: |
| 310 | arg = MSM_NO_PULL; |
| 311 | break; |
| 312 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 313 | arg = MSM_PULL_DOWN; |
| 314 | break; |
Andy Gross | b831a15 | 2014-06-17 23:49:11 -0500 | [diff] [blame] | 315 | case PIN_CONFIG_BIAS_BUS_HOLD: |
| 316 | arg = MSM_KEEPER; |
| 317 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 318 | case PIN_CONFIG_BIAS_PULL_UP: |
| 319 | arg = MSM_PULL_UP; |
| 320 | break; |
| 321 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 322 | /* Check for invalid values */ |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 323 | if (arg > 16 || arg < 2 || (arg % 2) != 0) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 324 | arg = -1; |
| 325 | else |
Stephen Boyd | 7cc34e2 | 2014-03-06 22:44:44 -0800 | [diff] [blame] | 326 | arg = (arg / 2) - 1; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 327 | break; |
Bjorn Andersson | ed118a5 | 2014-02-04 19:55:31 -0800 | [diff] [blame] | 328 | case PIN_CONFIG_OUTPUT: |
| 329 | /* set output value */ |
| 330 | spin_lock_irqsave(&pctrl->lock, flags); |
| 331 | val = readl(pctrl->regs + g->io_reg); |
| 332 | if (arg) |
| 333 | val |= BIT(g->out_bit); |
| 334 | else |
| 335 | val &= ~BIT(g->out_bit); |
| 336 | writel(val, pctrl->regs + g->io_reg); |
| 337 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 338 | |
| 339 | /* enable output */ |
| 340 | arg = 1; |
| 341 | break; |
Stanimir Varbanov | 407f5e3 | 2015-03-04 12:41:57 +0200 | [diff] [blame] | 342 | case PIN_CONFIG_INPUT_ENABLE: |
| 343 | /* disable output */ |
| 344 | arg = 0; |
| 345 | break; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 346 | default: |
| 347 | dev_err(pctrl->dev, "Unsupported config parameter: %x\n", |
| 348 | param); |
| 349 | return -EINVAL; |
| 350 | } |
| 351 | |
| 352 | /* Range-check user-supplied value */ |
| 353 | if (arg & ~mask) { |
| 354 | dev_err(pctrl->dev, "config %x: %x is invalid\n", param, arg); |
| 355 | return -EINVAL; |
| 356 | } |
| 357 | |
| 358 | spin_lock_irqsave(&pctrl->lock, flags); |
Stephen Boyd | 051a58b | 2014-03-06 22:44:46 -0800 | [diff] [blame] | 359 | val = readl(pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 360 | val &= ~(mask << bit); |
| 361 | val |= arg << bit; |
Stephen Boyd | 051a58b | 2014-03-06 22:44:46 -0800 | [diff] [blame] | 362 | writel(val, pctrl->regs + g->ctl_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 363 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 369 | static const struct pinconf_ops msm_pinconf_ops = { |
Stanimir Varbanov | 38d756a | 2015-03-04 12:41:56 +0200 | [diff] [blame] | 370 | .is_generic = true, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 371 | .pin_config_group_get = msm_config_group_get, |
| 372 | .pin_config_group_set = msm_config_group_set, |
| 373 | }; |
| 374 | |
| 375 | static struct pinctrl_desc msm_pinctrl_desc = { |
| 376 | .pctlops = &msm_pinctrl_ops, |
| 377 | .pmxops = &msm_pinmux_ops, |
| 378 | .confops = &msm_pinconf_ops, |
| 379 | .owner = THIS_MODULE, |
| 380 | }; |
| 381 | |
| 382 | static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
| 383 | { |
| 384 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 385 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 386 | unsigned long flags; |
| 387 | u32 val; |
| 388 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 389 | g = &pctrl->soc->groups[offset]; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 390 | |
| 391 | spin_lock_irqsave(&pctrl->lock, flags); |
| 392 | |
| 393 | val = readl(pctrl->regs + g->ctl_reg); |
| 394 | val &= ~BIT(g->oe_bit); |
| 395 | writel(val, pctrl->regs + g->ctl_reg); |
| 396 | |
| 397 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static int msm_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) |
| 403 | { |
| 404 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 405 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 406 | unsigned long flags; |
| 407 | u32 val; |
| 408 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 409 | g = &pctrl->soc->groups[offset]; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 410 | |
| 411 | spin_lock_irqsave(&pctrl->lock, flags); |
| 412 | |
Axel Lin | e476e77 | 2013-12-13 21:35:55 +0800 | [diff] [blame] | 413 | val = readl(pctrl->regs + g->io_reg); |
| 414 | if (value) |
| 415 | val |= BIT(g->out_bit); |
| 416 | else |
| 417 | val &= ~BIT(g->out_bit); |
| 418 | writel(val, pctrl->regs + g->io_reg); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 419 | |
| 420 | val = readl(pctrl->regs + g->ctl_reg); |
| 421 | val |= BIT(g->oe_bit); |
| 422 | writel(val, pctrl->regs + g->ctl_reg); |
| 423 | |
| 424 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static int msm_gpio_get(struct gpio_chip *chip, unsigned offset) |
| 430 | { |
| 431 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 432 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 433 | u32 val; |
| 434 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 435 | g = &pctrl->soc->groups[offset]; |
| 436 | |
| 437 | val = readl(pctrl->regs + g->io_reg); |
| 438 | return !!(val & BIT(g->in_bit)); |
| 439 | } |
| 440 | |
| 441 | static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 442 | { |
| 443 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 444 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 445 | unsigned long flags; |
| 446 | u32 val; |
| 447 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 448 | g = &pctrl->soc->groups[offset]; |
| 449 | |
| 450 | spin_lock_irqsave(&pctrl->lock, flags); |
| 451 | |
| 452 | val = readl(pctrl->regs + g->io_reg); |
Axel Lin | e476e77 | 2013-12-13 21:35:55 +0800 | [diff] [blame] | 453 | if (value) |
| 454 | val |= BIT(g->out_bit); |
| 455 | else |
| 456 | val &= ~BIT(g->out_bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 457 | writel(val, pctrl->regs + g->io_reg); |
| 458 | |
| 459 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 460 | } |
| 461 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 462 | #ifdef CONFIG_DEBUG_FS |
| 463 | #include <linux/seq_file.h> |
| 464 | |
| 465 | static void msm_gpio_dbg_show_one(struct seq_file *s, |
| 466 | struct pinctrl_dev *pctldev, |
| 467 | struct gpio_chip *chip, |
| 468 | unsigned offset, |
| 469 | unsigned gpio) |
| 470 | { |
| 471 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 472 | struct msm_pinctrl *pctrl = gpiochip_get_data(chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 473 | unsigned func; |
| 474 | int is_out; |
| 475 | int drive; |
| 476 | int pull; |
| 477 | u32 ctl_reg; |
| 478 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 479 | static const char * const pulls[] = { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 480 | "no pull", |
| 481 | "pull down", |
| 482 | "keeper", |
| 483 | "pull up" |
| 484 | }; |
| 485 | |
| 486 | g = &pctrl->soc->groups[offset]; |
| 487 | ctl_reg = readl(pctrl->regs + g->ctl_reg); |
| 488 | |
| 489 | is_out = !!(ctl_reg & BIT(g->oe_bit)); |
| 490 | func = (ctl_reg >> g->mux_bit) & 7; |
| 491 | drive = (ctl_reg >> g->drv_bit) & 7; |
| 492 | pull = (ctl_reg >> g->pull_bit) & 3; |
| 493 | |
| 494 | 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] | 495 | seq_printf(s, " %dmA", msm_regval_to_drive(drive)); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 496 | seq_printf(s, " %s", pulls[pull]); |
| 497 | } |
| 498 | |
| 499 | static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) |
| 500 | { |
| 501 | unsigned gpio = chip->base; |
| 502 | unsigned i; |
| 503 | |
| 504 | for (i = 0; i < chip->ngpio; i++, gpio++) { |
| 505 | msm_gpio_dbg_show_one(s, NULL, chip, i, gpio); |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 506 | seq_puts(s, "\n"); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
| 510 | #else |
| 511 | #define msm_gpio_dbg_show NULL |
| 512 | #endif |
| 513 | |
| 514 | static struct gpio_chip msm_gpio_template = { |
| 515 | .direction_input = msm_gpio_direction_input, |
| 516 | .direction_output = msm_gpio_direction_output, |
| 517 | .get = msm_gpio_get, |
| 518 | .set = msm_gpio_set, |
Jonas Gorski | 98c85d5 | 2015-10-11 17:34:19 +0200 | [diff] [blame] | 519 | .request = gpiochip_generic_request, |
| 520 | .free = gpiochip_generic_free, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 521 | .dbg_show = msm_gpio_dbg_show, |
| 522 | }; |
| 523 | |
| 524 | /* For dual-edge interrupts in software, since some hardware has no |
| 525 | * such support: |
| 526 | * |
| 527 | * At appropriate moments, this function may be called to flip the polarity |
| 528 | * settings of both-edge irq lines to try and catch the next edge. |
| 529 | * |
| 530 | * The attempt is considered successful if: |
| 531 | * - the status bit goes high, indicating that an edge was caught, or |
| 532 | * - the input value of the gpio doesn't change during the attempt. |
| 533 | * If the value changes twice during the process, that would cause the first |
| 534 | * test to fail but would force the second, as two opposite |
| 535 | * transitions would cause a detection no matter the polarity setting. |
| 536 | * |
| 537 | * The do-loop tries to sledge-hammer closed the timing hole between |
| 538 | * the initial value-read and the polarity-write - if the line value changes |
| 539 | * during that window, an interrupt is lost, the new polarity setting is |
| 540 | * incorrect, and the first success test will fail, causing a retry. |
| 541 | * |
| 542 | * Algorithm comes from Google's msmgpio driver. |
| 543 | */ |
| 544 | static void msm_gpio_update_dual_edge_pos(struct msm_pinctrl *pctrl, |
| 545 | const struct msm_pingroup *g, |
| 546 | struct irq_data *d) |
| 547 | { |
| 548 | int loop_limit = 100; |
| 549 | unsigned val, val2, intstat; |
| 550 | unsigned pol; |
| 551 | |
| 552 | do { |
| 553 | val = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit); |
| 554 | |
| 555 | pol = readl(pctrl->regs + g->intr_cfg_reg); |
| 556 | pol ^= BIT(g->intr_polarity_bit); |
| 557 | writel(pol, pctrl->regs + g->intr_cfg_reg); |
| 558 | |
| 559 | val2 = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit); |
| 560 | intstat = readl(pctrl->regs + g->intr_status_reg); |
| 561 | if (intstat || (val == val2)) |
| 562 | return; |
| 563 | } while (loop_limit-- > 0); |
| 564 | dev_err(pctrl->dev, "dual-edge irq failed to stabilize, %#08x != %#08x\n", |
| 565 | val, val2); |
| 566 | } |
| 567 | |
| 568 | static void msm_gpio_irq_mask(struct irq_data *d) |
| 569 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 570 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 571 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 572 | const struct msm_pingroup *g; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 573 | unsigned long flags; |
| 574 | u32 val; |
| 575 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 576 | g = &pctrl->soc->groups[d->hwirq]; |
| 577 | |
| 578 | spin_lock_irqsave(&pctrl->lock, flags); |
| 579 | |
| 580 | val = readl(pctrl->regs + g->intr_cfg_reg); |
| 581 | val &= ~BIT(g->intr_enable_bit); |
| 582 | writel(val, pctrl->regs + g->intr_cfg_reg); |
| 583 | |
| 584 | clear_bit(d->hwirq, pctrl->enabled_irqs); |
| 585 | |
| 586 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 587 | } |
| 588 | |
| 589 | static void msm_gpio_irq_unmask(struct irq_data *d) |
| 590 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 591 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 592 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 593 | const struct msm_pingroup *g; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 594 | unsigned long flags; |
| 595 | u32 val; |
| 596 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 597 | g = &pctrl->soc->groups[d->hwirq]; |
| 598 | |
| 599 | spin_lock_irqsave(&pctrl->lock, flags); |
| 600 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 601 | val = readl(pctrl->regs + g->intr_cfg_reg); |
| 602 | val |= BIT(g->intr_enable_bit); |
| 603 | writel(val, pctrl->regs + g->intr_cfg_reg); |
| 604 | |
| 605 | set_bit(d->hwirq, pctrl->enabled_irqs); |
| 606 | |
| 607 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 608 | } |
| 609 | |
| 610 | static void msm_gpio_irq_ack(struct irq_data *d) |
| 611 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 612 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 613 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 614 | const struct msm_pingroup *g; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 615 | unsigned long flags; |
| 616 | u32 val; |
| 617 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 618 | g = &pctrl->soc->groups[d->hwirq]; |
| 619 | |
| 620 | spin_lock_irqsave(&pctrl->lock, flags); |
| 621 | |
| 622 | val = readl(pctrl->regs + g->intr_status_reg); |
Bjorn Andersson | 48f15e9 | 2014-03-31 14:49:54 -0700 | [diff] [blame] | 623 | if (g->intr_ack_high) |
| 624 | val |= BIT(g->intr_status_bit); |
| 625 | else |
| 626 | val &= ~BIT(g->intr_status_bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 627 | writel(val, pctrl->regs + g->intr_status_reg); |
| 628 | |
| 629 | if (test_bit(d->hwirq, pctrl->dual_edge_irqs)) |
| 630 | msm_gpio_update_dual_edge_pos(pctrl, g, d); |
| 631 | |
| 632 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 633 | } |
| 634 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 635 | static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) |
| 636 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 637 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 638 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 639 | const struct msm_pingroup *g; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 640 | unsigned long flags; |
| 641 | u32 val; |
| 642 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 643 | g = &pctrl->soc->groups[d->hwirq]; |
| 644 | |
| 645 | spin_lock_irqsave(&pctrl->lock, flags); |
| 646 | |
| 647 | /* |
| 648 | * For hw without possibility of detecting both edges |
| 649 | */ |
| 650 | if (g->intr_detection_width == 1 && type == IRQ_TYPE_EDGE_BOTH) |
| 651 | set_bit(d->hwirq, pctrl->dual_edge_irqs); |
| 652 | else |
| 653 | clear_bit(d->hwirq, pctrl->dual_edge_irqs); |
| 654 | |
| 655 | /* Route interrupts to application cpu */ |
| 656 | val = readl(pctrl->regs + g->intr_target_reg); |
| 657 | val &= ~(7 << g->intr_target_bit); |
Georgi Djakov | f712c55 | 2014-09-03 19:28:16 +0300 | [diff] [blame] | 658 | val |= g->intr_target_kpss_val << g->intr_target_bit; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 659 | writel(val, pctrl->regs + g->intr_target_reg); |
| 660 | |
| 661 | /* Update configuration for gpio. |
| 662 | * RAW_STATUS_EN is left on for all gpio irqs. Due to the |
| 663 | * internal circuitry of TLMM, toggling the RAW_STATUS |
| 664 | * could cause the INTR_STATUS to be set for EDGE interrupts. |
| 665 | */ |
| 666 | val = readl(pctrl->regs + g->intr_cfg_reg); |
| 667 | val |= BIT(g->intr_raw_status_bit); |
| 668 | if (g->intr_detection_width == 2) { |
| 669 | val &= ~(3 << g->intr_detection_bit); |
| 670 | val &= ~(1 << g->intr_polarity_bit); |
| 671 | switch (type) { |
| 672 | case IRQ_TYPE_EDGE_RISING: |
| 673 | val |= 1 << g->intr_detection_bit; |
| 674 | val |= BIT(g->intr_polarity_bit); |
| 675 | break; |
| 676 | case IRQ_TYPE_EDGE_FALLING: |
| 677 | val |= 2 << g->intr_detection_bit; |
| 678 | val |= BIT(g->intr_polarity_bit); |
| 679 | break; |
| 680 | case IRQ_TYPE_EDGE_BOTH: |
| 681 | val |= 3 << g->intr_detection_bit; |
| 682 | val |= BIT(g->intr_polarity_bit); |
| 683 | break; |
| 684 | case IRQ_TYPE_LEVEL_LOW: |
| 685 | break; |
| 686 | case IRQ_TYPE_LEVEL_HIGH: |
| 687 | val |= BIT(g->intr_polarity_bit); |
| 688 | break; |
| 689 | } |
| 690 | } else if (g->intr_detection_width == 1) { |
| 691 | val &= ~(1 << g->intr_detection_bit); |
| 692 | val &= ~(1 << g->intr_polarity_bit); |
| 693 | switch (type) { |
| 694 | case IRQ_TYPE_EDGE_RISING: |
| 695 | val |= BIT(g->intr_detection_bit); |
| 696 | val |= BIT(g->intr_polarity_bit); |
| 697 | break; |
| 698 | case IRQ_TYPE_EDGE_FALLING: |
| 699 | val |= BIT(g->intr_detection_bit); |
| 700 | break; |
| 701 | case IRQ_TYPE_EDGE_BOTH: |
| 702 | val |= BIT(g->intr_detection_bit); |
Bjorn Andersson | 48f15e9 | 2014-03-31 14:49:54 -0700 | [diff] [blame] | 703 | val |= BIT(g->intr_polarity_bit); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 704 | break; |
| 705 | case IRQ_TYPE_LEVEL_LOW: |
| 706 | break; |
| 707 | case IRQ_TYPE_LEVEL_HIGH: |
| 708 | val |= BIT(g->intr_polarity_bit); |
| 709 | break; |
| 710 | } |
| 711 | } else { |
| 712 | BUG(); |
| 713 | } |
| 714 | writel(val, pctrl->regs + g->intr_cfg_reg); |
| 715 | |
| 716 | if (test_bit(d->hwirq, pctrl->dual_edge_irqs)) |
| 717 | msm_gpio_update_dual_edge_pos(pctrl, g, d); |
| 718 | |
| 719 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 720 | |
| 721 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
Thomas Gleixner | 34c0ad8 | 2015-06-23 15:52:51 +0200 | [diff] [blame] | 722 | irq_set_handler_locked(d, handle_level_irq); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 723 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
Thomas Gleixner | 34c0ad8 | 2015-06-23 15:52:51 +0200 | [diff] [blame] | 724 | irq_set_handler_locked(d, handle_edge_irq); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on) |
| 730 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 731 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 732 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 733 | unsigned long flags; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 734 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 735 | spin_lock_irqsave(&pctrl->lock, flags); |
| 736 | |
Josh Cartwright | 6aced33 | 2014-03-05 13:33:08 -0600 | [diff] [blame] | 737 | irq_set_irq_wake(pctrl->irq, on); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 738 | |
| 739 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 744 | static struct irq_chip msm_gpio_irq_chip = { |
| 745 | .name = "msmgpio", |
| 746 | .irq_mask = msm_gpio_irq_mask, |
| 747 | .irq_unmask = msm_gpio_irq_unmask, |
| 748 | .irq_ack = msm_gpio_irq_ack, |
| 749 | .irq_set_type = msm_gpio_irq_set_type, |
| 750 | .irq_set_wake = msm_gpio_irq_set_wake, |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 751 | }; |
| 752 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame^] | 753 | static void msm_dirconn_irq_mask(struct irq_data *d) |
| 754 | { |
| 755 | struct irq_desc *desc = irq_data_to_desc(d); |
| 756 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 757 | |
| 758 | if (parent_data->chip->irq_mask) |
| 759 | parent_data->chip->irq_mask(parent_data); |
| 760 | } |
| 761 | |
| 762 | static void msm_dirconn_irq_unmask(struct irq_data *d) |
| 763 | { |
| 764 | struct irq_desc *desc = irq_data_to_desc(d); |
| 765 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 766 | |
| 767 | if (parent_data->chip->irq_unmask) |
| 768 | parent_data->chip->irq_unmask(parent_data); |
| 769 | } |
| 770 | |
| 771 | static void msm_dirconn_irq_ack(struct irq_data *d) |
| 772 | { |
| 773 | struct irq_desc *desc = irq_data_to_desc(d); |
| 774 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 775 | |
| 776 | if (parent_data->chip->irq_ack) |
| 777 | parent_data->chip->irq_ack(parent_data); |
| 778 | } |
| 779 | |
| 780 | static void msm_dirconn_irq_eoi(struct irq_data *d) |
| 781 | { |
| 782 | struct irq_desc *desc = irq_data_to_desc(d); |
| 783 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 784 | |
| 785 | if (parent_data->chip->irq_eoi) |
| 786 | parent_data->chip->irq_eoi(parent_data); |
| 787 | } |
| 788 | |
| 789 | static int msm_dirconn_irq_set_affinity(struct irq_data *d, |
| 790 | const struct cpumask *maskval, bool force) |
| 791 | { |
| 792 | struct irq_desc *desc = irq_data_to_desc(d); |
| 793 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 794 | |
| 795 | if (parent_data->chip->irq_set_affinity) |
| 796 | return parent_data->chip->irq_set_affinity(parent_data, |
| 797 | maskval, force); |
| 798 | return 0; |
| 799 | } |
| 800 | |
| 801 | static int msm_dirconn_irq_set_vcpu_affinity(struct irq_data *d, |
| 802 | void *vcpu_info) |
| 803 | { |
| 804 | struct irq_desc *desc = irq_data_to_desc(d); |
| 805 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 806 | |
| 807 | if (parent_data->chip->irq_set_vcpu_affinity) |
| 808 | return parent_data->chip->irq_set_vcpu_affinity(parent_data, |
| 809 | vcpu_info); |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | static int msm_dirconn_irq_set_type(struct irq_data *d, unsigned int type) |
| 814 | { |
| 815 | struct irq_desc *desc = irq_data_to_desc(d); |
| 816 | struct irq_data *parent_data = irq_get_irq_data(desc->parent_irq); |
| 817 | |
| 818 | if (parent_data->chip->irq_set_type) |
| 819 | return parent_data->chip->irq_set_type(parent_data, type); |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | static struct irq_chip msm_dirconn_irq_chip = { |
| 825 | .name = "msmgpio-dc", |
| 826 | .irq_mask = msm_dirconn_irq_mask, |
| 827 | .irq_unmask = msm_dirconn_irq_unmask, |
| 828 | .irq_eoi = msm_dirconn_irq_eoi, |
| 829 | .irq_ack = msm_dirconn_irq_ack, |
| 830 | .irq_set_type = msm_dirconn_irq_set_type, |
| 831 | .irq_set_affinity = msm_dirconn_irq_set_affinity, |
| 832 | .irq_set_vcpu_affinity = msm_dirconn_irq_set_vcpu_affinity, |
| 833 | .flags = IRQCHIP_SKIP_SET_WAKE |
| 834 | | IRQCHIP_MASK_ON_SUSPEND |
| 835 | | IRQCHIP_SET_TYPE_MASKED, |
| 836 | }; |
| 837 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 838 | static void msm_gpio_irq_handler(struct irq_desc *desc) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 839 | { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 840 | struct gpio_chip *gc = irq_desc_get_handler_data(desc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 841 | const struct msm_pingroup *g; |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 842 | struct msm_pinctrl *pctrl = gpiochip_get_data(gc); |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 843 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 844 | int irq_pin; |
| 845 | int handled = 0; |
| 846 | u32 val; |
| 847 | int i; |
| 848 | |
| 849 | chained_irq_enter(chip, desc); |
| 850 | |
| 851 | /* |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 852 | * Each pin has it's own IRQ status register, so use |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 853 | * enabled_irq bitmap to limit the number of reads. |
| 854 | */ |
| 855 | for_each_set_bit(i, pctrl->enabled_irqs, pctrl->chip.ngpio) { |
| 856 | g = &pctrl->soc->groups[i]; |
| 857 | val = readl(pctrl->regs + g->intr_status_reg); |
| 858 | if (val & BIT(g->intr_status_bit)) { |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 859 | irq_pin = irq_find_mapping(gc->irqdomain, i); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 860 | generic_handle_irq(irq_pin); |
| 861 | handled++; |
| 862 | } |
| 863 | } |
| 864 | |
Bjorn Andersson | 1f2b239 | 2013-12-14 23:01:51 -0800 | [diff] [blame] | 865 | /* No interrupts were flagged */ |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 866 | if (handled == 0) |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 867 | handle_bad_irq(desc); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 868 | |
| 869 | chained_irq_exit(chip, desc); |
| 870 | } |
| 871 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame^] | 872 | static void msm_gpio_dirconn_handler(struct irq_desc *desc) |
| 873 | { |
| 874 | struct irq_data *irqd = irq_desc_get_handler_data(desc); |
| 875 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 876 | |
| 877 | chained_irq_enter(chip, desc); |
| 878 | generic_handle_irq(irqd->irq); |
| 879 | chained_irq_exit(chip, desc); |
| 880 | } |
| 881 | |
| 882 | static void msm_gpio_setup_dir_connects(struct msm_pinctrl *pctrl) |
| 883 | { |
| 884 | struct device_node *parent_node; |
| 885 | struct irq_domain *parent_domain; |
| 886 | struct irq_fwspec fwspec; |
| 887 | unsigned int i; |
| 888 | |
| 889 | parent_node = of_irq_find_parent(pctrl->dev->of_node); |
| 890 | |
| 891 | if (!parent_node) |
| 892 | return; |
| 893 | |
| 894 | parent_domain = irq_find_host(parent_node); |
| 895 | if (!parent_domain) |
| 896 | return; |
| 897 | |
| 898 | fwspec.fwnode = parent_domain->fwnode; |
| 899 | for (i = 0; i < pctrl->soc->n_dir_conns; i++) { |
| 900 | const struct msm_dir_conn *dirconn = &pctrl->soc->dir_conn[i]; |
| 901 | unsigned int parent_irq; |
| 902 | int irq; |
| 903 | |
| 904 | fwspec.param[0] = 0; /* SPI */ |
| 905 | fwspec.param[1] = dirconn->hwirq; |
| 906 | fwspec.param[2] = IRQ_TYPE_NONE; |
| 907 | fwspec.param_count = 3; |
| 908 | parent_irq = irq_create_fwspec_mapping(&fwspec); |
| 909 | |
| 910 | irq = irq_find_mapping(pctrl->chip.irqdomain, dirconn->gpio); |
| 911 | |
| 912 | irq_set_parent(irq, parent_irq); |
| 913 | irq_set_chip(irq, &msm_dirconn_irq_chip); |
| 914 | irq_set_chip_data(irq, irq_get_irq_data(parent_irq)); |
| 915 | __irq_set_handler(parent_irq, msm_gpio_dirconn_handler, |
| 916 | false, NULL); |
| 917 | irq_set_handler_data(parent_irq, irq_get_irq_data(irq)); |
| 918 | } |
| 919 | } |
| 920 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 921 | static int msm_gpio_init(struct msm_pinctrl *pctrl) |
| 922 | { |
| 923 | struct gpio_chip *chip; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 924 | int ret; |
Stephen Boyd | dcd278b | 2014-03-06 22:44:41 -0800 | [diff] [blame] | 925 | unsigned ngpio = pctrl->soc->ngpios; |
| 926 | |
| 927 | if (WARN_ON(ngpio > MAX_NR_GPIO)) |
| 928 | return -EINVAL; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 929 | |
| 930 | chip = &pctrl->chip; |
| 931 | chip->base = 0; |
Stephen Boyd | dcd278b | 2014-03-06 22:44:41 -0800 | [diff] [blame] | 932 | chip->ngpio = ngpio; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 933 | chip->label = dev_name(pctrl->dev); |
Linus Walleij | 58383c7 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 934 | chip->parent = pctrl->dev; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 935 | chip->owner = THIS_MODULE; |
| 936 | chip->of_node = pctrl->dev->of_node; |
| 937 | |
Linus Walleij | fded3f4 | 2015-12-08 09:49:18 +0100 | [diff] [blame] | 938 | ret = gpiochip_add_data(&pctrl->chip, pctrl); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 939 | if (ret) { |
| 940 | dev_err(pctrl->dev, "Failed register gpiochip\n"); |
| 941 | return ret; |
| 942 | } |
| 943 | |
| 944 | ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 0, 0, chip->ngpio); |
| 945 | if (ret) { |
| 946 | dev_err(pctrl->dev, "Failed to add pin range\n"); |
Pramod Gurav | c6e927a | 2014-08-29 13:41:48 +0530 | [diff] [blame] | 947 | gpiochip_remove(&pctrl->chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 948 | return ret; |
| 949 | } |
| 950 | |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 951 | ret = gpiochip_irqchip_add(chip, |
| 952 | &msm_gpio_irq_chip, |
| 953 | 0, |
| 954 | handle_edge_irq, |
| 955 | IRQ_TYPE_NONE); |
| 956 | if (ret) { |
| 957 | dev_err(pctrl->dev, "Failed to add irqchip to gpiochip\n"); |
Pramod Gurav | c6e927a | 2014-08-29 13:41:48 +0530 | [diff] [blame] | 958 | gpiochip_remove(&pctrl->chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 959 | return -ENOSYS; |
| 960 | } |
| 961 | |
Linus Walleij | cdcb0ab | 2014-04-29 11:00:40 -0700 | [diff] [blame] | 962 | gpiochip_set_chained_irqchip(chip, &msm_gpio_irq_chip, pctrl->irq, |
| 963 | msm_gpio_irq_handler); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 964 | |
Mahesh Sivasubramanian | fcc313e | 2017-04-10 09:05:59 -0600 | [diff] [blame^] | 965 | msm_gpio_setup_dir_connects(pctrl); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 966 | return 0; |
| 967 | } |
| 968 | |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 969 | static int msm_ps_hold_restart(struct notifier_block *nb, unsigned long action, |
| 970 | void *data) |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 971 | { |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 972 | struct msm_pinctrl *pctrl = container_of(nb, struct msm_pinctrl, restart_nb); |
| 973 | |
| 974 | writel(0, pctrl->regs + PS_HOLD_OFFSET); |
| 975 | mdelay(1000); |
| 976 | return NOTIFY_DONE; |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 977 | } |
| 978 | |
Stephen Boyd | ad64498 | 2015-07-06 18:09:30 -0700 | [diff] [blame] | 979 | static struct msm_pinctrl *poweroff_pctrl; |
| 980 | |
| 981 | static void msm_ps_hold_poweroff(void) |
| 982 | { |
| 983 | msm_ps_hold_restart(&poweroff_pctrl->restart_nb, 0, NULL); |
| 984 | } |
| 985 | |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 986 | static void msm_pinctrl_setup_pm_reset(struct msm_pinctrl *pctrl) |
| 987 | { |
Stephen Boyd | bcd53f8 | 2015-01-19 11:17:45 +0100 | [diff] [blame] | 988 | int i; |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 989 | const struct msm_function *func = pctrl->soc->functions; |
| 990 | |
Stephen Boyd | bcd53f8 | 2015-01-19 11:17:45 +0100 | [diff] [blame] | 991 | for (i = 0; i < pctrl->soc->nfunctions; i++) |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 992 | if (!strcmp(func[i].name, "ps_hold")) { |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 993 | pctrl->restart_nb.notifier_call = msm_ps_hold_restart; |
| 994 | pctrl->restart_nb.priority = 128; |
| 995 | if (register_restart_handler(&pctrl->restart_nb)) |
| 996 | dev_err(pctrl->dev, |
| 997 | "failed to setup restart handler.\n"); |
Stephen Boyd | ad64498 | 2015-07-06 18:09:30 -0700 | [diff] [blame] | 998 | poweroff_pctrl = pctrl; |
| 999 | pm_power_off = msm_ps_hold_poweroff; |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 1000 | break; |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1001 | } |
| 1002 | } |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1003 | |
Prasad Sodagudi | d045185 | 2016-07-01 14:12:20 +0530 | [diff] [blame] | 1004 | #ifdef CONFIG_PM |
| 1005 | static int msm_pinctrl_suspend(void) |
| 1006 | { |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | static void msm_pinctrl_resume(void) |
| 1011 | { |
| 1012 | int i, irq; |
| 1013 | u32 val; |
| 1014 | unsigned long flags; |
| 1015 | struct irq_desc *desc; |
| 1016 | const struct msm_pingroup *g; |
| 1017 | const char *name = "null"; |
| 1018 | struct msm_pinctrl *pctrl = msm_pinctrl_data; |
| 1019 | |
| 1020 | if (!msm_show_resume_irq_mask) |
| 1021 | return; |
| 1022 | |
| 1023 | spin_lock_irqsave(&pctrl->lock, flags); |
| 1024 | for_each_set_bit(i, pctrl->enabled_irqs, pctrl->chip.ngpio) { |
| 1025 | g = &pctrl->soc->groups[i]; |
| 1026 | val = readl_relaxed(pctrl->regs + g->intr_status_reg); |
| 1027 | if (val & BIT(g->intr_status_bit)) { |
| 1028 | irq = irq_find_mapping(pctrl->chip.irqdomain, i); |
| 1029 | desc = irq_to_desc(irq); |
| 1030 | if (desc == NULL) |
| 1031 | name = "stray irq"; |
| 1032 | else if (desc->action && desc->action->name) |
| 1033 | name = desc->action->name; |
| 1034 | |
| 1035 | pr_warn("%s: %d triggered %s\n", __func__, irq, name); |
| 1036 | } |
| 1037 | } |
| 1038 | spin_unlock_irqrestore(&pctrl->lock, flags); |
| 1039 | } |
| 1040 | #else |
| 1041 | #define msm_pinctrl_suspend NULL |
| 1042 | #define msm_pinctrl_resume NULL |
| 1043 | #endif |
| 1044 | |
| 1045 | static struct syscore_ops msm_pinctrl_pm_ops = { |
| 1046 | .suspend = msm_pinctrl_suspend, |
| 1047 | .resume = msm_pinctrl_resume, |
| 1048 | }; |
| 1049 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1050 | int msm_pinctrl_probe(struct platform_device *pdev, |
| 1051 | const struct msm_pinctrl_soc_data *soc_data) |
| 1052 | { |
| 1053 | struct msm_pinctrl *pctrl; |
| 1054 | struct resource *res; |
| 1055 | int ret; |
| 1056 | |
Prasad Sodagudi | d045185 | 2016-07-01 14:12:20 +0530 | [diff] [blame] | 1057 | msm_pinctrl_data = pctrl = devm_kzalloc(&pdev->dev, |
| 1058 | sizeof(*pctrl), GFP_KERNEL); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1059 | if (!pctrl) { |
| 1060 | dev_err(&pdev->dev, "Can't allocate msm_pinctrl\n"); |
| 1061 | return -ENOMEM; |
| 1062 | } |
| 1063 | pctrl->dev = &pdev->dev; |
| 1064 | pctrl->soc = soc_data; |
| 1065 | pctrl->chip = msm_gpio_template; |
| 1066 | |
| 1067 | spin_lock_init(&pctrl->lock); |
| 1068 | |
| 1069 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1070 | pctrl->regs = devm_ioremap_resource(&pdev->dev, res); |
| 1071 | if (IS_ERR(pctrl->regs)) |
| 1072 | return PTR_ERR(pctrl->regs); |
| 1073 | |
Pramod Gurav | 3274558 | 2014-08-29 20:00:59 +0530 | [diff] [blame] | 1074 | msm_pinctrl_setup_pm_reset(pctrl); |
| 1075 | |
Bjorn Andersson | f393e48 | 2013-12-14 23:01:52 -0800 | [diff] [blame] | 1076 | pctrl->irq = platform_get_irq(pdev, 0); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1077 | if (pctrl->irq < 0) { |
| 1078 | dev_err(&pdev->dev, "No interrupt defined for msmgpio\n"); |
| 1079 | return pctrl->irq; |
| 1080 | } |
| 1081 | |
| 1082 | msm_pinctrl_desc.name = dev_name(&pdev->dev); |
| 1083 | msm_pinctrl_desc.pins = pctrl->soc->pins; |
| 1084 | msm_pinctrl_desc.npins = pctrl->soc->npins; |
Laxman Dewangan | fe0267f | 2016-02-24 14:44:07 +0530 | [diff] [blame] | 1085 | pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &msm_pinctrl_desc, |
| 1086 | pctrl); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1087 | if (IS_ERR(pctrl->pctrl)) { |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1088 | dev_err(&pdev->dev, "Couldn't register pinctrl driver\n"); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1089 | return PTR_ERR(pctrl->pctrl); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | ret = msm_gpio_init(pctrl); |
Laxman Dewangan | fe0267f | 2016-02-24 14:44:07 +0530 | [diff] [blame] | 1093 | if (ret) |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1094 | return ret; |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1095 | |
| 1096 | platform_set_drvdata(pdev, pctrl); |
| 1097 | |
Prasad Sodagudi | d045185 | 2016-07-01 14:12:20 +0530 | [diff] [blame] | 1098 | register_syscore_ops(&msm_pinctrl_pm_ops); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1099 | dev_dbg(&pdev->dev, "Probed Qualcomm pinctrl driver\n"); |
| 1100 | |
| 1101 | return 0; |
| 1102 | } |
| 1103 | EXPORT_SYMBOL(msm_pinctrl_probe); |
| 1104 | |
| 1105 | int msm_pinctrl_remove(struct platform_device *pdev) |
| 1106 | { |
| 1107 | struct msm_pinctrl *pctrl = platform_get_drvdata(pdev); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1108 | |
Linus Walleij | 2fcea6c | 2014-09-16 15:05:41 -0700 | [diff] [blame] | 1109 | gpiochip_remove(&pctrl->chip); |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1110 | |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 1111 | unregister_restart_handler(&pctrl->restart_nb); |
Prasad Sodagudi | d045185 | 2016-07-01 14:12:20 +0530 | [diff] [blame] | 1112 | unregister_syscore_ops(&msm_pinctrl_pm_ops); |
Josh Cartwright | cf1fc18 | 2014-09-23 15:59:53 -0500 | [diff] [blame] | 1113 | |
Bjorn Andersson | f365be0 | 2013-12-05 18:10:03 -0800 | [diff] [blame] | 1114 | return 0; |
| 1115 | } |
| 1116 | EXPORT_SYMBOL(msm_pinctrl_remove); |
| 1117 | |