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