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