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