]> Git Repo - J-u-boot.git/blob - drivers/reset/reset-socfpga.c
dm: core: Create a new header file for 'compat' features
[J-u-boot.git] / drivers / reset / reset-socfpga.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Socfpga Reset Controller Driver
4  *
5  * Copyright 2014 Steffen Trumtrar <[email protected]>
6  *
7  * based on
8  * Allwinner SoCs Reset Controller driver
9  *
10  * Copyright 2013 Maxime Ripard
11  *
12  * Maxime Ripard <[email protected]>
13  */
14
15 #include <common.h>
16 #include <dm.h>
17 #include <malloc.h>
18 #include <dm/lists.h>
19 #include <dm/of_access.h>
20 #include <env.h>
21 #include <reset-uclass.h>
22 #include <linux/bitops.h>
23 #include <linux/io.h>
24 #include <linux/sizes.h>
25
26 #define BANK_INCREMENT          4
27 #define NR_BANKS                8
28
29 struct socfpga_reset_data {
30         void __iomem *modrst_base;
31 };
32
33 /*
34  * For compatibility with Kernels that don't support peripheral reset, this
35  * driver can keep the old behaviour of not asserting peripheral reset before
36  * starting the OS and deasserting all peripheral resets (enabling all
37  * peripherals).
38  *
39  * For that, the reset driver checks the environment variable
40  * "socfpga_legacy_reset_compat". If this variable is '1', perihperals are not
41  * reset again once taken out of reset and all peripherals in 'permodrst' are
42  * taken out of reset before booting into the OS.
43  * Note that this should be required for gen5 systems only that are running
44  * Linux kernels without proper peripheral reset support for all drivers used.
45  */
46 static bool socfpga_reset_keep_enabled(void)
47 {
48 #if !defined(CONFIG_SPL_BUILD) || CONFIG_IS_ENABLED(ENV_SUPPORT)
49         const char *env_str;
50         long val;
51
52         env_str = env_get("socfpga_legacy_reset_compat");
53         if (env_str) {
54                 val = simple_strtol(env_str, NULL, 0);
55                 if (val == 1)
56                         return true;
57         }
58 #endif
59
60         return false;
61 }
62
63 static int socfpga_reset_assert(struct reset_ctl *reset_ctl)
64 {
65         struct socfpga_reset_data *data = dev_get_priv(reset_ctl->dev);
66         int id = reset_ctl->id;
67         int reg_width = sizeof(u32);
68         int bank = id / (reg_width * BITS_PER_BYTE);
69         int offset = id % (reg_width * BITS_PER_BYTE);
70
71         setbits_le32(data->modrst_base + (bank * BANK_INCREMENT), BIT(offset));
72         return 0;
73 }
74
75 static int socfpga_reset_deassert(struct reset_ctl *reset_ctl)
76 {
77         struct socfpga_reset_data *data = dev_get_priv(reset_ctl->dev);
78         int id = reset_ctl->id;
79         int reg_width = sizeof(u32);
80         int bank = id / (reg_width * BITS_PER_BYTE);
81         int offset = id % (reg_width * BITS_PER_BYTE);
82
83         clrbits_le32(data->modrst_base + (bank * BANK_INCREMENT), BIT(offset));
84         return 0;
85 }
86
87 static int socfpga_reset_request(struct reset_ctl *reset_ctl)
88 {
89         debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__,
90               reset_ctl, reset_ctl->dev, reset_ctl->id);
91
92         return 0;
93 }
94
95 static int socfpga_reset_free(struct reset_ctl *reset_ctl)
96 {
97         debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
98               reset_ctl->dev, reset_ctl->id);
99
100         return 0;
101 }
102
103 static const struct reset_ops socfpga_reset_ops = {
104         .request = socfpga_reset_request,
105         .rfree = socfpga_reset_free,
106         .rst_assert = socfpga_reset_assert,
107         .rst_deassert = socfpga_reset_deassert,
108 };
109
110 static int socfpga_reset_probe(struct udevice *dev)
111 {
112         struct socfpga_reset_data *data = dev_get_priv(dev);
113         u32 modrst_offset;
114         void __iomem *membase;
115
116         membase = devfdt_get_addr_ptr(dev);
117
118         modrst_offset = dev_read_u32_default(dev, "altr,modrst-offset", 0x10);
119         data->modrst_base = membase + modrst_offset;
120
121         return 0;
122 }
123
124 static int socfpga_reset_remove(struct udevice *dev)
125 {
126         struct socfpga_reset_data *data = dev_get_priv(dev);
127
128         if (socfpga_reset_keep_enabled()) {
129                 puts("Deasserting all peripheral resets\n");
130                 writel(0, data->modrst_base + 4);
131         }
132
133         return 0;
134 }
135
136 static int socfpga_reset_bind(struct udevice *dev)
137 {
138         int ret;
139         struct udevice *sys_child;
140
141         /*
142          * The sysreset driver does not have a device node, so bind it here.
143          * Bind it to the node, too, so that it can get its base address.
144          */
145         ret = device_bind_driver_to_node(dev, "socfpga_sysreset", "sysreset",
146                                          dev->node, &sys_child);
147         if (ret)
148                 debug("Warning: No sysreset driver: ret=%d\n", ret);
149
150         return 0;
151 }
152
153 static const struct udevice_id socfpga_reset_match[] = {
154         { .compatible = "altr,rst-mgr" },
155         { /* sentinel */ },
156 };
157
158 U_BOOT_DRIVER(socfpga_reset) = {
159         .name = "socfpga-reset",
160         .id = UCLASS_RESET,
161         .of_match = socfpga_reset_match,
162         .bind = socfpga_reset_bind,
163         .probe = socfpga_reset_probe,
164         .priv_auto_alloc_size = sizeof(struct socfpga_reset_data),
165         .ops = &socfpga_reset_ops,
166         .remove = socfpga_reset_remove,
167         .flags  = DM_FLAG_OS_PREPARE,
168 };
This page took 0.034969 seconds and 4 git commands to generate.