Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 - Beniamino Galvani <b.galvani@gmail.com> |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 11 | #include <dm/device-internal.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <dm/device_compat.h> |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 13 | #include <dm/lists.h> |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 14 | #include <dm/pinctrl.h> |
| 15 | #include <fdt_support.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 16 | #include <linux/bitops.h> |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 17 | #include <linux/err.h> |
| 18 | #include <linux/io.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 19 | #include <linux/libfdt.h> |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 20 | #include <linux/sizes.h> |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 21 | #include <asm/gpio.h> |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 22 | |
| 23 | #include "pinctrl-meson.h" |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | static const char *meson_pinctrl_dummy_name = "_dummy"; |
| 28 | |
Neil Armstrong | a5ea157 | 2019-06-04 11:04:52 +0200 | [diff] [blame] | 29 | static char pin_name[PINNAME_SIZE]; |
| 30 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 31 | int meson_pinctrl_get_groups_count(struct udevice *dev) |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 32 | { |
| 33 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 34 | |
| 35 | return priv->data->num_groups; |
| 36 | } |
| 37 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 38 | const char *meson_pinctrl_get_group_name(struct udevice *dev, |
| 39 | unsigned int selector) |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 40 | { |
| 41 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 42 | |
| 43 | if (!priv->data->groups[selector].name) |
| 44 | return meson_pinctrl_dummy_name; |
| 45 | |
| 46 | return priv->data->groups[selector].name; |
| 47 | } |
| 48 | |
Neil Armstrong | a5ea157 | 2019-06-04 11:04:52 +0200 | [diff] [blame] | 49 | int meson_pinctrl_get_pins_count(struct udevice *dev) |
| 50 | { |
| 51 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 52 | |
| 53 | return priv->data->num_pins; |
| 54 | } |
| 55 | |
| 56 | const char *meson_pinctrl_get_pin_name(struct udevice *dev, |
| 57 | unsigned int selector) |
| 58 | { |
| 59 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 60 | |
| 61 | if (selector > priv->data->num_pins || |
| 62 | selector > priv->data->funcs[0].num_groups) |
| 63 | snprintf(pin_name, PINNAME_SIZE, "Error"); |
| 64 | else |
| 65 | snprintf(pin_name, PINNAME_SIZE, "%s", |
| 66 | priv->data->funcs[0].groups[selector]); |
| 67 | |
| 68 | return pin_name; |
| 69 | } |
| 70 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 71 | int meson_pinmux_get_functions_count(struct udevice *dev) |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 72 | { |
| 73 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 74 | |
| 75 | return priv->data->num_funcs; |
| 76 | } |
| 77 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 78 | const char *meson_pinmux_get_function_name(struct udevice *dev, |
| 79 | unsigned int selector) |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 80 | { |
| 81 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 82 | |
| 83 | return priv->data->funcs[selector].name; |
| 84 | } |
| 85 | |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 86 | static int meson_gpio_calc_reg_and_bit(struct udevice *dev, unsigned int offset, |
| 87 | enum meson_reg_type reg_type, |
| 88 | unsigned int *reg, unsigned int *bit) |
| 89 | { |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 90 | struct meson_pinctrl *priv = dev_get_priv(dev); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 91 | struct meson_bank *bank = NULL; |
| 92 | struct meson_reg_desc *desc; |
| 93 | unsigned int pin; |
| 94 | int i; |
| 95 | |
| 96 | pin = priv->data->pin_base + offset; |
| 97 | |
| 98 | for (i = 0; i < priv->data->num_banks; i++) { |
| 99 | if (pin >= priv->data->banks[i].first && |
| 100 | pin <= priv->data->banks[i].last) { |
| 101 | bank = &priv->data->banks[i]; |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (!bank) |
| 107 | return -EINVAL; |
| 108 | |
| 109 | desc = &bank->regs[reg_type]; |
| 110 | *reg = desc->reg * 4; |
| 111 | *bit = desc->bit + pin - bank->first; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 116 | int meson_gpio_get(struct udevice *dev, unsigned int offset) |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 117 | { |
| 118 | struct meson_pinctrl *priv = dev_get_priv(dev->parent); |
| 119 | unsigned int reg, bit; |
| 120 | int ret; |
| 121 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 122 | ret = meson_gpio_calc_reg_and_bit(dev->parent, offset, REG_IN, ®, |
| 123 | &bit); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 124 | if (ret) |
| 125 | return ret; |
| 126 | |
| 127 | return !!(readl(priv->reg_gpio + reg) & BIT(bit)); |
| 128 | } |
| 129 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 130 | int meson_gpio_set(struct udevice *dev, unsigned int offset, int value) |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 131 | { |
| 132 | struct meson_pinctrl *priv = dev_get_priv(dev->parent); |
| 133 | unsigned int reg, bit; |
| 134 | int ret; |
| 135 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 136 | ret = meson_gpio_calc_reg_and_bit(dev->parent, offset, REG_OUT, ®, |
| 137 | &bit); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 138 | if (ret) |
| 139 | return ret; |
| 140 | |
| 141 | clrsetbits_le32(priv->reg_gpio + reg, BIT(bit), value ? BIT(bit) : 0); |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 146 | int meson_gpio_get_direction(struct udevice *dev, unsigned int offset) |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 147 | { |
| 148 | struct meson_pinctrl *priv = dev_get_priv(dev->parent); |
| 149 | unsigned int reg, bit, val; |
| 150 | int ret; |
| 151 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 152 | ret = meson_gpio_calc_reg_and_bit(dev->parent, offset, REG_DIR, ®, |
| 153 | &bit); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 154 | if (ret) |
| 155 | return ret; |
| 156 | |
| 157 | val = readl(priv->reg_gpio + reg); |
| 158 | |
| 159 | return (val & BIT(bit)) ? GPIOF_INPUT : GPIOF_OUTPUT; |
| 160 | } |
| 161 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 162 | int meson_gpio_direction_input(struct udevice *dev, unsigned int offset) |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 163 | { |
| 164 | struct meson_pinctrl *priv = dev_get_priv(dev->parent); |
| 165 | unsigned int reg, bit; |
| 166 | int ret; |
| 167 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 168 | ret = meson_gpio_calc_reg_and_bit(dev->parent, offset, REG_DIR, ®, |
| 169 | &bit); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 170 | if (ret) |
| 171 | return ret; |
| 172 | |
Carlo Caione | b380570 | 2018-12-03 18:00:42 +0000 | [diff] [blame] | 173 | setbits_le32(priv->reg_gpio + reg, BIT(bit)); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 178 | int meson_gpio_direction_output(struct udevice *dev, |
| 179 | unsigned int offset, int value) |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 180 | { |
| 181 | struct meson_pinctrl *priv = dev_get_priv(dev->parent); |
| 182 | unsigned int reg, bit; |
| 183 | int ret; |
| 184 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 185 | ret = meson_gpio_calc_reg_and_bit(dev->parent, offset, REG_DIR, ®, |
| 186 | &bit); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 187 | if (ret) |
| 188 | return ret; |
| 189 | |
Carlo Caione | b380570 | 2018-12-03 18:00:42 +0000 | [diff] [blame] | 190 | clrbits_le32(priv->reg_gpio + reg, BIT(bit)); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 191 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 192 | ret = meson_gpio_calc_reg_and_bit(dev->parent, offset, REG_OUT, ®, |
| 193 | &bit); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 194 | if (ret) |
| 195 | return ret; |
| 196 | |
| 197 | clrsetbits_le32(priv->reg_gpio + reg, BIT(bit), value ? BIT(bit) : 0); |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 202 | static int meson_pinconf_bias_set(struct udevice *dev, unsigned int pin, |
| 203 | unsigned int param) |
| 204 | { |
| 205 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 206 | unsigned int offset = pin - priv->data->pin_base; |
| 207 | unsigned int reg, bit; |
| 208 | int ret; |
| 209 | |
| 210 | ret = meson_gpio_calc_reg_and_bit(dev, offset, REG_PULLEN, ®, &bit); |
| 211 | if (ret) |
| 212 | return ret; |
| 213 | |
| 214 | if (param == PIN_CONFIG_BIAS_DISABLE) { |
| 215 | clrsetbits_le32(priv->reg_pullen + reg, BIT(bit), 0); |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | /* othewise, enable the bias and select level */ |
Neil Armstrong | cf1b569 | 2020-12-14 19:39:07 +0100 | [diff] [blame] | 220 | clrsetbits_le32(priv->reg_pullen + reg, BIT(bit), BIT(bit)); |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 221 | ret = meson_gpio_calc_reg_and_bit(dev, offset, REG_PULL, ®, &bit); |
| 222 | if (ret) |
| 223 | return ret; |
| 224 | |
| 225 | clrsetbits_le32(priv->reg_pull + reg, BIT(bit), |
Neil Armstrong | cf1b569 | 2020-12-14 19:39:07 +0100 | [diff] [blame] | 226 | (param == PIN_CONFIG_BIAS_PULL_UP ? BIT(bit) : 0)); |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Guillaume La Roque | 3076735 | 2019-06-04 13:53:07 +0200 | [diff] [blame] | 231 | static int meson_pinconf_drive_strength_set(struct udevice *dev, |
| 232 | unsigned int pin, |
| 233 | unsigned int drive_strength_ua) |
| 234 | { |
| 235 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 236 | unsigned int offset = pin - priv->data->pin_base; |
| 237 | unsigned int reg, bit; |
| 238 | unsigned int ds_val; |
| 239 | int ret; |
| 240 | |
| 241 | if (!priv->reg_ds) { |
| 242 | dev_err(dev, "drive-strength-microamp not supported\n"); |
| 243 | return -ENOTSUPP; |
| 244 | } |
| 245 | |
| 246 | ret = meson_gpio_calc_reg_and_bit(dev, offset, REG_DS, ®, &bit); |
| 247 | if (ret) |
| 248 | return ret; |
| 249 | |
| 250 | bit = bit << 1; |
| 251 | |
| 252 | if (drive_strength_ua <= 500) { |
| 253 | ds_val = MESON_PINCONF_DRV_500UA; |
| 254 | } else if (drive_strength_ua <= 2500) { |
| 255 | ds_val = MESON_PINCONF_DRV_2500UA; |
| 256 | } else if (drive_strength_ua <= 3000) { |
| 257 | ds_val = MESON_PINCONF_DRV_3000UA; |
| 258 | } else if (drive_strength_ua <= 4000) { |
| 259 | ds_val = MESON_PINCONF_DRV_4000UA; |
| 260 | } else { |
| 261 | dev_warn(dev, |
| 262 | "pin %u: invalid drive-strength-microamp : %d , default to 4mA\n", |
| 263 | pin, drive_strength_ua); |
| 264 | ds_val = MESON_PINCONF_DRV_4000UA; |
| 265 | } |
| 266 | |
| 267 | clrsetbits_le32(priv->reg_ds + reg, 0x3 << bit, ds_val << bit); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 272 | int meson_pinconf_set(struct udevice *dev, unsigned int pin, |
| 273 | unsigned int param, unsigned int arg) |
| 274 | { |
| 275 | int ret; |
| 276 | |
| 277 | switch (param) { |
| 278 | case PIN_CONFIG_BIAS_DISABLE: |
| 279 | case PIN_CONFIG_BIAS_PULL_UP: |
| 280 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 281 | ret = meson_pinconf_bias_set(dev, pin, param); |
| 282 | break; |
Guillaume La Roque | 3076735 | 2019-06-04 13:53:07 +0200 | [diff] [blame] | 283 | case PIN_CONFIG_DRIVE_STRENGTH_UA: |
| 284 | ret = meson_pinconf_drive_strength_set(dev, pin, arg); |
| 285 | break; |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 286 | default: |
| 287 | dev_err(dev, "unsupported configuration parameter %u\n", param); |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | |
| 291 | return ret; |
| 292 | } |
| 293 | |
| 294 | int meson_pinconf_group_set(struct udevice *dev, |
| 295 | unsigned int group_selector, |
| 296 | unsigned int param, unsigned int arg) |
| 297 | { |
| 298 | struct meson_pinctrl *priv = dev_get_priv(dev); |
| 299 | struct meson_pmx_group *grp = &priv->data->groups[group_selector]; |
| 300 | int i, ret; |
| 301 | |
| 302 | for (i = 0; i < grp->num_pins; i++) { |
| 303 | ret = meson_pinconf_set(dev, grp->pins[i], param, arg); |
| 304 | if (ret) |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 311 | int meson_gpio_probe(struct udevice *dev) |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 312 | { |
| 313 | struct meson_pinctrl *priv = dev_get_priv(dev->parent); |
| 314 | struct gpio_dev_priv *uc_priv; |
| 315 | |
| 316 | uc_priv = dev_get_uclass_priv(dev); |
| 317 | uc_priv->bank_name = priv->data->name; |
| 318 | uc_priv->gpio_count = priv->data->num_pins; |
| 319 | |
| 320 | return 0; |
| 321 | } |
| 322 | |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 323 | static fdt_addr_t parse_address(int offset, const char *name, int na, int ns) |
| 324 | { |
| 325 | int index, len = 0; |
| 326 | const fdt32_t *reg; |
| 327 | |
Simon Glass | b0ea740 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 328 | index = fdt_stringlist_search(gd->fdt_blob, offset, "reg-names", name); |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 329 | if (index < 0) |
| 330 | return FDT_ADDR_T_NONE; |
| 331 | |
| 332 | reg = fdt_getprop(gd->fdt_blob, offset, "reg", &len); |
| 333 | if (!reg || (len <= (index * sizeof(fdt32_t) * (na + ns)))) |
| 334 | return FDT_ADDR_T_NONE; |
| 335 | |
| 336 | reg += index * (na + ns); |
| 337 | |
| 338 | return fdt_translate_address((void *)gd->fdt_blob, offset, reg); |
| 339 | } |
| 340 | |
| 341 | int meson_pinctrl_probe(struct udevice *dev) |
| 342 | { |
| 343 | struct meson_pinctrl *priv = dev_get_priv(dev); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 344 | struct uclass_driver *drv; |
| 345 | struct udevice *gpio_dev; |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 346 | fdt_addr_t addr; |
| 347 | int node, gpio = -1, len; |
| 348 | int na, ns; |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 349 | char *name; |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 350 | |
Simon Glass | 6996c66 | 2020-11-28 17:50:03 -0700 | [diff] [blame] | 351 | /* FIXME: Should use livetree */ |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 352 | na = fdt_address_cells(gd->fdt_blob, dev_of_offset(dev->parent)); |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 353 | if (na < 1) { |
| 354 | debug("bad #address-cells\n"); |
| 355 | return -EINVAL; |
| 356 | } |
| 357 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 358 | ns = fdt_size_cells(gd->fdt_blob, dev_of_offset(dev->parent)); |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 359 | if (ns < 1) { |
| 360 | debug("bad #size-cells\n"); |
| 361 | return -EINVAL; |
| 362 | } |
| 363 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 364 | fdt_for_each_subnode(node, gd->fdt_blob, dev_of_offset(dev)) { |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 365 | if (fdt_getprop(gd->fdt_blob, node, "gpio-controller", &len)) { |
| 366 | gpio = node; |
| 367 | break; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (!gpio) { |
| 372 | debug("gpio node not found\n"); |
| 373 | return -EINVAL; |
| 374 | } |
| 375 | |
| 376 | addr = parse_address(gpio, "mux", na, ns); |
| 377 | if (addr == FDT_ADDR_T_NONE) { |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 378 | debug("mux address not found\n"); |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 379 | return -EINVAL; |
| 380 | } |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 381 | priv->reg_mux = (void __iomem *)addr; |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 382 | |
| 383 | addr = parse_address(gpio, "gpio", na, ns); |
| 384 | if (addr == FDT_ADDR_T_NONE) { |
| 385 | debug("gpio address not found\n"); |
| 386 | return -EINVAL; |
| 387 | } |
| 388 | priv->reg_gpio = (void __iomem *)addr; |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 389 | |
| 390 | addr = parse_address(gpio, "pull", na, ns); |
Jerome Brunet | 0ff3cd0 | 2019-02-08 17:40:57 +0100 | [diff] [blame] | 391 | /* Use gpio region if pull one is not present */ |
| 392 | if (addr == FDT_ADDR_T_NONE) |
| 393 | priv->reg_pull = priv->reg_gpio; |
| 394 | else |
| 395 | priv->reg_pull = (void __iomem *)addr; |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 396 | |
| 397 | addr = parse_address(gpio, "pull-enable", na, ns); |
| 398 | /* Use pull region if pull-enable one is not present */ |
| 399 | if (addr == FDT_ADDR_T_NONE) |
| 400 | priv->reg_pullen = priv->reg_pull; |
| 401 | else |
| 402 | priv->reg_pullen = (void __iomem *)addr; |
| 403 | |
Jerome Brunet | 0ff3cd0 | 2019-02-08 17:40:57 +0100 | [diff] [blame] | 404 | addr = parse_address(gpio, "ds", na, ns); |
| 405 | /* Drive strength region is optional */ |
| 406 | if (addr == FDT_ADDR_T_NONE) |
| 407 | priv->reg_ds = NULL; |
| 408 | else |
| 409 | priv->reg_ds = (void __iomem *)addr; |
| 410 | |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 411 | priv->data = (struct meson_pinctrl_data *)dev_get_driver_data(dev); |
| 412 | |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 413 | /* Lookup GPIO driver */ |
| 414 | drv = lists_uclass_lookup(UCLASS_GPIO); |
| 415 | if (!drv) { |
| 416 | puts("Cannot find GPIO driver\n"); |
| 417 | return -ENOENT; |
| 418 | } |
| 419 | |
| 420 | name = calloc(1, 32); |
| 421 | sprintf(name, "meson-gpio"); |
| 422 | |
| 423 | /* Create child device UCLASS_GPIO and bind it */ |
Simon Glass | 6996c66 | 2020-11-28 17:50:03 -0700 | [diff] [blame] | 424 | device_bind(dev, priv->data->gpio_driver, name, NULL, |
| 425 | offset_to_ofnode(gpio), &gpio_dev); |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 426 | |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 427 | return 0; |
| 428 | } |