xref: /openbmc/linux/drivers/reset/tegra/reset-bpmp.c (revision 82e6fdd6)
1 /*
2  * Copyright (C) 2016 NVIDIA Corporation
3  *
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  */
8 
9 #include <linux/reset-controller.h>
10 
11 #include <soc/tegra/bpmp.h>
12 #include <soc/tegra/bpmp-abi.h>
13 
14 static struct tegra_bpmp *to_tegra_bpmp(struct reset_controller_dev *rstc)
15 {
16 	return container_of(rstc, struct tegra_bpmp, rstc);
17 }
18 
19 static int tegra_bpmp_reset_common(struct reset_controller_dev *rstc,
20 				   enum mrq_reset_commands command,
21 				   unsigned int id)
22 {
23 	struct tegra_bpmp *bpmp = to_tegra_bpmp(rstc);
24 	struct mrq_reset_request request;
25 	struct tegra_bpmp_message msg;
26 
27 	memset(&request, 0, sizeof(request));
28 	request.cmd = command;
29 	request.reset_id = id;
30 
31 	memset(&msg, 0, sizeof(msg));
32 	msg.mrq = MRQ_RESET;
33 	msg.tx.data = &request;
34 	msg.tx.size = sizeof(request);
35 
36 	return tegra_bpmp_transfer(bpmp, &msg);
37 }
38 
39 static int tegra_bpmp_reset_module(struct reset_controller_dev *rstc,
40 				   unsigned long id)
41 {
42 	return tegra_bpmp_reset_common(rstc, CMD_RESET_MODULE, id);
43 }
44 
45 static int tegra_bpmp_reset_assert(struct reset_controller_dev *rstc,
46 				   unsigned long id)
47 {
48 	return tegra_bpmp_reset_common(rstc, CMD_RESET_ASSERT, id);
49 }
50 
51 static int tegra_bpmp_reset_deassert(struct reset_controller_dev *rstc,
52 				     unsigned long id)
53 {
54 	return tegra_bpmp_reset_common(rstc, CMD_RESET_DEASSERT, id);
55 }
56 
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,
61 };
62 
63 int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
64 {
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;
69 
70 	return devm_reset_controller_register(bpmp->dev, &bpmp->rstc);
71 }
72