blob: 680b759eb3cc49fcf53498b1ded1627a8b907444 [file] [log] [blame]
Michal Simek8a196af2018-07-13 11:04:56 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2018 Xilinx, Inc. - Michal Simek
4 */
5
6#include <common.h>
7#include <dm.h>
8#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Michal Simek8a196af2018-07-13 11:04:56 +020010#include <sysreset.h>
11#include <asm/gpio.h>
12
13struct gpio_reboot_priv {
14 struct gpio_desc gpio;
15};
16
17static int gpio_reboot_request(struct udevice *dev, enum sysreset_t type)
18{
19 struct gpio_reboot_priv *priv = dev_get_priv(dev);
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 */
29 return dm_gpio_set_value(&priv->gpio, 1);
30}
31
32static struct sysreset_ops gpio_reboot_ops = {
33 .request = gpio_reboot_request,
34};
35
36int gpio_reboot_probe(struct udevice *dev)
37{
38 struct gpio_reboot_priv *priv = dev_get_priv(dev);
39
40 /*
41 * Linux kernel DT binding contain others optional properties
42 * which are not supported now
43 */
44
45 return gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT);
46}
47
48static const struct udevice_id led_gpio_ids[] = {
49 { .compatible = "gpio-restart" },
50 { }
51};
52
53U_BOOT_DRIVER(gpio_reboot) = {
54 .id = UCLASS_SYSRESET,
55 .name = "gpio_restart",
56 .of_match = led_gpio_ids,
57 .ops = &gpio_reboot_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070058 .priv_auto = sizeof(struct gpio_reboot_priv),
Michal Simek8a196af2018-07-13 11:04:56 +020059 .probe = gpio_reboot_probe,
60};