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