2 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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.
15 #ifndef __PINCTRL_UNIPHIER_H__
16 #define __PINCTRL_UNIPHIER_H__
18 #include <linux/bug.h>
19 #include <linux/kernel.h>
20 #include <linux/types.h>
22 #define UNIPHIER_PINCTRL_PINMUX_BASE 0x0
23 #define UNIPHIER_PINCTRL_LOAD_PINMUX 0x700
24 #define UNIPHIER_PINCTRL_DRVCTRL_BASE 0x800
25 #define UNIPHIER_PINCTRL_DRV2CTRL_BASE 0x900
26 #define UNIPHIER_PINCTRL_PUPDCTRL_BASE 0xa00
27 #define UNIPHIER_PINCTRL_IECTRL 0xd00
29 /* input enable control register bit */
30 #define UNIPHIER_PIN_IECTRL_SHIFT 0
31 #define UNIPHIER_PIN_IECTRL_BITS 8
32 #define UNIPHIER_PIN_IECTRL_MASK ((1UL << (UNIPHIER_PIN_IECTRL_BITS)) \
35 /* drive strength control register number */
36 #define UNIPHIER_PIN_DRVCTRL_SHIFT ((UNIPHIER_PIN_IECTRL_SHIFT) + \
37 (UNIPHIER_PIN_IECTRL_BITS))
38 #define UNIPHIER_PIN_DRVCTRL_BITS 9
39 #define UNIPHIER_PIN_DRVCTRL_MASK ((1UL << (UNIPHIER_PIN_DRVCTRL_BITS)) \
42 /* supported drive strength (mA) */
43 #define UNIPHIER_PIN_DRV_STR_SHIFT ((UNIPHIER_PIN_DRVCTRL_SHIFT) + \
44 (UNIPHIER_PIN_DRVCTRL_BITS))
45 #define UNIPHIER_PIN_DRV_STR_BITS 3
46 #define UNIPHIER_PIN_DRV_STR_MASK ((1UL << (UNIPHIER_PIN_DRV_STR_BITS)) \
49 /* pull-up / pull-down register number */
50 #define UNIPHIER_PIN_PUPDCTRL_SHIFT ((UNIPHIER_PIN_DRV_STR_SHIFT) + \
51 (UNIPHIER_PIN_DRV_STR_BITS))
52 #define UNIPHIER_PIN_PUPDCTRL_BITS 9
53 #define UNIPHIER_PIN_PUPDCTRL_MASK ((1UL << (UNIPHIER_PIN_PUPDCTRL_BITS))\
56 /* direction of pull register */
57 #define UNIPHIER_PIN_PULL_DIR_SHIFT ((UNIPHIER_PIN_PUPDCTRL_SHIFT) + \
58 (UNIPHIER_PIN_PUPDCTRL_BITS))
59 #define UNIPHIER_PIN_PULL_DIR_BITS 3
60 #define UNIPHIER_PIN_PULL_DIR_MASK ((1UL << (UNIPHIER_PIN_PULL_DIR_BITS))\
63 #if UNIPHIER_PIN_PULL_DIR_SHIFT + UNIPHIER_PIN_PULL_DIR_BITS > BITS_PER_LONG
64 #error "unable to pack pin attributes."
67 #define UNIPHIER_PIN_IECTRL_NONE (UNIPHIER_PIN_IECTRL_MASK)
69 /* selectable drive strength */
70 enum uniphier_pin_drv_str
{
71 UNIPHIER_PIN_DRV_4_8
, /* 2 level control: 4/8 mA */
72 UNIPHIER_PIN_DRV_8_12_16_20
, /* 4 level control: 8/12/16/20 mA */
73 UNIPHIER_PIN_DRV_FIXED_4
, /* fixed to 4mA */
74 UNIPHIER_PIN_DRV_FIXED_5
, /* fixed to 5mA */
75 UNIPHIER_PIN_DRV_FIXED_8
, /* fixed to 8mA */
76 UNIPHIER_PIN_DRV_NONE
, /* no support (input only pin) */
79 /* direction of pull register (no pin supports bi-directional pull biasing) */
80 enum uniphier_pin_pull_dir
{
81 UNIPHIER_PIN_PULL_UP
, /* pull-up or disabled */
82 UNIPHIER_PIN_PULL_DOWN
, /* pull-down or disabled */
83 UNIPHIER_PIN_PULL_UP_FIXED
, /* always pull-up */
84 UNIPHIER_PIN_PULL_DOWN_FIXED
, /* always pull-down */
85 UNIPHIER_PIN_PULL_NONE
, /* no pull register */
88 #define UNIPHIER_PIN_IECTRL(x) \
89 (((x) & (UNIPHIER_PIN_IECTRL_MASK)) << (UNIPHIER_PIN_IECTRL_SHIFT))
90 #define UNIPHIER_PIN_DRVCTRL(x) \
91 (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT))
92 #define UNIPHIER_PIN_DRV_STR(x) \
93 (((x) & (UNIPHIER_PIN_DRV_STR_MASK)) << (UNIPHIER_PIN_DRV_STR_SHIFT))
94 #define UNIPHIER_PIN_PUPDCTRL(x) \
95 (((x) & (UNIPHIER_PIN_PUPDCTRL_MASK)) << (UNIPHIER_PIN_PUPDCTRL_SHIFT))
96 #define UNIPHIER_PIN_PULL_DIR(x) \
97 (((x) & (UNIPHIER_PIN_PULL_DIR_MASK)) << (UNIPHIER_PIN_PULL_DIR_SHIFT))
99 #define UNIPHIER_PIN_ATTR_PACKED(iectrl, drvctrl, drv_str, pupdctrl, pull_dir)\
100 (UNIPHIER_PIN_IECTRL(iectrl) | \
101 UNIPHIER_PIN_DRVCTRL(drvctrl) | \
102 UNIPHIER_PIN_DRV_STR(drv_str) | \
103 UNIPHIER_PIN_PUPDCTRL(pupdctrl) | \
104 UNIPHIER_PIN_PULL_DIR(pull_dir))
106 static inline unsigned int uniphier_pin_get_iectrl(void *drv_data
)
108 return ((unsigned long)drv_data
>> UNIPHIER_PIN_IECTRL_SHIFT
) &
109 UNIPHIER_PIN_IECTRL_MASK
;
112 static inline unsigned int uniphier_pin_get_drvctrl(void *drv_data
)
114 return ((unsigned long)drv_data
>> UNIPHIER_PIN_DRVCTRL_SHIFT
) &
115 UNIPHIER_PIN_DRVCTRL_MASK
;
118 static inline unsigned int uniphier_pin_get_drv_str(void *drv_data
)
120 return ((unsigned long)drv_data
>> UNIPHIER_PIN_DRV_STR_SHIFT
) &
121 UNIPHIER_PIN_DRV_STR_MASK
;
124 static inline unsigned int uniphier_pin_get_pupdctrl(void *drv_data
)
126 return ((unsigned long)drv_data
>> UNIPHIER_PIN_PUPDCTRL_SHIFT
) &
127 UNIPHIER_PIN_PUPDCTRL_MASK
;
130 static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data
)
132 return ((unsigned long)drv_data
>> UNIPHIER_PIN_PULL_DIR_SHIFT
) &
133 UNIPHIER_PIN_PULL_DIR_MASK
;
136 enum uniphier_pinmux_gpio_range_type
{
137 UNIPHIER_PINMUX_GPIO_RANGE_PORT
,
138 UNIPHIER_PINMUX_GPIO_RANGE_IRQ
,
139 UNIPHIER_PINMUX_GPIO_RANGE_NONE
,
142 struct uniphier_pinctrl_group
{
144 const unsigned *pins
;
146 const unsigned *muxvals
;
147 enum uniphier_pinmux_gpio_range_type range_type
;
150 struct uniphier_pinmux_function
{
152 const char * const *groups
;
156 struct uniphier_pinctrl_socdata
{
157 const struct uniphier_pinctrl_group
*groups
;
159 const struct uniphier_pinmux_function
*functions
;
166 #define UNIPHIER_PINCTRL_PIN(a, b, c, d, e, f, g) \
170 .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \
173 #define __UNIPHIER_PINCTRL_GROUP(grp, type) \
176 .pins = grp##_pins, \
177 .num_pins = ARRAY_SIZE(grp##_pins), \
178 .muxvals = grp##_muxvals + \
179 BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \
180 ARRAY_SIZE(grp##_muxvals)), \
181 .range_type = type, \
184 #define UNIPHIER_PINCTRL_GROUP(grp) \
185 __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_NONE)
187 #define UNIPHIER_PINCTRL_GROUP_GPIO_RANGE_PORT(grp) \
188 __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_PORT)
190 #define UNIPHIER_PINCTRL_GROUP_GPIO_RANGE_IRQ(grp) \
191 __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_IRQ)
193 #define UNIPHIER_PINCTRL_GROUP_SINGLE(grp, array, ofst) \
196 .pins = array##_pins + ofst, \
198 .muxvals = array##_muxvals + ofst, \
201 #define UNIPHIER_PINMUX_FUNCTION(func) \
204 .groups = func##_groups, \
205 .num_groups = ARRAY_SIZE(func##_groups), \
208 struct platform_device
;
211 int uniphier_pinctrl_probe(struct platform_device
*pdev
,
212 struct pinctrl_desc
*desc
,
213 struct uniphier_pinctrl_socdata
*socdata
);
215 int uniphier_pinctrl_remove(struct platform_device
*pdev
);
217 #endif /* __PINCTRL_UNIPHIER_H__ */