blob: 24d3395964cc4ba2d3934a32299fef3f667cd45f [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Thierry Redingdc606c52016-08-18 15:50:09 +02002/*
3 * Copyright (C) 2016 NVIDIA Corporation
Thierry Redingdc606c52016-08-18 15:50:09 +02004 */
5
6#include <linux/reset-controller.h>
7
8#include <soc/tegra/bpmp.h>
9#include <soc/tegra/bpmp-abi.h>
10
11static struct tegra_bpmp *to_tegra_bpmp(struct reset_controller_dev *rstc)
12{
13 return container_of(rstc, struct tegra_bpmp, rstc);
14}
15
16static int tegra_bpmp_reset_common(struct reset_controller_dev *rstc,
17 enum mrq_reset_commands command,
18 unsigned int id)
19{
20 struct tegra_bpmp *bpmp = to_tegra_bpmp(rstc);
21 struct mrq_reset_request request;
22 struct tegra_bpmp_message msg;
23
24 memset(&request, 0, sizeof(request));
25 request.cmd = command;
26 request.reset_id = id;
27
28 memset(&msg, 0, sizeof(msg));
29 msg.mrq = MRQ_RESET;
30 msg.tx.data = &request;
31 msg.tx.size = sizeof(request);
32
33 return tegra_bpmp_transfer(bpmp, &msg);
34}
35
36static int tegra_bpmp_reset_module(struct reset_controller_dev *rstc,
37 unsigned long id)
38{
39 return tegra_bpmp_reset_common(rstc, CMD_RESET_MODULE, id);
40}
41
42static int tegra_bpmp_reset_assert(struct reset_controller_dev *rstc,
43 unsigned long id)
44{
45 return tegra_bpmp_reset_common(rstc, CMD_RESET_ASSERT, id);
46}
47
48static int tegra_bpmp_reset_deassert(struct reset_controller_dev *rstc,
49 unsigned long id)
50{
51 return tegra_bpmp_reset_common(rstc, CMD_RESET_DEASSERT, id);
52}
53
54static const struct reset_control_ops tegra_bpmp_reset_ops = {
55 .reset = tegra_bpmp_reset_module,
56 .assert = tegra_bpmp_reset_assert,
57 .deassert = tegra_bpmp_reset_deassert,
58};
59
60int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
61{
62 bpmp->rstc.ops = &tegra_bpmp_reset_ops;
63 bpmp->rstc.owner = THIS_MODULE;
64 bpmp->rstc.of_node = bpmp->dev->of_node;
65 bpmp->rstc.nr_resets = bpmp->soc->num_resets;
66
67 return devm_reset_controller_register(bpmp->dev, &bpmp->rstc);
68}