Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | e388969 | 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 | e388969 | 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 | e388969 | 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); |
Patrick Delaunay | 4869421 | 2019-05-20 10:58:39 +0200 | [diff] [blame] | 26 | ulong driver_data = dev_get_driver_data(dev); |
Álvaro Fernández Rojas | e388969 | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 27 | |
Patrick Delaunay | 4869421 | 2019-05-20 10:58:39 +0200 | [diff] [blame] | 28 | if (type != driver_data) |
Patrick Delaunay | 50fd31f | 2019-04-18 17:16:21 +0200 | [diff] [blame] | 29 | return -EPROTONOSUPPORT; |
| 30 | |
Álvaro Fernández Rojas | e388969 | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 31 | regmap_write(priv->regmap, priv->offset, priv->mask); |
| 32 | |
| 33 | return -EINPROGRESS; |
| 34 | } |
| 35 | |
| 36 | static struct sysreset_ops syscon_reboot_ops = { |
| 37 | .request = syscon_reboot_request, |
| 38 | }; |
| 39 | |
| 40 | int syscon_reboot_probe(struct udevice *dev) |
| 41 | { |
Álvaro Fernández Rojas | e388969 | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 42 | struct syscon_reboot_priv *priv = dev_get_priv(dev); |
Álvaro Fernández Rojas | e388969 | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 43 | |
Patrick Delaunay | 662a74a | 2019-03-07 09:57:14 +0100 | [diff] [blame] | 44 | priv->regmap = syscon_regmap_lookup_by_phandle(dev, "regmap"); |
| 45 | if (IS_ERR(priv->regmap)) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 46 | pr_err("unable to find regmap\n"); |
Álvaro Fernández Rojas | e388969 | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 47 | return -ENODEV; |
| 48 | } |
| 49 | |
Álvaro Fernández Rojas | 0606906 | 2018-03-17 12:22:24 +0100 | [diff] [blame] | 50 | priv->offset = dev_read_u32_default(dev, "offset", 0); |
| 51 | priv->mask = dev_read_u32_default(dev, "mask", 0); |
Álvaro Fernández Rojas | e388969 | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static const struct udevice_id syscon_reboot_ids[] = { |
Patrick Delaunay | 4869421 | 2019-05-20 10:58:39 +0200 | [diff] [blame] | 57 | { .compatible = "syscon-reboot", .data = SYSRESET_COLD }, |
| 58 | { .compatible = "syscon-poweroff", .data = SYSRESET_POWER_OFF }, |
Álvaro Fernández Rojas | e388969 | 2017-04-25 00:39:14 +0200 | [diff] [blame] | 59 | { /* sentinel */ } |
| 60 | }; |
| 61 | |
| 62 | U_BOOT_DRIVER(syscon_reboot) = { |
| 63 | .name = "syscon_reboot", |
| 64 | .id = UCLASS_SYSRESET, |
| 65 | .of_match = syscon_reboot_ids, |
| 66 | .probe = syscon_reboot_probe, |
| 67 | .priv_auto_alloc_size = sizeof(struct syscon_reboot_priv), |
| 68 | .ops = &syscon_reboot_ops, |
| 69 | }; |