Simon Goldschmidt | be36639 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2019 Pepperl+Fuchs |
| 4 | * Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> |
| 5 | */ |
| 6 | |
Simon Goldschmidt | be36639 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <errno.h> |
| 9 | #include <sysreset.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/reset_manager.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Simon Goldschmidt | be36639 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 13 | |
| 14 | struct socfpga_sysreset_data { |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 15 | void __iomem *rstmgr_base; |
Simon Goldschmidt | be36639 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | static int socfpga_sysreset_request(struct udevice *dev, |
| 19 | enum sysreset_t type) |
| 20 | { |
| 21 | struct socfpga_sysreset_data *data = dev_get_priv(dev); |
| 22 | |
| 23 | switch (type) { |
| 24 | case SYSRESET_WARM: |
| 25 | writel(BIT(RSTMGR_CTRL_SWWARMRSTREQ_LSB), |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 26 | data->rstmgr_base + RSTMGR_CTRL); |
Simon Goldschmidt | be36639 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 27 | break; |
| 28 | case SYSRESET_COLD: |
| 29 | writel(BIT(RSTMGR_CTRL_SWCOLDRSTREQ_LSB), |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 30 | data->rstmgr_base + RSTMGR_CTRL); |
Simon Goldschmidt | be36639 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 31 | break; |
| 32 | default: |
| 33 | return -EPROTONOSUPPORT; |
| 34 | } |
| 35 | return -EINPROGRESS; |
| 36 | } |
| 37 | |
| 38 | static int socfpga_sysreset_probe(struct udevice *dev) |
| 39 | { |
| 40 | struct socfpga_sysreset_data *data = dev_get_priv(dev); |
| 41 | |
Paweł Anikiel | 2d44572 | 2022-06-17 12:47:22 +0200 | [diff] [blame] | 42 | data->rstmgr_base = dev_read_addr_ptr(dev_get_parent(dev)); |
Simon Goldschmidt | be36639 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static struct sysreset_ops socfpga_sysreset = { |
| 47 | .request = socfpga_sysreset_request, |
| 48 | }; |
| 49 | |
| 50 | U_BOOT_DRIVER(sysreset_socfpga) = { |
| 51 | .id = UCLASS_SYSRESET, |
| 52 | .name = "socfpga_sysreset", |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 53 | .priv_auto = sizeof(struct socfpga_sysreset_data), |
Simon Goldschmidt | be36639 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 54 | .ops = &socfpga_sysreset, |
| 55 | .probe = socfpga_sysreset_probe, |
| 56 | }; |