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> |
| 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 | |
Ye Li | e5e9109 | 2019-10-26 16:24:03 +0200 | [diff] [blame] | 40 | call_imx_sip(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN, |
| 41 | pdata->resource_id, 1, 0); |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static int imx8m_power_domain_off(struct power_domain *power_domain) |
| 47 | { |
| 48 | struct udevice *dev = power_domain->dev; |
| 49 | struct imx8m_power_domain_platdata *pdata; |
| 50 | pdata = dev_get_platdata(dev); |
| 51 | |
| 52 | if (pdata->resource_id < 0) |
| 53 | return -EINVAL; |
| 54 | |
Ye Li | e5e9109 | 2019-10-26 16:24:03 +0200 | [diff] [blame] | 55 | call_imx_sip(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN, |
| 56 | pdata->resource_id, 0, 0); |
Patrick Wildt | 8bd5656 | 2019-10-03 15:51:50 +0200 | [diff] [blame] | 57 | |
| 58 | if (pdata->has_pd) |
| 59 | power_domain_off(&pdata->pd); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int imx8m_power_domain_of_xlate(struct power_domain *power_domain, |
| 65 | struct ofnode_phandle_args *args) |
| 66 | { |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static int imx8m_power_domain_bind(struct udevice *dev) |
| 71 | { |
| 72 | int offset; |
| 73 | const char *name; |
| 74 | int ret = 0; |
| 75 | |
| 76 | offset = dev_of_offset(dev); |
| 77 | for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0; |
| 78 | offset = fdt_next_subnode(gd->fdt_blob, offset)) { |
| 79 | /* Bind the subnode to this driver */ |
| 80 | name = fdt_get_name(gd->fdt_blob, offset, NULL); |
| 81 | |
| 82 | ret = device_bind_with_driver_data(dev, dev->driver, name, |
| 83 | dev->driver_data, |
| 84 | offset_to_ofnode(offset), |
| 85 | NULL); |
| 86 | |
| 87 | if (ret == -ENODEV) |
| 88 | printf("Driver '%s' refuses to bind\n", |
| 89 | dev->driver->name); |
| 90 | |
| 91 | if (ret) |
| 92 | printf("Error binding driver '%s': %d\n", |
| 93 | dev->driver->name, ret); |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static int imx8m_power_domain_probe(struct udevice *dev) |
| 100 | { |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static int imx8m_power_domain_ofdata_to_platdata(struct udevice *dev) |
| 105 | { |
| 106 | struct imx8m_power_domain_platdata *pdata = dev_get_platdata(dev); |
| 107 | |
| 108 | pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 109 | "reg", -1); |
| 110 | |
| 111 | if (!power_domain_get(dev, &pdata->pd)) |
| 112 | pdata->has_pd = 1; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static const struct udevice_id imx8m_power_domain_ids[] = { |
| 118 | { .compatible = "fsl,imx8mq-gpc" }, |
| 119 | { } |
| 120 | }; |
| 121 | |
| 122 | struct power_domain_ops imx8m_power_domain_ops = { |
| 123 | .request = imx8m_power_domain_request, |
| 124 | .free = imx8m_power_domain_free, |
| 125 | .on = imx8m_power_domain_on, |
| 126 | .off = imx8m_power_domain_off, |
| 127 | .of_xlate = imx8m_power_domain_of_xlate, |
| 128 | }; |
| 129 | |
| 130 | U_BOOT_DRIVER(imx8m_power_domain) = { |
| 131 | .name = "imx8m_power_domain", |
| 132 | .id = UCLASS_POWER_DOMAIN, |
| 133 | .of_match = imx8m_power_domain_ids, |
| 134 | .bind = imx8m_power_domain_bind, |
| 135 | .probe = imx8m_power_domain_probe, |
| 136 | .ofdata_to_platdata = imx8m_power_domain_ofdata_to_platdata, |
| 137 | .platdata_auto_alloc_size = sizeof(struct imx8m_power_domain_platdata), |
| 138 | .ops = &imx8m_power_domain_ops, |
| 139 | }; |