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 #ifndef __PINCTRL_UNIPHIER_H__
17 #define __PINCTRL_UNIPHIER_H__
19 #include <linux/bitops.h>
20 #include <linux/build_bug.h>
21 #include <linux/kernel.h>
22 #include <linux/types.h>
24 struct platform_device
;
26 /* input enable control register bit */
27 #define UNIPHIER_PIN_IECTRL_SHIFT 0
28 #define UNIPHIER_PIN_IECTRL_BITS 3
29 #define UNIPHIER_PIN_IECTRL_MASK ((1UL << (UNIPHIER_PIN_IECTRL_BITS)) \
32 /* drive strength control register number */
33 #define UNIPHIER_PIN_DRVCTRL_SHIFT ((UNIPHIER_PIN_IECTRL_SHIFT) + \
34 (UNIPHIER_PIN_IECTRL_BITS))
35 #define UNIPHIER_PIN_DRVCTRL_BITS 9
36 #define UNIPHIER_PIN_DRVCTRL_MASK ((1UL << (UNIPHIER_PIN_DRVCTRL_BITS)) \
39 /* drive control type */
40 #define UNIPHIER_PIN_DRV_TYPE_SHIFT ((UNIPHIER_PIN_DRVCTRL_SHIFT) + \
41 (UNIPHIER_PIN_DRVCTRL_BITS))
42 #define UNIPHIER_PIN_DRV_TYPE_BITS 3
43 #define UNIPHIER_PIN_DRV_TYPE_MASK ((1UL << (UNIPHIER_PIN_DRV_TYPE_BITS)) \
46 /* pull-up / pull-down register number */
47 #define UNIPHIER_PIN_PUPDCTRL_SHIFT ((UNIPHIER_PIN_DRV_TYPE_SHIFT) + \
48 (UNIPHIER_PIN_DRV_TYPE_BITS))
49 #define UNIPHIER_PIN_PUPDCTRL_BITS 9
50 #define UNIPHIER_PIN_PUPDCTRL_MASK ((1UL << (UNIPHIER_PIN_PUPDCTRL_BITS))\
53 /* direction of pull register */
54 #define UNIPHIER_PIN_PULL_DIR_SHIFT ((UNIPHIER_PIN_PUPDCTRL_SHIFT) + \
55 (UNIPHIER_PIN_PUPDCTRL_BITS))
56 #define UNIPHIER_PIN_PULL_DIR_BITS 3
57 #define UNIPHIER_PIN_PULL_DIR_MASK ((1UL << (UNIPHIER_PIN_PULL_DIR_BITS))\
60 #if UNIPHIER_PIN_PULL_DIR_SHIFT + UNIPHIER_PIN_PULL_DIR_BITS > BITS_PER_LONG
61 #error "unable to pack pin attributes."
64 #define UNIPHIER_PIN_IECTRL_NONE (UNIPHIER_PIN_IECTRL_MASK)
65 #define UNIPHIER_PIN_IECTRL_EXIST 0
67 /* drive control type */
68 enum uniphier_pin_drv_type
{
69 UNIPHIER_PIN_DRV_1BIT
, /* 2 level control: 4/8 mA */
70 UNIPHIER_PIN_DRV_2BIT
, /* 4 level control: 8/12/16/20 mA */
71 UNIPHIER_PIN_DRV_3BIT
, /* 8 level control: 4/5/7/9/11/12/14/16 mA */
72 UNIPHIER_PIN_DRV_FIXED4
, /* fixed to 4mA */
73 UNIPHIER_PIN_DRV_FIXED5
, /* fixed to 5mA */
74 UNIPHIER_PIN_DRV_FIXED8
, /* fixed to 8mA */
75 UNIPHIER_PIN_DRV_NONE
, /* no support (input only pin) */
78 /* direction of pull register (no pin supports bi-directional pull biasing) */
79 enum uniphier_pin_pull_dir
{
80 UNIPHIER_PIN_PULL_UP
, /* pull-up or disabled */
81 UNIPHIER_PIN_PULL_DOWN
, /* pull-down or disabled */
82 UNIPHIER_PIN_PULL_UP_FIXED
, /* always pull-up */
83 UNIPHIER_PIN_PULL_DOWN_FIXED
, /* always pull-down */
84 UNIPHIER_PIN_PULL_NONE
, /* no pull register */
87 #define UNIPHIER_PIN_IECTRL(x) \
88 (((x) & (UNIPHIER_PIN_IECTRL_MASK)) << (UNIPHIER_PIN_IECTRL_SHIFT))
89 #define UNIPHIER_PIN_DRVCTRL(x) \
90 (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT))
91 #define UNIPHIER_PIN_DRV_TYPE(x) \
92 (((x) & (UNIPHIER_PIN_DRV_TYPE_MASK)) << (UNIPHIER_PIN_DRV_TYPE_SHIFT))
93 #define UNIPHIER_PIN_PUPDCTRL(x) \
94 (((x) & (UNIPHIER_PIN_PUPDCTRL_MASK)) << (UNIPHIER_PIN_PUPDCTRL_SHIFT))
95 #define UNIPHIER_PIN_PULL_DIR(x) \
96 (((x) & (UNIPHIER_PIN_PULL_DIR_MASK)) << (UNIPHIER_PIN_PULL_DIR_SHIFT))
98 #define UNIPHIER_PIN_ATTR_PACKED(iectrl, drvctrl, drv_type, pupdctrl, pull_dir)\
99 (UNIPHIER_PIN_IECTRL(iectrl) | \
100 UNIPHIER_PIN_DRVCTRL(drvctrl) | \
101 UNIPHIER_PIN_DRV_TYPE(drv_type) | \
102 UNIPHIER_PIN_PUPDCTRL(pupdctrl) | \
103 UNIPHIER_PIN_PULL_DIR(pull_dir))
105 static inline unsigned int uniphier_pin_get_iectrl(void *drv_data
)
107 return ((unsigned long)drv_data
>> UNIPHIER_PIN_IECTRL_SHIFT
) &
108 UNIPHIER_PIN_IECTRL_MASK
;
111 static inline unsigned int uniphier_pin_get_drvctrl(void *drv_data
)
113 return ((unsigned long)drv_data
>> UNIPHIER_PIN_DRVCTRL_SHIFT
) &
114 UNIPHIER_PIN_DRVCTRL_MASK
;
117 static inline unsigned int uniphier_pin_get_drv_type(void *drv_data
)
119 return ((unsigned long)drv_data
>> UNIPHIER_PIN_DRV_TYPE_SHIFT
) &
120 UNIPHIER_PIN_DRV_TYPE_MASK
;
123 static inline unsigned int uniphier_pin_get_pupdctrl(void *drv_data
)
125 return ((unsigned long)drv_data
>> UNIPHIER_PIN_PUPDCTRL_SHIFT
) &
126 UNIPHIER_PIN_PUPDCTRL_MASK
;
129 static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data
)
131 return ((unsigned long)drv_data
>> UNIPHIER_PIN_PULL_DIR_SHIFT
) &
132 UNIPHIER_PIN_PULL_DIR_MASK
;
135 struct uniphier_pinctrl_group
{
137 const unsigned *pins
;
142 struct uniphier_pinmux_function
{
144 const char * const *groups
;
148 struct uniphier_pinctrl_socdata
{
149 const struct pinctrl_pin_desc
*pins
;
151 const struct uniphier_pinctrl_group
*groups
;
153 const struct uniphier_pinmux_function
*functions
;
155 int (*get_gpio_muxval
)(unsigned int pin
, unsigned int gpio_offset
);
157 #define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(1)
158 #define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(0)
161 #define UNIPHIER_PINCTRL_PIN(a, b, c, d, e, f, g) \
165 .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \
168 #define __UNIPHIER_PINCTRL_GROUP(grp, mux) \
171 .pins = grp##_pins, \
172 .num_pins = ARRAY_SIZE(grp##_pins), \
176 #define UNIPHIER_PINCTRL_GROUP(grp) \
177 __UNIPHIER_PINCTRL_GROUP(grp, \
179 BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \
180 ARRAY_SIZE(grp##_muxvals)))
182 #define UNIPHIER_PINCTRL_GROUP_GPIO(grp) \
183 __UNIPHIER_PINCTRL_GROUP(grp, NULL)
185 #define UNIPHIER_PINMUX_FUNCTION(func) \
188 .groups = func##_groups, \
189 .num_groups = ARRAY_SIZE(func##_groups), \
192 int uniphier_pinctrl_probe(struct platform_device
*pdev
,
193 struct uniphier_pinctrl_socdata
*socdata
);
195 extern const struct dev_pm_ops uniphier_pinctrl_pm_ops
;
197 #endif /* __PINCTRL_UNIPHIER_H__ */