blob: f8e9e1c2b2f6f45078aa2fe9a3356b450d60fd58 [file] [log] [blame]
Bjorn Anderssonf365be02013-12-05 18:10:03 -08001/*
2 * Copyright (c) 2013, Sony Mobile Communications AB.
3 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
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 Gurav32745582014-08-29 20:00:59 +053015#include <linux/delay.h>
Bjorn Anderssonf365be02013-12-05 18:10:03 -080016#include <linux/err.h>
Bjorn Anderssonf365be02013-12-05 18:10:03 -080017#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/of.h>
20#include <linux/platform_device.h>
21#include <linux/pinctrl/machine.h>
22#include <linux/pinctrl/pinctrl.h>
23#include <linux/pinctrl/pinmux.h>
24#include <linux/pinctrl/pinconf.h>
25#include <linux/pinctrl/pinconf-generic.h>
26#include <linux/slab.h>
27#include <linux/gpio.h>
28#include <linux/interrupt.h>
Bjorn Anderssonf365be02013-12-05 18:10:03 -080029#include <linux/spinlock.h>
Josh Cartwrightcf1fc182014-09-23 15:59:53 -050030#include <linux/reboot.h>
Stephen Boydad644982015-07-06 18:09:30 -070031#include <linux/pm.h>
Stephen Boyd47a01ee2016-06-25 22:21:31 -070032#include <linux/log2.h>
Pramod Gurav32745582014-08-29 20:00:59 +053033
Linus Walleij69b78b82014-07-09 13:55:12 +020034#include "../core.h"
35#include "../pinconf.h"
Bjorn Anderssonf365be02013-12-05 18:10:03 -080036#include "pinctrl-msm.h"
Linus Walleij69b78b82014-07-09 13:55:12 +020037#include "../pinctrl-utils.h"
Bjorn Anderssonf365be02013-12-05 18:10:03 -080038
Bjorn Andersson408e3c62013-12-14 23:01:53 -080039#define MAX_NR_GPIO 300
Pramod Gurav32745582014-08-29 20:00:59 +053040#define PS_HOLD_OFFSET 0x820
Bjorn Andersson408e3c62013-12-14 23:01:53 -080041
Bjorn Anderssonf365be02013-12-05 18:10:03 -080042/**
43 * struct msm_pinctrl - state for a pinctrl-msm device
44 * @dev: device handle.
45 * @pctrl: pinctrl handle.
Bjorn Anderssonf365be02013-12-05 18:10:03 -080046 * @chip: gpiochip handle.
Josh Cartwrightcf1fc182014-09-23 15:59:53 -050047 * @restart_nb: restart notifier block.
Bjorn Anderssonf365be02013-12-05 18:10:03 -080048 * @irq: parent irq for the TLMM irq_chip.
49 * @lock: Spinlock to protect register resources as well
50 * as msm_pinctrl data structures.
51 * @enabled_irqs: Bitmap of currently enabled irqs.
52 * @dual_edge_irqs: Bitmap of irqs that need sw emulated dual edge
53 * detection.
Bjorn Anderssonf365be02013-12-05 18:10:03 -080054 * @soc; Reference to soc_data of platform specific data.
55 * @regs: Base address for the TLMM register map.
56 */
57struct msm_pinctrl {
58 struct device *dev;
59 struct pinctrl_dev *pctrl;
Bjorn Anderssonf365be02013-12-05 18:10:03 -080060 struct gpio_chip chip;
Josh Cartwrightcf1fc182014-09-23 15:59:53 -050061 struct notifier_block restart_nb;
Bjorn Anderssonf393e482013-12-14 23:01:52 -080062 int irq;
Bjorn Anderssonf365be02013-12-05 18:10:03 -080063
Julia Cartwright47b03ca2017-01-20 10:13:47 -060064 raw_spinlock_t lock;
Bjorn Anderssonf365be02013-12-05 18:10:03 -080065
Bjorn Andersson408e3c62013-12-14 23:01:53 -080066 DECLARE_BITMAP(dual_edge_irqs, MAX_NR_GPIO);
67 DECLARE_BITMAP(enabled_irqs, MAX_NR_GPIO);
Bjorn Anderssonf365be02013-12-05 18:10:03 -080068
69 const struct msm_pinctrl_soc_data *soc;
70 void __iomem *regs;
71};
72
73static int msm_get_groups_count(struct pinctrl_dev *pctldev)
74{
75 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
76
77 return pctrl->soc->ngroups;
78}
79
80static const char *msm_get_group_name(struct pinctrl_dev *pctldev,
81 unsigned group)
82{
83 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
84
85 return pctrl->soc->groups[group].name;
86}
87
88static int msm_get_group_pins(struct pinctrl_dev *pctldev,
89 unsigned group,
90 const unsigned **pins,
91 unsigned *num_pins)
92{
93 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
94
95 *pins = pctrl->soc->groups[group].pins;
96 *num_pins = pctrl->soc->groups[group].npins;
97 return 0;
98}
99
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800100static const struct pinctrl_ops msm_pinctrl_ops = {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800101 .get_groups_count = msm_get_groups_count,
102 .get_group_name = msm_get_group_name,
103 .get_group_pins = msm_get_group_pins,
104 .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
Irina Tirdead32f7fd2016-03-31 14:44:42 +0300105 .dt_free_map = pinctrl_utils_free_map,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800106};
107
108static int msm_get_functions_count(struct pinctrl_dev *pctldev)
109{
110 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
111
112 return pctrl->soc->nfunctions;
113}
114
115static const char *msm_get_function_name(struct pinctrl_dev *pctldev,
116 unsigned function)
117{
118 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
119
120 return pctrl->soc->functions[function].name;
121}
122
123static int msm_get_function_groups(struct pinctrl_dev *pctldev,
124 unsigned function,
125 const char * const **groups,
126 unsigned * const num_groups)
127{
128 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
129
130 *groups = pctrl->soc->functions[function].groups;
131 *num_groups = pctrl->soc->functions[function].ngroups;
132 return 0;
133}
134
Linus Walleij03e9f0c2014-09-03 13:02:56 +0200135static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev,
136 unsigned function,
137 unsigned group)
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800138{
139 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
140 const struct msm_pingroup *g;
141 unsigned long flags;
Stephen Boyd47a01ee2016-06-25 22:21:31 -0700142 u32 val, mask;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800143 int i;
144
145 g = &pctrl->soc->groups[group];
Stephen Boyd47a01ee2016-06-25 22:21:31 -0700146 mask = GENMASK(g->mux_bit + order_base_2(g->nfuncs) - 1, g->mux_bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800147
Bjorn Andersson3c253812014-03-31 14:49:55 -0700148 for (i = 0; i < g->nfuncs; i++) {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800149 if (g->funcs[i] == function)
150 break;
151 }
152
Bjorn Andersson3c253812014-03-31 14:49:55 -0700153 if (WARN_ON(i == g->nfuncs))
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800154 return -EINVAL;
155
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600156 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800157
158 val = readl(pctrl->regs + g->ctl_reg);
John Crispin6bcf3f62016-09-12 11:36:55 +0200159 val &= ~mask;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800160 val |= i << g->mux_bit;
161 writel(val, pctrl->regs + g->ctl_reg);
162
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600163 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800164
165 return 0;
166}
167
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800168static const struct pinmux_ops msm_pinmux_ops = {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800169 .get_functions_count = msm_get_functions_count,
170 .get_function_name = msm_get_function_name,
171 .get_function_groups = msm_get_function_groups,
Linus Walleij03e9f0c2014-09-03 13:02:56 +0200172 .set_mux = msm_pinmux_set_mux,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800173};
174
175static int msm_config_reg(struct msm_pinctrl *pctrl,
176 const struct msm_pingroup *g,
177 unsigned param,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800178 unsigned *mask,
179 unsigned *bit)
180{
181 switch (param) {
182 case PIN_CONFIG_BIAS_DISABLE:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800183 case PIN_CONFIG_BIAS_PULL_DOWN:
Andy Grossb831a152014-06-17 23:49:11 -0500184 case PIN_CONFIG_BIAS_BUS_HOLD:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800185 case PIN_CONFIG_BIAS_PULL_UP:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800186 *bit = g->pull_bit;
187 *mask = 3;
188 break;
189 case PIN_CONFIG_DRIVE_STRENGTH:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800190 *bit = g->drv_bit;
191 *mask = 7;
192 break;
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800193 case PIN_CONFIG_OUTPUT:
Stanimir Varbanov407f5e32015-03-04 12:41:57 +0200194 case PIN_CONFIG_INPUT_ENABLE:
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800195 *bit = g->oe_bit;
196 *mask = 1;
197 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800198 default:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800199 return -ENOTSUPP;
200 }
201
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800202 return 0;
203}
204
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800205#define MSM_NO_PULL 0
206#define MSM_PULL_DOWN 1
Andy Grossb831a152014-06-17 23:49:11 -0500207#define MSM_KEEPER 2
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800208#define MSM_PULL_UP 3
209
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800210static unsigned msm_regval_to_drive(u32 val)
211{
212 return (val + 1) * 2;
213}
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800214
215static int msm_config_group_get(struct pinctrl_dev *pctldev,
216 unsigned int group,
217 unsigned long *config)
218{
219 const struct msm_pingroup *g;
220 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
221 unsigned param = pinconf_to_config_param(*config);
222 unsigned mask;
223 unsigned arg;
224 unsigned bit;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800225 int ret;
226 u32 val;
227
228 g = &pctrl->soc->groups[group];
229
Stephen Boyd051a58b2014-03-06 22:44:46 -0800230 ret = msm_config_reg(pctrl, g, param, &mask, &bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800231 if (ret < 0)
232 return ret;
233
Stephen Boyd051a58b2014-03-06 22:44:46 -0800234 val = readl(pctrl->regs + g->ctl_reg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800235 arg = (val >> bit) & mask;
236
237 /* Convert register value to pinconf value */
238 switch (param) {
239 case PIN_CONFIG_BIAS_DISABLE:
240 arg = arg == MSM_NO_PULL;
241 break;
242 case PIN_CONFIG_BIAS_PULL_DOWN:
243 arg = arg == MSM_PULL_DOWN;
244 break;
Andy Grossb831a152014-06-17 23:49:11 -0500245 case PIN_CONFIG_BIAS_BUS_HOLD:
246 arg = arg == MSM_KEEPER;
247 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800248 case PIN_CONFIG_BIAS_PULL_UP:
249 arg = arg == MSM_PULL_UP;
250 break;
251 case PIN_CONFIG_DRIVE_STRENGTH:
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800252 arg = msm_regval_to_drive(arg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800253 break;
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800254 case PIN_CONFIG_OUTPUT:
255 /* Pin is not output */
256 if (!arg)
257 return -EINVAL;
258
259 val = readl(pctrl->regs + g->io_reg);
260 arg = !!(val & BIT(g->in_bit));
261 break;
Stanimir Varbanov407f5e32015-03-04 12:41:57 +0200262 case PIN_CONFIG_INPUT_ENABLE:
263 /* Pin is output */
264 if (arg)
265 return -EINVAL;
266 arg = 1;
267 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800268 default:
Stanimir Varbanov38d756a2015-03-04 12:41:56 +0200269 return -ENOTSUPP;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800270 }
271
272 *config = pinconf_to_config_packed(param, arg);
273
274 return 0;
275}
276
277static int msm_config_group_set(struct pinctrl_dev *pctldev,
278 unsigned group,
279 unsigned long *configs,
280 unsigned num_configs)
281{
282 const struct msm_pingroup *g;
283 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
284 unsigned long flags;
285 unsigned param;
286 unsigned mask;
287 unsigned arg;
288 unsigned bit;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800289 int ret;
290 u32 val;
291 int i;
292
293 g = &pctrl->soc->groups[group];
294
295 for (i = 0; i < num_configs; i++) {
296 param = pinconf_to_config_param(configs[i]);
297 arg = pinconf_to_config_argument(configs[i]);
298
Stephen Boyd051a58b2014-03-06 22:44:46 -0800299 ret = msm_config_reg(pctrl, g, param, &mask, &bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800300 if (ret < 0)
301 return ret;
302
303 /* Convert pinconf values to register values */
304 switch (param) {
305 case PIN_CONFIG_BIAS_DISABLE:
306 arg = MSM_NO_PULL;
307 break;
308 case PIN_CONFIG_BIAS_PULL_DOWN:
309 arg = MSM_PULL_DOWN;
310 break;
Andy Grossb831a152014-06-17 23:49:11 -0500311 case PIN_CONFIG_BIAS_BUS_HOLD:
312 arg = MSM_KEEPER;
313 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800314 case PIN_CONFIG_BIAS_PULL_UP:
315 arg = MSM_PULL_UP;
316 break;
317 case PIN_CONFIG_DRIVE_STRENGTH:
318 /* Check for invalid values */
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800319 if (arg > 16 || arg < 2 || (arg % 2) != 0)
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800320 arg = -1;
321 else
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800322 arg = (arg / 2) - 1;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800323 break;
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800324 case PIN_CONFIG_OUTPUT:
325 /* set output value */
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600326 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800327 val = readl(pctrl->regs + g->io_reg);
328 if (arg)
329 val |= BIT(g->out_bit);
330 else
331 val &= ~BIT(g->out_bit);
332 writel(val, pctrl->regs + g->io_reg);
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600333 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800334
335 /* enable output */
336 arg = 1;
337 break;
Stanimir Varbanov407f5e32015-03-04 12:41:57 +0200338 case PIN_CONFIG_INPUT_ENABLE:
339 /* disable output */
340 arg = 0;
341 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800342 default:
343 dev_err(pctrl->dev, "Unsupported config parameter: %x\n",
344 param);
345 return -EINVAL;
346 }
347
348 /* Range-check user-supplied value */
349 if (arg & ~mask) {
350 dev_err(pctrl->dev, "config %x: %x is invalid\n", param, arg);
351 return -EINVAL;
352 }
353
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600354 raw_spin_lock_irqsave(&pctrl->lock, flags);
Stephen Boyd051a58b2014-03-06 22:44:46 -0800355 val = readl(pctrl->regs + g->ctl_reg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800356 val &= ~(mask << bit);
357 val |= arg << bit;
Stephen Boyd051a58b2014-03-06 22:44:46 -0800358 writel(val, pctrl->regs + g->ctl_reg);
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600359 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800360 }
361
362 return 0;
363}
364
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800365static const struct pinconf_ops msm_pinconf_ops = {
Stanimir Varbanov38d756a2015-03-04 12:41:56 +0200366 .is_generic = true,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800367 .pin_config_group_get = msm_config_group_get,
368 .pin_config_group_set = msm_config_group_set,
369};
370
371static struct pinctrl_desc msm_pinctrl_desc = {
372 .pctlops = &msm_pinctrl_ops,
373 .pmxops = &msm_pinmux_ops,
374 .confops = &msm_pinconf_ops,
375 .owner = THIS_MODULE,
376};
377
378static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
379{
380 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100381 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800382 unsigned long flags;
383 u32 val;
384
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800385 g = &pctrl->soc->groups[offset];
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800386
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600387 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800388
389 val = readl(pctrl->regs + g->ctl_reg);
390 val &= ~BIT(g->oe_bit);
391 writel(val, pctrl->regs + g->ctl_reg);
392
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600393 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800394
395 return 0;
396}
397
398static int msm_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value)
399{
400 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100401 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800402 unsigned long flags;
403 u32 val;
404
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800405 g = &pctrl->soc->groups[offset];
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800406
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600407 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800408
Axel Line476e772013-12-13 21:35:55 +0800409 val = readl(pctrl->regs + g->io_reg);
410 if (value)
411 val |= BIT(g->out_bit);
412 else
413 val &= ~BIT(g->out_bit);
414 writel(val, pctrl->regs + g->io_reg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800415
416 val = readl(pctrl->regs + g->ctl_reg);
417 val |= BIT(g->oe_bit);
418 writel(val, pctrl->regs + g->ctl_reg);
419
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600420 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800421
422 return 0;
423}
424
425static int msm_gpio_get(struct gpio_chip *chip, unsigned offset)
426{
427 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100428 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800429 u32 val;
430
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800431 g = &pctrl->soc->groups[offset];
432
433 val = readl(pctrl->regs + g->io_reg);
434 return !!(val & BIT(g->in_bit));
435}
436
437static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
438{
439 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100440 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800441 unsigned long flags;
442 u32 val;
443
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800444 g = &pctrl->soc->groups[offset];
445
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600446 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800447
448 val = readl(pctrl->regs + g->io_reg);
Axel Line476e772013-12-13 21:35:55 +0800449 if (value)
450 val |= BIT(g->out_bit);
451 else
452 val &= ~BIT(g->out_bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800453 writel(val, pctrl->regs + g->io_reg);
454
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600455 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800456}
457
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800458#ifdef CONFIG_DEBUG_FS
459#include <linux/seq_file.h>
460
461static void msm_gpio_dbg_show_one(struct seq_file *s,
462 struct pinctrl_dev *pctldev,
463 struct gpio_chip *chip,
464 unsigned offset,
465 unsigned gpio)
466{
467 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100468 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800469 unsigned func;
470 int is_out;
471 int drive;
472 int pull;
473 u32 ctl_reg;
474
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800475 static const char * const pulls[] = {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800476 "no pull",
477 "pull down",
478 "keeper",
479 "pull up"
480 };
481
482 g = &pctrl->soc->groups[offset];
483 ctl_reg = readl(pctrl->regs + g->ctl_reg);
484
485 is_out = !!(ctl_reg & BIT(g->oe_bit));
486 func = (ctl_reg >> g->mux_bit) & 7;
487 drive = (ctl_reg >> g->drv_bit) & 7;
488 pull = (ctl_reg >> g->pull_bit) & 3;
489
490 seq_printf(s, " %-8s: %-3s %d", g->name, is_out ? "out" : "in", func);
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800491 seq_printf(s, " %dmA", msm_regval_to_drive(drive));
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800492 seq_printf(s, " %s", pulls[pull]);
493}
494
495static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
496{
497 unsigned gpio = chip->base;
498 unsigned i;
499
500 for (i = 0; i < chip->ngpio; i++, gpio++) {
501 msm_gpio_dbg_show_one(s, NULL, chip, i, gpio);
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800502 seq_puts(s, "\n");
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800503 }
504}
505
506#else
507#define msm_gpio_dbg_show NULL
508#endif
509
510static struct gpio_chip msm_gpio_template = {
511 .direction_input = msm_gpio_direction_input,
512 .direction_output = msm_gpio_direction_output,
513 .get = msm_gpio_get,
514 .set = msm_gpio_set,
Jonas Gorski98c85d52015-10-11 17:34:19 +0200515 .request = gpiochip_generic_request,
516 .free = gpiochip_generic_free,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800517 .dbg_show = msm_gpio_dbg_show,
518};
519
520/* For dual-edge interrupts in software, since some hardware has no
521 * such support:
522 *
523 * At appropriate moments, this function may be called to flip the polarity
524 * settings of both-edge irq lines to try and catch the next edge.
525 *
526 * The attempt is considered successful if:
527 * - the status bit goes high, indicating that an edge was caught, or
528 * - the input value of the gpio doesn't change during the attempt.
529 * If the value changes twice during the process, that would cause the first
530 * test to fail but would force the second, as two opposite
531 * transitions would cause a detection no matter the polarity setting.
532 *
533 * The do-loop tries to sledge-hammer closed the timing hole between
534 * the initial value-read and the polarity-write - if the line value changes
535 * during that window, an interrupt is lost, the new polarity setting is
536 * incorrect, and the first success test will fail, causing a retry.
537 *
538 * Algorithm comes from Google's msmgpio driver.
539 */
540static void msm_gpio_update_dual_edge_pos(struct msm_pinctrl *pctrl,
541 const struct msm_pingroup *g,
542 struct irq_data *d)
543{
544 int loop_limit = 100;
545 unsigned val, val2, intstat;
546 unsigned pol;
547
548 do {
549 val = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit);
550
551 pol = readl(pctrl->regs + g->intr_cfg_reg);
552 pol ^= BIT(g->intr_polarity_bit);
553 writel(pol, pctrl->regs + g->intr_cfg_reg);
554
555 val2 = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit);
556 intstat = readl(pctrl->regs + g->intr_status_reg);
557 if (intstat || (val == val2))
558 return;
559 } while (loop_limit-- > 0);
560 dev_err(pctrl->dev, "dual-edge irq failed to stabilize, %#08x != %#08x\n",
561 val, val2);
562}
563
564static void msm_gpio_irq_mask(struct irq_data *d)
565{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700566 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100567 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800568 const struct msm_pingroup *g;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800569 unsigned long flags;
570 u32 val;
571
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800572 g = &pctrl->soc->groups[d->hwirq];
573
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600574 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800575
576 val = readl(pctrl->regs + g->intr_cfg_reg);
577 val &= ~BIT(g->intr_enable_bit);
578 writel(val, pctrl->regs + g->intr_cfg_reg);
579
580 clear_bit(d->hwirq, pctrl->enabled_irqs);
581
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600582 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800583}
584
585static void msm_gpio_irq_unmask(struct irq_data *d)
586{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700587 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100588 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800589 const struct msm_pingroup *g;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800590 unsigned long flags;
591 u32 val;
592
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800593 g = &pctrl->soc->groups[d->hwirq];
594
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600595 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800596
597 val = readl(pctrl->regs + g->intr_status_reg);
598 val &= ~BIT(g->intr_status_bit);
599 writel(val, pctrl->regs + g->intr_status_reg);
600
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
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600607 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800608}
609
610static void msm_gpio_irq_ack(struct irq_data *d)
611{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700612 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100613 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800614 const struct msm_pingroup *g;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800615 unsigned long flags;
616 u32 val;
617
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800618 g = &pctrl->soc->groups[d->hwirq];
619
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600620 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800621
622 val = readl(pctrl->regs + g->intr_status_reg);
Bjorn Andersson48f15e92014-03-31 14:49:54 -0700623 if (g->intr_ack_high)
624 val |= BIT(g->intr_status_bit);
625 else
626 val &= ~BIT(g->intr_status_bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800627 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
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600632 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800633}
634
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800635static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
636{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700637 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100638 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800639 const struct msm_pingroup *g;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800640 unsigned long flags;
641 u32 val;
642
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800643 g = &pctrl->soc->groups[d->hwirq];
644
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600645 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800646
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 Djakovf712c552014-09-03 19:28:16 +0300658 val |= g->intr_target_kpss_val << g->intr_target_bit;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800659 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 Andersson48f15e92014-03-31 14:49:54 -0700703 val |= BIT(g->intr_polarity_bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800704 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
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600719 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800720
721 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
Thomas Gleixner34c0ad82015-06-23 15:52:51 +0200722 irq_set_handler_locked(d, handle_level_irq);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800723 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
Thomas Gleixner34c0ad82015-06-23 15:52:51 +0200724 irq_set_handler_locked(d, handle_edge_irq);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800725
726 return 0;
727}
728
729static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
730{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700731 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100732 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800733 unsigned long flags;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800734
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600735 raw_spin_lock_irqsave(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800736
Josh Cartwright6aced332014-03-05 13:33:08 -0600737 irq_set_irq_wake(pctrl->irq, on);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800738
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600739 raw_spin_unlock_irqrestore(&pctrl->lock, flags);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800740
741 return 0;
742}
743
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800744static 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 Anderssonf365be02013-12-05 18:10:03 -0800751};
752
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200753static void msm_gpio_irq_handler(struct irq_desc *desc)
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800754{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700755 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800756 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100757 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Jiang Liu5663bb22015-06-04 12:13:16 +0800758 struct irq_chip *chip = irq_desc_get_chip(desc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800759 int irq_pin;
760 int handled = 0;
761 u32 val;
762 int i;
763
764 chained_irq_enter(chip, desc);
765
766 /*
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800767 * Each pin has it's own IRQ status register, so use
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800768 * enabled_irq bitmap to limit the number of reads.
769 */
770 for_each_set_bit(i, pctrl->enabled_irqs, pctrl->chip.ngpio) {
771 g = &pctrl->soc->groups[i];
772 val = readl(pctrl->regs + g->intr_status_reg);
773 if (val & BIT(g->intr_status_bit)) {
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700774 irq_pin = irq_find_mapping(gc->irqdomain, i);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800775 generic_handle_irq(irq_pin);
776 handled++;
777 }
778 }
779
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800780 /* No interrupts were flagged */
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800781 if (handled == 0)
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200782 handle_bad_irq(desc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800783
784 chained_irq_exit(chip, desc);
785}
786
787static int msm_gpio_init(struct msm_pinctrl *pctrl)
788{
789 struct gpio_chip *chip;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800790 int ret;
Stephen Boyddcd278b2014-03-06 22:44:41 -0800791 unsigned ngpio = pctrl->soc->ngpios;
792
793 if (WARN_ON(ngpio > MAX_NR_GPIO))
794 return -EINVAL;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800795
796 chip = &pctrl->chip;
797 chip->base = 0;
Stephen Boyddcd278b2014-03-06 22:44:41 -0800798 chip->ngpio = ngpio;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800799 chip->label = dev_name(pctrl->dev);
Linus Walleij58383c782015-11-04 09:56:26 +0100800 chip->parent = pctrl->dev;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800801 chip->owner = THIS_MODULE;
802 chip->of_node = pctrl->dev->of_node;
803
Linus Walleijfded3f42015-12-08 09:49:18 +0100804 ret = gpiochip_add_data(&pctrl->chip, pctrl);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800805 if (ret) {
806 dev_err(pctrl->dev, "Failed register gpiochip\n");
807 return ret;
808 }
809
810 ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 0, 0, chip->ngpio);
811 if (ret) {
812 dev_err(pctrl->dev, "Failed to add pin range\n");
Pramod Guravc6e927a2014-08-29 13:41:48 +0530813 gpiochip_remove(&pctrl->chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800814 return ret;
815 }
816
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700817 ret = gpiochip_irqchip_add(chip,
818 &msm_gpio_irq_chip,
819 0,
820 handle_edge_irq,
821 IRQ_TYPE_NONE);
822 if (ret) {
823 dev_err(pctrl->dev, "Failed to add irqchip to gpiochip\n");
Pramod Guravc6e927a2014-08-29 13:41:48 +0530824 gpiochip_remove(&pctrl->chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800825 return -ENOSYS;
826 }
827
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700828 gpiochip_set_chained_irqchip(chip, &msm_gpio_irq_chip, pctrl->irq,
829 msm_gpio_irq_handler);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800830
831 return 0;
832}
833
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500834static int msm_ps_hold_restart(struct notifier_block *nb, unsigned long action,
835 void *data)
Pramod Gurav32745582014-08-29 20:00:59 +0530836{
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500837 struct msm_pinctrl *pctrl = container_of(nb, struct msm_pinctrl, restart_nb);
838
839 writel(0, pctrl->regs + PS_HOLD_OFFSET);
840 mdelay(1000);
841 return NOTIFY_DONE;
Pramod Gurav32745582014-08-29 20:00:59 +0530842}
843
Stephen Boydad644982015-07-06 18:09:30 -0700844static struct msm_pinctrl *poweroff_pctrl;
845
846static void msm_ps_hold_poweroff(void)
847{
848 msm_ps_hold_restart(&poweroff_pctrl->restart_nb, 0, NULL);
849}
850
Pramod Gurav32745582014-08-29 20:00:59 +0530851static void msm_pinctrl_setup_pm_reset(struct msm_pinctrl *pctrl)
852{
Stephen Boydbcd53f82015-01-19 11:17:45 +0100853 int i;
Pramod Gurav32745582014-08-29 20:00:59 +0530854 const struct msm_function *func = pctrl->soc->functions;
855
Stephen Boydbcd53f82015-01-19 11:17:45 +0100856 for (i = 0; i < pctrl->soc->nfunctions; i++)
Pramod Gurav32745582014-08-29 20:00:59 +0530857 if (!strcmp(func[i].name, "ps_hold")) {
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500858 pctrl->restart_nb.notifier_call = msm_ps_hold_restart;
859 pctrl->restart_nb.priority = 128;
860 if (register_restart_handler(&pctrl->restart_nb))
861 dev_err(pctrl->dev,
862 "failed to setup restart handler.\n");
Stephen Boydad644982015-07-06 18:09:30 -0700863 poweroff_pctrl = pctrl;
864 pm_power_off = msm_ps_hold_poweroff;
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500865 break;
Pramod Gurav32745582014-08-29 20:00:59 +0530866 }
867}
Pramod Gurav32745582014-08-29 20:00:59 +0530868
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800869int msm_pinctrl_probe(struct platform_device *pdev,
870 const struct msm_pinctrl_soc_data *soc_data)
871{
872 struct msm_pinctrl *pctrl;
873 struct resource *res;
874 int ret;
875
876 pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
877 if (!pctrl) {
878 dev_err(&pdev->dev, "Can't allocate msm_pinctrl\n");
879 return -ENOMEM;
880 }
881 pctrl->dev = &pdev->dev;
882 pctrl->soc = soc_data;
883 pctrl->chip = msm_gpio_template;
884
Julia Cartwright47b03ca2017-01-20 10:13:47 -0600885 raw_spin_lock_init(&pctrl->lock);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800886
887 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
888 pctrl->regs = devm_ioremap_resource(&pdev->dev, res);
889 if (IS_ERR(pctrl->regs))
890 return PTR_ERR(pctrl->regs);
891
Pramod Gurav32745582014-08-29 20:00:59 +0530892 msm_pinctrl_setup_pm_reset(pctrl);
893
Bjorn Anderssonf393e482013-12-14 23:01:52 -0800894 pctrl->irq = platform_get_irq(pdev, 0);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800895 if (pctrl->irq < 0) {
896 dev_err(&pdev->dev, "No interrupt defined for msmgpio\n");
897 return pctrl->irq;
898 }
899
900 msm_pinctrl_desc.name = dev_name(&pdev->dev);
901 msm_pinctrl_desc.pins = pctrl->soc->pins;
902 msm_pinctrl_desc.npins = pctrl->soc->npins;
Laxman Dewanganfe0267f2016-02-24 14:44:07 +0530903 pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &msm_pinctrl_desc,
904 pctrl);
Masahiro Yamada323de9e2015-06-09 13:01:16 +0900905 if (IS_ERR(pctrl->pctrl)) {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800906 dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
Masahiro Yamada323de9e2015-06-09 13:01:16 +0900907 return PTR_ERR(pctrl->pctrl);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800908 }
909
910 ret = msm_gpio_init(pctrl);
Laxman Dewanganfe0267f2016-02-24 14:44:07 +0530911 if (ret)
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800912 return ret;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800913
914 platform_set_drvdata(pdev, pctrl);
915
916 dev_dbg(&pdev->dev, "Probed Qualcomm pinctrl driver\n");
917
918 return 0;
919}
920EXPORT_SYMBOL(msm_pinctrl_probe);
921
922int msm_pinctrl_remove(struct platform_device *pdev)
923{
924 struct msm_pinctrl *pctrl = platform_get_drvdata(pdev);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800925
Linus Walleij2fcea6c2014-09-16 15:05:41 -0700926 gpiochip_remove(&pctrl->chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800927
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500928 unregister_restart_handler(&pctrl->restart_nb);
929
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800930 return 0;
931}
932EXPORT_SYMBOL(msm_pinctrl_remove);
933