blob: d94bde0777c8df024efad78e8b13ce70e347bcb7 [file] [log] [blame]
Pali Rohár4669df32021-12-21 12:20:18 +01001// SPDX-License-Identifier: GPL-2.0+
Marek Behún1c657bc2024-04-04 09:50:58 +02002/*
3 * Copyright (C) 2021 Pali Rohár <pali@kernel.org>
4 * Copyright (C) 2024 Marek Behún <kabel@kernel.org>
5 */
Pali Rohár4669df32021-12-21 12:20:18 +01006
Pali Rohár4669df32021-12-21 12:20:18 +01007#include <dm.h>
Marek Behún1c657bc2024-04-04 09:50:58 +02008#include <dm/lists.h>
9#include <regmap.h>
Pali Rohár4669df32021-12-21 12:20:18 +010010#include <reset-uclass.h>
Marek Behún1c657bc2024-04-04 09:50:58 +020011#include <syscon.h>
Marek Behún514628c2024-04-04 09:51:00 +020012#include <sysreset.h>
Pali Rohár4669df32021-12-21 12:20:18 +010013#include <asm/io.h>
14
Marek Behún514628c2024-04-04 09:51:00 +020015#define MVEBU_SOC_CONTROL_1_REG 0x4
Pali Rohár4669df32021-12-21 12:20:18 +010016
Marek Behún514628c2024-04-04 09:51:00 +020017#if defined(CONFIG_ARMADA_375)
18# define MVEBU_RSTOUTN_MASK_REG 0x54
19# define MVEBU_SYS_SOFT_RST_REG 0x58
20#else
21# define MVEBU_RSTOUTN_MASK_REG 0x60
22# define MVEBU_SYS_SOFT_RST_REG 0x64
23#endif
24
25#define MVEBU_GLOBAL_SOFT_RST_BIT BIT(0)
26
27#define MVEBU_PCIE_ID 0
28
29#if IS_ENABLED(CONFIG_ARMADA_32BIT_SYSCON_RESET)
Pali Rohár4669df32021-12-21 12:20:18 +010030
Pali Rohár4669df32021-12-21 12:20:18 +010031static int mvebu_reset_of_xlate(struct reset_ctl *rst,
32 struct ofnode_phandle_args *args)
33{
34 if (args->args_count < 2)
35 return -EINVAL;
36
37 rst->id = args->args[0];
38 rst->data = args->args[1];
39
40 /* Currently only PCIe is implemented */
41 if (rst->id != MVEBU_PCIE_ID)
42 return -EINVAL;
43
44 /* Four PCIe enable bits are shared across more PCIe links */
45 if (!(rst->data >= 0 && rst->data <= 3))
46 return -EINVAL;
47
48 return 0;
49}
50
51static int mvebu_reset_request(struct reset_ctl *rst)
52{
53 return 0;
54}
55
56static int mvebu_reset_free(struct reset_ctl *rst)
57{
58 return 0;
59}
60
61static int mvebu_reset_assert(struct reset_ctl *rst)
62{
Marek Behún1c657bc2024-04-04 09:50:58 +020063 struct regmap *regmap = syscon_get_regmap(rst->dev->parent);
Pali Rohár4669df32021-12-21 12:20:18 +010064
Marek Behún1c657bc2024-04-04 09:50:58 +020065 return regmap_update_bits(regmap, MVEBU_SOC_CONTROL_1_REG,
66 BIT(rst->data), 0);
Pali Rohár4669df32021-12-21 12:20:18 +010067}
68
69static int mvebu_reset_deassert(struct reset_ctl *rst)
70{
Marek Behún1c657bc2024-04-04 09:50:58 +020071 struct regmap *regmap = syscon_get_regmap(rst->dev->parent);
Pali Rohár4669df32021-12-21 12:20:18 +010072
Marek Behún1c657bc2024-04-04 09:50:58 +020073 return regmap_update_bits(regmap, MVEBU_SOC_CONTROL_1_REG,
74 BIT(rst->data), BIT(rst->data));
Pali Rohár4669df32021-12-21 12:20:18 +010075}
76
77static int mvebu_reset_status(struct reset_ctl *rst)
78{
Marek Behún1c657bc2024-04-04 09:50:58 +020079 struct regmap *regmap = syscon_get_regmap(rst->dev->parent);
80 uint val;
81 int ret;
Pali Rohár4669df32021-12-21 12:20:18 +010082
Marek Behún1c657bc2024-04-04 09:50:58 +020083 ret = regmap_read(regmap, MVEBU_SOC_CONTROL_1_REG, &val);
84 if (ret < 0)
85 return ret;
Pali Rohár4669df32021-12-21 12:20:18 +010086
Marek Behún1c657bc2024-04-04 09:50:58 +020087 return !(val & BIT(rst->data));
Pali Rohár4669df32021-12-21 12:20:18 +010088}
89
Pali Rohár32301ee2022-09-09 14:41:28 +020090static const struct reset_ops mvebu_reset_ops = {
Pali Rohár4669df32021-12-21 12:20:18 +010091 .of_xlate = mvebu_reset_of_xlate,
92 .request = mvebu_reset_request,
93 .rfree = mvebu_reset_free,
94 .rst_assert = mvebu_reset_assert,
95 .rst_deassert = mvebu_reset_deassert,
96 .rst_status = mvebu_reset_status,
97};
98
99U_BOOT_DRIVER(mvebu_reset) = {
100 .name = "mvebu-reset",
101 .id = UCLASS_RESET,
Pali Rohár4669df32021-12-21 12:20:18 +0100102 .ops = &mvebu_reset_ops,
103};
Marek Behún1c657bc2024-04-04 09:50:58 +0200104
Marek Behún514628c2024-04-04 09:51:00 +0200105#endif /* IS_ENABLED(CONFIG_ARMADA_32BIT_SYSCON_RESET) */
106
107#if IS_ENABLED(CONFIG_ARMADA_32BIT_SYSCON_SYSRESET)
108
109static int mvebu_sysreset_request(struct udevice *dev, enum sysreset_t type)
110{
111 struct regmap *regmap = syscon_get_regmap(dev->parent);
112 uint bit;
113
114 if (type != SYSRESET_COLD)
115 return -EPROTONOSUPPORT;
116
117 bit = MVEBU_GLOBAL_SOFT_RST_BIT;
118
119 regmap_update_bits(regmap, MVEBU_RSTOUTN_MASK_REG, bit, bit);
120 regmap_update_bits(regmap, MVEBU_SYS_SOFT_RST_REG, bit, bit);
121
122 /* Loop while waiting for the reset */
123 while (1)
124 ;
125
126 return 0;
127}
128
129static struct sysreset_ops mvebu_sysreset_ops = {
130 .request = mvebu_sysreset_request,
131};
132
133U_BOOT_DRIVER(mvebu_sysreset) = {
134 .name = "mvebu-sysreset",
135 .id = UCLASS_SYSRESET,
136 .ops = &mvebu_sysreset_ops,
137};
138
139#endif /* IS_ENABLED(CONFIG_ARMADA_32BIT_SYSCON_SYSRESET) */
140
Marek Behún1c657bc2024-04-04 09:50:58 +0200141static int mvebu_syscon_bind(struct udevice *dev)
142{
Marek Behún514628c2024-04-04 09:51:00 +0200143 int ret = 0;
144
Marek Behún1c657bc2024-04-04 09:50:58 +0200145 /* bind also mvebu-reset, with the same ofnode */
Marek Behún514628c2024-04-04 09:51:00 +0200146 if (IS_ENABLED(CONFIG_ARMADA_32BIT_SYSCON_RESET)) {
147 ret = device_bind_driver_to_node(dev, "mvebu-reset",
148 "mvebu-reset", dev_ofnode(dev),
149 NULL);
150 if (ret < 0)
151 return ret;
152 }
153
154 /* bind also mvebu-sysreset, with the same ofnode */
155 if (IS_ENABLED(CONFIG_ARMADA_32BIT_SYSCON_SYSRESET)) {
156 ret = device_bind_driver_to_node(dev, "mvebu-sysreset",
157 "mvebu-sysreset",
158 dev_ofnode(dev), NULL);
159 if (ret < 0)
160 return ret;
161 }
162
163 return ret;
Marek Behún1c657bc2024-04-04 09:50:58 +0200164}
165
166static const struct udevice_id mvebu_syscon_of_match[] = {
167 { .compatible = "marvell,armada-370-xp-system-controller" },
168 { .compatible = "marvell,armada-375-system-controller" },
169 { .compatible = "marvell,armada-380-system-controller" },
170 { .compatible = "marvell,armada-390-system-controller" },
171 { },
172};
173
174U_BOOT_DRIVER(mvebu_syscon) = {
175 .name = "mvebu-system-controller",
176 .id = UCLASS_SYSCON,
177 .of_match = mvebu_syscon_of_match,
178 .bind = mvebu_syscon_bind,
179};