summaryrefslogtreecommitdiff
path: root/drivers/pmdomain/ti
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pmdomain/ti')
-rw-r--r--drivers/pmdomain/ti/omap_prm.c2
-rw-r--r--drivers/pmdomain/ti/ti_sci_pm_domains.c128
2 files changed, 114 insertions, 16 deletions
diff --git a/drivers/pmdomain/ti/omap_prm.c b/drivers/pmdomain/ti/omap_prm.c
index c2feae3a634c..b8ceb3c2b81c 100644
--- a/drivers/pmdomain/ti/omap_prm.c
+++ b/drivers/pmdomain/ti/omap_prm.c
@@ -695,6 +695,8 @@ static int omap_prm_domain_init(struct device *dev, struct omap_prm *prm)
data = prm->data;
name = devm_kasprintf(dev, GFP_KERNEL, "prm_%s",
data->name);
+ if (!name)
+ return -ENOMEM;
prmd->dev = dev;
prmd->prm = prm;
diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c
index c091d569ecd5..82df7e44250b 100644
--- a/drivers/pmdomain/ti/ti_sci_pm_domains.c
+++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c
@@ -12,6 +12,8 @@
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_domain.h>
+#include <linux/pm_qos.h>
+#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/soc/ti/ti_sci_protocol.h>
#include <dt-bindings/soc/ti,sci_pm_domain.h>
@@ -51,6 +53,56 @@ struct ti_sci_pm_domain {
#define genpd_to_ti_sci_pd(gpd) container_of(gpd, struct ti_sci_pm_domain, pd)
+static inline bool ti_sci_pd_is_valid_constraint(s32 val)
+{
+ return val != PM_QOS_RESUME_LATENCY_NO_CONSTRAINT;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static void ti_sci_pd_set_lat_constraint(struct device *dev, s32 val)
+{
+ struct generic_pm_domain *genpd = pd_to_genpd(dev->pm_domain);
+ struct ti_sci_pm_domain *pd = genpd_to_ti_sci_pd(genpd);
+ const struct ti_sci_handle *ti_sci = pd->parent->ti_sci;
+ u16 val_ms;
+ int ret;
+
+ /* PM QoS latency unit is usecs, TI SCI uses msecs */
+ val_ms = val / USEC_PER_MSEC;
+ ret = ti_sci->ops.pm_ops.set_latency_constraint(ti_sci, val_ms, TISCI_MSG_CONSTRAINT_SET);
+ if (ret)
+ dev_err(dev, "ti_sci_pd: set latency constraint failed: ret=%d\n",
+ ret);
+ else
+ dev_dbg(dev, "ti_sci_pd: ID:%d set latency constraint %d\n",
+ pd->idx, val);
+}
+#endif
+
+static inline void ti_sci_pd_set_wkup_constraint(struct device *dev)
+{
+ struct generic_pm_domain *genpd = pd_to_genpd(dev->pm_domain);
+ struct ti_sci_pm_domain *pd = genpd_to_ti_sci_pd(genpd);
+ const struct ti_sci_handle *ti_sci = pd->parent->ti_sci;
+ int ret;
+
+ if (device_may_wakeup(dev)) {
+ /*
+ * If device can wakeup using IO daisy chain wakeups,
+ * we do not want to set a constraint.
+ */
+ if (dev->power.wakeirq) {
+ dev_dbg(dev, "%s: has wake IRQ, not setting constraints\n", __func__);
+ return;
+ }
+
+ ret = ti_sci->ops.pm_ops.set_device_constraint(ti_sci, pd->idx,
+ TISCI_MSG_CONSTRAINT_SET);
+ if (!ret)
+ dev_dbg(dev, "ti_sci_pd: ID:%d set device constraint.\n", pd->idx);
+ }
+}
+
/*
* ti_sci_pd_power_off(): genpd power down hook
* @domain: pointer to the powerdomain to power off
@@ -79,13 +131,35 @@ static int ti_sci_pd_power_on(struct generic_pm_domain *domain)
return ti_sci->ops.dev_ops.get_device(ti_sci, pd->idx);
}
+#ifdef CONFIG_PM_SLEEP
+static int ti_sci_pd_suspend(struct device *dev)
+{
+ int ret;
+ s32 val;
+
+ ret = pm_generic_suspend(dev);
+ if (ret)
+ return ret;
+
+ val = dev_pm_qos_read_value(dev, DEV_PM_QOS_RESUME_LATENCY);
+ if (ti_sci_pd_is_valid_constraint(val))
+ ti_sci_pd_set_lat_constraint(dev, val);
+
+ ti_sci_pd_set_wkup_constraint(dev);
+
+ return 0;
+}
+#else
+#define ti_sci_pd_suspend NULL
+#endif
+
/*
* ti_sci_pd_xlate(): translation service for TI SCI genpds
* @genpdspec: DT identification data for the genpd
* @data: genpd core data for all the powerdomains on the device
*/
static struct generic_pm_domain *ti_sci_pd_xlate(
- struct of_phandle_args *genpdspec,
+ const struct of_phandle_args *genpdspec,
void *data)
{
struct genpd_onecell_data *genpd_data = data;
@@ -114,14 +188,25 @@ static const struct of_device_id ti_sci_pm_domain_matches[] = {
};
MODULE_DEVICE_TABLE(of, ti_sci_pm_domain_matches);
+static bool ti_sci_pm_idx_exists(struct ti_sci_genpd_provider *pd_provider, u32 idx)
+{
+ struct ti_sci_pm_domain *pd;
+
+ list_for_each_entry(pd, &pd_provider->pd_list, node) {
+ if (pd->idx == idx)
+ return true;
+ }
+
+ return false;
+}
+
static int ti_sci_pm_domain_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct ti_sci_genpd_provider *pd_provider;
struct ti_sci_pm_domain *pd;
- struct device_node *np;
+ struct device_node *np __free(device_node) = NULL;
struct of_phandle_args args;
- int ret;
u32 max_id = 0;
int index;
@@ -141,40 +226,51 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev)
for_each_node_with_property(np, "power-domains") {
index = 0;
- while (1) {
- ret = of_parse_phandle_with_args(np, "power-domains",
- "#power-domain-cells",
- index, &args);
- if (ret)
- break;
+ while (!of_parse_phandle_with_args(np, "power-domains",
+ "#power-domain-cells",
+ index, &args)) {
if (args.args_count >= 1 && args.np == dev->of_node) {
- if (args.args[0] > max_id)
+ of_node_put(args.np);
+ if (args.args[0] > max_id) {
max_id = args.args[0];
+ } else {
+ if (ti_sci_pm_idx_exists(pd_provider, args.args[0])) {
+ index++;
+ continue;
+ }
+ }
pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
- if (!pd) {
- of_node_put(np);
+ if (!pd)
return -ENOMEM;
- }
pd->pd.name = devm_kasprintf(dev, GFP_KERNEL,
"pd:%d",
args.args[0]);
- if (!pd->pd.name) {
- of_node_put(np);
+ if (!pd->pd.name)
return -ENOMEM;
- }
pd->pd.power_off = ti_sci_pd_power_off;
pd->pd.power_on = ti_sci_pd_power_on;
+ pd->pd.flags |= GENPD_FLAG_ACTIVE_WAKEUP;
pd->idx = args.args[0];
pd->parent = pd_provider;
+ /*
+ * If SCI constraint functions are present, then firmware
+ * supports the constraints API.
+ */
+ if (pd_provider->ti_sci->ops.pm_ops.set_device_constraint &&
+ pd_provider->ti_sci->ops.pm_ops.set_latency_constraint)
+ pd->pd.domain.ops.suspend = ti_sci_pd_suspend;
pm_genpd_init(&pd->pd, NULL, true);
list_add(&pd->node, &pd_provider->pd_list);
+ } else {
+ of_node_put(args.np);
}
+
index++;
}
}