Linux 4.16.11
[linux/fpc-iii.git] / drivers / reset / tegra / reset-bpmp.c
blob5daf2ee1a396b453248be33b0183e7092bccb457
1 /*
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.
7 */
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,
21 unsigned int id)
23 struct tegra_bpmp *bpmp = to_tegra_bpmp(rstc);
24 struct mrq_reset_request request;
25 struct tegra_bpmp_message msg;
27 memset(&request, 0, sizeof(request));
28 request.cmd = command;
29 request.reset_id = id;
31 memset(&msg, 0, sizeof(msg));
32 msg.mrq = MRQ_RESET;
33 msg.tx.data = &request;
34 msg.tx.size = sizeof(request);
36 return tegra_bpmp_transfer(bpmp, &msg);
39 static int tegra_bpmp_reset_module(struct reset_controller_dev *rstc,
40 unsigned long id)
42 return tegra_bpmp_reset_common(rstc, CMD_RESET_MODULE, id);
45 static int tegra_bpmp_reset_assert(struct reset_controller_dev *rstc,
46 unsigned long id)
48 return tegra_bpmp_reset_common(rstc, CMD_RESET_ASSERT, id);
51 static int tegra_bpmp_reset_deassert(struct reset_controller_dev *rstc,
52 unsigned long id)
54 return tegra_bpmp_reset_common(rstc, CMD_RESET_DEASSERT, id);
57 static const struct reset_control_ops tegra_bpmp_reset_ops = {
58 .reset = tegra_bpmp_reset_module,
59 .assert = tegra_bpmp_reset_assert,
60 .deassert = tegra_bpmp_reset_deassert,
63 int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
65 bpmp->rstc.ops = &tegra_bpmp_reset_ops;
66 bpmp->rstc.owner = THIS_MODULE;
67 bpmp->rstc.of_node = bpmp->dev->of_node;
68 bpmp->rstc.nr_resets = bpmp->soc->num_resets;
70 return devm_reset_controller_register(bpmp->dev, &bpmp->rstc);