Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 92c67fa | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 92c67fa | 2016-07-13 13:45:31 -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 | 92c67fa | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 10 | #include <power-domain-uclass.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/power-domain.h> |
| 13 | |
| 14 | #define SANDBOX_POWER_DOMAINS 3 |
| 15 | |
| 16 | struct sandbox_power_domain { |
| 17 | bool on[SANDBOX_POWER_DOMAINS]; |
| 18 | }; |
| 19 | |
| 20 | static int sandbox_power_domain_request(struct power_domain *power_domain) |
| 21 | { |
| 22 | debug("%s(power_domain=%p)\n", __func__, power_domain); |
| 23 | |
| 24 | if (power_domain->id >= SANDBOX_POWER_DOMAINS) |
| 25 | return -EINVAL; |
| 26 | |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | static int sandbox_power_domain_free(struct power_domain *power_domain) |
| 31 | { |
| 32 | debug("%s(power_domain=%p)\n", __func__, power_domain); |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int sandbox_power_domain_on(struct power_domain *power_domain) |
| 38 | { |
| 39 | struct sandbox_power_domain *sbr = dev_get_priv(power_domain->dev); |
| 40 | |
| 41 | debug("%s(power_domain=%p)\n", __func__, power_domain); |
| 42 | |
| 43 | sbr->on[power_domain->id] = true; |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | static int sandbox_power_domain_off(struct power_domain *power_domain) |
| 49 | { |
| 50 | struct sandbox_power_domain *sbr = dev_get_priv(power_domain->dev); |
| 51 | |
| 52 | debug("%s(power_domain=%p)\n", __func__, power_domain); |
| 53 | |
| 54 | sbr->on[power_domain->id] = false; |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int sandbox_power_domain_bind(struct udevice *dev) |
| 60 | { |
| 61 | debug("%s(dev=%p)\n", __func__, dev); |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static int sandbox_power_domain_probe(struct udevice *dev) |
| 67 | { |
| 68 | debug("%s(dev=%p)\n", __func__, dev); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static const struct udevice_id sandbox_power_domain_ids[] = { |
| 74 | { .compatible = "sandbox,power-domain" }, |
| 75 | { } |
| 76 | }; |
| 77 | |
| 78 | struct power_domain_ops sandbox_power_domain_ops = { |
| 79 | .request = sandbox_power_domain_request, |
Simon Glass | 92ed3a3 | 2020-02-03 07:35:51 -0700 | [diff] [blame] | 80 | .rfree = sandbox_power_domain_free, |
Stephen Warren | 92c67fa | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 81 | .on = sandbox_power_domain_on, |
| 82 | .off = sandbox_power_domain_off, |
| 83 | }; |
| 84 | |
| 85 | U_BOOT_DRIVER(sandbox_power_domain) = { |
| 86 | .name = "sandbox_power_domain", |
| 87 | .id = UCLASS_POWER_DOMAIN, |
| 88 | .of_match = sandbox_power_domain_ids, |
| 89 | .bind = sandbox_power_domain_bind, |
| 90 | .probe = sandbox_power_domain_probe, |
| 91 | .priv_auto_alloc_size = sizeof(struct sandbox_power_domain), |
| 92 | .ops = &sandbox_power_domain_ops, |
| 93 | }; |
| 94 | |
| 95 | int sandbox_power_domain_query(struct udevice *dev, unsigned long id) |
| 96 | { |
| 97 | struct sandbox_power_domain *sbr = dev_get_priv(dev); |
| 98 | |
| 99 | debug("%s(dev=%p, id=%ld)\n", __func__, dev, id); |
| 100 | |
| 101 | if (id >= SANDBOX_POWER_DOMAINS) |
| 102 | return -EINVAL; |
| 103 | |
| 104 | return sbr->on[id]; |
| 105 | } |