2 * Copyright (C) 2015-2017 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/list.h>
17 #include <linux/mfd/syscon.h>
19 #include <linux/pinctrl/pinconf.h>
20 #include <linux/pinctrl/pinconf-generic.h>
21 #include <linux/pinctrl/pinctrl.h>
22 #include <linux/pinctrl/pinmux.h>
23 #include <linux/platform_device.h>
24 #include <linux/regmap.h>
27 #include "../pinctrl-utils.h"
28 #include "pinctrl-uniphier.h"
30 #define UNIPHIER_PINCTRL_PINMUX_BASE 0x1000
31 #define UNIPHIER_PINCTRL_LOAD_PINMUX 0x1700
32 #define UNIPHIER_PINCTRL_DRVCTRL_BASE 0x1800
33 #define UNIPHIER_PINCTRL_DRV2CTRL_BASE 0x1900
34 #define UNIPHIER_PINCTRL_DRV3CTRL_BASE 0x1980
35 #define UNIPHIER_PINCTRL_PUPDCTRL_BASE 0x1a00
36 #define UNIPHIER_PINCTRL_IECTRL_BASE 0x1d00
38 struct uniphier_pinctrl_reg_region
{
39 struct list_head node
;
45 struct uniphier_pinctrl_priv
{
46 struct pinctrl_desc pctldesc
;
47 struct pinctrl_dev
*pctldev
;
48 struct regmap
*regmap
;
49 struct uniphier_pinctrl_socdata
*socdata
;
50 struct list_head reg_regions
;
53 static int uniphier_pctl_get_groups_count(struct pinctrl_dev
*pctldev
)
55 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
57 return priv
->socdata
->groups_count
;
60 static const char *uniphier_pctl_get_group_name(struct pinctrl_dev
*pctldev
,
63 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
65 return priv
->socdata
->groups
[selector
].name
;
68 static int uniphier_pctl_get_group_pins(struct pinctrl_dev
*pctldev
,
70 const unsigned **pins
,
73 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
75 *pins
= priv
->socdata
->groups
[selector
].pins
;
76 *num_pins
= priv
->socdata
->groups
[selector
].num_pins
;
81 #ifdef CONFIG_DEBUG_FS
82 static void uniphier_pctl_pin_dbg_show(struct pinctrl_dev
*pctldev
,
83 struct seq_file
*s
, unsigned offset
)
85 const struct pin_desc
*desc
= pin_desc_get(pctldev
, offset
);
86 const char *pull_dir
, *drv_type
;
88 switch (uniphier_pin_get_pull_dir(desc
->drv_data
)) {
89 case UNIPHIER_PIN_PULL_UP
:
92 case UNIPHIER_PIN_PULL_DOWN
:
95 case UNIPHIER_PIN_PULL_UP_FIXED
:
96 pull_dir
= "UP(FIXED)";
98 case UNIPHIER_PIN_PULL_DOWN_FIXED
:
99 pull_dir
= "DOWN(FIXED)";
101 case UNIPHIER_PIN_PULL_NONE
:
108 switch (uniphier_pin_get_drv_type(desc
->drv_data
)) {
109 case UNIPHIER_PIN_DRV_1BIT
:
110 drv_type
= "4/8(mA)";
112 case UNIPHIER_PIN_DRV_2BIT
:
113 drv_type
= "8/12/16/20(mA)";
115 case UNIPHIER_PIN_DRV_3BIT
:
116 drv_type
= "4/5/7/9/11/12/14/16(mA)";
118 case UNIPHIER_PIN_DRV_FIXED4
:
121 case UNIPHIER_PIN_DRV_FIXED5
:
124 case UNIPHIER_PIN_DRV_FIXED8
:
127 case UNIPHIER_PIN_DRV_NONE
:
134 seq_printf(s
, " PULL_DIR=%s DRV_TYPE=%s", pull_dir
, drv_type
);
138 static const struct pinctrl_ops uniphier_pctlops
= {
139 .get_groups_count
= uniphier_pctl_get_groups_count
,
140 .get_group_name
= uniphier_pctl_get_group_name
,
141 .get_group_pins
= uniphier_pctl_get_group_pins
,
142 #ifdef CONFIG_DEBUG_FS
143 .pin_dbg_show
= uniphier_pctl_pin_dbg_show
,
145 .dt_node_to_map
= pinconf_generic_dt_node_to_map_all
,
146 .dt_free_map
= pinctrl_utils_free_map
,
149 static const unsigned int uniphier_conf_drv_strengths_1bit
[] = {4, 8};
150 static const unsigned int uniphier_conf_drv_strengths_2bit
[] = {8, 12, 16, 20};
151 static const unsigned int uniphier_conf_drv_strengths_3bit
[] = {4, 5, 7, 9, 11,
153 static const unsigned int uniphier_conf_drv_strengths_fixed4
[] = {4};
154 static const unsigned int uniphier_conf_drv_strengths_fixed5
[] = {5};
155 static const unsigned int uniphier_conf_drv_strengths_fixed8
[] = {8};
157 static int uniphier_conf_get_drvctrl_data(struct pinctrl_dev
*pctldev
,
158 unsigned int pin
, unsigned int *reg
,
161 const unsigned int **strengths
)
163 const struct pin_desc
*desc
= pin_desc_get(pctldev
, pin
);
164 enum uniphier_pin_drv_type type
=
165 uniphier_pin_get_drv_type(desc
->drv_data
);
166 unsigned int base
= 0;
167 unsigned int stride
= 0;
168 unsigned int width
= 0;
169 unsigned int drvctrl
;
172 case UNIPHIER_PIN_DRV_1BIT
:
173 *strengths
= uniphier_conf_drv_strengths_1bit
;
174 base
= UNIPHIER_PINCTRL_DRVCTRL_BASE
;
178 case UNIPHIER_PIN_DRV_2BIT
:
179 *strengths
= uniphier_conf_drv_strengths_2bit
;
180 base
= UNIPHIER_PINCTRL_DRV2CTRL_BASE
;
184 case UNIPHIER_PIN_DRV_3BIT
:
185 *strengths
= uniphier_conf_drv_strengths_3bit
;
186 base
= UNIPHIER_PINCTRL_DRV3CTRL_BASE
;
190 case UNIPHIER_PIN_DRV_FIXED4
:
191 *strengths
= uniphier_conf_drv_strengths_fixed4
;
193 case UNIPHIER_PIN_DRV_FIXED5
:
194 *strengths
= uniphier_conf_drv_strengths_fixed5
;
196 case UNIPHIER_PIN_DRV_FIXED8
:
197 *strengths
= uniphier_conf_drv_strengths_fixed8
;
200 /* drive strength control is not supported for this pin */
204 drvctrl
= uniphier_pin_get_drvctrl(desc
->drv_data
);
207 *reg
= base
+ drvctrl
/ 32 * 4;
208 *shift
= drvctrl
% 32;
209 *mask
= (1U << width
) - 1;
214 static int uniphier_conf_pin_bias_get(struct pinctrl_dev
*pctldev
,
216 enum pin_config_param param
)
218 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
219 const struct pin_desc
*desc
= pin_desc_get(pctldev
, pin
);
220 enum uniphier_pin_pull_dir pull_dir
=
221 uniphier_pin_get_pull_dir(desc
->drv_data
);
222 unsigned int pupdctrl
, reg
, shift
, val
;
223 unsigned int expected
= 1;
227 case PIN_CONFIG_BIAS_DISABLE
:
228 if (pull_dir
== UNIPHIER_PIN_PULL_NONE
)
230 if (pull_dir
== UNIPHIER_PIN_PULL_UP_FIXED
||
231 pull_dir
== UNIPHIER_PIN_PULL_DOWN_FIXED
)
235 case PIN_CONFIG_BIAS_PULL_UP
:
236 if (pull_dir
== UNIPHIER_PIN_PULL_UP_FIXED
)
238 if (pull_dir
!= UNIPHIER_PIN_PULL_UP
)
241 case PIN_CONFIG_BIAS_PULL_DOWN
:
242 if (pull_dir
== UNIPHIER_PIN_PULL_DOWN_FIXED
)
244 if (pull_dir
!= UNIPHIER_PIN_PULL_DOWN
)
251 pupdctrl
= uniphier_pin_get_pupdctrl(desc
->drv_data
);
253 reg
= UNIPHIER_PINCTRL_PUPDCTRL_BASE
+ pupdctrl
/ 32 * 4;
254 shift
= pupdctrl
% 32;
256 ret
= regmap_read(priv
->regmap
, reg
, &val
);
260 val
= (val
>> shift
) & 1;
262 return (val
== expected
) ? 0 : -EINVAL
;
265 static int uniphier_conf_pin_drive_get(struct pinctrl_dev
*pctldev
,
266 unsigned int pin
, u32
*strength
)
268 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
269 unsigned int reg
, shift
, mask
, val
;
270 const unsigned int *strengths
;
273 ret
= uniphier_conf_get_drvctrl_data(pctldev
, pin
, ®
, &shift
,
279 ret
= regmap_read(priv
->regmap
, reg
, &val
);
286 *strength
= strengths
[(val
>> shift
) & mask
];
291 static int uniphier_conf_pin_input_enable_get(struct pinctrl_dev
*pctldev
,
294 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
295 const struct pin_desc
*desc
= pin_desc_get(pctldev
, pin
);
296 unsigned int iectrl
= uniphier_pin_get_iectrl(desc
->drv_data
);
297 unsigned int reg
, mask
, val
;
300 if (iectrl
== UNIPHIER_PIN_IECTRL_NONE
)
301 /* This pin is always input-enabled. */
304 if (priv
->socdata
->caps
& UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL
)
307 reg
= UNIPHIER_PINCTRL_IECTRL_BASE
+ iectrl
/ 32 * 4;
308 mask
= BIT(iectrl
% 32);
310 ret
= regmap_read(priv
->regmap
, reg
, &val
);
314 return val
& mask
? 0 : -EINVAL
;
317 static int uniphier_conf_pin_config_get(struct pinctrl_dev
*pctldev
,
319 unsigned long *configs
)
321 enum pin_config_param param
= pinconf_to_config_param(*configs
);
322 bool has_arg
= false;
327 case PIN_CONFIG_BIAS_DISABLE
:
328 case PIN_CONFIG_BIAS_PULL_UP
:
329 case PIN_CONFIG_BIAS_PULL_DOWN
:
330 ret
= uniphier_conf_pin_bias_get(pctldev
, pin
, param
);
332 case PIN_CONFIG_DRIVE_STRENGTH
:
333 ret
= uniphier_conf_pin_drive_get(pctldev
, pin
, &arg
);
336 case PIN_CONFIG_INPUT_ENABLE
:
337 ret
= uniphier_conf_pin_input_enable_get(pctldev
, pin
);
340 /* unsupported parameter */
345 if (ret
== 0 && has_arg
)
346 *configs
= pinconf_to_config_packed(param
, arg
);
351 static int uniphier_conf_pin_bias_set(struct pinctrl_dev
*pctldev
,
353 enum pin_config_param param
, u32 arg
)
355 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
356 const struct pin_desc
*desc
= pin_desc_get(pctldev
, pin
);
357 enum uniphier_pin_pull_dir pull_dir
=
358 uniphier_pin_get_pull_dir(desc
->drv_data
);
359 unsigned int pupdctrl
, reg
, shift
;
360 unsigned int val
= 1;
363 case PIN_CONFIG_BIAS_DISABLE
:
364 if (pull_dir
== UNIPHIER_PIN_PULL_NONE
)
366 if (pull_dir
== UNIPHIER_PIN_PULL_UP_FIXED
||
367 pull_dir
== UNIPHIER_PIN_PULL_DOWN_FIXED
) {
368 dev_err(pctldev
->dev
,
369 "can not disable pull register for pin %s\n",
375 case PIN_CONFIG_BIAS_PULL_UP
:
376 if (pull_dir
== UNIPHIER_PIN_PULL_UP_FIXED
&& arg
!= 0)
378 if (pull_dir
!= UNIPHIER_PIN_PULL_UP
) {
379 dev_err(pctldev
->dev
,
380 "pull-up is unsupported for pin %s\n",
385 dev_err(pctldev
->dev
, "pull-up can not be total\n");
389 case PIN_CONFIG_BIAS_PULL_DOWN
:
390 if (pull_dir
== UNIPHIER_PIN_PULL_DOWN_FIXED
&& arg
!= 0)
392 if (pull_dir
!= UNIPHIER_PIN_PULL_DOWN
) {
393 dev_err(pctldev
->dev
,
394 "pull-down is unsupported for pin %s\n",
399 dev_err(pctldev
->dev
, "pull-down can not be total\n");
403 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
404 if (pull_dir
== UNIPHIER_PIN_PULL_NONE
) {
405 dev_err(pctldev
->dev
,
406 "pull-up/down is unsupported for pin %s\n",
412 return 0; /* configuration ingored */
418 pupdctrl
= uniphier_pin_get_pupdctrl(desc
->drv_data
);
420 reg
= UNIPHIER_PINCTRL_PUPDCTRL_BASE
+ pupdctrl
/ 32 * 4;
421 shift
= pupdctrl
% 32;
423 return regmap_update_bits(priv
->regmap
, reg
, 1 << shift
, val
<< shift
);
426 static int uniphier_conf_pin_drive_set(struct pinctrl_dev
*pctldev
,
427 unsigned int pin
, u32 strength
)
429 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
430 const struct pin_desc
*desc
= pin_desc_get(pctldev
, pin
);
431 unsigned int reg
, shift
, mask
, val
;
432 const unsigned int *strengths
;
435 ret
= uniphier_conf_get_drvctrl_data(pctldev
, pin
, ®
, &shift
,
438 dev_err(pctldev
->dev
, "cannot set drive strength for pin %s\n",
443 for (val
= 0; val
<= mask
; val
++) {
444 if (strengths
[val
] > strength
)
449 dev_err(pctldev
->dev
,
450 "unsupported drive strength %u mA for pin %s\n",
451 strength
, desc
->name
);
460 return regmap_update_bits(priv
->regmap
, reg
,
461 mask
<< shift
, val
<< shift
);
464 static int uniphier_conf_pin_input_enable(struct pinctrl_dev
*pctldev
,
465 unsigned int pin
, u32 enable
)
467 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
468 const struct pin_desc
*desc
= pin_desc_get(pctldev
, pin
);
469 unsigned int iectrl
= uniphier_pin_get_iectrl(desc
->drv_data
);
470 unsigned int reg
, mask
;
473 * Multiple pins share one input enable, per-pin disabling is
476 if (!(priv
->socdata
->caps
& UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL
) &&
480 /* UNIPHIER_PIN_IECTRL_NONE means the pin is always input-enabled */
481 if (iectrl
== UNIPHIER_PIN_IECTRL_NONE
)
482 return enable
? 0 : -EINVAL
;
484 if (priv
->socdata
->caps
& UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL
)
487 reg
= UNIPHIER_PINCTRL_IECTRL_BASE
+ iectrl
/ 32 * 4;
488 mask
= BIT(iectrl
% 32);
490 return regmap_update_bits(priv
->regmap
, reg
, mask
, enable
? mask
: 0);
493 static int uniphier_conf_pin_config_set(struct pinctrl_dev
*pctldev
,
495 unsigned long *configs
,
496 unsigned num_configs
)
500 for (i
= 0; i
< num_configs
; i
++) {
501 enum pin_config_param param
=
502 pinconf_to_config_param(configs
[i
]);
503 u32 arg
= pinconf_to_config_argument(configs
[i
]);
506 case PIN_CONFIG_BIAS_DISABLE
:
507 case PIN_CONFIG_BIAS_PULL_UP
:
508 case PIN_CONFIG_BIAS_PULL_DOWN
:
509 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
510 ret
= uniphier_conf_pin_bias_set(pctldev
, pin
,
513 case PIN_CONFIG_DRIVE_STRENGTH
:
514 ret
= uniphier_conf_pin_drive_set(pctldev
, pin
, arg
);
516 case PIN_CONFIG_INPUT_ENABLE
:
517 ret
= uniphier_conf_pin_input_enable(pctldev
, pin
, arg
);
520 dev_err(pctldev
->dev
,
521 "unsupported configuration parameter %u\n",
533 static int uniphier_conf_pin_config_group_set(struct pinctrl_dev
*pctldev
,
535 unsigned long *configs
,
536 unsigned num_configs
)
538 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
539 const unsigned *pins
= priv
->socdata
->groups
[selector
].pins
;
540 unsigned num_pins
= priv
->socdata
->groups
[selector
].num_pins
;
543 for (i
= 0; i
< num_pins
; i
++) {
544 ret
= uniphier_conf_pin_config_set(pctldev
, pins
[i
],
545 configs
, num_configs
);
553 static const struct pinconf_ops uniphier_confops
= {
555 .pin_config_get
= uniphier_conf_pin_config_get
,
556 .pin_config_set
= uniphier_conf_pin_config_set
,
557 .pin_config_group_set
= uniphier_conf_pin_config_group_set
,
560 static int uniphier_pmx_get_functions_count(struct pinctrl_dev
*pctldev
)
562 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
564 return priv
->socdata
->functions_count
;
567 static const char *uniphier_pmx_get_function_name(struct pinctrl_dev
*pctldev
,
570 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
572 return priv
->socdata
->functions
[selector
].name
;
575 static int uniphier_pmx_get_function_groups(struct pinctrl_dev
*pctldev
,
577 const char * const **groups
,
578 unsigned *num_groups
)
580 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
582 *groups
= priv
->socdata
->functions
[selector
].groups
;
583 *num_groups
= priv
->socdata
->functions
[selector
].num_groups
;
588 static int uniphier_pmx_set_one_mux(struct pinctrl_dev
*pctldev
, unsigned pin
,
591 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
592 unsigned int mux_bits
, reg_stride
, reg
, reg_end
, shift
, mask
;
596 /* some pins need input-enabling */
597 ret
= uniphier_conf_pin_input_enable(pctldev
, pin
, 1);
602 return 0; /* dedicated pin; nothing to do for pin-mux */
604 if (priv
->socdata
->caps
& UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE
) {
606 * Mode reg_offset bit_position
607 * Normal 4 * n shift+3:shift
608 * Debug 4 * n shift+7:shift+4
615 * Mode reg_offset bit_position
616 * Normal 8 * n shift+3:shift
617 * Debug 8 * n + 4 shift+3:shift
621 load_pinctrl
= false;
624 reg
= UNIPHIER_PINCTRL_PINMUX_BASE
+ pin
* mux_bits
/ 32 * reg_stride
;
625 reg_end
= reg
+ reg_stride
;
626 shift
= pin
* mux_bits
% 32;
627 mask
= (1U << mux_bits
) - 1;
630 * If reg_stride is greater than 4, the MSB of each pinsel shall be
631 * stored in the offset+4.
633 for (; reg
< reg_end
; reg
+= 4) {
634 ret
= regmap_update_bits(priv
->regmap
, reg
,
635 mask
<< shift
, muxval
<< shift
);
642 ret
= regmap_write(priv
->regmap
,
643 UNIPHIER_PINCTRL_LOAD_PINMUX
, 1);
651 static int uniphier_pmx_set_mux(struct pinctrl_dev
*pctldev
,
652 unsigned func_selector
,
653 unsigned group_selector
)
655 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
656 const struct uniphier_pinctrl_group
*grp
=
657 &priv
->socdata
->groups
[group_selector
];
661 for (i
= 0; i
< grp
->num_pins
; i
++) {
662 ret
= uniphier_pmx_set_one_mux(pctldev
, grp
->pins
[i
],
671 static int uniphier_pmx_gpio_request_enable(struct pinctrl_dev
*pctldev
,
672 struct pinctrl_gpio_range
*range
,
675 struct uniphier_pinctrl_priv
*priv
= pinctrl_dev_get_drvdata(pctldev
);
676 unsigned int gpio_offset
;
680 for (i
= 0; i
< range
->npins
; i
++)
681 if (range
->pins
[i
] == offset
)
684 if (WARN_ON(i
== range
->npins
))
689 gpio_offset
= offset
- range
->pin_base
;
692 gpio_offset
+= range
->id
;
694 muxval
= priv
->socdata
->get_gpio_muxval(offset
, gpio_offset
);
696 return uniphier_pmx_set_one_mux(pctldev
, offset
, muxval
);
699 static const struct pinmux_ops uniphier_pmxops
= {
700 .get_functions_count
= uniphier_pmx_get_functions_count
,
701 .get_function_name
= uniphier_pmx_get_function_name
,
702 .get_function_groups
= uniphier_pmx_get_function_groups
,
703 .set_mux
= uniphier_pmx_set_mux
,
704 .gpio_request_enable
= uniphier_pmx_gpio_request_enable
,
708 #ifdef CONFIG_PM_SLEEP
709 static int uniphier_pinctrl_suspend(struct device
*dev
)
711 struct uniphier_pinctrl_priv
*priv
= dev_get_drvdata(dev
);
712 struct uniphier_pinctrl_reg_region
*r
;
715 list_for_each_entry(r
, &priv
->reg_regions
, node
) {
716 ret
= regmap_bulk_read(priv
->regmap
, r
->base
, r
->vals
,
725 static int uniphier_pinctrl_resume(struct device
*dev
)
727 struct uniphier_pinctrl_priv
*priv
= dev_get_drvdata(dev
);
728 struct uniphier_pinctrl_reg_region
*r
;
731 list_for_each_entry(r
, &priv
->reg_regions
, node
) {
732 ret
= regmap_bulk_write(priv
->regmap
, r
->base
, r
->vals
,
738 if (priv
->socdata
->caps
& UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE
) {
739 ret
= regmap_write(priv
->regmap
,
740 UNIPHIER_PINCTRL_LOAD_PINMUX
, 1);
748 static int uniphier_pinctrl_add_reg_region(struct device
*dev
,
749 struct uniphier_pinctrl_priv
*priv
,
754 struct uniphier_pinctrl_reg_region
*region
;
760 nregs
= DIV_ROUND_UP(count
* width
, 32);
762 region
= devm_kzalloc(dev
, struct_size(region
, vals
, nregs
),
768 region
->nregs
= nregs
;
770 list_add_tail(®ion
->node
, &priv
->reg_regions
);
776 static int uniphier_pinctrl_pm_init(struct device
*dev
,
777 struct uniphier_pinctrl_priv
*priv
)
779 #ifdef CONFIG_PM_SLEEP
780 const struct uniphier_pinctrl_socdata
*socdata
= priv
->socdata
;
781 unsigned int num_drvctrl
= 0;
782 unsigned int num_drv2ctrl
= 0;
783 unsigned int num_drv3ctrl
= 0;
784 unsigned int num_pupdctrl
= 0;
785 unsigned int num_iectrl
= 0;
786 unsigned int iectrl
, drvctrl
, pupdctrl
;
787 enum uniphier_pin_drv_type drv_type
;
788 enum uniphier_pin_pull_dir pull_dir
;
791 for (i
= 0; i
< socdata
->npins
; i
++) {
792 void *drv_data
= socdata
->pins
[i
].drv_data
;
794 drvctrl
= uniphier_pin_get_drvctrl(drv_data
);
795 drv_type
= uniphier_pin_get_drv_type(drv_data
);
796 pupdctrl
= uniphier_pin_get_pupdctrl(drv_data
);
797 pull_dir
= uniphier_pin_get_pull_dir(drv_data
);
798 iectrl
= uniphier_pin_get_iectrl(drv_data
);
801 case UNIPHIER_PIN_DRV_1BIT
:
802 num_drvctrl
= max(num_drvctrl
, drvctrl
+ 1);
804 case UNIPHIER_PIN_DRV_2BIT
:
805 num_drv2ctrl
= max(num_drv2ctrl
, drvctrl
+ 1);
807 case UNIPHIER_PIN_DRV_3BIT
:
808 num_drv3ctrl
= max(num_drv3ctrl
, drvctrl
+ 1);
814 if (pull_dir
== UNIPHIER_PIN_PULL_UP
||
815 pull_dir
== UNIPHIER_PIN_PULL_DOWN
)
816 num_pupdctrl
= max(num_pupdctrl
, pupdctrl
+ 1);
818 if (iectrl
!= UNIPHIER_PIN_IECTRL_NONE
) {
819 if (socdata
->caps
& UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL
)
821 num_iectrl
= max(num_iectrl
, iectrl
+ 1);
825 INIT_LIST_HEAD(&priv
->reg_regions
);
827 ret
= uniphier_pinctrl_add_reg_region(dev
, priv
,
828 UNIPHIER_PINCTRL_PINMUX_BASE
,
833 ret
= uniphier_pinctrl_add_reg_region(dev
, priv
,
834 UNIPHIER_PINCTRL_DRVCTRL_BASE
,
839 ret
= uniphier_pinctrl_add_reg_region(dev
, priv
,
840 UNIPHIER_PINCTRL_DRV2CTRL_BASE
,
845 ret
= uniphier_pinctrl_add_reg_region(dev
, priv
,
846 UNIPHIER_PINCTRL_DRV3CTRL_BASE
,
851 ret
= uniphier_pinctrl_add_reg_region(dev
, priv
,
852 UNIPHIER_PINCTRL_PUPDCTRL_BASE
,
857 ret
= uniphier_pinctrl_add_reg_region(dev
, priv
,
858 UNIPHIER_PINCTRL_IECTRL_BASE
,
866 const struct dev_pm_ops uniphier_pinctrl_pm_ops
= {
867 SET_LATE_SYSTEM_SLEEP_PM_OPS(uniphier_pinctrl_suspend
,
868 uniphier_pinctrl_resume
)
871 int uniphier_pinctrl_probe(struct platform_device
*pdev
,
872 struct uniphier_pinctrl_socdata
*socdata
)
874 struct device
*dev
= &pdev
->dev
;
875 struct uniphier_pinctrl_priv
*priv
;
876 struct device_node
*parent
;
880 !socdata
->pins
|| !socdata
->npins
||
881 !socdata
->groups
|| !socdata
->groups_count
||
882 !socdata
->functions
|| !socdata
->functions_count
) {
883 dev_err(dev
, "pinctrl socdata lacks necessary members\n");
887 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
891 parent
= of_get_parent(dev
->of_node
);
892 priv
->regmap
= syscon_node_to_regmap(parent
);
895 if (IS_ERR(priv
->regmap
)) {
896 dev_err(dev
, "failed to get regmap\n");
897 return PTR_ERR(priv
->regmap
);
900 priv
->socdata
= socdata
;
901 priv
->pctldesc
.name
= dev
->driver
->name
;
902 priv
->pctldesc
.pins
= socdata
->pins
;
903 priv
->pctldesc
.npins
= socdata
->npins
;
904 priv
->pctldesc
.pctlops
= &uniphier_pctlops
;
905 priv
->pctldesc
.pmxops
= &uniphier_pmxops
;
906 priv
->pctldesc
.confops
= &uniphier_confops
;
907 priv
->pctldesc
.owner
= dev
->driver
->owner
;
909 ret
= uniphier_pinctrl_pm_init(dev
, priv
);
913 priv
->pctldev
= devm_pinctrl_register(dev
, &priv
->pctldesc
, priv
);
914 if (IS_ERR(priv
->pctldev
)) {
915 dev_err(dev
, "failed to register UniPhier pinctrl driver\n");
916 return PTR_ERR(priv
->pctldev
);
919 platform_set_drvdata(pdev
, priv
);