Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | fa1f73f | 2016-07-19 21:56:13 +0900 | [diff] [blame] | 3 | * Copyright (C) 2015-2016 Socionext Inc. |
| 4 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 7 | #include <common.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 9 | #include <linux/io.h> |
| 10 | #include <linux/err.h> |
Masahiro Yamada | 165c558 | 2017-10-13 19:21:54 +0900 | [diff] [blame] | 11 | #include <linux/kernel.h> |
Masahiro Yamada | fba3a66 | 2016-03-24 22:32:43 +0900 | [diff] [blame] | 12 | #include <linux/sizes.h> |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 13 | #include <dm/pinctrl.h> |
| 14 | |
| 15 | #include "pinctrl-uniphier.h" |
| 16 | |
Masahiro Yamada | a994520 | 2016-09-14 01:06:05 +0900 | [diff] [blame] | 17 | #define UNIPHIER_PINCTRL_PINMUX_BASE 0x1000 |
| 18 | #define UNIPHIER_PINCTRL_LOAD_PINMUX 0x1700 |
Masahiro Yamada | e5299ed | 2018-05-05 19:53:55 +0900 | [diff] [blame] | 19 | #define UNIPHIER_PINCTRL_DRVCTRL_BASE 0x1800 |
| 20 | #define UNIPHIER_PINCTRL_DRV2CTRL_BASE 0x1900 |
| 21 | #define UNIPHIER_PINCTRL_DRV3CTRL_BASE 0x1980 |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 22 | #define UNIPHIER_PINCTRL_PUPDCTRL_BASE 0x1a00 |
Masahiro Yamada | a994520 | 2016-09-14 01:06:05 +0900 | [diff] [blame] | 23 | #define UNIPHIER_PINCTRL_IECTRL 0x1d00 |
| 24 | |
Masahiro Yamada | 65ef4f7 | 2016-06-29 19:39:00 +0900 | [diff] [blame] | 25 | static const char *uniphier_pinctrl_dummy_name = "_dummy"; |
| 26 | |
Masahiro Yamada | 914b571 | 2018-05-05 19:53:54 +0900 | [diff] [blame] | 27 | static int uniphier_pinctrl_get_pins_count(struct udevice *dev) |
| 28 | { |
| 29 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 30 | const struct uniphier_pinctrl_pin *pins = priv->socdata->pins; |
| 31 | int pins_count = priv->socdata->pins_count; |
| 32 | |
| 33 | /* |
| 34 | * We do not list all pins in the pin table to save memory footprint. |
| 35 | * Report the max pin number + 1 to fake the framework. |
| 36 | */ |
| 37 | return pins[pins_count - 1].number + 1; |
| 38 | } |
| 39 | |
| 40 | static const char *uniphier_pinctrl_get_pin_name(struct udevice *dev, |
| 41 | unsigned int selector) |
| 42 | { |
| 43 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 44 | const struct uniphier_pinctrl_pin *pins = priv->socdata->pins; |
| 45 | int pins_count = priv->socdata->pins_count; |
| 46 | int i; |
| 47 | |
| 48 | for (i = 0; i < pins_count; i++) |
| 49 | if (pins[i].number == selector) |
| 50 | return pins[i].name; |
| 51 | |
| 52 | return uniphier_pinctrl_dummy_name; |
| 53 | } |
| 54 | |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 55 | static int uniphier_pinctrl_get_groups_count(struct udevice *dev) |
| 56 | { |
| 57 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 58 | |
| 59 | return priv->socdata->groups_count; |
| 60 | } |
| 61 | |
| 62 | static const char *uniphier_pinctrl_get_group_name(struct udevice *dev, |
| 63 | unsigned selector) |
| 64 | { |
| 65 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 66 | |
Masahiro Yamada | 65ef4f7 | 2016-06-29 19:39:00 +0900 | [diff] [blame] | 67 | if (!priv->socdata->groups[selector].name) |
| 68 | return uniphier_pinctrl_dummy_name; |
| 69 | |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 70 | return priv->socdata->groups[selector].name; |
| 71 | } |
| 72 | |
| 73 | static int uniphier_pinmux_get_functions_count(struct udevice *dev) |
| 74 | { |
| 75 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 76 | |
| 77 | return priv->socdata->functions_count; |
| 78 | } |
| 79 | |
| 80 | static const char *uniphier_pinmux_get_function_name(struct udevice *dev, |
| 81 | unsigned selector) |
| 82 | { |
| 83 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 84 | |
Masahiro Yamada | 65ef4f7 | 2016-06-29 19:39:00 +0900 | [diff] [blame] | 85 | if (!priv->socdata->functions[selector]) |
| 86 | return uniphier_pinctrl_dummy_name; |
| 87 | |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 88 | return priv->socdata->functions[selector]; |
| 89 | } |
| 90 | |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 91 | static int uniphier_pinconf_input_enable_perpin(struct udevice *dev, |
| 92 | unsigned int pin, int enable) |
Masahiro Yamada | 73e6775 | 2016-03-24 22:32:45 +0900 | [diff] [blame] | 93 | { |
| 94 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 95 | unsigned reg; |
| 96 | u32 mask, tmp; |
| 97 | |
| 98 | reg = UNIPHIER_PINCTRL_IECTRL + pin / 32 * 4; |
| 99 | mask = BIT(pin % 32); |
| 100 | |
| 101 | tmp = readl(priv->base + reg); |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 102 | if (enable) |
| 103 | tmp |= mask; |
| 104 | else |
| 105 | tmp &= ~mask; |
Masahiro Yamada | 73e6775 | 2016-03-24 22:32:45 +0900 | [diff] [blame] | 106 | writel(tmp, priv->base + reg); |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 107 | |
| 108 | return 0; |
Masahiro Yamada | 73e6775 | 2016-03-24 22:32:45 +0900 | [diff] [blame] | 109 | } |
| 110 | |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 111 | static int uniphier_pinconf_input_enable_legacy(struct udevice *dev, |
| 112 | unsigned int pin, int enable) |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 113 | { |
| 114 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 115 | |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 116 | /* |
| 117 | * Multiple pins share one input enable, per-pin disabling is |
| 118 | * impossible. |
| 119 | */ |
| 120 | if (!enable) |
| 121 | return -EINVAL; |
| 122 | |
Masahiro Yamada | 165c558 | 2017-10-13 19:21:54 +0900 | [diff] [blame] | 123 | /* Set all bits instead of having a bunch of pin data */ |
| 124 | writel(U32_MAX, priv->base + UNIPHIER_PINCTRL_IECTRL); |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 125 | |
| 126 | return 0; |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 127 | } |
| 128 | |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 129 | static int uniphier_pinconf_input_enable(struct udevice *dev, |
| 130 | unsigned int pin, int enable) |
Masahiro Yamada | 73e6775 | 2016-03-24 22:32:45 +0900 | [diff] [blame] | 131 | { |
| 132 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 133 | |
| 134 | if (priv->socdata->caps & UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL) |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 135 | return uniphier_pinconf_input_enable_perpin(dev, pin, enable); |
Masahiro Yamada | 73e6775 | 2016-03-24 22:32:45 +0900 | [diff] [blame] | 136 | else |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 137 | return uniphier_pinconf_input_enable_legacy(dev, pin, enable); |
Masahiro Yamada | 73e6775 | 2016-03-24 22:32:45 +0900 | [diff] [blame] | 138 | } |
| 139 | |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 140 | #if CONFIG_IS_ENABLED(PINCONF) |
| 141 | |
| 142 | static const struct pinconf_param uniphier_pinconf_params[] = { |
| 143 | { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 }, |
| 144 | { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 }, |
| 145 | { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 }, |
| 146 | { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 }, |
Masahiro Yamada | e5299ed | 2018-05-05 19:53:55 +0900 | [diff] [blame] | 147 | { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 }, |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 148 | { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 }, |
| 149 | { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 }, |
| 150 | }; |
| 151 | |
Masahiro Yamada | e5299ed | 2018-05-05 19:53:55 +0900 | [diff] [blame] | 152 | static const struct uniphier_pinctrl_pin * |
| 153 | uniphier_pinctrl_pin_get(struct uniphier_pinctrl_priv *priv, unsigned int pin) |
| 154 | { |
| 155 | const struct uniphier_pinctrl_pin *pins = priv->socdata->pins; |
| 156 | int pins_count = priv->socdata->pins_count; |
| 157 | int i; |
| 158 | |
| 159 | for (i = 0; i < pins_count; i++) |
| 160 | if (pins[i].number == pin) |
| 161 | return &pins[i]; |
| 162 | |
| 163 | return NULL; |
| 164 | } |
| 165 | |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 166 | static int uniphier_pinconf_bias_set(struct udevice *dev, unsigned int pin, |
| 167 | unsigned int param, unsigned int arg) |
| 168 | { |
| 169 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 170 | unsigned int enable = 1; |
| 171 | unsigned int reg; |
| 172 | u32 mask, tmp; |
| 173 | |
| 174 | if (!(priv->socdata->caps & UNIPHIER_PINCTRL_CAPS_PUPD_SIMPLE)) |
| 175 | return -ENOTSUPP; |
| 176 | |
| 177 | switch (param) { |
| 178 | case PIN_CONFIG_BIAS_DISABLE: |
| 179 | enable = 0; |
| 180 | break; |
| 181 | case PIN_CONFIG_BIAS_PULL_UP: |
| 182 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 183 | if (arg == 0) /* total bias is not supported */ |
| 184 | return -EINVAL; |
| 185 | break; |
| 186 | case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: |
| 187 | if (arg == 0) /* configuration ignored */ |
| 188 | return 0; |
| 189 | default: |
| 190 | BUG(); |
| 191 | } |
| 192 | |
| 193 | reg = UNIPHIER_PINCTRL_PUPDCTRL_BASE + pin / 32 * 4; |
| 194 | mask = BIT(pin % 32); |
| 195 | |
| 196 | tmp = readl(priv->base + reg); |
| 197 | if (enable) |
| 198 | tmp |= mask; |
| 199 | else |
| 200 | tmp &= ~mask; |
| 201 | writel(tmp, priv->base + reg); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Masahiro Yamada | e5299ed | 2018-05-05 19:53:55 +0900 | [diff] [blame] | 206 | static const unsigned int uniphier_pinconf_drv_strengths_1bit[] = { |
| 207 | 4, 8, |
| 208 | }; |
| 209 | |
| 210 | static const unsigned int uniphier_pinconf_drv_strengths_2bit[] = { |
| 211 | 8, 12, 16, 20, |
| 212 | }; |
| 213 | |
| 214 | static const unsigned int uniphier_pinconf_drv_strengths_3bit[] = { |
| 215 | 4, 5, 7, 9, 11, 12, 14, 16, |
| 216 | }; |
| 217 | |
| 218 | static int uniphier_pinconf_drive_set(struct udevice *dev, unsigned int pin, |
| 219 | unsigned int strength) |
| 220 | { |
| 221 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 222 | const struct uniphier_pinctrl_pin *desc; |
| 223 | const unsigned int *strengths; |
| 224 | unsigned int base, stride, width, drvctrl, reg, shift; |
| 225 | u32 val, mask, tmp; |
| 226 | |
| 227 | desc = uniphier_pinctrl_pin_get(priv, pin); |
| 228 | if (WARN_ON(!desc)) |
| 229 | return -EINVAL; |
| 230 | |
| 231 | switch (uniphier_pin_get_drv_type(desc->data)) { |
| 232 | case UNIPHIER_PIN_DRV_1BIT: |
| 233 | strengths = uniphier_pinconf_drv_strengths_1bit; |
| 234 | base = UNIPHIER_PINCTRL_DRVCTRL_BASE; |
| 235 | stride = 1; |
| 236 | width = 1; |
| 237 | break; |
| 238 | case UNIPHIER_PIN_DRV_2BIT: |
| 239 | strengths = uniphier_pinconf_drv_strengths_2bit; |
| 240 | base = UNIPHIER_PINCTRL_DRV2CTRL_BASE; |
| 241 | stride = 2; |
| 242 | width = 2; |
| 243 | break; |
| 244 | case UNIPHIER_PIN_DRV_3BIT: |
| 245 | strengths = uniphier_pinconf_drv_strengths_3bit; |
| 246 | base = UNIPHIER_PINCTRL_DRV3CTRL_BASE; |
| 247 | stride = 4; |
| 248 | width = 3; |
| 249 | break; |
| 250 | default: |
| 251 | /* drive strength control is not supported for this pin */ |
| 252 | return -EINVAL; |
| 253 | } |
| 254 | |
| 255 | drvctrl = uniphier_pin_get_drvctrl(desc->data); |
| 256 | drvctrl *= stride; |
| 257 | |
| 258 | reg = base + drvctrl / 32 * 4; |
| 259 | shift = drvctrl % 32; |
| 260 | mask = (1U << width) - 1; |
| 261 | |
| 262 | for (val = 0; val <= mask; val++) { |
| 263 | if (strengths[val] > strength) |
| 264 | break; |
| 265 | } |
| 266 | |
| 267 | if (val == 0) { |
| 268 | dev_err(dev, "unsupported drive strength %u mA for pin %s\n", |
| 269 | strength, desc->name); |
| 270 | return -EINVAL; |
| 271 | } |
| 272 | |
| 273 | if (!mask) |
| 274 | return 0; |
| 275 | |
| 276 | val--; |
| 277 | |
| 278 | tmp = readl(priv->base + reg); |
| 279 | tmp &= ~(mask << shift); |
| 280 | tmp |= (mask & val) << shift; |
| 281 | writel(tmp, priv->base + reg); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
Masahiro Yamada | 914b571 | 2018-05-05 19:53:54 +0900 | [diff] [blame] | 286 | static int uniphier_pinconf_set(struct udevice *dev, unsigned int pin, |
| 287 | unsigned int param, unsigned int arg) |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 288 | { |
| 289 | int ret; |
| 290 | |
| 291 | switch (param) { |
| 292 | case PIN_CONFIG_BIAS_DISABLE: |
| 293 | case PIN_CONFIG_BIAS_PULL_UP: |
| 294 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 295 | case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: |
| 296 | ret = uniphier_pinconf_bias_set(dev, pin, param, arg); |
| 297 | break; |
Masahiro Yamada | e5299ed | 2018-05-05 19:53:55 +0900 | [diff] [blame] | 298 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 299 | ret = uniphier_pinconf_drive_set(dev, pin, arg); |
| 300 | break; |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 301 | case PIN_CONFIG_INPUT_ENABLE: |
| 302 | ret = uniphier_pinconf_input_enable(dev, pin, arg); |
| 303 | break; |
| 304 | default: |
Masahiro Yamada | 4bffb14 | 2018-05-05 19:53:52 +0900 | [diff] [blame] | 305 | dev_err(dev, "unsupported configuration parameter %u\n", param); |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 306 | return -EINVAL; |
| 307 | } |
| 308 | |
| 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | static int uniphier_pinconf_group_set(struct udevice *dev, |
| 313 | unsigned int group_selector, |
| 314 | unsigned int param, unsigned int arg) |
| 315 | { |
| 316 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 317 | const struct uniphier_pinctrl_group *grp = |
| 318 | &priv->socdata->groups[group_selector]; |
| 319 | int i, ret; |
| 320 | |
| 321 | for (i = 0; i < grp->num_pins; i++) { |
Masahiro Yamada | 914b571 | 2018-05-05 19:53:54 +0900 | [diff] [blame] | 322 | ret = uniphier_pinconf_set(dev, grp->pins[i], param, arg); |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 323 | if (ret) |
| 324 | return ret; |
| 325 | } |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | #endif /* CONFIG_IS_ENABLED(PINCONF) */ |
| 331 | |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 332 | static void uniphier_pinmux_set_one(struct udevice *dev, unsigned pin, |
Masahiro Yamada | 9447e13 | 2016-06-29 19:38:59 +0900 | [diff] [blame] | 333 | int muxval) |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 334 | { |
| 335 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
Masahiro Yamada | c3380ed | 2016-09-17 03:32:58 +0900 | [diff] [blame] | 336 | unsigned reg, reg_end, shift, mask; |
| 337 | unsigned mux_bits = 8; |
| 338 | unsigned reg_stride = 4; |
| 339 | bool load_pinctrl = false; |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 340 | u32 tmp; |
| 341 | |
Masahiro Yamada | a64e11a | 2016-03-04 15:56:16 +0900 | [diff] [blame] | 342 | /* some pins need input-enabling */ |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 343 | uniphier_pinconf_input_enable(dev, pin, 1); |
Masahiro Yamada | a64e11a | 2016-03-04 15:56:16 +0900 | [diff] [blame] | 344 | |
Masahiro Yamada | 9447e13 | 2016-06-29 19:38:59 +0900 | [diff] [blame] | 345 | if (muxval < 0) |
| 346 | return; /* dedicated pin; nothing to do for pin-mux */ |
| 347 | |
Masahiro Yamada | c3380ed | 2016-09-17 03:32:58 +0900 | [diff] [blame] | 348 | if (priv->socdata->caps & UNIPHIER_PINCTRL_CAPS_MUX_4BIT) |
| 349 | mux_bits = 4; |
| 350 | |
Masahiro Yamada | 7a629ef | 2016-03-24 22:32:44 +0900 | [diff] [blame] | 351 | if (priv->socdata->caps & UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE) { |
| 352 | /* |
| 353 | * Mode offset bit |
| 354 | * Normal 4 * n shift+3:shift |
| 355 | * Debug 4 * n shift+7:shift+4 |
| 356 | */ |
Masahiro Yamada | c3380ed | 2016-09-17 03:32:58 +0900 | [diff] [blame] | 357 | mux_bits /= 2; |
Masahiro Yamada | 7a629ef | 2016-03-24 22:32:44 +0900 | [diff] [blame] | 358 | reg_stride = 8; |
| 359 | load_pinctrl = true; |
Masahiro Yamada | 7a629ef | 2016-03-24 22:32:44 +0900 | [diff] [blame] | 360 | } |
| 361 | |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 362 | reg = UNIPHIER_PINCTRL_PINMUX_BASE + pin * mux_bits / 32 * reg_stride; |
| 363 | reg_end = reg + reg_stride; |
| 364 | shift = pin * mux_bits % 32; |
| 365 | mask = (1U << mux_bits) - 1; |
| 366 | |
| 367 | /* |
| 368 | * If reg_stride is greater than 4, the MSB of each pinsel shall be |
| 369 | * stored in the offset+4. |
| 370 | */ |
| 371 | for (; reg < reg_end; reg += 4) { |
| 372 | tmp = readl(priv->base + reg); |
| 373 | tmp &= ~(mask << shift); |
| 374 | tmp |= (mask & muxval) << shift; |
| 375 | writel(tmp, priv->base + reg); |
| 376 | |
| 377 | muxval >>= mux_bits; |
| 378 | } |
| 379 | |
Masahiro Yamada | 7a629ef | 2016-03-24 22:32:44 +0900 | [diff] [blame] | 380 | if (load_pinctrl) |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 381 | writel(1, priv->base + UNIPHIER_PINCTRL_LOAD_PINMUX); |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static int uniphier_pinmux_group_set(struct udevice *dev, |
| 385 | unsigned group_selector, |
| 386 | unsigned func_selector) |
| 387 | { |
| 388 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 389 | const struct uniphier_pinctrl_group *grp = |
| 390 | &priv->socdata->groups[group_selector]; |
| 391 | int i; |
| 392 | |
| 393 | for (i = 0; i < grp->num_pins; i++) |
| 394 | uniphier_pinmux_set_one(dev, grp->pins[i], grp->muxvals[i]); |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | const struct pinctrl_ops uniphier_pinctrl_ops = { |
Masahiro Yamada | 914b571 | 2018-05-05 19:53:54 +0900 | [diff] [blame] | 400 | .get_pins_count = uniphier_pinctrl_get_pins_count, |
| 401 | .get_pin_name = uniphier_pinctrl_get_pin_name, |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 402 | .get_groups_count = uniphier_pinctrl_get_groups_count, |
| 403 | .get_group_name = uniphier_pinctrl_get_group_name, |
| 404 | .get_functions_count = uniphier_pinmux_get_functions_count, |
| 405 | .get_function_name = uniphier_pinmux_get_function_name, |
| 406 | .pinmux_group_set = uniphier_pinmux_group_set, |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 407 | #if CONFIG_IS_ENABLED(PINCONF) |
| 408 | .pinconf_num_params = ARRAY_SIZE(uniphier_pinconf_params), |
| 409 | .pinconf_params = uniphier_pinconf_params, |
Masahiro Yamada | 914b571 | 2018-05-05 19:53:54 +0900 | [diff] [blame] | 410 | .pinconf_set = uniphier_pinconf_set, |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 411 | .pinconf_group_set = uniphier_pinconf_group_set, |
| 412 | #endif |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 413 | .set_state = pinctrl_generic_set_state, |
| 414 | }; |
| 415 | |
| 416 | int uniphier_pinctrl_probe(struct udevice *dev, |
| 417 | struct uniphier_pinctrl_socdata *socdata) |
| 418 | { |
| 419 | struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); |
| 420 | fdt_addr_t addr; |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 421 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 422 | addr = devfdt_get_addr(dev->parent); |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 423 | if (addr == FDT_ADDR_T_NONE) |
| 424 | return -EINVAL; |
| 425 | |
Masahiro Yamada | fa1f73f | 2016-07-19 21:56:13 +0900 | [diff] [blame] | 426 | priv->base = devm_ioremap(dev, addr, SZ_4K); |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 427 | if (!priv->base) |
| 428 | return -ENOMEM; |
| 429 | |
| 430 | priv->socdata = socdata; |
| 431 | |
| 432 | return 0; |
| 433 | } |