blob: 9b62dd5eab096e33394e71400463fb62f1fbb165 [file] [log] [blame]
Simon Goldschmidt1f166882019-07-15 21:47:53 +02001// 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 Glasscd93d622020-05-10 11:40:13 -060013#include <linux/bitops.h>
Simon Goldschmidt1f166882019-07-15 21:47:53 +020014
15struct socfpga_sysreset_data {
Ley Foon Tanbb25aca2019-11-08 10:38:19 +080016 void __iomem *rstmgr_base;
Simon Goldschmidt1f166882019-07-15 21:47:53 +020017};
18
19static 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 Tanbb25aca2019-11-08 10:38:19 +080027 data->rstmgr_base + RSTMGR_CTRL);
Simon Goldschmidt1f166882019-07-15 21:47:53 +020028 break;
29 case SYSRESET_COLD:
30 writel(BIT(RSTMGR_CTRL_SWCOLDRSTREQ_LSB),
Ley Foon Tanbb25aca2019-11-08 10:38:19 +080031 data->rstmgr_base + RSTMGR_CTRL);
Simon Goldschmidt1f166882019-07-15 21:47:53 +020032 break;
33 default:
34 return -EPROTONOSUPPORT;
35 }
36 return -EINPROGRESS;
37}
38
39static int socfpga_sysreset_probe(struct udevice *dev)
40{
41 struct socfpga_sysreset_data *data = dev_get_priv(dev);
42
Paweł Anikiel9ebca702022-06-17 12:47:22 +020043 data->rstmgr_base = dev_read_addr_ptr(dev_get_parent(dev));
Simon Goldschmidt1f166882019-07-15 21:47:53 +020044 return 0;
45}
46
47static struct sysreset_ops socfpga_sysreset = {
48 .request = socfpga_sysreset_request,
49};
50
51U_BOOT_DRIVER(sysreset_socfpga) = {
52 .id = UCLASS_SYSRESET,
53 .name = "socfpga_sysreset",
Simon Glass41575d82020-12-03 16:55:17 -070054 .priv_auto = sizeof(struct socfpga_sysreset_data),
Simon Goldschmidt1f166882019-07-15 21:47:53 +020055 .ops = &socfpga_sysreset,
56 .probe = socfpga_sysreset_probe,
57};