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