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