Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Delaunay | b953ec2 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_PINCTRL |
| 7 | |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <dm/device_compat.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 13 | #include <linux/err.h> |
| 14 | #include <linux/list.h> |
Simon Glass | 9d92245 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 15 | #include <dm.h> |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 16 | #include <dm/lists.h> |
| 17 | #include <dm/pinctrl.h> |
Heiko Stübner | 27326c7 | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 18 | #include <dm/util.h> |
Kever Yang | 1e656ad | 2018-02-09 10:56:24 +0800 | [diff] [blame] | 19 | #include <dm/of_access.h> |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | #if CONFIG_IS_ENABLED(PINCTRL_FULL) |
| 24 | /** |
| 25 | * pinctrl_config_one() - apply pinctrl settings for a single node |
| 26 | * |
| 27 | * @config: pin configuration node |
| 28 | * @return: 0 on success, or negative error code on failure |
| 29 | */ |
| 30 | static int pinctrl_config_one(struct udevice *config) |
| 31 | { |
| 32 | struct udevice *pctldev; |
| 33 | const struct pinctrl_ops *ops; |
| 34 | |
| 35 | pctldev = config; |
| 36 | for (;;) { |
| 37 | pctldev = dev_get_parent(pctldev); |
| 38 | if (!pctldev) { |
| 39 | dev_err(config, "could not find pctldev\n"); |
| 40 | return -EINVAL; |
| 41 | } |
| 42 | if (pctldev->uclass->uc_drv->id == UCLASS_PINCTRL) |
| 43 | break; |
| 44 | } |
| 45 | |
| 46 | ops = pinctrl_get_ops(pctldev); |
| 47 | return ops->set_state(pctldev, config); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * pinctrl_select_state_full() - full implementation of pinctrl_select_state |
| 52 | * |
| 53 | * @dev: peripheral device |
| 54 | * @statename: state name, like "default" |
| 55 | * @return: 0 on success, or negative error code on failure |
| 56 | */ |
| 57 | static int pinctrl_select_state_full(struct udevice *dev, const char *statename) |
| 58 | { |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 59 | char propname[32]; /* long enough */ |
| 60 | const fdt32_t *list; |
| 61 | uint32_t phandle; |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 62 | struct udevice *config; |
| 63 | int state, size, i, ret; |
| 64 | |
Kever Yang | 1e656ad | 2018-02-09 10:56:24 +0800 | [diff] [blame] | 65 | state = dev_read_stringlist_search(dev, "pinctrl-names", statename); |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 66 | if (state < 0) { |
| 67 | char *end; |
| 68 | /* |
| 69 | * If statename is not found in "pinctrl-names", |
| 70 | * assume statename is just the integer state ID. |
| 71 | */ |
Simon Glass | 0b1284e | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 72 | state = dectoul(statename, &end); |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 73 | if (*end) |
| 74 | return -EINVAL; |
| 75 | } |
| 76 | |
| 77 | snprintf(propname, sizeof(propname), "pinctrl-%d", state); |
Kever Yang | 1e656ad | 2018-02-09 10:56:24 +0800 | [diff] [blame] | 78 | list = dev_read_prop(dev, propname, &size); |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 79 | if (!list) |
| 80 | return -EINVAL; |
| 81 | |
| 82 | size /= sizeof(*list); |
| 83 | for (i = 0; i < size; i++) { |
| 84 | phandle = fdt32_to_cpu(*list++); |
Kever Yang | 1e656ad | 2018-02-09 10:56:24 +0800 | [diff] [blame] | 85 | ret = uclass_get_device_by_phandle_id(UCLASS_PINCONFIG, phandle, |
| 86 | &config); |
Michael Trimarchi | 36a90ed | 2019-09-17 22:06:03 +0200 | [diff] [blame] | 87 | if (ret) { |
| 88 | dev_warn(dev, "%s: uclass_get_device_by_phandle_id: err=%d\n", |
| 89 | __func__, ret); |
| 90 | continue; |
| 91 | } |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 92 | |
| 93 | ret = pinctrl_config_one(config); |
Michael Trimarchi | 36a90ed | 2019-09-17 22:06:03 +0200 | [diff] [blame] | 94 | if (ret) { |
| 95 | dev_warn(dev, "%s: pinctrl_config_one: err=%d\n", |
| 96 | __func__, ret); |
| 97 | continue; |
| 98 | } |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /** |
Masahiro Yamada | f835706 | 2016-08-19 18:26:54 +0900 | [diff] [blame] | 105 | * pinconfig_post_bind() - post binding for PINCONFIG uclass |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 106 | * Recursively bind its children as pinconfig devices. |
| 107 | * |
| 108 | * @dev: pinconfig device |
| 109 | * @return: 0 on success, or negative error code on failure |
| 110 | */ |
| 111 | static int pinconfig_post_bind(struct udevice *dev) |
| 112 | { |
Simon Glass | 5589a81 | 2015-12-29 05:22:52 -0700 | [diff] [blame] | 113 | bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC); |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 114 | const char *name; |
Simon Glass | 45a2686 | 2017-05-18 20:09:07 -0600 | [diff] [blame] | 115 | ofnode node; |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 116 | int ret; |
| 117 | |
Simon Glass | 7d14ee4 | 2020-12-19 10:40:13 -0700 | [diff] [blame] | 118 | if (!dev_has_ofnode(dev)) |
Urja Rannikko | 6340283 | 2019-03-22 19:14:33 +0000 | [diff] [blame] | 119 | return 0; |
| 120 | |
Simon Glass | 45a2686 | 2017-05-18 20:09:07 -0600 | [diff] [blame] | 121 | dev_for_each_subnode(node, dev) { |
Lukasz Majewski | b6a6238 | 2019-01-09 23:05:02 +0100 | [diff] [blame] | 122 | if (pre_reloc_only && |
| 123 | !ofnode_pre_reloc(node)) |
Simon Glass | 5589a81 | 2015-12-29 05:22:52 -0700 | [diff] [blame] | 124 | continue; |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 125 | /* |
| 126 | * If this node has "compatible" property, this is not |
| 127 | * a pin configuration node, but a normal device. skip. |
| 128 | */ |
Masahiro Yamada | 61e51ba | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 129 | ofnode_get_property(node, "compatible", &ret); |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 130 | if (ret >= 0) |
| 131 | continue; |
Patrick Delaunay | d39e2bd | 2019-02-25 13:39:56 +0100 | [diff] [blame] | 132 | /* If this node has "gpio-controller" property, skip */ |
| 133 | if (ofnode_read_bool(node, "gpio-controller")) |
| 134 | continue; |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 135 | |
| 136 | if (ret != -FDT_ERR_NOTFOUND) |
| 137 | return ret; |
| 138 | |
Simon Glass | 45a2686 | 2017-05-18 20:09:07 -0600 | [diff] [blame] | 139 | name = ofnode_get_name(node); |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 140 | if (!name) |
| 141 | return -EINVAL; |
| 142 | ret = device_bind_driver_to_node(dev, "pinconfig", name, |
Simon Glass | 45a2686 | 2017-05-18 20:09:07 -0600 | [diff] [blame] | 143 | node, NULL); |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 144 | if (ret) |
| 145 | return ret; |
| 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | UCLASS_DRIVER(pinconfig) = { |
| 152 | .id = UCLASS_PINCONFIG, |
Patrick Delaunay | 44510da | 2019-10-21 15:02:40 +0200 | [diff] [blame] | 153 | #if CONFIG_IS_ENABLED(PINCONF_RECURSIVE) |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 154 | .post_bind = pinconfig_post_bind, |
Patrick Delaunay | c20851b | 2019-08-02 14:48:00 +0200 | [diff] [blame] | 155 | #endif |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 156 | .name = "pinconfig", |
| 157 | }; |
| 158 | |
| 159 | U_BOOT_DRIVER(pinconfig_generic) = { |
| 160 | .name = "pinconfig", |
| 161 | .id = UCLASS_PINCONFIG, |
| 162 | }; |
| 163 | |
| 164 | #else |
| 165 | static int pinctrl_select_state_full(struct udevice *dev, const char *statename) |
| 166 | { |
| 167 | return -ENODEV; |
| 168 | } |
| 169 | |
| 170 | static int pinconfig_post_bind(struct udevice *dev) |
| 171 | { |
Masahiro Yamada | 8a5f612 | 2015-09-06 01:44:50 +0900 | [diff] [blame] | 172 | return 0; |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 173 | } |
| 174 | #endif |
| 175 | |
Marek Vasut | ae59d7c | 2019-04-21 23:57:23 +0200 | [diff] [blame] | 176 | static int |
| 177 | pinctrl_gpio_get_pinctrl_and_offset(struct udevice *dev, unsigned offset, |
| 178 | struct udevice **pctldev, |
| 179 | unsigned int *pin_selector) |
| 180 | { |
| 181 | struct ofnode_phandle_args args; |
| 182 | unsigned gpio_offset, pfc_base, pfc_pins; |
| 183 | int ret; |
| 184 | |
| 185 | ret = dev_read_phandle_with_args(dev, "gpio-ranges", NULL, 3, |
| 186 | 0, &args); |
| 187 | if (ret) { |
| 188 | dev_dbg(dev, "%s: dev_read_phandle_with_args: err=%d\n", |
| 189 | __func__, ret); |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | ret = uclass_get_device_by_ofnode(UCLASS_PINCTRL, |
| 194 | args.node, pctldev); |
| 195 | if (ret) { |
| 196 | dev_dbg(dev, |
| 197 | "%s: uclass_get_device_by_of_offset failed: err=%d\n", |
| 198 | __func__, ret); |
| 199 | return ret; |
| 200 | } |
| 201 | |
| 202 | gpio_offset = args.args[0]; |
| 203 | pfc_base = args.args[1]; |
| 204 | pfc_pins = args.args[2]; |
| 205 | |
| 206 | if (offset < gpio_offset || offset > gpio_offset + pfc_pins) { |
| 207 | dev_dbg(dev, |
| 208 | "%s: GPIO can not be mapped to pincontrol pin\n", |
| 209 | __func__); |
| 210 | return -EINVAL; |
| 211 | } |
| 212 | |
| 213 | offset -= gpio_offset; |
| 214 | offset += pfc_base; |
| 215 | *pin_selector = offset; |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * pinctrl_gpio_request() - request a single pin to be used as GPIO |
| 222 | * |
| 223 | * @dev: GPIO peripheral device |
| 224 | * @offset: the GPIO pin offset from the GPIO controller |
Pali Rohár | a1de103 | 2022-07-25 13:56:11 +0200 | [diff] [blame] | 225 | * @label: the GPIO pin label |
Marek Vasut | ae59d7c | 2019-04-21 23:57:23 +0200 | [diff] [blame] | 226 | * @return: 0 on success, or negative error code on failure |
| 227 | */ |
Pali Rohár | a1de103 | 2022-07-25 13:56:11 +0200 | [diff] [blame] | 228 | int pinctrl_gpio_request(struct udevice *dev, unsigned offset, const char *label) |
Marek Vasut | ae59d7c | 2019-04-21 23:57:23 +0200 | [diff] [blame] | 229 | { |
| 230 | const struct pinctrl_ops *ops; |
| 231 | struct udevice *pctldev; |
| 232 | unsigned int pin_selector; |
| 233 | int ret; |
| 234 | |
| 235 | ret = pinctrl_gpio_get_pinctrl_and_offset(dev, offset, |
| 236 | &pctldev, &pin_selector); |
| 237 | if (ret) |
| 238 | return ret; |
| 239 | |
| 240 | ops = pinctrl_get_ops(pctldev); |
Simon Glass | bddac45 | 2021-03-25 10:26:11 +1300 | [diff] [blame] | 241 | assert(ops); |
| 242 | if (!ops->gpio_request_enable) |
| 243 | return -ENOSYS; |
Marek Vasut | ae59d7c | 2019-04-21 23:57:23 +0200 | [diff] [blame] | 244 | |
| 245 | return ops->gpio_request_enable(pctldev, pin_selector); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * pinctrl_gpio_free() - free a single pin used as GPIO |
| 250 | * |
| 251 | * @dev: GPIO peripheral device |
| 252 | * @offset: the GPIO pin offset from the GPIO controller |
| 253 | * @return: 0 on success, or negative error code on failure |
| 254 | */ |
| 255 | int pinctrl_gpio_free(struct udevice *dev, unsigned offset) |
| 256 | { |
| 257 | const struct pinctrl_ops *ops; |
| 258 | struct udevice *pctldev; |
| 259 | unsigned int pin_selector; |
| 260 | int ret; |
| 261 | |
| 262 | ret = pinctrl_gpio_get_pinctrl_and_offset(dev, offset, |
| 263 | &pctldev, &pin_selector); |
| 264 | if (ret) |
| 265 | return ret; |
| 266 | |
| 267 | ops = pinctrl_get_ops(pctldev); |
Simon Glass | bddac45 | 2021-03-25 10:26:11 +1300 | [diff] [blame] | 268 | assert(ops); |
| 269 | if (!ops->gpio_disable_free) |
| 270 | return -ENOSYS; |
Marek Vasut | ae59d7c | 2019-04-21 23:57:23 +0200 | [diff] [blame] | 271 | |
| 272 | return ops->gpio_disable_free(pctldev, pin_selector); |
| 273 | } |
| 274 | |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 275 | /** |
| 276 | * pinctrl_select_state_simple() - simple implementation of pinctrl_select_state |
| 277 | * |
| 278 | * @dev: peripheral device |
| 279 | * @return: 0 on success, or negative error code on failure |
| 280 | */ |
| 281 | static int pinctrl_select_state_simple(struct udevice *dev) |
| 282 | { |
| 283 | struct udevice *pctldev; |
| 284 | struct pinctrl_ops *ops; |
| 285 | int ret; |
| 286 | |
| 287 | /* |
Patrice Chotard | dce406e | 2019-02-25 13:39:55 +0100 | [diff] [blame] | 288 | * For most system, there is only one pincontroller device. But in |
| 289 | * case of multiple pincontroller devices, probe the one with sequence |
| 290 | * number 0 (defined by alias) to avoid race condition. |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 291 | */ |
Patrice Chotard | dce406e | 2019-02-25 13:39:55 +0100 | [diff] [blame] | 292 | ret = uclass_get_device_by_seq(UCLASS_PINCTRL, 0, &pctldev); |
| 293 | if (ret) |
| 294 | /* if not found, get the first one */ |
| 295 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &pctldev); |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 296 | if (ret) |
| 297 | return ret; |
| 298 | |
| 299 | ops = pinctrl_get_ops(pctldev); |
| 300 | if (!ops->set_state_simple) { |
| 301 | dev_dbg(dev, "set_state_simple op missing\n"); |
| 302 | return -ENOSYS; |
| 303 | } |
| 304 | |
| 305 | return ops->set_state_simple(pctldev, dev); |
| 306 | } |
| 307 | |
| 308 | int pinctrl_select_state(struct udevice *dev, const char *statename) |
| 309 | { |
| 310 | /* |
Kever Yang | f717b4c | 2018-04-18 17:54:04 +0800 | [diff] [blame] | 311 | * Some device which is logical like mmc.blk, do not have |
| 312 | * a valid ofnode. |
| 313 | */ |
Simon Glass | c23405f | 2020-12-19 10:40:12 -0700 | [diff] [blame] | 314 | if (!dev_has_ofnode(dev)) |
Kever Yang | f717b4c | 2018-04-18 17:54:04 +0800 | [diff] [blame] | 315 | return 0; |
| 316 | /* |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 317 | * Try full-implemented pinctrl first. |
| 318 | * If it fails or is not implemented, try simple one. |
| 319 | */ |
| 320 | if (pinctrl_select_state_full(dev, statename)) |
| 321 | return pinctrl_select_state_simple(dev); |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
Simon Glass | c5acf4a | 2015-08-30 16:55:13 -0600 | [diff] [blame] | 326 | int pinctrl_request(struct udevice *dev, int func, int flags) |
| 327 | { |
| 328 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
| 329 | |
| 330 | if (!ops->request) |
| 331 | return -ENOSYS; |
| 332 | |
| 333 | return ops->request(dev, func, flags); |
| 334 | } |
| 335 | |
| 336 | int pinctrl_request_noflags(struct udevice *dev, int func) |
| 337 | { |
| 338 | return pinctrl_request(dev, func, 0); |
| 339 | } |
| 340 | |
| 341 | int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph) |
| 342 | { |
| 343 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
| 344 | |
| 345 | if (!ops->get_periph_id) |
| 346 | return -ENOSYS; |
| 347 | |
| 348 | return ops->get_periph_id(dev, periph); |
| 349 | } |
| 350 | |
Simon Glass | 77eaa19 | 2016-01-21 19:43:56 -0700 | [diff] [blame] | 351 | int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index) |
| 352 | { |
| 353 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
| 354 | |
| 355 | if (!ops->get_gpio_mux) |
| 356 | return -ENOSYS; |
| 357 | |
| 358 | return ops->get_gpio_mux(dev, banknum, index); |
| 359 | } |
| 360 | |
Patrice Chotard | 8bbb5b2 | 2018-10-24 14:10:14 +0200 | [diff] [blame] | 361 | int pinctrl_get_pins_count(struct udevice *dev) |
| 362 | { |
| 363 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
| 364 | |
| 365 | if (!ops->get_pins_count) |
| 366 | return -ENOSYS; |
| 367 | |
| 368 | return ops->get_pins_count(dev); |
| 369 | } |
| 370 | |
| 371 | int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf, |
| 372 | int size) |
| 373 | { |
| 374 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
| 375 | |
| 376 | if (!ops->get_pin_name) |
| 377 | return -ENOSYS; |
| 378 | |
| 379 | snprintf(buf, size, ops->get_pin_name(dev, selector)); |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Patrice Chotard | f55a0c0 | 2018-10-24 14:10:13 +0200 | [diff] [blame] | 384 | int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf, |
| 385 | int size) |
| 386 | { |
| 387 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
| 388 | |
| 389 | if (!ops->get_pin_muxing) |
| 390 | return -ENOSYS; |
| 391 | |
| 392 | return ops->get_pin_muxing(dev, selector, buf, size); |
| 393 | } |
| 394 | |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 395 | /** |
Masahiro Yamada | f835706 | 2016-08-19 18:26:54 +0900 | [diff] [blame] | 396 | * pinconfig_post_bind() - post binding for PINCTRL uclass |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 397 | * Recursively bind child nodes as pinconfig devices in case of full pinctrl. |
| 398 | * |
| 399 | * @dev: pinctrl device |
| 400 | * @return: 0 on success, or negative error code on failure |
| 401 | */ |
Patrick Delaunay | e878b53 | 2019-08-02 14:48:00 +0200 | [diff] [blame] | 402 | static int __maybe_unused pinctrl_post_bind(struct udevice *dev) |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 403 | { |
| 404 | const struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
| 405 | |
| 406 | if (!ops) { |
| 407 | dev_dbg(dev, "ops is not set. Do not bind.\n"); |
| 408 | return -EINVAL; |
| 409 | } |
| 410 | |
| 411 | /* |
Masahiro Yamada | 8a5f612 | 2015-09-06 01:44:50 +0900 | [diff] [blame] | 412 | * If set_state callback is set, we assume this pinctrl driver is the |
| 413 | * full implementation. In this case, its child nodes should be bound |
| 414 | * so that peripheral devices can easily search in parent devices |
| 415 | * during later DT-parsing. |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 416 | */ |
Masahiro Yamada | 8a5f612 | 2015-09-06 01:44:50 +0900 | [diff] [blame] | 417 | if (ops->set_state) |
| 418 | return pinconfig_post_bind(dev); |
| 419 | |
| 420 | return 0; |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | UCLASS_DRIVER(pinctrl) = { |
| 424 | .id = UCLASS_PINCTRL, |
Simon Glass | 9539738 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 425 | #if CONFIG_IS_ENABLED(OF_REAL) |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 426 | .post_bind = pinctrl_post_bind, |
Simon Glass | c8fbf30 | 2020-12-23 08:11:13 -0700 | [diff] [blame] | 427 | #endif |
Thomas Abraham | ac98527 | 2016-04-23 22:18:07 +0530 | [diff] [blame] | 428 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
Masahiro Yamada | d90a5a3 | 2015-08-27 12:44:29 +0900 | [diff] [blame] | 429 | .name = "pinctrl", |
| 430 | }; |