Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 2 | /* |
Patrice Chotard | fb48bc4 | 2017-10-23 09:53:57 +0200 | [diff] [blame] | 3 | * Copyright (C) 2017, STMicroelectronics - All Rights Reserved |
Patrice Chotard | 0f8106f | 2020-12-02 18:47:30 +0100 | [diff] [blame] | 4 | * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics. |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <regmap.h> |
| 10 | #include <syscon.h> |
| 11 | #include <sysreset.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 13 | #include <asm/io.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | struct sti_sysreset_priv { |
| 19 | phys_addr_t base; |
| 20 | }; |
| 21 | |
| 22 | static int sti_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 23 | { |
| 24 | struct sti_sysreset_priv *priv = dev_get_priv(dev); |
| 25 | |
| 26 | generic_clear_bit(0, (void __iomem *)priv->base); |
| 27 | |
| 28 | return -EINPROGRESS; |
| 29 | } |
| 30 | |
| 31 | static int sti_sysreset_probe(struct udevice *dev) |
| 32 | { |
| 33 | struct sti_sysreset_priv *priv = dev_get_priv(dev); |
| 34 | struct udevice *syscon; |
| 35 | struct regmap *regmap; |
| 36 | struct fdtdec_phandle_args syscfg_phandle; |
| 37 | int ret; |
| 38 | |
| 39 | /* get corresponding syscon phandle */ |
| 40 | ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev), |
| 41 | "st,syscfg", NULL, 0, 0, |
| 42 | &syscfg_phandle); |
| 43 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 44 | pr_err("Can't get syscfg phandle: %d\n", ret); |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 45 | return ret; |
| 46 | } |
| 47 | |
| 48 | ret = uclass_get_device_by_of_offset(UCLASS_SYSCON, |
| 49 | syscfg_phandle.node, |
| 50 | &syscon); |
| 51 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 52 | pr_err("%s: uclass_get_device_by_of_offset failed: %d\n", |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 53 | __func__, ret); |
| 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | regmap = syscon_get_regmap(syscon); |
| 58 | if (!regmap) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 59 | pr_err("unable to get regmap for %s\n", syscon->name); |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 60 | return -ENODEV; |
| 61 | } |
| 62 | |
Masahiro Yamada | 8c1de5e | 2018-04-19 12:14:01 +0900 | [diff] [blame] | 63 | priv->base = regmap->ranges[0].start; |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static struct sysreset_ops sti_sysreset = { |
| 69 | .request = sti_sysreset_request, |
| 70 | }; |
| 71 | |
| 72 | static const struct udevice_id sti_sysreset_ids[] = { |
| 73 | { .compatible = "st,stih407-restart" }, |
| 74 | { } |
| 75 | }; |
| 76 | |
| 77 | U_BOOT_DRIVER(sysreset_sti) = { |
| 78 | .name = "sysreset_sti", |
| 79 | .id = UCLASS_SYSRESET, |
| 80 | .ops = &sti_sysreset, |
| 81 | .probe = sti_sysreset_probe, |
| 82 | .of_match = sti_sysreset_ids, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 83 | .priv_auto = sizeof(struct sti_sysreset_priv), |
Patrice Chotard | 413788c | 2017-02-21 13:37:06 +0100 | [diff] [blame] | 84 | }; |