blob: 5c82a4a7dbf97d0e6c53911e8a90ac9cc4e7e549 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasse821d182014-02-26 15:59:24 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glasse821d182014-02-26 15:59:24 -07004 */
5
6#include <common.h>
7#include <dm.h>
Heiko Schocher39cb3402019-06-12 06:11:46 +02008#include <dm/device-internal.h>
9#include <dm/lists.h>
10#include <dm/uclass-internal.h>
Eric Nelson786e98d2016-04-24 16:32:40 -070011#include <dt-bindings/gpio/gpio.h>
Simon Glasse821d182014-02-26 15:59:24 -070012#include <errno.h>
Simon Glassd3322bb2015-01-05 20:05:28 -070013#include <fdtdec.h>
Simon Glass0f4517d2014-10-04 11:29:42 -060014#include <malloc.h>
Simon Glasse821d182014-02-26 15:59:24 -070015#include <asm/gpio.h>
Masahiro Yamada78eeb912016-01-24 23:27:48 +090016#include <linux/bug.h>
Simon Glass43b2e1a2014-10-22 21:37:01 -060017#include <linux/ctype.h>
Simon Glasse821d182014-02-26 15:59:24 -070018
Simon Glass16e10402015-01-05 20:05:29 -070019DECLARE_GLOBAL_DATA_PTR;
20
Simon Glasse821d182014-02-26 15:59:24 -070021/**
Patrick Delaunay758bba92020-01-13 11:35:01 +010022 * gpio_desc_init() - Initialize the GPIO descriptor
23 *
24 * @desc: GPIO descriptor to initialize
25 * @dev: GPIO device
26 * @offset: Offset of device GPIO
27 */
28static void gpio_desc_init(struct gpio_desc *desc,
29 struct udevice *dev,
30 uint offset)
31{
32 desc->dev = dev;
33 desc->offset = offset;
34 desc->flags = 0;
35}
36
37/**
Simon Glasse821d182014-02-26 15:59:24 -070038 * gpio_to_device() - Convert global GPIO number to device, number
Simon Glasse821d182014-02-26 15:59:24 -070039 *
40 * Convert the GPIO number to an entry in the list of GPIOs
41 * or GPIO blocks registered with the GPIO controller. Returns
42 * entry on success, NULL on error.
Simon Glassce555292015-01-05 20:05:27 -070043 *
44 * @gpio: The numeric representation of the GPIO
45 * @desc: Returns description (desc->flags will always be 0)
46 * @return 0 if found, -ENOENT if not found
Simon Glasse821d182014-02-26 15:59:24 -070047 */
Simon Glassce555292015-01-05 20:05:27 -070048static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)
Simon Glasse821d182014-02-26 15:59:24 -070049{
50 struct gpio_dev_priv *uc_priv;
Heiko Schocherb74fcb42014-05-22 12:43:05 +020051 struct udevice *dev;
Simon Glasse821d182014-02-26 15:59:24 -070052 int ret;
53
54 for (ret = uclass_first_device(UCLASS_GPIO, &dev);
55 dev;
56 ret = uclass_next_device(&dev)) {
Simon Glassde0977b2015-03-05 12:25:20 -070057 uc_priv = dev_get_uclass_priv(dev);
Simon Glasse821d182014-02-26 15:59:24 -070058 if (gpio >= uc_priv->gpio_base &&
59 gpio < uc_priv->gpio_base + uc_priv->gpio_count) {
Patrick Delaunay758bba92020-01-13 11:35:01 +010060 gpio_desc_init(desc, dev, gpio - uc_priv->gpio_base);
Simon Glasse821d182014-02-26 15:59:24 -070061 return 0;
62 }
63 }
64
65 /* No such GPIO */
Simon Glassce555292015-01-05 20:05:27 -070066 return ret ? ret : -ENOENT;
Simon Glasse821d182014-02-26 15:59:24 -070067}
68
Simon Glass215bcc72015-06-23 15:38:40 -060069int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
Simon Glasse821d182014-02-26 15:59:24 -070070{
Simon Glass43b2e1a2014-10-22 21:37:01 -060071 struct gpio_dev_priv *uc_priv = NULL;
Heiko Schocherb74fcb42014-05-22 12:43:05 +020072 struct udevice *dev;
Simon Glass43b2e1a2014-10-22 21:37:01 -060073 ulong offset;
74 int numeric;
Simon Glasse821d182014-02-26 15:59:24 -070075 int ret;
76
Simon Glass43b2e1a2014-10-22 21:37:01 -060077 numeric = isdigit(*name) ? simple_strtoul(name, NULL, 10) : -1;
Simon Glasse821d182014-02-26 15:59:24 -070078 for (ret = uclass_first_device(UCLASS_GPIO, &dev);
79 dev;
80 ret = uclass_next_device(&dev)) {
Simon Glasse821d182014-02-26 15:59:24 -070081 int len;
82
Simon Glassde0977b2015-03-05 12:25:20 -070083 uc_priv = dev_get_uclass_priv(dev);
Simon Glass43b2e1a2014-10-22 21:37:01 -060084 if (numeric != -1) {
85 offset = numeric - uc_priv->gpio_base;
86 /* Allow GPIOs to be numbered from 0 */
Tom Rini26fd9682017-05-10 15:20:15 -040087 if (offset < uc_priv->gpio_count)
Simon Glass43b2e1a2014-10-22 21:37:01 -060088 break;
89 }
90
Simon Glasse821d182014-02-26 15:59:24 -070091 len = uc_priv->bank_name ? strlen(uc_priv->bank_name) : 0;
92
Simon Glassd4acf632014-06-11 23:29:47 -060093 if (!strncasecmp(name, uc_priv->bank_name, len)) {
Simon Glass43b2e1a2014-10-22 21:37:01 -060094 if (!strict_strtoul(name + len, 10, &offset))
95 break;
Simon Glasse821d182014-02-26 15:59:24 -070096 }
97 }
98
Simon Glass43b2e1a2014-10-22 21:37:01 -060099 if (!dev)
100 return ret ? ret : -EINVAL;
101
Patrick Delaunay758bba92020-01-13 11:35:01 +0100102 gpio_desc_init(desc, dev, offset);
Simon Glass215bcc72015-06-23 15:38:40 -0600103
104 return 0;
105}
106
107int gpio_lookup_name(const char *name, struct udevice **devp,
108 unsigned int *offsetp, unsigned int *gpiop)
109{
110 struct gpio_desc desc;
111 int ret;
112
113 if (devp)
114 *devp = NULL;
115 ret = dm_gpio_lookup_name(name, &desc);
116 if (ret)
117 return ret;
118
Simon Glass43b2e1a2014-10-22 21:37:01 -0600119 if (devp)
Simon Glass215bcc72015-06-23 15:38:40 -0600120 *devp = desc.dev;
Simon Glass43b2e1a2014-10-22 21:37:01 -0600121 if (offsetp)
Simon Glass215bcc72015-06-23 15:38:40 -0600122 *offsetp = desc.offset;
123 if (gpiop) {
124 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(desc.dev);
125
126 *gpiop = uc_priv->gpio_base + desc.offset;
127 }
Simon Glass43b2e1a2014-10-22 21:37:01 -0600128
129 return 0;
Simon Glasse821d182014-02-26 15:59:24 -0700130}
131
Simon Glass12faa022017-05-18 20:09:18 -0600132int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
133 struct ofnode_phandle_args *args)
Eric Nelson786e98d2016-04-24 16:32:40 -0700134{
135 if (args->args_count < 1)
136 return -EINVAL;
137
138 desc->offset = args->args[0];
139
140 if (args->args_count < 2)
141 return 0;
142
143 if (args->args[1] & GPIO_ACTIVE_LOW)
144 desc->flags = GPIOD_ACTIVE_LOW;
145
146 return 0;
147}
148
Simon Glass16e10402015-01-05 20:05:29 -0700149static int gpio_find_and_xlate(struct gpio_desc *desc,
Simon Glass12faa022017-05-18 20:09:18 -0600150 struct ofnode_phandle_args *args)
Simon Glassd3322bb2015-01-05 20:05:28 -0700151{
152 struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
153
Eric Nelson786e98d2016-04-24 16:32:40 -0700154 if (ops->xlate)
155 return ops->xlate(desc->dev, desc, args);
Simon Glassd3322bb2015-01-05 20:05:28 -0700156 else
Eric Nelson786e98d2016-04-24 16:32:40 -0700157 return gpio_xlate_offs_flags(desc->dev, desc, args);
Simon Glassd3322bb2015-01-05 20:05:28 -0700158}
159
Heiko Schocher58e4c382019-07-17 06:59:51 +0200160#if defined(CONFIG_GPIO_HOG)
Heiko Schocher39cb3402019-06-12 06:11:46 +0200161
162struct gpio_hog_priv {
163 struct gpio_desc gpiod;
164};
165
166struct gpio_hog_data {
167 int gpiod_flags;
168 int value;
169 u32 val[2];
170};
171
172static int gpio_hog_ofdata_to_platdata(struct udevice *dev)
173{
174 struct gpio_hog_data *plat = dev_get_platdata(dev);
175 const char *nodename;
176 int ret;
177
178 plat->value = 0;
179 if (dev_read_bool(dev, "input")) {
180 plat->gpiod_flags = GPIOD_IS_IN;
181 } else if (dev_read_bool(dev, "output-high")) {
182 plat->value = 1;
183 plat->gpiod_flags = GPIOD_IS_OUT;
184 } else if (dev_read_bool(dev, "output-low")) {
185 plat->gpiod_flags = GPIOD_IS_OUT;
186 } else {
187 printf("%s: missing gpio-hog state.\n", __func__);
188 return -EINVAL;
189 }
190 ret = dev_read_u32_array(dev, "gpios", plat->val, 2);
191 if (ret) {
192 printf("%s: wrong gpios property, 2 values needed %d\n",
193 __func__, ret);
194 return ret;
195 }
196 nodename = dev_read_string(dev, "line-name");
Heiko Schocher58e4c382019-07-17 06:59:51 +0200197 if (nodename)
198 device_set_name(dev, nodename);
Heiko Schocher39cb3402019-06-12 06:11:46 +0200199
200 return 0;
201}
202
203static int gpio_hog_probe(struct udevice *dev)
204{
205 struct gpio_hog_data *plat = dev_get_platdata(dev);
206 struct gpio_hog_priv *priv = dev_get_priv(dev);
207 int ret;
208
209 ret = gpio_dev_request_index(dev->parent, dev->name, "gpio-hog",
210 plat->val[0], plat->gpiod_flags,
211 plat->val[1], &priv->gpiod);
212 if (ret < 0) {
213 debug("%s: node %s could not get gpio.\n", __func__,
214 dev->name);
215 return ret;
216 }
Heiko Schocher58e4c382019-07-17 06:59:51 +0200217
218 if (plat->gpiod_flags == GPIOD_IS_OUT) {
219 ret = dm_gpio_set_value(&priv->gpiod, plat->value);
220 if (ret < 0) {
221 debug("%s: node %s could not set gpio.\n", __func__,
222 dev->name);
223 return ret;
224 }
225 }
Heiko Schocher39cb3402019-06-12 06:11:46 +0200226
227 return 0;
228}
229
230int gpio_hog_probe_all(void)
231{
232 struct udevice *dev;
233 int ret;
Heiko Schocher58e4c382019-07-17 06:59:51 +0200234 int retval = 0;
Heiko Schocher39cb3402019-06-12 06:11:46 +0200235
236 for (uclass_first_device(UCLASS_NOP, &dev);
237 dev;
238 uclass_find_next_device(&dev)) {
239 if (dev->driver == DM_GET_DRIVER(gpio_hog)) {
240 ret = device_probe(dev);
Heiko Schocher58e4c382019-07-17 06:59:51 +0200241 if (ret) {
242 printf("Failed to probe device %s err: %d\n",
243 dev->name, ret);
244 retval = ret;
245 }
Heiko Schocher39cb3402019-06-12 06:11:46 +0200246 }
247 }
248
Heiko Schocher58e4c382019-07-17 06:59:51 +0200249 return retval;
Heiko Schocher39cb3402019-06-12 06:11:46 +0200250}
251
Heiko Schocher58e4c382019-07-17 06:59:51 +0200252int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc)
Heiko Schocher39cb3402019-06-12 06:11:46 +0200253{
254 struct udevice *dev;
255
Heiko Schocher58e4c382019-07-17 06:59:51 +0200256 *desc = NULL;
Heiko Schocher39cb3402019-06-12 06:11:46 +0200257 gpio_hog_probe_all();
258 if (!uclass_get_device_by_name(UCLASS_NOP, name, &dev)) {
259 struct gpio_hog_priv *priv = dev_get_priv(dev);
260
Heiko Schocher58e4c382019-07-17 06:59:51 +0200261 *desc = &priv->gpiod;
262 return 0;
Heiko Schocher39cb3402019-06-12 06:11:46 +0200263 }
264
Heiko Schocher58e4c382019-07-17 06:59:51 +0200265 return -ENODEV;
Heiko Schocher39cb3402019-06-12 06:11:46 +0200266}
267
268U_BOOT_DRIVER(gpio_hog) = {
269 .name = "gpio_hog",
270 .id = UCLASS_NOP,
271 .ofdata_to_platdata = gpio_hog_ofdata_to_platdata,
272 .probe = gpio_hog_probe,
273 .priv_auto_alloc_size = sizeof(struct gpio_hog_priv),
274 .platdata_auto_alloc_size = sizeof(struct gpio_hog_data),
275};
276#else
Heiko Schocher58e4c382019-07-17 06:59:51 +0200277int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc)
Heiko Schocher39cb3402019-06-12 06:11:46 +0200278{
Heiko Schocher58e4c382019-07-17 06:59:51 +0200279 return 0;
Heiko Schocher39cb3402019-06-12 06:11:46 +0200280}
281#endif
282
Simon Glass047cdb32015-06-23 15:38:41 -0600283int dm_gpio_request(struct gpio_desc *desc, const char *label)
Simon Glassce555292015-01-05 20:05:27 -0700284{
285 struct udevice *dev = desc->dev;
286 struct gpio_dev_priv *uc_priv;
287 char *str;
288 int ret;
289
Simon Glassde0977b2015-03-05 12:25:20 -0700290 uc_priv = dev_get_uclass_priv(dev);
Simon Glassce555292015-01-05 20:05:27 -0700291 if (uc_priv->name[desc->offset])
292 return -EBUSY;
293 str = strdup(label);
294 if (!str)
295 return -ENOMEM;
296 if (gpio_get_ops(dev)->request) {
297 ret = gpio_get_ops(dev)->request(dev, desc->offset, label);
298 if (ret) {
299 free(str);
300 return ret;
301 }
302 }
303 uc_priv->name[desc->offset] = str;
304
305 return 0;
306}
307
Simon Glass16e10402015-01-05 20:05:29 -0700308static int dm_gpio_requestf(struct gpio_desc *desc, const char *fmt, ...)
309{
Simon Glass7611ac62019-09-25 08:56:27 -0600310#if !defined(CONFIG_SPL_BUILD) || !CONFIG_IS_ENABLED(USE_TINY_PRINTF)
Simon Glass16e10402015-01-05 20:05:29 -0700311 va_list args;
312 char buf[40];
313
314 va_start(args, fmt);
315 vscnprintf(buf, sizeof(buf), fmt, args);
316 va_end(args);
317 return dm_gpio_request(desc, buf);
Simon Glassee8a3d92015-12-29 05:22:48 -0700318#else
319 return dm_gpio_request(desc, fmt);
320#endif
Simon Glass16e10402015-01-05 20:05:29 -0700321}
322
Simon Glasse821d182014-02-26 15:59:24 -0700323/**
324 * gpio_request() - [COMPAT] Request GPIO
325 * gpio: GPIO number
326 * label: Name for the requested GPIO
327 *
Simon Glass0f4517d2014-10-04 11:29:42 -0600328 * The label is copied and allocated so the caller does not need to keep
329 * the pointer around.
330 *
Simon Glasse821d182014-02-26 15:59:24 -0700331 * This function implements the API that's compatible with current
332 * GPIO API used in U-Boot. The request is forwarded to particular
333 * GPIO driver. Returns 0 on success, negative value on error.
334 */
335int gpio_request(unsigned gpio, const char *label)
336{
Simon Glassce555292015-01-05 20:05:27 -0700337 struct gpio_desc desc;
Simon Glasse821d182014-02-26 15:59:24 -0700338 int ret;
339
Simon Glassce555292015-01-05 20:05:27 -0700340 ret = gpio_to_device(gpio, &desc);
Simon Glasse821d182014-02-26 15:59:24 -0700341 if (ret)
342 return ret;
343
Simon Glassce555292015-01-05 20:05:27 -0700344 return dm_gpio_request(&desc, label);
Simon Glasse821d182014-02-26 15:59:24 -0700345}
346
347/**
Simon Glass1b27d602014-10-04 11:29:49 -0600348 * gpio_requestf() - [COMPAT] Request GPIO
349 * @gpio: GPIO number
350 * @fmt: Format string for the requested GPIO
351 * @...: Arguments for the printf() format string
352 *
353 * This function implements the API that's compatible with current
354 * GPIO API used in U-Boot. The request is forwarded to particular
355 * GPIO driver. Returns 0 on success, negative value on error.
356 */
357int gpio_requestf(unsigned gpio, const char *fmt, ...)
358{
Simon Glass7611ac62019-09-25 08:56:27 -0600359#if !defined(CONFIG_SPL_BUILD) || !CONFIG_IS_ENABLED(USE_TINY_PRINTF)
Simon Glass1b27d602014-10-04 11:29:49 -0600360 va_list args;
361 char buf[40];
362
363 va_start(args, fmt);
364 vscnprintf(buf, sizeof(buf), fmt, args);
365 va_end(args);
366 return gpio_request(gpio, buf);
Simon Glassee8a3d92015-12-29 05:22:48 -0700367#else
368 return gpio_request(gpio, fmt);
369#endif
Simon Glass1b27d602014-10-04 11:29:49 -0600370}
371
Simon Glassce555292015-01-05 20:05:27 -0700372int _dm_gpio_free(struct udevice *dev, uint offset)
Simon Glasse821d182014-02-26 15:59:24 -0700373{
Simon Glass0f4517d2014-10-04 11:29:42 -0600374 struct gpio_dev_priv *uc_priv;
Simon Glasse821d182014-02-26 15:59:24 -0700375 int ret;
376
Simon Glassde0977b2015-03-05 12:25:20 -0700377 uc_priv = dev_get_uclass_priv(dev);
Simon Glass0f4517d2014-10-04 11:29:42 -0600378 if (!uc_priv->name[offset])
379 return -ENXIO;
Simon Glassb3a47542020-02-04 20:15:17 -0700380 if (gpio_get_ops(dev)->rfree) {
381 ret = gpio_get_ops(dev)->rfree(dev, offset);
Simon Glass0f4517d2014-10-04 11:29:42 -0600382 if (ret)
383 return ret;
384 }
385
386 free(uc_priv->name[offset]);
387 uc_priv->name[offset] = NULL;
388
389 return 0;
390}
391
Simon Glassce555292015-01-05 20:05:27 -0700392/**
393 * gpio_free() - [COMPAT] Relinquish GPIO
394 * gpio: GPIO number
395 *
396 * This function implements the API that's compatible with current
397 * GPIO API used in U-Boot. The request is forwarded to particular
398 * GPIO driver. Returns 0 on success, negative value on error.
399 */
400int gpio_free(unsigned gpio)
401{
402 struct gpio_desc desc;
403 int ret;
404
405 ret = gpio_to_device(gpio, &desc);
406 if (ret)
407 return ret;
408
409 return _dm_gpio_free(desc.dev, desc.offset);
410}
411
Simon Glassfd838972016-03-06 19:27:51 -0700412static int check_reserved(const struct gpio_desc *desc, const char *func)
Simon Glass0f4517d2014-10-04 11:29:42 -0600413{
Simon Glass230c1432015-07-02 18:16:16 -0600414 struct gpio_dev_priv *uc_priv;
415
416 if (!dm_gpio_is_valid(desc))
417 return -ENOENT;
Simon Glass0f4517d2014-10-04 11:29:42 -0600418
Simon Glass230c1432015-07-02 18:16:16 -0600419 uc_priv = dev_get_uclass_priv(desc->dev);
Simon Glassce555292015-01-05 20:05:27 -0700420 if (!uc_priv->name[desc->offset]) {
Simon Glass0f4517d2014-10-04 11:29:42 -0600421 printf("%s: %s: error: gpio %s%d not reserved\n",
Simon Glassce555292015-01-05 20:05:27 -0700422 desc->dev->name, func,
423 uc_priv->bank_name ? uc_priv->bank_name : "",
424 desc->offset);
Simon Glass0f4517d2014-10-04 11:29:42 -0600425 return -EBUSY;
426 }
427
428 return 0;
Simon Glasse821d182014-02-26 15:59:24 -0700429}
430
431/**
432 * gpio_direction_input() - [COMPAT] Set GPIO direction to input
433 * gpio: GPIO number
434 *
435 * This function implements the API that's compatible with current
436 * GPIO API used in U-Boot. The request is forwarded to particular
437 * GPIO driver. Returns 0 on success, negative value on error.
438 */
439int gpio_direction_input(unsigned gpio)
440{
Simon Glassce555292015-01-05 20:05:27 -0700441 struct gpio_desc desc;
Simon Glasse821d182014-02-26 15:59:24 -0700442 int ret;
443
Simon Glassce555292015-01-05 20:05:27 -0700444 ret = gpio_to_device(gpio, &desc);
Simon Glasse821d182014-02-26 15:59:24 -0700445 if (ret)
446 return ret;
Simon Glassce555292015-01-05 20:05:27 -0700447 ret = check_reserved(&desc, "dir_input");
448 if (ret)
449 return ret;
Simon Glasse821d182014-02-26 15:59:24 -0700450
Simon Glassce555292015-01-05 20:05:27 -0700451 return gpio_get_ops(desc.dev)->direction_input(desc.dev, desc.offset);
Simon Glasse821d182014-02-26 15:59:24 -0700452}
453
454/**
455 * gpio_direction_output() - [COMPAT] Set GPIO direction to output and set value
456 * gpio: GPIO number
457 * value: Logical value to be set on the GPIO pin
458 *
459 * This function implements the API that's compatible with current
460 * GPIO API used in U-Boot. The request is forwarded to particular
461 * GPIO driver. Returns 0 on success, negative value on error.
462 */
463int gpio_direction_output(unsigned gpio, int value)
464{
Simon Glassce555292015-01-05 20:05:27 -0700465 struct gpio_desc desc;
466 int ret;
467
468 ret = gpio_to_device(gpio, &desc);
469 if (ret)
470 return ret;
471 ret = check_reserved(&desc, "dir_output");
472 if (ret)
473 return ret;
474
475 return gpio_get_ops(desc.dev)->direction_output(desc.dev,
476 desc.offset, value);
477}
478
Patrick Delaunay4c2c96f2020-01-13 11:35:02 +0100479static int _gpio_get_value(const struct gpio_desc *desc)
Simon Glassce555292015-01-05 20:05:27 -0700480{
481 int value;
Patrick Delaunay4c2c96f2020-01-13 11:35:02 +0100482
483 value = gpio_get_ops(desc->dev)->get_value(desc->dev, desc->offset);
484
485 return desc->flags & GPIOD_ACTIVE_LOW ? !value : value;
486}
487
488int dm_gpio_get_value(const struct gpio_desc *desc)
489{
Simon Glassce555292015-01-05 20:05:27 -0700490 int ret;
491
492 ret = check_reserved(desc, "get_value");
493 if (ret)
494 return ret;
495
Patrick Delaunay4c2c96f2020-01-13 11:35:02 +0100496 return _gpio_get_value(desc);
Simon Glassce555292015-01-05 20:05:27 -0700497}
498
Simon Glassfd838972016-03-06 19:27:51 -0700499int dm_gpio_set_value(const struct gpio_desc *desc, int value)
Simon Glassce555292015-01-05 20:05:27 -0700500{
501 int ret;
502
503 ret = check_reserved(desc, "set_value");
504 if (ret)
505 return ret;
506
507 if (desc->flags & GPIOD_ACTIVE_LOW)
508 value = !value;
509 gpio_get_ops(desc->dev)->set_value(desc->dev, desc->offset, value);
510 return 0;
511}
512
513int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
514{
515 struct udevice *dev = desc->dev;
516 struct dm_gpio_ops *ops = gpio_get_ops(dev);
Simon Glasse821d182014-02-26 15:59:24 -0700517 int ret;
518
Simon Glassce555292015-01-05 20:05:27 -0700519 ret = check_reserved(desc, "set_dir");
Simon Glasse821d182014-02-26 15:59:24 -0700520 if (ret)
521 return ret;
522
Simon Glassce555292015-01-05 20:05:27 -0700523 if (flags & GPIOD_IS_OUT) {
524 int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;
525
526 if (flags & GPIOD_ACTIVE_LOW)
527 value = !value;
528 ret = ops->direction_output(dev, desc->offset, value);
529 } else if (flags & GPIOD_IS_IN) {
530 ret = ops->direction_input(dev, desc->offset);
531 }
532 if (ret)
533 return ret;
534 /*
535 * Update desc->flags here, so that GPIO_ACTIVE_LOW is honoured in
536 * futures
537 */
538 desc->flags = flags;
539
540 return 0;
541}
542
543int dm_gpio_set_dir(struct gpio_desc *desc)
544{
545 return dm_gpio_set_dir_flags(desc, desc->flags);
Simon Glasse821d182014-02-26 15:59:24 -0700546}
547
548/**
549 * gpio_get_value() - [COMPAT] Sample GPIO pin and return it's value
550 * gpio: GPIO number
551 *
552 * This function implements the API that's compatible with current
553 * GPIO API used in U-Boot. The request is forwarded to particular
554 * GPIO driver. Returns the value of the GPIO pin, or negative value
555 * on error.
556 */
557int gpio_get_value(unsigned gpio)
558{
Simon Glasse821d182014-02-26 15:59:24 -0700559 int ret;
560
Simon Glassce555292015-01-05 20:05:27 -0700561 struct gpio_desc desc;
562
563 ret = gpio_to_device(gpio, &desc);
Simon Glasse821d182014-02-26 15:59:24 -0700564 if (ret)
565 return ret;
Simon Glassce555292015-01-05 20:05:27 -0700566 return dm_gpio_get_value(&desc);
Simon Glasse821d182014-02-26 15:59:24 -0700567}
568
569/**
570 * gpio_set_value() - [COMPAT] Configure logical value on GPIO pin
571 * gpio: GPIO number
572 * value: Logical value to be set on the GPIO pin.
573 *
574 * This function implements the API that's compatible with current
575 * GPIO API used in U-Boot. The request is forwarded to particular
576 * GPIO driver. Returns 0 on success, negative value on error.
577 */
578int gpio_set_value(unsigned gpio, int value)
579{
Simon Glassce555292015-01-05 20:05:27 -0700580 struct gpio_desc desc;
Simon Glasse821d182014-02-26 15:59:24 -0700581 int ret;
582
Simon Glassce555292015-01-05 20:05:27 -0700583 ret = gpio_to_device(gpio, &desc);
Simon Glasse821d182014-02-26 15:59:24 -0700584 if (ret)
585 return ret;
Simon Glassce555292015-01-05 20:05:27 -0700586 return dm_gpio_set_value(&desc, value);
Simon Glasse821d182014-02-26 15:59:24 -0700587}
588
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200589const char *gpio_get_bank_info(struct udevice *dev, int *bit_count)
Simon Glasse821d182014-02-26 15:59:24 -0700590{
591 struct gpio_dev_priv *priv;
592
593 /* Must be called on an active device */
Simon Glassde0977b2015-03-05 12:25:20 -0700594 priv = dev_get_uclass_priv(dev);
Simon Glasse821d182014-02-26 15:59:24 -0700595 assert(priv);
596
597 *bit_count = priv->gpio_count;
598 return priv->bank_name;
599}
600
Simon Glass6e5e6dd2014-10-04 11:29:43 -0600601static const char * const gpio_function[GPIOF_COUNT] = {
602 "input",
603 "output",
604 "unused",
605 "unknown",
606 "func",
607};
608
Masahiro Yamada286c2522017-06-22 16:50:25 +0900609static int get_function(struct udevice *dev, int offset, bool skip_unused,
610 const char **namep)
Simon Glass6e5e6dd2014-10-04 11:29:43 -0600611{
Simon Glassde0977b2015-03-05 12:25:20 -0700612 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass6e5e6dd2014-10-04 11:29:43 -0600613 struct dm_gpio_ops *ops = gpio_get_ops(dev);
614
615 BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function));
616 if (!device_active(dev))
617 return -ENODEV;
618 if (offset < 0 || offset >= uc_priv->gpio_count)
619 return -EINVAL;
620 if (namep)
621 *namep = uc_priv->name[offset];
622 if (skip_unused && !uc_priv->name[offset])
623 return GPIOF_UNUSED;
624 if (ops->get_function) {
625 int ret;
626
627 ret = ops->get_function(dev, offset);
628 if (ret < 0)
629 return ret;
630 if (ret >= ARRAY_SIZE(gpio_function))
631 return -ENODATA;
632 return ret;
633 }
634
635 return GPIOF_UNKNOWN;
636}
637
638int gpio_get_function(struct udevice *dev, int offset, const char **namep)
639{
640 return get_function(dev, offset, true, namep);
641}
642
643int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep)
644{
645 return get_function(dev, offset, false, namep);
646}
647
Simon Glass6b1ef592014-10-04 11:29:44 -0600648int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)
649{
650 struct dm_gpio_ops *ops = gpio_get_ops(dev);
651 struct gpio_dev_priv *priv;
652 char *str = buf;
653 int func;
654 int ret;
655 int len;
656
657 BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function));
658
659 *buf = 0;
Simon Glassde0977b2015-03-05 12:25:20 -0700660 priv = dev_get_uclass_priv(dev);
Simon Glass6b1ef592014-10-04 11:29:44 -0600661 ret = gpio_get_raw_function(dev, offset, NULL);
662 if (ret < 0)
663 return ret;
664 func = ret;
665 len = snprintf(str, buffsize, "%s%d: %s",
666 priv->bank_name ? priv->bank_name : "",
667 offset, gpio_function[func]);
668 if (func == GPIOF_INPUT || func == GPIOF_OUTPUT ||
669 func == GPIOF_UNUSED) {
670 const char *label;
671 bool used;
672
673 ret = ops->get_value(dev, offset);
674 if (ret < 0)
675 return ret;
676 used = gpio_get_function(dev, offset, &label) != GPIOF_UNUSED;
677 snprintf(str + len, buffsize - len, ": %d [%c]%s%s",
678 ret,
679 used ? 'x' : ' ',
680 used ? " " : "",
681 label ? label : "");
682 }
683
684 return 0;
685}
686
Simon Glassbef54db2015-04-14 21:03:20 -0600687int gpio_claim_vector(const int *gpio_num_array, const char *fmt)
688{
689 int i, ret;
690 int gpio;
691
692 for (i = 0; i < 32; i++) {
693 gpio = gpio_num_array[i];
694 if (gpio == -1)
695 break;
696 ret = gpio_requestf(gpio, fmt, i);
697 if (ret)
698 goto err;
699 ret = gpio_direction_input(gpio);
700 if (ret) {
701 gpio_free(gpio);
702 goto err;
703 }
704 }
705
706 return 0;
707err:
708 for (i--; i >= 0; i--)
709 gpio_free(gpio_num_array[i]);
710
711 return ret;
712}
713
Simon Glass2c97a8f2014-11-10 18:00:21 -0700714/*
715 * get a number comprised of multiple GPIO values. gpio_num_array points to
716 * the array of gpio pin numbers to scan, terminated by -1.
717 */
Simon Glassbef54db2015-04-14 21:03:20 -0600718int gpio_get_values_as_int(const int *gpio_list)
Simon Glass2c97a8f2014-11-10 18:00:21 -0700719{
720 int gpio;
721 unsigned bitmask = 1;
722 unsigned vector = 0;
Simon Glassbef54db2015-04-14 21:03:20 -0600723 int ret;
Simon Glass2c97a8f2014-11-10 18:00:21 -0700724
725 while (bitmask &&
Simon Glassbef54db2015-04-14 21:03:20 -0600726 ((gpio = *gpio_list++) != -1)) {
727 ret = gpio_get_value(gpio);
728 if (ret < 0)
729 return ret;
730 else if (ret)
Simon Glass2c97a8f2014-11-10 18:00:21 -0700731 vector |= bitmask;
732 bitmask <<= 1;
733 }
Simon Glassbef54db2015-04-14 21:03:20 -0600734
Simon Glass2c97a8f2014-11-10 18:00:21 -0700735 return vector;
736}
737
Simon Glassfd838972016-03-06 19:27:51 -0700738int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count)
Simon Glassdf1687d2016-03-06 19:27:50 -0700739{
740 unsigned bitmask = 1;
741 unsigned vector = 0;
742 int ret, i;
743
744 for (i = 0; i < count; i++) {
745 ret = dm_gpio_get_value(&desc_list[i]);
746 if (ret < 0)
747 return ret;
748 else if (ret)
749 vector |= bitmask;
750 bitmask <<= 1;
751 }
752
753 return vector;
754}
755
Heiko Schocher58e4c382019-07-17 06:59:51 +0200756/**
757 * gpio_request_tail: common work for requesting a gpio.
758 *
759 * ret: return value from previous work in function which calls
760 * this function.
761 * This seems bogus (why calling this function instead not
762 * calling it and end caller function instead?).
763 * Because on error in caller function we want to set some
764 * default values in gpio desc and have a common error
765 * debug message, which provides this function.
766 * nodename: Name of node for which gpio gets requested
767 * used for gpio label name.
768 * args: pointer to output arguments structure
769 * list_name: Name of GPIO list
770 * used for gpio label name.
771 * index: gpio index in gpio list
772 * used for gpio label name.
773 * desc: pointer to gpio descriptor, filled from this
774 * function.
775 * flags: gpio flags to use.
776 * add_index: should index added to gpio label name
777 * gpio_dev: pointer to gpio device from which the gpio
778 * will be requested. If NULL try to get the
779 * gpio device with uclass_get_device_by_ofnode()
780 *
781 * return: In error case this function sets default values in
782 * gpio descriptor, also emmits a debug message.
783 * On success it returns 0 else the error code from
784 * function calls, or the error code passed through
785 * ret to this function.
786 *
787 */
Heiko Schocher39cb3402019-06-12 06:11:46 +0200788static int gpio_request_tail(int ret, const char *nodename,
Simon Glass12faa022017-05-18 20:09:18 -0600789 struct ofnode_phandle_args *args,
790 const char *list_name, int index,
Heiko Schocher39cb3402019-06-12 06:11:46 +0200791 struct gpio_desc *desc, int flags,
Heiko Schocher58e4c382019-07-17 06:59:51 +0200792 bool add_index, struct udevice *gpio_dev)
Simon Glass16e10402015-01-05 20:05:29 -0700793{
Patrick Delaunay758bba92020-01-13 11:35:01 +0100794 gpio_desc_init(desc, gpio_dev, 0);
Simon Glass12faa022017-05-18 20:09:18 -0600795 if (ret)
Simon Glass16e10402015-01-05 20:05:29 -0700796 goto err;
Simon Glass16e10402015-01-05 20:05:29 -0700797
Heiko Schocher39cb3402019-06-12 06:11:46 +0200798 if (!desc->dev) {
799 ret = uclass_get_device_by_ofnode(UCLASS_GPIO, args->node,
800 &desc->dev);
801 if (ret) {
Heiko Schocher58e4c382019-07-17 06:59:51 +0200802 debug("%s: uclass_get_device_by_ofnode failed\n",
803 __func__);
Heiko Schocher39cb3402019-06-12 06:11:46 +0200804 goto err;
805 }
Simon Glass16e10402015-01-05 20:05:29 -0700806 }
Simon Glass12faa022017-05-18 20:09:18 -0600807 ret = gpio_find_and_xlate(desc, args);
Simon Glass16e10402015-01-05 20:05:29 -0700808 if (ret) {
809 debug("%s: gpio_find_and_xlate failed\n", __func__);
810 goto err;
811 }
812 ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s",
Heiko Schocher39cb3402019-06-12 06:11:46 +0200813 nodename, list_name, index);
Simon Glass16e10402015-01-05 20:05:29 -0700814 if (ret) {
815 debug("%s: dm_gpio_requestf failed\n", __func__);
816 goto err;
817 }
818 ret = dm_gpio_set_dir_flags(desc, flags | desc->flags);
819 if (ret) {
820 debug("%s: dm_gpio_set_dir failed\n", __func__);
821 goto err;
822 }
823
824 return 0;
825err:
826 debug("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n",
Heiko Schocher39cb3402019-06-12 06:11:46 +0200827 __func__, nodename, list_name, index, ret);
Simon Glass16e10402015-01-05 20:05:29 -0700828 return ret;
829}
830
Simon Glass1d9af1f2017-05-30 21:47:09 -0600831static int _gpio_request_by_name_nodev(ofnode node, const char *list_name,
832 int index, struct gpio_desc *desc,
833 int flags, bool add_index)
Simon Glass12faa022017-05-18 20:09:18 -0600834{
835 struct ofnode_phandle_args args;
836 int ret;
837
Simon Glass1d9af1f2017-05-30 21:47:09 -0600838 ret = ofnode_parse_phandle_with_args(node, list_name, "#gpio-cells", 0,
839 index, &args);
Simon Glass12faa022017-05-18 20:09:18 -0600840
Heiko Schocher39cb3402019-06-12 06:11:46 +0200841 return gpio_request_tail(ret, ofnode_get_name(node), &args, list_name,
842 index, desc, flags, add_index, NULL);
Simon Glass12faa022017-05-18 20:09:18 -0600843}
844
Simon Glass1d9af1f2017-05-30 21:47:09 -0600845int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index,
Simon Glass16e10402015-01-05 20:05:29 -0700846 struct gpio_desc *desc, int flags)
847{
Simon Glass1d9af1f2017-05-30 21:47:09 -0600848 return _gpio_request_by_name_nodev(node, list_name, index, desc, flags,
849 index > 0);
Simon Glass16e10402015-01-05 20:05:29 -0700850}
851
Simon Glass1d9af1f2017-05-30 21:47:09 -0600852int gpio_request_by_name(struct udevice *dev, const char *list_name, int index,
Simon Glass16e10402015-01-05 20:05:29 -0700853 struct gpio_desc *desc, int flags)
854{
Simon Glass1d9af1f2017-05-30 21:47:09 -0600855 struct ofnode_phandle_args args;
Heiko Schocher39cb3402019-06-12 06:11:46 +0200856 ofnode node;
Simon Glass1d9af1f2017-05-30 21:47:09 -0600857 int ret;
858
859 ret = dev_read_phandle_with_args(dev, list_name, "#gpio-cells", 0,
860 index, &args);
Heiko Schocher39cb3402019-06-12 06:11:46 +0200861 node = dev_ofnode(dev);
862 return gpio_request_tail(ret, ofnode_get_name(node), &args, list_name,
863 index, desc, flags, index > 0, NULL);
Simon Glass16e10402015-01-05 20:05:29 -0700864}
865
Simon Glass1d9af1f2017-05-30 21:47:09 -0600866int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,
Simon Glass16e10402015-01-05 20:05:29 -0700867 struct gpio_desc *desc, int max_count,
868 int flags)
869{
870 int count;
871 int ret;
872
Przemyslaw Marczak44fc5362015-03-31 18:57:16 +0200873 for (count = 0; count < max_count; count++) {
Simon Glass1d9af1f2017-05-30 21:47:09 -0600874 ret = _gpio_request_by_name_nodev(node, list_name, count,
Simon Glass16e10402015-01-05 20:05:29 -0700875 &desc[count], flags, true);
876 if (ret == -ENOENT)
877 break;
878 else if (ret)
879 goto err;
880 }
881
882 /* We ran out of GPIOs in the list */
883 return count;
884
885err:
886 gpio_free_list_nodev(desc, count - 1);
887
888 return ret;
889}
890
891int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
892 struct gpio_desc *desc, int max_count,
893 int flags)
894{
895 /*
896 * This isn't ideal since we don't use dev->name in the debug()
897 * calls in gpio_request_by_name(), but we can do this until
898 * gpio_request_list_by_name_nodev() can be dropped.
899 */
Simon Glass1d9af1f2017-05-30 21:47:09 -0600900 return gpio_request_list_by_name_nodev(dev_ofnode(dev), list_name, desc,
901 max_count, flags);
Simon Glass16e10402015-01-05 20:05:29 -0700902}
903
904int gpio_get_list_count(struct udevice *dev, const char *list_name)
905{
906 int ret;
907
Simon Glassdd79d6e2017-01-17 16:52:55 -0700908 ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
Simon Glass16e10402015-01-05 20:05:29 -0700909 list_name, "#gpio-cells", 0, -1,
910 NULL);
911 if (ret) {
912 debug("%s: Node '%s', property '%s', GPIO count failed: %d\n",
913 __func__, dev->name, list_name, ret);
914 }
915
916 return ret;
917}
918
919int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc)
920{
921 /* For now, we don't do any checking of dev */
922 return _dm_gpio_free(desc->dev, desc->offset);
923}
924
925int gpio_free_list(struct udevice *dev, struct gpio_desc *desc, int count)
926{
927 int i;
928
929 /* For now, we don't do any checking of dev */
930 for (i = 0; i < count; i++)
931 dm_gpio_free(dev, &desc[i]);
932
933 return 0;
934}
935
936int gpio_free_list_nodev(struct gpio_desc *desc, int count)
937{
938 return gpio_free_list(NULL, desc, count);
939}
940
Simon Glasse821d182014-02-26 15:59:24 -0700941/* We need to renumber the GPIOs when any driver is probed/removed */
Simon Glass0f4517d2014-10-04 11:29:42 -0600942static int gpio_renumber(struct udevice *removed_dev)
Simon Glasse821d182014-02-26 15:59:24 -0700943{
944 struct gpio_dev_priv *uc_priv;
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200945 struct udevice *dev;
Simon Glasse821d182014-02-26 15:59:24 -0700946 struct uclass *uc;
947 unsigned base;
948 int ret;
949
950 ret = uclass_get(UCLASS_GPIO, &uc);
951 if (ret)
952 return ret;
953
954 /* Ensure that we have a base for each bank */
955 base = 0;
956 uclass_foreach_dev(dev, uc) {
Simon Glass0f4517d2014-10-04 11:29:42 -0600957 if (device_active(dev) && dev != removed_dev) {
Simon Glassde0977b2015-03-05 12:25:20 -0700958 uc_priv = dev_get_uclass_priv(dev);
Simon Glasse821d182014-02-26 15:59:24 -0700959 uc_priv->gpio_base = base;
960 base += uc_priv->gpio_count;
961 }
962 }
963
964 return 0;
965}
966
Simon Glassfd838972016-03-06 19:27:51 -0700967int gpio_get_number(const struct gpio_desc *desc)
Simon Glass94f54d12015-03-25 12:21:58 -0600968{
969 struct udevice *dev = desc->dev;
970 struct gpio_dev_priv *uc_priv;
971
972 if (!dev)
973 return -1;
974 uc_priv = dev->uclass_priv;
975
976 return uc_priv->gpio_base + desc->offset;
977}
978
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200979static int gpio_post_probe(struct udevice *dev)
Simon Glasse821d182014-02-26 15:59:24 -0700980{
Simon Glassde0977b2015-03-05 12:25:20 -0700981 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass0f4517d2014-10-04 11:29:42 -0600982
983 uc_priv->name = calloc(uc_priv->gpio_count, sizeof(char *));
984 if (!uc_priv->name)
985 return -ENOMEM;
986
987 return gpio_renumber(NULL);
Simon Glasse821d182014-02-26 15:59:24 -0700988}
989
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200990static int gpio_pre_remove(struct udevice *dev)
Simon Glasse821d182014-02-26 15:59:24 -0700991{
Simon Glassde0977b2015-03-05 12:25:20 -0700992 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass0f4517d2014-10-04 11:29:42 -0600993 int i;
994
995 for (i = 0; i < uc_priv->gpio_count; i++) {
996 if (uc_priv->name[i])
997 free(uc_priv->name[i]);
998 }
999 free(uc_priv->name);
1000
1001 return gpio_renumber(dev);
Simon Glasse821d182014-02-26 15:59:24 -07001002}
1003
Heiko Schocher39cb3402019-06-12 06:11:46 +02001004int gpio_dev_request_index(struct udevice *dev, const char *nodename,
1005 char *list_name, int index, int flags,
1006 int dtflags, struct gpio_desc *desc)
1007{
1008 struct ofnode_phandle_args args;
1009
1010 args.node = ofnode_null();
1011 args.args_count = 2;
1012 args.args[0] = index;
1013 args.args[1] = dtflags;
1014
1015 return gpio_request_tail(0, nodename, &args, list_name, index, desc,
1016 flags, 0, dev);
1017}
1018
Michal Simek5f7202c2018-07-12 12:42:27 +02001019static int gpio_post_bind(struct udevice *dev)
1020{
Heiko Schocher39cb3402019-06-12 06:11:46 +02001021 struct udevice *child;
1022 ofnode node;
Heiko Schocher39cb3402019-06-12 06:11:46 +02001023
Michal Simek5f7202c2018-07-12 12:42:27 +02001024#if defined(CONFIG_NEEDS_MANUAL_RELOC)
1025 struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops(dev);
1026 static int reloc_done;
1027
1028 if (!reloc_done) {
1029 if (ops->request)
1030 ops->request += gd->reloc_off;
Simon Glassb3a47542020-02-04 20:15:17 -07001031 if (ops->rfree)
1032 ops->rfree += gd->reloc_off;
Michal Simek5f7202c2018-07-12 12:42:27 +02001033 if (ops->direction_input)
1034 ops->direction_input += gd->reloc_off;
1035 if (ops->direction_output)
1036 ops->direction_output += gd->reloc_off;
1037 if (ops->get_value)
1038 ops->get_value += gd->reloc_off;
1039 if (ops->set_value)
1040 ops->set_value += gd->reloc_off;
Michal Simek5f7202c2018-07-12 12:42:27 +02001041 if (ops->get_function)
1042 ops->get_function += gd->reloc_off;
1043 if (ops->xlate)
1044 ops->xlate += gd->reloc_off;
1045
1046 reloc_done++;
1047 }
1048#endif
Heiko Schocher39cb3402019-06-12 06:11:46 +02001049
Heiko Schocher58e4c382019-07-17 06:59:51 +02001050 if (IS_ENABLED(CONFIG_GPIO_HOG)) {
1051 dev_for_each_subnode(node, dev) {
1052 if (ofnode_read_bool(node, "gpio-hog")) {
1053 const char *name = ofnode_get_name(node);
1054 int ret;
Heiko Schocher39cb3402019-06-12 06:11:46 +02001055
Heiko Schocher58e4c382019-07-17 06:59:51 +02001056 ret = device_bind_driver_to_node(dev,
1057 "gpio_hog",
1058 name, node,
1059 &child);
1060 if (ret)
1061 return ret;
1062 }
Heiko Schocher39cb3402019-06-12 06:11:46 +02001063 }
1064 }
Michal Simek5f7202c2018-07-12 12:42:27 +02001065 return 0;
1066}
1067
Simon Glasse821d182014-02-26 15:59:24 -07001068UCLASS_DRIVER(gpio) = {
1069 .id = UCLASS_GPIO,
1070 .name = "gpio",
Bhuvanchandra DVb1a1fc92015-06-01 18:37:15 +05301071 .flags = DM_UC_FLAG_SEQ_ALIAS,
Simon Glasse821d182014-02-26 15:59:24 -07001072 .post_probe = gpio_post_probe,
Michal Simek5f7202c2018-07-12 12:42:27 +02001073 .post_bind = gpio_post_bind,
Simon Glasse821d182014-02-26 15:59:24 -07001074 .pre_remove = gpio_pre_remove,
1075 .per_device_auto_alloc_size = sizeof(struct gpio_dev_priv),
1076};