Merge branch 'r6040-next'
[linux/fpc-iii.git] / drivers / pinctrl / freescale / pinctrl-imx.c
blobeccb47480e1db12d0212ea54c47b94d4b79d5cc8
1 /*
2 * Core driver for the imx pin controller
4 * Copyright (C) 2012 Freescale Semiconductor, Inc.
5 * Copyright (C) 2012 Linaro Ltd.
7 * Author: Dong Aisheng <dong.aisheng@linaro.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
15 #include <linux/err.h>
16 #include <linux/init.h>
17 #include <linux/io.h>
18 #include <linux/mfd/syscon.h>
19 #include <linux/module.h>
20 #include <linux/of.h>
21 #include <linux/of_device.h>
22 #include <linux/of_address.h>
23 #include <linux/pinctrl/machine.h>
24 #include <linux/pinctrl/pinconf.h>
25 #include <linux/pinctrl/pinctrl.h>
26 #include <linux/pinctrl/pinmux.h>
27 #include <linux/slab.h>
28 #include <linux/regmap.h>
30 #include "../core.h"
31 #include "pinctrl-imx.h"
33 /* The bits in CONFIG cell defined in binding doc*/
34 #define IMX_NO_PAD_CTL 0x80000000 /* no pin config need */
35 #define IMX_PAD_SION 0x40000000 /* set SION */
37 /**
38 * @dev: a pointer back to containing device
39 * @base: the offset to the controller in virtual memory
41 struct imx_pinctrl {
42 struct device *dev;
43 struct pinctrl_dev *pctl;
44 void __iomem *base;
45 void __iomem *input_sel_base;
46 const struct imx_pinctrl_soc_info *info;
49 static const inline struct imx_pin_group *imx_pinctrl_find_group_by_name(
50 const struct imx_pinctrl_soc_info *info,
51 const char *name)
53 const struct imx_pin_group *grp = NULL;
54 int i;
56 for (i = 0; i < info->ngroups; i++) {
57 if (!strcmp(info->groups[i].name, name)) {
58 grp = &info->groups[i];
59 break;
63 return grp;
66 static int imx_get_groups_count(struct pinctrl_dev *pctldev)
68 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
69 const struct imx_pinctrl_soc_info *info = ipctl->info;
71 return info->ngroups;
74 static const char *imx_get_group_name(struct pinctrl_dev *pctldev,
75 unsigned selector)
77 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
78 const struct imx_pinctrl_soc_info *info = ipctl->info;
80 return info->groups[selector].name;
83 static int imx_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
84 const unsigned **pins,
85 unsigned *npins)
87 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
88 const struct imx_pinctrl_soc_info *info = ipctl->info;
90 if (selector >= info->ngroups)
91 return -EINVAL;
93 *pins = info->groups[selector].pin_ids;
94 *npins = info->groups[selector].npins;
96 return 0;
99 static void imx_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
100 unsigned offset)
102 seq_printf(s, "%s", dev_name(pctldev->dev));
105 static int imx_dt_node_to_map(struct pinctrl_dev *pctldev,
106 struct device_node *np,
107 struct pinctrl_map **map, unsigned *num_maps)
109 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
110 const struct imx_pinctrl_soc_info *info = ipctl->info;
111 const struct imx_pin_group *grp;
112 struct pinctrl_map *new_map;
113 struct device_node *parent;
114 int map_num = 1;
115 int i, j;
118 * first find the group of this node and check if we need create
119 * config maps for pins
121 grp = imx_pinctrl_find_group_by_name(info, np->name);
122 if (!grp) {
123 dev_err(info->dev, "unable to find group for node %s\n",
124 np->name);
125 return -EINVAL;
128 for (i = 0; i < grp->npins; i++) {
129 if (!(grp->pins[i].config & IMX_NO_PAD_CTL))
130 map_num++;
133 new_map = kmalloc(sizeof(struct pinctrl_map) * map_num, GFP_KERNEL);
134 if (!new_map)
135 return -ENOMEM;
137 *map = new_map;
138 *num_maps = map_num;
140 /* create mux map */
141 parent = of_get_parent(np);
142 if (!parent) {
143 kfree(new_map);
144 return -EINVAL;
146 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
147 new_map[0].data.mux.function = parent->name;
148 new_map[0].data.mux.group = np->name;
149 of_node_put(parent);
151 /* create config map */
152 new_map++;
153 for (i = j = 0; i < grp->npins; i++) {
154 if (!(grp->pins[i].config & IMX_NO_PAD_CTL)) {
155 new_map[j].type = PIN_MAP_TYPE_CONFIGS_PIN;
156 new_map[j].data.configs.group_or_pin =
157 pin_get_name(pctldev, grp->pins[i].pin);
158 new_map[j].data.configs.configs = &grp->pins[i].config;
159 new_map[j].data.configs.num_configs = 1;
160 j++;
164 dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n",
165 (*map)->data.mux.function, (*map)->data.mux.group, map_num);
167 return 0;
170 static void imx_dt_free_map(struct pinctrl_dev *pctldev,
171 struct pinctrl_map *map, unsigned num_maps)
173 kfree(map);
176 static const struct pinctrl_ops imx_pctrl_ops = {
177 .get_groups_count = imx_get_groups_count,
178 .get_group_name = imx_get_group_name,
179 .get_group_pins = imx_get_group_pins,
180 .pin_dbg_show = imx_pin_dbg_show,
181 .dt_node_to_map = imx_dt_node_to_map,
182 .dt_free_map = imx_dt_free_map,
186 static int imx_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
187 unsigned group)
189 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
190 const struct imx_pinctrl_soc_info *info = ipctl->info;
191 const struct imx_pin_reg *pin_reg;
192 unsigned int npins, pin_id;
193 int i;
194 struct imx_pin_group *grp;
197 * Configure the mux mode for each pin in the group for a specific
198 * function.
200 grp = &info->groups[group];
201 npins = grp->npins;
203 dev_dbg(ipctl->dev, "enable function %s group %s\n",
204 info->functions[selector].name, grp->name);
206 for (i = 0; i < npins; i++) {
207 struct imx_pin *pin = &grp->pins[i];
208 pin_id = pin->pin;
209 pin_reg = &info->pin_regs[pin_id];
211 if (pin_reg->mux_reg == -1) {
212 dev_dbg(ipctl->dev, "Pin(%s) does not support mux function\n",
213 info->pins[pin_id].name);
214 continue;
217 if (info->flags & SHARE_MUX_CONF_REG) {
218 u32 reg;
219 reg = readl(ipctl->base + pin_reg->mux_reg);
220 reg &= ~(0x7 << 20);
221 reg |= (pin->mux_mode << 20);
222 writel(reg, ipctl->base + pin_reg->mux_reg);
223 } else {
224 writel(pin->mux_mode, ipctl->base + pin_reg->mux_reg);
226 dev_dbg(ipctl->dev, "write: offset 0x%x val 0x%x\n",
227 pin_reg->mux_reg, pin->mux_mode);
230 * If the select input value begins with 0xff, it's a quirky
231 * select input and the value should be interpreted as below.
232 * 31 23 15 7 0
233 * | 0xff | shift | width | select |
234 * It's used to work around the problem that the select
235 * input for some pin is not implemented in the select
236 * input register but in some general purpose register.
237 * We encode the select input value, width and shift of
238 * the bit field into input_val cell of pin function ID
239 * in device tree, and then decode them here for setting
240 * up the select input bits in general purpose register.
242 if (pin->input_val >> 24 == 0xff) {
243 u32 val = pin->input_val;
244 u8 select = val & 0xff;
245 u8 width = (val >> 8) & 0xff;
246 u8 shift = (val >> 16) & 0xff;
247 u32 mask = ((1 << width) - 1) << shift;
249 * The input_reg[i] here is actually some IOMUXC general
250 * purpose register, not regular select input register.
252 val = readl(ipctl->base + pin->input_reg);
253 val &= ~mask;
254 val |= select << shift;
255 writel(val, ipctl->base + pin->input_reg);
256 } else if (pin->input_reg) {
258 * Regular select input register can never be at offset
259 * 0, and we only print register value for regular case.
261 if (ipctl->input_sel_base)
262 writel(pin->input_val, ipctl->input_sel_base +
263 pin->input_reg);
264 else
265 writel(pin->input_val, ipctl->base +
266 pin->input_reg);
267 dev_dbg(ipctl->dev,
268 "==>select_input: offset 0x%x val 0x%x\n",
269 pin->input_reg, pin->input_val);
273 return 0;
276 static int imx_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
278 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
279 const struct imx_pinctrl_soc_info *info = ipctl->info;
281 return info->nfunctions;
284 static const char *imx_pmx_get_func_name(struct pinctrl_dev *pctldev,
285 unsigned selector)
287 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
288 const struct imx_pinctrl_soc_info *info = ipctl->info;
290 return info->functions[selector].name;
293 static int imx_pmx_get_groups(struct pinctrl_dev *pctldev, unsigned selector,
294 const char * const **groups,
295 unsigned * const num_groups)
297 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
298 const struct imx_pinctrl_soc_info *info = ipctl->info;
300 *groups = info->functions[selector].groups;
301 *num_groups = info->functions[selector].num_groups;
303 return 0;
306 static int imx_pmx_gpio_request_enable(struct pinctrl_dev *pctldev,
307 struct pinctrl_gpio_range *range, unsigned offset)
309 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
310 const struct imx_pinctrl_soc_info *info = ipctl->info;
311 const struct imx_pin_reg *pin_reg;
312 struct imx_pin_group *grp;
313 struct imx_pin *imx_pin;
314 unsigned int pin, group;
315 u32 reg;
317 /* Currently implementation only for shared mux/conf register */
318 if (!(info->flags & SHARE_MUX_CONF_REG))
319 return -EINVAL;
321 pin_reg = &info->pin_regs[offset];
322 if (pin_reg->mux_reg == -1)
323 return -EINVAL;
325 /* Find the pinctrl config with GPIO mux mode for the requested pin */
326 for (group = 0; group < info->ngroups; group++) {
327 grp = &info->groups[group];
328 for (pin = 0; pin < grp->npins; pin++) {
329 imx_pin = &grp->pins[pin];
330 if (imx_pin->pin == offset && !imx_pin->mux_mode)
331 goto mux_pin;
335 return -EINVAL;
337 mux_pin:
338 reg = readl(ipctl->base + pin_reg->mux_reg);
339 reg &= ~(0x7 << 20);
340 reg |= imx_pin->config;
341 writel(reg, ipctl->base + pin_reg->mux_reg);
343 return 0;
346 static void imx_pmx_gpio_disable_free(struct pinctrl_dev *pctldev,
347 struct pinctrl_gpio_range *range, unsigned offset)
349 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
350 const struct imx_pinctrl_soc_info *info = ipctl->info;
351 const struct imx_pin_reg *pin_reg;
352 u32 reg;
355 * Only Vybrid has the input/output buffer enable flags (IBE/OBE)
356 * They are part of the shared mux/conf register.
358 if (!(info->flags & SHARE_MUX_CONF_REG))
359 return;
361 pin_reg = &info->pin_regs[offset];
362 if (pin_reg->mux_reg == -1)
363 return;
365 /* Clear IBE/OBE/PUE to disable the pin (Hi-Z) */
366 reg = readl(ipctl->base + pin_reg->mux_reg);
367 reg &= ~0x7;
368 writel(reg, ipctl->base + pin_reg->mux_reg);
371 static int imx_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
372 struct pinctrl_gpio_range *range, unsigned offset, bool input)
374 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
375 const struct imx_pinctrl_soc_info *info = ipctl->info;
376 const struct imx_pin_reg *pin_reg;
377 u32 reg;
380 * Only Vybrid has the input/output buffer enable flags (IBE/OBE)
381 * They are part of the shared mux/conf register.
383 if (!(info->flags & SHARE_MUX_CONF_REG))
384 return -EINVAL;
386 pin_reg = &info->pin_regs[offset];
387 if (pin_reg->mux_reg == -1)
388 return -EINVAL;
390 /* IBE always enabled allows us to read the value "on the wire" */
391 reg = readl(ipctl->base + pin_reg->mux_reg);
392 if (input)
393 reg &= ~0x2;
394 else
395 reg |= 0x2;
396 writel(reg, ipctl->base + pin_reg->mux_reg);
398 return 0;
401 static const struct pinmux_ops imx_pmx_ops = {
402 .get_functions_count = imx_pmx_get_funcs_count,
403 .get_function_name = imx_pmx_get_func_name,
404 .get_function_groups = imx_pmx_get_groups,
405 .set_mux = imx_pmx_set,
406 .gpio_request_enable = imx_pmx_gpio_request_enable,
407 .gpio_disable_free = imx_pmx_gpio_disable_free,
408 .gpio_set_direction = imx_pmx_gpio_set_direction,
411 static int imx_pinconf_get(struct pinctrl_dev *pctldev,
412 unsigned pin_id, unsigned long *config)
414 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
415 const struct imx_pinctrl_soc_info *info = ipctl->info;
416 const struct imx_pin_reg *pin_reg = &info->pin_regs[pin_id];
418 if (pin_reg->conf_reg == -1) {
419 dev_err(info->dev, "Pin(%s) does not support config function\n",
420 info->pins[pin_id].name);
421 return -EINVAL;
424 *config = readl(ipctl->base + pin_reg->conf_reg);
426 if (info->flags & SHARE_MUX_CONF_REG)
427 *config &= 0xffff;
429 return 0;
432 static int imx_pinconf_set(struct pinctrl_dev *pctldev,
433 unsigned pin_id, unsigned long *configs,
434 unsigned num_configs)
436 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
437 const struct imx_pinctrl_soc_info *info = ipctl->info;
438 const struct imx_pin_reg *pin_reg = &info->pin_regs[pin_id];
439 int i;
441 if (pin_reg->conf_reg == -1) {
442 dev_err(info->dev, "Pin(%s) does not support config function\n",
443 info->pins[pin_id].name);
444 return -EINVAL;
447 dev_dbg(ipctl->dev, "pinconf set pin %s\n",
448 info->pins[pin_id].name);
450 for (i = 0; i < num_configs; i++) {
451 if (info->flags & SHARE_MUX_CONF_REG) {
452 u32 reg;
453 reg = readl(ipctl->base + pin_reg->conf_reg);
454 reg &= ~0xffff;
455 reg |= configs[i];
456 writel(reg, ipctl->base + pin_reg->conf_reg);
457 } else {
458 writel(configs[i], ipctl->base + pin_reg->conf_reg);
460 dev_dbg(ipctl->dev, "write: offset 0x%x val 0x%lx\n",
461 pin_reg->conf_reg, configs[i]);
462 } /* for each config */
464 return 0;
467 static void imx_pinconf_dbg_show(struct pinctrl_dev *pctldev,
468 struct seq_file *s, unsigned pin_id)
470 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
471 const struct imx_pinctrl_soc_info *info = ipctl->info;
472 const struct imx_pin_reg *pin_reg = &info->pin_regs[pin_id];
473 unsigned long config;
475 if (!pin_reg || pin_reg->conf_reg == -1) {
476 seq_printf(s, "N/A");
477 return;
480 config = readl(ipctl->base + pin_reg->conf_reg);
481 seq_printf(s, "0x%lx", config);
484 static void imx_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
485 struct seq_file *s, unsigned group)
487 struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
488 const struct imx_pinctrl_soc_info *info = ipctl->info;
489 struct imx_pin_group *grp;
490 unsigned long config;
491 const char *name;
492 int i, ret;
494 if (group > info->ngroups)
495 return;
497 seq_printf(s, "\n");
498 grp = &info->groups[group];
499 for (i = 0; i < grp->npins; i++) {
500 struct imx_pin *pin = &grp->pins[i];
501 name = pin_get_name(pctldev, pin->pin);
502 ret = imx_pinconf_get(pctldev, pin->pin, &config);
503 if (ret)
504 return;
505 seq_printf(s, "%s: 0x%lx", name, config);
509 static const struct pinconf_ops imx_pinconf_ops = {
510 .pin_config_get = imx_pinconf_get,
511 .pin_config_set = imx_pinconf_set,
512 .pin_config_dbg_show = imx_pinconf_dbg_show,
513 .pin_config_group_dbg_show = imx_pinconf_group_dbg_show,
516 static struct pinctrl_desc imx_pinctrl_desc = {
517 .pctlops = &imx_pctrl_ops,
518 .pmxops = &imx_pmx_ops,
519 .confops = &imx_pinconf_ops,
520 .owner = THIS_MODULE,
524 * Each pin represented in fsl,pins consists of 5 u32 PIN_FUNC_ID and
525 * 1 u32 CONFIG, so 24 types in total for each pin.
527 #define FSL_PIN_SIZE 24
528 #define SHARE_FSL_PIN_SIZE 20
530 static int imx_pinctrl_parse_groups(struct device_node *np,
531 struct imx_pin_group *grp,
532 struct imx_pinctrl_soc_info *info,
533 u32 index)
535 int size, pin_size;
536 const __be32 *list;
537 int i;
538 u32 config;
540 dev_dbg(info->dev, "group(%d): %s\n", index, np->name);
542 if (info->flags & SHARE_MUX_CONF_REG)
543 pin_size = SHARE_FSL_PIN_SIZE;
544 else
545 pin_size = FSL_PIN_SIZE;
546 /* Initialise group */
547 grp->name = np->name;
550 * the binding format is fsl,pins = <PIN_FUNC_ID CONFIG ...>,
551 * do sanity check and calculate pins number
553 list = of_get_property(np, "fsl,pins", &size);
554 if (!list) {
555 dev_err(info->dev, "no fsl,pins property in node %s\n", np->full_name);
556 return -EINVAL;
559 /* we do not check return since it's safe node passed down */
560 if (!size || size % pin_size) {
561 dev_err(info->dev, "Invalid fsl,pins property in node %s\n", np->full_name);
562 return -EINVAL;
565 grp->npins = size / pin_size;
566 grp->pins = devm_kzalloc(info->dev, grp->npins * sizeof(struct imx_pin),
567 GFP_KERNEL);
568 grp->pin_ids = devm_kzalloc(info->dev, grp->npins * sizeof(unsigned int),
569 GFP_KERNEL);
570 if (!grp->pins || ! grp->pin_ids)
571 return -ENOMEM;
573 for (i = 0; i < grp->npins; i++) {
574 u32 mux_reg = be32_to_cpu(*list++);
575 u32 conf_reg;
576 unsigned int pin_id;
577 struct imx_pin_reg *pin_reg;
578 struct imx_pin *pin = &grp->pins[i];
580 if (!(info->flags & ZERO_OFFSET_VALID) && !mux_reg)
581 mux_reg = -1;
583 if (info->flags & SHARE_MUX_CONF_REG) {
584 conf_reg = mux_reg;
585 } else {
586 conf_reg = be32_to_cpu(*list++);
587 if (!conf_reg)
588 conf_reg = -1;
591 pin_id = (mux_reg != -1) ? mux_reg / 4 : conf_reg / 4;
592 pin_reg = &info->pin_regs[pin_id];
593 pin->pin = pin_id;
594 grp->pin_ids[i] = pin_id;
595 pin_reg->mux_reg = mux_reg;
596 pin_reg->conf_reg = conf_reg;
597 pin->input_reg = be32_to_cpu(*list++);
598 pin->mux_mode = be32_to_cpu(*list++);
599 pin->input_val = be32_to_cpu(*list++);
601 /* SION bit is in mux register */
602 config = be32_to_cpu(*list++);
603 if (config & IMX_PAD_SION)
604 pin->mux_mode |= IOMUXC_CONFIG_SION;
605 pin->config = config & ~IMX_PAD_SION;
607 dev_dbg(info->dev, "%s: 0x%x 0x%08lx", info->pins[pin_id].name,
608 pin->mux_mode, pin->config);
611 return 0;
614 static int imx_pinctrl_parse_functions(struct device_node *np,
615 struct imx_pinctrl_soc_info *info,
616 u32 index)
618 struct device_node *child;
619 struct imx_pmx_func *func;
620 struct imx_pin_group *grp;
621 u32 i = 0;
623 dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name);
625 func = &info->functions[index];
627 /* Initialise function */
628 func->name = np->name;
629 func->num_groups = of_get_child_count(np);
630 if (func->num_groups == 0) {
631 dev_err(info->dev, "no groups defined in %s\n", np->full_name);
632 return -EINVAL;
634 func->groups = devm_kzalloc(info->dev,
635 func->num_groups * sizeof(char *), GFP_KERNEL);
637 for_each_child_of_node(np, child) {
638 func->groups[i] = child->name;
639 grp = &info->groups[info->group_index++];
640 imx_pinctrl_parse_groups(child, grp, info, i++);
643 return 0;
647 * Check if the DT contains pins in the direct child nodes. This indicates the
648 * newer DT format to store pins. This function returns true if the first found
649 * fsl,pins property is in a child of np. Otherwise false is returned.
651 static bool imx_pinctrl_dt_is_flat_functions(struct device_node *np)
653 struct device_node *function_np;
654 struct device_node *pinctrl_np;
656 for_each_child_of_node(np, function_np) {
657 if (of_property_read_bool(function_np, "fsl,pins"))
658 return true;
660 for_each_child_of_node(function_np, pinctrl_np) {
661 if (of_property_read_bool(pinctrl_np, "fsl,pins"))
662 return false;
666 return true;
669 static int imx_pinctrl_probe_dt(struct platform_device *pdev,
670 struct imx_pinctrl_soc_info *info)
672 struct device_node *np = pdev->dev.of_node;
673 struct device_node *child;
674 u32 nfuncs = 0;
675 u32 i = 0;
676 bool flat_funcs;
678 if (!np)
679 return -ENODEV;
681 flat_funcs = imx_pinctrl_dt_is_flat_functions(np);
682 if (flat_funcs) {
683 nfuncs = 1;
684 } else {
685 nfuncs = of_get_child_count(np);
686 if (nfuncs <= 0) {
687 dev_err(&pdev->dev, "no functions defined\n");
688 return -EINVAL;
692 info->nfunctions = nfuncs;
693 info->functions = devm_kzalloc(&pdev->dev, nfuncs * sizeof(struct imx_pmx_func),
694 GFP_KERNEL);
695 if (!info->functions)
696 return -ENOMEM;
698 if (flat_funcs) {
699 info->ngroups = of_get_child_count(np);
700 } else {
701 info->ngroups = 0;
702 for_each_child_of_node(np, child)
703 info->ngroups += of_get_child_count(child);
705 info->groups = devm_kzalloc(&pdev->dev, info->ngroups * sizeof(struct imx_pin_group),
706 GFP_KERNEL);
707 if (!info->groups)
708 return -ENOMEM;
710 if (flat_funcs) {
711 imx_pinctrl_parse_functions(np, info, 0);
712 } else {
713 for_each_child_of_node(np, child)
714 imx_pinctrl_parse_functions(child, info, i++);
717 return 0;
720 int imx_pinctrl_probe(struct platform_device *pdev,
721 struct imx_pinctrl_soc_info *info)
723 struct regmap_config config = { .name = "gpr" };
724 struct device_node *dev_np = pdev->dev.of_node;
725 struct device_node *np;
726 struct imx_pinctrl *ipctl;
727 struct resource *res;
728 struct regmap *gpr;
729 int ret, i;
731 if (!info || !info->pins || !info->npins) {
732 dev_err(&pdev->dev, "wrong pinctrl info\n");
733 return -EINVAL;
735 info->dev = &pdev->dev;
737 if (info->gpr_compatible) {
738 gpr = syscon_regmap_lookup_by_compatible(info->gpr_compatible);
739 if (!IS_ERR(gpr))
740 regmap_attach_dev(&pdev->dev, gpr, &config);
743 /* Create state holders etc for this driver */
744 ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL);
745 if (!ipctl)
746 return -ENOMEM;
748 info->pin_regs = devm_kmalloc(&pdev->dev, sizeof(*info->pin_regs) *
749 info->npins, GFP_KERNEL);
750 if (!info->pin_regs)
751 return -ENOMEM;
753 for (i = 0; i < info->npins; i++) {
754 info->pin_regs[i].mux_reg = -1;
755 info->pin_regs[i].conf_reg = -1;
758 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
759 ipctl->base = devm_ioremap_resource(&pdev->dev, res);
760 if (IS_ERR(ipctl->base))
761 return PTR_ERR(ipctl->base);
763 if (of_property_read_bool(dev_np, "fsl,input-sel")) {
764 np = of_parse_phandle(dev_np, "fsl,input-sel", 0);
765 if (!np) {
766 dev_err(&pdev->dev, "iomuxc fsl,input-sel property not found\n");
767 return -EINVAL;
770 ipctl->input_sel_base = of_iomap(np, 0);
771 of_node_put(np);
772 if (!ipctl->input_sel_base) {
773 dev_err(&pdev->dev,
774 "iomuxc input select base address not found\n");
775 return -ENOMEM;
779 imx_pinctrl_desc.name = dev_name(&pdev->dev);
780 imx_pinctrl_desc.pins = info->pins;
781 imx_pinctrl_desc.npins = info->npins;
783 ret = imx_pinctrl_probe_dt(pdev, info);
784 if (ret) {
785 dev_err(&pdev->dev, "fail to probe dt properties\n");
786 return ret;
789 ipctl->info = info;
790 ipctl->dev = info->dev;
791 platform_set_drvdata(pdev, ipctl);
792 ipctl->pctl = devm_pinctrl_register(&pdev->dev, &imx_pinctrl_desc, ipctl);
793 if (IS_ERR(ipctl->pctl)) {
794 dev_err(&pdev->dev, "could not register IMX pinctrl driver\n");
795 return PTR_ERR(ipctl->pctl);
798 dev_info(&pdev->dev, "initialized IMX pinctrl driver\n");
800 return 0;