Michal Simek | 8a196af | 2018-07-13 11:04:56 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2018 Xilinx, Inc. - Michal Simek |
| 4 | */ |
| 5 | |
Michal Simek | 8a196af | 2018-07-13 11:04:56 +0200 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Michal Simek | 8a196af | 2018-07-13 11:04:56 +0200 | [diff] [blame] | 9 | #include <sysreset.h> |
| 10 | #include <asm/gpio.h> |
| 11 | |
| 12 | struct gpio_reboot_priv { |
| 13 | struct gpio_desc gpio; |
| 14 | }; |
| 15 | |
| 16 | static int gpio_reboot_request(struct udevice *dev, enum sysreset_t type) |
| 17 | { |
| 18 | struct gpio_reboot_priv *priv = dev_get_priv(dev); |
Jonathan Liu | 431e414 | 2023-03-28 17:44:23 +1100 | [diff] [blame] | 19 | int ret; |
Michal Simek | 8a196af | 2018-07-13 11:04:56 +0200 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * When debug log is enabled please make sure that chars won't end up |
| 23 | * in output fifo. Or you can append udelay(); to get enough time |
| 24 | * to HW to emit output fifo. |
| 25 | */ |
| 26 | debug("GPIO reset\n"); |
| 27 | |
| 28 | /* Writing 1 respects polarity (active high/low) based on gpio->flags */ |
Jonathan Liu | 431e414 | 2023-03-28 17:44:23 +1100 | [diff] [blame] | 29 | ret = dm_gpio_set_value(&priv->gpio, 1); |
| 30 | if (ret < 0) |
| 31 | return ret; |
| 32 | |
| 33 | return -EINPROGRESS; |
Michal Simek | 8a196af | 2018-07-13 11:04:56 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static struct sysreset_ops gpio_reboot_ops = { |
| 37 | .request = gpio_reboot_request, |
| 38 | }; |
| 39 | |
Samuel Holland | 83e32fa | 2021-11-03 22:55:12 -0500 | [diff] [blame] | 40 | static int gpio_reboot_probe(struct udevice *dev) |
Michal Simek | 8a196af | 2018-07-13 11:04:56 +0200 | [diff] [blame] | 41 | { |
| 42 | struct gpio_reboot_priv *priv = dev_get_priv(dev); |
| 43 | |
| 44 | /* |
| 45 | * Linux kernel DT binding contain others optional properties |
| 46 | * which are not supported now |
| 47 | */ |
| 48 | |
| 49 | return gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT); |
| 50 | } |
| 51 | |
| 52 | static const struct udevice_id led_gpio_ids[] = { |
| 53 | { .compatible = "gpio-restart" }, |
| 54 | { } |
| 55 | }; |
| 56 | |
| 57 | U_BOOT_DRIVER(gpio_reboot) = { |
| 58 | .id = UCLASS_SYSRESET, |
| 59 | .name = "gpio_restart", |
| 60 | .of_match = led_gpio_ids, |
| 61 | .ops = &gpio_reboot_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 62 | .priv_auto = sizeof(struct gpio_reboot_priv), |
Michal Simek | 8a196af | 2018-07-13 11:04:56 +0200 | [diff] [blame] | 63 | .probe = gpio_reboot_probe, |
| 64 | }; |