Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Texas Instruments System Control Interface (TI SCI) power domain driver |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/ |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 6 | * Andreas Dannenberg <dannenberg@ti.com> |
| 7 | * |
| 8 | * Loosely based on Linux kernel ti_sci_pm_domains.c... |
| 9 | */ |
| 10 | |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 11 | #include <dm.h> |
| 12 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 15 | #include <power-domain-uclass.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 16 | #include <dm/device_compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 17 | #include <linux/err.h> |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 18 | #include <linux/soc/ti/ti_sci_protocol.h> |
Lokesh Vutla | e34f7a8 | 2019-06-07 19:24:46 +0530 | [diff] [blame] | 19 | #include <dt-bindings/soc/ti,sci_pm_domain.h> |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * struct ti_sci_power_domain_data - pm domain controller information structure |
| 23 | * @sci: TI SCI handle used for communication with system controller |
| 24 | */ |
| 25 | struct ti_sci_power_domain_data { |
| 26 | const struct ti_sci_handle *sci; |
| 27 | }; |
| 28 | |
| 29 | static int ti_sci_power_domain_probe(struct udevice *dev) |
| 30 | { |
| 31 | struct ti_sci_power_domain_data *data = dev_get_priv(dev); |
| 32 | |
| 33 | debug("%s(dev=%p)\n", __func__, dev); |
| 34 | |
| 35 | if (!data) |
| 36 | return -ENOMEM; |
| 37 | |
| 38 | /* Store handle for communication with the system controller */ |
| 39 | data->sci = ti_sci_get_handle(dev); |
| 40 | if (IS_ERR(data->sci)) |
| 41 | return PTR_ERR(data->sci); |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 46 | static int ti_sci_power_domain_on(struct power_domain *pd) |
| 47 | { |
| 48 | struct ti_sci_power_domain_data *data = dev_get_priv(pd->dev); |
| 49 | const struct ti_sci_handle *sci = data->sci; |
| 50 | const struct ti_sci_dev_ops *dops = &sci->ops.dev_ops; |
Lokesh Vutla | e34f7a8 | 2019-06-07 19:24:46 +0530 | [diff] [blame] | 51 | u8 flags = (uintptr_t)pd->priv; |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 52 | int ret; |
| 53 | |
| 54 | debug("%s(pd=%p)\n", __func__, pd); |
| 55 | |
Lokesh Vutla | e34f7a8 | 2019-06-07 19:24:46 +0530 | [diff] [blame] | 56 | if (flags & TI_SCI_PD_EXCLUSIVE) |
| 57 | ret = dops->get_device_exclusive(sci, pd->id); |
| 58 | else |
| 59 | ret = dops->get_device(sci, pd->id); |
| 60 | |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 61 | if (ret) |
Nishanth Menon | 0401fb6 | 2019-08-01 19:08:24 +0530 | [diff] [blame] | 62 | dev_err(pd->dev, "%s: get_device(%lu) failed (%d)\n", |
| 63 | __func__, pd->id, ret); |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 64 | |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | static int ti_sci_power_domain_off(struct power_domain *pd) |
| 69 | { |
| 70 | struct ti_sci_power_domain_data *data = dev_get_priv(pd->dev); |
| 71 | const struct ti_sci_handle *sci = data->sci; |
| 72 | const struct ti_sci_dev_ops *dops = &sci->ops.dev_ops; |
| 73 | int ret; |
| 74 | |
| 75 | debug("%s(pd=%p)\n", __func__, pd); |
| 76 | |
| 77 | ret = dops->put_device(sci, pd->id); |
| 78 | if (ret) |
Nishanth Menon | 0401fb6 | 2019-08-01 19:08:24 +0530 | [diff] [blame] | 79 | dev_err(pd->dev, "%s: put_device(%lu) failed (%d)\n", |
| 80 | __func__, pd->id, ret); |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 81 | |
| 82 | return ret; |
| 83 | } |
| 84 | |
Lokesh Vutla | e34f7a8 | 2019-06-07 19:24:46 +0530 | [diff] [blame] | 85 | static int ti_sci_power_domain_of_xlate(struct power_domain *pd, |
| 86 | struct ofnode_phandle_args *args) |
| 87 | { |
| 88 | u8 flags; |
| 89 | |
| 90 | debug("%s(power_domain=%p)\n", __func__, pd); |
| 91 | |
| 92 | if (args->args_count < 1) { |
| 93 | debug("Invalid args_count: %d\n", args->args_count); |
| 94 | return -EINVAL; |
| 95 | } |
| 96 | |
| 97 | pd->id = args->args[0]; |
| 98 | /* By default request for device exclusive */ |
| 99 | flags = TI_SCI_PD_EXCLUSIVE; |
| 100 | if (args->args_count == 2) |
| 101 | flags = args->args[1] & TI_SCI_PD_EXCLUSIVE; |
| 102 | pd->priv = (void *)(uintptr_t)flags; |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 107 | static const struct udevice_id ti_sci_power_domain_of_match[] = { |
| 108 | { .compatible = "ti,sci-pm-domain" }, |
| 109 | { /* sentinel */ } |
| 110 | }; |
| 111 | |
| 112 | static struct power_domain_ops ti_sci_power_domain_ops = { |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 113 | .on = ti_sci_power_domain_on, |
| 114 | .off = ti_sci_power_domain_off, |
Lokesh Vutla | e34f7a8 | 2019-06-07 19:24:46 +0530 | [diff] [blame] | 115 | .of_xlate = ti_sci_power_domain_of_xlate, |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | U_BOOT_DRIVER(ti_sci_pm_domains) = { |
| 119 | .name = "ti-sci-pm-domains", |
| 120 | .id = UCLASS_POWER_DOMAIN, |
| 121 | .of_match = ti_sci_power_domain_of_match, |
| 122 | .probe = ti_sci_power_domain_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 123 | .priv_auto = sizeof(struct ti_sci_power_domain_data), |
Andreas Dannenberg | 24c6e91 | 2018-08-27 15:57:45 +0530 | [diff] [blame] | 124 | .ops = &ti_sci_power_domain_ops, |
| 125 | }; |