Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 402a0fa | 2016-08-08 11:28:26 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 402a0fa | 2016-08-08 11:28:26 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame^] | 8 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Stephen Warren | 402a0fa | 2016-08-08 11:28:26 -0600 | [diff] [blame] | 10 | #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 | |
| 17 | static 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 | |
| 25 | static 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 | |
| 33 | static 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 | |
| 58 | static 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 | |
| 66 | static 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 | |
| 74 | struct power_domain_ops tegra186_power_domain_ops = { |
| 75 | .request = tegra186_power_domain_request, |
Simon Glass | 92ed3a3 | 2020-02-03 07:35:51 -0700 | [diff] [blame] | 76 | .rfree = tegra186_power_domain_free, |
Stephen Warren | 402a0fa | 2016-08-08 11:28:26 -0600 | [diff] [blame] | 77 | .on = tegra186_power_domain_on, |
| 78 | .off = tegra186_power_domain_off, |
| 79 | }; |
| 80 | |
| 81 | static int tegra186_power_domain_probe(struct udevice *dev) |
| 82 | { |
| 83 | debug("%s(dev=%p)\n", __func__, dev); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | U_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 | }; |