blob: ed9a49ad08c8e168073217d7e2eb8be2ed98a272 [file] [log] [blame]
Michal Simek0d832b32018-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>
9#include <sysreset.h>
10#include <asm/gpio.h>
11
12struct gpio_reboot_priv {
13 struct gpio_desc gpio;
14};
15
16static int gpio_reboot_request(struct udevice *dev, enum sysreset_t type)
17{
18 struct gpio_reboot_priv *priv = dev_get_priv(dev);
19
20 /*
21 * When debug log is enabled please make sure that chars won't end up
22 * in output fifo. Or you can append udelay(); to get enough time
23 * to HW to emit output fifo.
24 */
25 debug("GPIO reset\n");
26
27 /* Writing 1 respects polarity (active high/low) based on gpio->flags */
28 return dm_gpio_set_value(&priv->gpio, 1);
29}
30
31static struct sysreset_ops gpio_reboot_ops = {
32 .request = gpio_reboot_request,
33};
34
35int gpio_reboot_probe(struct udevice *dev)
36{
37 struct gpio_reboot_priv *priv = dev_get_priv(dev);
38
39 /*
40 * Linux kernel DT binding contain others optional properties
41 * which are not supported now
42 */
43
44 return gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT);
45}
46
47static const struct udevice_id led_gpio_ids[] = {
48 { .compatible = "gpio-restart" },
49 { }
50};
51
52U_BOOT_DRIVER(gpio_reboot) = {
53 .id = UCLASS_SYSRESET,
54 .name = "gpio_restart",
55 .of_match = led_gpio_ids,
56 .ops = &gpio_reboot_ops,
57 .priv_auto_alloc_size = sizeof(struct gpio_reboot_priv),
58 .probe = gpio_reboot_probe,
59};