Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Etienne Carriere | f487a88 | 2022-05-31 18:09:26 +0200 | [diff] [blame] | 3 | * Copyright (C) 2019-2022 Linaro Limited |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 4 | */ |
Patrick Delaunay | d963154 | 2021-10-28 19:13:12 +0200 | [diff] [blame] | 5 | |
| 6 | #define LOG_CATEGORY UCLASS_RESET |
| 7 | |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 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 | |
Etienne Carriere | f487a88 | 2022-05-31 18:09:26 +0200 | [diff] [blame] | 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 | |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 24 | static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert) |
| 25 | { |
Etienne Carriere | f487a88 | 2022-05-31 18:09:26 +0200 | [diff] [blame] | 26 | struct scmi_reset_priv *priv = dev_get_priv(rst->dev); |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 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 | |
Etienne Carriere | f487a88 | 2022-05-31 18:09:26 +0200 | [diff] [blame] | 38 | ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg); |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 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 | { |
Etienne Carriere | f487a88 | 2022-05-31 18:09:26 +0200 | [diff] [blame] | 57 | struct scmi_reset_priv *priv = dev_get_priv(rst->dev); |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 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 | */ |
Etienne Carriere | f487a88 | 2022-05-31 18:09:26 +0200 | [diff] [blame] | 71 | ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg); |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 72 | if (ret) |
| 73 | return ret; |
| 74 | |
| 75 | return scmi_to_linux_errno(out.status); |
| 76 | } |
| 77 | |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 78 | static const struct reset_ops scmi_reset_domain_ops = { |
| 79 | .request = scmi_reset_request, |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 80 | .rst_assert = scmi_reset_assert, |
| 81 | .rst_deassert = scmi_reset_deassert, |
| 82 | }; |
| 83 | |
Etienne Carriere | f487a88 | 2022-05-31 18:09:26 +0200 | [diff] [blame] | 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 | |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 91 | U_BOOT_DRIVER(scmi_reset_domain) = { |
| 92 | .name = "scmi_reset_domain", |
| 93 | .id = UCLASS_RESET, |
| 94 | .ops = &scmi_reset_domain_ops, |
Etienne Carriere | f487a88 | 2022-05-31 18:09:26 +0200 | [diff] [blame] | 95 | .probe = scmi_reset_probe, |
| 96 | .priv_auto = sizeof(struct scmi_reset_priv *), |
Etienne Carriere | 34d76fe | 2020-09-09 18:44:06 +0200 | [diff] [blame] | 97 | }; |