blob: 334c460c805f6fdc16948041b664267fd823020f [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
Stephen Warren402a0fa2016-08-08 11:28:26 -06006#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -07008#include <malloc.h>
Stephen Warren402a0fa2016-08-08 11:28:26 -06009#include <misc.h>
10#include <power-domain-uclass.h>
11#include <asm/arch-tegra/bpmp_abi.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060012#include <linux/bitops.h>
Stephen Warren402a0fa2016-08-08 11:28:26 -060013
14#define UPDATE BIT(0)
15#define ON BIT(1)
16
Stephen Warren402a0fa2016-08-08 11:28:26 -060017static int tegra186_power_domain_common(struct power_domain *power_domain,
18 bool on)
19{
20 struct mrq_pg_update_state_request req;
21 int on_state = on ? ON : 0;
22 int ret;
23
24 req.partition_id = power_domain->id;
25 req.logic_state = UPDATE | on_state;
26 req.sram_state = UPDATE | on_state;
27 /*
28 * Drivers manage their own clocks so they don't get out of sync, and
29 * since some power domains have many clocks, only a subset of which
30 * are actually needed depending on use-case.
31 */
32 req.clock_state = UPDATE;
33
34 ret = misc_call(power_domain->dev->parent, MRQ_PG_UPDATE_STATE, &req,
35 sizeof(req), NULL, 0);
36 if (ret < 0)
37 return ret;
38
39 return 0;
40}
41
42static int tegra186_power_domain_on(struct power_domain *power_domain)
43{
44 debug("%s(power_domain=%p) (dev=%p, id=%lu)\n", __func__,
45 power_domain, power_domain->dev, power_domain->id);
46
47 return tegra186_power_domain_common(power_domain, true);
48}
49
50static int tegra186_power_domain_off(struct power_domain *power_domain)
51{
52 debug("%s(power_domain=%p) (dev=%p, id=%lu)\n", __func__,
53 power_domain, power_domain->dev, power_domain->id);
54
55 return tegra186_power_domain_common(power_domain, false);
56}
57
58struct power_domain_ops tegra186_power_domain_ops = {
Stephen Warren402a0fa2016-08-08 11:28:26 -060059 .on = tegra186_power_domain_on,
60 .off = tegra186_power_domain_off,
61};
62
Stephen Warren402a0fa2016-08-08 11:28:26 -060063U_BOOT_DRIVER(tegra186_power_domain) = {
64 .name = "tegra186_power_domain",
65 .id = UCLASS_POWER_DOMAIN,
Stephen Warren402a0fa2016-08-08 11:28:26 -060066 .ops = &tegra186_power_domain_ops,
67};