Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright 2017 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 8 | #include <malloc.h> |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 9 | #include <power-domain-uclass.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/power-domain.h> |
| 13 | #include <asm/mach-imx/sys_proto.h> |
| 14 | #include <dm/device-internal.h> |
| 15 | #include <dm/device.h> |
| 16 | #include <imx_sip.h> |
Peng Fan | aae3356 | 2020-05-11 15:16:37 +0800 | [diff] [blame] | 17 | #include <linux/arm-smccc.h> |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | static int imx8m_power_domain_request(struct power_domain *power_domain) |
| 22 | { |
| 23 | return 0; |
| 24 | } |
| 25 | |
| 26 | static int imx8m_power_domain_free(struct power_domain *power_domain) |
| 27 | { |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static int imx8m_power_domain_on(struct power_domain *power_domain) |
| 32 | { |
| 33 | struct udevice *dev = power_domain->dev; |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 34 | struct imx8m_power_domain_plat *pdata; |
Peng Fan | aae3356 | 2020-05-11 15:16:37 +0800 | [diff] [blame] | 35 | |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 36 | pdata = dev_get_plat(dev); |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 37 | |
| 38 | if (pdata->resource_id < 0) |
| 39 | return -EINVAL; |
| 40 | |
| 41 | if (pdata->has_pd) |
| 42 | power_domain_on(&pdata->pd); |
| 43 | |
Peng Fan | aae3356 | 2020-05-11 15:16:37 +0800 | [diff] [blame] | 44 | arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN, |
| 45 | pdata->resource_id, 1, 0, 0, 0, 0, NULL); |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int imx8m_power_domain_off(struct power_domain *power_domain) |
| 51 | { |
| 52 | struct udevice *dev = power_domain->dev; |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 53 | struct imx8m_power_domain_plat *pdata; |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 54 | pdata = dev_get_plat(dev); |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 55 | |
| 56 | if (pdata->resource_id < 0) |
| 57 | return -EINVAL; |
| 58 | |
Peng Fan | aae3356 | 2020-05-11 15:16:37 +0800 | [diff] [blame] | 59 | arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN, |
| 60 | pdata->resource_id, 0, 0, 0, 0, 0, NULL); |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 61 | |
| 62 | if (pdata->has_pd) |
| 63 | power_domain_off(&pdata->pd); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static int imx8m_power_domain_of_xlate(struct power_domain *power_domain, |
| 69 | struct ofnode_phandle_args *args) |
| 70 | { |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static int imx8m_power_domain_bind(struct udevice *dev) |
| 75 | { |
| 76 | int offset; |
| 77 | const char *name; |
| 78 | int ret = 0; |
| 79 | |
| 80 | offset = dev_of_offset(dev); |
| 81 | for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0; |
| 82 | offset = fdt_next_subnode(gd->fdt_blob, offset)) { |
| 83 | /* Bind the subnode to this driver */ |
| 84 | name = fdt_get_name(gd->fdt_blob, offset, NULL); |
| 85 | |
| 86 | ret = device_bind_with_driver_data(dev, dev->driver, name, |
| 87 | dev->driver_data, |
| 88 | offset_to_ofnode(offset), |
| 89 | NULL); |
| 90 | |
| 91 | if (ret == -ENODEV) |
| 92 | printf("Driver '%s' refuses to bind\n", |
| 93 | dev->driver->name); |
| 94 | |
| 95 | if (ret) |
| 96 | printf("Error binding driver '%s': %d\n", |
| 97 | dev->driver->name, ret); |
| 98 | } |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static int imx8m_power_domain_probe(struct udevice *dev) |
| 104 | { |
| 105 | return 0; |
| 106 | } |
| 107 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 108 | static int imx8m_power_domain_of_to_plat(struct udevice *dev) |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 109 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 110 | struct imx8m_power_domain_plat *pdata = dev_get_plat(dev); |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 111 | |
| 112 | pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 113 | "reg", -1); |
| 114 | |
| 115 | if (!power_domain_get(dev, &pdata->pd)) |
| 116 | pdata->has_pd = 1; |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static const struct udevice_id imx8m_power_domain_ids[] = { |
| 122 | { .compatible = "fsl,imx8mq-gpc" }, |
Marek Vasut | d72ac58 | 2021-04-02 13:32:40 +0200 | [diff] [blame] | 123 | { .compatible = "fsl,imx8mm-gpc" }, |
Marek Vasut | e95c8dc | 2021-04-10 00:19:27 +0200 | [diff] [blame] | 124 | { .compatible = "fsl,imx8mn-gpc" }, |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 125 | { } |
| 126 | }; |
| 127 | |
| 128 | struct power_domain_ops imx8m_power_domain_ops = { |
| 129 | .request = imx8m_power_domain_request, |
Simon Glass | 92ed3a3 | 2020-02-03 07:35:51 -0700 | [diff] [blame] | 130 | .rfree = imx8m_power_domain_free, |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 131 | .on = imx8m_power_domain_on, |
| 132 | .off = imx8m_power_domain_off, |
| 133 | .of_xlate = imx8m_power_domain_of_xlate, |
| 134 | }; |
| 135 | |
| 136 | U_BOOT_DRIVER(imx8m_power_domain) = { |
| 137 | .name = "imx8m_power_domain", |
| 138 | .id = UCLASS_POWER_DOMAIN, |
| 139 | .of_match = imx8m_power_domain_ids, |
| 140 | .bind = imx8m_power_domain_bind, |
| 141 | .probe = imx8m_power_domain_probe, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 142 | .of_to_plat = imx8m_power_domain_of_to_plat, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 143 | .plat_auto = sizeof(struct imx8m_power_domain_plat), |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 144 | .ops = &imx8m_power_domain_ops, |
| 145 | }; |