summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2019-11-12 07:18:23 -0500
committerTom Rini <trini@konsulko.com>2019-11-12 07:18:23 -0500
commit5f7ff6d63eeb81ad2c071ff5f5adae5bcc94f7a4 (patch)
treeeb3707f7e5b4ae1d0f3094cc8814ef8bc389aa8c /drivers/power
parenta965a8b904093c9e6790d0460d18a144cefa5e42 (diff)
parentbdcf3a88cc582ce8bb9ea024fa917d9a52e05479 (diff)
downloadu-boot-5f7ff6d63eeb81ad2c071ff5f5adae5bcc94f7a4.tar.gz
u-boot-5f7ff6d63eeb81ad2c071ff5f5adae5bcc94f7a4.tar.bz2
u-boot-5f7ff6d63eeb81ad2c071ff5f5adae5bcc94f7a4.zip
Merge tag 'u-boot-imx-20191105' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx
u-boot-imx-20191105 ------------------- i.MX8MN SoC support ROM API image download support i.MX8MM enet enabling
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/domain/Makefile2
-rw-r--r--drivers/power/domain/imx8-power-domain-legacy.c315
-rw-r--r--drivers/power/domain/imx8-power-domain.c270
3 files changed, 337 insertions, 250 deletions
diff --git a/drivers/power/domain/Makefile b/drivers/power/domain/Makefile
index d0dce14a08..45bf9f6383 100644
--- a/drivers/power/domain/Makefile
+++ b/drivers/power/domain/Makefile
@@ -5,7 +5,7 @@
obj-$(CONFIG_$(SPL_)POWER_DOMAIN) += power-domain-uclass.o
obj-$(CONFIG_BCM6328_POWER_DOMAIN) += bcm6328-power-domain.o
-obj-$(CONFIG_IMX8_POWER_DOMAIN) += imx8-power-domain.o
+obj-$(CONFIG_IMX8_POWER_DOMAIN) += imx8-power-domain-legacy.o imx8-power-domain.o
obj-$(CONFIG_IMX8M_POWER_DOMAIN) += imx8m-power-domain.o
obj-$(CONFIG_MTK_POWER_DOMAIN) += mtk-power-domain.o
obj-$(CONFIG_MESON_GX_VPU_POWER_DOMAIN) += meson-gx-pwrc-vpu.o
diff --git a/drivers/power/domain/imx8-power-domain-legacy.c b/drivers/power/domain/imx8-power-domain-legacy.c
new file mode 100644
index 0000000000..d51dbaa6c0
--- /dev/null
+++ b/drivers/power/domain/imx8-power-domain-legacy.c
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2017 NXP
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <power-domain-uclass.h>
+#include <asm/io.h>
+#include <asm/arch/power-domain.h>
+#include <dm/device-internal.h>
+#include <dm/device.h>
+#include <asm/arch/sci/sci.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct imx8_power_domain_priv {
+ bool state_on;
+};
+
+static int imx8_power_domain_request(struct power_domain *power_domain)
+{
+ debug("%s(power_domain=%p)\n", __func__, power_domain);
+
+ return 0;
+}
+
+static int imx8_power_domain_free(struct power_domain *power_domain)
+{
+ debug("%s(power_domain=%p)\n", __func__, power_domain);
+
+ return 0;
+}
+
+static int imx8_power_domain_on(struct power_domain *power_domain)
+{
+ struct udevice *dev = power_domain->dev;
+ struct imx8_power_domain_platdata *pdata;
+ struct imx8_power_domain_priv *ppriv;
+ sc_err_t ret;
+ int err;
+
+ struct power_domain parent_domain;
+ struct udevice *parent = dev_get_parent(dev);
+
+ /* Need to power on parent node first */
+ if (device_get_uclass_id(parent) == UCLASS_POWER_DOMAIN) {
+ parent_domain.dev = parent;
+ err = imx8_power_domain_on(&parent_domain);
+ if (err)
+ return err;
+ }
+
+ pdata = (struct imx8_power_domain_platdata *)dev_get_platdata(dev);
+ ppriv = (struct imx8_power_domain_priv *)dev_get_priv(dev);
+
+ debug("%s(power_domain=%s) resource_id %d\n", __func__, dev->name,
+ pdata->resource_id);
+
+ /* Already powered on */
+ if (ppriv->state_on)
+ return 0;
+
+ if (pdata->resource_id != SC_R_LAST) {
+ ret = sc_pm_set_resource_power_mode(-1, pdata->resource_id,
+ SC_PM_PW_MODE_ON);
+ if (ret) {
+ printf("Error: %s Power up failed! (error = %d)\n",
+ dev->name, ret);
+ return -EIO;
+ }
+ }
+
+ ppriv->state_on = true;
+ debug("%s is powered on\n", dev->name);
+
+ return 0;
+}
+
+static int imx8_power_domain_off_node(struct power_domain *power_domain)
+{
+ struct udevice *dev = power_domain->dev;
+ struct udevice *child;
+ struct imx8_power_domain_priv *ppriv;
+ struct imx8_power_domain_priv *child_ppriv;
+ struct imx8_power_domain_platdata *pdata;
+ sc_err_t ret;
+
+ ppriv = dev_get_priv(dev);
+ pdata = dev_get_platdata(dev);
+
+ debug("%s, %s, state_on %d\n", __func__, dev->name, ppriv->state_on);
+
+ /* Already powered off */
+ if (!ppriv->state_on)
+ return 0;
+
+ /* Check if all subnodes are off */
+ for (device_find_first_child(dev, &child);
+ child;
+ device_find_next_child(&child)) {
+ if (device_active(child)) {
+ child_ppriv =
+ (struct imx8_power_domain_priv *)dev_get_priv(child);
+ if (child_ppriv->state_on)
+ return -EPERM;
+ }
+ }
+
+ if (pdata->resource_id != SC_R_LAST) {
+ if (!sc_rm_is_resource_owned(-1, pdata->resource_id)) {
+ printf("%s not owned by curr partition\n", dev->name);
+ return 0;
+ }
+ ret = sc_pm_set_resource_power_mode(-1, pdata->resource_id,
+ SC_PM_PW_MODE_OFF);
+ if (ret) {
+ printf("Error: %s Power off failed! (error = %d)\n",
+ dev->name, ret);
+ return -EIO;
+ }
+ }
+
+ ppriv->state_on = false;
+ debug("%s is powered off\n", dev->name);
+
+ return 0;
+}
+
+static int imx8_power_domain_off_parentnodes(struct power_domain *power_domain)
+{
+ struct udevice *dev = power_domain->dev;
+ struct udevice *parent = dev_get_parent(dev);
+ struct udevice *child;
+ struct imx8_power_domain_priv *ppriv;
+ struct imx8_power_domain_priv *child_ppriv;
+ struct imx8_power_domain_platdata *pdata;
+ sc_err_t ret;
+ struct power_domain parent_pd;
+
+ if (device_get_uclass_id(parent) == UCLASS_POWER_DOMAIN) {
+ pdata =
+ (struct imx8_power_domain_platdata *)dev_get_platdata(parent);
+ ppriv = (struct imx8_power_domain_priv *)dev_get_priv(parent);
+
+ debug("%s, %s, state_on %d\n", __func__, parent->name,
+ ppriv->state_on);
+
+ /* Already powered off */
+ if (!ppriv->state_on)
+ return 0;
+
+ /*
+ * Check if all sibling nodes are off. If yes,
+ * power off parent
+ */
+ for (device_find_first_child(parent, &child); child;
+ device_find_next_child(&child)) {
+ if (device_active(child)) {
+ child_ppriv = (struct imx8_power_domain_priv *)
+ dev_get_priv(child);
+ /* Find a power on sibling */
+ if (child_ppriv->state_on) {
+ debug("sibling %s, state_on %d\n",
+ child->name,
+ child_ppriv->state_on);
+ return 0;
+ }
+ }
+ }
+
+ /* power off parent */
+ if (pdata->resource_id != SC_R_LAST) {
+ ret = sc_pm_set_resource_power_mode(-1,
+ pdata->resource_id,
+ SC_PM_PW_MODE_OFF);
+ if (ret) {
+ printf("%s Power off failed! (error = %d)\n",
+ parent->name, ret);
+ return -EIO;
+ }
+ }
+
+ ppriv->state_on = false;
+ debug("%s is powered off\n", parent->name);
+
+ parent_pd.dev = parent;
+ imx8_power_domain_off_parentnodes(&parent_pd);
+ }
+
+ return 0;
+}
+
+static int imx8_power_domain_off(struct power_domain *power_domain)
+{
+ int ret;
+
+ debug("%s(power_domain=%p)\n", __func__, power_domain);
+
+ /* Turn off the node */
+ ret = imx8_power_domain_off_node(power_domain);
+ if (ret) {
+ debug("Can't power off the node of dev %s, ret = %d\n",
+ power_domain->dev->name, ret);
+ return ret;
+ }
+
+ /* Turn off parent nodes, if sibling nodes are all off */
+ ret = imx8_power_domain_off_parentnodes(power_domain);
+ if (ret) {
+ printf("Failed to power off parent nodes of dev %s, ret = %d\n",
+ power_domain->dev->name, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int imx8_power_domain_of_xlate(struct power_domain *power_domain,
+ struct ofnode_phandle_args *args)
+{
+ debug("%s(power_domain=%p)\n", __func__, power_domain);
+
+ /* Do nothing to the xlate, since we don't have args used */
+
+ return 0;
+}
+
+static int imx8_power_domain_bind(struct udevice *dev)
+{
+ int offset;
+ const char *name;
+ int ret = 0;
+
+ debug("%s(dev=%p)\n", __func__, dev);
+
+ offset = dev_of_offset(dev);
+ for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0;
+ offset = fdt_next_subnode(gd->fdt_blob, offset)) {
+ /* Bind the subnode to this driver */
+ name = fdt_get_name(gd->fdt_blob, offset, NULL);
+
+ ret = device_bind_with_driver_data(dev, dev->driver, name,
+ dev->driver_data,
+ offset_to_ofnode(offset),
+ NULL);
+
+ if (ret == -ENODEV)
+ printf("Driver '%s' refuses to bind\n",
+ dev->driver->name);
+
+ if (ret)
+ printf("Error binding driver '%s': %d\n",
+ dev->driver->name, ret);
+ }
+
+ return 0;
+}
+
+static int imx8_power_domain_probe(struct udevice *dev)
+{
+ struct imx8_power_domain_priv *ppriv;
+
+ debug("%s(dev=%s)\n", __func__, dev->name);
+
+ ppriv = (struct imx8_power_domain_priv *)dev_get_priv(dev);
+
+ /* Set default to power off */
+ if (ppriv)
+ ppriv->state_on = false;
+
+ return 0;
+}
+
+static int imx8_power_domain_ofdata_to_platdata(struct udevice *dev)
+{
+ int reg;
+ struct imx8_power_domain_platdata *pdata = dev_get_platdata(dev);
+
+ reg = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), "reg", -1);
+ if (reg == -1) {
+ debug("%s: Invalid resource id %d\n", __func__, reg);
+ return -EINVAL;
+ }
+ pdata->resource_id = (sc_rsrc_t)reg;
+
+ debug("%s resource_id %d\n", __func__, pdata->resource_id);
+
+ return 0;
+}
+
+static const struct udevice_id imx8_power_domain_ids[] = {
+ { .compatible = "nxp,imx8-pd" },
+ { }
+};
+
+struct power_domain_ops imx8_power_domain_ops = {
+ .request = imx8_power_domain_request,
+ .free = imx8_power_domain_free,
+ .on = imx8_power_domain_on,
+ .off = imx8_power_domain_off,
+ .of_xlate = imx8_power_domain_of_xlate,
+};
+
+U_BOOT_DRIVER(imx8_power_domain) = {
+ .name = "imx8_power_domain",
+ .id = UCLASS_POWER_DOMAIN,
+ .of_match = imx8_power_domain_ids,
+ .bind = imx8_power_domain_bind,
+ .probe = imx8_power_domain_probe,
+ .ofdata_to_platdata = imx8_power_domain_ofdata_to_platdata,
+ .platdata_auto_alloc_size = sizeof(struct imx8_power_domain_platdata),
+ .priv_auto_alloc_size = sizeof(struct imx8_power_domain_priv),
+ .ops = &imx8_power_domain_ops,
+};
diff --git a/drivers/power/domain/imx8-power-domain.c b/drivers/power/domain/imx8-power-domain.c
index d51dbaa6c0..aa768365b4 100644
--- a/drivers/power/domain/imx8-power-domain.c
+++ b/drivers/power/domain/imx8-power-domain.c
@@ -1,23 +1,15 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * Copyright 2017 NXP
+ * Copyright 2019 NXP
*/
+#define DEBUG
#include <common.h>
#include <dm.h>
#include <power-domain-uclass.h>
-#include <asm/io.h>
#include <asm/arch/power-domain.h>
-#include <dm/device-internal.h>
-#include <dm/device.h>
#include <asm/arch/sci/sci.h>
-DECLARE_GLOBAL_DATA_PTR;
-
-struct imx8_power_domain_priv {
- bool state_on;
-};
-
static int imx8_power_domain_request(struct power_domain *power_domain)
{
debug("%s(power_domain=%p)\n", __func__, power_domain);
@@ -34,158 +26,16 @@ static int imx8_power_domain_free(struct power_domain *power_domain)
static int imx8_power_domain_on(struct power_domain *power_domain)
{
- struct udevice *dev = power_domain->dev;
- struct imx8_power_domain_platdata *pdata;
- struct imx8_power_domain_priv *ppriv;
- sc_err_t ret;
- int err;
-
- struct power_domain parent_domain;
- struct udevice *parent = dev_get_parent(dev);
-
- /* Need to power on parent node first */
- if (device_get_uclass_id(parent) == UCLASS_POWER_DOMAIN) {
- parent_domain.dev = parent;
- err = imx8_power_domain_on(&parent_domain);
- if (err)
- return err;
- }
-
- pdata = (struct imx8_power_domain_platdata *)dev_get_platdata(dev);
- ppriv = (struct imx8_power_domain_priv *)dev_get_priv(dev);
-
- debug("%s(power_domain=%s) resource_id %d\n", __func__, dev->name,
- pdata->resource_id);
-
- /* Already powered on */
- if (ppriv->state_on)
- return 0;
-
- if (pdata->resource_id != SC_R_LAST) {
- ret = sc_pm_set_resource_power_mode(-1, pdata->resource_id,
- SC_PM_PW_MODE_ON);
- if (ret) {
- printf("Error: %s Power up failed! (error = %d)\n",
- dev->name, ret);
- return -EIO;
- }
- }
-
- ppriv->state_on = true;
- debug("%s is powered on\n", dev->name);
-
- return 0;
-}
-
-static int imx8_power_domain_off_node(struct power_domain *power_domain)
-{
- struct udevice *dev = power_domain->dev;
- struct udevice *child;
- struct imx8_power_domain_priv *ppriv;
- struct imx8_power_domain_priv *child_ppriv;
- struct imx8_power_domain_platdata *pdata;
- sc_err_t ret;
-
- ppriv = dev_get_priv(dev);
- pdata = dev_get_platdata(dev);
-
- debug("%s, %s, state_on %d\n", __func__, dev->name, ppriv->state_on);
-
- /* Already powered off */
- if (!ppriv->state_on)
- return 0;
-
- /* Check if all subnodes are off */
- for (device_find_first_child(dev, &child);
- child;
- device_find_next_child(&child)) {
- if (device_active(child)) {
- child_ppriv =
- (struct imx8_power_domain_priv *)dev_get_priv(child);
- if (child_ppriv->state_on)
- return -EPERM;
- }
- }
-
- if (pdata->resource_id != SC_R_LAST) {
- if (!sc_rm_is_resource_owned(-1, pdata->resource_id)) {
- printf("%s not owned by curr partition\n", dev->name);
- return 0;
- }
- ret = sc_pm_set_resource_power_mode(-1, pdata->resource_id,
- SC_PM_PW_MODE_OFF);
- if (ret) {
- printf("Error: %s Power off failed! (error = %d)\n",
- dev->name, ret);
- return -EIO;
- }
- }
-
- ppriv->state_on = false;
- debug("%s is powered off\n", dev->name);
-
- return 0;
-}
-
-static int imx8_power_domain_off_parentnodes(struct power_domain *power_domain)
-{
- struct udevice *dev = power_domain->dev;
- struct udevice *parent = dev_get_parent(dev);
- struct udevice *child;
- struct imx8_power_domain_priv *ppriv;
- struct imx8_power_domain_priv *child_ppriv;
- struct imx8_power_domain_platdata *pdata;
- sc_err_t ret;
- struct power_domain parent_pd;
-
- if (device_get_uclass_id(parent) == UCLASS_POWER_DOMAIN) {
- pdata =
- (struct imx8_power_domain_platdata *)dev_get_platdata(parent);
- ppriv = (struct imx8_power_domain_priv *)dev_get_priv(parent);
-
- debug("%s, %s, state_on %d\n", __func__, parent->name,
- ppriv->state_on);
-
- /* Already powered off */
- if (!ppriv->state_on)
- return 0;
-
- /*
- * Check if all sibling nodes are off. If yes,
- * power off parent
- */
- for (device_find_first_child(parent, &child); child;
- device_find_next_child(&child)) {
- if (device_active(child)) {
- child_ppriv = (struct imx8_power_domain_priv *)
- dev_get_priv(child);
- /* Find a power on sibling */
- if (child_ppriv->state_on) {
- debug("sibling %s, state_on %d\n",
- child->name,
- child_ppriv->state_on);
- return 0;
- }
- }
- }
-
- /* power off parent */
- if (pdata->resource_id != SC_R_LAST) {
- ret = sc_pm_set_resource_power_mode(-1,
- pdata->resource_id,
- SC_PM_PW_MODE_OFF);
- if (ret) {
- printf("%s Power off failed! (error = %d)\n",
- parent->name, ret);
- return -EIO;
- }
- }
+ u32 resource_id = power_domain->id;
+ int ret;
- ppriv->state_on = false;
- debug("%s is powered off\n", parent->name);
+ debug("%s: resource_id %u\n", __func__, resource_id);
- parent_pd.dev = parent;
- imx8_power_domain_off_parentnodes(&parent_pd);
+ ret = sc_pm_set_resource_power_mode(-1, resource_id, SC_PM_PW_MODE_ON);
+ if (ret) {
+ printf("Error: %u Power up failed! (error = %d)\n",
+ resource_id, ret);
+ return ret;
}
return 0;
@@ -193,123 +43,45 @@ static int imx8_power_domain_off_parentnodes(struct power_domain *power_domain)
static int imx8_power_domain_off(struct power_domain *power_domain)
{
+ u32 resource_id = power_domain->id;
int ret;
- debug("%s(power_domain=%p)\n", __func__, power_domain);
+ debug("%s: resource_id %u\n", __func__, resource_id);
- /* Turn off the node */
- ret = imx8_power_domain_off_node(power_domain);
+ ret = sc_pm_set_resource_power_mode(-1, resource_id, SC_PM_PW_MODE_OFF);
if (ret) {
- debug("Can't power off the node of dev %s, ret = %d\n",
- power_domain->dev->name, ret);
+ printf("Error: %u Power off failed! (error = %d)\n",
+ resource_id, ret);
return ret;
}
- /* Turn off parent nodes, if sibling nodes are all off */
- ret = imx8_power_domain_off_parentnodes(power_domain);
- if (ret) {
- printf("Failed to power off parent nodes of dev %s, ret = %d\n",
- power_domain->dev->name, ret);
- return ret;
- }
-
- return 0;
-}
-
-static int imx8_power_domain_of_xlate(struct power_domain *power_domain,
- struct ofnode_phandle_args *args)
-{
- debug("%s(power_domain=%p)\n", __func__, power_domain);
-
- /* Do nothing to the xlate, since we don't have args used */
-
- return 0;
-}
-
-static int imx8_power_domain_bind(struct udevice *dev)
-{
- int offset;
- const char *name;
- int ret = 0;
-
- debug("%s(dev=%p)\n", __func__, dev);
-
- offset = dev_of_offset(dev);
- for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0;
- offset = fdt_next_subnode(gd->fdt_blob, offset)) {
- /* Bind the subnode to this driver */
- name = fdt_get_name(gd->fdt_blob, offset, NULL);
-
- ret = device_bind_with_driver_data(dev, dev->driver, name,
- dev->driver_data,
- offset_to_ofnode(offset),
- NULL);
-
- if (ret == -ENODEV)
- printf("Driver '%s' refuses to bind\n",
- dev->driver->name);
-
- if (ret)
- printf("Error binding driver '%s': %d\n",
- dev->driver->name, ret);
- }
-
return 0;
}
static int imx8_power_domain_probe(struct udevice *dev)
{
- struct imx8_power_domain_priv *ppriv;
-
debug("%s(dev=%s)\n", __func__, dev->name);
- ppriv = (struct imx8_power_domain_priv *)dev_get_priv(dev);
-
- /* Set default to power off */
- if (ppriv)
- ppriv->state_on = false;
-
- return 0;
-}
-
-static int imx8_power_domain_ofdata_to_platdata(struct udevice *dev)
-{
- int reg;
- struct imx8_power_domain_platdata *pdata = dev_get_platdata(dev);
-
- reg = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), "reg", -1);
- if (reg == -1) {
- debug("%s: Invalid resource id %d\n", __func__, reg);
- return -EINVAL;
- }
- pdata->resource_id = (sc_rsrc_t)reg;
-
- debug("%s resource_id %d\n", __func__, pdata->resource_id);
-
return 0;
}
static const struct udevice_id imx8_power_domain_ids[] = {
- { .compatible = "nxp,imx8-pd" },
+ { .compatible = "fsl,imx8qxp-scu-pd" },
+ { .compatible = "fsl,scu-pd" },
{ }
};
-struct power_domain_ops imx8_power_domain_ops = {
+struct power_domain_ops imx8_power_domain_ops_v2 = {
.request = imx8_power_domain_request,
.free = imx8_power_domain_free,
.on = imx8_power_domain_on,
.off = imx8_power_domain_off,
- .of_xlate = imx8_power_domain_of_xlate,
};
-U_BOOT_DRIVER(imx8_power_domain) = {
- .name = "imx8_power_domain",
+U_BOOT_DRIVER(imx8_power_domain_v2) = {
+ .name = "imx8_power_domain_v2",
.id = UCLASS_POWER_DOMAIN,
.of_match = imx8_power_domain_ids,
- .bind = imx8_power_domain_bind,
.probe = imx8_power_domain_probe,
- .ofdata_to_platdata = imx8_power_domain_ofdata_to_platdata,
- .platdata_auto_alloc_size = sizeof(struct imx8_power_domain_platdata),
- .priv_auto_alloc_size = sizeof(struct imx8_power_domain_priv),
- .ops = &imx8_power_domain_ops,
+ .ops = &imx8_power_domain_ops_v2,
};