Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com> |
| 4 | * |
| 5 | * Derived from linux/drivers/power/reset/syscon-reboot.c: |
| 6 | * Copyright (C) 2013, Applied Micro Circuits Corporation |
| 7 | * Author: Feng Kan <fkan@apm.com> |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <dm.h> |
| 12 | #include <errno.h> |
| 13 | #include <regmap.h> |
| 14 | #include <sysreset.h> |
| 15 | #include <syscon.h> |
| 16 | |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 17 | struct syscon_reboot_priv { |
| 18 | struct regmap *regmap; |
| 19 | unsigned int offset; |
| 20 | unsigned int mask; |
| 21 | }; |
| 22 | |
| 23 | static int syscon_reboot_request(struct udevice *dev, enum sysreset_t type) |
| 24 | { |
| 25 | struct syscon_reboot_priv *priv = dev_get_priv(dev); |
| 26 | |
| 27 | regmap_write(priv->regmap, priv->offset, priv->mask); |
| 28 | |
| 29 | return -EINPROGRESS; |
| 30 | } |
| 31 | |
| 32 | static struct sysreset_ops syscon_reboot_ops = { |
| 33 | .request = syscon_reboot_request, |
| 34 | }; |
| 35 | |
| 36 | int syscon_reboot_probe(struct udevice *dev) |
| 37 | { |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 38 | struct syscon_reboot_priv *priv = dev_get_priv(dev); |
| 39 | int err; |
Patrick Delaunay | 7fd78fe | 2018-07-09 14:59:29 +0200 | [diff] [blame] | 40 | u32 phandle; |
| 41 | ofnode node; |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 42 | |
Patrick Delaunay | 7fd78fe | 2018-07-09 14:59:29 +0200 | [diff] [blame] | 43 | err = ofnode_read_u32(dev_ofnode(dev), "regmap", &phandle); |
| 44 | if (err) |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 45 | return err; |
Patrick Delaunay | 7fd78fe | 2018-07-09 14:59:29 +0200 | [diff] [blame] | 46 | |
| 47 | node = ofnode_get_by_phandle(phandle); |
| 48 | if (!ofnode_valid(node)) |
| 49 | return -EINVAL; |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 50 | |
Patrick Delaunay | 7fd78fe | 2018-07-09 14:59:29 +0200 | [diff] [blame] | 51 | priv->regmap = syscon_node_to_regmap(node); |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 52 | if (!priv->regmap) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 53 | pr_err("unable to find regmap\n"); |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 54 | return -ENODEV; |
| 55 | } |
| 56 | |
Álvaro Fernández Rojas | 4bc3e25 | 2018-03-17 12:22:24 +0100 | [diff] [blame] | 57 | priv->offset = dev_read_u32_default(dev, "offset", 0); |
| 58 | priv->mask = dev_read_u32_default(dev, "mask", 0); |
Álvaro Fernández Rojas | aa19aaf | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static const struct udevice_id syscon_reboot_ids[] = { |
| 64 | { .compatible = "syscon-reboot" }, |
| 65 | { /* sentinel */ } |
| 66 | }; |
| 67 | |
| 68 | U_BOOT_DRIVER(syscon_reboot) = { |
| 69 | .name = "syscon_reboot", |
| 70 | .id = UCLASS_SYSRESET, |
| 71 | .of_match = syscon_reboot_ids, |
| 72 | .probe = syscon_reboot_probe, |
| 73 | .priv_auto_alloc_size = sizeof(struct syscon_reboot_priv), |
| 74 | .ops = &syscon_reboot_ops, |
| 75 | }; |