2 * Copyright (C) 2016 NVIDIA Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/reset-controller.h>
11 #include <soc/tegra/bpmp.h>
12 #include <soc/tegra/bpmp-abi.h>
14 static struct tegra_bpmp *to_tegra_bpmp(struct reset_controller_dev *rstc)
16 return container_of(rstc, struct tegra_bpmp, rstc);
19 static int tegra_bpmp_reset_common(struct reset_controller_dev *rstc,
20 enum mrq_reset_commands command,
23 struct tegra_bpmp *bpmp = to_tegra_bpmp(rstc);
24 struct mrq_reset_request request;
25 struct tegra_bpmp_message msg;
28 memset(&request, 0, sizeof(request));
29 request.cmd = command;
30 request.reset_id = id;
32 memset(&msg, 0, sizeof(msg));
34 msg.tx.data = &request;
35 msg.tx.size = sizeof(request);
37 err = tegra_bpmp_transfer(bpmp, &msg);
46 static int tegra_bpmp_reset_module(struct reset_controller_dev *rstc,
49 return tegra_bpmp_reset_common(rstc, CMD_RESET_MODULE, id);
52 static int tegra_bpmp_reset_assert(struct reset_controller_dev *rstc,
55 return tegra_bpmp_reset_common(rstc, CMD_RESET_ASSERT, id);
58 static int tegra_bpmp_reset_deassert(struct reset_controller_dev *rstc,
61 return tegra_bpmp_reset_common(rstc, CMD_RESET_DEASSERT, id);
64 static const struct reset_control_ops tegra_bpmp_reset_ops = {
65 .reset = tegra_bpmp_reset_module,
66 .assert = tegra_bpmp_reset_assert,
67 .deassert = tegra_bpmp_reset_deassert,
70 int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
72 bpmp->rstc.ops = &tegra_bpmp_reset_ops;
73 bpmp->rstc.owner = THIS_MODULE;
74 bpmp->rstc.of_node = bpmp->dev->of_node;
75 bpmp->rstc.nr_resets = bpmp->soc->num_resets;
77 return devm_reset_controller_register(bpmp->dev, &bpmp->rstc);