2 * Socfpga Reset Controller Driver
7 * Allwinner SoCs Reset Controller driver
9 * Copyright 2013 Maxime Ripard
13 * SPDX-License-Identifier: GPL-2.0+
18 #include <dm/of_access.h>
19 #include <reset-uclass.h>
20 #include <linux/bitops.h>
22 #include <linux/sizes.h>
24 #define BANK_INCREMENT 4
27 struct socfpga_reset_data {
28 void __iomem *membase;
31 static int socfpga_reset_assert(struct reset_ctl *reset_ctl)
33 struct socfpga_reset_data *data = dev_get_priv(reset_ctl->dev);
34 int id = reset_ctl->id;
35 int reg_width = sizeof(u32);
36 int bank = id / (reg_width * BITS_PER_BYTE);
37 int offset = id % (reg_width * BITS_PER_BYTE);
39 setbits_le32(data->membase + (bank * BANK_INCREMENT), BIT(offset));
43 static int socfpga_reset_deassert(struct reset_ctl *reset_ctl)
45 struct socfpga_reset_data *data = dev_get_priv(reset_ctl->dev);
46 int id = reset_ctl->id;
47 int reg_width = sizeof(u32);
48 int bank = id / (reg_width * BITS_PER_BYTE);
49 int offset = id % (reg_width * BITS_PER_BYTE);
51 clrbits_le32(data->membase + (bank * BANK_INCREMENT), BIT(offset));
55 static int socfpga_reset_request(struct reset_ctl *reset_ctl)
57 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__,
58 reset_ctl, reset_ctl->dev, reset_ctl->id);
63 static int socfpga_reset_free(struct reset_ctl *reset_ctl)
65 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
66 reset_ctl->dev, reset_ctl->id);
71 static const struct reset_ops socfpga_reset_ops = {
72 .request = socfpga_reset_request,
73 .free = socfpga_reset_free,
74 .rst_assert = socfpga_reset_assert,
75 .rst_deassert = socfpga_reset_deassert,
78 static int socfpga_reset_probe(struct udevice *dev)
80 struct socfpga_reset_data *data = dev_get_priv(dev);
81 const void *blob = gd->fdt_blob;
82 int node = dev_of_offset(dev);
85 data->membase = devfdt_get_addr_ptr(dev);
87 modrst_offset = fdtdec_get_int(blob, node, "altr,modrst-offset", 0x10);
88 data->membase += modrst_offset;
93 static const struct udevice_id socfpga_reset_match[] = {
94 { .compatible = "altr,rst-mgr" },
98 U_BOOT_DRIVER(socfpga_reset) = {
99 .name = "socfpga-reset",
101 .of_match = socfpga_reset_match,
102 .probe = socfpga_reset_probe,
103 .priv_auto_alloc_size = sizeof(struct socfpga_reset_data),
104 .ops = &socfpga_reset_ops,