1 // SPDX-License-Identifier: GPL-2.0+
3 * Texas Instruments System Control Interface (TI SCI) power domain driver
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Andreas Dannenberg <dannenberg@ti.com>
8 * Loosely based on Linux kernel ti_sci_pm_domains.c...
15 #include <power-domain-uclass.h>
16 #include <dm/device_compat.h>
17 #include <linux/err.h>
18 #include <linux/soc/ti/ti_sci_protocol.h>
19 #include <dt-bindings/soc/ti,sci_pm_domain.h>
22 * struct ti_sci_power_domain_data - pm domain controller information structure
23 * @sci: TI SCI handle used for communication with system controller
25 struct ti_sci_power_domain_data {
26 const struct ti_sci_handle *sci;
29 static int ti_sci_power_domain_probe(struct udevice *dev)
31 struct ti_sci_power_domain_data *data = dev_get_priv(dev);
33 debug("%s(dev=%p)\n", __func__, dev);
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);
46 static int ti_sci_power_domain_request(struct power_domain *pd)
48 debug("%s(pd=%p)\n", __func__, pd);
52 static int ti_sci_power_domain_free(struct power_domain *pd)
54 debug("%s(pd=%p)\n", __func__, pd);
58 static int ti_sci_power_domain_on(struct power_domain *pd)
60 struct ti_sci_power_domain_data *data = dev_get_priv(pd->dev);
61 const struct ti_sci_handle *sci = data->sci;
62 const struct ti_sci_dev_ops *dops = &sci->ops.dev_ops;
63 u8 flags = (uintptr_t)pd->priv;
66 debug("%s(pd=%p)\n", __func__, pd);
68 if (flags & TI_SCI_PD_EXCLUSIVE)
69 ret = dops->get_device_exclusive(sci, pd->id);
71 ret = dops->get_device(sci, pd->id);
74 dev_err(pd->dev, "%s: get_device(%lu) failed (%d)\n",
75 __func__, pd->id, ret);
80 static int ti_sci_power_domain_off(struct power_domain *pd)
82 struct ti_sci_power_domain_data *data = dev_get_priv(pd->dev);
83 const struct ti_sci_handle *sci = data->sci;
84 const struct ti_sci_dev_ops *dops = &sci->ops.dev_ops;
87 debug("%s(pd=%p)\n", __func__, pd);
89 ret = dops->put_device(sci, pd->id);
91 dev_err(pd->dev, "%s: put_device(%lu) failed (%d)\n",
92 __func__, pd->id, ret);
97 static int ti_sci_power_domain_of_xlate(struct power_domain *pd,
98 struct ofnode_phandle_args *args)
102 debug("%s(power_domain=%p)\n", __func__, pd);
104 if (args->args_count < 1) {
105 debug("Invalid args_count: %d\n", args->args_count);
109 pd->id = args->args[0];
110 /* By default request for device exclusive */
111 flags = TI_SCI_PD_EXCLUSIVE;
112 if (args->args_count == 2)
113 flags = args->args[1] & TI_SCI_PD_EXCLUSIVE;
114 pd->priv = (void *)(uintptr_t)flags;
119 static const struct udevice_id ti_sci_power_domain_of_match[] = {
120 { .compatible = "ti,sci-pm-domain" },
124 static struct power_domain_ops ti_sci_power_domain_ops = {
125 .request = ti_sci_power_domain_request,
126 .rfree = ti_sci_power_domain_free,
127 .on = ti_sci_power_domain_on,
128 .off = ti_sci_power_domain_off,
129 .of_xlate = ti_sci_power_domain_of_xlate,
132 U_BOOT_DRIVER(ti_sci_pm_domains) = {
133 .name = "ti-sci-pm-domains",
134 .id = UCLASS_POWER_DOMAIN,
135 .of_match = ti_sci_power_domain_of_match,
136 .probe = ti_sci_power_domain_probe,
137 .priv_auto_alloc_size = sizeof(struct ti_sci_power_domain_data),
138 .ops = &ti_sci_power_domain_ops,