Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | be04f1a | 2021-02-04 21:22:08 -0700 | [diff] [blame^] | 6 | #define LOG_CATEGORY UCLASS_GPIO |
| 7 | |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Jean-Jacques Hiblot | d4b722e | 2020-09-11 13:43:34 +0530 | [diff] [blame] | 11 | #include <dm/devres.h> |
| 12 | #include <dm/device_compat.h> |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 13 | #include <dm/device-internal.h> |
| 14 | #include <dm/lists.h> |
| 15 | #include <dm/uclass-internal.h> |
Eric Nelson | 6c880b7 | 2016-04-24 16:32:40 -0700 | [diff] [blame] | 16 | #include <dt-bindings/gpio/gpio.h> |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 17 | #include <errno.h> |
Simon Glass | 0dac4d5 | 2015-01-05 20:05:28 -0700 | [diff] [blame] | 18 | #include <fdtdec.h> |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 19 | #include <malloc.h> |
Simon Glass | 2912686 | 2020-07-07 13:11:44 -0600 | [diff] [blame] | 20 | #include <acpi/acpi_device.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 22 | #include <asm/gpio.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 23 | #include <dm/device_compat.h> |
Masahiro Yamada | 84b8bf6 | 2016-01-24 23:27:48 +0900 | [diff] [blame] | 24 | #include <linux/bug.h> |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 25 | #include <linux/ctype.h> |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 26 | |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 29 | /** |
Patrick Delaunay | 9f2b066 | 2020-01-13 11:35:01 +0100 | [diff] [blame] | 30 | * gpio_desc_init() - Initialize the GPIO descriptor |
| 31 | * |
| 32 | * @desc: GPIO descriptor to initialize |
| 33 | * @dev: GPIO device |
| 34 | * @offset: Offset of device GPIO |
| 35 | */ |
| 36 | static void gpio_desc_init(struct gpio_desc *desc, |
| 37 | struct udevice *dev, |
| 38 | uint offset) |
| 39 | { |
| 40 | desc->dev = dev; |
| 41 | desc->offset = offset; |
| 42 | desc->flags = 0; |
| 43 | } |
| 44 | |
| 45 | /** |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 46 | * gpio_to_device() - Convert global GPIO number to device, number |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 47 | * |
| 48 | * Convert the GPIO number to an entry in the list of GPIOs |
| 49 | * or GPIO blocks registered with the GPIO controller. Returns |
| 50 | * entry on success, NULL on error. |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 51 | * |
| 52 | * @gpio: The numeric representation of the GPIO |
| 53 | * @desc: Returns description (desc->flags will always be 0) |
| 54 | * @return 0 if found, -ENOENT if not found |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 55 | */ |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 56 | static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc) |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 57 | { |
| 58 | struct gpio_dev_priv *uc_priv; |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 59 | struct udevice *dev; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 60 | int ret; |
| 61 | |
| 62 | for (ret = uclass_first_device(UCLASS_GPIO, &dev); |
| 63 | dev; |
| 64 | ret = uclass_next_device(&dev)) { |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 65 | uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 66 | if (gpio >= uc_priv->gpio_base && |
| 67 | gpio < uc_priv->gpio_base + uc_priv->gpio_count) { |
Patrick Delaunay | 9f2b066 | 2020-01-13 11:35:01 +0100 | [diff] [blame] | 68 | gpio_desc_init(desc, dev, gpio - uc_priv->gpio_base); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /* No such GPIO */ |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 74 | return ret ? ret : -ENOENT; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Heiko Schocher | 2bd261d | 2020-05-22 11:08:59 +0200 | [diff] [blame] | 77 | #if CONFIG_IS_ENABLED(DM_GPIO_LOOKUP_LABEL) |
| 78 | /** |
| 79 | * dm_gpio_lookup_label() - look for name in gpio device |
| 80 | * |
| 81 | * search in uc_priv, if there is a gpio with labelname same |
| 82 | * as name. |
| 83 | * |
| 84 | * @name: name which is searched |
| 85 | * @uc_priv: gpio_dev_priv pointer. |
| 86 | * @offset: gpio offset within the device |
| 87 | * @return: 0 if found, -ENOENT if not. |
| 88 | */ |
| 89 | static int dm_gpio_lookup_label(const char *name, |
| 90 | struct gpio_dev_priv *uc_priv, ulong *offset) |
| 91 | { |
| 92 | int len; |
| 93 | int i; |
| 94 | |
| 95 | *offset = -1; |
| 96 | len = strlen(name); |
| 97 | for (i = 0; i < uc_priv->gpio_count; i++) { |
| 98 | if (!uc_priv->name[i]) |
| 99 | continue; |
| 100 | if (!strncmp(name, uc_priv->name[i], len)) { |
| 101 | *offset = i; |
| 102 | return 0; |
| 103 | } |
| 104 | } |
| 105 | return -ENOENT; |
| 106 | } |
| 107 | #else |
| 108 | static int |
| 109 | dm_gpio_lookup_label(const char *name, struct gpio_dev_priv *uc_priv, |
| 110 | ulong *offset) |
| 111 | { |
| 112 | return -ENOENT; |
| 113 | } |
| 114 | #endif |
| 115 | |
Simon Glass | 32ec159 | 2015-06-23 15:38:40 -0600 | [diff] [blame] | 116 | int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc) |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 117 | { |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 118 | struct gpio_dev_priv *uc_priv = NULL; |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 119 | struct udevice *dev; |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 120 | ulong offset; |
| 121 | int numeric; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 122 | int ret; |
| 123 | |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 124 | numeric = isdigit(*name) ? simple_strtoul(name, NULL, 10) : -1; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 125 | for (ret = uclass_first_device(UCLASS_GPIO, &dev); |
| 126 | dev; |
| 127 | ret = uclass_next_device(&dev)) { |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 128 | int len; |
| 129 | |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 130 | uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 131 | if (numeric != -1) { |
| 132 | offset = numeric - uc_priv->gpio_base; |
| 133 | /* Allow GPIOs to be numbered from 0 */ |
Tom Rini | 7589791 | 2017-05-10 15:20:15 -0400 | [diff] [blame] | 134 | if (offset < uc_priv->gpio_count) |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 135 | break; |
| 136 | } |
| 137 | |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 138 | len = uc_priv->bank_name ? strlen(uc_priv->bank_name) : 0; |
| 139 | |
Simon Glass | 939cda5 | 2014-06-11 23:29:47 -0600 | [diff] [blame] | 140 | if (!strncasecmp(name, uc_priv->bank_name, len)) { |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 141 | if (!strict_strtoul(name + len, 10, &offset)) |
| 142 | break; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 143 | } |
Heiko Schocher | 2bd261d | 2020-05-22 11:08:59 +0200 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * if we did not found a gpio through its bank |
| 147 | * name, we search for a valid gpio label. |
| 148 | */ |
| 149 | if (!dm_gpio_lookup_label(name, uc_priv, &offset)) |
| 150 | break; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 153 | if (!dev) |
| 154 | return ret ? ret : -EINVAL; |
| 155 | |
Patrick Delaunay | 9f2b066 | 2020-01-13 11:35:01 +0100 | [diff] [blame] | 156 | gpio_desc_init(desc, dev, offset); |
Simon Glass | 32ec159 | 2015-06-23 15:38:40 -0600 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | int gpio_lookup_name(const char *name, struct udevice **devp, |
| 162 | unsigned int *offsetp, unsigned int *gpiop) |
| 163 | { |
| 164 | struct gpio_desc desc; |
| 165 | int ret; |
| 166 | |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 167 | if (devp) |
Simon Glass | 32ec159 | 2015-06-23 15:38:40 -0600 | [diff] [blame] | 168 | *devp = NULL; |
| 169 | ret = dm_gpio_lookup_name(name, &desc); |
| 170 | if (ret) |
| 171 | return ret; |
| 172 | |
| 173 | if (devp) |
| 174 | *devp = desc.dev; |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 175 | if (offsetp) |
Simon Glass | 32ec159 | 2015-06-23 15:38:40 -0600 | [diff] [blame] | 176 | *offsetp = desc.offset; |
| 177 | if (gpiop) { |
| 178 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(desc.dev); |
| 179 | |
| 180 | *gpiop = uc_priv->gpio_base + desc.offset; |
| 181 | } |
Simon Glass | fe1ef50 | 2014-10-22 21:37:01 -0600 | [diff] [blame] | 182 | |
| 183 | return 0; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 186 | int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, |
| 187 | struct ofnode_phandle_args *args) |
Eric Nelson | 6c880b7 | 2016-04-24 16:32:40 -0700 | [diff] [blame] | 188 | { |
| 189 | if (args->args_count < 1) |
| 190 | return -EINVAL; |
| 191 | |
| 192 | desc->offset = args->args[0]; |
| 193 | |
| 194 | if (args->args_count < 2) |
| 195 | return 0; |
| 196 | |
Patrick Delaunay | 695e5fd | 2020-01-13 11:35:06 +0100 | [diff] [blame] | 197 | desc->flags = 0; |
Eric Nelson | 6c880b7 | 2016-04-24 16:32:40 -0700 | [diff] [blame] | 198 | if (args->args[1] & GPIO_ACTIVE_LOW) |
Patrick Delaunay | 695e5fd | 2020-01-13 11:35:06 +0100 | [diff] [blame] | 199 | desc->flags |= GPIOD_ACTIVE_LOW; |
Eric Nelson | 6c880b7 | 2016-04-24 16:32:40 -0700 | [diff] [blame] | 200 | |
Patrick Delaunay | 477ca57 | 2020-01-13 11:35:07 +0100 | [diff] [blame] | 201 | /* |
| 202 | * need to test 2 bits for gpio output binding: |
| 203 | * OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (0x4) |
| 204 | * OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) | LINE_OPEN_SOURCE (0x0) |
| 205 | */ |
| 206 | if (args->args[1] & GPIO_SINGLE_ENDED) { |
| 207 | if (args->args[1] & GPIO_LINE_OPEN_DRAIN) |
| 208 | desc->flags |= GPIOD_OPEN_DRAIN; |
| 209 | else |
| 210 | desc->flags |= GPIOD_OPEN_SOURCE; |
| 211 | } |
| 212 | |
| 213 | if (args->args[1] & GPIO_PULL_UP) |
| 214 | desc->flags |= GPIOD_PULL_UP; |
| 215 | |
| 216 | if (args->args[1] & GPIO_PULL_DOWN) |
| 217 | desc->flags |= GPIOD_PULL_DOWN; |
| 218 | |
Eric Nelson | 6c880b7 | 2016-04-24 16:32:40 -0700 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 222 | static int gpio_find_and_xlate(struct gpio_desc *desc, |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 223 | struct ofnode_phandle_args *args) |
Simon Glass | 0dac4d5 | 2015-01-05 20:05:28 -0700 | [diff] [blame] | 224 | { |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 225 | const struct dm_gpio_ops *ops = gpio_get_ops(desc->dev); |
Simon Glass | 0dac4d5 | 2015-01-05 20:05:28 -0700 | [diff] [blame] | 226 | |
Eric Nelson | 6c880b7 | 2016-04-24 16:32:40 -0700 | [diff] [blame] | 227 | if (ops->xlate) |
| 228 | return ops->xlate(desc->dev, desc, args); |
Simon Glass | 0dac4d5 | 2015-01-05 20:05:28 -0700 | [diff] [blame] | 229 | else |
Eric Nelson | 6c880b7 | 2016-04-24 16:32:40 -0700 | [diff] [blame] | 230 | return gpio_xlate_offs_flags(desc->dev, desc, args); |
Simon Glass | 0dac4d5 | 2015-01-05 20:05:28 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 233 | #if defined(CONFIG_GPIO_HOG) |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 234 | |
| 235 | struct gpio_hog_priv { |
| 236 | struct gpio_desc gpiod; |
| 237 | }; |
| 238 | |
| 239 | struct gpio_hog_data { |
| 240 | int gpiod_flags; |
| 241 | int value; |
| 242 | u32 val[2]; |
| 243 | }; |
| 244 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 245 | static int gpio_hog_of_to_plat(struct udevice *dev) |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 246 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 247 | struct gpio_hog_data *plat = dev_get_plat(dev); |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 248 | const char *nodename; |
| 249 | int ret; |
| 250 | |
| 251 | plat->value = 0; |
| 252 | if (dev_read_bool(dev, "input")) { |
| 253 | plat->gpiod_flags = GPIOD_IS_IN; |
| 254 | } else if (dev_read_bool(dev, "output-high")) { |
| 255 | plat->value = 1; |
| 256 | plat->gpiod_flags = GPIOD_IS_OUT; |
| 257 | } else if (dev_read_bool(dev, "output-low")) { |
| 258 | plat->gpiod_flags = GPIOD_IS_OUT; |
| 259 | } else { |
| 260 | printf("%s: missing gpio-hog state.\n", __func__); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | ret = dev_read_u32_array(dev, "gpios", plat->val, 2); |
| 264 | if (ret) { |
| 265 | printf("%s: wrong gpios property, 2 values needed %d\n", |
| 266 | __func__, ret); |
| 267 | return ret; |
| 268 | } |
| 269 | nodename = dev_read_string(dev, "line-name"); |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 270 | if (nodename) |
| 271 | device_set_name(dev, nodename); |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static int gpio_hog_probe(struct udevice *dev) |
| 277 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 278 | struct gpio_hog_data *plat = dev_get_plat(dev); |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 279 | struct gpio_hog_priv *priv = dev_get_priv(dev); |
| 280 | int ret; |
| 281 | |
| 282 | ret = gpio_dev_request_index(dev->parent, dev->name, "gpio-hog", |
| 283 | plat->val[0], plat->gpiod_flags, |
| 284 | plat->val[1], &priv->gpiod); |
| 285 | if (ret < 0) { |
| 286 | debug("%s: node %s could not get gpio.\n", __func__, |
| 287 | dev->name); |
| 288 | return ret; |
| 289 | } |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 290 | |
| 291 | if (plat->gpiod_flags == GPIOD_IS_OUT) { |
| 292 | ret = dm_gpio_set_value(&priv->gpiod, plat->value); |
| 293 | if (ret < 0) { |
| 294 | debug("%s: node %s could not set gpio.\n", __func__, |
| 295 | dev->name); |
| 296 | return ret; |
| 297 | } |
| 298 | } |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | int gpio_hog_probe_all(void) |
| 304 | { |
| 305 | struct udevice *dev; |
| 306 | int ret; |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 307 | int retval = 0; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 308 | |
| 309 | for (uclass_first_device(UCLASS_NOP, &dev); |
| 310 | dev; |
| 311 | uclass_find_next_device(&dev)) { |
Simon Glass | 65e25be | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 312 | if (dev->driver == DM_DRIVER_GET(gpio_hog)) { |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 313 | ret = device_probe(dev); |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 314 | if (ret) { |
| 315 | printf("Failed to probe device %s err: %d\n", |
| 316 | dev->name, ret); |
| 317 | retval = ret; |
| 318 | } |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 322 | return retval; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 325 | int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc) |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 326 | { |
| 327 | struct udevice *dev; |
| 328 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 329 | *desc = NULL; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 330 | gpio_hog_probe_all(); |
| 331 | if (!uclass_get_device_by_name(UCLASS_NOP, name, &dev)) { |
| 332 | struct gpio_hog_priv *priv = dev_get_priv(dev); |
| 333 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 334 | *desc = &priv->gpiod; |
| 335 | return 0; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 338 | return -ENODEV; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | U_BOOT_DRIVER(gpio_hog) = { |
| 342 | .name = "gpio_hog", |
| 343 | .id = UCLASS_NOP, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 344 | .of_to_plat = gpio_hog_of_to_plat, |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 345 | .probe = gpio_hog_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 346 | .priv_auto = sizeof(struct gpio_hog_priv), |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 347 | .plat_auto = sizeof(struct gpio_hog_data), |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 348 | }; |
| 349 | #else |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 350 | int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc) |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 351 | { |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 352 | return 0; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 353 | } |
| 354 | #endif |
| 355 | |
Simon Glass | efa677f | 2015-06-23 15:38:41 -0600 | [diff] [blame] | 356 | int dm_gpio_request(struct gpio_desc *desc, const char *label) |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 357 | { |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 358 | const struct dm_gpio_ops *ops = gpio_get_ops(desc->dev); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 359 | struct udevice *dev = desc->dev; |
| 360 | struct gpio_dev_priv *uc_priv; |
| 361 | char *str; |
| 362 | int ret; |
| 363 | |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 364 | uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 365 | if (uc_priv->name[desc->offset]) |
| 366 | return -EBUSY; |
| 367 | str = strdup(label); |
| 368 | if (!str) |
| 369 | return -ENOMEM; |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 370 | if (ops->request) { |
| 371 | ret = ops->request(dev, desc->offset, label); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 372 | if (ret) { |
| 373 | free(str); |
| 374 | return ret; |
| 375 | } |
| 376 | } |
| 377 | uc_priv->name[desc->offset] = str; |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 382 | static int dm_gpio_requestf(struct gpio_desc *desc, const char *fmt, ...) |
| 383 | { |
Simon Glass | 27084c0 | 2019-09-25 08:56:27 -0600 | [diff] [blame] | 384 | #if !defined(CONFIG_SPL_BUILD) || !CONFIG_IS_ENABLED(USE_TINY_PRINTF) |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 385 | va_list args; |
| 386 | char buf[40]; |
| 387 | |
| 388 | va_start(args, fmt); |
| 389 | vscnprintf(buf, sizeof(buf), fmt, args); |
| 390 | va_end(args); |
| 391 | return dm_gpio_request(desc, buf); |
Simon Glass | 4dc5259 | 2015-12-29 05:22:48 -0700 | [diff] [blame] | 392 | #else |
| 393 | return dm_gpio_request(desc, fmt); |
| 394 | #endif |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 397 | /** |
| 398 | * gpio_request() - [COMPAT] Request GPIO |
| 399 | * gpio: GPIO number |
| 400 | * label: Name for the requested GPIO |
| 401 | * |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 402 | * The label is copied and allocated so the caller does not need to keep |
| 403 | * the pointer around. |
| 404 | * |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 405 | * This function implements the API that's compatible with current |
| 406 | * GPIO API used in U-Boot. The request is forwarded to particular |
| 407 | * GPIO driver. Returns 0 on success, negative value on error. |
| 408 | */ |
| 409 | int gpio_request(unsigned gpio, const char *label) |
| 410 | { |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 411 | struct gpio_desc desc; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 412 | int ret; |
| 413 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 414 | ret = gpio_to_device(gpio, &desc); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 415 | if (ret) |
| 416 | return ret; |
| 417 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 418 | return dm_gpio_request(&desc, label); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /** |
Simon Glass | d44f597 | 2014-10-04 11:29:49 -0600 | [diff] [blame] | 422 | * gpio_requestf() - [COMPAT] Request GPIO |
| 423 | * @gpio: GPIO number |
| 424 | * @fmt: Format string for the requested GPIO |
| 425 | * @...: Arguments for the printf() format string |
| 426 | * |
| 427 | * This function implements the API that's compatible with current |
| 428 | * GPIO API used in U-Boot. The request is forwarded to particular |
| 429 | * GPIO driver. Returns 0 on success, negative value on error. |
| 430 | */ |
| 431 | int gpio_requestf(unsigned gpio, const char *fmt, ...) |
| 432 | { |
Simon Glass | 27084c0 | 2019-09-25 08:56:27 -0600 | [diff] [blame] | 433 | #if !defined(CONFIG_SPL_BUILD) || !CONFIG_IS_ENABLED(USE_TINY_PRINTF) |
Simon Glass | d44f597 | 2014-10-04 11:29:49 -0600 | [diff] [blame] | 434 | va_list args; |
| 435 | char buf[40]; |
| 436 | |
| 437 | va_start(args, fmt); |
| 438 | vscnprintf(buf, sizeof(buf), fmt, args); |
| 439 | va_end(args); |
| 440 | return gpio_request(gpio, buf); |
Simon Glass | 4dc5259 | 2015-12-29 05:22:48 -0700 | [diff] [blame] | 441 | #else |
| 442 | return gpio_request(gpio, fmt); |
| 443 | #endif |
Simon Glass | d44f597 | 2014-10-04 11:29:49 -0600 | [diff] [blame] | 444 | } |
| 445 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 446 | int _dm_gpio_free(struct udevice *dev, uint offset) |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 447 | { |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 448 | const struct dm_gpio_ops *ops = gpio_get_ops(dev); |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 449 | struct gpio_dev_priv *uc_priv; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 450 | int ret; |
| 451 | |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 452 | uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 453 | if (!uc_priv->name[offset]) |
| 454 | return -ENXIO; |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 455 | if (ops->rfree) { |
| 456 | ret = ops->rfree(dev, offset); |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 457 | if (ret) |
| 458 | return ret; |
| 459 | } |
| 460 | |
| 461 | free(uc_priv->name[offset]); |
| 462 | uc_priv->name[offset] = NULL; |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 467 | /** |
| 468 | * gpio_free() - [COMPAT] Relinquish GPIO |
| 469 | * gpio: GPIO number |
| 470 | * |
| 471 | * This function implements the API that's compatible with current |
| 472 | * GPIO API used in U-Boot. The request is forwarded to particular |
| 473 | * GPIO driver. Returns 0 on success, negative value on error. |
| 474 | */ |
| 475 | int gpio_free(unsigned gpio) |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 476 | { |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 477 | struct gpio_desc desc; |
| 478 | int ret; |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 479 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 480 | ret = gpio_to_device(gpio, &desc); |
| 481 | if (ret) |
| 482 | return ret; |
| 483 | |
| 484 | return _dm_gpio_free(desc.dev, desc.offset); |
| 485 | } |
| 486 | |
Simon Glass | 17c43f1 | 2016-03-06 19:27:51 -0700 | [diff] [blame] | 487 | static int check_reserved(const struct gpio_desc *desc, const char *func) |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 488 | { |
Simon Glass | eca4866 | 2015-07-02 18:16:16 -0600 | [diff] [blame] | 489 | struct gpio_dev_priv *uc_priv; |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 490 | |
Simon Glass | eca4866 | 2015-07-02 18:16:16 -0600 | [diff] [blame] | 491 | if (!dm_gpio_is_valid(desc)) |
| 492 | return -ENOENT; |
| 493 | |
| 494 | uc_priv = dev_get_uclass_priv(desc->dev); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 495 | if (!uc_priv->name[desc->offset]) { |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 496 | printf("%s: %s: error: gpio %s%d not reserved\n", |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 497 | desc->dev->name, func, |
| 498 | uc_priv->bank_name ? uc_priv->bank_name : "", |
| 499 | desc->offset); |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 500 | return -EBUSY; |
| 501 | } |
| 502 | |
| 503 | return 0; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /** |
| 507 | * gpio_direction_input() - [COMPAT] Set GPIO direction to input |
| 508 | * gpio: GPIO number |
| 509 | * |
| 510 | * This function implements the API that's compatible with current |
| 511 | * GPIO API used in U-Boot. The request is forwarded to particular |
| 512 | * GPIO driver. Returns 0 on success, negative value on error. |
| 513 | */ |
| 514 | int gpio_direction_input(unsigned gpio) |
| 515 | { |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 516 | struct gpio_desc desc; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 517 | int ret; |
| 518 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 519 | ret = gpio_to_device(gpio, &desc); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 520 | if (ret) |
| 521 | return ret; |
| 522 | |
Simon Glass | ca1e1f5 | 2021-02-04 21:22:04 -0700 | [diff] [blame] | 523 | return dm_gpio_clrset_flags(&desc, GPIOD_MASK_DIR, GPIOD_IS_IN); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /** |
| 527 | * gpio_direction_output() - [COMPAT] Set GPIO direction to output and set value |
| 528 | * gpio: GPIO number |
| 529 | * value: Logical value to be set on the GPIO pin |
| 530 | * |
| 531 | * This function implements the API that's compatible with current |
| 532 | * GPIO API used in U-Boot. The request is forwarded to particular |
| 533 | * GPIO driver. Returns 0 on success, negative value on error. |
| 534 | */ |
| 535 | int gpio_direction_output(unsigned gpio, int value) |
| 536 | { |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 537 | struct gpio_desc desc; |
Simon Glass | ca1e1f5 | 2021-02-04 21:22:04 -0700 | [diff] [blame] | 538 | ulong flags; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 539 | int ret; |
| 540 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 541 | ret = gpio_to_device(gpio, &desc); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 542 | if (ret) |
| 543 | return ret; |
| 544 | |
Simon Glass | ca1e1f5 | 2021-02-04 21:22:04 -0700 | [diff] [blame] | 545 | flags = GPIOD_IS_OUT; |
| 546 | if (value) |
| 547 | flags |= GPIOD_IS_OUT_ACTIVE; |
| 548 | return dm_gpio_clrset_flags(&desc, GPIOD_MASK_DIR, flags); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Patrick Delaunay | 8a9140c | 2020-01-13 11:35:02 +0100 | [diff] [blame] | 551 | static int _gpio_get_value(const struct gpio_desc *desc) |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 552 | { |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 553 | const struct dm_gpio_ops *ops = gpio_get_ops(desc->dev); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 554 | int value; |
Patrick Delaunay | 8a9140c | 2020-01-13 11:35:02 +0100 | [diff] [blame] | 555 | |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 556 | value = ops->get_value(desc->dev, desc->offset); |
Patrick Delaunay | 8a9140c | 2020-01-13 11:35:02 +0100 | [diff] [blame] | 557 | |
| 558 | return desc->flags & GPIOD_ACTIVE_LOW ? !value : value; |
| 559 | } |
| 560 | |
| 561 | int dm_gpio_get_value(const struct gpio_desc *desc) |
| 562 | { |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 563 | int ret; |
| 564 | |
| 565 | ret = check_reserved(desc, "get_value"); |
| 566 | if (ret) |
| 567 | return ret; |
| 568 | |
Patrick Delaunay | 8a9140c | 2020-01-13 11:35:02 +0100 | [diff] [blame] | 569 | return _gpio_get_value(desc); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Simon Glass | 17c43f1 | 2016-03-06 19:27:51 -0700 | [diff] [blame] | 572 | int dm_gpio_set_value(const struct gpio_desc *desc, int value) |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 573 | { |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 574 | const struct dm_gpio_ops *ops; |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 575 | int ret; |
| 576 | |
| 577 | ret = check_reserved(desc, "set_value"); |
| 578 | if (ret) |
| 579 | return ret; |
| 580 | |
| 581 | if (desc->flags & GPIOD_ACTIVE_LOW) |
| 582 | value = !value; |
Neil Armstrong | 47bd533 | 2020-05-05 10:43:17 +0200 | [diff] [blame] | 583 | |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 584 | /* GPIOD_ are directly managed by driver in set_flags */ |
| 585 | ops = gpio_get_ops(desc->dev); |
| 586 | if (ops->set_flags) { |
| 587 | ulong flags = desc->flags; |
| 588 | |
| 589 | if (value) |
| 590 | flags |= GPIOD_IS_OUT_ACTIVE; |
| 591 | else |
| 592 | flags &= ~GPIOD_IS_OUT_ACTIVE; |
| 593 | return ops->set_flags(desc->dev, desc->offset, flags); |
| 594 | } |
| 595 | |
Neil Armstrong | 47bd533 | 2020-05-05 10:43:17 +0200 | [diff] [blame] | 596 | /* |
| 597 | * Emulate open drain by not actively driving the line high or |
| 598 | * Emulate open source by not actively driving the line low |
| 599 | */ |
| 600 | if ((desc->flags & GPIOD_OPEN_DRAIN && value) || |
| 601 | (desc->flags & GPIOD_OPEN_SOURCE && !value)) |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 602 | return ops->direction_input(desc->dev, desc->offset); |
Neil Armstrong | 47bd533 | 2020-05-05 10:43:17 +0200 | [diff] [blame] | 603 | else if (desc->flags & GPIOD_OPEN_DRAIN || |
| 604 | desc->flags & GPIOD_OPEN_SOURCE) |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 605 | return ops->direction_output(desc->dev, desc->offset, value); |
Neil Armstrong | 47bd533 | 2020-05-05 10:43:17 +0200 | [diff] [blame] | 606 | |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 607 | ret = ops->set_value(desc->dev, desc->offset, value); |
| 608 | if (ret) |
| 609 | return ret; |
| 610 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | |
Patrick Delaunay | 4292fb1 | 2020-01-13 11:35:04 +0100 | [diff] [blame] | 614 | /* check dir flags invalid configuration */ |
| 615 | static int check_dir_flags(ulong flags) |
| 616 | { |
| 617 | if ((flags & GPIOD_IS_OUT) && (flags & GPIOD_IS_IN)) { |
| 618 | log_debug("%s: flags 0x%lx has GPIOD_IS_OUT and GPIOD_IS_IN\n", |
| 619 | __func__, flags); |
| 620 | return -EINVAL; |
| 621 | } |
| 622 | |
Patrick Delaunay | 477ca57 | 2020-01-13 11:35:07 +0100 | [diff] [blame] | 623 | if ((flags & GPIOD_PULL_UP) && (flags & GPIOD_PULL_DOWN)) { |
| 624 | log_debug("%s: flags 0x%lx has GPIOD_PULL_UP and GPIOD_PULL_DOWN\n", |
| 625 | __func__, flags); |
| 626 | return -EINVAL; |
| 627 | } |
| 628 | |
| 629 | if ((flags & GPIOD_OPEN_DRAIN) && (flags & GPIOD_OPEN_SOURCE)) { |
| 630 | log_debug("%s: flags 0x%lx has GPIOD_OPEN_DRAIN and GPIOD_OPEN_SOURCE\n", |
| 631 | __func__, flags); |
| 632 | return -EINVAL; |
| 633 | } |
| 634 | |
Patrick Delaunay | 4292fb1 | 2020-01-13 11:35:04 +0100 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 638 | /** |
| 639 | * _dm_gpio_set_flags() - Send flags to the driver |
| 640 | * |
| 641 | * This uses the best available method to send the given flags to the driver. |
| 642 | * Note that if flags & GPIOD_ACTIVE_LOW, the driver sees the opposite value |
| 643 | * of GPIOD_IS_OUT_ACTIVE. |
| 644 | * |
| 645 | * @desc: GPIO description |
| 646 | * @flags: flags value to set |
| 647 | * @return 0 if OK, -ve on error |
| 648 | */ |
Simon Glass | 13979fc | 2021-02-04 21:21:55 -0700 | [diff] [blame] | 649 | static int _dm_gpio_set_flags(struct gpio_desc *desc, ulong flags) |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 650 | { |
| 651 | struct udevice *dev = desc->dev; |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 652 | const struct dm_gpio_ops *ops = gpio_get_ops(dev); |
Patrick Delaunay | 4292fb1 | 2020-01-13 11:35:04 +0100 | [diff] [blame] | 653 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
Patrick Delaunay | 788ea83 | 2020-01-13 11:35:03 +0100 | [diff] [blame] | 654 | int ret = 0; |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 655 | |
Patrick Delaunay | 4292fb1 | 2020-01-13 11:35:04 +0100 | [diff] [blame] | 656 | ret = check_dir_flags(flags); |
| 657 | if (ret) { |
| 658 | dev_dbg(dev, |
| 659 | "%s error: set_dir_flags for gpio %s%d has invalid dir flags 0x%lx\n", |
| 660 | desc->dev->name, |
| 661 | uc_priv->bank_name ? uc_priv->bank_name : "", |
| 662 | desc->offset, flags); |
| 663 | |
| 664 | return ret; |
| 665 | } |
| 666 | |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 667 | /* If active low, invert the output state */ |
| 668 | if ((flags & (GPIOD_IS_OUT | GPIOD_ACTIVE_LOW)) == |
| 669 | (GPIOD_IS_OUT | GPIOD_ACTIVE_LOW)) |
| 670 | flags ^= GPIOD_IS_OUT_ACTIVE; |
| 671 | |
Simon Glass | 13979fc | 2021-02-04 21:21:55 -0700 | [diff] [blame] | 672 | /* GPIOD_ are directly managed by driver in set_flags */ |
| 673 | if (ops->set_flags) { |
| 674 | ret = ops->set_flags(dev, desc->offset, flags); |
Patrick Delaunay | 8fd9daf | 2020-01-13 11:35:09 +0100 | [diff] [blame] | 675 | } else { |
| 676 | if (flags & GPIOD_IS_OUT) { |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 677 | bool value = flags & GPIOD_IS_OUT_ACTIVE; |
| 678 | |
| 679 | ret = ops->direction_output(dev, desc->offset, value); |
Patrick Delaunay | 8fd9daf | 2020-01-13 11:35:09 +0100 | [diff] [blame] | 680 | } else if (flags & GPIOD_IS_IN) { |
| 681 | ret = ops->direction_input(dev, desc->offset); |
| 682 | } |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 683 | } |
Patrick Delaunay | 788ea83 | 2020-01-13 11:35:03 +0100 | [diff] [blame] | 684 | |
| 685 | return ret; |
| 686 | } |
| 687 | |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 688 | int dm_gpio_clrset_flags(struct gpio_desc *desc, ulong clr, ulong set) |
Patrick Delaunay | 788ea83 | 2020-01-13 11:35:03 +0100 | [diff] [blame] | 689 | { |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 690 | ulong flags; |
Patrick Delaunay | 788ea83 | 2020-01-13 11:35:03 +0100 | [diff] [blame] | 691 | int ret; |
| 692 | |
| 693 | ret = check_reserved(desc, "set_dir_flags"); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 694 | if (ret) |
| 695 | return ret; |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 696 | |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 697 | flags = (desc->flags & ~clr) | set; |
Patrick Delaunay | 788ea83 | 2020-01-13 11:35:03 +0100 | [diff] [blame] | 698 | |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 699 | ret = _dm_gpio_set_flags(desc, flags); |
| 700 | if (ret) |
| 701 | return ret; |
| 702 | |
| 703 | /* save the flags also in descriptor */ |
| 704 | desc->flags = flags; |
| 705 | |
| 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) |
| 710 | { |
| 711 | /* combine the requested flags (for IN/OUT) and the descriptor flags */ |
| 712 | return dm_gpio_clrset_flags(desc, GPIOD_MASK_DIR, flags); |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | int dm_gpio_set_dir(struct gpio_desc *desc) |
| 716 | { |
Patrick Delaunay | 788ea83 | 2020-01-13 11:35:03 +0100 | [diff] [blame] | 717 | int ret; |
| 718 | |
| 719 | ret = check_reserved(desc, "set_dir"); |
| 720 | if (ret) |
| 721 | return ret; |
| 722 | |
Simon Glass | 13979fc | 2021-02-04 21:21:55 -0700 | [diff] [blame] | 723 | return _dm_gpio_set_flags(desc, desc->flags); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Simon Glass | c0c1e62 | 2021-02-04 21:21:57 -0700 | [diff] [blame] | 726 | int dm_gpio_get_flags(struct gpio_desc *desc, ulong *flagsp) |
Patrick Delaunay | 695e5fd | 2020-01-13 11:35:06 +0100 | [diff] [blame] | 727 | { |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 728 | struct udevice *dev = desc->dev; |
| 729 | int ret, value; |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 730 | const struct dm_gpio_ops *ops = gpio_get_ops(dev); |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 731 | ulong flags; |
Patrick Delaunay | 695e5fd | 2020-01-13 11:35:06 +0100 | [diff] [blame] | 732 | |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 733 | ret = check_reserved(desc, "get_flags"); |
Patrick Delaunay | 695e5fd | 2020-01-13 11:35:06 +0100 | [diff] [blame] | 734 | if (ret) |
| 735 | return ret; |
| 736 | |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 737 | /* GPIOD_ are directly provided by driver except GPIOD_ACTIVE_LOW */ |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 738 | if (ops->get_flags) { |
| 739 | ret = ops->get_flags(dev, desc->offset, &flags); |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 740 | if (ret) |
| 741 | return ret; |
Patrick Delaunay | 695e5fd | 2020-01-13 11:35:06 +0100 | [diff] [blame] | 742 | |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 743 | /* GPIOD_ACTIVE_LOW is saved in desc->flags */ |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 744 | value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0; |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 745 | if (desc->flags & GPIOD_ACTIVE_LOW) |
| 746 | value = !value; |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 747 | flags &= ~(GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE); |
| 748 | flags |= (desc->flags & GPIOD_ACTIVE_LOW); |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 749 | if (value) |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 750 | flags |= GPIOD_IS_OUT_ACTIVE; |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 751 | } else { |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 752 | flags = desc->flags; |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 753 | /* only GPIOD_IS_OUT_ACTIVE is provided by uclass */ |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 754 | flags &= ~GPIOD_IS_OUT_ACTIVE; |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 755 | if ((desc->flags & GPIOD_IS_OUT) && _gpio_get_value(desc)) |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 756 | flags |= GPIOD_IS_OUT_ACTIVE; |
Patrick Delaunay | d2c07e5 | 2020-01-13 11:35:08 +0100 | [diff] [blame] | 757 | } |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 758 | *flagsp = flags; |
Patrick Delaunay | 695e5fd | 2020-01-13 11:35:06 +0100 | [diff] [blame] | 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 763 | /** |
| 764 | * gpio_get_value() - [COMPAT] Sample GPIO pin and return it's value |
| 765 | * gpio: GPIO number |
| 766 | * |
| 767 | * This function implements the API that's compatible with current |
| 768 | * GPIO API used in U-Boot. The request is forwarded to particular |
| 769 | * GPIO driver. Returns the value of the GPIO pin, or negative value |
| 770 | * on error. |
| 771 | */ |
| 772 | int gpio_get_value(unsigned gpio) |
| 773 | { |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 774 | int ret; |
| 775 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 776 | struct gpio_desc desc; |
| 777 | |
| 778 | ret = gpio_to_device(gpio, &desc); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 779 | if (ret) |
| 780 | return ret; |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 781 | return dm_gpio_get_value(&desc); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /** |
| 785 | * gpio_set_value() - [COMPAT] Configure logical value on GPIO pin |
| 786 | * gpio: GPIO number |
| 787 | * value: Logical value to be set on the GPIO pin. |
| 788 | * |
| 789 | * This function implements the API that's compatible with current |
| 790 | * GPIO API used in U-Boot. The request is forwarded to particular |
| 791 | * GPIO driver. Returns 0 on success, negative value on error. |
| 792 | */ |
| 793 | int gpio_set_value(unsigned gpio, int value) |
| 794 | { |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 795 | struct gpio_desc desc; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 796 | int ret; |
| 797 | |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 798 | ret = gpio_to_device(gpio, &desc); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 799 | if (ret) |
| 800 | return ret; |
Simon Glass | ae7123f | 2015-01-05 20:05:27 -0700 | [diff] [blame] | 801 | return dm_gpio_set_value(&desc, value); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 804 | const char *gpio_get_bank_info(struct udevice *dev, int *bit_count) |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 805 | { |
| 806 | struct gpio_dev_priv *priv; |
| 807 | |
| 808 | /* Must be called on an active device */ |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 809 | priv = dev_get_uclass_priv(dev); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 810 | assert(priv); |
| 811 | |
| 812 | *bit_count = priv->gpio_count; |
| 813 | return priv->bank_name; |
| 814 | } |
| 815 | |
Simon Glass | 6449a50 | 2014-10-04 11:29:43 -0600 | [diff] [blame] | 816 | static const char * const gpio_function[GPIOF_COUNT] = { |
| 817 | "input", |
| 818 | "output", |
| 819 | "unused", |
| 820 | "unknown", |
| 821 | "func", |
| 822 | }; |
| 823 | |
Masahiro Yamada | fb07f97 | 2017-06-22 16:50:25 +0900 | [diff] [blame] | 824 | static int get_function(struct udevice *dev, int offset, bool skip_unused, |
| 825 | const char **namep) |
Simon Glass | 6449a50 | 2014-10-04 11:29:43 -0600 | [diff] [blame] | 826 | { |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 827 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 828 | const struct dm_gpio_ops *ops = gpio_get_ops(dev); |
Simon Glass | 6449a50 | 2014-10-04 11:29:43 -0600 | [diff] [blame] | 829 | |
| 830 | BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function)); |
| 831 | if (!device_active(dev)) |
| 832 | return -ENODEV; |
| 833 | if (offset < 0 || offset >= uc_priv->gpio_count) |
| 834 | return -EINVAL; |
| 835 | if (namep) |
| 836 | *namep = uc_priv->name[offset]; |
| 837 | if (skip_unused && !uc_priv->name[offset]) |
| 838 | return GPIOF_UNUSED; |
| 839 | if (ops->get_function) { |
| 840 | int ret; |
| 841 | |
| 842 | ret = ops->get_function(dev, offset); |
| 843 | if (ret < 0) |
| 844 | return ret; |
| 845 | if (ret >= ARRAY_SIZE(gpio_function)) |
| 846 | return -ENODATA; |
| 847 | return ret; |
| 848 | } |
| 849 | |
| 850 | return GPIOF_UNKNOWN; |
| 851 | } |
| 852 | |
| 853 | int gpio_get_function(struct udevice *dev, int offset, const char **namep) |
| 854 | { |
| 855 | return get_function(dev, offset, true, namep); |
| 856 | } |
| 857 | |
| 858 | int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep) |
| 859 | { |
| 860 | return get_function(dev, offset, false, namep); |
| 861 | } |
| 862 | |
Simon Glass | 0757535 | 2014-10-04 11:29:44 -0600 | [diff] [blame] | 863 | int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize) |
| 864 | { |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 865 | const struct dm_gpio_ops *ops = gpio_get_ops(dev); |
Simon Glass | 0757535 | 2014-10-04 11:29:44 -0600 | [diff] [blame] | 866 | struct gpio_dev_priv *priv; |
| 867 | char *str = buf; |
| 868 | int func; |
| 869 | int ret; |
| 870 | int len; |
| 871 | |
| 872 | BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function)); |
| 873 | |
| 874 | *buf = 0; |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 875 | priv = dev_get_uclass_priv(dev); |
Simon Glass | 0757535 | 2014-10-04 11:29:44 -0600 | [diff] [blame] | 876 | ret = gpio_get_raw_function(dev, offset, NULL); |
| 877 | if (ret < 0) |
| 878 | return ret; |
| 879 | func = ret; |
| 880 | len = snprintf(str, buffsize, "%s%d: %s", |
| 881 | priv->bank_name ? priv->bank_name : "", |
| 882 | offset, gpio_function[func]); |
| 883 | if (func == GPIOF_INPUT || func == GPIOF_OUTPUT || |
| 884 | func == GPIOF_UNUSED) { |
| 885 | const char *label; |
| 886 | bool used; |
| 887 | |
| 888 | ret = ops->get_value(dev, offset); |
| 889 | if (ret < 0) |
| 890 | return ret; |
| 891 | used = gpio_get_function(dev, offset, &label) != GPIOF_UNUSED; |
| 892 | snprintf(str + len, buffsize - len, ": %d [%c]%s%s", |
| 893 | ret, |
| 894 | used ? 'x' : ' ', |
| 895 | used ? " " : "", |
| 896 | label ? label : ""); |
| 897 | } |
| 898 | |
| 899 | return 0; |
| 900 | } |
| 901 | |
Simon Glass | 2912686 | 2020-07-07 13:11:44 -0600 | [diff] [blame] | 902 | #if CONFIG_IS_ENABLED(ACPIGEN) |
| 903 | int gpio_get_acpi(const struct gpio_desc *desc, struct acpi_gpio *gpio) |
| 904 | { |
Simon Glass | 3d64774 | 2021-02-04 21:22:05 -0700 | [diff] [blame] | 905 | const struct dm_gpio_ops *ops; |
Simon Glass | 2912686 | 2020-07-07 13:11:44 -0600 | [diff] [blame] | 906 | |
| 907 | memset(gpio, '\0', sizeof(*gpio)); |
| 908 | if (!dm_gpio_is_valid(desc)) { |
| 909 | /* Indicate that the GPIO is not valid */ |
| 910 | gpio->pin_count = 0; |
| 911 | gpio->pins[0] = 0; |
| 912 | return -EINVAL; |
| 913 | } |
| 914 | |
| 915 | ops = gpio_get_ops(desc->dev); |
| 916 | if (!ops->get_acpi) |
| 917 | return -ENOSYS; |
| 918 | |
| 919 | return ops->get_acpi(desc, gpio); |
| 920 | } |
| 921 | #endif |
| 922 | |
Simon Glass | 962f5ca | 2015-04-14 21:03:20 -0600 | [diff] [blame] | 923 | int gpio_claim_vector(const int *gpio_num_array, const char *fmt) |
| 924 | { |
| 925 | int i, ret; |
| 926 | int gpio; |
| 927 | |
| 928 | for (i = 0; i < 32; i++) { |
| 929 | gpio = gpio_num_array[i]; |
| 930 | if (gpio == -1) |
| 931 | break; |
| 932 | ret = gpio_requestf(gpio, fmt, i); |
| 933 | if (ret) |
| 934 | goto err; |
| 935 | ret = gpio_direction_input(gpio); |
| 936 | if (ret) { |
| 937 | gpio_free(gpio); |
| 938 | goto err; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | return 0; |
| 943 | err: |
| 944 | for (i--; i >= 0; i--) |
| 945 | gpio_free(gpio_num_array[i]); |
| 946 | |
| 947 | return ret; |
| 948 | } |
| 949 | |
Simon Glass | e5901c9 | 2014-11-10 18:00:21 -0700 | [diff] [blame] | 950 | /* |
| 951 | * get a number comprised of multiple GPIO values. gpio_num_array points to |
| 952 | * the array of gpio pin numbers to scan, terminated by -1. |
| 953 | */ |
Simon Glass | 962f5ca | 2015-04-14 21:03:20 -0600 | [diff] [blame] | 954 | int gpio_get_values_as_int(const int *gpio_list) |
Simon Glass | e5901c9 | 2014-11-10 18:00:21 -0700 | [diff] [blame] | 955 | { |
| 956 | int gpio; |
| 957 | unsigned bitmask = 1; |
| 958 | unsigned vector = 0; |
Simon Glass | 962f5ca | 2015-04-14 21:03:20 -0600 | [diff] [blame] | 959 | int ret; |
Simon Glass | e5901c9 | 2014-11-10 18:00:21 -0700 | [diff] [blame] | 960 | |
| 961 | while (bitmask && |
Simon Glass | 962f5ca | 2015-04-14 21:03:20 -0600 | [diff] [blame] | 962 | ((gpio = *gpio_list++) != -1)) { |
| 963 | ret = gpio_get_value(gpio); |
| 964 | if (ret < 0) |
| 965 | return ret; |
| 966 | else if (ret) |
Simon Glass | e5901c9 | 2014-11-10 18:00:21 -0700 | [diff] [blame] | 967 | vector |= bitmask; |
| 968 | bitmask <<= 1; |
| 969 | } |
Simon Glass | 962f5ca | 2015-04-14 21:03:20 -0600 | [diff] [blame] | 970 | |
Simon Glass | e5901c9 | 2014-11-10 18:00:21 -0700 | [diff] [blame] | 971 | return vector; |
| 972 | } |
| 973 | |
Simon Glass | 17c43f1 | 2016-03-06 19:27:51 -0700 | [diff] [blame] | 974 | int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count) |
Simon Glass | bbf2478 | 2016-03-06 19:27:50 -0700 | [diff] [blame] | 975 | { |
| 976 | unsigned bitmask = 1; |
| 977 | unsigned vector = 0; |
| 978 | int ret, i; |
| 979 | |
| 980 | for (i = 0; i < count; i++) { |
| 981 | ret = dm_gpio_get_value(&desc_list[i]); |
| 982 | if (ret < 0) |
| 983 | return ret; |
| 984 | else if (ret) |
| 985 | vector |= bitmask; |
| 986 | bitmask <<= 1; |
| 987 | } |
| 988 | |
| 989 | return vector; |
| 990 | } |
| 991 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 992 | /** |
| 993 | * gpio_request_tail: common work for requesting a gpio. |
| 994 | * |
| 995 | * ret: return value from previous work in function which calls |
| 996 | * this function. |
| 997 | * This seems bogus (why calling this function instead not |
| 998 | * calling it and end caller function instead?). |
| 999 | * Because on error in caller function we want to set some |
| 1000 | * default values in gpio desc and have a common error |
| 1001 | * debug message, which provides this function. |
| 1002 | * nodename: Name of node for which gpio gets requested |
| 1003 | * used for gpio label name. |
| 1004 | * args: pointer to output arguments structure |
| 1005 | * list_name: Name of GPIO list |
| 1006 | * used for gpio label name. |
| 1007 | * index: gpio index in gpio list |
| 1008 | * used for gpio label name. |
| 1009 | * desc: pointer to gpio descriptor, filled from this |
| 1010 | * function. |
| 1011 | * flags: gpio flags to use. |
| 1012 | * add_index: should index added to gpio label name |
| 1013 | * gpio_dev: pointer to gpio device from which the gpio |
| 1014 | * will be requested. If NULL try to get the |
| 1015 | * gpio device with uclass_get_device_by_ofnode() |
| 1016 | * |
| 1017 | * return: In error case this function sets default values in |
| 1018 | * gpio descriptor, also emmits a debug message. |
| 1019 | * On success it returns 0 else the error code from |
| 1020 | * function calls, or the error code passed through |
| 1021 | * ret to this function. |
| 1022 | * |
| 1023 | */ |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1024 | static int gpio_request_tail(int ret, const char *nodename, |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 1025 | struct ofnode_phandle_args *args, |
| 1026 | const char *list_name, int index, |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1027 | struct gpio_desc *desc, int flags, |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 1028 | bool add_index, struct udevice *gpio_dev) |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1029 | { |
Patrick Delaunay | 9f2b066 | 2020-01-13 11:35:01 +0100 | [diff] [blame] | 1030 | gpio_desc_init(desc, gpio_dev, 0); |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 1031 | if (ret) |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1032 | goto err; |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1033 | |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1034 | if (!desc->dev) { |
| 1035 | ret = uclass_get_device_by_ofnode(UCLASS_GPIO, args->node, |
| 1036 | &desc->dev); |
| 1037 | if (ret) { |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 1038 | debug("%s: uclass_get_device_by_ofnode failed\n", |
| 1039 | __func__); |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1040 | goto err; |
| 1041 | } |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1042 | } |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 1043 | ret = gpio_find_and_xlate(desc, args); |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1044 | if (ret) { |
| 1045 | debug("%s: gpio_find_and_xlate failed\n", __func__); |
| 1046 | goto err; |
| 1047 | } |
| 1048 | ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s", |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1049 | nodename, list_name, index); |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1050 | if (ret) { |
| 1051 | debug("%s: dm_gpio_requestf failed\n", __func__); |
| 1052 | goto err; |
| 1053 | } |
Simon Glass | 7e0a96d | 2021-02-04 21:22:03 -0700 | [diff] [blame] | 1054 | |
| 1055 | /* Keep any direction flags provided by the devicetree */ |
| 1056 | ret = dm_gpio_set_dir_flags(desc, |
| 1057 | flags | (desc->flags & GPIOD_MASK_DIR)); |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1058 | if (ret) { |
| 1059 | debug("%s: dm_gpio_set_dir failed\n", __func__); |
| 1060 | goto err; |
| 1061 | } |
| 1062 | |
| 1063 | return 0; |
| 1064 | err: |
| 1065 | debug("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n", |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1066 | __func__, nodename, list_name, index, ret); |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1067 | return ret; |
| 1068 | } |
| 1069 | |
Simon Glass | 4fe4067 | 2021-02-04 21:21:54 -0700 | [diff] [blame] | 1070 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1071 | static int _gpio_request_by_name_nodev(ofnode node, const char *list_name, |
| 1072 | int index, struct gpio_desc *desc, |
| 1073 | int flags, bool add_index) |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 1074 | { |
| 1075 | struct ofnode_phandle_args args; |
| 1076 | int ret; |
| 1077 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1078 | ret = ofnode_parse_phandle_with_args(node, list_name, "#gpio-cells", 0, |
| 1079 | index, &args); |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 1080 | |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1081 | return gpio_request_tail(ret, ofnode_get_name(node), &args, list_name, |
| 1082 | index, desc, flags, add_index, NULL); |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 1083 | } |
| 1084 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1085 | int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index, |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1086 | struct gpio_desc *desc, int flags) |
| 1087 | { |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1088 | return _gpio_request_by_name_nodev(node, list_name, index, desc, flags, |
| 1089 | index > 0); |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1092 | int gpio_request_by_name(struct udevice *dev, const char *list_name, int index, |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1093 | struct gpio_desc *desc, int flags) |
| 1094 | { |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1095 | struct ofnode_phandle_args args; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1096 | ofnode node; |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1097 | int ret; |
| 1098 | |
| 1099 | ret = dev_read_phandle_with_args(dev, list_name, "#gpio-cells", 0, |
| 1100 | index, &args); |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1101 | node = dev_ofnode(dev); |
| 1102 | return gpio_request_tail(ret, ofnode_get_name(node), &args, list_name, |
| 1103 | index, desc, flags, index > 0, NULL); |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1106 | int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1107 | struct gpio_desc *desc, int max_count, |
| 1108 | int flags) |
| 1109 | { |
| 1110 | int count; |
| 1111 | int ret; |
| 1112 | |
Przemyslaw Marczak | 2984e7a | 2015-03-31 18:57:16 +0200 | [diff] [blame] | 1113 | for (count = 0; count < max_count; count++) { |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1114 | ret = _gpio_request_by_name_nodev(node, list_name, count, |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1115 | &desc[count], flags, true); |
| 1116 | if (ret == -ENOENT) |
| 1117 | break; |
| 1118 | else if (ret) |
| 1119 | goto err; |
| 1120 | } |
| 1121 | |
| 1122 | /* We ran out of GPIOs in the list */ |
| 1123 | return count; |
| 1124 | |
| 1125 | err: |
| 1126 | gpio_free_list_nodev(desc, count - 1); |
| 1127 | |
| 1128 | return ret; |
| 1129 | } |
| 1130 | |
| 1131 | int gpio_request_list_by_name(struct udevice *dev, const char *list_name, |
| 1132 | struct gpio_desc *desc, int max_count, |
| 1133 | int flags) |
| 1134 | { |
| 1135 | /* |
| 1136 | * This isn't ideal since we don't use dev->name in the debug() |
| 1137 | * calls in gpio_request_by_name(), but we can do this until |
| 1138 | * gpio_request_list_by_name_nodev() can be dropped. |
| 1139 | */ |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 1140 | return gpio_request_list_by_name_nodev(dev_ofnode(dev), list_name, desc, |
| 1141 | max_count, flags); |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | int gpio_get_list_count(struct udevice *dev, const char *list_name) |
| 1145 | { |
| 1146 | int ret; |
| 1147 | |
Patrick Delaunay | 8558217 | 2020-09-09 18:26:16 +0200 | [diff] [blame] | 1148 | ret = dev_read_phandle_with_args(dev, list_name, "#gpio-cells", 0, -1, |
| 1149 | NULL); |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1150 | if (ret) { |
| 1151 | debug("%s: Node '%s', property '%s', GPIO count failed: %d\n", |
| 1152 | __func__, dev->name, list_name, ret); |
| 1153 | } |
| 1154 | |
| 1155 | return ret; |
| 1156 | } |
Simon Glass | 4fe4067 | 2021-02-04 21:21:54 -0700 | [diff] [blame] | 1157 | #endif /* OF_PLATDATA */ |
Simon Glass | 3669e0e | 2015-01-05 20:05:29 -0700 | [diff] [blame] | 1158 | |
| 1159 | int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc) |
| 1160 | { |
| 1161 | /* For now, we don't do any checking of dev */ |
| 1162 | return _dm_gpio_free(desc->dev, desc->offset); |
| 1163 | } |
| 1164 | |
| 1165 | int gpio_free_list(struct udevice *dev, struct gpio_desc *desc, int count) |
| 1166 | { |
| 1167 | int i; |
| 1168 | |
| 1169 | /* For now, we don't do any checking of dev */ |
| 1170 | for (i = 0; i < count; i++) |
| 1171 | dm_gpio_free(dev, &desc[i]); |
| 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | int gpio_free_list_nodev(struct gpio_desc *desc, int count) |
| 1177 | { |
| 1178 | return gpio_free_list(NULL, desc, count); |
| 1179 | } |
| 1180 | |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1181 | /* We need to renumber the GPIOs when any driver is probed/removed */ |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 1182 | static int gpio_renumber(struct udevice *removed_dev) |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1183 | { |
| 1184 | struct gpio_dev_priv *uc_priv; |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 1185 | struct udevice *dev; |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1186 | struct uclass *uc; |
| 1187 | unsigned base; |
| 1188 | int ret; |
| 1189 | |
| 1190 | ret = uclass_get(UCLASS_GPIO, &uc); |
| 1191 | if (ret) |
| 1192 | return ret; |
| 1193 | |
| 1194 | /* Ensure that we have a base for each bank */ |
| 1195 | base = 0; |
| 1196 | uclass_foreach_dev(dev, uc) { |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 1197 | if (device_active(dev) && dev != removed_dev) { |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 1198 | uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1199 | uc_priv->gpio_base = base; |
| 1200 | base += uc_priv->gpio_count; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
Simon Glass | 17c43f1 | 2016-03-06 19:27:51 -0700 | [diff] [blame] | 1207 | int gpio_get_number(const struct gpio_desc *desc) |
Simon Glass | 56a71f8 | 2015-03-25 12:21:58 -0600 | [diff] [blame] | 1208 | { |
| 1209 | struct udevice *dev = desc->dev; |
| 1210 | struct gpio_dev_priv *uc_priv; |
| 1211 | |
| 1212 | if (!dev) |
| 1213 | return -1; |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 1214 | uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 56a71f8 | 2015-03-25 12:21:58 -0600 | [diff] [blame] | 1215 | |
| 1216 | return uc_priv->gpio_base + desc->offset; |
| 1217 | } |
| 1218 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 1219 | static int gpio_post_probe(struct udevice *dev) |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1220 | { |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 1221 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 1222 | |
| 1223 | uc_priv->name = calloc(uc_priv->gpio_count, sizeof(char *)); |
| 1224 | if (!uc_priv->name) |
| 1225 | return -ENOMEM; |
| 1226 | |
| 1227 | return gpio_renumber(NULL); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 1230 | static int gpio_pre_remove(struct udevice *dev) |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1231 | { |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 1232 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | b892d12 | 2014-10-04 11:29:42 -0600 | [diff] [blame] | 1233 | int i; |
| 1234 | |
| 1235 | for (i = 0; i < uc_priv->gpio_count; i++) { |
| 1236 | if (uc_priv->name[i]) |
| 1237 | free(uc_priv->name[i]); |
| 1238 | } |
| 1239 | free(uc_priv->name); |
| 1240 | |
| 1241 | return gpio_renumber(dev); |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1244 | int gpio_dev_request_index(struct udevice *dev, const char *nodename, |
| 1245 | char *list_name, int index, int flags, |
| 1246 | int dtflags, struct gpio_desc *desc) |
| 1247 | { |
| 1248 | struct ofnode_phandle_args args; |
| 1249 | |
| 1250 | args.node = ofnode_null(); |
| 1251 | args.args_count = 2; |
| 1252 | args.args[0] = index; |
| 1253 | args.args[1] = dtflags; |
| 1254 | |
| 1255 | return gpio_request_tail(0, nodename, &args, list_name, index, desc, |
| 1256 | flags, 0, dev); |
| 1257 | } |
| 1258 | |
Jean-Jacques Hiblot | d4b722e | 2020-09-11 13:43:34 +0530 | [diff] [blame] | 1259 | static void devm_gpiod_release(struct udevice *dev, void *res) |
| 1260 | { |
| 1261 | dm_gpio_free(dev, res); |
| 1262 | } |
| 1263 | |
| 1264 | static int devm_gpiod_match(struct udevice *dev, void *res, void *data) |
| 1265 | { |
| 1266 | return res == data; |
| 1267 | } |
| 1268 | |
| 1269 | struct gpio_desc *devm_gpiod_get_index(struct udevice *dev, const char *id, |
| 1270 | unsigned int index, int flags) |
| 1271 | { |
| 1272 | int rc; |
| 1273 | struct gpio_desc *desc; |
| 1274 | char *propname; |
| 1275 | static const char suffix[] = "-gpios"; |
| 1276 | |
| 1277 | propname = malloc(strlen(id) + sizeof(suffix)); |
| 1278 | if (!propname) { |
| 1279 | rc = -ENOMEM; |
| 1280 | goto end; |
| 1281 | } |
| 1282 | |
| 1283 | strcpy(propname, id); |
| 1284 | strcat(propname, suffix); |
| 1285 | |
| 1286 | desc = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc), |
| 1287 | __GFP_ZERO); |
| 1288 | if (unlikely(!desc)) { |
| 1289 | rc = -ENOMEM; |
| 1290 | goto end; |
| 1291 | } |
| 1292 | |
| 1293 | rc = gpio_request_by_name(dev, propname, index, desc, flags); |
| 1294 | |
| 1295 | end: |
| 1296 | if (propname) |
| 1297 | free(propname); |
| 1298 | |
| 1299 | if (rc) |
| 1300 | return ERR_PTR(rc); |
| 1301 | |
| 1302 | devres_add(dev, desc); |
| 1303 | |
| 1304 | return desc; |
| 1305 | } |
| 1306 | |
| 1307 | struct gpio_desc *devm_gpiod_get_index_optional(struct udevice *dev, |
| 1308 | const char *id, |
| 1309 | unsigned int index, |
| 1310 | int flags) |
| 1311 | { |
| 1312 | struct gpio_desc *desc = devm_gpiod_get_index(dev, id, index, flags); |
| 1313 | |
| 1314 | if (IS_ERR(desc)) |
| 1315 | return NULL; |
| 1316 | |
| 1317 | return desc; |
| 1318 | } |
| 1319 | |
| 1320 | void devm_gpiod_put(struct udevice *dev, struct gpio_desc *desc) |
| 1321 | { |
| 1322 | int rc; |
| 1323 | |
| 1324 | rc = devres_release(dev, devm_gpiod_release, devm_gpiod_match, desc); |
| 1325 | WARN_ON(rc); |
| 1326 | } |
| 1327 | |
Michal Simek | 1b4c2aa | 2018-07-12 12:42:27 +0200 | [diff] [blame] | 1328 | static int gpio_post_bind(struct udevice *dev) |
| 1329 | { |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1330 | struct udevice *child; |
| 1331 | ofnode node; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1332 | |
Michal Simek | 1b4c2aa | 2018-07-12 12:42:27 +0200 | [diff] [blame] | 1333 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
| 1334 | struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops(dev); |
| 1335 | static int reloc_done; |
| 1336 | |
| 1337 | if (!reloc_done) { |
| 1338 | if (ops->request) |
| 1339 | ops->request += gd->reloc_off; |
Simon Glass | 093152f | 2020-02-04 20:15:17 -0700 | [diff] [blame] | 1340 | if (ops->rfree) |
| 1341 | ops->rfree += gd->reloc_off; |
Michal Simek | 1b4c2aa | 2018-07-12 12:42:27 +0200 | [diff] [blame] | 1342 | if (ops->direction_input) |
| 1343 | ops->direction_input += gd->reloc_off; |
| 1344 | if (ops->direction_output) |
| 1345 | ops->direction_output += gd->reloc_off; |
| 1346 | if (ops->get_value) |
| 1347 | ops->get_value += gd->reloc_off; |
| 1348 | if (ops->set_value) |
| 1349 | ops->set_value += gd->reloc_off; |
Michal Simek | 1b4c2aa | 2018-07-12 12:42:27 +0200 | [diff] [blame] | 1350 | if (ops->get_function) |
| 1351 | ops->get_function += gd->reloc_off; |
| 1352 | if (ops->xlate) |
| 1353 | ops->xlate += gd->reloc_off; |
Simon Glass | 13979fc | 2021-02-04 21:21:55 -0700 | [diff] [blame] | 1354 | if (ops->set_flags) |
| 1355 | ops->set_flags += gd->reloc_off; |
Simon Glass | 9648789 | 2021-02-04 21:21:56 -0700 | [diff] [blame] | 1356 | if (ops->get_flags) |
| 1357 | ops->get_flags += gd->reloc_off; |
Michal Simek | 1b4c2aa | 2018-07-12 12:42:27 +0200 | [diff] [blame] | 1358 | |
| 1359 | reloc_done++; |
| 1360 | } |
| 1361 | #endif |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1362 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 1363 | if (IS_ENABLED(CONFIG_GPIO_HOG)) { |
| 1364 | dev_for_each_subnode(node, dev) { |
| 1365 | if (ofnode_read_bool(node, "gpio-hog")) { |
| 1366 | const char *name = ofnode_get_name(node); |
| 1367 | int ret; |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1368 | |
Heiko Schocher | 49b10cb | 2019-07-17 06:59:51 +0200 | [diff] [blame] | 1369 | ret = device_bind_driver_to_node(dev, |
| 1370 | "gpio_hog", |
| 1371 | name, node, |
| 1372 | &child); |
| 1373 | if (ret) |
| 1374 | return ret; |
| 1375 | } |
Heiko Schocher | 5fc7cf8 | 2019-06-12 06:11:46 +0200 | [diff] [blame] | 1376 | } |
| 1377 | } |
Michal Simek | 1b4c2aa | 2018-07-12 12:42:27 +0200 | [diff] [blame] | 1378 | return 0; |
| 1379 | } |
| 1380 | |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1381 | UCLASS_DRIVER(gpio) = { |
| 1382 | .id = UCLASS_GPIO, |
| 1383 | .name = "gpio", |
Bhuvanchandra DV | ae89bb0 | 2015-06-01 18:37:15 +0530 | [diff] [blame] | 1384 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1385 | .post_probe = gpio_post_probe, |
Michal Simek | 1b4c2aa | 2018-07-12 12:42:27 +0200 | [diff] [blame] | 1386 | .post_bind = gpio_post_bind, |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1387 | .pre_remove = gpio_pre_remove, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1388 | .per_device_auto = sizeof(struct gpio_dev_priv), |
Simon Glass | 96495d9 | 2014-02-26 15:59:24 -0700 | [diff] [blame] | 1389 | }; |