blob: 244db51d85cbdfdf9130e7da6916b293b63833f4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dinh Nguyen5427f5a2018-04-04 17:18:20 -05002/*
3 * Socfpga Reset Controller Driver
4 *
5 * Copyright 2014 Steffen Trumtrar <s.trumtrar@pengutronix.de>
6 *
7 * based on
8 * Allwinner SoCs Reset Controller driver
9 *
10 * Copyright 2013 Maxime Ripard
11 *
12 * Maxime Ripard <maxime.ripard@free-electrons.com>
Dinh Nguyen5427f5a2018-04-04 17:18:20 -050013 */
14
15#include <common.h>
16#include <dm.h>
17#include <dm/of_access.h>
18#include <reset-uclass.h>
19#include <linux/bitops.h>
20#include <linux/io.h>
21#include <linux/sizes.h>
22
23#define BANK_INCREMENT 4
24#define NR_BANKS 8
25
26struct socfpga_reset_data {
Simon Goldschmidt53a0cf52019-03-01 20:12:30 +010027 void __iomem *modrst_base;
Dinh Nguyen5427f5a2018-04-04 17:18:20 -050028};
29
30static int socfpga_reset_assert(struct reset_ctl *reset_ctl)
31{
32 struct socfpga_reset_data *data = dev_get_priv(reset_ctl->dev);
33 int id = reset_ctl->id;
34 int reg_width = sizeof(u32);
35 int bank = id / (reg_width * BITS_PER_BYTE);
36 int offset = id % (reg_width * BITS_PER_BYTE);
37
Simon Goldschmidt53a0cf52019-03-01 20:12:30 +010038 setbits_le32(data->modrst_base + (bank * BANK_INCREMENT), BIT(offset));
Dinh Nguyen5427f5a2018-04-04 17:18:20 -050039 return 0;
40}
41
42static int socfpga_reset_deassert(struct reset_ctl *reset_ctl)
43{
44 struct socfpga_reset_data *data = dev_get_priv(reset_ctl->dev);
45 int id = reset_ctl->id;
46 int reg_width = sizeof(u32);
47 int bank = id / (reg_width * BITS_PER_BYTE);
48 int offset = id % (reg_width * BITS_PER_BYTE);
49
Simon Goldschmidt53a0cf52019-03-01 20:12:30 +010050 clrbits_le32(data->modrst_base + (bank * BANK_INCREMENT), BIT(offset));
Dinh Nguyen5427f5a2018-04-04 17:18:20 -050051 return 0;
52}
53
54static int socfpga_reset_request(struct reset_ctl *reset_ctl)
55{
56 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__,
57 reset_ctl, reset_ctl->dev, reset_ctl->id);
58
59 return 0;
60}
61
62static int socfpga_reset_free(struct reset_ctl *reset_ctl)
63{
64 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
65 reset_ctl->dev, reset_ctl->id);
66
67 return 0;
68}
69
70static const struct reset_ops socfpga_reset_ops = {
71 .request = socfpga_reset_request,
72 .free = socfpga_reset_free,
73 .rst_assert = socfpga_reset_assert,
74 .rst_deassert = socfpga_reset_deassert,
75};
76
77static int socfpga_reset_probe(struct udevice *dev)
78{
79 struct socfpga_reset_data *data = dev_get_priv(dev);
80 const void *blob = gd->fdt_blob;
81 int node = dev_of_offset(dev);
82 u32 modrst_offset;
Simon Goldschmidt53a0cf52019-03-01 20:12:30 +010083 void __iomem *membase;
Dinh Nguyen5427f5a2018-04-04 17:18:20 -050084
Simon Goldschmidt53a0cf52019-03-01 20:12:30 +010085 membase = devfdt_get_addr_ptr(dev);
Dinh Nguyen5427f5a2018-04-04 17:18:20 -050086
87 modrst_offset = fdtdec_get_int(blob, node, "altr,modrst-offset", 0x10);
Simon Goldschmidt53a0cf52019-03-01 20:12:30 +010088 data->modrst_base = membase + modrst_offset;
Dinh Nguyen5427f5a2018-04-04 17:18:20 -050089
90 return 0;
91}
92
93static const struct udevice_id socfpga_reset_match[] = {
94 { .compatible = "altr,rst-mgr" },
95 { /* sentinel */ },
96};
97
98U_BOOT_DRIVER(socfpga_reset) = {
99 .name = "socfpga-reset",
100 .id = UCLASS_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,
105};