blob: 4c4351d2d9982909c62963f483b556acf823d424 [file] [log] [blame]
Andreas Dannenberg1a88a042018-08-27 15:57:45 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Texas Instruments System Control Interface (TI SCI) power domain driver
4 *
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Andreas Dannenberg <dannenberg@ti.com>
7 *
8 * Loosely based on Linux kernel ti_sci_pm_domains.c...
9 */
10
11#include <common.h>
12#include <dm.h>
13#include <errno.h>
14#include <power-domain-uclass.h>
15#include <linux/soc/ti/ti_sci_protocol.h>
Lokesh Vutlacd041c82019-06-07 19:24:46 +053016#include <dt-bindings/soc/ti,sci_pm_domain.h>
Andreas Dannenberg1a88a042018-08-27 15:57:45 +053017
18/**
19 * struct ti_sci_power_domain_data - pm domain controller information structure
20 * @sci: TI SCI handle used for communication with system controller
21 */
22struct ti_sci_power_domain_data {
23 const struct ti_sci_handle *sci;
24};
25
26static int ti_sci_power_domain_probe(struct udevice *dev)
27{
28 struct ti_sci_power_domain_data *data = dev_get_priv(dev);
29
30 debug("%s(dev=%p)\n", __func__, dev);
31
32 if (!data)
33 return -ENOMEM;
34
35 /* Store handle for communication with the system controller */
36 data->sci = ti_sci_get_handle(dev);
37 if (IS_ERR(data->sci))
38 return PTR_ERR(data->sci);
39
40 return 0;
41}
42
43static int ti_sci_power_domain_request(struct power_domain *pd)
44{
45 debug("%s(pd=%p)\n", __func__, pd);
46 return 0;
47}
48
49static int ti_sci_power_domain_free(struct power_domain *pd)
50{
51 debug("%s(pd=%p)\n", __func__, pd);
52 return 0;
53}
54
55static int ti_sci_power_domain_on(struct power_domain *pd)
56{
57 struct ti_sci_power_domain_data *data = dev_get_priv(pd->dev);
58 const struct ti_sci_handle *sci = data->sci;
59 const struct ti_sci_dev_ops *dops = &sci->ops.dev_ops;
Lokesh Vutlacd041c82019-06-07 19:24:46 +053060 u8 flags = (uintptr_t)pd->priv;
Andreas Dannenberg1a88a042018-08-27 15:57:45 +053061 int ret;
62
63 debug("%s(pd=%p)\n", __func__, pd);
64
Lokesh Vutlacd041c82019-06-07 19:24:46 +053065 if (flags & TI_SCI_PD_EXCLUSIVE)
66 ret = dops->get_device_exclusive(sci, pd->id);
67 else
68 ret = dops->get_device(sci, pd->id);
69
Andreas Dannenberg1a88a042018-08-27 15:57:45 +053070 if (ret)
Nishanth Menon71cd80a2019-08-01 19:08:24 +053071 dev_err(pd->dev, "%s: get_device(%lu) failed (%d)\n",
72 __func__, pd->id, ret);
Andreas Dannenberg1a88a042018-08-27 15:57:45 +053073
74 return ret;
75}
76
77static int ti_sci_power_domain_off(struct power_domain *pd)
78{
79 struct ti_sci_power_domain_data *data = dev_get_priv(pd->dev);
80 const struct ti_sci_handle *sci = data->sci;
81 const struct ti_sci_dev_ops *dops = &sci->ops.dev_ops;
82 int ret;
83
84 debug("%s(pd=%p)\n", __func__, pd);
85
86 ret = dops->put_device(sci, pd->id);
87 if (ret)
Nishanth Menon71cd80a2019-08-01 19:08:24 +053088 dev_err(pd->dev, "%s: put_device(%lu) failed (%d)\n",
89 __func__, pd->id, ret);
Andreas Dannenberg1a88a042018-08-27 15:57:45 +053090
91 return ret;
92}
93
Lokesh Vutlacd041c82019-06-07 19:24:46 +053094static int ti_sci_power_domain_of_xlate(struct power_domain *pd,
95 struct ofnode_phandle_args *args)
96{
97 u8 flags;
98
99 debug("%s(power_domain=%p)\n", __func__, pd);
100
101 if (args->args_count < 1) {
102 debug("Invalid args_count: %d\n", args->args_count);
103 return -EINVAL;
104 }
105
106 pd->id = args->args[0];
107 /* By default request for device exclusive */
108 flags = TI_SCI_PD_EXCLUSIVE;
109 if (args->args_count == 2)
110 flags = args->args[1] & TI_SCI_PD_EXCLUSIVE;
111 pd->priv = (void *)(uintptr_t)flags;
112
113 return 0;
114}
115
Andreas Dannenberg1a88a042018-08-27 15:57:45 +0530116static const struct udevice_id ti_sci_power_domain_of_match[] = {
117 { .compatible = "ti,sci-pm-domain" },
118 { /* sentinel */ }
119};
120
121static struct power_domain_ops ti_sci_power_domain_ops = {
122 .request = ti_sci_power_domain_request,
123 .free = ti_sci_power_domain_free,
124 .on = ti_sci_power_domain_on,
125 .off = ti_sci_power_domain_off,
Lokesh Vutlacd041c82019-06-07 19:24:46 +0530126 .of_xlate = ti_sci_power_domain_of_xlate,
Andreas Dannenberg1a88a042018-08-27 15:57:45 +0530127};
128
129U_BOOT_DRIVER(ti_sci_pm_domains) = {
130 .name = "ti-sci-pm-domains",
131 .id = UCLASS_POWER_DOMAIN,
132 .of_match = ti_sci_power_domain_of_match,
133 .probe = ti_sci_power_domain_probe,
134 .priv_auto_alloc_size = sizeof(struct ti_sci_power_domain_data),
135 .ops = &ti_sci_power_domain_ops,
136};