dm: spi: Fix spi_free_slave() freed memory write
[platform/kernel/u-boot.git] / drivers / reset / reset-ast2500.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright 2017 Google, Inc
4  * Copyright 2020 ASPEED Technology Inc.
5  */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <log.h>
10 #include <misc.h>
11 #include <reset.h>
12 #include <reset-uclass.h>
13 #include <linux/err.h>
14 #include <asm/io.h>
15 #include <asm/arch/scu_ast2500.h>
16
17 struct ast2500_reset_priv {
18         struct ast2500_scu *scu;
19 };
20
21 static int ast2500_reset_request(struct reset_ctl *reset_ctl)
22 {
23         debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
24               reset_ctl->dev, reset_ctl->id);
25
26         return 0;
27 }
28
29 static int ast2500_reset_free(struct reset_ctl *reset_ctl)
30 {
31         debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
32               reset_ctl->dev, reset_ctl->id);
33
34         return 0;
35 }
36
37 static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
38 {
39         struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
40         struct ast2500_scu *scu = priv->scu;
41
42         debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
43
44         if (reset_ctl->id < 32)
45                 setbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
46         else
47                 setbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
48
49         return 0;
50 }
51
52 static int ast2500_reset_deassert(struct reset_ctl *reset_ctl)
53 {
54         struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
55         struct ast2500_scu *scu = priv->scu;
56
57         debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
58
59         if (reset_ctl->id < 32)
60                 clrbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
61         else
62                 clrbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
63
64         return 0;
65 }
66
67 static int ast2500_reset_probe(struct udevice *dev)
68 {
69         int rc;
70         struct ast2500_reset_priv *priv = dev_get_priv(dev);
71         struct udevice *scu_dev;
72
73         /* get SCU base from clock device */
74         rc = uclass_get_device_by_driver(UCLASS_CLK,
75                                          DM_GET_DRIVER(aspeed_ast2500_scu), &scu_dev);
76         if (rc) {
77                 debug("%s: clock device not found, rc=%d\n", __func__, rc);
78                 return rc;
79         }
80
81         priv->scu = devfdt_get_addr_ptr(scu_dev);
82         if (IS_ERR_OR_NULL(priv->scu)) {
83                 debug("%s: invalid SCU base pointer\n", __func__);
84                 return PTR_ERR(priv->scu);
85         }
86
87         return 0;
88 }
89
90 static const struct udevice_id ast2500_reset_ids[] = {
91         { .compatible = "aspeed,ast2500-reset" },
92         { }
93 };
94
95 struct reset_ops ast2500_reset_ops = {
96         .request = ast2500_reset_request,
97         .rfree = ast2500_reset_free,
98         .rst_assert = ast2500_reset_assert,
99         .rst_deassert = ast2500_reset_deassert,
100 };
101
102 U_BOOT_DRIVER(ast2500_reset) = {
103         .name = "ast2500_reset",
104         .id = UCLASS_RESET,
105         .of_match = ast2500_reset_ids,
106         .probe = ast2500_reset_probe,
107         .ops = &ast2500_reset_ops,
108         .priv_auto      = sizeof(struct ast2500_reset_priv),
109 };