1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2016, NVIDIA CORPORATION.
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <misc.h>
9 #include <power-domain-uclass.h>
10 #include <asm/arch-tegra/bpmp_abi.h>
11 
12 #define UPDATE	BIT(0)
13 #define ON	BIT(1)
14 
tegra186_power_domain_request(struct power_domain * power_domain)15 static int tegra186_power_domain_request(struct power_domain *power_domain)
16 {
17 	debug("%s(power_domain=%p) (dev=%p, id=%lu)\n", __func__,
18 	      power_domain, power_domain->dev, power_domain->id);
19 
20 	return 0;
21 }
22 
tegra186_power_domain_free(struct power_domain * power_domain)23 static int tegra186_power_domain_free(struct power_domain *power_domain)
24 {
25 	debug("%s(power_domain=%p) (dev=%p, id=%lu)\n", __func__,
26 	      power_domain, power_domain->dev, power_domain->id);
27 
28 	return 0;
29 }
30 
tegra186_power_domain_common(struct power_domain * power_domain,bool on)31 static int tegra186_power_domain_common(struct power_domain *power_domain,
32 					bool on)
33 {
34 	struct mrq_pg_update_state_request req;
35 	int on_state = on ? ON : 0;
36 	int ret;
37 
38 	req.partition_id = power_domain->id;
39 	req.logic_state = UPDATE | on_state;
40 	req.sram_state = UPDATE | on_state;
41 	/*
42 	 * Drivers manage their own clocks so they don't get out of sync, and
43 	 * since some power domains have many clocks, only a subset of which
44 	 * are actually needed depending on use-case.
45 	 */
46 	req.clock_state = UPDATE;
47 
48 	ret = misc_call(power_domain->dev->parent, MRQ_PG_UPDATE_STATE, &req,
49 			sizeof(req), NULL, 0);
50 	if (ret < 0)
51 		return ret;
52 
53 	return 0;
54 }
55 
tegra186_power_domain_on(struct power_domain * power_domain)56 static int tegra186_power_domain_on(struct power_domain *power_domain)
57 {
58 	debug("%s(power_domain=%p) (dev=%p, id=%lu)\n", __func__,
59 	      power_domain, power_domain->dev, power_domain->id);
60 
61 	return tegra186_power_domain_common(power_domain, true);
62 }
63 
tegra186_power_domain_off(struct power_domain * power_domain)64 static int tegra186_power_domain_off(struct power_domain *power_domain)
65 {
66 	debug("%s(power_domain=%p) (dev=%p, id=%lu)\n", __func__,
67 	      power_domain, power_domain->dev, power_domain->id);
68 
69 	return tegra186_power_domain_common(power_domain, false);
70 }
71 
72 struct power_domain_ops tegra186_power_domain_ops = {
73 	.request = tegra186_power_domain_request,
74 	.free = tegra186_power_domain_free,
75 	.on = tegra186_power_domain_on,
76 	.off = tegra186_power_domain_off,
77 };
78 
tegra186_power_domain_probe(struct udevice * dev)79 static int tegra186_power_domain_probe(struct udevice *dev)
80 {
81 	debug("%s(dev=%p)\n", __func__, dev);
82 
83 	return 0;
84 }
85 
86 U_BOOT_DRIVER(tegra186_power_domain) = {
87 	.name = "tegra186_power_domain",
88 	.id = UCLASS_POWER_DOMAIN,
89 	.probe = tegra186_power_domain_probe,
90 	.ops = &tegra186_power_domain_ops,
91 };
92