blob: f9d483b554977f02fd45fb45308697e02366b9c4 [file] [log] [blame]
Bjorn Anderssonf365be02013-12-05 18:10:03 -08001/*
2 * Copyright (c) 2013, Sony Mobile Communications AB.
Prasad Sodagudid0451852016-07-01 14:12:20 +05303 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
Bjorn Anderssonf365be02013-12-05 18:10:03 -08004 *
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>
Prasad Sodagudid0451852016-07-01 14:12:20 +053030#include <linux/syscore_ops.h>
Josh Cartwrightcf1fc182014-09-23 15:59:53 -050031#include <linux/reboot.h>
Stephen Boydad644982015-07-06 18:09:30 -070032#include <linux/pm.h>
Stephen Boyd47a01ee2016-06-25 22:21:31 -070033#include <linux/log2.h>
Pramod Gurav32745582014-08-29 20:00:59 +053034
Linus Walleij69b78b82014-07-09 13:55:12 +020035#include "../core.h"
36#include "../pinconf.h"
Bjorn Anderssonf365be02013-12-05 18:10:03 -080037#include "pinctrl-msm.h"
Linus Walleij69b78b82014-07-09 13:55:12 +020038#include "../pinctrl-utils.h"
Bjorn Anderssonf365be02013-12-05 18:10:03 -080039
Bjorn Andersson408e3c62013-12-14 23:01:53 -080040#define MAX_NR_GPIO 300
Pramod Gurav32745582014-08-29 20:00:59 +053041#define PS_HOLD_OFFSET 0x820
Bjorn Andersson408e3c62013-12-14 23:01:53 -080042
Bjorn Anderssonf365be02013-12-05 18:10:03 -080043/**
44 * struct msm_pinctrl - state for a pinctrl-msm device
45 * @dev: device handle.
46 * @pctrl: pinctrl handle.
Bjorn Anderssonf365be02013-12-05 18:10:03 -080047 * @chip: gpiochip handle.
Josh Cartwrightcf1fc182014-09-23 15:59:53 -050048 * @restart_nb: restart notifier block.
Bjorn Anderssonf365be02013-12-05 18:10:03 -080049 * @irq: parent irq for the TLMM irq_chip.
50 * @lock: Spinlock to protect register resources as well
51 * as msm_pinctrl data structures.
52 * @enabled_irqs: Bitmap of currently enabled irqs.
53 * @dual_edge_irqs: Bitmap of irqs that need sw emulated dual edge
54 * detection.
Bjorn Anderssonf365be02013-12-05 18:10:03 -080055 * @soc; Reference to soc_data of platform specific data.
56 * @regs: Base address for the TLMM register map.
57 */
58struct msm_pinctrl {
59 struct device *dev;
60 struct pinctrl_dev *pctrl;
Bjorn Anderssonf365be02013-12-05 18:10:03 -080061 struct gpio_chip chip;
Josh Cartwrightcf1fc182014-09-23 15:59:53 -050062 struct notifier_block restart_nb;
Bjorn Anderssonf393e482013-12-14 23:01:52 -080063 int irq;
Bjorn Anderssonf365be02013-12-05 18:10:03 -080064
65 spinlock_t lock;
66
Bjorn Andersson408e3c62013-12-14 23:01:53 -080067 DECLARE_BITMAP(dual_edge_irqs, MAX_NR_GPIO);
68 DECLARE_BITMAP(enabled_irqs, MAX_NR_GPIO);
Bjorn Anderssonf365be02013-12-05 18:10:03 -080069
70 const struct msm_pinctrl_soc_data *soc;
71 void __iomem *regs;
72};
73
Prasad Sodagudid0451852016-07-01 14:12:20 +053074static struct msm_pinctrl *msm_pinctrl_data;
75
Bjorn Anderssonf365be02013-12-05 18:10:03 -080076static int msm_get_groups_count(struct pinctrl_dev *pctldev)
77{
78 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
79
80 return pctrl->soc->ngroups;
81}
82
83static const char *msm_get_group_name(struct pinctrl_dev *pctldev,
84 unsigned group)
85{
86 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
87
88 return pctrl->soc->groups[group].name;
89}
90
91static int msm_get_group_pins(struct pinctrl_dev *pctldev,
92 unsigned group,
93 const unsigned **pins,
94 unsigned *num_pins)
95{
96 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
97
98 *pins = pctrl->soc->groups[group].pins;
99 *num_pins = pctrl->soc->groups[group].npins;
100 return 0;
101}
102
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800103static const struct pinctrl_ops msm_pinctrl_ops = {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800104 .get_groups_count = msm_get_groups_count,
105 .get_group_name = msm_get_group_name,
106 .get_group_pins = msm_get_group_pins,
107 .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
Irina Tirdead32f7fd2016-03-31 14:44:42 +0300108 .dt_free_map = pinctrl_utils_free_map,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800109};
110
111static int msm_get_functions_count(struct pinctrl_dev *pctldev)
112{
113 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
114
115 return pctrl->soc->nfunctions;
116}
117
118static const char *msm_get_function_name(struct pinctrl_dev *pctldev,
119 unsigned function)
120{
121 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
122
123 return pctrl->soc->functions[function].name;
124}
125
126static int msm_get_function_groups(struct pinctrl_dev *pctldev,
127 unsigned function,
128 const char * const **groups,
129 unsigned * const num_groups)
130{
131 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
132
133 *groups = pctrl->soc->functions[function].groups;
134 *num_groups = pctrl->soc->functions[function].ngroups;
135 return 0;
136}
137
Linus Walleij03e9f0c2014-09-03 13:02:56 +0200138static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev,
139 unsigned function,
140 unsigned group)
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800141{
142 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
143 const struct msm_pingroup *g;
144 unsigned long flags;
Stephen Boyd47a01ee2016-06-25 22:21:31 -0700145 u32 val, mask;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800146 int i;
147
148 g = &pctrl->soc->groups[group];
Stephen Boyd47a01ee2016-06-25 22:21:31 -0700149 mask = GENMASK(g->mux_bit + order_base_2(g->nfuncs) - 1, g->mux_bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800150
Bjorn Andersson3c253812014-03-31 14:49:55 -0700151 for (i = 0; i < g->nfuncs; i++) {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800152 if (g->funcs[i] == function)
153 break;
154 }
155
Bjorn Andersson3c253812014-03-31 14:49:55 -0700156 if (WARN_ON(i == g->nfuncs))
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800157 return -EINVAL;
158
159 spin_lock_irqsave(&pctrl->lock, flags);
160
161 val = readl(pctrl->regs + g->ctl_reg);
John Crispin6bcf3f62016-09-12 11:36:55 +0200162 val &= ~mask;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800163 val |= i << g->mux_bit;
164 writel(val, pctrl->regs + g->ctl_reg);
165
166 spin_unlock_irqrestore(&pctrl->lock, flags);
167
168 return 0;
169}
170
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800171static const struct pinmux_ops msm_pinmux_ops = {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800172 .get_functions_count = msm_get_functions_count,
173 .get_function_name = msm_get_function_name,
174 .get_function_groups = msm_get_function_groups,
Linus Walleij03e9f0c2014-09-03 13:02:56 +0200175 .set_mux = msm_pinmux_set_mux,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800176};
177
178static int msm_config_reg(struct msm_pinctrl *pctrl,
179 const struct msm_pingroup *g,
180 unsigned param,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800181 unsigned *mask,
182 unsigned *bit)
183{
184 switch (param) {
185 case PIN_CONFIG_BIAS_DISABLE:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800186 case PIN_CONFIG_BIAS_PULL_DOWN:
Andy Grossb831a152014-06-17 23:49:11 -0500187 case PIN_CONFIG_BIAS_BUS_HOLD:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800188 case PIN_CONFIG_BIAS_PULL_UP:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800189 *bit = g->pull_bit;
190 *mask = 3;
191 break;
192 case PIN_CONFIG_DRIVE_STRENGTH:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800193 *bit = g->drv_bit;
194 *mask = 7;
195 break;
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800196 case PIN_CONFIG_OUTPUT:
Stanimir Varbanov407f5e32015-03-04 12:41:57 +0200197 case PIN_CONFIG_INPUT_ENABLE:
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800198 *bit = g->oe_bit;
199 *mask = 1;
200 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800201 default:
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800202 return -ENOTSUPP;
203 }
204
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800205 return 0;
206}
207
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800208#define MSM_NO_PULL 0
209#define MSM_PULL_DOWN 1
Andy Grossb831a152014-06-17 23:49:11 -0500210#define MSM_KEEPER 2
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800211#define MSM_PULL_UP 3
212
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800213static unsigned msm_regval_to_drive(u32 val)
214{
215 return (val + 1) * 2;
216}
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800217
218static int msm_config_group_get(struct pinctrl_dev *pctldev,
219 unsigned int group,
220 unsigned long *config)
221{
222 const struct msm_pingroup *g;
223 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
224 unsigned param = pinconf_to_config_param(*config);
225 unsigned mask;
226 unsigned arg;
227 unsigned bit;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800228 int ret;
229 u32 val;
230
231 g = &pctrl->soc->groups[group];
232
Stephen Boyd051a58b2014-03-06 22:44:46 -0800233 ret = msm_config_reg(pctrl, g, param, &mask, &bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800234 if (ret < 0)
235 return ret;
236
Stephen Boyd051a58b2014-03-06 22:44:46 -0800237 val = readl(pctrl->regs + g->ctl_reg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800238 arg = (val >> bit) & mask;
239
240 /* Convert register value to pinconf value */
241 switch (param) {
242 case PIN_CONFIG_BIAS_DISABLE:
243 arg = arg == MSM_NO_PULL;
244 break;
245 case PIN_CONFIG_BIAS_PULL_DOWN:
246 arg = arg == MSM_PULL_DOWN;
247 break;
Andy Grossb831a152014-06-17 23:49:11 -0500248 case PIN_CONFIG_BIAS_BUS_HOLD:
249 arg = arg == MSM_KEEPER;
250 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800251 case PIN_CONFIG_BIAS_PULL_UP:
252 arg = arg == MSM_PULL_UP;
253 break;
254 case PIN_CONFIG_DRIVE_STRENGTH:
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800255 arg = msm_regval_to_drive(arg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800256 break;
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800257 case PIN_CONFIG_OUTPUT:
258 /* Pin is not output */
259 if (!arg)
260 return -EINVAL;
261
262 val = readl(pctrl->regs + g->io_reg);
263 arg = !!(val & BIT(g->in_bit));
264 break;
Stanimir Varbanov407f5e32015-03-04 12:41:57 +0200265 case PIN_CONFIG_INPUT_ENABLE:
266 /* Pin is output */
267 if (arg)
268 return -EINVAL;
269 arg = 1;
270 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800271 default:
Stanimir Varbanov38d756a2015-03-04 12:41:56 +0200272 return -ENOTSUPP;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800273 }
274
275 *config = pinconf_to_config_packed(param, arg);
276
277 return 0;
278}
279
280static int msm_config_group_set(struct pinctrl_dev *pctldev,
281 unsigned group,
282 unsigned long *configs,
283 unsigned num_configs)
284{
285 const struct msm_pingroup *g;
286 struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
287 unsigned long flags;
288 unsigned param;
289 unsigned mask;
290 unsigned arg;
291 unsigned bit;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800292 int ret;
293 u32 val;
294 int i;
295
296 g = &pctrl->soc->groups[group];
297
298 for (i = 0; i < num_configs; i++) {
299 param = pinconf_to_config_param(configs[i]);
300 arg = pinconf_to_config_argument(configs[i]);
301
Stephen Boyd051a58b2014-03-06 22:44:46 -0800302 ret = msm_config_reg(pctrl, g, param, &mask, &bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800303 if (ret < 0)
304 return ret;
305
306 /* Convert pinconf values to register values */
307 switch (param) {
308 case PIN_CONFIG_BIAS_DISABLE:
309 arg = MSM_NO_PULL;
310 break;
311 case PIN_CONFIG_BIAS_PULL_DOWN:
312 arg = MSM_PULL_DOWN;
313 break;
Andy Grossb831a152014-06-17 23:49:11 -0500314 case PIN_CONFIG_BIAS_BUS_HOLD:
315 arg = MSM_KEEPER;
316 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800317 case PIN_CONFIG_BIAS_PULL_UP:
318 arg = MSM_PULL_UP;
319 break;
320 case PIN_CONFIG_DRIVE_STRENGTH:
321 /* Check for invalid values */
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800322 if (arg > 16 || arg < 2 || (arg % 2) != 0)
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800323 arg = -1;
324 else
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800325 arg = (arg / 2) - 1;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800326 break;
Bjorn Anderssoned118a52014-02-04 19:55:31 -0800327 case PIN_CONFIG_OUTPUT:
328 /* set output value */
329 spin_lock_irqsave(&pctrl->lock, flags);
330 val = readl(pctrl->regs + g->io_reg);
331 if (arg)
332 val |= BIT(g->out_bit);
333 else
334 val &= ~BIT(g->out_bit);
335 writel(val, pctrl->regs + g->io_reg);
336 spin_unlock_irqrestore(&pctrl->lock, flags);
337
338 /* enable output */
339 arg = 1;
340 break;
Stanimir Varbanov407f5e32015-03-04 12:41:57 +0200341 case PIN_CONFIG_INPUT_ENABLE:
342 /* disable output */
343 arg = 0;
344 break;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800345 default:
346 dev_err(pctrl->dev, "Unsupported config parameter: %x\n",
347 param);
348 return -EINVAL;
349 }
350
351 /* Range-check user-supplied value */
352 if (arg & ~mask) {
353 dev_err(pctrl->dev, "config %x: %x is invalid\n", param, arg);
354 return -EINVAL;
355 }
356
357 spin_lock_irqsave(&pctrl->lock, flags);
Stephen Boyd051a58b2014-03-06 22:44:46 -0800358 val = readl(pctrl->regs + g->ctl_reg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800359 val &= ~(mask << bit);
360 val |= arg << bit;
Stephen Boyd051a58b2014-03-06 22:44:46 -0800361 writel(val, pctrl->regs + g->ctl_reg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800362 spin_unlock_irqrestore(&pctrl->lock, flags);
363 }
364
365 return 0;
366}
367
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800368static const struct pinconf_ops msm_pinconf_ops = {
Stanimir Varbanov38d756a2015-03-04 12:41:56 +0200369 .is_generic = true,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800370 .pin_config_group_get = msm_config_group_get,
371 .pin_config_group_set = msm_config_group_set,
372};
373
374static struct pinctrl_desc msm_pinctrl_desc = {
375 .pctlops = &msm_pinctrl_ops,
376 .pmxops = &msm_pinmux_ops,
377 .confops = &msm_pinconf_ops,
378 .owner = THIS_MODULE,
379};
380
381static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
382{
383 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100384 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800385 unsigned long flags;
386 u32 val;
387
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800388 g = &pctrl->soc->groups[offset];
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800389
390 spin_lock_irqsave(&pctrl->lock, flags);
391
392 val = readl(pctrl->regs + g->ctl_reg);
393 val &= ~BIT(g->oe_bit);
394 writel(val, pctrl->regs + g->ctl_reg);
395
396 spin_unlock_irqrestore(&pctrl->lock, flags);
397
398 return 0;
399}
400
401static int msm_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value)
402{
403 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100404 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800405 unsigned long flags;
406 u32 val;
407
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800408 g = &pctrl->soc->groups[offset];
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800409
410 spin_lock_irqsave(&pctrl->lock, flags);
411
Axel Line476e772013-12-13 21:35:55 +0800412 val = readl(pctrl->regs + g->io_reg);
413 if (value)
414 val |= BIT(g->out_bit);
415 else
416 val &= ~BIT(g->out_bit);
417 writel(val, pctrl->regs + g->io_reg);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800418
419 val = readl(pctrl->regs + g->ctl_reg);
420 val |= BIT(g->oe_bit);
421 writel(val, pctrl->regs + g->ctl_reg);
422
423 spin_unlock_irqrestore(&pctrl->lock, flags);
424
425 return 0;
426}
427
428static int msm_gpio_get(struct gpio_chip *chip, unsigned offset)
429{
430 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100431 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800432 u32 val;
433
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800434 g = &pctrl->soc->groups[offset];
435
436 val = readl(pctrl->regs + g->io_reg);
437 return !!(val & BIT(g->in_bit));
438}
439
440static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
441{
442 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100443 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800444 unsigned long flags;
445 u32 val;
446
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800447 g = &pctrl->soc->groups[offset];
448
449 spin_lock_irqsave(&pctrl->lock, flags);
450
451 val = readl(pctrl->regs + g->io_reg);
Axel Line476e772013-12-13 21:35:55 +0800452 if (value)
453 val |= BIT(g->out_bit);
454 else
455 val &= ~BIT(g->out_bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800456 writel(val, pctrl->regs + g->io_reg);
457
458 spin_unlock_irqrestore(&pctrl->lock, flags);
459}
460
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800461#ifdef CONFIG_DEBUG_FS
462#include <linux/seq_file.h>
463
464static void msm_gpio_dbg_show_one(struct seq_file *s,
465 struct pinctrl_dev *pctldev,
466 struct gpio_chip *chip,
467 unsigned offset,
468 unsigned gpio)
469{
470 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100471 struct msm_pinctrl *pctrl = gpiochip_get_data(chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800472 unsigned func;
473 int is_out;
474 int drive;
475 int pull;
476 u32 ctl_reg;
477
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800478 static const char * const pulls[] = {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800479 "no pull",
480 "pull down",
481 "keeper",
482 "pull up"
483 };
484
485 g = &pctrl->soc->groups[offset];
486 ctl_reg = readl(pctrl->regs + g->ctl_reg);
487
488 is_out = !!(ctl_reg & BIT(g->oe_bit));
489 func = (ctl_reg >> g->mux_bit) & 7;
490 drive = (ctl_reg >> g->drv_bit) & 7;
491 pull = (ctl_reg >> g->pull_bit) & 3;
492
493 seq_printf(s, " %-8s: %-3s %d", g->name, is_out ? "out" : "in", func);
Stephen Boyd7cc34e22014-03-06 22:44:44 -0800494 seq_printf(s, " %dmA", msm_regval_to_drive(drive));
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800495 seq_printf(s, " %s", pulls[pull]);
496}
497
498static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
499{
500 unsigned gpio = chip->base;
501 unsigned i;
502
503 for (i = 0; i < chip->ngpio; i++, gpio++) {
504 msm_gpio_dbg_show_one(s, NULL, chip, i, gpio);
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800505 seq_puts(s, "\n");
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800506 }
507}
508
509#else
510#define msm_gpio_dbg_show NULL
511#endif
512
513static struct gpio_chip msm_gpio_template = {
514 .direction_input = msm_gpio_direction_input,
515 .direction_output = msm_gpio_direction_output,
516 .get = msm_gpio_get,
517 .set = msm_gpio_set,
Jonas Gorski98c85d52015-10-11 17:34:19 +0200518 .request = gpiochip_generic_request,
519 .free = gpiochip_generic_free,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800520 .dbg_show = msm_gpio_dbg_show,
521};
522
523/* For dual-edge interrupts in software, since some hardware has no
524 * such support:
525 *
526 * At appropriate moments, this function may be called to flip the polarity
527 * settings of both-edge irq lines to try and catch the next edge.
528 *
529 * The attempt is considered successful if:
530 * - the status bit goes high, indicating that an edge was caught, or
531 * - the input value of the gpio doesn't change during the attempt.
532 * If the value changes twice during the process, that would cause the first
533 * test to fail but would force the second, as two opposite
534 * transitions would cause a detection no matter the polarity setting.
535 *
536 * The do-loop tries to sledge-hammer closed the timing hole between
537 * the initial value-read and the polarity-write - if the line value changes
538 * during that window, an interrupt is lost, the new polarity setting is
539 * incorrect, and the first success test will fail, causing a retry.
540 *
541 * Algorithm comes from Google's msmgpio driver.
542 */
543static void msm_gpio_update_dual_edge_pos(struct msm_pinctrl *pctrl,
544 const struct msm_pingroup *g,
545 struct irq_data *d)
546{
547 int loop_limit = 100;
548 unsigned val, val2, intstat;
549 unsigned pol;
550
551 do {
552 val = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit);
553
554 pol = readl(pctrl->regs + g->intr_cfg_reg);
555 pol ^= BIT(g->intr_polarity_bit);
556 writel(pol, pctrl->regs + g->intr_cfg_reg);
557
558 val2 = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit);
559 intstat = readl(pctrl->regs + g->intr_status_reg);
560 if (intstat || (val == val2))
561 return;
562 } while (loop_limit-- > 0);
563 dev_err(pctrl->dev, "dual-edge irq failed to stabilize, %#08x != %#08x\n",
564 val, val2);
565}
566
567static void msm_gpio_irq_mask(struct irq_data *d)
568{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700569 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100570 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800571 const struct msm_pingroup *g;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800572 unsigned long flags;
573 u32 val;
574
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800575 g = &pctrl->soc->groups[d->hwirq];
576
577 spin_lock_irqsave(&pctrl->lock, flags);
578
579 val = readl(pctrl->regs + g->intr_cfg_reg);
580 val &= ~BIT(g->intr_enable_bit);
581 writel(val, pctrl->regs + g->intr_cfg_reg);
582
583 clear_bit(d->hwirq, pctrl->enabled_irqs);
584
585 spin_unlock_irqrestore(&pctrl->lock, flags);
586}
587
588static void msm_gpio_irq_unmask(struct irq_data *d)
589{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700590 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100591 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800592 const struct msm_pingroup *g;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800593 unsigned long flags;
594 u32 val;
595
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800596 g = &pctrl->soc->groups[d->hwirq];
597
598 spin_lock_irqsave(&pctrl->lock, flags);
599
600 val = readl(pctrl->regs + g->intr_status_reg);
601 val &= ~BIT(g->intr_status_bit);
602 writel(val, pctrl->regs + g->intr_status_reg);
603
604 val = readl(pctrl->regs + g->intr_cfg_reg);
605 val |= BIT(g->intr_enable_bit);
606 writel(val, pctrl->regs + g->intr_cfg_reg);
607
608 set_bit(d->hwirq, pctrl->enabled_irqs);
609
610 spin_unlock_irqrestore(&pctrl->lock, flags);
611}
612
613static void msm_gpio_irq_ack(struct irq_data *d)
614{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700615 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100616 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800617 const struct msm_pingroup *g;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800618 unsigned long flags;
619 u32 val;
620
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800621 g = &pctrl->soc->groups[d->hwirq];
622
623 spin_lock_irqsave(&pctrl->lock, flags);
624
625 val = readl(pctrl->regs + g->intr_status_reg);
Bjorn Andersson48f15e92014-03-31 14:49:54 -0700626 if (g->intr_ack_high)
627 val |= BIT(g->intr_status_bit);
628 else
629 val &= ~BIT(g->intr_status_bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800630 writel(val, pctrl->regs + g->intr_status_reg);
631
632 if (test_bit(d->hwirq, pctrl->dual_edge_irqs))
633 msm_gpio_update_dual_edge_pos(pctrl, g, d);
634
635 spin_unlock_irqrestore(&pctrl->lock, flags);
636}
637
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800638static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
639{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700640 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100641 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800642 const struct msm_pingroup *g;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800643 unsigned long flags;
644 u32 val;
645
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800646 g = &pctrl->soc->groups[d->hwirq];
647
648 spin_lock_irqsave(&pctrl->lock, flags);
649
650 /*
651 * For hw without possibility of detecting both edges
652 */
653 if (g->intr_detection_width == 1 && type == IRQ_TYPE_EDGE_BOTH)
654 set_bit(d->hwirq, pctrl->dual_edge_irqs);
655 else
656 clear_bit(d->hwirq, pctrl->dual_edge_irqs);
657
658 /* Route interrupts to application cpu */
659 val = readl(pctrl->regs + g->intr_target_reg);
660 val &= ~(7 << g->intr_target_bit);
Georgi Djakovf712c552014-09-03 19:28:16 +0300661 val |= g->intr_target_kpss_val << g->intr_target_bit;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800662 writel(val, pctrl->regs + g->intr_target_reg);
663
664 /* Update configuration for gpio.
665 * RAW_STATUS_EN is left on for all gpio irqs. Due to the
666 * internal circuitry of TLMM, toggling the RAW_STATUS
667 * could cause the INTR_STATUS to be set for EDGE interrupts.
668 */
669 val = readl(pctrl->regs + g->intr_cfg_reg);
670 val |= BIT(g->intr_raw_status_bit);
671 if (g->intr_detection_width == 2) {
672 val &= ~(3 << g->intr_detection_bit);
673 val &= ~(1 << g->intr_polarity_bit);
674 switch (type) {
675 case IRQ_TYPE_EDGE_RISING:
676 val |= 1 << g->intr_detection_bit;
677 val |= BIT(g->intr_polarity_bit);
678 break;
679 case IRQ_TYPE_EDGE_FALLING:
680 val |= 2 << g->intr_detection_bit;
681 val |= BIT(g->intr_polarity_bit);
682 break;
683 case IRQ_TYPE_EDGE_BOTH:
684 val |= 3 << g->intr_detection_bit;
685 val |= BIT(g->intr_polarity_bit);
686 break;
687 case IRQ_TYPE_LEVEL_LOW:
688 break;
689 case IRQ_TYPE_LEVEL_HIGH:
690 val |= BIT(g->intr_polarity_bit);
691 break;
692 }
693 } else if (g->intr_detection_width == 1) {
694 val &= ~(1 << g->intr_detection_bit);
695 val &= ~(1 << g->intr_polarity_bit);
696 switch (type) {
697 case IRQ_TYPE_EDGE_RISING:
698 val |= BIT(g->intr_detection_bit);
699 val |= BIT(g->intr_polarity_bit);
700 break;
701 case IRQ_TYPE_EDGE_FALLING:
702 val |= BIT(g->intr_detection_bit);
703 break;
704 case IRQ_TYPE_EDGE_BOTH:
705 val |= BIT(g->intr_detection_bit);
Bjorn Andersson48f15e92014-03-31 14:49:54 -0700706 val |= BIT(g->intr_polarity_bit);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800707 break;
708 case IRQ_TYPE_LEVEL_LOW:
709 break;
710 case IRQ_TYPE_LEVEL_HIGH:
711 val |= BIT(g->intr_polarity_bit);
712 break;
713 }
714 } else {
715 BUG();
716 }
717 writel(val, pctrl->regs + g->intr_cfg_reg);
718
719 if (test_bit(d->hwirq, pctrl->dual_edge_irqs))
720 msm_gpio_update_dual_edge_pos(pctrl, g, d);
721
722 spin_unlock_irqrestore(&pctrl->lock, flags);
723
724 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
Thomas Gleixner34c0ad82015-06-23 15:52:51 +0200725 irq_set_handler_locked(d, handle_level_irq);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800726 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
Thomas Gleixner34c0ad82015-06-23 15:52:51 +0200727 irq_set_handler_locked(d, handle_edge_irq);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800728
729 return 0;
730}
731
732static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
733{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700734 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijfded3f42015-12-08 09:49:18 +0100735 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800736 unsigned long flags;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800737
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800738 spin_lock_irqsave(&pctrl->lock, flags);
739
Josh Cartwright6aced332014-03-05 13:33:08 -0600740 irq_set_irq_wake(pctrl->irq, on);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800741
742 spin_unlock_irqrestore(&pctrl->lock, flags);
743
744 return 0;
745}
746
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800747static struct irq_chip msm_gpio_irq_chip = {
748 .name = "msmgpio",
749 .irq_mask = msm_gpio_irq_mask,
750 .irq_unmask = msm_gpio_irq_unmask,
751 .irq_ack = msm_gpio_irq_ack,
752 .irq_set_type = msm_gpio_irq_set_type,
753 .irq_set_wake = msm_gpio_irq_set_wake,
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800754};
755
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200756static void msm_gpio_irq_handler(struct irq_desc *desc)
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800757{
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700758 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800759 const struct msm_pingroup *g;
Linus Walleijfded3f42015-12-08 09:49:18 +0100760 struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
Jiang Liu5663bb22015-06-04 12:13:16 +0800761 struct irq_chip *chip = irq_desc_get_chip(desc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800762 int irq_pin;
763 int handled = 0;
764 u32 val;
765 int i;
766
767 chained_irq_enter(chip, desc);
768
769 /*
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800770 * Each pin has it's own IRQ status register, so use
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800771 * enabled_irq bitmap to limit the number of reads.
772 */
773 for_each_set_bit(i, pctrl->enabled_irqs, pctrl->chip.ngpio) {
774 g = &pctrl->soc->groups[i];
775 val = readl(pctrl->regs + g->intr_status_reg);
776 if (val & BIT(g->intr_status_bit)) {
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700777 irq_pin = irq_find_mapping(gc->irqdomain, i);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800778 generic_handle_irq(irq_pin);
779 handled++;
780 }
781 }
782
Bjorn Andersson1f2b2392013-12-14 23:01:51 -0800783 /* No interrupts were flagged */
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800784 if (handled == 0)
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200785 handle_bad_irq(desc);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800786
787 chained_irq_exit(chip, desc);
788}
789
790static int msm_gpio_init(struct msm_pinctrl *pctrl)
791{
792 struct gpio_chip *chip;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800793 int ret;
Stephen Boyddcd278b2014-03-06 22:44:41 -0800794 unsigned ngpio = pctrl->soc->ngpios;
795
796 if (WARN_ON(ngpio > MAX_NR_GPIO))
797 return -EINVAL;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800798
799 chip = &pctrl->chip;
800 chip->base = 0;
Stephen Boyddcd278b2014-03-06 22:44:41 -0800801 chip->ngpio = ngpio;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800802 chip->label = dev_name(pctrl->dev);
Linus Walleij58383c72015-11-04 09:56:26 +0100803 chip->parent = pctrl->dev;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800804 chip->owner = THIS_MODULE;
805 chip->of_node = pctrl->dev->of_node;
806
Linus Walleijfded3f42015-12-08 09:49:18 +0100807 ret = gpiochip_add_data(&pctrl->chip, pctrl);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800808 if (ret) {
809 dev_err(pctrl->dev, "Failed register gpiochip\n");
810 return ret;
811 }
812
813 ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 0, 0, chip->ngpio);
814 if (ret) {
815 dev_err(pctrl->dev, "Failed to add pin range\n");
Pramod Guravc6e927a2014-08-29 13:41:48 +0530816 gpiochip_remove(&pctrl->chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800817 return ret;
818 }
819
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700820 ret = gpiochip_irqchip_add(chip,
821 &msm_gpio_irq_chip,
822 0,
823 handle_edge_irq,
824 IRQ_TYPE_NONE);
825 if (ret) {
826 dev_err(pctrl->dev, "Failed to add irqchip to gpiochip\n");
Pramod Guravc6e927a2014-08-29 13:41:48 +0530827 gpiochip_remove(&pctrl->chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800828 return -ENOSYS;
829 }
830
Linus Walleijcdcb0ab2014-04-29 11:00:40 -0700831 gpiochip_set_chained_irqchip(chip, &msm_gpio_irq_chip, pctrl->irq,
832 msm_gpio_irq_handler);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800833
834 return 0;
835}
836
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500837static int msm_ps_hold_restart(struct notifier_block *nb, unsigned long action,
838 void *data)
Pramod Gurav32745582014-08-29 20:00:59 +0530839{
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500840 struct msm_pinctrl *pctrl = container_of(nb, struct msm_pinctrl, restart_nb);
841
842 writel(0, pctrl->regs + PS_HOLD_OFFSET);
843 mdelay(1000);
844 return NOTIFY_DONE;
Pramod Gurav32745582014-08-29 20:00:59 +0530845}
846
Stephen Boydad644982015-07-06 18:09:30 -0700847static struct msm_pinctrl *poweroff_pctrl;
848
849static void msm_ps_hold_poweroff(void)
850{
851 msm_ps_hold_restart(&poweroff_pctrl->restart_nb, 0, NULL);
852}
853
Pramod Gurav32745582014-08-29 20:00:59 +0530854static void msm_pinctrl_setup_pm_reset(struct msm_pinctrl *pctrl)
855{
Stephen Boydbcd53f82015-01-19 11:17:45 +0100856 int i;
Pramod Gurav32745582014-08-29 20:00:59 +0530857 const struct msm_function *func = pctrl->soc->functions;
858
Stephen Boydbcd53f82015-01-19 11:17:45 +0100859 for (i = 0; i < pctrl->soc->nfunctions; i++)
Pramod Gurav32745582014-08-29 20:00:59 +0530860 if (!strcmp(func[i].name, "ps_hold")) {
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500861 pctrl->restart_nb.notifier_call = msm_ps_hold_restart;
862 pctrl->restart_nb.priority = 128;
863 if (register_restart_handler(&pctrl->restart_nb))
864 dev_err(pctrl->dev,
865 "failed to setup restart handler.\n");
Stephen Boydad644982015-07-06 18:09:30 -0700866 poweroff_pctrl = pctrl;
867 pm_power_off = msm_ps_hold_poweroff;
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500868 break;
Pramod Gurav32745582014-08-29 20:00:59 +0530869 }
870}
Pramod Gurav32745582014-08-29 20:00:59 +0530871
Prasad Sodagudid0451852016-07-01 14:12:20 +0530872#ifdef CONFIG_PM
873static int msm_pinctrl_suspend(void)
874{
875 return 0;
876}
877
878static void msm_pinctrl_resume(void)
879{
880 int i, irq;
881 u32 val;
882 unsigned long flags;
883 struct irq_desc *desc;
884 const struct msm_pingroup *g;
885 const char *name = "null";
886 struct msm_pinctrl *pctrl = msm_pinctrl_data;
887
888 if (!msm_show_resume_irq_mask)
889 return;
890
891 spin_lock_irqsave(&pctrl->lock, flags);
892 for_each_set_bit(i, pctrl->enabled_irqs, pctrl->chip.ngpio) {
893 g = &pctrl->soc->groups[i];
894 val = readl_relaxed(pctrl->regs + g->intr_status_reg);
895 if (val & BIT(g->intr_status_bit)) {
896 irq = irq_find_mapping(pctrl->chip.irqdomain, i);
897 desc = irq_to_desc(irq);
898 if (desc == NULL)
899 name = "stray irq";
900 else if (desc->action && desc->action->name)
901 name = desc->action->name;
902
903 pr_warn("%s: %d triggered %s\n", __func__, irq, name);
904 }
905 }
906 spin_unlock_irqrestore(&pctrl->lock, flags);
907}
908#else
909#define msm_pinctrl_suspend NULL
910#define msm_pinctrl_resume NULL
911#endif
912
913static struct syscore_ops msm_pinctrl_pm_ops = {
914 .suspend = msm_pinctrl_suspend,
915 .resume = msm_pinctrl_resume,
916};
917
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800918int msm_pinctrl_probe(struct platform_device *pdev,
919 const struct msm_pinctrl_soc_data *soc_data)
920{
921 struct msm_pinctrl *pctrl;
922 struct resource *res;
923 int ret;
924
Prasad Sodagudid0451852016-07-01 14:12:20 +0530925 msm_pinctrl_data = pctrl = devm_kzalloc(&pdev->dev,
926 sizeof(*pctrl), GFP_KERNEL);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800927 if (!pctrl) {
928 dev_err(&pdev->dev, "Can't allocate msm_pinctrl\n");
929 return -ENOMEM;
930 }
931 pctrl->dev = &pdev->dev;
932 pctrl->soc = soc_data;
933 pctrl->chip = msm_gpio_template;
934
935 spin_lock_init(&pctrl->lock);
936
937 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
938 pctrl->regs = devm_ioremap_resource(&pdev->dev, res);
939 if (IS_ERR(pctrl->regs))
940 return PTR_ERR(pctrl->regs);
941
Pramod Gurav32745582014-08-29 20:00:59 +0530942 msm_pinctrl_setup_pm_reset(pctrl);
943
Bjorn Anderssonf393e482013-12-14 23:01:52 -0800944 pctrl->irq = platform_get_irq(pdev, 0);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800945 if (pctrl->irq < 0) {
946 dev_err(&pdev->dev, "No interrupt defined for msmgpio\n");
947 return pctrl->irq;
948 }
949
950 msm_pinctrl_desc.name = dev_name(&pdev->dev);
951 msm_pinctrl_desc.pins = pctrl->soc->pins;
952 msm_pinctrl_desc.npins = pctrl->soc->npins;
Laxman Dewanganfe0267f2016-02-24 14:44:07 +0530953 pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &msm_pinctrl_desc,
954 pctrl);
Masahiro Yamada323de9e2015-06-09 13:01:16 +0900955 if (IS_ERR(pctrl->pctrl)) {
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800956 dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
Masahiro Yamada323de9e2015-06-09 13:01:16 +0900957 return PTR_ERR(pctrl->pctrl);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800958 }
959
960 ret = msm_gpio_init(pctrl);
Laxman Dewanganfe0267f2016-02-24 14:44:07 +0530961 if (ret)
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800962 return ret;
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800963
964 platform_set_drvdata(pdev, pctrl);
965
Prasad Sodagudid0451852016-07-01 14:12:20 +0530966 register_syscore_ops(&msm_pinctrl_pm_ops);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800967 dev_dbg(&pdev->dev, "Probed Qualcomm pinctrl driver\n");
968
969 return 0;
970}
971EXPORT_SYMBOL(msm_pinctrl_probe);
972
973int msm_pinctrl_remove(struct platform_device *pdev)
974{
975 struct msm_pinctrl *pctrl = platform_get_drvdata(pdev);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800976
Linus Walleij2fcea6c2014-09-16 15:05:41 -0700977 gpiochip_remove(&pctrl->chip);
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800978
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500979 unregister_restart_handler(&pctrl->restart_nb);
Prasad Sodagudid0451852016-07-01 14:12:20 +0530980 unregister_syscore_ops(&msm_pinctrl_pm_ops);
Josh Cartwrightcf1fc182014-09-23 15:59:53 -0500981
Bjorn Anderssonf365be02013-12-05 18:10:03 -0800982 return 0;
983}
984EXPORT_SYMBOL(msm_pinctrl_remove);
985