blob: 122556162ec3be967683b7d634a0d90c6afa40aa [file] [log] [blame]
Etienne Carriere34d76fe2020-09-09 18:44:06 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
Etienne Carrieref487a882022-05-31 18:09:26 +02003 * Copyright (C) 2019-2022 Linaro Limited
Etienne Carriere34d76fe2020-09-09 18:44:06 +02004 */
Patrick Delaunayd9631542021-10-28 19:13:12 +02005
6#define LOG_CATEGORY UCLASS_RESET
7
Etienne Carriere34d76fe2020-09-09 18:44:06 +02008#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
Etienne Carrieref487a882022-05-31 18:09:26 +020016/**
17 * struct scmi_reset_priv - Private data for SCMI reset controller
18 * @channel: Reference to the SCMI channel to use
19 */
20struct scmi_reset_priv {
21 struct scmi_channel *channel;
22};
23
Etienne Carriere34d76fe2020-09-09 18:44:06 +020024static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert)
25{
Etienne Carrieref487a882022-05-31 18:09:26 +020026 struct scmi_reset_priv *priv = dev_get_priv(rst->dev);
Etienne Carriere34d76fe2020-09-09 18:44:06 +020027 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
Etienne Carrieref487a882022-05-31 18:09:26 +020038 ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg);
Etienne Carriere34d76fe2020-09-09 18:44:06 +020039 if (ret)
40 return ret;
41
42 return scmi_to_linux_errno(out.status);
43}
44
45static int scmi_reset_assert(struct reset_ctl *rst)
46{
47 return scmi_reset_set_level(rst, true);
48}
49
50static int scmi_reset_deassert(struct reset_ctl *rst)
51{
52 return scmi_reset_set_level(rst, false);
53}
54
55static int scmi_reset_request(struct reset_ctl *rst)
56{
Etienne Carrieref487a882022-05-31 18:09:26 +020057 struct scmi_reset_priv *priv = dev_get_priv(rst->dev);
Etienne Carriere34d76fe2020-09-09 18:44:06 +020058 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 */
Etienne Carrieref487a882022-05-31 18:09:26 +020071 ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg);
Etienne Carriere34d76fe2020-09-09 18:44:06 +020072 if (ret)
73 return ret;
74
75 return scmi_to_linux_errno(out.status);
76}
77
Etienne Carriere34d76fe2020-09-09 18:44:06 +020078static const struct reset_ops scmi_reset_domain_ops = {
79 .request = scmi_reset_request,
Etienne Carriere34d76fe2020-09-09 18:44:06 +020080 .rst_assert = scmi_reset_assert,
81 .rst_deassert = scmi_reset_deassert,
82};
83
Etienne Carrieref487a882022-05-31 18:09:26 +020084static 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
Etienne Carriere34d76fe2020-09-09 18:44:06 +020091U_BOOT_DRIVER(scmi_reset_domain) = {
92 .name = "scmi_reset_domain",
93 .id = UCLASS_RESET,
94 .ops = &scmi_reset_domain_ops,
Etienne Carrieref487a882022-05-31 18:09:26 +020095 .probe = scmi_reset_probe,
96 .priv_auto = sizeof(struct scmi_reset_priv *),
Etienne Carriere34d76fe2020-09-09 18:44:06 +020097};