1 // SPDX-License-Identifier: GPL-2.0+
2 // (C) 2021 Pali Rohár <pali@kernel.org>
6 #include <reset-uclass.h>
9 #define MVEBU_SOC_CONTROL_1_REG 0x4
11 #define MVEBU_PCIE_ID 0
13 struct mvebu_reset_data {
17 static int mvebu_reset_of_xlate(struct reset_ctl *rst,
18 struct ofnode_phandle_args *args)
20 if (args->args_count < 2)
23 rst->id = args->args[0];
24 rst->data = args->args[1];
26 /* Currently only PCIe is implemented */
27 if (rst->id != MVEBU_PCIE_ID)
30 /* Four PCIe enable bits are shared across more PCIe links */
31 if (!(rst->data >= 0 && rst->data <= 3))
37 static int mvebu_reset_request(struct reset_ctl *rst)
42 static int mvebu_reset_free(struct reset_ctl *rst)
47 static int mvebu_reset_assert(struct reset_ctl *rst)
49 struct mvebu_reset_data *data = dev_get_priv(rst->dev);
51 clrbits_32(data->base + MVEBU_SOC_CONTROL_1_REG, BIT(rst->data));
55 static int mvebu_reset_deassert(struct reset_ctl *rst)
57 struct mvebu_reset_data *data = dev_get_priv(rst->dev);
59 setbits_32(data->base + MVEBU_SOC_CONTROL_1_REG, BIT(rst->data));
63 static int mvebu_reset_status(struct reset_ctl *rst)
65 struct mvebu_reset_data *data = dev_get_priv(rst->dev);
67 return !(readl(data->base + MVEBU_SOC_CONTROL_1_REG) & BIT(rst->data));
70 static int mvebu_reset_of_to_plat(struct udevice *dev)
72 struct mvebu_reset_data *data = dev_get_priv(dev);
74 data->base = (void *)dev_read_addr(dev);
75 if ((fdt_addr_t)data->base == FDT_ADDR_T_NONE)
81 static const struct udevice_id mvebu_reset_of_match[] = {
82 { .compatible = "marvell,armada-370-xp-system-controller" },
83 { .compatible = "marvell,armada-375-system-controller" },
84 { .compatible = "marvell,armada-380-system-controller" },
85 { .compatible = "marvell,armada-390-system-controller" },
89 static const struct reset_ops mvebu_reset_ops = {
90 .of_xlate = mvebu_reset_of_xlate,
91 .request = mvebu_reset_request,
92 .rfree = mvebu_reset_free,
93 .rst_assert = mvebu_reset_assert,
94 .rst_deassert = mvebu_reset_deassert,
95 .rst_status = mvebu_reset_status,
98 U_BOOT_DRIVER(mvebu_reset) = {
99 .name = "mvebu-reset",
101 .of_match = mvebu_reset_of_match,
102 .of_to_plat = mvebu_reset_of_to_plat,
103 .priv_auto = sizeof(struct mvebu_reset_data),
104 .ops = &mvebu_reset_ops,