ARM: dts: npcm8xx: add npcm845 function node
[platform/kernel/u-boot.git] / drivers / reset / reset-scmi.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2019-2022 Linaro Limited
4  */
5
6 #define LOG_CATEGORY UCLASS_RESET
7
8 #include <common.h>
9 #include <dm.h>
10 #include <errno.h>
11 #include <reset-uclass.h>
12 #include <scmi_agent.h>
13 #include <scmi_protocols.h>
14 #include <asm/types.h>
15
16 /**
17  * struct scmi_reset_priv - Private data for SCMI reset controller
18  * @channel: Reference to the SCMI channel to use
19  */
20 struct scmi_reset_priv {
21         struct scmi_channel *channel;
22 };
23
24 static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert)
25 {
26         struct scmi_reset_priv *priv = dev_get_priv(rst->dev);
27         struct scmi_rd_reset_in in = {
28                 .domain_id = rst->id,
29                 .flags = assert_not_deassert ? SCMI_RD_RESET_FLAG_ASSERT : 0,
30                 .reset_state = 0,
31         };
32         struct scmi_rd_reset_out out;
33         struct scmi_msg msg = SCMI_MSG_IN(SCMI_PROTOCOL_ID_RESET_DOMAIN,
34                                           SCMI_RESET_DOMAIN_RESET,
35                                           in, out);
36         int ret;
37
38         ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg);
39         if (ret)
40                 return ret;
41
42         return scmi_to_linux_errno(out.status);
43 }
44
45 static int scmi_reset_assert(struct reset_ctl *rst)
46 {
47         return scmi_reset_set_level(rst, true);
48 }
49
50 static int scmi_reset_deassert(struct reset_ctl *rst)
51 {
52         return scmi_reset_set_level(rst, false);
53 }
54
55 static int scmi_reset_request(struct reset_ctl *rst)
56 {
57         struct scmi_reset_priv *priv = dev_get_priv(rst->dev);
58         struct scmi_rd_attr_in in = {
59                 .domain_id = rst->id,
60         };
61         struct scmi_rd_attr_out out;
62         struct scmi_msg msg = SCMI_MSG_IN(SCMI_PROTOCOL_ID_RESET_DOMAIN,
63                                           SCMI_RESET_DOMAIN_ATTRIBUTES,
64                                           in, out);
65         int ret;
66
67         /*
68          * We don't really care about the attribute, just check
69          * the reset domain exists.
70          */
71         ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg);
72         if (ret)
73                 return ret;
74
75         return scmi_to_linux_errno(out.status);
76 }
77
78 static const struct reset_ops scmi_reset_domain_ops = {
79         .request        = scmi_reset_request,
80         .rst_assert     = scmi_reset_assert,
81         .rst_deassert   = scmi_reset_deassert,
82 };
83
84 static int scmi_reset_probe(struct udevice *dev)
85 {
86         struct scmi_reset_priv *priv = dev_get_priv(dev);
87
88         return devm_scmi_of_get_channel(dev, &priv->channel);
89 }
90
91 U_BOOT_DRIVER(scmi_reset_domain) = {
92         .name = "scmi_reset_domain",
93         .id = UCLASS_RESET,
94         .ops = &scmi_reset_domain_ops,
95         .probe = scmi_reset_probe,
96         .priv_auto = sizeof(struct scmi_reset_priv *),
97 };