Commit d08a194871fdf91b2ccdbaf02e35ed9443e0e170

Authored by Patrick Wildt
Committed by Stefano Babic
1 parent 6745dac494

imx: add support for i.MX8MQ power domain controller

Add support for the power domain controller that's used on the
i.MX8MQ.  This will be needed to be able to power on the PCIe
controller.  Bindings taken from Linux, driver implementation
taken from the i.MX8 power domain controller and adjusted for
the i.MX8M SoC.

Signed-off-by: Patrick Wildt <patrick@blueri.se>

Showing 8 changed files with 218 additions and 6 deletions Side-by-side Diff

arch/arm/dts/fsl-imx8mq.dtsi
... ... @@ -19,6 +19,7 @@
19 19 #include <dt-bindings/input/input.h>
20 20 #include <dt-bindings/interrupt-controller/arm-gic.h>
21 21 #include <dt-bindings/pinctrl/pins-imx8mq.h>
  22 +#include <dt-bindings/power/imx8mq-power.h>
22 23 #include <dt-bindings/thermal/thermal.h>
23 24  
24 25 / {
... ... @@ -71,12 +72,6 @@
71 72 interrupt-parent = <&gic>;
72 73 };
73 74  
74   - power: power-controller {
75   - compatible = "fsl,imx8mq-pm-domain";
76   - num-domains = <11>;
77   - #power-domain-cells = <1>;
78   - };
79   -
80 75 pwm2: pwm@30670000 {
81 76 compatible = "fsl,imx8mq-pwm", "fsl,imx27-pwm";
82 77 reg = <0x0 0x30670000 0x0 0x10000>;
... ... @@ -276,6 +271,37 @@
276 271 interrupts = <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>;
277 272 #interrupt-cells = <3>;
278 273 interrupt-parent = <&gic>;
  274 +
  275 + pgc {
  276 + #address-cells = <1>;
  277 + #size-cells = <0>;
  278 +
  279 + /*
  280 + * As per comment in ATF source code:
  281 + *
  282 + * PCIE1 and PCIE2 share the
  283 + * same reset signal, if we
  284 + * power down PCIE2, PCIE1
  285 + * will be held in reset too.
  286 + *
  287 + * So instead of creating two
  288 + * separate power domains for
  289 + * PCIE1 and PCIE2 we create a
  290 + * link between both and use
  291 + * it as a shared PCIE power
  292 + * domain.
  293 + */
  294 + pgc_pcie: power-domain@1 {
  295 + #power-domain-cells = <0>;
  296 + reg = <IMX8M_POWER_DOMAIN_PCIE1>;
  297 + power-domains = <&pgc_pcie2>;
  298 + };
  299 +
  300 + pgc_pcie2: power-domain@a {
  301 + #power-domain-cells = <0>;
  302 + reg = <IMX8M_POWER_DOMAIN_PCIE2>;
  303 + };
  304 + };
279 305 };
280 306  
281 307 usdhc1: usdhc@30b40000 {
arch/arm/include/asm/arch-imx8m/power-domain.h
  1 +/* SPDX-License-Identifier: GPL-2.0 */
  2 +/*
  3 + * Copyright 2017 NXP
  4 + */
  5 +
  6 +#ifndef _ASM_ARCH_IMX8M_POWER_DOMAIN_H
  7 +#define _ASM_ARCH_IMX8M_POWER_DOMAIN_H
  8 +
  9 +struct imx8m_power_domain_platdata {
  10 + int resource_id;
  11 + int has_pd;
  12 + struct power_domain pd;
  13 +};
  14 +
  15 +#endif
configs/imx8mq_evk_defconfig
... ... @@ -37,6 +37,8 @@
37 37 CONFIG_DM_ETH=y
38 38 CONFIG_PINCTRL=y
39 39 CONFIG_PINCTRL_IMX8M=y
  40 +CONFIG_POWER_DOMAIN=y
  41 +CONFIG_IMX8M_POWER_DOMAIN=y
40 42 CONFIG_DM_REGULATOR=y
41 43 CONFIG_DM_REGULATOR_FIXED=y
42 44 CONFIG_DM_REGULATOR_GPIO=y
drivers/power/domain/Kconfig
... ... @@ -23,6 +23,13 @@
23 23 Enable support for manipulating NXP i.MX8 on-SoC power domains via IPC
24 24 requests to the SCU.
25 25  
  26 +config IMX8M_POWER_DOMAIN
  27 + bool "Enable i.MX8M power domain driver"
  28 + depends on POWER_DOMAIN && ARCH_IMX8M
  29 + help
  30 + Enable support for manipulating NXP i.MX8M on-SoC power domains via
  31 + requests to the ATF.
  32 +
26 33 config MTK_POWER_DOMAIN
27 34 bool "Enable the MediaTek power domain driver"
28 35 depends on POWER_DOMAIN && ARCH_MEDIATEK
drivers/power/domain/Makefile
... ... @@ -6,6 +6,7 @@
6 6 obj-$(CONFIG_$(SPL_)POWER_DOMAIN) += power-domain-uclass.o
7 7 obj-$(CONFIG_BCM6328_POWER_DOMAIN) += bcm6328-power-domain.o
8 8 obj-$(CONFIG_IMX8_POWER_DOMAIN) += imx8-power-domain.o
  9 +obj-$(CONFIG_IMX8M_POWER_DOMAIN) += imx8m-power-domain.o
9 10 obj-$(CONFIG_MTK_POWER_DOMAIN) += mtk-power-domain.o
10 11 obj-$(CONFIG_MESON_GX_VPU_POWER_DOMAIN) += meson-gx-pwrc-vpu.o
11 12 obj-$(CONFIG_SANDBOX_POWER_DOMAIN) += sandbox-power-domain.o
drivers/power/domain/imx8m-power-domain.c
  1 +// SPDX-License-Identifier: GPL-2.0
  2 +/*
  3 + * Copyright 2017 NXP
  4 + */
  5 +
  6 +#include <common.h>
  7 +#include <dm.h>
  8 +#include <power-domain-uclass.h>
  9 +#include <asm/io.h>
  10 +#include <asm/arch/power-domain.h>
  11 +#include <asm/mach-imx/sys_proto.h>
  12 +#include <dm/device-internal.h>
  13 +#include <dm/device.h>
  14 +#include <imx_sip.h>
  15 +
  16 +DECLARE_GLOBAL_DATA_PTR;
  17 +
  18 +static int imx8m_power_domain_request(struct power_domain *power_domain)
  19 +{
  20 + return 0;
  21 +}
  22 +
  23 +static int imx8m_power_domain_free(struct power_domain *power_domain)
  24 +{
  25 + return 0;
  26 +}
  27 +
  28 +static int imx8m_power_domain_on(struct power_domain *power_domain)
  29 +{
  30 + struct udevice *dev = power_domain->dev;
  31 + struct imx8m_power_domain_platdata *pdata;
  32 + pdata = dev_get_platdata(dev);
  33 +
  34 + if (pdata->resource_id < 0)
  35 + return -EINVAL;
  36 +
  37 + if (pdata->has_pd)
  38 + power_domain_on(&pdata->pd);
  39 +
  40 + call_imx_sip(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN, pdata->resource_id, 1);
  41 +
  42 + return 0;
  43 +}
  44 +
  45 +static int imx8m_power_domain_off(struct power_domain *power_domain)
  46 +{
  47 + struct udevice *dev = power_domain->dev;
  48 + struct imx8m_power_domain_platdata *pdata;
  49 + pdata = dev_get_platdata(dev);
  50 +
  51 + if (pdata->resource_id < 0)
  52 + return -EINVAL;
  53 +
  54 + call_imx_sip(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN, pdata->resource_id, 0);
  55 +
  56 + if (pdata->has_pd)
  57 + power_domain_off(&pdata->pd);
  58 +
  59 + return 0;
  60 +}
  61 +
  62 +static int imx8m_power_domain_of_xlate(struct power_domain *power_domain,
  63 + struct ofnode_phandle_args *args)
  64 +{
  65 + return 0;
  66 +}
  67 +
  68 +static int imx8m_power_domain_bind(struct udevice *dev)
  69 +{
  70 + int offset;
  71 + const char *name;
  72 + int ret = 0;
  73 +
  74 + offset = dev_of_offset(dev);
  75 + for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0;
  76 + offset = fdt_next_subnode(gd->fdt_blob, offset)) {
  77 + /* Bind the subnode to this driver */
  78 + name = fdt_get_name(gd->fdt_blob, offset, NULL);
  79 +
  80 + ret = device_bind_with_driver_data(dev, dev->driver, name,
  81 + dev->driver_data,
  82 + offset_to_ofnode(offset),
  83 + NULL);
  84 +
  85 + if (ret == -ENODEV)
  86 + printf("Driver '%s' refuses to bind\n",
  87 + dev->driver->name);
  88 +
  89 + if (ret)
  90 + printf("Error binding driver '%s': %d\n",
  91 + dev->driver->name, ret);
  92 + }
  93 +
  94 + return 0;
  95 +}
  96 +
  97 +static int imx8m_power_domain_probe(struct udevice *dev)
  98 +{
  99 + return 0;
  100 +}
  101 +
  102 +static int imx8m_power_domain_ofdata_to_platdata(struct udevice *dev)
  103 +{
  104 + struct imx8m_power_domain_platdata *pdata = dev_get_platdata(dev);
  105 +
  106 + pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
  107 + "reg", -1);
  108 +
  109 + if (!power_domain_get(dev, &pdata->pd))
  110 + pdata->has_pd = 1;
  111 +
  112 + return 0;
  113 +}
  114 +
  115 +static const struct udevice_id imx8m_power_domain_ids[] = {
  116 + { .compatible = "fsl,imx8mq-gpc" },
  117 + { }
  118 +};
  119 +
  120 +struct power_domain_ops imx8m_power_domain_ops = {
  121 + .request = imx8m_power_domain_request,
  122 + .free = imx8m_power_domain_free,
  123 + .on = imx8m_power_domain_on,
  124 + .off = imx8m_power_domain_off,
  125 + .of_xlate = imx8m_power_domain_of_xlate,
  126 +};
  127 +
  128 +U_BOOT_DRIVER(imx8m_power_domain) = {
  129 + .name = "imx8m_power_domain",
  130 + .id = UCLASS_POWER_DOMAIN,
  131 + .of_match = imx8m_power_domain_ids,
  132 + .bind = imx8m_power_domain_bind,
  133 + .probe = imx8m_power_domain_probe,
  134 + .ofdata_to_platdata = imx8m_power_domain_ofdata_to_platdata,
  135 + .platdata_auto_alloc_size = sizeof(struct imx8m_power_domain_platdata),
  136 + .ops = &imx8m_power_domain_ops,
  137 +};
include/dt-bindings/power/imx8mq-power.h
  1 +/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
  2 +/*
  3 + * Copyright (C) 2018 Pengutronix, Lucas Stach <kernel@pengutronix.de>
  4 + */
  5 +
  6 +#ifndef __DT_BINDINGS_IMX8MQ_POWER_H__
  7 +#define __DT_BINDINGS_IMX8MQ_POWER_H__
  8 +
  9 +#define IMX8M_POWER_DOMAIN_MIPI 0
  10 +#define IMX8M_POWER_DOMAIN_PCIE1 1
  11 +#define IMX8M_POWER_DOMAIN_USB_OTG1 2
  12 +#define IMX8M_POWER_DOMAIN_USB_OTG2 3
  13 +#define IMX8M_POWER_DOMAIN_DDR1 4
  14 +#define IMX8M_POWER_DOMAIN_GPU 5
  15 +#define IMX8M_POWER_DOMAIN_VPU 6
  16 +#define IMX8M_POWER_DOMAIN_DISP 7
  17 +#define IMX8M_POWER_DOMAIN_MIPI_CSI1 8
  18 +#define IMX8M_POWER_DOMAIN_MIPI_CSI2 9
  19 +#define IMX8M_POWER_DOMAIN_PCIE2 10
  20 +
  21 +#endif
... ... @@ -6,6 +6,9 @@
6 6 #ifndef _IMX_SIP_H__
7 7 #define _IMX_SIP_H_
8 8  
  9 +#define IMX_SIP_GPC 0xC2000000
  10 +#define IMX_SIP_GPC_PM_DOMAIN 0x03
  11 +
9 12 #define IMX_SIP_SRC 0xC2000005
10 13 #define IMX_SIP_SRC_M4_START 0x00
11 14 #define IMX_SIP_SRC_M4_STARTED 0x01