Simon Goldschmidt | 1f16688 | 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 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <errno.h> |
| 10 | #include <sysreset.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/reset_manager.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 13 | #include <linux/bitops.h> |
Simon Goldschmidt | 1f16688 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 14 | |
| 15 | struct socfpga_sysreset_data { |
Ley Foon Tan | bb25aca | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 16 | void __iomem *rstmgr_base; |
Simon Goldschmidt | 1f16688 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | static int socfpga_sysreset_request(struct udevice *dev, |
| 20 | enum sysreset_t type) |
| 21 | { |
| 22 | struct socfpga_sysreset_data *data = dev_get_priv(dev); |
| 23 | |
| 24 | switch (type) { |
| 25 | case SYSRESET_WARM: |
| 26 | writel(BIT(RSTMGR_CTRL_SWWARMRSTREQ_LSB), |
Ley Foon Tan | bb25aca | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 27 | data->rstmgr_base + RSTMGR_CTRL); |
Simon Goldschmidt | 1f16688 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 28 | break; |
| 29 | case SYSRESET_COLD: |
| 30 | writel(BIT(RSTMGR_CTRL_SWCOLDRSTREQ_LSB), |
Ley Foon Tan | bb25aca | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 31 | data->rstmgr_base + RSTMGR_CTRL); |
Simon Goldschmidt | 1f16688 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 32 | break; |
| 33 | default: |
| 34 | return -EPROTONOSUPPORT; |
| 35 | } |
| 36 | return -EINPROGRESS; |
| 37 | } |
| 38 | |
| 39 | static int socfpga_sysreset_probe(struct udevice *dev) |
| 40 | { |
| 41 | struct socfpga_sysreset_data *data = dev_get_priv(dev); |
| 42 | |
Masahiro Yamada | 702e57e | 2020-08-04 14:14:43 +0900 | [diff] [blame] | 43 | data->rstmgr_base = dev_read_addr_ptr(dev); |
Simon Goldschmidt | 1f16688 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static struct sysreset_ops socfpga_sysreset = { |
| 48 | .request = socfpga_sysreset_request, |
| 49 | }; |
| 50 | |
| 51 | U_BOOT_DRIVER(sysreset_socfpga) = { |
| 52 | .id = UCLASS_SYSRESET, |
| 53 | .name = "socfpga_sysreset", |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 54 | .priv_auto = sizeof(struct socfpga_sysreset_data), |
Simon Goldschmidt | 1f16688 | 2019-07-15 21:47:53 +0200 | [diff] [blame] | 55 | .ops = &socfpga_sysreset, |
| 56 | .probe = socfpga_sysreset_probe, |
| 57 | }; |