1 // SPDX-License-Identifier: GPL-2.0+
3 // Core driver for the imx pin controller
5 // Copyright (C) 2012 Freescale Semiconductor, Inc.
6 // Copyright (C) 2012 Linaro Ltd.
8 // Author: Dong Aisheng <dong.aisheng@linaro.org>
10 #include <linux/err.h>
11 #include <linux/init.h>
13 #include <linux/mfd/syscon.h>
15 #include <linux/of_device.h>
16 #include <linux/of_address.h>
17 #include <linux/pinctrl/machine.h>
18 #include <linux/pinctrl/pinconf.h>
19 #include <linux/pinctrl/pinctrl.h>
20 #include <linux/pinctrl/pinmux.h>
21 #include <linux/slab.h>
22 #include <linux/regmap.h>
25 #include "../pinconf.h"
26 #include "../pinmux.h"
27 #include "pinctrl-imx.h"
29 /* The bits in CONFIG cell defined in binding doc*/
30 #define IMX_NO_PAD_CTL 0x80000000 /* no pin config need */
31 #define IMX_PAD_SION 0x40000000 /* set SION */
33 static inline const struct group_desc
*imx_pinctrl_find_group_by_name(
34 struct pinctrl_dev
*pctldev
,
37 const struct group_desc
*grp
= NULL
;
40 for (i
= 0; i
< pctldev
->num_groups
; i
++) {
41 grp
= pinctrl_generic_get_group(pctldev
, i
);
42 if (grp
&& !strcmp(grp
->name
, name
))
49 static void imx_pin_dbg_show(struct pinctrl_dev
*pctldev
, struct seq_file
*s
,
52 seq_printf(s
, "%s", dev_name(pctldev
->dev
));
55 static int imx_dt_node_to_map(struct pinctrl_dev
*pctldev
,
56 struct device_node
*np
,
57 struct pinctrl_map
**map
, unsigned *num_maps
)
59 struct imx_pinctrl
*ipctl
= pinctrl_dev_get_drvdata(pctldev
);
60 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
61 const struct group_desc
*grp
;
62 struct pinctrl_map
*new_map
;
63 struct device_node
*parent
;
69 * first find the group of this node and check if we need create
70 * config maps for pins
72 grp
= imx_pinctrl_find_group_by_name(pctldev
, np
->name
);
74 dev_err(ipctl
->dev
, "unable to find group for node %pOFn\n", np
);
78 if (info
->flags
& IMX_USE_SCU
) {
79 map_num
+= grp
->num_pins
;
81 for (i
= 0; i
< grp
->num_pins
; i
++) {
82 pin
= &((struct imx_pin
*)(grp
->data
))[i
];
83 if (!(pin
->conf
.mmio
.config
& IMX_NO_PAD_CTL
))
88 new_map
= kmalloc_array(map_num
, sizeof(struct pinctrl_map
),
97 parent
= of_get_parent(np
);
102 new_map
[0].type
= PIN_MAP_TYPE_MUX_GROUP
;
103 new_map
[0].data
.mux
.function
= parent
->name
;
104 new_map
[0].data
.mux
.group
= np
->name
;
107 /* create config map */
109 for (i
= j
= 0; i
< grp
->num_pins
; i
++) {
110 pin
= &((struct imx_pin
*)(grp
->data
))[i
];
113 * We only create config maps for SCU pads or MMIO pads that
114 * are not using the default config(a.k.a IMX_NO_PAD_CTL)
116 if (!(info
->flags
& IMX_USE_SCU
) &&
117 (pin
->conf
.mmio
.config
& IMX_NO_PAD_CTL
))
120 new_map
[j
].type
= PIN_MAP_TYPE_CONFIGS_PIN
;
121 new_map
[j
].data
.configs
.group_or_pin
=
122 pin_get_name(pctldev
, pin
->pin
);
124 if (info
->flags
& IMX_USE_SCU
) {
126 * For SCU case, we set mux and conf together
129 new_map
[j
].data
.configs
.configs
=
130 (unsigned long *)&pin
->conf
.scu
;
131 new_map
[j
].data
.configs
.num_configs
= 2;
133 new_map
[j
].data
.configs
.configs
=
134 &pin
->conf
.mmio
.config
;
135 new_map
[j
].data
.configs
.num_configs
= 1;
141 dev_dbg(pctldev
->dev
, "maps: function %s group %s num %d\n",
142 (*map
)->data
.mux
.function
, (*map
)->data
.mux
.group
, map_num
);
147 static void imx_dt_free_map(struct pinctrl_dev
*pctldev
,
148 struct pinctrl_map
*map
, unsigned num_maps
)
153 static const struct pinctrl_ops imx_pctrl_ops
= {
154 .get_groups_count
= pinctrl_generic_get_group_count
,
155 .get_group_name
= pinctrl_generic_get_group_name
,
156 .get_group_pins
= pinctrl_generic_get_group_pins
,
157 .pin_dbg_show
= imx_pin_dbg_show
,
158 .dt_node_to_map
= imx_dt_node_to_map
,
159 .dt_free_map
= imx_dt_free_map
,
162 static int imx_pmx_set_one_pin_mmio(struct imx_pinctrl
*ipctl
,
165 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
166 struct imx_pin_mmio
*pin_mmio
= &pin
->conf
.mmio
;
167 const struct imx_pin_reg
*pin_reg
;
171 pin_reg
= &ipctl
->pin_regs
[pin_id
];
173 if (pin_reg
->mux_reg
== -1) {
174 dev_dbg(ipctl
->dev
, "Pin(%s) does not support mux function\n",
175 info
->pins
[pin_id
].name
);
179 if (info
->flags
& SHARE_MUX_CONF_REG
) {
182 reg
= readl(ipctl
->base
+ pin_reg
->mux_reg
);
183 reg
&= ~info
->mux_mask
;
184 reg
|= (pin_mmio
->mux_mode
<< info
->mux_shift
);
185 writel(reg
, ipctl
->base
+ pin_reg
->mux_reg
);
186 dev_dbg(ipctl
->dev
, "write: offset 0x%x val 0x%x\n",
187 pin_reg
->mux_reg
, reg
);
189 writel(pin_mmio
->mux_mode
, ipctl
->base
+ pin_reg
->mux_reg
);
190 dev_dbg(ipctl
->dev
, "write: offset 0x%x val 0x%x\n",
191 pin_reg
->mux_reg
, pin_mmio
->mux_mode
);
195 * If the select input value begins with 0xff, it's a quirky
196 * select input and the value should be interpreted as below.
198 * | 0xff | shift | width | select |
199 * It's used to work around the problem that the select
200 * input for some pin is not implemented in the select
201 * input register but in some general purpose register.
202 * We encode the select input value, width and shift of
203 * the bit field into input_val cell of pin function ID
204 * in device tree, and then decode them here for setting
205 * up the select input bits in general purpose register.
207 if (pin_mmio
->input_val
>> 24 == 0xff) {
208 u32 val
= pin_mmio
->input_val
;
209 u8 select
= val
& 0xff;
210 u8 width
= (val
>> 8) & 0xff;
211 u8 shift
= (val
>> 16) & 0xff;
212 u32 mask
= ((1 << width
) - 1) << shift
;
214 * The input_reg[i] here is actually some IOMUXC general
215 * purpose register, not regular select input register.
217 val
= readl(ipctl
->base
+ pin_mmio
->input_reg
);
219 val
|= select
<< shift
;
220 writel(val
, ipctl
->base
+ pin_mmio
->input_reg
);
221 } else if (pin_mmio
->input_reg
) {
223 * Regular select input register can never be at offset
224 * 0, and we only print register value for regular case.
226 if (ipctl
->input_sel_base
)
227 writel(pin_mmio
->input_val
, ipctl
->input_sel_base
+
228 pin_mmio
->input_reg
);
230 writel(pin_mmio
->input_val
, ipctl
->base
+
231 pin_mmio
->input_reg
);
233 "==>select_input: offset 0x%x val 0x%x\n",
234 pin_mmio
->input_reg
, pin_mmio
->input_val
);
240 static int imx_pmx_set(struct pinctrl_dev
*pctldev
, unsigned selector
,
243 struct imx_pinctrl
*ipctl
= pinctrl_dev_get_drvdata(pctldev
);
244 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
245 struct function_desc
*func
;
246 struct group_desc
*grp
;
252 * Configure the mux mode for each pin in the group for a specific
255 grp
= pinctrl_generic_get_group(pctldev
, group
);
259 func
= pinmux_generic_get_function(pctldev
, selector
);
263 npins
= grp
->num_pins
;
265 dev_dbg(ipctl
->dev
, "enable function %s group %s\n",
266 func
->name
, grp
->name
);
268 for (i
= 0; i
< npins
; i
++) {
270 * For IMX_USE_SCU case, we postpone the mux setting
271 * until config is set as we can set them together
274 pin
= &((struct imx_pin
*)(grp
->data
))[i
];
275 if (!(info
->flags
& IMX_USE_SCU
)) {
276 err
= imx_pmx_set_one_pin_mmio(ipctl
, pin
);
285 struct pinmux_ops imx_pmx_ops
= {
286 .get_functions_count
= pinmux_generic_get_function_count
,
287 .get_function_name
= pinmux_generic_get_function_name
,
288 .get_function_groups
= pinmux_generic_get_function_groups
,
289 .set_mux
= imx_pmx_set
,
292 /* decode generic config into raw register values */
293 static u32
imx_pinconf_decode_generic_config(struct imx_pinctrl
*ipctl
,
294 unsigned long *configs
,
295 unsigned int num_configs
)
297 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
298 const struct imx_cfg_params_decode
*decode
;
299 enum pin_config_param param
;
304 WARN_ON(num_configs
> info
->num_decodes
);
306 for (i
= 0; i
< num_configs
; i
++) {
307 param
= pinconf_to_config_param(configs
[i
]);
308 param_val
= pinconf_to_config_argument(configs
[i
]);
309 decode
= info
->decodes
;
310 for (j
= 0; j
< info
->num_decodes
; j
++) {
311 if (param
== decode
->param
) {
313 param_val
= !param_val
;
314 raw_config
|= (param_val
<< decode
->shift
)
323 info
->fixup(configs
, num_configs
, &raw_config
);
328 static u32
imx_pinconf_parse_generic_config(struct device_node
*np
,
329 struct imx_pinctrl
*ipctl
)
331 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
332 struct pinctrl_dev
*pctl
= ipctl
->pctl
;
333 unsigned int num_configs
;
334 unsigned long *configs
;
337 if (!info
->generic_pinconf
)
340 ret
= pinconf_generic_parse_dt_config(np
, pctl
, &configs
,
345 return imx_pinconf_decode_generic_config(ipctl
, configs
, num_configs
);
348 static int imx_pinconf_get_mmio(struct pinctrl_dev
*pctldev
, unsigned pin_id
,
349 unsigned long *config
)
351 struct imx_pinctrl
*ipctl
= pinctrl_dev_get_drvdata(pctldev
);
352 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
353 const struct imx_pin_reg
*pin_reg
= &ipctl
->pin_regs
[pin_id
];
355 if (pin_reg
->conf_reg
== -1) {
356 dev_err(ipctl
->dev
, "Pin(%s) does not support config function\n",
357 info
->pins
[pin_id
].name
);
361 *config
= readl(ipctl
->base
+ pin_reg
->conf_reg
);
363 if (info
->flags
& SHARE_MUX_CONF_REG
)
364 *config
&= ~info
->mux_mask
;
369 static int imx_pinconf_get(struct pinctrl_dev
*pctldev
,
370 unsigned pin_id
, unsigned long *config
)
372 struct imx_pinctrl
*ipctl
= pinctrl_dev_get_drvdata(pctldev
);
373 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
375 if (info
->flags
& IMX_USE_SCU
)
376 return imx_pinconf_get_scu(pctldev
, pin_id
, config
);
378 return imx_pinconf_get_mmio(pctldev
, pin_id
, config
);
381 static int imx_pinconf_set_mmio(struct pinctrl_dev
*pctldev
,
382 unsigned pin_id
, unsigned long *configs
,
383 unsigned num_configs
)
385 struct imx_pinctrl
*ipctl
= pinctrl_dev_get_drvdata(pctldev
);
386 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
387 const struct imx_pin_reg
*pin_reg
= &ipctl
->pin_regs
[pin_id
];
390 if (pin_reg
->conf_reg
== -1) {
391 dev_err(ipctl
->dev
, "Pin(%s) does not support config function\n",
392 info
->pins
[pin_id
].name
);
396 dev_dbg(ipctl
->dev
, "pinconf set pin %s\n",
397 info
->pins
[pin_id
].name
);
399 for (i
= 0; i
< num_configs
; i
++) {
400 if (info
->flags
& SHARE_MUX_CONF_REG
) {
402 reg
= readl(ipctl
->base
+ pin_reg
->conf_reg
);
403 reg
&= info
->mux_mask
;
405 writel(reg
, ipctl
->base
+ pin_reg
->conf_reg
);
406 dev_dbg(ipctl
->dev
, "write: offset 0x%x val 0x%x\n",
407 pin_reg
->conf_reg
, reg
);
409 writel(configs
[i
], ipctl
->base
+ pin_reg
->conf_reg
);
410 dev_dbg(ipctl
->dev
, "write: offset 0x%x val 0x%lx\n",
411 pin_reg
->conf_reg
, configs
[i
]);
413 } /* for each config */
418 static int imx_pinconf_set(struct pinctrl_dev
*pctldev
,
419 unsigned pin_id
, unsigned long *configs
,
420 unsigned num_configs
)
422 struct imx_pinctrl
*ipctl
= pinctrl_dev_get_drvdata(pctldev
);
423 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
425 if (info
->flags
& IMX_USE_SCU
)
426 return imx_pinconf_set_scu(pctldev
, pin_id
,
427 configs
, num_configs
);
429 return imx_pinconf_set_mmio(pctldev
, pin_id
,
430 configs
, num_configs
);
433 static void imx_pinconf_dbg_show(struct pinctrl_dev
*pctldev
,
434 struct seq_file
*s
, unsigned pin_id
)
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
;
439 unsigned long config
;
442 if (info
->flags
& IMX_USE_SCU
) {
443 ret
= imx_pinconf_get_scu(pctldev
, pin_id
, &config
);
445 dev_err(ipctl
->dev
, "failed to get %s pinconf\n",
446 pin_get_name(pctldev
, pin_id
));
451 pin_reg
= &ipctl
->pin_regs
[pin_id
];
452 if (pin_reg
->conf_reg
== -1) {
457 config
= readl(ipctl
->base
+ pin_reg
->conf_reg
);
460 seq_printf(s
, "0x%lx", config
);
463 static void imx_pinconf_group_dbg_show(struct pinctrl_dev
*pctldev
,
464 struct seq_file
*s
, unsigned group
)
466 struct group_desc
*grp
;
467 unsigned long config
;
471 if (group
>= pctldev
->num_groups
)
475 grp
= pinctrl_generic_get_group(pctldev
, group
);
479 for (i
= 0; i
< grp
->num_pins
; i
++) {
480 struct imx_pin
*pin
= &((struct imx_pin
*)(grp
->data
))[i
];
482 name
= pin_get_name(pctldev
, pin
->pin
);
483 ret
= imx_pinconf_get(pctldev
, pin
->pin
, &config
);
486 seq_printf(s
, " %s: 0x%lx\n", name
, config
);
490 static const struct pinconf_ops imx_pinconf_ops
= {
491 .pin_config_get
= imx_pinconf_get
,
492 .pin_config_set
= imx_pinconf_set
,
493 .pin_config_dbg_show
= imx_pinconf_dbg_show
,
494 .pin_config_group_dbg_show
= imx_pinconf_group_dbg_show
,
498 * Each pin represented in fsl,pins consists of a number of u32 PIN_FUNC_ID
499 * and 1 u32 CONFIG, the total size is PIN_FUNC_ID + CONFIG for each pin.
500 * For generic_pinconf case, there's no extra u32 CONFIG.
502 * PIN_FUNC_ID format:
504 * <mux_reg conf_reg input_reg mux_mode input_val>
505 * SHARE_MUX_CONF_REG:
506 * <mux_conf_reg input_reg mux_mode input_val>
510 #define FSL_PIN_SIZE 24
511 #define FSL_PIN_SHARE_SIZE 20
512 #define FSL_SCU_PIN_SIZE 12
514 static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl
*ipctl
,
515 unsigned int *pin_id
, struct imx_pin
*pin
,
516 const __be32
**list_p
,
517 struct device_node
*np
)
519 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
520 struct imx_pin_mmio
*pin_mmio
= &pin
->conf
.mmio
;
521 struct imx_pin_reg
*pin_reg
;
522 const __be32
*list
= *list_p
;
523 u32 mux_reg
, conf_reg
;
526 mux_reg
= be32_to_cpu(*list
++);
528 if (!(info
->flags
& ZERO_OFFSET_VALID
) && !mux_reg
)
531 if (info
->flags
& SHARE_MUX_CONF_REG
) {
534 conf_reg
= be32_to_cpu(*list
++);
539 *pin_id
= (mux_reg
!= -1) ? mux_reg
/ 4 : conf_reg
/ 4;
540 pin_reg
= &ipctl
->pin_regs
[*pin_id
];
542 pin_reg
->mux_reg
= mux_reg
;
543 pin_reg
->conf_reg
= conf_reg
;
544 pin_mmio
->input_reg
= be32_to_cpu(*list
++);
545 pin_mmio
->mux_mode
= be32_to_cpu(*list
++);
546 pin_mmio
->input_val
= be32_to_cpu(*list
++);
548 if (info
->generic_pinconf
) {
549 /* generic pin config decoded */
550 pin_mmio
->config
= imx_pinconf_parse_generic_config(np
, ipctl
);
552 /* legacy pin config read from devicetree */
553 config
= be32_to_cpu(*list
++);
555 /* SION bit is in mux register */
556 if (config
& IMX_PAD_SION
)
557 pin_mmio
->mux_mode
|= IOMUXC_CONFIG_SION
;
558 pin_mmio
->config
= config
& ~IMX_PAD_SION
;
563 dev_dbg(ipctl
->dev
, "%s: 0x%x 0x%08lx", info
->pins
[*pin_id
].name
,
564 pin_mmio
->mux_mode
, pin_mmio
->config
);
567 static int imx_pinctrl_parse_groups(struct device_node
*np
,
568 struct group_desc
*grp
,
569 struct imx_pinctrl
*ipctl
,
572 const struct imx_pinctrl_soc_info
*info
= ipctl
->info
;
578 dev_dbg(ipctl
->dev
, "group(%d): %pOFn\n", index
, np
);
580 if (info
->flags
& IMX_USE_SCU
)
581 pin_size
= FSL_SCU_PIN_SIZE
;
582 else if (info
->flags
& SHARE_MUX_CONF_REG
)
583 pin_size
= FSL_PIN_SHARE_SIZE
;
585 pin_size
= FSL_PIN_SIZE
;
587 if (info
->generic_pinconf
)
590 /* Initialise group */
591 grp
->name
= np
->name
;
594 * the binding format is fsl,pins = <PIN_FUNC_ID CONFIG ...>,
595 * do sanity check and calculate pins number
597 * First try legacy 'fsl,pins' property, then fall back to the
600 * Note: for generic 'pinmux' case, there's no CONFIG part in
601 * the binding format.
603 list
= of_get_property(np
, "fsl,pins", &size
);
605 list
= of_get_property(np
, "pinmux", &size
);
608 "no fsl,pins and pins property in node %pOF\n", np
);
613 /* we do not check return since it's safe node passed down */
614 if (!size
|| size
% pin_size
) {
615 dev_err(ipctl
->dev
, "Invalid fsl,pins or pins property in node %pOF\n", np
);
619 grp
->num_pins
= size
/ pin_size
;
620 grp
->data
= devm_kcalloc(ipctl
->dev
,
621 grp
->num_pins
, sizeof(struct imx_pin
),
623 grp
->pins
= devm_kcalloc(ipctl
->dev
,
624 grp
->num_pins
, sizeof(unsigned int),
626 if (!grp
->pins
|| !grp
->data
)
629 for (i
= 0; i
< grp
->num_pins
; i
++) {
630 pin
= &((struct imx_pin
*)(grp
->data
))[i
];
631 if (info
->flags
& IMX_USE_SCU
)
632 imx_pinctrl_parse_pin_scu(ipctl
, &grp
->pins
[i
],
635 imx_pinctrl_parse_pin_mmio(ipctl
, &grp
->pins
[i
],
642 static int imx_pinctrl_parse_functions(struct device_node
*np
,
643 struct imx_pinctrl
*ipctl
,
646 struct pinctrl_dev
*pctl
= ipctl
->pctl
;
647 struct device_node
*child
;
648 struct function_desc
*func
;
649 struct group_desc
*grp
;
652 dev_dbg(pctl
->dev
, "parse function(%d): %pOFn\n", index
, np
);
654 func
= pinmux_generic_get_function(pctl
, index
);
658 /* Initialise function */
659 func
->name
= np
->name
;
660 func
->num_group_names
= of_get_child_count(np
);
661 if (func
->num_group_names
== 0) {
662 dev_err(ipctl
->dev
, "no groups defined in %pOF\n", np
);
665 func
->group_names
= devm_kcalloc(ipctl
->dev
, func
->num_group_names
,
666 sizeof(char *), GFP_KERNEL
);
667 if (!func
->group_names
)
670 for_each_child_of_node(np
, child
) {
671 func
->group_names
[i
] = child
->name
;
673 grp
= devm_kzalloc(ipctl
->dev
, sizeof(struct group_desc
),
680 mutex_lock(&ipctl
->mutex
);
681 radix_tree_insert(&pctl
->pin_group_tree
,
682 ipctl
->group_index
++, grp
);
683 mutex_unlock(&ipctl
->mutex
);
685 imx_pinctrl_parse_groups(child
, grp
, ipctl
, i
++);
692 * Check if the DT contains pins in the direct child nodes. This indicates the
693 * newer DT format to store pins. This function returns true if the first found
694 * fsl,pins property is in a child of np. Otherwise false is returned.
696 static bool imx_pinctrl_dt_is_flat_functions(struct device_node
*np
)
698 struct device_node
*function_np
;
699 struct device_node
*pinctrl_np
;
701 for_each_child_of_node(np
, function_np
) {
702 if (of_property_read_bool(function_np
, "fsl,pins")) {
703 of_node_put(function_np
);
707 for_each_child_of_node(function_np
, pinctrl_np
) {
708 if (of_property_read_bool(pinctrl_np
, "fsl,pins")) {
709 of_node_put(pinctrl_np
);
710 of_node_put(function_np
);
719 static int imx_pinctrl_probe_dt(struct platform_device
*pdev
,
720 struct imx_pinctrl
*ipctl
)
722 struct device_node
*np
= pdev
->dev
.of_node
;
723 struct device_node
*child
;
724 struct pinctrl_dev
*pctl
= ipctl
->pctl
;
732 flat_funcs
= imx_pinctrl_dt_is_flat_functions(np
);
736 nfuncs
= of_get_child_count(np
);
738 dev_err(&pdev
->dev
, "no functions defined\n");
743 for (i
= 0; i
< nfuncs
; i
++) {
744 struct function_desc
*function
;
746 function
= devm_kzalloc(&pdev
->dev
, sizeof(*function
),
751 mutex_lock(&ipctl
->mutex
);
752 radix_tree_insert(&pctl
->pin_function_tree
, i
, function
);
753 mutex_unlock(&ipctl
->mutex
);
755 pctl
->num_functions
= nfuncs
;
757 ipctl
->group_index
= 0;
759 pctl
->num_groups
= of_get_child_count(np
);
761 pctl
->num_groups
= 0;
762 for_each_child_of_node(np
, child
)
763 pctl
->num_groups
+= of_get_child_count(child
);
767 imx_pinctrl_parse_functions(np
, ipctl
, 0);
770 for_each_child_of_node(np
, child
)
771 imx_pinctrl_parse_functions(child
, ipctl
, i
++);
778 * imx_free_resources() - free memory used by this driver
779 * @info: info driver instance
781 static void imx_free_resources(struct imx_pinctrl
*ipctl
)
784 pinctrl_unregister(ipctl
->pctl
);
787 int imx_pinctrl_probe(struct platform_device
*pdev
,
788 const struct imx_pinctrl_soc_info
*info
)
790 struct regmap_config config
= { .name
= "gpr" };
791 struct device_node
*dev_np
= pdev
->dev
.of_node
;
792 struct pinctrl_desc
*imx_pinctrl_desc
;
793 struct device_node
*np
;
794 struct imx_pinctrl
*ipctl
;
798 if (!info
|| !info
->pins
|| !info
->npins
) {
799 dev_err(&pdev
->dev
, "wrong pinctrl info\n");
803 if (info
->gpr_compatible
) {
804 gpr
= syscon_regmap_lookup_by_compatible(info
->gpr_compatible
);
806 regmap_attach_dev(&pdev
->dev
, gpr
, &config
);
809 /* Create state holders etc for this driver */
810 ipctl
= devm_kzalloc(&pdev
->dev
, sizeof(*ipctl
), GFP_KERNEL
);
814 if (!(info
->flags
& IMX_USE_SCU
)) {
815 ipctl
->pin_regs
= devm_kmalloc_array(&pdev
->dev
, info
->npins
,
816 sizeof(*ipctl
->pin_regs
),
818 if (!ipctl
->pin_regs
)
821 for (i
= 0; i
< info
->npins
; i
++) {
822 ipctl
->pin_regs
[i
].mux_reg
= -1;
823 ipctl
->pin_regs
[i
].conf_reg
= -1;
826 ipctl
->base
= devm_platform_ioremap_resource(pdev
, 0);
827 if (IS_ERR(ipctl
->base
))
828 return PTR_ERR(ipctl
->base
);
830 if (of_property_read_bool(dev_np
, "fsl,input-sel")) {
831 np
= of_parse_phandle(dev_np
, "fsl,input-sel", 0);
833 dev_err(&pdev
->dev
, "iomuxc fsl,input-sel property not found\n");
837 ipctl
->input_sel_base
= of_iomap(np
, 0);
839 if (!ipctl
->input_sel_base
) {
841 "iomuxc input select base address not found\n");
847 imx_pinctrl_desc
= devm_kzalloc(&pdev
->dev
, sizeof(*imx_pinctrl_desc
),
849 if (!imx_pinctrl_desc
)
852 imx_pinctrl_desc
->name
= dev_name(&pdev
->dev
);
853 imx_pinctrl_desc
->pins
= info
->pins
;
854 imx_pinctrl_desc
->npins
= info
->npins
;
855 imx_pinctrl_desc
->pctlops
= &imx_pctrl_ops
;
856 imx_pinctrl_desc
->pmxops
= &imx_pmx_ops
;
857 imx_pinctrl_desc
->confops
= &imx_pinconf_ops
;
858 imx_pinctrl_desc
->owner
= THIS_MODULE
;
860 /* for generic pinconf */
861 imx_pinctrl_desc
->custom_params
= info
->custom_params
;
862 imx_pinctrl_desc
->num_custom_params
= info
->num_custom_params
;
864 /* platform specific callback */
865 imx_pmx_ops
.gpio_set_direction
= info
->gpio_set_direction
;
867 mutex_init(&ipctl
->mutex
);
870 ipctl
->dev
= &pdev
->dev
;
871 platform_set_drvdata(pdev
, ipctl
);
872 ret
= devm_pinctrl_register_and_init(&pdev
->dev
,
873 imx_pinctrl_desc
, ipctl
,
876 dev_err(&pdev
->dev
, "could not register IMX pinctrl driver\n");
880 ret
= imx_pinctrl_probe_dt(pdev
, ipctl
);
882 dev_err(&pdev
->dev
, "fail to probe dt properties\n");
886 dev_info(&pdev
->dev
, "initialized IMX pinctrl driver\n");
888 return pinctrl_enable(ipctl
->pctl
);
891 imx_free_resources(ipctl
);
896 static int __maybe_unused
imx_pinctrl_suspend(struct device
*dev
)
898 struct imx_pinctrl
*ipctl
= dev_get_drvdata(dev
);
900 return pinctrl_force_sleep(ipctl
->pctl
);
903 static int __maybe_unused
imx_pinctrl_resume(struct device
*dev
)
905 struct imx_pinctrl
*ipctl
= dev_get_drvdata(dev
);
907 return pinctrl_force_default(ipctl
->pctl
);
910 const struct dev_pm_ops imx_pinctrl_pm_ops
= {
911 SET_LATE_SYSTEM_SLEEP_PM_OPS(imx_pinctrl_suspend
,