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